From ac3f95e6c27186d57b60ce5a719655590334b61d Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Fri, 8 Jul 2022 16:37:35 +0300 Subject: [PATCH] feat: use custom mempool_endpoint for the charge details --- lnbits/extensions/satspay/crud.py | 2 +- .../satspay/templates/satspay/display.html | 18 ++++++++++++++---- .../satspay/templates/satspay/index.html | 12 ++++++------ lnbits/extensions/satspay/views.py | 9 ++++++++- lnbits/extensions/satspay/views_api.py | 1 - 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/lnbits/extensions/satspay/crud.py b/lnbits/extensions/satspay/crud.py index 65f9e2281..be681dc21 100644 --- a/lnbits/extensions/satspay/crud.py +++ b/lnbits/extensions/satspay/crud.py @@ -6,7 +6,7 @@ from lnbits.core.services import create_invoice from lnbits.core.views.api import api_payment from lnbits.helpers import urlsafe_short_hash -from ..watchonly.crud import get_fresh_address, get_config, get_watch_wallet +from ..watchonly.crud import get_fresh_address, get_config # from lnbits.db import open_ext_db from . import db diff --git a/lnbits/extensions/satspay/templates/satspay/display.html b/lnbits/extensions/satspay/templates/satspay/display.html index b6d2019d9..94ff5e002 100644 --- a/lnbits/extensions/satspay/templates/satspay/display.html +++ b/lnbits/extensions/satspay/templates/satspay/display.html @@ -215,7 +215,15 @@ class="row items-center" >
- + +
@@ -294,6 +302,7 @@ data() { return { charge: JSON.parse('{{charge_data | tojson}}'), + mempool_endpoint: '{{mempool_endpoint}}', pendingFunds: 0, ws: null, newProgress: 0.4, @@ -339,7 +348,9 @@ checkPendingOnchain: async function () { const { bitcoin: {addresses: addressesAPI} - } = mempoolJS() + } = mempoolJS({ + hostname: new URL(this.mempool_endpoint).hostname + }) try { const utxos = await addressesAPI.getAddressTxsUtxo({ @@ -394,7 +405,7 @@ const { bitcoin: {websocket} } = mempoolJS({ - hostname: 'mempool.space' + hostname: new URL(this.mempool_endpoint).hostname }) this.ws = new WebSocket('wss://mempool.space/api/v1/ws') @@ -434,7 +445,6 @@ } }, created: async function () { - console.log('### charge', this.charge) if (this.charge.lnbitswallet) this.payInvoice() else this.payOnchain() await this.checkBalances() diff --git a/lnbits/extensions/satspay/templates/satspay/index.html b/lnbits/extensions/satspay/templates/satspay/index.html index 3c4418be3..0e02285db 100644 --- a/lnbits/extensions/satspay/templates/satspay/index.html +++ b/lnbits/extensions/satspay/templates/satspay/index.html @@ -532,6 +532,8 @@ this.g.user.wallets[0].inkey ) this.mempool.endpoint = data.mempool_endpoint + const url = new URL(this.mempool.endpoint) + this.mempool.hostname = url.hostname } catch (error) { LNbits.utils.notifyApiError(error) } @@ -560,7 +562,6 @@ this.chargeLinks.find(old => old.id === c.id) ) ) - console.log('### this.chargeLinks', this.chargeLinks) } catch (error) { LNbits.utils.notifyApiError(error) } @@ -587,7 +588,7 @@ await this.getCharges() }, 20000) }, - refreshBalance: async function(charge) { + refreshBalance: async function (charge) { try { const {data} = await LNbits.api.request( 'GET', @@ -595,16 +596,15 @@ 'filla' ) charge.balance = data.balance - } catch (error) { - - } + } catch (error) {} }, rescanOnchainAddresses: async function () { if (this.rescanning) return this.rescanning = true + const { bitcoin: {addresses: addressesAPI} - } = mempoolJS() + } = mempoolJS({hostname: this.mempool.hostname}) try { const onchainActiveCharges = this.chargeLinks.filter( diff --git a/lnbits/extensions/satspay/views.py b/lnbits/extensions/satspay/views.py index d4fc457df..5b641510a 100644 --- a/lnbits/extensions/satspay/views.py +++ b/lnbits/extensions/satspay/views.py @@ -9,6 +9,7 @@ from starlette.responses import HTMLResponse from lnbits.core.crud import get_wallet from lnbits.core.models import User from lnbits.decorators import check_user_exists +from lnbits.extensions.watchonly.crud import get_config from . import satspay_ext, satspay_renderer from .crud import get_charge @@ -31,8 +32,14 @@ async def display(request: Request, charge_id: str): status_code=HTTPStatus.NOT_FOUND, detail="Charge link does not exist." ) wallet = await get_wallet(charge.lnbitswallet) + onchainwallet_config = await get_config(charge.user) inkey = wallet.inkey if wallet else None return satspay_renderer().TemplateResponse( "satspay/display.html", - {"request": request, "charge_data": charge.dict(), "wallet_inkey": inkey}, + { + "request": request, + "charge_data": charge.dict(), + "wallet_inkey": inkey, + "mempool_endpoint": onchainwallet_config.mempool_endpoint, + }, ) diff --git a/lnbits/extensions/satspay/views_api.py b/lnbits/extensions/satspay/views_api.py index 5aaf04f13..43593cb39 100644 --- a/lnbits/extensions/satspay/views_api.py +++ b/lnbits/extensions/satspay/views_api.py @@ -1,7 +1,6 @@ from http import HTTPStatus import httpx -from fastapi import Query from fastapi.params import Depends from starlette.exceptions import HTTPException