Browse Source

wizard: make 'stack' private

sqlite_db
SomberNight 6 years ago
parent
commit
9013f6d59e
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 15
      electrum/base_wizard.py
  2. 2
      electrum/gui/qt/installwizard.py
  3. 5
      electrum/plugins/trustedcoin/qt.py
  4. 9
      electrum/plugins/trustedcoin/trustedcoin.py

15
electrum/base_wizard.py

@ -64,7 +64,7 @@ class BaseWizard(object):
self.plugins = plugins self.plugins = plugins
self.storage = storage self.storage = storage
self.wallet = None # type: Abstract_Wallet self.wallet = None # type: Abstract_Wallet
self.stack = [] self._stack = []
self.plugin = None self.plugin = None
self.keystores = [] self.keystores = []
self.is_kivy = config.get('gui') == 'kivy' self.is_kivy = config.get('gui') == 'kivy'
@ -76,7 +76,7 @@ class BaseWizard(object):
def run(self, *args): def run(self, *args):
action = args[0] action = args[0]
args = args[1:] args = args[1:]
self.stack.append((action, args)) self._stack.append((action, args))
if not action: if not action:
return return
if type(action) is tuple: if type(action) is tuple:
@ -91,15 +91,18 @@ class BaseWizard(object):
raise Exception("unknown action", action) raise Exception("unknown action", action)
def can_go_back(self): def can_go_back(self):
return len(self.stack)>1 return len(self._stack) > 1
def go_back(self): def go_back(self):
if not self.can_go_back(): if not self.can_go_back():
return return
self.stack.pop() self._stack.pop()
action, args = self.stack.pop() action, args = self._stack.pop()
self.run(action, *args) self.run(action, *args)
def reset_stack(self):
self._stack = []
def new(self): def new(self):
name = os.path.basename(self.storage.path) name = os.path.basename(self.storage.path)
title = _("Create") + ' ' + name title = _("Create") + ' ' + name
@ -476,7 +479,7 @@ class BaseWizard(object):
self.keystores.append(k) self.keystores.append(k)
if len(self.keystores) == 1: if len(self.keystores) == 1:
xpub = k.get_master_public_key() xpub = k.get_master_public_key()
self.stack = [] self.reset_stack()
self.run('show_xpub_and_add_cosigners', xpub) self.run('show_xpub_and_add_cosigners', xpub)
elif len(self.keystores) < self.n: elif len(self.keystores) < self.n:
self.run('choose_keystore') self.run('choose_keystore')

2
electrum/gui/qt/installwizard.py

@ -272,7 +272,7 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard):
None, _('Error'), None, _('Error'),
_('Failed to decrypt using this hardware device.') + '\n' + _('Failed to decrypt using this hardware device.') + '\n' +
_('If you use a passphrase, make sure it is correct.')) _('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) return self.run_and_get_wallet(get_wallet_from_daemon)
except BaseException as e: except BaseException as e:
traceback.print_exc(file=sys.stdout) traceback.print_exc(file=sys.stdout)

5
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.qrcodewidget import QRCodeWidget
from electrum.gui.qt.amountedit import AmountEdit from electrum.gui.qt.amountedit import AmountEdit
from electrum.gui.qt.main_window import StatusBarButton from electrum.gui.qt.main_window import StatusBarButton
from electrum.gui.qt.installwizard import InstallWizard
from electrum.i18n import _ from electrum.i18n import _
from electrum.plugin import hook from electrum.plugin import hook
from electrum.util import PrintError, is_valid_email from electrum.util import PrintError, is_valid_email
@ -195,7 +196,7 @@ class Plugin(TrustedCoinPlugin):
vbox.addLayout(Buttons(CloseButton(d))) vbox.addLayout(Buttons(CloseButton(d)))
d.exec_() d.exec_()
def go_online_dialog(self, wizard): def go_online_dialog(self, wizard: InstallWizard):
msg = [ msg = [
_("Your wallet file is: {}.").format(os.path.abspath(wizard.storage.path)), _("Your wallet file is: {}.").format(os.path.abspath(wizard.storage.path)),
_("You need to be online in order to complete the creation of " _("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')) _('If you are online, click on "{}" to continue.').format(_('Next'))
] ]
msg = '\n\n'.join(msg) 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')) wizard.confirm_dialog(title='', message=msg, run_next = lambda x: wizard.run('accept_terms_of_use'))
def accept_terms_of_use(self, window): def accept_terms_of_use(self, window):

9
electrum/plugins/trustedcoin/trustedcoin.py

@ -48,6 +48,7 @@ from electrum.plugin import BasePlugin, hook
from electrum.util import NotEnoughFunds, UserFacingException from electrum.util import NotEnoughFunds, UserFacingException
from electrum.storage import STO_EV_USER_PW from electrum.storage import STO_EV_USER_PW
from electrum.network import Network from electrum.network import Network
from electrum.base_wizard import BaseWizard
def get_signing_xpub(xtype): def get_signing_xpub(xtype):
if not constants.net.TESTNET: if not constants.net.TESTNET:
@ -491,9 +492,9 @@ class TrustedCoinPlugin(BasePlugin):
def do_clear(self, window): def do_clear(self, window):
window.wallet.is_billing = False window.wallet.is_billing = False
def show_disclaimer(self, wizard): def show_disclaimer(self, wizard: BaseWizard):
wizard.set_icon('trustedcoin-wizard.png') 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')) 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): def choose_seed(self, wizard):
@ -580,9 +581,9 @@ class TrustedCoinPlugin(BasePlugin):
f = lambda x: self.restore_choice(wizard, seed, x) f = lambda x: self.restore_choice(wizard, seed, x)
wizard.passphrase_dialog(run_next=f) if is_ext else f('') 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.set_icon('trustedcoin-wizard.png')
wizard.stack = [] wizard.reset_stack()
title = _('Restore 2FA wallet') title = _('Restore 2FA wallet')
msg = ' '.join([ msg = ' '.join([
'You are going to restore a wallet protected with two-factor authentication.', 'You are going to restore a wallet protected with two-factor authentication.',

Loading…
Cancel
Save