Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): fix the chunkification of longer Cardano addresses in send flow #3409

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions core/embed/rust/src/ui/model_tt/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,8 @@ impl ConfirmBlobParams {
description_font: &theme::TEXT_NORMAL,
extra_font: &theme::TEXT_DEMIBOLD,
data_font: if self.chunkify {
&theme::TEXT_MONO_ADDRESS_CHUNKS
let data: StrBuffer = self.data.try_into()?;
theme::get_chunkified_text_style(data.len())
} else {
&theme::TEXT_MONO
},
Expand Down Expand Up @@ -585,15 +586,8 @@ extern "C" fn new_confirm_address(n_args: usize, args: *const Obj, kwargs: *mut
let chunkify: bool = kwargs.get_or(Qstr::MP_QSTR_chunkify, false)?;

let data_style = if chunkify {
// Longer addresses have smaller x_offset so they fit even with scrollbar
// (as they will be shown on more than one page)
const FITS_ON_ONE_PAGE: usize = 16 * 4;
let address: StrBuffer = data.try_into()?;
if address.len() <= FITS_ON_ONE_PAGE {
&theme::TEXT_MONO_ADDRESS_CHUNKS
} else {
&theme::TEXT_MONO_ADDRESS_CHUNKS_SMALLER_X_OFFSET
}
theme::get_chunkified_text_style(address.len())
} else {
&theme::TEXT_MONO
};
Expand Down
12 changes: 12 additions & 0 deletions core/embed/rust/src/ui/model_tt/theme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,18 @@ pub const TEXT_MONO_ADDRESS_CHUNKS_SMALLER_X_OFFSET: TextStyle = TEXT_MONO
.with_line_spacing(5)
.with_ellipsis_icon(ICON_PAGE_NEXT, -12);

/// Decide the text style of chunkified text according to its length.
pub fn get_chunkified_text_style(character_length: usize) -> &'static TextStyle {
// Longer addresses have smaller x_offset so they fit even with scrollbar
// (as they will be shown on more than one page)
const FITS_ON_ONE_PAGE: usize = 16 * 4;
if character_length <= FITS_ON_ONE_PAGE {
&TEXT_MONO_ADDRESS_CHUNKS
} else {
&TEXT_MONO_ADDRESS_CHUNKS_SMALLER_X_OFFSET
}
}

/// Convert Python-side numeric id to a `TextStyle`.
pub fn textstyle_number(num: i32) -> &'static TextStyle {
let font = Font::from_i32(-num);
Expand Down
12 changes: 6 additions & 6 deletions tests/ui_tests/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -2867,13 +2867,13 @@
"TT_cardano-test_sign_tx.py::test_cardano_sign_tx_failed[withdrawal_has_script_hash]": "0aafa2ecd08c24a6192e557a0e77e5b0abcbd4bf7e7b44af7feebfa1114e21a3",
"TT_cardano-test_sign_tx.py::test_cardano_sign_tx_show_details[mainnet_transaction_without_change]": "468690086dda091c024e7bac1c6bad638b4dc9c7c90aa2e89bcc3d1910167b1c",
"TT_cardano-test_sign_tx.py::test_cardano_sign_tx_show_details[multisig_transaction_with_a_requ-c2fba589": "be409a32f2a558fae9dae332264053166f0d3916ebfdbaecf80cc820c90a6a0c",
"TT_cardano-test_sign_tx.py::test_cardano_sign_tx_show_details[ordinary_transaction_with_a_requ-9728607e": "9f0c7909d8323960642144aa05399e27dbb9ab5bf67e00a733dd827d28dbd19f",
"TT_cardano-test_sign_tx.py::test_cardano_sign_tx_show_details[ordinary_transaction_with_long_i-708443f3": "d160a2fb0dddf288f340e22c9b186a3ec733c92d46599d46430418f1b5006ba6",
"TT_cardano-test_sign_tx.py::test_cardano_sign_tx_show_details[ordinary_transaction_with_a_requ-9728607e": "da22afb34f298cbd3ed6bde0fcabbe458a4de9a7d5bb0ccccded1b28668e4e4e",
"TT_cardano-test_sign_tx.py::test_cardano_sign_tx_show_details[ordinary_transaction_with_long_i-708443f3": "f19bae2be77b3918ab3c252a5d0bcdc321c06ee03b0a2b2b9922cc5a70011950",
"TT_cardano-test_sign_tx.py::test_cardano_sign_tx_show_details[ordinary_transaction_with_output-9ba7352d": "333453ec30e9813548597d8d7e72a1b9ba8dc05e621ab45d06bf49f7ab344688",
"TT_cardano-test_sign_tx.py::test_cardano_sign_tx_show_details[plutus_transaction_with_reference_input]": "809cac6d78877944a01a4661adfbd69cc118faa9fa2185bf63fa08a96b8d17b5",
"TT_cardano-test_sign_tx.py::test_cardano_sign_tx_show_details[plutus_transaction_with_total_co-e846c221": "8b43b1fa717d1dfa216d321d81b92aef834b0f63955c9b32219da02ff4891799",
"TT_cardano-test_sign_tx.py::test_cardano_sign_tx_show_details[transaction_with_cip36_registrat-b9111c27": "2c6d145fe350001cb5e9d03c1c480a3c1ee041cca11d7debb4068c5a7e3aed84",
"TT_cardano-test_sign_tx.py::test_cardano_sign_tx_show_details[transaction_with_stake_deregistr-6e84da2f": "a7d10d8bae4762c60765abd7d5d7cf19b17c58bd0aad5060a4b89ddd141df63d",
"TT_cardano-test_sign_tx.py::test_cardano_sign_tx_show_details[plutus_transaction_with_reference_input]": "8382a58775800729f5c451f8dfdf0ec56dfee32fd429efd972aa5d4d99fc314e",
"TT_cardano-test_sign_tx.py::test_cardano_sign_tx_show_details[plutus_transaction_with_total_co-e846c221": "5cb5930ab6b5f3039e324498b9415b207d9ea2a972cc7061fd2027eac63964cf",
"TT_cardano-test_sign_tx.py::test_cardano_sign_tx_show_details[transaction_with_cip36_registrat-b9111c27": "784bda53e8aff24fb10b42f4652a393e6a42b745767f11bfa2f391f8f905d580",
"TT_cardano-test_sign_tx.py::test_cardano_sign_tx_show_details[transaction_with_stake_deregistr-6e84da2f": "abf531211a541574a744839e236f828e0c5de19c3d39413d5e34a974a421478d",
"TT_eos-test_get_public_key.py::test_eos_get_public_key": "6664c46f17816199cd89e6acb7e49233e66800ac6ba1993aac79157378de8476",
"TT_eos-test_signtx.py::test_eos_signtx_buyram": "714d9260fd979223e6a7193d8ff6f984b742f6c55fc0a5b021fa7ebf8b729186",
"TT_eos-test_signtx.py::test_eos_signtx_buyrambytes": "1499ef6a40023ee5fcf9b8e514bdbea5668d6acc5af84eb37c95dd0a3272f344",
Expand Down
Loading