diff --git a/core/embed/rust/librust_qstr.h b/core/embed/rust/librust_qstr.h index 74e82a4444..fed0411473 100644 --- a/core/embed/rust/librust_qstr.h +++ b/core/embed/rust/librust_qstr.h @@ -655,7 +655,6 @@ static void _librust_qstrs(void) { MP_QSTR_show_instructions; MP_QSTR_show_lockscreen; MP_QSTR_show_mismatch; - MP_QSTR_show_passphrase; MP_QSTR_show_progress; MP_QSTR_show_progress_coinjoin; MP_QSTR_show_remaining_shares; diff --git a/core/embed/rust/src/ui/api/firmware_upy.rs b/core/embed/rust/src/ui/api/firmware_upy.rs index 8b38a56457..707b035509 100644 --- a/core/embed/rust/src/ui/api/firmware_upy.rs +++ b/core/embed/rust/src/ui/api/firmware_upy.rs @@ -432,6 +432,24 @@ extern "C" fn new_show_remaining_shares(n_args: usize, args: *const Obj, kwargs: unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } } +extern "C" fn new_show_simple(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj { + let block = move |_args: &[Obj], kwargs: &Map| { + let text: TString = kwargs.get(Qstr::MP_QSTR_text)?.try_into()?; + let title: Option = kwargs + .get(Qstr::MP_QSTR_title) + .and_then(Obj::try_into_option) + .unwrap_or(None); + let button: Option = kwargs + .get(Qstr::MP_QSTR_button) + .and_then(Obj::try_into_option) + .unwrap_or(None); + + let obj = ModelUI::show_simple(text, title, button)?; + Ok(obj.into()) + }; + unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } +} + extern "C" fn new_show_success(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()?; @@ -834,6 +852,15 @@ pub static mp_module_trezorui_api: Module = obj_module! { /// """Shows SLIP39 state after info button is pressed on `confirm_recovery`.""" Qstr::MP_QSTR_show_remaining_shares => obj_fn_kw!(0, new_show_remaining_shares).as_obj(), + /// def show_simple( + /// *, + /// text: str, + /// title: str | None = None, + /// button: str | None = None, + /// ) -> LayoutObj[UiResult]: + /// """Simple dialog with text. TT: optional button.""" + Qstr::MP_QSTR_show_simple => obj_fn_kw!(0, new_show_simple).as_obj(), + /// def show_success( /// *, /// title: str, diff --git a/core/embed/rust/src/ui/model_mercury/layout.rs b/core/embed/rust/src/ui/model_mercury/layout.rs index 261b2433c8..89f569c4a4 100644 --- a/core/embed/rust/src/ui/model_mercury/layout.rs +++ b/core/embed/rust/src/ui/model_mercury/layout.rs @@ -690,20 +690,6 @@ extern "C" fn new_show_share_words(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_simple(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj { - let block = move |_args: &[Obj], kwargs: &Map| { - let description: TString = kwargs.get_or(Qstr::MP_QSTR_description, "".into())?; - - let obj = LayoutObj::new(Border::new( - theme::borders(), - Paragraphs::new(Paragraph::new(&theme::TEXT_DEMIBOLD, description)), - ))?; - - Ok(obj.into()) - }; - unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } -} - extern "C" fn new_confirm_with_info(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()?; @@ -973,15 +959,6 @@ pub static mp_module_trezorui2: Module = obj_module! { /// """ Qstr::MP_QSTR_confirm_fido => obj_fn_kw!(0, new_confirm_fido).as_obj(), - /// def show_simple( - /// *, - /// title: str | None, - /// description: str = "", - /// button: str = "", - /// ) -> LayoutObj[UiResult]: - /// """Simple dialog with text and one button.""" - Qstr::MP_QSTR_show_simple => obj_fn_kw!(0, new_show_simple).as_obj(), - /// def confirm_with_info( /// *, /// title: str, 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 30248460c1..aff5b0435a 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 @@ -14,7 +14,7 @@ use crate::{ Checklist, Paragraph, ParagraphSource, ParagraphVecLong, ParagraphVecShort, Paragraphs, VecExt, }, - CachedJpeg, ComponentExt, Empty, Never, Timeout, + Border, CachedJpeg, ComponentExt, Empty, Never, Timeout, }, geometry::{self, Direction}, layout::{ @@ -503,6 +503,18 @@ impl UIFeaturesFirmware for ModelMercuryFeatures { )) } + fn show_simple( + text: TString<'static>, + _title: Option>, + _button: Option>, + ) -> Result, Error> { + let obj = LayoutObj::new(Border::new( + theme::borders(), + Paragraphs::new(Paragraph::new(&theme::TEXT_DEMIBOLD, text)), + ))?; + Ok(obj) + } + fn show_success( title: TString<'static>, button: 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 1d8afe985c..29fc5cd370 100644 --- a/core/embed/rust/src/ui/model_tr/layout.rs +++ b/core/embed/rust/src/ui/model_tr/layout.rs @@ -842,28 +842,6 @@ extern "C" fn new_confirm_fido(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_show_passphrase() -> Obj { - let block = move || { - let text: TString = TR::passphrase__please_enter.into(); - let paragraph = Paragraph::new(&theme::TEXT_NORMAL, text).centered(); - let content = Paragraphs::new([paragraph]); - let obj = LayoutObj::new(content)?; - Ok(obj.into()) - }; - unsafe { util::try_or_raise(block) } -} - -extern "C" fn new_show_waiting_text(message: Obj) -> Obj { - let block = || { - let text: TString = message.try_into()?; - let paragraph = Paragraph::new(&theme::TEXT_NORMAL, text).centered(); - let content = Paragraphs::new([paragraph]); - let obj = LayoutObj::new(content)?; - Ok(obj.into()) - }; - unsafe { util::try_or_raise(block) } -} - extern "C" fn new_confirm_with_info(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()?; @@ -1132,10 +1110,6 @@ pub static mp_module_trezorui2: Module = obj_module! { /// """Show multiple texts, each on its own page.""" Qstr::MP_QSTR_multiple_pages_texts => obj_fn_kw!(0, new_multiple_pages_texts).as_obj(), - /// def show_passphrase() -> LayoutObj[UiResult]: - /// """Show passphrase on host dialog.""" - Qstr::MP_QSTR_show_passphrase => obj_fn_0!(new_show_passphrase).as_obj(), - /// def confirm_with_info( /// *, /// title: 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 8f1cb951c9..6a60e9788f 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 @@ -510,6 +510,17 @@ impl UIFeaturesFirmware for ModelTRFeatures { )) } + fn show_simple( + text: TString<'static>, + _title: Option>, + _button: Option>, + ) -> Result, Error> { + let paragraph = Paragraph::new(&theme::TEXT_NORMAL, text).centered(); + let content = Paragraphs::new([paragraph]); + let obj = LayoutObj::new(content)?; + Ok(obj) + } + fn show_success( title: TString<'static>, button: 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 d8f084f359..32e1dc86b7 100644 --- a/core/embed/rust/src/ui/model_tt/layout.rs +++ b/core/embed/rust/src/ui/model_tt/layout.rs @@ -733,53 +733,6 @@ extern "C" fn new_confirm_fido(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_show_simple(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj { - let block = move |_args: &[Obj], kwargs: &Map| { - let title: Option = kwargs.get(Qstr::MP_QSTR_title)?.try_into_option()?; - let description: TString = kwargs.get_or(Qstr::MP_QSTR_description, "".into())?; - let button: TString = kwargs.get_or(Qstr::MP_QSTR_button, "".into())?; - - let obj = if let Some(t) = title { - LayoutObj::new(Frame::left_aligned( - theme::label_title(), - t, - Dialog::new( - Paragraphs::new([Paragraph::new(&theme::TEXT_NORMAL, description)]), - theme::button_bar(Button::with_text(button).map(|msg| { - (matches!(msg, ButtonMsg::Clicked)).then(|| CancelConfirmMsg::Confirmed) - })), - ), - ))? - .into() - } else if !button.is_empty() { - LayoutObj::new(Border::new( - theme::borders(), - Dialog::new( - Paragraphs::new([Paragraph::new(&theme::TEXT_NORMAL, description)]), - theme::button_bar(Button::with_text(button).map(|msg| { - (matches!(msg, ButtonMsg::Clicked)).then(|| CancelConfirmMsg::Confirmed) - })), - ), - ))? - .into() - } else { - LayoutObj::new(Border::new( - theme::borders(), - Dialog::new( - Paragraphs::new( - [Paragraph::new(&theme::TEXT_DEMIBOLD, description).centered()], - ), - Empty, - ), - ))? - .into() - }; - - Ok(obj) - }; - unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } -} - extern "C" fn new_confirm_with_info(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()?; @@ -1033,15 +986,6 @@ pub static mp_module_trezorui2: Module = obj_module! { /// """ Qstr::MP_QSTR_confirm_fido => obj_fn_kw!(0, new_confirm_fido).as_obj(), - /// def show_simple( - /// *, - /// title: str | None, - /// description: str = "", - /// button: str = "", - /// ) -> LayoutObj[UiResult]: - /// """Simple dialog with text and one button.""" - Qstr::MP_QSTR_show_simple => obj_fn_kw!(0, new_show_simple).as_obj(), - /// def confirm_with_info( /// *, /// 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 50ee840977..023b3893e9 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 @@ -14,7 +14,7 @@ use crate::{ Checklist, Paragraph, ParagraphSource, ParagraphVecLong, ParagraphVecShort, Paragraphs, VecExt, }, - ComponentExt, Empty, Jpeg, Label, Never, Timeout, + Border, ComponentExt, Empty, Jpeg, Label, Never, Timeout, }, layout::{ obj::{LayoutMaybeTrace, LayoutObj, RootComponent}, @@ -587,6 +587,44 @@ impl UIFeaturesFirmware for ModelTTFeatures { Ok(layout) } + fn show_simple( + text: TString<'static>, + title: Option>, + button: Option>, + ) -> Result, Error> { + let button = button.unwrap_or(TString::empty()); + if let Some(t) = title { + LayoutObj::new(Frame::left_aligned( + theme::label_title(), + t, + Dialog::new( + Paragraphs::new([Paragraph::new(&theme::TEXT_NORMAL, text)]), + theme::button_bar(Button::with_text(button).map(|msg| { + (matches!(msg, ButtonMsg::Clicked)).then(|| CancelConfirmMsg::Confirmed) + })), + ), + )) + } else if !button.is_empty() { + LayoutObj::new(Border::new( + theme::borders(), + Dialog::new( + Paragraphs::new([Paragraph::new(&theme::TEXT_NORMAL, text)]), + theme::button_bar(Button::with_text(button).map(|msg| { + (matches!(msg, ButtonMsg::Clicked)).then(|| CancelConfirmMsg::Confirmed) + })), + ), + )) + } else { + LayoutObj::new(Border::new( + theme::borders(), + Dialog::new( + Paragraphs::new([Paragraph::new(&theme::TEXT_DEMIBOLD, text).centered()]), + Empty, + ), + )) + } + } + fn show_success( title: TString<'static>, button: 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 3c317b49ab..5039951ea5 100644 --- a/core/embed/rust/src/ui/ui_features_fw.rs +++ b/core/embed/rust/src/ui/ui_features_fw.rs @@ -159,6 +159,12 @@ pub trait UIFeaturesFirmware { pages_iterable: Obj, // TODO: replace Obj ) -> Result; + fn show_simple( + text: TString<'static>, + title: Option>, + button: Option>, + ) -> Result, Error>; // TODO: return LayoutMaybeTrace + fn show_success( title: TString<'static>, button: TString<'static>, diff --git a/core/mocks/generated/trezorui2.pyi b/core/mocks/generated/trezorui2.pyi index 5cdd8cb406..d453efe50d 100644 --- a/core/mocks/generated/trezorui2.pyi +++ b/core/mocks/generated/trezorui2.pyi @@ -121,16 +121,6 @@ def confirm_fido( """ -# rust/src/ui/model_mercury/layout.rs -def show_simple( - *, - title: str | None, - description: str = "", - button: str = "", -) -> LayoutObj[UiResult]: - """Simple dialog with text and one button.""" - - # rust/src/ui/model_mercury/layout.rs def confirm_with_info( *, @@ -412,11 +402,6 @@ def multiple_pages_texts( """Show multiple texts, each on its own page.""" -# rust/src/ui/model_tr/layout.rs -def show_passphrase() -> LayoutObj[UiResult]: - """Show passphrase on host dialog.""" - - # rust/src/ui/model_tr/layout.rs def confirm_with_info( *, @@ -587,16 +572,6 @@ def confirm_fido( """ -# rust/src/ui/model_tt/layout.rs -def show_simple( - *, - title: str | None, - description: str = "", - button: str = "", -) -> LayoutObj[UiResult]: - """Simple dialog with text and one button.""" - - # rust/src/ui/model_tt/layout.rs def confirm_with_info( *, diff --git a/core/mocks/generated/trezorui_api.pyi b/core/mocks/generated/trezorui_api.pyi index 49c1135790..3d9decf697 100644 --- a/core/mocks/generated/trezorui_api.pyi +++ b/core/mocks/generated/trezorui_api.pyi @@ -335,6 +335,16 @@ def show_remaining_shares( """Shows SLIP39 state after info button is pressed on `confirm_recovery`.""" +# rust/src/ui/api/firmware_upy.rs +def show_simple( + *, + text: str, + title: str | None = None, + button: str | None = None, +) -> LayoutObj[UiResult]: + """Simple dialog with text. TT: optional button.""" + + # rust/src/ui/api/firmware_upy.rs def show_success( *, diff --git a/core/src/trezor/ui/layouts/mercury/__init__.py b/core/src/trezor/ui/layouts/mercury/__init__.py index 00ea0f8ee5..bf1c589a22 100644 --- a/core/src/trezor/ui/layouts/mercury/__init__.py +++ b/core/src/trezor/ui/layouts/mercury/__init__.py @@ -1085,9 +1085,9 @@ def error_popup( def request_passphrase_on_host() -> None: draw_simple( - trezorui2.show_simple( + trezorui_api.show_simple( title=None, - description=TR.passphrase__please_enter, + text=TR.passphrase__please_enter, ) ) diff --git a/core/src/trezor/ui/layouts/tr/__init__.py b/core/src/trezor/ui/layouts/tr/__init__.py index bc4802fabd..7dab84b7ad 100644 --- a/core/src/trezor/ui/layouts/tr/__init__.py +++ b/core/src/trezor/ui/layouts/tr/__init__.py @@ -1136,7 +1136,12 @@ def error_popup( def request_passphrase_on_host() -> None: - draw_simple(trezorui2.show_passphrase()) + draw_simple( + trezorui_api.show_simple( + title=None, + text=TR.passphrase__please_enter, + ) + ) def show_wait_text(message: str) -> None: diff --git a/core/src/trezor/ui/layouts/tt/__init__.py b/core/src/trezor/ui/layouts/tt/__init__.py index 78842b520e..89fdbd3939 100644 --- a/core/src/trezor/ui/layouts/tt/__init__.py +++ b/core/src/trezor/ui/layouts/tt/__init__.py @@ -1133,9 +1133,9 @@ def error_popup( def request_passphrase_on_host() -> None: draw_simple( - trezorui2.show_simple( + trezorui_api.show_simple( title=None, - description=TR.passphrase__please_enter, + text=TR.passphrase__please_enter, ) ) diff --git a/core/src/trezor/ui/layouts/tt/reset.py b/core/src/trezor/ui/layouts/tt/reset.py index 231aad0750..2a580b2e56 100644 --- a/core/src/trezor/ui/layouts/tt/reset.py +++ b/core/src/trezor/ui/layouts/tt/reset.py @@ -168,9 +168,9 @@ async def _prompt_number( return value await interact( - trezorui2.show_simple( + trezorui_api.show_simple( title=None, - description=info(value), + text=info(value), button=TR.buttons__ok_i_understand, ), None,