refactor: move setInterval outside method logic

This commit is contained in:
Vlad Stan
2022-07-11 10:36:03 +03:00
parent e960285c8f
commit 31b6a9410c

View File

@@ -574,19 +574,17 @@
data.onchainwallet = this.onchainwallet?.id data.onchainwallet = this.onchainwallet?.id
this.createCharge(wallet, data) this.createCharge(wallet, data)
}, },
timerCount: function () { refreshActiveChargesBalance: async function () {
setInterval(async () => { const activeLinkIds = this.chargeLinks
const activeLinkIds = this.chargeLinks .filter(c => !c.paid && !c.time_elapsed)
.filter(c => !c.paid && !c.time_elapsed) .map(c => c.id)
.map(c => c.id) .join(',')
.join(',') await LNbits.api.request(
await LNbits.api.request( 'GET',
'GET', '/satspay/api/v1/charges/balance/' + activeLinkIds,
'/satspay/api/v1/charges/balance/' + activeLinkIds, 'filla'
'filla' )
) await this.getCharges()
await this.getCharges()
}, 20000)
}, },
refreshBalance: async function (charge) { refreshBalance: async function (charge) {
try { try {
@@ -617,7 +615,9 @@
}) })
const utxos = await retryWithDelay(fn) 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) { } catch (error) {
console.error(error) console.error(error)
@@ -669,14 +669,18 @@
}) })
}, },
exportchargeCSV: function () { exportchargeCSV: function () {
LNbits.utils.exportCSV(this.chargesTable.columns, this.chargeLinks) LNbits.utils.exportCSV(
this.chargesTable.columns,
this.chargeLinks,
'charges'
)
} }
}, },
created: async function () { created: async function () {
await this.getCharges() await this.getCharges()
await this.getWalletLinks() await this.getWalletLinks()
await this.getWalletConfig() await this.getWalletConfig()
this.timerCount() setInterval(() => this.refreshActiveChargesBalance(), 10 * 2000)
await this.rescanOnchainAddresses() await this.rescanOnchainAddresses()
setInterval(() => this.rescanOnchainAddresses(), 10 * 1000) setInterval(() => this.rescanOnchainAddresses(), 10 * 1000)
} }