mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-25 17:09:44 +00:00
refactor(core): move confirm_firmware_update
This commit is contained in:
parent
5aeab55429
commit
88c5466288
@ -69,6 +69,21 @@ extern "C" fn new_confirm_action(n_args: usize, args: *const Obj, kwargs: *mut M
|
||||
};
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
// TODO: there was `no_mangle` attribute in TT, should we apply it?
|
||||
extern "C" fn new_confirm_firmware_update(
|
||||
n_args: usize,
|
||||
args: *const Obj,
|
||||
kwargs: *mut Map,
|
||||
) -> Obj {
|
||||
let block = move |_args: &[Obj], kwargs: &Map| {
|
||||
let description: TString = kwargs.get(Qstr::MP_QSTR_description)?.try_into()?;
|
||||
let fingerprint: TString = kwargs.get(Qstr::MP_QSTR_fingerprint)?.try_into()?;
|
||||
|
||||
let layout = ModelUI::confirm_firmware_update(description, fingerprint)?;
|
||||
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| {
|
||||
@ -286,6 +301,14 @@ pub static mp_module_trezorui_api: Module = obj_module! {
|
||||
/// """Confirm action."""
|
||||
Qstr::MP_QSTR_confirm_action => obj_fn_kw!(0, new_confirm_action).as_obj(),
|
||||
|
||||
/// def confirm_firmware_update(
|
||||
/// *,
|
||||
/// description: str,
|
||||
/// fingerprint: str,
|
||||
/// ) -> LayoutObj[UiResult]:
|
||||
/// """Ask whether to update firmware, optionally show fingerprint."""
|
||||
Qstr::MP_QSTR_confirm_firmware_update => obj_fn_kw!(0, new_confirm_firmware_update).as_obj(),
|
||||
|
||||
/// def request_bip39(
|
||||
/// *,
|
||||
/// prompt: str,
|
||||
|
@ -363,22 +363,6 @@ extern "C" fn new_confirm_address(n_args: usize, args: *const Obj, kwargs: *mut
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_confirm_firmware_update(
|
||||
n_args: usize,
|
||||
args: *const Obj,
|
||||
kwargs: *mut Map,
|
||||
) -> Obj {
|
||||
let block = move |_args: &[Obj], kwargs: &Map| {
|
||||
let description: TString = kwargs.get(Qstr::MP_QSTR_description)?.try_into()?;
|
||||
let fingerprint: TString = kwargs.get(Qstr::MP_QSTR_fingerprint)?.try_into()?;
|
||||
|
||||
let flow =
|
||||
flow::confirm_firmware_update::new_confirm_firmware_update(description, fingerprint)?;
|
||||
Ok(LayoutObj::new_root(flow)?.into())
|
||||
};
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_confirm_properties(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()?;
|
||||
@ -1697,14 +1681,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
||||
/// """Homescreen for locked device."""
|
||||
Qstr::MP_QSTR_show_lockscreen => obj_fn_kw!(0, new_show_lockscreen).as_obj(),
|
||||
|
||||
/// def confirm_firmware_update(
|
||||
/// *,
|
||||
/// description: str,
|
||||
/// fingerprint: str,
|
||||
/// ) -> LayoutObj[UiResult]:
|
||||
/// """Ask whether to update firmware, optionally show fingerprint."""
|
||||
Qstr::MP_QSTR_confirm_firmware_update => obj_fn_kw!(0, new_confirm_firmware_update).as_obj(),
|
||||
|
||||
/// def tutorial() -> LayoutObj[UiResult]:
|
||||
/// """Show user how to interact with the device."""
|
||||
Qstr::MP_QSTR_tutorial => obj_fn_0!(new_show_tutorial).as_obj(),
|
||||
|
@ -54,6 +54,15 @@ impl UIFeaturesFirmware for ModelMercuryFeatures {
|
||||
Ok(flow)
|
||||
}
|
||||
|
||||
fn confirm_firmware_update(
|
||||
description: TString<'static>,
|
||||
fingerprint: TString<'static>,
|
||||
) -> Result<impl LayoutMaybeTrace, Error> {
|
||||
let flow =
|
||||
flow::confirm_firmware_update::new_confirm_firmware_update(description, fingerprint)?;
|
||||
Ok(flow)
|
||||
}
|
||||
|
||||
fn check_homescreen_format(image: BinaryData, __accept_toif: bool) -> bool {
|
||||
super::component::check_homescreen_format(image)
|
||||
}
|
||||
|
@ -1423,43 +1423,6 @@ extern "C" fn new_show_lockscreen(n_args: usize, args: *const Obj, kwargs: *mut
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_confirm_firmware_update(
|
||||
n_args: usize,
|
||||
args: *const Obj,
|
||||
kwargs: *mut Map,
|
||||
) -> Obj {
|
||||
use super::component::bl_confirm::Confirm;
|
||||
let block = move |_args: &[Obj], kwargs: &Map| {
|
||||
let description: TString = kwargs.get(Qstr::MP_QSTR_description)?.try_into()?;
|
||||
let fingerprint: TString = kwargs.get(Qstr::MP_QSTR_fingerprint)?.try_into()?;
|
||||
|
||||
let title = TR::firmware_update__title;
|
||||
let message = Label::left_aligned(description, theme::TEXT_NORMAL).vertically_centered();
|
||||
let fingerprint = Label::left_aligned(
|
||||
fingerprint,
|
||||
theme::TEXT_NORMAL.with_line_breaking(LineBreaking::BreakWordsNoHyphen),
|
||||
)
|
||||
.vertically_centered();
|
||||
|
||||
let obj = LayoutObj::new(
|
||||
Confirm::new(
|
||||
theme::BG,
|
||||
title.into(),
|
||||
message,
|
||||
None,
|
||||
TR::buttons__install.as_tstring(),
|
||||
false,
|
||||
)
|
||||
.with_info_screen(
|
||||
TR::firmware_update__title_fingerprint.as_tstring(),
|
||||
fingerprint,
|
||||
),
|
||||
)?;
|
||||
Ok(obj.into())
|
||||
};
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_show_wait_text(message: Obj) -> Obj {
|
||||
let block = || {
|
||||
let message: TString<'static> = message.try_into()?;
|
||||
@ -1798,14 +1761,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
||||
/// """Homescreen for locked device."""
|
||||
Qstr::MP_QSTR_show_lockscreen => obj_fn_kw!(0, new_show_lockscreen).as_obj(),
|
||||
|
||||
/// def confirm_firmware_update(
|
||||
/// *,
|
||||
/// description: str,
|
||||
/// fingerprint: str,
|
||||
/// ) -> LayoutObj[UiResult]:
|
||||
/// """Ask whether to update firmware, optionally show fingerprint. Shared with bootloader."""
|
||||
Qstr::MP_QSTR_confirm_firmware_update => obj_fn_kw!(0, new_confirm_firmware_update).as_obj(),
|
||||
|
||||
/// def show_wait_text(message: str, /) -> None:
|
||||
/// """Show single-line text in the middle of the screen."""
|
||||
Qstr::MP_QSTR_show_wait_text => obj_fn_1!(new_show_wait_text).as_obj(),
|
||||
|
@ -8,7 +8,7 @@ use crate::{
|
||||
ui::{
|
||||
component::{
|
||||
text::paragraphs::{Paragraph, ParagraphSource, ParagraphVecShort, Paragraphs, VecExt},
|
||||
Component, ComponentExt, Paginate, Timeout,
|
||||
Component, ComponentExt, Label, LineBreaking, Paginate, Timeout,
|
||||
},
|
||||
layout::{
|
||||
obj::{LayoutMaybeTrace, LayoutObj, RootComponent},
|
||||
@ -67,6 +67,36 @@ impl UIFeaturesFirmware for ModelTRFeatures {
|
||||
)
|
||||
}
|
||||
|
||||
fn confirm_firmware_update(
|
||||
description: TString<'static>,
|
||||
fingerprint: TString<'static>,
|
||||
) -> Result<impl LayoutMaybeTrace, Error> {
|
||||
use super::component::bl_confirm::Confirm;
|
||||
let title = TR::firmware_update__title;
|
||||
let message = Label::left_aligned(description, theme::TEXT_NORMAL).vertically_centered();
|
||||
let fingerprint = Label::left_aligned(
|
||||
fingerprint,
|
||||
theme::TEXT_NORMAL.with_line_breaking(LineBreaking::BreakWordsNoHyphen),
|
||||
)
|
||||
.vertically_centered();
|
||||
|
||||
let layout = RootComponent::new(
|
||||
Confirm::new(
|
||||
theme::BG,
|
||||
title.into(),
|
||||
message,
|
||||
None,
|
||||
TR::buttons__install.as_tstring(),
|
||||
false,
|
||||
)
|
||||
.with_info_screen(
|
||||
TR::firmware_update__title_fingerprint.as_tstring(),
|
||||
fingerprint,
|
||||
),
|
||||
);
|
||||
Ok(layout)
|
||||
}
|
||||
|
||||
fn check_homescreen_format(image: BinaryData, _accept_toif: bool) -> bool {
|
||||
super::component::check_homescreen_format(image)
|
||||
}
|
||||
|
@ -1432,36 +1432,6 @@ extern "C" fn new_show_lockscreen(n_args: usize, args: *const Obj, kwargs: *mut
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn new_confirm_firmware_update(
|
||||
n_args: usize,
|
||||
args: *const Obj,
|
||||
kwargs: *mut Map,
|
||||
) -> Obj {
|
||||
use super::component::bl_confirm::{Confirm, ConfirmTitle};
|
||||
let block = move |_args: &[Obj], kwargs: &Map| {
|
||||
let description: TString = kwargs.get(Qstr::MP_QSTR_description)?.try_into()?;
|
||||
let fingerprint: TString = kwargs.get(Qstr::MP_QSTR_fingerprint)?.try_into()?;
|
||||
|
||||
let title_str = TR::firmware_update__title.into();
|
||||
let title = Label::left_aligned(title_str, theme::TEXT_BOLD).vertically_centered();
|
||||
let msg = Label::left_aligned(description, theme::TEXT_NORMAL);
|
||||
|
||||
let left = Button::with_text(TR::buttons__cancel.into()).styled(theme::button_default());
|
||||
let right = Button::with_text(TR::buttons__install.into()).styled(theme::button_confirm());
|
||||
|
||||
let obj = LayoutObj::new(
|
||||
Confirm::new(theme::BG, left, right, ConfirmTitle::Text(title), msg).with_info(
|
||||
TR::firmware_update__title_fingerprint.into(),
|
||||
fingerprint,
|
||||
theme::button_moreinfo(),
|
||||
),
|
||||
)?;
|
||||
Ok(obj.into())
|
||||
};
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_show_wait_text(message: Obj) -> Obj {
|
||||
let block = || {
|
||||
let message: TString<'static> = message.try_into()?;
|
||||
@ -1813,14 +1783,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
||||
/// """Homescreen for locked device."""
|
||||
Qstr::MP_QSTR_show_lockscreen => obj_fn_kw!(0, new_show_lockscreen).as_obj(),
|
||||
|
||||
/// def confirm_firmware_update(
|
||||
/// *,
|
||||
/// description: str,
|
||||
/// fingerprint: str,
|
||||
/// ) -> LayoutObj[UiResult]:
|
||||
/// """Ask whether to update firmware, optionally show fingerprint. Shared with bootloader."""
|
||||
Qstr::MP_QSTR_confirm_firmware_update => obj_fn_kw!(0, new_confirm_firmware_update).as_obj(),
|
||||
|
||||
/// def show_wait_text(message: str, /) -> LayoutObj[None]:
|
||||
/// """Show single-line text in the middle of the screen."""
|
||||
Qstr::MP_QSTR_show_wait_text => obj_fn_1!(new_show_wait_text).as_obj(),
|
||||
|
@ -6,9 +6,7 @@ use crate::{
|
||||
translations::TR,
|
||||
ui::{
|
||||
component::{
|
||||
image::BlendedImage,
|
||||
text::paragraphs::{Paragraph, ParagraphSource, ParagraphVecShort, Paragraphs, VecExt},
|
||||
ComponentExt, Empty, Timeout,
|
||||
image::BlendedImage, text::paragraphs::{Paragraph, ParagraphSource, ParagraphVecShort, Paragraphs, VecExt}, ComponentExt, Empty, Label, Timeout
|
||||
},
|
||||
layout::{
|
||||
obj::{LayoutMaybeTrace, LayoutObj, RootComponent},
|
||||
@ -69,6 +67,29 @@ impl UIFeaturesFirmware for ModelTTFeatures {
|
||||
Ok(layout)
|
||||
}
|
||||
|
||||
fn confirm_firmware_update(
|
||||
description: TString<'static>,
|
||||
fingerprint: TString<'static>,
|
||||
) -> Result<impl LayoutMaybeTrace, Error> {
|
||||
use super::component::bl_confirm::{Confirm, ConfirmTitle};
|
||||
|
||||
let title_str = TR::firmware_update__title.into();
|
||||
let title = Label::left_aligned(title_str, theme::TEXT_BOLD).vertically_centered();
|
||||
let msg = Label::left_aligned(description, theme::TEXT_NORMAL);
|
||||
|
||||
let left = Button::with_text(TR::buttons__cancel.into()).styled(theme::button_default());
|
||||
let right = Button::with_text(TR::buttons__install.into()).styled(theme::button_confirm());
|
||||
|
||||
let layout = RootComponent::new(
|
||||
Confirm::new(theme::BG, left, right, ConfirmTitle::Text(title), msg).with_info(
|
||||
TR::firmware_update__title_fingerprint.into(),
|
||||
fingerprint,
|
||||
theme::button_moreinfo(),
|
||||
),
|
||||
);
|
||||
Ok(layout)
|
||||
}
|
||||
|
||||
fn check_homescreen_format(image: BinaryData, accept_toif: bool) -> bool {
|
||||
super::component::check_homescreen_format(image, false)
|
||||
}
|
||||
|
@ -20,6 +20,11 @@ pub trait UIFeaturesFirmware {
|
||||
prompt_title: Option<TString<'static>>,
|
||||
) -> Result<impl LayoutMaybeTrace, Error>;
|
||||
|
||||
fn confirm_firmware_update(
|
||||
description: TString<'static>,
|
||||
fingerprint: TString<'static>,
|
||||
) -> Result<impl LayoutMaybeTrace, Error>;
|
||||
|
||||
fn check_homescreen_format(image: BinaryData, accept_toif: bool) -> bool;
|
||||
|
||||
fn request_bip39(
|
||||
|
@ -364,15 +364,6 @@ def show_lockscreen(
|
||||
"""Homescreen for locked device."""
|
||||
|
||||
|
||||
# rust/src/ui/model_mercury/layout.rs
|
||||
def confirm_firmware_update(
|
||||
*,
|
||||
description: str,
|
||||
fingerprint: str,
|
||||
) -> LayoutObj[UiResult]:
|
||||
"""Ask whether to update firmware, optionally show fingerprint."""
|
||||
|
||||
|
||||
# rust/src/ui/model_mercury/layout.rs
|
||||
def tutorial() -> LayoutObj[UiResult]:
|
||||
"""Show user how to interact with the device."""
|
||||
@ -808,15 +799,6 @@ def show_lockscreen(
|
||||
"""Homescreen for locked device."""
|
||||
|
||||
|
||||
# rust/src/ui/model_tr/layout.rs
|
||||
def confirm_firmware_update(
|
||||
*,
|
||||
description: str,
|
||||
fingerprint: str,
|
||||
) -> LayoutObj[UiResult]:
|
||||
"""Ask whether to update firmware, optionally show fingerprint. Shared with bootloader."""
|
||||
|
||||
|
||||
# rust/src/ui/model_tr/layout.rs
|
||||
def show_wait_text(message: str, /) -> None:
|
||||
"""Show single-line text in the middle of the screen."""
|
||||
@ -1190,15 +1172,6 @@ def show_lockscreen(
|
||||
"""Homescreen for locked device."""
|
||||
|
||||
|
||||
# rust/src/ui/model_tt/layout.rs
|
||||
def confirm_firmware_update(
|
||||
*,
|
||||
description: str,
|
||||
fingerprint: str,
|
||||
) -> LayoutObj[UiResult]:
|
||||
"""Ask whether to update firmware, optionally show fingerprint. Shared with bootloader."""
|
||||
|
||||
|
||||
# rust/src/ui/model_tt/layout.rs
|
||||
def show_wait_text(message: str, /) -> LayoutObj[None]:
|
||||
"""Show single-line text in the middle of the screen."""
|
||||
|
@ -96,6 +96,15 @@ def confirm_action(
|
||||
"""Confirm action."""
|
||||
|
||||
|
||||
# rust/src/ui/api/firmware_upy.rs
|
||||
def confirm_firmware_update(
|
||||
*,
|
||||
description: str,
|
||||
fingerprint: str,
|
||||
) -> LayoutObj[UiResult]:
|
||||
"""Ask whether to update firmware, optionally show fingerprint."""
|
||||
|
||||
|
||||
# rust/src/ui/api/firmware_upy.rs
|
||||
def request_bip39(
|
||||
*,
|
||||
|
@ -1183,7 +1183,7 @@ def confirm_set_new_pin(
|
||||
|
||||
def confirm_firmware_update(description: str, fingerprint: str) -> Awaitable[None]:
|
||||
return raise_if_not_confirmed(
|
||||
trezorui2.confirm_firmware_update(
|
||||
trezorui_api.confirm_firmware_update(
|
||||
description=description, fingerprint=fingerprint
|
||||
),
|
||||
"firmware_update",
|
||||
|
@ -1291,7 +1291,7 @@ async def confirm_set_new_pin(
|
||||
|
||||
def confirm_firmware_update(description: str, fingerprint: str) -> Awaitable[None]:
|
||||
return raise_if_not_confirmed(
|
||||
trezorui2.confirm_firmware_update(
|
||||
trezorui_api.confirm_firmware_update(
|
||||
description=description, fingerprint=fingerprint
|
||||
),
|
||||
"firmware_update",
|
||||
|
@ -1252,7 +1252,7 @@ def confirm_set_new_pin(
|
||||
|
||||
def confirm_firmware_update(description: str, fingerprint: str) -> Awaitable[None]:
|
||||
return raise_if_not_confirmed(
|
||||
trezorui2.confirm_firmware_update(
|
||||
trezorui_api.confirm_firmware_update(
|
||||
description=description, fingerprint=fingerprint
|
||||
),
|
||||
"firmware_update",
|
||||
|
Loading…
Reference in New Issue
Block a user