From bb939f73e4e02b528e346b9f9d909c3a25cfedbb Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 26 Jun 2026 13:57:27 -0700 Subject: Update balance/history optimistically right after a send MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On the Electrum backend the post-send rescan is many round-trips, so the balance lagged a few seconds. Now a successful broadcast immediately applies the tx locally (applySentTx): drop the spent coins, credit change as pending, add a pending history row, recompute the balance, and emit — so the UI reflects the send instantly. The realtime watcher / backstop poll reconciles and fills in the confirmation once the explorer has indexed it (no immediate rescan, so a not-yet-indexed tx can't briefly revert the optimistic state). Verified the balance/utxo/history math. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/app.js') diff --git a/src/app.js b/src/app.js index cba23ba..99343f7 100644 --- a/src/app.js +++ b/src/app.js @@ -2768,12 +2768,12 @@ async function broadcast() { wallet.broadcast(hexTx), new Promise((_, rej) => setTimeout(() => rej(new Error(t('broadcastTimeout'))), 30000)), ]); + wallet.applySentTx(ui.draft.tx); // update balance/history locally, right now ui.sendResult = { txid }; ui.draft = null; ui.send = blankSend(); ui.busy = false; - render(); // show success immediately — don't hold the - wallet.scan().catch(() => {}); // spinner up for the post-send rescan + render(); // the realtime watcher / backstop poll reconciles + confirms later return; } catch (e) { ui.sendError = t('broadcastFailed', { msg: e.message }); -- cgit v1.2.3