diff --git a/static/js/tpos.js b/static/js/tpos.js index 2b5bbc6..8ade174 100644 --- a/static/js/tpos.js +++ b/static/js/tpos.js @@ -289,12 +289,26 @@ const tposJS = async () => { atmGetWithdraw: function () { self = this var dialog = this.invoiceDialog + if (this.sat > this.withdrawamtposs) { + this.$q.notify({ + type: 'negative', + message: 'Amount exceeds the maximum withdrawal limit.' + }) + return + } LNbits.api .request( 'GET', `/tpos/api/v1/atm/withdraw/` + this.atmToken + `/` + this.sat ) .then(function (res) { + if (res.data.status == 'ERROR') { + self.$q.notify({ + type: 'negative', + message: res.data.reason + }) + return + } lnurl = res.data.lnurl dialog.data = {payment_request: lnurl} dialog.show = true @@ -331,7 +345,7 @@ const tposJS = async () => { this.connectionWithdraw.close() } } - this.getRates() + self.getRates() }) .catch(function (error) { LNbits.utils.notifyApiError(error) diff --git a/views_api.py b/views_api.py index 36debb7..7102960 100644 --- a/views_api.py +++ b/views_api.py @@ -7,6 +7,7 @@ get_latest_payments_by_extension, get_standalone_payment, get_user, + get_wallet, ) from lnbits.core.models import Payment, WalletTypeInfo from lnbits.core.services import create_invoice @@ -333,6 +334,16 @@ async def api_tpos_create_withdraw( "status": "ERROR", "reason": f"TPoS {lnurlcharge.tpos_id} not found on this server", } + + wallet = await get_wallet(tpos.wallet) + assert wallet + balance = int(wallet.balance_msat / 1000) + if balance < int(amount): + return { + "status": "ERROR", + "reason": f"Insufficient balance. Your balance is {balance} sats", + } + lnurlcharge = await update_lnurlcharge( LNURLCharge( id=withdraw_token,