mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-04 13:38:28 +00:00
refactor(core): move prompt_backup
- model_r `confirm_backup` and mercury `flow_prompt_backup` merged into `prompt_backup` - not implemented for model_t
This commit is contained in:
parent
2b7c3a4e03
commit
d3e3c87be7
@ -192,7 +192,6 @@ static void _librust_qstrs(void) {
|
||||
MP_QSTR_coinjoin_authorized;
|
||||
MP_QSTR_confirm_action;
|
||||
MP_QSTR_confirm_address;
|
||||
MP_QSTR_confirm_backup;
|
||||
MP_QSTR_confirm_blob;
|
||||
MP_QSTR_confirm_blob_intro;
|
||||
MP_QSTR_confirm_coinjoin;
|
||||
@ -255,7 +254,6 @@ static void _librust_qstrs(void) {
|
||||
MP_QSTR_flow_confirm_set_new_pin;
|
||||
MP_QSTR_flow_confirm_summary;
|
||||
MP_QSTR_flow_get_address;
|
||||
MP_QSTR_flow_prompt_backup;
|
||||
MP_QSTR_get_language;
|
||||
MP_QSTR_get_transition_out;
|
||||
MP_QSTR_haptic_feedback__disable;
|
||||
@ -425,6 +423,7 @@ static void _librust_qstrs(void) {
|
||||
MP_QSTR_progress__x_seconds_left_template;
|
||||
MP_QSTR_progress_event;
|
||||
MP_QSTR_prompt;
|
||||
MP_QSTR_prompt_backup;
|
||||
MP_QSTR_prompt_screen;
|
||||
MP_QSTR_prompt_title;
|
||||
MP_QSTR_qr_title;
|
||||
|
@ -4,7 +4,7 @@ use crate::{
|
||||
gc::Gc,
|
||||
iter::IterBuf,
|
||||
list::List,
|
||||
macros::{obj_fn_1, obj_fn_kw, obj_module},
|
||||
macros::{obj_fn_0, obj_fn_1, obj_fn_kw, obj_module},
|
||||
map::Map,
|
||||
module::Module,
|
||||
obj::Obj,
|
||||
@ -387,6 +387,14 @@ extern "C" fn new_continue_recovery_homepage(
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_prompt_backup() -> Obj {
|
||||
let block = || {
|
||||
let layout = ModelUI::prompt_backup()?;
|
||||
Ok(LayoutObj::new_root(layout)?.into())
|
||||
};
|
||||
unsafe { util::try_or_raise(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()?;
|
||||
@ -1091,6 +1099,10 @@ pub static mp_module_trezorui_api: Module = obj_module! {
|
||||
/// """Device recovery homescreen."""
|
||||
Qstr::MP_QSTR_continue_recovery_homepage => obj_fn_kw!(0, new_continue_recovery_homepage).as_obj(),
|
||||
|
||||
/// def prompt_backup() -> LayoutObj[UiResult]:
|
||||
/// """Strongly recommend user to do a backup."""
|
||||
Qstr::MP_QSTR_prompt_backup => obj_fn_0!(new_prompt_backup).as_obj(),
|
||||
|
||||
/// def request_bip39(
|
||||
/// *,
|
||||
/// prompt: str,
|
||||
|
@ -534,16 +534,6 @@ extern "C" fn new_get_address(n_args: usize, args: *const Obj, kwargs: *mut Map)
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_prompt_backup() -> Obj {
|
||||
let block = || {
|
||||
let flow = flow::prompt_backup::new_prompt_backup()?;
|
||||
let obj = LayoutObj::new_root(flow)?;
|
||||
Ok(obj.into())
|
||||
};
|
||||
unsafe { util::try_or_raise(block) }
|
||||
}
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
pub static mp_module_trezorui2: Module = obj_module! {
|
||||
/// from trezor import utils
|
||||
@ -594,10 +584,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
||||
/// """Transaction summary. Always hold to confirm."""
|
||||
Qstr::MP_QSTR_confirm_total => obj_fn_kw!(0, new_confirm_total).as_obj(),
|
||||
|
||||
/// def flow_prompt_backup() -> LayoutObj[UiResult]:
|
||||
/// """Prompt a user to create backup with an option to skip."""
|
||||
Qstr::MP_QSTR_flow_prompt_backup => obj_fn_0!(new_prompt_backup).as_obj(),
|
||||
|
||||
/// def flow_get_address(
|
||||
/// *,
|
||||
/// address: str | bytes,
|
||||
|
@ -427,6 +427,11 @@ impl UIFeaturesFirmware for ModelMercuryFeatures {
|
||||
LayoutObj::new_root(flow)
|
||||
}
|
||||
|
||||
fn prompt_backup() -> Result<impl LayoutMaybeTrace, Error> {
|
||||
let flow = flow::prompt_backup::new_prompt_backup()?;
|
||||
Ok(flow)
|
||||
}
|
||||
|
||||
fn request_bip39(
|
||||
prompt: TString<'static>,
|
||||
prefill_word: TString<'static>,
|
||||
|
@ -270,39 +270,6 @@ fn content_in_button_page<T: Component + Paginate + MaybeTrace + 'static>(
|
||||
Ok(obj.into())
|
||||
}
|
||||
|
||||
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 {
|
||||
0 => {
|
||||
let btn_layout = ButtonLayout::text_none_arrow_wide(TR::buttons__skip.into());
|
||||
let btn_actions = ButtonActions::cancel_none_next();
|
||||
let ops = OpTextLayout::new(theme::TEXT_NORMAL)
|
||||
.text_normal(TR::backup__new_wallet_created)
|
||||
.newline()
|
||||
.text_normal(TR::backup__it_should_be_backed_up_now);
|
||||
let formatted = FormattedText::new(ops).vertically_centered();
|
||||
Page::new(btn_layout, btn_actions, formatted)
|
||||
.with_title(TR::words__title_success.into())
|
||||
}
|
||||
1 => {
|
||||
let btn_layout = ButtonLayout::up_arrow_none_text(TR::buttons__back_up.into());
|
||||
let btn_actions = ButtonActions::prev_none_confirm();
|
||||
let ops =
|
||||
OpTextLayout::new(theme::TEXT_NORMAL).text_normal(TR::backup__recover_anytime);
|
||||
let formatted = FormattedText::new(ops).vertically_centered();
|
||||
Page::new(btn_layout, btn_actions, formatted)
|
||||
.with_title(TR::backup__title_backup_wallet.into())
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let pages = FlowPages::new(get_page, 2);
|
||||
|
||||
let obj = LayoutObj::new(Flow::new(pages))?;
|
||||
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 address: TString = kwargs.get(Qstr::MP_QSTR_address)?.try_into()?;
|
||||
@ -624,10 +591,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
||||
///
|
||||
Qstr::MP_QSTR___name__ => Qstr::MP_QSTR_trezorui2.to_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(),
|
||||
|
||||
/// def show_address_details(
|
||||
/// *,
|
||||
/// address: str,
|
||||
|
@ -544,6 +544,36 @@ impl UIFeaturesFirmware for ModelTRFeatures {
|
||||
LayoutObj::new_root(layout)
|
||||
}
|
||||
|
||||
fn prompt_backup() -> Result<impl LayoutMaybeTrace, Error> {
|
||||
let get_page = move |page_index| match page_index {
|
||||
0 => {
|
||||
let btn_layout = ButtonLayout::text_none_arrow_wide(TR::buttons__skip.into());
|
||||
let btn_actions = ButtonActions::cancel_none_next();
|
||||
let ops = OpTextLayout::new(theme::TEXT_NORMAL)
|
||||
.text_normal(TR::backup__new_wallet_created)
|
||||
.newline()
|
||||
.text_normal(TR::backup__it_should_be_backed_up_now);
|
||||
let formatted = FormattedText::new(ops).vertically_centered();
|
||||
Page::new(btn_layout, btn_actions, formatted)
|
||||
.with_title(TR::words__title_success.into())
|
||||
}
|
||||
1 => {
|
||||
let btn_layout = ButtonLayout::up_arrow_none_text(TR::buttons__back_up.into());
|
||||
let btn_actions = ButtonActions::prev_none_confirm();
|
||||
let ops =
|
||||
OpTextLayout::new(theme::TEXT_NORMAL).text_normal(TR::backup__recover_anytime);
|
||||
let formatted = FormattedText::new(ops).vertically_centered();
|
||||
Page::new(btn_layout, btn_actions, formatted)
|
||||
.with_title(TR::backup__title_backup_wallet.into())
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let pages = FlowPages::new(get_page, 2);
|
||||
|
||||
let layout = RootComponent::new(Flow::new(pages));
|
||||
Ok(layout)
|
||||
}
|
||||
|
||||
fn request_bip39(
|
||||
prompt: TString<'static>,
|
||||
prefill_word: TString<'static>,
|
||||
|
@ -488,6 +488,12 @@ impl UIFeaturesFirmware for ModelTTFeatures {
|
||||
}
|
||||
}
|
||||
|
||||
fn prompt_backup() -> Result<impl LayoutMaybeTrace, Error> {
|
||||
Err::<RootComponent<Empty, ModelTTFeatures>, Error>(Error::ValueError(
|
||||
c"prompt_backup not implemented",
|
||||
))
|
||||
}
|
||||
|
||||
fn request_bip39(
|
||||
prompt: TString<'static>,
|
||||
prefill_word: TString<'static>,
|
||||
|
@ -137,6 +137,8 @@ pub trait UIFeaturesFirmware {
|
||||
|
||||
fn check_homescreen_format(image: BinaryData, accept_toif: bool) -> bool;
|
||||
|
||||
fn prompt_backup() -> Result<impl LayoutMaybeTrace, Error>;
|
||||
|
||||
fn request_bip39(
|
||||
prompt: TString<'static>,
|
||||
prefill_word: TString<'static>,
|
||||
|
@ -47,11 +47,6 @@ def confirm_total(
|
||||
"""Transaction summary. Always hold to confirm."""
|
||||
|
||||
|
||||
# rust/src/ui/model_mercury/layout.rs
|
||||
def flow_prompt_backup() -> LayoutObj[UiResult]:
|
||||
"""Prompt a user to create backup with an option to skip."""
|
||||
|
||||
|
||||
# rust/src/ui/model_mercury/layout.rs
|
||||
def flow_get_address(
|
||||
*,
|
||||
@ -114,11 +109,6 @@ from trezor import utils
|
||||
from trezorui_api import *
|
||||
|
||||
|
||||
# rust/src/ui/model_tr/layout.rs
|
||||
def confirm_backup() -> LayoutObj[UiResult]:
|
||||
"""Strongly recommend user to do backup."""
|
||||
|
||||
|
||||
# rust/src/ui/model_tr/layout.rs
|
||||
def show_address_details(
|
||||
*,
|
||||
|
@ -266,6 +266,11 @@ def continue_recovery_homepage(
|
||||
"""Device recovery homescreen."""
|
||||
|
||||
|
||||
# rust/src/ui/api/firmware_upy.rs
|
||||
def prompt_backup() -> LayoutObj[UiResult]:
|
||||
"""Strongly recommend user to do a backup."""
|
||||
|
||||
|
||||
# rust/src/ui/api/firmware_upy.rs
|
||||
def request_bip39(
|
||||
*,
|
||||
|
@ -105,7 +105,7 @@ async def show_wallet_created_success() -> None:
|
||||
|
||||
async def prompt_backup() -> bool:
|
||||
result = await interact(
|
||||
trezorui2.flow_prompt_backup(),
|
||||
trezorui_api.prompt_backup(),
|
||||
"backup_device",
|
||||
ButtonRequestType.ResetDevice,
|
||||
raise_on_cancel=None,
|
||||
|
@ -128,7 +128,7 @@ async def prompt_backup() -> bool:
|
||||
br_code = ButtonRequestType.ResetDevice
|
||||
|
||||
result = await interact(
|
||||
trezorui2.confirm_backup(),
|
||||
trezorui_api.prompt_backup(),
|
||||
br_name,
|
||||
br_code,
|
||||
raise_on_cancel=None,
|
||||
|
Loading…
Reference in New Issue
Block a user