From 76a5196dbfe779db768ac547796c1419eb2768c5 Mon Sep 17 00:00:00 2001 From: calle <93376500+callebtc@users.noreply.github.com> Date: Thu, 21 Jul 2022 12:38:30 +0200 Subject: [PATCH] LNURLp: Write NFC tags with LNURL-pay links (#766) * NFC for LNURL-pay * notification ui improvements --- lnbits/extensions/lnurlp/static/js/index.js | 37 +++++++++++++++++++ .../lnurlp/templates/lnurlp/display.html | 9 ++++- .../lnurlp/templates/lnurlp/index.html | 23 +++++++++--- lnbits/extensions/withdraw/static/js/index.js | 12 ++++-- 4 files changed, 71 insertions(+), 10 deletions(-) diff --git a/lnbits/extensions/lnurlp/static/js/index.js b/lnbits/extensions/lnurlp/static/js/index.js index e18d6161e..99448802d 100644 --- a/lnbits/extensions/lnurlp/static/js/index.js +++ b/lnbits/extensions/lnurlp/static/js/index.js @@ -35,6 +35,7 @@ new Vue({ rowsPerPage: 10 } }, + nfcTagWriting: false, formDialog: { show: false, fixedAmount: true, @@ -205,6 +206,42 @@ new Vue({ .catch(err => { LNbits.utils.notifyApiError(err) }) + }, + writeNfcTag: async function (lnurl) { + try { + if (typeof NDEFReader == 'undefined') { + throw { + toString: function () { + return 'NFC not supported on this device or browser.' + } + } + } + + const ndef = new NDEFReader() + + this.nfcTagWriting = true + this.$q.notify({ + message: 'Tap your NFC tag to write the LNURL-pay link to it.' + }) + + await ndef.write({ + records: [{recordType: 'url', data: 'lightning:' + lnurl, lang: 'en'}] + }) + + this.nfcTagWriting = false + this.$q.notify({ + type: 'positive', + message: 'NFC Tag written successfully.' + }) + } catch (error) { + this.nfcTagWriting = false + this.$q.notify({ + type: 'negative', + message: error + ? error.toString() + : 'An unexpected error has occurred.' + }) + } } }, created() { diff --git a/lnbits/extensions/lnurlp/templates/lnurlp/display.html b/lnbits/extensions/lnurlp/templates/lnurlp/display.html index 08e4de15c..944e764bf 100644 --- a/lnbits/extensions/lnurlp/templates/lnurlp/display.html +++ b/lnbits/extensions/lnurlp/templates/lnurlp/display.html @@ -14,10 +14,17 @@ -