Browse Source

qml: remove redundant WalletDB, closes #8628

master
Sander van Grieken 2 years ago
parent
commit
cbcafe8960
  1. 35
      electrum/gui/qml/components/OpenWalletDialog.qml
  2. 11
      electrum/gui/qml/components/main.qml

35
electrum/gui/qml/components/OpenWalletDialog.qml

@ -13,6 +13,7 @@ ElDialog {
property string name property string name
property string path property string path
property bool _invalidPassword: false
property bool _unlockClicked: false property bool _unlockClicked: false
title: qsTr('Open Wallet') title: qsTr('Open Wallet')
@ -38,17 +39,15 @@ ElDialog {
InfoTextArea { InfoTextArea {
id: notice id: notice
text: Daemon.singlePasswordEnabled text: Daemon.singlePasswordEnabled || !Daemon.currentWallet
? qsTr('Please enter password') ? qsTr('Please enter password')
: qsTr('Wallet <b>%1</b> requires password to unlock').arg(name) : qsTr('Wallet <b>%1</b> requires password to unlock').arg(name)
visible: wallet_db.needsPassword
iconStyle: InfoTextArea.IconStyle.Warn iconStyle: InfoTextArea.IconStyle.Warn
Layout.fillWidth: true Layout.fillWidth: true
} }
Label { Label {
text: qsTr('Password') text: qsTr('Password')
visible: wallet_db.needsPassword
Layout.fillWidth: true Layout.fillWidth: true
color: Material.accentColor color: Material.accentColor
} }
@ -57,7 +56,6 @@ ElDialog {
id: password id: password
Layout.fillWidth: true Layout.fillWidth: true
Layout.leftMargin: constants.paddingXLarge Layout.leftMargin: constants.paddingXLarge
visible: wallet_db.needsPassword
onTextChanged: { onTextChanged: {
unlockButton.enabled = true unlockButton.enabled = true
@ -70,7 +68,7 @@ ElDialog {
Label { Label {
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
text: !wallet_db.validPassword && _unlockClicked ? qsTr("Invalid Password") : '' text: _invalidPassword && _unlockClicked ? qsTr("Invalid Password") : ''
color: constants.colorError color: constants.colorError
font.pixelSize: constants.fontSizeLarge font.pixelSize: constants.fontSizeLarge
} }
@ -79,7 +77,6 @@ ElDialog {
FlatButton { FlatButton {
id: unlockButton id: unlockButton
Layout.fillWidth: true Layout.fillWidth: true
visible: wallet_db.needsPassword
icon.source: '../../icons/unlock.png' icon.source: '../../icons/unlock.png'
text: qsTr("Unlock") text: qsTr("Unlock")
onClicked: { onClicked: {
@ -92,32 +89,22 @@ ElDialog {
function unlock() { function unlock() {
unlockButton.enabled = false unlockButton.enabled = false
_unlockClicked = true _unlockClicked = true
wallet_db.password = password.text Daemon.loadWallet(openwalletdialog.path, password.text)
wallet_db.verify()
} }
WalletDB { Connections {
id: wallet_db target: Daemon
path: openwalletdialog.path function onWalletRequiresPassword() {
onReadyChanged: { console.log('invalid password')
if (ready) { _invalidPassword = true
Daemon.loadWallet(openwalletdialog.path, password.text)
openwalletdialog.close()
}
}
onInvalidPassword: {
password.tf.forceActiveFocus() password.tf.forceActiveFocus()
} }
onNeedsPasswordChanged: { function onWalletLoaded() {
notice.visible = needsPassword
}
onWalletOpenProblem: {
openwalletdialog.close() openwalletdialog.close()
Daemon.onWalletOpenProblem(error)
} }
} }
Component.onCompleted: { Component.onCompleted: {
wallet_db.verify() password.tf.forceActiveFocus()
} }
} }

11
electrum/gui/qml/components/main.qml

@ -496,12 +496,19 @@ ApplicationWindow
} }
} }
property var _opendialog: undefined
Connections { Connections {
target: Daemon target: Daemon
function onWalletRequiresPassword(name, path) { function onWalletRequiresPassword(name, path) {
console.log('wallet requires password') console.log('wallet requires password')
var dialog = openWalletDialog.createObject(app, { path: path, name: name }) if (_opendialog == undefined) {
dialog.open() _opendialog = openWalletDialog.createObject(app, { path: path, name: name })
_opendialog.closed.connect(function() {
_opendialog = undefined
})
_opendialog.open()
}
} }
function onWalletOpenError(error) { function onWalletOpenError(error) {
console.log('wallet open error') console.log('wallet open error')

Loading…
Cancel
Save