diff --git a/lnbits/core/static/js/wallet.js b/lnbits/core/static/js/wallet.js index f3dd8b6..3a5eec4 100644 --- a/lnbits/core/static/js/wallet.js +++ b/lnbits/core/static/js/wallet.js @@ -1,4 +1,4 @@ -/* globals moment, decode, Vue, VueQrcodeReader, VueQrcode, Quasar, LNbits, _, EventHub, Chart */ +/* globals windowMixin, decode, Vue, VueQrcodeReader, VueQrcode, Quasar, LNbits, _, EventHub, Chart */ Vue.component(VueQrcode.name, VueQrcode) Vue.use(VueQrcodeReader) @@ -132,8 +132,9 @@ new Vue({ send: { show: false, invoice: null, + lnurl: {}, data: { - bolt11: '' + request: '' } }, theCamera: { @@ -206,12 +207,6 @@ new Vue({ } }, methods: { - // closeCamera: function () { - // this.sendCamera.show = false - // }, - // showCamera: function () { - // this.sendCamera.show = true - // }, closeCamera: function () { this.theCamera.show = false }, @@ -240,8 +235,9 @@ new Vue({ this.send = { show: true, invoice: null, + lnurl: {}, data: { - bolt11: '' + request: '' }, paymentChecker: null } @@ -253,7 +249,6 @@ new Vue({ }, 10000) }, closeSendDialog: function () { - // this.sendCamera.show = false var checker = this.send.paymentChecker setTimeout(function () { clearInterval(checker) @@ -290,29 +285,32 @@ new Vue({ }) }, decodeQR: function (res) { - if (res.substring(0, 4) == 'lnurl') { - console.log(res) - var self = this + this.send.data.request = res + this.decodeRequest() + this.sendCamera.show = false + }, + decodeRequest: function () { + if (this.send.data.request.startsWith('lightning:')) { + this.send.data.request = this.send.data.request.slice(10) + } + if (this.send.data.request.startsWith('lnurl:')) { + this.send.data.request = this.send.data.request.slice(6) + } + if (this.send.data.request.toLowerCase().startsWith('lnurl1')) { LNbits.api - .request('GET', '/lnurlscan/' + res, this.g.user.wallets[0].adminkey) + .request( + 'GET', + '/api/v1/lnurlscan/' + this.send.data.request, + this.g.user.wallets[0].adminkey + ) .then(function (response) { - console.log(response.data) + this.send.lnurl[response.kind] = Object.freeze(response) }) .catch(function (error) { - clearInterval(self.checker) LNbits.utils.notifyApiError(error) }) - } else { - this.send.data.bolt11 = res - this.decodeInvoice() - this.theCamera.show = false - } - }, - - decodeInvoice: function () { - if (this.send.data.bolt11.startsWith('lightning:')) { - this.send.data.bolt11 = this.send.data.bolt11.slice(10) + return } let invoice diff --git a/lnbits/core/templates/core/wallet.html b/lnbits/core/templates/core/wallet.html index 5bf94da..bf94e96 100644 --- a/lnbits/core/templates/core/wallet.html +++ b/lnbits/core/templates/core/wallet.html @@ -17,7 +17,7 @@ color="deep-purple" class="full-width" @click="showSendDialog" - >SendPaste Request
- This whole wallet will be deleted, the funds will be - UNRECOVERABLE. -
-+ This whole wallet will be deleted, the funds will be + UNRECOVERABLE. +
+
+ Description: {{ send.invoice.description }}
+ Payment hash: {{ send.invoice.hash }}
+ Expire date: {{ send.invoice.expireDate }}
+
", methods=["GET"])
+@api_check_wallet_key("invoice")
+async def api_lnurlscan(code: str):
+ try:
+ url = lnurl.Lnurl(code)
+ except ValueError:
+ return jsonify({"error": "invalid lnurl"}), HTTPStatus.BAD_REQUEST
+
+ domain = urlparse(url.url).netloc
+ if url.is_login:
+ return jsonify({"domain": domain, "kind": "auth", "error": "unsupported"})
+
+ data: lnurl.LnurlResponseModel = lnurl.get(url.url)
+ if not data.ok:
+ return jsonify({"domain": domain, "error": "failed to get parameters"})
+
+ if type(data) is lnurl.LnurlChannelResponse:
+ return jsonify({"domain": domain, "kind": "channel", "error": "unsupported"})
+
+ params = data.dict()
+ if type(data) is lnurl.LnurlWithdrawResponse:
+ params.update(kind="withdraw", fixed=data.min_withdrawable == data.max_withdrawable)
+
+ if type(data) is lnurl.LnurlPayResponse:
+ params.update(kind="pay", fixed=data.min_sendable == data.max_sendable)
+
+ params.update(domain=domain)
+ return jsonify(params)
+>>>>>>> da8fd9a... send/create buttons wip.
diff --git a/lnbits/extensions/lnurlp/templates/lnurlp/display.html b/lnbits/extensions/lnurlp/templates/lnurlp/display.html
index fd9b3de..a2e0389 100644
--- a/lnbits/extensions/lnurlp/templates/lnurlp/display.html
+++ b/lnbits/extensions/lnurlp/templates/lnurlp/display.html
@@ -26,9 +26,7 @@
LNbits LNURL-pay link
-
- Use an LNURL compatible bitcoin wallet to pay.
-
+ Use an LNURL compatible bitcoin wallet to pay.