simplify wizard handling of hardware wallets. fixes #1793
This commit is contained in:
parent
0e853a6769
commit
85aa633269
|
@ -260,7 +260,7 @@ class InstallWizard(QDialog, MessageBoxMixin, WizardBase):
|
||||||
'restore', and kind the index of the wallet kind chosen."""
|
'restore', and kind the index of the wallet kind chosen."""
|
||||||
|
|
||||||
actions = [_("Create a new wallet"),
|
actions = [_("Create a new wallet"),
|
||||||
_("Restore a wallet or import keys")]
|
_("Restore a wallet from seed words or from keys")]
|
||||||
title = _("Electrum could not find an existing wallet.")
|
title = _("Electrum could not find an existing wallet.")
|
||||||
actions_clayout = ChoicesLayout(_("What do you want to do?"), actions)
|
actions_clayout = ChoicesLayout(_("What do you want to do?"), actions)
|
||||||
wallet_clayout = ChoicesLayout(_("Wallet kind:"), wallet_kinds)
|
wallet_clayout = ChoicesLayout(_("Wallet kind:"), wallet_kinds)
|
||||||
|
@ -273,25 +273,15 @@ class InstallWizard(QDialog, MessageBoxMixin, WizardBase):
|
||||||
action = ['create', 'restore'][actions_clayout.selected_index()]
|
action = ['create', 'restore'][actions_clayout.selected_index()]
|
||||||
return action, wallet_clayout.selected_index()
|
return action, wallet_clayout.selected_index()
|
||||||
|
|
||||||
def query_hw_wallet_choice(self, msg, action, choices):
|
def query_hw_wallet_choice(self, msg, choices):
|
||||||
actions = [_("Initialize a new or wiped device"),
|
|
||||||
_("Use a device you have already set up"),
|
|
||||||
_("Restore Electrum wallet from device seed words")]
|
|
||||||
default_action = 1 if action == 'create' else 2
|
|
||||||
actions_clayout = ChoicesLayout(_("What do you want to do?"), actions,
|
|
||||||
checked_index=default_action)
|
|
||||||
wallet_clayout = ChoicesLayout(msg, choices)
|
|
||||||
|
|
||||||
vbox = QVBoxLayout()
|
vbox = QVBoxLayout()
|
||||||
vbox.addLayout(actions_clayout.layout())
|
if choices:
|
||||||
vbox.addLayout(wallet_clayout.layout())
|
wallet_clayout = ChoicesLayout(msg, choices)
|
||||||
self.set_main_layout(vbox, next_enabled=len(choices) != 0)
|
vbox.addLayout(wallet_clayout.layout())
|
||||||
|
|
||||||
if actions_clayout.selected_index() == 2:
|
|
||||||
action = 'restore'
|
|
||||||
else:
|
else:
|
||||||
action = 'create'
|
vbox.addWidget(QLabel(msg, wordWrap=True))
|
||||||
return action, wallet_clayout.selected_index()
|
self.set_main_layout(vbox, next_enabled=len(choices) != 0)
|
||||||
|
return wallet_clayout.selected_index() if choices else 0
|
||||||
|
|
||||||
def request_many(self, n, xpub_hot=None):
|
def request_many(self, n, xpub_hot=None):
|
||||||
vbox = QVBoxLayout()
|
vbox = QVBoxLayout()
|
||||||
|
|
|
@ -209,19 +209,20 @@ class WizardBase(PrintError):
|
||||||
kinds, descriptions = zip(*[pair for pair in WizardBase.wallet_kinds
|
kinds, descriptions = zip(*[pair for pair in WizardBase.wallet_kinds
|
||||||
if pair[0] in registered_kinds])
|
if pair[0] in registered_kinds])
|
||||||
action, kind_index = self.query_create_or_restore(descriptions)
|
action, kind_index = self.query_create_or_restore(descriptions)
|
||||||
|
|
||||||
assert action in WizardBase.user_actions
|
assert action in WizardBase.user_actions
|
||||||
|
|
||||||
kind = kinds[kind_index]
|
kind = kinds[kind_index]
|
||||||
if kind == 'multisig':
|
if kind == 'multisig':
|
||||||
wallet_type = self.query_multisig(action)
|
wallet_type = self.query_multisig(action)
|
||||||
elif kind == 'hardware':
|
elif kind == 'hardware':
|
||||||
# The create/restore distinction is not obvious for hardware
|
|
||||||
# wallets; so we ask for the action again and default based
|
|
||||||
# on the prior choice :)
|
|
||||||
hw_wallet_types, choices = self.plugins.hardware_wallets(action)
|
hw_wallet_types, choices = self.plugins.hardware_wallets(action)
|
||||||
msg = _('Select the type of hardware wallet: ')
|
if choices:
|
||||||
action, choice = self.query_hw_wallet_choice(msg, action, choices)
|
msg = _('Select the type of hardware wallet: ')
|
||||||
|
else:
|
||||||
|
msg = ' '.join([
|
||||||
|
_('No hardware wallet support found on your system.'),
|
||||||
|
_('Please install the relevant libraries (eg python-trezor for Trezor).'),
|
||||||
|
])
|
||||||
|
choice = self.query_hw_wallet_choice(msg, choices)
|
||||||
wallet_type = hw_wallet_types[choice]
|
wallet_type = hw_wallet_types[choice]
|
||||||
elif kind == 'twofactor':
|
elif kind == 'twofactor':
|
||||||
wallet_type = '2fa'
|
wallet_type = '2fa'
|
||||||
|
|
Loading…
Reference in New Issue