refactor(core/rust/ui): add should_show_more

[no changelog]
pull/2496/head
Martin Milata 2 years ago
parent a5cff25209
commit 885ae2a943

@ -23,10 +23,10 @@ static void _librust_qstrs(void) {
MP_QSTR_confirm_modify_fee;
MP_QSTR_confirm_modify_output;
MP_QSTR_confirm_output;
MP_QSTR_confirm_payment_request;
MP_QSTR_confirm_reset_device;
MP_QSTR_confirm_text;
MP_QSTR_confirm_total;
MP_QSTR_confirm_with_info;
MP_QSTR_show_checklist;
MP_QSTR_show_error;
MP_QSTR_show_qr;
@ -84,4 +84,5 @@ static void _librust_qstrs(void) {
MP_QSTR_max_count;
MP_QSTR_items;
MP_QSTR_active;
MP_QSTR_info_button;
}

@ -610,29 +610,27 @@ extern "C" fn new_show_simple(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_confirm_payment_request(
n_args: usize,
args: *const Obj,
kwargs: *mut Map,
) -> Obj {
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 description: StrBuffer = kwargs.get(Qstr::MP_QSTR_description)?.try_into()?;
let memos: Obj = kwargs.get(Qstr::MP_QSTR_memos)?;
let title: StrBuffer = kwargs.get(Qstr::MP_QSTR_title)?.try_into()?;
let button: StrBuffer = kwargs.get(Qstr::MP_QSTR_button)?.try_into()?;
let info_button: StrBuffer = kwargs.get(Qstr::MP_QSTR_info_button)?.try_into()?;
let items: Obj = kwargs.get(Qstr::MP_QSTR_items)?;
let mut paragraphs = Paragraphs::new().add(theme::TEXT_NORMAL, description);
let mut paragraphs = Paragraphs::new();
let mut iter_buf = IterBuf::new();
let iter = Iter::try_from_obj_with_buf(memos, &mut iter_buf)?;
for memo in iter {
let text: StrBuffer = memo.try_into()?;
let iter = Iter::try_from_obj_with_buf(items, &mut iter_buf)?;
for text in iter {
let text: StrBuffer = text.try_into()?;
paragraphs = paragraphs.add(theme::TEXT_NORMAL, text);
}
let buttons = Button::cancel_info_confirm("CONFIRM", "DETAILS");
let buttons = Button::cancel_info_confirm(button, info_button);
let obj = LayoutObj::new(
Frame::new(
"SENDING",
title,
SwipePage::new(paragraphs, buttons, theme::BG).with_button_rows(2),
)
.into_child(),
@ -988,13 +986,15 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// """Simple dialog with text and one button."""
Qstr::MP_QSTR_show_simple => obj_fn_kw!(0, new_show_simple).as_obj(),
/// def confirm_payment_request(
/// def confirm_with_info(
/// *,
/// description: str,
/// memos: Iterable[str],
/// title: str,
/// button: str,
/// info_button: str,
/// items: Iterable[str],
/// ) -> object:
/// """Confirm payment request."""
Qstr::MP_QSTR_confirm_payment_request => obj_fn_kw!(0, new_confirm_payment_request).as_obj(),
/// """Confirm action but with third button."""
Qstr::MP_QSTR_confirm_with_info => obj_fn_kw!(0, new_confirm_with_info).as_obj(),
/// def confirm_coinjoin(
/// *,

@ -210,12 +210,14 @@ def show_simple(
# rust/src/ui/model_tt/layout.rs
def confirm_payment_request(
def confirm_with_info(
*,
description: str,
memos: Iterable[str],
title: str,
button: str,
info_button: str,
items: Iterable[str],
) -> object:
"""Confirm payment request."""
"""Confirm action but with third button."""
# rust/src/ui/model_tt/layout.rs

@ -526,9 +526,11 @@ async def confirm_payment_request(
result = await interact(
ctx,
_RustLayout(
trezorui2.confirm_payment_request(
description=f"{amount} to\n{recipient_name}",
memos=memos,
trezorui2.confirm_with_info(
title="SENDING",
items=[f"{amount} to\n{recipient_name}"] + memos,
button="CONFIRM",
info_button="DETAILS",
)
),
"confirm_payment_request",
@ -554,7 +556,39 @@ async def should_show_more(
confirm: str | bytes | None = None,
major_confirm: bool = False,
) -> bool:
raise NotImplementedError
"""Return True if the user wants to show more (they click a special button)
and False when the user wants to continue without showing details.
Raises ActionCancelled if the user cancels.
"""
if confirm is None or not isinstance(confirm, str):
confirm = "CONFIRM"
items = []
for _font, text in para:
items.append(text)
result = await interact(
ctx,
_RustLayout(
trezorui2.confirm_with_info(
title=title.upper(),
items=items,
button=confirm.upper(),
info_button=button_text.upper(),
)
),
br_type,
br_code,
)
if result is trezorui2.CONFIRMED:
return False
elif result is trezorui2.INFO:
return True
else:
assert result is trezorui2.CANCELLED
raise wire.ActionCancelled
async def confirm_blob(

Loading…
Cancel
Save