feat: update to lnbits 1.0.0 (#41)

---------

Co-authored-by: Pavol Rusnak <pavol@rusnak.io>
This commit is contained in:
dni ⚡ 2024-10-23 15:45:23 +02:00 committed by GitHub
commit 7f8b269ecd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 1513 additions and 1457 deletions

View file

@ -1,16 +1,13 @@
from http import HTTPStatus
from fastapi import APIRouter, Depends, Request
from fastapi.templating import Jinja2Templates
from fastapi import APIRouter, Depends, HTTPException, Request
from fastapi.responses import HTMLResponse
from lnbits.core.models import User
from lnbits.decorators import check_user_exists
from lnbits.helpers import template_renderer
from starlette.exceptions import HTTPException
from starlette.responses import HTMLResponse
from .crud import get_card_by_external_id, get_hits, get_refunds
templates = Jinja2Templates(directory="templates")
boltcards_generic_router = APIRouter()
@ -21,7 +18,7 @@ def boltcards_renderer():
@boltcards_generic_router.get("/", response_class=HTMLResponse)
async def index(request: Request, user: User = Depends(check_user_exists)):
return boltcards_renderer().TemplateResponse(
"boltcards/index.html", {"request": request, "user": user.dict()}
"boltcards/index.html", {"request": request, "user": user.json()}
)
@ -32,15 +29,11 @@ async def display(request: Request, card_id: str):
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="Card does not exist."
)
hits = [hit.dict() for hit in await get_hits([card.id])]
refunds = [
refund.hit_id for refund in await get_refunds([hit["id"] for hit in hits])
]
card_dict = card.dict()
# Remove wallet id from card dict
del card_dict["wallet"]
hits = await get_hits([card.id])
hits_json = [hit.json() for hit in hits]
refunds = [refund.hit_id for refund in await get_refunds([hit.id for hit in hits])]
card_json = card.json(exclude={"wallet"})
return boltcards_renderer().TemplateResponse(
"boltcards/display.html",
{"request": request, "card": card_dict, "hits": hits, "refunds": refunds},
{"request": request, "card": card_json, "hits": hits_json, "refunds": refunds},
)