From 6803575cb3fcbe1bb92a6c40b9e810a294f5d657 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 16 Jun 2026 00:00:34 -0700 Subject: Advance fresh address instantly on WS deposit The pending balance showed immediately from the WS ingest, but the next receive address/QR only appeared after the debounced refreshLive. Now the WS ingest marks the receiving address used and advances the fresh index right away, so the new address shows in the same update as the balance. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/wallet.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/wallet.js b/src/wallet.js index b266283..c57149f 100644 --- a/src/wallet.js +++ b/src/wallet.js @@ -697,12 +697,27 @@ export class Wallet { const confirmed = !!(tx.status && tx.status.confirmed); this.utxos.push({ txid: tx.txid, vout: i, value: vo.value, address: a, chain: p.chain, index: p.index, confirmed }); have.add(id); - if (confirmed) this.confirmed += vo.value; - else this.pending += vo.value; + // Mark the receiving address used + record its balance, so the fresh + // index advances immediately (next address/QR shows right away). + const arr = p.chain === 0 ? this.receive : this.change; + let entry = arr.find((e) => e.index === p.index); + if (!entry) { + entry = { chain: p.chain, index: p.index, address: a, used: false, confirmed: 0, pending: 0 }; + arr.push(entry); + } + entry.used = true; + if (confirmed) entry.confirmed = (entry.confirmed || 0) + vo.value; + else entry.pending = (entry.pending || 0) + vo.value; changed = true; }); } - if (changed) this.emit(); + if (changed) { + this.nextReceiveIndex = firstUnused(this.receive); + this.nextChangeIndex = firstUnused(this.change); + this._recomputeBalanceFromChains(); + this.retrack(); // start watching the new fresh address + this.emit(); + } return changed; } -- cgit v1.2.3