fix products price in fiat

This commit is contained in:
Tiago Vasconcelos 2022-12-29 12:02:03 +00:00
parent 11b015e516
commit 690ef74313
3 changed files with 29 additions and 4 deletions

View file

@ -94,7 +94,10 @@
</q-item-section> </q-item-section>
<q-item-section side> <q-item-section side>
<span> {{p.price}} sats</span> <span v-if="stall.currency != 'sat'"
>{{ getAmountFormated(p.price) }}</span
>
<span v-else> {{p.price}} sats</span>
</q-item-section> </q-item-section>
</q-item> </q-item>
{% endraw %} {% endraw %}
@ -273,6 +276,12 @@
} }
return obj return obj
} }
const mapProductsItems = obj => {
obj.price = (obj.price / 100).toFixed(2)
return obj
}
Vue.component(VueQrcode.name, VueQrcode) Vue.component(VueQrcode.name, VueQrcode)
const nostr = window.NostrTools const nostr = window.NostrTools
new Vue({ new Vue({
@ -314,6 +323,9 @@
} }
}, },
methods: { methods: {
getAmountFormated(amount) {
return LNbits.utils.formatCurrency(amount, this.stall.currency)
},
clearMessage() { clearMessage() {
this.newMessage = '' this.newMessage = ''
this.$refs.newMessage.focus() this.$refs.newMessage.focus()
@ -471,6 +483,10 @@
price: product.price price: product.price
} }
}) })
console.log(this.stall)
if (this.stall.currency != 'sat') {
this.products = this.products.map(mapProductsItems)
}
let data = this.$q.localStorage.getItem(`lnbits.shop.data`) || false let data = this.$q.localStorage.getItem(`lnbits.shop.data`) || false

View file

@ -284,6 +284,11 @@
</div> </div>
{% endblock %} {% block scripts %} {% endblock %} {% block scripts %}
<script> <script>
const mapProductsItems = obj => {
obj.price = (obj.price / 100).toFixed(2)
return obj
}
Vue.component(VueQrcode.name, VueQrcode) Vue.component(VueQrcode.name, VueQrcode)
new Vue({ new Vue({
el: '#vue', el: '#vue',
@ -333,8 +338,8 @@
let zoneCost = this.stall.zones.find( let zoneCost = this.stall.zones.find(
z => z.value == this.checkoutDialog.data.shippingzone z => z.value == this.checkoutDialog.data.shippingzone
) )
console.log(+this.cart.total, zoneCost.cost)
return this.cart.total + zoneCost.cost return +this.cart.total + zoneCost.cost
} }
}, },
methods: { methods: {
@ -350,7 +355,7 @@
} }
}, },
getAmountFormated(amount) { getAmountFormated(amount) {
return LNbits.utils.formatCurrency(amount.toFixed(2), this.unit) return LNbits.utils.formatCurrency(amount, this.unit)
}, },
async getRates() { async getRates() {
if (this.unit == 'sat') return if (this.unit == 'sat') return
@ -492,6 +497,9 @@
this.stall = JSON.parse('{{ stall | tojson }}') this.stall = JSON.parse('{{ stall | tojson }}')
this.products = JSON.parse('{{ products | tojson }}') this.products = JSON.parse('{{ products | tojson }}')
this.unit = this.stall.currency this.unit = this.stall.currency
if (this.unit != 'sat') {
this.products = this.products.map(mapProductsItems)
}
await this.getRates() await this.getRates()
setInterval(this.getRates, 300000) setInterval(this.getRates, 300000)
} }

View file

@ -122,6 +122,7 @@ async def order_chat(
"name": stall.name, "name": stall.name,
"publickey": stall.publickey, "publickey": stall.publickey,
"wallet": stall.wallet, "wallet": stall.wallet,
"currency": stall.currency,
}, },
"publickey": keys.split(",")[0] if keys else None, "publickey": keys.split(",")[0] if keys else None,
"privatekey": keys.split(",")[1] if keys else None, "privatekey": keys.split(",")[1] if keys else None,