Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions static/components/receipt.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ window.app.component('receipt', {
return amount
}
return amount / this.exchangeRate
},
formatCurrencyAmount(amount) {
return roundTposCurrencyAmount(amount, this.currency).toFixed(
getTposCurrencyFractionDigits(this.currency)
)
}
},
created() {
Expand Down Expand Up @@ -137,7 +142,7 @@ window.app.component('receipt', {
<span v-if="currency != 'sats'" v-text="currencyText"></span>
</div>
<div class="col-6 text-right">
<span v-text="cartSubtotal.toFixed(2)"></span>
<span v-text="formatCurrencyAmount(cartSubtotal)"></span>
</div>
</div>
<div class="row">
Expand All @@ -146,7 +151,7 @@ window.app.component('receipt', {
<span v-if="currency != 'sats'" v-text="currencyText"></span>
</div>
<div class="col-6 text-right">
<span v-text="data.extra.details.taxValue.toFixed(2)"></span>
<span v-text="formatCurrencyAmount(data.extra.details.taxValue)"></span>
</div>
</div>
<div class="row">
Expand All @@ -155,7 +160,7 @@ window.app.component('receipt', {
<span v-if="currency != 'sats'" v-text="currencyText"></span>
</div>
<div class="col-6 text-right">
<span v-text="cartTotal.toFixed(2)"></span>
<span v-text="formatCurrencyAmount(cartTotal)"></span>
</div>
</div>
<div class="row" v-if="showBitcoinDetails">
Expand Down
34 changes: 32 additions & 2 deletions static/js/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
const getTposCurrencyFractionDigits = currency => {
const code = (currency || '').toUpperCase()
if (code === 'SAT' || code === 'SATS') {
return 0
}
try {
return new Intl.NumberFormat(window.i18n.global.locale, {
style: 'currency',
currency: code
}).resolvedOptions().maximumFractionDigits
} catch (e) {
return 2
}
}

const roundTposCurrencyAmount = (amount, currency) => {
const value = Number(amount) || 0
if ((currency || '').toLowerCase() === 'sats') {
return Math.ceil(value)
}
const scale = 10 ** getTposCurrencyFractionDigits(currency)
return Math.round(value * scale) / scale
}

const mapTpos = obj => {
obj.date = Quasar.date.formatDate(
new Date(obj.time * 1000),
Expand Down Expand Up @@ -468,7 +492,10 @@ window.app = Vue.createApp({
if (currency == 'sats') {
return LNbits.utils.formatSat(price) + ' sat'
} else {
return LNbits.utils.formatCurrency(Number(price).toFixed(2), currency)
return LNbits.utils.formatCurrency(
roundTposCurrencyAmount(price, currency),
currency
)
}
},
openItemDialog(id) {
Expand Down Expand Up @@ -649,7 +676,10 @@ window.app = Vue.createApp({
if (currency == 'sats') {
return LNbits.utils.formatSat(amount) + ' sat'
} else {
return LNbits.utils.formatCurrency(Number(amount).toFixed(2), currency)
return LNbits.utils.formatCurrency(
roundTposCurrencyAmount(amount, currency),
currency
)
}
}
},
Expand Down
Loading
Loading