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

Compare commits

..

6 Commits

Author SHA1 Message Date
Vít Obrusník
f602e2e968
Merge 6a25ea7675 into ef02c4de5d 2024-12-04 00:54:03 +01:00
obrusvit
6a25ea7675 fixup! refactor(core): model_t confirm_summary 2024-12-04 00:52:47 +01:00
obrusvit
ebf7c38ffc fixup! refactor(core): mercury confirm_summary 2024-12-04 00:51:37 +01:00
obrusvit
83afdc4e32 fixup! refactor(core): model_t confirm_summary 2024-12-04 00:38:44 +01:00
obrusvit
c3ac40889f fixup! refactor(core): model_r confirm_summary 2024-12-04 00:38:44 +01:00
obrusvit
da71639ce3 fixup! refactor(core): mercury confirm_summary 2024-12-04 00:38:44 +01:00
11 changed files with 62 additions and 94 deletions

View File

@ -238,6 +238,7 @@ static void _librust_qstrs(void) {
MP_QSTR_experimental_mode__title;
MP_QSTR_extra;
MP_QSTR_extra_items;
MP_QSTR_extra_title;
MP_QSTR_fee;
MP_QSTR_fee_items;
MP_QSTR_fee_label;

View File

@ -85,7 +85,7 @@ pub use swipe_up_screen::{SwipeUpScreen, SwipeUpScreenMsg};
#[cfg(feature = "translations")]
pub use tap_to_confirm::TapToConfirm;
pub use updatable_more_info::UpdatableMoreInfo;
pub use vertical_menu::{PagedVerticalMenu, VerticalMenu, VerticalMenuChoiceMsg, MENU_MAX_ITEMS};
pub use vertical_menu::{PagedVerticalMenu, VerticalMenu, VerticalMenuChoiceMsg};
pub use welcome_screen::WelcomeScreen;
use super::{constant, theme};

View File

@ -25,7 +25,7 @@ pub enum VerticalMenuChoiceMsg {
/// Number of buttons.
/// Presently, VerticalMenu holds only fixed number of buttons.
pub const MENU_MAX_ITEMS: usize = 3;
const MENU_MAX_ITEMS: usize = 3;
/// Fixed height of each menu button.
const MENU_BUTTON_HEIGHT: i16 = 64;

View File

@ -19,7 +19,7 @@ use super::{
super::{
component::{
Frame, FrameMsg, PromptMsg, PromptScreen, SwipeContent, VerticalMenu,
VerticalMenuChoiceMsg, MENU_MAX_ITEMS,
VerticalMenuChoiceMsg,
},
theme,
},
@ -27,18 +27,16 @@ use super::{
};
const MENU_ITEM_CANCEL: usize = 0;
const MENU_ITEM_FEE_INFO: usize = 1;
const MENU_ITEM_EXTRA_INFO: usize = 1;
const MENU_ITEM_ACCOUNT_INFO: usize = 2;
const MENU_ITEM_EXTRA_INFO: usize = 3;
#[derive(Copy, Clone, PartialEq, Eq)]
pub enum ConfirmSummary {
Summary,
Hold,
Menu,
FeeInfo,
AccountInfo,
ExtraInfo,
AccountInfo,
CancelTap,
}
@ -54,10 +52,9 @@ impl FlowController for ConfirmSummary {
(Self::Summary, Direction::Up) => Self::Hold.swipe(direction),
(Self::Hold, Direction::Down) => Self::Summary.swipe(direction),
(Self::Menu, Direction::Right) => Self::Summary.swipe(direction),
(
Self::AccountInfo | Self::FeeInfo | Self::ExtraInfo | Self::CancelTap,
Direction::Right,
) => Self::Menu.swipe(direction),
(Self::ExtraInfo | Self::AccountInfo | Self::CancelTap, Direction::Right) => {
Self::Menu.swipe(direction)
}
_ => self.do_nothing(),
}
}
@ -67,9 +64,8 @@ impl FlowController for ConfirmSummary {
(_, FlowMsg::Info) => Self::Menu.goto(),
(Self::Hold, FlowMsg::Confirmed) => self.return_msg(FlowMsg::Confirmed),
(Self::Menu, FlowMsg::Choice(MENU_ITEM_CANCEL)) => Self::CancelTap.swipe_left(),
(Self::Menu, FlowMsg::Choice(MENU_ITEM_FEE_INFO)) => Self::FeeInfo.swipe_left(),
(Self::Menu, FlowMsg::Choice(MENU_ITEM_ACCOUNT_INFO)) => Self::AccountInfo.swipe_left(),
(Self::Menu, FlowMsg::Choice(MENU_ITEM_EXTRA_INFO)) => Self::ExtraInfo.swipe_left(),
(Self::Menu, FlowMsg::Choice(MENU_ITEM_ACCOUNT_INFO)) => Self::AccountInfo.swipe_left(),
(Self::Menu, FlowMsg::Cancelled) => Self::Summary.swipe_right(),
(Self::CancelTap, FlowMsg::Confirmed) => self.return_msg(FlowMsg::Cancelled),
(_, FlowMsg::Cancelled) => Self::Menu.goto(),
@ -84,9 +80,9 @@ fn dummy_page() -> impl Component<Msg = FlowMsg> + Swipable + MaybeTrace {
pub fn new_confirm_summary(
summary_params: ShowInfoParams,
fee_params: Option<ShowInfoParams>,
account_params: Option<ShowInfoParams>,
extra_params: Option<ShowInfoParams>,
extra_title: Option<TString<'static>>,
verb_cancel: Option<TString<'static>>,
) -> Result<SwipeFlow, error::Error> {
// Summary
@ -110,26 +106,24 @@ pub fn new_confirm_summary(
_ => None,
});
// FeeInfo
let content_fee = fee_params.map(|params| params.into_layout()).transpose()?;
// AccountInfo
let content_account = account_params
.map(|params| params.into_layout())
.transpose()?;
// ExtraInfo
let content_extra = extra_params
.map(|params| params.into_layout())
.transpose()?;
// AccountInfo
let content_account = account_params
.map(|params| params.into_layout())
.transpose()?;
// Menu with provided info and cancel
let mut menu = VerticalMenu::empty();
let mut menu_items = Vec::<usize, 3>::new();
if content_fee.is_some() {
if content_extra.is_some() {
menu = menu.item(
theme::ICON_CHEVRON_RIGHT,
TR::confirm_total__title_fee.into(),
extra_title.unwrap_or(TR::buttons__more_info.into()),
);
unwrap!(menu_items.push(MENU_ITEM_FEE_INFO));
unwrap!(menu_items.push(MENU_ITEM_EXTRA_INFO));
}
if content_account.is_some() {
menu = menu.item(
@ -138,14 +132,6 @@ pub fn new_confirm_summary(
);
unwrap!(menu_items.push(MENU_ITEM_ACCOUNT_INFO));
}
if content_extra.is_some() && menu_items.len() < MENU_MAX_ITEMS - 1 {
// NOTE: extra is shown only if VerticalMenu has space considering mandatory "Cancel"
menu = menu.item(
theme::ICON_CHEVRON_RIGHT,
TR::words__title_information.into(),
);
unwrap!(menu_items.push(MENU_ITEM_EXTRA_INFO));
}
menu = menu.danger(
theme::ICON_CANCEL,
verb_cancel.unwrap_or(TR::send__cancel_sign.into()),
@ -180,21 +166,16 @@ pub fn new_confirm_summary(
.with_page(&ConfirmSummary::Summary, content_summary)?
.with_page(&ConfirmSummary::Hold, content_hold)?
.with_page(&ConfirmSummary::Menu, content_menu)?;
if let Some(content_fee) = content_fee {
res = res.with_page(&ConfirmSummary::FeeInfo, content_fee)?;
if let Some(content_extra) = content_extra {
res = res.with_page(&ConfirmSummary::ExtraInfo, content_extra)?
} else {
res = res.with_page(&ConfirmSummary::FeeInfo, dummy_page())?;
res = res.with_page(&ConfirmSummary::ExtraInfo, dummy_page())?
};
if let Some(content_account) = content_account {
res = res.with_page(&ConfirmSummary::AccountInfo, content_account)?
} else {
res = res.with_page(&ConfirmSummary::AccountInfo, dummy_page())?
};
if let Some(content_extra) = content_extra {
res = res.with_page(&ConfirmSummary::ExtraInfo, content_extra)?
} else {
res = res.with_page(&ConfirmSummary::ExtraInfo, dummy_page())?
};
res = res.with_page(&ConfirmSummary::CancelTap, content_cancel_tap)?;
Ok(res)

View File

@ -632,10 +632,6 @@ extern "C" fn new_confirm_summary(n_args: usize, args: *const Obj, kwargs: *mut
.get(Qstr::MP_QSTR_title)
.unwrap_or_else(|_| Obj::const_none())
.try_into_option()?;
let fee_items: Option<Obj> = kwargs
.get(Qstr::MP_QSTR_fee_items)
.unwrap_or_else(|_| Obj::const_none())
.try_into_option()?;
let account_items: Option<Obj> = kwargs
.get(Qstr::MP_QSTR_account_items)
.unwrap_or_else(|_| Obj::const_none())
@ -644,6 +640,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 extra_title: Option<TString> = kwargs
.get(Qstr::MP_QSTR_extra_title)
.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())
@ -657,17 +657,6 @@ extern "C" fn new_confirm_summary(n_args: usize, args: *const Obj, kwargs: *mut
summary_params = unwrap!(summary_params.add(fee_label, fee));
// collect available info
let fee_params = if let Some(items) = fee_items {
let mut fee_params =
ShowInfoParams::new(TR::confirm_total__title_fee.into()).with_cancel_button();
for pair in IterBuf::new().try_iterate(items)? {
let [label, value]: [TString; 2] = util::iter_into_array(pair)?;
fee_params = unwrap!(fee_params.add(label, value));
}
Some(fee_params)
} else {
None
};
let account_params = if let Some(items) = account_items {
let mut account_params =
ShowInfoParams::new(TR::send__send_from.into()).with_cancel_button();
@ -680,8 +669,8 @@ extern "C" fn new_confirm_summary(n_args: usize, args: *const Obj, kwargs: *mut
None
};
let extra_params = if let Some(items) = extra_items {
let mut extra_params =
ShowInfoParams::new(TR::words__title_information.into()).with_cancel_button();
let extra_title = extra_title.unwrap_or(TR::buttons__more_info.into());
let mut extra_params = ShowInfoParams::new(extra_title).with_cancel_button();
for pair in IterBuf::new().try_iterate(items)? {
let [label, value]: [TString; 2] = util::iter_into_array(pair)?;
extra_params = unwrap!(extra_params.add(label, value));
@ -693,9 +682,9 @@ extern "C" fn new_confirm_summary(n_args: usize, args: *const Obj, kwargs: *mut
let flow = flow::new_confirm_summary(
summary_params,
fee_params,
account_params,
extra_params,
extra_title,
verb_cancel,
)?;
Ok(LayoutObj::new_root(flow)?.into())
@ -2002,9 +1991,9 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// fee: str,
/// fee_label: str,
/// title: str | None = None,
/// fee_items: Iterable[tuple[str, str]] | None = None,
/// account_items: Iterable[tuple[str, str]] | None = None,
/// extra_items: Iterable[tuple[str, str]] | None = None,
/// extra_title: str | None = None,
/// verb_cancel: str | None = None,
/// ) -> LayoutObj[UiResult]:
/// """Confirm summary of a transaction."""

View File

@ -649,10 +649,6 @@ extern "C" fn new_confirm_summary(n_args: usize, args: *const Obj, kwargs: *mut
.get(Qstr::MP_QSTR_title)
.unwrap_or_else(|_| Obj::const_none())
.try_into_option()?;
let fee_items: Option<Obj> = kwargs
.get(Qstr::MP_QSTR_fee_items)
.unwrap_or_else(|_| Obj::const_none())
.try_into_option()?;
let account_items: Option<Obj> = kwargs
.get(Qstr::MP_QSTR_account_items)
.unwrap_or_else(|_| Obj::const_none())
@ -661,22 +657,25 @@ 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 extra_title: Option<TString> = kwargs
.get(Qstr::MP_QSTR_extra_title)
.unwrap_or_else(|_| Obj::const_none())
.try_into_option()?;
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();
if let Some(info) = fee_items {
unwrap!(info_pages.push((TR::confirm_total__title_fee.into(), info)));
let mut info_pages: Vec<(TString, Obj), 2> = Vec::new();
if let Some(info) = extra_items {
// put extra items first as it's typically used for fee info
let extra_title = extra_title.unwrap_or(TR::words__title_information.into());
unwrap!(info_pages.push((extra_title, info)));
}
if let Some(info) = account_items {
unwrap!(info_pages.push((TR::confirm_total__title_sending_from.into(), info)));
}
if let Some(info) = extra_items {
unwrap!(info_pages.push((TR::words__title_information.into(), info)));
}
// button layouts and actions
let verb_cancel: TString = verb_cancel.unwrap_or(TString::empty());
@ -1796,9 +1795,9 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// fee: str,
/// fee_label: str,
/// title: str | None = None,
/// fee_items: Iterable[tuple[str, str]] | None = None,
/// account_items: Iterable[tuple[str, str]] | None = None,
/// extra_items: Iterable[tuple[str, str]] | None = None,
/// extra_title: str | None = None,
/// verb_cancel: str | None = None,
/// ) -> LayoutObj[UiResult]:
/// """Confirm summary of a transaction."""

View File

@ -773,10 +773,6 @@ extern "C" fn new_confirm_summary(n_args: usize, args: *const Obj, kwargs: *mut
.get(Qstr::MP_QSTR_title)
.unwrap_or_else(|_| Obj::const_none())
.try_into_option()?;
let fee_items: Option<Obj> = kwargs
.get(Qstr::MP_QSTR_fee_items)
.unwrap_or_else(|_| Obj::const_none())
.try_into_option()?;
let account_items: Option<Obj> = kwargs
.get(Qstr::MP_QSTR_account_items)
.unwrap_or_else(|_| Obj::const_none())
@ -785,13 +781,16 @@ 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 _extra_title: Option<TString> = kwargs
.get(Qstr::MP_QSTR_extra_title)
.unwrap_or_else(|_| Obj::const_none())
.try_into_option()?;
let verb_cancel: Option<TString<'static>> = kwargs
.get(Qstr::MP_QSTR_verb_cancel)
.unwrap_or_else(|_| Obj::const_none())
.try_into_option()?;
let info_button: bool =
fee_items.is_some() || account_items.is_some() || extra_items.is_some();
let info_button: bool = account_items.is_some() || extra_items.is_some();
let paragraphs = ParagraphVecShort::from_iter([
Paragraph::new(&theme::TEXT_NORMAL, amount_label).no_break(),
Paragraph::new(&theme::TEXT_MONO, amount),
@ -1900,9 +1899,9 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// fee: str,
/// fee_label: str,
/// title: str | None = None,
/// fee_items: Iterable[tuple[str, str]] | None = None,
/// account_items: Iterable[tuple[str, str]] | None = None,
/// extra_items: Iterable[tuple[str, str]] | None = None,
/// extra_title: str | None = None,
/// verb_cancel: str | None = None,
/// ) -> LayoutObj[UiResult]:
/// """Confirm summary of a transaction."""

View File

@ -530,9 +530,9 @@ def confirm_summary(
fee: str,
fee_label: str,
title: str | None = None,
fee_items: Iterable[tuple[str, str]] | None = None,
account_items: Iterable[tuple[str, str]] | None = None,
extra_items: Iterable[tuple[str, str]] | None = None,
extra_title: str | None = None,
verb_cancel: str | None = None,
) -> LayoutObj[UiResult]:
"""Confirm summary of a transaction."""
@ -740,9 +740,9 @@ def confirm_summary(
fee: str,
fee_label: str,
title: str | None = None,
fee_items: Iterable[tuple[str, str]] | None = None,
account_items: Iterable[tuple[str, str]] | None = None,
extra_items: Iterable[tuple[str, str]] | None = None,
extra_title: str | None = None,
verb_cancel: str | None = None,
) -> LayoutObj[UiResult]:
"""Confirm summary of a transaction."""
@ -1276,9 +1276,9 @@ def confirm_summary(
fee: str,
fee_label: str,
title: str | None = None,
fee_items: Iterable[tuple[str, str]] | None = None,
account_items: Iterable[tuple[str, str]] | None = None,
extra_items: Iterable[tuple[str, str]] | None = None,
extra_title: str | None = None,
verb_cancel: str | None = None,
) -> LayoutObj[UiResult]:
"""Confirm summary of a transaction."""

View File

@ -702,8 +702,9 @@ def confirm_total(
fee=fee_amount,
fee_label=fee_label,
title=title,
fee_items=fee_items or None,
account_items=account_items or None,
extra_items=fee_items or None,
extra_title=TR.confirm_total__title_fee,
),
br_name,
br_code,
@ -716,7 +717,6 @@ def _confirm_summary(
fee: str,
fee_label: str,
title: str | None = None,
fee_items: Iterable[tuple[str, str]] | None = None,
account_items: Iterable[tuple[str, str]] | None = None,
extra_items: Iterable[tuple[str, str]] | None = None,
extra_title: str | None = None,
@ -732,9 +732,9 @@ def _confirm_summary(
fee=fee,
fee_label=fee_label,
title=title,
fee_items=fee_items or None,
account_items=account_items or None,
extra_items=extra_items or None,
extra_title=extra_title or None,
),
br_name,
br_code,

View File

@ -828,8 +828,9 @@ def confirm_total(
amount_label=total_label,
fee=fee_amount,
fee_label=fee_label,
fee_items=fee_info_items or None,
account_items=account_info_items or None,
extra_items=fee_info_items or None,
extra_title=TR.confirm_total__title_fee,
),
br_name,
br_code,
@ -883,7 +884,8 @@ if not utils.BITCOIN_ONLY:
amount_label=amount_title,
fee=maximum_fee,
fee_label=f"{TR.send__maximum_fee}:",
fee_items=[(f"{k}:", v) for (k, v) in info_items],
extra_items=[(f"{k}:", v) for (k, v) in info_items],
extra_title=TR.confirm_total__title_fee,
),
br_name=br_name,
br_code=br_code,
@ -908,7 +910,7 @@ if not utils.BITCOIN_ONLY:
amount_label=amount_title,
fee=fee,
fee_label=fee_title,
fee_items=items,
extra_items=items, # TODO: extra_title here?
),
br_name=br_name,
br_code=br_code,
@ -953,7 +955,8 @@ if not utils.BITCOIN_ONLY:
amount_label=f"{TR.words__amount}:",
fee=maximum_fee,
fee_label=f"{TR.send__maximum_fee}:",
fee_items=[(f"{k}:", v) for (k, v) in fee_info_items],
extra_items=[(f"{k}:", v) for (k, v) in fee_info_items],
extra_title=TR.confirm_total__title_fee,
)
if not is_contract_interaction:

View File

@ -751,14 +751,13 @@ def confirm_total(
fee_label = fee_label or TR.send__including_fee # def_arg
account_info_items = []
fee_info_items = []
extra_info_items = []
if source_account:
account_info_items.append(
(TR.confirm_total__sending_from_account, source_account)
)
if fee_rate_amount:
fee_info_items.append((f"{TR.confirm_total__fee_rate}:", fee_rate_amount))
extra_info_items.append((f"{TR.confirm_total__fee_rate}:", fee_rate_amount))
return _confirm_summary(
total_amount,
@ -766,9 +765,9 @@ def confirm_total(
fee_amount,
fee_label,
title=title,
fee_items=fee_info_items,
account_items=account_info_items,
extra_items=extra_info_items,
extra_title=TR.words__title_information,
br_name=br_name,
br_code=br_code,
)
@ -780,7 +779,6 @@ def _confirm_summary(
fee: str,
fee_label: str,
title: str | None = None,
fee_items: Iterable[tuple[str, str]] | None = None,
account_items: Iterable[tuple[str, str]] | None = None,
extra_items: Iterable[tuple[str, str]] | None = None,
extra_title: str | None = None,
@ -795,15 +793,12 @@ def _confirm_summary(
fee=fee,
fee_label=fee_label,
title=title,
fee_items=fee_items or None,
account_items=account_items or None,
extra_items=extra_items or None,
)
# TODO: use `_info` params directly in this^ layout instead of using `with_info`
info_items = []
if fee_items:
info_items.extend(fee_items)
if account_items:
info_items.extend(account_items)
if extra_items:
@ -841,7 +836,8 @@ if not utils.BITCOIN_ONLY:
fee=maximum_fee,
fee_label=f"{TR.send__maximum_fee}:",
title=TR.words__title_summary,
fee_items=fee_info_items,
extra_items=fee_info_items,
extra_title=TR.confirm_total__title_fee,
verb_cancel="^",
)
info_layout = trezorui2.show_info_with_cancel(