From d42e1d1b0df8be6ec1fead89b61cbd090e7acc08 Mon Sep 17 00:00:00 2001 From: Tiago Vasconcelos Date: Tue, 26 Nov 2024 16:50:00 +0000 Subject: [PATCH] fix currency errors on v1 (#109) * fix currency errors on v1 * fix: close cart drawer on completion * chore: fix lint * fix: use quasar screen api --------- Co-authored-by: Vlad Stan --- static/js/tpos.js | 18 ++++++++++++++---- templates/tpos/tpos.html | 2 +- views.py | 3 ++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/static/js/tpos.js b/static/js/tpos.js index 647f986..af69c68 100644 --- a/static/js/tpos.js +++ b/static/js/tpos.js @@ -91,7 +91,7 @@ window.app = Vue.createApp({ }, monochrome: this.$q.localStorage.getItem('lnbits.tpos.color') || false, showPoS: true, - cartDrawer: this.$q.screen.width > 1200, + cartDrawer: this.$q.screen.gt.md, searchTerm: '', categoryFilter: '', cart: new Map(), @@ -101,6 +101,7 @@ window.app = Vue.createApp({ computed: { amount: function () { if (!this.stack.length) return 0.0 + if (this.currency == 'sats') return Number(this.stack.join('')) return ( this.stack.reduce((acc, dig) => acc * 10 + dig, 0) * (this.currency == 'sats' ? 1 : 0.01) @@ -179,7 +180,7 @@ window.app = Vue.createApp({ return items }, drawerWidth() { - return this.$q.screen.width < 500 ? 375 : 450 + return this.$q.screen.lt.sm ? 375 : 450 }, formattedCartTax() { return this.formatAmount(this.cartTax, this.currency) @@ -335,7 +336,7 @@ window.app = Vue.createApp({ dialog.show = false this.atmPin = null this.atmToken = '' - this.complete.show = true + this.showComplete() this.atmMode = false this.connectionWithdraw.close() } @@ -476,7 +477,7 @@ window.app = Vue.createApp({ dialog.show = false this.clearCart() - this.complete.show = true + this.showComplete() } }) }, 3000) @@ -619,11 +620,13 @@ window.app = Vue.createApp({ getRates() { if (this.currency == 'sats') { this.exchangeRate = 1 + Quasar.Loading.hide() } else { LNbits.api .request('GET', `/tpos/api/v1/rate/${this.currency}`) .then(response => { this.exchangeRate = response.data.rate + Quasar.Loading.hide() }) .catch(e => console.error(e)) } @@ -689,9 +692,16 @@ window.app = Vue.createApp({ } else { return LNbits.utils.formatCurrency(Number(amount).toFixed(2), currency) } + }, + showComplete() { + this.complete.show = true + if (this.$q.screen.lt.lg && this.cartDrawer) { + this.cartDrawer = false + } } }, created() { + Quasar.Loading.show() this.tposId = tpos.id this.currency = tpos.currency this.atmPremium = tpos.withdraw_premium / 100 diff --git a/templates/tpos/tpos.html b/templates/tpos/tpos.html index e64ef2f..64e2724 100644 --- a/templates/tpos/tpos.html +++ b/templates/tpos/tpos.html @@ -244,7 +244,7 @@
show-if-above bordered :width="drawerWidth" - :breakpoint="1200" + :breakpoint="1024" >
diff --git a/views.py b/views.py index 6bfd586..dd61002 100644 --- a/views.py +++ b/views.py @@ -1,4 +1,5 @@ from http import HTTPStatus +from typing import Optional from fastapi import APIRouter, Depends, HTTPException, Request from lnbits.core.models import User @@ -31,7 +32,7 @@ async def tpos(request: Request, tpos_id): raise HTTPException( status_code=HTTPStatus.NOT_FOUND, detail="TPoS does not exist." ) - withdraw_pin_open = 0 + withdraw_pin_open: Optional[int] = 0 if tpos.withdraw_pin_disabled: withdraw_pin_open = tpos.withdraw_pin