From b0b14464835a9b460407d1c8fe4d142b43bbf3a2 Mon Sep 17 00:00:00 2001 From: Tiago Vasconcelos Date: Thu, 27 Oct 2022 19:14:26 +0100 Subject: [PATCH 1/4] fixed display amount --- .../extensions/tpos/templates/tpos/tpos.html | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/lnbits/extensions/tpos/templates/tpos/tpos.html b/lnbits/extensions/tpos/templates/tpos/tpos.html index c66238f7..9e462aba 100644 --- a/lnbits/extensions/tpos/templates/tpos/tpos.html +++ b/lnbits/extensions/tpos/templates/tpos/tpos.html @@ -360,15 +360,15 @@ computed: { amount: function () { if (!this.stack.length) return 0.0 - return (Number(this.stack.join('')) / 100).toFixed(2) + return Number(this.stack.join('') / 100) }, famount: function () { - return LNbits.utils.formatCurrency(this.amount, this.currency) + return LNbits.utils.formatCurrency(this.amount.toFixed(2), this.currency) }, sat: function () { if (!this.exchangeRate) return 0 return Math.ceil( - ((this.amount - this.tipAmount) / this.exchangeRate) * 100000000 + (this.amount / this.exchangeRate) * 100000000 ) }, tipAmountSat: function () { @@ -392,26 +392,25 @@ processTipSelection: function (selectedTipOption) { this.tipDialog.show = false - if (selectedTipOption) { - const tipAmount = parseFloat( - parseFloat((selectedTipOption / 100) * this.amount) - ) - const subtotal = parseFloat(this.amount) - const grandTotal = parseFloat((tipAmount + subtotal).toFixed(2)) - const totalString = grandTotal.toFixed(2).toString() + if(!selectedTipOption) return this.showInvoice() - this.stack = [] - for (var i = 0; i < totalString.length; i++) { - const char = totalString[i] + const tipAmount = (selectedTipOption / 100) * this.amount + const subtotal = this.amount + const grandTotal = (tipAmount + subtotal) + const totalString = grandTotal.toFixed(2) - if (char !== '.') { - this.stack.push(char) - } + this.stack = [] + for (var i = 0; i < totalString.length; i++) { + const char = totalString[i] + + if (char !== '.') { + this.stack.push(char) } - - this.tipAmount = tipAmount } + + this.tipAmount = tipAmount + this.showInvoice() }, submitForm: function () { From 476f915fd28a41b2676025d7b1834d850ca0c914 Mon Sep 17 00:00:00 2001 From: Tiago Vasconcelos Date: Thu, 27 Oct 2022 19:16:40 +0100 Subject: [PATCH 2/4] format --- lnbits/extensions/tpos/templates/tpos/tpos.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lnbits/extensions/tpos/templates/tpos/tpos.html b/lnbits/extensions/tpos/templates/tpos/tpos.html index 9e462aba..929af4d7 100644 --- a/lnbits/extensions/tpos/templates/tpos/tpos.html +++ b/lnbits/extensions/tpos/templates/tpos/tpos.html @@ -363,13 +363,14 @@ return Number(this.stack.join('') / 100) }, famount: function () { - return LNbits.utils.formatCurrency(this.amount.toFixed(2), this.currency) + return LNbits.utils.formatCurrency( + this.amount.toFixed(2), + this.currency + ) }, sat: function () { if (!this.exchangeRate) return 0 - return Math.ceil( - (this.amount / this.exchangeRate) * 100000000 - ) + return Math.ceil((this.amount / this.exchangeRate) * 100000000) }, tipAmountSat: function () { if (!this.exchangeRate) return 0 @@ -392,11 +393,11 @@ processTipSelection: function (selectedTipOption) { this.tipDialog.show = false - if(!selectedTipOption) return this.showInvoice() + if (!selectedTipOption) return this.showInvoice() const tipAmount = (selectedTipOption / 100) * this.amount const subtotal = this.amount - const grandTotal = (tipAmount + subtotal) + const grandTotal = tipAmount + subtotal const totalString = grandTotal.toFixed(2) this.stack = [] @@ -408,7 +409,6 @@ } } - this.tipAmount = tipAmount this.showInvoice() From 9ecf6f273b092f33573c9f541e616852be330e2f Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Fri, 18 Nov 2022 11:42:30 +0200 Subject: [PATCH 3/4] fix: total amount for invoice --- lnbits/extensions/tpos/templates/tpos/tpos.html | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/lnbits/extensions/tpos/templates/tpos/tpos.html b/lnbits/extensions/tpos/templates/tpos/tpos.html index 929af4d7..0dd105b9 100644 --- a/lnbits/extensions/tpos/templates/tpos/tpos.html +++ b/lnbits/extensions/tpos/templates/tpos/tpos.html @@ -395,22 +395,7 @@ if (!selectedTipOption) return this.showInvoice() - const tipAmount = (selectedTipOption / 100) * this.amount - const subtotal = this.amount - const grandTotal = tipAmount + subtotal - const totalString = grandTotal.toFixed(2) - - this.stack = [] - for (var i = 0; i < totalString.length; i++) { - const char = totalString[i] - - if (char !== '.') { - this.stack.push(char) - } - } - - this.tipAmount = tipAmount - + this.tipAmount = (selectedTipOption / 100) * this.amount this.showInvoice() }, submitForm: function () { From 0039a48e730565c308d2e5bef02e97de823207bc Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Fri, 18 Nov 2022 12:02:51 +0200 Subject: [PATCH 4/4] fix: total amount (amount + tip) --- .../extensions/tpos/templates/tpos/tpos.html | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/lnbits/extensions/tpos/templates/tpos/tpos.html b/lnbits/extensions/tpos/templates/tpos/tpos.html index 0dd105b9..0f9620a9 100644 --- a/lnbits/extensions/tpos/templates/tpos/tpos.html +++ b/lnbits/extensions/tpos/templates/tpos/tpos.html @@ -13,7 +13,7 @@
-

{% raw %}{{ famount }}{% endraw %}

+

{% raw %}{{ amountFormatted }}{% endraw %}

{% raw %}{{ fsat }}{% endraw %} sat
@@ -173,12 +173,14 @@ >
-

{% raw %}{{ famount }}{% endraw %}

+

+ {% raw %}{{ amountWithTipFormatted }}{% endraw %} +

{% raw %}{{ fsat }} sat ( + {{ tipAmountSat }} tip)( + {{ tipAmountFormatted }} tip) {% endraw %}
@@ -362,12 +364,18 @@ if (!this.stack.length) return 0.0 return Number(this.stack.join('') / 100) }, - famount: function () { + amountFormatted: function () { return LNbits.utils.formatCurrency( this.amount.toFixed(2), this.currency ) }, + amountWithTipFormatted: function () { + return LNbits.utils.formatCurrency( + (this.amount + this.tipAmount).toFixed(2), + this.currency + ) + }, sat: function () { if (!this.exchangeRate) return 0 return Math.ceil((this.amount / this.exchangeRate) * 100000000) @@ -376,6 +384,9 @@ if (!this.exchangeRate) return 0 return Math.ceil((this.tipAmount / this.exchangeRate) * 100000000) }, + tipAmountFormatted: function () { + return LNbits.utils.formatSat(this.tipAmountSat) + }, fsat: function () { return LNbits.utils.formatSat(this.sat) } @@ -393,7 +404,10 @@ processTipSelection: function (selectedTipOption) { this.tipDialog.show = false - if (!selectedTipOption) return this.showInvoice() + if (!selectedTipOption) { + this.tipAmount = 0.0 + return this.showInvoice() + } this.tipAmount = (selectedTipOption / 100) * this.amount this.showInvoice()