mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-28 07:51:27 +00:00
wizard hww: use exception handling to choose hw device again
- no need to pass args, caller knows what it wanted - avoids deepening the call stack on every rescan (nicer tracebacks, no stack overflow)
This commit is contained in:
parent
71eed1d4cb
commit
b6bac0182f
1 changed files with 22 additions and 18 deletions
|
@ -60,6 +60,9 @@ class ScriptTypeNotSupported(Exception): pass
|
||||||
class GoBack(Exception): pass
|
class GoBack(Exception): pass
|
||||||
|
|
||||||
|
|
||||||
|
class ChooseHwDeviceAgain(Exception): pass
|
||||||
|
|
||||||
|
|
||||||
class WizardStackItem(NamedTuple):
|
class WizardStackItem(NamedTuple):
|
||||||
action: Any
|
action: Any
|
||||||
args: Any
|
args: Any
|
||||||
|
@ -264,6 +267,15 @@ class BaseWizard(Logger):
|
||||||
self.on_keystore(k)
|
self.on_keystore(k)
|
||||||
|
|
||||||
def choose_hw_device(self, purpose=HWD_SETUP_NEW_WALLET, *, storage: WalletStorage = None):
|
def choose_hw_device(self, purpose=HWD_SETUP_NEW_WALLET, *, storage: WalletStorage = None):
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
self._choose_hw_device(purpose=purpose, storage=storage)
|
||||||
|
except ChooseHwDeviceAgain:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
def _choose_hw_device(self, *, purpose, storage: WalletStorage = None):
|
||||||
title = _('Hardware Keystore')
|
title = _('Hardware Keystore')
|
||||||
# check available plugins
|
# check available plugins
|
||||||
supported_plugins = self.plugins.get_hardware_support()
|
supported_plugins = self.plugins.get_hardware_support()
|
||||||
|
@ -327,8 +339,8 @@ class BaseWizard(Logger):
|
||||||
msg += '\n\n'
|
msg += '\n\n'
|
||||||
msg += _('Debug message') + '\n' + debug_msg
|
msg += _('Debug message') + '\n' + debug_msg
|
||||||
self.confirm_dialog(title=title, message=msg,
|
self.confirm_dialog(title=title, message=msg,
|
||||||
run_next=lambda x: self.choose_hw_device(purpose, storage=storage))
|
run_next=lambda x: None)
|
||||||
return
|
raise ChooseHwDeviceAgain()
|
||||||
# select device
|
# select device
|
||||||
self.devices = devices
|
self.devices = devices
|
||||||
choices = []
|
choices = []
|
||||||
|
@ -355,27 +367,22 @@ class BaseWizard(Logger):
|
||||||
+ _('To try to fix this, we will now re-pair with your device.') + '\n'
|
+ _('To try to fix this, we will now re-pair with your device.') + '\n'
|
||||||
+ _('Please try again.'))
|
+ _('Please try again.'))
|
||||||
devmgr.unpair_id(device_info.device.id_)
|
devmgr.unpair_id(device_info.device.id_)
|
||||||
self.choose_hw_device(purpose, storage=storage)
|
raise ChooseHwDeviceAgain()
|
||||||
return
|
|
||||||
except OutdatedHwFirmwareException as e:
|
except OutdatedHwFirmwareException as e:
|
||||||
if self.question(e.text_ignore_old_fw_and_continue(), title=_("Outdated device firmware")):
|
if self.question(e.text_ignore_old_fw_and_continue(), title=_("Outdated device firmware")):
|
||||||
self.plugin.set_ignore_outdated_fw()
|
self.plugin.set_ignore_outdated_fw()
|
||||||
# will need to re-pair
|
# will need to re-pair
|
||||||
devmgr.unpair_id(device_info.device.id_)
|
devmgr.unpair_id(device_info.device.id_)
|
||||||
self.choose_hw_device(purpose, storage=storage)
|
raise ChooseHwDeviceAgain()
|
||||||
return
|
|
||||||
except (UserCancelled, GoBack):
|
except (UserCancelled, GoBack):
|
||||||
self.choose_hw_device(purpose, storage=storage)
|
raise ChooseHwDeviceAgain()
|
||||||
return
|
|
||||||
except UserFacingException as e:
|
except UserFacingException as e:
|
||||||
self.show_error(str(e))
|
self.show_error(str(e))
|
||||||
self.choose_hw_device(purpose, storage=storage)
|
raise ChooseHwDeviceAgain()
|
||||||
return
|
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
self.logger.exception('')
|
self.logger.exception('')
|
||||||
self.show_error(str(e))
|
self.show_error(str(e))
|
||||||
self.choose_hw_device(purpose, storage=storage)
|
raise ChooseHwDeviceAgain()
|
||||||
return
|
|
||||||
|
|
||||||
if purpose == HWD_SETUP_NEW_WALLET:
|
if purpose == HWD_SETUP_NEW_WALLET:
|
||||||
def f(derivation, script_type):
|
def f(derivation, script_type):
|
||||||
|
@ -444,8 +451,7 @@ class BaseWizard(Logger):
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
self.logger.exception('')
|
self.logger.exception('')
|
||||||
self.show_error(e)
|
self.show_error(e)
|
||||||
self.choose_hw_device()
|
raise ChooseHwDeviceAgain()
|
||||||
return
|
|
||||||
d = {
|
d = {
|
||||||
'type': 'hardware',
|
'type': 'hardware',
|
||||||
'hw_type': name,
|
'hw_type': name,
|
||||||
|
@ -561,13 +567,11 @@ class BaseWizard(Logger):
|
||||||
except UserCancelled:
|
except UserCancelled:
|
||||||
devmgr = self.plugins.device_manager
|
devmgr = self.plugins.device_manager
|
||||||
devmgr.unpair_xpub(k.xpub)
|
devmgr.unpair_xpub(k.xpub)
|
||||||
self.choose_hw_device()
|
raise ChooseHwDeviceAgain()
|
||||||
return
|
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
self.logger.exception('')
|
self.logger.exception('')
|
||||||
self.show_error(str(e))
|
self.show_error(str(e))
|
||||||
self.choose_hw_device()
|
raise ChooseHwDeviceAgain()
|
||||||
return
|
|
||||||
self.request_storage_encryption(
|
self.request_storage_encryption(
|
||||||
run_next=lambda encrypt_storage: self.on_password(
|
run_next=lambda encrypt_storage: self.on_password(
|
||||||
password,
|
password,
|
||||||
|
|
Loading…
Add table
Reference in a new issue