TPoS now theme dependent

This commit is contained in:
benarc
2022-04-20 10:42:55 +01:00
parent d1d252210c
commit 1874d7fd54

View File

@ -1,5 +1,4 @@
{% extends "public.html" %} {% block toolbar_title %}{{ tpos.name }}{% endblock {% extends "public.html" %} {% block toolbar_title %}{{ tpos.name }}{% endblock %} {% block footer %}{% endblock %} {% block page_container %}
%} {% block footer %}{% endblock %} {% block page_container %}
<q-page-container> <q-page-container>
<q-page> <q-page>
<q-page-sticky v-if="exchangeRate" expand position="top"> <q-page-sticky v-if="exchangeRate" expand position="top">
@ -16,86 +15,28 @@
<div class="row justify-center full-width"> <div class="row justify-center full-width">
<div class="col-12 col-sm-8 col-md-6 col-lg-4"> <div class="col-12 col-sm-8 col-md-6 col-lg-4">
<div class="keypad q-pa-sm"> <div class="keypad q-pa-sm">
<q-btn unelevated @click="stack.push(1)" size="xl" color="grey-8" <q-btn unelevated @click="stack.push(1)" size="xl" :outline="!($q.dark.isActive)" rounded color="primary">1</q-btn>
>1</q-btn <q-btn unelevated @click="stack.push(2)" size="xl" :outline="!($q.dark.isActive)" rounded color="primary">2</q-btn>
> <q-btn unelevated @click="stack.push(3)" size="xl" :outline="!($q.dark.isActive)" rounded color="primary">3</q-btn>
<q-btn unelevated @click="stack.push(2)" size="xl" color="grey-8" <q-btn unelevated @click="stack = []" size="xl" :outline="!($q.dark.isActive)" rounded color="primary" class="btn-cancel">C</q-btn>
>2</q-btn <q-btn unelevated @click="stack.push(4)" size="xl" :outline="!($q.dark.isActive)" rounded color="primary">4</q-btn>
> <q-btn unelevated @click="stack.push(5)" size="xl" :outline="!($q.dark.isActive)" rounded color="primary">5</q-btn>
<q-btn unelevated @click="stack.push(3)" size="xl" color="grey-8" <q-btn unelevated @click="stack.push(6)" size="xl" :outline="!($q.dark.isActive)" rounded color="primary">6</q-btn>
>3</q-btn <q-btn unelevated @click="stack.push(7)" size="xl" :outline="!($q.dark.isActive)" rounded color="primary">7</q-btn>
> <q-btn unelevated @click="stack.push(8)" size="xl" :outline="!($q.dark.isActive)" rounded color="primary">8</q-btn>
<q-btn <q-btn unelevated @click="stack.push(9)" size="xl" :outline="!($q.dark.isActive)" rounded color="primary">9</q-btn>
unelevated <q-btn unelevated :disabled="amount == 0" @click="showInvoice()" size="xl" :outline="!($q.dark.isActive)" rounded color="primary" class="btn-confirm">OK</q-btn>
@click="stack = []" <q-btn unelevated @click="stack.splice(-1, 1)" size="xl" :outline="!($q.dark.isActive)" rounded color="primary">DEL</q-btn>
size="xl" <q-btn unelevated @click="stack.push(0)" size="xl" :outline="!($q.dark.isActive)" rounded color="primary">0</q-btn>
color="pink" <q-btn unelevated @click="urlDialog.show = true" size="xl" :outline="!($q.dark.isActive)" rounded color="primary">#</q-btn>
class="btn-cancel"
>C</q-btn
>
<q-btn unelevated @click="stack.push(4)" size="xl" color="grey-8"
>4</q-btn
>
<q-btn unelevated @click="stack.push(5)" size="xl" color="grey-8"
>5</q-btn
>
<q-btn unelevated @click="stack.push(6)" size="xl" color="grey-8"
>6</q-btn
>
<q-btn unelevated @click="stack.push(7)" size="xl" color="grey-8"
>7</q-btn
>
<q-btn unelevated @click="stack.push(8)" size="xl" color="grey-8"
>8</q-btn
>
<q-btn unelevated @click="stack.push(9)" size="xl" color="grey-8"
>9</q-btn
>
<q-btn
unelevated
:disabled="amount == 0"
@click="showInvoice()"
size="xl"
color="green"
class="btn-confirm"
>OK</q-btn
>
<q-btn
unelevated
@click="stack.splice(-1, 1)"
size="xl"
color="grey-7"
>DEL</q-btn
>
<q-btn unelevated @click="stack.push(0)" size="xl" color="grey-8"
>0</q-btn
>
<q-btn
unelevated
@click="urlDialog.show = true"
size="xl"
color="grey-7"
>#</q-btn
>
</div> </div>
</div> </div>
</div> </div>
</q-page-sticky> </q-page-sticky>
<q-dialog <q-dialog v-model="invoiceDialog.show" position="top" @hide="closeInvoiceDialog">
v-model="invoiceDialog.show" <q-card v-if="invoiceDialog.data" class="q-pa-lg q-pt-xl lnbits__dialog-card">
position="top"
@hide="closeInvoiceDialog"
>
<q-card
v-if="invoiceDialog.data"
class="q-pa-lg q-pt-xl lnbits__dialog-card"
>
<q-responsive :ratio="1" class="q-mx-xl q-mb-md"> <q-responsive :ratio="1" class="q-mx-xl q-mb-md">
<qrcode <qrcode :value="invoiceDialog.data.payment_request" :options="{width: 800}" class="rounded-borders"></qrcode>
:value="invoiceDialog.data.payment_request"
:options="{width: 800}"
class="rounded-borders"
></qrcode>
</q-responsive> </q-responsive>
<div class="text-center"> <div class="text-center">
<h3 class="q-my-md">{% raw %}{{ famount }}{% endraw %}</h3> <h3 class="q-my-md">{% raw %}{{ famount }}{% endraw %}</h3>
@ -111,11 +52,7 @@
<q-dialog v-model="urlDialog.show" position="top"> <q-dialog v-model="urlDialog.show" position="top">
<q-card class="q-pa-lg q-pt-xl lnbits__dialog-card"> <q-card class="q-pa-lg q-pt-xl lnbits__dialog-card">
<q-responsive :ratio="1" class="q-mx-xl q-mb-md"> <q-responsive :ratio="1" class="q-mx-xl q-mb-md">
<qrcode <qrcode value="{{ request.url }}" :options="{width: 800}" class="rounded-borders"></qrcode>
value="{{ request.url }}"
:options="{width: 800}"
class="rounded-borders"
></qrcode>
</q-responsive> </q-responsive>
<div class="text-center q-mb-xl"> <div class="text-center q-mb-xl">
<p style="word-break: break-all"> <p style="word-break: break-all">
@ -123,25 +60,15 @@
</p> </p>
</div> </div>
<div class="row q-mt-lg"> <div class="row q-mt-lg">
<q-btn <q-btn outline color="grey" @click="copyText('{{ request.url }}', 'TPoS URL copied to clipboard!')">Copy URL</q-btn>
outline
color="grey"
@click="copyText('{{ request.url }}', 'TPoS URL copied to clipboard!')"
>Copy URL</q-btn
>
<q-btn v-close-popup flat color="grey" class="q-ml-auto">Close</q-btn> <q-btn v-close-popup flat color="grey" class="q-ml-auto">Close</q-btn>
</div> </div>
</q-card> </q-card>
</q-dialog> </q-dialog>
<q-dialog v-model="complete.show" position="top"> <q-dialog v-model="complete.show" position="top">
<q-icon <q-icon name="check" transition-show="fade" class="text-light-green" style="font-size: 40em"></q-icon>
name="check" </q-dialog>
transition-show="fade"
class="text-light-green"
style="font-size: 40em"
></q-icon
></q-dialog>
</q-page> </q-page>
</q-page-container> </q-page-container>
{% endblock %} {% block styles %} {% endblock %} {% block styles %}
@ -152,9 +79,11 @@
grid-template-columns: repeat(4, 1fr); grid-template-columns: repeat(4, 1fr);
grid-template-rows: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr);
} }
.keypad .btn { .keypad .btn {
height: 100%; height: 100%;
} }
.btn-cancel, .btn-cancel,
.btn-confirm { .btn-confirm {
grid-row: auto/span 2; grid-row: auto/span 2;
@ -167,7 +96,7 @@
new Vue({ new Vue({
el: '#vue', el: '#vue',
mixins: [windowMixin], mixins: [windowMixin],
data: function () { data: function() {
return { return {
tposId: '{{ tpos.id }}', tposId: '{{ tpos.id }}',
currency: '{{ tpos.currency }}', currency: '{{ tpos.currency }}',
@ -188,32 +117,32 @@
} }
}, },
computed: { computed: {
amount: function () { amount: function() {
if (!this.stack.length) return 0.0 if (!this.stack.length) return 0.0
return (Number(this.stack.join('')) / 100).toFixed(2) return (Number(this.stack.join('')) / 100).toFixed(2)
}, },
famount: function () { famount: function() {
return LNbits.utils.formatCurrency(this.amount, this.currency) return LNbits.utils.formatCurrency(this.amount, this.currency)
}, },
sat: function () { sat: function() {
if (!this.exchangeRate) return 0 if (!this.exchangeRate) return 0
return Math.ceil((this.amount / this.exchangeRate) * 100000000) return Math.ceil((this.amount / this.exchangeRate) * 100000000)
}, },
fsat: function () { fsat: function() {
console.log('sat', this.sat, LNbits.utils.formatSat(this.sat)) console.log('sat', this.sat, LNbits.utils.formatSat(this.sat))
return LNbits.utils.formatSat(this.sat) return LNbits.utils.formatSat(this.sat)
} }
}, },
methods: { methods: {
closeInvoiceDialog: function () { closeInvoiceDialog: function() {
this.stack = [] this.stack = []
var dialog = this.invoiceDialog var dialog = this.invoiceDialog
setTimeout(function () { setTimeout(function() {
clearInterval(dialog.paymentChecker) clearInterval(dialog.paymentChecker)
dialog.dismissMsg() dialog.dismissMsg()
}, 3000) }, 3000)
}, },
showInvoice: function () { showInvoice: function() {
var self = this var self = this
var dialog = this.invoiceDialog var dialog = this.invoiceDialog
console.log(this.sat, this.tposId) console.log(this.sat, this.tposId)
@ -223,7 +152,7 @@
amount: this.sat amount: this.sat
} }
}) })
.then(function (response) { .then(function(response) {
dialog.data = response.data dialog.data = response.data
dialog.show = true dialog.show = true
@ -232,7 +161,7 @@
message: 'Waiting for payment...' message: 'Waiting for payment...'
}) })
dialog.paymentChecker = setInterval(function () { dialog.paymentChecker = setInterval(function() {
axios axios
.get( .get(
'/tpos/api/v1/tposs/' + '/tpos/api/v1/tposs/' +
@ -240,36 +169,36 @@
'/invoices/' + '/invoices/' +
response.data.payment_hash response.data.payment_hash
) )
.then(function (res) { .then(function(res) {
if (res.data.paid) { if (res.data.paid) {
clearInterval(dialog.paymentChecker) clearInterval(dialog.paymentChecker)
dialog.dismissMsg() dialog.dismissMsg()
dialog.show = false dialog.show = false
self.complete.show = true self.complete.show = true
setTimeout(function () { setTimeout(function() {
self.complete.show = false self.complete.show = false
}, 5000) }, 5000)
} }
}) })
}, 3000) }, 3000)
}) })
.catch(function (error) { .catch(function(error) {
LNbits.utils.notifyApiError(error) LNbits.utils.notifyApiError(error)
}) })
}, },
getRates: function () { getRates: function() {
var self = this var self = this
axios.get('https://api.opennode.co/v1/rates').then(function (response) { axios.get('https://api.opennode.co/v1/rates').then(function(response) {
self.exchangeRate = self.exchangeRate =
response.data.data['BTC' + self.currency][self.currency] response.data.data['BTC' + self.currency][self.currency]
}) })
} }
}, },
created: function () { created: function() {
var getRates = this.getRates var getRates = this.getRates
getRates() getRates()
setInterval(function () { setInterval(function() {
getRates() getRates()
}, 20000) }, 20000)
} }