refactor: remove extra state fields

This commit is contained in:
Vlad Stan 2022-07-07 11:06:41 +03:00
parent 74322232d0
commit 09a9a0f9ec

View File

@ -18,7 +18,7 @@
class="col" class="col"
color="white" color="white"
style="background-color: grey; height: 30px; padding: 5px" style="background-color: grey; height: 30px; padding: 5px"
v-else-if="charge_paid == 'True'" v-else-if="charge.paid"
> >
<center>Charge paid</center> <center>Charge paid</center>
</div> </div>
@ -46,10 +46,10 @@
</center> </center>
<span <span
><small ><small
>{% raw %} Total to pay: {{ charge_amount }}sats<br /> >{% raw %} Total to pay: {{ charge.amount }}sats<br />
Amount paid: {{ charge_balance }}</small Amount paid: {{ charge.balance }}</small
><br /> ><br />
Amount due: {{ charge_amount - charge_balance }}sats {% endraw %} Amount due: {{ charge.amount - charge.balance }}sats {% endraw %}
</span> </span>
</div> </div>
<q-separator></q-separator> <q-separator></q-separator>
@ -59,7 +59,7 @@
<q-btn <q-btn
flat flat
disable disable
v-if="'{{ charge.lnbitswallet }}' == 'None' || charge_time_elapsed == 'True'" v-if="!charge.lnbitswallet || charge.time_elapsed"
style="color: primary; width: 100%" style="color: primary; width: 100%"
label="lightning⚡" label="lightning⚡"
> >
@ -81,7 +81,7 @@
<q-btn <q-btn
flat flat
disable disable
v-if="'{{ charge.onchainwallet }}' == 'None' || charge_time_elapsed == 'True'" v-if="!charge.onchainwallet || charge.time_elapsed"
style="color: primary; width: 100%" style="color: primary; width: 100%"
label="onchain⛓" label="onchain⛓"
> >
@ -106,13 +106,13 @@
<q-card class="q-pa-lg" v-if="lnbtc"> <q-card class="q-pa-lg" v-if="lnbtc">
<q-card-section class="q-pa-none"> <q-card-section class="q-pa-none">
<div class="text-center q-pt-md"> <div class="text-center q-pt-md">
<div v-if="timetoComplete < 1 && charge_paid == 'False'"> <div v-if="timetoComplete < 1 && !charge.paid">
<q-icon <q-icon
name="block" name="block"
style="color: #ccc; font-size: 21.4em" style="color: #ccc; font-size: 21.4em"
></q-icon> ></q-icon>
</div> </div>
<div v-else-if="charge_paid == 'True'"> <div v-else-if="charge.paid">
<q-icon <q-icon
name="check" name="check"
style="color: green; font-size: 21.4em" style="color: green; font-size: 21.4em"
@ -156,13 +156,13 @@
<q-card class="q-pa-lg" v-if="onbtc"> <q-card class="q-pa-lg" v-if="onbtc">
<q-card-section class="q-pa-none"> <q-card-section class="q-pa-none">
<div class="text-center q-pt-md"> <div class="text-center q-pt-md">
<div v-if="timetoComplete < 1 && charge_paid == 'False'"> <div v-if="timetoComplete < 1 && !charge.paid">
<q-icon <q-icon
name="block" name="block"
style="color: #ccc; font-size: 21.4em" style="color: #ccc; font-size: 21.4em"
></q-icon> ></q-icon>
</div> </div>
<div v-else-if="charge_paid == 'True'"> <div v-else-if="charge.paid">
<q-icon <q-icon
name="check" name="check"
style="color: green; font-size: 21.4em" style="color: green; font-size: 21.4em"
@ -233,10 +233,6 @@
timetoComplete: 100, timetoComplete: 100,
lnbtc: true, lnbtc: true,
onbtc: false, onbtc: false,
charge_time_elapsed: '{{charge.time_elapsed}}',
charge_amount: '{{charge.amount}}',
charge_balance: '{{charge.balance}}',
charge_paid: '{{charge.paid}}',
wallet: { wallet: {
inkey: '' inkey: ''
}, },
@ -254,25 +250,27 @@
} }
) )
}, },
checkBalance: function () { checkBalance: async function () {
var self = this try {
LNbits.api const {data} = await LNbits.api
.request( .request(
'GET', 'GET',
`/satspay/api/v1/charges/balance/${this.charge.id}`, `/satspay/api/v1/charges/balance/${this.charge.id}`,
'filla' 'filla'
) )
.then(function (response) {
self.charge_time_elapsed = response.data.time_elapsed this.charge.time_elapsed = data.time_elapsed
self.charge_amount = response.data.amount this.charge.amount = data.amount
self.charge_balance = response.data.balance this.charge.balance = data.balance
if (self.charge_balance >= self.charge_amount) { if (this.charge.balance >= this.charge.amount) {
self.charge_paid = 'True' this.charge.paid = true
} }
}) } catch (error) {
.catch(function (error) { LNbits.utils.notifyApiError(error)
LNbits.utils.notifyApiError(error) }
})
}, },
payLN: function () { payLN: function () {
this.lnbtc = true this.lnbtc = true
@ -304,7 +302,7 @@
timerCount: function () { timerCount: function () {
self = this self = this
var refreshIntervalId = setInterval(function () { var refreshIntervalId = setInterval(function () {
if (self.charge_paid == 'True' || self.timetoComplete < 1) { if (self.charge.paid|| self.timetoComplete < 1) {
clearInterval(refreshIntervalId) clearInterval(refreshIntervalId)
} }
self.getTheTime() self.getTheTime()
@ -327,7 +325,7 @@
this.getTheTime() this.getTheTime()
this.getThePercentage() this.getThePercentage()
var timerCount = this.timerCount var timerCount = this.timerCount
if ('{{ charge.paid }}' == 'False') { if (!this.charge.paid) {
timerCount() timerCount()
} }
this.startPaymentNotifier() this.startPaymentNotifier()