mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-02 02:41:28 +00:00
refactor(core): turn show_success, show_warning into layouts
This commit is contained in:
parent
f38abf9d89
commit
03699f5639
@ -86,42 +86,6 @@ def address_n_to_str(address_n: Iterable[int]) -> str:
|
||||
return "m/" + "/".join([path_item(i) for i in address_n])
|
||||
|
||||
|
||||
async def show_warning(
|
||||
ctx: wire.GenericContext,
|
||||
content: Iterable[str],
|
||||
subheader: Iterable[str] = [],
|
||||
button: str = "Try again",
|
||||
) -> None:
|
||||
text = Text("Warning", ui.ICON_WRONG, ui.RED)
|
||||
if subheader:
|
||||
for row in subheader:
|
||||
text.bold(row)
|
||||
text.br_half()
|
||||
for row in content:
|
||||
text.normal(row)
|
||||
await require_confirm(
|
||||
ctx, text, ButtonRequestType.Warning, confirm=button, cancel=None
|
||||
)
|
||||
|
||||
|
||||
async def show_success(
|
||||
ctx: wire.GenericContext,
|
||||
content: Iterable[str] = [],
|
||||
subheader: Iterable[str] = [],
|
||||
button: str = "Continue",
|
||||
) -> None:
|
||||
text = Text("Success", ui.ICON_CONFIRM, ui.GREEN)
|
||||
if subheader:
|
||||
for row in subheader:
|
||||
text.bold(row)
|
||||
text.br_half()
|
||||
for row in content:
|
||||
text.normal(row)
|
||||
await require_confirm(
|
||||
ctx, text, ButtonRequestType.Success, confirm=button, cancel=None
|
||||
)
|
||||
|
||||
|
||||
def paginate_text(
|
||||
text: str,
|
||||
header: str,
|
||||
|
@ -3,9 +3,9 @@ from trezor import config, ui, wire
|
||||
from trezor.messages.Success import Success
|
||||
from trezor.pin import pin_to_int
|
||||
from trezor.ui.components.tt.text import Text
|
||||
from trezor.ui.layouts import require, show_success
|
||||
|
||||
from apps.common.confirm import require_confirm
|
||||
from apps.common.layout import show_success
|
||||
from apps.common.request_pin import (
|
||||
error_pin_invalid,
|
||||
error_pin_matches_wipe_code,
|
||||
@ -47,16 +47,16 @@ async def change_pin(ctx: wire.Context, msg: ChangePin) -> Success:
|
||||
|
||||
if newpin:
|
||||
if curpin:
|
||||
msg_screen = "changed your PIN."
|
||||
msg_screen = "You have successfully changed your PIN."
|
||||
msg_wire = "PIN changed"
|
||||
else:
|
||||
msg_screen = "enabled PIN protection."
|
||||
msg_screen = "You have successfully enabled PIN protection."
|
||||
msg_wire = "PIN enabled"
|
||||
else:
|
||||
msg_screen = "disabled PIN protection."
|
||||
msg_screen = "You have successfully disabled PIN protection."
|
||||
msg_wire = "PIN removed"
|
||||
|
||||
await show_success(ctx, ("You have successfully", msg_screen))
|
||||
await require(show_success(ctx, "success_pin", msg_screen))
|
||||
return Success(message=msg_wire)
|
||||
|
||||
|
||||
|
@ -3,10 +3,10 @@ from trezor import config, ui, wire
|
||||
from trezor.messages.Success import Success
|
||||
from trezor.pin import pin_to_int
|
||||
from trezor.ui.components.tt.text import Text
|
||||
from trezor.ui.layouts import require, show_success
|
||||
from trezor.ui.popup import Popup
|
||||
|
||||
from apps.common.confirm import require_confirm
|
||||
from apps.common.layout import show_success
|
||||
from apps.common.request_pin import (
|
||||
error_pin_invalid,
|
||||
request_pin,
|
||||
@ -44,16 +44,16 @@ async def change_wipe_code(ctx: wire.Context, msg: ChangeWipeCode) -> Success:
|
||||
|
||||
if wipe_code:
|
||||
if has_wipe_code:
|
||||
msg_screen = "changed the wipe code."
|
||||
msg_screen = "You have successfully changed the wipe code."
|
||||
msg_wire = "Wipe code changed"
|
||||
else:
|
||||
msg_screen = "set the wipe code."
|
||||
msg_screen = "You have successfully set the wipe code."
|
||||
msg_wire = "Wipe code set"
|
||||
else:
|
||||
msg_screen = "disabled the wipe code."
|
||||
msg_screen = "You have successfully disabled the wipe code."
|
||||
msg_wire = "Wipe code removed"
|
||||
|
||||
await show_success(ctx, ("You have successfully", msg_screen))
|
||||
await require(show_success(ctx, "success_wipe_code", msg_screen))
|
||||
return Success(message=msg_wire)
|
||||
|
||||
|
||||
|
@ -8,9 +8,9 @@ from trezor.crypto.hashlib import sha256
|
||||
from trezor.errors import MnemonicError
|
||||
from trezor.messages import BackupType
|
||||
from trezor.messages.Success import Success
|
||||
from trezor.ui.layouts import require, show_success
|
||||
|
||||
from apps.common import mnemonic
|
||||
from apps.common.layout import show_success
|
||||
from apps.homescreen.homescreen import homescreen
|
||||
|
||||
from .. import backup_types
|
||||
@ -146,7 +146,11 @@ async def _finish_recovery(
|
||||
|
||||
storage.recovery.end_progress()
|
||||
|
||||
await show_success(ctx, ("You have successfully", "recovered your wallet."))
|
||||
await require(
|
||||
show_success(
|
||||
ctx, "success_recovery", "You have successfully recovered your wallet."
|
||||
)
|
||||
)
|
||||
return Success(message="Device recovered")
|
||||
|
||||
|
||||
|
@ -5,10 +5,10 @@ from trezor.messages import ButtonRequestType
|
||||
from trezor.ui.components.tt.scroll import Paginated
|
||||
from trezor.ui.components.tt.text import Text
|
||||
from trezor.ui.components.tt.word_select import WordSelector
|
||||
from trezor.ui.layouts import require, show_success, show_warning
|
||||
|
||||
from apps.common import button_request
|
||||
from apps.common.confirm import confirm, info_confirm, require_confirm
|
||||
from apps.common.layout import show_success, show_warning
|
||||
|
||||
from .. import backup_types
|
||||
from . import word_validity
|
||||
@ -131,36 +131,20 @@ async def show_dry_run_result(
|
||||
) -> None:
|
||||
if result:
|
||||
if is_slip39:
|
||||
text = (
|
||||
"The entered recovery",
|
||||
"shares are valid and",
|
||||
"match what is currently",
|
||||
"in the device.",
|
||||
)
|
||||
text = "The entered recovery\nshares are valid and\nmatch what is currently\nin the device."
|
||||
else:
|
||||
text = (
|
||||
"The entered recovery",
|
||||
"seed is valid and",
|
||||
"matches the one",
|
||||
"in the device.",
|
||||
)
|
||||
await show_success(ctx, text, button="Continue")
|
||||
text = "The entered recovery\nseed is valid and\nmatches the one\nin the device."
|
||||
await require(
|
||||
show_success(ctx, "success_dry_recovery", text, button="Continue")
|
||||
)
|
||||
else:
|
||||
if is_slip39:
|
||||
text = (
|
||||
"The entered recovery",
|
||||
"shares are valid but",
|
||||
"do not match what is",
|
||||
"currently in the device.",
|
||||
)
|
||||
text = "The entered recovery\nshares are valid but\ndo not match what is\ncurrently in the device."
|
||||
else:
|
||||
text = (
|
||||
"The entered recovery",
|
||||
"seed is valid but does",
|
||||
"not match the one",
|
||||
"in the device.",
|
||||
)
|
||||
await show_warning(ctx, text, button="Continue")
|
||||
text = "The entered recovery\nseed is valid but does\nnot match the one\nin the device."
|
||||
await require(
|
||||
show_warning(ctx, "warning_dry_recovery", text, button="Continue")
|
||||
)
|
||||
|
||||
|
||||
async def show_dry_run_different_type(ctx: wire.GenericContext) -> None:
|
||||
@ -175,32 +159,50 @@ async def show_dry_run_different_type(ctx: wire.GenericContext) -> None:
|
||||
|
||||
async def show_invalid_mnemonic(ctx: wire.GenericContext, word_count: int) -> None:
|
||||
if backup_types.is_slip39_word_count(word_count):
|
||||
await show_warning(ctx, ("You have entered", "an invalid recovery", "share."))
|
||||
await require(
|
||||
show_warning(
|
||||
ctx,
|
||||
"warning_invalid_share",
|
||||
"You have entered\nan invalid recovery\nshare.",
|
||||
)
|
||||
)
|
||||
else:
|
||||
await show_warning(ctx, ("You have entered", "an invalid recovery", "seed."))
|
||||
await require(
|
||||
show_warning(
|
||||
ctx,
|
||||
"warning_invalid_seed",
|
||||
"You have entered\nan invalid recovery\nseed.",
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def show_share_already_added(ctx: wire.GenericContext) -> None:
|
||||
await show_warning(
|
||||
ctx, ("Share already entered,", "please enter", "a different share.")
|
||||
await require(
|
||||
show_warning(
|
||||
ctx,
|
||||
"warning_known_share",
|
||||
"Share already entered,\nplease enter\na different share.",
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def show_identifier_mismatch(ctx: wire.GenericContext) -> None:
|
||||
await show_warning(
|
||||
ctx, ("You have entered", "a share from another", "Shamir Backup.")
|
||||
await require(
|
||||
show_warning(
|
||||
ctx,
|
||||
"warning_mismatched_share",
|
||||
"You have entered\na share from another\nShamir Backup.",
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def show_group_threshold_reached(ctx: wire.GenericContext) -> None:
|
||||
await show_warning(
|
||||
ctx,
|
||||
(
|
||||
"Threshold of this",
|
||||
"group has been reached.",
|
||||
"Input share from",
|
||||
"different group",
|
||||
),
|
||||
await require(
|
||||
show_warning(
|
||||
ctx,
|
||||
"warning_group_threshold",
|
||||
"Threshold of this\ngroup has been reached.\nInput share from\ndifferent group.",
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
|
@ -9,9 +9,9 @@ from trezor.ui.components.tt.info import InfoConfirm
|
||||
from trezor.ui.components.tt.num_input import NumInput
|
||||
from trezor.ui.components.tt.scroll import Paginated
|
||||
from trezor.ui.components.tt.text import Text
|
||||
from trezor.ui.layouts import require, show_success
|
||||
|
||||
from apps.common.confirm import confirm, require_confirm, require_hold_to_confirm
|
||||
from apps.common.layout import show_success
|
||||
|
||||
if False:
|
||||
from trezor import loop
|
||||
@ -155,36 +155,33 @@ async def _show_confirmation_success(
|
||||
ctx, share_index=None, num_of_shares=None, group_index=None
|
||||
):
|
||||
if share_index is None: # it is a BIP39 backup
|
||||
subheader = ("You have finished", "verifying your", "recovery seed.")
|
||||
text = []
|
||||
subheader = "You have finished\nverifying your\nrecovery seed."
|
||||
text = ""
|
||||
|
||||
elif share_index == num_of_shares - 1:
|
||||
if group_index is None:
|
||||
subheader = ("You have finished", "verifying your", "recovery shares.")
|
||||
subheader = "You have finished\nverifying your\nrecovery shares."
|
||||
else:
|
||||
subheader = (
|
||||
"You have finished",
|
||||
"verifying your",
|
||||
"recovery shares",
|
||||
"for group %s." % (group_index + 1),
|
||||
"You have finished\nverifying your\nrecovery shares\nfor group %s."
|
||||
% (group_index + 1)
|
||||
)
|
||||
text = []
|
||||
text = ""
|
||||
|
||||
else:
|
||||
if group_index is None:
|
||||
subheader = (
|
||||
"Recovery share #%s" % (share_index + 1),
|
||||
"checked successfully.",
|
||||
)
|
||||
text = ["Continue with share #%s." % (share_index + 2)]
|
||||
subheader = "Recovery share #%s\nchecked successfully." % (share_index + 1)
|
||||
text = "Continue with share #%s." % (share_index + 2)
|
||||
else:
|
||||
subheader = (
|
||||
"Group %s - Share %s" % ((group_index + 1), (share_index + 1)),
|
||||
"checked successfully.",
|
||||
subheader = "Group %s - Share %s\nchecked successfully." % (
|
||||
(group_index + 1),
|
||||
(share_index + 1),
|
||||
)
|
||||
text = ("Continue with the next ", "share.")
|
||||
text = "Continue with the next\nshare."
|
||||
|
||||
return await show_success(ctx, text, subheader=subheader)
|
||||
return await require(
|
||||
show_success(ctx, "success_recovery", text, subheader=subheader)
|
||||
)
|
||||
|
||||
|
||||
async def _show_confirmation_failure(ctx, share_index):
|
||||
@ -221,8 +218,10 @@ async def show_backup_warning(ctx, slip39=False):
|
||||
|
||||
|
||||
async def show_backup_success(ctx):
|
||||
text = ("Use your backup", "when you need to", "recover your wallet.")
|
||||
await show_success(ctx, text, subheader=["Your backup is done."])
|
||||
text = "Use your backup\nwhen you need to\nrecover your wallet."
|
||||
await require(
|
||||
show_success(ctx, "success_backup", text, subheader="Your backup is done.")
|
||||
)
|
||||
|
||||
|
||||
# BIP39
|
||||
|
@ -6,9 +6,9 @@ from trezor.messages import SdProtectOperationType
|
||||
from trezor.messages.Success import Success
|
||||
from trezor.pin import pin_to_int
|
||||
from trezor.ui.components.tt.text import Text
|
||||
from trezor.ui.layouts import require, show_success
|
||||
|
||||
from apps.common.confirm import require_confirm
|
||||
from apps.common.layout import show_success
|
||||
from apps.common.request_pin import (
|
||||
error_pin_invalid,
|
||||
request_pin,
|
||||
@ -87,7 +87,9 @@ async def sd_protect_enable(ctx: wire.Context, msg: SdProtect) -> Success:
|
||||
|
||||
storage.device.set_sd_salt_auth_key(salt_auth_key)
|
||||
|
||||
await show_success(ctx, ("You have successfully", "enabled SD protection."))
|
||||
await require(
|
||||
show_success(ctx, "success_sd", "You have successfully enabled SD protection.")
|
||||
)
|
||||
return Success(message="SD card protection enabled")
|
||||
|
||||
|
||||
@ -119,7 +121,9 @@ async def sd_protect_disable(ctx: wire.Context, msg: SdProtect) -> Success:
|
||||
# because overall SD-protection was successfully disabled.
|
||||
pass
|
||||
|
||||
await show_success(ctx, ("You have successfully", "disabled SD protection."))
|
||||
await require(
|
||||
show_success(ctx, "success_sd", "You have successfully disabled SD protection.")
|
||||
)
|
||||
return Success(message="SD card protection disabled")
|
||||
|
||||
|
||||
@ -154,7 +158,11 @@ async def sd_protect_refresh(ctx: wire.Context, msg: SdProtect) -> Success:
|
||||
# SD-protection was successfully refreshed.
|
||||
pass
|
||||
|
||||
await show_success(ctx, ("You have successfully", "refreshed SD protection."))
|
||||
await require(
|
||||
show_success(
|
||||
ctx, "success_sd", "You have successfully refreshed SD protection."
|
||||
)
|
||||
)
|
||||
return Success(message="SD card protection refreshed")
|
||||
|
||||
|
||||
|
@ -39,6 +39,8 @@ __all__ = (
|
||||
"confirm_backup",
|
||||
"confirm_path_warning",
|
||||
"show_address",
|
||||
"show_success",
|
||||
"show_warning",
|
||||
"confirm_output",
|
||||
"confirm_hex",
|
||||
"confirm_total",
|
||||
@ -250,6 +252,48 @@ async def show_address(
|
||||
return
|
||||
|
||||
|
||||
def show_warning(
|
||||
ctx: wire.GenericContext,
|
||||
br_type: str,
|
||||
content: str,
|
||||
subheader: Optional[str] = None,
|
||||
button: str = "Try again",
|
||||
) -> LayoutType:
|
||||
text = Text("Warning", ui.ICON_WRONG, ui.RED, new_lines=False)
|
||||
if subheader:
|
||||
text.bold(subheader)
|
||||
text.br()
|
||||
text.br_half()
|
||||
text.normal(content)
|
||||
return interact(
|
||||
ctx,
|
||||
Confirm(text, confirm=button, cancel=None),
|
||||
br_type,
|
||||
ButtonRequestType.Warning,
|
||||
)
|
||||
|
||||
|
||||
def show_success(
|
||||
ctx: wire.GenericContext,
|
||||
br_type: str,
|
||||
content: str,
|
||||
subheader: Optional[str] = None,
|
||||
button: str = "Continue",
|
||||
) -> LayoutType:
|
||||
text = Text("Success", ui.ICON_CONFIRM, ui.GREEN, new_lines=False)
|
||||
if subheader:
|
||||
text.bold(subheader)
|
||||
text.br()
|
||||
text.br_half()
|
||||
text.normal(content)
|
||||
return interact(
|
||||
ctx,
|
||||
Confirm(text, confirm=button, cancel=None),
|
||||
br_type,
|
||||
ButtonRequestType.Success,
|
||||
)
|
||||
|
||||
|
||||
def confirm_output(
|
||||
ctx: wire.GenericContext,
|
||||
address: str,
|
||||
|
Loading…
Reference in New Issue
Block a user