From deb5ce3f4893e416ad454108e880089dbf384159 Mon Sep 17 00:00:00 2001 From: obrusvit Date: Thu, 28 Nov 2024 11:54:34 +0100 Subject: [PATCH] refactor(core): remove flow confirm_with_info - usage of `flow::confirm_with_info` is replaced with `flow::confirm_action` which is parameterized accordingly [no changelog] --- .../model_mercury/flow/confirm_with_info.rs | 142 ------------------ .../rust/src/ui/model_mercury/flow/mod.rs | 2 - .../embed/rust/src/ui/model_mercury/layout.rs | 44 ++++-- 3 files changed, 33 insertions(+), 155 deletions(-) delete mode 100644 core/embed/rust/src/ui/model_mercury/flow/confirm_with_info.rs diff --git a/core/embed/rust/src/ui/model_mercury/flow/confirm_with_info.rs b/core/embed/rust/src/ui/model_mercury/flow/confirm_with_info.rs deleted file mode 100644 index ca56028789..0000000000 --- a/core/embed/rust/src/ui/model_mercury/flow/confirm_with_info.rs +++ /dev/null @@ -1,142 +0,0 @@ -use crate::{ - error, - strutil::TString, - translations::TR, - ui::{ - component::{ - swipe_detect::SwipeSettings, - text::paragraphs::{ParagraphSource, ParagraphVecShort}, - ComponentExt, - }, - flow::{ - base::{Decision, DecisionBuilder}, - FlowController, FlowMsg, SwipeFlow, - }, - geometry::Direction, - model_mercury::{ - component::{ - Frame, FrameMsg, PromptMsg, PromptScreen, SwipeContent, VerticalMenu, - VerticalMenuChoiceMsg, - }, - theme, - }, - }, -}; - -#[derive(Copy, Clone, PartialEq, Eq)] -pub enum ConfirmWithInfoSimple { - Main, - Menu, -} - -impl FlowController for ConfirmWithInfoSimple { - #[inline] - fn index(&'static self) -> usize { - *self as usize - } - fn handle_swipe(&'static self, direction: Direction) -> Decision { - match (self, direction) { - (Self::Main, Direction::Left) => Self::Menu.swipe(direction), - (Self::Main, Direction::Up) => self.return_msg(FlowMsg::Confirmed), - (Self::Menu, Direction::Right) => Self::Main.swipe(direction), - _ => self.do_nothing(), - } - } - fn handle_event(&'static self, msg: FlowMsg) -> Decision { - match (self, msg) { - (Self::Main, FlowMsg::Info) => Self::Menu.goto(), - (Self::Menu, FlowMsg::Cancelled) => Self::Main.swipe_right(), - (Self::Menu, FlowMsg::Choice(0)) => self.return_msg(FlowMsg::Info), - (Self::Menu, FlowMsg::Choice(1)) => self.return_msg(FlowMsg::Cancelled), - _ => self.do_nothing(), - } - } -} - -#[derive(Copy, Clone, PartialEq, Eq)] -pub enum ConfirmWithInfo { - Main, - Menu, - Confirm, -} - -impl FlowController for ConfirmWithInfo { - #[inline] - fn index(&'static self) -> usize { - *self as usize - } - fn handle_swipe(&'static self, direction: Direction) -> Decision { - match (self, direction) { - (Self::Main, Direction::Left) => Self::Menu.swipe(direction), - (Self::Main, Direction::Up) => Self::Confirm.swipe(direction), - (Self::Menu, Direction::Right) => Self::Main.swipe(direction), - (Self::Confirm, Direction::Left) => Self::Menu.swipe(direction), - (Self::Confirm, Direction::Down) => Self::Main.swipe(direction), - _ => self.do_nothing(), - } - } - fn handle_event(&'static self, msg: FlowMsg) -> Decision { - match (self, msg) { - (Self::Main, FlowMsg::Info) => Self::Menu.goto(), - (Self::Menu, FlowMsg::Cancelled) => Self::Main.swipe_right(), - (Self::Menu, FlowMsg::Choice(0)) => self.return_msg(FlowMsg::Info), - (Self::Menu, FlowMsg::Choice(1)) => self.return_msg(FlowMsg::Cancelled), - (Self::Confirm, FlowMsg::Info) => Self::Menu.goto(), - (Self::Confirm, FlowMsg::Confirmed) => self.return_msg(FlowMsg::Confirmed), - _ => self.do_nothing(), - } - } -} - -pub fn new_confirm_with_info( - title: TString<'static>, - footer_description: Option>, - info_button: TString<'static>, - paragraphs: ParagraphVecShort<'static>, - prompt_title: Option>, -) -> Result { - let num_pages = if prompt_title.is_some() { 2 } else { 1 }; - let content_main = Frame::left_aligned(title, SwipeContent::new(paragraphs.into_paragraphs())) - .with_menu_button() - .with_footer(TR::instructions__swipe_up.into(), footer_description) - .with_swipe(Direction::Up, SwipeSettings::default()) - .map(|msg| matches!(msg, FrameMsg::Button(FlowMsg::Info)).then_some(FlowMsg::Info)) - .with_pages(move |_| num_pages); - - let content_menu = Frame::left_aligned( - TString::empty(), - VerticalMenu::empty() - .item(theme::ICON_CHEVRON_RIGHT, info_button) - .danger(theme::ICON_CANCEL, TR::buttons__cancel.into()), - ) - .with_cancel_button() - .with_swipe(Direction::Right, SwipeSettings::immediate()) - .map(|msg| match msg { - FrameMsg::Content(VerticalMenuChoiceMsg::Selected(i)) => Some(FlowMsg::Choice(i)), - FrameMsg::Button(_) => Some(FlowMsg::Cancelled), - }); - - if prompt_title.is_none() { - SwipeFlow::new(&ConfirmWithInfoSimple::Main)? - .with_page(&ConfirmWithInfoSimple::Main, content_main)? - .with_page(&ConfirmWithInfoSimple::Menu, content_menu) - } else { - let content_confirm = Frame::left_aligned( - prompt_title.unwrap(), - SwipeContent::new(PromptScreen::new_hold_to_confirm()), - ) - .with_footer(TR::instructions__hold_to_confirm.into(), None) - .with_menu_button() - .with_swipe(Direction::Down, SwipeSettings::default()) - .map(|msg| match msg { - FrameMsg::Content(PromptMsg::Confirmed) => Some(FlowMsg::Confirmed), - FrameMsg::Button(_) => Some(FlowMsg::Info), - _ => Some(FlowMsg::Cancelled), - }); - - SwipeFlow::new(&ConfirmWithInfo::Main)? - .with_page(&ConfirmWithInfo::Main, content_main)? - .with_page(&ConfirmWithInfo::Menu, content_menu)? - .with_page(&ConfirmWithInfo::Confirm, content_confirm) - } -} diff --git a/core/embed/rust/src/ui/model_mercury/flow/mod.rs b/core/embed/rust/src/ui/model_mercury/flow/mod.rs index c01249063b..6bb6b7a1d7 100644 --- a/core/embed/rust/src/ui/model_mercury/flow/mod.rs +++ b/core/embed/rust/src/ui/model_mercury/flow/mod.rs @@ -6,7 +6,6 @@ pub mod confirm_output; pub mod confirm_reset; pub mod confirm_set_new_pin; pub mod confirm_summary; -pub mod confirm_with_info; pub mod continue_recovery; pub mod get_address; pub mod prompt_backup; @@ -29,7 +28,6 @@ pub use confirm_output::new_confirm_output; pub use confirm_reset::new_confirm_reset; pub use confirm_set_new_pin::SetNewPin; pub use confirm_summary::new_confirm_summary; -pub use confirm_with_info::new_confirm_with_info; pub use continue_recovery::new_continue_recovery; pub use get_address::GetAddress; pub use prompt_backup::PromptBackup; diff --git a/core/embed/rust/src/ui/model_mercury/layout.rs b/core/embed/rust/src/ui/model_mercury/layout.rs index 03b7a4e73e..84a91bc5b7 100644 --- a/core/embed/rust/src/ui/model_mercury/layout.rs +++ b/core/embed/rust/src/ui/model_mercury/layout.rs @@ -412,14 +412,19 @@ extern "C" fn new_confirm_address(n_args: usize, args: *const Obj, kwargs: *mut let paragraphs = ParagraphVecShort::from_iter([ Paragraph::new(&theme::TEXT_NORMAL, description.unwrap_or("".into())), Paragraph::new(data_style, data.as_str_offset(0)), - ]); + ]) + .into_paragraphs(); - let flow = flow::new_confirm_with_info( - title, - None, - TR::buttons__more_info.into(), + let flow = flow::new_confirm_action_simple( paragraphs, + ConfirmActionExtra::Menu( + ConfirmActionMenuStrings::new().with_verb_info(Some(TR::buttons__more_info.into())), + ), + ConfirmActionStrings::new(title, None, None, None), + false, None, + 0, + false, )?; Ok(LayoutObj::new_root(flow)?.into()) }; @@ -881,13 +886,19 @@ extern "C" fn new_confirm_modify_fee(n_args: usize, args: *const Obj, kwargs: *m Paragraph::new(&theme::TEXT_MONO, total_fee_new), ]); - let flow = flow::new_confirm_with_info( - title, + let flow = flow::new_confirm_action_simple( + paragraphs.into_paragraphs(), + ConfirmActionExtra::Menu( + ConfirmActionMenuStrings::new() + .with_verb_info(Some(TR::words__title_information.into())), + ), + ConfirmActionStrings::new(title, None, None, Some(title)), + true, None, - TR::words__title_information.into(), - paragraphs, - Some(title), + 0, + false, )?; + Ok(LayoutObj::new_root(flow)?.into()) }; unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } @@ -1076,7 +1087,18 @@ extern "C" fn new_confirm_with_info(n_args: usize, args: *const Obj, kwargs: *mu } } - let flow = flow::new_confirm_with_info(title, Some(button), info_button, paragraphs, None)?; + let flow = flow::new_confirm_action_simple( + paragraphs.into_paragraphs(), + ConfirmActionExtra::Menu( + ConfirmActionMenuStrings::new().with_verb_info(Some(info_button)), + ), + ConfirmActionStrings::new(title, None, None, None) + .with_footer_description(Some(button)), + false, + None, + 0, + false, + )?; Ok(LayoutObj::new_root(flow)?.into()) }; unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }