From 6394de43d4e596aaeddd2b262bb7a595679d8fbc Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 14 Sep 2026 08:53:35 -0700 Subject: A zap answered by two tabs no longer reports as failed. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every open tab of the same wallet sees every wallet-connect request. Two hidden tabs on one laptop both tried to pay the same zap: the ASP refused the second with "payment already in progress", and that error reached Amethyst half a second before the first tab's preimage. A Web Lock per request now lets one tab (or the worker) answer while the rest stay quiet, and a device that does meet "already in progress" waits for the sibling payment's outcome — relaying its preimage only if the payer never speaks — instead of shouting a failure over sats that went through. The losing side also stops writing a failed row into history for it. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01QYJfZ4A1TDCEY4Foq3CApR --- src/nwc-respond.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/nwc-respond.js') diff --git a/src/nwc-respond.js b/src/nwc-respond.js index 532b13e..9fdfcff 100644 --- a/src/nwc-respond.js +++ b/src/nwc-respond.js @@ -293,6 +293,19 @@ export async function respondFromBg(data, { } break; } + if (a && a.step === 'failed' && /already in progress/i.test(a.error || '')) { + // Another device of this wallet started this same payment first. Its + // outcome is ours: wait on it, and only speak if the payer stays quiet. + log('a sibling device is paying this invoice — waiting on its outcome'); + const out = await mgr.lnOutcome(dec.paymentHash, Math.max(3000, deadline - Date.now())); + if (out.status === 'failed') return failQuietly(a.error); + if (out.status !== 'success') { log('sibling payment still pending — leaving it to them'); return true; } + await new Promise((r) => setTimeout(r, errGraceMs)); + if (!(await answered())) { + await publish({ result_type: 'pay_invoice', result: { preimage: out.preimage, fees_paid: 0 } }); + } + return true; + } if (!a || a.step === 'failed') { return failQuietly((a && a.error) || 'payment failed'); } -- cgit v1.2.3