Add NFC Writing support to LNURLw extension (#725)
This commit is contained in:
parent
f4580955b9
commit
b6d01792e2
3 changed files with 82 additions and 2 deletions
|
|
@ -53,6 +53,7 @@ new Vue({
|
||||||
rowsPerPage: 10
|
rowsPerPage: 10
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
nfcTagWriting: false,
|
||||||
formDialog: {
|
formDialog: {
|
||||||
show: false,
|
show: false,
|
||||||
secondMultiplier: 'seconds',
|
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 () {
|
exportCSV: function () {
|
||||||
LNbits.utils.exportCSV(this.paywallsTable.columns, this.paywalls)
|
LNbits.utils.exportCSV(this.paywallsTable.columns, this.paywalls)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,17 @@
|
||||||
</q-responsive>
|
</q-responsive>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="row q-mt-lg">
|
<div class="row q-mt-lg q-gutter-sm">
|
||||||
<q-btn outline color="grey" @click="copyText('{{ lnurl }}')"
|
<q-btn outline color="grey" @click="copyText('{{ lnurl }}')"
|
||||||
>Copy LNURL</q-btn
|
>Copy LNURL</q-btn
|
||||||
>
|
>
|
||||||
|
<q-btn
|
||||||
|
outline
|
||||||
|
color="grey"
|
||||||
|
icon="nfc"
|
||||||
|
@click="writeNfcTag(' {{ lnurl }} ')"
|
||||||
|
:disable="nfcTagWriting"
|
||||||
|
></q-btn>
|
||||||
</div>
|
</div>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
|
@ -51,7 +58,42 @@
|
||||||
mixins: [windowMixin],
|
mixins: [windowMixin],
|
||||||
data: function () {
|
data: function () {
|
||||||
return {
|
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'
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -369,6 +369,13 @@
|
||||||
@click="copyText(qrCodeDialog.data.withdraw_url, 'Link copied to clipboard!')"
|
@click="copyText(qrCodeDialog.data.withdraw_url, 'Link copied to clipboard!')"
|
||||||
>Shareable link</q-btn
|
>Shareable link</q-btn
|
||||||
>
|
>
|
||||||
|
<q-btn
|
||||||
|
outline
|
||||||
|
color="grey"
|
||||||
|
icon="nfc"
|
||||||
|
@click="writeNfcTag(qrCodeDialog.data.lnurl)"
|
||||||
|
:disable="nfcTagWriting"
|
||||||
|
></q-btn>
|
||||||
<q-btn
|
<q-btn
|
||||||
outline
|
outline
|
||||||
color="grey"
|
color="grey"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue