diff --git a/lnbits/extensions/satspay/templates/satspay/display.html b/lnbits/extensions/satspay/templates/satspay/display.html index 94ff5e002..a60bce17d 100644 --- a/lnbits/extensions/satspay/templates/satspay/display.html +++ b/lnbits/extensions/satspay/templates/satspay/display.html @@ -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') } diff --git a/lnbits/extensions/satspay/templates/satspay/index.html b/lnbits/extensions/satspay/templates/satspay/index.html index 1879925fd..c007b44ac 100644 --- a/lnbits/extensions/satspay/templates/satspay/index.html +++ b/lnbits/extensions/satspay/templates/satspay/index.html @@ -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)