Fixed timer

master
Chakib Benziane 5 years ago
parent 849d5ebff5
commit be1f3ae1b7

@ -40,7 +40,6 @@ export default {
this.worker.listenTo('payment-received', (e)=>{ this.worker.listenTo('payment-received', (e)=>{
console.log('pay received', e.data) console.log('pay received', e.data)
this.invoice = e.data.invoice; this.invoice = e.data.invoice;
this.uploadId = e.data.upload_id;
this.status = e.data.status; this.status = e.data.status;
}) })

@ -2,7 +2,7 @@
<div id="payment"> <div id="payment">
<img :src="payreqURI" /> <img :src="payreqURI" />
<timer v-if="invoice.status != 'paid'" :expires="invoice.expires_at" :expired="expired"></timer> <timer v-if="showTimer" :expires="expires" :expired="expired"></timer>
<p v-if="invoice.status == 'paid'">Paid on {{paidAt}}</p> <p v-if="invoice.status == 'paid'">Paid on {{paidAt}}</p>
<p class='paid' v-if="paid">PAID</p> <p class='paid' v-if="paid">PAID</p>
<p class='unpaid' v-if="unpaid">UNPAID</p> <p class='unpaid' v-if="unpaid">UNPAID</p>
@ -23,6 +23,7 @@ export default {
return { return {
payreqURI: "", payreqURI: "",
expired: false, expired: false,
expires: 0,
} }
}, },
props: ['invoice', 'uploadId', 'status'], props: ['invoice', 'uploadId', 'status'],
@ -47,12 +48,10 @@ export default {
}) })
} }
}, },
mounted(){
this.expired = (this.invoice.status === 'expired')
},
computed: { computed: {
paidAt: function(){ paidAt: function(){
return new Date(this.invoice.paid_at).toGMTString(); return new Date(this.invoice.paid_at).toGMTString();
}, },
paid: function() { paid: function() {
@ -62,14 +61,24 @@ export default {
unpaid: function(){ unpaid: function(){
return this.invoice.status == 'unpaid'; return this.invoice.status == 'unpaid';
}, },
showTimer: function(){
return !this.paid;
}
}, },
watch: { watch: {
invoice: function(val) { invoice: function(val) {
if (new Date(val.expires_at*1000) - new Date() <= 0){ if (val){
this.expired = true; this.expires = val.expires_at;
if (new Date(val.expires_at*1000) - new Date() <= 0){
this.expired = true;
} else {
this.expired = false;
}
this.makeLnQR(val.payreq)
} }
this.makeLnQR(val.payreq)
} }
}, },
components:{ components:{

@ -1,7 +1,6 @@
<template> <template>
<div class="timer"> <div class="timer">
<p v-if="!expired && timer">remaining: {{mins}}:{{secs}}</p> <p>remaining: {{mins}}:{{secs}}</p>
<p class="expired" v-if="expired">expired</p>
</div> </div>
</template> </template>
@ -14,6 +13,12 @@ export default {
timer: null, timer: null,
} }
}, },
methods: {
restart(){
console.log('restart timer')
this.timer = new Timer(new Date(this.expires*1000));
}
},
props: ['expires', 'expired'], props: ['expires', 'expired'],
computed: { computed: {
secs: function() { secs: function() {
@ -30,7 +35,6 @@ export default {
watch: { watch: {
expires: function(val){ expires: function(val){
let self = this; let self = this;
this.timer = new Timer(new Date(val*1000)); this.timer = new Timer(new Date(val*1000));
} }
} }

Loading…
Cancel
Save