wizard: remove finished call, it's unused
qt: call is_finalized before closing the wizard dialog and add a check if wallet can be
decrypted with the supplied secret (user pw, hw device)
This commit is contained in:
@@ -16,7 +16,7 @@ from electrum.i18n import _
|
|||||||
from electrum.keystore import bip44_derivation, bip39_to_seed, purpose48_derivation, ScriptTypeNotSupported
|
from electrum.keystore import bip44_derivation, bip39_to_seed, purpose48_derivation, ScriptTypeNotSupported
|
||||||
from electrum.plugin import run_hook, HardwarePluginLibraryUnavailable
|
from electrum.plugin import run_hook, HardwarePluginLibraryUnavailable
|
||||||
from electrum.storage import StorageReadWriteError
|
from electrum.storage import StorageReadWriteError
|
||||||
from electrum.util import WalletFileException, get_new_wallet_name, UserCancelled, UserFacingException
|
from electrum.util import WalletFileException, get_new_wallet_name, UserCancelled, UserFacingException, InvalidPassword
|
||||||
from electrum.wallet import wallet_types
|
from electrum.wallet import wallet_types
|
||||||
from .wizard import QEAbstractWizard, WizardComponent
|
from .wizard import QEAbstractWizard, WizardComponent
|
||||||
from electrum.logging import get_logger, Logger
|
from electrum.logging import get_logger, Logger
|
||||||
@@ -181,6 +181,29 @@ class QENewWalletWizard(NewWalletWizard, QEAbstractWizard, MessageBoxMixin):
|
|||||||
if db.requires_upgrade():
|
if db.requires_upgrade():
|
||||||
self.waiting_dialog(db.upgrade, _('Upgrading wallet format...'))
|
self.waiting_dialog(db.upgrade, _('Upgrading wallet format...'))
|
||||||
|
|
||||||
|
def is_finalized(self, wizard_data: dict) -> bool:
|
||||||
|
# check decryption of existing wallet and keep wizard open if incorrect.
|
||||||
|
|
||||||
|
if not wizard_data['wallet_exists'] or wizard_data['wallet_is_open']:
|
||||||
|
return True
|
||||||
|
|
||||||
|
wallet_file = wizard_data['wallet_name']
|
||||||
|
|
||||||
|
storage = WalletStorage(wallet_file)
|
||||||
|
if not storage.is_encrypted_with_user_pw() and not storage.is_encrypted_with_hw_device():
|
||||||
|
return True
|
||||||
|
|
||||||
|
try:
|
||||||
|
storage.decrypt(wizard_data['password'])
|
||||||
|
except InvalidPassword:
|
||||||
|
if storage.is_encrypted_with_hw_device():
|
||||||
|
self.show_message('This hardware device could not decrypt this wallet. Is it the correct one?')
|
||||||
|
else:
|
||||||
|
self.show_message('Invalid password')
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def waiting_dialog(self, task, msg, on_finished=None):
|
def waiting_dialog(self, task, msg, on_finished=None):
|
||||||
dialog = QDialog()
|
dialog = QDialog()
|
||||||
label = WWLabel(msg)
|
label = WWLabel(msg)
|
||||||
|
|||||||
@@ -193,8 +193,10 @@ class QEAbstractWizard(QDialog, MessageBoxMixin):
|
|||||||
wd = page.wizard_data.copy()
|
wd = page.wizard_data.copy()
|
||||||
if self.is_last(wd):
|
if self.is_last(wd):
|
||||||
self.submit(wd)
|
self.submit(wd)
|
||||||
self.finished(wd)
|
if self.is_finalized(wd):
|
||||||
self.accept()
|
self.accept()
|
||||||
|
else:
|
||||||
|
self.prev() # rollback the submit above
|
||||||
else:
|
else:
|
||||||
next = self.submit(wd)
|
next = self.submit(wd)
|
||||||
self.load_next_component(next.view, next.wizard_data, next.params)
|
self.load_next_component(next.view, next.wizard_data, next.params)
|
||||||
@@ -219,6 +221,10 @@ class QEAbstractWizard(QDialog, MessageBoxMixin):
|
|||||||
wdata = wizard_data.copy()
|
wdata = wizard_data.copy()
|
||||||
return self.is_last_view(self._current.view, wdata)
|
return self.is_last_view(self._current.view, wdata)
|
||||||
|
|
||||||
|
def is_finalized(self, wizard_data: dict) -> bool:
|
||||||
|
''' Final check before closing the wizard. '''
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class WizardComponent(QWidget):
|
class WizardComponent(QWidget):
|
||||||
updated = pyqtSignal(object)
|
updated = pyqtSignal(object)
|
||||||
|
|||||||
@@ -79,10 +79,7 @@ class AbstractWizard:
|
|||||||
# make a clone for next view
|
# make a clone for next view
|
||||||
wizard_data = copy.deepcopy(wizard_data)
|
wizard_data = copy.deepcopy(wizard_data)
|
||||||
|
|
||||||
is_finished = False
|
|
||||||
if 'next' not in nav:
|
if 'next' not in nav:
|
||||||
# finished
|
|
||||||
is_finished = True
|
|
||||||
new_view = WizardViewState(None, wizard_data, {})
|
new_view = WizardViewState(None, wizard_data, {})
|
||||||
else:
|
else:
|
||||||
view_next = nav['next']
|
view_next = nav['next']
|
||||||
@@ -118,9 +115,6 @@ class AbstractWizard:
|
|||||||
|
|
||||||
self.log_stack()
|
self.log_stack()
|
||||||
|
|
||||||
if is_finished:
|
|
||||||
self.finished(wizard_data)
|
|
||||||
|
|
||||||
return new_view
|
return new_view
|
||||||
|
|
||||||
def resolve_prev(self):
|
def resolve_prev(self):
|
||||||
@@ -154,9 +148,6 @@ class AbstractWizard:
|
|||||||
else:
|
else:
|
||||||
raise Exception(f'last handler for view {view} is not callable nor a bool literal')
|
raise Exception(f'last handler for view {view} is not callable nor a bool literal')
|
||||||
|
|
||||||
def finished(self, wizard_data: dict):
|
|
||||||
self._logger.debug('finished.')
|
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self._stack = []
|
self._stack = []
|
||||||
self._current = WizardViewState(None, {}, {})
|
self._current = WizardViewState(None, {}, {})
|
||||||
|
|||||||
Reference in New Issue
Block a user