test if wizard is needed in daemon

This commit is contained in:
ThomasV 2016-01-13 14:30:09 +01:00
parent 6178f5a28f
commit 2f6e2ebcd2
2 changed files with 18 additions and 24 deletions

View File

@ -125,11 +125,17 @@ class Daemon(DaemonThread):
if path in self.wallets: if path in self.wallets:
wallet = self.wallets[path] wallet = self.wallets[path]
else: else:
storage = WalletStorage(path)
if get_wizard: if get_wizard:
wallet = WizardBase.open_wallet(self.network, path, if storage.file_exists:
self.config, get_wizard) wallet = Wallet(storage)
action = wallet.get_action()
else:
action = 'new'
if action:
wizard = get_wizard()
wallet = wizard.run(self.network, storage)
else: else:
storage = WalletStorage(path)
wallet = Wallet(storage) wallet = Wallet(storage)
wallet.start_threads(self.network) wallet.start_threads(self.network)
if wallet: if wallet:

View File

@ -123,27 +123,19 @@ class WizardBase(PrintError):
"""Called when the wizard is done.""" """Called when the wizard is done."""
pass pass
@classmethod def run(self, network, storage):
def open_wallet(self, network, filename, config, create_wizard):
'''The main entry point of the wizard. Open a wallet from the given '''The main entry point of the wizard. Open a wallet from the given
filename. If the file doesn't exist launch the GUI-specific filename. If the file doesn't exist launch the GUI-specific
install wizard proper, created by calling create_wizard().''' install wizard proper, created by calling create_wizard().'''
storage = WalletStorage(filename)
need_sync = False need_sync = False
is_restore = False is_restore = False
self.my_wizard = None
def wizard():
if self.my_wizard is None:
self.my_wizard = create_wizard()
return self.my_wizard
if storage.file_exists: if storage.file_exists:
wallet = Wallet(storage) wallet = Wallet(storage)
if wallet.imported_keys: if wallet.imported_keys:
wizard().update_wallet_format(wallet) self.update_wallet_format(wallet)
else: else:
cr, wallet = wizard().create_or_restore(storage) cr, wallet = self.create_or_restore(storage)
if not wallet: if not wallet:
return return
need_sync = True need_sync = True
@ -154,30 +146,26 @@ class WizardBase(PrintError):
if not action: if not action:
break break
need_sync = True need_sync = True
wizard().run_wallet_action(wallet, action) self.run_wallet_action(wallet, action)
# Save the wallet after each action # Save the wallet after each action
wallet.storage.write() wallet.storage.write()
if network: if network:
# Show network dialog if config does not exist # Show network dialog if config does not exist
if config.get('auto_connect') is None: if self.config.get('auto_connect') is None:
wizard().choose_server(network) self.choose_server(network)
else: else:
wizard().show_warning(_('You are offline')) self.show_warning(_('You are offline'))
if need_sync: if need_sync:
wizard().create_addresses(wallet) self.create_addresses(wallet)
# start wallet threads # start wallet threads
if network: if network:
wallet.start_threads(network) wallet.start_threads(network)
if is_restore: if is_restore:
wizard().show_restore(wallet, network) self.show_restore(wallet, network)
if self.my_wizard:
self.my_wizard.finished()
self.my_wizard = None
return wallet return wallet