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.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

View File

@ -215,7 +215,15 @@
class="row items-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 class="row items-center q-mt-md">
@ -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()

View File

@ -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(

View File

@ -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,
},
)

View File

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