mirror of
https://github.com/lnbits/lnbits.git
synced 2025-06-28 17:50:56 +02:00
fix: fix progress for charges
This commit is contained in:
parent
0f204485c3
commit
46a7b54a00
@ -13,7 +13,7 @@
|
|||||||
<div
|
<div
|
||||||
color="white"
|
color="white"
|
||||||
style="background-color: grey; height: 30px; padding: 5px"
|
style="background-color: grey; height: 30px; padding: 5px"
|
||||||
v-if="timetoComplete < 1"
|
v-if="!charge.timeLeft"
|
||||||
>
|
>
|
||||||
Time elapsed
|
Time elapsed
|
||||||
</div>
|
</div>
|
||||||
@ -25,14 +25,18 @@
|
|||||||
Charge paid
|
Charge paid
|
||||||
</div>
|
</div>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<q-linear-progress size="30px" :value="newProgress" color="grey">
|
<q-linear-progress
|
||||||
|
size="30px"
|
||||||
|
:value="charge.progress"
|
||||||
|
color="secondary"
|
||||||
|
>
|
||||||
<q-item-section>
|
<q-item-section>
|
||||||
<q-item style="padding: 3px">
|
<q-item style="padding: 3px">
|
||||||
<q-spinner color="white" size="0.8em"></q-spinner
|
<q-spinner color="white" size="0.8em"></q-spinner
|
||||||
><span style="font-size: 15px; color: white"
|
><span style="font-size: 15px; color: white"
|
||||||
><span class="q-pr-xl q-pl-md"> Awaiting payment...</span>
|
><span class="q-pr-xl q-pl-md"> Awaiting payment...</span>
|
||||||
<span class="q-pl-xl" style="color: white">
|
<span class="q-pl-xl" style="color: white">
|
||||||
{% raw %} {{ newTimeLeft }} {% endraw %}</span
|
{% raw %} {{ charge.timeLeft }} {% endraw %}</span
|
||||||
></span
|
></span
|
||||||
>
|
>
|
||||||
</q-item>
|
</q-item>
|
||||||
@ -155,7 +159,7 @@
|
|||||||
<div class="row items-center q-mt-sm">
|
<div class="row items-center q-mt-sm">
|
||||||
<div class="col-md-2 col-sm-0"></div>
|
<div class="col-md-2 col-sm-0"></div>
|
||||||
<div class="col-md-8 col-sm-12">
|
<div class="col-md-8 col-sm-12">
|
||||||
<div v-if="timetoComplete < 1 && !charge.paid">
|
<div v-if="!charge.timeLeft && !charge.paid">
|
||||||
<q-icon
|
<q-icon
|
||||||
name="block"
|
name="block"
|
||||||
style="color: #ccc; font-size: 21.4em"
|
style="color: #ccc; font-size: 21.4em"
|
||||||
@ -210,10 +214,7 @@
|
|||||||
</q-card>
|
</q-card>
|
||||||
<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
|
<div v-if="charge.timeLeft && !charge.paid" class="row items-center">
|
||||||
v-if="timetoComplete >= 0 && !charge.paid"
|
|
||||||
class="row items-center"
|
|
||||||
>
|
|
||||||
<div class="col text-center">
|
<div class="col text-center">
|
||||||
<a
|
<a
|
||||||
style="color: unset"
|
style="color: unset"
|
||||||
@ -229,7 +230,7 @@
|
|||||||
<div class="row items-center q-mt-md">
|
<div class="row items-center q-mt-md">
|
||||||
<div class="col-md-2 col-sm-0"></div>
|
<div class="col-md-2 col-sm-0"></div>
|
||||||
<div class="col-md-8 col-sm-12 text-center">
|
<div class="col-md-8 col-sm-12 text-center">
|
||||||
<div v-if="timetoComplete < 1 && !charge.paid">
|
<div v-if="!charge.timeLeft && !charge.paid">
|
||||||
<q-icon
|
<q-icon
|
||||||
name="block"
|
name="block"
|
||||||
style="color: #ccc; font-size: 21.4em"
|
style="color: #ccc; font-size: 21.4em"
|
||||||
@ -307,8 +308,6 @@
|
|||||||
ws: null,
|
ws: null,
|
||||||
newProgress: 0.4,
|
newProgress: 0.4,
|
||||||
counter: 1,
|
counter: 1,
|
||||||
newTimeLeft: '',
|
|
||||||
timetoComplete: 100,
|
|
||||||
lnbtc: true,
|
lnbtc: true,
|
||||||
onbtc: false,
|
onbtc: false,
|
||||||
wallet: {
|
wallet: {
|
||||||
@ -329,19 +328,25 @@
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
checkBalances: async function () {
|
checkBalances: async function () {
|
||||||
if (!this.charge.hasStaleBalance) return
|
if (!this.charge.hasStaleBalance) await this.refreshCharge()
|
||||||
try {
|
try {
|
||||||
const {data} = await LNbits.api.request(
|
const {data} = await LNbits.api.request(
|
||||||
'GET',
|
'GET',
|
||||||
`/satspay/api/v1/charge/balance/${this.charge.id}`,
|
`/satspay/api/v1/charge/balance/${this.charge.id}`
|
||||||
'filla'
|
|
||||||
)
|
)
|
||||||
this.charge.time_elapsed = data.time_elapsed
|
this.charge = mapCharge(data, this.charge)
|
||||||
this.charge.amount = data.amount
|
} catch (error) {
|
||||||
this.charge.balance = data.balance
|
LNbits.utils.notifyApiError(error)
|
||||||
if (this.charge.balance >= this.charge.amount) {
|
|
||||||
this.charge.paid = true
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
refreshCharge: async function () {
|
||||||
|
try {
|
||||||
|
const {data} = await LNbits.api.request(
|
||||||
|
'GET',
|
||||||
|
`/satspay/api/v1/charge/${this.charge.id}`
|
||||||
|
)
|
||||||
|
this.charge = mapCharge(data, this.charge)
|
||||||
|
console.log('### ', this.charge)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
LNbits.utils.notifyApiError(error)
|
LNbits.utils.notifyApiError(error)
|
||||||
}
|
}
|
||||||
@ -375,28 +380,13 @@
|
|||||||
this.lnbtc = false
|
this.lnbtc = false
|
||||||
this.onbtc = true
|
this.onbtc = true
|
||||||
},
|
},
|
||||||
refreshExpirationTime: function () {
|
|
||||||
this.timetoComplete =
|
|
||||||
parseInt(this.charge.time) * 60 -
|
|
||||||
(Date.now() / 1000 - parseInt(this.charge.timestamp))
|
|
||||||
|
|
||||||
this.newTimeLeft = Quasar.utils.date.formatDate(
|
|
||||||
new Date((this.timeToComplete - 3600) * 1000),
|
|
||||||
'HH:mm:ss'
|
|
||||||
)
|
|
||||||
},
|
|
||||||
refreshProgres: function () {
|
|
||||||
this.refreshExpirationTime()
|
|
||||||
this.newProgress =
|
|
||||||
1 - this.timeToComplete / (parseInt(this.charge.time) * 60)
|
|
||||||
},
|
|
||||||
loopRefresh: function () {
|
loopRefresh: function () {
|
||||||
// invoice only
|
// invoice only
|
||||||
const refreshIntervalId = setInterval(async () => {
|
const refreshIntervalId = setInterval(async () => {
|
||||||
if (this.charge.paid || this.timetoComplete < 1) {
|
if (this.charge.paid || !this.charge.timeLeft) {
|
||||||
clearInterval(refreshIntervalId)
|
clearInterval(refreshIntervalId)
|
||||||
}
|
}
|
||||||
this.refreshProgres()
|
|
||||||
if (this.counter % 10 === 0) {
|
if (this.counter % 10 === 0) {
|
||||||
await this.checkBalances()
|
await this.checkBalances()
|
||||||
await this.checkPendingOnchain()
|
await this.checkPendingOnchain()
|
||||||
@ -456,7 +446,6 @@
|
|||||||
this.wallet.inkey = '{{ wallet_inkey }}'
|
this.wallet.inkey = '{{ wallet_inkey }}'
|
||||||
this.startPaymentNotifier()
|
this.startPaymentNotifier()
|
||||||
|
|
||||||
this.refreshProgres()
|
|
||||||
if (!this.charge.paid) {
|
if (!this.charge.paid) {
|
||||||
this.loopRefresh()
|
this.loopRefresh()
|
||||||
}
|
}
|
||||||
|
@ -125,8 +125,13 @@
|
|||||||
>{{props.row.description}}</a
|
>{{props.row.description}}</a
|
||||||
>
|
>
|
||||||
</q-td>
|
</q-td>
|
||||||
<q-td key="timeleft" :props="props" :class="">
|
<q-td key="timeLeft" :props="props" :class="">
|
||||||
<div>{{props.row.date}}</div>
|
<div>{{props.row.timeLeft}}</div>
|
||||||
|
<q-linear-progress
|
||||||
|
:value="props.row.progress"
|
||||||
|
color="secondary"
|
||||||
|
>
|
||||||
|
</q-linear-progress>
|
||||||
</q-td>
|
</q-td>
|
||||||
<q-td key="time to pay" :props="props" :class="">
|
<q-td key="time to pay" :props="props" :class="">
|
||||||
<div>{{props.row.time}}</div>
|
<div>{{props.row.time}}</div>
|
||||||
@ -424,10 +429,10 @@
|
|||||||
field: 'description'
|
field: 'description'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'timeleft',
|
name: 'timeLeft',
|
||||||
align: 'left',
|
align: 'left',
|
||||||
label: 'Time left',
|
label: 'Time left',
|
||||||
field: 'date'
|
field: 'timeLeft'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'time to pay',
|
name: 'time to pay',
|
||||||
@ -638,7 +643,7 @@
|
|||||||
data
|
data
|
||||||
)
|
)
|
||||||
|
|
||||||
this.chargeLinks.push(mapCharge(resp.data))
|
this.chargeLinks.unshift(mapCharge(resp.data))
|
||||||
this.formDialogCharge.show = false
|
this.formDialogCharge.show = false
|
||||||
this.formDialogCharge.data = {
|
this.formDialogCharge.data = {
|
||||||
onchain: false,
|
onchain: false,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user