diff options
| author | Adam Soltys <[email protected]> | 2022-12-28 15:05:00 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-12-28 15:05:00 -0800 |
| commit | 065721964152f1022e755c33d24353beaa07abd1 (patch) | |
| tree | 8abece462a0f4c8269f343ea1f4679a9d4e36a29 /src/lib | |
| parent | 671ec0529f466c3fc9218e928486f0277bd4c990 (diff) | |
| download | coinos-ui-065721964152f1022e755c33d24353beaa07abd1.tar.gz coinos-ui-065721964152f1022e755c33d24353beaa07abd1.zip | |
get follows and followers working
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/nostr.js | 17 | ||||
| -rw-r--r-- | src/lib/utils.js | 5 |
2 files changed, 7 insertions, 15 deletions
diff --git a/src/lib/nostr.js b/src/lib/nostr.js index 7523e97f..3f112788 100644 --- a/src/lib/nostr.js +++ b/src/lib/nostr.js @@ -2,28 +2,19 @@ import { get } from 'svelte/store'; import { entropyToMnemonic, mnemonicToSeedSync } from 'bip39'; import { Buffer } from 'buffer'; import { bech32m } from 'bech32'; -import { bip32, post, stretch } from '$lib/utils'; +import { bip32, wait, post, stretch } from '$lib/utils'; import { calculateId, signId } from 'nostr'; import { password as pw, passwordPrompt } from '$lib/store'; const { decode, fromWords } = bech32m; -let signing; - -pw.subscribe((nv, ov) => { - if (!signing) return; - sign(signing); -}); - export let sign = async ({ event, user }) => { - signing = { event, user }; let { cipher, username, salt } = user; let password = get(pw); if (!password) { passwordPrompt.set(true); - return; } try { @@ -31,9 +22,11 @@ export let sign = async ({ event, user }) => { } catch (e) { console.log(e); passwordPrompt.set(true); - return; } + await wait(() => !!get(pw)); + password = get(pw); + let mnemonic, key, seed, entropy, child, privkey; entropy = Buffer.from( await crypto.subtle.decrypt( @@ -52,8 +45,6 @@ export let sign = async ({ event, user }) => { event.id = await calculateId(event); event.sig = await signId(privkey, event.id); - - signing = false; }; export let send = (event) => { diff --git a/src/lib/utils.js b/src/lib/utils.js index e1088cac..e5441575 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -172,9 +172,10 @@ export const sats = 100000000; export const back = () => browser && history.go(-1); export const focus = (el) => setTimeout(() => el.focus()); -export const wait = async (f, s = 300) => { +export const sleep = (n) => new Promise((r) => setTimeout(r, n)); +export const wait = async (f, n = 100, s = 300) => { let i = 0; - while (!(await f()) && i < s) (await sleep(1000)) && i++; + while (!(await f()) && i < s) (await sleep(n)) && i++; if (i >= s) throw new Error('timeout'); return f(); }; |
