better handle exceptions in wizard re "cannot connect to trustedcoin server"
This commit is contained in:
@@ -485,7 +485,7 @@ class ElectrumWindow(App):
|
|||||||
else:
|
else:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
def on_wizard_complete(self, instance, wallet):
|
def on_wizard_complete(self, wizard, wallet):
|
||||||
if wallet: # wizard returned a wallet
|
if wallet: # wizard returned a wallet
|
||||||
wallet.start_threads(self.daemon.network)
|
wallet.start_threads(self.daemon.network)
|
||||||
self.daemon.add_wallet(wallet)
|
self.daemon.add_wallet(wallet)
|
||||||
@@ -493,9 +493,9 @@ class ElectrumWindow(App):
|
|||||||
elif not self.wallet:
|
elif not self.wallet:
|
||||||
# wizard did not return a wallet; and there is no wallet open atm
|
# wizard did not return a wallet; and there is no wallet open atm
|
||||||
# try to open last saved wallet (potentially start wizard again)
|
# 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:
|
if not path:
|
||||||
return
|
return
|
||||||
if self.wallet and self.wallet.storage.path == path:
|
if self.wallet and self.wallet.storage.path == path:
|
||||||
@@ -508,11 +508,27 @@ class ElectrumWindow(App):
|
|||||||
self.load_wallet(wallet)
|
self.load_wallet(wallet)
|
||||||
else:
|
else:
|
||||||
Logger.debug('Electrum: Wallet not found or action needed. Launching install wizard')
|
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)
|
def launch_wizard():
|
||||||
wizard.bind(on_wizard_complete=self.on_wizard_complete)
|
storage = WalletStorage(path, manual_upgrades=True)
|
||||||
action = wizard.storage.get_action()
|
wizard = Factory.InstallWizard(self.electrum_config, self.plugins, storage)
|
||||||
wizard.run(action)
|
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):
|
def on_stop(self):
|
||||||
Logger.info('on_stop')
|
Logger.info('on_stop')
|
||||||
|
|||||||
@@ -189,6 +189,7 @@ Builder.load_string('''
|
|||||||
|
|
||||||
<WizardTOSDialog>
|
<WizardTOSDialog>
|
||||||
message : ''
|
message : ''
|
||||||
|
size_hint: 1, 1
|
||||||
ScrollView:
|
ScrollView:
|
||||||
size_hint: 1, 1
|
size_hint: 1, 1
|
||||||
Label:
|
Label:
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ from kivy.clock import Clock
|
|||||||
|
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
from electrum.plugins import hook
|
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
|
if e.status_code == 400: # invalid OTP
|
||||||
Clock.schedule_once(lambda dt: on_failure(_('Invalid one-time password.')))
|
Clock.schedule_once(lambda dt: on_failure(_('Invalid one-time password.')))
|
||||||
else:
|
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:
|
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:
|
else:
|
||||||
on_success(tx)
|
on_success(tx)
|
||||||
|
|
||||||
def accept_terms_of_use(self, wizard):
|
def accept_terms_of_use(self, wizard):
|
||||||
tos = server.get_terms_of_service()
|
def handle_error(msg, e):
|
||||||
f = lambda x: self.read_email(wizard)
|
wizard.show_error(msg + ':\n' + str(e))
|
||||||
wizard.tos_dialog(tos=tos, run_next = f)
|
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):
|
def read_email(self, wizard):
|
||||||
f = lambda x: self.create_remote_key(x, 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):
|
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)
|
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)
|
||||||
|
|||||||
@@ -539,8 +539,9 @@ class TrustedCoinPlugin(BasePlugin):
|
|||||||
# secret must be sent by the server
|
# secret must be sent by the server
|
||||||
try:
|
try:
|
||||||
r = server.create(xpub1, xpub2, email)
|
r = server.create(xpub1, xpub2, email)
|
||||||
except socket.error:
|
except (socket.error, ErrorConnectingServer):
|
||||||
wizard.show_message('Server not reachable, aborting')
|
wizard.show_message('Server not reachable, aborting')
|
||||||
|
wizard.terminate()
|
||||||
return
|
return
|
||||||
except TrustedCoinException as e:
|
except TrustedCoinException as e:
|
||||||
if e.status_code == 409:
|
if e.status_code == 409:
|
||||||
|
|||||||
Reference in New Issue
Block a user