From 97db2560f87fed6609ce59c10cb1dc1ce9241bfe Mon Sep 17 00:00:00 2001 From: obrusvit Date: Fri, 1 Nov 2024 21:42:26 +0100 Subject: [PATCH] refactor(core): move confirm_coinjoin --- core/embed/rust/src/ui/api/firmware_upy.rs | 20 +++++++++ .../embed/rust/src/ui/model_mercury/layout.rs | 41 ------------------- .../src/ui/model_mercury/ui_features_fw.rs | 29 +++++++++++++ core/embed/rust/src/ui/model_tr/layout.rs | 34 --------------- .../rust/src/ui/model_tr/ui_features_fw.rs | 23 +++++++++++ core/embed/rust/src/ui/model_tt/layout.rs | 30 -------------- .../rust/src/ui/model_tt/ui_features_fw.rs | 19 +++++++++ core/embed/rust/src/ui/ui_features_fw.rs | 5 +++ core/mocks/generated/trezorui2.pyi | 27 ------------ core/mocks/generated/trezorui_api.pyi | 9 ++++ .../src/trezor/ui/layouts/mercury/__init__.py | 2 +- core/src/trezor/ui/layouts/tr/__init__.py | 2 +- core/src/trezor/ui/layouts/tt/__init__.py | 2 +- 13 files changed, 108 insertions(+), 135 deletions(-) diff --git a/core/embed/rust/src/ui/api/firmware_upy.rs b/core/embed/rust/src/ui/api/firmware_upy.rs index fcece645f7..7b713c236c 100644 --- a/core/embed/rust/src/ui/api/firmware_upy.rs +++ b/core/embed/rust/src/ui/api/firmware_upy.rs @@ -80,6 +80,18 @@ extern "C" fn new_confirm_action(n_args: usize, args: *const Obj, kwargs: *mut M }; unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } } + +extern "C" fn new_confirm_coinjoin(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj { + let block = move |_args: &[Obj], kwargs: &Map| { + let max_rounds: TString = kwargs.get(Qstr::MP_QSTR_max_rounds)?.try_into()?; + let max_feerate: TString = kwargs.get(Qstr::MP_QSTR_max_feerate)?.try_into()?; + + let layout = ModelUI::confirm_coinjoin(max_rounds, max_feerate)?; + Ok(LayoutObj::new_root(layout)?.into()) + }; + unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } +} + // TODO: there was `no_mangle` attribute in TT, should we apply it? extern "C" fn new_confirm_firmware_update( n_args: usize, @@ -496,6 +508,14 @@ pub static mp_module_trezorui_api: Module = obj_module! { /// """Confirm action.""" Qstr::MP_QSTR_confirm_action => obj_fn_kw!(0, new_confirm_action).as_obj(), + /// def confirm_coinjoin( + /// *, + /// max_rounds: str, + /// max_feerate: str, + /// ) -> LayoutObj[UiResult]: + /// """Confirm coinjoin authorization.""" + Qstr::MP_QSTR_confirm_coinjoin => obj_fn_kw!(0, new_confirm_coinjoin).as_obj(), + /// def confirm_firmware_update( /// *, /// description: str, diff --git a/core/embed/rust/src/ui/model_mercury/layout.rs b/core/embed/rust/src/ui/model_mercury/layout.rs index f542f5c410..864e5b9714 100644 --- a/core/embed/rust/src/ui/model_mercury/layout.rs +++ b/core/embed/rust/src/ui/model_mercury/layout.rs @@ -919,39 +919,6 @@ extern "C" fn new_confirm_with_info(n_args: usize, args: *const Obj, kwargs: *mu unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } } -extern "C" fn new_confirm_coinjoin(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj { - let block = move |_args: &[Obj], kwargs: &Map| { - let max_rounds: TString = kwargs.get(Qstr::MP_QSTR_max_rounds)?.try_into()?; - let max_feerate: TString = kwargs.get(Qstr::MP_QSTR_max_feerate)?.try_into()?; - - let paragraphs = ParagraphVecShort::from_iter([ - Paragraph::new(&theme::TEXT_NORMAL, TR::coinjoin__max_rounds), - Paragraph::new(&theme::TEXT_MONO, max_rounds), - Paragraph::new(&theme::TEXT_NORMAL, TR::coinjoin__max_mining_fee), - Paragraph::new(&theme::TEXT_MONO, max_feerate), - ]) - .into_paragraphs(); - - new_confirm_action_simple( - paragraphs, - ConfirmActionExtra::Menu(ConfirmActionMenuStrings::new()), - ConfirmActionStrings::new( - TR::coinjoin__title.into(), - None, - None, - Some(TR::coinjoin__title.into()), - ), - true, - None, - 0, - false, - ) - .and_then(LayoutObj::new_root) - .map(Into::into) - }; - unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } -} - extern "C" fn new_continue_recovery(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj { let block = move |_args: &[Obj], kwargs: &Map| { let first_screen: bool = kwargs.get(Qstr::MP_QSTR_first_screen)?.try_into()?; @@ -1289,14 +1256,6 @@ pub static mp_module_trezorui2: Module = obj_module! { /// context menu.""" Qstr::MP_QSTR_confirm_with_info => obj_fn_kw!(0, new_confirm_with_info).as_obj(), - /// def confirm_coinjoin( - /// *, - /// max_rounds: str, - /// max_feerate: str, - /// ) -> LayoutObj[UiResult]: - /// """Confirm coinjoin authorization.""" - Qstr::MP_QSTR_confirm_coinjoin => obj_fn_kw!(0, new_confirm_coinjoin).as_obj(), - /// def flow_prompt_backup() -> LayoutObj[UiResult]: /// """Prompt a user to create backup with an option to skip.""" Qstr::MP_QSTR_flow_prompt_backup => obj_fn_0!(new_prompt_backup).as_obj(), diff --git a/core/embed/rust/src/ui/model_mercury/ui_features_fw.rs b/core/embed/rust/src/ui/model_mercury/ui_features_fw.rs index 371d42ff7e..cc85a4a254 100644 --- a/core/embed/rust/src/ui/model_mercury/ui_features_fw.rs +++ b/core/embed/rust/src/ui/model_mercury/ui_features_fw.rs @@ -103,6 +103,35 @@ impl UIFeaturesFirmware for ModelMercuryFeatures { Ok(layout) } + fn confirm_coinjoin( + max_rounds: TString<'static>, + max_feerate: TString<'static>, + ) -> Result { + let paragraphs = ParagraphVecShort::from_iter([ + Paragraph::new(&theme::TEXT_NORMAL, TR::coinjoin__max_rounds), + Paragraph::new(&theme::TEXT_MONO, max_rounds), + Paragraph::new(&theme::TEXT_NORMAL, TR::coinjoin__max_mining_fee), + Paragraph::new(&theme::TEXT_MONO, max_feerate), + ]) + .into_paragraphs(); + + let flow = flow::new_confirm_action_simple( + paragraphs, + ConfirmActionExtra::Menu(ConfirmActionMenuStrings::new()), + ConfirmActionStrings::new( + TR::coinjoin__title.into(), + None, + None, + Some(TR::coinjoin__title.into()), + ), + true, + None, + 0, + false, + )?; + Ok(flow) + } + fn confirm_firmware_update( description: TString<'static>, fingerprint: TString<'static>, diff --git a/core/embed/rust/src/ui/model_tr/layout.rs b/core/embed/rust/src/ui/model_tr/layout.rs index a92d82963a..860d9fa5d2 100644 --- a/core/embed/rust/src/ui/model_tr/layout.rs +++ b/core/embed/rust/src/ui/model_tr/layout.rs @@ -1026,32 +1026,6 @@ extern "C" fn new_confirm_more(n_args: usize, args: *const Obj, kwargs: *mut Map unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } } -extern "C" fn new_confirm_coinjoin(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj { - let block = move |_args: &[Obj], kwargs: &Map| { - let max_rounds: TString = kwargs.get(Qstr::MP_QSTR_max_rounds)?.try_into()?; - let max_feerate: TString = kwargs.get(Qstr::MP_QSTR_max_feerate)?.try_into()?; - - // Decreasing bottom padding between paragraphs to fit one screen - let paragraphs = Paragraphs::new([ - Paragraph::new(&theme::TEXT_BOLD, TR::coinjoin__max_rounds).with_bottom_padding(2), - Paragraph::new(&theme::TEXT_MONO, max_rounds), - Paragraph::new(&theme::TEXT_BOLD, TR::coinjoin__max_mining_fee) - .with_bottom_padding(2) - .no_break(), - Paragraph::new(&theme::TEXT_MONO, max_feerate).with_bottom_padding(2), - ]); - - content_in_button_page( - TR::coinjoin__title.into(), - paragraphs, - TR::buttons__hold_to_confirm.into(), - None, - true, - ) - }; - unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } -} - extern "C" fn new_show_share_words(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj { let block = |_args: &[Obj], kwargs: &Map| { let share_words_obj: Obj = kwargs.get(Qstr::MP_QSTR_share_words)?; @@ -1344,14 +1318,6 @@ pub static mp_module_trezorui2: Module = obj_module! { /// Meant to be used with confirm_with_info.""" Qstr::MP_QSTR_confirm_more => obj_fn_kw!(0, new_confirm_more).as_obj(), - /// def confirm_coinjoin( - /// *, - /// max_rounds: str, - /// max_feerate: str, - /// ) -> LayoutObj[UiResult]: - /// """Confirm coinjoin authorization.""" - Qstr::MP_QSTR_confirm_coinjoin => obj_fn_kw!(0, new_confirm_coinjoin).as_obj(), - /// def show_share_words( /// *, /// share_words: Iterable[str], diff --git a/core/embed/rust/src/ui/model_tr/ui_features_fw.rs b/core/embed/rust/src/ui/model_tr/ui_features_fw.rs index 96e94c0931..a39bc59a36 100644 --- a/core/embed/rust/src/ui/model_tr/ui_features_fw.rs +++ b/core/embed/rust/src/ui/model_tr/ui_features_fw.rs @@ -89,6 +89,29 @@ impl UIFeaturesFirmware for ModelTRFeatures { Ok(layout) } + fn confirm_coinjoin( + max_rounds: TString<'static>, + max_feerate: TString<'static>, + ) -> Result { + // Decreasing bottom padding between paragraphs to fit one screen + let paragraphs = Paragraphs::new([ + Paragraph::new(&theme::TEXT_BOLD, TR::coinjoin__max_rounds).with_bottom_padding(2), + Paragraph::new(&theme::TEXT_MONO, max_rounds), + Paragraph::new(&theme::TEXT_BOLD, TR::coinjoin__max_mining_fee) + .with_bottom_padding(2) + .no_break(), + Paragraph::new(&theme::TEXT_MONO, max_feerate).with_bottom_padding(2), + ]); + + content_in_button_page( + TR::coinjoin__title.into(), + paragraphs, + TR::buttons__hold_to_confirm.into(), + None, + true, + ) + } + fn confirm_firmware_update( description: TString<'static>, fingerprint: TString<'static>, diff --git a/core/embed/rust/src/ui/model_tt/layout.rs b/core/embed/rust/src/ui/model_tt/layout.rs index 6ac97fe5cc..fdce3bcda4 100644 --- a/core/embed/rust/src/ui/model_tt/layout.rs +++ b/core/embed/rust/src/ui/model_tt/layout.rs @@ -1020,28 +1020,6 @@ extern "C" fn new_confirm_more(n_args: usize, args: *const Obj, kwargs: *mut Map unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } } -extern "C" fn new_confirm_coinjoin(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj { - let block = move |_args: &[Obj], kwargs: &Map| { - let max_rounds: TString = kwargs.get(Qstr::MP_QSTR_max_rounds)?.try_into()?; - let max_feerate: TString = kwargs.get(Qstr::MP_QSTR_max_feerate)?.try_into()?; - - let paragraphs = Paragraphs::new([ - Paragraph::new(&theme::TEXT_NORMAL, TR::coinjoin__max_rounds), - Paragraph::new(&theme::TEXT_MONO, max_rounds), - Paragraph::new(&theme::TEXT_NORMAL, TR::coinjoin__max_mining_fee), - Paragraph::new(&theme::TEXT_MONO, max_feerate), - ]); - - let obj = LayoutObj::new(Frame::left_aligned( - theme::label_title(), - TR::coinjoin__title.into(), - ButtonPage::new(paragraphs, theme::BG).with_hold()?, - ))?; - Ok(obj.into()) - }; - unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } -} - extern "C" fn new_show_share_words(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()?; @@ -1362,14 +1340,6 @@ pub static mp_module_trezorui2: Module = obj_module! { /// Meant to be used with confirm_with_info.""" Qstr::MP_QSTR_confirm_more => obj_fn_kw!(0, new_confirm_more).as_obj(), - /// def confirm_coinjoin( - /// *, - /// max_rounds: str, - /// max_feerate: str, - /// ) -> LayoutObj[UiResult]: - /// """Confirm coinjoin authorization.""" - Qstr::MP_QSTR_confirm_coinjoin => obj_fn_kw!(0, new_confirm_coinjoin).as_obj(), - /// def show_share_words( /// *, /// title: str, diff --git a/core/embed/rust/src/ui/model_tt/ui_features_fw.rs b/core/embed/rust/src/ui/model_tt/ui_features_fw.rs index dcdff4d91c..c4dade3747 100644 --- a/core/embed/rust/src/ui/model_tt/ui_features_fw.rs +++ b/core/embed/rust/src/ui/model_tt/ui_features_fw.rs @@ -99,6 +99,25 @@ impl UIFeaturesFirmware for ModelTTFeatures { Ok(layout) } + fn confirm_coinjoin( + max_rounds: TString<'static>, + max_feerate: TString<'static>, + ) -> Result { + let paragraphs = Paragraphs::new([ + Paragraph::new(&theme::TEXT_NORMAL, TR::coinjoin__max_rounds), + Paragraph::new(&theme::TEXT_MONO, max_rounds), + Paragraph::new(&theme::TEXT_NORMAL, TR::coinjoin__max_mining_fee), + Paragraph::new(&theme::TEXT_MONO, max_feerate), + ]); + + let layout = RootComponent::new(Frame::left_aligned( + theme::label_title(), + TR::coinjoin__title.into(), + ButtonPage::new(paragraphs, theme::BG).with_hold()?, + )); + Ok(layout) + } + fn confirm_firmware_update( description: TString<'static>, fingerprint: TString<'static>, diff --git a/core/embed/rust/src/ui/ui_features_fw.rs b/core/embed/rust/src/ui/ui_features_fw.rs index f719c2b6da..c4db947c90 100644 --- a/core/embed/rust/src/ui/ui_features_fw.rs +++ b/core/embed/rust/src/ui/ui_features_fw.rs @@ -25,6 +25,11 @@ pub trait UIFeaturesFirmware { image: BinaryData<'static>, ) -> Result; + fn confirm_coinjoin( + max_rounds: TString<'static>, + max_feerate: TString<'static>, + ) -> Result; + fn confirm_firmware_update( description: TString<'static>, fingerprint: TString<'static>, diff --git a/core/mocks/generated/trezorui2.pyi b/core/mocks/generated/trezorui2.pyi index 18b26d1273..0f42a6543f 100644 --- a/core/mocks/generated/trezorui2.pyi +++ b/core/mocks/generated/trezorui2.pyi @@ -219,15 +219,6 @@ def confirm_with_info( context menu.""" -# rust/src/ui/model_mercury/layout.rs -def confirm_coinjoin( - *, - max_rounds: str, - max_feerate: str, -) -> LayoutObj[UiResult]: - """Confirm coinjoin authorization.""" - - # rust/src/ui/model_mercury/layout.rs def flow_prompt_backup() -> LayoutObj[UiResult]: """Prompt a user to create backup with an option to skip.""" @@ -556,15 +547,6 @@ def confirm_more( Meant to be used with confirm_with_info.""" -# rust/src/ui/model_tr/layout.rs -def confirm_coinjoin( - *, - max_rounds: str, - max_feerate: str, -) -> LayoutObj[UiResult]: - """Confirm coinjoin authorization.""" - - # rust/src/ui/model_tr/layout.rs def show_share_words( *, @@ -843,15 +825,6 @@ def confirm_more( Meant to be used with confirm_with_info.""" -# rust/src/ui/model_tt/layout.rs -def confirm_coinjoin( - *, - max_rounds: str, - max_feerate: str, -) -> LayoutObj[UiResult]: - """Confirm coinjoin authorization.""" - - # rust/src/ui/model_tt/layout.rs def show_share_words( *, diff --git a/core/mocks/generated/trezorui_api.pyi b/core/mocks/generated/trezorui_api.pyi index fb8fd4a73b..eef24c70b3 100644 --- a/core/mocks/generated/trezorui_api.pyi +++ b/core/mocks/generated/trezorui_api.pyi @@ -96,6 +96,15 @@ def confirm_action( """Confirm action.""" +# rust/src/ui/api/firmware_upy.rs +def confirm_coinjoin( + *, + max_rounds: str, + max_feerate: str, +) -> LayoutObj[UiResult]: + """Confirm coinjoin authorization.""" + + # rust/src/ui/api/firmware_upy.rs def confirm_firmware_update( *, diff --git a/core/src/trezor/ui/layouts/mercury/__init__.py b/core/src/trezor/ui/layouts/mercury/__init__.py index 63c60b02cd..2fe765d2da 100644 --- a/core/src/trezor/ui/layouts/mercury/__init__.py +++ b/core/src/trezor/ui/layouts/mercury/__init__.py @@ -965,7 +965,7 @@ def confirm_modify_fee( def confirm_coinjoin(max_rounds: int, max_fee_per_vbyte: str) -> Awaitable[None]: return raise_if_not_confirmed( - trezorui2.confirm_coinjoin( + trezorui_api.confirm_coinjoin( max_rounds=str(max_rounds), max_feerate=max_fee_per_vbyte, ), diff --git a/core/src/trezor/ui/layouts/tr/__init__.py b/core/src/trezor/ui/layouts/tr/__init__.py index f26003df99..fa4a7dd97f 100644 --- a/core/src/trezor/ui/layouts/tr/__init__.py +++ b/core/src/trezor/ui/layouts/tr/__init__.py @@ -1052,7 +1052,7 @@ def confirm_modify_fee( def confirm_coinjoin(max_rounds: int, max_fee_per_vbyte: str) -> Awaitable[None]: return raise_if_not_confirmed( - trezorui2.confirm_coinjoin( + trezorui_api.confirm_coinjoin( max_rounds=str(max_rounds), max_feerate=max_fee_per_vbyte, ), diff --git a/core/src/trezor/ui/layouts/tt/__init__.py b/core/src/trezor/ui/layouts/tt/__init__.py index 1f439a863e..f09525eebc 100644 --- a/core/src/trezor/ui/layouts/tt/__init__.py +++ b/core/src/trezor/ui/layouts/tt/__init__.py @@ -1012,7 +1012,7 @@ def confirm_modify_fee( def confirm_coinjoin(max_rounds: int, max_fee_per_vbyte: str) -> Awaitable[None]: return raise_if_not_confirmed( - trezorui2.confirm_coinjoin( + trezorui_api.confirm_coinjoin( max_rounds=str(max_rounds), max_feerate=max_fee_per_vbyte, ),