Adding frontend page

This commit is contained in:
ben 2022-09-26 10:30:48 +01:00
parent f4439974e4
commit 69c7cdb49f
7 changed files with 85 additions and 29 deletions

View file

@ -10,8 +10,8 @@ async def create_gerty(wallet_id: str, data: Gerty) -> Gerty:
gerty_id = urlsafe_short_hash() gerty_id = urlsafe_short_hash()
await db.execute( await db.execute(
""" """
INSERT INTO gerty.gertys (id, name, wallet, lnbits_wallets, sats_quote, exchange, onchain_sats, ln_stats) INSERT INTO gerty.gertys (id, name, wallet, lnbits_wallets, sats_quote, exchange, onchain_stats, ln_stats)
VALUES (?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
""", """,
( (
gerty_id, gerty_id,

View file

@ -6,12 +6,13 @@ async def m001_initial(db):
""" """
CREATE TABLE gerty.gertys ( CREATE TABLE gerty.gertys (
id TEXT PRIMARY KEY, id TEXT PRIMARY KEY,
name TEXT NOT NULL,
wallet TEXT NOT NULL, wallet TEXT NOT NULL,
lnbits_wallets TEXT NOT NULL, lnbits_wallets TEXT,
sats_quote BOOL NOT NULL, sats_quote BOOL,
exchange TEXT NOT NULL, exchange TEXT,
onchain_sats BOOL NOT NULL, onchain_stats BOOL,
ln_stats BOOL NOT NULL ln_stats BOOL
); );
""" """
) )

View file

@ -7,10 +7,10 @@ from pydantic import BaseModel
class Gerty(BaseModel): class Gerty(BaseModel):
id: str id: str = Query(None)
name: str name: str
wallet: str wallet: str
lnbits_wallets: str # Wallets to keep an eye on, {"wallet-id": "wallet-read-key, etc"} lnbits_wallets: str = Query(None) # Wallets to keep an eye on, {"wallet-id": "wallet-read-key, etc"}
sats_quote: bool = Query(False) # Fetch Satoshi quotes sats_quote: bool = Query(False) # Fetch Satoshi quotes
exchange: str = Query(None) # BTC <-> Fiat exchange rate to pull ie "USD", in 0.0001 and sats exchange: str = Query(None) # BTC <-> Fiat exchange rate to pull ie "USD", in 0.0001 and sats
onchain_sats: bool = Query(False) # Onchain stats onchain_sats: bool = Query(False) # Onchain stats

View file

@ -0,0 +1,54 @@
{% extends "public.html" %} {% block page %}
<div class="row q-col-gutter-md justify-center">
<div class="col-12 col-sm-6 col-md-5 col-lg-4">
<q-card class="q-pa-lg">
<q-card-section class="q-pa-none">
<div class="text-center">
<a href="lightning:{{ lnurl }}">
<q-responsive :ratio="1" class="q-mx-md">
<qrcode
value="{{ lnurl }}"
:options="{width: 800}"
class="rounded-borders"
></qrcode>
</q-responsive>
</a>
</div>
<div class="row q-mt-lg q-gutter-sm">
<q-btn outline color="grey" @click="copyText('{{ lnurl }}')"
>Copy LNURL</q-btn
>
<q-btn
outline
color="grey"
icon="nfc"
@click="writeNfcTag(' {{ lnurl }} ')"
:disable="nfcTagWriting"
></q-btn>
</div>
</q-card-section>
</q-card>
</div>
<div class="col-12 col-sm-6 col-md-5 col-lg-4 q-gutter-y-md">
<q-card>
<q-card-section>
<h6 class="text-subtitle1 q-mb-sm q-mt-none">Gerty</h6>
<p class="q-my-none">Use an LNURL compatible bitcoin wallet to pay.</p>
</q-card-section>
<q-card-section class="q-pa-none">
<q-separator></q-separator>
<q-list> {% include "lnurlp/_lnurl.html" %} </q-list>
</q-card-section>
</q-card>
</div>
</div>
{% endblock %} {% block scripts %}
<script>
Vue.component(VueQrcode.name, VueQrcode)
new Vue({
el: '#vue',
mixins: [windowMixin]
})
</script>
{% endblock %}

View file

@ -9,7 +9,6 @@
> >
</q-card-section> </q-card-section>
</q-card> </q-card>
<q-card> <q-card>
<q-card-section> <q-card-section>
<div class="row items-center no-wrap q-mb-md"> <div class="row items-center no-wrap q-mb-md">
@ -137,7 +136,7 @@
<q-btn <q-btn
unelevated unelevated
color="primary" color="primary"
:disable="formDialog.data.walletOptions == null || formDialog.data.name == null" :disable="formDialog.data.wallet == null || formDialog.data.name == null"
type="submit" type="submit"
>Create Gerty</q-btn >Create Gerty</q-btn
> >
@ -383,7 +382,7 @@
formDialog: { formDialog: {
show: false, show: false,
data: {sats_quote: false, data: {sats_quote: false,
onchain_sats: false, onchain_stats: false,
ln_stats: false} ln_stats: false}
} }
} }
@ -396,11 +395,10 @@
}, },
getGertys: function () { getGertys: function () {
var self = this var self = this
LNbits.api LNbits.api
.request( .request(
'GET', 'GET',
'/gerty/api/v1/gertys?all_wallets=true', '/gerty/api/v1/gerty?all_wallets=true',
this.g.user.wallets[0].inkey this.g.user.wallets[0].inkey
) )
.then(function (response) { .then(function (response) {
@ -412,20 +410,19 @@
createGerty: function () { createGerty: function () {
var data = { var data = {
name: this.formDialog.data.name, name: this.formDialog.data.name,
currency: this.formDialog.data.currency, wallet: this.formDialog.data.wallet,
tip_options: this.formDialog.data.tip_options lnbits_wallets: this.formDialog.data.lnbits_wallets,
? JSON.stringify( sats_quote: this.formDialog.data.sats_quote,
this.formDialog.data.tip_options.map(str => parseInt(str)) exchange: this.formDialog.data.exchange,
) onchain_sats: this.formDialog.data.onchain_sats,
: JSON.stringify([]), ln_stats: this.formDialog.data.ln_stats
tip_wallet: this.formDialog.data.tip_wallet || ''
} }
var self = this var self = this
LNbits.api LNbits.api
.request( .request(
'POST', 'POST',
'/gerty/api/v1/gertys', '/gerty/api/v1/gerty',
_.findWhere(this.g.user.wallets, {id: this.formDialog.data.wallet}) _.findWhere(this.g.user.wallets, {id: this.formDialog.data.wallet})
.inkey, .inkey,
data data
@ -448,7 +445,7 @@
LNbits.api LNbits.api
.request( .request(
'DELETE', 'DELETE',
'/gerty/api/v1/gertys/' + gertyId, '/gerty/api/v1/gerty/' + gertyId,
_.findWhere(self.g.user.wallets, {id: gerty.wallet}).adminkey _.findWhere(self.g.user.wallets, {id: gerty.wallet}).adminkey
) )
.then(function (response) { .then(function (response) {

View file

@ -21,3 +21,11 @@ async def index(request: Request, user: User = Depends(check_user_exists)):
"gerty/index.html", {"request": request, "user": user.dict()} "gerty/index.html", {"request": request, "user": user.dict()}
) )
@gerty_ext.get("/{gerty_id}", response_class=HTMLResponse)
async def display(request: Request, gerty_id):
gerty = await get_gerty(gerty_id)
if not gerty:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="Gerty does not exist."
)
return lnurlp_renderer().TemplateResponse("gerty/gerty.html", ctx)

View file

@ -91,18 +91,14 @@ async def api_gerty_satoshi():
@gerty_ext.get("/api/v1/gerty/{gerty_id}") @gerty_ext.get("/api/v1/gerty/{gerty_id}")
async def api_gerty_json( async def api_gerty_json(
gerty_id: str, wallet: WalletTypeInfo = Depends(require_admin_key) gerty_id: str
): ):
gerty = await get_gerty(gerty_id) gerty = await get_gerty(gerty_id)
logger.debug(gerty.wallet)
if not gerty: if not gerty:
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="Gerty does not exist." status_code=HTTPStatus.NOT_FOUND, detail="Gerty does not exist."
) )
if gerty.wallet != wallet.wallet.id:
raise HTTPException(
status_code=HTTPStatus.FORBIDDEN,
detail="Come on, seriously, this isn't your Gerty!",
)
gertyReturn = [] gertyReturn = []
if gerty.lnbits_wallets != "": if gerty.lnbits_wallets != "":
gertyReturn.append(gerty.lnbitsWallets) gertyReturn.append(gerty.lnbitsWallets)