Improved multi-device handling
Ask user which device to use when there are many. If there is only one skip the question. We used to just pick the first one we found; user had no way to switch. We have to handle querying from the non-GUI thread.
This commit is contained in:
@@ -25,9 +25,6 @@ TIM_NEW, TIM_RECOVER, TIM_MNEMONIC, TIM_PRIVKEY = range(0, 4)
|
||||
class DeviceDisconnectedError(Exception):
|
||||
pass
|
||||
|
||||
class OutdatedFirmwareError(Exception):
|
||||
pass
|
||||
|
||||
class TrezorCompatibleWallet(BIP44_Wallet):
|
||||
# Extend BIP44 Wallet as required by hardware implementation.
|
||||
# Derived classes must set:
|
||||
@@ -332,42 +329,15 @@ class TrezorCompatiblePlugin(BasePlugin, ThreadJob):
|
||||
'''Called when creating a new wallet. Select the device to use. If
|
||||
the device is uninitialized, go through the intialization
|
||||
process. Then create the wallet accounts.'''
|
||||
initialized = self.select_device(wallet)
|
||||
if initialized:
|
||||
devmgr = self.device_manager()
|
||||
device_info = devmgr.select_device(wallet, self)
|
||||
devmgr.pair_wallet(wallet, device_info.device.id_)
|
||||
if device_info.initialized:
|
||||
task = partial(wallet.create_hd_account, None)
|
||||
else:
|
||||
task = self.initialize_device(wallet)
|
||||
wallet.thread.add(task, on_done=on_done, on_error=on_error)
|
||||
|
||||
def unpaired_devices(self, handler):
|
||||
'''Returns all connected, unpaired devices as a list of clients and a
|
||||
list of descriptions.'''
|
||||
devmgr = self.device_manager()
|
||||
devices = devmgr.unpaired_devices(handler)
|
||||
|
||||
states = [_("wiped"), _("initialized")]
|
||||
infos = []
|
||||
for device in devices:
|
||||
if not device.product_key in self.DEVICE_IDS:
|
||||
continue
|
||||
client = self.device_manager().create_client(device, handler, self)
|
||||
if not client:
|
||||
continue
|
||||
state = states[client.is_initialized()]
|
||||
label = client.label() or _("An unnamed %s") % self.device
|
||||
descr = "%s (%s)" % (label, state)
|
||||
infos.append((device, descr, client.is_initialized()))
|
||||
|
||||
return infos
|
||||
|
||||
def select_device(self, wallet):
|
||||
msg = _("Please select which %s device to use:") % self.device
|
||||
infos = self.unpaired_devices(wallet.handler)
|
||||
labels = [info[1] for info in infos]
|
||||
device, descr, init = infos[wallet.handler.query_choice(msg, labels)]
|
||||
self.device_manager().pair_wallet(wallet, device.id_)
|
||||
return init
|
||||
|
||||
def on_restore_wallet(self, wallet, wizard):
|
||||
assert isinstance(wallet, self.wallet_class)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user