aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/nostrlogin.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/features/nostrlogin.js')
-rw-r--r--src/features/nostrlogin.js18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/features/nostrlogin.js b/src/features/nostrlogin.js
index f18b075..f7f9e16 100644
--- a/src/features/nostrlogin.js
+++ b/src/features/nostrlogin.js
@@ -28,7 +28,13 @@ export function nostrLoginFeature(ctx) {
const { h, ui, render, wallet, toast, copyBtn } = ctx;
const load = () => wallet.loadFeatureState('nostrlogin', {});
- const save = (st) => wallet.saveFeatureState('nostrlogin', st);
+ const save = (st) => { idMemo = null; wallet.saveFeatureState('nostrlogin', st); };
+ // nostrLoginIdentity() is asked per feed row per moderation check (isMe,
+ // mePk, trusted…): thousands of times per scroll frame. Each answer parsed
+ // the stored state twice and bech32-encoded the npub. Keep the last answer
+ // briefly; a save, a signer change or another wallet's key drops it.
+ let idMemo = null;
+ const ID_MEMO_MS = 250;
// The signer that opened this session, kept so the names feature can claim
// the user's real npub as their payment address (and nominate the wallet
@@ -765,10 +771,14 @@ export function nostrLoginFeature(ctx) {
// wallet key's face in the gap.
// `via`: how the account came in, known before its signer wakes (an
// Amber account is one whether or not Amber has been asked anything yet)
+ const key = wallet.featureStateKey('nostrlogin');
+ if (idMemo && idMemo.live === live && idMemo.key === key && Date.now() - idMemo.at < ID_MEMO_MS) return idMemo.value;
const st = load();
- if (liveSigner()) return { pubkey: live.pubkey, npub: npubOf(live.pubkey), signer: live, via: st.pubkey === live.pubkey ? reconnectViaOf(st) : viaOf(live) };
- if (!st.pubkey) return null;
- return { pubkey: st.pubkey, npub: npubOf(st.pubkey), signer: live, via: reconnectViaOf(st) };
+ let value = null;
+ if (liveSigner()) value = { pubkey: live.pubkey, npub: npubOf(live.pubkey), signer: live, via: st.pubkey === live.pubkey ? reconnectViaOf(st) : viaOf(live) };
+ else if (st.pubkey) value = { pubkey: st.pubkey, npub: npubOf(st.pubkey), signer: live, via: reconnectViaOf(st) };
+ idMemo = { at: Date.now(), live, key, value };
+ return value;
},
// A page reload loses the signer. A stored passkey key or an installed
// extension reattaches without prompting, which is what lets the payment