WIP - make ethereum summary reusable for more coins

grdddj/solana_summary_layout
grdddj 6 months ago
parent 087becd2ca
commit 4b72a60ced

@ -24,10 +24,12 @@ static void _librust_qstrs(void) {
MP_QSTR_address_label;
MP_QSTR_address_title;
MP_QSTR_allow_cancel;
MP_QSTR_altcoin_tx_summary;
MP_QSTR_amount;
MP_QSTR_amount_change;
MP_QSTR_amount_new;
MP_QSTR_amount_title;
MP_QSTR_amount_value;
MP_QSTR_app_name;
MP_QSTR_attach_timer_fn;
MP_QSTR_bootscreen;
@ -69,11 +71,12 @@ static void _librust_qstrs(void) {
MP_QSTR_dry_run;
MP_QSTR_encode;
MP_QSTR_encoded_length;
MP_QSTR_ethereum_tx_summary;
MP_QSTR_extra;
MP_QSTR_fee_amount;
MP_QSTR_fee_label;
MP_QSTR_fee_rate_amount;
MP_QSTR_fee_title;
MP_QSTR_fee_value;
MP_QSTR_fingerprint;
MP_QSTR_hold;
MP_QSTR_hold_danger;
@ -90,7 +93,6 @@ static void _librust_qstrs(void) {
MP_QSTR_max_feerate;
MP_QSTR_max_len;
MP_QSTR_max_rounds;
MP_QSTR_maximum_fee;
MP_QSTR_min_count;
MP_QSTR_multiple_pages_texts;
MP_QSTR_notification;

@ -751,32 +751,34 @@ 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_ethereum_tx_summary(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
extern "C" fn new_altcoin_tx_summary(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
let block = |_args: &[Obj], kwargs: &Map| {
let total_amount: StrBuffer = kwargs.get(Qstr::MP_QSTR_total_amount)?.try_into()?;
let maximum_fee: StrBuffer = kwargs.get(Qstr::MP_QSTR_maximum_fee)?.try_into()?;
let amount_title: StrBuffer = kwargs.get(Qstr::MP_QSTR_amount_title)?.try_into()?;
let amount_value: StrBuffer = kwargs.get(Qstr::MP_QSTR_amount_value)?.try_into()?;
let fee_title: StrBuffer = kwargs.get(Qstr::MP_QSTR_fee_title)?.try_into()?;
let fee_value: StrBuffer = kwargs.get(Qstr::MP_QSTR_fee_value)?.try_into()?;
let items: Obj = kwargs.get(Qstr::MP_QSTR_items)?;
let get_page = move |page_index| {
match page_index {
0 => {
// Total amount + fee
// Amount + fee
let btn_layout = ButtonLayout::up_arrow_armed_info("CONFIRM".into());
let btn_actions = ButtonActions::prev_confirm_next();
let btn_actions = ButtonActions::cancel_confirm_next();
let ops = OpTextLayout::new(theme::TEXT_MONO)
.text_mono(total_amount.clone())
.text_mono(amount_value.clone())
.newline()
.newline_half()
.text_bold("Maximum fee:".into())
.text_bold(fee_title.clone())
.newline()
.text_mono(maximum_fee.clone());
.text_mono(fee_value.clone());
let formatted = FormattedText::new(ops);
Page::new(btn_layout, btn_actions, formatted).with_title("Amount:".into())
Page::new(btn_layout, btn_actions, formatted).with_title(amount_title.clone())
}
1 => {
// Fee information
// Other information
let btn_layout = ButtonLayout::arrow_none_none();
let btn_actions = ButtonActions::prev_none_none();
@ -1793,14 +1795,16 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// """Confirm summary of a transaction."""
Qstr::MP_QSTR_confirm_total => obj_fn_kw!(0, new_confirm_total).as_obj(),
/// def ethereum_tx_summary(
/// def altcoin_tx_summary(
/// *,
/// total_amount: str,
/// maximum_fee: str,
/// amount_title: str,
/// amount_value: str,
/// fee_title: str,
/// fee_amount: str,
/// items: Iterable[Tuple[str, str]],
/// ) -> object:
/// """Confirm details about Ethereum transaction."""
Qstr::MP_QSTR_ethereum_tx_summary => obj_fn_kw!(0, new_ethereum_tx_summary).as_obj(),
/// """Confirm details about altcoin transaction."""
Qstr::MP_QSTR_altcoin_tx_summary => obj_fn_kw!(0, new_altcoin_tx_summary).as_obj(),
/// def tutorial() -> object:
/// """Show user how to interact with the device."""

@ -169,13 +169,15 @@ def confirm_total(
# rust/src/ui/model_tr/layout.rs
def ethereum_tx_summary(
def altcoin_tx_summary(
*,
total_amount: str,
maximum_fee: str,
amount_title: str,
amount_value: str,
fee_title: str,
fee_amount: str,
items: Iterable[Tuple[str, str]],
) -> object:
"""Confirm details about Ethereum transaction."""
"""Confirm details about altcoin transaction."""
# rust/src/ui/model_tr/layout.rs

@ -1001,9 +1001,11 @@ async def confirm_ethereum_tx(
chunkify: bool = False,
) -> None:
summary_layout = RustLayout(
trezorui2.ethereum_tx_summary(
total_amount=total_amount,
maximum_fee=maximum_fee,
trezorui2.altcoin_tx_summary(
amount_title="Amount:",
amount_value=total_amount,
fee_title="Maximum fee:",
fee_value=maximum_fee,
items=items,
)
)

@ -6,7 +6,7 @@ EXCEPTIONS+=( "decred" ) # "decred" figures in field names used by the bitcoin
EXCEPTIONS+=( "omni" ) # OMNI is part of the bitcoin app
# BIP39 or SLIP39 words that have "dash" in them
EXCEPTIONS+=( "dash" )
EXCEPTIONS+=( "confirm_ethereum_tx" "ethereum_tx_summary" ) # is model-specific, so is in layout/__init__.py instead of ethereum/layout.py
EXCEPTIONS+=( "confirm_ethereum_tx" ) # is model-specific, so is in layout/__init__.py instead of ethereum/layout.py
GREP_ARGS=()
for exception in "${EXCEPTIONS[@]}"; do

Loading…
Cancel
Save