feat: improve on lnbits-qrcode-scanner design (#3633)

This commit is contained in:
dni ⚡
2025-12-06 14:38:12 +01:00
committed by GitHub
parent d9a2a7bb95
commit aed3f3b569
8 changed files with 40 additions and 33 deletions
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
@@ -1,25 +1,44 @@
window.app.component('lnbits-qrcode-scanner', {
template: '#lnbits-qrcode-scanner',
mixins: [window.windowMixin],
props: ['callback'],
data() {
return {
showScanner: false
}
},
watch: {
'g.showScanner'(newVal) {
if (newVal === true) {
if (this.g.hasCamera === false) {
Quasar.Notify.create({
message: 'No camera found on this device.',
type: 'negative'
})
this.g.showScanner = false
}
callback(newVal) {
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) {
Quasar.Notify.create({
message: 'No camera found on this device.',
type: 'negative'
})
return this.reset()
}
this.showScanner = true
}
},
methods: {
reset() {
this.showScanner = false
this.g.scanner = null
},
detect(val) {
const rawValue = val[0].rawValue
console.log('Detected QR code value:', rawValue)
this.callback(rawValue)
this.$emit('detect', rawValue)
this.g.showScanner = false
this.reset()
},
async onInitQR(promise) {
try {
@@ -48,7 +67,7 @@ window.app.component('lnbits-qrcode-scanner', {
type: 'negative'
})
this.g.hasCamera = false
this.showScanner = false
this.reset()
}
}
}
+1 -2
View File
@@ -22,7 +22,6 @@ window.g = Vue.reactive({
fiatBalance: 0,
exchangeRate: 0,
fiatTracking: false,
showScanner: false,
payments: [],
walletEventListeners: [],
showNewWalletDialog: false,
@@ -58,7 +57,7 @@ window.g = Vue.reactive({
ads: WINDOW_SETTINGS.AD_SPACE.split(',').map(ad => ad.split(';')),
denomination: WINDOW_SETTINGS.LNBITS_DENOMINATION,
isSatsDenomination: WINDOW_SETTINGS.LNBITS_DENOMINATION == 'sats',
scanDetectCallback: null
scanner: null
})
window.dateFormat = 'YYYY-MM-DD HH:mm'
-10
View File
@@ -1,15 +1,5 @@
window.windowMixin = {
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') {
this.g.newWalletType = walletType
this.g.showNewWalletDialog = true