Move wallet_kinds to the base class

This logic isn't gui-dependent so belongs in wizard.py
This commit is contained in:
Neil Booth 2016-01-02 00:35:09 +09:00
parent 1d07960290
commit 12f62212ba
2 changed files with 22 additions and 20 deletions

View File

@ -151,9 +151,11 @@ class InstallWizard(WindowModalDialog, MessageBoxMixin, WizardBase):
self.stack.setCurrentWidget(w) self.stack.setCurrentWidget(w)
self.show() self.show()
def query_create_or_restore(self): def query_create_or_restore(self, wallet_kinds):
"""Returns a tuple (action, kind). Action is one of user_actions, """Ask the user what they want to do, and to what wallet kind.
or None if cancelled. kind is one of wallet_kinds.""" wallet_kinds is an array of tuples (kind, description).
Return a tuple (action, kind). Action is 'create' or 'restore',
and kind is one of the wallet kinds passed."""
vbox = QVBoxLayout() vbox = QVBoxLayout()
main_label = QLabel(_("Electrum could not find an existing wallet.")) main_label = QLabel(_("Electrum could not find an existing wallet."))
@ -188,14 +190,7 @@ class InstallWizard(WindowModalDialog, MessageBoxMixin, WizardBase):
group2 = QButtonGroup() group2 = QButtonGroup()
wallet_types = [ for i, (wtype,name) in enumerate(wallet_kinds):
('standard', _("Standard wallet")),
('twofactor', _("Wallet with two-factor authentication")),
('multisig', _("Multi-signature wallet")),
('hardware', _("Hardware wallet")),
]
for i, (wtype,name) in enumerate(wallet_types):
if not filter(lambda x:x[0]==wtype, electrum.wallet.wallet_types): if not filter(lambda x:x[0]==wtype, electrum.wallet.wallet_types):
continue continue
button = QRadioButton(gb2) button = QRadioButton(gb2)
@ -217,7 +212,7 @@ class InstallWizard(WindowModalDialog, MessageBoxMixin, WizardBase):
raise UserCancelled raise UserCancelled
action = 'create' if b1.isChecked() else 'restore' action = 'create' if b1.isChecked() else 'restore'
wallet_type = wallet_types[group2.checkedId()][0] wallet_type = wallet_kinds[group2.checkedId()][0]
return action, wallet_type return action, wallet_type
def verify_seed(self, seed, is_valid=None): def verify_seed(self, seed, is_valid=None):

View File

@ -42,7 +42,13 @@ class UserCancelled(Exception):
class WizardBase(PrintError): class WizardBase(PrintError):
'''Base class for gui-specific install wizards.''' '''Base class for gui-specific install wizards.'''
user_actions = ('create', 'restore') user_actions = ('create', 'restore')
wallet_kinds = ('standard', 'hardware', 'multisig', 'twofactor') wallet_kinds = [
('standard', _("Standard wallet")),
('twofactor', _("Wallet with two-factor authentication")),
('multisig', _("Multi-signature wallet")),
('hardware', _("Hardware wallet")),
]
# Derived classes must set: # Derived classes must set:
# self.language_for_seed # self.language_for_seed
@ -58,9 +64,11 @@ class WizardBase(PrintError):
"""Remove filename from the recently used list.""" """Remove filename from the recently used list."""
raise NotImplementedError raise NotImplementedError
def query_create_or_restore(self): def query_create_or_restore(self, wallet_kinds):
"""Returns a tuple (action, kind). Action is one of user_actions, """Ask the user what they want to do, and to what wallet kind.
kind is one of wallet_kinds.""" wallet_kinds is an array of tuples (kind, description).
Return a tuple (action, kind). Action is 'create' or 'restore',
and kind is one of the wallet kinds passed."""
raise NotImplementedError raise NotImplementedError
def query_multisig(self, action): def query_multisig(self, action):
@ -189,10 +197,10 @@ class WizardBase(PrintError):
a wallet and return it.''' a wallet and return it.'''
self.remove_from_recently_open(storage.path) self.remove_from_recently_open(storage.path)
action, kind = self.query_create_or_restore() action, kind = self.query_create_or_restore(WizardBase.wallet_kinds)
assert action in self.user_actions assert action in WizardBase.user_actions
assert kind in self.wallet_kinds assert kind in [k for k, desc in WizardBase.wallet_kinds]
if kind == 'multisig': if kind == 'multisig':
wallet_type = self.query_multisig(action) wallet_type = self.query_multisig(action)
@ -225,7 +233,6 @@ class WizardBase(PrintError):
if wallet_type == 'standard': if wallet_type == 'standard':
return self.restore_standard_wallet(storage) return self.restore_standard_wallet(storage)
# Multisig?
if kind == 'multisig': if kind == 'multisig':
return self.restore_multisig_wallet(storage, wallet_type) return self.restore_multisig_wallet(storage, wallet_type)