Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

confirm_blob housekeeping #4372

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion core/embed/rust/librust_qstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ static void _librust_qstrs(void) {
MP_QSTR_confirm_total__sending_from_account;
MP_QSTR_confirm_total__title_fee;
MP_QSTR_confirm_total__title_sending_from;
MP_QSTR_confirm_value;
MP_QSTR_confirm_with_info;
MP_QSTR_continue_recovery_homepage;
MP_QSTR_count;
Expand Down
66 changes: 0 additions & 66 deletions core/embed/rust/src/ui/api/firmware_micropython.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,53 +373,6 @@ extern "C" fn new_confirm_summary(n_args: usize, args: *const Obj, kwargs: *mut
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
}

extern "C" fn new_confirm_value(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
let block = move |_args: &[Obj], kwargs: &Map| {
let title: TString = kwargs.get(Qstr::MP_QSTR_title)?.try_into()?;
let subtitle: Option<TString> = kwargs
.get(Qstr::MP_QSTR_subtitle)
.unwrap_or_else(|_| Obj::const_none())
.try_into_option()?;
let description: Option<TString> = kwargs
.get(Qstr::MP_QSTR_description)
.unwrap_or_else(|_| Obj::const_none())
.try_into_option()?;
let value: Obj = kwargs.get(Qstr::MP_QSTR_value)?;
let info_button: bool = kwargs.get_or(Qstr::MP_QSTR_info_button, false)?;
let verb: Option<TString> = kwargs
.get(Qstr::MP_QSTR_verb)
.unwrap_or_else(|_| Obj::const_none())
.try_into_option()?;
let verb_info: Option<TString> = kwargs
.get(Qstr::MP_QSTR_verb_info)
.unwrap_or_else(|_| Obj::const_none())
.try_into_option()?;
let verb_cancel: Option<TString> = kwargs
.get(Qstr::MP_QSTR_verb_cancel)
.unwrap_or_else(|_| Obj::const_none())
.try_into_option()?;
let hold: bool = kwargs.get_or(Qstr::MP_QSTR_hold, false)?;
let chunkify: bool = kwargs.get_or(Qstr::MP_QSTR_chunkify, false)?;
let text_mono: bool = kwargs.get_or(Qstr::MP_QSTR_text_mono, true)?;

let layout_obj = ModelUI::confirm_value(
title,
value,
description,
subtitle,
verb,
verb_info,
verb_cancel,
info_button,
hold,
chunkify,
text_mono,
)?;
Ok(layout_obj.into())
};
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
}

extern "C" fn new_confirm_with_info(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
let block = move |_args: &[Obj], kwargs: &Map| {
let title: TString = kwargs.get(Qstr::MP_QSTR_title)?.try_into()?;
Expand Down Expand Up @@ -1175,12 +1128,10 @@ pub static mp_module_trezorui_api: Module = obj_module! {
/// title: str,
/// data: str | bytes,
/// description: str | None,
/// text_mono: bool = True,
/// extra: str | None = None,
/// subtitle: str | None = None,
/// verb: str | None = None,
/// verb_cancel: str | None = None,
/// verb_info: str | None = None,
/// info: bool = True,
/// hold: bool = False,
/// chunkify: bool = False,
Expand Down Expand Up @@ -1312,23 +1263,6 @@ pub static mp_module_trezorui_api: Module = obj_module! {
/// """Confirm summary of a transaction."""
Qstr::MP_QSTR_confirm_summary => obj_fn_kw!(0, new_confirm_summary).as_obj(),

/// def confirm_value(
/// *,
/// title: str,
/// value: str,
/// description: str | None,
/// subtitle: str | None,
/// verb: str | None = None,
/// verb_info: str | None = None,
/// verb_cancel: str | None = None,
/// info_button: bool = False,
/// hold: bool = False,
/// chunkify: bool = False,
/// text_mono: bool = True,
/// ) -> LayoutObj[UiResult]:
/// """Confirm value. Merge of confirm_total and confirm_output."""
Qstr::MP_QSTR_confirm_value => obj_fn_kw!(0, new_confirm_value).as_obj(),

/// def confirm_with_info(
/// *,
/// title: str,
Expand Down
31 changes: 0 additions & 31 deletions core/embed/rust/src/ui/model_mercury/ui_firmware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,37 +438,6 @@ impl FirmwareUI for UIMercury {
Ok(flow)
}

fn confirm_value(
title: TString<'static>,
value: Obj,
description: Option<TString<'static>>,
subtitle: Option<TString<'static>>,
verb: Option<TString<'static>>,
verb_info: Option<TString<'static>>,
verb_cancel: Option<TString<'static>>,
info_button: bool,
hold: bool,
chunkify: bool,
text_mono: bool,
) -> Result<Gc<LayoutObj>, Error> {
ConfirmBlobParams::new(title, value, description)
.with_subtitle(subtitle)
.with_verb(verb)
.with_verb_cancel(verb_cancel)
.with_verb_info(if info_button {
Some(verb_info.unwrap_or(TR::words__title_information.into()))
} else {
None
})
.with_chunkify(chunkify)
.with_text_mono(text_mono)
.with_prompt(hold)
.with_hold(hold)
.into_flow()
.and_then(LayoutObj::new_root)
.map(Into::into)
}

fn confirm_with_info(
title: TString<'static>,
button: TString<'static>,
Expand Down
34 changes: 2 additions & 32 deletions core/embed/rust/src/ui/model_tr/ui_firmware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ impl FirmwareUI for UIModelTR {
title: TString<'static>,
data: Obj,
description: Option<TString<'static>>,
_text_mono: bool,
text_mono: bool,
extra: Option<TString<'static>>,
_subtitle: Option<TString<'static>>,
verb: Option<TString<'static>>,
verb_cancel: Option<TString<'static>>,
_verb_info: Option<TString<'static>>,
verb_info: Option<TString<'static>>,
_info: bool,
hold: bool,
chunkify: bool,
Expand Down Expand Up @@ -593,36 +593,6 @@ impl FirmwareUI for UIModelTR {
Ok(layout)
}

fn confirm_value(
title: TString<'static>,
value: Obj,
description: Option<TString<'static>>,
_subtitle: Option<TString<'static>>,
verb: Option<TString<'static>>,
_verb_info: Option<TString<'static>>,
verb_cancel: Option<TString<'static>>,
_info_button: bool,
hold: bool,
_chunkify: bool,
_text_mono: bool,
) -> Result<Gc<LayoutObj>, Error> {
let value: TString = value.try_into()?;
let description = description.unwrap_or("".into());
let paragraphs = Paragraphs::new([
Paragraph::new(&theme::TEXT_BOLD, description),
Paragraph::new(&theme::TEXT_MONO, value),
]);

let layout = content_in_button_page(
title,
paragraphs,
verb.unwrap_or(TR::buttons__confirm.into()),
verb_cancel,
hold,
)?;
LayoutObj::new_root(layout)
}

fn confirm_with_info(
title: TString<'static>,
button: TString<'static>,
Expand Down
26 changes: 3 additions & 23 deletions core/embed/rust/src/ui/model_tt/ui_firmware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ impl FirmwareUI for UIModelTT {
description: Option<TString<'static>>,
text_mono: bool,
extra: Option<TString<'static>>,
_subtitle: Option<TString<'static>>,
subtitle: Option<TString<'static>>,
verb: Option<TString<'static>>,
verb_cancel: Option<TString<'static>>,
_verb_info: Option<TString<'static>>,
verb_info: Option<TString<'static>>,
info: bool,
hold: bool,
chunkify: bool,
Expand All @@ -120,6 +120,7 @@ impl FirmwareUI for UIModelTT {
) -> Result<Gc<LayoutObj>, Error> {
ConfirmBlobParams::new(title, data, description, verb, verb_cancel, hold)
.with_text_mono(text_mono)
.with_subtitle(subtitle)
.with_extra(extra)
.with_chunkify(chunkify)
.with_info_button(info)
Expand Down Expand Up @@ -450,27 +451,6 @@ impl FirmwareUI for UIModelTT {
Ok(layout)
}

fn confirm_value(
title: TString<'static>,
value: Obj,
description: Option<TString<'static>>,
subtitle: Option<TString<'static>>,
verb: Option<TString<'static>>,
_verb_info: Option<TString<'static>>,
verb_cancel: Option<TString<'static>>,
info_button: bool,
hold: bool,
chunkify: bool,
text_mono: bool,
) -> Result<Gc<LayoutObj>, Error> {
ConfirmBlobParams::new(title, value, description, verb, verb_cancel, hold)
.with_subtitle(subtitle)
.with_info_button(info_button)
.with_chunkify(chunkify)
.with_text_mono(text_mono)
.into_layout()
}

fn confirm_with_info(
title: TString<'static>,
button: TString<'static>,
Expand Down
15 changes: 0 additions & 15 deletions core/embed/rust/src/ui/ui_firmware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,6 @@ pub trait FirmwareUI {
verb_cancel: Option<TString<'static>>,
) -> Result<impl LayoutMaybeTrace, Error>;

#[allow(clippy::too_many_arguments)]
fn confirm_value(
title: TString<'static>,
value: Obj, // TODO: replace Obj
description: Option<TString<'static>>,
subtitle: Option<TString<'static>>,
verb: Option<TString<'static>>,
verb_info: Option<TString<'static>>,
verb_cancel: Option<TString<'static>>,
info_button: bool,
hold: bool,
chunkify: bool,
text_mono: bool,
) -> Result<Gc<LayoutObj>, Error>; // TODO: return LayoutMaybeTrace

fn confirm_with_info(
title: TString<'static>,
button: TString<'static>,
Expand Down
20 changes: 0 additions & 20 deletions core/mocks/generated/trezorui_api.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,10 @@ def confirm_blob(
title: str,
data: str | bytes,
description: str | None,
text_mono: bool = True,
extra: str | None = None,
subtitle: str | None = None,
verb: str | None = None,
verb_cancel: str | None = None,
verb_info: str | None = None,
info: bool = True,
hold: bool = False,
chunkify: bool = False,
Expand Down Expand Up @@ -265,24 +263,6 @@ def confirm_summary(
"""Confirm summary of a transaction."""


# rust/src/ui/api/firmware_micropython.rs
def confirm_value(
*,
title: str,
value: str,
description: str | None,
subtitle: str | None,
verb: str | None = None,
verb_info: str | None = None,
verb_cancel: str | None = None,
info_button: bool = False,
hold: bool = False,
chunkify: bool = False,
text_mono: bool = True,
) -> LayoutObj[UiResult]:
"""Confirm value. Merge of confirm_total and confirm_output."""


# rust/src/ui/api/firmware_micropython.rs
def confirm_with_info(
*,
Expand Down
18 changes: 7 additions & 11 deletions core/src/trezor/ui/layouts/mercury/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ def confirm_blob(
title: str,
data: bytes | str,
description: str | None = None,
text_mono: bool = True,
subtitle: str | None = None,
verb: str | None = None,
verb_cancel: str | None = None,
Expand Down Expand Up @@ -532,7 +531,6 @@ def confirm_blob(
title=title,
data=data,
description=description,
text_mono=text_mono,
subtitle=subtitle,
verb=verb,
verb_cancel=verb_cancel,
Expand Down Expand Up @@ -634,16 +632,15 @@ def confirm_value(
)

return with_info(
trezorui_api.confirm_value(
trezorui_api.confirm_blob(
title=title,
subtitle=subtitle,
data=value,
description=description,
value=value,
subtitle=subtitle,
verb=verb,
info=bool(info_items),
hold=hold,
info_button=bool(info_items),
chunkify=chunkify,
text_mono=value_text_mono,
),
info_layout,
br_name,
Expand Down Expand Up @@ -1031,14 +1028,13 @@ async def confirm_signverify(
address_title = TR.sign_message__confirm_address
br_name = "sign_message"

address_layout = trezorui_api.confirm_value(
address_layout = trezorui_api.confirm_blob(
title=address_title,
subtitle=None,
data=address,
description="",
value=address,
verb=TR.buttons__continue,
verb_info=TR.buttons__more_info,
info_button=True,
info=True,
chunkify=chunkify,
)

Expand Down
10 changes: 5 additions & 5 deletions core/src/trezor/ui/layouts/tr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,10 @@ async def confirm_output(

try:
await interact(
trezorui_api.confirm_value(
trezorui_api.confirm_blob(
title=amount_title,
value=amount,
data=amount,
description=None,
subtitle=None,
verb_cancel="^",
verb=TR.buttons__confirm,
),
Expand Down Expand Up @@ -746,12 +745,13 @@ async def confirm_value(

if info_items is None:
return await raise_if_not_confirmed(
trezorui_api.confirm_value( # type: ignore [Argument missing for parameter "subtitle"]
trezorui_api.confirm_blob( # type: ignore [Argument missing for parameter "subtitle"]
title=title,
data=value,
description=description,
value=value,
verb=verb or TR.buttons__hold_to_confirm,
verb_cancel="",
info=False,
hold=hold,
),
br_name,
Expand Down
Loading
Loading