electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit db1ff4915fc613d30d4d73289337b38a2e2b0e2c
parent e1996bde01edbae2619915eb216ede0639765946
Author: SomberNight <somber.night@protonmail.com>
Date:   Wed,  8 Apr 2020 17:25:18 +0200

hww: show model name in device enum lists (e.g. "Trezor T")

Diffstat:
Melectrum/base_wizard.py | 2+-
Melectrum/plugin.py | 9++++++---
Melectrum/plugins/hw_wallet/plugin.py | 6++++++
Melectrum/plugins/ledger/ledger.py | 22++++++++++++++++------
Melectrum/plugins/trezor/clientbase.py | 8++++++++
5 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/electrum/base_wizard.py b/electrum/base_wizard.py @@ -336,7 +336,7 @@ class BaseWizard(Logger): label = info.label or _("An unnamed {}").format(name) try: transport_str = info.device.transport_ui_string[:20] except: transport_str = 'unknown transport' - descr = f"{label} [{name}, {state}, {transport_str}]" + descr = f"{label} [{info.model_name or name}, {state}, {transport_str}]" choices.append(((name, info), descr)) msg = _('Select a device') + ':' self.choice_dialog(title=title, message=msg, choices=choices, diff --git a/electrum/plugin.py b/electrum/plugin.py @@ -308,6 +308,7 @@ class DeviceInfo(NamedTuple): exception: Optional[Exception] = None plugin_name: Optional[str] = None # manufacturer, e.g. "trezor" soft_device_id: Optional[str] = None # if available, used to distinguish same-type hw devices + model_name: Optional[str] = None # e.g. "Ledger Nano S" class HardwarePluginToScan(NamedTuple): @@ -560,7 +561,8 @@ class DeviceMgr(ThreadJob): label=client.label(), initialized=client.is_initialized(), plugin_name=plugin.name, - soft_device_id=client.get_soft_device_id())) + soft_device_id=client.get_soft_device_id(), + model_name=client.device_model_name())) return infos @@ -613,10 +615,11 @@ class DeviceMgr(ThreadJob): raise CannotAutoSelectDevice() # ask user to select device manually msg = _("Please select which {} device to use:").format(plugin.device) - descriptions = ["{label} ({init}, {transport})" + descriptions = ["{label} ({maybe_model}{init}, {transport})" .format(label=info.label or _("An unnamed {}").format(info.plugin_name), init=(_("initialized") if info.initialized else _("wiped")), - transport=info.device.transport_ui_string) + transport=info.device.transport_ui_string, + maybe_model=f"{info.model_name}, " if info.model_name else "") for info in infos] c = handler.query_choice(msg, descriptions) if c is None: diff --git a/electrum/plugins/hw_wallet/plugin.py b/electrum/plugins/hw_wallet/plugin.py @@ -228,6 +228,12 @@ class HardwareClientBase: password = Xpub.get_pubkey_from_xpub(xpub, ()).hex() return password + def device_model_name(self) -> Optional[str]: + """Return the name of the model of this device, which might be displayed in the UI. + E.g. for Trezor, "Trezor One" or "Trezor T". + """ + return None + class HardwareHandlerBase: """An interface between the GUI and the device handling logic for handling I/O.""" diff --git a/electrum/plugins/ledger/ledger.py b/electrum/plugins/ledger/ledger.py @@ -2,7 +2,7 @@ from struct import pack, unpack import hashlib import sys import traceback -from typing import Optional +from typing import Optional, Tuple from electrum import ecc from electrum import bip32 @@ -62,10 +62,10 @@ def test_pin_unlocked(func): class Ledger_Client(HardwareClientBase): - def __init__(self, hidDevice, *, is_hw1: bool = False): + def __init__(self, hidDevice, *, product_key: Tuple[int, int]): self.dongleObject = btchip(hidDevice) self.preflightDone = False - self._is_hw1 = is_hw1 + self._product_key = product_key self._soft_device_id = None def is_pairable(self): @@ -92,7 +92,18 @@ class Ledger_Client(HardwareClientBase): return self._soft_device_id def is_hw1(self) -> bool: - return self._is_hw1 + return self._product_key[0] == 0x2581 + + def device_model_name(self): + if self.is_hw1(): + return "Ledger HW.1" + if self._product_key == (0x2c97, 0x0000): + return "Ledger Blue" + if self._product_key == (0x2c97, 0x0001): + return "Ledger Nano S" + if self._product_key == (0x2c97, 0x0004): + return "Ledger Nano X" + return None def has_usable_connection_with_device(self): try: @@ -594,8 +605,7 @@ class LedgerPlugin(HW_PluginBase): client = self.get_btchip_device(device) if client is not None: - is_hw1 = device.product_key[0] == 0x2581 - client = Ledger_Client(client, is_hw1=is_hw1) + client = Ledger_Client(client, product_key=device.product_key) return client def setup_device(self, device_info, wizard, purpose): diff --git a/electrum/plugins/trezor/clientbase.py b/electrum/plugins/trezor/clientbase.py @@ -196,6 +196,14 @@ class TrezorClientBase(HardwareClientBase, Logger): """Returns '1' for Trezor One, 'T' for Trezor T.""" return self.features.model + def device_model_name(self): + model = self.get_trezor_model() + if model == '1': + return "Trezor One" + elif model == 'T': + return "Trezor T" + return None + def show_address(self, address_str, script_type, multisig=None): coin_name = self.plugin.get_coin_name() address_n = parse_path(address_str)