From 4884caaf16c89543a5de40a97d9679f32641104d Mon Sep 17 00:00:00 2001 From: Tiago Vasconcelos Date: Wed, 13 Nov 2024 11:10:10 +0000 Subject: [PATCH 1/2] add card balance on public page --- templates/boltcards/display.html | 11 +++++++++-- views.py | 14 +++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/templates/boltcards/display.html b/templates/boltcards/display.html index 20fde95..bc23b3e 100644 --- a/templates/boltcards/display.html +++ b/templates/boltcards/display.html @@ -5,6 +5,10 @@
Card Info
+
+ Balance: + sats +
This card is ${enabled}
@@ -89,6 +93,7 @@ data() { return { card: null, + balance: 0, hits: null, cardInfo: [ { @@ -119,11 +124,13 @@ } }, created() { - this.card = JSON.parse({{ card | tojson }}) const hits = {{ hits | tojson | safe }} - this.hits = hits.map(JSON.parse).map(mapHits) const refunds = {{ refunds | tojson | safe }} + const balance = {{ balance }} + this.card = JSON.parse({{ card | tojson }}) + this.hits = hits.map(JSON.parse).map(mapHits) this.refunds = refunds || [] + this.balance = LNbits.utils.formatSat(balance) }, computed: { enabled() { diff --git a/views.py b/views.py index dea7a4c..f4ee551 100644 --- a/views.py +++ b/views.py @@ -2,6 +2,8 @@ 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 +31,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), + }, ) From 72c19339b113d56bcdd807cf2301d1ee43ed4c10 Mon Sep 17 00:00:00 2001 From: Tiago Vasconcelos Date: Wed, 13 Nov 2024 11:13:33 +0000 Subject: [PATCH 2/2] lint --- views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/views.py b/views.py index f4ee551..baf9a8d 100644 --- a/views.py +++ b/views.py @@ -2,7 +2,6 @@ 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