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/sw-nwc.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/sw-nwc.js') diff --git a/src/sw-nwc.js b/src/sw-nwc.js index 2566a5c..a166368 100644 --- a/src/sw-nwc.js +++ b/src/sw-nwc.js @@ -5,6 +5,7 @@ // when it can't. import { respondFromBg } from './nwc-respond.js'; +import { withRequestLock } from './nwc-lock.js'; import { bgAutoWithdraw } from './bg-autowithdraw.js'; import { allInboxes, classifyDm, shouldNotifyDm } from './dm-inbox.js'; @@ -67,10 +68,9 @@ self.addEventListener('push', (e) => { setTimeout(() => { bgAutoWithdraw({ log: (m) => console.log('[sw-aw]', m) }).catch(() => {}); }, 0); let handled = false; try { - handled = await respondFromBg(data, { - notifier: NOTIFIER, - log: (m) => console.log('[sw-nwc]', m), - }); + handled = await withRequestLock(data.event && data.event.id, + () => respondFromBg(data, { notifier: NOTIFIER, log: (m) => console.log('[sw-nwc]', m) }), + () => { console.log('[sw-nwc] another context holds this request'); return true; }); } catch (err) { console.warn('[sw-nwc] auto-answer failed:', err && err.message); } -- cgit v1.2.3