From 5dde0f2961194d56a4622a17a655e5cc57ac070f Mon Sep 17 00:00:00 2001 From: obrusvit Date: Wed, 12 Feb 2025 02:44:44 +0100 Subject: [PATCH] feat(eckhart): implement a few show_xyz functions --- .../rust/src/ui/api/firmware_micropython.rs | 2 +- .../rust/src/ui/layout_eckhart/ui_firmware.rs | 103 ++++++++++++++---- .../src/trezor/ui/layouts/eckhart/__init__.py | 6 +- 3 files changed, 86 insertions(+), 25 deletions(-) diff --git a/core/embed/rust/src/ui/api/firmware_micropython.rs b/core/embed/rust/src/ui/api/firmware_micropython.rs index 10eea0a46c..ff5c773e0b 100644 --- a/core/embed/rust/src/ui/api/firmware_micropython.rs +++ b/core/embed/rust/src/ui/api/firmware_micropython.rs @@ -1643,7 +1643,7 @@ pub static mp_module_trezorui_api: Module = obj_module! { /// title: str, /// button: str, /// description: str = "", - /// allow_cancel: bool = True, + /// allow_cancel: bool = False, /// time_ms: int = 0, /// ) -> LayoutObj[UiResult]: /// """Success modal. No buttons shown when `button` is empty string.""" diff --git a/core/embed/rust/src/ui/layout_eckhart/ui_firmware.rs b/core/embed/rust/src/ui/layout_eckhart/ui_firmware.rs index 5071043bc8..b1bd638cc2 100644 --- a/core/embed/rust/src/ui/layout_eckhart/ui_firmware.rs +++ b/core/embed/rust/src/ui/layout_eckhart/ui_firmware.rs @@ -8,7 +8,7 @@ use crate::{ component::{ text::{ op::OpTextLayout, - paragraphs::{Paragraph, ParagraphSource, ParagraphVecShort, VecExt}, + paragraphs::{Paragraph, ParagraphSource, ParagraphVecShort, Paragraphs, VecExt}, }, Empty, FormattedText, }, @@ -514,8 +514,22 @@ impl FirmwareUI for UIEckhart { Err::, Error>(Error::ValueError(c"not implemented")) } - fn show_mismatch(_title: TString<'static>) -> Result { - Err::, Error>(Error::ValueError(c"not implemented")) + fn show_mismatch(title: TString<'static>) -> Result { + let description: TString = TR::addr_mismatch__contact_support_at.into(); + let url: TString = TR::addr_mismatch__support_url.into(); + let button: TString = TR::buttons__quit.into(); + + let paragraphs = ParagraphVecShort::from_iter([ + Paragraph::new(&theme::TEXT_REGULAR, description).centered(), + Paragraph::new(&theme::TEXT_MONO_MEDIUM, url).centered(), + ]) + .into_paragraphs(); + let screen = TextScreen::new(paragraphs) + .with_header(Header::new(title)) + .with_action_bar(ActionBar::new_single(Button::with_text(button))); + + let layout = RootComponent::new(screen); + Ok(layout) } fn show_progress( @@ -557,36 +571,83 @@ impl FirmwareUI for UIEckhart { } fn show_simple( - _text: TString<'static>, - _title: Option>, - _button: Option>, + text: TString<'static>, + title: Option>, + button: Option>, ) -> Result, Error> { - Err::, Error>(Error::ValueError(c"not implemented")) + let paragraphs = Paragraph::new(&theme::TEXT_REGULAR, text).into_paragraphs(); + + let mut screen = TextScreen::new(paragraphs); + if let Some(title) = title { + screen = screen.with_header(Header::new(title)); + } + if let Some(button) = button { + screen = screen.with_action_bar(ActionBar::new_single(Button::with_text(button))); + } + + let obj = LayoutObj::new(screen)?; + Ok(obj) } fn show_success( - _title: TString<'static>, - _button: TString<'static>, - _description: TString<'static>, - _allow_cancel: bool, + title: TString<'static>, + button: TString<'static>, + description: TString<'static>, + allow_cancel: bool, _time_ms: u32, ) -> Result, Error> { - Err::, Error>(Error::ValueError(c"not implemented")) + let paragraphs = Paragraph::new(&theme::TEXT_REGULAR, description).into_paragraphs(); + let header = Header::new(title).with_icon(theme::ICON_DONE, theme::GREEN_LIGHT); + let action_bar = if allow_cancel { + ActionBar::new_double( + Button::with_icon(theme::ICON_CROSS), + Button::with_text(button), + ) + } else { + ActionBar::new_single(Button::with_text(button)) + }; + let screen = TextScreen::new(paragraphs) + .with_header(header) + .with_action_bar(action_bar); + let layout = LayoutObj::new(screen)?; + Ok(layout) } - fn show_wait_text(_text: TString<'static>) -> Result { - Err::, Error>(Error::ValueError(c"not implemented")) + fn show_wait_text(text: TString<'static>) -> Result { + let paragraphs = Paragraph::new(&theme::TEXT_REGULAR, text).into_paragraphs(); + let screen = TextScreen::new(paragraphs); + let layout = RootComponent::new(screen); + Ok(layout) } fn show_warning( - _title: TString<'static>, - _button: TString<'static>, - _value: TString<'static>, - _description: TString<'static>, - _allow_cancel: bool, - _danger: bool, + title: TString<'static>, + button: TString<'static>, + value: TString<'static>, + description: TString<'static>, + allow_cancel: bool, + danger: bool, // TODO: review if `danger` needed in all layouts since we have show_danger ) -> Result, Error> { - Err::, Error>(Error::ValueError(c"not implemented")) + let paragraphs = ParagraphVecShort::from_iter([ + Paragraph::new(&theme::TEXT_SMALL, description), + Paragraph::new(&theme::TEXT_REGULAR, value), + ]) + .into_paragraphs(); + + let header = Header::new(title).with_icon(theme::ICON_INFO, theme::GREEN_LIGHT); + let action_bar = if allow_cancel { + ActionBar::new_double( + Button::with_icon(theme::ICON_CROSS), + Button::with_text(button), + ) + } else { + ActionBar::new_single(Button::with_text(button)) + }; + let screen = TextScreen::new(paragraphs) + .with_header(header) + .with_action_bar(action_bar); + let layout = LayoutObj::new(screen)?; + Ok(layout) } fn tutorial() -> Result { diff --git a/core/src/trezor/ui/layouts/eckhart/__init__.py b/core/src/trezor/ui/layouts/eckhart/__init__.py index cfacfe415b..5468ea9412 100644 --- a/core/src/trezor/ui/layouts/eckhart/__init__.py +++ b/core/src/trezor/ui/layouts/eckhart/__init__.py @@ -356,9 +356,9 @@ def show_success( ) -> Awaitable[None]: return raise_if_not_confirmed( trezorui_api.show_success( - title=content, - button="", - description=subheader if subheader else "", + title=subheader if subheader else "", + button=button if button else "", + description=content, ), br_name, ButtonRequestType.Success,