fixed updating paid tickets on index.html

This commit is contained in:
Tiago vasconcelos 2021-06-16 11:23:58 +01:00
parent bb1253f30e
commit b490d9f260
3 changed files with 36 additions and 12 deletions

View File

@ -25,10 +25,12 @@ async def on_invoice_paid(payment: Payment) -> None:
# not a lnticket invoice # not a lnticket invoice
return return
ticket = await get_ticket(payment.payment_hash) ticket = await get_ticket(payment.checking_id)
if not ticket: if not ticket:
print("this should never happen", payment) print("this should never happen", payment)
return return
await payment.set_pending(False) await payment.set_pending(False)
await set_ticket_paid(payment_hash=payment.payment_hash) await set_ticket_paid(payment.payment_hash)
_ticket = await get_ticket(payment.checking_id)
print('ticket', _ticket)

View File

@ -77,7 +77,7 @@
{% endblock %} {% block scripts %} {% endblock %} {% block scripts %}
<script> <script>
console.log('{{ form_costpword }}') //console.log('{{ form_costpword }}')
Vue.component(VueQrcode.name, VueQrcode) Vue.component(VueQrcode.name, VueQrcode)
new Vue({ new Vue({
@ -139,7 +139,7 @@
}, },
startPaymentNotifier() { startPaymentNotifier() {
this.cancelListener() this.cancelListener()
console.log(this.wallet)
this.cancelListener = LNbits.events.onInvoicePaid( this.cancelListener = LNbits.events.onInvoicePaid(
this.wallet, this.wallet,
payment => { payment => {

View File

@ -90,7 +90,7 @@
<div class="col"> <div class="col">
<h5 class="text-subtitle1 q-my-none">Tickets</h5> <h5 class="text-subtitle1 q-my-none">Tickets</h5>
</div> </div>
<div class="col-auto"> <!-- <div class="col-auto">
<q-btn <q-btn
flat flat
color="grey" color="grey"
@ -99,7 +99,7 @@
@click="getTickets" @click="getTickets"
><q-tooltip> Refresh Tickets </q-tooltip></q-btn ><q-tooltip> Refresh Tickets </q-tooltip></q-btn
> >
</div> </div> -->
<div class="col-auto"> <div class="col-auto">
<q-btn flat color="grey" @click="exportticketsCSV" <q-btn flat color="grey" @click="exportticketsCSV"
>Export to CSV</q-btn >Export to CSV</q-btn
@ -240,7 +240,7 @@
</div> </div>
{% endblock %} {% block scripts %} {{ window_vars(user) }} {% endblock %} {% block scripts %} {{ window_vars(user) }}
<script> <script>
var mapLNTicket = function (obj) { const mapLNTicket = function (obj) {
obj.date = Quasar.utils.date.formatDate( obj.date = Quasar.utils.date.formatDate(
new Date(obj.time * 1000), new Date(obj.time * 1000),
'YYYY-MM-DD HH:mm' 'YYYY-MM-DD HH:mm'
@ -291,7 +291,8 @@
{name: 'name', align: 'left', label: 'Name', field: 'name'}, {name: 'name', align: 'left', label: 'Name', field: 'name'},
{name: 'email', align: 'left', label: 'Email', field: 'email'}, {name: 'email', align: 'left', label: 'Email', field: 'email'},
{name: 'ltext', align: 'left', label: 'Ticket', field: 'ltext'}, {name: 'ltext', align: 'left', label: 'Ticket', field: 'ltext'},
{name: 'sats', align: 'left', label: 'Cost', field: 'sats'} {name: 'sats', align: 'left', label: 'Cost', field: 'sats'},
{name: 'paid', align: 'left', label: 'Paid', field: 'paid'}
], ],
pagination: { pagination: {
rowsPerPage: 10 rowsPerPage: 10
@ -300,7 +301,8 @@
formDialog: { formDialog: {
show: false, show: false,
data: {} data: {}
} },
cancelListener: () => {}
} }
}, },
methods: { methods: {
@ -314,9 +316,12 @@
this.g.user.wallets[0].inkey this.g.user.wallets[0].inkey
) )
.then(function (response) { .then(function (response) {
self.tickets = response.data.map(function (obj) { self.tickets = response.data
return mapLNTicket(obj) .map(function (obj) {
}) if (!obj?.paid) return
return mapLNTicket(obj)
})
.filter(v => v)
}) })
}, },
deleteTicket: function (ticketId) { deleteTicket: function (ticketId) {
@ -446,6 +451,22 @@
}, },
exportformsCSV: function () { exportformsCSV: function () {
LNbits.utils.exportCSV(this.formsTable.columns, this.forms) LNbits.utils.exportCSV(this.formsTable.columns, this.forms)
},
startPaymentNotifier() {
this.cancelListener()
this.cancelListener = LNbits.events.onInvoicePaid(
this.g.user.wallets[0],
payment => {
this.getTickets()
this.$q.notify({
type: 'positive',
message: 'Sent, thank you!',
icon: 'thumb_up'
})
}
)
} }
}, },
@ -453,6 +474,7 @@
if (this.g.user.wallets.length) { if (this.g.user.wallets.length) {
this.getTickets() this.getTickets()
this.getForms() this.getForms()
this.startPaymentNotifier()
} }
} }
}) })