feat: improve on lnbits-qrcode-scanner design (#3633)
This commit is contained in:
parent
d9a2a7bb95
commit
aed3f3b569
8 changed files with 40 additions and 33 deletions
2
lnbits/static/bundle-components.min.js
vendored
2
lnbits/static/bundle-components.min.js
vendored
File diff suppressed because one or more lines are too long
2
lnbits/static/bundle.min.js
vendored
2
lnbits/static/bundle.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -1,25 +1,44 @@
|
||||||
window.app.component('lnbits-qrcode-scanner', {
|
window.app.component('lnbits-qrcode-scanner', {
|
||||||
template: '#lnbits-qrcode-scanner',
|
template: '#lnbits-qrcode-scanner',
|
||||||
mixins: [window.windowMixin],
|
props: ['callback'],
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
showScanner: false
|
||||||
|
}
|
||||||
|
},
|
||||||
watch: {
|
watch: {
|
||||||
'g.showScanner'(newVal) {
|
callback(newVal) {
|
||||||
if (newVal === true) {
|
if (newVal === null) {
|
||||||
|
return this.reset()
|
||||||
|
}
|
||||||
|
if (typeof newVal !== 'function') {
|
||||||
|
Quasar.Notify.create({
|
||||||
|
message: 'QR code scanner callback is not a function.',
|
||||||
|
type: 'negative'
|
||||||
|
})
|
||||||
|
return this.reset()
|
||||||
|
}
|
||||||
if (this.g.hasCamera === false) {
|
if (this.g.hasCamera === false) {
|
||||||
Quasar.Notify.create({
|
Quasar.Notify.create({
|
||||||
message: 'No camera found on this device.',
|
message: 'No camera found on this device.',
|
||||||
type: 'negative'
|
type: 'negative'
|
||||||
})
|
})
|
||||||
this.g.showScanner = false
|
return this.reset()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
this.showScanner = true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
reset() {
|
||||||
|
this.showScanner = false
|
||||||
|
this.g.scanner = null
|
||||||
|
},
|
||||||
detect(val) {
|
detect(val) {
|
||||||
const rawValue = val[0].rawValue
|
const rawValue = val[0].rawValue
|
||||||
console.log('Detected QR code value:', rawValue)
|
console.log('Detected QR code value:', rawValue)
|
||||||
|
this.callback(rawValue)
|
||||||
this.$emit('detect', rawValue)
|
this.$emit('detect', rawValue)
|
||||||
this.g.showScanner = false
|
this.reset()
|
||||||
},
|
},
|
||||||
async onInitQR(promise) {
|
async onInitQR(promise) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -48,7 +67,7 @@ window.app.component('lnbits-qrcode-scanner', {
|
||||||
type: 'negative'
|
type: 'negative'
|
||||||
})
|
})
|
||||||
this.g.hasCamera = false
|
this.g.hasCamera = false
|
||||||
this.showScanner = false
|
this.reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ window.g = Vue.reactive({
|
||||||
fiatBalance: 0,
|
fiatBalance: 0,
|
||||||
exchangeRate: 0,
|
exchangeRate: 0,
|
||||||
fiatTracking: false,
|
fiatTracking: false,
|
||||||
showScanner: false,
|
|
||||||
payments: [],
|
payments: [],
|
||||||
walletEventListeners: [],
|
walletEventListeners: [],
|
||||||
showNewWalletDialog: false,
|
showNewWalletDialog: false,
|
||||||
|
|
@ -58,7 +57,7 @@ window.g = Vue.reactive({
|
||||||
ads: WINDOW_SETTINGS.AD_SPACE.split(',').map(ad => ad.split(';')),
|
ads: WINDOW_SETTINGS.AD_SPACE.split(',').map(ad => ad.split(';')),
|
||||||
denomination: WINDOW_SETTINGS.LNBITS_DENOMINATION,
|
denomination: WINDOW_SETTINGS.LNBITS_DENOMINATION,
|
||||||
isSatsDenomination: WINDOW_SETTINGS.LNBITS_DENOMINATION == 'sats',
|
isSatsDenomination: WINDOW_SETTINGS.LNBITS_DENOMINATION == 'sats',
|
||||||
scanDetectCallback: null
|
scanner: null
|
||||||
})
|
})
|
||||||
|
|
||||||
window.dateFormat = 'YYYY-MM-DD HH:mm'
|
window.dateFormat = 'YYYY-MM-DD HH:mm'
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,5 @@
|
||||||
window.windowMixin = {
|
window.windowMixin = {
|
||||||
methods: {
|
methods: {
|
||||||
handleScan(val) {
|
|
||||||
if (this.g.scanDetectCallback) {
|
|
||||||
this.g.scanDetectCallback(val)
|
|
||||||
this.g.scanDetectCallback = null
|
|
||||||
}
|
|
||||||
},
|
|
||||||
openScanDialog(scanDetectCallback) {
|
|
||||||
this.g.showScanner = true
|
|
||||||
this.g.scanDetectCallback = scanDetectCallback
|
|
||||||
},
|
|
||||||
openNewWalletDialog(walletType = 'lightning') {
|
openNewWalletDialog(walletType = 'lightning') {
|
||||||
this.g.newWalletType = walletType
|
this.g.newWalletType = walletType
|
||||||
this.g.showNewWalletDialog = true
|
this.g.showNewWalletDialog = true
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@
|
||||||
<div id="vue">
|
<div id="vue">
|
||||||
<q-layout view="hHh lpR lfr" v-cloak>
|
<q-layout view="hHh lpR lfr" v-cloak>
|
||||||
<lnbits-disclaimer v-if="g.user && !g.isPublicPage"></lnbits-disclaimer>
|
<lnbits-disclaimer v-if="g.user && !g.isPublicPage"></lnbits-disclaimer>
|
||||||
<lnbits-qrcode-scanner @detect="handleScan"></lnbits-qrcode-scanner>
|
<lnbits-qrcode-scanner :callback="g.scanner"></lnbits-qrcode-scanner>
|
||||||
<lnbits-theme></lnbits-theme>
|
<lnbits-theme></lnbits-theme>
|
||||||
<lnbits-header></lnbits-header>
|
<lnbits-header></lnbits-header>
|
||||||
<lnbits-drawer v-if="g.user && !g.isPublicPage"></lnbits-drawer>
|
<lnbits-drawer v-if="g.user && !g.isPublicPage"></lnbits-drawer>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<template id="lnbits-qrcode-scanner">
|
<template id="lnbits-qrcode-scanner">
|
||||||
<q-dialog v-model="g.showScanner" position="top">
|
<q-dialog v-model="showScanner" position="top">
|
||||||
<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
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="row q-mt-lg">
|
<div class="row q-mt-lg">
|
||||||
<q-btn
|
<q-btn
|
||||||
@click="g.showScanner = false"
|
@click="reset"
|
||||||
flat
|
flat
|
||||||
color="grey"
|
color="grey"
|
||||||
class="q-ml-auto"
|
class="q-ml-auto"
|
||||||
|
|
|
||||||
|
|
@ -162,10 +162,9 @@
|
||||||
unelevated
|
unelevated
|
||||||
icon="qr_code_scanner"
|
icon="qr_code_scanner"
|
||||||
color="secondary"
|
color="secondary"
|
||||||
@click="openScanDialog(decodeQR)"
|
@click="g.scanner = decodeQR"
|
||||||
:disable="
|
:disable="
|
||||||
!this.g.wallet.canReceivePayments &&
|
!g.wallet.canReceivePayments && !g.wallet.canSendPayments
|
||||||
!this.g.wallet.canSendPayments
|
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
<q-tooltip
|
<q-tooltip
|
||||||
|
|
@ -861,7 +860,7 @@
|
||||||
</q-tabs>
|
</q-tabs>
|
||||||
|
|
||||||
<q-btn
|
<q-btn
|
||||||
@click="openScanDialog(decodeQR)"
|
@click="g.scanner = decodeQR"
|
||||||
round
|
round
|
||||||
unelevated
|
unelevated
|
||||||
size="35px"
|
size="35px"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue