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.plugin import run_hook, HardwarePluginLibraryUnavailable
|
||||
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 .wizard import QEAbstractWizard, WizardComponent
|
||||
from electrum.logging import get_logger, Logger
|
||||
@@ -181,6 +181,29 @@ class QENewWalletWizard(NewWalletWizard, QEAbstractWizard, MessageBoxMixin):
|
||||
if db.requires_upgrade():
|
||||
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):
|
||||
dialog = QDialog()
|
||||
label = WWLabel(msg)
|
||||
|
||||
@@ -193,8 +193,10 @@ class QEAbstractWizard(QDialog, MessageBoxMixin):
|
||||
wd = page.wizard_data.copy()
|
||||
if self.is_last(wd):
|
||||
self.submit(wd)
|
||||
self.finished(wd)
|
||||
self.accept()
|
||||
if self.is_finalized(wd):
|
||||
self.accept()
|
||||
else:
|
||||
self.prev() # rollback the submit above
|
||||
else:
|
||||
next = self.submit(wd)
|
||||
self.load_next_component(next.view, next.wizard_data, next.params)
|
||||
@@ -219,6 +221,10 @@ class QEAbstractWizard(QDialog, MessageBoxMixin):
|
||||
wdata = wizard_data.copy()
|
||||
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):
|
||||
updated = pyqtSignal(object)
|
||||
|
||||
@@ -79,10 +79,7 @@ class AbstractWizard:
|
||||
# make a clone for next view
|
||||
wizard_data = copy.deepcopy(wizard_data)
|
||||
|
||||
is_finished = False
|
||||
if 'next' not in nav:
|
||||
# finished
|
||||
is_finished = True
|
||||
new_view = WizardViewState(None, wizard_data, {})
|
||||
else:
|
||||
view_next = nav['next']
|
||||
@@ -118,9 +115,6 @@ class AbstractWizard:
|
||||
|
||||
self.log_stack()
|
||||
|
||||
if is_finished:
|
||||
self.finished(wizard_data)
|
||||
|
||||
return new_view
|
||||
|
||||
def resolve_prev(self):
|
||||
@@ -154,9 +148,6 @@ class AbstractWizard:
|
||||
else:
|
||||
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):
|
||||
self._stack = []
|
||||
self._current = WizardViewState(None, {}, {})
|
||||
|
||||
Reference in New Issue
Block a user