FIX: adjusted fees; cache invalidation
This commit is contained in:
parent
7c71c5e775
commit
a74f1e9ff2
@ -12,6 +12,10 @@ export class Paym {
|
||||
this._isPaid = null;
|
||||
}
|
||||
|
||||
get fee() {
|
||||
return 0.003;
|
||||
}
|
||||
|
||||
setInvoice(bolt11) {
|
||||
this._bolt11 = bolt11;
|
||||
}
|
||||
@ -69,7 +73,7 @@ export class Paym {
|
||||
if (payment && payment.payment_route && payment.payment_route.total_amt_msat) {
|
||||
// paid just now
|
||||
this._isPaid = true;
|
||||
payment.payment_route.total_fees = +payment.payment_route.total_fees + Math.floor(+payment.payment_route.total_amt * 0.01);
|
||||
payment.payment_route.total_fees = +payment.payment_route.total_fees + Math.floor(+payment.payment_route.total_amt * Paym.fee);
|
||||
if (this._bolt11) payment.pay_req = this._bolt11;
|
||||
if (this._decoded) payment.decoded = this._decoded;
|
||||
}
|
||||
|
@ -173,7 +173,12 @@ export class User {
|
||||
async saveBalance(balance) {
|
||||
const key = 'balance_for_' + this._userid;
|
||||
await this._redis.set(key, balance);
|
||||
await this._redis.expire(key, 3600 * 24);
|
||||
await this._redis.expire(key, 3600);
|
||||
}
|
||||
|
||||
async clearBalanceCache() {
|
||||
const key = 'balance_for_' + this._userid;
|
||||
return this._redis.del(key);
|
||||
}
|
||||
|
||||
async savePaidLndInvoice(doc) {
|
||||
|
@ -170,7 +170,7 @@ router.post('/payinvoice', async function(req, res) {
|
||||
timestamp: parseInt(+new Date() / 1000),
|
||||
type: 'paid_invoice',
|
||||
value: +info.num_satoshis + Math.floor(info.num_satoshis * 0.01),
|
||||
fee: Math.floor(info.num_satoshis * 0.01),
|
||||
fee: Math.floor(info.num_satoshis * Paym.fee),
|
||||
memo: decodeURIComponent(info.description),
|
||||
});
|
||||
|
||||
@ -189,11 +189,10 @@ router.post('/payinvoice', async function(req, res) {
|
||||
if (payment && payment.payment_route && payment.payment_route.total_amt_msat) {
|
||||
let PaymentShallow = new Paym(false, false, false);
|
||||
payment = PaymentShallow.processSendPaymentResponse(payment);
|
||||
userBalance -= +payment.payment_route.total_fees + +payment.payment_route.total_amt;
|
||||
u.saveBalance(userBalance);
|
||||
payment.pay_req = req.body.invoice;
|
||||
payment.decoded = info;
|
||||
await u.savePaidLndInvoice(payment);
|
||||
await u.clearBalanceCache();
|
||||
lock.releaseLock();
|
||||
res.send(payment);
|
||||
} else {
|
||||
|
750
package-lock.json
generated
750
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user