1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-25 17:09:44 +00:00

refactor(core): move show_remaining_shares

- only supported for model_t
- dependence on Obj
This commit is contained in:
obrusvit 2024-11-04 14:18:17 +01:00
parent 6bb6ce401c
commit e551a61e39
9 changed files with 72 additions and 47 deletions

View File

@ -409,6 +409,15 @@ extern "C" fn new_show_progress_coinjoin(n_args: usize, args: *const Obj, kwargs
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
} }
extern "C" fn new_show_remaining_shares(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
let block = move |_args: &[Obj], kwargs: &Map| {
let pages_iterable: Obj = kwargs.get(Qstr::MP_QSTR_pages)?;
let layout = ModelUI::show_remaining_shares(pages_iterable)?;
Ok(LayoutObj::new_root(layout)?.into())
};
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
}
extern "C" fn new_show_wait_text(message: Obj) -> Obj { extern "C" fn new_show_wait_text(message: Obj) -> Obj {
let block = || { let block = || {
let message: TString<'static> = message.try_into()?; let message: TString<'static> = message.try_into()?;
@ -755,6 +764,13 @@ pub static mp_module_trezorui_api: Module = obj_module! {
/// time_ms timeout is passed.""" /// time_ms timeout is passed."""
Qstr::MP_QSTR_show_progress_coinjoin => obj_fn_kw!(0, new_show_progress_coinjoin).as_obj(), Qstr::MP_QSTR_show_progress_coinjoin => obj_fn_kw!(0, new_show_progress_coinjoin).as_obj(),
/// def show_remaining_shares(
/// *,
/// pages: Iterable[tuple[str, str]],
/// ) -> LayoutObj[UiResult]:
/// """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_wait_text(message: str, /) -> LayoutObj[None]: /// def show_wait_text(message: str, /) -> LayoutObj[None]:
/// """Show single-line text in the middle of the screen.""" /// """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(), Qstr::MP_QSTR_show_wait_text => obj_fn_1!(new_show_wait_text).as_obj(),

View File

@ -8,13 +8,10 @@ use crate::{
translations::TR, translations::TR,
ui::{ ui::{
component::{ component::{
connect::Connect, connect::Connect, swipe_detect::SwipeSettings, text::paragraphs::{
swipe_detect::SwipeSettings,
text::paragraphs::{
Checklist, Paragraph, ParagraphSource, ParagraphVecLong, ParagraphVecShort, Checklist, Paragraph, ParagraphSource, ParagraphVecLong, ParagraphVecShort,
Paragraphs, VecExt, Paragraphs, VecExt,
}, }, CachedJpeg, ComponentExt, Empty, Never, Timeout
CachedJpeg, ComponentExt, Never, Timeout,
}, },
geometry::{self, Direction}, geometry::{self, Direction},
layout::{ layout::{
@ -469,6 +466,15 @@ impl UIFeaturesFirmware for ModelMercuryFeatures {
Ok(obj) Ok(obj)
} }
fn show_remaining_shares(
pages_iterable: crate::micropython::obj::Obj, // TODO: replace Obj
) -> Result<impl LayoutMaybeTrace, Error> {
// Mercury: remaining shares is a part of `continue_recovery` flow
Err::<RootComponent<Empty, ModelMercuryFeatures>, Error>(Error::ValueError(
c"show remaining shares not supported",
))
}
fn show_wait_text(text: TString<'static>) -> Result<impl LayoutMaybeTrace, Error> { fn show_wait_text(text: TString<'static>) -> Result<impl LayoutMaybeTrace, Error> {
let layout = RootComponent::new(Connect::new(text, theme::FG, theme::BG)); let layout = RootComponent::new(Connect::new(text, theme::FG, theme::BG));
Ok(layout) Ok(layout)

View File

@ -491,6 +491,14 @@ impl UIFeaturesFirmware for ModelTRFeatures {
Ok(obj) Ok(obj)
} }
fn show_remaining_shares(
pages_iterable: crate::micropython::obj::Obj, // TODO: replace Obj
) -> Result<impl LayoutMaybeTrace, Error> {
Err::<RootComponent<Empty, ModelTRFeatures>, Error>(Error::ValueError(
c"show remaining shares not supported",
))
}
fn show_wait_text(text: TString<'static>) -> Result<impl LayoutMaybeTrace, Error> { fn show_wait_text(text: TString<'static>) -> Result<impl LayoutMaybeTrace, Error> {
let layout = RootComponent::new(Connect::new(text, theme::FG, theme::BG)); let layout = RootComponent::new(Connect::new(text, theme::FG, theme::BG));
Ok(layout) Ok(layout)

View File

@ -1023,31 +1023,6 @@ extern "C" fn new_confirm_recovery(n_args: usize, args: *const Obj, kwargs: *mut
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
} }
extern "C" fn new_show_remaining_shares(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
let block = move |_args: &[Obj], kwargs: &Map| {
let pages_iterable: Obj = kwargs.get(Qstr::MP_QSTR_pages)?;
let mut paragraphs = ParagraphVecLong::new();
for page in IterBuf::new().try_iterate(pages_iterable)? {
let [title, description]: [TString; 2] = util::iter_into_array(page)?;
paragraphs
.add(Paragraph::new(&theme::TEXT_DEMIBOLD, title))
.add(Paragraph::new(&theme::TEXT_NORMAL, description).break_after());
}
let obj = LayoutObj::new(Frame::left_aligned(
theme::label_title(),
TR::recovery__title_remaining_shares.into(),
ButtonPage::new(paragraphs.into_paragraphs(), theme::BG)
.with_cancel_confirm(None, Some(TR::buttons__continue.into()))
.with_confirm_style(theme::button_default())
.without_cancel(),
))?;
Ok(obj.into())
};
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
}
#[no_mangle] #[no_mangle]
pub static mp_module_trezorui2: Module = obj_module! { pub static mp_module_trezorui2: Module = obj_module! {
/// from trezor import utils /// from trezor import utils
@ -1254,13 +1229,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// ) -> LayoutObj[UiResult]: /// ) -> LayoutObj[UiResult]:
/// """Device recovery homescreen.""" /// """Device recovery homescreen."""
Qstr::MP_QSTR_confirm_recovery => obj_fn_kw!(0, new_confirm_recovery).as_obj(), Qstr::MP_QSTR_confirm_recovery => obj_fn_kw!(0, new_confirm_recovery).as_obj(),
/// def show_remaining_shares(
/// *,
/// pages: Iterable[tuple[str, str]],
/// ) -> LayoutObj[UiResult]:
/// """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(),
}; };
#[cfg(test)] #[cfg(test)]

View File

@ -539,6 +539,29 @@ impl UIFeaturesFirmware for ModelTTFeatures {
Ok(obj) Ok(obj)
} }
fn show_remaining_shares(
pages_iterable: crate::micropython::obj::Obj, // TODO: replace Obj
) -> Result<impl LayoutMaybeTrace, Error> {
let mut paragraphs = ParagraphVecLong::new();
for page in crate::micropython::iter::IterBuf::new().try_iterate(pages_iterable)? {
let [title, description]: [TString; 2] =
crate::micropython::util::iter_into_array(page)?;
paragraphs
.add(Paragraph::new(&theme::TEXT_DEMIBOLD, title))
.add(Paragraph::new(&theme::TEXT_NORMAL, description).break_after());
}
let layout = RootComponent::new(Frame::left_aligned(
theme::label_title(),
TR::recovery__title_remaining_shares.into(),
ButtonPage::new(paragraphs.into_paragraphs(), theme::BG)
.with_cancel_confirm(None, Some(TR::buttons__continue.into()))
.with_confirm_style(theme::button_default())
.without_cancel(),
));
Ok(layout)
}
fn show_wait_text(text: TString<'static>) -> Result<impl LayoutMaybeTrace, Error> { fn show_wait_text(text: TString<'static>) -> Result<impl LayoutMaybeTrace, Error> {
let layout = RootComponent::new(Connect::new(text, theme::FG, theme::BG)); let layout = RootComponent::new(Connect::new(text, theme::FG, theme::BG));
Ok(layout) Ok(layout)

View File

@ -1,4 +1,4 @@
use crate::{error::Error, io::BinaryData, micropython::gc::Gc, strutil::TString}; use crate::{error::Error, io::BinaryData, micropython::{gc::Gc, obj::Obj}, strutil::TString};
use super::layout::{ use super::layout::{
obj::{LayoutMaybeTrace, LayoutObj}, obj::{LayoutMaybeTrace, LayoutObj},
@ -142,6 +142,10 @@ pub trait UIFeaturesFirmware {
skip_first_paint: bool, skip_first_paint: bool,
) -> Result<Gc<LayoutObj>, Error>; // TODO: return LayoutMaybeTrace ) -> Result<Gc<LayoutObj>, Error>; // TODO: return LayoutMaybeTrace
fn show_remaining_shares(
pages_iterable: Obj, // TODO: replace Obj
) -> Result<impl LayoutMaybeTrace, Error>;
fn show_wait_text(text: TString<'static>) -> Result<impl LayoutMaybeTrace, Error>; fn show_wait_text(text: TString<'static>) -> Result<impl LayoutMaybeTrace, Error>;
fn tutorial() -> Result<impl LayoutMaybeTrace, Error>; fn tutorial() -> Result<impl LayoutMaybeTrace, Error>;

View File

@ -727,11 +727,3 @@ def confirm_recovery(
show_instructions: bool = False, # unused on TT show_instructions: bool = False, # unused on TT
) -> LayoutObj[UiResult]: ) -> LayoutObj[UiResult]:
"""Device recovery homescreen.""" """Device recovery homescreen."""
# rust/src/ui/model_tt/layout.rs
def show_remaining_shares(
*,
pages: Iterable[tuple[str, str]],
) -> LayoutObj[UiResult]:
"""Shows SLIP39 state after info button is pressed on `confirm_recovery`."""

View File

@ -315,6 +315,14 @@ def show_progress_coinjoin(
time_ms timeout is passed.""" time_ms timeout is passed."""
# rust/src/ui/api/firmware_upy.rs
def show_remaining_shares(
*,
pages: Iterable[tuple[str, str]],
) -> LayoutObj[UiResult]:
"""Shows SLIP39 state after info button is pressed on `confirm_recovery`."""
# rust/src/ui/api/firmware_upy.rs # rust/src/ui/api/firmware_upy.rs
def show_wait_text(message: str, /) -> LayoutObj[None]: def show_wait_text(message: str, /) -> LayoutObj[None]:
"""Show single-line text in the middle of the screen.""" """Show single-line text in the middle of the screen."""

View File

@ -82,7 +82,7 @@ def show_remaining_shares(
pages.append((title, words)) pages.append((title, words))
return interact( return interact(
trezorui2.show_remaining_shares(pages=pages), trezorui_api.show_remaining_shares(pages=pages),
"show_shares", "show_shares",
ButtonRequestType.Other, ButtonRequestType.Other,
) )