mirror of
https://github.com/lnbits/lnbits.git
synced 2025-06-26 16:51:42 +02:00
feat: only refresh balance on the back-end if new funds are detected by the front-end refresh
This commit is contained in:
parent
31b6a9410c
commit
057de41678
@ -329,6 +329,9 @@
|
||||
)
|
||||
},
|
||||
checkBalances: async function () {
|
||||
console.log('### checkBalances 1', this.charge.hasStaleBalance)
|
||||
if (!this.charge.hasStaleBalance) return
|
||||
console.log('### checkBalances 2')
|
||||
try {
|
||||
const {data} = await LNbits.api.request(
|
||||
'GET',
|
||||
@ -356,10 +359,18 @@
|
||||
const utxos = await addressesAPI.getAddressTxsUtxo({
|
||||
address: this.charge.onchainaddress
|
||||
})
|
||||
const newBalance = utxos.reduce((t, u) => t + u.value, 0)
|
||||
this.charge.hasStaleBalance = this.charge.balance === newBalance
|
||||
|
||||
this.pendingFunds = utxos
|
||||
.filter(u => !u.status.confirmed)
|
||||
.reduce((t, u) => t + u.value, 0)
|
||||
|
||||
console.log(
|
||||
'### charge new funds',
|
||||
this.charge.balance === newBalance,
|
||||
this.charge
|
||||
)
|
||||
} catch (error) {
|
||||
console.error('cannot check pending funds')
|
||||
}
|
||||
|
@ -576,9 +576,10 @@
|
||||
},
|
||||
refreshActiveChargesBalance: async function () {
|
||||
const activeLinkIds = this.chargeLinks
|
||||
.filter(c => !c.paid && !c.time_elapsed)
|
||||
.filter(c => !c.paid && !c.time_elapsed && !c.hasStaleBalance)
|
||||
.map(c => c.id)
|
||||
.join(',')
|
||||
console.log('### activeLinkIds', activeLinkIds)
|
||||
await LNbits.api.request(
|
||||
'GET',
|
||||
'/satspay/api/v1/charges/balance/' + activeLinkIds,
|
||||
@ -615,9 +616,18 @@
|
||||
})
|
||||
|
||||
const utxos = await retryWithDelay(fn)
|
||||
const newBalance = utxos.reduce((t, u) => t + u.value, 0)
|
||||
|
||||
charge.pendingBalance = utxos
|
||||
.filter(u => !u.status.confirmed)
|
||||
.reduce((t, u) => t + u.value, 0)
|
||||
|
||||
charge.hasStaleBalance = charge.balance === newBalance
|
||||
console.log(
|
||||
'### charge new funds',
|
||||
charge.balance === newBalance,
|
||||
charge
|
||||
)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
|
Loading…
x
Reference in New Issue
Block a user