diff --git a/lnbits/extensions/cashu/templates/cashu/wallet.html b/lnbits/extensions/cashu/templates/cashu/wallet.html index 1e93dd47..9638f347 100644 --- a/lnbits/extensions/cashu/templates/cashu/wallet.html +++ b/lnbits/extensions/cashu/templates/cashu/wallet.html @@ -627,22 +627,25 @@ page_container %} {% endraw %} --> -

{{ payInvoiceData.lnurlpay.targetUser || - payInvoiceData.lnurlpay.domain }} is requesting
between @@ -654,13 +657,13 @@ page_container %} >{{ payInvoiceData.lnurlpay.maxSendable | msatoshiFormat }} {% endraw %} {{LNBITS_DENOMINATION}} {% raw %} - +

-
+

{{ payInvoiceData.lnurlpay.description }}

@@ -674,14 +677,14 @@ page_container %} - {% raw %}
- Send {{LNBITS_DENOMINATION}} + Send Cancel
- {% endraw %} - --> +
@@ -1580,6 +1580,7 @@ page_container %} this.payInvoiceData.show = true this.payInvoiceData.invoice = null this.payInvoiceData.lnurlpay = null + this.payInvoiceData.domain = '' this.payInvoiceData.lnurlauth = null this.payInvoiceData.data.request = '' this.payInvoiceData.data.comment = '' @@ -1651,10 +1652,6 @@ page_container %} ) { this.payInvoiceData.data.request = req reqtype = 'lnurl' - return - // } else if (req.indexOf('cashu:') !== 1) { - // this.receiveData.tokensBase64 = req.slice(req.indexOf('cashu:')) - // reqtype = 'cashu' } else if (req.indexOf('eyJwcm')) { // very dirty way of parsing cashu tokens from either a pasted token or a URL like https://host.com?token=eyJwcm this.receiveData.tokensBase64 = req.slice(req.indexOf('eyJwcm')) @@ -1704,13 +1701,63 @@ page_container %} this.payInvoiceData.invoice = Object.freeze(cleanInvoice) } else if (reqtype == 'lnurl') { console.log('#### QR CODE: LNURL') - // not supported yet + this.lnurlPayFirst(this.payInvoiceData.data.request) } else if (reqtype == 'cashu') { console.log('#### QR CODE: CASHU TOKEN') this.payInvoiceData.show = false this.showReceiveTokens = true } }, + lnurlPayFirst: async function (address) { + var host + if (address.split('@').length == 2) { + let [user, lnaddresshost] = address.split('@') + host = `https://${lnaddresshost}/.well-known/lnurlp/${user}` + } else if (address.toLowerCase().slice(0, 6) === 'lnurl1') { + // let host = Buffer.from( + // bech32.fromWords(bech32.decode(address, 20000).words) + // ).toString() + // var {data} = await axios.get(host) + const {data} = await LNbits.api.request( + 'POST', + '/api/v1/payments/decode', + '', + { + data: address + } + ) + host = data.domain + } + var {data} = await axios.get(host) + if (data.tag == 'payRequest') { + this.payInvoiceData.domain = host.split('https://')[1].split('/')[0] + this.payInvoiceData.lnurlpay = data + if ( + this.payInvoiceData.lnurlpay.maxSendable == + this.payInvoiceData.lnurlpay.minSendable + ) { + this.payInvoiceData.data.amount = + this.payInvoiceData.lnurlpay.maxSendable / 1000 + } + this.payInvoiceData.show = true + } + }, + lnurlPaySecond: async function () { + let amount = this.payInvoiceData.data.amount + if ( + this.payInvoiceData.lnurlpay.tag == 'payRequest' && + this.payInvoiceData.lnurlpay.minSendable <= + amount * 1000 <= + this.payInvoiceData.lnurlpay.maxSendable + ) { + var {data} = await axios.get( + `${this.payInvoiceData.lnurlpay.callback}?amount=${amount * 1000}` + ) + console.log(data.pr) + this.payInvoiceData.data.request = data.pr + this.decodeRequest() + } + }, payInvoice: function () { let dismissPaymentMsg = this.$q.notify({ timeout: 0, @@ -1725,34 +1772,35 @@ page_container %} ] }) }, - payLnurl: function () { - let dismissPaymentMsg = this.$q.notify({ - timeout: 0, - message: 'Processing payment...', - position: 'top', - actions: [ - { - icon: 'close', - color: 'white', - handler: () => {} - } - ] - }) - }, - authLnurl: function () { - let dismissAuthMsg = this.$q.notify({ - timeout: 10, - message: 'Performing authentication...', - position: 'top', - actions: [ - { - icon: 'close', - color: 'white', - handler: () => {} - } - ] - }) - }, + // payLnurl: function () { + // let dismissPaymentMsg = this.$q.notify({ + // timeout: 0, + // message: 'Processing payment...', + // position: 'top', + // actions: [ + // { + // icon: 'close', + // color: 'white', + // handler: () => {} + // } + // ] + // }) + // this.lnurlPaySecond() + // }, + // authLnurl: function () { + // let dismissAuthMsg = this.$q.notify({ + // timeout: 10, + // message: 'Performing authentication...', + // position: 'top', + // actions: [ + // { + // icon: 'close', + // color: 'white', + // handler: () => {} + // } + // ] + // }) + // }, /////////////////////////////////// WALLET /////////////////////////////////// showInvoiceCreateDialog: async function () {