mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-29 10:58:21 +00:00
refactor(core): move show_simple to UiFeatures
- replace `show_passphrase` of model_r with `show_simple`
This commit is contained in:
parent
f5fbed7146
commit
f34fbe95eb
@ -657,7 +657,6 @@ static void _librust_qstrs(void) {
|
||||
MP_QSTR_show_instructions;
|
||||
MP_QSTR_show_lockscreen;
|
||||
MP_QSTR_show_mismatch;
|
||||
MP_QSTR_show_passphrase;
|
||||
MP_QSTR_show_progress;
|
||||
MP_QSTR_show_progress_coinjoin;
|
||||
MP_QSTR_show_remaining_shares;
|
||||
|
@ -432,6 +432,24 @@ extern "C" fn new_show_remaining_shares(n_args: usize, args: *const Obj, kwargs:
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_show_simple(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
|
||||
let block = move |_args: &[Obj], kwargs: &Map| {
|
||||
let text: TString = kwargs.get(Qstr::MP_QSTR_text)?.try_into()?;
|
||||
let title: Option<TString> = kwargs
|
||||
.get(Qstr::MP_QSTR_title)
|
||||
.and_then(Obj::try_into_option)
|
||||
.unwrap_or(None);
|
||||
let button: Option<TString> = kwargs
|
||||
.get(Qstr::MP_QSTR_button)
|
||||
.and_then(Obj::try_into_option)
|
||||
.unwrap_or(None);
|
||||
|
||||
let obj = ModelUI::show_simple(text, title, button)?;
|
||||
Ok(obj.into())
|
||||
};
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_show_success(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()?;
|
||||
@ -834,6 +852,15 @@ pub static mp_module_trezorui_api: Module = obj_module! {
|
||||
/// """Shows SLIP39 state after info button is pressed on `confirm_recovery`."""
|
||||
Qstr::MP_QSTR_show_remaining_shares => obj_fn_kw!(0, new_show_remaining_shares).as_obj(),
|
||||
|
||||
/// def show_simple(
|
||||
/// *,
|
||||
/// text: str,
|
||||
/// title: str | None = None,
|
||||
/// button: str | None = None,
|
||||
/// ) -> LayoutObj[UiResult]:
|
||||
/// """Simple dialog with text. TT: optional button."""
|
||||
Qstr::MP_QSTR_show_simple => obj_fn_kw!(0, new_show_simple).as_obj(),
|
||||
|
||||
/// def show_success(
|
||||
/// *,
|
||||
/// title: str,
|
||||
|
@ -727,20 +727,6 @@ extern "C" fn new_show_share_words(n_args: usize, args: *const Obj, kwargs: *mut
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_show_simple(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
|
||||
let block = move |_args: &[Obj], kwargs: &Map| {
|
||||
let description: TString = kwargs.get_or(Qstr::MP_QSTR_description, "".into())?;
|
||||
|
||||
let obj = LayoutObj::new(Border::new(
|
||||
theme::borders(),
|
||||
Paragraphs::new(Paragraph::new(&theme::TEXT_DEMIBOLD, description)),
|
||||
))?;
|
||||
|
||||
Ok(obj.into())
|
||||
};
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_confirm_with_info(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()?;
|
||||
@ -999,15 +985,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
||||
/// """
|
||||
Qstr::MP_QSTR_confirm_fido => obj_fn_kw!(0, new_confirm_fido).as_obj(),
|
||||
|
||||
/// def show_simple(
|
||||
/// *,
|
||||
/// title: str | None,
|
||||
/// description: str = "",
|
||||
/// button: str = "",
|
||||
/// ) -> LayoutObj[UiResult]:
|
||||
/// """Simple dialog with text and one button."""
|
||||
Qstr::MP_QSTR_show_simple => obj_fn_kw!(0, new_show_simple).as_obj(),
|
||||
|
||||
/// def confirm_with_info(
|
||||
/// *,
|
||||
/// title: str,
|
||||
|
@ -14,7 +14,7 @@ use crate::{
|
||||
Checklist, Paragraph, ParagraphSource, ParagraphVecLong, ParagraphVecShort,
|
||||
Paragraphs, VecExt,
|
||||
},
|
||||
CachedJpeg, ComponentExt, Empty, Never, Timeout,
|
||||
Border, CachedJpeg, ComponentExt, Empty, Never, Timeout,
|
||||
},
|
||||
geometry::{self, Direction},
|
||||
layout::{
|
||||
@ -508,6 +508,18 @@ impl UIFeaturesFirmware for ModelMercuryFeatures {
|
||||
))
|
||||
}
|
||||
|
||||
fn show_simple(
|
||||
text: TString<'static>,
|
||||
_title: Option<TString<'static>>,
|
||||
_button: Option<TString<'static>>,
|
||||
) -> Result<Gc<LayoutObj>, Error> {
|
||||
let obj = LayoutObj::new(Border::new(
|
||||
theme::borders(),
|
||||
Paragraphs::new(Paragraph::new(&theme::TEXT_DEMIBOLD, text)),
|
||||
))?;
|
||||
Ok(obj)
|
||||
}
|
||||
|
||||
fn show_success(
|
||||
title: TString<'static>,
|
||||
button: TString<'static>,
|
||||
|
@ -842,28 +842,6 @@ extern "C" fn new_confirm_fido(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_show_passphrase() -> Obj {
|
||||
let block = move || {
|
||||
let text: TString = TR::passphrase__please_enter.into();
|
||||
let paragraph = Paragraph::new(&theme::TEXT_NORMAL, text).centered();
|
||||
let content = Paragraphs::new([paragraph]);
|
||||
let obj = LayoutObj::new(content)?;
|
||||
Ok(obj.into())
|
||||
};
|
||||
unsafe { util::try_or_raise(block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_show_waiting_text(message: Obj) -> Obj {
|
||||
let block = || {
|
||||
let text: TString = message.try_into()?;
|
||||
let paragraph = Paragraph::new(&theme::TEXT_NORMAL, text).centered();
|
||||
let content = Paragraphs::new([paragraph]);
|
||||
let obj = LayoutObj::new(content)?;
|
||||
Ok(obj.into())
|
||||
};
|
||||
unsafe { util::try_or_raise(block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_confirm_with_info(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()?;
|
||||
@ -1133,10 +1111,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
||||
/// """Show multiple texts, each on its own page."""
|
||||
Qstr::MP_QSTR_multiple_pages_texts => obj_fn_kw!(0, new_multiple_pages_texts).as_obj(),
|
||||
|
||||
/// def show_passphrase() -> LayoutObj[UiResult]:
|
||||
/// """Show passphrase on host dialog."""
|
||||
Qstr::MP_QSTR_show_passphrase => obj_fn_0!(new_show_passphrase).as_obj(),
|
||||
|
||||
/// def confirm_with_info(
|
||||
/// *,
|
||||
/// title: str,
|
||||
|
@ -510,6 +510,17 @@ impl UIFeaturesFirmware for ModelTRFeatures {
|
||||
))
|
||||
}
|
||||
|
||||
fn show_simple(
|
||||
text: TString<'static>,
|
||||
_title: Option<TString<'static>>,
|
||||
_button: Option<TString<'static>>,
|
||||
) -> Result<Gc<LayoutObj>, Error> {
|
||||
let paragraph = Paragraph::new(&theme::TEXT_NORMAL, text).centered();
|
||||
let content = Paragraphs::new([paragraph]);
|
||||
let obj = LayoutObj::new(content)?;
|
||||
Ok(obj)
|
||||
}
|
||||
|
||||
fn show_success(
|
||||
title: TString<'static>,
|
||||
button: TString<'static>,
|
||||
|
@ -720,53 +720,6 @@ extern "C" fn new_confirm_fido(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_show_simple(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
|
||||
let block = move |_args: &[Obj], kwargs: &Map| {
|
||||
let title: Option<TString> = kwargs.get(Qstr::MP_QSTR_title)?.try_into_option()?;
|
||||
let description: TString = kwargs.get_or(Qstr::MP_QSTR_description, "".into())?;
|
||||
let button: TString = kwargs.get_or(Qstr::MP_QSTR_button, "".into())?;
|
||||
|
||||
let obj = if let Some(t) = title {
|
||||
LayoutObj::new(Frame::left_aligned(
|
||||
theme::label_title(),
|
||||
t,
|
||||
Dialog::new(
|
||||
Paragraphs::new([Paragraph::new(&theme::TEXT_NORMAL, description)]),
|
||||
theme::button_bar(Button::with_text(button).map(|msg| {
|
||||
(matches!(msg, ButtonMsg::Clicked)).then(|| CancelConfirmMsg::Confirmed)
|
||||
})),
|
||||
),
|
||||
))?
|
||||
.into()
|
||||
} else if !button.is_empty() {
|
||||
LayoutObj::new(Border::new(
|
||||
theme::borders(),
|
||||
Dialog::new(
|
||||
Paragraphs::new([Paragraph::new(&theme::TEXT_NORMAL, description)]),
|
||||
theme::button_bar(Button::with_text(button).map(|msg| {
|
||||
(matches!(msg, ButtonMsg::Clicked)).then(|| CancelConfirmMsg::Confirmed)
|
||||
})),
|
||||
),
|
||||
))?
|
||||
.into()
|
||||
} else {
|
||||
LayoutObj::new(Border::new(
|
||||
theme::borders(),
|
||||
Dialog::new(
|
||||
Paragraphs::new(
|
||||
[Paragraph::new(&theme::TEXT_DEMIBOLD, description).centered()],
|
||||
),
|
||||
Empty,
|
||||
),
|
||||
))?
|
||||
.into()
|
||||
};
|
||||
|
||||
Ok(obj)
|
||||
};
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_confirm_with_info(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()?;
|
||||
@ -1021,15 +974,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
||||
/// """
|
||||
Qstr::MP_QSTR_confirm_fido => obj_fn_kw!(0, new_confirm_fido).as_obj(),
|
||||
|
||||
/// def show_simple(
|
||||
/// *,
|
||||
/// title: str | None,
|
||||
/// description: str = "",
|
||||
/// button: str = "",
|
||||
/// ) -> LayoutObj[UiResult]:
|
||||
/// """Simple dialog with text and one button."""
|
||||
Qstr::MP_QSTR_show_simple => obj_fn_kw!(0, new_show_simple).as_obj(),
|
||||
|
||||
/// def confirm_with_info(
|
||||
/// *,
|
||||
/// title: str,
|
||||
|
@ -14,7 +14,7 @@ use crate::{
|
||||
Checklist, Paragraph, ParagraphSource, ParagraphVecLong, ParagraphVecShort,
|
||||
Paragraphs, VecExt,
|
||||
},
|
||||
ComponentExt, Empty, Jpeg, Label, Never, Timeout,
|
||||
Border, ComponentExt, Empty, Jpeg, Label, Never, Timeout,
|
||||
},
|
||||
layout::{
|
||||
obj::{LayoutMaybeTrace, LayoutObj, RootComponent},
|
||||
@ -587,6 +587,44 @@ impl UIFeaturesFirmware for ModelTTFeatures {
|
||||
Ok(layout)
|
||||
}
|
||||
|
||||
fn show_simple(
|
||||
text: TString<'static>,
|
||||
title: Option<TString<'static>>,
|
||||
button: Option<TString<'static>>,
|
||||
) -> Result<Gc<LayoutObj>, Error> {
|
||||
let button = button.unwrap_or(TString::empty());
|
||||
if let Some(t) = title {
|
||||
LayoutObj::new(Frame::left_aligned(
|
||||
theme::label_title(),
|
||||
t,
|
||||
Dialog::new(
|
||||
Paragraphs::new([Paragraph::new(&theme::TEXT_NORMAL, text)]),
|
||||
theme::button_bar(Button::with_text(button).map(|msg| {
|
||||
(matches!(msg, ButtonMsg::Clicked)).then(|| CancelConfirmMsg::Confirmed)
|
||||
})),
|
||||
),
|
||||
))
|
||||
} else if !button.is_empty() {
|
||||
LayoutObj::new(Border::new(
|
||||
theme::borders(),
|
||||
Dialog::new(
|
||||
Paragraphs::new([Paragraph::new(&theme::TEXT_NORMAL, text)]),
|
||||
theme::button_bar(Button::with_text(button).map(|msg| {
|
||||
(matches!(msg, ButtonMsg::Clicked)).then(|| CancelConfirmMsg::Confirmed)
|
||||
})),
|
||||
),
|
||||
))
|
||||
} else {
|
||||
LayoutObj::new(Border::new(
|
||||
theme::borders(),
|
||||
Dialog::new(
|
||||
Paragraphs::new([Paragraph::new(&theme::TEXT_DEMIBOLD, text).centered()]),
|
||||
Empty,
|
||||
),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn show_success(
|
||||
title: TString<'static>,
|
||||
button: TString<'static>,
|
||||
|
@ -159,6 +159,12 @@ pub trait UIFeaturesFirmware {
|
||||
pages_iterable: Obj, // TODO: replace Obj
|
||||
) -> Result<impl LayoutMaybeTrace, Error>;
|
||||
|
||||
fn show_simple(
|
||||
text: TString<'static>,
|
||||
title: Option<TString<'static>>,
|
||||
button: Option<TString<'static>>,
|
||||
) -> Result<Gc<LayoutObj>, Error>; // TODO: return LayoutMaybeTrace
|
||||
|
||||
fn show_success(
|
||||
title: TString<'static>,
|
||||
button: TString<'static>,
|
||||
|
@ -137,16 +137,6 @@ def confirm_fido(
|
||||
"""
|
||||
|
||||
|
||||
# rust/src/ui/model_mercury/layout.rs
|
||||
def show_simple(
|
||||
*,
|
||||
title: str | None,
|
||||
description: str = "",
|
||||
button: str = "",
|
||||
) -> LayoutObj[UiResult]:
|
||||
"""Simple dialog with text and one button."""
|
||||
|
||||
|
||||
# rust/src/ui/model_mercury/layout.rs
|
||||
def confirm_with_info(
|
||||
*,
|
||||
@ -418,11 +408,6 @@ def multiple_pages_texts(
|
||||
"""Show multiple texts, each on its own page."""
|
||||
|
||||
|
||||
# rust/src/ui/model_tr/layout.rs
|
||||
def show_passphrase() -> LayoutObj[UiResult]:
|
||||
"""Show passphrase on host dialog."""
|
||||
|
||||
|
||||
# rust/src/ui/model_tr/layout.rs
|
||||
def confirm_with_info(
|
||||
*,
|
||||
@ -594,16 +579,6 @@ def confirm_fido(
|
||||
"""
|
||||
|
||||
|
||||
# rust/src/ui/model_tt/layout.rs
|
||||
def show_simple(
|
||||
*,
|
||||
title: str | None,
|
||||
description: str = "",
|
||||
button: str = "",
|
||||
) -> LayoutObj[UiResult]:
|
||||
"""Simple dialog with text and one button."""
|
||||
|
||||
|
||||
# rust/src/ui/model_tt/layout.rs
|
||||
def confirm_with_info(
|
||||
*,
|
||||
|
@ -335,6 +335,16 @@ def show_remaining_shares(
|
||||
"""Shows SLIP39 state after info button is pressed on `confirm_recovery`."""
|
||||
|
||||
|
||||
# rust/src/ui/api/firmware_upy.rs
|
||||
def show_simple(
|
||||
*,
|
||||
text: str,
|
||||
title: str | None = None,
|
||||
button: str | None = None,
|
||||
) -> LayoutObj[UiResult]:
|
||||
"""Simple dialog with text. TT: optional button."""
|
||||
|
||||
|
||||
# rust/src/ui/api/firmware_upy.rs
|
||||
def show_success(
|
||||
*,
|
||||
|
@ -1085,9 +1085,9 @@ def error_popup(
|
||||
|
||||
def request_passphrase_on_host() -> None:
|
||||
draw_simple(
|
||||
trezorui2.show_simple(
|
||||
trezorui_api.show_simple(
|
||||
title=None,
|
||||
description=TR.passphrase__please_enter,
|
||||
text=TR.passphrase__please_enter,
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -1141,7 +1141,12 @@ def error_popup(
|
||||
|
||||
|
||||
def request_passphrase_on_host() -> None:
|
||||
draw_simple(trezorui2.show_passphrase())
|
||||
draw_simple(
|
||||
trezorui_api.show_simple(
|
||||
title=None,
|
||||
text=TR.passphrase__please_enter,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def show_wait_text(message: str) -> None:
|
||||
|
@ -1133,9 +1133,9 @@ def error_popup(
|
||||
|
||||
def request_passphrase_on_host() -> None:
|
||||
draw_simple(
|
||||
trezorui2.show_simple(
|
||||
trezorui_api.show_simple(
|
||||
title=None,
|
||||
description=TR.passphrase__please_enter,
|
||||
text=TR.passphrase__please_enter,
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -168,9 +168,9 @@ async def _prompt_number(
|
||||
return value
|
||||
|
||||
await interact(
|
||||
trezorui2.show_simple(
|
||||
trezorui_api.show_simple(
|
||||
title=None,
|
||||
description=info(value),
|
||||
text=info(value),
|
||||
button=TR.buttons__ok_i_understand,
|
||||
),
|
||||
None,
|
||||
|
Loading…
Reference in New Issue
Block a user