From ed4d86167d32503ad8813c81dda9591d1b1b8190 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 5 Feb 2026 11:13:16 -0800 Subject: fix ark handling --- src/lib/ark.ts | 6 ++++++ src/lib/store.ts | 29 ++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) (limited to 'src/lib') diff --git a/src/lib/ark.ts b/src/lib/ark.ts index 7b289d8a..26c16a93 100644 --- a/src/lib/ark.ts +++ b/src/lib/ark.ts @@ -30,6 +30,12 @@ export const getBalance = async (): Promise<{ available: number }> => { return wallet.getBalance(); }; +export const getVtxos = async () => { + const wallet = await getWallet(); + if (!wallet) return []; + return wallet.getVtxos({ spendableOnly: false }); +}; + export const syncTransactions = async (aid: string) => { const wallet = await getWallet(); if (!wallet) return; diff --git a/src/lib/store.ts b/src/lib/store.ts index 0148f480..7cd17aec 100644 --- a/src/lib/store.ts +++ b/src/lib/store.ts @@ -44,13 +44,40 @@ export const persistLocal = (key, defaultValue: any = undefined) => { return s; }; +export const persistLocalValue = (key, defaultValue: any = undefined) => { + const s = writable( + browser && + localStorage.getItem(key) && + localStorage.getItem(key) !== "undefined" + ? JSON.parse(localStorage.getItem(key) || "") + : defaultValue, + ); + + s.subscribe((v) => { + try { + if (browser) { + if (v === undefined) { + localStorage.removeItem(key); + } else { + localStorage.setItem(key, JSON.stringify(v)); + } + } + } catch (e) { + console.log("problem setting key", v); + console.log(e); + } + }); + + return s; +}; + export const account = writable(); export const amountPrompt = persistLocal("amountPrompt"); export const avatar = writable(); export const banner = writable(); export const event = writable(); export const events = writable({}); -export const fiat = persistLocal("fiat", true); +export const fiat = persistLocalValue("fiat", true); export const installPrompt = writable(); export const invoice = writable(); export const last = writable(); -- cgit v1.2.3