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

@ -5,6 +5,10 @@ card.card_name }{% endblock %} {% block page %}
<q-card> <q-card>
<q-card-section> <q-card-section>
<div class="text-h6">Card Info</div> <div class="text-h6">Card Info</div>
<div class="text-subtitle2">
<b>Balance: </b>
<span v-text="balance"></span> sats
</div>
<div class="text-subtitle2">This card is ${enabled}</div> <div class="text-subtitle2">This card is ${enabled}</div>
</q-card-section> </q-card-section>
@ -89,6 +93,7 @@ card.card_name }{% endblock %} {% block page %}
data() { data() {
return { return {
card: null, card: null,
balance: 0,
hits: null, hits: null,
cardInfo: [ cardInfo: [
{ {
@ -119,11 +124,13 @@ card.card_name }{% endblock %} {% block page %}
} }
}, },
created() { created() {
this.card = JSON.parse({{ card | tojson }})
const hits = {{ hits | tojson | safe }} const hits = {{ hits | tojson | safe }}
this.hits = hits.map(JSON.parse).map(mapHits)
const refunds = {{ refunds | tojson | safe }} 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.refunds = refunds || []
this.balance = LNbits.utils.formatSat(balance)
}, },
computed: { computed: {
enabled() { enabled() {

View file

@ -2,6 +2,7 @@ from http import HTTPStatus
from fastapi import APIRouter, Depends, HTTPException, Request from fastapi import APIRouter, Depends, HTTPException, Request
from fastapi.responses import HTMLResponse from fastapi.responses import HTMLResponse
from lnbits.core.crud import get_wallet
from lnbits.core.models import User from lnbits.core.models import User
from lnbits.decorators import check_user_exists from lnbits.decorators import check_user_exists
from lnbits.helpers import template_renderer from lnbits.helpers import template_renderer
@ -29,11 +30,21 @@ async def display(request: Request, card_id: str):
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="Card does not exist." 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 = await get_hits([card.id])
hits_json = [hit.json() for hit in hits] hits_json = [hit.json() for hit in hits]
refunds = [refund.hit_id for refund in await get_refunds([hit.id 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"}) card_json = card.json(exclude={"wallet"})
return boltcards_renderer().TemplateResponse( return boltcards_renderer().TemplateResponse(
"boltcards/display.html", "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),
},
) )