From 1ab37ff48bbe4ffaa421c52a5afdf85ce55ac6fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Sun, 18 Aug 2024 09:20:01 +0200 Subject: [PATCH] fix: charge frontend with zeroconf = false still had some display issue if we set zeroconf to false --- static/js/components.js | 14 ++++++++++---- static/js/display.js | 18 ++++++++++-------- tasks.py | 11 +++-------- templates/satspay/display.html | 9 ++++----- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/static/js/components.js b/static/js/components.js index 9a42596..d917d9f 100644 --- a/static/js/components.js +++ b/static/js/components.js @@ -1,7 +1,7 @@ Vue.component(VueQrcode.name, VueQrcode) Vue.component('satspay-paid', { - props: ['charge', 'timer'], + props: ['charge'], template: `
0) { this.barColor = 'secondary' setInterval(() => { if (!this.charge.paid && this.timeSeconds > 0) { this.timeSeconds -= 1 this.timeLeft = secondsToTime(this.timeSeconds) - this.progress = progress(chargeTimeSeconds, this.timeSeconds) - console.log(this.timeSeconds, chargeTimeSeconds, this.progress) + this.progress = progress(this.charge.time * 60, this.timeSeconds) + } + if (this.charge.paid) { + this.barColor = 'positive' + this.progress = 1 } }, 1000) } diff --git a/static/js/display.js b/static/js/display.js index 9225ca4..a482aad 100644 --- a/static/js/display.js +++ b/static/js/display.js @@ -6,19 +6,22 @@ new Vue({ return { charge: mapCharge(charge_data), network: network, - pendingFunds: 0, ws: null, - newProgress: 0.4, - counter: 1, wallet: { inkey: '' }, - timer: 0, - cancelListener: () => {}, tab: 'uqr' } }, computed: { + mempoolLink() { + const onchainaddress = this.charge.onchainaddress + if (this.network === 'Testnet') { + return `https://mempool.space/testnet/address/${onchainaddress}` + } else { + return `https://mempool.space/address/${onchainaddress}` + } + }, unifiedQR() { const bitcoin = (this.charge.onchainaddress || '').toUpperCase() let queryString = `bitcoin:${bitcoin}?amount=${( @@ -44,8 +47,9 @@ new Vue({ this.ws.addEventListener('message', async ({data}) => { const res = JSON.parse(data.toString()) this.charge.balance = res.balance + this.charge.pending = res.pending if (res.paid) { - this.charge.progress = 0 + this.charge.progress = 1 this.charge.paid = true this.$q.notify({ type: 'positive', @@ -55,13 +59,11 @@ new Vue({ } }) this.ws.addEventListener('close', async () => { - console.log('ws closed') this.$q.notify({ type: 'negative', message: 'WebSocket connection closed. Retrying...', timeout: 1000 }) - console.log('retrying ws connection...') setTimeout(() => { this.initWs() }, 3000) diff --git a/tasks.py b/tasks.py index 929ae3b..10bb5fe 100644 --- a/tasks.py +++ b/tasks.py @@ -30,10 +30,10 @@ async def send_success_websocket(charge: Charge): if charge_id == charge.id: await listener.send_json( { - "paid": True, + "paid": charge.paid, "balance": charge.balance, "pending": charge.pending, - "completelink": charge.completelink, + "completelink": charge.completelink if charge.paid else None, } ) @@ -96,19 +96,14 @@ def sum_transactions(address: str, txs): async def _handle_ws_message(address: str, data: dict): charge = await get_charge_by_onchain_address(address) assert charge, f"Charge with address `{address}` does not exist." - - for charge_id, listener in public_ws_listeners.items(): - if charge_id == charge.id: - await listener.send_json(data) - unconfirmed_balance = sum_transactions(address, data.get("mempool", [])) confirmed_balance = sum_transactions(address, data.get("confirmed", [])) if charge.zeroconf: confirmed_balance += unconfirmed_balance charge.balance = confirmed_balance charge.pending = unconfirmed_balance + await send_success_websocket(charge) if charge.paid: - await send_success_websocket(charge) stop_onchain_listener(address) if charge.webhook: resp = await call_webhook(charge) diff --git a/templates/satspay/display.html b/templates/satspay/display.html index d7a6387..94d511e 100644 --- a/templates/satspay/display.html +++ b/templates/satspay/display.html @@ -48,15 +48,15 @@ - - + + Amount pending: - ${pendingFunds} sats + ${charge.pending} sats @@ -91,7 +91,6 @@
@@ -161,7 +160,7 @@