aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-02-13 23:47:16 -0800
committerAdam Soltys <[email protected]>2026-02-13 23:47:16 -0800
commit193905fb8d3f5638cc865ef29784db9ebe206710 (patch)
treed2ec611839aafb99e1d11d7fa33bd82aeaae2750 /src/routes
parent8eb6cfb222c6c438374421b4e3918372a66e28b5 (diff)
downloadcoinos-ui-193905fb8d3f5638cc865ef29784db9ebe206710.tar.gz
coinos-ui-193905fb8d3f5638cc865ef29784db9ebe206710.zip
ark payment notifications
Diffstat (limited to 'src/routes')
-rw-r--r--src/routes/(app)/+layout.svelte38
1 files changed, 25 insertions, 13 deletions
diff --git a/src/routes/(app)/+layout.svelte b/src/routes/(app)/+layout.svelte
index eb4ec6b6..2c96fc7c 100644
--- a/src/routes/(app)/+layout.svelte
+++ b/src/routes/(app)/+layout.svelte
@@ -1,5 +1,5 @@
<script lang="ts">
- import { getWallet, syncTransactions, settle, arkkey } from "$lib/ark";
+ import { getWallet, syncTransactions, settle, arkkey, arkaid } from "$lib/ark";
import { SvelteToast } from "@zerodevx/svelte-toast";
import { onDestroy, onMount } from "svelte";
import { close, connect, send, socket } from "$lib/socket";
@@ -47,6 +47,7 @@
preloadData(`/${user.username}/receive`);
preloadData("/payments");
preloadData("/send");
+ if ($arkkey) arkSync();
}
});
@@ -57,7 +58,7 @@
arkSyncing = true;
try {
- const aid = getCookie("aid") || user.id;
+ const aid = $arkaid || getCookie("aid") || user.id;
const result = await syncTransactions(aid);
if (result?.received > 0) {
@@ -68,7 +69,7 @@
}
}
- if (result?.synced) invalidate("app:payments");
+ invalidate("app:payments");
} catch (e) {
console.error("Ark sync failed:", e);
} finally {
@@ -76,6 +77,26 @@
}
};
+ let arkInitializedKey: string | undefined;
+
+ const initArk = async () => {
+ const key = $arkkey;
+ if (!key || arkInitializedKey === key) return;
+ arkInitializedKey = key;
+
+ const wallet = await getWallet();
+ if (wallet) {
+ localStorage.setItem("arkkey:uid", user.id);
+ wallet.notifyIncomingFunds(arkSync);
+ arkSync();
+ settle().catch((e) => console.error("Ark settle failed:", e));
+ }
+ };
+
+ $effect(() => {
+ if (browser && user && $arkkey) initArk();
+ });
+
onMount(async () => {
if (browser) {
checkSocket();
@@ -85,18 +106,9 @@
const storedUid = localStorage.getItem("arkkey:uid");
if (storedUid && storedUid !== user.id) {
$arkkey = "";
+ $arkaid = "";
localStorage.removeItem("arkkey:uid");
}
-
- const wallet = await getWallet();
- if (wallet) {
- localStorage.setItem("arkkey:uid", user.id);
- wallet.notifyIncomingFunds(arkSync);
-
- arkSync();
-
- settle().catch((e) => console.error("Ark settle failed:", e));
- }
}
// if (window.NDEFReader) {