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..baf9a8d 100644
--- a/views.py
+++ b/views.py
@@ -2,6 +2,7 @@
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),
+ },
)