1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-08-04 21:05:29 +00:00

feat(core): delegate some layouts to models, do some wording changes

This commit is contained in:
grdddj 2023-05-04 14:49:43 +02:00 committed by Martin Milata
parent 35896a7d6c
commit 127e399d28
8 changed files with 157 additions and 70 deletions

View File

@ -56,21 +56,15 @@ async def request_pin(
async def request_pin_confirm(ctx: Context, *args: Any, **kwargs: Any) -> str: async def request_pin_confirm(ctx: Context, *args: Any, **kwargs: Any) -> str:
from trezor.ui.layouts import confirm_reenter_pin, pin_mismatch
while True: while True:
pin1 = await request_pin(ctx, "Enter new PIN", *args, **kwargs) pin1 = await request_pin(ctx, "Enter new PIN", *args, **kwargs)
await confirm_reenter_pin(ctx)
pin2 = await request_pin(ctx, "Re-enter new PIN", *args, **kwargs) pin2 = await request_pin(ctx, "Re-enter new PIN", *args, **kwargs)
if pin1 == pin2: if pin1 == pin2:
return pin1 return pin1
await _pin_mismatch() await pin_mismatch(ctx)
async def _pin_mismatch() -> None:
from trezor.ui.layouts import show_popup
await show_popup(
"PIN mismatch",
"The PINs you entered do not match.\n\nPlease try again.",
)
async def request_pin_and_sd_salt( async def request_pin_and_sd_salt(
@ -146,7 +140,7 @@ async def error_pin_invalid(ctx: Context) -> NoReturn:
await show_error_and_raise( await show_error_and_raise(
ctx, ctx,
"warning_wrong_pin", "warning_wrong_pin",
"The PIN you entered is invalid.", "The PIN you have entered is not valid.",
"Wrong PIN", # header "Wrong PIN", # header
exc=wire.PinInvalid, exc=wire.PinInvalid,
) )

View File

@ -50,13 +50,13 @@ async def change_pin(ctx: Context, msg: ChangePin) -> Success:
if newpin: if newpin:
if curpin: if curpin:
msg_screen = "You have successfully changed your PIN." msg_screen = "PIN changed."
msg_wire = "PIN changed" msg_wire = "PIN changed"
else: else:
msg_screen = "You have successfully enabled PIN protection." msg_screen = "PIN protection enabled."
msg_wire = "PIN enabled" msg_wire = "PIN enabled"
else: else:
msg_screen = "You have successfully disabled PIN protection." msg_screen = "PIN protection disabled."
msg_wire = "PIN removed" msg_wire = "PIN removed"
await show_success(ctx, "success_pin", msg_screen) await show_success(ctx, "success_pin", msg_screen)
@ -64,15 +64,18 @@ async def change_pin(ctx: Context, msg: ChangePin) -> Success:
def _require_confirm_change_pin(ctx: Context, msg: ChangePin) -> Awaitable[None]: def _require_confirm_change_pin(ctx: Context, msg: ChangePin) -> Awaitable[None]:
from trezor.ui.layouts import confirm_action from trezor.ui.layouts import confirm_action, confirm_set_new_pin
has_pin = config.has_pin() has_pin = config.has_pin()
br_type = "set_pin"
title = "PIN settings"
if msg.remove and has_pin: # removing pin if msg.remove and has_pin: # removing pin
return confirm_action( return confirm_action(
ctx, ctx,
"set_pin", br_type,
"PIN settings", title,
description="Do you want to disable PIN protection?", description="Do you want to disable PIN protection?",
verb="Disable", verb="Disable",
) )
@ -80,19 +83,22 @@ def _require_confirm_change_pin(ctx: Context, msg: ChangePin) -> Awaitable[None]
if not msg.remove and has_pin: # changing pin if not msg.remove and has_pin: # changing pin
return confirm_action( return confirm_action(
ctx, ctx,
"set_pin", br_type,
"PIN settings", title,
description="Do you want to change your PIN?", description="Do you want to change your PIN?",
verb="Change", verb="Change",
) )
if not msg.remove and not has_pin: # setting new pin if not msg.remove and not has_pin: # setting new pin
return confirm_action( return confirm_set_new_pin(
ctx, ctx,
"set_pin", br_type,
"PIN settings", title,
description="Do you want to enable PIN protection?", "Do you want to enable PIN protection?",
verb="Enable", [
"PIN will be used to access this device.",
"PIN should be 4-50 digits long.",
],
) )
# removing non-existing PIN # removing non-existing PIN

View File

@ -44,13 +44,13 @@ async def change_wipe_code(ctx: Context, msg: ChangeWipeCode) -> Success:
if wipe_code: if wipe_code:
if has_wipe_code: if has_wipe_code:
msg_screen = "You have successfully changed the wipe code." msg_screen = "Wipe code changed."
msg_wire = "Wipe code changed" msg_wire = "Wipe code changed"
else: else:
msg_screen = "You have successfully set the wipe code." msg_screen = "Wipe code enabled."
msg_wire = "Wipe code set" msg_wire = "Wipe code set"
else: else:
msg_screen = "You have successfully disabled the wipe code." msg_screen = "Wipe code disabled."
msg_wire = "Wipe code removed" msg_wire = "Wipe code removed"
await show_success(ctx, "success_wipe_code", msg_screen) await show_success(ctx, "success_wipe_code", msg_screen)
@ -61,36 +61,37 @@ def _require_confirm_action(
ctx: Context, msg: ChangeWipeCode, has_wipe_code: bool ctx: Context, msg: ChangeWipeCode, has_wipe_code: bool
) -> Awaitable[None]: ) -> Awaitable[None]:
from trezor.wire import ProcessError from trezor.wire import ProcessError
from trezor.ui.layouts import confirm_action from trezor.ui.layouts import confirm_action, confirm_set_new_pin
title = "Wipe code settings"
if msg.remove and has_wipe_code: if msg.remove and has_wipe_code:
return confirm_action( return confirm_action(
ctx, ctx,
"disable_wipe_code", "disable_wipe_code",
"Disable wipe code", title,
"disable wipe code protection?", description="Do you want to disable wipe code protection?",
"Do you really want to", verb="Disable",
reverse=True,
) )
if not msg.remove and has_wipe_code: if not msg.remove and has_wipe_code:
return confirm_action( return confirm_action(
ctx, ctx,
"change_wipe_code", "change_wipe_code",
"Change wipe code", title,
"change the wipe code?", description="Do you want to change the wipe code?",
"Do you really want to", verb="Change",
reverse=True,
) )
if not msg.remove and not has_wipe_code: if not msg.remove and not has_wipe_code:
return confirm_action( return confirm_set_new_pin(
ctx, ctx,
"set_wipe_code", "set_wipe_code",
"Set wipe code", title,
"set the wipe code?", "Do you want to enable wipe code?",
"Do you really want to", [
reverse=True, "Wipe code can be used to erase all data from this device.",
],
) )
# Removing non-existing wipe code. # Removing non-existing wipe code.
@ -98,24 +99,20 @@ def _require_confirm_action(
async def _request_wipe_code_confirm(ctx: Context, pin: str) -> str: async def _request_wipe_code_confirm(ctx: Context, pin: str) -> str:
from trezor.ui.layouts import show_popup
from apps.common.request_pin import request_pin from apps.common.request_pin import request_pin
from trezor.ui.layouts import (
confirm_reenter_pin,
pin_mismatch,
wipe_code_same_as_pin,
)
while True: while True:
code1 = await request_pin(ctx, "Enter new wipe code") code1 = await request_pin(ctx, "Enter new wipe code")
if code1 == pin: if code1 == pin:
# _wipe_code_invalid await wipe_code_same_as_pin(ctx)
await show_popup(
"Invalid wipe code",
"The wipe code must be different from your PIN.\n\nPlease try again.",
)
continue continue
await confirm_reenter_pin(ctx, br_type="set_wipe_code", is_wipe_code=True)
code2 = await request_pin(ctx, "Re-enter new wipe code") code2 = await request_pin(ctx, "Re-enter wipe code")
if code1 == code2: if code1 == code2:
return code1 return code1
# _wipe_code_mismatch await pin_mismatch(ctx, br_type="set_wipe_code", is_wipe_code=True)
await show_popup(
"Code mismatch",
"The wipe codes you entered do not match.\n\nPlease try again.",
)

View File

@ -65,7 +65,11 @@ async def _continue_recovery_process(ctx: GenericContext) -> Success:
if is_first_step: if is_first_step:
# If we are starting recovery, ask for word count first... # If we are starting recovery, ask for word count first...
# _request_word_count # _request_word_count
await layout.homescreen_dialog(ctx, "Select", "Select number of words") await layout.homescreen_dialog(
ctx,
"Continue",
"First select the number of words in your recovery seed",
)
# ask for the number of words # ask for the number of words
word_count = await layout.request_word_count(ctx, dry_run) word_count = await layout.request_word_count(ctx, dry_run)
# ...and only then show the starting screen with word count. # ...and only then show the starting screen with word count.
@ -158,7 +162,7 @@ async def _finish_recovery(
storage_recovery.end_progress() storage_recovery.end_progress()
await show_success( await show_success(
ctx, "success_recovery", "You have successfully recovered your wallet." ctx, "success_recovery", "You have finished recovering your wallet."
) )
return Success(message="Device recovered") return Success(message="Device recovered")
@ -192,11 +196,11 @@ async def _request_share_first_screen(ctx: GenericContext, word_count: int) -> N
await _request_share_next_screen(ctx) await _request_share_next_screen(ctx)
else: else:
await layout.homescreen_dialog( await layout.homescreen_dialog(
ctx, "Enter share", "Enter any share", f"({word_count} words)" ctx, "Continue", "Enter any share", f"({word_count} words)"
) )
else: # BIP-39 else: # BIP-39
await layout.homescreen_dialog( await layout.homescreen_dialog(
ctx, "Enter seed", "Enter recovery seed", f"({word_count} words)" ctx, "Continue", "Now enter your recovery seed", f"({word_count} words)"
) )
@ -212,13 +216,13 @@ async def _request_share_next_screen(ctx: GenericContext) -> None:
if group_count > 1: if group_count > 1:
await layout.homescreen_dialog( await layout.homescreen_dialog(
ctx, ctx,
"Enter", "Continue",
"More shares needed", "More shares needed",
info_func=_show_remaining_groups_and_shares, info_func=_show_remaining_groups_and_shares,
) )
else: else:
text = strings.format_plural("{count} more {plural}", remaining[0], "share") text = strings.format_plural("{count} more {plural}", remaining[0], "share")
await layout.homescreen_dialog(ctx, "Enter share", text, "needed to enter") await layout.homescreen_dialog(ctx, "Continue", text, "needed to enter")
async def _show_remaining_groups_and_shares(ctx: GenericContext) -> None: async def _show_remaining_groups_and_shares(ctx: GenericContext) -> None:

View File

@ -91,12 +91,7 @@ async def show_dry_run_result(
from trezor.ui.layouts import show_success from trezor.ui.layouts import show_success
if result: if result:
if is_slip39: text = "You have finished verifying your recovery seed"
text = "The entered recovery shares are valid and match what is currently in the device."
else:
text = (
"The entered recovery seed is valid and matches the one in the device."
)
await show_success(ctx, "success_dry_recovery", text, button="Continue") await show_success(ctx, "success_dry_recovery", text, button="Continue")
else: else:
if is_slip39: if is_slip39:

View File

@ -161,8 +161,9 @@ async def show_backup_warning(ctx: GenericContext, slip39: bool = False) -> None
async def show_backup_success(ctx: GenericContext) -> None: async def show_backup_success(ctx: GenericContext) -> None:
text = "Use your backup when you need to recover your wallet." from trezor.ui.layouts.reset import show_success_backup
await show_success(ctx, "success_backup", text, "Your backup is done.")
await show_success_backup(ctx)
# BIP39 # BIP39

View File

@ -437,7 +437,7 @@ async def show_address(
# User pressed corner button or swiped left, go to address details. # User pressed corner button or swiped left, go to address details.
elif result is INFO: elif result is INFO:
def xpub_title(i: int): def xpub_title(i: int) -> str:
result = f"MULTISIG XPUB #{i + 1}\n" result = f"MULTISIG XPUB #{i + 1}\n"
result += "(YOURS)" if i == multisig_index else "(COSIGNER)" result += "(YOURS)" if i == multisig_index else "(COSIGNER)"
return result return result
@ -1020,7 +1020,6 @@ async def confirm_modify_fee(
total_fee_new: str, total_fee_new: str,
fee_rate_amount: str | None = None, fee_rate_amount: str | None = None,
) -> None: ) -> None:
# TODO: include fee_rate_amount
await raise_if_not_confirmed( await raise_if_not_confirmed(
interact( interact(
ctx, ctx,
@ -1029,6 +1028,7 @@ async def confirm_modify_fee(
sign=sign, sign=sign,
user_fee_change=user_fee_change, user_fee_change=user_fee_change,
total_fee_new=total_fee_new, total_fee_new=total_fee_new,
fee_rate_amount=fee_rate_amount,
) )
), ),
"modify_fee", "modify_fee",
@ -1175,6 +1175,89 @@ async def request_pin_on_device(
return result return result
async def confirm_reenter_pin(
ctx: GenericContext,
br_type: str = "set_pin",
br_code: ButtonRequestType = BR_TYPE_OTHER,
is_wipe_code: bool = False,
) -> None:
title = "CHECK WIPE CODE" if is_wipe_code else "CHECK PIN"
return await confirm_action(
ctx,
br_type,
title,
action="Please re-enter to confirm.",
verb="BEGIN",
br_code=br_code,
)
async def pin_mismatch(
ctx: GenericContext,
br_type: str = "set_pin",
br_code: ButtonRequestType = BR_TYPE_OTHER,
is_wipe_code: bool = False,
) -> None:
title = "WIPE CODE MISMATCH" if is_wipe_code else "PIN MISMATCH"
description = "wipe codes" if is_wipe_code else "PINs"
return await confirm_action(
ctx,
br_type,
title,
action=f"The {description} you entered do not match.\n\nPlease try again.",
verb="TRY AGAIN",
verb_cancel=None,
br_code=br_code,
)
async def wipe_code_same_as_pin(
ctx: GenericContext,
br_type: str = "set_wipe_code",
br_code: ButtonRequestType = BR_TYPE_OTHER,
) -> None:
return await confirm_action(
ctx,
br_type,
"INVALID WIPE CODE",
action="The wipe code must be different from your PIN.\n\nPlease try again.",
verb="TRY AGAIN",
verb_cancel=None,
br_code=br_code,
)
async def confirm_set_new_pin(
ctx: GenericContext,
br_type: str,
title: str,
description: str,
information: list[str],
br_code: ButtonRequestType = BR_TYPE_OTHER,
) -> None:
await confirm_action(
ctx,
br_type,
title,
description=description,
verb="ENABLE",
br_code=br_code,
)
if "wipe_code" in br_type:
title = "WIPE CODE INFO"
else:
title = "PIN INFORMATION"
return await confirm_action(
ctx,
br_type,
title=title,
description="\n\n".join(information),
br_code=br_code,
)
class RustProgress: class RustProgress:
def __init__( def __init__(
self, self,

View File

@ -355,3 +355,10 @@ async def show_warning_backup(ctx: GenericContext, slip39: bool) -> None:
) )
if result != CONFIRMED: if result != CONFIRMED:
raise ActionCancelled raise ActionCancelled
async def show_success_backup(ctx: GenericContext) -> None:
from . import show_success
text = "Use your backup when you need to recover your wallet."
await show_success(ctx, "success_backup", text, "Your backup is done.")