diff options
| author | Adam Soltys <[email protected]> | 2026-08-03 14:02:25 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-08-03 14:02:25 -0700 |
| commit | cdd34e88be8a58c1cc9fa3d0cfbbd02b23439629 (patch) | |
| tree | eca597b57765aa6adbfbbe36dffb00087713b413 /src/sw-nwc.js | |
| parent | da13a93a3852eb15156a5a84a73a8200d1344685 (diff) | |
| download | coinosv3-cdd34e88be8a58c1cc9fa3d0cfbbd02b23439629.tar.gz coinosv3-cdd34e88be8a58c1cc9fa3d0cfbbd02b23439629.zip | |
Auto-withdraw runs with the app closed; fix the dead Back on the legacy step
The service worker can't watch a relay, so it doesn't try: the app
resolves the destination to something concrete (ark address, LNURL
endpoint, or on-chain script) and mirrors it beside the keys the
background NWC payer already uses. On a push wake-up — which is exactly
when money has just landed — the worker re-checks the same gate and
sends, writing the outcome back into the mirror for the app to absorb on
next open. A partial on-chain forward still waits for the app, since
carving an exact vtxo needs more round trips than a worker is promised.
writeBgMirror now carries forward the NWC connections and offer when
another caller refreshes the mirror, instead of blanking them.
And onboarding's legacy step loses its Back: the wallet exists by then,
so returning to the nostr question just bounced straight forward again
and the link looked broken. Its copy no longer promises a rename either.
Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Wvj4aoeMZwA7VUGdJP9Swi
Diffstat (limited to 'src/sw-nwc.js')
| -rw-r--r-- | src/sw-nwc.js | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/sw-nwc.js b/src/sw-nwc.js index 0fdc4d7..e887963 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 { bgAutoWithdraw } from './bg-autowithdraw.js'; const NOTIFIER = 'https://nwcpush.coinos.io'; @@ -17,6 +18,13 @@ self.addEventListener('push', (e) => { e.waitUntil((async () => { const clients = await self.clients.matchAll({ type: 'window', includeUncontrolled: true }); if (clients.some((c) => c.visibilityState === 'visible')) return; + // Money landing is exactly when a forwarding rule wants to run, and this + // wake-up is the only moment the worker gets. Failures are recorded in + // the mirror; the notification still goes out either way. + if (data.reason === 'payment') { + try { await bgAutoWithdraw({ log: (m) => console.log('[sw-aw]', m) }); } + catch (err) { console.warn('[sw-aw] failed:', err && err.message); } + } const T = { payment: ['Payment received', data.amountSat ? `+${Number(data.amountSat).toLocaleString()} sats — open coinos to see it.` : 'Open coinos to see it.'], dm: ['New message', 'You have a new private message.'], @@ -41,6 +49,8 @@ self.addEventListener('push', (e) => { for (const c of clients) c.postMessage({ type: 'nwc-wake', servicePubkey: data.servicePubkey }); return; } + // an NWC wake-up may also have moved money in; check the rule after + setTimeout(() => { bgAutoWithdraw({ log: (m) => console.log('[sw-aw]', m) }).catch(() => {}); }, 0); let handled = false; try { handled = await respondFromBg(data, { |
