aboutsummaryrefslogtreecommitdiffstats
path: root/src
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
parent8eb6cfb222c6c438374421b4e3918372a66e28b5 (diff)
downloadcoinos-ui-193905fb8d3f5638cc865ef29784db9ebe206710.tar.gz
coinos-ui-193905fb8d3f5638cc865ef29784db9ebe206710.zip
ark payment notifications
Diffstat (limited to 'src')
-rw-r--r--src/components/Account.svelte4
-rw-r--r--src/lib/ark.ts1
-rw-r--r--src/routes/(app)/+layout.svelte38
3 files changed, 29 insertions, 14 deletions
diff --git a/src/components/Account.svelte b/src/components/Account.svelte
index d588932a..b077c30b 100644
--- a/src/components/Account.svelte
+++ b/src/components/Account.svelte
@@ -9,7 +9,7 @@
import { t } from "$lib/translations";
import { versions, s, f, loc, toFiat } from "$lib/utils";
import { fiat } from "$lib/store";
- import { arkkey } from "$lib/ark";
+ import { arkkey, arkaid } from "$lib/ark";
import { getRememberedWalletPassword, forgetWalletPassword } from "$lib/passwordCache";
let { user, rates, account }: any = $props();
@@ -51,6 +51,7 @@
} else {
return false;
}
+ $arkaid = id;
return true;
} catch (e) {
forgetWalletPassword();
@@ -94,6 +95,7 @@
let arkChild = master.derive("m/86'/0'/0'/0/0");
$arkkey = bytesToHex(arkChild.privateKey!);
}
+ $arkaid = id;
passwordPrompt = false;
if (pendingUrl) {
goto(pendingUrl);
diff --git a/src/lib/ark.ts b/src/lib/ark.ts
index 61668c3a..b9902a5a 100644
--- a/src/lib/ark.ts
+++ b/src/lib/ark.ts
@@ -8,6 +8,7 @@ export const arkServerUrl = {
regtest: "http://localhost:7070",
}[PUBLIC_COINOS_NETWORK || "regtest"];
export const arkkey = persistLocal("arkkey", "");
+export const arkaid = persistLocal("arkaid", "");
let arkSdkPromise: Promise<typeof import("@arkade-os/sdk")> | undefined;
const loadArkSdk = () => (arkSdkPromise ||= import("@arkade-os/sdk"));
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) {