instantiate wizard only if needed
This commit is contained in:
parent
0219687d41
commit
632905dfbe
|
@ -143,6 +143,9 @@ class ElectrumGui:
|
||||||
run_hook('on_new_window', w)
|
run_hook('on_new_window', w)
|
||||||
return w
|
return w
|
||||||
|
|
||||||
|
def get_wizard(self):
|
||||||
|
return InstallWizard(self.config, self.app, self.plugins)
|
||||||
|
|
||||||
def start_new_window(self, path, uri):
|
def start_new_window(self, path, uri):
|
||||||
'''Raises the window for the wallet if it is open. Otherwise
|
'''Raises the window for the wallet if it is open. Otherwise
|
||||||
opens the wallet and creates a new window for it.'''
|
opens the wallet and creates a new window for it.'''
|
||||||
|
@ -151,8 +154,7 @@ class ElectrumGui:
|
||||||
w.bring_to_top()
|
w.bring_to_top()
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
wizard = InstallWizard(self.config, self.app, self.plugins)
|
wallet = self.daemon.load_wallet(path, self.get_wizard)
|
||||||
wallet = self.daemon.load_wallet(path, wizard)
|
|
||||||
if not wallet:
|
if not wallet:
|
||||||
return
|
return
|
||||||
w = self.create_window_for_wallet(wallet)
|
w = self.create_window_for_wallet(wallet)
|
||||||
|
|
|
@ -120,12 +120,12 @@ class Daemon(DaemonThread):
|
||||||
response = "Error: Electrum is running in daemon mode. Please stop the daemon first."
|
response = "Error: Electrum is running in daemon mode. Please stop the daemon first."
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def load_wallet(self, path, wizard=None):
|
def load_wallet(self, path, get_wizard):
|
||||||
if path in self.wallets:
|
if path in self.wallets:
|
||||||
wallet = self.wallets[path]
|
wallet = self.wallets[path]
|
||||||
else:
|
else:
|
||||||
if wizard:
|
if get_wizard:
|
||||||
wallet = wizard.open_wallet(self.network, path)
|
wallet = self.open_wallet_with_wizard(self.network, path, get_wizard)
|
||||||
else:
|
else:
|
||||||
storage = WalletStorage(path)
|
storage = WalletStorage(path)
|
||||||
wallet = Wallet(storage)
|
wallet = Wallet(storage)
|
||||||
|
@ -134,6 +134,57 @@ class Daemon(DaemonThread):
|
||||||
self.wallets[path] = wallet
|
self.wallets[path] = wallet
|
||||||
return wallet
|
return wallet
|
||||||
|
|
||||||
|
def open_wallet_with_wizard(self, network, filename, get_wizard):
|
||||||
|
'''Instantiate wizard only if needed'''
|
||||||
|
storage = WalletStorage(filename)
|
||||||
|
need_sync = False
|
||||||
|
is_restore = False
|
||||||
|
self.wizard = None
|
||||||
|
|
||||||
|
def wizard():
|
||||||
|
if self.wizard is None:
|
||||||
|
self.wizard = get_wizard()
|
||||||
|
return self.wizard
|
||||||
|
|
||||||
|
if storage.file_exists:
|
||||||
|
wallet = Wallet(storage)
|
||||||
|
#self.update_wallet_format(wallet)
|
||||||
|
else:
|
||||||
|
cr, wallet = wizard().create_or_restore(storage)
|
||||||
|
if not wallet:
|
||||||
|
return
|
||||||
|
need_sync = True
|
||||||
|
is_restore = (cr == 'restore')
|
||||||
|
|
||||||
|
while True:
|
||||||
|
action = wallet.get_action()
|
||||||
|
if not action:
|
||||||
|
break
|
||||||
|
need_sync = True
|
||||||
|
wizard().run_wallet_action(wallet, action)
|
||||||
|
# Save the wallet after each action
|
||||||
|
wallet.storage.write()
|
||||||
|
|
||||||
|
if network:
|
||||||
|
# Show network dialog if config does not exist
|
||||||
|
if self.config.get('server') is None:
|
||||||
|
wizard().choose_server(network)
|
||||||
|
else:
|
||||||
|
wizard().show_warning(_('You are offline'))
|
||||||
|
|
||||||
|
if need_sync:
|
||||||
|
wizard().create_addresses(wallet)
|
||||||
|
|
||||||
|
# start wallet threads
|
||||||
|
if network:
|
||||||
|
wallet.start_threads(network)
|
||||||
|
|
||||||
|
if is_restore:
|
||||||
|
wizard().show_restore(wallet, network)
|
||||||
|
|
||||||
|
return wallet
|
||||||
|
|
||||||
|
|
||||||
def run_cmdline(self, config_options):
|
def run_cmdline(self, config_options):
|
||||||
config = SimpleConfig(config_options)
|
config = SimpleConfig(config_options)
|
||||||
cmdname = config.get('cmd')
|
cmdname = config.get('cmd')
|
||||||
|
|
|
@ -119,51 +119,6 @@ class WizardBase(PrintError):
|
||||||
"""Show restore result"""
|
"""Show restore result"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def open_wallet(self, network, filename):
|
|
||||||
'''The main entry point of the wizard. Open a wallet from the given
|
|
||||||
filename. If the file doesn't exist launch the GUI-specific
|
|
||||||
install wizard proper.'''
|
|
||||||
storage = WalletStorage(filename)
|
|
||||||
need_sync = False
|
|
||||||
is_restore = False
|
|
||||||
|
|
||||||
if storage.file_exists:
|
|
||||||
wallet = Wallet(storage)
|
|
||||||
self.update_wallet_format(wallet)
|
|
||||||
else:
|
|
||||||
cr, wallet = self.create_or_restore(storage)
|
|
||||||
if not wallet:
|
|
||||||
return
|
|
||||||
need_sync = True
|
|
||||||
is_restore = (cr == 'restore')
|
|
||||||
|
|
||||||
while True:
|
|
||||||
action = wallet.get_action()
|
|
||||||
if not action:
|
|
||||||
break
|
|
||||||
need_sync = True
|
|
||||||
self.run_wallet_action(wallet, action)
|
|
||||||
# Save the wallet after each action
|
|
||||||
wallet.storage.write()
|
|
||||||
|
|
||||||
if network:
|
|
||||||
# Show network dialog if config does not exist
|
|
||||||
if self.config.get('server') is None:
|
|
||||||
self.choose_server(network)
|
|
||||||
else:
|
|
||||||
self.show_warning(_('You are offline'))
|
|
||||||
|
|
||||||
if need_sync:
|
|
||||||
self.create_addresses(wallet)
|
|
||||||
|
|
||||||
# start wallet threads
|
|
||||||
if network:
|
|
||||||
wallet.start_threads(network)
|
|
||||||
|
|
||||||
if is_restore:
|
|
||||||
self.show_restore(wallet, network)
|
|
||||||
|
|
||||||
return wallet
|
|
||||||
|
|
||||||
|
|
||||||
def run_wallet_action(self, wallet, action):
|
def run_wallet_action(self, wallet, action):
|
||||||
|
|
Loading…
Reference in New Issue