mirror of
https://github.com/lnbits/lnbits.git
synced 2025-10-11 13:02:39 +02:00
Merge pull request #1056 from lnbits/fix/tipingRoundTpos
Add Rounding as tipping option
This commit is contained in:
@@ -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
|
||||||
|
@@ -214,19 +214,48 @@
|
|||||||
style="padding: 10px; margin: 3px"
|
style="padding: 10px; margin: 3px"
|
||||||
unelevated
|
unelevated
|
||||||
@click="processTipSelection(tip)"
|
@click="processTipSelection(tip)"
|
||||||
size="xl"
|
size="lg"
|
||||||
:outline="!($q.dark.isActive)"
|
:outline="!($q.dark.isActive)"
|
||||||
rounded
|
rounded
|
||||||
color="primary"
|
color="primary"
|
||||||
v-for="tip in this.tip_options"
|
v-for="tip in tip_options.filter(f => f != 'Round')"
|
||||||
:key="tip"
|
:key="tip"
|
||||||
>{% raw %}{{ tip }}{% endraw %}%</q-btn
|
>{% raw %}{{ tip }}{% endraw %}%</q-btn
|
||||||
>
|
>
|
||||||
</div>
|
<q-btn
|
||||||
<div class="text-center q-mb-xl">
|
style="padding: 10px; margin: 3px"
|
||||||
<p><a @click="processTipSelection(0)"> No, thanks</a></p>
|
unelevated
|
||||||
|
@click="setRounding"
|
||||||
|
size="lg"
|
||||||
|
:outline="!($q.dark.isActive)"
|
||||||
|
rounded
|
||||||
|
color="primary"
|
||||||
|
label="Round to"
|
||||||
|
></q-btn>
|
||||||
|
<div class="row q-my-lg" v-if="rounding">
|
||||||
|
<q-input
|
||||||
|
class="col"
|
||||||
|
ref="inputRounding"
|
||||||
|
v-model.number="tipRounding"
|
||||||
|
:placeholder="roundToSugestion"
|
||||||
|
type="number"
|
||||||
|
hint="Total amount including tip"
|
||||||
|
:prefix="currency"
|
||||||
|
>
|
||||||
|
</q-input>
|
||||||
|
<q-btn
|
||||||
|
class="q-ml-sm"
|
||||||
|
style="margin-bottom: 20px"
|
||||||
|
color="primary"
|
||||||
|
@click="calculatePercent"
|
||||||
|
>Ok</q-btn
|
||||||
|
>
|
||||||
|
</div>
|
||||||
</div>
|
</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>
|
||||||
@@ -336,6 +365,7 @@
|
|||||||
exchangeRate: null,
|
exchangeRate: null,
|
||||||
stack: [],
|
stack: [],
|
||||||
tipAmount: 0.0,
|
tipAmount: 0.0,
|
||||||
|
tipRounding: null,
|
||||||
hasNFC: false,
|
hasNFC: false,
|
||||||
nfcTagReading: false,
|
nfcTagReading: false,
|
||||||
lastPaymentsDialog: {
|
lastPaymentsDialog: {
|
||||||
@@ -356,7 +386,8 @@
|
|||||||
},
|
},
|
||||||
complete: {
|
complete: {
|
||||||
show: false
|
show: false
|
||||||
}
|
},
|
||||||
|
rounding: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -389,9 +420,47 @@
|
|||||||
},
|
},
|
||||||
fsat: function () {
|
fsat: function () {
|
||||||
return LNbits.utils.formatSat(this.sat)
|
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: {
|
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 () {
|
closeInvoiceDialog: function () {
|
||||||
this.stack = []
|
this.stack = []
|
||||||
this.tipAmount = 0.0
|
this.tipAmount = 0.0
|
||||||
@@ -414,6 +483,8 @@
|
|||||||
},
|
},
|
||||||
submitForm: function () {
|
submitForm: function () {
|
||||||
if (this.tip_options && this.tip_options.length) {
|
if (this.tip_options && this.tip_options.length) {
|
||||||
|
this.rounding = false
|
||||||
|
this.tipRounding = null
|
||||||
this.showTipModal()
|
this.showTipModal()
|
||||||
} else {
|
} else {
|
||||||
this.showInvoice()
|
this.showInvoice()
|
||||||
@@ -589,10 +660,26 @@
|
|||||||
'{{ tpos.tip_options | tojson }}' == 'null'
|
'{{ tpos.tip_options | tojson }}' == 'null'
|
||||||
? null
|
? null
|
||||||
: JSON.parse('{{ tpos.tip_options }}')
|
: JSON.parse('{{ tpos.tip_options }}')
|
||||||
|
|
||||||
|
if ('{{ tpos.tip_wallet }}') {
|
||||||
|
this.tip_options.push('Round')
|
||||||
|
}
|
||||||
setInterval(function () {
|
setInterval(function () {
|
||||||
getRates()
|
getRates()
|
||||||
}, 120000)
|
}, 120000)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
<style scoped>
|
||||||
|
input::-webkit-outer-spin-button,
|
||||||
|
input::-webkit-inner-spin-button {
|
||||||
|
-webkit-appearance: none;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Firefox */
|
||||||
|
input[type='number'] {
|
||||||
|
-moz-appearance: textfield;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Reference in New Issue
Block a user