add fiat balance to wallet (#2157)

also fixed payments table fiat denomination for consistency
This commit is contained in:
Tiago Vasconcelos
2023-12-06 17:54:58 +01:00
committed by GitHub
parent b8e6e80bdf
commit a83fb13335
2 changed files with 38 additions and 4 deletions
+27
View File
@@ -241,6 +241,7 @@ new Vue({
location: window.location
},
balance: 0,
fiatBalance: 0,
credit: 0,
update: {
name: null,
@@ -256,6 +257,14 @@ new Vue({
return LNbits.utils.formatSat(this.balance || this.g.wallet.sat)
}
},
formattedFiatBalance() {
if (this.fiatBalance) {
return LNbits.utils.formatCurrency(
this.fiatBalance.toFixed(2),
this.g.wallet.currency
)
}
},
filteredPayments: function () {
var q = this.paymentsTable.filter
if (!q || q === '') return this.payments
@@ -797,6 +806,24 @@ new Vue({
this.balance
])
})
if (this.g.wallet.currency) {
this.updateFiatBalance()
}
},
updateFiatBalance() {
if (!this.g.wallet.currency) return 0
LNbits.api
.request('POST', `/api/v1/conversion`, null, {
amount: this.balance || this.g.wallet.sat,
to: this.g.wallet.currency
})
.then(response => {
this.fiatBalance = response.data[this.g.wallet.currency]
})
.catch(e => console.error(e))
},
formatFiat(currency, amount) {
return LNbits.utils.formatCurrency(amount, currency)
},
exportCSV: function () {
// status is important for export but it is not in paymentsTable