From eb3c2aad4cef9b86294bc9a13a36da4918529209 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 11 Feb 2025 20:07:21 -0800 Subject: nwc notifications --- lib/nwc.ts | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'lib/nwc.ts') diff --git a/lib/nwc.ts b/lib/nwc.ts index 3f346b87..a902b0a6 100644 --- a/lib/nwc.ts +++ b/lib/nwc.ts @@ -22,6 +22,7 @@ const methods = [ "make_invoice", "lookup_invoice", "list_transactions", + "notifications", ]; const week = 7 * 24 * 60 * 60; @@ -31,14 +32,19 @@ export default () => { r.on("open", async (_) => { r.subscribe("nwc", { kinds: [23194], "#p": [serverPubkey] }); - let info: UnsignedEvent = { - created_at: Math.floor(Date.now() / 1000), - kind: 13194, - tags: [["p", serverPubkey]], - pubkey: serverPubkey, - content: methods.join(" "), - }; - info = await finalizeEvent(info, sk); + const info = await finalizeEvent( + { + created_at: Math.floor(Date.now() / 1000), + kind: 13194, + tags: [ + ["p", serverPubkey], + ["notifications", "payment_received payment_sent"], + ], + pubkey: serverPubkey, + content: methods.join(" "), + }, + sk, + ); r.send(["EVENT", info]); }); @@ -314,9 +320,7 @@ const handle = (method, params, ev, app, user) => async list_transactions() { const { from, until, limit = 10, offset = 0, type } = params; - const { pubkey } = app; - const k = pubkey === user.pubkey ? user.id : pubkey; - const payments = await db.lRange(`${k}:payments`, 0, -1); + const payments = await db.lRange(`${user.id}:payments`, 0, -1); let transactions = []; for (const pid of payments) { -- cgit v1.2.3