From 4bd700ec3874be60efbab7dcab12a5e44f1fbdbb Mon Sep 17 00:00:00 2001 From: minibits-cash Date: Mon, 17 Jun 2024 22:41:21 +0200 Subject: [PATCH] Fix crash in public contact list if followed Nostr profiles contain invalid params. --- package.json | 2 +- src/screens/Contacts/PublicContacts.tsx | 25 ++++++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 4f088dc6..c6d6b45d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minibits_wallet", - "version": "0.1.8-beta.28", + "version": "0.1.8-beta.29", "private": true, "scripts": { "android:clean": "cd android && ./gradlew clean", diff --git a/src/screens/Contacts/PublicContacts.tsx b/src/screens/Contacts/PublicContacts.tsx index 5def56dc..28600ec1 100644 --- a/src/screens/Contacts/PublicContacts.tsx +++ b/src/screens/Contacts/PublicContacts.tsx @@ -14,7 +14,6 @@ import { StackNavigationProp } from '@react-navigation/stack' import { ContactsStackParamList } from '../../navigation' import { SendOption } from '../SendOptionsScreen' import { ReceiveOption } from '../ReceiveOptionsScreen' -import { useSafeAreaInsetsStyle } from '../../utils/useSafeAreaInsetsStyle' import { useSafeAreaInsets } from 'react-native-safe-area-context' import { IncomingDataType, IncomingParser } from '../../services/incomingParser' import { translate } from '../../i18n' @@ -118,17 +117,17 @@ export const PublicContacts = observer(function (props: { const subscribeToOwnProfileAndPubkeys = async function () { - log.trace('subscribeToOwnProfileAndPubkeys start') + log.trace('[subscribeToOwnProfileAndPubkeys] start') if(!contactsStore.publicPubkey) { return } - const filters: NostrFilter = [{ + const filters: NostrFilter[] = [{ authors: [contactsStore.publicPubkey], kinds: [0, 3], }] - log.trace('subscribeToOwnProfileAndPubkeys getEvents') + log.trace('[subscribeToOwnProfileAndPubkeys] getEvents') const events: NostrEvent[] = await NostrClient.getEvents(relaysStore.allPublicUrls, filters) log.trace(events) @@ -142,7 +141,7 @@ export const PublicContacts = observer(function (props: { const profile: NostrProfile = JSON.parse(event.content) profile.pubkey = contactsStore.publicPubkey as string // pubkey might not be in ev.content - log.trace('Updating own profile', profile) + log.trace('[subscribeToOwnProfileAndPubkeys] Updating own profile', profile) setOwnProfile(profile) } catch(e: any) { continue @@ -173,7 +172,7 @@ export const PublicContacts = observer(function (props: { limit: maxContactsToLoad, }] - log.trace('Starting following profiles subscription...') + log.trace('[loadProfiles] Starting following profiles subscription...') setIsLoading(true) @@ -188,7 +187,12 @@ export const PublicContacts = observer(function (props: { profile.pubkey = event.pubkey profile.npub = NostrClient.getNpubkey(event.pubkey) - if (!following.some(f => f.pubkey === profile.pubkey)) { + // fix potentially invalid types + if(profile.nip05) profile.nip05 = String(profile.nip05) + if(profile.picture) profile.picture = String(profile.picture) + if(profile.name) profile.name = String(profile.name) + + if (!following.some(f => f.pubkey === profile.pubkey)) { following.push(profile) } else { log.trace('[loadProfiles]', 'Got duplicate profile from relays', profile.pubkey) @@ -199,7 +203,10 @@ export const PublicContacts = observer(function (props: { } } - log.trace('Updating following profiles', following.length) + log.trace('Updating following profiles', following.length) + + log.warn(following) + setFollowingProfiles(following) setIsLoading(false) } @@ -483,7 +490,7 @@ export const PublicContacts = observer(function (props: { const isFirst= index === 0 return( {item.picture ? (