Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add card balance on public page #43

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
},
)