diff --git a/apps/desktop/src/lib/states/monero-wallet.svelte.ts b/apps/desktop/src/lib/states/monero-wallet.svelte.ts index 8a09588..6fc312b 100644 --- a/apps/desktop/src/lib/states/monero-wallet.svelte.ts +++ b/apps/desktop/src/lib/states/monero-wallet.svelte.ts @@ -56,6 +56,8 @@ export const MoneroWallet = () => { let refreshInFlight: Promise | null = null let syncing = $state(false) let syncRetryTimer: ReturnType | null = null + let price = $state(null) + let priceInFlight = false const rpcTimeout = (promise: Promise, ms: number, label: string): Promise => new Promise((resolve, reject) => { @@ -478,6 +480,18 @@ export const MoneroWallet = () => { return refreshInFlight } + const fetchPrice = async () => { + const rpc = electrobun.rpc + if (!rpc || priceInFlight) return + priceInFlight = true + try { + const [p] = await tryCatch(rpc.request.fetchMoneroPrice({})) + if (p) price = p.usd + } finally { + priceInFlight = false + } + } + const send = async ( address: string, amountAtomic: string, @@ -597,6 +611,9 @@ export const MoneroWallet = () => { get syncing() { return syncing }, + get price() { + return price + }, get error() { return error }, @@ -646,6 +663,7 @@ export const MoneroWallet = () => { autoUnlock, unlockWallet, refresh, + fetchPrice, send, sendAll, createAccount, diff --git a/apps/desktop/src/lib/states/xrp-wallet.svelte.ts b/apps/desktop/src/lib/states/xrp-wallet.svelte.ts index 60bcf71..3595094 100644 --- a/apps/desktop/src/lib/states/xrp-wallet.svelte.ts +++ b/apps/desktop/src/lib/states/xrp-wallet.svelte.ts @@ -29,6 +29,9 @@ export const XrpWallet = () => { let loading = $state(false) let error = $state('') let wallets = $state([]) + let balances = $state>({}) + let balancesLoading = $state(false) + let fetchBalancesInFlight = false let currentWalletId = $state(null) let currentPasswordHash = $state(null) @@ -319,6 +322,34 @@ export const XrpWallet = () => { })() } + const fetchBalances = async () => { + const rpc = electrobun.rpc + if (!rpc || fetchBalancesInFlight) return + if (wallets.length === 0) return + fetchBalancesInFlight = true + balancesLoading = true + try { + const [p] = await tryCatch(rpc.request.fetchXrpPrice({})) + if (p) price = p.usd + await Promise.allSettled( + wallets.map(async (w) => { + const [res] = await tryCatch( + rpc.request.xrpGetBalance({ address: w.address }), + ) + if (res) { + balances[w.address] = { + balance: parseFloat(res.balance), + funded: res.funded, + } + } + }), + ) + } finally { + balancesLoading = false + fetchBalancesInFlight = false + } + } + const send = async ( to: string, amount: string, @@ -399,6 +430,12 @@ export const XrpWallet = () => { get wallets() { return wallets }, + get balances() { + return balances + }, + get balancesLoading() { + return balancesLoading + }, get currentWalletId() { return currentWalletId }, @@ -424,6 +461,7 @@ export const XrpWallet = () => { login, logout, refresh, + fetchBalances, createWallet, importWallet, lock, diff --git a/apps/desktop/src/routes/index.svelte b/apps/desktop/src/routes/index.svelte index 090a052..c0d90c7 100644 --- a/apps/desktop/src/routes/index.svelte +++ b/apps/desktop/src/routes/index.svelte @@ -1,7 +1,6 @@