mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-29 10:58:21 +00:00
refactor(core): move confirm_reset to UiFeatures
- unify param to just one bool `recovery` - title and button is determined in Rust based on the argument
This commit is contained in:
parent
2692743608
commit
d4fa752709
@ -251,7 +251,6 @@ static void _librust_qstrs(void) {
|
||||
MP_QSTR_firmware_update__title_fingerprint;
|
||||
MP_QSTR_first_screen;
|
||||
MP_QSTR_flow_confirm_output;
|
||||
MP_QSTR_flow_confirm_reset;
|
||||
MP_QSTR_flow_confirm_set_new_pin;
|
||||
MP_QSTR_flow_confirm_summary;
|
||||
MP_QSTR_flow_continue_recovery;
|
||||
|
@ -110,6 +110,16 @@ extern "C" fn new_confirm_homescreen(n_args: usize, args: *const Obj, kwargs: *m
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_confirm_reset_device(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
|
||||
let block = move |_args: &[Obj], kwargs: &Map| {
|
||||
let recovery: bool = kwargs.get(Qstr::MP_QSTR_recovery)?.try_into()?;
|
||||
|
||||
let layout = ModelUI::confirm_reset_device(recovery)?;
|
||||
Ok(LayoutObj::new_root(layout)?.into())
|
||||
};
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_request_bip39(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
|
||||
let block = move |_args: &[Obj], kwargs: &Map| {
|
||||
let prompt: TString = kwargs.get(Qstr::MP_QSTR_prompt)?.try_into()?;
|
||||
@ -494,6 +504,10 @@ pub static mp_module_trezorui_api: Module = obj_module! {
|
||||
/// """Confirm homescreen."""
|
||||
Qstr::MP_QSTR_confirm_homescreen => obj_fn_kw!(0, new_confirm_homescreen).as_obj(),
|
||||
|
||||
/// def confirm_reset_device(recovery: bool) -> LayoutObj[UiResult]:
|
||||
/// """Confirm TOS before creating wallet creation or wallet recovery."""
|
||||
Qstr::MP_QSTR_confirm_reset_device => obj_fn_kw!(0, new_confirm_reset_device).as_obj(),
|
||||
|
||||
/// def request_bip39(
|
||||
/// *,
|
||||
/// prompt: str,
|
||||
|
@ -389,16 +389,6 @@ extern "C" fn new_confirm_properties(n_args: usize, args: *const Obj, kwargs: *m
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_confirm_reset(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
|
||||
let block = move |_args: &[Obj], kwargs: &Map| {
|
||||
let recovery: bool = kwargs.get(Qstr::MP_QSTR_recovery)?.try_into()?;
|
||||
|
||||
let flow = flow::confirm_reset::new_confirm_reset(recovery)?;
|
||||
Ok(LayoutObj::new_root(flow)?.into())
|
||||
};
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_confirm_set_new_pin(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()?;
|
||||
@ -1147,10 +1137,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
||||
/// the value is to be rendered as binary with monospace font, False otherwise."""
|
||||
Qstr::MP_QSTR_confirm_properties => obj_fn_kw!(0, new_confirm_properties).as_obj(),
|
||||
|
||||
/// def flow_confirm_reset(recovery: bool) -> LayoutObj[UiResult]:
|
||||
/// """Confirm TOS before creating wallet creation or wallet recovery."""
|
||||
Qstr::MP_QSTR_flow_confirm_reset => obj_fn_kw!(0, new_confirm_reset).as_obj(),
|
||||
|
||||
// TODO: supply more arguments for Wipe code setting when figma done
|
||||
/// def flow_confirm_set_new_pin(
|
||||
/// *,
|
||||
|
@ -107,6 +107,11 @@ impl UIFeaturesFirmware for ModelMercuryFeatures {
|
||||
Ok(flow)
|
||||
}
|
||||
|
||||
fn confirm_reset_device(recovery: bool) -> Result<impl LayoutMaybeTrace, Error> {
|
||||
let flow = flow::confirm_reset::new_confirm_reset(recovery)?;
|
||||
Ok(flow)
|
||||
}
|
||||
|
||||
fn check_homescreen_format(image: BinaryData, __accept_toif: bool) -> bool {
|
||||
super::component::check_homescreen_format(image)
|
||||
}
|
||||
|
@ -372,24 +372,6 @@ extern "C" fn new_confirm_properties(n_args: usize, args: *const Obj, kwargs: *m
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_confirm_reset_device(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 button: TString<'static> = kwargs.get(Qstr::MP_QSTR_button)?.try_into()?;
|
||||
|
||||
let ops = OpTextLayout::new(theme::TEXT_NORMAL)
|
||||
.text_normal(TR::reset__by_continuing)
|
||||
.next_page()
|
||||
.text_normal(TR::reset__more_info_at)
|
||||
.newline()
|
||||
.text_bold(TR::reset__tos_link);
|
||||
let formatted = FormattedText::new(ops).vertically_centered();
|
||||
|
||||
content_in_button_page(title, formatted, button, Some("".into()), false)
|
||||
};
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_confirm_backup(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
|
||||
let block = move |_args: &[Obj], _kwargs: &Map| {
|
||||
let get_page = move |page_index| match page_index {
|
||||
@ -1296,14 +1278,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
||||
/// This only concerns the text style, you need to decode the value to UTF-8 in python."""
|
||||
Qstr::MP_QSTR_confirm_properties => obj_fn_kw!(0, new_confirm_properties).as_obj(),
|
||||
|
||||
/// def confirm_reset_device(
|
||||
/// *,
|
||||
/// title: str,
|
||||
/// button: str,
|
||||
/// ) -> LayoutObj[UiResult]:
|
||||
/// """Confirm TOS before device setup."""
|
||||
Qstr::MP_QSTR_confirm_reset_device => obj_fn_kw!(0, new_confirm_reset_device).as_obj(),
|
||||
|
||||
/// def confirm_backup() -> LayoutObj[UiResult]:
|
||||
/// """Strongly recommend user to do backup."""
|
||||
Qstr::MP_QSTR_confirm_backup => obj_fn_kw!(0, new_confirm_backup).as_obj(),
|
||||
|
@ -30,7 +30,9 @@ use crate::{
|
||||
|
||||
use super::{
|
||||
component::{
|
||||
ButtonDetails, ButtonPage, CoinJoinProgress, ConfirmHomescreen, Flow, FlowPages, Frame, Homescreen, Lockscreen, NumberInput, PassphraseEntry, PinEntry, Progress, ScrollableFrame, SimpleChoice, WordlistEntry, WordlistType
|
||||
ButtonDetails, ButtonPage, CoinJoinProgress, ConfirmHomescreen, Flow, FlowPages, Frame,
|
||||
Homescreen, Lockscreen, NumberInput, PassphraseEntry, PinEntry, Progress, ScrollableFrame,
|
||||
SimpleChoice, WordlistEntry, WordlistType,
|
||||
},
|
||||
theme, ModelTRFeatures,
|
||||
};
|
||||
@ -114,6 +116,29 @@ impl UIFeaturesFirmware for ModelTRFeatures {
|
||||
Ok(layout)
|
||||
}
|
||||
|
||||
fn confirm_reset_device(recovery: bool) -> Result<impl LayoutMaybeTrace, Error> {
|
||||
let (title, button) = if recovery {
|
||||
(
|
||||
TR::recovery__title_recover.into(),
|
||||
TR::reset__button_recover.into(),
|
||||
)
|
||||
} else {
|
||||
(
|
||||
TR::reset__title_create_wallet.into(),
|
||||
TR::reset__button_create.into(),
|
||||
)
|
||||
};
|
||||
let ops = OpTextLayout::new(theme::TEXT_NORMAL)
|
||||
.text_normal(TR::reset__by_continuing)
|
||||
.next_page()
|
||||
.text_normal(TR::reset__more_info_at)
|
||||
.newline()
|
||||
.text_bold(TR::reset__tos_link);
|
||||
let formatted = FormattedText::new(ops).vertically_centered();
|
||||
|
||||
content_in_button_page(title, formatted, button, Some("".into()), false)
|
||||
}
|
||||
|
||||
fn check_homescreen_format(image: BinaryData, _accept_toif: bool) -> bool {
|
||||
super::component::check_homescreen_format(image)
|
||||
}
|
||||
|
@ -565,32 +565,6 @@ extern "C" fn new_confirm_properties(n_args: usize, args: *const Obj, kwargs: *m
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_confirm_reset_device(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 button: TString = kwargs.get(Qstr::MP_QSTR_button)?.try_into()?;
|
||||
|
||||
let par_array: [Paragraph<'static>; 3] = [
|
||||
Paragraph::new(&theme::TEXT_NORMAL, TR::reset__by_continuing).with_bottom_padding(17), /* simulating a carriage return */
|
||||
Paragraph::new(&theme::TEXT_NORMAL, TR::reset__more_info_at),
|
||||
Paragraph::new(&theme::TEXT_DEMIBOLD, TR::reset__tos_link),
|
||||
];
|
||||
let paragraphs = Paragraphs::new(par_array);
|
||||
let buttons = Button::cancel_confirm(
|
||||
Button::with_icon(theme::ICON_CANCEL),
|
||||
Button::with_text(button).styled(theme::button_confirm()),
|
||||
true,
|
||||
);
|
||||
let obj = LayoutObj::new(Frame::left_aligned(
|
||||
theme::label_title(),
|
||||
title,
|
||||
Dialog::new(paragraphs, buttons),
|
||||
))?;
|
||||
Ok(obj.into())
|
||||
};
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_show_address_details(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
|
||||
let block = move |_args: &[Obj], kwargs: &Map| {
|
||||
let qr_title: TString<'static> = kwargs.get(Qstr::MP_QSTR_qr_title)?.try_into()?;
|
||||
@ -1252,14 +1226,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
||||
/// the value is to be rendered as binary with monospace font, False otherwise."""
|
||||
Qstr::MP_QSTR_confirm_properties => obj_fn_kw!(0, new_confirm_properties).as_obj(),
|
||||
|
||||
/// def confirm_reset_device(
|
||||
/// *,
|
||||
/// title: str,
|
||||
/// button: str,
|
||||
/// ) -> LayoutObj[UiResult]:
|
||||
/// """Confirm TOS before device setup."""
|
||||
Qstr::MP_QSTR_confirm_reset_device => obj_fn_kw!(0, new_confirm_reset_device).as_obj(),
|
||||
|
||||
/// def show_address_details(
|
||||
/// *,
|
||||
/// qr_title: str,
|
||||
|
@ -122,6 +122,37 @@ impl UIFeaturesFirmware for ModelTTFeatures {
|
||||
Ok(layout)
|
||||
}
|
||||
|
||||
fn confirm_reset_device(recovery: bool) -> Result<impl LayoutMaybeTrace, Error> {
|
||||
let (title, button) = if recovery {
|
||||
(
|
||||
TR::recovery__title_recover.into(),
|
||||
TR::reset__button_recover.into(),
|
||||
)
|
||||
} else {
|
||||
(
|
||||
TR::reset__title_create_wallet.into(),
|
||||
TR::reset__button_create.into(),
|
||||
)
|
||||
};
|
||||
let par_array: [Paragraph<'static>; 3] = [
|
||||
Paragraph::new(&theme::TEXT_NORMAL, TR::reset__by_continuing).with_bottom_padding(17), /* simulating a carriage return */
|
||||
Paragraph::new(&theme::TEXT_NORMAL, TR::reset__more_info_at),
|
||||
Paragraph::new(&theme::TEXT_DEMIBOLD, TR::reset__tos_link),
|
||||
];
|
||||
let paragraphs = Paragraphs::new(par_array);
|
||||
let buttons = Button::cancel_confirm(
|
||||
Button::with_icon(theme::ICON_CANCEL),
|
||||
Button::with_text(button).styled(theme::button_confirm()),
|
||||
true,
|
||||
);
|
||||
let layout = RootComponent::new(Frame::left_aligned(
|
||||
theme::label_title(),
|
||||
title,
|
||||
Dialog::new(paragraphs, buttons),
|
||||
));
|
||||
Ok(layout)
|
||||
}
|
||||
|
||||
fn check_homescreen_format(image: BinaryData, accept_toif: bool) -> bool {
|
||||
super::component::check_homescreen_format(image, false)
|
||||
}
|
||||
|
@ -30,6 +30,8 @@ pub trait UIFeaturesFirmware {
|
||||
fingerprint: TString<'static>,
|
||||
) -> Result<impl LayoutMaybeTrace, Error>;
|
||||
|
||||
fn confirm_reset_device(recovery: bool) -> Result<impl LayoutMaybeTrace, Error>;
|
||||
|
||||
fn check_homescreen_format(image: BinaryData, accept_toif: bool) -> bool;
|
||||
|
||||
fn request_bip39(
|
||||
|
@ -60,11 +60,6 @@ def confirm_properties(
|
||||
the value is to be rendered as binary with monospace font, False otherwise."""
|
||||
|
||||
|
||||
# rust/src/ui/model_mercury/layout.rs
|
||||
def flow_confirm_reset(recovery: bool) -> LayoutObj[UiResult]:
|
||||
"""Confirm TOS before creating wallet creation or wallet recovery."""
|
||||
|
||||
|
||||
# rust/src/ui/model_mercury/layout.rs
|
||||
def flow_confirm_set_new_pin(
|
||||
*,
|
||||
@ -391,15 +386,6 @@ def confirm_properties(
|
||||
This only concerns the text style, you need to decode the value to UTF-8 in python."""
|
||||
|
||||
|
||||
# rust/src/ui/model_tr/layout.rs
|
||||
def confirm_reset_device(
|
||||
*,
|
||||
title: str,
|
||||
button: str,
|
||||
) -> LayoutObj[UiResult]:
|
||||
"""Confirm TOS before device setup."""
|
||||
|
||||
|
||||
# rust/src/ui/model_tr/layout.rs
|
||||
def confirm_backup() -> LayoutObj[UiResult]:
|
||||
"""Strongly recommend user to do backup."""
|
||||
@ -700,15 +686,6 @@ def confirm_properties(
|
||||
the value is to be rendered as binary with monospace font, False otherwise."""
|
||||
|
||||
|
||||
# rust/src/ui/model_tt/layout.rs
|
||||
def confirm_reset_device(
|
||||
*,
|
||||
title: str,
|
||||
button: str,
|
||||
) -> LayoutObj[UiResult]:
|
||||
"""Confirm TOS before device setup."""
|
||||
|
||||
|
||||
# rust/src/ui/model_tt/layout.rs
|
||||
def show_address_details(
|
||||
*,
|
||||
|
@ -114,6 +114,11 @@ def confirm_homescreen(
|
||||
"""Confirm homescreen."""
|
||||
|
||||
|
||||
# rust/src/ui/api/firmware_upy.rs
|
||||
def confirm_reset_device(recovery: bool) -> LayoutObj[UiResult]:
|
||||
"""Confirm TOS before creating wallet creation or wallet recovery."""
|
||||
|
||||
|
||||
# rust/src/ui/api/firmware_upy.rs
|
||||
def request_bip39(
|
||||
*,
|
||||
|
@ -67,7 +67,7 @@ async def recovery_device(msg: RecoveryDevice) -> Success:
|
||||
return await recovery_process()
|
||||
|
||||
if recovery_type == RecoveryType.NormalRecovery:
|
||||
await confirm_reset_device(TR.recovery__title_recover, recovery=True)
|
||||
await confirm_reset_device(recovery=True)
|
||||
|
||||
# wipe storage to make sure the device is in a clear state
|
||||
storage.reset()
|
||||
|
@ -55,7 +55,7 @@ async def reset_device(msg: ResetDevice) -> Success:
|
||||
_validate_reset_device(msg)
|
||||
|
||||
# make sure user knows they're setting up a new wallet
|
||||
await confirm_reset_device(TR.reset__title_create_wallet)
|
||||
await confirm_reset_device()
|
||||
|
||||
# Rendering empty loader so users do not feel a freezing screen
|
||||
render_empty_loader(config.StorageMessage.PROCESSING_MSG)
|
||||
|
@ -89,8 +89,10 @@ def confirm_single(
|
||||
)
|
||||
|
||||
|
||||
def confirm_reset_device(_title: str, recovery: bool = False) -> Awaitable[None]:
|
||||
return raise_if_not_confirmed(trezorui2.flow_confirm_reset(recovery=recovery), None)
|
||||
def confirm_reset_device(recovery: bool = False) -> Awaitable[None]:
|
||||
return raise_if_not_confirmed(
|
||||
trezorui_api.confirm_reset_device(recovery=recovery), None
|
||||
)
|
||||
|
||||
|
||||
async def show_wallet_created_success() -> None:
|
||||
|
@ -109,19 +109,10 @@ def confirm_single(
|
||||
|
||||
|
||||
def confirm_reset_device(
|
||||
title: str,
|
||||
recovery: bool = False,
|
||||
) -> Awaitable[None]:
|
||||
if recovery:
|
||||
button = TR.reset__button_recover
|
||||
else:
|
||||
button = TR.reset__button_create
|
||||
|
||||
return raise_if_not_confirmed(
|
||||
trezorui2.confirm_reset_device(
|
||||
title=title,
|
||||
button=button,
|
||||
),
|
||||
trezorui_api.confirm_reset_device(recovery=recovery),
|
||||
"recover_device" if recovery else "setup_device",
|
||||
ButtonRequestType.ProtectCall if recovery else ButtonRequestType.ResetDevice,
|
||||
)
|
||||
|
@ -84,17 +84,9 @@ def confirm_single(
|
||||
)
|
||||
|
||||
|
||||
def confirm_reset_device(title: str, recovery: bool = False) -> Awaitable[None]:
|
||||
if recovery:
|
||||
button = TR.reset__button_recover
|
||||
else:
|
||||
button = TR.reset__button_create
|
||||
|
||||
def confirm_reset_device(recovery: bool = False) -> Awaitable[None]:
|
||||
return raise_if_not_confirmed(
|
||||
trezorui2.confirm_reset_device(
|
||||
title=title,
|
||||
button=button,
|
||||
),
|
||||
trezorui_api.confirm_reset_device(recovery=recovery),
|
||||
"recover_device" if recovery else "setup_device",
|
||||
(ButtonRequestType.ProtectCall if recovery else ButtonRequestType.ResetDevice),
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user