aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2025-06-23 08:48:52 -0700
committerAdam Soltys <[email protected]>2025-06-23 08:50:12 -0700
commit6aa385b4bcfe5a97bbf21263126f61adcd3bc606 (patch)
tree68a65dc4c92e8df1823dcba7047d9680546f9678 /routes
parente92f232d7194626d9182a5eaeff3d42d67fbb53f (diff)
downloadcoinos-server-6aa385b4bcfe5a97bbf21263126f61adcd3bc606.tar.gz
coinos-server-6aa385b4bcfe5a97bbf21263126f61adcd3bc606.zip
mark self-generated invoices
Diffstat (limited to 'routes')
-rw-r--r--routes/invoices.ts7
-rw-r--r--routes/lnurl.ts16
2 files changed, 17 insertions, 6 deletions
diff --git a/routes/invoices.ts b/routes/invoices.ts
index 0881c69f..ecac713c 100644
--- a/routes/invoices.ts
+++ b/routes/invoices.ts
@@ -24,11 +24,14 @@ export default {
async create(req, res) {
let { body, user } = req;
- if (body.user) user = body.user;
const { invoice } = body;
+ if (body.user) user = body.user;
+ if (req.user.username === user.username) invoice.own = true;
+
try {
- res.send(await generate({ invoice, user }));
+ const result = await generate({ invoice, user });
+ res.send(result);
} catch (e) {
err(
"problem generating invoice",
diff --git a/routes/lnurl.ts b/routes/lnurl.ts
index e5b3e60c..18785164 100644
--- a/routes/lnurl.ts
+++ b/routes/lnurl.ts
@@ -46,7 +46,8 @@ export default {
bech32.fromWords(bech32.decode(text, 20000).words),
).toString();
- res.send(await got(url).json());
+ const r = await got(url).json();
+ res.send(r);
} catch (e) {
bail(res, e.message);
}
@@ -156,11 +157,18 @@ export default {
try {
const user = await getUser(username);
const iid = await db.lIndex(`${user.id}:invoices`, 0);
- const invoice = await getInvoice(iid);
+ let invoice = await getInvoice(iid);
const fiveMinutes = 1000 * 60 * 5;
const paid = invoice.received >= invoice.amount;
const expired = Date.now() - invoice.created > fiveMinutes;
- if (paid || expired) fail("No active invoice");
+ if (paid || expired || !invoice.own) {
+ invoice = await generate({
+ invoice: {
+ type: PaymentType.lightning,
+ },
+ user,
+ });
+ }
const { id: uid } = user;
@@ -175,7 +183,7 @@ export default {
res.send({
allowsNostr: true,
minSendable: invoice.amount * 1000,
- maxSendable: invoice.amount * 1000,
+ maxSendable: invoice.amount ? invoice.amount * 1000 : undefined,
metadata,
nostrPubkey: serverPubkey,
commentAllowed: 512,