mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-01 11:58:28 +00:00
WIP - refactoring confirm_total of TT
This commit is contained in:
parent
4306a2b2eb
commit
bdcd81e531
@ -37,6 +37,7 @@ static void _librust_qstrs(void) {
|
|||||||
MP_QSTR___dict__;
|
MP_QSTR___dict__;
|
||||||
MP_QSTR___name__;
|
MP_QSTR___name__;
|
||||||
MP_QSTR_account;
|
MP_QSTR_account;
|
||||||
|
MP_QSTR_account_info;
|
||||||
MP_QSTR_account_items;
|
MP_QSTR_account_items;
|
||||||
MP_QSTR_account_items_title;
|
MP_QSTR_account_items_title;
|
||||||
MP_QSTR_account_label;
|
MP_QSTR_account_label;
|
||||||
@ -72,6 +73,7 @@ static void _librust_qstrs(void) {
|
|||||||
MP_QSTR_altcoin_tx_summary;
|
MP_QSTR_altcoin_tx_summary;
|
||||||
MP_QSTR_amount;
|
MP_QSTR_amount;
|
||||||
MP_QSTR_amount_change;
|
MP_QSTR_amount_change;
|
||||||
|
MP_QSTR_amount_label;
|
||||||
MP_QSTR_amount_new;
|
MP_QSTR_amount_new;
|
||||||
MP_QSTR_amount_title;
|
MP_QSTR_amount_title;
|
||||||
MP_QSTR_amount_value;
|
MP_QSTR_amount_value;
|
||||||
@ -241,7 +243,10 @@ static void _librust_qstrs(void) {
|
|||||||
MP_QSTR_experimental_mode__only_for_dev;
|
MP_QSTR_experimental_mode__only_for_dev;
|
||||||
MP_QSTR_experimental_mode__title;
|
MP_QSTR_experimental_mode__title;
|
||||||
MP_QSTR_extra;
|
MP_QSTR_extra;
|
||||||
|
MP_QSTR_extra_info;
|
||||||
|
MP_QSTR_fee;
|
||||||
MP_QSTR_fee_amount;
|
MP_QSTR_fee_amount;
|
||||||
|
MP_QSTR_fee_info;
|
||||||
MP_QSTR_fee_items;
|
MP_QSTR_fee_items;
|
||||||
MP_QSTR_fee_label;
|
MP_QSTR_fee_label;
|
||||||
MP_QSTR_fee_rate_amount;
|
MP_QSTR_fee_rate_amount;
|
||||||
|
@ -319,18 +319,39 @@ impl ComponentMsgObj for super::component::bl_confirm::Confirm<'_> {
|
|||||||
|
|
||||||
extern "C" fn new_confirm_total(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
|
extern "C" fn new_confirm_total(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
|
||||||
let block = move |_args: &[Obj], kwargs: &Map| {
|
let block = move |_args: &[Obj], kwargs: &Map| {
|
||||||
let title: TString = kwargs.get(Qstr::MP_QSTR_title)?.try_into()?;
|
let amount: TString = kwargs.get(Qstr::MP_QSTR_amount)?.try_into()?;
|
||||||
let items: Obj = kwargs.get(Qstr::MP_QSTR_items)?;
|
let amount_label: TString = kwargs.get(Qstr::MP_QSTR_amount_label)?.try_into()?;
|
||||||
let info_button: bool = kwargs.get_or(Qstr::MP_QSTR_info_button, false)?;
|
let fee: TString = kwargs.get(Qstr::MP_QSTR_fee)?.try_into()?;
|
||||||
|
let fee_label: TString = kwargs.get(Qstr::MP_QSTR_fee_label)?.try_into()?;
|
||||||
|
let title: Option<TString> = kwargs
|
||||||
|
.get(Qstr::MP_QSTR_title)
|
||||||
|
.unwrap_or_else(|_| Obj::const_none())
|
||||||
|
.try_into_option()?;
|
||||||
|
let fee_info: Option<Obj> = kwargs
|
||||||
|
.get(Qstr::MP_QSTR_fee_info)
|
||||||
|
.unwrap_or_else(|_| Obj::const_none())
|
||||||
|
.try_into_option()?;
|
||||||
|
let account_info: Option<Obj> = kwargs
|
||||||
|
.get(Qstr::MP_QSTR_account_info)
|
||||||
|
.unwrap_or_else(|_| Obj::const_none())
|
||||||
|
.try_into_option()?;
|
||||||
|
let extra_info: Option<Obj> = kwargs
|
||||||
|
.get(Qstr::MP_QSTR_extra_info)
|
||||||
|
.unwrap_or_else(|_| Obj::const_none())
|
||||||
|
.try_into_option()?;
|
||||||
let cancel_arrow: bool = kwargs.get_or(Qstr::MP_QSTR_cancel_arrow, false)?;
|
let cancel_arrow: bool = kwargs.get_or(Qstr::MP_QSTR_cancel_arrow, false)?;
|
||||||
|
|
||||||
let mut paragraphs = ParagraphVecShort::new();
|
// TODO: default title here?
|
||||||
|
let title = title.unwrap_or(TR::words__title_summary.into());
|
||||||
|
let info_button: bool =
|
||||||
|
fee_info.is_some() || account_info.is_some() || extra_info.is_some();
|
||||||
|
let mut paragraphs = ParagraphVecShort::from_iter([
|
||||||
|
Paragraph::new(&theme::TEXT_NORMAL, amount_label).no_break(),
|
||||||
|
Paragraph::new(&theme::TEXT_MONO, amount),
|
||||||
|
Paragraph::new(&theme::TEXT_NORMAL, fee_label).no_break(),
|
||||||
|
Paragraph::new(&theme::TEXT_MONO, fee),
|
||||||
|
]);
|
||||||
|
|
||||||
for pair in IterBuf::new().try_iterate(items)? {
|
|
||||||
let [label, value]: [TString; 2] = util::iter_into_array(pair)?;
|
|
||||||
paragraphs.add(Paragraph::new(&theme::TEXT_NORMAL, label).no_break());
|
|
||||||
paragraphs.add(Paragraph::new(&theme::TEXT_MONO, value));
|
|
||||||
}
|
|
||||||
let mut page = ButtonPage::new(paragraphs.into_paragraphs(), theme::BG).with_hold()?;
|
let mut page = ButtonPage::new(paragraphs.into_paragraphs(), theme::BG).with_hold()?;
|
||||||
if cancel_arrow {
|
if cancel_arrow {
|
||||||
page = page.with_cancel_arrow()
|
page = page.with_cancel_arrow()
|
||||||
@ -356,10 +377,15 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
|||||||
|
|
||||||
/// def confirm_total(
|
/// def confirm_total(
|
||||||
/// *,
|
/// *,
|
||||||
/// title: str,
|
/// amount: str,
|
||||||
/// items: Iterable[tuple[str, str]],
|
/// amount_label: str,
|
||||||
/// info_button: bool = False,
|
/// fee: str,
|
||||||
/// cancel_arrow: bool = False,
|
/// fee_label: str,
|
||||||
|
/// title: str | None = None,
|
||||||
|
/// fee_info: Iterable[tuple[str, str]] | None = None,
|
||||||
|
/// account_info: Iterable[tuple[str, str]] | None = None,
|
||||||
|
/// extra_info: Iterable[tuple[str, str]] | None = None,
|
||||||
|
/// cancel_arrow: bool = False, # unused on mercury
|
||||||
/// ) -> LayoutObj[UiResult]:
|
/// ) -> LayoutObj[UiResult]:
|
||||||
/// """Transaction summary. Always hold to confirm."""
|
/// """Transaction summary. Always hold to confirm."""
|
||||||
Qstr::MP_QSTR_confirm_total => obj_fn_kw!(0, new_confirm_total).as_obj(),
|
Qstr::MP_QSTR_confirm_total => obj_fn_kw!(0, new_confirm_total).as_obj(),
|
||||||
|
@ -171,9 +171,14 @@ from trezorui_api import *
|
|||||||
# rust/src/ui/model_tt/layout.rs
|
# rust/src/ui/model_tt/layout.rs
|
||||||
def confirm_total(
|
def confirm_total(
|
||||||
*,
|
*,
|
||||||
title: str,
|
amount: str,
|
||||||
items: Iterable[tuple[str, str]],
|
amount_label: str,
|
||||||
info_button: bool = False,
|
fee: str,
|
||||||
cancel_arrow: bool = False,
|
fee_label: str,
|
||||||
|
title: str | None = None,
|
||||||
|
fee_info: Iterable[tuple[str, str]] | None = None,
|
||||||
|
account_info: Iterable[tuple[str, str]] | None = None,
|
||||||
|
extra_info: Iterable[tuple[str, str]] | None = None,
|
||||||
|
cancel_arrow: bool = False, # unused on mercury
|
||||||
) -> LayoutObj[UiResult]:
|
) -> LayoutObj[UiResult]:
|
||||||
"""Transaction summary. Always hold to confirm."""
|
"""Transaction summary. Always hold to confirm."""
|
||||||
|
@ -719,43 +719,67 @@ def confirm_total(
|
|||||||
total_label = total_label or f"{TR.send__total_amount}:" # def_arg
|
total_label = total_label or f"{TR.send__total_amount}:" # def_arg
|
||||||
fee_label = fee_label or TR.send__including_fee # def_arg
|
fee_label = fee_label or TR.send__including_fee # def_arg
|
||||||
|
|
||||||
items = [
|
account_info_items = []
|
||||||
(total_label, total_amount),
|
fee_info_items = []
|
||||||
(fee_label, fee_amount),
|
extra_info_items = []
|
||||||
]
|
|
||||||
info_items = []
|
|
||||||
if source_account:
|
if source_account:
|
||||||
info_items.append((TR.confirm_total__sending_from_account, source_account))
|
account_info_items.append(
|
||||||
|
(TR.confirm_total__sending_from_account, source_account)
|
||||||
|
)
|
||||||
if fee_rate_amount:
|
if fee_rate_amount:
|
||||||
info_items.append((f"{TR.confirm_total__fee_rate}:", fee_rate_amount))
|
fee_info_items.append((f"{TR.confirm_total__fee_rate}:", fee_rate_amount))
|
||||||
|
|
||||||
return _confirm_summary(
|
return _confirm_summary(
|
||||||
items,
|
total_amount,
|
||||||
TR.words__title_summary,
|
total_label,
|
||||||
info_items=info_items,
|
fee_amount,
|
||||||
|
fee_label,
|
||||||
|
title=title,
|
||||||
|
fee_info_items=fee_info_items,
|
||||||
|
account_info_items=account_info_items,
|
||||||
|
extra_info_items=extra_info_items,
|
||||||
br_name=br_name,
|
br_name=br_name,
|
||||||
br_code=br_code,
|
br_code=br_code,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _confirm_summary(
|
def _confirm_summary(
|
||||||
items: Iterable[tuple[str, str]],
|
amount: str,
|
||||||
|
amount_label: str,
|
||||||
|
fee: str,
|
||||||
|
fee_label: str,
|
||||||
title: str | None = None,
|
title: str | None = None,
|
||||||
info_items: Iterable[tuple[str, str]] | None = None,
|
fee_info_items: Iterable[tuple[str, str]] | None = None,
|
||||||
info_title: str | None = None,
|
account_info_items: Iterable[tuple[str, str]] | None = None,
|
||||||
|
extra_info_items: Iterable[tuple[str, str]] | None = None,
|
||||||
|
extra_info_title: str | None = None,
|
||||||
br_name: str = "confirm_total",
|
br_name: str = "confirm_total",
|
||||||
br_code: ButtonRequestType = ButtonRequestType.SignTx,
|
br_code: ButtonRequestType = ButtonRequestType.SignTx,
|
||||||
) -> Awaitable[None]:
|
) -> Awaitable[None]:
|
||||||
title = title or TR.words__title_summary # def_arg
|
title = title or TR.words__title_summary # def_arg
|
||||||
|
|
||||||
total_layout = trezorui2.confirm_total(
|
total_layout = trezorui2.confirm_total(
|
||||||
|
amount=amount,
|
||||||
|
amount_label=amount_label,
|
||||||
|
fee=fee,
|
||||||
|
fee_label=fee_label,
|
||||||
title=title,
|
title=title,
|
||||||
items=items,
|
fee_info=fee_info_items,
|
||||||
info_button=bool(info_items),
|
account_info=account_info_items,
|
||||||
|
extra_info=extra_info_items,
|
||||||
|
cancel_arrow=True,
|
||||||
)
|
)
|
||||||
info_items = info_items or []
|
|
||||||
|
# TODO: use `_info` params directly in this^ layout instead of using `with_info`
|
||||||
|
info_items = []
|
||||||
|
if fee_info_items:
|
||||||
|
info_items.extend(fee_info_items)
|
||||||
|
if account_info_items:
|
||||||
|
info_items.extend(account_info_items)
|
||||||
|
if extra_info_items:
|
||||||
|
info_items.extend(extra_info_items)
|
||||||
info_layout = trezorui_api.show_info_with_cancel(
|
info_layout = trezorui_api.show_info_with_cancel(
|
||||||
title=info_title if info_title else TR.words__title_information,
|
title=extra_info_title if extra_info_title else TR.words__title_information,
|
||||||
items=info_items,
|
items=info_items,
|
||||||
)
|
)
|
||||||
return with_info(total_layout, info_layout, br_name, br_code)
|
return with_info(total_layout, info_layout, br_name, br_code)
|
||||||
@ -782,13 +806,14 @@ if not utils.BITCOIN_ONLY:
|
|||||||
br_code: ButtonRequestType = ButtonRequestType.SignTx,
|
br_code: ButtonRequestType = ButtonRequestType.SignTx,
|
||||||
chunkify: bool = False,
|
chunkify: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
# NOTE: fee_info used so that info button is shown
|
||||||
total_layout = trezorui2.confirm_total(
|
total_layout = trezorui2.confirm_total(
|
||||||
|
amount=total_amount,
|
||||||
|
amount_label=f"{TR.words__amount}:",
|
||||||
|
fee=maximum_fee,
|
||||||
|
fee_label=f"{TR.send__maximum_fee}:",
|
||||||
title=TR.words__title_summary,
|
title=TR.words__title_summary,
|
||||||
items=[
|
fee_info=fee_info_items,
|
||||||
(f"{TR.words__amount}:", total_amount),
|
|
||||||
(f"{TR.send__maximum_fee}:", maximum_fee),
|
|
||||||
],
|
|
||||||
info_button=True,
|
|
||||||
cancel_arrow=True,
|
cancel_arrow=True,
|
||||||
)
|
)
|
||||||
info_layout = trezorui_api.show_info_with_cancel(
|
info_layout = trezorui_api.show_info_with_cancel(
|
||||||
@ -850,17 +875,23 @@ if not utils.BITCOIN_ONLY:
|
|||||||
|
|
||||||
# confirmation
|
# confirmation
|
||||||
if verb == TR.ethereum__staking_claim:
|
if verb == TR.ethereum__staking_claim:
|
||||||
items = ((f"{TR.send__maximum_fee}:", maximum_fee),)
|
amount = ""
|
||||||
|
amount_label = ""
|
||||||
|
fee_label = f"{TR.send__maximum_fee}:"
|
||||||
|
fee = maximum_fee
|
||||||
else:
|
else:
|
||||||
items = (
|
amount_label = f"{TR.words__amount}:"
|
||||||
(f"{TR.words__amount}:", total_amount),
|
amount = total_amount
|
||||||
(f"{TR.send__maximum_fee}:", maximum_fee),
|
fee_label = f"{TR.send__maximum_fee}:"
|
||||||
)
|
fee = maximum_fee
|
||||||
await _confirm_summary(
|
await _confirm_summary(
|
||||||
items, # items
|
amount,
|
||||||
|
amount_label,
|
||||||
|
fee,
|
||||||
|
fee_label,
|
||||||
title=title,
|
title=title,
|
||||||
info_title=TR.confirm_total__title_fee,
|
extra_info_items=[(f"{k}:", v) for (k, v) in info_items],
|
||||||
info_items=[(f"{k}:", v) for (k, v) in info_items],
|
extra_info_title=TR.confirm_total__title_fee,
|
||||||
br_name=br_name,
|
br_name=br_name,
|
||||||
br_code=br_code,
|
br_code=br_code,
|
||||||
)
|
)
|
||||||
@ -879,8 +910,11 @@ if not utils.BITCOIN_ONLY:
|
|||||||
) # def_arg
|
) # def_arg
|
||||||
fee_title = fee_title or TR.words__fee # def_arg
|
fee_title = fee_title or TR.words__fee # def_arg
|
||||||
return _confirm_summary(
|
return _confirm_summary(
|
||||||
((amount_title, amount), (fee_title, fee)),
|
amount,
|
||||||
info_items=items,
|
amount_title,
|
||||||
|
fee,
|
||||||
|
fee_title,
|
||||||
|
extra_info_items=items,
|
||||||
br_name=br_name,
|
br_name=br_name,
|
||||||
br_code=br_code,
|
br_code=br_code,
|
||||||
)
|
)
|
||||||
@ -893,8 +927,11 @@ if not utils.BITCOIN_ONLY:
|
|||||||
amount_title = f"{TR.send__total_amount}:"
|
amount_title = f"{TR.send__total_amount}:"
|
||||||
fee_title = TR.send__including_fee
|
fee_title = TR.send__including_fee
|
||||||
return _confirm_summary(
|
return _confirm_summary(
|
||||||
((amount_title, amount), (fee_title, fee)),
|
amount,
|
||||||
info_items=items,
|
amount_title,
|
||||||
|
fee,
|
||||||
|
fee_title,
|
||||||
|
extra_info_items=items,
|
||||||
br_name="confirm_cardano_tx",
|
br_name="confirm_cardano_tx",
|
||||||
br_code=ButtonRequestType.SignTx,
|
br_code=ButtonRequestType.SignTx,
|
||||||
)
|
)
|
||||||
@ -902,12 +939,13 @@ if not utils.BITCOIN_ONLY:
|
|||||||
|
|
||||||
def confirm_joint_total(spending_amount: str, total_amount: str) -> Awaitable[None]:
|
def confirm_joint_total(spending_amount: str, total_amount: str) -> Awaitable[None]:
|
||||||
return raise_if_not_confirmed(
|
return raise_if_not_confirmed(
|
||||||
|
# FIXME: arguments for amount/fee are misused here
|
||||||
trezorui2.confirm_total(
|
trezorui2.confirm_total(
|
||||||
|
spending_amount,
|
||||||
|
TR.send__you_are_contributing,
|
||||||
|
total_amount,
|
||||||
|
TR.send__to_the_total_amount,
|
||||||
title=TR.send__title_joint_transaction,
|
title=TR.send__title_joint_transaction,
|
||||||
items=[
|
|
||||||
(TR.send__you_are_contributing, spending_amount),
|
|
||||||
(TR.send__to_the_total_amount, total_amount),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
"confirm_joint_total",
|
"confirm_joint_total",
|
||||||
ButtonRequestType.SignTx,
|
ButtonRequestType.SignTx,
|
||||||
|
Loading…
Reference in New Issue
Block a user