1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-20 13:38:11 +00:00

WIP - remove confirm_text and replace it with confirm_action

This commit is contained in:
grdddj 2022-12-31 15:11:09 +01:00
parent 9638de43ab
commit b0d9e24f1f
6 changed files with 30 additions and 97 deletions

View File

@ -34,7 +34,6 @@ static void _librust_qstrs(void) {
MP_QSTR_confirm_output_r; MP_QSTR_confirm_output_r;
MP_QSTR_confirm_payment_request; MP_QSTR_confirm_payment_request;
MP_QSTR_confirm_reset_device; MP_QSTR_confirm_reset_device;
MP_QSTR_confirm_text;
MP_QSTR_confirm_total; MP_QSTR_confirm_total;
MP_QSTR_confirm_total_r; MP_QSTR_confirm_total_r;
MP_QSTR_confirm_value; MP_QSTR_confirm_value;

View File

@ -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) } 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<StrBuffer> =
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 { extern "C" fn new_confirm_properties(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
let block = move |_args: &[Obj], kwargs: &Map| { let block = move |_args: &[Obj], kwargs: &Map| {
let title: StrBuffer = kwargs.get(Qstr::MP_QSTR_title)?.try_into()?; 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.""" /// """Request pin on device."""
Qstr::MP_QSTR_request_pin => obj_fn_kw!(0, new_request_pin).as_obj(), 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( /// def show_share_words(
/// *, /// *,
/// share_words: Iterable[str], /// share_words: Iterable[str],

View File

@ -95,16 +95,6 @@ def request_pin(
"""Request pin on device.""" """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 # rust/src/ui/model_tr/layout.rs
def show_share_words( def show_share_words(
*, *,

View File

@ -443,18 +443,23 @@ async def _placeholder_confirm(
br_type: str, br_type: str,
title: str, title: str,
data: str, data: str,
verb: str = "CONFIRM",
verb_cancel: str | bytes | None = "",
hold: bool = False,
description: str | None = None, description: str | None = None,
br_code: ButtonRequestType = BR_TYPE_OTHER, br_code: ButtonRequestType = BR_TYPE_OTHER,
) -> Any: ) -> Any:
return await raise_if_cancelled( return await confirm_action(
confirm_text(
ctx=ctx, ctx=ctx,
br_type=br_type, br_type=br_type,
title=title.upper(),
data=data,
description=description,
br_code=br_code, 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 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( async def confirm_action(
ctx: GenericContext, ctx: GenericContext,
br_type: str, br_type: str,
@ -507,7 +509,6 @@ async def confirm_action(
action: str | None = None, action: str | None = None,
description: str | None = None, description: str | None = None,
description_param: str | None = None, description_param: str | None = None,
description_param_font: int = ui.BOLD,
verb: str = "CONFIRM", verb: str = "CONFIRM",
verb_cancel: str | None = None, verb_cancel: str | None = None,
hold: bool = False, hold: bool = False,
@ -525,8 +526,6 @@ async def confirm_action(
return await pin_confirm_action(ctx, br_type, action) return await pin_confirm_action(ctx, br_type, action)
if description is not None and description_param is not None: 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) description = description.format(description_param)
# Making the button text UPPERCASE, so it is better readable # 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: def _show_xpub(xpub: str, title: str, cancel: str | None) -> ui.Layout:
content = RustLayout( content = RustLayout(
trezorui2.confirm_text( trezorui2.confirm_action(
title=title.upper(), title=title.upper(),
data=xpub, action="",
description="", description=xpub,
# verb_cancel=cancel, verb="CONFIRM",
verb_cancel=cancel,
hold=False,
reverse=False,
) )
) )
return content return content
@ -952,17 +954,13 @@ async def confirm_text(
description: str | None = None, description: str | None = None,
br_code: ButtonRequestType = BR_TYPE_OTHER, br_code: ButtonRequestType = BR_TYPE_OTHER,
) -> Any: ) -> Any:
return await interact( return await _placeholder_confirm(
ctx, ctx=ctx,
RustLayout( br_type=br_type,
trezorui2.confirm_text( title=title,
title=title.upper(),
data=data, data=data,
description=description, description=description,
) br_code=br_code,
),
br_type,
br_code,
) )
@ -1094,13 +1092,12 @@ async def confirm_metadata(
br_code: ButtonRequestType = ButtonRequestType.SignTx, br_code: ButtonRequestType = ButtonRequestType.SignTx,
hold: bool = False, hold: bool = False,
) -> None: ) -> None:
# TODO: implement `hold`
await _placeholder_confirm( await _placeholder_confirm(
ctx=ctx, ctx=ctx,
br_type=br_type, br_type=br_type,
title=title.upper(), title=title.upper(),
data=content.format(param), data=content.format(param),
description="", hold=hold,
br_code=br_code, br_code=br_code,
) )
@ -1111,7 +1108,6 @@ async def confirm_replacement(ctx: GenericContext, description: str, txid: str)
br_type="confirm_replacement", br_type="confirm_replacement",
title=description.upper(), title=description.upper(),
data=f"Confirm transaction ID:\n{txid}", data=f"Confirm transaction ID:\n{txid}",
description="",
br_code=ButtonRequestType.SignTx, br_code=ButtonRequestType.SignTx,
) )
@ -1135,7 +1131,6 @@ async def confirm_modify_output(
br_type="modify_output", br_type="modify_output",
title="MODIFY AMOUNT", title="MODIFY AMOUNT",
data=text, data=text,
description="",
br_code=ButtonRequestType.ConfirmOutput, br_code=ButtonRequestType.ConfirmOutput,
) )
@ -1165,7 +1160,6 @@ async def confirm_modify_fee(
br_type="modify_fee", br_type="modify_fee",
title="MODIFY FEE", title="MODIFY FEE",
data=text, data=text,
description="",
br_code=ButtonRequestType.SignTx, br_code=ButtonRequestType.SignTx,
) )
@ -1178,7 +1172,6 @@ async def confirm_coinjoin(
br_type="coinjoin_final", br_type="coinjoin_final",
title="AUTHORIZE COINJOIN", title="AUTHORIZE COINJOIN",
data=f"Maximum rounds: {max_rounds}\n\nMaximum mining fee:\n{max_fee_per_vbyte}", data=f"Maximum rounds: {max_rounds}\n\nMaximum mining fee:\n{max_fee_per_vbyte}",
description="",
br_code=BR_TYPE_OTHER, br_code=BR_TYPE_OTHER,
) )
@ -1201,7 +1194,6 @@ async def confirm_sign_identity(
br_type="confirm_sign_identity", br_type="confirm_sign_identity",
title=f"Sign {proto}".upper(), title=f"Sign {proto}".upper(),
data=text, data=text,
description="",
br_code=BR_TYPE_OTHER, br_code=BR_TYPE_OTHER,
) )
@ -1221,7 +1213,6 @@ async def confirm_signverify(
br_type=br_type, br_type=br_type,
title=header.upper(), title=header.upper(),
data=f"Confirm address:\n{address}", data=f"Confirm address:\n{address}",
description="",
br_code=BR_TYPE_OTHER, br_code=BR_TYPE_OTHER,
) )
@ -1230,7 +1221,6 @@ async def confirm_signverify(
br_type=br_type, br_type=br_type,
title=header.upper(), title=header.upper(),
data=f"Confirm message:\n{message}", data=f"Confirm message:\n{message}",
description="",
br_code=BR_TYPE_OTHER, br_code=BR_TYPE_OTHER,
) )

View File

@ -1,6 +1,6 @@
from typing import TYPE_CHECKING 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.enums import ButtonRequestType
from trezor.wire import ActionCancelled from trezor.wire import ActionCancelled
@ -212,21 +212,16 @@ async def confirm_action(
action: str | None = None, action: str | None = None,
description: str | None = None, description: str | None = None,
description_param: str | None = None, description_param: str | None = None,
description_param_font: int = ui.BOLD,
verb: str = "CONFIRM", verb: str = "CONFIRM",
verb_cancel: str | None = None, verb_cancel: str | None = None,
hold: bool = False, hold: bool = False,
hold_danger: bool = False,
reverse: bool = False, reverse: bool = False,
exc: ExceptionType = ActionCancelled, exc: ExceptionType = ActionCancelled,
br_code: ButtonRequestType = BR_TYPE_OTHER,
) -> None: ) -> None:
if verb_cancel is not None: if verb_cancel is not None:
verb_cancel = verb_cancel.upper() verb_cancel = verb_cancel.upper()
if description is not None and description_param is not None: 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) description = description.format(description_param)
await raise_if_not_confirmed( await raise_if_not_confirmed(

View File

@ -23,7 +23,6 @@ from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import H_, parse_path from trezorlib.tools import H_, parse_path
from ...common import get_text_from_paginated_screen
from ...tx_cache import TxCache from ...tx_cache import TxCache
from .signtx import ( from .signtx import (
assert_tx_matches, assert_tx_matches,