mirror of
https://github.com/lnbits/lnbits.git
synced 2025-06-27 09:11:57 +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 () {
|
checkBalances: async function () {
|
||||||
|
console.log('### checkBalances 1', this.charge.hasStaleBalance)
|
||||||
|
if (!this.charge.hasStaleBalance) return
|
||||||
|
console.log('### checkBalances 2')
|
||||||
try {
|
try {
|
||||||
const {data} = await LNbits.api.request(
|
const {data} = await LNbits.api.request(
|
||||||
'GET',
|
'GET',
|
||||||
@ -356,10 +359,18 @@
|
|||||||
const utxos = await addressesAPI.getAddressTxsUtxo({
|
const utxos = await addressesAPI.getAddressTxsUtxo({
|
||||||
address: this.charge.onchainaddress
|
address: this.charge.onchainaddress
|
||||||
})
|
})
|
||||||
|
const newBalance = utxos.reduce((t, u) => t + u.value, 0)
|
||||||
|
this.charge.hasStaleBalance = this.charge.balance === newBalance
|
||||||
|
|
||||||
this.pendingFunds = utxos
|
this.pendingFunds = utxos
|
||||||
.filter(u => !u.status.confirmed)
|
.filter(u => !u.status.confirmed)
|
||||||
.reduce((t, u) => t + u.value, 0)
|
.reduce((t, u) => t + u.value, 0)
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
'### charge new funds',
|
||||||
|
this.charge.balance === newBalance,
|
||||||
|
this.charge
|
||||||
|
)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('cannot check pending funds')
|
console.error('cannot check pending funds')
|
||||||
}
|
}
|
||||||
|
@ -576,9 +576,10 @@
|
|||||||
},
|
},
|
||||||
refreshActiveChargesBalance: async function () {
|
refreshActiveChargesBalance: async function () {
|
||||||
const activeLinkIds = this.chargeLinks
|
const activeLinkIds = this.chargeLinks
|
||||||
.filter(c => !c.paid && !c.time_elapsed)
|
.filter(c => !c.paid && !c.time_elapsed && !c.hasStaleBalance)
|
||||||
.map(c => c.id)
|
.map(c => c.id)
|
||||||
.join(',')
|
.join(',')
|
||||||
|
console.log('### activeLinkIds', activeLinkIds)
|
||||||
await LNbits.api.request(
|
await LNbits.api.request(
|
||||||
'GET',
|
'GET',
|
||||||
'/satspay/api/v1/charges/balance/' + activeLinkIds,
|
'/satspay/api/v1/charges/balance/' + activeLinkIds,
|
||||||
@ -615,9 +616,18 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
const utxos = await retryWithDelay(fn)
|
const utxos = await retryWithDelay(fn)
|
||||||
|
const newBalance = utxos.reduce((t, u) => t + u.value, 0)
|
||||||
|
|
||||||
charge.pendingBalance = utxos
|
charge.pendingBalance = utxos
|
||||||
.filter(u => !u.status.confirmed)
|
.filter(u => !u.status.confirmed)
|
||||||
.reduce((t, u) => t + u.value, 0)
|
.reduce((t, u) => t + u.value, 0)
|
||||||
|
|
||||||
|
charge.hasStaleBalance = charge.balance === newBalance
|
||||||
|
console.log(
|
||||||
|
'### charge new funds',
|
||||||
|
charge.balance === newBalance,
|
||||||
|
charge
|
||||||
|
)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user