From e7ebf5d950dcff8dd08b7ec5b1b66b68012609d7 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Wed, 31 Jan 2024 04:02:02 +0000 Subject: [PATCH] qt wizard: handle some cases of hw device being unplugged during flow To reproduce, open two wizards in parallel. Use one to enter the flow and start creating a wallet, then physically unplug the hw device at the correct time, and use the other wizard to trigger a rescan. The rescan will unpair the hw device, resulting in device_manager.client_by_id to return None when continuing the flow on the first wizard. fixes https://github.com/spesmilo/electrum/issues/8858 --- electrum/gui/qt/wizard/wallet.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/electrum/gui/qt/wizard/wallet.py b/electrum/gui/qt/wizard/wallet.py index 37299c4eb..48f001609 100644 --- a/electrum/gui/qt/wizard/wallet.py +++ b/electrum/gui/qt/wizard/wallet.py @@ -1253,6 +1253,8 @@ class WCWalletPasswordHardware(WalletWizardComponent): device_id = _info.device.id_ 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() @@ -1282,6 +1284,11 @@ class WCHWUnlock(WalletWizardComponent, Logger): device_id = _info.device.id_ client = self.plugins.device_manager.client_by_id(device_id, scan_now=False) + if client is None: + self.error = _("Client for hardware device was unpaired.") + self.busy = False + self.validate() + return client.handler = self.plugin.create_handler(self.wizard) def unlock_task(client): @@ -1357,6 +1364,11 @@ class WCHWXPub(WalletWizardComponent, Logger): device_id = _info.device.id_ client = self.plugins.device_manager.client_by_id(device_id, scan_now=False) + if client is None: + self.error = _("Client for hardware device was unpaired.") + self.busy = False + self.validate() + return if not client.handler: client.handler = self.plugin.create_handler(self.wizard)