feat: use custom mempool_endpoint for the charge details

This commit is contained in:
Vlad Stan 2022-07-08 16:37:35 +03:00
parent 4cb54ce549
commit ac3f95e6c2
5 changed files with 29 additions and 13 deletions

View file

@ -6,7 +6,7 @@ from lnbits.core.services import create_invoice
from lnbits.core.views.api import api_payment from lnbits.core.views.api import api_payment
from lnbits.helpers import urlsafe_short_hash 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 lnbits.db import open_ext_db
from . import db from . import db

View file

@ -215,7 +215,15 @@
class="row items-center" class="row items-center"
> >
<div class="col text-center"> <div class="col text-center">
<span class="text-subtitle1" v-text="charge.onchainaddress"></span> <a
style="color: unset"
:href="mempool_endpoint + '/address/' + charge.onchainaddress"
target="_blank"
><span
class="text-subtitle1"
v-text="charge.onchainaddress"
></span>
</a>
</div> </div>
</div> </div>
<div class="row items-center q-mt-md"> <div class="row items-center q-mt-md">
@ -294,6 +302,7 @@
data() { data() {
return { return {
charge: JSON.parse('{{charge_data | tojson}}'), charge: JSON.parse('{{charge_data | tojson}}'),
mempool_endpoint: '{{mempool_endpoint}}',
pendingFunds: 0, pendingFunds: 0,
ws: null, ws: null,
newProgress: 0.4, newProgress: 0.4,
@ -339,7 +348,9 @@
checkPendingOnchain: async function () { checkPendingOnchain: async function () {
const { const {
bitcoin: {addresses: addressesAPI} bitcoin: {addresses: addressesAPI}
} = mempoolJS() } = mempoolJS({
hostname: new URL(this.mempool_endpoint).hostname
})
try { try {
const utxos = await addressesAPI.getAddressTxsUtxo({ const utxos = await addressesAPI.getAddressTxsUtxo({
@ -394,7 +405,7 @@
const { const {
bitcoin: {websocket} bitcoin: {websocket}
} = mempoolJS({ } = mempoolJS({
hostname: 'mempool.space' hostname: new URL(this.mempool_endpoint).hostname
}) })
this.ws = new WebSocket('wss://mempool.space/api/v1/ws') this.ws = new WebSocket('wss://mempool.space/api/v1/ws')
@ -434,7 +445,6 @@
} }
}, },
created: async function () { created: async function () {
console.log('### charge', this.charge)
if (this.charge.lnbitswallet) this.payInvoice() if (this.charge.lnbitswallet) this.payInvoice()
else this.payOnchain() else this.payOnchain()
await this.checkBalances() await this.checkBalances()

View file

@ -532,6 +532,8 @@
this.g.user.wallets[0].inkey this.g.user.wallets[0].inkey
) )
this.mempool.endpoint = data.mempool_endpoint this.mempool.endpoint = data.mempool_endpoint
const url = new URL(this.mempool.endpoint)
this.mempool.hostname = url.hostname
} catch (error) { } catch (error) {
LNbits.utils.notifyApiError(error) LNbits.utils.notifyApiError(error)
} }
@ -560,7 +562,6 @@
this.chargeLinks.find(old => old.id === c.id) this.chargeLinks.find(old => old.id === c.id)
) )
) )
console.log('### this.chargeLinks', this.chargeLinks)
} catch (error) { } catch (error) {
LNbits.utils.notifyApiError(error) LNbits.utils.notifyApiError(error)
} }
@ -595,16 +596,15 @@
'filla' 'filla'
) )
charge.balance = data.balance charge.balance = data.balance
} catch (error) { } catch (error) {}
}
}, },
rescanOnchainAddresses: async function () { rescanOnchainAddresses: async function () {
if (this.rescanning) return if (this.rescanning) return
this.rescanning = true this.rescanning = true
const { const {
bitcoin: {addresses: addressesAPI} bitcoin: {addresses: addressesAPI}
} = mempoolJS() } = mempoolJS({hostname: this.mempool.hostname})
try { try {
const onchainActiveCharges = this.chargeLinks.filter( const onchainActiveCharges = this.chargeLinks.filter(

View file

@ -9,6 +9,7 @@ from starlette.responses import HTMLResponse
from lnbits.core.crud import get_wallet from lnbits.core.crud import get_wallet
from lnbits.core.models import User from lnbits.core.models import User
from lnbits.decorators import check_user_exists from lnbits.decorators import check_user_exists
from lnbits.extensions.watchonly.crud import get_config
from . import satspay_ext, satspay_renderer from . import satspay_ext, satspay_renderer
from .crud import get_charge 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." status_code=HTTPStatus.NOT_FOUND, detail="Charge link does not exist."
) )
wallet = await get_wallet(charge.lnbitswallet) wallet = await get_wallet(charge.lnbitswallet)
onchainwallet_config = await get_config(charge.user)
inkey = wallet.inkey if wallet else None inkey = wallet.inkey if wallet else None
return satspay_renderer().TemplateResponse( return satspay_renderer().TemplateResponse(
"satspay/display.html", "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,
},
) )

View file

@ -1,7 +1,6 @@
from http import HTTPStatus from http import HTTPStatus
import httpx import httpx
from fastapi import Query
from fastapi.params import Depends from fastapi.params import Depends
from starlette.exceptions import HTTPException from starlette.exceptions import HTTPException