From 0130e5aecf6f12e0e40ce18f4219abee6c0f249d Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Tue, 5 Jul 2022 18:30:54 +0200 Subject: [PATCH] invert (in)validPassword property in QEWalletDB, add invalidPassword signal. This is to better support state in OpenWallet page --- electrum/gui/qml/components/OpenWallet.qml | 39 +++++++++++++++++++--- electrum/gui/qml/qedaemon.py | 4 +-- electrum/gui/qml/qewalletdb.py | 28 ++++++++-------- 3 files changed, 51 insertions(+), 20 deletions(-) diff --git a/electrum/gui/qml/components/OpenWallet.qml b/electrum/gui/qml/components/OpenWallet.qml index 4131a34fc..715ae2685 100644 --- a/electrum/gui/qml/components/OpenWallet.qml +++ b/electrum/gui/qml/components/OpenWallet.qml @@ -8,7 +8,7 @@ import "controls" Pane { id: openwalletdialog - + property string title: qsTr("Open Wallet") property string name @@ -39,7 +39,7 @@ Pane { Layout.columnSpan: 2 Layout.alignment: Qt.AlignHCenter text: qsTr("Invalid Password") - visible: wallet_db.invalidPassword && _unlockClicked + visible: !wallet_db.validPassword && _unlockClicked width: parent.width * 2/3 error: true } @@ -53,16 +53,24 @@ Pane { id: password visible: wallet_db.needsPassword echoMode: TextInput.Password + inputMethodHints: Qt.ImhSensitiveData + onTextChanged: { + unlockButton.enabled = true + _unlockClicked = false + } + onAccepted: { + unlock() + } } Button { + id: unlockButton Layout.columnSpan: 2 Layout.alignment: Qt.AlignHCenter visible: wallet_db.needsPassword text: qsTr("Unlock") onClicked: { - _unlockClicked = true - wallet_db.password = password.text + unlock() } } @@ -87,8 +95,22 @@ Pane { text: qsTr('Split wallet') onClicked: wallet_db.doSplit() } + + BusyIndicator { + id: busy + running: false + Layout.columnSpan: 2 + Layout.alignment: Qt.AlignHCenter + } } + function unlock() { + unlockButton.enabled = false + _unlockClicked = true + wallet_db.password = password.text + openwalletdialog.forceActiveFocus() + } + WalletDB { id: wallet_db path: openwalletdialog.path @@ -99,10 +121,17 @@ Pane { } onReadyChanged: { if (ready) { + busy.running = true Daemon.load_wallet(openwalletdialog.path, password.text) app.stack.pop(null) } } + onInvalidPassword: { + password.forceActiveFocus() + } + } + + Component.onCompleted: { + password.forceActiveFocus() } - } diff --git a/electrum/gui/qml/qedaemon.py b/electrum/gui/qml/qedaemon.py index 958bd88ca..855488b72 100644 --- a/electrum/gui/qml/qedaemon.py +++ b/electrum/gui/qml/qedaemon.py @@ -97,7 +97,7 @@ class QEDaemon(AuthMixin, QObject): self.daemon = daemon self.qefx = QEFX(daemon.fx, daemon.config) self._walletdb = QEWalletDB() - self._walletdb.invalidPasswordChanged.connect(self.passwordValidityCheck) + self._walletdb.validPasswordChanged.connect(self.passwordValidityCheck) _logger = get_logger(__name__) _loaded_wallets = QEWalletListModel() @@ -115,7 +115,7 @@ class QEDaemon(AuthMixin, QObject): @pyqtSlot() def passwordValidityCheck(self): - if self._walletdb._invalidPassword: + if not self._walletdb._validPassword: self.walletRequiresPassword.emit() @pyqtSlot() diff --git a/electrum/gui/qml/qewalletdb.py b/electrum/gui/qml/qewalletdb.py index d3dae8e16..d97a57f50 100644 --- a/electrum/gui/qml/qewalletdb.py +++ b/electrum/gui/qml/qewalletdb.py @@ -25,20 +25,21 @@ class QEWalletDB(QObject): needsPasswordChanged = pyqtSignal() needsHWDeviceChanged = pyqtSignal() passwordChanged = pyqtSignal() - invalidPasswordChanged = pyqtSignal() + validPasswordChanged = pyqtSignal() requiresSplitChanged = pyqtSignal() splitFinished = pyqtSignal() readyChanged = pyqtSignal() createError = pyqtSignal([str], arguments=["error"]) createSuccess = pyqtSignal() - + invalidPassword = pyqtSignal() + def reset(self): self._path = None self._needsPassword = False self._needsHWDevice = False self._password = '' self._requiresSplit = False - self._invalidPassword = False + self._validPassword = True self._storage = None self._db = None @@ -110,15 +111,15 @@ class QEWalletDB(QObject): def requiresSplit(self): return self._requiresSplit - @pyqtProperty(bool, notify=invalidPasswordChanged) - def invalidPassword(self): - return self._invalidPassword + @pyqtProperty(bool, notify=validPasswordChanged) + def validPassword(self): + return self._validPassword - @invalidPassword.setter - def invalidPassword(self, invalidPassword): - if self._invalidPassword != invalidPassword: - self._invalidPassword = invalidPassword - self.invalidPasswordChanged.emit() + @validPassword.setter + def validPassword(self, validPassword): + if self._validPassword != validPassword: + self._validPassword = validPassword + self.validPasswordChanged.emit() @pyqtProperty(bool, notify=readyChanged) def ready(self): @@ -148,9 +149,10 @@ class QEWalletDB(QObject): try: self._storage.decrypt('' if not self._password else self._password) - self.invalidPassword = False + self.validPassword = True except InvalidPassword as e: - self.invalidPassword = True + self.validPassword = False + self.invalidPassword.emit() if not self._storage.is_past_initial_decryption(): self._storage = None