From c741b2baba430ed3caad803c52c333fae9b7e9c4 Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Wed, 10 Apr 2024 13:08:42 +0200 Subject: [PATCH] fixup! feat(core/ui): rust-based UI flows --- core/embed/rust/librust_qstr.h | 2 -- core/embed/rust/src/ui/flow/flow.rs | 10 +++++----- core/embed/rust/src/ui/flow/mod.rs | 2 +- core/embed/rust/src/ui/mod.rs | 2 +- .../rust/src/ui/model_mercury/flow/get_address.rs | 7 +++---- core/embed/rust/src/ui/model_mercury/layout.rs | 7 ++----- core/mocks/generated/trezorui2.pyi | 10 +++++----- core/src/apps/base.py | 1 - 8 files changed, 17 insertions(+), 24 deletions(-) diff --git a/core/embed/rust/librust_qstr.h b/core/embed/rust/librust_qstr.h index 00d325353..3981f8fa9 100644 --- a/core/embed/rust/librust_qstr.h +++ b/core/embed/rust/librust_qstr.h @@ -203,9 +203,7 @@ static void _librust_qstrs(void) { MP_QSTR_fingerprint; MP_QSTR_firmware_update__title; MP_QSTR_firmware_update__title_fingerprint; - MP_QSTR_flow; MP_QSTR_flow_get_address; - MP_QSTR_get_address; MP_QSTR_get_language; MP_QSTR_hold; MP_QSTR_hold_danger; diff --git a/core/embed/rust/src/ui/flow/flow.rs b/core/embed/rust/src/ui/flow/flow.rs index 5811880f2..2bb622786 100644 --- a/core/embed/rust/src/ui/flow/flow.rs +++ b/core/embed/rust/src/ui/flow/flow.rs @@ -18,7 +18,7 @@ const ANIMATION_DURATION: Duration = Duration::from_millis(333); /// If a swipe is detected: /// - currently active component is asked to handle the event, /// - if it can't then FlowState::handle_swipe is consulted. -pub struct Flow { +pub struct SwipeFlow { /// Current state. state: Q, /// FlowStore with all screens/components. @@ -37,7 +37,7 @@ struct Transition { direction: SwipeDirection, } -impl Flow { +impl SwipeFlow { pub fn new(init: Q, store: S) -> Result { Ok(Self { state: init, @@ -126,7 +126,7 @@ impl Flow { } } -impl Component for Flow { +impl Component for SwipeFlow { type Msg = FlowMsg; fn place(&mut self, bounds: Rect) -> Rect { @@ -178,14 +178,14 @@ impl Component for Flow { } #[cfg(feature = "ui_debug")] -impl crate::trace::Trace for Flow { +impl crate::trace::Trace for SwipeFlow { fn trace(&self, t: &mut dyn crate::trace::Tracer) { self.store.trace(self.state.index(), t) } } #[cfg(feature = "micropython")] -impl crate::ui::layout::obj::ComponentMsgObj for Flow { +impl crate::ui::layout::obj::ComponentMsgObj for SwipeFlow { fn msg_try_into_obj( &self, msg: Self::Msg, diff --git a/core/embed/rust/src/ui/flow/mod.rs b/core/embed/rust/src/ui/flow/mod.rs index be55fe0fb..6f3d1f45a 100644 --- a/core/embed/rust/src/ui/flow/mod.rs +++ b/core/embed/rust/src/ui/flow/mod.rs @@ -5,6 +5,6 @@ mod store; mod swipe; pub use base::{FlowMsg, FlowState, Swipable, SwipeDirection}; -pub use flow::Flow; +pub use flow::SwipeFlow; pub use page::{IgnoreSwipe, SwipePage}; pub use store::{flow_store, FlowStore}; diff --git a/core/embed/rust/src/ui/mod.rs b/core/embed/rust/src/ui/mod.rs index 83742af66..d26168eb7 100644 --- a/core/embed/rust/src/ui/mod.rs +++ b/core/embed/rust/src/ui/mod.rs @@ -6,7 +6,7 @@ pub mod component; pub mod constant; pub mod display; pub mod event; -#[cfg(feature = "micropython")] +#[cfg(all(feature = "micropython", feature = "model_mercury"))] pub mod flow; pub mod geometry; pub mod lerp; diff --git a/core/embed/rust/src/ui/model_mercury/flow/get_address.rs b/core/embed/rust/src/ui/model_mercury/flow/get_address.rs index e3c55a1c2..c5fe1d10c 100644 --- a/core/embed/rust/src/ui/model_mercury/flow/get_address.rs +++ b/core/embed/rust/src/ui/model_mercury/flow/get_address.rs @@ -7,7 +7,7 @@ use crate::{ Qr, Timeout, }, flow::{ - base::Decision, flow_store, Flow, FlowMsg, FlowState, FlowStore, SwipeDirection, + base::Decision, flow_store, FlowMsg, FlowState, FlowStore, SwipeDirection, SwipeFlow, SwipePage, }, }, @@ -103,8 +103,7 @@ pub extern "C" fn new_get_address(n_args: usize, args: *const Obj, kwargs: *mut } impl GetAddress { - fn new(args: &[Obj], kwargs: &Map) -> Result { - // Result, error::Error> { + fn new(_args: &[Obj], _kwargs: &Map) -> Result { let store = flow_store() .add( Frame::left_aligned( @@ -179,7 +178,7 @@ impl GetAddress { ), |_| Some(FlowMsg::Confirmed), )?; - let res = Flow::new(GetAddress::Address, store)?; + let res = SwipeFlow::new(GetAddress::Address, store)?; Ok(LayoutObj::new(res)?.into()) } } diff --git a/core/embed/rust/src/ui/model_mercury/layout.rs b/core/embed/rust/src/ui/model_mercury/layout.rs index b23302146..fa896a317 100644 --- a/core/embed/rust/src/ui/model_mercury/layout.rs +++ b/core/embed/rust/src/ui/model_mercury/layout.rs @@ -1336,10 +1336,7 @@ extern "C" fn new_show_tx_context_menu(n_args: usize, args: *const Obj, kwargs: let options: [(StrBuffer, Icon); 3] = [ (StrBuffer::from("Address QR code"), theme::ICON_QR_CODE), - ( - StrBuffer::from("Fee info"), - theme::ICON_CHEVRON_RIGHT, - ), + (StrBuffer::from("Fee info"), theme::ICON_CHEVRON_RIGHT), (StrBuffer::from("Cancel transaction"), theme::ICON_CANCEL), ]; let content = VerticalMenu::context_menu(options); @@ -2197,7 +2194,7 @@ pub static mp_module_trezorui2: Module = obj_module! { Qstr::MP_QSTR_show_wait_text => obj_fn_1!(new_show_wait_text).as_obj(), /// def flow_get_address() -> LayoutObj[UiResult]: - /// """Get address / receive funds." + /// """Get address / receive funds.""" Qstr::MP_QSTR_flow_get_address => obj_fn_kw!(0, flow::get_address::new_get_address).as_obj(), }; diff --git a/core/mocks/generated/trezorui2.pyi b/core/mocks/generated/trezorui2.pyi index b87f63f79..3a34239b9 100644 --- a/core/mocks/generated/trezorui2.pyi +++ b/core/mocks/generated/trezorui2.pyi @@ -70,11 +70,6 @@ def check_homescreen_format(data: bytes) -> bool: """Check homescreen format and dimensions.""" -# rust/src/ui/model_mercury/layout.rs -def flow_get_address() -> LayoutObj[UiResult]: - """Get address / receive funds." - - # rust/src/ui/model_mercury/layout.rs def confirm_action( *, @@ -528,6 +523,11 @@ def confirm_firmware_update( # rust/src/ui/model_mercury/layout.rs def show_wait_text(message: str, /) -> LayoutObj[None]: """Show single-line text in the middle of the screen.""" + + +# rust/src/ui/model_mercury/layout.rs +def flow_get_address() -> LayoutObj[UiResult]: + """Get address / receive funds.""" CONFIRMED: UiResult CANCELLED: UiResult INFO: UiResult diff --git a/core/src/apps/base.py b/core/src/apps/base.py index 066a8238f..443984659 100644 --- a/core/src/apps/base.py +++ b/core/src/apps/base.py @@ -239,7 +239,6 @@ async def handle_EndSession(msg: EndSession) -> Success: async def handle_Ping(msg: Ping) -> Success: if msg.button_protection: - from trezor.enums import ButtonRequestType as B from trezor.ui.layouts.mercury import flow_demo await flow_demo()