From 2a4c3dd7c81e6569089984cee4ca81cd5752a485 Mon Sep 17 00:00:00 2001 From: Ren Amamiya <123083837+reyamir@users.noreply.github.com> Date: Mon, 10 Jul 2023 14:20:36 +0700 Subject: [PATCH] update useProfile hook --- src/app/auth/import/step-2.tsx | 2 +- src/app/chat/components/item.tsx | 2 +- src/app/chat/components/self.tsx | 2 +- src/app/chat/components/sidebar.tsx | 2 +- src/app/user/index.tsx | 2 +- src/shared/composer/user.tsx | 2 +- src/shared/user.tsx | 4 ++-- src/utils/hooks/useProfile.tsx | 15 +++++++++++---- 8 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/app/auth/import/step-2.tsx b/src/app/auth/import/step-2.tsx index f3ae5127..6a65cc0d 100644 --- a/src/app/auth/import/step-2.tsx +++ b/src/app/auth/import/step-2.tsx @@ -60,7 +60,7 @@ export function ImportStep2Screen() { setPassword(data.password); // save privkey to secure storage - await save(pubkey, privkey); + await save(pubkey, privkey, data.password); // redirect to next step navigate('/auth/import/step-3', { replace: true }); diff --git a/src/app/chat/components/item.tsx b/src/app/chat/components/item.tsx index 71d0e9e6..f75015a8 100644 --- a/src/app/chat/components/item.tsx +++ b/src/app/chat/components/item.tsx @@ -33,7 +33,7 @@ export function ChatsListItem({ data }: { data: any }) { >
{data.sender_pubkey}
{data.pubkey}
{pubkey}
{pubkey}
{pubkey} {pubkey}
{pubkey}= current) { return cache; } else { - const user = ndk.getUser({ hexpubkey: pubkey }); - await user.fetchProfile(); - await createMetadata(pubkey, pubkey, JSON.stringify(user.profile)); - return user.profile; + const filter: NDKFilter = { kinds: [0], authors: [pubkey] }; + const events = await ndk.fetchEvents(filter); + const latest = [...events].slice(-1)[0]; + if (latest) { + await createMetadata(pubkey, pubkey, latest.content); + return JSON.parse(latest.content); + } else { + await createMetadata(pubkey, pubkey, [...events][0].content); + return JSON.parse([...events][0].content); + } } } else { const profile = JSON.parse(fallback);