mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-02-22 22:25:47 +01:00
feat: do client side rescan for onchain address
This commit is contained in:
parent
6c21bf359c
commit
91c6d32852
2 changed files with 50 additions and 0 deletions
|
@ -280,6 +280,8 @@
|
||||||
<!-- lnbits/static/vendor
|
<!-- lnbits/static/vendor
|
||||||
<script src="/vendor/vue-qrcode@1.0.2/vue-qrcode.min.js"></script> -->
|
<script src="/vendor/vue-qrcode@1.0.2/vue-qrcode.min.js"></script> -->
|
||||||
<style></style>
|
<style></style>
|
||||||
|
<!-- todo: use config mempool -->
|
||||||
|
<script src="https://mempool.space/mempool.js"></script>
|
||||||
<script>
|
<script>
|
||||||
Vue.component(VueQrcode.name, VueQrcode)
|
Vue.component(VueQrcode.name, VueQrcode)
|
||||||
|
|
||||||
|
@ -300,6 +302,21 @@
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sleep = ms => new Promise(r => setTimeout(r, ms))
|
||||||
|
const retryWithDelay = async function (fn, retryCount = 0) {
|
||||||
|
try {
|
||||||
|
await sleep(25)
|
||||||
|
// Do not return the call directly, use result.
|
||||||
|
// Otherwise the error will not be cought in this try-catch block.
|
||||||
|
const result = await fn()
|
||||||
|
return result
|
||||||
|
} catch (err) {
|
||||||
|
if (retryCount > 100) throw err
|
||||||
|
await sleep((retryCount + 1) * 1000)
|
||||||
|
return retryWithDelay(fn, retryCount + 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
new Vue({
|
new Vue({
|
||||||
el: '#vue',
|
el: '#vue',
|
||||||
mixins: [windowMixin],
|
mixins: [windowMixin],
|
||||||
|
@ -423,6 +440,19 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getWalletConfig: async function () {
|
||||||
|
try {
|
||||||
|
const {data} = await LNbits.api.request(
|
||||||
|
'GET',
|
||||||
|
'/watchonly/api/v1/config',
|
||||||
|
this.g.user.wallets[0].inkey
|
||||||
|
)
|
||||||
|
this.mempool.endpoint = data.mempool_endpoint
|
||||||
|
} catch (error) {
|
||||||
|
LNbits.utils.notifyApiError(error)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
getCharges: async function () {
|
getCharges: async function () {
|
||||||
try {
|
try {
|
||||||
const {data} = await LNbits.api.request(
|
const {data} = await LNbits.api.request(
|
||||||
|
@ -460,6 +490,22 @@
|
||||||
await this.getCharges()
|
await this.getCharges()
|
||||||
}, 20000)
|
}, 20000)
|
||||||
},
|
},
|
||||||
|
rescanOnchainAddresses: async function () {
|
||||||
|
const {
|
||||||
|
bitcoin: {addresses: addressesAPI}
|
||||||
|
} = mempoolJS()
|
||||||
|
|
||||||
|
const onchainCharges = this.chargeLinks.filter(c => c.onchainaddress)
|
||||||
|
for (const charge of onchainCharges) {
|
||||||
|
const fn = async () =>
|
||||||
|
addressesAPI.getAddressTxsUtxo({
|
||||||
|
address: charge.onchainaddress
|
||||||
|
})
|
||||||
|
|
||||||
|
const utxos = await retryWithDelay(fn)
|
||||||
|
charge.balance = utxos.reduce((t, u) => t + u.value, 0)
|
||||||
|
}
|
||||||
|
},
|
||||||
createCharge: async function (wallet, data) {
|
createCharge: async function (wallet, data) {
|
||||||
try {
|
try {
|
||||||
const resp = await LNbits.api.request(
|
const resp = await LNbits.api.request(
|
||||||
|
@ -511,7 +557,10 @@
|
||||||
console.log(this.g.user)
|
console.log(this.g.user)
|
||||||
await this.getCharges()
|
await this.getCharges()
|
||||||
await this.getWalletLinks()
|
await this.getWalletLinks()
|
||||||
|
await this.getWalletConfig()
|
||||||
this.timerCount()
|
this.timerCount()
|
||||||
|
this.rescanOnchainAddresses()
|
||||||
|
setInterval(() => this.rescanOnchainAddresses(), 30 * 1000)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1198,6 +1198,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endblock %} {% block scripts %} {{ window_vars(user) }}
|
{% endblock %} {% block scripts %} {{ window_vars(user) }}
|
||||||
|
<!-- todo: use endpoint here -->
|
||||||
<script type="text/javascript" src="https://mempool.space/mempool.js"></script>
|
<script type="text/javascript" src="https://mempool.space/mempool.js"></script>
|
||||||
|
|
||||||
<script src="{{ url_for('watchonly_static', path='js/tables.js') }}"></script>
|
<script src="{{ url_for('watchonly_static', path='js/tables.js') }}"></script>
|
||||||
|
|
Loading…
Add table
Reference in a new issue