diff --git a/lnbits/extensions/withdraw/static/js/index.js b/lnbits/extensions/withdraw/static/js/index.js index e54005c6..a2563d84 100644 --- a/lnbits/extensions/withdraw/static/js/index.js +++ b/lnbits/extensions/withdraw/static/js/index.js @@ -53,6 +53,7 @@ new Vue({ rowsPerPage: 10 } }, + nfcTagWriting: false, formDialog: { show: false, secondMultiplier: 'seconds', @@ -231,6 +232,36 @@ new Vue({ }) }) }, + writeNfcTag: async function (lnurl) { + try { + if (typeof NDEFReader == 'undefined') { + throw { + toString: function () { + return 'NFC not supported on this device and/or browser.' + } + } + } + + const ndef = new NDEFReader() + + this.nfcTagWriting = true + this.$q.notify({ + message: 'Tap your NFC tag now to write the LNURLw to it' + }) + + await ndef.write(lnurl) + + this.nfcTagWriting = false + this.$q.notify({ + message: 'NFC Tag written successfully!' + }) + } catch (error) { + this.nfcTagWriting = false + this.$q.notify({ + message: error ? error.toString() : 'An unexpected error has occurred' + }) + } + }, exportCSV: function () { LNbits.utils.exportCSV(this.paywallsTable.columns, this.paywalls) } diff --git a/lnbits/extensions/withdraw/templates/withdraw/display.html b/lnbits/extensions/withdraw/templates/withdraw/display.html index 5552c77f..0c523b27 100644 --- a/lnbits/extensions/withdraw/templates/withdraw/display.html +++ b/lnbits/extensions/withdraw/templates/withdraw/display.html @@ -17,10 +17,17 @@ -
+
Copy LNURL +
@@ -51,7 +58,42 @@ mixins: [windowMixin], data: function () { return { - here: location.protocol + '//' + location.host + here: location.protocol + '//' + location.host, + nfcTagWriting: false + } + }, + methods: { + writeNfcTag: async function (lnurl) { + try { + if (typeof NDEFReader == 'undefined') { + throw { + toString: function () { + return 'NFC not supported on this device and/or browser.' + } + } + } + + const ndef = new NDEFReader() + + this.nfcTagWriting = true + this.$q.notify({ + message: 'Tap your NFC tag now to write the LNURLw to it' + }) + + await ndef.write(lnurl) + + this.nfcTagWriting = false + this.$q.notify({ + message: 'NFC Tag written successfully!' + }) + } catch (error) { + this.nfcTagWriting = false + this.$q.notify({ + message: error + ? error.toString() + : 'An unexpected error has occurred' + }) + } } } }) diff --git a/lnbits/extensions/withdraw/templates/withdraw/index.html b/lnbits/extensions/withdraw/templates/withdraw/index.html index 6d3ab374..99aa03b2 100644 --- a/lnbits/extensions/withdraw/templates/withdraw/index.html +++ b/lnbits/extensions/withdraw/templates/withdraw/index.html @@ -369,6 +369,13 @@ @click="copyText(qrCodeDialog.data.withdraw_url, 'Link copied to clipboard!')" >Shareable link +