diff --git a/core/embed/rust/librust_qstr.h b/core/embed/rust/librust_qstr.h index 9d08976b91..d88fa2cf3a 100644 --- a/core/embed/rust/librust_qstr.h +++ b/core/embed/rust/librust_qstr.h @@ -706,6 +706,7 @@ static void _librust_qstrs(void) { MP_QSTR_share_words__words_in_order; MP_QSTR_share_words__wrote_down_all; MP_QSTR_show_address_details; + MP_QSTR_show_ble_pairing_code; MP_QSTR_show_checklist; MP_QSTR_show_danger; MP_QSTR_show_device_menu; @@ -717,7 +718,6 @@ static void _librust_qstrs(void) { MP_QSTR_show_instructions; MP_QSTR_show_lockscreen; MP_QSTR_show_mismatch; - MP_QSTR_show_pairing_code; MP_QSTR_show_pairing_device_name; MP_QSTR_show_progress; MP_QSTR_show_progress_coinjoin; @@ -726,6 +726,7 @@ static void _librust_qstrs(void) { MP_QSTR_show_share_words_extended; MP_QSTR_show_simple; MP_QSTR_show_success; + MP_QSTR_show_thp_pairing_code; MP_QSTR_show_wait_text; MP_QSTR_show_warning; MP_QSTR_sign; diff --git a/core/embed/rust/src/ui/api/firmware_micropython.rs b/core/embed/rust/src/ui/api/firmware_micropython.rs index a7a0a4e0e1..d9dbf15538 100644 --- a/core/embed/rust/src/ui/api/firmware_micropython.rs +++ b/core/embed/rust/src/ui/api/firmware_micropython.rs @@ -874,12 +874,30 @@ extern "C" fn new_show_pairing_device_name( unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } } -extern "C" fn new_show_pairing_code(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj { +extern "C" fn new_show_ble_pairing_code(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj { + #[cfg(feature = "ble")] + { + let block = move |_args: &[Obj], kwargs: &Map| { + let title: TString = kwargs.get(Qstr::MP_QSTR_title)?.try_into()?; + let description: TString = kwargs.get(Qstr::MP_QSTR_description)?.try_into()?; + let code: TString = kwargs.get(Qstr::MP_QSTR_code)?.try_into()?; + let layout = ModelUI::show_ble_pairing_code(title, description, code)?; + let layout_obj = LayoutObj::new_root(layout)?; + Ok(layout_obj.into()) + }; + unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } + } + + #[cfg(not(feature = "ble"))] + unimplemented!() +} + +extern "C" fn new_show_thp_pairing_code(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()?; let description: TString = kwargs.get(Qstr::MP_QSTR_description)?.try_into()?; let code: TString = kwargs.get(Qstr::MP_QSTR_code)?.try_into()?; - let layout = ModelUI::show_pairing_code(title, description, code)?; + let layout = ModelUI::show_thp_pairing_code(title, description, code)?; let layout_obj = LayoutObj::new_root(layout)?; Ok(layout_obj.into()) }; @@ -1689,15 +1707,24 @@ pub static mp_module_trezorui_api: Module = obj_module! { /// Returns if BLEEvent::PairingRequest is received.""" Qstr::MP_QSTR_show_pairing_device_name => obj_fn_kw!(0, new_show_pairing_device_name).as_obj(), - /// def show_pairing_code( + /// def show_ble_pairing_code( /// *, /// title: str, /// description: str, /// code: str, /// ) -> LayoutObj[UiResult]: - /// """Pairing device: second screen (pairing code). + /// """BLE pairing: second screen (pairing code). /// Returns on BLEEvent::{PairingCanceled, Disconnected}.""" - Qstr::MP_QSTR_show_pairing_code => obj_fn_kw!(0, new_show_pairing_code).as_obj(), + Qstr::MP_QSTR_show_ble_pairing_code => obj_fn_kw!(0, new_show_ble_pairing_code).as_obj(), + + /// def show_thp_pairing_code( + /// *, + /// title: str, + /// description: str, + /// code: str, + /// ) -> LayoutObj[UiResult]: + /// """THP pairing: second screen (pairing code).""" + Qstr::MP_QSTR_show_thp_pairing_code => obj_fn_kw!(0, new_show_thp_pairing_code).as_obj(), /// def show_info( /// *, diff --git a/core/embed/rust/src/ui/component/base.rs b/core/embed/rust/src/ui/component/base.rs index c3848f27b9..ce8393d09a 100644 --- a/core/embed/rust/src/ui/component/base.rs +++ b/core/embed/rust/src/ui/component/base.rs @@ -625,7 +625,6 @@ pub enum FlowMsg { Next, Choice(usize), Text(ShortString), - Number(u32), } #[cfg(feature = "micropython")] @@ -641,7 +640,6 @@ impl TryFrom for crate::micropython::obj::Obj { FlowMsg::Info => Ok(result::INFO.as_obj()), FlowMsg::Choice(i) => i.try_into(), FlowMsg::Text(s) => s.as_str().try_into(), - FlowMsg::Number(i) => i.try_into(), } } } diff --git a/core/embed/rust/src/ui/component/ble.rs b/core/embed/rust/src/ui/component/ble.rs index 4e2fa66080..1462fd821d 100644 --- a/core/embed/rust/src/ui/component/ble.rs +++ b/core/embed/rust/src/ui/component/ble.rs @@ -3,12 +3,8 @@ use crate::ui::{ event::BLEEvent, geometry::Rect, shape::Renderer, - util::Pager, }; -#[cfg(all(feature = "micropython", feature = "touch"))] -use crate::ui::{component::swipe_detect::SwipeConfig, flow::Swipable}; - pub struct BLEHandler { inner: T, waiting_for_pairing: bool, @@ -29,19 +25,6 @@ impl BLEHandler { } } -#[cfg(all(feature = "micropython", feature = "touch"))] -impl Swipable for BLEHandler -where - T: Component, -{ - fn get_pager(&self) -> Pager { - Pager::single_page() - } - fn get_swipe_config(&self) -> SwipeConfig { - SwipeConfig::default() - } -} - impl Component for BLEHandler where T: Component, diff --git a/core/embed/rust/src/ui/layout_bolt/ui_firmware.rs b/core/embed/rust/src/ui/layout_bolt/ui_firmware.rs index 3e280e31d3..0892f175ca 100644 --- a/core/embed/rust/src/ui/layout_bolt/ui_firmware.rs +++ b/core/embed/rust/src/ui/layout_bolt/ui_firmware.rs @@ -892,7 +892,18 @@ impl FirmwareUI for UIBolt { )) } - fn show_pairing_code( + #[cfg(feature = "ble")] + fn show_ble_pairing_code( + _title: TString<'static>, + _description: TString<'static>, + _code: TString<'static>, + ) -> Result { + Err::, Error>(Error::ValueError( + c"show_ble_pairing_code not supported", + )) + } + + fn show_thp_pairing_code( title: TString<'static>, description: TString<'static>, code: TString<'static>, diff --git a/core/embed/rust/src/ui/layout_caesar/ui_firmware.rs b/core/embed/rust/src/ui/layout_caesar/ui_firmware.rs index 4da678b9ea..8cf7a2d08f 100644 --- a/core/embed/rust/src/ui/layout_caesar/ui_firmware.rs +++ b/core/embed/rust/src/ui/layout_caesar/ui_firmware.rs @@ -1089,13 +1089,24 @@ impl FirmwareUI for UICaesar { )) } - fn show_pairing_code( + #[cfg(feature = "ble")] + fn show_ble_pairing_code( _title: TString<'static>, _description: TString<'static>, _code: TString<'static>, ) -> Result { Err::, Error>(Error::ValueError( - c"show_pairing_code not supported", + c"show_ble_pairing_code not supported", + )) + } + + fn show_thp_pairing_code( + _title: TString<'static>, + _description: TString<'static>, + _code: TString<'static>, + ) -> Result { + Err::, Error>(Error::ValueError( + c"show_thp_pairing_code not supported", )) } diff --git a/core/embed/rust/src/ui/layout_delizia/ui_firmware.rs b/core/embed/rust/src/ui/layout_delizia/ui_firmware.rs index e816b62e2f..d5c84b47c8 100644 --- a/core/embed/rust/src/ui/layout_delizia/ui_firmware.rs +++ b/core/embed/rust/src/ui/layout_delizia/ui_firmware.rs @@ -916,13 +916,24 @@ impl FirmwareUI for UIDelizia { )) } - fn show_pairing_code( + #[cfg(feature = "ble")] + fn show_ble_pairing_code( _title: TString<'static>, _description: TString<'static>, _code: TString<'static>, ) -> Result { Err::, Error>(Error::ValueError( - c"show_pairing_code not supported", + c"show_ble_pairing_code not supported", + )) + } + + fn show_thp_pairing_code( + _title: TString<'static>, + _description: TString<'static>, + _code: TString<'static>, + ) -> Result { + Err::, Error>(Error::ValueError( + c"show_thp_pairing_code not supported", )) } diff --git a/core/embed/rust/src/ui/layout_eckhart/flow/mod.rs b/core/embed/rust/src/ui/layout_eckhart/flow/mod.rs index ae197ba775..09ea11a7eb 100644 --- a/core/embed/rust/src/ui/layout_eckhart/flow/mod.rs +++ b/core/embed/rust/src/ui/layout_eckhart/flow/mod.rs @@ -13,8 +13,8 @@ pub mod prompt_backup; pub mod request_number; pub mod request_passphrase; pub mod show_danger; -pub mod show_pairing_code; pub mod show_share_words; +pub mod show_thp_pairing_code; #[cfg(feature = "universal_fw")] pub use confirm_fido::new_confirm_fido; @@ -31,5 +31,5 @@ pub use prompt_backup::PromptBackup; pub use request_number::new_request_number; pub use request_passphrase::RequestPassphrase; pub use show_danger::ShowDanger; -pub use show_pairing_code::new_show_pairing_code; pub use show_share_words::new_show_share_words_flow; +pub use show_thp_pairing_code::new_show_thp_pairing_code; diff --git a/core/embed/rust/src/ui/layout_eckhart/flow/show_pairing_code.rs b/core/embed/rust/src/ui/layout_eckhart/flow/show_thp_pairing_code.rs similarity index 78% rename from core/embed/rust/src/ui/layout_eckhart/flow/show_pairing_code.rs rename to core/embed/rust/src/ui/layout_eckhart/flow/show_thp_pairing_code.rs index 3753dc5fed..3215d6f9a0 100644 --- a/core/embed/rust/src/ui/layout_eckhart/flow/show_pairing_code.rs +++ b/core/embed/rust/src/ui/layout_eckhart/flow/show_thp_pairing_code.rs @@ -12,9 +12,6 @@ use crate::{ }, }; -#[cfg(feature = "ble")] -use crate::ui::component::BLEHandlerMsg; - use super::super::{ component::Button, firmware::{ @@ -45,9 +42,6 @@ impl FlowController for ShowPairingCode { (Self::Main, FlowMsg::Cancelled) => self.return_msg(FlowMsg::Cancelled), (Self::Main, FlowMsg::Confirmed) => self.return_msg(FlowMsg::Confirmed), (Self::Main, FlowMsg::Info) => Self::Menu.goto(), - (Self::Main, FlowMsg::Number(pairing_code)) => { - self.return_msg(FlowMsg::Number(pairing_code)) - } (Self::Menu, FlowMsg::Choice(..)) => self.return_msg(FlowMsg::Cancelled), (Self::Menu, FlowMsg::Cancelled) => Self::Main.goto(), _ => self.do_nothing(), @@ -55,7 +49,7 @@ impl FlowController for ShowPairingCode { } } -pub fn new_show_pairing_code( +pub fn new_show_thp_pairing_code( title: TString<'static>, description: TString<'static>, code: TString<'static>, @@ -69,16 +63,6 @@ pub fn new_show_pairing_code( .add_text(code, fonts::FONT_SATOSHI_EXTRALIGHT_72); let screen = TextScreen::new(FormattedText::new(ops)).with_header(Header::new(title).with_menu_button()); - - #[cfg(feature = "ble")] - let main_content = crate::ui::component::BLEHandler::new(screen, false).map(|msg| match msg { - BLEHandlerMsg::Cancelled => Some(FlowMsg::Cancelled), - BLEHandlerMsg::Content(TextScreenMsg::Cancelled) => Some(FlowMsg::Cancelled), - BLEHandlerMsg::Content(TextScreenMsg::Confirmed) => Some(FlowMsg::Confirmed), - BLEHandlerMsg::Content(TextScreenMsg::Menu) => Some(FlowMsg::Info), - BLEHandlerMsg::PairingCode(code) => Some(FlowMsg::Number(code)), - }); - #[cfg(not(feature = "ble"))] let main_content = screen.map(|msg| match msg { TextScreenMsg::Cancelled => Some(FlowMsg::Cancelled), TextScreenMsg::Confirmed => Some(FlowMsg::Confirmed), 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 121969061d..b9a610d993 100644 --- a/core/embed/rust/src/ui/layout_eckhart/ui_firmware.rs +++ b/core/embed/rust/src/ui/layout_eckhart/ui_firmware.rs @@ -18,7 +18,7 @@ use crate::{ }, ComponentExt as _, Empty, FormattedText, Timeout, }, - geometry::{LinearPlacement, Offset}, + geometry::{Alignment, LinearPlacement, Offset}, layout::{ obj::{LayoutMaybeTrace, LayoutObj, RootComponent}, util::{ConfirmValueParams, PropsList, RecoveryType, StrOrBytes}, @@ -1079,12 +1079,36 @@ impl FirmwareUI for UIEckhart { Ok(layout) } - fn show_pairing_code( + #[cfg(feature = "ble")] + fn show_ble_pairing_code( title: TString<'static>, description: TString<'static>, code: TString<'static>, ) -> Result { - let flow = flow::show_pairing_code::new_show_pairing_code(title, description, code)?; + let mut ops = OpTextLayout::new(theme::firmware::TEXT_REGULAR); + ops.add_text(description, fonts::FONT_SATOSHI_REGULAR_38) + .add_newline() + .add_newline() + .add_newline() + .add_alignment(Alignment::Center) + .add_text(code, fonts::FONT_SATOSHI_EXTRALIGHT_72); + let screen = crate::ui::component::BLEHandler::new( + TextScreen::new(FormattedText::new(ops)) + .with_header(Header::new(title)) + .with_action_bar(ActionBar::new_cancel_confirm()), + false, + ); + let layout = RootComponent::new(screen); + Ok(layout) + } + + fn show_thp_pairing_code( + title: TString<'static>, + description: TString<'static>, + code: TString<'static>, + ) -> Result { + let flow = + flow::show_thp_pairing_code::new_show_thp_pairing_code(title, description, code)?; Ok(flow) } diff --git a/core/embed/rust/src/ui/ui_firmware.rs b/core/embed/rust/src/ui/ui_firmware.rs index 0d76ec3c44..e4a3b746ca 100644 --- a/core/embed/rust/src/ui/ui_firmware.rs +++ b/core/embed/rust/src/ui/ui_firmware.rs @@ -325,7 +325,14 @@ pub trait FirmwareUI { device_name: TString<'static>, ) -> Result; - fn show_pairing_code( + #[cfg(feature = "ble")] + fn show_ble_pairing_code( + title: TString<'static>, + description: TString<'static>, + code: TString<'static>, + ) -> Result; + + fn show_thp_pairing_code( title: TString<'static>, description: TString<'static>, code: TString<'static>, diff --git a/core/mocks/generated/trezorui_api.pyi b/core/mocks/generated/trezorui_api.pyi index 212aab7769..e772726a4e 100644 --- a/core/mocks/generated/trezorui_api.pyi +++ b/core/mocks/generated/trezorui_api.pyi @@ -571,16 +571,26 @@ def show_pairing_device_name( # rust/src/ui/api/firmware_micropython.rs -def show_pairing_code( +def show_ble_pairing_code( *, title: str, description: str, code: str, ) -> LayoutObj[UiResult]: - """Pairing device: second screen (pairing code). + """BLE pairing: second screen (pairing code). Returns on BLEEvent::{PairingCanceled, Disconnected}.""" +# rust/src/ui/api/firmware_micropython.rs +def show_thp_pairing_code( + *, + title: str, + description: str, + code: str, +) -> LayoutObj[UiResult]: + """THP pairing: second screen (pairing code).""" + + # rust/src/ui/api/firmware_micropython.rs def show_info( *, diff --git a/core/src/apps/management/ble/pair_new_device.py b/core/src/apps/management/ble/pair_new_device.py index b3b92101e0..ae155781de 100644 --- a/core/src/apps/management/ble/pair_new_device.py +++ b/core/src/apps/management/ble/pair_new_device.py @@ -28,7 +28,7 @@ async def pair_new_device() -> None: try: result = await raise_if_not_confirmed( - trezorui_api.show_pairing_code( + trezorui_api.show_ble_pairing_code( title="Bluetooth pairing", description="Pairing code match?", code=f"{code:0>6}",