mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
hww: show model name in device enum lists (e.g. "Trezor T")
This commit is contained in:
parent
e1996bde01
commit
db1ff4915f
5 changed files with 37 additions and 10 deletions
|
@ -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,
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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."""
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue