mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-04 21:48:17 +00:00
refactor(core): move confirm_more
- not implemented for mercury
This commit is contained in:
parent
edae631aa1
commit
042c7dd8b4
@ -232,6 +232,20 @@ extern "C" fn new_confirm_modify_output(n_args: usize, args: *const Obj, kwargs:
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_confirm_more(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 button: TString = kwargs.get(Qstr::MP_QSTR_button)?.try_into()?;
|
||||
let button_style_confirm: bool =
|
||||
kwargs.get_or(Qstr::MP_QSTR_button_style_confirm, false)?;
|
||||
let items: Obj = kwargs.get(Qstr::MP_QSTR_items)?;
|
||||
|
||||
let layout = ModelUI::confirm_more(title, button, button_style_confirm, items)?;
|
||||
Ok(LayoutObj::new_root(layout)?.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: TString = kwargs.get(Qstr::MP_QSTR_title)?.try_into()?;
|
||||
@ -974,6 +988,17 @@ pub static mp_module_trezorui_api: Module = obj_module! {
|
||||
/// """Decrease or increase output amount."""
|
||||
Qstr::MP_QSTR_confirm_modify_output => obj_fn_kw!(0, new_confirm_modify_output).as_obj(),
|
||||
|
||||
/// def confirm_more(
|
||||
/// *,
|
||||
/// title: str,
|
||||
/// button: str,
|
||||
/// button_style_confirm: bool = False,
|
||||
/// items: Iterable[tuple[int, str | bytes]],
|
||||
/// ) -> LayoutObj[UiResult]:
|
||||
/// """Confirm long content with the possibility to go back from any page.
|
||||
/// Meant to be used with confirm_with_info on model TT and TR."""
|
||||
Qstr::MP_QSTR_confirm_more => obj_fn_kw!(0, new_confirm_more).as_obj(),
|
||||
|
||||
/// def confirm_properties(
|
||||
/// *,
|
||||
/// title: str,
|
||||
|
@ -274,6 +274,17 @@ impl UIFeaturesFirmware for ModelMercuryFeatures {
|
||||
Ok(layout)
|
||||
}
|
||||
|
||||
fn confirm_more(
|
||||
_title: TString<'static>,
|
||||
_button: TString<'static>,
|
||||
_button_style_confirm: bool,
|
||||
_items: Obj,
|
||||
) -> Result<impl LayoutMaybeTrace, Error> {
|
||||
Err::<RootComponent<Empty, ModelMercuryFeatures>, Error>(Error::ValueError(
|
||||
c"confirm_more not implemented",
|
||||
))
|
||||
}
|
||||
|
||||
fn confirm_reset_device(recovery: bool) -> Result<impl LayoutMaybeTrace, Error> {
|
||||
let flow = flow::confirm_reset::new_confirm_reset(recovery)?;
|
||||
Ok(flow)
|
||||
|
@ -648,32 +648,6 @@ extern "C" fn new_multiple_pages_texts(n_args: usize, args: *const Obj, kwargs:
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_confirm_more(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 button: TString<'static> = kwargs.get(Qstr::MP_QSTR_button)?.try_into()?;
|
||||
let items: Obj = kwargs.get(Qstr::MP_QSTR_items)?;
|
||||
|
||||
let mut paragraphs = ParagraphVecLong::new();
|
||||
|
||||
for para in IterBuf::new().try_iterate(items)? {
|
||||
let [font, text]: [Obj; 2] = util::iter_into_array(para)?;
|
||||
let style: &TextStyle = theme::textstyle_number(font.try_into()?);
|
||||
let text: TString = text.try_into()?;
|
||||
paragraphs.add(Paragraph::new(style, text));
|
||||
}
|
||||
|
||||
content_in_button_page(
|
||||
title,
|
||||
paragraphs.into_paragraphs(),
|
||||
button,
|
||||
Some("<".into()),
|
||||
false,
|
||||
)
|
||||
};
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub static mp_module_trezorui2: Module = obj_module! {
|
||||
/// from trezor import utils
|
||||
@ -767,14 +741,4 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
||||
/// ) -> LayoutObj[UiResult]:
|
||||
/// """Show multiple texts, each on its own page."""
|
||||
Qstr::MP_QSTR_multiple_pages_texts => obj_fn_kw!(0, new_multiple_pages_texts).as_obj(),
|
||||
|
||||
/// def confirm_more(
|
||||
/// *,
|
||||
/// title: str,
|
||||
/// button: str,
|
||||
/// items: Iterable[tuple[int, str | bytes]],
|
||||
/// ) -> object:
|
||||
/// """Confirm long content with the possibility to go back from any page.
|
||||
/// Meant to be used with confirm_with_info."""
|
||||
Qstr::MP_QSTR_confirm_more => obj_fn_kw!(0, new_confirm_more).as_obj(),
|
||||
};
|
||||
|
@ -312,6 +312,30 @@ impl UIFeaturesFirmware for ModelTRFeatures {
|
||||
)
|
||||
}
|
||||
|
||||
fn confirm_more(
|
||||
title: TString<'static>,
|
||||
button: TString<'static>,
|
||||
_button_style_confirm: bool,
|
||||
items: Obj,
|
||||
) -> Result<impl LayoutMaybeTrace, Error> {
|
||||
let mut paragraphs = ParagraphVecLong::new();
|
||||
|
||||
for para in IterBuf::new().try_iterate(items)? {
|
||||
let [font, text]: [Obj; 2] = util::iter_into_array(para)?;
|
||||
let style: &TextStyle = theme::textstyle_number(font.try_into()?);
|
||||
let text: TString = text.try_into()?;
|
||||
paragraphs.add(Paragraph::new(style, text));
|
||||
}
|
||||
|
||||
content_in_button_page(
|
||||
title,
|
||||
paragraphs.into_paragraphs(),
|
||||
button,
|
||||
Some("<".into()),
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
fn confirm_properties(
|
||||
title: TString<'static>,
|
||||
items: Obj,
|
||||
|
@ -457,40 +457,6 @@ extern "C" fn new_confirm_total(n_args: usize, args: *const Obj, kwargs: *mut Ma
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_confirm_more(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 button: TString = kwargs.get(Qstr::MP_QSTR_button)?.try_into()?;
|
||||
let button_style_confirm: bool =
|
||||
kwargs.get_or(Qstr::MP_QSTR_button_style_confirm, false)?;
|
||||
let items: Obj = kwargs.get(Qstr::MP_QSTR_items)?;
|
||||
|
||||
let mut paragraphs = ParagraphVecLong::new();
|
||||
|
||||
for para in IterBuf::new().try_iterate(items)? {
|
||||
let [font, text]: [Obj; 2] = util::iter_into_array(para)?;
|
||||
let style: &TextStyle = theme::textstyle_number(font.try_into()?);
|
||||
let text: TString = text.try_into()?;
|
||||
paragraphs.add(Paragraph::new(style, text));
|
||||
}
|
||||
|
||||
let obj = LayoutObj::new(Frame::left_aligned(
|
||||
theme::label_title(),
|
||||
title,
|
||||
ButtonPage::new(paragraphs.into_paragraphs(), theme::BG)
|
||||
.with_cancel_confirm(None, Some(button))
|
||||
.with_confirm_style(if button_style_confirm {
|
||||
theme::button_confirm()
|
||||
} else {
|
||||
theme::button_default()
|
||||
})
|
||||
.with_back_button(),
|
||||
))?;
|
||||
Ok(obj.into())
|
||||
};
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub static mp_module_trezorui2: Module = obj_module! {
|
||||
/// from trezor import utils
|
||||
@ -542,17 +508,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
||||
/// ) -> LayoutObj[UiResult]:
|
||||
/// """Transaction summary. Always hold to confirm."""
|
||||
Qstr::MP_QSTR_confirm_total => obj_fn_kw!(0, new_confirm_total).as_obj(),
|
||||
|
||||
/// def confirm_more(
|
||||
/// *,
|
||||
/// title: str,
|
||||
/// button: str,
|
||||
/// button_style_confirm: bool = False,
|
||||
/// items: Iterable[tuple[int, str | bytes]],
|
||||
/// ) -> LayoutObj[UiResult]:
|
||||
/// """Confirm long content with the possibility to go back from any page.
|
||||
/// Meant to be used with confirm_with_info."""
|
||||
Qstr::MP_QSTR_confirm_more => obj_fn_kw!(0, new_confirm_more).as_obj(),
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -270,6 +270,36 @@ impl UIFeaturesFirmware for ModelTTFeatures {
|
||||
Ok(layout)
|
||||
}
|
||||
|
||||
fn confirm_more(
|
||||
title: TString<'static>,
|
||||
button: TString<'static>,
|
||||
button_style_confirm: bool,
|
||||
items: Obj,
|
||||
) -> Result<impl LayoutMaybeTrace, Error> {
|
||||
let mut paragraphs = ParagraphVecLong::new();
|
||||
|
||||
for para in IterBuf::new().try_iterate(items)? {
|
||||
let [font, text]: [Obj; 2] = util::iter_into_array(para)?;
|
||||
let style: &TextStyle = theme::textstyle_number(font.try_into()?);
|
||||
let text: TString = text.try_into()?;
|
||||
paragraphs.add(Paragraph::new(style, text));
|
||||
}
|
||||
|
||||
let layout = RootComponent::new(Frame::left_aligned(
|
||||
theme::label_title(),
|
||||
title,
|
||||
ButtonPage::new(paragraphs.into_paragraphs(), theme::BG)
|
||||
.with_cancel_confirm(None, Some(button))
|
||||
.with_confirm_style(if button_style_confirm {
|
||||
theme::button_confirm()
|
||||
} else {
|
||||
theme::button_default()
|
||||
})
|
||||
.with_back_button(),
|
||||
));
|
||||
Ok(layout)
|
||||
}
|
||||
|
||||
fn confirm_properties(
|
||||
title: TString<'static>,
|
||||
items: Obj,
|
||||
|
@ -80,6 +80,13 @@ pub trait UIFeaturesFirmware {
|
||||
amount_new: TString<'static>,
|
||||
) -> Result<impl LayoutMaybeTrace, Error>;
|
||||
|
||||
fn confirm_more(
|
||||
title: TString<'static>,
|
||||
button: TString<'static>,
|
||||
button_style_confirm: bool,
|
||||
items: Obj, // TODO: replace Obj
|
||||
) -> Result<impl LayoutMaybeTrace, Error>;
|
||||
|
||||
fn confirm_properties(
|
||||
title: TString<'static>,
|
||||
items: Obj, // TODO: replace Obj`
|
||||
|
@ -208,17 +208,6 @@ def multiple_pages_texts(
|
||||
items: list[str],
|
||||
) -> LayoutObj[UiResult]:
|
||||
"""Show multiple texts, each on its own page."""
|
||||
|
||||
|
||||
# rust/src/ui/model_tr/layout.rs
|
||||
def confirm_more(
|
||||
*,
|
||||
title: str,
|
||||
button: str,
|
||||
items: Iterable[tuple[int, str | bytes]],
|
||||
) -> object:
|
||||
"""Confirm long content with the possibility to go back from any page.
|
||||
Meant to be used with confirm_with_info."""
|
||||
from trezor import utils
|
||||
from trezorui_api import *
|
||||
|
||||
@ -271,15 +260,3 @@ def confirm_total(
|
||||
cancel_arrow: bool = False,
|
||||
) -> LayoutObj[UiResult]:
|
||||
"""Transaction summary. Always hold to confirm."""
|
||||
|
||||
|
||||
# rust/src/ui/model_tt/layout.rs
|
||||
def confirm_more(
|
||||
*,
|
||||
title: str,
|
||||
button: str,
|
||||
button_style_confirm: bool = False,
|
||||
items: Iterable[tuple[int, str | bytes]],
|
||||
) -> LayoutObj[UiResult]:
|
||||
"""Confirm long content with the possibility to go back from any page.
|
||||
Meant to be used with confirm_with_info."""
|
||||
|
@ -180,6 +180,18 @@ def confirm_modify_output(
|
||||
"""Decrease or increase output amount."""
|
||||
|
||||
|
||||
# rust/src/ui/api/firmware_upy.rs
|
||||
def confirm_more(
|
||||
*,
|
||||
title: str,
|
||||
button: str,
|
||||
button_style_confirm: bool = False,
|
||||
items: Iterable[tuple[int, str | bytes]],
|
||||
) -> LayoutObj[UiResult]:
|
||||
"""Confirm long content with the possibility to go back from any page.
|
||||
Meant to be used with confirm_with_info on model TT and TR."""
|
||||
|
||||
|
||||
# rust/src/ui/api/firmware_upy.rs
|
||||
def confirm_properties(
|
||||
*,
|
||||
|
@ -616,7 +616,7 @@ async def _confirm_ask_pagination(
|
||||
|
||||
data = hexlify(data).decode()
|
||||
|
||||
confirm_more_layout = trezorui2.confirm_more(
|
||||
confirm_more_layout = trezorui_api.confirm_more(
|
||||
title=title,
|
||||
button=TR.buttons__confirm,
|
||||
items=[(ui.NORMAL, description), (ui.MONO, data)],
|
||||
|
@ -543,7 +543,7 @@ async def _confirm_ask_pagination(
|
||||
|
||||
data = hexlify(data).decode()
|
||||
|
||||
confirm_more_layout = trezorui2.confirm_more(
|
||||
confirm_more_layout = trezorui_api.confirm_more(
|
||||
title=title,
|
||||
button=TR.buttons__confirm,
|
||||
button_style_confirm=True,
|
||||
|
Loading…
Reference in New Issue
Block a user