fix: ugly method to refresh UI

This commit is contained in:
Vlad Stan 2022-11-04 18:46:26 +02:00 committed by dni ⚡
parent ce27136757
commit f140b19e56

View file

@ -22,7 +22,7 @@ page_container %}
<div class="col-6"> <div class="col-6">
<h3 class="q-my-none"> <h3 class="q-my-none">
<center> <center>
<strong>{% raw %} {{balance}} </strong> <strong>{% raw %} {{getBalance()}} </strong>
{{tickershort}}{% endraw %} {{tickershort}}{% endraw %}
</center> </center>
</h3> </h3>
@ -81,7 +81,7 @@ page_container %}
<q-table <q-table
dense dense
flat flat
:data="tokenList" :data="getTokenList()"
:columns="tokensTable.columns" :columns="tokensTable.columns"
:pagination.sync="tokensTable.pagination" :pagination.sync="tokensTable.pagination"
no-data-label="No tokens yet" no-data-label="No tokens yet"
@ -912,6 +912,26 @@ page_container %}
} }
}, },
methods: { methods: {
getBalance: function () {
return this.proofs
.map(t => t)
.flat()
.reduce((sum, el) => (sum += el.amount), 0)
},
getTokenList: function () {
const x = this.proofs
.map(t => t.amount)
.reduce((acc, amount) => {
acc[amount] = acc[amount] + amount || 1
return acc
}, {})
return Object.keys(x).map(k => ({
value: k,
count: x[k],
sum: k * x[k]
}))
},
paymentTableRowKey: function (row) { paymentTableRowKey: function (row) {
return row.payment_hash + row.amount return row.payment_hash + row.amount
}, },
@ -1269,7 +1289,7 @@ page_container %}
if (!proofs.length) { if (!proofs.length) {
throw 'could not mint' throw 'could not mint'
} }
this.proofs.push(...proofs) this.proofs = this.proofs.concat(proofs)
this.storeProofs() this.storeProofs()
await this.setInvoicePaid(payment_hash) await this.setInvoicePaid(payment_hash)
return proofs return proofs
@ -1398,8 +1418,7 @@ page_container %}
const usedSecrets = proofs.map(p => p.secret) const usedSecrets = proofs.map(p => p.secret)
this.proofs = this.proofs.filter(p => !usedSecrets.includes(p.secret)) this.proofs = this.proofs.filter(p => !usedSecrets.includes(p.secret))
// add new fristProofs, scndProofs to this.proofs // add new fristProofs, scndProofs to this.proofs
this.proofs.push(...fristProofs) this.proofs = this.proofs.concat(fristProofs).concat(scndProofs)
this.proofs.push(...scndProofs)
this.storeProofs() this.storeProofs()
return {fristProofs, scndProofs} return {fristProofs, scndProofs}
} catch (error) { } catch (error) {