This commit is contained in:
arcbtc
2024-12-18 21:33:02 +00:00
parent 468a786f78
commit 7fc723c2dd
+63 -14
View File
@@ -58,7 +58,11 @@ window.app = Vue.createApp({
inkeyHidden: true, inkeyHidden: true,
adminkeyHidden: true, adminkeyHidden: true,
hasNfc: false, hasNfc: false,
nfcReaderAbortController: null nfcReaderAbortController: null,
isPrioritySwapped: false,
fiatTracking: false,
formattedFiatAmount: 0,
exchangeRate: 0
} }
}, },
computed: { computed: {
@@ -69,10 +73,10 @@ window.app = Vue.createApp({
return LNbits.utils.formatSat(this.balance || this.g.wallet.sat) return LNbits.utils.formatSat(this.balance || this.g.wallet.sat)
} }
}, },
formattedFiatBalance() { formattedExchange() {
if (this.fiatBalance) { if (this.fiatTracking) {
return LNbits.utils.formatCurrency( return LNbits.utils.formatCurrency(
this.fiatBalance.toFixed(2), this.exchangeRate,
this.g.wallet.currency this.g.wallet.currency
) )
} }
@@ -96,6 +100,12 @@ window.app = Vue.createApp({
} }
}, },
methods: { methods: {
formatFiatAmount(amount, currency) {
this.formattedFiatAmount = LNbits.utils.formatCurrency(
amount.toFixed(2),
currency
)
},
msatoshiFormat(value) { msatoshiFormat(value) {
return LNbits.utils.formatSat(value / 1000) return LNbits.utils.formatSat(value / 1000)
}, },
@@ -538,15 +548,20 @@ window.app = Vue.createApp({
}) })
}) })
}, },
updateFiatBalance() { updateFiatBalance(currency) {
if (!this.g.wallet.currency) return 0 this.exchangeRate = this.$q.localStorage.getItem('lnbits.exchangeRate')
this.fiatBalance =
(this.exchangeRate / 100000000) * (this.g.wallet.sat)
LNbits.api LNbits.api
.request('POST', `/api/v1/conversion`, null, { .request('GET', `/api/v1/rate/` + currency, null)
amount: this.balance || this.g.wallet.sat,
to: this.g.wallet.currency
})
.then(response => { .then(response => {
this.fiatBalance = response.data[this.g.wallet.currency] this.fiatBalance =
(response.data.rate / 100000000) *
(this.g.wallet.sat)
this.exchangeRate = response.data.rate.toFixed(2)
this.fiatTracking = true
this.formatFiatAmount(this.fiatBalance, currency)
this.$q.localStorage.set('lnbits.exchangeRate', this.exchangeRate)
}) })
.catch(e => console.error(e)) .catch(e => console.error(e))
}, },
@@ -651,6 +666,23 @@ window.app = Vue.createApp({
dismissPaymentMsg() dismissPaymentMsg()
LNbits.utils.notifyApiError(err) LNbits.utils.notifyApiError(err)
}) })
},
swapBalancePriority() {
this.isPrioritySwapped = !this.isPrioritySwapped
this.$q.localStorage.setItem(
'lnbits.isPrioritySwapped',
this.isPrioritySwapped
)
},
handleFiatTracking() {
if (this.fiatTracking === false) {
this.updateWallet({ currency: ''})
this.$q.localStorage.setItem(
'lnbits.isPrioritySwapped',
false
)
this.$q.localStorage.remove(`lnbits.exchangeRate`)
}
} }
}, },
created() { created() {
@@ -664,15 +696,26 @@ window.app = Vue.createApp({
if (this.$q.screen.lt.md) { if (this.$q.screen.lt.md) {
this.mobileSimple = true this.mobileSimple = true
} }
if(this.g.wallet.currency){
this.updateFiatBalance(this.g.wallet.currency)
this.getPriceChange()
}
this.update.name = this.g.wallet.name this.update.name = this.g.wallet.name
this.update.currency = this.g.wallet.currency
this.receive.units = ['sat', ...window.currencies] this.receive.units = ['sat', ...window.currencies]
this.updateFiatBalance()
}, },
watch: { watch: {
'$q.screen.gt.sm'(value) {
if (value == true) {
this.mobileSimple = false
}
},
updatePayments() { updatePayments() {
this.updateFiatBalance() this.updateFiatBalance()
} },
'update.currency'(newValue) {
this.updateWallet({ currency: newValue })
this.updateFiatBalance(newValue)
this.getPriceChange()
}, },
mounted() { mounted() {
// show disclaimer // show disclaimer
@@ -680,6 +723,12 @@ window.app = Vue.createApp({
this.disclaimerDialog.show = true this.disclaimerDialog.show = true
this.$q.localStorage.set('lnbits.disclaimerShown', true) this.$q.localStorage.set('lnbits.disclaimerShown', true)
} }
// check blanace priority
if (this.$q.localStorage.getItem('lnbits.isPrioritySwapped')) {
this.isPrioritySwapped = this.$q.localStorage.getItem(
'lnbits.isPrioritySwapped'
)
}
// listen to incoming payments // listen to incoming payments
LNbits.events.onInvoicePaid(this.g.wallet, data => { LNbits.events.onInvoicePaid(this.g.wallet, data => {
console.log('Payment received:', data.payment.payment_hash) console.log('Payment received:', data.payment.payment_hash)