add card balance on public page (#43)

* add card balance on public page
* lint
This commit is contained in:
Tiago Vasconcelos 2024-11-25 11:20:11 +00:00 committed by GitHub
commit 173776d48e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 3 deletions

View file

@ -2,6 +2,7 @@ from http import HTTPStatus
from fastapi import APIRouter, Depends, HTTPException, Request
from fastapi.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.helpers import template_renderer
@ -29,11 +30,21 @@ async def display(request: Request, card_id: str):
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="Card does not exist."
)
wallet = await get_wallet(card.wallet)
wallet_balance = 0
if wallet:
wallet_balance = wallet.balance
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_json, "hits": hits_json, "refunds": refunds},
{
"request": request,
"card": card_json,
"hits": hits_json,
"refunds": refunds,
"balance": int(wallet_balance),
},
)