diff options
| author | Adam Soltys <[email protected]> | 2026-06-30 09:29:46 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-06-30 09:29:46 -0700 |
| commit | 6d649f9bdd0582520e23dff4b5a967f0a125857e (patch) | |
| tree | e8312ef64fc95a30144b50bbb563829eba6bc26b /src/wallet.js | |
| parent | c74a3181a415024eea016727a11a1fc59335697d (diff) | |
| download | coinosv3-6d649f9bdd0582520e23dff4b5a967f0a125857e.tar.gz coinosv3-6d649f9bdd0582520e23dff4b5a967f0a125857e.zip | |
Swaps: reuse the generic 'Payment received' screen for LN receives
A reverse-swap claim is an on-chain receive, so instead of a separate LN
'Received!' card (which stacked with the generic celebration and needed
suppression), credit the claimed coin to the wallet the instant we broadcast the
claim — new wallet.creditReceive() mirrors the instant-payment watcher path
(adds the utxo + pending row, advances the receive index, emits). The generic
'Payment received!' then fires immediately with the right amount, one screen, one
tap. Dropped the LN success card + the suppression logic.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Diffstat (limited to 'src/wallet.js')
| -rw-r--r-- | src/wallet.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/wallet.js b/src/wallet.js index 596ca1b..1972f22 100644 --- a/src/wallet.js +++ b/src/wallet.js @@ -1922,6 +1922,36 @@ export class Wallet { return true; } + // Credit an on-chain receive we produced ourselves (a reverse-swap claim) the + // instant we broadcast it — so the balance + generic "payment received" fire + // without waiting for the next scan, exactly like the watcher does for inbound + // payments. `address` must be one of our receive (chain-0) addresses; returns + // false (caller relies on the scan) if it isn't known or the coin already exists. + creditReceive({ txid, vout, value, address }) { + let entry = this.receive.find((e) => e.address === address); + if (!entry) { + const info = this.addrMap.get(address); + if (info && info.chain === 0) entry = this.receive.find((e) => e.index === info.index); + } + if (!entry) return false; + if (this.utxos.find((u) => utxoId(u) === `${txid}:${vout}`)) return false; + this.utxos.push({ txid, vout, value, address, chain: 0, index: entry.index, confirmed: false }); + entry.used = true; + entry.pending = (entry.pending || 0) + value; + if (!this.txs.find((t) => t.txid === txid)) { + this.txs.push({ txid, net: value, fee: 0, vsize: 0, confirmed: false, blockTime: 0, blockHeight: 0, firstSeen: Date.now() }); + } + this.nextReceiveIndex = firstUnused(this.receive); + this.utxos.sort((a, b) => b.value - a.value); + this._sortTxs(); + this._recomputeBalanceFromUtxos(); + this.loaded = true; + this.saveCache(); + this.retrack(); + this.emit(); + return true; + } + // Optimistically reflect a just-broadcast outgoing tx so the balance and // history update instantly instead of waiting for the post-send rescan: drop // the spent coins, credit our change as pending, and add a pending history |
