LNURLp: Write NFC tags with LNURL-pay links (#766)
* NFC for LNURL-pay * notification ui improvements
This commit is contained in:
parent
45c356cf6c
commit
76a5196dbf
4 changed files with 71 additions and 10 deletions
|
|
@ -35,6 +35,7 @@ new Vue({
|
||||||
rowsPerPage: 10
|
rowsPerPage: 10
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
nfcTagWriting: false,
|
||||||
formDialog: {
|
formDialog: {
|
||||||
show: false,
|
show: false,
|
||||||
fixedAmount: true,
|
fixedAmount: true,
|
||||||
|
|
@ -205,6 +206,42 @@ new Vue({
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
LNbits.utils.notifyApiError(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() {
|
created() {
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,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>
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,8 @@
|
||||||
@click="openUpdateDialog(props.row.id)"
|
@click="openUpdateDialog(props.row.id)"
|
||||||
icon="edit"
|
icon="edit"
|
||||||
color="light-blue"
|
color="light-blue"
|
||||||
></q-btn>
|
>
|
||||||
|
</q-btn>
|
||||||
<q-btn
|
<q-btn
|
||||||
flat
|
flat
|
||||||
dense
|
dense
|
||||||
|
|
@ -153,7 +154,8 @@
|
||||||
v-model.trim="formDialog.data.description"
|
v-model.trim="formDialog.data.description"
|
||||||
type="text"
|
type="text"
|
||||||
label="Item description *"
|
label="Item description *"
|
||||||
></q-input>
|
>
|
||||||
|
</q-input>
|
||||||
<div class="row q-col-gutter-sm">
|
<div class="row q-col-gutter-sm">
|
||||||
<q-input
|
<q-input
|
||||||
filled
|
filled
|
||||||
|
|
@ -171,7 +173,8 @@
|
||||||
type="number"
|
type="number"
|
||||||
:step="formDialog.data.currency && formDialog.data.currency !== 'satoshis' ? '0.01' : '1'"
|
:step="formDialog.data.currency && formDialog.data.currency !== 'satoshis' ? '0.01' : '1'"
|
||||||
label="Max *"
|
label="Max *"
|
||||||
></q-input>
|
>
|
||||||
|
</q-input>
|
||||||
</div>
|
</div>
|
||||||
<div class="row q-col-gutter-sm">
|
<div class="row q-col-gutter-sm">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
|
|
@ -200,7 +203,8 @@
|
||||||
type="number"
|
type="number"
|
||||||
label="Comment maximum characters"
|
label="Comment maximum characters"
|
||||||
hint="Tell wallets to prompt users for a comment that will be sent along with the payment. LNURLp will store the comment and send it in the webhook."
|
hint="Tell wallets to prompt users for a comment that will be sent along with the payment. LNURLp will store the comment and send it in the webhook."
|
||||||
></q-input>
|
>
|
||||||
|
</q-input>
|
||||||
<q-input
|
<q-input
|
||||||
filled
|
filled
|
||||||
dense
|
dense
|
||||||
|
|
@ -224,7 +228,8 @@
|
||||||
type="text"
|
type="text"
|
||||||
label="Success URL (optional)"
|
label="Success URL (optional)"
|
||||||
hint="Will be shown as a clickable link to the user in his wallet after a successful payment, appended by the payment_hash as a query string."
|
hint="Will be shown as a clickable link to the user in his wallet after a successful payment, appended by the payment_hash as a query string."
|
||||||
></q-input>
|
>
|
||||||
|
</q-input>
|
||||||
<div class="row q-mt-lg">
|
<div class="row q-mt-lg">
|
||||||
<q-btn
|
<q-btn
|
||||||
v-if="formDialog.data.id"
|
v-if="formDialog.data.id"
|
||||||
|
|
@ -294,6 +299,14 @@
|
||||||
@click="copyText(qrCodeDialog.data.pay_url, 'Link copied to clipboard!')"
|
@click="copyText(qrCodeDialog.data.pay_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"
|
||||||
|
|
|
||||||
|
|
@ -237,7 +237,7 @@ new Vue({
|
||||||
if (typeof NDEFReader == 'undefined') {
|
if (typeof NDEFReader == 'undefined') {
|
||||||
throw {
|
throw {
|
||||||
toString: function () {
|
toString: function () {
|
||||||
return 'NFC not supported on this device and/or browser.'
|
return 'NFC not supported on this device or browser.'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -246,7 +246,7 @@ new Vue({
|
||||||
|
|
||||||
this.nfcTagWriting = true
|
this.nfcTagWriting = true
|
||||||
this.$q.notify({
|
this.$q.notify({
|
||||||
message: 'Tap your NFC tag now to write the LNURLw to it'
|
message: 'Tap your NFC tag to write the LNURL-withdraw link to it.'
|
||||||
})
|
})
|
||||||
|
|
||||||
await ndef.write({
|
await ndef.write({
|
||||||
|
|
@ -255,12 +255,16 @@ new Vue({
|
||||||
|
|
||||||
this.nfcTagWriting = false
|
this.nfcTagWriting = false
|
||||||
this.$q.notify({
|
this.$q.notify({
|
||||||
message: 'NFC Tag written successfully!'
|
type: 'positive',
|
||||||
|
message: 'NFC Tag written successfully.'
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.nfcTagWriting = false
|
this.nfcTagWriting = false
|
||||||
this.$q.notify({
|
this.$q.notify({
|
||||||
message: error ? error.toString() : 'An unexpected error has occurred'
|
type: 'negative',
|
||||||
|
message: error
|
||||||
|
? error.toString()
|
||||||
|
: 'An unexpected error has occurred.'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue