aboutsummaryrefslogtreecommitdiffstats
path: root/src/sw-nwc.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/sw-nwc.js')
-rw-r--r--src/sw-nwc.js11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/sw-nwc.js b/src/sw-nwc.js
index ddcdbb5..3dac246 100644
--- a/src/sw-nwc.js
+++ b/src/sw-nwc.js
@@ -4,7 +4,7 @@
// nwc-respond.js), and only falls back to the wake-the-user notification
// when it can't.
-import { respondFromBg } from './nwc-respond.js';
+import { respondFromBg, tendRenewals } from './nwc-respond.js';
import { withRequestLock } from './nwc-lock.js';
import { bgAutoWithdraw } from './bg-autowithdraw.js';
import { allInboxes, classifyDm, shouldNotifyDm } from './dm-inbox.js';
@@ -70,6 +70,7 @@ self.addEventListener('push', (e) => {
return;
}
if (data.type !== 'nwc') return;
+ const startedAt = Date.now();
e.waitUntil((async () => {
// An open window handles requests itself with full wallet state — nudge
// it and stay out of the way.
@@ -78,6 +79,11 @@ self.addEventListener('push', (e) => {
for (const c of clients) c.postMessage({ type: 'nwc-wake', servicePubkey: data.servicePubkey });
return;
}
+ // A wake is the only moment a closed wallet gets to look after its coins:
+ // claim renewals whose round has run, cover coins without one. After the
+ // answer, inside what is left of the push budget.
+ const tend = () => tendRenewals({ deadline: startedAt + 27_000, log: (m) => console.log('[sw-renew]', m) })
+ .catch((err) => console.warn('[sw-renew] failed:', err && err.message));
// 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;
@@ -97,9 +103,10 @@ self.addEventListener('push', (e) => {
tag: handled.notify.tag || 'nwc-incoming', renotify: true,
data: { url: './' },
});
+ await tend();
return;
}
- if (handled) return;
+ if (handled) { await tend(); return; }
// A kind-21001 offer request is money coming IN (someone asking us to
// mint an invoice) — "an app wants to pay" would read as the opposite.
const incoming = data.event && data.event.kind === 21001;