From 5e9dc98b90a83e1222f4357abbeb4aa306ec78e9 Mon Sep 17 00:00:00 2001 From: Lukas Bielesch Date: Thu, 19 Dec 2024 17:52:26 +0100 Subject: [PATCH] fixup! chore(core): adapt wipe pin flow --- core/embed/rust/librust_qstr.h | 2 +- .../rust/src/ui/api/firmware_micropython.rs | 30 +++---------------- .../rust/src/ui/model_mercury/ui_firmware.rs | 24 +++++++-------- .../embed/rust/src/ui/model_tr/ui_firmware.rs | 11 +------ .../embed/rust/src/ui/model_tt/ui_firmware.rs | 11 +------ core/embed/rust/src/ui/ui_firmware.rs | 7 +---- core/mocks/generated/trezorui_api.pyi | 11 +------ .../src/trezor/ui/layouts/mercury/__init__.py | 30 +++++++------------ 8 files changed, 29 insertions(+), 97 deletions(-) diff --git a/core/embed/rust/librust_qstr.h b/core/embed/rust/librust_qstr.h index f284254741..7280f0e46e 100644 --- a/core/embed/rust/librust_qstr.h +++ b/core/embed/rust/librust_qstr.h @@ -244,7 +244,6 @@ static void _librust_qstrs(void) { MP_QSTR_firmware_update__title_fingerprint; MP_QSTR_flow_confirm_output; MP_QSTR_flow_confirm_set_new_pin; - MP_QSTR_flow_confirm_set_new_wipe_code; MP_QSTR_flow_get_address; MP_QSTR_get_language; MP_QSTR_get_transition_out; @@ -301,6 +300,7 @@ static void _librust_qstrs(void) { MP_QSTR_instructions__tap_to_start; MP_QSTR_instructions__view_all_data; MP_QSTR_is_type_of; + MP_QSTR_is_wipe_code; MP_QSTR_items; MP_QSTR_joint__title; MP_QSTR_joint__to_the_total_amount; diff --git a/core/embed/rust/src/ui/api/firmware_micropython.rs b/core/embed/rust/src/ui/api/firmware_micropython.rs index 6059da6864..abc92907eb 100644 --- a/core/embed/rust/src/ui/api/firmware_micropython.rs +++ b/core/embed/rust/src/ui/api/firmware_micropython.rs @@ -533,24 +533,10 @@ extern "C" fn new_flow_confirm_set_new_pin( let title: TString = kwargs.get(Qstr::MP_QSTR_title)?.try_into()?; let description: TString = kwargs.get(Qstr::MP_QSTR_description)?.try_into()?; let cancel_title: TString = kwargs.get(Qstr::MP_QSTR_cancel_title)?.try_into()?; + let is_wipe_code: bool = kwargs.get(Qstr::MP_QSTR_is_wipe_code)?.try_into()?; - let layout = ModelUI::flow_confirm_set_new_pin(title, description, cancel_title)?; - Ok(LayoutObj::new_root(layout)?.into()) - }; - unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } -} - -extern "C" fn new_flow_confirm_set_new_wipe_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 cancel_title: TString = kwargs.get(Qstr::MP_QSTR_cancel_title)?.try_into()?; - - let layout = ModelUI::flow_confirm_set_new_wipe_code(title, description, cancel_title)?; + let layout = + ModelUI::flow_confirm_set_new_pin(title, description, cancel_title, is_wipe_code)?; Ok(LayoutObj::new_root(layout)?.into()) }; unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } @@ -1400,19 +1386,11 @@ pub static mp_module_trezorui_api: Module = obj_module! { /// title: str, /// description: str, /// cancel_title: str, + /// is_wipe_code: bool, /// ) -> LayoutObj[UiResult]: /// """Confirm new PIN setup with an option to cancel action.""" Qstr::MP_QSTR_flow_confirm_set_new_pin => obj_fn_kw!(0, new_flow_confirm_set_new_pin).as_obj(), - /// def flow_confirm_set_new_wipe_code( - /// *, - /// title: str, - /// description: str, - /// cancel_title: str, - /// ) -> LayoutObj[UiResult]: - /// """Confirm new wipe code setup with an option to cancel action.""" - Qstr::MP_QSTR_flow_confirm_set_new_wipe_code => obj_fn_kw!(0, new_flow_confirm_set_new_wipe_code).as_obj(), - /// def flow_get_address( /// *, /// address: str | bytes, diff --git a/core/embed/rust/src/ui/model_mercury/ui_firmware.rs b/core/embed/rust/src/ui/model_mercury/ui_firmware.rs index 2935bee2b2..c350807a03 100644 --- a/core/embed/rust/src/ui/model_mercury/ui_firmware.rs +++ b/core/embed/rust/src/ui/model_mercury/ui_firmware.rs @@ -632,21 +632,17 @@ impl FirmwareUI for UIMercury { title: TString<'static>, description: TString<'static>, cancel_title: TString<'static>, + is_wipe_code: bool, ) -> Result { - let flow = flow::confirm_set_new_pin::new_set_new_pin(title, description, cancel_title)?; - Ok(flow) - } - - fn flow_confirm_set_new_wipe_code( - title: TString<'static>, - description: TString<'static>, - cancel_title: TString<'static>, - ) -> Result { - let flow = flow::confirm_set_new_wipe_code::new_set_new_wipe_code( - title, - description, - cancel_title, - )?; + let flow = if is_wipe_code { + flow::confirm_set_new_wipe_code::new_set_new_wipe_code( + title, + description, + cancel_title, + )? + } else { + flow::confirm_set_new_pin::new_set_new_pin(title, description, cancel_title)? + }; Ok(flow) } diff --git a/core/embed/rust/src/ui/model_tr/ui_firmware.rs b/core/embed/rust/src/ui/model_tr/ui_firmware.rs index 7ee62bafde..13593b358b 100644 --- a/core/embed/rust/src/ui/model_tr/ui_firmware.rs +++ b/core/embed/rust/src/ui/model_tr/ui_firmware.rs @@ -725,22 +725,13 @@ impl FirmwareUI for UIModelTR { _title: TString<'static>, _description: TString<'static>, _cancel_title: TString<'static>, + _is_wipe_code: bool, ) -> Result { Err::, Error>(Error::ValueError( c"flow_confirm_set_new_pin not supported", )) } - fn flow_confirm_set_new_wipe_code( - _title: TString<'static>, - _description: TString<'static>, - _cancel_title: TString<'static>, - ) -> Result { - Err::, Error>(Error::ValueError( - c"flow_confirm_set_new_wipe_code not supported", - )) - } - fn flow_get_address( _address: Obj, _title: TString<'static>, diff --git a/core/embed/rust/src/ui/model_tt/ui_firmware.rs b/core/embed/rust/src/ui/model_tt/ui_firmware.rs index f16d6c2de5..1b72d53c37 100644 --- a/core/embed/rust/src/ui/model_tt/ui_firmware.rs +++ b/core/embed/rust/src/ui/model_tt/ui_firmware.rs @@ -576,22 +576,13 @@ impl FirmwareUI for UIModelTT { _title: TString<'static>, _description: TString<'static>, _cancel_title: TString<'static>, + _is_wipe_code: bool, ) -> Result { Err::, Error>(Error::ValueError( c"flow_confirm_set_new_pin not supported", )) } - fn flow_confirm_set_new_wipe_code( - _title: TString<'static>, - _description: TString<'static>, - _cancel_title: TString<'static>, - ) -> Result { - Err::, Error>(Error::ValueError( - c"flow_confirm_set_new_wipe_code not supported", - )) - } - fn flow_get_address( _address: Obj, _title: TString<'static>, diff --git a/core/embed/rust/src/ui/ui_firmware.rs b/core/embed/rust/src/ui/ui_firmware.rs index a382d8eae6..8d2c4e0a97 100644 --- a/core/embed/rust/src/ui/ui_firmware.rs +++ b/core/embed/rust/src/ui/ui_firmware.rs @@ -198,12 +198,7 @@ pub trait FirmwareUI { title: TString<'static>, description: TString<'static>, cancel_title: TString<'static>, - ) -> Result; - - fn flow_confirm_set_new_wipe_code( - title: TString<'static>, - description: TString<'static>, - cancel_title: TString<'static>, + is_wipe_code: bool, ) -> Result; #[allow(clippy::too_many_arguments)] diff --git a/core/mocks/generated/trezorui_api.pyi b/core/mocks/generated/trezorui_api.pyi index bfc6341a8b..260e8e5026 100644 --- a/core/mocks/generated/trezorui_api.pyi +++ b/core/mocks/generated/trezorui_api.pyi @@ -341,20 +341,11 @@ def flow_confirm_set_new_pin( title: str, description: str, cancel_title: str, + is_wipe_code: bool, ) -> LayoutObj[UiResult]: """Confirm new PIN setup with an option to cancel action.""" -# rust/src/ui/api/firmware_micropython.rs -def flow_confirm_set_new_wipe_code( - *, - title: str, - description: str, - cancel_title: str, -) -> LayoutObj[UiResult]: - """Confirm new wipe code setup with an option to cancel action.""" - - # rust/src/ui/api/firmware_micropython.rs def flow_get_address( *, diff --git a/core/src/trezor/ui/layouts/mercury/__init__.py b/core/src/trezor/ui/layouts/mercury/__init__.py index c31cab9a7d..d828de06db 100644 --- a/core/src/trezor/ui/layouts/mercury/__init__.py +++ b/core/src/trezor/ui/layouts/mercury/__init__.py @@ -1211,26 +1211,16 @@ def confirm_set_new_pin( is_wipe_code: bool = False, br_code: ButtonRequestType = BR_CODE_OTHER, ) -> Awaitable[None]: - if is_wipe_code: - return raise_if_not_confirmed( - trezorui_api.flow_confirm_set_new_wipe_code( - title=title, - description=description + "\n" + information, - cancel_title=cancel_title, - ), - br_name, - br_code, - ) - else: - return raise_if_not_confirmed( - trezorui_api.flow_confirm_set_new_pin( - title=title, - description=description + "\n" + information, - cancel_title=cancel_title, - ), - br_name, - br_code, - ) + return raise_if_not_confirmed( + trezorui_api.flow_confirm_set_new_pin( + title=title, + description=description + "\n" + information, + cancel_title=cancel_title, + is_wipe_code=is_wipe_code, + ), + br_name, + br_code, + ) def confirm_firmware_update(description: str, fingerprint: str) -> Awaitable[None]: