From 6bb6ce401ccf82bb400ae04628ebe6860592cdc2 Mon Sep 17 00:00:00 2001 From: obrusvit Date: Sun, 3 Nov 2024 17:22:42 +0100 Subject: [PATCH] refactor(core): move show_group_share_success --- core/embed/rust/src/ui/api/firmware_upy.rs | 22 ++++++++ .../embed/rust/src/ui/model_mercury/layout.rs | 36 ------------ .../src/ui/model_mercury/ui_features_fw.rs | 22 +++++++- core/embed/rust/src/ui/model_tr/layout.rs | 36 ------------ .../rust/src/ui/model_tr/ui_features_fw.rs | 18 ++++++ core/embed/rust/src/ui/model_tt/layout.rs | 27 --------- .../rust/src/ui/model_tt/ui_features_fw.rs | 12 ++++ core/embed/rust/src/ui/ui_features_fw.rs | 4 ++ core/mocks/generated/trezorui2.pyi | 55 +------------------ core/mocks/generated/trezorui_api.pyi | 8 +++ .../src/trezor/ui/layouts/mercury/recovery.py | 2 +- core/src/trezor/ui/layouts/tr/recovery.py | 2 +- core/src/trezor/ui/layouts/tt/recovery.py | 2 +- 13 files changed, 89 insertions(+), 157 deletions(-) diff --git a/core/embed/rust/src/ui/api/firmware_upy.rs b/core/embed/rust/src/ui/api/firmware_upy.rs index 6384b270f1..ac5b060da5 100644 --- a/core/embed/rust/src/ui/api/firmware_upy.rs +++ b/core/embed/rust/src/ui/api/firmware_upy.rs @@ -299,6 +299,21 @@ extern "C" fn new_show_checklist(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_show_group_share_success( + n_args: usize, + args: *const Obj, + kwargs: *mut Map, +) -> Obj { + let block = move |_args: &[Obj], kwargs: &Map| { + let lines_iterable: Obj = kwargs.get(Qstr::MP_QSTR_lines)?; + let lines: [TString; 4] = util::iter_into_array(lines_iterable)?; + + let layout = ModelUI::show_group_share_success(lines)?; + Ok(LayoutObj::new_root(layout)?.into()) + }; + unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } +} + extern "C" fn new_show_homescreen(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj { let block = move |_args: &[Obj], kwargs: &Map| { let label: TString<'static> = kwargs @@ -676,6 +691,13 @@ pub static mp_module_trezorui_api: Module = obj_module! { /// mark next to them. Limited to 3 items.""" Qstr::MP_QSTR_show_checklist => obj_fn_kw!(0, new_show_checklist).as_obj(), + /// def show_group_share_success( + /// *, + /// lines: Iterable[str], + /// ) -> LayoutObj[UiResult]: + /// """Shown after successfully finishing a group.""" + Qstr::MP_QSTR_show_group_share_success => obj_fn_kw!(0, new_show_group_share_success).as_obj(), + /// def show_homescreen( /// *, /// label: str | None, diff --git a/core/embed/rust/src/ui/model_mercury/layout.rs b/core/embed/rust/src/ui/model_mercury/layout.rs index b02dc53b8e..b9d8ccf09c 100644 --- a/core/embed/rust/src/ui/model_mercury/layout.rs +++ b/core/embed/rust/src/ui/model_mercury/layout.rs @@ -909,35 +909,6 @@ extern "C" fn new_prompt_backup() -> Obj { unsafe { util::try_or_raise(block) } } -extern "C" fn new_show_group_share_success( - n_args: usize, - args: *const Obj, - kwargs: *mut Map, -) -> Obj { - let block = move |_args: &[Obj], kwargs: &Map| { - let lines_iterable: Obj = kwargs.get(Qstr::MP_QSTR_lines)?; - let lines: [TString; 4] = util::iter_into_array(lines_iterable)?; - - let paragraphs = ParagraphVecShort::from_iter([ - Paragraph::new(&theme::TEXT_NORMAL_GREY_EXTRA_LIGHT, lines[0]).centered(), - Paragraph::new(&theme::TEXT_DEMIBOLD, lines[1]).centered(), - Paragraph::new(&theme::TEXT_NORMAL_GREY_EXTRA_LIGHT, lines[2]).centered(), - Paragraph::new(&theme::TEXT_DEMIBOLD, lines[3]).centered(), - ]) - .into_paragraphs() - .with_placement(geometry::LinearPlacement::vertical().align_at_center()); - - let obj = LayoutObj::new(SwipeUpScreen::new( - Frame::left_aligned("".into(), SwipeContent::new(paragraphs)) - .with_footer(TR::instructions__swipe_up.into(), None) - .with_swipe(Direction::Up, SwipeSettings::default()), - ))?; - - Ok(obj.into()) - }; - unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } -} - extern "C" fn new_confirm_fido(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj { #[cfg(feature = "universal_fw")] return flow::confirm_fido::new_confirm_fido(n_args, args, kwargs); @@ -1173,13 +1144,6 @@ pub static mp_module_trezorui2: Module = obj_module! { /// """Device recovery homescreen.""" Qstr::MP_QSTR_flow_continue_recovery => obj_fn_kw!(0, new_continue_recovery).as_obj(), - /// def show_group_share_success( - /// *, - /// lines: Iterable[str] - /// ) -> LayoutObj[UiResult]: - /// """Shown after successfully finishing a group.""" - Qstr::MP_QSTR_show_group_share_success => obj_fn_kw!(0, new_show_group_share_success).as_obj(), - /// def flow_get_address( /// *, /// address: str | bytes, 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 0236aafebd..1f9651dac3 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 @@ -16,7 +16,7 @@ use crate::{ }, CachedJpeg, ComponentExt, Never, Timeout, }, - geometry::Direction, + geometry::{self, Direction}, layout::{ obj::{LayoutMaybeTrace, LayoutObj, RootComponent}, util::RecoveryType, @@ -359,6 +359,26 @@ impl UIFeaturesFirmware for ModelMercuryFeatures { Ok(layout) } + fn show_group_share_success( + lines: [TString<'static>; 4], + ) -> Result { + let paragraphs = ParagraphVecShort::from_iter([ + Paragraph::new(&theme::TEXT_NORMAL_GREY_EXTRA_LIGHT, lines[0]).centered(), + Paragraph::new(&theme::TEXT_DEMIBOLD, lines[1]).centered(), + Paragraph::new(&theme::TEXT_NORMAL_GREY_EXTRA_LIGHT, lines[2]).centered(), + Paragraph::new(&theme::TEXT_DEMIBOLD, lines[3]).centered(), + ]) + .into_paragraphs() + .with_placement(geometry::LinearPlacement::vertical().align_at_center()); + + let layout = RootComponent::new(SwipeUpScreen::new( + Frame::left_aligned("".into(), SwipeContent::new(paragraphs)) + .with_footer(TR::instructions__swipe_up.into(), None) + .with_swipe(Direction::Up, SwipeSettings::default()), + )); + Ok(layout) + } + fn show_homescreen( label: TString<'static>, hold: bool, diff --git a/core/embed/rust/src/ui/model_tr/layout.rs b/core/embed/rust/src/ui/model_tr/layout.rs index 1719b3d04a..b20240ac39 100644 --- a/core/embed/rust/src/ui/model_tr/layout.rs +++ b/core/embed/rust/src/ui/model_tr/layout.rs @@ -1014,35 +1014,6 @@ extern "C" fn new_confirm_recovery(n_args: usize, args: *const Obj, kwargs: *mut unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } } -extern "C" fn new_show_group_share_success( - n_args: usize, - args: *const Obj, - kwargs: *mut Map, -) -> Obj { - let block = move |_args: &[Obj], kwargs: &Map| { - let lines_iterable: Obj = kwargs.get(Qstr::MP_QSTR_lines)?; - let lines: [TString; 4] = util::iter_into_array(lines_iterable)?; - - let [l0, l1, l2, l3] = lines; - - let paragraphs = Paragraphs::new([ - Paragraph::new(&theme::TEXT_MONO, l0), - Paragraph::new(&theme::TEXT_BOLD, l1), - Paragraph::new(&theme::TEXT_MONO, l2), - Paragraph::new(&theme::TEXT_BOLD, l3), - ]); - - content_in_button_page( - "".into(), - paragraphs, - TR::buttons__continue.into(), - None, - false, - ) - }; - unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } -} - #[no_mangle] pub static mp_module_trezorui2: Module = obj_module! { /// from trezor import utils @@ -1246,11 +1217,4 @@ pub static mp_module_trezorui2: Module = obj_module! { /// ) -> LayoutObj[UiResult]: /// """Device recovery homescreen.""" Qstr::MP_QSTR_confirm_recovery => obj_fn_kw!(0, new_confirm_recovery).as_obj(), - - /// def show_group_share_success( - /// *, - /// lines: Iterable[str], - /// ) -> LayoutObj[int]: - /// """Shown after successfully finishing a group.""" - Qstr::MP_QSTR_show_group_share_success => obj_fn_kw!(0, new_show_group_share_success).as_obj(), }; 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 6921a62b92..02a6409d50 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 @@ -375,6 +375,24 @@ impl UIFeaturesFirmware for ModelTRFeatures { Ok(layout) } + fn show_group_share_success( + lines: [TString<'static>; 4], + ) -> Result { + let paragraphs = Paragraphs::new([ + Paragraph::new(&theme::TEXT_MONO, lines[0]), + Paragraph::new(&theme::TEXT_BOLD, lines[1]), + Paragraph::new(&theme::TEXT_MONO, lines[2]), + Paragraph::new(&theme::TEXT_BOLD, lines[3]), + ]); + content_in_button_page( + "".into(), + paragraphs, + TR::buttons__continue.into(), + None, + false, + ) + } + fn show_homescreen( label: TString<'static>, hold: bool, diff --git a/core/embed/rust/src/ui/model_tt/layout.rs b/core/embed/rust/src/ui/model_tt/layout.rs index 865c0b9fed..48826bf0a6 100644 --- a/core/embed/rust/src/ui/model_tt/layout.rs +++ b/core/embed/rust/src/ui/model_tt/layout.rs @@ -1023,26 +1023,6 @@ extern "C" fn new_confirm_recovery(n_args: usize, args: *const Obj, kwargs: *mut unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } } -extern "C" fn new_show_group_share_success( - n_args: usize, - args: *const Obj, - kwargs: *mut Map, -) -> Obj { - let block = move |_args: &[Obj], kwargs: &Map| { - let lines_iterable: Obj = kwargs.get(Qstr::MP_QSTR_lines)?; - let lines: [TString; 4] = util::iter_into_array(lines_iterable)?; - - let obj = LayoutObj::new(IconDialog::new_shares( - lines, - theme::button_bar(Button::with_text(TR::buttons__continue.into()).map(|msg| { - (matches!(msg, ButtonMsg::Clicked)).then(|| CancelConfirmMsg::Confirmed) - })), - ))?; - Ok(obj.into()) - }; - unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } -} - extern "C" fn new_show_remaining_shares(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj { let block = move |_args: &[Obj], kwargs: &Map| { let pages_iterable: Obj = kwargs.get(Qstr::MP_QSTR_pages)?; @@ -1275,13 +1255,6 @@ pub static mp_module_trezorui2: Module = obj_module! { /// """Device recovery homescreen.""" Qstr::MP_QSTR_confirm_recovery => obj_fn_kw!(0, new_confirm_recovery).as_obj(), - /// def show_group_share_success( - /// *, - /// lines: Iterable[str] - /// ) -> LayoutObj[UiResult]: - /// """Shown after successfully finishing a group.""" - Qstr::MP_QSTR_show_group_share_success => obj_fn_kw!(0, new_show_group_share_success).as_obj(), - /// def show_remaining_shares( /// *, /// pages: Iterable[tuple[str, 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 1f666aa884..f52630731c 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 @@ -406,6 +406,18 @@ impl UIFeaturesFirmware for ModelTTFeatures { Ok(layout) } + fn show_group_share_success( + lines: [TString<'static>; 4], + ) -> Result { + let layout = RootComponent::new(IconDialog::new_shares( + lines, + theme::button_bar(Button::with_text(TR::buttons__continue.into()).map(|msg| { + (matches!(msg, ButtonMsg::Clicked)).then(|| CancelConfirmMsg::Confirmed) + })), + )); + Ok(layout) + } + fn show_homescreen( label: TString<'static>, hold: bool, diff --git a/core/embed/rust/src/ui/ui_features_fw.rs b/core/embed/rust/src/ui/ui_features_fw.rs index 32fe7a350e..3764c399cd 100644 --- a/core/embed/rust/src/ui/ui_features_fw.rs +++ b/core/embed/rust/src/ui/ui_features_fw.rs @@ -103,6 +103,10 @@ pub trait UIFeaturesFirmware { items: [TString<'static>; 3], ) -> Result; + fn show_group_share_success( + lines: [TString<'static>; 4], + ) -> Result; + fn show_homescreen( label: TString<'static>, hold: bool, diff --git a/core/mocks/generated/trezorui2.pyi b/core/mocks/generated/trezorui2.pyi index afa4c25b73..63ef0de2eb 100644 --- a/core/mocks/generated/trezorui2.pyi +++ b/core/mocks/generated/trezorui2.pyi @@ -223,14 +223,6 @@ def flow_continue_recovery( """Device recovery homescreen.""" -# rust/src/ui/model_mercury/layout.rs -def show_group_share_success( - *, - lines: Iterable[str] -) -> LayoutObj[UiResult]: - """Shown after successfully finishing a group.""" - - # rust/src/ui/model_mercury/layout.rs def flow_get_address( *, @@ -515,44 +507,7 @@ def confirm_recovery( info_button: bool, # unused on TR show_instructions: bool, ) -> LayoutObj[UiResult]: - """Device recovery homescreen.""" - - -# rust/src/ui/model_tr/layout.rs -def show_group_share_success( - *, - lines: Iterable[str], -) -> LayoutObj[int]: - """Shown after successfully finishing a group.""" - - -# rust/src/ui/model_tr/layout.rs -def show_progress( - *, - description: str, - indeterminate: bool = False, - title: str | None = None, -) -> LayoutObj[UiResult]: - """Show progress loader. Please note that the number of lines reserved on screen for - description is determined at construction time. If you want multiline descriptions - make sure the initial description has at least that amount of lines.""" - - -# rust/src/ui/model_tr/layout.rs -def show_progress_coinjoin( - *, - title: str, - indeterminate: bool = False, - time_ms: int = 0, - skip_first_paint: bool = False, -) -> LayoutObj[UiResult]: - """Show progress loader for coinjoin. Returns CANCELLED after a specified time when - time_ms timeout is passed.""" - - -# rust/src/ui/model_tr/layout.rs -def show_wait_text(message: str, /) -> None: - """Show single-line text in the middle of the screen.""" + """Device recovery homescreen.""" from trezor import utils from trezorui_api import * @@ -774,14 +729,6 @@ def confirm_recovery( """Device recovery homescreen.""" -# rust/src/ui/model_tt/layout.rs -def show_group_share_success( - *, - lines: Iterable[str] -) -> LayoutObj[UiResult]: - """Shown after successfully finishing a group.""" - - # rust/src/ui/model_tt/layout.rs def show_remaining_shares( *, diff --git a/core/mocks/generated/trezorui_api.pyi b/core/mocks/generated/trezorui_api.pyi index 224b4bb55d..0602e03514 100644 --- a/core/mocks/generated/trezorui_api.pyi +++ b/core/mocks/generated/trezorui_api.pyi @@ -244,6 +244,14 @@ def show_checklist( mark next to them. Limited to 3 items.""" +# rust/src/ui/api/firmware_upy.rs +def show_group_share_success( + *, + lines: Iterable[str], +) -> LayoutObj[UiResult]: + """Shown after successfully finishing a group.""" + + # rust/src/ui/api/firmware_upy.rs def show_homescreen( *, diff --git a/core/src/trezor/ui/layouts/mercury/recovery.py b/core/src/trezor/ui/layouts/mercury/recovery.py index fb90b4c248..2f009c8932 100644 --- a/core/src/trezor/ui/layouts/mercury/recovery.py +++ b/core/src/trezor/ui/layouts/mercury/recovery.py @@ -86,7 +86,7 @@ def format_remaining_shares_info( async def show_group_share_success(share_index: int, group_index: int) -> None: await raise_if_not_confirmed( - trezorui2.show_group_share_success( + trezorui_api.show_group_share_success( lines=[ TR.recovery__you_have_entered, TR.recovery__share_num_template.format(share_index + 1), diff --git a/core/src/trezor/ui/layouts/tr/recovery.py b/core/src/trezor/ui/layouts/tr/recovery.py index bcf6605a6f..4b200ed1c1 100644 --- a/core/src/trezor/ui/layouts/tr/recovery.py +++ b/core/src/trezor/ui/layouts/tr/recovery.py @@ -65,7 +65,7 @@ def show_group_share_success( share_index: int, group_index: int ) -> Awaitable[ui.UiResult]: return interact( - trezorui2.show_group_share_success( + trezorui_api.show_group_share_success( lines=[ TR.recovery__you_have_entered, TR.recovery__share_num_template.format(share_index + 1), diff --git a/core/src/trezor/ui/layouts/tt/recovery.py b/core/src/trezor/ui/layouts/tt/recovery.py index 2fa89e4f6d..1f769fbf5c 100644 --- a/core/src/trezor/ui/layouts/tt/recovery.py +++ b/core/src/trezor/ui/layouts/tt/recovery.py @@ -92,7 +92,7 @@ def show_group_share_success( share_index: int, group_index: int ) -> Awaitable[ui.UiResult]: return interact( - trezorui2.show_group_share_success( + trezorui_api.show_group_share_success( lines=[ TR.recovery__you_have_entered, TR.recovery__share_num_template.format(share_index + 1),