diff options
| author | Adam Soltys <[email protected]> | 2026-02-16 22:48:48 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-02-16 22:48:48 -0800 |
| commit | 6a607d98d4368d6d171a40fad83f65167198f4c5 (patch) | |
| tree | 7e6ff20868a10a48aa50e2a8544f964d0d8ccedf /src/routes/(app)/+layout.svelte | |
| parent | d0784c34787e6d96f0131af2e12079e7915b2f57 (diff) | |
| download | coinos-ui-6a607d98d4368d6d171a40fad83f65167198f4c5.tar.gz coinos-ui-6a607d98d4368d6d171a40fad83f65167198f4c5.zip | |
ark notifications
Diffstat (limited to 'src/routes/(app)/+layout.svelte')
| -rw-r--r-- | src/routes/(app)/+layout.svelte | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/routes/(app)/+layout.svelte b/src/routes/(app)/+layout.svelte index 8cd580e2..0c88ff19 100644 --- a/src/routes/(app)/+layout.svelte +++ b/src/routes/(app)/+layout.svelte @@ -11,6 +11,7 @@ passwordPrompt, selectSigner, password, + paymentSignal, pin, theme as themeStore, fiat, @@ -48,20 +49,25 @@ preloadData(`/${user.username}/receive`); preloadData("/payments"); preloadData("/send"); - if ($arkkey) arkSync(); + if ($arkkey) arkSync("afterNavigate"); } }); let arkSyncing = false; let arkForwarding = false; - let arkSync = async () => { - if (arkSyncing || arkSending) return; + let arkSync = async (source = "unknown") => { + if (arkSyncing || arkSending) { + console.log(`[arkSync] SKIPPED (source: ${source}, syncing: ${arkSyncing}, sending: ${arkSending})`); + return; + } + console.log(`[arkSync] START (source: ${source})`); arkSyncing = true; try { const aid = $arkaid || getCookie("aid") || user.id; const result = await syncTransactions(aid); + console.log(`[arkSync] DONE (source: ${source}, received: ${result?.received || 0})`); if (result?.forward && !arkForwarding) { arkForwarding = true; @@ -96,7 +102,6 @@ let arkInitializedKey: string | undefined; let arkRefreshTimer: ReturnType<typeof setInterval> | undefined; - let arkSyncTimer: ReturnType<typeof setInterval> | undefined; const initArk = async () => { const key = $arkkey; @@ -106,15 +111,11 @@ const wallet = await getWallet(); if (wallet) { localStorage.setItem("arkkey:uid", user.id); - wallet.notifyIncomingFunds(arkSync); - arkSync(); + wallet.notifyIncomingFunds(() => arkSync("notifyIncomingFunds")); + arkSync("initArk"); refresh().catch((e) => console.error("Ark refresh failed:", e)); settle().catch((e) => console.error("Ark settle failed:", e)); - // Poll for incoming ark transactions (fallback for SSE) - if (arkSyncTimer) clearInterval(arkSyncTimer); - arkSyncTimer = setInterval(() => arkSync(), 15_000); - // Periodically recover expired VTXOs if (arkRefreshTimer) clearInterval(arkRefreshTimer); arkRefreshTimer = setInterval(() => { @@ -127,6 +128,10 @@ if (browser && user && $arkkey) initArk(); }); + $effect(() => { + if ($paymentSignal && $arkkey) arkSync("paymentSignal"); + }); + onMount(async () => { if (browser) { @@ -194,7 +199,6 @@ if (browser) { close(); clearTimeout(checkTimer); - if (arkSyncTimer) clearInterval(arkSyncTimer); if (arkRefreshTimer) clearInterval(arkRefreshTimer); } }); |
