Skip to content

Commit

Permalink
Check for funds on ATM (#95)
Browse files Browse the repository at this point in the history
* feat: display error if amount is too high
* check for wallet balance before creating LNURLw
  • Loading branch information
talvasconcelos authored Aug 20, 2024
1 parent 7c3bc0a commit ea18a40
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
16 changes: 15 additions & 1 deletion static/js/tpos.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -331,7 +345,7 @@ const tposJS = async () => {
this.connectionWithdraw.close()
}
}
this.getRates()
self.getRates()
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
Expand Down
11 changes: 11 additions & 0 deletions views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ea18a40

Please sign in to comment.