From a9506cee11afd87fdec2fed9523a4e0c748a933c Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Fri, 8 Jul 2022 11:35:36 +0300 Subject: [PATCH] feat: show pending funds --- .../satspay/templates/satspay/display.html | 102 ++++++++++++------ 1 file changed, 71 insertions(+), 31 deletions(-) diff --git a/lnbits/extensions/satspay/templates/satspay/display.html b/lnbits/extensions/satspay/templates/satspay/display.html index 3e72028f0..bcb23000c 100644 --- a/lnbits/extensions/satspay/templates/satspay/display.html +++ b/lnbits/extensions/satspay/templates/satspay/display.html @@ -3,28 +3,26 @@
-
-
-
- -
-
-
+
+
+ +
+
+
+
-
Time elapsed
+ Time elapsed
-
Charge paid
+ Charge paid
@@ -42,8 +40,10 @@
-
-
+
+
+
+
Charge Id:
Total to pay:
- sats + + sat +
-
+
Amount paid:
- sats + + + sat
-
+
+
Amount pending:
+
+ + sat + +
+
+
Amount due:
-
- sats -
- + + + sat + + none
- +
+ +
@@ -271,6 +294,7 @@ data() { return { charge: JSON.parse('{{charge_data | tojson}}'), + pendingFunds: 0, ws: null, newProgress: 0.4, counter: 1, @@ -313,6 +337,26 @@ LNbits.utils.notifyApiError(error) } }, + checkPendingOnchain: async function () { + const { + bitcoin: {addresses: addressesAPI} + } = mempoolJS() + + try { + const fn = async () => + addressesAPI.getAddressTxsUtxo({ + address: this.charge.onchainaddress + }) + + const utxos = await retryWithDelay(fn) + + this.pendingFunds = utxos + .filter(u => !u.status.confirmed) + .reduce((t, u) => t + u.value, 0) + } catch (error) { + console.error('cannot check pending funds') + } + }, payInvoice: function () { this.lnbtc = true this.onbtc = false @@ -339,14 +383,13 @@ loopRefresh: function () { // invoice only const refreshIntervalId = setInterval(async () => { - console.log('### 1111') if (this.charge.paid || this.timetoComplete < 1) { clearInterval(refreshIntervalId) } this.refreshProgres() if (this.counter % 10 === 0) { - console.log('### 11110') await this.checkBalances() + await this.checkPendingOnchain() } this.counter++ }, 1000) @@ -360,17 +403,14 @@ this.ws = new WebSocket('wss://mempool.space/api/v1/ws') this.ws.addEventListener('open', x => { - console.log('### open ws', x) - }) - this.ws.addEventListener('close', x => { - console.log('### close ws', x) + if (this.charge.onchainaddress) { + this.trackAddress(this.charge.onchainaddress) + } }) this.ws.addEventListener('message', async ({data}) => { const res = JSON.parse(data.toString()) - console.log('### socker mempool res', res) if (res['address-transactions']) { - console.log('### res', res) await this.checkBalances() this.$q.notify({ type: 'positive', @@ -389,7 +429,6 @@ trackAddress: async function (address, retry = 0) { try { if (!this.ws || this.ws.readyState !== WebSocket.OPEN) this.initWs() - console.log('### start to track: ', address) this.ws.send(JSON.stringify({'track-address': address})) } catch (error) { await sleep(1000) @@ -415,6 +454,7 @@ if (this.charge.onchainaddress) { this.loopPingWs() + this.checkPendingOnchain() this.trackAddress(this.charge.onchainaddress) } }