From 9013f6d59e4134b623688bd030d2e894c054e4bf Mon Sep 17 00:00:00 2001 From: SomberNight Date: Mon, 4 Feb 2019 16:51:19 +0100 Subject: [PATCH] wizard: make 'stack' private --- electrum/base_wizard.py | 15 +++++++++------ electrum/gui/qt/installwizard.py | 2 +- electrum/plugins/trustedcoin/qt.py | 5 +++-- electrum/plugins/trustedcoin/trustedcoin.py | 9 +++++---- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/electrum/base_wizard.py b/electrum/base_wizard.py index a5050d149..97ae29e28 100644 --- a/electrum/base_wizard.py +++ b/electrum/base_wizard.py @@ -64,7 +64,7 @@ class BaseWizard(object): self.plugins = plugins self.storage = storage self.wallet = None # type: Abstract_Wallet - self.stack = [] + self._stack = [] self.plugin = None self.keystores = [] self.is_kivy = config.get('gui') == 'kivy' @@ -76,7 +76,7 @@ class BaseWizard(object): def run(self, *args): action = args[0] args = args[1:] - self.stack.append((action, args)) + self._stack.append((action, args)) if not action: return if type(action) is tuple: @@ -91,15 +91,18 @@ class BaseWizard(object): raise Exception("unknown action", action) def can_go_back(self): - return len(self.stack)>1 + return len(self._stack) > 1 def go_back(self): if not self.can_go_back(): return - self.stack.pop() - action, args = self.stack.pop() + self._stack.pop() + action, args = self._stack.pop() self.run(action, *args) + def reset_stack(self): + self._stack = [] + def new(self): name = os.path.basename(self.storage.path) title = _("Create") + ' ' + name @@ -476,7 +479,7 @@ class BaseWizard(object): self.keystores.append(k) if len(self.keystores) == 1: xpub = k.get_master_public_key() - self.stack = [] + self.reset_stack() self.run('show_xpub_and_add_cosigners', xpub) elif len(self.keystores) < self.n: self.run('choose_keystore') diff --git a/electrum/gui/qt/installwizard.py b/electrum/gui/qt/installwizard.py index 102721a86..51b200255 100644 --- a/electrum/gui/qt/installwizard.py +++ b/electrum/gui/qt/installwizard.py @@ -272,7 +272,7 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard): None, _('Error'), _('Failed to decrypt using this hardware device.') + '\n' + _('If you use a passphrase, make sure it is correct.')) - self.stack = [] + self.reset_stack() return self.run_and_get_wallet(get_wallet_from_daemon) except BaseException as e: traceback.print_exc(file=sys.stdout) diff --git a/electrum/plugins/trustedcoin/qt.py b/electrum/plugins/trustedcoin/qt.py index 71db486ad..34446fe25 100644 --- a/electrum/plugins/trustedcoin/qt.py +++ b/electrum/plugins/trustedcoin/qt.py @@ -36,6 +36,7 @@ from electrum.gui.qt.util import * from electrum.gui.qt.qrcodewidget import QRCodeWidget from electrum.gui.qt.amountedit import AmountEdit from electrum.gui.qt.main_window import StatusBarButton +from electrum.gui.qt.installwizard import InstallWizard from electrum.i18n import _ from electrum.plugin import hook from electrum.util import PrintError, is_valid_email @@ -195,7 +196,7 @@ class Plugin(TrustedCoinPlugin): vbox.addLayout(Buttons(CloseButton(d))) d.exec_() - def go_online_dialog(self, wizard): + def go_online_dialog(self, wizard: InstallWizard): msg = [ _("Your wallet file is: {}.").format(os.path.abspath(wizard.storage.path)), _("You need to be online in order to complete the creation of " @@ -206,7 +207,7 @@ class Plugin(TrustedCoinPlugin): _('If you are online, click on "{}" to continue.').format(_('Next')) ] msg = '\n\n'.join(msg) - wizard.stack = [] + wizard.reset_stack() wizard.confirm_dialog(title='', message=msg, run_next = lambda x: wizard.run('accept_terms_of_use')) def accept_terms_of_use(self, window): diff --git a/electrum/plugins/trustedcoin/trustedcoin.py b/electrum/plugins/trustedcoin/trustedcoin.py index f8484d299..d4d293a84 100644 --- a/electrum/plugins/trustedcoin/trustedcoin.py +++ b/electrum/plugins/trustedcoin/trustedcoin.py @@ -48,6 +48,7 @@ from electrum.plugin import BasePlugin, hook from electrum.util import NotEnoughFunds, UserFacingException from electrum.storage import STO_EV_USER_PW from electrum.network import Network +from electrum.base_wizard import BaseWizard def get_signing_xpub(xtype): if not constants.net.TESTNET: @@ -491,9 +492,9 @@ class TrustedCoinPlugin(BasePlugin): def do_clear(self, window): window.wallet.is_billing = False - def show_disclaimer(self, wizard): + def show_disclaimer(self, wizard: BaseWizard): wizard.set_icon('trustedcoin-wizard.png') - wizard.stack = [] + wizard.reset_stack() wizard.confirm_dialog(title='Disclaimer', message='\n\n'.join(self.disclaimer_msg), run_next = lambda x: wizard.run('choose_seed')) def choose_seed(self, wizard): @@ -580,9 +581,9 @@ class TrustedCoinPlugin(BasePlugin): f = lambda x: self.restore_choice(wizard, seed, x) wizard.passphrase_dialog(run_next=f) if is_ext else f('') - def restore_choice(self, wizard, seed, passphrase): + def restore_choice(self, wizard: BaseWizard, seed, passphrase): wizard.set_icon('trustedcoin-wizard.png') - wizard.stack = [] + wizard.reset_stack() title = _('Restore 2FA wallet') msg = ' '.join([ 'You are going to restore a wallet protected with two-factor authentication.',