feat: use multiple charges balance endpoint (one call only)
This commit is contained in:
parent
6da62c648a
commit
5317d5afd5
|
@ -296,6 +296,7 @@
|
||||||
walletLinks: [],
|
walletLinks: [],
|
||||||
chargeLinks: [],
|
chargeLinks: [],
|
||||||
onchainwallet: '',
|
onchainwallet: '',
|
||||||
|
rescanning: false,
|
||||||
mempool: {
|
mempool: {
|
||||||
endpoint: ''
|
endpoint: ''
|
||||||
},
|
},
|
||||||
|
@ -444,35 +445,42 @@
|
||||||
},
|
},
|
||||||
timerCount: function () {
|
timerCount: function () {
|
||||||
setInterval(async () => {
|
setInterval(async () => {
|
||||||
for (i = 0; i < this.chargeLinks.length - 1; i++) {
|
const activeLinkIds = this.chargeLinks
|
||||||
if (this.chargeLinks[i]['paid'] == 'True') {
|
.filter(c => !c.paid && !c.time_elapsed)
|
||||||
setTimeout(async () => {
|
.map(c => c.id)
|
||||||
await LNbits.api.request(
|
.join(',')
|
||||||
'GET',
|
await LNbits.api.request(
|
||||||
'/satspay/api/v1/charges/balance/' +
|
'GET',
|
||||||
this.chargeLinks[i]['id'],
|
'/satspay/api/v1/charges/balance/' + activeLinkIds,
|
||||||
'filla'
|
'filla'
|
||||||
)
|
)
|
||||||
}, 2000)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await this.getCharges()
|
await this.getCharges()
|
||||||
}, 20000)
|
}, 20000)
|
||||||
},
|
},
|
||||||
rescanOnchainAddresses: async function () {
|
rescanOnchainAddresses: async function () {
|
||||||
|
if (this.rescanning) return
|
||||||
|
this.rescanning = true
|
||||||
const {
|
const {
|
||||||
bitcoin: {addresses: addressesAPI}
|
bitcoin: {addresses: addressesAPI}
|
||||||
} = mempoolJS()
|
} = mempoolJS()
|
||||||
|
|
||||||
const onchainCharges = this.chargeLinks.filter(c => c.onchainaddress)
|
try {
|
||||||
for (const charge of onchainCharges) {
|
const onchainActiveCharges = this.chargeLinks.filter(
|
||||||
const fn = async () =>
|
c => c.onchainaddress && !c.paid && !c.time_elapsed
|
||||||
addressesAPI.getAddressTxsUtxo({
|
)
|
||||||
address: charge.onchainaddress
|
for (const charge of onchainActiveCharges) {
|
||||||
})
|
const fn = async () =>
|
||||||
|
addressesAPI.getAddressTxsUtxo({
|
||||||
|
address: charge.onchainaddress
|
||||||
|
})
|
||||||
|
|
||||||
const utxos = await retryWithDelay(fn)
|
const utxos = await retryWithDelay(fn)
|
||||||
charge.balance = utxos.reduce((t, u) => t + u.value, 0)
|
charge.balance = utxos.reduce((t, u) => t + u.value, 0)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
} finally {
|
||||||
|
this.rescanning = false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
createCharge: async function (wallet, data) {
|
createCharge: async function (wallet, data) {
|
||||||
|
@ -523,13 +531,12 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created: async function () {
|
created: async function () {
|
||||||
console.log(this.g.user)
|
|
||||||
await this.getCharges()
|
await this.getCharges()
|
||||||
await this.getWalletLinks()
|
await this.getWalletLinks()
|
||||||
await this.getWalletConfig()
|
await this.getWalletConfig()
|
||||||
this.timerCount()
|
this.timerCount()
|
||||||
await this.rescanOnchainAddresses()
|
await this.rescanOnchainAddresses()
|
||||||
setInterval(() => this.rescanOnchainAddresses(), 30 * 1000)
|
setInterval(() => this.rescanOnchainAddresses(), 10 * 1000)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user