From 59fe8d2e24085239b15ca282c182d5c7cd1ce4de Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 19 Jul 2025 22:55:10 -0700 Subject: respect null tips --- index.ts | 1 + lib/invoices.ts | 2 +- routes/lnurl.ts | 17 +++++++++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/index.ts b/index.ts index b8aaf5dd..c09e26b9 100644 --- a/index.ts +++ b/index.ts @@ -94,6 +94,7 @@ app.get("/lnurl/verify/:id", lnurl.verify); app.get("/lnurlp/:username", lnurl.lnurlp); app.get("/lnurl/:id", lnurl.lnurl); app.get("/pay/:username", lnurl.pay); +app.get("/pay/:username/:amount", lnurl.pay); // app.get("/lnurlw", lnurl.withdraw); app.post("/freeze", payments.freeze); diff --git a/lib/invoices.ts b/lib/invoices.ts index d624ac6b..1e08140a 100644 --- a/lib/invoices.ts +++ b/lib/invoices.ts @@ -35,7 +35,7 @@ export const generate = async ({ invoice, user }) => { } = invoice; amount = parseInt(amount || 0); - tip = parseInt(tip) || null; + tip = tip == null ? null : parseInt(tip); if (user) user = await getUser(user.username); if (!user) fail("user not provided"); diff --git a/routes/lnurl.ts b/routes/lnurl.ts index 4be33ef1..dc51e8fc 100644 --- a/routes/lnurl.ts +++ b/routes/lnurl.ts @@ -160,12 +160,13 @@ export default { }, async pay(req, res) { - const { username } = req.params; + const { amount, username } = req.params; try { const user = await getUser(username); const invoices = await db.lRange(`${user.id}:invoices`, 0, 10); let invoice; + for (const iid of invoices) { const i = await getInvoice(iid); const paid = i.amount > 0 && i.received >= i.amount; @@ -177,9 +178,21 @@ export default { } } - if (!invoice) { + if (invoice) { + if (amount?.startsWith("+")) { + const tip = invoice.amount * amount.split("+")[1]; + invoice = await generate({ + invoice: { + ...invoice, + tip, + }, + user, + }); + } + } else { invoice = await generate({ invoice: { + amount, prompt: user.prompt, type: PaymentType.lightning, }, -- cgit v1.2.3