From 31b6a9410c3ed078373abae349897b11929dc2cb Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Mon, 11 Jul 2022 10:36:03 +0300 Subject: [PATCH] refactor: move setInterval outside method logic --- .../satspay/templates/satspay/index.html | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/lnbits/extensions/satspay/templates/satspay/index.html b/lnbits/extensions/satspay/templates/satspay/index.html index 0e02285d..1879925f 100644 --- a/lnbits/extensions/satspay/templates/satspay/index.html +++ b/lnbits/extensions/satspay/templates/satspay/index.html @@ -574,19 +574,17 @@ data.onchainwallet = this.onchainwallet?.id this.createCharge(wallet, data) }, - timerCount: function () { - setInterval(async () => { - const activeLinkIds = this.chargeLinks - .filter(c => !c.paid && !c.time_elapsed) - .map(c => c.id) - .join(',') - await LNbits.api.request( - 'GET', - '/satspay/api/v1/charges/balance/' + activeLinkIds, - 'filla' - ) - await this.getCharges() - }, 20000) + refreshActiveChargesBalance: async function () { + const activeLinkIds = this.chargeLinks + .filter(c => !c.paid && !c.time_elapsed) + .map(c => c.id) + .join(',') + await LNbits.api.request( + 'GET', + '/satspay/api/v1/charges/balance/' + activeLinkIds, + 'filla' + ) + await this.getCharges() }, refreshBalance: async function (charge) { try { @@ -617,7 +615,9 @@ }) const utxos = await retryWithDelay(fn) - charge.pendingBalance = utxos.reduce((t, u) => t + u.value, 0) + charge.pendingBalance = utxos + .filter(u => !u.status.confirmed) + .reduce((t, u) => t + u.value, 0) } } catch (error) { console.error(error) @@ -669,14 +669,18 @@ }) }, exportchargeCSV: function () { - LNbits.utils.exportCSV(this.chargesTable.columns, this.chargeLinks) + LNbits.utils.exportCSV( + this.chargesTable.columns, + this.chargeLinks, + 'charges' + ) } }, created: async function () { await this.getCharges() await this.getWalletLinks() await this.getWalletConfig() - this.timerCount() + setInterval(() => this.refreshActiveChargesBalance(), 10 * 2000) await this.rescanOnchainAddresses() setInterval(() => this.rescanOnchainAddresses(), 10 * 1000) }