Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for funds on ATM #95

Merged
merged 2 commits into from
Aug 20, 2024
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
16 changes: 15 additions & 1 deletion static/js/tpos.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,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 @@ -328,7 +342,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