diff --git a/lnbits/static/js/wallet.js b/lnbits/static/js/wallet.js index 4aa6f62b9..a1fbdae53 100644 --- a/lnbits/static/js/wallet.js +++ b/lnbits/static/js/wallet.js @@ -211,6 +211,54 @@ new Vue({ }) } }, + lnurlScan() { + LNbits.api + .request( + 'GET', + '/api/v1/lnurlscan/' + this.parse.data.request, + this.g.wallet.adminkey + ) + .catch(err => { + LNbits.utils.notifyApiError(err) + }) + .then(response => { + let data = response.data + + if (data.status === 'ERROR') { + this.$q.notify({ + timeout: 5000, + type: 'warning', + message: `${data.domain} lnurl call failed.`, + caption: data.reason + }) + return + } + + if (data.kind === 'pay') { + this.parse.lnurlpay = Object.freeze(data) + this.parse.data.amount = data.minSendable / 1000 + } else if (data.kind === 'auth') { + this.parse.lnurlauth = Object.freeze(data) + } else if (data.kind === 'withdraw') { + this.parse.show = false + this.receive.show = true + this.receive.status = 'pending' + this.receive.paymentReq = null + this.receive.paymentHash = null + this.receive.data.amount = data.maxWithdrawable / 1000 + this.receive.data.memo = data.defaultDescription + this.receive.minMax = [ + data.minWithdrawable / 1000, + data.maxWithdrawable / 1000 + ] + this.receive.lnurl = { + domain: data.domain, + callback: data.callback, + fixed: data.fixed + } + } + }) + }, decodeQR: function (res) { this.parse.data.request = res this.decodeRequest() @@ -218,7 +266,8 @@ new Vue({ }, decodeRequest: function () { this.parse.show = true - let req = this.parse.data.request.toLowerCase() + this.parse.data.request = this.parse.data.request.trim().toLowerCase() + let req = this.parse.data.request if (req.startsWith('lightning:')) { this.parse.data.request = req.slice(10) } else if (req.startsWith('lnurl:')) { @@ -228,52 +277,7 @@ new Vue({ } req = this.parse.data.request if (req.startsWith('lnurl1') || req.match(/[\w.+-~_]+@[\w.+-~_]/)) { - LNbits.api - .request( - 'GET', - '/api/v1/lnurlscan/' + this.parse.data.request, - this.g.wallet.adminkey - ) - .catch(err => { - LNbits.utils.notifyApiError(err) - }) - .then(response => { - let data = response.data - - if (data.status === 'ERROR') { - this.$q.notify({ - timeout: 5000, - type: 'warning', - message: `${data.domain} lnurl call failed.`, - caption: data.reason - }) - return - } - - if (data.kind === 'pay') { - this.parse.lnurlpay = Object.freeze(data) - this.parse.data.amount = data.minSendable / 1000 - } else if (data.kind === 'auth') { - this.parse.lnurlauth = Object.freeze(data) - } else if (data.kind === 'withdraw') { - this.parse.show = false - this.receive.show = true - this.receive.status = 'pending' - this.receive.paymentReq = null - this.receive.paymentHash = null - this.receive.data.amount = data.maxWithdrawable / 1000 - this.receive.data.memo = data.defaultDescription - this.receive.minMax = [ - data.minWithdrawable / 1000, - data.maxWithdrawable / 1000 - ] - this.receive.lnurl = { - domain: data.domain, - callback: data.callback, - fixed: data.fixed - } - } - }) + this.lnurlScan() return }