1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-04 21:48:17 +00:00

fixup! refactor(core): model_r confirm_summary

This commit is contained in:
obrusvit 2024-12-02 14:46:35 +01:00
parent e7c5bc2632
commit f9c897d2df

View File

@ -661,7 +661,10 @@ extern "C" fn new_confirm_summary(n_args: usize, args: *const Obj, kwargs: *mut
.get(Qstr::MP_QSTR_extra_items)
.unwrap_or_else(|_| Obj::const_none())
.try_into_option()?;
let cancel_arrow: bool = kwargs.get_or(Qstr::MP_QSTR_cancel_arrow, false)?;
let verb_cancel: Option<TString<'static>> = kwargs
.get(Qstr::MP_QSTR_verb_cancel)
.unwrap_or_else(|_| Obj::const_none())
.try_into_option()?;
// collect available info pages
let mut info_pages: Vec<(TString, Obj), 3> = Vec::new();
@ -676,31 +679,26 @@ extern "C" fn new_confirm_summary(n_args: usize, args: *const Obj, kwargs: *mut
}
// button layouts and actions
let btns_summary_page =
|cancel_arrow: bool, has_pages_after: bool| -> (ButtonLayout, ButtonActions) {
// if there are no info pages, the right button is not needed
// if cancel_arrow is true, the left button is an arrow pointing up
let left_button = Some(if cancel_arrow {
ButtonDetails::up_arrow_icon()
} else {
ButtonDetails::cancel_icon()
});
let right_button = has_pages_after.then(|| {
ButtonDetails::text("i".into())
.with_fixed_width(theme::BUTTON_ICON_WIDTH)
.with_font(Font::NORMAL)
});
let middle_button = Some(ButtonDetails::armed_text(TR::buttons__confirm.into()));
let btns_summary_page = move |has_pages_after: bool| -> (ButtonLayout, ButtonActions) {
// if there are no info pages, the right button is not needed
// if verb_cancel is "^", the left button is an arrow pointing up
let left_btn = verb_cancel.map(ButtonDetails::from_text_possible_icon);
let right_btn = has_pages_after.then(|| {
ButtonDetails::text("i".into())
.with_fixed_width(theme::BUTTON_ICON_WIDTH)
.with_font(Font::NORMAL)
});
let middle_btn = Some(ButtonDetails::armed_text(TR::buttons__confirm.into()));
(
ButtonLayout::new(left_button, middle_button, right_button),
if has_pages_after {
ButtonActions::cancel_confirm_next()
} else {
ButtonActions::cancel_confirm_none()
},
)
};
(
ButtonLayout::new(left_btn, middle_btn, right_btn),
if has_pages_after {
ButtonActions::cancel_confirm_next()
} else {
ButtonActions::cancel_confirm_none()
},
)
};
let btns_info_page = |is_last: bool| -> (ButtonLayout, ButtonActions) {
// on the last info page, the right button is not needed
if is_last {
@ -721,8 +719,7 @@ extern "C" fn new_confirm_summary(n_args: usize, args: *const Obj, kwargs: *mut
match page_index {
0 => {
// Total amount + fee
let (btn_layout, btn_actions) =
btns_summary_page(cancel_arrow, !info_pages.is_empty());
let (btn_layout, btn_actions) = btns_summary_page(!info_pages.is_empty());
let ops = OpTextLayout::new(theme::TEXT_MONO)
.text_bold(amount_label)
@ -1800,7 +1797,7 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// fee_items: Iterable[tuple[str, str]] | None = None,
/// account_items: Iterable[tuple[str, str]] | None = None,
/// extra_items: Iterable[tuple[str, str]] | None = None,
/// cancel_arrow: bool = False,
/// verb_cancel: str | None = None,
/// ) -> LayoutObj[UiResult]:
/// """Confirm summary of a transaction."""
Qstr::MP_QSTR_confirm_summary => obj_fn_kw!(0, new_confirm_summary).as_obj(),