mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-02-24 14:51:05 +01:00
camera for tokens
This commit is contained in:
parent
b936d122a3
commit
ac5512cdbe
1 changed files with 105 additions and 73 deletions
|
@ -321,7 +321,8 @@ page_container %}
|
||||||
@click="showInvoicesDialog"
|
@click="showInvoicesDialog"
|
||||||
>
|
>
|
||||||
</q-tab>
|
</q-tab>
|
||||||
<q-tab icon="photo_camera" @click="showCamera"> </q-tab>
|
<q-tab icon="photo_camera" v-if="hasCamera" @click="showCamera">
|
||||||
|
</q-tab>
|
||||||
<q-tab
|
<q-tab
|
||||||
icon="bolt"
|
icon="bolt"
|
||||||
class="q-pa-none"
|
class="q-pa-none"
|
||||||
|
@ -487,7 +488,7 @@ page_container %}
|
||||||
</div>
|
</div>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<q-form
|
<q-form
|
||||||
v-if="!payInvoiceData.camera.show"
|
v-if="!camera.show"
|
||||||
@submit="decodeRequest"
|
@submit="decodeRequest"
|
||||||
class="q-gutter-md"
|
class="q-gutter-md"
|
||||||
>
|
>
|
||||||
|
@ -512,11 +513,12 @@ page_container %}
|
||||||
unelevated
|
unelevated
|
||||||
icon="photo_camera"
|
icon="photo_camera"
|
||||||
class="q-mx-0"
|
class="q-mx-0"
|
||||||
|
v-if="hasCamera"
|
||||||
@click="showCamera"
|
@click="showCamera"
|
||||||
>
|
>
|
||||||
</q-btn>
|
</q-btn>
|
||||||
<q-btn v-close-popup flat color="grey" class="q-ml-auto"
|
<q-btn v-close-popup flat color="grey" class="q-ml-auto"
|
||||||
>Cancel</q-btn
|
>Close</q-btn
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
</q-form>
|
</q-form>
|
||||||
|
@ -537,7 +539,7 @@ page_container %}
|
||||||
</q-card>
|
</q-card>
|
||||||
</q-dialog>
|
</q-dialog>
|
||||||
|
|
||||||
<q-dialog v-model="payInvoiceData.camera.show">
|
<q-dialog v-model="camera.show">
|
||||||
<q-card class="q-pa-lg q-pt-xl">
|
<q-card class="q-pa-lg q-pt-xl">
|
||||||
<div class="text-center q-mb-lg">
|
<div class="text-center q-mb-lg">
|
||||||
<qrcode-stream
|
<qrcode-stream
|
||||||
|
@ -755,6 +757,13 @@ page_container %}
|
||||||
|
|
||||||
<div class="row q-mt-lg">
|
<div class="row q-mt-lg">
|
||||||
<q-btn @click="redeem" color="primary">Receive Tokens</q-btn>
|
<q-btn @click="redeem" color="primary">Receive Tokens</q-btn>
|
||||||
|
<q-btn
|
||||||
|
unelevated
|
||||||
|
icon="photo_camera"
|
||||||
|
class="q-mx-0"
|
||||||
|
v-if="hasCamera"
|
||||||
|
@click="showCamera"
|
||||||
|
>
|
||||||
<q-btn v-close-popup flat color="grey" class="q-ml-auto"
|
<q-btn v-close-popup flat color="grey" class="q-ml-auto"
|
||||||
>Close</q-btn
|
>Close</q-btn
|
||||||
>
|
>
|
||||||
|
@ -825,6 +834,11 @@ page_container %}
|
||||||
bolt11: '',
|
bolt11: '',
|
||||||
hash: ''
|
hash: ''
|
||||||
},
|
},
|
||||||
|
camera: {
|
||||||
|
data: null,
|
||||||
|
show: false,
|
||||||
|
camera: 'auto'
|
||||||
|
},
|
||||||
invoiceCheckListener: () => {},
|
invoiceCheckListener: () => {},
|
||||||
payInvoiceData: {
|
payInvoiceData: {
|
||||||
blocking: false,
|
blocking: false,
|
||||||
|
@ -1089,10 +1103,15 @@ page_container %}
|
||||||
return row.payment_hash + row.amount
|
return row.payment_hash + row.amount
|
||||||
},
|
},
|
||||||
closeCamera: function () {
|
closeCamera: function () {
|
||||||
this.payInvoiceData.camera.show = false
|
this.camera.show = false
|
||||||
},
|
},
|
||||||
showCamera: function () {
|
showCamera: function () {
|
||||||
this.payInvoiceData.camera.show = true
|
this.camera.show = true
|
||||||
|
},
|
||||||
|
hasCamera: function () {
|
||||||
|
navigator.permissions.query({name: 'camera'}).then(res => {
|
||||||
|
return res.state == 'granted'
|
||||||
|
})
|
||||||
},
|
},
|
||||||
showChart: function () {
|
showChart: function () {
|
||||||
this.paymentsChart.show = true
|
this.paymentsChart.show = true
|
||||||
|
@ -1124,7 +1143,7 @@ page_container %}
|
||||||
this.payInvoiceData.data.request = ''
|
this.payInvoiceData.data.request = ''
|
||||||
this.payInvoiceData.data.comment = ''
|
this.payInvoiceData.data.comment = ''
|
||||||
this.payInvoiceData.data.paymentChecker = null
|
this.payInvoiceData.data.paymentChecker = null
|
||||||
this.payInvoiceData.camera.show = false
|
this.camera.show = false
|
||||||
this.focusInput('pasteInput')
|
this.focusInput('pasteInput')
|
||||||
},
|
},
|
||||||
showDisclaimerDialog: function () {
|
showDisclaimerDialog: function () {
|
||||||
|
@ -1203,40 +1222,46 @@ page_container %}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
decodeQR: function (res) {
|
decodeQR: function (res) {
|
||||||
this.payInvoiceData.data.request = res
|
this.camera.data = res
|
||||||
|
// this.payInvoiceData.data.request = res
|
||||||
this.decodeRequest()
|
this.decodeRequest()
|
||||||
this.payInvoiceData.camera.show = false
|
this.camera.show = false
|
||||||
},
|
},
|
||||||
decodeRequest: function () {
|
decodeRequest: function () {
|
||||||
this.payInvoiceData.show = true
|
// let req = this.payInvoiceData.data.request.toLowerCase()
|
||||||
let req = this.payInvoiceData.data.request.toLowerCase()
|
reqtype = null
|
||||||
if (
|
let req = this.camera.data
|
||||||
this.payInvoiceData.data.request
|
if (req.toLowerCase().startsWith('lnbc')) {
|
||||||
.toLowerCase()
|
this.payInvoiceData.data.request = req
|
||||||
.startsWith('lightning:')
|
reqtype = 'bolt11'
|
||||||
) {
|
} else if (req.toLowerCase().startsWith('lightning:')) {
|
||||||
this.payInvoiceData.data.request = this.payInvoiceData.data.request.slice(
|
this.payInvoiceData.data.request = req.slice(10)
|
||||||
10
|
reqtype = 'bolt11'
|
||||||
)
|
} else if (req.toLowerCase().startsWith('lnurl:')) {
|
||||||
} else if (
|
this.payInvoiceData.data.request = req.slice(6)
|
||||||
this.payInvoiceData.data.request.toLowerCase().startsWith('lnurl:')
|
reqtype = 'lnurl'
|
||||||
) {
|
|
||||||
this.payInvoiceData.data.request = this.payInvoiceData.data.request.slice(
|
|
||||||
6
|
|
||||||
)
|
|
||||||
} else if (req.indexOf('lightning=lnurl1') !== -1) {
|
} else if (req.indexOf('lightning=lnurl1') !== -1) {
|
||||||
this.payInvoiceData.data.request = this.payInvoiceData.data.request
|
this.payInvoiceData.data.request = req
|
||||||
.split('lightning=')[1]
|
.split('lightning=')[1]
|
||||||
.split('&')[0]
|
.split('&')[0]
|
||||||
}
|
reqtype = 'lnurl'
|
||||||
|
} else if (
|
||||||
if (
|
req.toLowerCase().startsWith('lnurl1') ||
|
||||||
this.payInvoiceData.data.request.toLowerCase().startsWith('lnurl1') ||
|
req.match(/[\w.+-~_]+@[\w.+-~_]/)
|
||||||
this.payInvoiceData.data.request.match(/[\w.+-~_]+@[\w.+-~_]/)
|
|
||||||
) {
|
) {
|
||||||
|
this.payInvoiceData.data.request = req
|
||||||
|
reqtype = 'lnurl'
|
||||||
return
|
return
|
||||||
|
} else if (req.indexOf('W3siaWQ') !== 1) {
|
||||||
|
// very dirty way of parsing cashu tokens
|
||||||
|
|
||||||
|
this.receiveData.tokensBase64 = req.slice(req.indexOf('W3siaWQ'))
|
||||||
|
reqtype = 'cashu'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (reqtype == 'bolt11') {
|
||||||
|
console.log('#### QR CODE: BOLT11')
|
||||||
|
this.payInvoiceData.show = true
|
||||||
let invoice
|
let invoice
|
||||||
try {
|
try {
|
||||||
invoice = decode(this.payInvoiceData.data.request)
|
invoice = decode(this.payInvoiceData.data.request)
|
||||||
|
@ -1280,6 +1305,13 @@ page_container %}
|
||||||
})
|
})
|
||||||
|
|
||||||
this.payInvoiceData.invoice = Object.freeze(cleanInvoice)
|
this.payInvoiceData.invoice = Object.freeze(cleanInvoice)
|
||||||
|
} else if (reqtype == 'lnurl') {
|
||||||
|
console.log('#### QR CODE: LNURL')
|
||||||
|
// not supported yet
|
||||||
|
} else if (reqtype == 'cashu') {
|
||||||
|
console.log('#### QR CODE: CASHU TOKEN')
|
||||||
|
this.showReceiveTokens = true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
payInvoice: function () {
|
payInvoice: function () {
|
||||||
let dismissPaymentMsg = this.$q.notify({
|
let dismissPaymentMsg = this.$q.notify({
|
||||||
|
@ -1348,7 +1380,7 @@ page_container %}
|
||||||
this.payInvoiceData.invoice = ''
|
this.payInvoiceData.invoice = ''
|
||||||
this.payInvoiceData.data.request = ''
|
this.payInvoiceData.data.request = ''
|
||||||
this.showPayInvoice = true
|
this.showPayInvoice = true
|
||||||
this.payInvoiceData.camera.show = false
|
this.camera.show = false
|
||||||
},
|
},
|
||||||
|
|
||||||
showTokenDialog: function (token) {
|
showTokenDialog: function (token) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue