mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-18 13:38:12 +00:00
feat(core): delegate some layouts to models, do some wording changes
This commit is contained in:
parent
35896a7d6c
commit
127e399d28
@ -56,21 +56,15 @@ async def request_pin(
|
||||
|
||||
|
||||
async def request_pin_confirm(ctx: Context, *args: Any, **kwargs: Any) -> str:
|
||||
from trezor.ui.layouts import confirm_reenter_pin, pin_mismatch
|
||||
|
||||
while True:
|
||||
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)
|
||||
if pin1 == pin2:
|
||||
return pin1
|
||||
await _pin_mismatch()
|
||||
|
||||
|
||||
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.",
|
||||
)
|
||||
await pin_mismatch(ctx)
|
||||
|
||||
|
||||
async def request_pin_and_sd_salt(
|
||||
@ -146,7 +140,7 @@ async def error_pin_invalid(ctx: Context) -> NoReturn:
|
||||
await show_error_and_raise(
|
||||
ctx,
|
||||
"warning_wrong_pin",
|
||||
"The PIN you entered is invalid.",
|
||||
"The PIN you have entered is not valid.",
|
||||
"Wrong PIN", # header
|
||||
exc=wire.PinInvalid,
|
||||
)
|
||||
|
@ -50,13 +50,13 @@ async def change_pin(ctx: Context, msg: ChangePin) -> Success:
|
||||
|
||||
if newpin:
|
||||
if curpin:
|
||||
msg_screen = "You have successfully changed your PIN."
|
||||
msg_screen = "PIN changed."
|
||||
msg_wire = "PIN changed"
|
||||
else:
|
||||
msg_screen = "You have successfully enabled PIN protection."
|
||||
msg_screen = "PIN protection enabled."
|
||||
msg_wire = "PIN enabled"
|
||||
else:
|
||||
msg_screen = "You have successfully disabled PIN protection."
|
||||
msg_screen = "PIN protection disabled."
|
||||
msg_wire = "PIN removed"
|
||||
|
||||
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]:
|
||||
from trezor.ui.layouts import confirm_action
|
||||
from trezor.ui.layouts import confirm_action, confirm_set_new_pin
|
||||
|
||||
has_pin = config.has_pin()
|
||||
|
||||
br_type = "set_pin"
|
||||
title = "PIN settings"
|
||||
|
||||
if msg.remove and has_pin: # removing pin
|
||||
return confirm_action(
|
||||
ctx,
|
||||
"set_pin",
|
||||
"PIN settings",
|
||||
br_type,
|
||||
title,
|
||||
description="Do you want to disable PIN protection?",
|
||||
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
|
||||
return confirm_action(
|
||||
ctx,
|
||||
"set_pin",
|
||||
"PIN settings",
|
||||
br_type,
|
||||
title,
|
||||
description="Do you want to change your PIN?",
|
||||
verb="Change",
|
||||
)
|
||||
|
||||
if not msg.remove and not has_pin: # setting new pin
|
||||
return confirm_action(
|
||||
return confirm_set_new_pin(
|
||||
ctx,
|
||||
"set_pin",
|
||||
"PIN settings",
|
||||
description="Do you want to enable PIN protection?",
|
||||
verb="Enable",
|
||||
br_type,
|
||||
title,
|
||||
"Do you want to enable PIN protection?",
|
||||
[
|
||||
"PIN will be used to access this device.",
|
||||
"PIN should be 4-50 digits long.",
|
||||
],
|
||||
)
|
||||
|
||||
# removing non-existing PIN
|
||||
|
@ -44,13 +44,13 @@ async def change_wipe_code(ctx: Context, msg: ChangeWipeCode) -> Success:
|
||||
|
||||
if 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"
|
||||
else:
|
||||
msg_screen = "You have successfully set the wipe code."
|
||||
msg_screen = "Wipe code enabled."
|
||||
msg_wire = "Wipe code set"
|
||||
else:
|
||||
msg_screen = "You have successfully disabled the wipe code."
|
||||
msg_screen = "Wipe code disabled."
|
||||
msg_wire = "Wipe code removed"
|
||||
|
||||
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
|
||||
) -> Awaitable[None]:
|
||||
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:
|
||||
return confirm_action(
|
||||
ctx,
|
||||
"disable_wipe_code",
|
||||
"Disable wipe code",
|
||||
"disable wipe code protection?",
|
||||
"Do you really want to",
|
||||
reverse=True,
|
||||
title,
|
||||
description="Do you want to disable wipe code protection?",
|
||||
verb="Disable",
|
||||
)
|
||||
|
||||
if not msg.remove and has_wipe_code:
|
||||
return confirm_action(
|
||||
ctx,
|
||||
"change_wipe_code",
|
||||
"Change wipe code",
|
||||
"change the wipe code?",
|
||||
"Do you really want to",
|
||||
reverse=True,
|
||||
title,
|
||||
description="Do you want to change the wipe code?",
|
||||
verb="Change",
|
||||
)
|
||||
|
||||
if not msg.remove and not has_wipe_code:
|
||||
return confirm_action(
|
||||
return confirm_set_new_pin(
|
||||
ctx,
|
||||
"set_wipe_code",
|
||||
"Set wipe code",
|
||||
"set the wipe code?",
|
||||
"Do you really want to",
|
||||
reverse=True,
|
||||
title,
|
||||
"Do you want to enable wipe code?",
|
||||
[
|
||||
"Wipe code can be used to erase all data from this device.",
|
||||
],
|
||||
)
|
||||
|
||||
# Removing non-existing wipe code.
|
||||
@ -98,24 +99,20 @@ def _require_confirm_action(
|
||||
|
||||
|
||||
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 trezor.ui.layouts import (
|
||||
confirm_reenter_pin,
|
||||
pin_mismatch,
|
||||
wipe_code_same_as_pin,
|
||||
)
|
||||
|
||||
while True:
|
||||
code1 = await request_pin(ctx, "Enter new wipe code")
|
||||
if code1 == pin:
|
||||
# _wipe_code_invalid
|
||||
await show_popup(
|
||||
"Invalid wipe code",
|
||||
"The wipe code must be different from your PIN.\n\nPlease try again.",
|
||||
)
|
||||
await wipe_code_same_as_pin(ctx)
|
||||
continue
|
||||
|
||||
code2 = await request_pin(ctx, "Re-enter new wipe code")
|
||||
await confirm_reenter_pin(ctx, br_type="set_wipe_code", is_wipe_code=True)
|
||||
code2 = await request_pin(ctx, "Re-enter wipe code")
|
||||
if code1 == code2:
|
||||
return code1
|
||||
# _wipe_code_mismatch
|
||||
await show_popup(
|
||||
"Code mismatch",
|
||||
"The wipe codes you entered do not match.\n\nPlease try again.",
|
||||
)
|
||||
await pin_mismatch(ctx, br_type="set_wipe_code", is_wipe_code=True)
|
||||
|
@ -65,7 +65,11 @@ async def _continue_recovery_process(ctx: GenericContext) -> Success:
|
||||
if is_first_step:
|
||||
# If we are starting recovery, ask for word count first...
|
||||
# _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
|
||||
word_count = await layout.request_word_count(ctx, dry_run)
|
||||
# ...and only then show the starting screen with word count.
|
||||
@ -158,7 +162,7 @@ async def _finish_recovery(
|
||||
storage_recovery.end_progress()
|
||||
|
||||
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")
|
||||
|
||||
@ -192,11 +196,11 @@ async def _request_share_first_screen(ctx: GenericContext, word_count: int) -> N
|
||||
await _request_share_next_screen(ctx)
|
||||
else:
|
||||
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
|
||||
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:
|
||||
await layout.homescreen_dialog(
|
||||
ctx,
|
||||
"Enter",
|
||||
"Continue",
|
||||
"More shares needed",
|
||||
info_func=_show_remaining_groups_and_shares,
|
||||
)
|
||||
else:
|
||||
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:
|
||||
|
@ -91,12 +91,7 @@ async def show_dry_run_result(
|
||||
from trezor.ui.layouts import show_success
|
||||
|
||||
if result:
|
||||
if is_slip39:
|
||||
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."
|
||||
)
|
||||
text = "You have finished verifying your recovery seed"
|
||||
await show_success(ctx, "success_dry_recovery", text, button="Continue")
|
||||
else:
|
||||
if is_slip39:
|
||||
|
@ -161,8 +161,9 @@ async def show_backup_warning(ctx: GenericContext, slip39: bool = False) -> None
|
||||
|
||||
|
||||
async def show_backup_success(ctx: GenericContext) -> None:
|
||||
text = "Use your backup when you need to recover your wallet."
|
||||
await show_success(ctx, "success_backup", text, "Your backup is done.")
|
||||
from trezor.ui.layouts.reset import show_success_backup
|
||||
|
||||
await show_success_backup(ctx)
|
||||
|
||||
|
||||
# BIP39
|
||||
|
@ -437,7 +437,7 @@ async def show_address(
|
||||
# User pressed corner button or swiped left, go to address details.
|
||||
elif result is INFO:
|
||||
|
||||
def xpub_title(i: int):
|
||||
def xpub_title(i: int) -> str:
|
||||
result = f"MULTISIG XPUB #{i + 1}\n"
|
||||
result += "(YOURS)" if i == multisig_index else "(COSIGNER)"
|
||||
return result
|
||||
@ -1020,7 +1020,6 @@ async def confirm_modify_fee(
|
||||
total_fee_new: str,
|
||||
fee_rate_amount: str | None = None,
|
||||
) -> None:
|
||||
# TODO: include fee_rate_amount
|
||||
await raise_if_not_confirmed(
|
||||
interact(
|
||||
ctx,
|
||||
@ -1029,6 +1028,7 @@ async def confirm_modify_fee(
|
||||
sign=sign,
|
||||
user_fee_change=user_fee_change,
|
||||
total_fee_new=total_fee_new,
|
||||
fee_rate_amount=fee_rate_amount,
|
||||
)
|
||||
),
|
||||
"modify_fee",
|
||||
@ -1175,6 +1175,89 @@ async def request_pin_on_device(
|
||||
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:
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -355,3 +355,10 @@ async def show_warning_backup(ctx: GenericContext, slip39: bool) -> None:
|
||||
)
|
||||
if result != CONFIRMED:
|
||||
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.")
|
||||
|
Loading…
Reference in New Issue
Block a user