1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 07:28:10 +00:00

core/shamir: text improvements

This commit is contained in:
Tomas Susanka 2019-07-26 11:41:47 +02:00
parent ac887f514d
commit 4117f3506c
6 changed files with 50 additions and 64 deletions

View File

@ -80,12 +80,13 @@ def address_n_to_str(address_n: list) -> str:
async def show_warning(
ctx: wire.Context,
content: List[str],
subheader: str = None,
button: str = "Continue",
subheader: List[str] = [],
button: str = "Try again",
) -> None:
text = Text("Warning", ui.ICON_WRONG, ui.RED)
if subheader:
text.bold(subheader)
for row in subheader:
text.bold(row)
text.br_half()
for row in content:
text.normal(row)
@ -96,13 +97,14 @@ async def show_warning(
async def show_success(
ctx: wire.Context,
content: List[str],
subheader: str = None,
content: List[str] = [],
subheader: List[str] = [],
button: str = "Continue",
) -> None:
text = Text("Success", ui.ICON_CONFIRM, ui.GREEN)
if subheader:
text.bold(subheader)
for row in subheader:
text.bold(row)
text.br_half()
for row in content:
text.normal(row)

View File

@ -12,6 +12,7 @@ from trezor.ui.shamir import NumInput
from trezor.ui.text import Text
from apps.common.confirm import confirm, hold_to_confirm, require_confirm
from apps.common.layout import show_success
if __debug__:
from apps import debug
@ -26,7 +27,7 @@ async def show_internal_entropy(ctx, entropy: bytes):
async def confirm_backup(ctx):
text = Text("Back up wallet", ui.ICON_RESET, new_lines=False)
text = Text("Success", ui.ICON_CONFIRM, ui.GREEN, new_lines=False)
text.bold("New wallet created")
text.br()
text.bold("successfully!")
@ -46,7 +47,7 @@ async def confirm_backup(ctx):
async def confirm_backup_again(ctx):
text = Text("Back up wallet", ui.ICON_RESET, new_lines=False)
text = Text("Warning", ui.ICON_WRONG, ui.RED, new_lines=False)
text.bold("Are you sure you want")
text.br()
text.bold("to skip the backup?")
@ -76,13 +77,13 @@ async def _confirm_share_words(ctx, share_index, share_words):
third += 1
for part in utils.chunks(numbered, third):
if not await _confirm_word(ctx, share_index, part):
if not await _confirm_word(ctx, share_index, part, len(share_words)):
return False
return True
async def _confirm_word(ctx, share_index, numbered_share_words):
async def _confirm_word(ctx, share_index, numbered_share_words, count):
# TODO: duplicated words in the choice list
# shuffle the numbered seed half, slice off the choices we need
@ -99,7 +100,7 @@ async def _confirm_word(ctx, share_index, numbered_share_words):
# let the user pick a word
choices = [word for _, word in numbered_choices]
select = MnemonicWordSelect(choices, share_index, checked_index)
select = MnemonicWordSelect(choices, share_index, checked_index, count)
if __debug__:
selected_word = await ctx.wait(select, debug.input_signal)
else:
@ -113,20 +114,16 @@ async def _show_confirmation_success(
ctx, share_index, num_of_shares=None, slip39=False
):
if share_index is None or num_of_shares is None or share_index == num_of_shares - 1:
text = Text("Recovery seed", ui.ICON_RESET)
text.bold("You finished verifying")
if slip39:
text.bold("your recovery shares.")
subheader = ("You finished verifying", "your recovery shares.")
else:
text.bold("your recovery seed.")
subheader = ("You finished verifying", "your recovery seed.")
text = []
else:
text = Text("Recovery share #%s" % (share_index + 1), ui.ICON_RESET)
text.bold("Recovery share #%s" % (share_index + 1))
text.bold("checked successfully.")
text.normal("Continue with share #%s." % (share_index + 2))
return await confirm(
ctx, text, ButtonRequestType.ResetDevice, cancel=None, confirm="Continue"
)
subheader = ("Recovery share #%s" % (share_index + 1), "checked successfully.")
text = ["Continue with share #%s." % (share_index + 2)]
return await show_success(ctx, text, subheader=subheader)
async def _show_confirmation_failure(ctx, share_index):
@ -135,14 +132,14 @@ async def _show_confirmation_failure(ctx, share_index):
else:
text = Text("Recovery share #%s" % (share_index + 1), ui.ICON_WRONG, ui.RED)
text.bold("That is the wrong word.")
text.bold("Please check again.")
text.normal("Please check again.")
await require_confirm(
ctx, text, ButtonRequestType.ResetDevice, confirm="Check again", cancel=None
)
async def show_backup_warning(ctx, slip39=False):
text = Text("Back up your seed", ui.ICON_NOCOPY)
text = Text("Caution", ui.ICON_NOCOPY)
if slip39:
text.normal(
"Never make a digital",
@ -163,13 +160,8 @@ async def show_backup_warning(ctx, slip39=False):
async def show_backup_success(ctx):
text = Text("Backup is done!", ui.ICON_RESET)
text.normal(
"Use the backup to", "recover your wallet", "if you ever lose", "the device."
)
await require_confirm(
ctx, text, ButtonRequestType.ResetDevice, "Finish backup", cancel=None
)
text = ("Use your backup", "when you need to", "recover your wallet.")
await show_success(ctx, text, subheader=["Your backup is done."])
# BIP39
@ -343,7 +335,7 @@ async def slip39_show_and_confirm_shares(ctx, shares):
# display paginated share on the screen
await _slip39_show_share_words(ctx, index, share_words)
# make the user confirm 2 words from the share
# make the user confirm words from the share
if await _confirm_share_words(ctx, index, share_words):
await _show_confirmation_success(
ctx, index, num_of_shares=len(shares), slip39=True
@ -485,7 +477,7 @@ class ShamirNumInput(ui.Control):
class MnemonicWordSelect(ui.Layout):
NUM_OF_CHOICES = 3
def __init__(self, words, share_index, word_index):
def __init__(self, words, share_index, word_index, count):
self.words = words
self.share_index = share_index
self.word_index = word_index
@ -499,7 +491,7 @@ class MnemonicWordSelect(ui.Layout):
self.text = Text("Check seed")
else:
self.text = Text("Check share #%s" % (share_index + 1))
self.text.normal("Select the %s word:" % utils.format_ordinal(word_index + 1))
self.text.normal("Select word %d of %d:" % (word_index + 1, count))
def dispatch(self, event, x, y):
for btn in self.buttons:

View File

@ -23,7 +23,7 @@ async def recovery_device(ctx: wire.Context, msg: RecoveryDevice) -> Success:
_check_state(msg)
if not msg.dry_run:
title = "Wallet recovery"
title = "Recovery mode"
text = Text(title, ui.ICON_RECOVERY)
text.normal("Do you really want to", "recover the wallet?", "")
else:

View File

@ -39,7 +39,7 @@ async def request_word_count(ctx: wire.Context, dry_run: bool) -> int:
if dry_run:
text = Text("Seed check", ui.ICON_RECOVERY)
else:
text = Text("Wallet recovery", ui.ICON_RECOVERY)
text = Text("Recovery mode", ui.ICON_RECOVERY)
text.normal("Number of words?")
if __debug__:
@ -137,31 +137,23 @@ async def show_keyboard_info(ctx: wire.Context) -> None:
async def show_invalid_mnemonic(ctx, mnemonic_type: int):
if mnemonic_type == mnemonic.TYPE_SLIP39:
await show_warning(
ctx,
("You have entered", "a recovery share", "that is not valid."),
button="Try again",
ctx, ("You have entered", "a recovery share", "that is not valid.")
)
else:
await show_warning(
ctx,
("You have entered", "a recovery seed", "that is not valid."),
button="Try again",
ctx, ("You have entered", "a recovery seed", "that is not valid.")
)
async def show_share_already_added(ctx):
return await show_warning(
ctx,
("Share already entered,", "please enter", "a different share."),
button="Try again",
ctx, ("Share already entered,", "please enter", "a different share.")
)
async def show_identifier_mismatch(ctx):
return await show_warning(
ctx,
("You have entered", "a share from another", "Shamir Backup."),
button="Try again",
ctx, ("You have entered", "a share from another", "Shamir Backup.")
)

View File

@ -90,7 +90,7 @@ class TestMsgResetDeviceT2(TrezorTest):
# Confirm continue to next share
btn_code = yield
assert btn_code == B.ResetDevice
assert btn_code == B.Success
self.client.debug.press_yes()
# generate secret locally
@ -102,7 +102,7 @@ class TestMsgResetDeviceT2(TrezorTest):
# safety warning
btn_code = yield
assert btn_code == B.ResetDevice
assert btn_code == B.Success
self.client.debug.press_yes()
os_urandom = mock.Mock(return_value=EXTERNAL_ENTROPY)
@ -119,16 +119,16 @@ class TestMsgResetDeviceT2(TrezorTest):
proto.ButtonRequest(code=B.ResetDevice),
proto.ButtonRequest(code=B.ResetDevice),
proto.ButtonRequest(code=B.Other),
proto.ButtonRequest(code=B.ResetDevice),
proto.ButtonRequest(code=B.Success),
proto.ButtonRequest(code=B.Other),
proto.ButtonRequest(code=B.ResetDevice),
proto.ButtonRequest(code=B.Success),
proto.ButtonRequest(code=B.Other),
proto.ButtonRequest(code=B.ResetDevice),
proto.ButtonRequest(code=B.Success),
proto.ButtonRequest(code=B.Other),
proto.ButtonRequest(code=B.ResetDevice),
proto.ButtonRequest(code=B.Success),
proto.ButtonRequest(code=B.Other),
proto.ButtonRequest(code=B.ResetDevice),
proto.ButtonRequest(code=B.ResetDevice),
proto.ButtonRequest(code=B.Success),
proto.ButtonRequest(code=B.Success),
proto.Success(),
proto.Features(),
]

View File

@ -71,12 +71,12 @@ class TestMsgResetDeviceT2(TrezorTest):
# confirm recovery seed check
btn_code = yield
assert btn_code == B.ResetDevice
assert btn_code == B.Success
self.client.debug.press_yes()
# confirm success
btn_code = yield
assert btn_code == B.ResetDevice
assert btn_code == B.Success
self.client.debug.press_yes()
os_urandom = mock.Mock(return_value=EXTERNAL_ENTROPY)
@ -88,8 +88,8 @@ class TestMsgResetDeviceT2(TrezorTest):
proto.ButtonRequest(code=B.ResetDevice),
proto.ButtonRequest(code=B.ResetDevice),
proto.ButtonRequest(code=B.ResetDevice),
proto.ButtonRequest(code=B.ResetDevice),
proto.ButtonRequest(code=B.ResetDevice),
proto.ButtonRequest(code=B.Success),
proto.ButtonRequest(code=B.Success),
proto.Success(),
proto.Features(),
]
@ -176,12 +176,12 @@ class TestMsgResetDeviceT2(TrezorTest):
# confirm recovery seed check
btn_code = yield
assert btn_code == B.ResetDevice
assert btn_code == B.Success
self.client.debug.press_yes()
# confirm success
btn_code = yield
assert btn_code == B.ResetDevice
assert btn_code == B.Success
self.client.debug.press_yes()
os_urandom = mock.Mock(return_value=EXTERNAL_ENTROPY)
@ -196,8 +196,8 @@ class TestMsgResetDeviceT2(TrezorTest):
proto.ButtonRequest(code=B.ResetDevice),
proto.ButtonRequest(code=B.ResetDevice),
proto.ButtonRequest(code=B.ResetDevice),
proto.ButtonRequest(code=B.ResetDevice),
proto.ButtonRequest(code=B.ResetDevice),
proto.ButtonRequest(code=B.Success),
proto.ButtonRequest(code=B.Success),
proto.Success(),
proto.Features(),
]