mirror of
https://github.com/lnbits/lnbits.git
synced 2025-06-29 02:01:35 +02:00
fix: wallet not found error (#1063)
This commit is contained in:
@ -102,7 +102,7 @@ async def check_address_balance(charge_id: str) -> List[Charges]:
|
|||||||
charge = await get_charge(charge_id)
|
charge = await get_charge(charge_id)
|
||||||
if not charge.paid:
|
if not charge.paid:
|
||||||
if charge.onchainaddress:
|
if charge.onchainaddress:
|
||||||
config = await get_config(charge.user)
|
config = await get_charge_config(charge_id)
|
||||||
try:
|
try:
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
r = await client.get(
|
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)
|
return await update_charge(charge_id=charge_id, balance=charge.amount)
|
||||||
row = await db.fetchone("SELECT * FROM satspay.charges WHERE id = ?", (charge_id,))
|
row = await db.fetchone("SELECT * FROM satspay.charges WHERE id = ?", (charge_id,))
|
||||||
return Charges.from_row(row) if row else None
|
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)
|
||||||
|
17
lnbits/extensions/satspay/helpers.py
Normal file
17
lnbits/extensions/satspay/helpers.py
Normal 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?
|
||||||
|
}
|
@ -19,7 +19,6 @@ class CreateCharge(BaseModel):
|
|||||||
|
|
||||||
class Charges(BaseModel):
|
class Charges(BaseModel):
|
||||||
id: str
|
id: str
|
||||||
user: str
|
|
||||||
description: Optional[str]
|
description: Optional[str]
|
||||||
onchainwallet: Optional[str]
|
onchainwallet: Optional[str]
|
||||||
onchainaddress: Optional[str]
|
onchainaddress: Optional[str]
|
||||||
|
@ -328,7 +328,7 @@
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
checkBalances: async function () {
|
checkBalances: async function () {
|
||||||
if (!this.charge.hasStaleBalance) await this.refreshCharge()
|
if (this.charge.hasStaleBalance) return
|
||||||
try {
|
try {
|
||||||
const {data} = await LNbits.api.request(
|
const {data} = await LNbits.api.request(
|
||||||
'GET',
|
'GET',
|
||||||
@ -339,18 +339,9 @@
|
|||||||
LNbits.utils.notifyApiError(error)
|
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 () {
|
checkPendingOnchain: async function () {
|
||||||
|
if (!this.charge.onchainaddress) return
|
||||||
|
|
||||||
const {
|
const {
|
||||||
bitcoin: {addresses: addressesAPI}
|
bitcoin: {addresses: addressesAPI}
|
||||||
} = mempoolJS({
|
} = mempoolJS({
|
||||||
|
@ -9,10 +9,9 @@ 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, get_charge_config
|
||||||
|
|
||||||
templates = Jinja2Templates(directory="templates")
|
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."
|
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)
|
onchainwallet_config = await get_charge_config(charge_id)
|
||||||
inkey = wallet.inkey if wallet else None
|
inkey = wallet.inkey if wallet else None
|
||||||
mempool_endpoint = (
|
mempool_endpoint = (
|
||||||
onchainwallet_config.mempool_endpoint if onchainwallet_config else None
|
onchainwallet_config.mempool_endpoint if onchainwallet_config else None
|
||||||
|
@ -20,6 +20,7 @@ from .crud import (
|
|||||||
get_charges,
|
get_charges,
|
||||||
update_charge,
|
update_charge,
|
||||||
)
|
)
|
||||||
|
from .helpers import compact_charge
|
||||||
from .models import CreateCharge
|
from .models import CreateCharge
|
||||||
|
|
||||||
#############################CHARGES##########################
|
#############################CHARGES##########################
|
||||||
@ -123,25 +124,13 @@ async def api_charge_balance(charge_id):
|
|||||||
try:
|
try:
|
||||||
r = await client.post(
|
r = await client.post(
|
||||||
charge.webhook,
|
charge.webhook,
|
||||||
json={
|
json=compact_charge(charge),
|
||||||
"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,
|
|
||||||
},
|
|
||||||
timeout=40,
|
timeout=40,
|
||||||
)
|
)
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
charge.webhook = None
|
charge.webhook = None
|
||||||
return {
|
return {
|
||||||
**charge.dict(),
|
**compact_charge(charge),
|
||||||
**{"time_elapsed": charge.time_elapsed},
|
**{"time_elapsed": charge.time_elapsed},
|
||||||
**{"time_left": charge.time_left},
|
**{"time_left": charge.time_left},
|
||||||
**{"paid": charge.paid},
|
**{"paid": charge.paid},
|
||||||
|
Reference in New Issue
Block a user