Skip to content

Commit

Permalink
fixup! chore(core): adapt wipe pin flow
Browse files Browse the repository at this point in the history
  • Loading branch information
bieleluk committed Dec 19, 2024
1 parent 3d7720e commit 5e9dc98
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 97 deletions.
2 changes: 1 addition & 1 deletion core/embed/rust/librust_qstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
30 changes: 4 additions & 26 deletions core/embed/rust/src/ui/api/firmware_micropython.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 10 additions & 14 deletions core/embed/rust/src/ui/model_mercury/ui_firmware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,21 +632,17 @@ impl FirmwareUI for UIMercury {
title: TString<'static>,
description: TString<'static>,
cancel_title: TString<'static>,
is_wipe_code: bool,
) -> Result<impl LayoutMaybeTrace, Error> {
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<impl LayoutMaybeTrace, Error> {
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)
}

Expand Down
11 changes: 1 addition & 10 deletions core/embed/rust/src/ui/model_tr/ui_firmware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,22 +725,13 @@ impl FirmwareUI for UIModelTR {
_title: TString<'static>,
_description: TString<'static>,
_cancel_title: TString<'static>,
_is_wipe_code: bool,
) -> Result<impl LayoutMaybeTrace, Error> {
Err::<RootComponent<Empty, ModelUI>, 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<impl LayoutMaybeTrace, Error> {
Err::<RootComponent<Empty, ModelUI>, Error>(Error::ValueError(
c"flow_confirm_set_new_wipe_code not supported",
))
}

fn flow_get_address(
_address: Obj,
_title: TString<'static>,
Expand Down
11 changes: 1 addition & 10 deletions core/embed/rust/src/ui/model_tt/ui_firmware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,22 +576,13 @@ impl FirmwareUI for UIModelTT {
_title: TString<'static>,
_description: TString<'static>,
_cancel_title: TString<'static>,
_is_wipe_code: bool,
) -> Result<impl LayoutMaybeTrace, Error> {
Err::<RootComponent<Empty, ModelUI>, 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<impl LayoutMaybeTrace, Error> {
Err::<RootComponent<Empty, ModelUI>, Error>(Error::ValueError(
c"flow_confirm_set_new_wipe_code not supported",
))
}

fn flow_get_address(
_address: Obj,
_title: TString<'static>,
Expand Down
7 changes: 1 addition & 6 deletions core/embed/rust/src/ui/ui_firmware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,7 @@ pub trait FirmwareUI {
title: TString<'static>,
description: TString<'static>,
cancel_title: TString<'static>,
) -> Result<impl LayoutMaybeTrace, Error>;

fn flow_confirm_set_new_wipe_code(
title: TString<'static>,
description: TString<'static>,
cancel_title: TString<'static>,
is_wipe_code: bool,
) -> Result<impl LayoutMaybeTrace, Error>;

#[allow(clippy::too_many_arguments)]
Expand Down
11 changes: 1 addition & 10 deletions core/mocks/generated/trezorui_api.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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(
*,
Expand Down
30 changes: 10 additions & 20 deletions core/src/trezor/ui/layouts/mercury/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down

0 comments on commit 5e9dc98

Please sign in to comment.