mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 07:28:10 +00:00
fix(core): unify sent button requests in ETH send flow
Makes sure T2B1 will send the same ButtonRequests as T2T1. Does it by splitting the Rust layout into two separate dialogs. [no changelog]
This commit is contained in:
parent
91e98c58ba
commit
9db8ff1fae
@ -45,7 +45,6 @@ static void _librust_qstrs(void) {
|
|||||||
MP_QSTR_confirm_blob;
|
MP_QSTR_confirm_blob;
|
||||||
MP_QSTR_confirm_coinjoin;
|
MP_QSTR_confirm_coinjoin;
|
||||||
MP_QSTR_confirm_emphasized;
|
MP_QSTR_confirm_emphasized;
|
||||||
MP_QSTR_confirm_ethereum_tx;
|
|
||||||
MP_QSTR_confirm_fido;
|
MP_QSTR_confirm_fido;
|
||||||
MP_QSTR_confirm_firmware_update;
|
MP_QSTR_confirm_firmware_update;
|
||||||
MP_QSTR_confirm_homescreen;
|
MP_QSTR_confirm_homescreen;
|
||||||
@ -70,6 +69,7 @@ static void _librust_qstrs(void) {
|
|||||||
MP_QSTR_dry_run;
|
MP_QSTR_dry_run;
|
||||||
MP_QSTR_encode;
|
MP_QSTR_encode;
|
||||||
MP_QSTR_encoded_length;
|
MP_QSTR_encoded_length;
|
||||||
|
MP_QSTR_ethereum_tx_summary;
|
||||||
MP_QSTR_extra;
|
MP_QSTR_extra;
|
||||||
MP_QSTR_fee_amount;
|
MP_QSTR_fee_amount;
|
||||||
MP_QSTR_fee_label;
|
MP_QSTR_fee_label;
|
||||||
@ -102,7 +102,6 @@ static void _librust_qstrs(void) {
|
|||||||
MP_QSTR_progress_event;
|
MP_QSTR_progress_event;
|
||||||
MP_QSTR_prompt;
|
MP_QSTR_prompt;
|
||||||
MP_QSTR_qr_title;
|
MP_QSTR_qr_title;
|
||||||
MP_QSTR_recipient;
|
|
||||||
MP_QSTR_request_bip39;
|
MP_QSTR_request_bip39;
|
||||||
MP_QSTR_request_complete_repaint;
|
MP_QSTR_request_complete_repaint;
|
||||||
MP_QSTR_request_number;
|
MP_QSTR_request_number;
|
||||||
|
@ -754,34 +754,15 @@ 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) }
|
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" fn new_confirm_ethereum_tx(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
|
extern "C" fn new_ethereum_tx_summary(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
|
||||||
let block = |_args: &[Obj], kwargs: &Map| {
|
let block = |_args: &[Obj], kwargs: &Map| {
|
||||||
let recipient: StrBuffer = kwargs.get(Qstr::MP_QSTR_recipient)?.try_into()?;
|
|
||||||
let total_amount: StrBuffer = kwargs.get(Qstr::MP_QSTR_total_amount)?.try_into()?;
|
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 maximum_fee: StrBuffer = kwargs.get(Qstr::MP_QSTR_maximum_fee)?.try_into()?;
|
||||||
let items: Obj = kwargs.get(Qstr::MP_QSTR_items)?;
|
let items: Obj = kwargs.get(Qstr::MP_QSTR_items)?;
|
||||||
let chunkify: bool = kwargs.get_or(Qstr::MP_QSTR_chunkify, false)?;
|
|
||||||
|
|
||||||
let get_page = move |page_index| {
|
let get_page = move |page_index| {
|
||||||
match page_index {
|
match page_index {
|
||||||
0 => {
|
0 => {
|
||||||
// RECIPIENT
|
|
||||||
let btn_layout = ButtonLayout::cancel_none_text("CONTINUE".into());
|
|
||||||
let btn_actions = ButtonActions::cancel_none_next();
|
|
||||||
|
|
||||||
let style = if chunkify {
|
|
||||||
// Chunkifying the address into smaller pieces when requested
|
|
||||||
theme::TEXT_MONO_ADDRESS_CHUNKS
|
|
||||||
} else {
|
|
||||||
theme::TEXT_MONO_DATA
|
|
||||||
};
|
|
||||||
|
|
||||||
let ops = OpTextLayout::new(style).text_mono(recipient.clone());
|
|
||||||
|
|
||||||
let formatted = FormattedText::new(ops).vertically_centered();
|
|
||||||
Page::new(btn_layout, btn_actions, formatted).with_title("RECIPIENT".into())
|
|
||||||
}
|
|
||||||
1 => {
|
|
||||||
// Total amount + fee
|
// Total amount + fee
|
||||||
let btn_layout = ButtonLayout::up_arrow_armed_info("CONFIRM".into());
|
let btn_layout = ButtonLayout::up_arrow_armed_info("CONFIRM".into());
|
||||||
let btn_actions = ButtonActions::prev_confirm_next();
|
let btn_actions = ButtonActions::prev_confirm_next();
|
||||||
@ -797,7 +778,7 @@ extern "C" fn new_confirm_ethereum_tx(n_args: usize, args: *const Obj, kwargs: *
|
|||||||
let formatted = FormattedText::new(ops);
|
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:".into())
|
||||||
}
|
}
|
||||||
2 => {
|
1 => {
|
||||||
// Fee information
|
// Fee information
|
||||||
let btn_layout = ButtonLayout::arrow_none_none();
|
let btn_layout = ButtonLayout::arrow_none_none();
|
||||||
let btn_actions = ButtonActions::prev_none_none();
|
let btn_actions = ButtonActions::prev_none_none();
|
||||||
@ -824,7 +805,7 @@ extern "C" fn new_confirm_ethereum_tx(n_args: usize, args: *const Obj, kwargs: *
|
|||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let pages = FlowPages::new(get_page, 3);
|
let pages = FlowPages::new(get_page, 2);
|
||||||
|
|
||||||
let obj = LayoutObj::new(Flow::new(pages).with_scrollbar(false))?;
|
let obj = LayoutObj::new(Flow::new(pages).with_scrollbar(false))?;
|
||||||
Ok(obj.into())
|
Ok(obj.into())
|
||||||
@ -1816,16 +1797,14 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
|||||||
/// """Confirm summary of a transaction."""
|
/// """Confirm summary of a transaction."""
|
||||||
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(),
|
||||||
|
|
||||||
/// def confirm_ethereum_tx(
|
/// def ethereum_tx_summary(
|
||||||
/// *,
|
/// *,
|
||||||
/// recipient: str,
|
|
||||||
/// total_amount: str,
|
/// total_amount: str,
|
||||||
/// maximum_fee: str,
|
/// maximum_fee: str,
|
||||||
/// items: Iterable[Tuple[str, str]],
|
/// items: Iterable[Tuple[str, str]],
|
||||||
/// chunkify: bool = False,
|
|
||||||
/// ) -> object:
|
/// ) -> object:
|
||||||
/// """Confirm details about Ethereum transaction."""
|
/// """Confirm details about Ethereum transaction."""
|
||||||
Qstr::MP_QSTR_confirm_ethereum_tx => obj_fn_kw!(0, new_confirm_ethereum_tx).as_obj(),
|
Qstr::MP_QSTR_ethereum_tx_summary => obj_fn_kw!(0, new_ethereum_tx_summary).as_obj(),
|
||||||
|
|
||||||
/// def tutorial() -> object:
|
/// def tutorial() -> object:
|
||||||
/// """Show user how to interact with the device."""
|
/// """Show user how to interact with the device."""
|
||||||
|
@ -170,13 +170,11 @@ def confirm_total(
|
|||||||
|
|
||||||
|
|
||||||
# rust/src/ui/model_tr/layout.rs
|
# rust/src/ui/model_tr/layout.rs
|
||||||
def confirm_ethereum_tx(
|
def ethereum_tx_summary(
|
||||||
*,
|
*,
|
||||||
recipient: str,
|
|
||||||
total_amount: str,
|
total_amount: str,
|
||||||
maximum_fee: str,
|
maximum_fee: str,
|
||||||
items: Iterable[Tuple[str, str]],
|
items: Iterable[Tuple[str, str]],
|
||||||
chunkify: bool = False,
|
|
||||||
) -> object:
|
) -> object:
|
||||||
"""Confirm details about Ethereum transaction."""
|
"""Confirm details about Ethereum transaction."""
|
||||||
|
|
||||||
|
@ -1000,22 +1000,37 @@ async def confirm_ethereum_tx(
|
|||||||
br_code: ButtonRequestType = ButtonRequestType.SignTx,
|
br_code: ButtonRequestType = ButtonRequestType.SignTx,
|
||||||
chunkify: bool = False,
|
chunkify: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
await raise_if_not_confirmed(
|
summary_layout = RustLayout(
|
||||||
interact(
|
trezorui2.ethereum_tx_summary(
|
||||||
RustLayout(
|
total_amount=total_amount,
|
||||||
trezorui2.confirm_ethereum_tx(
|
maximum_fee=maximum_fee,
|
||||||
recipient=recipient,
|
items=items,
|
||||||
total_amount=total_amount,
|
|
||||||
maximum_fee=maximum_fee,
|
|
||||||
items=items,
|
|
||||||
chunkify=chunkify,
|
|
||||||
)
|
|
||||||
),
|
|
||||||
br_type,
|
|
||||||
br_code,
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
# Allowing going back and forth between recipient and summary/details
|
||||||
|
await confirm_blob(
|
||||||
|
br_type,
|
||||||
|
"RECIPIENT",
|
||||||
|
recipient,
|
||||||
|
verb="CONTINUE",
|
||||||
|
chunkify=chunkify,
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
summary_layout.request_complete_repaint()
|
||||||
|
await raise_if_not_confirmed(
|
||||||
|
interact(
|
||||||
|
summary_layout,
|
||||||
|
br_type,
|
||||||
|
br_code,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
break
|
||||||
|
except ActionCancelled:
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
async def confirm_joint_total(spending_amount: str, total_amount: str) -> None:
|
async def confirm_joint_total(spending_amount: str, total_amount: str) -> None:
|
||||||
await raise_if_not_confirmed(
|
await raise_if_not_confirmed(
|
||||||
|
@ -187,12 +187,14 @@ def test_data_streaming(client: Client):
|
|||||||
"""
|
"""
|
||||||
with client:
|
with client:
|
||||||
is_t1 = client.features.model == "1"
|
is_t1 = client.features.model == "1"
|
||||||
is_tt = client.features.model == "T"
|
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[
|
[
|
||||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||||
(is_t1, messages.ButtonRequest(code=messages.ButtonRequestType.SignTx)),
|
(is_t1, messages.ButtonRequest(code=messages.ButtonRequestType.SignTx)),
|
||||||
(is_tt, messages.ButtonRequest(code=messages.ButtonRequestType.Other)),
|
(
|
||||||
|
not is_t1,
|
||||||
|
messages.ButtonRequest(code=messages.ButtonRequestType.Other),
|
||||||
|
),
|
||||||
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
|
||||||
message_filters.EthereumTxRequest(
|
message_filters.EthereumTxRequest(
|
||||||
data_length=1_024,
|
data_length=1_024,
|
||||||
|
@ -316,6 +316,7 @@ class EthereumFlow:
|
|||||||
self.debug.press_left()
|
self.debug.press_left()
|
||||||
else:
|
else:
|
||||||
self.debug.press_right()
|
self.debug.press_right()
|
||||||
|
yield
|
||||||
assert "Maximum fee:" in self.debug.wait_layout().text_content()
|
assert "Maximum fee:" in self.debug.wait_layout().text_content()
|
||||||
if info:
|
if info:
|
||||||
self.debug.press_right(wait=True)
|
self.debug.press_right(wait=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user