diff --git a/lnbits/extensions/tpos/templates/tpos/index.html b/lnbits/extensions/tpos/templates/tpos/index.html index 3c4fa24f8..1aa75fcf1 100644 --- a/lnbits/extensions/tpos/templates/tpos/index.html +++ b/lnbits/extensions/tpos/templates/tpos/index.html @@ -139,8 +139,12 @@ input-debounce="0" new-value-mode="add-unique" label="Tip % Options (hit enter to add values)" - >Hit enter to add values + >Hit enter to add values + +
{% raw %}{{ tip }}{% endraw %}% -
-
-

No, thanks

+ +
+ + + Ok +
+ No, thanks Close
@@ -336,6 +365,7 @@ exchangeRate: null, stack: [], tipAmount: 0.0, + tipRounding: null, hasNFC: false, nfcTagReading: false, lastPaymentsDialog: { @@ -356,7 +386,8 @@ }, complete: { show: false - } + }, + rounding: false } }, computed: { @@ -389,9 +420,47 @@ }, fsat: function () { return LNbits.utils.formatSat(this.sat) + }, + isRoundValid() { + return this.tipRounding > this.amount + }, + roundToSugestion() { + switch (true) { + case this.amount > 50: + toNext = 10 + break + case this.amount > 6: + toNext = 5 + break + case this.amount > 2.5: + toNext = 1 + break + default: + toNext = 0.5 + break + } + + return Math.ceil(this.amount / toNext) * toNext } }, methods: { + setRounding() { + this.rounding = true + this.tipRounding = this.roundToSugestion + this.$nextTick(() => this.$refs.inputRounding.focus()) + }, + calculatePercent() { + let change = ((this.tipRounding - this.amount) / this.amount) * 100 + if (change < 0) { + this.$q.notify({ + type: 'warning', + message: 'Amount with tip must be greater than initial amount.' + }) + this.tipRounding = this.roundToSugestion + return + } + this.processTipSelection(change) + }, closeInvoiceDialog: function () { this.stack = [] this.tipAmount = 0.0 @@ -414,6 +483,8 @@ }, submitForm: function () { if (this.tip_options && this.tip_options.length) { + this.rounding = false + this.tipRounding = null this.showTipModal() } else { this.showInvoice() @@ -589,10 +660,26 @@ '{{ tpos.tip_options | tojson }}' == 'null' ? null : JSON.parse('{{ tpos.tip_options }}') + + if ('{{ tpos.tip_wallet }}') { + this.tip_options.push('Round') + } setInterval(function () { getRates() }, 120000) } }) + {% endblock %}