add rounding tip option

This commit is contained in:
Tiago Vasconcelos 2022-10-17 11:40:30 +01:00 committed by Vlad Stan
parent 96046b8d0c
commit 9430aa28c7
2 changed files with 35 additions and 20 deletions

View file

@ -139,8 +139,12 @@
input-debounce="0" input-debounce="0"
new-value-mode="add-unique" new-value-mode="add-unique"
label="Tip % Options (hit enter to add values)" label="Tip % Options (hit enter to add values)"
><q-tooltip>Hit enter to add values</q-tooltip></q-select ><q-tooltip>Hit enter to add values</q-tooltip>
> <template v-slot:hint>
You can leave this blank. A default rounding option is available
(round amount to a value)
</template>
</q-select>
<div class="row q-mt-lg"> <div class="row q-mt-lg">
<q-btn <q-btn
unelevated unelevated

View file

@ -17,7 +17,6 @@
<h5 class="q-mt-none q-mb-sm"> <h5 class="q-mt-none q-mb-sm">
{% raw %}{{ fsat }}{% endraw %} <small>sat</small> {% raw %}{{ fsat }}{% endraw %} <small>sat</small>
</h5> </h5>
<p>{% raw %}{{ parseFloat(roundToSugestion) }}{% endraw %}</p>
</div> </div>
</div> </div>
</q-page-sticky> </q-page-sticky>
@ -232,9 +231,9 @@
rounded rounded
color="primary" color="primary"
label="Round" label="Round"
></q-btn ></q-btn>
>
<q-input <q-input
class="q-my-lg"
ref="inputRounding" ref="inputRounding"
v-if="rounding" v-if="rounding"
filled filled
@ -243,14 +242,14 @@
hint="Rounded amount" hint="Rounded amount"
> >
<template v-slot:append> <template v-slot:append>
<q-icon name="send" @click="processTipSelection((1 - (amount/tipRounding))*100)" /> <q-icon name="send" @click="calculatePercent" />
</template> </template>
</q-input> </q-input>
</div> </div>
<div class="text-center q-mb-xl">
<p><a @click="processTipSelection(0)"> No, thanks</a></p>
</div>
<div class="row q-mt-lg"> <div class="row q-mt-lg">
<q-btn flat color="primary" @click="processTipSelection(0)"
>No, thanks</q-btn
>
<q-btn v-close-popup flat color="grey" class="q-ml-auto">Close</q-btn> <q-btn v-close-popup flat color="grey" class="q-ml-auto">Close</q-btn>
</div> </div>
</q-card> </q-card>
@ -445,6 +444,18 @@
this.tipRounding = this.roundToSugestion this.tipRounding = this.roundToSugestion
this.$nextTick(() => this.$refs.inputRounding.focus()) 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: 'Value must be greater than initial amount'
})
this.tipRounding = this.roundToSugestion
return
}
this.processTipSelection(change)
},
closeInvoiceDialog: function () { closeInvoiceDialog: function () {
this.stack = [] this.stack = []
this.tipAmount = 0.0 this.tipAmount = 0.0
@ -644,7 +655,7 @@
: JSON.parse('{{ tpos.tip_options }}') : JSON.parse('{{ tpos.tip_options }}')
if ('{{ tpos.tip_wallet }}') { if ('{{ tpos.tip_wallet }}') {
this.tip_options.push("Round") this.tip_options.push('Round')
} }
setInterval(function () { setInterval(function () {
getRates() getRates()