Skip to content

Commit

Permalink
add card balance on public page (#43)
Browse files Browse the repository at this point in the history
* add card balance on public page
* lint
  • Loading branch information
talvasconcelos authored Nov 25, 2024
1 parent 7f8b269 commit 173776d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
11 changes: 9 additions & 2 deletions templates/boltcards/display.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<q-card>
<q-card-section>
<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>
</q-card-section>

Expand Down Expand Up @@ -89,6 +93,7 @@
data() {
return {
card: null,
balance: 0,
hits: null,
cardInfo: [
{
Expand Down Expand Up @@ -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() {
Expand Down
13 changes: 12 additions & 1 deletion views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
},
)

0 comments on commit 173776d

Please sign in to comment.