From 3dd1c6992b69d402a14f9b01392829b2d7945f52 Mon Sep 17 00:00:00 2001 From: arcbtc Date: Wed, 18 Dec 2024 20:40:32 +0000 Subject: [PATCH 01/17] Trigger to default fiat conversion on Like all the other wallets --- lnbits/core/migrations.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lnbits/core/migrations.py b/lnbits/core/migrations.py index 2d4f059c8..347f45d36 100644 --- a/lnbits/core/migrations.py +++ b/lnbits/core/migrations.py @@ -684,3 +684,22 @@ async def m029_create_audit_table(db: Connection): ); """ ) + +async def m030_add_currency_to_wallet(db: Connection): + """ + Setting currency to default is heavy, so easier just to add a trigger. + """ + await db.execute( + + """ + CREATE TRIGGER IF NOT EXISTS set_default_currency + AFTER INSERT ON wallets + FOR EACH ROW + WHEN NEW.currency IS NULL + BEGIN + UPDATE wallets + SET currency = 'USD' + WHERE id = NEW.id; + END; + """ + ) \ No newline at end of file From ce9b63c54ebf0fc9a6a428a80e14694ef7553401 Mon Sep 17 00:00:00 2001 From: arcbtc Date: Wed, 18 Dec 2024 20:53:55 +0000 Subject: [PATCH 02/17] step1 wallet card adjust --- lnbits/core/templates/core/wallet.html | 127 +++++++++++++++++++++---- 1 file changed, 106 insertions(+), 21 deletions(-) diff --git a/lnbits/core/templates/core/wallet.html b/lnbits/core/templates/core/wallet.html index 58ff78e43..4c6363bf2 100644 --- a/lnbits/core/templates/core/wallet.html +++ b/lnbits/core/templates/core/wallet.html @@ -34,31 +34,111 @@ } : ''" > -

- - {{LNBITS_DENOMINATION}} - -

-
-
+
+ +
+
+
+
+
+
+
+ + {{LNBITS_DENOMINATION}} +
+
+
+ +
+
+
+
+
+ +
+
+
+ +
+
+
+
+
+ +
+
+
+ +
+
+
+
+ + +
+
+ +
+
+ BTC Price + +
-
-
@@ -80,7 +160,7 @@ @@ -89,14 +169,19 @@ +
From f74a7cbe1f675409887ded34451eb26a476b0ea9 Mon Sep 17 00:00:00 2001 From: arcbtc Date: Wed, 18 Dec 2024 20:56:28 +0000 Subject: [PATCH 03/17] step2 --- lnbits/core/templates/core/wallet.html | 37 ++++++++++++++------------ 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/lnbits/core/templates/core/wallet.html b/lnbits/core/templates/core/wallet.html index 4c6363bf2..33fd4f6bf 100644 --- a/lnbits/core/templates/core/wallet.html +++ b/lnbits/core/templates/core/wallet.html @@ -300,24 +300,27 @@
- +
+
+ +
+
+ +
+
-
From 468a786f784c08dcd026ce8874a222071471f388 Mon Sep 17 00:00:00 2001 From: arcbtc Date: Wed, 18 Dec 2024 21:00:41 +0000 Subject: [PATCH 04/17] step3 --- lnbits/core/templates/core/wallet.html | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lnbits/core/templates/core/wallet.html b/lnbits/core/templates/core/wallet.html index 33fd4f6bf..6e6b50462 100644 --- a/lnbits/core/templates/core/wallet.html +++ b/lnbits/core/templates/core/wallet.html @@ -185,6 +185,7 @@
+ + >
{% if HIDE_API %}
{% else %} -
+
From 7fc723c2ddc804236a292514acb97fe823966476 Mon Sep 17 00:00:00 2001 From: arcbtc Date: Wed, 18 Dec 2024 21:33:02 +0000 Subject: [PATCH 05/17] added js --- lnbits/static/js/wallet.js | 77 +++++++++++++++++++++++++++++++------- 1 file changed, 63 insertions(+), 14 deletions(-) diff --git a/lnbits/static/js/wallet.js b/lnbits/static/js/wallet.js index aa0fffeab..cfa75d621 100644 --- a/lnbits/static/js/wallet.js +++ b/lnbits/static/js/wallet.js @@ -58,7 +58,11 @@ window.app = Vue.createApp({ inkeyHidden: true, adminkeyHidden: true, hasNfc: false, - nfcReaderAbortController: null + nfcReaderAbortController: null, + isPrioritySwapped: false, + fiatTracking: false, + formattedFiatAmount: 0, + exchangeRate: 0 } }, computed: { @@ -69,10 +73,10 @@ window.app = Vue.createApp({ return LNbits.utils.formatSat(this.balance || this.g.wallet.sat) } }, - formattedFiatBalance() { - if (this.fiatBalance) { + formattedExchange() { + if (this.fiatTracking) { return LNbits.utils.formatCurrency( - this.fiatBalance.toFixed(2), + this.exchangeRate, this.g.wallet.currency ) } @@ -96,6 +100,12 @@ window.app = Vue.createApp({ } }, methods: { + formatFiatAmount(amount, currency) { + this.formattedFiatAmount = LNbits.utils.formatCurrency( + amount.toFixed(2), + currency + ) + }, msatoshiFormat(value) { return LNbits.utils.formatSat(value / 1000) }, @@ -538,15 +548,20 @@ window.app = Vue.createApp({ }) }) }, - updateFiatBalance() { - if (!this.g.wallet.currency) return 0 + updateFiatBalance(currency) { + this.exchangeRate = this.$q.localStorage.getItem('lnbits.exchangeRate') + this.fiatBalance = + (this.exchangeRate / 100000000) * (this.g.wallet.sat) LNbits.api - .request('POST', `/api/v1/conversion`, null, { - amount: this.balance || this.g.wallet.sat, - to: this.g.wallet.currency - }) + .request('GET', `/api/v1/rate/` + currency, null) .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)) }, @@ -651,6 +666,23 @@ window.app = Vue.createApp({ dismissPaymentMsg() 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() { @@ -664,15 +696,26 @@ window.app = Vue.createApp({ if (this.$q.screen.lt.md) { 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.currency = this.g.wallet.currency this.receive.units = ['sat', ...window.currencies] - this.updateFiatBalance() }, watch: { + '$q.screen.gt.sm'(value) { + if (value == true) { + this.mobileSimple = false + } + }, updatePayments() { this.updateFiatBalance() - } + }, + 'update.currency'(newValue) { + this.updateWallet({ currency: newValue }) + this.updateFiatBalance(newValue) + this.getPriceChange() }, mounted() { // show disclaimer @@ -680,6 +723,12 @@ window.app = Vue.createApp({ this.disclaimerDialog.show = 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 LNbits.events.onInvoicePaid(this.g.wallet, data => { console.log('Payment received:', data.payment.payment_hash) From 1a6671b4b337fb0e807892cdfa4f5277d1e0aaf6 Mon Sep 17 00:00:00 2001 From: arcbtc Date: Wed, 18 Dec 2024 21:38:48 +0000 Subject: [PATCH 06/17] bug --- lnbits/static/js/wallet.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lnbits/static/js/wallet.js b/lnbits/static/js/wallet.js index cfa75d621..300a08717 100644 --- a/lnbits/static/js/wallet.js +++ b/lnbits/static/js/wallet.js @@ -524,7 +524,6 @@ window.app = Vue.createApp({ type: 'positive', timeout: 3500 }) - window.location.reload() }) .catch(err => { LNbits.utils.notifyApiError(err) @@ -698,7 +697,6 @@ window.app = Vue.createApp({ } if(this.g.wallet.currency){ this.updateFiatBalance(this.g.wallet.currency) - this.getPriceChange() } this.update.name = this.g.wallet.name this.receive.units = ['sat', ...window.currencies] @@ -710,12 +708,12 @@ window.app = Vue.createApp({ } }, updatePayments() { - this.updateFiatBalance() + this.updateFiatBalance(this.g.wallet.currenc) }, 'update.currency'(newValue) { this.updateWallet({ currency: newValue }) this.updateFiatBalance(newValue) - this.getPriceChange() + } }, mounted() { // show disclaimer From acd3b598b7dd6ae264925a89db654546028d9b20 Mon Sep 17 00:00:00 2001 From: arcbtc Date: Wed, 18 Dec 2024 21:55:54 +0000 Subject: [PATCH 07/17] bug fix --- lnbits/core/templates/core/wallet.html | 8 +++----- lnbits/static/js/wallet.js | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lnbits/core/templates/core/wallet.html b/lnbits/core/templates/core/wallet.html index 6e6b50462..2d21f2f90 100644 --- a/lnbits/core/templates/core/wallet.html +++ b/lnbits/core/templates/core/wallet.html @@ -28,10 +28,9 @@
@@ -170,7 +169,6 @@ unelevated color="secondary" icon="qr_code_scanner" - :label="$t('scan')" > Date: Wed, 18 Dec 2024 22:15:17 +0000 Subject: [PATCH 08/17] layout bug --- lnbits/core/templates/core/wallet.html | 15 +++------------ lnbits/static/js/wallet.js | 9 +++++---- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/lnbits/core/templates/core/wallet.html b/lnbits/core/templates/core/wallet.html index 2d21f2f90..4411661f8 100644 --- a/lnbits/core/templates/core/wallet.html +++ b/lnbits/core/templates/core/wallet.html @@ -51,7 +51,7 @@ v-if="!isPrioritySwapped" style="height: 100px" > -
+
@@ -120,10 +120,6 @@
BTC Price -
-
+ -
-
-
-
-
-
+
{ From fb5659de2a23239bd38f43bdd6275a47fbe1c3e5 Mon Sep 17 00:00:00 2001 From: arcbtc Date: Wed, 18 Dec 2024 23:19:03 +0000 Subject: [PATCH 09/17] working, also fixed the button --- lnbits/core/templates/core/wallet.html | 25 ++++++++++++------ lnbits/static/js/components.js | 2 +- lnbits/static/js/wallet.js | 35 +++++++++++++++----------- lnbits/templates/components.vue | 26 ++++++++++++++++++- 4 files changed, 64 insertions(+), 24 deletions(-) diff --git a/lnbits/core/templates/core/wallet.html b/lnbits/core/templates/core/wallet.html index 4411661f8..e707b1a4c 100644 --- a/lnbits/core/templates/core/wallet.html +++ b/lnbits/core/templates/core/wallet.html @@ -36,7 +36,7 @@
-
+
@@ -70,7 +74,7 @@
-
+
-
+
BTC Price
@@ -143,6 +151,7 @@
+
-
+
{ this.fiatBalance = - (response.data.rate / 100000000) * - (this.g.wallet.sat) - this.exchangeRate = response.data.rate.toFixed(2) + (response.data.price / 100000000) * + (this.balance || this.g.wallet.sat) + this.exchangeRate = response.data.price.toFixed(2) this.fiatTracking = true this.formatFiatAmount(this.fiatBalance, currency) this.$q.localStorage.set('lnbits.exchangeRate', this.exchangeRate) @@ -675,7 +677,7 @@ window.app = Vue.createApp({ }, handleFiatTracking() { if (this.fiatTracking === false) { - this.updateWallet({ currency: ''}) + this.update.currency = '' this.$q.localStorage.setItem( 'lnbits.isPrioritySwapped', false @@ -695,7 +697,11 @@ window.app = Vue.createApp({ if (this.$q.screen.lt.md) { this.mobileSimple = true } + setTimeout(() => { + this.ignoreWatcher = false + }, 3000) if(this.g.wallet.currency){ + this.fiatTracking = true this.updateFiatBalance(this.g.wallet.currency) } this.update.name = this.g.wallet.name @@ -711,6 +717,7 @@ window.app = Vue.createApp({ this.fetchBalance() }, 'update.currency'(newValue) { + if (this.ignoreWatcher) return this.updateWallet({ currency: newValue }) this.updateFiatBalance(newValue) } diff --git a/lnbits/templates/components.vue b/lnbits/templates/components.vue index 955670aed..195ecd729 100644 --- a/lnbits/templates/components.vue +++ b/lnbits/templates/components.vue @@ -506,7 +506,31 @@