1
0

Merge pull request #10357 from f321x/fix_ledger_exception

wizard: hw: handle UserFacingException during encryption step
This commit is contained in:
ghost43
2025-12-10 17:04:59 +00:00
committed by GitHub
2 changed files with 34 additions and 8 deletions

View File

@@ -1275,19 +1275,40 @@ class WCWalletPasswordHardware(WalletWizardComponent):
self.layout().addLayout(self.playout.layout()) self.layout().addLayout(self.playout.layout())
self.layout().addStretch(1) self.layout().addStretch(1)
self._valid = True self._hw_password = None # type: Optional[str]
self._valid = False
def on_ready(self):
_name, info = self.wizard_data['hardware_device']
device_id = info.device.id_
client = self.plugins.device_manager.client_by_id(device_id, scan_now=False)
if client is None:
self.valid = False
self.error = _("Client for hardware device was unpaired.")
return
def retrieve_password_task():
try:
self._hw_password = client.get_password_for_storage_encryption()
self.valid = True
except UserFacingException as e:
self.error = str(e)
self.valid = False
finally:
self.busy = False
self.busy = True
t = threading.Thread(target=retrieve_password_task, daemon=True)
t.start()
def apply(self): def apply(self):
if not self.valid:
return
self.wizard_data['encrypt'] = True self.wizard_data['encrypt'] = True
if self.playout.should_encrypt_storage_with_xpub(): if self.playout.should_encrypt_storage_with_xpub():
self.wizard_data['xpub_encrypt'] = True self.wizard_data['xpub_encrypt'] = True
_name, _info = self.wizard_data['hardware_device'] assert self._hw_password
device_id = _info.device.id_ self.wizard_data['password'] = self._hw_password
client = self.plugins.device_manager.client_by_id(device_id, scan_now=False)
# client.handler = self.plugin.create_handler(self.wizard)
# FIXME client can be None if it was recently disconnected.
# also, even if not None, this might raise (e.g. if it disconnected *just now*):
self.wizard_data['password'] = client.get_password_for_storage_encryption()
else: else:
self.wizard_data['xpub_encrypt'] = False self.wizard_data['xpub_encrypt'] = False
self.wizard_data['password'] = self.playout.new_password() self.wizard_data['password'] = self.playout.new_password()

View File

@@ -137,6 +137,11 @@ def test_pin_unlocked(func):
return func(self, *args, **kwargs) return func(self, *args, **kwargs)
except SecurityStatusNotSatisfiedError: except SecurityStatusNotSatisfiedError:
raise UserFacingException(_('Your Ledger is locked. Please unlock it.')) raise UserFacingException(_('Your Ledger is locked. Please unlock it.'))
except OSError as e:
_logger.exception('')
raise UserFacingException(
_('Communication with Ledger failed. Open the Bitcoin app and try again.') + f'\n{str(e)}',
)
return catch_exception return catch_exception