From b0d9e24f1fe749d7dc3874b4bba69d3a61810d83 Mon Sep 17 00:00:00 2001 From: grdddj Date: Sat, 31 Dec 2022 15:11:09 +0100 Subject: [PATCH] WIP - remove confirm_text and replace it with confirm_action --- core/embed/rust/librust_qstr.h | 1 - core/embed/rust/src/ui/model_tr/layout.rs | 40 ------------ core/mocks/generated/trezorui2.pyi | 10 --- core/src/trezor/ui/layouts/tr/__init__.py | 68 +++++++++----------- core/src/trezor/ui/layouts/tt_v2/__init__.py | 7 +- tests/device_tests/bitcoin/test_signtx.py | 1 - 6 files changed, 30 insertions(+), 97 deletions(-) diff --git a/core/embed/rust/librust_qstr.h b/core/embed/rust/librust_qstr.h index 62647cd95b..ad9a53301e 100644 --- a/core/embed/rust/librust_qstr.h +++ b/core/embed/rust/librust_qstr.h @@ -34,7 +34,6 @@ static void _librust_qstrs(void) { MP_QSTR_confirm_output_r; MP_QSTR_confirm_payment_request; MP_QSTR_confirm_reset_device; - MP_QSTR_confirm_text; MP_QSTR_confirm_total; MP_QSTR_confirm_total_r; MP_QSTR_confirm_value; diff --git a/core/embed/rust/src/ui/model_tr/layout.rs b/core/embed/rust/src/ui/model_tr/layout.rs index 3ffc773183..fcf2804d84 100644 --- a/core/embed/rust/src/ui/model_tr/layout.rs +++ b/core/embed/rust/src/ui/model_tr/layout.rs @@ -266,37 +266,6 @@ extern "C" fn new_confirm_action(n_args: usize, args: *const Obj, kwargs: *mut M unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } } -extern "C" fn new_confirm_text(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj { - // TODO: should be deleted and replaced by confirm_action with some default - // parameters - - let block = |_args: &[Obj], kwargs: &Map| { - let title: StrBuffer = kwargs.get(Qstr::MP_QSTR_title)?.try_into()?; - let data: StrBuffer = kwargs.get(Qstr::MP_QSTR_data)?.try_into()?; - let description: Option = - kwargs.get(Qstr::MP_QSTR_description)?.try_into_option()?; - - // TODO: could be replaced by Flow with one element after it supports pagination - - let content = ButtonPage::new_str( - Paragraphs::new([ - Paragraph::new(&theme::TEXT_MONO, description.unwrap_or_default()), - Paragraph::new(&theme::TEXT_BOLD, data), - ]), - theme::BG, - ); - - let obj = if title.as_ref().is_empty() { - LayoutObj::new(content)? - } else { - LayoutObj::new(Frame::new(title, content))? - }; - - Ok(obj.into()) - }; - unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } -} - extern "C" fn new_confirm_properties(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj { let block = move |_args: &[Obj], kwargs: &Map| { let title: StrBuffer = kwargs.get(Qstr::MP_QSTR_title)?.try_into()?; @@ -856,15 +825,6 @@ pub static mp_module_trezorui2: Module = obj_module! { /// """Request pin on device.""" Qstr::MP_QSTR_request_pin => obj_fn_kw!(0, new_request_pin).as_obj(), - /// def confirm_text( - /// *, - /// title: str, - /// data: str, - /// description: str | None, - /// ) -> object: - /// """Confirm text.""" - Qstr::MP_QSTR_confirm_text => obj_fn_kw!(0, new_confirm_text).as_obj(), - /// def show_share_words( /// *, /// share_words: Iterable[str], diff --git a/core/mocks/generated/trezorui2.pyi b/core/mocks/generated/trezorui2.pyi index 0703a0ace9..6eaf896ea5 100644 --- a/core/mocks/generated/trezorui2.pyi +++ b/core/mocks/generated/trezorui2.pyi @@ -95,16 +95,6 @@ def request_pin( """Request pin on device.""" -# rust/src/ui/model_tr/layout.rs -def confirm_text( - *, - title: str, - data: str, - description: str | None, -) -> object: - """Confirm text.""" - - # rust/src/ui/model_tr/layout.rs def show_share_words( *, diff --git a/core/src/trezor/ui/layouts/tr/__init__.py b/core/src/trezor/ui/layouts/tr/__init__.py index aa089ab9d6..7d347266c1 100644 --- a/core/src/trezor/ui/layouts/tr/__init__.py +++ b/core/src/trezor/ui/layouts/tr/__init__.py @@ -443,18 +443,23 @@ async def _placeholder_confirm( br_type: str, title: str, data: str, + verb: str = "CONFIRM", + verb_cancel: str | bytes | None = "", + hold: bool = False, description: str | None = None, br_code: ButtonRequestType = BR_TYPE_OTHER, ) -> Any: - return await raise_if_cancelled( - confirm_text( - ctx=ctx, - br_type=br_type, - title=title.upper(), - data=data, - description=description, - br_code=br_code, - ) + return await confirm_action( + ctx=ctx, + br_type=br_type, + br_code=br_code, + title=title.upper(), + action=data, + description=description, + verb=verb, + verb_cancel=verb_cancel, + hold=hold, + reverse=True, ) @@ -497,9 +502,6 @@ async def raise_if_cancelled(a: Awaitable[T], exc: Any = ActionCancelled) -> T: return result -# TODO: probably make special version of some `action` and -# `description` strings for model R, as those for model T -# have newlines at random places (suitable for T). async def confirm_action( ctx: GenericContext, br_type: str, @@ -507,7 +509,6 @@ async def confirm_action( action: str | None = None, description: str | None = None, description_param: str | None = None, - description_param_font: int = ui.BOLD, verb: str = "CONFIRM", verb_cancel: str | None = None, hold: bool = False, @@ -525,8 +526,6 @@ async def confirm_action( return await pin_confirm_action(ctx, br_type, action) if description is not None and description_param is not None: - if description_param_font != ui.BOLD: - log.error(__name__, "confirm_action description_param_font not implemented") description = description.format(description_param) # Making the button text UPPERCASE, so it is better readable @@ -629,11 +628,14 @@ async def confirm_path_warning( def _show_xpub(xpub: str, title: str, cancel: str | None) -> ui.Layout: content = RustLayout( - trezorui2.confirm_text( + trezorui2.confirm_action( title=title.upper(), - data=xpub, - description="", - # verb_cancel=cancel, + action="", + description=xpub, + verb="CONFIRM", + verb_cancel=cancel, + hold=False, + reverse=False, ) ) return content @@ -952,17 +954,13 @@ async def confirm_text( description: str | None = None, br_code: ButtonRequestType = BR_TYPE_OTHER, ) -> Any: - return await interact( - ctx, - RustLayout( - trezorui2.confirm_text( - title=title.upper(), - data=data, - description=description, - ) - ), - br_type, - br_code, + return await _placeholder_confirm( + ctx=ctx, + br_type=br_type, + title=title, + data=data, + description=description, + br_code=br_code, ) @@ -1094,13 +1092,12 @@ async def confirm_metadata( br_code: ButtonRequestType = ButtonRequestType.SignTx, hold: bool = False, ) -> None: - # TODO: implement `hold` await _placeholder_confirm( ctx=ctx, br_type=br_type, title=title.upper(), data=content.format(param), - description="", + hold=hold, br_code=br_code, ) @@ -1111,7 +1108,6 @@ async def confirm_replacement(ctx: GenericContext, description: str, txid: str) br_type="confirm_replacement", title=description.upper(), data=f"Confirm transaction ID:\n{txid}", - description="", br_code=ButtonRequestType.SignTx, ) @@ -1135,7 +1131,6 @@ async def confirm_modify_output( br_type="modify_output", title="MODIFY AMOUNT", data=text, - description="", br_code=ButtonRequestType.ConfirmOutput, ) @@ -1165,7 +1160,6 @@ async def confirm_modify_fee( br_type="modify_fee", title="MODIFY FEE", data=text, - description="", br_code=ButtonRequestType.SignTx, ) @@ -1178,7 +1172,6 @@ async def confirm_coinjoin( br_type="coinjoin_final", title="AUTHORIZE COINJOIN", data=f"Maximum rounds: {max_rounds}\n\nMaximum mining fee:\n{max_fee_per_vbyte}", - description="", br_code=BR_TYPE_OTHER, ) @@ -1201,7 +1194,6 @@ async def confirm_sign_identity( br_type="confirm_sign_identity", title=f"Sign {proto}".upper(), data=text, - description="", br_code=BR_TYPE_OTHER, ) @@ -1221,7 +1213,6 @@ async def confirm_signverify( br_type=br_type, title=header.upper(), data=f"Confirm address:\n{address}", - description="", br_code=BR_TYPE_OTHER, ) @@ -1230,7 +1221,6 @@ async def confirm_signverify( br_type=br_type, title=header.upper(), data=f"Confirm message:\n{message}", - description="", br_code=BR_TYPE_OTHER, ) diff --git a/core/src/trezor/ui/layouts/tt_v2/__init__.py b/core/src/trezor/ui/layouts/tt_v2/__init__.py index ee41890742..8f2c9701e2 100644 --- a/core/src/trezor/ui/layouts/tt_v2/__init__.py +++ b/core/src/trezor/ui/layouts/tt_v2/__init__.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING -from trezor import io, log, loop, ui +from trezor import io, loop, ui from trezor.enums import ButtonRequestType from trezor.wire import ActionCancelled @@ -212,21 +212,16 @@ async def confirm_action( action: str | None = None, description: str | None = None, description_param: str | None = None, - description_param_font: int = ui.BOLD, verb: str = "CONFIRM", verb_cancel: str | None = None, hold: bool = False, - hold_danger: bool = False, reverse: bool = False, exc: ExceptionType = ActionCancelled, - br_code: ButtonRequestType = BR_TYPE_OTHER, ) -> None: if verb_cancel is not None: verb_cancel = verb_cancel.upper() if description is not None and description_param is not None: - if description_param_font != ui.BOLD: - log.error(__name__, "confirm_action description_param_font not implemented") description = description.format(description_param) await raise_if_not_confirmed( diff --git a/tests/device_tests/bitcoin/test_signtx.py b/tests/device_tests/bitcoin/test_signtx.py index 913810476e..8ecf8f90c6 100644 --- a/tests/device_tests/bitcoin/test_signtx.py +++ b/tests/device_tests/bitcoin/test_signtx.py @@ -23,7 +23,6 @@ from trezorlib.debuglink import TrezorClientDebugLink as Client from trezorlib.exceptions import TrezorFailure from trezorlib.tools import H_, parse_path -from ...common import get_text_from_paginated_screen from ...tx_cache import TxCache from .signtx import ( assert_tx_matches,