Skip to content

Commit 30dfae3

Browse files
authored
Satoshi denominated tpos (#63)
* allow satoshi denomination * use of formatSat * apply suggestions from code review * denomIsSats is possitive now * prettier * some refactoring + one missed line to hide
1 parent e5e97ad commit 30dfae3

File tree

2 files changed

+60
-30
lines changed

2 files changed

+60
-30
lines changed

Diff for: templates/tpos/index.html

+14-5
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ <h6 class="text-subtitle1 q-my-none">
591591
return {
592592
tposs: [],
593593
currencyOptions: [
594+
'sats',
594595
'USD',
595596
'EUR',
596597
'GBP',
@@ -1009,7 +1010,8 @@ <h6 class="text-subtitle1 q-my-none">
10091010
itemFormatPrice(price, id) {
10101011
const tpos = id.split(':')[0]
10111012
const currency = _.findWhere(this.tposs, {id: tpos}).currency
1012-
return LNbits.utils.formatCurrency(Number(price).toFixed(2), currency)
1013+
1014+
return this.formatAmount(price, currency)
10131015
},
10141016
openItemDialog(id) {
10151017
const [tposId, itemId] = id.split(':')
@@ -1154,10 +1156,7 @@ <h6 class="text-subtitle1 q-my-none">
11541156
id: tpos.wallet
11551157
})
11561158
data.forEach(item => {
1157-
item.formattedPrice = LNbits.utils.formatCurrency(
1158-
Number(item.price).toFixed(2),
1159-
tpos.currency
1160-
)
1159+
item.formattedPrice = this.formatAmount(item.price, tpos.currency)
11611160
})
11621161
this.fileDataDialog.data = data
11631162
this.fileDataDialog.count = data.length
@@ -1174,6 +1173,16 @@ <h6 class="text-subtitle1 q-my-none">
11741173
openUrlDialog(id) {
11751174
this.urlDialog.data = _.findWhere(this.tposs, {id})
11761175
this.urlDialog.show = true
1176+
},
1177+
formatAmount: function (amount, currency) {
1178+
if (currency == 'sats') {
1179+
return LNbits.utils.formatSat(amount) + ' sat'
1180+
} else {
1181+
return LNbits.utils.formatCurrency(
1182+
Number(amount).toFixed(2),
1183+
currency
1184+
)
1185+
}
11771186
}
11781187
},
11791188
created: function () {

Diff for: templates/tpos/tpos.html

+46-25
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,16 @@
2525
<div class="row justify-center full-width">
2626
<div class="col-12 col-sm-8 col-md-6 col-lg-4 text-center">
2727
<h3 class="q-mb-md">${ amountFormatted }</h3>
28-
<h5 class="q-mt-none q-mb-sm">${ fsat }<small> sat</small></h5>
28+
<h5 v-show="!denomIsSats" class="q-mt-none q-mb-sm">
29+
${ fsat }<small> sat</small>
30+
</h5>
2931
<div v-if="total > 0.0">
3032
<h5>
31-
<i>Total: ${totalFormatted}<br />${totalfsat} sat</i>
33+
<i
34+
>Total: ${totalFormatted}<span v-if="!denomIsSats"
35+
><br />${totalfsat} sat</span
36+
></i
37+
>
3238
</h5>
3339
</div>
3440
</div>
@@ -220,7 +226,9 @@ <h5>
220226
<div class="row full-width q-pa-md">
221227
<div class="col-12 text-center">
222228
<h3 class="q-mb-md">${totalFormatted}</h3>
223-
<h5 class="q-mt-none q-mb-sm">${totalfsat}<small> sat</small></h5>
229+
<h5 v-show="!denomIsSats" class="q-mt-none q-mb-sm">
230+
${totalfsat}<small> sat</small>
231+
</h5>
224232
</div>
225233
<div class="col-12">
226234
<table class="table full-width">
@@ -755,28 +763,26 @@ <h5 class="q-mt-none q-mb-sm">
755763
cartDrawer: this.$q.screen.width > 1200,
756764
searchTerm: '',
757765
categoryFilter: '',
758-
cart: new Map()
766+
cart: new Map(),
767+
denomIsSats: '{{ tpos.currency }}' == 'sats'
759768
}
760769
},
761770
computed: {
762771
amount: function () {
763772
if (!this.stack.length) return 0.0
764-
return this.stack.reduce((acc, dig) => acc * 10 + dig, 0) * 0.01
773+
return (
774+
this.stack.reduce((acc, dig) => acc * 10 + dig, 0) *
775+
(this.currency == 'sats' ? 1 : 0.01)
776+
)
765777
},
766778
amountFormatted: function () {
767-
return LNbits.utils.formatCurrency(
768-
this.amount.toFixed(2),
769-
this.currency
770-
)
779+
return this.formatAmount(this.amount, this.currency)
771780
},
772781
totalFormatted() {
773-
return LNbits.utils.formatCurrency(this.total.toFixed(2), this.currency)
782+
return this.formatAmount(this.total, this.currency)
774783
},
775784
amountWithTipFormatted: function () {
776-
return LNbits.utils.formatCurrency(
777-
(this.amount + this.tipAmount).toFixed(2),
778-
this.currency
779-
)
785+
return this.formatAmount(this.amount + this.tipAmount, this.currency)
780786
},
781787
sat: function () {
782788
if (!this.exchangeRate) return 0
@@ -1000,7 +1006,11 @@ <h5 class="q-mt-none q-mb-sm">
10001006
},
10011007
submitForm: function () {
10021008
if (this.total != 0.0) {
1003-
this.stack = Array.from(String(Math.ceil(this.total * 100)), Number)
1009+
if (this.currency == 'sats') {
1010+
this.stack = Array.from(String(Math.ceil(this.total), Number))
1011+
} else {
1012+
this.stack = Array.from(String(Math.ceil(this.total * 100)), Number)
1013+
}
10041014
}
10051015
if (!this.exchangeRate || this.exchangeRate == 0 || this.sat == 0) {
10061016
this.$q.notify({
@@ -1224,12 +1234,16 @@ <h5 class="q-mt-none q-mb-sm">
12241234
})
12251235
},
12261236
getRates() {
1227-
LNbits.api
1228-
.request('GET', `/tpos/api/v1/rate/${this.currency}`)
1229-
.then(response => {
1230-
this.exchangeRate = response.data.rate
1231-
})
1232-
.catch(e => console.error(e))
1237+
if (this.currency == 'sats') {
1238+
this.exchangeRate = 1
1239+
} else {
1240+
LNbits.api
1241+
.request('GET', `/tpos/api/v1/rate/${this.currency}`)
1242+
.then(response => {
1243+
this.exchangeRate = response.data.rate
1244+
})
1245+
.catch(e => console.error(e))
1246+
}
12331247
},
12341248
getLastPayments() {
12351249
return axios
@@ -1285,6 +1299,16 @@ <h5 class="q-mt-none q-mb-sm">
12851299
} else {
12861300
this.categoryFilter = category == 'All' ? '' : category
12871301
}
1302+
},
1303+
formatAmount: function (amount, currency) {
1304+
if (currency == 'sats') {
1305+
return LNbits.utils.formatSat(amount) + ' sat'
1306+
} else {
1307+
return LNbits.utils.formatCurrency(
1308+
Number(amount).toFixed(2),
1309+
currency
1310+
)
1311+
}
12881312
}
12891313
},
12901314
created: function () {
@@ -1301,10 +1325,7 @@ <h5 class="q-mt-none q-mb-sm">
13011325

13021326
this.items = JSON.parse(`{{ tpos.items | safe }}`)
13031327
this.items.forEach((item, id) => {
1304-
item.formattedPrice = LNbits.utils.formatCurrency(
1305-
item.price,
1306-
this.currency
1307-
)
1328+
item.formattedPrice = this.formatAmount(item.price, this.currency)
13081329
item.id = id
13091330
return item
13101331
})

0 commit comments

Comments
 (0)