From 96046b8d0cd459ca7bf54cd13b3b74398c737f94 Mon Sep 17 00:00:00 2001 From: Tiago Vasconcelos Date: Fri, 14 Oct 2022 21:59:28 +0100 Subject: [PATCH] add default tip by rounding to value --- .../extensions/tpos/templates/tpos/tpos.html | 63 ++++++++++++++++++- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/lnbits/extensions/tpos/templates/tpos/tpos.html b/lnbits/extensions/tpos/templates/tpos/tpos.html index 0f9620a96..4b1b0ad3c 100644 --- a/lnbits/extensions/tpos/templates/tpos/tpos.html +++ b/lnbits/extensions/tpos/templates/tpos/tpos.html @@ -17,6 +17,7 @@
{% raw %}{{ fsat }}{% endraw %} sat
+

{% raw %}{{ parseFloat(roundToSugestion) }}{% endraw %}

@@ -214,14 +215,37 @@ style="padding: 10px; margin: 3px" unelevated @click="processTipSelection(tip)" - size="xl" + size="lg" :outline="!($q.dark.isActive)" rounded color="primary" - v-for="tip in this.tip_options" + v-for="tip in tip_options.filter(f => f != 'Round')" :key="tip" >{% raw %}{{ tip }}{% endraw %}% + + + +

No, thanks

@@ -336,6 +360,7 @@ exchangeRate: null, stack: [], tipAmount: 0.0, + tipRounding: null, hasNFC: false, nfcTagReading: false, lastPaymentsDialog: { @@ -356,7 +381,8 @@ }, complete: { show: false - } + }, + rounding: false } }, computed: { @@ -389,9 +415,36 @@ }, fsat: function () { return LNbits.utils.formatSat(this.sat) + }, + isRoundValid(){ + return this.tipRounding > this.amount + }, + roundToSugestion(){ + //let toNext = 1 + 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()) + }, closeInvoiceDialog: function () { this.stack = [] this.tipAmount = 0.0 @@ -589,6 +642,10 @@ '{{ tpos.tip_options | tojson }}' == 'null' ? null : JSON.parse('{{ tpos.tip_options }}') + + if('{{ tpos.tip_wallet }}') { + this.tip_options.push("Round") + } setInterval(function () { getRates() }, 120000)