mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-29 02:48:18 +00:00
refactor(core): move confirm_more
- not implemented for mercury
This commit is contained in:
parent
48f1964ec0
commit
c8d7168b06
@ -233,6 +233,20 @@ extern "C" fn new_confirm_modify_output(n_args: usize, args: *const Obj, kwargs:
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_confirm_more(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 button_style_confirm: bool =
|
||||
kwargs.get_or(Qstr::MP_QSTR_button_style_confirm, false)?;
|
||||
let items: Obj = kwargs.get(Qstr::MP_QSTR_items)?;
|
||||
|
||||
let layout = ModelUI::confirm_more(title, button, button_style_confirm, items)?;
|
||||
Ok(LayoutObj::new_root(layout)?.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()?;
|
||||
@ -949,6 +963,17 @@ pub static mp_module_trezorui_api: Module = obj_module! {
|
||||
/// """Decrease or increase output amount."""
|
||||
Qstr::MP_QSTR_confirm_modify_output => obj_fn_kw!(0, new_confirm_modify_output).as_obj(),
|
||||
|
||||
/// def confirm_more(
|
||||
/// *,
|
||||
/// title: str,
|
||||
/// button: str,
|
||||
/// button_style_confirm: bool = False,
|
||||
/// items: Iterable[tuple[int, str | bytes]],
|
||||
/// ) -> LayoutObj[UiResult]:
|
||||
/// """Confirm long content with the possibility to go back from any page.
|
||||
/// Meant to be used with confirm_with_info on model TT and TR."""
|
||||
Qstr::MP_QSTR_confirm_more => obj_fn_kw!(0, new_confirm_more).as_obj(),
|
||||
|
||||
/// def confirm_properties(
|
||||
/// *,
|
||||
/// title: str,
|
||||
|
@ -495,31 +495,6 @@ extern "C" fn new_confirm_total(n_args: usize, args: *const Obj, kwargs: *mut Ma
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_confirm_more(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 items: Obj = kwargs.get(Qstr::MP_QSTR_items)?;
|
||||
|
||||
let mut paragraphs = ParagraphVecLong::new();
|
||||
|
||||
for para in IterBuf::new().try_iterate(items)? {
|
||||
let [font, text]: [Obj; 2] = util::iter_into_array(para)?;
|
||||
let style: &TextStyle = theme::textstyle_number(font.try_into()?);
|
||||
let text: TString = text.try_into()?;
|
||||
paragraphs.add(Paragraph::new(style, text));
|
||||
}
|
||||
|
||||
let obj = LayoutObj::new(SwipeUpScreen::new(
|
||||
Frame::left_aligned(title, SwipeContent::new(paragraphs.into_paragraphs()))
|
||||
.with_cancel_button()
|
||||
.with_footer(TR::instructions__swipe_up.into(), None)
|
||||
.with_swipe(Direction::Up, SwipeSettings::default()),
|
||||
))?;
|
||||
Ok(obj.into())
|
||||
};
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_get_address(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()?;
|
||||
@ -630,16 +605,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 confirm_more(
|
||||
/// *,
|
||||
/// title: str,
|
||||
/// button: str,
|
||||
/// items: Iterable[tuple[int, str]],
|
||||
/// ) -> LayoutObj[UiResult]:
|
||||
/// """Confirm long content with the possibility to go back from any page.
|
||||
/// Meant to be used with confirm_with_info."""
|
||||
Qstr::MP_QSTR_confirm_more => obj_fn_kw!(0, new_confirm_more).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(),
|
||||
|
@ -269,6 +269,17 @@ impl UIFeaturesFirmware for ModelMercuryFeatures {
|
||||
Ok(layout)
|
||||
}
|
||||
|
||||
fn confirm_more(
|
||||
_title: TString<'static>,
|
||||
_button: TString<'static>,
|
||||
_button_style_confirm: bool,
|
||||
_items: Obj,
|
||||
) -> Result<impl LayoutMaybeTrace, Error> {
|
||||
Err::<RootComponent<Empty, ModelMercuryFeatures>, Error>(Error::ValueError(
|
||||
c"confirm_more not implemented",
|
||||
))
|
||||
}
|
||||
|
||||
fn confirm_reset_device(recovery: bool) -> Result<impl LayoutMaybeTrace, Error> {
|
||||
let flow = flow::confirm_reset::new_confirm_reset(recovery)?;
|
||||
Ok(flow)
|
||||
|
@ -648,32 +648,6 @@ extern "C" fn new_multiple_pages_texts(n_args: usize, args: *const Obj, kwargs:
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_confirm_more(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 items: Obj = kwargs.get(Qstr::MP_QSTR_items)?;
|
||||
|
||||
let mut paragraphs = ParagraphVecLong::new();
|
||||
|
||||
for para in IterBuf::new().try_iterate(items)? {
|
||||
let [font, text]: [Obj; 2] = util::iter_into_array(para)?;
|
||||
let style: &TextStyle = theme::textstyle_number(font.try_into()?);
|
||||
let text: TString = text.try_into()?;
|
||||
paragraphs.add(Paragraph::new(style, text));
|
||||
}
|
||||
|
||||
content_in_button_page(
|
||||
title,
|
||||
paragraphs.into_paragraphs(),
|
||||
button,
|
||||
Some("<".into()),
|
||||
false,
|
||||
)
|
||||
};
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub static mp_module_trezorui2: Module = obj_module! {
|
||||
/// from trezor import utils
|
||||
@ -767,14 +741,4 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
||||
/// ) -> LayoutObj[UiResult]:
|
||||
/// """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 confirm_more(
|
||||
/// *,
|
||||
/// title: str,
|
||||
/// button: str,
|
||||
/// items: Iterable[tuple[int, str | bytes]],
|
||||
/// ) -> object:
|
||||
/// """Confirm long content with the possibility to go back from any page.
|
||||
/// Meant to be used with confirm_with_info."""
|
||||
Qstr::MP_QSTR_confirm_more => obj_fn_kw!(0, new_confirm_more).as_obj(),
|
||||
};
|
||||
|
@ -311,6 +311,30 @@ impl UIFeaturesFirmware for ModelTRFeatures {
|
||||
)
|
||||
}
|
||||
|
||||
fn confirm_more(
|
||||
title: TString<'static>,
|
||||
button: TString<'static>,
|
||||
_button_style_confirm: bool,
|
||||
items: Obj,
|
||||
) -> Result<impl LayoutMaybeTrace, Error> {
|
||||
let mut paragraphs = ParagraphVecLong::new();
|
||||
|
||||
for para in IterBuf::new().try_iterate(items)? {
|
||||
let [font, text]: [Obj; 2] = util::iter_into_array(para)?;
|
||||
let style: &TextStyle = theme::textstyle_number(font.try_into()?);
|
||||
let text: TString = text.try_into()?;
|
||||
paragraphs.add(Paragraph::new(style, text));
|
||||
}
|
||||
|
||||
content_in_button_page(
|
||||
title,
|
||||
paragraphs.into_paragraphs(),
|
||||
button,
|
||||
Some("<".into()),
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
fn confirm_properties(
|
||||
title: TString<'static>,
|
||||
items: Obj,
|
||||
|
@ -457,40 +457,6 @@ extern "C" fn new_confirm_total(n_args: usize, args: *const Obj, kwargs: *mut Ma
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_confirm_more(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 button_style_confirm: bool =
|
||||
kwargs.get_or(Qstr::MP_QSTR_button_style_confirm, false)?;
|
||||
let items: Obj = kwargs.get(Qstr::MP_QSTR_items)?;
|
||||
|
||||
let mut paragraphs = ParagraphVecLong::new();
|
||||
|
||||
for para in IterBuf::new().try_iterate(items)? {
|
||||
let [font, text]: [Obj; 2] = util::iter_into_array(para)?;
|
||||
let style: &TextStyle = theme::textstyle_number(font.try_into()?);
|
||||
let text: TString = text.try_into()?;
|
||||
paragraphs.add(Paragraph::new(style, text));
|
||||
}
|
||||
|
||||
let obj = LayoutObj::new(Frame::left_aligned(
|
||||
theme::label_title(),
|
||||
title,
|
||||
ButtonPage::new(paragraphs.into_paragraphs(), theme::BG)
|
||||
.with_cancel_confirm(None, Some(button))
|
||||
.with_confirm_style(if button_style_confirm {
|
||||
theme::button_confirm()
|
||||
} else {
|
||||
theme::button_default()
|
||||
})
|
||||
.with_back_button(),
|
||||
))?;
|
||||
Ok(obj.into())
|
||||
};
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub static mp_module_trezorui2: Module = obj_module! {
|
||||
/// from trezor import utils
|
||||
@ -542,17 +508,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
||||
/// ) -> LayoutObj[UiResult]:
|
||||
/// """Transaction summary. Always hold to confirm."""
|
||||
Qstr::MP_QSTR_confirm_total => obj_fn_kw!(0, new_confirm_total).as_obj(),
|
||||
|
||||
/// def confirm_more(
|
||||
/// *,
|
||||
/// title: str,
|
||||
/// button: str,
|
||||
/// button_style_confirm: bool = False,
|
||||
/// items: Iterable[tuple[int, str | bytes]],
|
||||
/// ) -> LayoutObj[UiResult]:
|
||||
/// """Confirm long content with the possibility to go back from any page.
|
||||
/// Meant to be used with confirm_with_info."""
|
||||
Qstr::MP_QSTR_confirm_more => obj_fn_kw!(0, new_confirm_more).as_obj(),
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -270,6 +270,36 @@ impl UIFeaturesFirmware for ModelTTFeatures {
|
||||
Ok(layout)
|
||||
}
|
||||
|
||||
fn confirm_more(
|
||||
title: TString<'static>,
|
||||
button: TString<'static>,
|
||||
button_style_confirm: bool,
|
||||
items: Obj,
|
||||
) -> Result<impl LayoutMaybeTrace, Error> {
|
||||
let mut paragraphs = ParagraphVecLong::new();
|
||||
|
||||
for para in IterBuf::new().try_iterate(items)? {
|
||||
let [font, text]: [Obj; 2] = util::iter_into_array(para)?;
|
||||
let style: &TextStyle = theme::textstyle_number(font.try_into()?);
|
||||
let text: TString = text.try_into()?;
|
||||
paragraphs.add(Paragraph::new(style, text));
|
||||
}
|
||||
|
||||
let layout = RootComponent::new(Frame::left_aligned(
|
||||
theme::label_title(),
|
||||
title,
|
||||
ButtonPage::new(paragraphs.into_paragraphs(), theme::BG)
|
||||
.with_cancel_confirm(None, Some(button))
|
||||
.with_confirm_style(if button_style_confirm {
|
||||
theme::button_confirm()
|
||||
} else {
|
||||
theme::button_default()
|
||||
})
|
||||
.with_back_button(),
|
||||
));
|
||||
Ok(layout)
|
||||
}
|
||||
|
||||
fn confirm_properties(
|
||||
title: TString<'static>,
|
||||
items: Obj,
|
||||
|
@ -79,6 +79,13 @@ pub trait UIFeaturesFirmware {
|
||||
amount_new: TString<'static>,
|
||||
) -> Result<impl LayoutMaybeTrace, Error>;
|
||||
|
||||
fn confirm_more(
|
||||
title: TString<'static>,
|
||||
button: TString<'static>,
|
||||
button_style_confirm: bool,
|
||||
items: Obj, // TODO: replace Obj
|
||||
) -> Result<impl LayoutMaybeTrace, Error>;
|
||||
|
||||
fn confirm_properties(
|
||||
title: TString<'static>,
|
||||
items: Obj, // TODO: replace Obj`
|
||||
|
@ -48,17 +48,6 @@ def confirm_total(
|
||||
"""Transaction summary. Always hold to confirm."""
|
||||
|
||||
|
||||
# rust/src/ui/model_mercury/layout.rs
|
||||
def confirm_more(
|
||||
*,
|
||||
title: str,
|
||||
button: str,
|
||||
items: Iterable[tuple[int, str]],
|
||||
) -> LayoutObj[UiResult]:
|
||||
"""Confirm long content with the possibility to go back from any page.
|
||||
Meant to be used with confirm_with_info."""
|
||||
|
||||
|
||||
# rust/src/ui/model_mercury/layout.rs
|
||||
def flow_prompt_backup() -> LayoutObj[UiResult]:
|
||||
"""Prompt a user to create backup with an option to skip."""
|
||||
@ -231,17 +220,6 @@ def multiple_pages_texts(
|
||||
items: list[str],
|
||||
) -> LayoutObj[UiResult]:
|
||||
"""Show multiple texts, each on its own page."""
|
||||
|
||||
|
||||
# rust/src/ui/model_tr/layout.rs
|
||||
def confirm_more(
|
||||
*,
|
||||
title: str,
|
||||
button: str,
|
||||
items: Iterable[tuple[int, str | bytes]],
|
||||
) -> object:
|
||||
"""Confirm long content with the possibility to go back from any page.
|
||||
Meant to be used with confirm_with_info."""
|
||||
from trezor import utils
|
||||
from trezorui_api import *
|
||||
|
||||
@ -294,15 +272,3 @@ def confirm_total(
|
||||
cancel_arrow: bool = False,
|
||||
) -> LayoutObj[UiResult]:
|
||||
"""Transaction summary. Always hold to confirm."""
|
||||
|
||||
|
||||
# rust/src/ui/model_tt/layout.rs
|
||||
def confirm_more(
|
||||
*,
|
||||
title: str,
|
||||
button: str,
|
||||
button_style_confirm: bool = False,
|
||||
items: Iterable[tuple[int, str | bytes]],
|
||||
) -> LayoutObj[UiResult]:
|
||||
"""Confirm long content with the possibility to go back from any page.
|
||||
Meant to be used with confirm_with_info."""
|
||||
|
@ -179,6 +179,18 @@ def confirm_modify_output(
|
||||
"""Decrease or increase output amount."""
|
||||
|
||||
|
||||
# rust/src/ui/api/firmware_upy.rs
|
||||
def confirm_more(
|
||||
*,
|
||||
title: str,
|
||||
button: str,
|
||||
button_style_confirm: bool = False,
|
||||
items: Iterable[tuple[int, str | bytes]],
|
||||
) -> LayoutObj[UiResult]:
|
||||
"""Confirm long content with the possibility to go back from any page.
|
||||
Meant to be used with confirm_with_info on model TT and TR."""
|
||||
|
||||
|
||||
# rust/src/ui/api/firmware_upy.rs
|
||||
def confirm_properties(
|
||||
*,
|
||||
|
@ -591,7 +591,7 @@ async def _confirm_ask_pagination(
|
||||
|
||||
data = hexlify(data).decode()
|
||||
|
||||
confirm_more_layout = trezorui2.confirm_more(
|
||||
confirm_more_layout = trezorui_api.confirm_more(
|
||||
title=title,
|
||||
button="GO BACK",
|
||||
items=[(ui.BOLD_UPPER, f"Size: {len(data)} bytes"), (ui.MONO, data)],
|
||||
|
@ -519,7 +519,7 @@ async def _confirm_ask_pagination(
|
||||
|
||||
data = hexlify(data).decode()
|
||||
|
||||
confirm_more_layout = trezorui2.confirm_more(
|
||||
confirm_more_layout = trezorui_api.confirm_more(
|
||||
title=title,
|
||||
button=TR.buttons__confirm,
|
||||
button_style_confirm=True,
|
||||
|
Loading…
Reference in New Issue
Block a user