From 63fed38305590bbad18eb2c098b233e85b04e9e4 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Tue, 12 Jul 2022 17:34:52 +0200 Subject: [PATCH] qml: skip wallet password entry when single_password and password is known --- .../gui/qml/components/NewWalletWizard.qml | 22 +++++++++---------- electrum/gui/qml/qedaemon.py | 10 +++++++++ electrum/gui/qml/qewalletdb.py | 8 +++++-- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/electrum/gui/qml/components/NewWalletWizard.qml b/electrum/gui/qml/components/NewWalletWizard.qml index 3a82c5918..220735608 100644 --- a/electrum/gui/qml/components/NewWalletWizard.qml +++ b/electrum/gui/qml/components/NewWalletWizard.qml @@ -44,6 +44,8 @@ Wizard { case 'haveseed': page = _loadNextComponent(components.haveseed, wizard_data) page.next.connect(function() {haveseedDone()}) + if (wizard_data['seed_type'] != 'bip39' && Daemon.singlePassword) + page.last = true break // case 'masterkey' // case 'hardware' @@ -53,13 +55,15 @@ Wizard { function createseedDone(d) { console.log('create seed done') var page = _loadNextComponent(components.confirmseed, wizard_data) - page.next.connect(function() {confirmseedDone()}) + if (Daemon.singlePassword) + page.last = true + else + page.next.connect(function() {confirmseedDone()}) } function confirmseedDone(d) { console.log('confirm seed done') var page = _loadNextComponent(components.walletpassword, wizard_data) - page.next.connect(function() {walletpasswordDone()}) page.last = true } @@ -67,10 +71,12 @@ Wizard { console.log('have seed done') if (wizard_data['seed_type'] == 'bip39') { var page = _loadNextComponent(components.bip39refine, wizard_data) - page.next.connect(function() {bip39refineDone()}) + if (Daemon.singlePassword) + page.last = true + else + page.next.connect(function() {bip39refineDone()}) } else { var page = _loadNextComponent(components.walletpassword, wizard_data) - page.next.connect(function() {walletpasswordDone()}) page.last = true } } @@ -78,15 +84,9 @@ Wizard { function bip39refineDone(d) { console.log('bip39 refine done') var page = _loadNextComponent(components.walletpassword, wizard_data) - page.next.connect(function() {walletpasswordDone()}) page.last = true } - function walletpasswordDone(d) { - console.log('walletpassword done') - var page = _loadNextComponent(components.walletpassword, wizard_data) - } - WizardComponents { id: components } @@ -99,7 +99,7 @@ Wizard { onAccepted: { console.log('Finished new wallet wizard') - walletdb.create_storage(wizard_data) + walletdb.create_storage(wizard_data, Daemon.singlePasswordEnabled, Daemon.singlePassword) } WalletDB { diff --git a/electrum/gui/qml/qedaemon.py b/electrum/gui/qml/qedaemon.py index f61317598..94d19ded3 100644 --- a/electrum/gui/qml/qedaemon.py +++ b/electrum/gui/qml/qedaemon.py @@ -155,6 +155,7 @@ class QEDaemon(AuthMixin, QObject): if self.daemon.config.get('single_password'): self._use_single_password = self.daemon.update_password_for_directory(old_password=password, new_password=password) self._password = password + self.singlePasswordChanged.emit() self._logger.info(f'use single password: {self._use_single_password}') else: self._logger.info('use single password disabled by config') @@ -203,6 +204,15 @@ class QEDaemon(AuthMixin, QObject): def fx(self): return self.qefx + singlePasswordChanged = pyqtSignal() + @pyqtProperty(bool, notify=singlePasswordChanged) + def singlePasswordEnabled(self): + return self._use_single_password + + @pyqtProperty(str, notify=singlePasswordChanged) + def singlePassword(self): + return self._password + @pyqtSlot(result=str) def suggestWalletName(self): i = 1 diff --git a/electrum/gui/qml/qewalletdb.py b/electrum/gui/qml/qewalletdb.py index 4a3c986cd..9d585117d 100644 --- a/electrum/gui/qml/qewalletdb.py +++ b/electrum/gui/qml/qewalletdb.py @@ -172,12 +172,16 @@ class QEWalletDB(QObject): self._ready = True self.readyChanged.emit() - @pyqtSlot('QJSValue') - def create_storage(self, js_data): + @pyqtSlot('QJSValue',bool,str) + def create_storage(self, js_data, single_password_enabled, single_password): self._logger.info('Creating wallet from wizard data') data = js_data.toVariant() self._logger.debug(str(data)) + if single_password_enabled and single_password: + data['encrypt'] = True + data['password'] = single_password + try: path = os.path.join(os.path.dirname(self.daemon.config.get_wallet_path()), data['wallet_name']) if os.path.exists(path):