Trezor: better messages during initialization
This commit is contained in:
@@ -61,7 +61,7 @@ class GuiMixin(object):
|
|||||||
def callback_WordRequest(self, msg):
|
def callback_WordRequest(self, msg):
|
||||||
self.step += 1
|
self.step += 1
|
||||||
msg = _("Step %d/24. Enter seed word as explained on "
|
msg = _("Step %d/24. Enter seed word as explained on "
|
||||||
"your %s") % (self.step, self.device)
|
"your %s:") % (self.step, self.device)
|
||||||
word = self.handler.get_word(msg)
|
word = self.handler.get_word(msg)
|
||||||
# Unfortunately the device can't handle self.proto.Cancel()
|
# Unfortunately the device can't handle self.proto.Cancel()
|
||||||
return self.proto.WordAck(word=word)
|
return self.proto.WordAck(word=word)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import threading
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from binascii import unhexlify
|
from binascii import unhexlify
|
||||||
|
from functools import partial
|
||||||
from struct import pack
|
from struct import pack
|
||||||
|
|
||||||
from electrum.account import BIP32_Account
|
from electrum.account import BIP32_Account
|
||||||
@@ -14,9 +15,9 @@ from electrum.i18n import _
|
|||||||
from electrum.plugins import BasePlugin, hook
|
from electrum.plugins import BasePlugin, hook
|
||||||
from electrum.transaction import (deserialize, is_extended_pubkey,
|
from electrum.transaction import (deserialize, is_extended_pubkey,
|
||||||
Transaction, x_to_xpub)
|
Transaction, x_to_xpub)
|
||||||
from electrum.wallet import BIP32_HD_Wallet, BIP44_Wallet
|
from electrum.wallet import BIP44_Wallet
|
||||||
from electrum.util import ThreadJob
|
from electrum.util import ThreadJob
|
||||||
from electrum.plugins import DeviceMgr
|
|
||||||
|
|
||||||
# Trezor initialization methods
|
# Trezor initialization methods
|
||||||
TIM_NEW, TIM_RECOVER, TIM_MNEMONIC, TIM_PRIVKEY = range(0, 4)
|
TIM_NEW, TIM_RECOVER, TIM_MNEMONIC, TIM_PRIVKEY = range(0, 4)
|
||||||
@@ -263,13 +264,14 @@ class TrezorCompatiblePlugin(BasePlugin, ThreadJob):
|
|||||||
wallet.last_operation = self.prevent_timeout
|
wallet.last_operation = self.prevent_timeout
|
||||||
|
|
||||||
# Initialization method
|
# Initialization method
|
||||||
msg = _("Please select how you want to initialize your %s.\n"
|
msg = _("Choose how you want to initialize your %s.\n\n"
|
||||||
"The first two are secure as no secret information is entered "
|
"The first two methods are secure as no secret information "
|
||||||
"onto your computer.\nFor the last two methods you enter "
|
"is entered into your computer.\n\n"
|
||||||
"secrets into your computer and upload them to the device, "
|
"For the last two methods you input secrets on your keyboard "
|
||||||
"and so you should do those on a computer you know to be "
|
"and upload them to your %s, and so you should "
|
||||||
"trustworthy and free of malware."
|
"only do those on a computer you know to be trustworthy "
|
||||||
) % self.device
|
"and free of malware."
|
||||||
|
) % (self.device, self.device)
|
||||||
|
|
||||||
methods = [
|
methods = [
|
||||||
# Must be short as QT doesn't word-wrap radio button text
|
# Must be short as QT doesn't word-wrap radio button text
|
||||||
@@ -294,7 +296,7 @@ class TrezorCompatiblePlugin(BasePlugin, ThreadJob):
|
|||||||
|
|
||||||
language = 'english'
|
language = 'english'
|
||||||
|
|
||||||
def initialize_device():
|
def initialize_method():
|
||||||
client = self.get_client(wallet)
|
client = self.get_client(wallet)
|
||||||
|
|
||||||
if method == TIM_NEW:
|
if method == TIM_NEW:
|
||||||
@@ -316,7 +318,17 @@ class TrezorCompatiblePlugin(BasePlugin, ThreadJob):
|
|||||||
client.load_device_by_xprv(item, pin, passphrase_protection,
|
client.load_device_by_xprv(item, pin, passphrase_protection,
|
||||||
label, language)
|
label, language)
|
||||||
|
|
||||||
wallet.thread.add(initialize_device)
|
return initialize_method
|
||||||
|
|
||||||
|
def setup_device(self, wallet, on_done):
|
||||||
|
'''Called when creating a new wallet. Select the device to use. If
|
||||||
|
the device is uninitialized, go through the intialization
|
||||||
|
process. Then create the wallet accounts.'''
|
||||||
|
create_hd_task = partial(wallet.create_hd_account, None)
|
||||||
|
initialized = self.select_device(wallet)
|
||||||
|
if not initialized:
|
||||||
|
wallet.thread.add(self.initialize_device(wallet))
|
||||||
|
wallet.thread.add(create_hd_task, on_done=on_done)
|
||||||
|
|
||||||
def unpaired_devices(self, handler):
|
def unpaired_devices(self, handler):
|
||||||
'''Returns all connected, unpaired devices as a list of clients and a
|
'''Returns all connected, unpaired devices as a list of clients and a
|
||||||
@@ -331,23 +343,19 @@ class TrezorCompatiblePlugin(BasePlugin, ThreadJob):
|
|||||||
if not client:
|
if not client:
|
||||||
continue
|
continue
|
||||||
state = states[client.is_initialized()]
|
state = states[client.is_initialized()]
|
||||||
label = client.label() or _("An unnamed device")
|
label = client.label() or _("An unnamed %s") % self.device
|
||||||
descr = "%s: device ID %s (%s)" % (label, device.id_, state)
|
descr = "%s (%s)" % (label, state)
|
||||||
infos.append((device, descr, client.is_initialized()))
|
infos.append((device, descr, client.is_initialized()))
|
||||||
|
|
||||||
return infos
|
return infos
|
||||||
|
|
||||||
def select_device(self, wallet):
|
def select_device(self, wallet):
|
||||||
'''Called when creating a new wallet. Select the device to use. If
|
|
||||||
the device is uninitialized, go through the intialization
|
|
||||||
process.'''
|
|
||||||
msg = _("Please select which %s device to use:") % self.device
|
msg = _("Please select which %s device to use:") % self.device
|
||||||
infos = self.unpaired_devices(wallet.handler)
|
infos = self.unpaired_devices(wallet.handler)
|
||||||
labels = [info[1] for info in infos]
|
labels = [info[1] for info in infos]
|
||||||
device, descr, init = infos[wallet.handler.query_choice(msg, labels)]
|
device, descr, init = infos[wallet.handler.query_choice(msg, labels)]
|
||||||
self.device_manager().pair_wallet(wallet, device.id_)
|
self.device_manager().pair_wallet(wallet, device.id_)
|
||||||
if not init:
|
return init
|
||||||
self.initialize_device(wallet)
|
|
||||||
|
|
||||||
def on_restore_wallet(self, wallet, wizard):
|
def on_restore_wallet(self, wallet, wizard):
|
||||||
assert isinstance(wallet, self.wallet_class)
|
assert isinstance(wallet, self.wallet_class)
|
||||||
|
|||||||
@@ -252,11 +252,9 @@ def qt_plugin_class(base_plugin_class):
|
|||||||
assert type(wallet) == self.wallet_class
|
assert type(wallet) == self.wallet_class
|
||||||
wallet.handler = self.create_handler(wizard)
|
wallet.handler = self.create_handler(wizard)
|
||||||
wallet.thread = TaskThread(wizard, wizard.on_error)
|
wallet.thread = TaskThread(wizard, wizard.on_error)
|
||||||
self.select_device(wallet)
|
# Setup device and create accounts in separate thread; wait until done
|
||||||
# Create accounts in separate thread; wait until done
|
|
||||||
loop = QEventLoop()
|
loop = QEventLoop()
|
||||||
wallet.thread.add(partial(wallet.create_hd_account, None),
|
self.setup_device(wallet, loop.quit)
|
||||||
on_done=loop.quit)
|
|
||||||
loop.exec_()
|
loop.exec_()
|
||||||
|
|
||||||
@hook
|
@hook
|
||||||
|
|||||||
Reference in New Issue
Block a user