diff options
| author | Adam Soltys <[email protected]> | 2026-02-05 09:34:30 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-02-11 15:34:32 -0800 |
| commit | ec304f8bd1ffef69a85b75da033fbccbe6bfc72f (patch) | |
| tree | 664e765f3d7e9c4f26463760ed155dabca76486b /src/routes/(app)/+layout.svelte | |
| parent | 59fbd17aad12acfa19eb730c4ede67d50962ba9b (diff) | |
| download | coinos-ui-ec304f8bd1ffef69a85b75da033fbccbe6bfc72f.tar.gz coinos-ui-ec304f8bd1ffef69a85b75da033fbccbe6bfc72f.zip | |
fix ark payment notifications
Diffstat (limited to 'src/routes/(app)/+layout.svelte')
| -rw-r--r-- | src/routes/(app)/+layout.svelte | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/routes/(app)/+layout.svelte b/src/routes/(app)/+layout.svelte index 3a399c3a..c56a487a 100644 --- a/src/routes/(app)/+layout.svelte +++ b/src/routes/(app)/+layout.svelte @@ -46,10 +46,30 @@ } }); + // Track last known Ark balance to compute incoming amount + let getLastArkBalance = () => { + return parseInt(localStorage.getItem("lastArkBalance") || "0"); + }; + + let setLastArkBalance = (bal) => { + localStorage.setItem("lastArkBalance", bal.toString()); + }; + let handleArkPayment = async (notification) => { console.log("ARK payment notification:", notification); - let amount = notification.newVtxos.reduce((a, b) => a + b.value, 0); - if (!amount) return; + + // Calculate current total from newVtxos + let currentTotal = notification.newVtxos.reduce((a, b) => a + b.value, 0); + let lastBalance = getLastArkBalance(); + + // Compute delta (incoming amount) + let amount = currentTotal - lastBalance; + + // Update tracked balance + setLastArkBalance(currentTotal); + + // Only process positive incoming amounts + if (amount <= 0) return; if ($fiat && $rateStore && user?.currency) { success(`Received ${f(toFiat(amount, $rateStore), user.currency)}!`); @@ -58,12 +78,12 @@ } try { - let inv = await post(`/invoice`, { + let inv = await post(`/post/invoice`, { invoice: { type: "ark", amount }, user, }); - await post(`/ark/receive`, { + await post(`/post/ark/receive`, { amount, iid: inv.id, }); |
