Merge pull request #4 from lnbits/main

fix: wallet not found error (#1063)
This commit is contained in:
blackcoffeexbt 2022-10-20 16:33:06 +01:00 committed by GitHub
commit 2731e62a6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 31 deletions

View file

@ -102,7 +102,7 @@ async def check_address_balance(charge_id: str) -> List[Charges]:
charge = await get_charge(charge_id)
if not charge.paid:
if charge.onchainaddress:
config = await get_config(charge.user)
config = await get_charge_config(charge_id)
try:
async with httpx.AsyncClient() as client:
r = await client.get(
@ -122,3 +122,10 @@ async def check_address_balance(charge_id: str) -> List[Charges]:
return await update_charge(charge_id=charge_id, balance=charge.amount)
row = await db.fetchone("SELECT * FROM satspay.charges WHERE id = ?", (charge_id,))
return Charges.from_row(row) if row else None
async def get_charge_config(charge_id: str):
row = await db.fetchone(
"""SELECT "user" FROM satspay.charges WHERE id = ?""", (charge_id,)
)
return await get_config(row.user)

View file

@ -0,0 +1,17 @@
from .models import Charges
def compact_charge(charge: Charges):
return {
"id": charge.id,
"description": charge.description,
"onchainaddress": charge.onchainaddress,
"payment_request": charge.payment_request,
"payment_hash": charge.payment_hash,
"time": charge.time,
"amount": charge.amount,
"balance": charge.balance,
"paid": charge.paid,
"timestamp": charge.timestamp,
"completelink": charge.completelink, # should be secret?
}

View file

@ -19,7 +19,6 @@ class CreateCharge(BaseModel):
class Charges(BaseModel):
id: str
user: str
description: Optional[str]
onchainwallet: Optional[str]
onchainaddress: Optional[str]

View file

@ -328,7 +328,7 @@
)
},
checkBalances: async function () {
if (!this.charge.hasStaleBalance) await this.refreshCharge()
if (this.charge.hasStaleBalance) return
try {
const {data} = await LNbits.api.request(
'GET',
@ -339,18 +339,9 @@
LNbits.utils.notifyApiError(error)
}
},
refreshCharge: async function () {
try {
const {data} = await LNbits.api.request(
'GET',
`/satspay/api/v1/charge/${this.charge.id}`
)
this.charge = mapCharge(data, this.charge)
} catch (error) {
LNbits.utils.notifyApiError(error)
}
},
checkPendingOnchain: async function () {
if (!this.charge.onchainaddress) return
const {
bitcoin: {addresses: addressesAPI}
} = mempoolJS({

View file

@ -9,10 +9,9 @@ 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
from .crud import get_charge, get_charge_config
templates = Jinja2Templates(directory="templates")
@ -32,7 +31,7 @@ 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)
onchainwallet_config = await get_charge_config(charge_id)
inkey = wallet.inkey if wallet else None
mempool_endpoint = (
onchainwallet_config.mempool_endpoint if onchainwallet_config else None

View file

@ -20,6 +20,7 @@ from .crud import (
get_charges,
update_charge,
)
from .helpers import compact_charge
from .models import CreateCharge
#############################CHARGES##########################
@ -123,25 +124,13 @@ async def api_charge_balance(charge_id):
try:
r = await client.post(
charge.webhook,
json={
"id": charge.id,
"description": charge.description,
"onchainaddress": charge.onchainaddress,
"payment_request": charge.payment_request,
"payment_hash": charge.payment_hash,
"time": charge.time,
"amount": charge.amount,
"balance": charge.balance,
"paid": charge.paid,
"timestamp": charge.timestamp,
"completelink": charge.completelink,
},
json=compact_charge(charge),
timeout=40,
)
except AssertionError:
charge.webhook = None
return {
**charge.dict(),
**compact_charge(charge),
**{"time_elapsed": charge.time_elapsed},
**{"time_left": charge.time_left},
**{"paid": charge.paid},