diff --git a/apps/desktop/src/lib/states/monero-wallet.svelte.ts b/apps/desktop/src/lib/states/monero-wallet.svelte.ts index 269a9cc..2b744a1 100644 --- a/apps/desktop/src/lib/states/monero-wallet.svelte.ts +++ b/apps/desktop/src/lib/states/monero-wallet.svelte.ts @@ -56,6 +56,7 @@ export const createMoneroWallet = () => { let refreshInFlight: Promise | null = null let syncing = $state(false) let syncRetryTimer: ReturnType | null = null + let autoRefreshTimer: ReturnType | null = null let price = $state(null) let priceInFlight = false @@ -408,6 +409,31 @@ export const createMoneroWallet = () => { }, 15000) } + const stopAutoRefresh = () => { + if (autoRefreshTimer) { + clearInterval(autoRefreshTimer) + autoRefreshTimer = null + } + } + + // Refresh runs in the store so the dashboard's connection/sync state + // stays live regardless of which page is mounted. + const startAutoRefresh = () => { + if (autoRefreshTimer || !walletOpen) return + autoRefreshTimer = setInterval(() => { + if (walletOpen && !loading) refresh() + }, 30000) + } + + // $effect needs a root outside a component; the root lives for the + // lifetime of the singleton store. + $effect.root(() => { + $effect(() => { + if (walletOpen && !loading) startAutoRefresh() + else if (!walletOpen) stopAutoRefresh() + }) + }) + const refresh = async () => { const rpc = electrobun.rpc if (!rpc) return diff --git a/apps/desktop/src/routes/index.svelte b/apps/desktop/src/routes/index.svelte index 4c4abd7..90aba9c 100644 --- a/apps/desktop/src/routes/index.svelte +++ b/apps/desktop/src/routes/index.svelte @@ -47,6 +47,16 @@ const hasXmr = $derived(moneroWallet.wallets.length > 0) const noWallets = $derived(!hasXrp && !hasXmr) + const moneroDot = $derived( + !moneroWallet.running + ? 'bg-muted' + : !moneroWallet.connected + ? 'bg-red-500' + : moneroWallet.syncing || moneroWallet.height < moneroWallet.daemonHeight + ? 'bg-yellow-500 animate-pulse' + : 'bg-emerald-500', + ) + const fmtUsd = (v: number) => v.toLocaleString(undefined, { minimumFractionDigits: 2, @@ -154,9 +164,7 @@ XRP - - {xrpWallet.wallets.length} wallet{xrpWallet.wallets.length !== 1 ? 's' : ''} - + XRP Ledger {#if !xrpWallet.ready || (xrpWallet.wallets.length > 0 && Object.keys(xrpWallet.balances).length === 0)} @@ -185,20 +193,21 @@ Monero - - {moneroWallet.walletOpen - ? moneroWallet.walletName || 'Wallet open' - : moneroWallet.wallets.length > 0 - ? `${moneroWallet.wallets.length} wallet${moneroWallet.wallets.length !== 1 ? 's' : ''}` - : 'Not set up'} + + + {#if !moneroWallet.running} + Server offline + {:else if !moneroWallet.connected} + Connecting to daemon… + {:else} + {fmtBal(moneroWallet.height, 0)} / {fmtBal(moneroWallet.daemonHeight, 0)} + {/if} {#if moneroWallet.walletOpen}

{fmtBal(xmrBalance, 4)}

- {#if moneroWallet.syncing} -

Syncing…

- {:else if moneroWallet.price} + {#if !moneroWallet.syncing && moneroWallet.price}

${fmtUsd(xmrTotalUsd)}

diff --git a/apps/desktop/src/routes/monero/wallet/[name].svelte b/apps/desktop/src/routes/monero/wallet/[name].svelte index e662156..7b7ab0f 100644 --- a/apps/desktop/src/routes/monero/wallet/[name].svelte +++ b/apps/desktop/src/routes/monero/wallet/[name].svelte @@ -154,7 +154,6 @@ $effect(() => { if (w.walletOpen && !autoRefreshTimer) { autoRefreshTimer = setInterval(() => { - w.refresh() electrobun.rpc?.request .fetchMoneroPrice({}) .then((p) => (moneroPrice = p))