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
@@ -26,7 +26,7 @@ color="deep-purple" class="full-width" @click="showReceiveDialog" - >ReceiveCreate Invoice
@@ -141,7 +141,9 @@
Invoice waiting to be paid - +
Payment Sent - +
Outgoing payment pending - +
@@ -199,47 +207,46 @@
-
- - - Renew keys -
LNbits wallet
- Wallet name: {{ wallet.name }}
- Wallet ID: {{ wallet.id }}
- Admin key: {{ wallet.adminkey }}
- Invoice/read key: {{ wallet.inkey }} -
- +
+ + + Renew keys +
LNbits wallet
+ Wallet name: {{ wallet.name }}
+ Wallet ID: {{ wallet.id }}
+ Admin key: {{ wallet.adminkey }}
+ Invoice/read key: {{ wallet.inkey }} +
+ + + + {% include "core/_api_docs.html" %} - - {% include "core/_api_docs.html" %} - - - - -

- This whole wallet will be deleted, the funds will be - UNRECOVERABLE. -

- Delete wallet -
-
-
-
-
-
-
+ + + +

+ This whole wallet will be deleted, the funds will be + UNRECOVERABLE. +

+ Delete wallet +
+
+
+ +
+
@@ -304,25 +311,25 @@
Read invoiceRead Cancel
+
+ {% raw %} +
{{ send.invoice.fsat }} sat
+ +

+ Description: {{ send.invoice.description }}
+ Payment hash: {{ send.invoice.hash }}
+ Expire date: {{ send.invoice.expireDate }} +

+ {% endraw %} +
+ Send satoshis + Cancel +
+
+ Not enough funds! + Cancel +
+
{% raw %}
{{ send.invoice.fsat }} sat
@@ -383,7 +413,7 @@ - + diff --git a/lnbits/core/views/api.py b/lnbits/core/views/api.py index 357bc2e..b46f40e 100644 --- a/lnbits/core/views/api.py +++ b/lnbits/core/views/api.py @@ -1,9 +1,15 @@ +<<<<<<< HEAD import trio # type: ignore import json import traceback from quart import g, jsonify, request, make_response +======= +import lnurl +from quart import g, jsonify, request +>>>>>>> da8fd9a... send/create buttons wip. from http import HTTPStatus from binascii import unhexlify +from urllib.parse import urlparse from lnbits import bolt11 from lnbits.decorators import api_check_wallet_key, api_validate_post_request @@ -131,6 +137,7 @@ async def api_payment(payment_hash): return jsonify({"paid": not payment.pending}), HTTPStatus.OK +<<<<<<< HEAD @core_app.route("/api/v1/payments/sse", methods=["GET"]) @api_check_wallet_key("invoice") async def api_payments_sse(): @@ -183,3 +190,36 @@ async def api_payments_sse(): ) response.timeout = None return response +======= + return jsonify({"paid": False}), HTTPStatus.OK + + +@core_app.route("/api/v1/lnurlscan/", 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.