1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-06-29 19:32:34 +00:00

WIP - improve design of some screens

This commit is contained in:
grdddj 2023-01-09 13:51:35 +01:00
parent 4a11d41ba8
commit 0800d891e8
6 changed files with 248 additions and 228 deletions

View File

@ -92,7 +92,7 @@ test_emu: ## run selected device tests from python-trezor
$(EMU_TEST) $(PYTEST) $(TESTPATH)/device_tests $(TESTOPTS)
test_emu_multicore: ## run device tests using multiple cores
PYTEST_TIMEOUT=100 $(PYTEST) -n auto $(TESTPATH)/device_tests $(TESTOPTS) \
PYTEST_TIMEOUT=150 $(PYTEST) -n auto $(TESTPATH)/device_tests $(TESTOPTS) \
--control-emulators --model=core --random-order-seed=$(shell echo $$RANDOM)
test_emu_monero: ## run selected monero device tests from monero-agent
@ -114,7 +114,7 @@ test_emu_ui: ## run ui integration tests
--ui=test --ui-check-missing --not-generate-report-after-each-test
test_emu_ui_multicore: ## run ui integration tests using multiple cores
PYTEST_TIMEOUT=100 $(PYTEST) -n auto $(TESTPATH)/device_tests $(TESTOPTS) \
PYTEST_TIMEOUT=150 $(PYTEST) -n auto $(TESTPATH)/device_tests $(TESTOPTS) \
--ui=test --ui-check-missing --not-generate-report-after-each-test \
--control-emulators --model=core --random-order-seed=$(shell echo $$RANDOM)

View File

