commit 12f62212ba5139f115aca95aee936adae0feb577
parent 1d079602901047f551736002b4189f21e9bbf3d3
Author: Neil Booth <kyuupichan@gmail.com>
Date: Sat, 2 Jan 2016 00:35:09 +0900
Move wallet_kinds to the base class
This logic isn't gui-dependent so belongs in wizard.py
Diffstat:
2 files changed, 22 insertions(+), 20 deletions(-)
diff --git a/gui/qt/installwizard.py b/gui/qt/installwizard.py
@@ -151,9 +151,11 @@ class InstallWizard(WindowModalDialog, MessageBoxMixin, WizardBase):
self.stack.setCurrentWidget(w)
self.show()
- def query_create_or_restore(self):
- """Returns a tuple (action, kind). Action is one of user_actions,
- or None if cancelled. kind is one of wallet_kinds."""
+ def query_create_or_restore(self, wallet_kinds):
+ """Ask the user what they want to do, and to what wallet kind.
+ 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()
main_label = QLabel(_("Electrum could not find an existing wallet."))
@@ -188,14 +190,7 @@ class InstallWizard(WindowModalDialog, MessageBoxMixin, WizardBase):
group2 = QButtonGroup()
- wallet_types = [
- ('standard', _("Standard wallet")),
- ('twofactor', _("Wallet with two-factor authentication")),
- ('multisig', _("Multi-signature wallet")),
- ('hardware', _("Hardware wallet")),
- ]
-
- for i, (wtype,name) in enumerate(wallet_types):
+ for i, (wtype,name) in enumerate(wallet_kinds):
if not filter(lambda x:x[0]==wtype, electrum.wallet.wallet_types):
continue
button = QRadioButton(gb2)
@@ -217,7 +212,7 @@ class InstallWizard(WindowModalDialog, MessageBoxMixin, WizardBase):
raise UserCancelled
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
def verify_seed(self, seed, is_valid=None):
diff --git a/lib/wizard.py b/lib/wizard.py
@@ -42,7 +42,13 @@ class UserCancelled(Exception):
class WizardBase(PrintError):
'''Base class for gui-specific install wizards.'''
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:
# self.language_for_seed
@@ -58,9 +64,11 @@ class WizardBase(PrintError):
"""Remove filename from the recently used list."""
raise NotImplementedError
- def query_create_or_restore(self):
- """Returns a tuple (action, kind). Action is one of user_actions,
- kind is one of wallet_kinds."""
+ def query_create_or_restore(self, wallet_kinds):
+ """Ask the user what they want to do, and to what wallet kind.
+ 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
def query_multisig(self, action):
@@ -189,10 +197,10 @@ class WizardBase(PrintError):
a wallet and return it.'''
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 kind in self.wallet_kinds
+ assert action in WizardBase.user_actions
+ assert kind in [k for k, desc in WizardBase.wallet_kinds]
if kind == 'multisig':
wallet_type = self.query_multisig(action)
@@ -225,7 +233,6 @@ class WizardBase(PrintError):
if wallet_type == 'standard':
return self.restore_standard_wallet(storage)
- # Multisig?
if kind == 'multisig':
return self.restore_multisig_wallet(storage, wallet_type)