mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-26 01:18:28 +00:00
refactor(core): move show_info_with_cancel
- not implemented for model_r
This commit is contained in:
parent
926b91cb66
commit
04f6d779e2
@ -430,6 +430,19 @@ extern "C" fn new_show_info(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_info_with_cancel(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 horizontal: bool = kwargs.get_or(Qstr::MP_QSTR_horizontal, false)?;
|
||||
let chunkify: bool = kwargs.get_or(Qstr::MP_QSTR_chunkify, false)?;
|
||||
|
||||
let layout = ModelUI::show_info_with_cancel(title, items, horizontal, chunkify)?;
|
||||
Ok(LayoutObj::new_root(layout)?.into())
|
||||
};
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_show_lockscreen(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
|
||||
let block = move |_args: &[Obj], kwargs: &Map| {
|
||||
let label: TString<'static> = kwargs
|
||||
@ -960,6 +973,16 @@ pub static mp_module_trezorui_api: Module = obj_module! {
|
||||
/// """Info screen."""
|
||||
Qstr::MP_QSTR_show_info => obj_fn_kw!(0, new_show_info).as_obj(),
|
||||
|
||||
/// def show_info_with_cancel(
|
||||
/// *,
|
||||
/// title: str,
|
||||
/// items: Iterable[Tuple[str, str]],
|
||||
/// horizontal: bool = False,
|
||||
/// chunkify: bool = False,
|
||||
/// ) -> LayoutObj[UiResult]:
|
||||
/// """Show metadata for outgoing transaction."""
|
||||
Qstr::MP_QSTR_show_info_with_cancel => obj_fn_kw!(0, new_show_info_with_cancel).as_obj(),
|
||||
|
||||
/// def show_lockscreen(
|
||||
/// *,
|
||||
/// label: str | None,
|
||||
|
@ -562,39 +562,6 @@ extern "C" fn new_confirm_summary(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_info_with_cancel(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 _horizontal: bool = kwargs.get_or(Qstr::MP_QSTR_horizontal, false)?; // FIXME
|
||||
let chunkify: bool = kwargs.get_or(Qstr::MP_QSTR_chunkify, false)?;
|
||||
|
||||
let mut paragraphs = ParagraphVecShort::new();
|
||||
|
||||
for para in IterBuf::new().try_iterate(items)? {
|
||||
let [key, value]: [Obj; 2] = util::iter_into_array(para)?;
|
||||
let key: TString = key.try_into()?;
|
||||
let value: TString = value.try_into()?;
|
||||
paragraphs.add(Paragraph::new(&theme::TEXT_NORMAL, key).no_break());
|
||||
if chunkify {
|
||||
paragraphs.add(Paragraph::new(
|
||||
theme::get_chunkified_text_style(value.len()),
|
||||
value,
|
||||
));
|
||||
} else {
|
||||
paragraphs.add(Paragraph::new(&theme::TEXT_MONO, value));
|
||||
}
|
||||
}
|
||||
|
||||
let obj = LayoutObj::new(SwipeUpScreen::new(
|
||||
Frame::left_aligned(title, SwipeContent::new(paragraphs.into_paragraphs()))
|
||||
.with_cancel_button(),
|
||||
))?;
|
||||
Ok(obj.into())
|
||||
};
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_confirm_value(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()?;
|
||||
@ -813,16 +780,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
||||
/// """Confirm new PIN setup with an option to cancel action."""
|
||||
Qstr::MP_QSTR_flow_confirm_set_new_pin => obj_fn_kw!(0, new_confirm_set_new_pin).as_obj(),
|
||||
|
||||
/// def show_info_with_cancel(
|
||||
/// *,
|
||||
/// title: str,
|
||||
/// items: Iterable[Tuple[str, str]],
|
||||
/// horizontal: bool = False,
|
||||
/// chunkify: bool = False,
|
||||
/// ) -> LayoutObj[UiResult]:
|
||||
/// """Show metadata for outgoing transaction."""
|
||||
Qstr::MP_QSTR_show_info_with_cancel => obj_fn_kw!(0, new_show_info_with_cancel).as_obj(),
|
||||
|
||||
/// def confirm_value(
|
||||
/// *,
|
||||
/// title: str,
|
||||
|
@ -505,6 +505,36 @@ impl UIFeaturesFirmware for ModelMercuryFeatures {
|
||||
Ok(obj)
|
||||
}
|
||||
|
||||
fn show_info_with_cancel(
|
||||
title: TString<'static>,
|
||||
items: Obj,
|
||||
_horizontal: bool,
|
||||
chunkify: bool,
|
||||
) -> Result<impl LayoutMaybeTrace, Error> {
|
||||
let mut paragraphs = ParagraphVecShort::new();
|
||||
|
||||
for para in IterBuf::new().try_iterate(items)? {
|
||||
let [key, value]: [Obj; 2] = util::iter_into_array(para)?;
|
||||
let key: TString = key.try_into()?;
|
||||
let value: TString = value.try_into()?;
|
||||
paragraphs.add(Paragraph::new(&theme::TEXT_NORMAL, key).no_break());
|
||||
if chunkify {
|
||||
paragraphs.add(Paragraph::new(
|
||||
theme::get_chunkified_text_style(value.len()),
|
||||
value,
|
||||
));
|
||||
} else {
|
||||
paragraphs.add(Paragraph::new(&theme::TEXT_MONO, value));
|
||||
}
|
||||
}
|
||||
|
||||
let layout = RootComponent::new(SwipeUpScreen::new(
|
||||
Frame::left_aligned(title, SwipeContent::new(paragraphs.into_paragraphs()))
|
||||
.with_cancel_button(),
|
||||
));
|
||||
Ok(layout)
|
||||
}
|
||||
|
||||
fn show_lockscreen(
|
||||
label: TString<'static>,
|
||||
bootscreen: bool,
|
||||
|
@ -570,6 +570,17 @@ impl UIFeaturesFirmware for ModelTRFeatures {
|
||||
Ok(obj)
|
||||
}
|
||||
|
||||
fn show_info_with_cancel(
|
||||
_title: TString<'static>,
|
||||
_items: Obj,
|
||||
_horizontal: bool,
|
||||
_chunkify: bool,
|
||||
) -> Result<impl LayoutMaybeTrace, Error> {
|
||||
Err::<RootComponent<Empty, ModelTRFeatures>, Error>(Error::ValueError(
|
||||
c"show_info_with_cancel not supported",
|
||||
))
|
||||
}
|
||||
|
||||
fn show_lockscreen(
|
||||
label: TString<'static>,
|
||||
bootscreen: bool,
|
||||
|
@ -597,49 +597,6 @@ extern "C" fn new_show_address_details(n_args: usize, args: *const Obj, kwargs:
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_show_info_with_cancel(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 horizontal: bool = kwargs.get_or(Qstr::MP_QSTR_horizontal, false)?;
|
||||
let chunkify: bool = kwargs.get_or(Qstr::MP_QSTR_chunkify, false)?;
|
||||
|
||||
let mut paragraphs = ParagraphVecShort::new();
|
||||
|
||||
for para in IterBuf::new().try_iterate(items)? {
|
||||
let [key, value]: [Obj; 2] = util::iter_into_array(para)?;
|
||||
let key: TString = key.try_into()?;
|
||||
let value: TString = value.try_into()?;
|
||||
paragraphs.add(Paragraph::new(&theme::TEXT_NORMAL, key).no_break());
|
||||
if chunkify {
|
||||
paragraphs.add(Paragraph::new(
|
||||
theme::get_chunkified_text_style(value.len()),
|
||||
value,
|
||||
));
|
||||
} else {
|
||||
paragraphs.add(Paragraph::new(&theme::TEXT_MONO, value));
|
||||
}
|
||||
}
|
||||
|
||||
let axis = match horizontal {
|
||||
true => geometry::Axis::Horizontal,
|
||||
_ => geometry::Axis::Vertical,
|
||||
};
|
||||
|
||||
let obj = LayoutObj::new(
|
||||
Frame::left_aligned(
|
||||
theme::label_title(),
|
||||
title,
|
||||
SimplePage::new(paragraphs.into_paragraphs(), axis, theme::BG)
|
||||
.with_swipe_right_to_go_back(),
|
||||
)
|
||||
.with_cancel_button(),
|
||||
)?;
|
||||
Ok(obj.into())
|
||||
};
|
||||
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||
}
|
||||
|
||||
extern "C" fn new_confirm_value(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()?;
|
||||
@ -808,16 +765,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
||||
/// """Show address details - QR code, account, path, cosigner xpubs."""
|
||||
Qstr::MP_QSTR_show_address_details => obj_fn_kw!(0, new_show_address_details).as_obj(),
|
||||
|
||||
/// def show_info_with_cancel(
|
||||
/// *,
|
||||
/// title: str,
|
||||
/// items: Iterable[Tuple[str, str]],
|
||||
/// horizontal: bool = False,
|
||||
/// chunkify: bool = False,
|
||||
/// ) -> LayoutObj[UiResult]:
|
||||
/// """Show metadata for outgoing transaction."""
|
||||
Qstr::MP_QSTR_show_info_with_cancel => obj_fn_kw!(0, new_show_info_with_cancel).as_obj(),
|
||||
|
||||
/// def confirm_value(
|
||||
/// *,
|
||||
/// title: str,
|
||||
|
@ -19,6 +19,7 @@ use crate::{
|
||||
},
|
||||
Border, ComponentExt, Empty, Jpeg, Label, Never, Timeout,
|
||||
},
|
||||
geometry,
|
||||
layout::{
|
||||
obj::{LayoutMaybeTrace, LayoutObj, RootComponent},
|
||||
util::RecoveryType,
|
||||
@ -32,7 +33,7 @@ use super::{
|
||||
check_homescreen_format, Bip39Input, Button, ButtonMsg, ButtonPage, ButtonStyleSheet,
|
||||
CancelConfirmMsg, CoinJoinProgress, Dialog, FidoConfirm, Frame, Homescreen, IconDialog,
|
||||
Lockscreen, MnemonicKeyboard, NumberInputDialog, PassphraseKeyboard, PinKeyboard, Progress,
|
||||
SelectWordCount, SetBrightnessDialog, ShareWords, Slip39Input,
|
||||
SelectWordCount, SetBrightnessDialog, ShareWords, SimplePage, Slip39Input,
|
||||
},
|
||||
theme, ModelTTFeatures,
|
||||
};
|
||||
@ -588,6 +589,46 @@ impl UIFeaturesFirmware for ModelTTFeatures {
|
||||
)
|
||||
}
|
||||
|
||||
fn show_info_with_cancel(
|
||||
title: TString<'static>,
|
||||
items: Obj,
|
||||
horizontal: bool,
|
||||
chunkify: bool,
|
||||
) -> Result<impl LayoutMaybeTrace, Error> {
|
||||
let mut paragraphs = ParagraphVecShort::new();
|
||||
|
||||
for para in IterBuf::new().try_iterate(items)? {
|
||||
let [key, value]: [Obj; 2] = util::iter_into_array(para)?;
|
||||
let key: TString = key.try_into()?;
|
||||
let value: TString = value.try_into()?;
|
||||
paragraphs.add(Paragraph::new(&theme::TEXT_NORMAL, key).no_break());
|
||||
if chunkify {
|
||||
paragraphs.add(Paragraph::new(
|
||||
theme::get_chunkified_text_style(value.len()),
|
||||
value,
|
||||
));
|
||||
} else {
|
||||
paragraphs.add(Paragraph::new(&theme::TEXT_MONO, value));
|
||||
}
|
||||
}
|
||||
|
||||
let axis = match horizontal {
|
||||
true => geometry::Axis::Horizontal,
|
||||
_ => geometry::Axis::Vertical,
|
||||
};
|
||||
|
||||
let layout = RootComponent::new(
|
||||
Frame::left_aligned(
|
||||
theme::label_title(),
|
||||
title,
|
||||
SimplePage::new(paragraphs.into_paragraphs(), axis, theme::BG)
|
||||
.with_swipe_right_to_go_back(),
|
||||
)
|
||||
.with_cancel_button(),
|
||||
);
|
||||
Ok(layout)
|
||||
}
|
||||
|
||||
fn show_lockscreen(
|
||||
label: TString<'static>,
|
||||
bootscreen: bool,
|
||||
|
@ -159,6 +159,13 @@ pub trait UIFeaturesFirmware {
|
||||
time_ms: u32,
|
||||
) -> Result<Gc<LayoutObj>, Error>; // TODO: return LayoutMaybeTrace
|
||||
|
||||
fn show_info_with_cancel(
|
||||
title: TString<'static>,
|
||||
items: Obj, // TODO: replace Obj
|
||||
horizontal: bool,
|
||||
chunkify: bool,
|
||||
) -> Result<impl LayoutMaybeTrace, Error>;
|
||||
|
||||
fn show_lockscreen(
|
||||
label: TString<'static>,
|
||||
bootscreen: bool,
|
||||
|
@ -69,17 +69,6 @@ def flow_confirm_set_new_pin(
|
||||
"""Confirm new PIN setup with an option to cancel action."""
|
||||
|
||||
|
||||
# rust/src/ui/model_mercury/layout.rs
|
||||
def show_info_with_cancel(
|
||||
*,
|
||||
title: str,
|
||||
items: Iterable[Tuple[str, str]],
|
||||
horizontal: bool = False,
|
||||
chunkify: bool = False,
|
||||
) -> LayoutObj[UiResult]:
|
||||
"""Show metadata for outgoing transaction."""
|
||||
|
||||
|
||||
# rust/src/ui/model_mercury/layout.rs
|
||||
def confirm_value(
|
||||
*,
|
||||
@ -422,17 +411,6 @@ def show_address_details(
|
||||
"""Show address details - QR code, account, path, cosigner xpubs."""
|
||||
|
||||
|
||||
# rust/src/ui/model_tt/layout.rs
|
||||
def show_info_with_cancel(
|
||||
*,
|
||||
title: str,
|
||||
items: Iterable[Tuple[str, str]],
|
||||
horizontal: bool = False,
|
||||
chunkify: bool = False,
|
||||
) -> LayoutObj[UiResult]:
|
||||
"""Show metadata for outgoing transaction."""
|
||||
|
||||
|
||||
# rust/src/ui/model_tt/layout.rs
|
||||
def confirm_value(
|
||||
*,
|
||||
|
@ -327,6 +327,17 @@ def show_info(
|
||||
"""Info screen."""
|
||||
|
||||
|
||||
# rust/src/ui/api/firmware_upy.rs
|
||||
def show_info_with_cancel(
|
||||
*,
|
||||
title: str,
|
||||
items: Iterable[Tuple[str, str]],
|
||||
horizontal: bool = False,
|
||||
chunkify: bool = False,
|
||||
) -> LayoutObj[UiResult]:
|
||||
"""Show metadata for outgoing transaction."""
|
||||
|
||||
|
||||
# rust/src/ui/api/firmware_upy.rs
|
||||
def show_lockscreen(
|
||||
*,
|
||||
|
@ -601,7 +601,7 @@ def confirm_value(
|
||||
raise ValueError("Either verb or hold=True must be set")
|
||||
|
||||
info_items = info_items or []
|
||||
info_layout = trezorui2.show_info_with_cancel(
|
||||
info_layout = trezorui_api.show_info_with_cancel(
|
||||
title=info_title if info_title else TR.words__title_information,
|
||||
items=info_items,
|
||||
chunkify=chunkify_info,
|
||||
@ -958,7 +958,7 @@ def confirm_modify_fee(
|
||||
items: list[tuple[str, str]] = []
|
||||
if fee_rate_amount:
|
||||
items.append((TR.bitcoin__new_fee_rate, fee_rate_amount))
|
||||
info_layout = trezorui2.show_info_with_cancel(
|
||||
info_layout = trezorui_api.show_info_with_cancel(
|
||||
title=TR.confirm_total__title_fee,
|
||||
items=items,
|
||||
)
|
||||
@ -1025,7 +1025,7 @@ async def confirm_signverify(
|
||||
)
|
||||
)
|
||||
|
||||
info_layout = trezorui2.show_info_with_cancel(
|
||||
info_layout = trezorui_api.show_info_with_cancel(
|
||||
title=TR.words__title_information,
|
||||
items=items,
|
||||
horizontal=True,
|
||||
|
@ -659,7 +659,7 @@ def confirm_value(
|
||||
raise ValueError("Either verb or hold=True must be set")
|
||||
|
||||
info_items = info_items or []
|
||||
info_layout = trezorui2.show_info_with_cancel(
|
||||
info_layout = trezorui_api.show_info_with_cancel(
|
||||
title=info_title if info_title else TR.words__title_information,
|
||||
items=info_items,
|
||||
chunkify=chunkify_info,
|
||||
@ -754,7 +754,7 @@ def _confirm_summary(
|
||||
info_button=bool(info_items),
|
||||
)
|
||||
info_items = info_items or []
|
||||
info_layout = trezorui2.show_info_with_cancel(
|
||||
info_layout = trezorui_api.show_info_with_cancel(
|
||||
title=info_title if info_title else TR.words__title_information,
|
||||
items=info_items,
|
||||
)
|
||||
@ -791,7 +791,7 @@ if not utils.BITCOIN_ONLY:
|
||||
info_button=True,
|
||||
cancel_arrow=True,
|
||||
)
|
||||
info_layout = trezorui2.show_info_with_cancel(
|
||||
info_layout = trezorui_api.show_info_with_cancel(
|
||||
title=TR.confirm_total__title_fee,
|
||||
items=[(f"{k}:", v) for (k, v) in fee_info_items],
|
||||
)
|
||||
@ -1003,7 +1003,7 @@ def confirm_modify_fee(
|
||||
items: list[tuple[str, str]] = []
|
||||
if fee_rate_amount:
|
||||
items.append((TR.bitcoin__new_fee_rate, fee_rate_amount))
|
||||
info_layout = trezorui2.show_info_with_cancel(
|
||||
info_layout = trezorui_api.show_info_with_cancel(
|
||||
title=TR.confirm_total__title_fee,
|
||||
items=items,
|
||||
)
|
||||
@ -1070,7 +1070,7 @@ async def confirm_signverify(
|
||||
)
|
||||
)
|
||||
|
||||
info_layout = trezorui2.show_info_with_cancel(
|
||||
info_layout = trezorui_api.show_info_with_cancel(
|
||||
title=TR.words__title_information,
|
||||
items=items,
|
||||
horizontal=True,
|
||||
|
Loading…
Reference in New Issue
Block a user