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 9cf4ff6c91..d0a9f5bda1 100644 --- a/core/embed/rust/src/ui/model_mercury/flow/mod.rs +++ b/core/embed/rust/src/ui/model_mercury/flow/mod.rs @@ -14,10 +14,9 @@ pub mod request_passphrase; pub mod set_brightness; pub mod show_share_words; pub mod show_tutorial; +pub mod util; pub mod warning_hi_prio; -mod util; - pub use confirm_action::{new_confirm_action, new_confirm_action_simple}; #[cfg(feature = "universal_fw")] pub use confirm_fido::new_confirm_fido; @@ -34,4 +33,5 @@ pub use request_passphrase::RequestPassphrase; pub use set_brightness::SetBrightness; pub use show_share_words::ShowShareWords; pub use show_tutorial::ShowTutorial; +pub use util::{ConfirmBlobParams, ShowInfoParams}; pub use warning_hi_prio::WarningHiPrio; diff --git a/core/embed/rust/src/ui/model_mercury/flow/util.rs b/core/embed/rust/src/ui/model_mercury/flow/util.rs index 21cd83fe30..ca38692ac3 100644 --- a/core/embed/rust/src/ui/model_mercury/flow/util.rs +++ b/core/embed/rust/src/ui/model_mercury/flow/util.rs @@ -14,10 +14,11 @@ use crate::{ text::paragraphs::{Paragraph, ParagraphSource, ParagraphVecShort, VecExt}, Component, }, - flow::{FlowMsg, Swipable, SwipePage}, + flow::{FlowMsg, Swipable, SwipePage, SwipeFlow}, geometry::Direction, layout::util::{ConfirmBlob, StrOrBytes}, model_mercury::component::SwipeContent, + model_mercury::flow, }, }; use heapless::Vec; @@ -30,8 +31,12 @@ pub struct ConfirmBlobParams { data: Obj, description: Option>, extra: Option>, + verb_cancel: Option>, menu_button: bool, cancel_button: bool, + info_button: bool, + prompt: bool, + hold: bool, chunkify: bool, text_mono: bool, swipe_up: bool, @@ -52,9 +57,13 @@ impl ConfirmBlobParams { footer_description: None, data, description, + verb_cancel: None, extra: None, menu_button: false, cancel_button: false, + info_button: false, + prompt: false, + hold: false, chunkify: false, text_mono: true, swipe_up: false, @@ -83,6 +92,26 @@ impl ConfirmBlobParams { self } + pub const fn with_info_button(mut self, info_button: bool) -> Self { + self.info_button = info_button; + self + } + + pub const fn with_verb_cancel(mut self, verb_cancel: Option>) -> Self { + self.verb_cancel = verb_cancel; + self + } + + pub const fn with_hold(mut self, hold: bool) -> Self { + self.hold = hold; + self + } + + pub const fn with_prompt(mut self, prompt: bool) -> Self { + self.prompt = prompt; + self + } + pub const fn with_swipe_up(mut self) -> Self { self.swipe_up = true; self @@ -174,6 +203,35 @@ impl ConfirmBlobParams { Ok(frame.map(|msg| matches!(msg, FrameMsg::Button(_)).then_some(FlowMsg::Info))) } + + pub fn into_flow(self) -> Result { + let paragraphs = ConfirmBlob { + description: self.description.unwrap_or("".into()), + extra: self.extra.unwrap_or("".into()), + data: self.data.try_into()?, + description_font: &theme::TEXT_NORMAL, + extra_font: &theme::TEXT_DEMIBOLD, + data_font: if self.chunkify { + let data: TString = self.data.try_into()?; + theme::get_chunkified_text_style(data.len()) + } else if self.text_mono { + &theme::TEXT_MONO + } else { + &theme::TEXT_NORMAL + }, + } + .into_paragraphs(); + + flow::new_confirm_action_simple( + paragraphs, + self.title, + self.subtitle, + self.verb_cancel, + self.prompt.then_some(self.title), + self.hold, + self.info_button, + ) + } } pub struct ShowInfoParams { diff --git a/core/embed/rust/src/ui/model_mercury/layout.rs b/core/embed/rust/src/ui/model_mercury/layout.rs index 07fa72dc75..a881619bbe 100644 --- a/core/embed/rust/src/ui/model_mercury/layout.rs +++ b/core/embed/rust/src/ui/model_mercury/layout.rs @@ -50,6 +50,7 @@ use crate::{ model_mercury::{ component::{check_homescreen_format, SwipeContent}, flow::new_confirm_action_simple, + flow::util::ConfirmBlobParams, theme::ICON_BULLET_CHECKMARK, }, }, @@ -250,102 +251,6 @@ extern "C" fn new_confirm_emphasized(n_args: usize, args: *const Obj, kwargs: *m unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } } -struct ConfirmBlobParams { - title: TString<'static>, - subtitle: Option>, - data: Obj, - description: Option>, - extra: Option>, - verb: Option>, - verb_cancel: Option>, - info_button: bool, - prompt: bool, - hold: bool, - chunkify: bool, - text_mono: bool, -} - -impl ConfirmBlobParams { - fn new( - title: TString<'static>, - data: Obj, - description: Option>, - verb: Option>, - verb_cancel: Option>, - prompt: bool, - hold: bool, - ) -> Self { - Self { - title, - subtitle: None, - data, - description, - extra: None, - verb, - verb_cancel, - info_button: false, - prompt, - hold, - chunkify: false, - text_mono: true, - } - } - - fn with_extra(mut self, extra: Option>) -> Self { - self.extra = extra; - self - } - - fn with_subtitle(mut self, subtitle: Option>) -> Self { - self.subtitle = subtitle; - self - } - - fn with_info_button(mut self, info_button: bool) -> Self { - self.info_button = info_button; - self - } - - fn with_chunkify(mut self, chunkify: bool) -> Self { - self.chunkify = chunkify; - self - } - - fn with_text_mono(mut self, text_mono: bool) -> Self { - self.text_mono = text_mono; - self - } - - fn into_flow(self) -> Result { - let paragraphs = ConfirmBlob { - description: self.description.unwrap_or("".into()), - extra: self.extra.unwrap_or("".into()), - data: self.data.try_into()?, - description_font: &theme::TEXT_NORMAL, - extra_font: &theme::TEXT_DEMIBOLD, - data_font: if self.chunkify { - let data: TString = self.data.try_into()?; - theme::get_chunkified_text_style(data.len()) - } else if self.text_mono { - &theme::TEXT_MONO - } else { - &theme::TEXT_NORMAL - }, - } - .into_paragraphs(); - - flow::new_confirm_action_simple( - paragraphs, - self.title, - self.subtitle, - self.verb_cancel, - self.prompt.then_some(self.title), - self.hold, - self.info_button, - ) - } -} - extern "C" fn new_confirm_blob(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()?; @@ -353,7 +258,7 @@ extern "C" fn new_confirm_blob(n_args: usize, args: *const Obj, kwargs: *mut Map let description: Option = kwargs.get(Qstr::MP_QSTR_description)?.try_into_option()?; let extra: Option = kwargs.get(Qstr::MP_QSTR_extra)?.try_into_option()?; - let verb: Option = kwargs + let _verb: Option = kwargs .get(Qstr::MP_QSTR_verb) .unwrap_or_else(|_| Obj::const_none()) .try_into_option()?; @@ -369,14 +274,15 @@ extern "C" fn new_confirm_blob(n_args: usize, args: *const Obj, kwargs: *mut Map title, data, description, - verb, - verb_cancel, - prompt_screen, - hold, ) .with_extra(extra) .with_chunkify(chunkify) + .with_verb_cancel(verb_cancel) + .with_hold(hold) + .with_prompt(prompt_screen) .into_flow() + .and_then(LayoutObj::new) + .map(Into::into) }; unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } } @@ -527,7 +433,7 @@ extern "C" fn new_confirm_value(n_args: usize, args: *const Obj, kwargs: *mut Ma let value: Obj = kwargs.get(Qstr::MP_QSTR_value)?; let info_button: bool = kwargs.get_or(Qstr::MP_QSTR_info_button, false)?; - let verb: Option = kwargs + let _verb: Option = kwargs .get(Qstr::MP_QSTR_verb) .unwrap_or_else(|_| Obj::const_none()) .try_into_option()?; @@ -539,12 +445,17 @@ extern "C" fn new_confirm_value(n_args: usize, args: *const Obj, kwargs: *mut Ma let chunkify: bool = kwargs.get_or(Qstr::MP_QSTR_chunkify, false)?; let text_mono: bool = kwargs.get_or(Qstr::MP_QSTR_text_mono, true)?; - ConfirmBlobParams::new(title, value, description, verb, verb_cancel, hold, hold) + ConfirmBlobParams::new(title, value, description) .with_subtitle(subtitle) .with_info_button(info_button) .with_chunkify(chunkify) .with_text_mono(text_mono) + .with_verb_cancel(verb_cancel) + .with_prompt(hold) + .with_hold(hold) .into_flow() + .and_then(LayoutObj::new) + .map(Into::into) }; unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } }