1
0

qml: replace Send/ScanDialog with java bases zxing qr scan activity.

This commit is contained in:
SomberNight
2023-10-11 11:02:40 +00:00
committed by Sander van Grieken
parent c33ee87544
commit 5c3e14d8de
12 changed files with 234 additions and 191 deletions

View File

@@ -1,51 +0,0 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import "controls"
ElDialog {
id: scanDialog
property string scanData
property string error
property string hint
signal found
width: parent.width
height: parent.height
padding: 0
header: null
topPadding: 0 // dialog needs topPadding override
function doClose() {
qrscan.stop()
Qt.callLater(doReject)
}
ColumnLayout {
anchors.fill: parent
spacing: 0
QRScan {
id: qrscan
Layout.fillWidth: true
Layout.fillHeight: true
hint: scanDialog.hint
onFound: {
scanDialog.scanData = scanData
scanDialog.found()
}
}
FlatButton {
id: button
Layout.fillWidth: true
text: qsTr('Cancel')
icon.source: '../../icons/closebutton.png'
onClicked: doReject()
}
}
}

View File

@@ -1,82 +0,0 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Controls.Material
import org.electrum 1.0
import "controls"
ElDialog {
id: dialog
property InvoiceParser invoiceParser
signal txFound(data: string)
signal channelBackupFound(data: string)
header: null
padding: 0
topPadding: 0
onAboutToHide: {
console.log('about to hide')
qrscan.stop()
}
function restart() {
qrscan.restart()
}
function dispatch(data) {
data = data.trim()
if (bitcoin.isRawTx(data)) {
txFound(data)
} else if (Daemon.currentWallet.isValidChannelBackup(data)) {
channelBackupFound(data)
} else {
invoiceParser.recipient = data
}
}
// override
function doClose() {
console.log('SendDialog doClose override') // doesn't trigger when going back??
qrscan.stop()
Qt.callLater(doReject)
}
ColumnLayout {
anchors.fill: parent
spacing: 0
QRScan {
id: qrscan
Layout.fillWidth: true
Layout.fillHeight: true
hint: qsTr('Scan an Invoice, an Address, an LNURL-pay, a PSBT or a Channel backup')
onFound: dialog.dispatch(scanData)
}
ButtonContainer {
Layout.fillWidth: true
FlatButton {
Layout.fillWidth: true
Layout.preferredWidth: 1
icon.source: '../../icons/copy_bw.png'
text: qsTr('Paste')
onClicked: {
qrscan.stop()
dialog.dispatch(AppController.clipboardToText())
}
}
}
}
Bitcoin {
id: bitcoin
}
}

View File

@@ -13,7 +13,6 @@ Item {
property string title: Daemon.currentWallet ? Daemon.currentWallet.name : qsTr('no wallet loaded')
property var _sendDialog
property string _intentUri
property string _request_amount
@@ -34,21 +33,33 @@ Item {
}
function openSendDialog() {
_sendDialog = sendDialog.createObject(mainView, {invoiceParser: invoiceParser})
_sendDialog.open()
}
function closeSendDialog() {
if (_sendDialog) {
_sendDialog.doClose()
_sendDialog = null
}
var scanner = app.scanDialog.createObject(mainView, {
hint: qsTr('Scan an Invoice, an Address, an LNURL-pay, a PSBT or a Channel backup'),
})
scanner.onFound.connect(function() {
var data = scanner.scanData
data = data.trim()
if (bitcoin.isRawTx(data)) {
app.stack.push(Qt.resolvedUrl('TxDetails.qml'), { rawtx: data })
} else if (Daemon.currentWallet.isValidChannelBackup(data)) {
var dialog = app.messageDialog.createObject(app, {
title: qsTr('Import Channel backup?'),
yesno: true
})
dialog.accepted.connect(function() {
Daemon.currentWallet.importChannelBackup(data)
})
dialog.open()
} else {
invoiceParser.recipient = data
}
//scanner.destroy() // TODO
})
scanner.open()
}
function restartSendDialog() {
if (_sendDialog) {
_sendDialog.restart()
}
//openSendDialog() // note: ~infinite-loop on non-android due to directly pasting from clipboard
}
function showExport(data, helptext) {
@@ -287,7 +298,6 @@ Item {
}
}
onValidationSuccess: {
closeSendDialog()
var dialog = invoiceDialog.createObject(app, {
invoice: invoiceParser,
payImmediately: invoiceParser.isLnurlPay
@@ -299,7 +309,6 @@ Item {
}
onLnurlRetrieved: {
closeSendDialog()
var dialog = lnurlPayDialog.createObject(app, {
invoiceParser: invoiceParser
})
@@ -314,6 +323,10 @@ Item {
}
}
Bitcoin {
id: bitcoin
}
Connections {
target: AppController
function onUriReceived(uri) {
@@ -419,34 +432,6 @@ Item {
}
}
Component {
id: sendDialog
SendDialog {
width: parent.width
height: parent.height
onTxFound: {
app.stack.push(Qt.resolvedUrl('TxDetails.qml'), { rawtx: data })
close()
}
onChannelBackupFound: {
var dialog = app.messageDialog.createObject(app, {
title: qsTr('Import Channel backup?'),
yesno: true
})
dialog.accepted.connect(function() {
Daemon.currentWallet.importChannelBackup(data)
close()
})
dialog.rejected.connect(function() {
close()
})
dialog.open()
}
onClosed: destroy()
}
}
function createRequest(lightning_only, reuse_address) {
var qamt = Config.unitsToSats(_request_amount)
Daemon.currentWallet.createRequest(qamt, _request_description, _request_expiry, lightning_only, reuse_address)

View File

@@ -380,8 +380,8 @@ ApplicationWindow
property alias scanDialog: _scanDialog
Component {
id: _scanDialog
ScanDialog {
onClosed: destroy()
QRScanner {
//onClosed: destroy()
}
}