electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit cf809520718ac53d94dec06dea6a44eefd425390
parent 4fea9edd11f66536c5f6c56f8b0fabaaa18ca612
Author: SomberNight <somber.night@protonmail.com>
Date:   Fri,  8 Jun 2018 16:55:27 +0200

better handle exceptions in wizard re "cannot connect to trustedcoin server"

Diffstat:
Mgui/kivy/main_window.py | 32++++++++++++++++++++++++--------
Mgui/kivy/uix/dialogs/installwizard.py | 1+
Mplugins/trustedcoin/kivy.py | 25+++++++++++++++++--------
Mplugins/trustedcoin/trustedcoin.py | 3++-
4 files changed, 44 insertions(+), 17 deletions(-)

diff --git a/gui/kivy/main_window.py b/gui/kivy/main_window.py @@ -485,7 +485,7 @@ class ElectrumWindow(App): else: return '' - def on_wizard_complete(self, instance, wallet): + def on_wizard_complete(self, wizard, wallet): if wallet: # wizard returned a wallet wallet.start_threads(self.daemon.network) self.daemon.add_wallet(wallet) @@ -493,9 +493,9 @@ class ElectrumWindow(App): elif not self.wallet: # wizard did not return a wallet; and there is no wallet open atm # try to open last saved wallet (potentially start wizard again) - self.load_wallet_by_name(self.electrum_config.get_wallet_path()) + self.load_wallet_by_name(self.electrum_config.get_wallet_path(), ask_if_wizard=True) - def load_wallet_by_name(self, path): + def load_wallet_by_name(self, path, ask_if_wizard=False): if not path: return if self.wallet and self.wallet.storage.path == path: @@ -508,11 +508,27 @@ class ElectrumWindow(App): self.load_wallet(wallet) else: Logger.debug('Electrum: Wallet not found or action needed. Launching install wizard') - storage = WalletStorage(path, manual_upgrades=True) - wizard = Factory.InstallWizard(self.electrum_config, self.plugins, storage) - wizard.bind(on_wizard_complete=self.on_wizard_complete) - action = wizard.storage.get_action() - wizard.run(action) + + def launch_wizard(): + storage = WalletStorage(path, manual_upgrades=True) + wizard = Factory.InstallWizard(self.electrum_config, self.plugins, storage) + wizard.bind(on_wizard_complete=self.on_wizard_complete) + action = wizard.storage.get_action() + wizard.run(action) + if not ask_if_wizard: + launch_wizard() + else: + from .uix.dialogs.question import Question + + def handle_answer(b: bool): + if b: + launch_wizard() + else: + try: os.unlink(path) + except FileNotFoundError: pass + self.stop() + d = Question(_('Do you want to launch the wizard again?'), handle_answer) + d.open() def on_stop(self): Logger.info('on_stop') diff --git a/gui/kivy/uix/dialogs/installwizard.py b/gui/kivy/uix/dialogs/installwizard.py @@ -189,6 +189,7 @@ Builder.load_string(''' <WizardTOSDialog> message : '' + size_hint: 1, 1 ScrollView: size_hint: 1, 1 Label: diff --git a/plugins/trustedcoin/kivy.py b/plugins/trustedcoin/kivy.py @@ -32,7 +32,7 @@ from kivy.clock import Clock from electrum.i18n import _ from electrum.plugins import hook -from .trustedcoin import TrustedCoinPlugin, server, KIVY_DISCLAIMER, TrustedCoinException +from .trustedcoin import TrustedCoinPlugin, server, KIVY_DISCLAIMER, TrustedCoinException, ErrorConnectingServer @@ -66,21 +66,30 @@ class Plugin(TrustedCoinPlugin): if e.status_code == 400: # invalid OTP Clock.schedule_once(lambda dt: on_failure(_('Invalid one-time password.'))) else: - Clock.schedule_once(lambda dt, bound_e=e: on_failure(_('Error') + ':' + str(bound_e))) + Clock.schedule_once(lambda dt, bound_e=e: on_failure(_('Error') + ':\n' + str(bound_e))) except Exception as e: - Clock.schedule_once(lambda dt, bound_e=e: on_failure(_('Error') + ':' + str(bound_e))) + Clock.schedule_once(lambda dt, bound_e=e: on_failure(_('Error') + ':\n' + str(bound_e))) else: on_success(tx) def accept_terms_of_use(self, wizard): - tos = server.get_terms_of_service() - f = lambda x: self.read_email(wizard) - wizard.tos_dialog(tos=tos, run_next = f) + def handle_error(msg, e): + wizard.show_error(msg + ':\n' + str(e)) + wizard.terminate() + try: + tos = server.get_terms_of_service() + except ErrorConnectingServer as e: + Clock.schedule_once(lambda dt, bound_e=e: handle_error(_('Error connecting to server'), bound_e)) + except Exception as e: + Clock.schedule_once(lambda dt, bound_e=e: handle_error(_('Error'), bound_e)) + else: + f = lambda x: self.read_email(wizard) + wizard.tos_dialog(tos=tos, run_next=f) def read_email(self, wizard): f = lambda x: self.create_remote_key(x, wizard) - wizard.email_dialog(run_next = f) + wizard.email_dialog(run_next=f) def request_otp_dialog(self, wizard, short_id, otp_secret, xpub3): f = lambda otp, reset: self.check_otp(wizard, short_id, otp_secret, xpub3, otp, reset) - wizard.otp_dialog(otp_secret=otp_secret, run_next = f) + wizard.otp_dialog(otp_secret=otp_secret, run_next=f) diff --git a/plugins/trustedcoin/trustedcoin.py b/plugins/trustedcoin/trustedcoin.py @@ -539,8 +539,9 @@ class TrustedCoinPlugin(BasePlugin): # secret must be sent by the server try: r = server.create(xpub1, xpub2, email) - except socket.error: + except (socket.error, ErrorConnectingServer): wizard.show_message('Server not reachable, aborting') + wizard.terminate() return except TrustedCoinException as e: if e.status_code == 409: