diff options
| author | Adam Soltys <[email protected]> | 2026-02-27 15:24:13 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-02-27 15:24:13 -0800 |
| commit | 16da2cb00d16f87d02535bfdae815f83f19f251f (patch) | |
| tree | 2e6d003975d5a7a67cc81243da4a59bc476fff48 /src/components | |
| parent | 11fbf552ebbb9d1d5ae6823893ee80ae23f450a0 (diff) | |
| download | coinos-ui-16da2cb00d16f87d02535bfdae815f83f19f251f.tar.gz coinos-ui-16da2cb00d16f87d02535bfdae815f83f19f251f.zip | |
fix race condition
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/Account.svelte | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/components/Account.svelte b/src/components/Account.svelte index 45ffdd8b..ff9218fe 100644 --- a/src/components/Account.svelte +++ b/src/components/Account.svelte @@ -18,8 +18,8 @@ let arkBalance = $state(0); let arkLoading = $state(false); - let tryUnlockArk = async () => { - const deriveArkKey = async (key: ArrayBuffer) => { + let tryUnlockArk = async (): Promise<string | false> => { + const deriveArkKey = async (key: ArrayBuffer): Promise<string> => { const [{ HDKey }, { entropyToMnemonic, mnemonicToSeed }, { wordlist }] = await Promise.all([ import("@scure/bip32"), import("@scure/bip39"), @@ -36,8 +36,7 @@ const s = await mnemonicToSeed(mnemonicStr); const master = HDKey.fromMasterSeed(s, versions); const arkChild = master.derive("m/86'/0'/0'/0/0"); - $arkkey = bytesToHex(arkChild.privateKey!); - $arkaid = id; + return bytesToHex(arkChild.privateKey!); }; // Try cached PRF key or silent nsec @@ -45,8 +44,7 @@ const entropy = await getWalletEntropy(); if (entropy) { try { - await deriveArkKey(entropy); - return true; + return await deriveArkKey(entropy); } catch (e) { console.log("Wallet entropy unlock failed", e); } @@ -55,8 +53,7 @@ // Try interactive nostr derivation try { const interactiveEntropy = await deriveNostrEntropy(); - await deriveArkKey(interactiveEntropy); - return true; + return await deriveArkKey(interactiveEntropy); } catch (e) { console.log("Interactive nostr unlock failed", e); return false; @@ -69,9 +66,14 @@ document.cookie = `aid=${id}; path=/; max-age=86400`; if (isArk) { if ($arkkey && $arkaid === id) { - goto(url); - } else if (await tryUnlockArk()) { - goto(url); + await goto(url); + } else { + const key = await tryUnlockArk(); + if (key) { + await goto(url); + $arkkey = key; + $arkaid = id; + } } } else { $arkkey = undefined; |
