2021-11-25 18:52:16 +00:00
|
|
|
from http import HTTPStatus
|
|
|
|
|
2021-10-14 11:45:56 +01:00
|
|
|
from fastapi.param_functions import Depends
|
2021-11-25 18:52:16 +00:00
|
|
|
from fastapi.templating import Jinja2Templates
|
2021-10-14 11:45:56 +01:00
|
|
|
from starlette.exceptions import HTTPException
|
2021-10-14 22:30:29 +01:00
|
|
|
from starlette.requests import Request
|
2021-11-25 18:52:16 +00:00
|
|
|
from starlette.responses import HTMLResponse
|
|
|
|
|
2021-12-29 12:57:43 +00:00
|
|
|
from lnbits.core.crud import get_wallet
|
2021-10-14 11:45:56 +01:00
|
|
|
from lnbits.core.models import User
|
|
|
|
from lnbits.decorators import check_user_exists
|
2021-10-14 10:02:02 +01:00
|
|
|
|
2021-10-14 11:45:56 +01:00
|
|
|
from . import satspay_ext, satspay_renderer
|
2022-10-20 17:40:23 +03:00
|
|
|
from .crud import get_charge, get_charge_config
|
2021-10-14 10:02:02 +01:00
|
|
|
|
2021-10-14 11:45:56 +01:00
|
|
|
templates = Jinja2Templates(directory="templates")
|
2021-10-14 10:02:02 +01:00
|
|
|
|
2021-10-17 18:33:29 +01:00
|
|
|
|
2021-10-14 11:45:56 +01:00
|
|
|
@satspay_ext.get("/", response_class=HTMLResponse)
|
|
|
|
async def index(request: Request, user: User = Depends(check_user_exists)):
|
2021-10-17 18:33:29 +01:00
|
|
|
return satspay_renderer().TemplateResponse(
|
|
|
|
"satspay/index.html", {"request": request, "user": user.dict()}
|
|
|
|
)
|
2021-10-14 10:02:02 +01:00
|
|
|
|
|
|
|
|
2021-10-14 11:45:56 +01:00
|
|
|
@satspay_ext.get("/{charge_id}", response_class=HTMLResponse)
|
2022-07-06 11:35:11 +03:00
|
|
|
async def display(request: Request, charge_id: str):
|
2021-10-14 11:45:56 +01:00
|
|
|
charge = await get_charge(charge_id)
|
|
|
|
if not charge:
|
|
|
|
raise HTTPException(
|
2021-10-17 18:33:29 +01:00
|
|
|
status_code=HTTPStatus.NOT_FOUND, detail="Charge link does not exist."
|
2021-10-14 11:45:56 +01:00
|
|
|
)
|
2021-12-29 12:57:43 +00:00
|
|
|
wallet = await get_wallet(charge.lnbitswallet)
|
2022-10-20 17:40:23 +03:00
|
|
|
onchainwallet_config = await get_charge_config(charge_id)
|
2022-07-06 11:35:11 +03:00
|
|
|
inkey = wallet.inkey if wallet else None
|
2022-08-02 15:16:32 +01:00
|
|
|
mempool_endpoint = (
|
|
|
|
onchainwallet_config.mempool_endpoint if onchainwallet_config else None
|
|
|
|
)
|
2021-10-17 18:33:29 +01:00
|
|
|
return satspay_renderer().TemplateResponse(
|
2022-01-30 19:43:30 +00:00
|
|
|
"satspay/display.html",
|
2022-07-08 16:37:35 +03:00
|
|
|
{
|
|
|
|
"request": request,
|
|
|
|
"charge_data": charge.dict(),
|
|
|
|
"wallet_inkey": inkey,
|
2022-08-02 15:16:32 +01:00
|
|
|
"mempool_endpoint": mempool_endpoint,
|
2022-07-08 16:37:35 +03:00
|
|
|
},
|
2021-10-17 18:33:29 +01:00
|
|
|
)
|