From 2e508845545c4b56e96289adf0b7706b572bb182 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 10 Feb 2025 00:05:19 -0800 Subject: budget --- routes/users.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'routes') diff --git a/routes/users.ts b/routes/users.ts index ddadec5f..e6e11741 100644 --- a/routes/users.ts +++ b/routes/users.ts @@ -843,8 +843,16 @@ export default { if (a.secret) a.nwc = `nostr+walletconnect://${serverPubkey}?relay=${relay}&secret=${a.secret}&lud16=${lud16}`; - a.spent = (await db.lRange(`${a.pubkey}:payments`, 0, -1)).reduce( - (a, b) => a + (Math.abs(b.amount) + b.fee + b.ourfee), + const pids = await db.lRange(`${a.pubkey}:payments`, 0, -1); + const payments = await Promise.all( + pids.map((pid) => g(`payment:${pid}`)), + ); + a.spent = payments.reduce( + (a, b) => + a + + (Math.abs(parseInt(b.amount || 0)) + + parseInt(b.fee || 0) + + parseInt(b.ourfee || 0)), 0, ); }), -- cgit v1.2.3