From 7ea3830fed2f6028263b8b91fdc06fe7ce44c20f Mon Sep 17 00:00:00 2001 From: ben Date: Mon, 29 Aug 2022 15:11:25 +0100 Subject: [PATCH] Added NFC to get UID --- .../extensions/boltcards/static/js/index.js | 59 +++++++++++++++ .../boltcards/templates/boltcards/index.html | 74 +++++++++++-------- 2 files changed, 104 insertions(+), 29 deletions(-) diff --git a/lnbits/extensions/boltcards/static/js/index.js b/lnbits/extensions/boltcards/static/js/index.js index 33704f3a2..8f387f95d 100644 --- a/lnbits/extensions/boltcards/static/js/index.js +++ b/lnbits/extensions/boltcards/static/js/index.js @@ -26,6 +26,7 @@ new Vue({ k0: '', k1: '', k2: '', + uid: '', card_name: '' }, temp: {} @@ -146,6 +147,64 @@ new Vue({ } }, methods: { + readNfcTag: function () { + try { + const self = this + + if (typeof NDEFReader == 'undefined') { + throw { + toString: function () { + return 'NFC not supported on this device or browser.' + } + } + } + + const ndef = new NDEFReader() + + const readerAbortController = new AbortController() + readerAbortController.signal.onabort = event => { + console.log('All NFC Read operations have been aborted.') + } + + this.nfcTagReading = true + this.$q.notify({ + message: 'Tap your NFC tag to pay this invoice with LNURLw.' + }) + + return ndef.scan({signal: readerAbortController.signal}).then(() => { + ndef.onreadingerror = () => { + self.nfcTagReading = false + + this.$q.notify({ + type: 'negative', + message: 'There was an error reading this NFC tag.' + }) + + readerAbortController.abort() + } + + ndef.onreading = ({message, serialNumber}) => { + //Decode NDEF data from tag + var self = this + self.cardDialog.data.uid = serialNumber + .toUpperCase() + .replaceAll(':', '') + this.$q.notify({ + type: 'positive', + message: 'NFC tag read successfully.' + }) + } + }) + } catch (error) { + this.nfcTagReading = false + this.$q.notify({ + type: 'negative', + message: error + ? error.toString() + : 'An unexpected error has occurred.' + }) + } + }, getCards: function () { var self = this diff --git a/lnbits/extensions/boltcards/templates/boltcards/index.html b/lnbits/extensions/boltcards/templates/boltcards/index.html index 2a613fda2..ec2611a98 100644 --- a/lnbits/extensions/boltcards/templates/boltcards/index.html +++ b/lnbits/extensions/boltcards/templates/boltcards/index.html @@ -43,7 +43,6 @@ @@ -257,7 +248,8 @@ v-model.trim="cardDialog.data.card_name" type="text" label="Card name " - > + > +
Get from the card you'll use, using an NFC app + Get from the card you'll use, using an NFC app +
Tap card to scan UID (coming soon) + Tap card to scan UID +
@@ -322,10 +317,11 @@ v-model.number="cardDialog.data.counter" type="number" label="Initial counter" - >Zero if you don't know. + Zero if you don't know. + Create Card + >Create Card + Cancel @@ -371,7 +367,7 @@ >

- (QR code is for setting the keys with bolt-nfc-android-app) + (Keys for bolt-nfc-android-app)

Name: {{ qrCodeDialog.data.name }}
@@ -380,6 +376,26 @@ Meta key: {{ qrCodeDialog.data.k1 }}
File key: {{ qrCodeDialog.data.k2 }}

+
+ + + + + + Click to copy, then add to NFC card + {% endraw %}
Close