trezor: more user friendly when cannot connect
Tell the user and ask if they want to try again. If they say no, raise a silent exception. Apply this more friendly behaviour to the install wizard too (see issue #1668).
This commit is contained in:
@@ -26,7 +26,7 @@ import time
|
||||
|
||||
from util import *
|
||||
from i18n import _
|
||||
from util import profiler, PrintError, DaemonThread
|
||||
from util import profiler, PrintError, DaemonThread, UserCancelled
|
||||
import wallet
|
||||
|
||||
class Plugins(DaemonThread):
|
||||
@@ -386,26 +386,20 @@ class DeviceMgr(PrintError):
|
||||
# The wallet has not been previously paired, so let the user
|
||||
# choose an unpaired device and compare its first address.
|
||||
info = self.select_device(wallet, plugin, devices)
|
||||
if info:
|
||||
client = self.client_lookup(info.device.id_)
|
||||
if client and client.is_pairable():
|
||||
# See comment above for same code
|
||||
client.handler = wallet.handler
|
||||
# This will trigger a PIN/passphrase entry request
|
||||
client_first_address = client.first_address(derivation)
|
||||
if client_first_address == first_address:
|
||||
self.pair_wallet(wallet, info.device.id_)
|
||||
return client
|
||||
|
||||
if info and client:
|
||||
# The user input has wrong PIN or passphrase
|
||||
raise DeviceUnpairableError(
|
||||
_('Unable to pair with your %s.') % plugin.device)
|
||||
client = self.client_lookup(info.device.id_)
|
||||
if client and client.is_pairable():
|
||||
# See comment above for same code
|
||||
client.handler = wallet.handler
|
||||
# This will trigger a PIN/passphrase entry request
|
||||
client_first_address = client.first_address(derivation)
|
||||
if client_first_address == first_address:
|
||||
self.pair_wallet(wallet, info.device.id_)
|
||||
return client
|
||||
|
||||
raise DeviceNotFoundError(
|
||||
_('Could not connect to your %s. Verify the cable is '
|
||||
'connected and that no other application is using it.')
|
||||
% plugin.device)
|
||||
# The user input has wrong PIN or passphrase, or it is not pairable
|
||||
raise DeviceUnpairableError(
|
||||
_('Unable to pair with your %s.') % plugin.device)
|
||||
|
||||
def unpaired_device_infos(self, handler, plugin, devices=None):
|
||||
'''Returns a list of DeviceInfo objects: one for each connected,
|
||||
@@ -432,9 +426,17 @@ class DeviceMgr(PrintError):
|
||||
def select_device(self, wallet, plugin, devices=None):
|
||||
'''Ask the user to select a device to use if there is more than one,
|
||||
and return the DeviceInfo for the device.'''
|
||||
infos = self.unpaired_device_infos(wallet.handler, plugin, devices)
|
||||
if not infos:
|
||||
return None
|
||||
while True:
|
||||
infos = self.unpaired_device_infos(wallet.handler, plugin, devices)
|
||||
if infos:
|
||||
break
|
||||
msg = _('Could not connect to your %s. Verify the cable is '
|
||||
'connected and that no other application is using it.\n\n'
|
||||
'Try to connect again?') % plugin.device
|
||||
if not wallet.handler.yes_no_question(msg):
|
||||
raise UserCancelled()
|
||||
devices = None
|
||||
|
||||
if len(infos) == 1:
|
||||
return infos[0]
|
||||
msg = _("Please select which %s device to use:") % plugin.device
|
||||
|
||||
@@ -21,8 +21,10 @@ class InvalidPassword(Exception):
|
||||
def __str__(self):
|
||||
return _("Incorrect password")
|
||||
|
||||
class SilentException(Exception):
|
||||
'''An exception that should probably be suppressed from the user'''
|
||||
# Throw this exception to unwind the stack like when an error occurs.
|
||||
# However unlike other exceptions the user won't be informed.
|
||||
class UserCancelled(Exception):
|
||||
'''An exception that is suppressed from the user'''
|
||||
pass
|
||||
|
||||
class MyEncoder(json.JSONEncoder):
|
||||
|
||||
@@ -36,9 +36,6 @@ MSG_RESTORE_PASSPHRASE = \
|
||||
"Note this is NOT a password. Enter nothing if you did not use "
|
||||
"one or are unsure.")
|
||||
|
||||
class UserCancelled(Exception):
|
||||
pass
|
||||
|
||||
class WizardBase(PrintError):
|
||||
'''Base class for gui-specific install wizards.'''
|
||||
user_actions = ('create', 'restore')
|
||||
|
||||
Reference in New Issue
Block a user