diff --git a/src/components/Layout/Layout.tsx b/src/components/Layout/Layout.tsx index a31e056..8a4c316 100644 --- a/src/components/Layout/Layout.tsx +++ b/src/components/Layout/Layout.tsx @@ -81,9 +81,7 @@ const Layout: Component = () => { createEffect(() => { if (location.pathname === '/' || account?.isKeyLookupDone) return; - setTimeout(() => { - account?.actions.checkNostrKey(); - }, 1000); + account?.actions.checkNostrKey(); }); return ( diff --git a/src/contexts/AccountContext.tsx b/src/contexts/AccountContext.tsx index b6151df..68807e4 100644 --- a/src/contexts/AccountContext.tsx +++ b/src/contexts/AccountContext.tsx @@ -159,7 +159,9 @@ export function AccountProvider(props: { children: JSXElement }) { const pubkey = nostrGetPubkey(decoded.data); - setPublicKey(pubkey); + if (pubkey !== store.publicKey) { + setPublicKey(pubkey); + } // Read profile from storage const storedUser = getStoredProfile(pubkey); @@ -302,6 +304,12 @@ export function AccountProvider(props: { children: JSXElement }) { const win = window as NostrWindow; const nostr = win.nostr; + const storedKey = localStorage.getItem('pubkey'); + + if (storedKey) { + setPublicKey(storedKey); + } + if (nostr === undefined) { console.log('Nostr extension not found'); // Try again after one second if extensionAttempts are not exceeded @@ -336,7 +344,9 @@ export function AccountProvider(props: { children: JSXElement }) { setTimeout(fetchNostrKey, 250); } else { - setPublicKey(key); + if (key !== storedKey) { + setPublicKey(key); + } // Read profile from storage const storedUser = getStoredProfile(key);