From 1dc0c188d38c9d291375601c25a0533924402359 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 27 Jun 2026 13:49:48 -0700 Subject: Sort pending txs newest-first in History (by firstSeen, not blockTime) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All pending txs share blockTime 0, so _sortTxs's blockTime comparator returned 0 for every pending pair and they kept array (scan/arrival-append) order — so the most recently received tx sat at the bottom of the pending group instead of the top. Order pending txs by firstSeen descending (the timestamp we already record when a tx is first seen unconfirmed); confirmed txs still sort by block time. Also sort on cache restore so the order is right immediately, not only after the first refresh. Co-Authored-By: Claude Opus 4.8 --- src/wallet.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/wallet.js b/src/wallet.js index 7236a9f..46b9f5c 100644 --- a/src/wallet.js +++ b/src/wallet.js @@ -706,6 +706,9 @@ export class Wallet { _sortTxs() { this.txs.sort((a, b) => { if (a.confirmed !== b.confirmed) return a.confirmed ? 1 : -1; // pending first + // Pending txs share blockTime 0, so order them by when we first saw them + // (newest on top); confirmed txs go by block time (newest on top). + if (!a.confirmed) return (b.firstSeen || 0) - (a.firstSeen || 0); return (b.blockTime || 0) - (a.blockTime || 0); }); } @@ -1801,6 +1804,7 @@ export class Wallet { this.change = d.change || []; this.utxos = d.utxos || []; this.txs = d.txs || []; + this._sortTxs(); // a cache saved before the firstSeen-ordering fix may be stale this.nextReceiveIndex = d.nextReceiveIndex || 0; this.nextChangeIndex = d.nextChangeIndex || 0; this.feeRates = d.feeRates || this.feeRates; -- cgit v1.2.3