From 5100252ea53af546c654ab0109f91183b8b4695e Mon Sep 17 00:00:00 2001 From: Overtorment Date: Thu, 27 Dec 2018 00:44:13 +0000 Subject: [PATCH] FIX: internal invoice wasnt saving record in senders tx list --- class/User.js | 16 ++++++++++++---- controllers/api.js | 9 ++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/class/User.js b/class/User.js index 5013235..ab46c82 100644 --- a/class/User.js +++ b/class/User.js @@ -230,10 +230,18 @@ export class User { for (let invoice of range) { invoice = JSON.parse(invoice); invoice.type = 'paid_invoice'; - invoice.fee = +invoice.payment_route.total_fees; - invoice.value = +invoice.payment_route.total_fees + +invoice.payment_route.total_amt; - invoice.timestamp = invoice.decoded.timestamp; - invoice.memo = invoice.decoded.description; + + // for internal invoices it might not have properties `payment_route` and `decoded`... + if (invoice.payment_route) { + invoice.fee = +invoice.payment_route.total_fees; + invoice.value = +invoice.payment_route.total_fees + +invoice.payment_route.total_amt; + } else { + invoice.fee = 0; + } + if (invoice.decoded) { + invoice.timestamp = invoice.decoded.timestamp; + invoice.memo = invoice.decoded.description; + } result.push(invoice); } diff --git a/controllers/api.js b/controllers/api.js index bc4c0fc..06725c8 100644 --- a/controllers/api.js +++ b/controllers/api.js @@ -130,8 +130,15 @@ router.post('/payinvoice', async function(req, res) { // sender spent his balance: userBalance -= info.num_satoshis * 1; await u.saveBalance(userBalance); + await u.savePaidLndInvoice({ + timestamp: parseInt(+new Date() / 1000), + type: 'paid_invoice', + value: info.num_satoshis * 1, + fee: 0, // internal invoices are free + memo: decodeURIComponent(info.description), + }); - await u.setPaymentHashPaid(info.payment_hash); + await UserPayee.setPaymentHashPaid(info.payment_hash); return res.send(info); }