diff options
| author | Adam Soltys <[email protected]> | 2026-02-02 23:30:20 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-02-11 15:33:09 -0800 |
| commit | e8200be39f7b89efd5379c3c5bc24ca4533bf39c (patch) | |
| tree | 46360ba397abeb8f919411fb8fdee0a0cfb50f0b /src | |
| parent | e8105a9ad2eee8e8c3874851b245c6c755216298 (diff) | |
| download | coinos-ui-e8200be39f7b89efd5379c3c5bc24ca4533bf39c.tar.gz coinos-ui-e8200be39f7b89efd5379c3c5bc24ca4533bf39c.zip | |
sync and settle
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/Payments.svelte | 3 | ||||
| -rw-r--r-- | src/lib/ark.ts | 28 | ||||
| -rw-r--r-- | src/routes/(app)/+layout.svelte | 17 |
3 files changed, 45 insertions, 3 deletions
diff --git a/src/components/Payments.svelte b/src/components/Payments.svelte index 36633089..daedb036 100644 --- a/src/components/Payments.svelte +++ b/src/components/Payments.svelte @@ -101,6 +101,9 @@ alt="Liquid" /> </div> + {:else if p.type === types.ark} + <iconify-icon noobserver icon="ph:vault-bold" width="32" + ></iconify-icon> {/if} <div class="my-auto"> diff --git a/src/lib/ark.ts b/src/lib/ark.ts index 487898ae..05a3963d 100644 --- a/src/lib/ark.ts +++ b/src/lib/ark.ts @@ -1,4 +1,5 @@ import { persistLocal } from "$lib/store"; +import { post } from "$lib/utils"; import { SingleKey, Wallet } from "@arkade-os/sdk"; import { get } from "svelte/store"; @@ -25,3 +26,30 @@ export const getBalance = async (): Promise<{ available: number }> => { const wallet = await getWallet(); return wallet.getBalance(); }; + +export const syncTransactions = async (aid: string) => { + const wallet = await getWallet(); + if (!wallet) return; + + const history = await wallet.getTransactionHistory(); + if (!history.length) return; + + const transactions = history.map((tx) => ({ + hash: tx.key.arkTxid || tx.key.commitmentTxid, + amount: tx.type === "RECEIVED" ? tx.amount : -tx.amount, + settled: tx.settled, + createdAt: tx.createdAt, + })); + + return post("/ark/sync", { transactions, aid }); +}; + +export const settle = async () => { + const wallet = await getWallet(); + if (!wallet) return; + + const balance = await wallet.getBalance(); + if (!balance.preconfirmed) return; + + return wallet.settle(); +}; diff --git a/src/routes/(app)/+layout.svelte b/src/routes/(app)/+layout.svelte index 6624fff8..66596038 100644 --- a/src/routes/(app)/+layout.svelte +++ b/src/routes/(app)/+layout.svelte @@ -1,5 +1,5 @@ <script> - import { getWallet, getAddress } from "$lib/ark"; + import { getWallet, getAddress, syncTransactions, settle } from "$lib/ark"; import { SvelteToast } from "@zerodevx/svelte-toast"; import { onDestroy, onMount } from "svelte"; import { close, connect, send, socket } from "$lib/socket"; @@ -22,7 +22,7 @@ import Password from "$comp/Password.svelte"; import { s, success, post, getCookie, warning } from "$lib/utils"; import { t, locale, loading } from "$lib/translations"; - import { goto, afterNavigate, preloadData } from "$app/navigation"; + import { goto, invalidate, afterNavigate, preloadData } from "$app/navigation"; let { data, children } = $props(); @@ -64,6 +64,8 @@ invalidateAll: true, noScroll: true, }); + + settle().catch((e) => console.error("Ark settle failed:", e)); } catch (e) { console.error("Failed to record ARK payment:", e); } @@ -76,7 +78,16 @@ if (user) { const wallet = await getWallet(); - if (wallet) wallet.notifyIncomingFunds(handleArkPayment); + if (wallet) { + wallet.notifyIncomingFunds(handleArkPayment); + + const aid = getCookie("aid") || user.id; + syncTransactions(aid).then((result) => { + if (result?.synced) invalidate("app:payments"); + }).catch((e) => console.error("Ark sync failed:", e)); + + settle().catch((e) => console.error("Ark settle failed:", e)); + } } // if (window.NDEFReader) { |