@ -24,8 +24,7 @@ BR_TYPE_OTHER = ButtonRequestType.Other # global_import_cache
if __debug__:
trezorui2.disable_animation(bool(DISABLE_ANIMATION))
class RustLayoutContent:
class RustLayoutContent:
"""Providing shortcuts to the data returned by layouts.
Used only in debug mode.
@ -112,7 +111,9 @@ class RustLayoutContent:
def title(self) -> str:
"""Getting text that is displayed as a title."""
# there could be multiple of those - title and subtitle for example
title_strings = self._get_strings_inside_tag(self.str_content, self.TITLE_TAG)
title_strings = self._get_strings_inside_tag(
self.str_content, self.TITLE_TAG
)
return "\n".join(title_strings)
def content(self) -> str:
@ -263,7 +264,7 @@ class RustLayout(ui.Layout):
self.layout.trace(callback)
return result
def _content_obj(self) -> RustLayoutContent:
def _content_obj(self) -> RustLayoutContent: # type: ignore [is possibly unbound]
"""Gets object with user-friendly methods on Rust layout content."""
return RustLayoutContent(self._read_content_raw())
@ -448,16 +449,16 @@ async def _placeholder_confirm(
br_code: ButtonRequestType = BR_TYPE_OTHER,
) -> Any:
return await confirm_action(
ctx=ctx,
br_type=br_type,
br_code=br_code,
title=title.upper(),
action=data,
description=description,
ctx,
br_type,
title.upper(),
data,
description,
verb=verb,
verb_cancel=verb_cancel,
hold=hold,
reverse=True,
br_code=br_code,
)
@ -861,10 +862,10 @@ async def should_show_more(
confirm: str | bytes | None = None,
) -> bool:
return await get_bool(
ctx=ctx,
title=title.upper(),
data=button_text,
br_type=br_type,
ctx,
br_type,
title.upper(),
button_text,
br_code=br_code,
)
@ -879,12 +880,13 @@ async def confirm_blob(
br_code: ButtonRequestType = BR_TYPE_OTHER,
ask_pagination: bool = False,
) -> None:
await _placeholder_confirm(
ctx=ctx,
br_type=br_type,
title=title.upper(),
data=str(data),
description=description,
await confirm_action(
ctx,
br_type,
title.upper(),
description,
str(data),
hold=hold,
br_code=br_code,
)
@ -898,11 +900,11 @@ async def confirm_address(
br_code: ButtonRequestType = BR_TYPE_OTHER,
) -> Awaitable[None]:
return confirm_blob(
ctx=ctx,
br_type=br_type,
title=title.upper(),
data=address,
description=description,
ctx,
br_type,
title.upper(),
address,
description,
br_code=br_code,
)
@ -916,11 +918,11 @@ async def confirm_text(
br_code: ButtonRequestType = BR_TYPE_OTHER,
) -> Any:
return await _placeholder_confirm(
ctx=ctx,
br_type=br_type,
title=title,
data=data,
description=description,
ctx,
br_type,
title,
data,
description,
br_code=br_code,
)
@ -933,12 +935,12 @@ def confirm_amount(
br_type: str = "confirm_amount",
br_code: ButtonRequestType = BR_TYPE_OTHER,
) -> Awaitable[None]:
return _placeholder_confirm(
ctx=ctx,
br_type=br_type,
title=title.upper(),
data=amount,
description=description,
return confirm_blob(
ctx,
br_type,
title.upper(),
amount,
description,
br_code=br_code,
)
@ -991,12 +993,14 @@ def confirm_value(
if not verb and not hold:
raise ValueError("Either verb or hold=True must be set")
return _placeholder_confirm(
ctx=ctx,
br_type=br_type,
title=title.upper(),
data=value,
description=description,
return confirm_action(
ctx,
br_type,
title.upper(),
description,
value,
verb=verb or "HOLD TO CONFIRM",
hold=hold,
br_code=br_code,
)
@ -1032,11 +1036,14 @@ async def confirm_total(
async def confirm_joint_total(
ctx: GenericContext, spending_amount: str, total_amount: str
) -> None:
await _placeholder_confirm(
await confirm_properties(
ctx,
"confirm_joint_total",
"JOINT TRANSACTION",
f"You are contributing:\n{spending_amount}\nto the total amount:\n{total_amount}",
(
("You are contributing:", spending_amount),
("To the total amount:", total_amount),
),
br_code=ButtonRequestType.SignTx,
)
@ -1054,19 +1061,21 @@ async def confirm_metadata(
ctx,
br_type,
title.upper(),
content.format(param),
description=content.format(param),
hold=hold,
br_code=br_code,
)
async def confirm_replacement(ctx: GenericContext, description: str, txid: str) -> None:
await _placeholder_confirm(
await confirm_value(
ctx,
"confirm_replacement",
description.upper(),
f"Confirm transaction ID:\n{txid}",
br_code=ButtonRequestType.SignTx,
txid,
"Confirm transaction ID:",
"confirm_replacement",
ButtonRequestType.SignTx,
verb="CONFIRM",
)
@ -1100,24 +1109,26 @@ async def confirm_modify_fee(
total_fee_new: str,
fee_rate_amount: str | None = None,
) -> None:
text = ""
if sign == 0:
text += "Your fee did not change.\n"
change_verb = "Your fee did not change."
else:
if sign < 0:
text += "Decrease your fee by:\n"
change_verb = "Decrease your fee by:"
else:
text += "Increase your fee by:\n"
text += f"{user_fee_change}\n"
text += f"Transaction fee:\n{total_fee_new}"
if fee_rate_amount is not None:
text += "\n" + fee_rate_amount
change_verb = "Increase your fee by:"
await _placeholder_confirm(
properties: list[tuple[str, str]] = [
(change_verb, user_fee_change),
("Transaction fee:", total_fee_new),
]
if fee_rate_amount is not None:
properties.append(("Fee rate:", fee_rate_amount))
await confirm_properties(
ctx,
"modify_fee",
"MODIFY FEE",
text,
properties,
br_code=ButtonRequestType.SignTx,
)
@ -1125,11 +1136,14 @@ async def confirm_modify_fee(
async def confirm_coinjoin(
ctx: GenericContext, max_rounds: int, max_fee_per_vbyte: str
) -> None:
await _placeholder_confirm(
await confirm_properties(
ctx,
"coinjoin_final",
"AUTHORIZE COINJOIN",
f"Maximum rounds: {max_rounds}\n\nMaximum mining fee:\n{max_fee_per_vbyte}",
(
("Maximum rounds:", str(max_rounds)),
("Maximum mining fee:", max_fee_per_vbyte),
),
br_code=BR_TYPE_OTHER,
)
@ -1166,20 +1180,24 @@ async def confirm_signverify(
header = f"Sign {coin} message"
br_type = "sign_message"
await _placeholder_confirm(
ctx=ctx,
br_type=br_type,
title=header.upper(),
data=f"Confirm address:\n{address}",
br_code=BR_TYPE_OTHER,
await confirm_value(
ctx,
header.upper(),
address,
"Confirm address:",
br_type,
BR_TYPE_OTHER,
verb="CONFIRM",
)
await _placeholder_confirm(
await confirm_value(
ctx,
br_type,
header.upper(),
f"Confirm message:\n{message}",
br_code=BR_TYPE_OTHER,
message,
"Confirm message:",
br_type,
BR_TYPE_OTHER,
verb="CONFIRM",
)
@ -1257,7 +1275,6 @@ async def request_pin_on_device(
)
)
while True:
result = await ctx.wait(dialog)
if result is trezorui2.CANCELLED:
raise wire.PinCancelled
@ -1331,6 +1348,8 @@ async def confirm_set_new_pin(
br_code=br_code,
)
# Additional information for the user to know about PIN/WIPE CODE
if "wipe_code" in br_type:
title = "WIPE CODE INFO"
verb = "HODL TO BEGIN" # Easter egg from @Hannsek
@ -1344,7 +1363,7 @@ async def confirm_set_new_pin(
return await confirm_action(
ctx,
br_type,
title=title,
title,
description="\n".join(information),
verb=verb,
hold=True,

View File

@ -1110,7 +1110,6 @@ async def request_pin_on_device(
wrong_pin=wrong_pin,
)
)
while True:
result = await ctx.wait(dialog)
if result is CANCELLED:
raise PinCancelled

View File

@ -992,7 +992,8 @@ static secbool decrypt_dek(const uint8_t *kek, const uint8_t *keiv) {
static void ensure_not_wipe_code(const uint8_t *pin, size_t pin_len) {
if (sectrue != is_not_wipe_code(pin, pin_len)) {
storage_wipe();
// TODO: need to account for smaller model R - smaller font and different copy
// TODO: need to account for smaller model R - smaller font and different
// copy
error_shutdown("You have entered the", "wipe code. All private",
"data has been erased.", NULL);
}

View File

@ -333,6 +333,7 @@ def test_signmessage_pagination(client: Client, message: str):
br = yield
# TODO: try load the message_read the same way as in model T
if br.pages is not None:
for i in range(br.pages):
if i < br.pages - 1:
client.debug.swipe_up()

View File

@ -90,7 +90,7 @@ def test_cancel_on_paginated(client: Client):
resp = client._raw_read()
assert isinstance(resp, m.ButtonRequest)
assert resp.pages is not None
# assert resp.pages is not None
client._raw_write(m.ButtonAck())
client._raw_write(m.Cancel())