Skip to content

Commit 283b342

Browse files
committed
fix: server percentage time
1 parent f32eb7c commit 283b342

File tree

2 files changed

+41
-15
lines changed

2 files changed

+41
-15
lines changed

src/boot/saas.js

+24-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import axios from "axios";
33
var saas = {
44
slideimg: "assets/images/hero/bitcoin-accounts.png",
55
url: "https://api.lnbits.com",
6+
serverTime: null,
67

78
access_token: localStorage.getItem("token"),
89
email: localStorage.getItem("email"),
@@ -83,23 +84,37 @@ var saas = {
8384

8485
return response;
8586
},
87+
status: async function () {
88+
const response = await axios({
89+
method: "GET",
90+
url: this.url,
91+
});
92+
93+
this.serverTime = response.data.timestamp;
94+
95+
return response;
96+
},
8697
logout: function () {
8798
this.access_token = null;
8899
this.email = null;
89100
localStorage.clear();
101+
// todo: call endpoint
90102
},
91103

92104
mapInstance: function (instance) {
93-
const progress = (start, stop) => {
105+
const progress = (start, stop, serverTime) => {
94106
const now = new Date().getTime() / 1000;
95-
if (stop - start <= 0) {
107+
if (!serverTime) {
108+
return 0;
109+
}
110+
if (stop - start <= 0 || stop - serverTime <= 0) {
96111
return 100;
97112
}
98113

99-
const percentage = (1 - (stop - start) / (stop - now)) * 100;
114+
const percentage = (1 - (stop - serverTime) / (stop - start)) * 100;
100115

101116
console.log("## percentage", percentage, start, now, stop);
102-
return percentage;
117+
return Math.round(percentage);
103118
};
104119
return {
105120
id: instance.id,
@@ -113,7 +128,11 @@ var saas = {
113128
timestamp: instance.timestamp,
114129
timestampStop: instance.timestamp_stop,
115130
lnurl: instance.lnurl,
116-
progress: progress(instance.timestamp, instance.timestamp_stop),
131+
progress: progress(
132+
instance.timestamp,
133+
instance.timestamp_stop,
134+
this.serverTime
135+
),
117136
};
118137
},
119138
};

src/components/tables/TableDarkMode.vue

+17-10
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@
118118
</template>
119119

120120
<template v-slot:body-cell-Progress="props">
121-
<q-td :props="props">
121+
<q-td :props="props" tool-tip="xxxxx">
122+
<q-tooltip><span v-text="props.row.progress + '%'"></span></q-tooltip>
122123
<q-linear-progress
123124
dark
124125
:color="getColor(props.row.progress)"
@@ -145,11 +146,7 @@
145146
/>
146147
</p>
147148
<h5><span v-text="activeInstance.name"></span></h5>
148-
<q-linear-progress
149-
indeterminate
150-
color="secondary"
151-
class="q-mt-sm"
152-
/>
149+
<q-linear-progress indeterminate color="secondary" class="q-mt-sm" />
153150
<div class="row q-mt-md">
154151
<q-btn
155152
color="deep-purple"
@@ -400,9 +397,8 @@ export default defineComponent({
400397
const retryId = setInterval(async () => {
401398
try {
402399
const { data } = await saas.getInstances();
403-
console.log("### checkInstance", data);
404400
const updatedInstance = (data || [])
405-
.map(saas.mapInstance)
401+
.map(i => saas.mapInstance(i))
406402
.find((i) => i.id === instance.id);
407403
if (
408404
updatedInstance &&
@@ -415,14 +411,24 @@ export default defineComponent({
415411
});
416412
}
417413
if (!this.showPaymentQrDialog) {
418-
console.log("### clearInterval no dialog", retryId);
419414
clearInterval(retryId);
420415
}
421416
} catch (error) {
422417
console.warn(error);
423418
}
424419
}, 3000);
425420
},
421+
serverStatus: async function () {
422+
try {
423+
await saas.status();
424+
} catch (error) {
425+
console.warn(error);
426+
this.q.notify({
427+
message: "Failed to check SaaS Server status!",
428+
color: "negative",
429+
});
430+
}
431+
},
426432
extendInstance: function (instance) {
427433
this.activeInstance = instance;
428434
this.showPaymentQrDialog = true;
@@ -443,7 +449,8 @@ export default defineComponent({
443449
async created() {
444450
try {
445451
const { data } = await saas.getInstances();
446-
const tableData = (data || []).map(saas.mapInstance);
452+
await this.serverStatus()
453+
const tableData = (data || []).map(i => saas.mapInstance(i));
447454
448455
this.data = tableData;
449456
} catch (error) {

0 commit comments

Comments
 (0)