mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-03 12:00:59 +00:00
refactor(core): consistent use of confirm_address
- use `confirm_address` trait fn in both `confirm_output` and `confirm_address` layout functions [no changelog]
This commit is contained in:
parent
7e1f160dba
commit
e9ecbbc5e8
@ -63,6 +63,7 @@ static void _librust_qstrs(void) {
|
||||
MP_QSTR_address_details__derivation_path_colon;
|
||||
MP_QSTR_address_details__title_receive_address;
|
||||
MP_QSTR_address_details__title_receiving_to;
|
||||
MP_QSTR_address_label;
|
||||
MP_QSTR_address_qr;
|
||||
MP_QSTR_address_title;
|
||||
MP_QSTR_allow_cancel;
|
||||
|
@ -89,23 +89,21 @@ extern "C" fn new_confirm_action(n_args: usize, args: *const Obj, kwargs: *mut M
|
||||
extern "C" fn new_confirm_address(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 data: Obj = kwargs.get(Qstr::MP_QSTR_data)?;
|
||||
let description: Option<TString> = kwargs
|
||||
.get(Qstr::MP_QSTR_description)
|
||||
.unwrap_or_else(|_| Obj::const_none())
|
||||
.try_into_option()?;
|
||||
let extra: Option<TString> = kwargs
|
||||
.get(Qstr::MP_QSTR_extra)
|
||||
let address: Obj = kwargs.get(Qstr::MP_QSTR_address)?;
|
||||
let address_label: Option<TString> = kwargs
|
||||
.get(Qstr::MP_QSTR_address_label)
|
||||
.unwrap_or_else(|_| Obj::const_none())
|
||||
.try_into_option()?;
|
||||
let verb: Option<TString> = kwargs
|
||||
.get(Qstr::MP_QSTR_verb)
|
||||
.unwrap_or_else(|_| Obj::const_none())
|
||||
.try_into_option()?;
|
||||
let info_button: bool = kwargs.get_or(Qstr::MP_QSTR_info_button, false)?;
|
||||
let chunkify: bool = kwargs.get_or(Qstr::MP_QSTR_chunkify, false)?;
|
||||
|
||||
let layout = ModelUI::confirm_address(title, data, description, extra, verb, chunkify)?;
|
||||
Ok(LayoutObj::new_root(layout)?.into())
|
||||
let layout_obj =
|
||||
ModelUI::confirm_address(title, address, address_label, verb, info_button, chunkify)?;
|
||||
Ok(layout_obj.into())
|
||||
};
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
@ -1163,10 +1161,10 @@ pub static mp_module_trezorui_api: Module = obj_module! {
|
||||
/// def confirm_address(
|
||||
/// *,
|
||||
/// title: str,
|
||||
/// data: str | bytes,
|
||||
/// description: str | None,
|
||||
/// extra: str | None,
|
||||
/// address: str | bytes,
|
||||
/// address_label: str | None = None,
|
||||
/// verb: str | None = None,
|
||||
/// info_button: bool = False,
|
||||
/// chunkify: bool = False,
|
||||
/// ) -> LayoutObj[UiResult]:
|
||||
/// """Confirm address."""
|
||||
|
@ -75,16 +75,14 @@ impl FirmwareUI for UIMercury {
|
||||
|
||||
fn confirm_address(
|
||||
_title: TString<'static>,
|
||||
_data: Obj,
|
||||
_description: Option<TString<'static>>,
|
||||
_extra: Option<TString<'static>>,
|
||||
_address: Obj,
|
||||
_address_label: Option<TString<'static>>,
|
||||
_verb: Option<TString<'static>>,
|
||||
_info_button: bool,
|
||||
_chunkify: bool,
|
||||
) -> Result<impl LayoutMaybeTrace, Error> {
|
||||
) -> Result<Gc<LayoutObj>, Error> {
|
||||
// confirm_value is used instead
|
||||
Err::<RootComponent<Empty, ModelUI>, Error>(Error::ValueError(
|
||||
c"confirm_address not implemented",
|
||||
))
|
||||
Err::<Gc<LayoutObj>, Error>(Error::ValueError(c"confirm_address not implemented"))
|
||||
}
|
||||
|
||||
fn confirm_blob(
|
||||
|
@ -89,34 +89,50 @@ impl FirmwareUI for UIModelTR {
|
||||
|
||||
fn confirm_address(
|
||||
title: TString<'static>,
|
||||
data: Obj,
|
||||
_description: Option<TString<'static>>,
|
||||
_extra: Option<TString<'static>>,
|
||||
address: Obj,
|
||||
address_label: Option<TString<'static>>,
|
||||
verb: Option<TString<'static>>,
|
||||
info_button: bool,
|
||||
chunkify: bool,
|
||||
) -> Result<impl LayoutMaybeTrace, Error> {
|
||||
) -> Result<Gc<LayoutObj>, Error> {
|
||||
let verb = verb.unwrap_or(TR::buttons__confirm.into());
|
||||
let address: TString = data.try_into()?;
|
||||
let address: TString = address.try_into()?;
|
||||
|
||||
let get_page = move |page_index| {
|
||||
assert!(page_index == 0);
|
||||
|
||||
let btn_layout = ButtonLayout::cancel_armed_info(verb);
|
||||
let btn_actions = ButtonActions::cancel_confirm_info();
|
||||
let style = if chunkify {
|
||||
// Chunkifying the address into smaller pieces when requested
|
||||
theme::TEXT_MONO_ADDRESS_CHUNKS
|
||||
let (btn_layout, btn_actions) = if info_button {
|
||||
(
|
||||
ButtonLayout::cancel_armed_info(verb),
|
||||
ButtonActions::cancel_confirm_info(),
|
||||
)
|
||||
} else {
|
||||
theme::TEXT_MONO_DATA
|
||||
(
|
||||
ButtonLayout::cancel_none_text(verb),
|
||||
ButtonActions::cancel_none_confirm(),
|
||||
)
|
||||
};
|
||||
let ops = OpTextLayout::new(style).text_mono(address);
|
||||
let mut ops = OpTextLayout::new(theme::TEXT_MONO_DATA);
|
||||
if let Some(label) = address_label {
|
||||
// NOTE: need to explicitly turn off the chunkification before rendering the
|
||||
// address label (for some reason it does not help to turn it off after
|
||||
// rendering the chunks)
|
||||
if chunkify {
|
||||
ops = ops.chunkify_text(None);
|
||||
}
|
||||
ops = ops.text_normal(label).newline();
|
||||
}
|
||||
if chunkify {
|
||||
// Chunkifying the address into smaller pieces when requested
|
||||
ops = ops.chunkify_text(Some((theme::MONO_CHUNKS, 2)));
|
||||
}
|
||||
ops = ops.text_mono(address);
|
||||
let formatted = FormattedText::new(ops).vertically_centered();
|
||||
Page::new(btn_layout, btn_actions, formatted).with_title(title)
|
||||
};
|
||||
let pages = FlowPages::new(get_page, 1);
|
||||
|
||||
let layout = RootComponent::new(Flow::new(pages));
|
||||
Ok(layout)
|
||||
let obj = LayoutObj::new(Flow::new(pages))?;
|
||||
Ok(obj)
|
||||
}
|
||||
|
||||
fn confirm_blob(
|
||||
|
@ -87,41 +87,18 @@ impl FirmwareUI for UIModelTT {
|
||||
|
||||
fn confirm_address(
|
||||
title: TString<'static>,
|
||||
data: Obj,
|
||||
description: Option<TString<'static>>,
|
||||
extra: Option<TString<'static>>,
|
||||
address: Obj,
|
||||
address_label: Option<TString<'static>>,
|
||||
verb: Option<TString<'static>>,
|
||||
info_button: bool,
|
||||
chunkify: bool,
|
||||
) -> Result<impl LayoutMaybeTrace, Error> {
|
||||
) -> Result<Gc<LayoutObj>, Error> {
|
||||
let verb = verb.unwrap_or(TR::buttons__confirm.into());
|
||||
let data_style = if chunkify {
|
||||
let address: TString = data.try_into()?;
|
||||
theme::get_chunkified_text_style(address.len())
|
||||
} else {
|
||||
&theme::TEXT_MONO
|
||||
};
|
||||
|
||||
let paragraphs = ConfirmBlob {
|
||||
description: description.unwrap_or("".into()),
|
||||
extra: extra.unwrap_or("".into()),
|
||||
data: data.try_into()?,
|
||||
description_font: &theme::TEXT_NORMAL,
|
||||
extra_font: &theme::TEXT_DEMIBOLD,
|
||||
data_font: data_style,
|
||||
}
|
||||
.into_paragraphs();
|
||||
|
||||
let layout = RootComponent::new(
|
||||
Frame::left_aligned(
|
||||
theme::label_title(),
|
||||
title,
|
||||
ButtonPage::new(paragraphs, theme::BG)
|
||||
.with_swipe_left()
|
||||
.with_cancel_confirm(None, Some(verb)),
|
||||
)
|
||||
.with_info_button(),
|
||||
);
|
||||
Ok(layout)
|
||||
ConfirmBlobParams::new(title, address, None, Some(verb), None, false)
|
||||
.with_subtitle(address_label)
|
||||
.with_info_button(info_button)
|
||||
.with_chunkify(chunkify)
|
||||
.into_layout()
|
||||
}
|
||||
|
||||
fn confirm_blob(
|
||||
|
@ -33,12 +33,12 @@ pub trait FirmwareUI {
|
||||
|
||||
fn confirm_address(
|
||||
title: TString<'static>,
|
||||
data: Obj, // TODO: replace Obj
|
||||
description: Option<TString<'static>>,
|
||||
extra: Option<TString<'static>>,
|
||||
address: Obj, // TODO: replace Obj
|
||||
address_label: Option<TString<'static>>,
|
||||
verb: Option<TString<'static>>,
|
||||
info_button: bool,
|
||||
chunkify: bool,
|
||||
) -> Result<impl LayoutMaybeTrace, Error>;
|
||||
) -> Result<Gc<LayoutObj>, Error>; // TODO: return LayoutMaybeTrace
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn confirm_blob(
|
||||
|
@ -102,10 +102,10 @@ def confirm_action(
|
||||
def confirm_address(
|
||||
*,
|
||||
title: str,
|
||||
data: str | bytes,
|
||||
description: str | None,
|
||||
extra: str | None,
|
||||
address: str | bytes,
|
||||
address_label: str | None = None,
|
||||
verb: str | None = None,
|
||||
info_button: bool = False,
|
||||
chunkify: bool = False,
|
||||
) -> LayoutObj[UiResult]:
|
||||
"""Confirm address."""
|
||||
|
@ -257,9 +257,9 @@ async def show_address(
|
||||
result = await interact(
|
||||
trezorui_api.confirm_address(
|
||||
title=title,
|
||||
data=address,
|
||||
description="", # unused on TR
|
||||
extra=None, # unused on TR
|
||||
address=address,
|
||||
address_label=None,
|
||||
info_button=True,
|
||||
chunkify=chunkify,
|
||||
),
|
||||
br_name if send_button_request else None,
|
||||
@ -485,13 +485,12 @@ async def confirm_output(
|
||||
|
||||
while True:
|
||||
await interact(
|
||||
trezorui_api.confirm_blob(
|
||||
trezorui_api.confirm_address(
|
||||
title=address_title,
|
||||
data=address,
|
||||
description=address_label or "",
|
||||
subtitle=None,
|
||||
address=address,
|
||||
address_label=address_label or None,
|
||||
verb=TR.buttons__continue,
|
||||
verb_cancel="",
|
||||
info_button=False,
|
||||
chunkify=chunkify,
|
||||
),
|
||||
"confirm_output",
|
||||
@ -500,9 +499,9 @@ async def confirm_output(
|
||||
|
||||
try:
|
||||
await interact(
|
||||
trezorui_api.confirm_blob(
|
||||
trezorui_api.confirm_value(
|
||||
title=amount_title,
|
||||
data=amount,
|
||||
value=amount,
|
||||
description=None,
|
||||
subtitle=None,
|
||||
verb_cancel="^",
|
||||
|
@ -243,9 +243,9 @@ async def show_address(
|
||||
result = await interact(
|
||||
trezorui_api.confirm_address(
|
||||
title=title,
|
||||
data=address,
|
||||
description=network or "",
|
||||
extra=None,
|
||||
address=address,
|
||||
address_label=network or None,
|
||||
info_button=True,
|
||||
chunkify=chunkify,
|
||||
),
|
||||
br_name if send_button_request else None,
|
||||
@ -427,13 +427,11 @@ async def confirm_output(
|
||||
while True:
|
||||
# if the user cancels here, raise ActionCancelled (by default)
|
||||
await interact(
|
||||
trezorui_api.confirm_value(
|
||||
trezorui_api.confirm_address(
|
||||
title=recipient_title,
|
||||
subtitle=address_label,
|
||||
description=None,
|
||||
value=address,
|
||||
address=address,
|
||||
address_label=address_label,
|
||||
verb=TR.buttons__continue,
|
||||
hold=False,
|
||||
info_button=False,
|
||||
chunkify=chunkify,
|
||||
),
|
||||
@ -1105,10 +1103,10 @@ async def confirm_signverify(
|
||||
|
||||
address_layout = trezorui_api.confirm_address(
|
||||
title=address_title,
|
||||
data=address,
|
||||
description="",
|
||||
address=address,
|
||||
address_label=None,
|
||||
verb=TR.buttons__continue,
|
||||
extra=None,
|
||||
info_button=True,
|
||||
chunkify=chunkify,
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user