1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-21 22:08:08 +00:00

fix(core/ui): fix mnemonic keys availability

This commit disables keys of mnemonic keyboard if their press cannot
lead to a valid word if the keyboard is initialized with a pre-filled
word. This is useful to get valid keyboard state when going to a
previous word during recovery.

[no changelog]
This commit is contained in:
obrusvit 2024-08-17 18:42:53 +02:00 committed by Vít Obrusník
parent e2022db8fa
commit 65d3fd00f1
3 changed files with 34 additions and 18 deletions

View File

@ -55,6 +55,18 @@ where
let back_btn = Button::with_icon(theme::ICON_CHEVRON_LEFT)
.styled(theme::button_default())
.with_expanded_touch_area(Insets::right(BACK_BUTTON_RIGHT_EXPAND));
let keys = {
const EMPTY_BTN: Button = Button::empty();
let mut array = [EMPTY_BTN; MNEMONIC_KEY_COUNT];
for (key, t) in T::keys().iter().enumerate() {
array[key] = Button::with_text((*t).into())
.styled(theme::button_keyboard())
.with_text_align(Alignment::Center)
.initially_enabled(input.can_key_press_lead_to_a_valid_word(key));
}
array
};
Self {
prompt: Maybe::new(
theme::BG,
@ -65,11 +77,7 @@ where
back: Maybe::new(theme::BG, back_btn, prompt_visible && can_go_back),
input: Maybe::new(theme::BG, input, !prompt_visible),
keypad_area: Rect::zero(),
keys: T::keys().map(|t| {
Button::with_text(t.into())
.styled(theme::button_keyboard())
.with_text_align(Alignment::Center)
}),
keys,
swipe: Swipe::new().right(),
can_go_back,
}

View File

@ -40,6 +40,16 @@ where
pub fn new(input: T, prompt: TString<'static>, can_go_back: bool) -> Self {
// Input might be already pre-filled
let prompt_visible = input.is_empty();
let keys = {
const EMPTY_BTN: Button = Button::empty();
let mut array = [EMPTY_BTN; MNEMONIC_KEY_COUNT];
for (key, t) in T::keys().iter().enumerate() {
array[key] = Button::with_text((*t).into())
.styled(theme::button_pin())
.initially_enabled(input.can_key_press_lead_to_a_valid_word(key));
}
array.map(Child::new)
};
Self {
prompt: Child::new(Maybe::new(
@ -59,9 +69,7 @@ where
!prompt_visible,
)),
input: Child::new(Maybe::new(theme::BG, input, !prompt_visible)),
keys: T::keys()
.map(|t| Button::with_text(t.into()).styled(theme::button_pin()))
.map(Child::new),
keys,
swipe: Swipe::new().right(),
can_go_back,
}

View File

@ -7843,7 +7843,7 @@
"T2T1_cs_test_pin.py::test_wipe_code_same_as_pin": "c3446b0a48892acdb5fc178ad7c18ef6a1d2df14367148fa9bc02c54c9b819ae",
"T2T1_cs_test_pin.py::test_wipe_code_setup": "6035ededebf828bc8d85f1c3ba370a996c1267b1885bc7de27921badf9a244f1",
"T2T1_cs_test_recovery.py::test_recovery_bip39": "f2166fb9da2954b3ba3d45a8387ea2f54fbc5ba368dc8a3bae052605da85422e",
"T2T1_cs_test_recovery.py::test_recovery_bip39_previous_word": "00d3300ced62470ecb0cca321dc2d51815c420ce7f638f30d00d98bf2544430a",
"T2T1_cs_test_recovery.py::test_recovery_bip39_previous_word": "9090fb71903ebf09d2f355eca6148089234c968663a6fbc7ef8b3da83cb68d10",
"T2T1_cs_test_recovery.py::test_recovery_slip39_basic": "2fd13d2bfec6a17af56fff6e74298a1d22eccc162382909741c4f3153887cee2",
"T2T1_cs_test_repeated_backup.py::test_repeated_backup": "f0ddd5bcceb74cec9cc7c399d557c40cbc01037ec692e78690624a68df5c8564",
"T2T1_cs_test_reset_bip39.py::test_reset_bip39": "5674d27b155c782f45f5a3f5c6cb8b23f581b2346372cec20b3e36e7e944521e",
@ -7892,7 +7892,7 @@
"T2T1_de_test_pin.py::test_wipe_code_same_as_pin": "63f3a5b7c4b825e0369df49708667f0cfcef8bcd53e26cb5bcbc233bf5d9545d",
"T2T1_de_test_pin.py::test_wipe_code_setup": "ab1f71d108bdda802c5a182fdd15a89f6e5b924965170c45b652cc359b488c60",
"T2T1_de_test_recovery.py::test_recovery_bip39": "8eb3c0dfe5209acd644ab4d95e24852f2056adae2d023b25ce6c2de74638a099",
"T2T1_de_test_recovery.py::test_recovery_bip39_previous_word": "05782006b68c1f3b1898f46bf3535d0c79181f21c1e5a363c462df9df3744ded",
"T2T1_de_test_recovery.py::test_recovery_bip39_previous_word": "8d67f14a44e211a22189fc96947f9ea6aae558162076757fa26f8c55477dad5b",
"T2T1_de_test_recovery.py::test_recovery_slip39_basic": "2fabf58b8ebca83403c9d6a361009116c6d25791c489af35c87d03c5a9093442",
"T2T1_de_test_repeated_backup.py::test_repeated_backup": "448e6cb792f1f2081e83accea479ff910023df654bbb00f4186674d8934b300c",
"T2T1_de_test_reset_bip39.py::test_reset_bip39": "2c19504e49aefdf5c54d157b618763cf366f0a18cb1b488938d6ee7f0d6a78bf",
@ -7941,7 +7941,7 @@
"T2T1_en_test_pin.py::test_wipe_code_same_as_pin": "ca637846a0de6a5f5b8eca96ae2aa4c59432516bb28352b5e23dbfac470fe57b",
"T2T1_en_test_pin.py::test_wipe_code_setup": "01974e0c3a9169cfbe617c238fc73c20750736e60e52ad32ec170c829329823f",
"T2T1_en_test_recovery.py::test_recovery_bip39": "0246dc05c08fc0f59685314448ac43bbd95599d85b252abc31d258d435a98dec",
"T2T1_en_test_recovery.py::test_recovery_bip39_previous_word": "b2a434341e1f84d87bba74a742b9387ea37d85ed13f596b4228c9a5d84444120",
"T2T1_en_test_recovery.py::test_recovery_bip39_previous_word": "db9efe6d9c0e6e61dfa028e93f5eda6f9257cb8be5e1d1f36ac71e4f328f8355",
"T2T1_en_test_recovery.py::test_recovery_slip39_basic": "186037afb1c137cba14536c50f3ba854a10c289aa9792df59847e385671d5221",
"T2T1_en_test_repeated_backup.py::test_repeated_backup": "9d24a9538f3e10de96f5115db283813eccf6a5c471d9e9997a93c8a8b359b6c6",
"T2T1_en_test_reset_bip39.py::test_reset_bip39": "05255b352fde7646a698b74808b3de04350353ad7d8f7b2568a14967956c8bc8",
@ -7990,7 +7990,7 @@
"T2T1_es_test_pin.py::test_wipe_code_same_as_pin": "9c295e0f8093b5e484310899f5b9f93ca68581e1be0d569d3eeb2e0b763490d1",
"T2T1_es_test_pin.py::test_wipe_code_setup": "e7eeeafa1baed438c6eaf7983a54e6b7ea186f2d117e59041d9d63afb30d24ba",
"T2T1_es_test_recovery.py::test_recovery_bip39": "9cefbfa32e60aa0e9fc3f0ecdecb15bdd1a42ca90437629e3800f48a873ade71",
"T2T1_es_test_recovery.py::test_recovery_bip39_previous_word": "2d20545f8ae79659d805722e16510237660dedf46ad99405d0c1b455a8c3c8ce",
"T2T1_es_test_recovery.py::test_recovery_bip39_previous_word": "531bf101fe9f9d80a702816f490dea8dc5bf2f179460721f2a9d28322c153ec7",
"T2T1_es_test_recovery.py::test_recovery_slip39_basic": "3078b430c266dfc210f8f5e6a0b3f65659036354851c311769da3565c70039c2",
"T2T1_es_test_repeated_backup.py::test_repeated_backup": "d94bd04bfbc22fda7951e5f0e05e9978099412409db1c7ab01583ad83ad94275",
"T2T1_es_test_reset_bip39.py::test_reset_bip39": "2707d73e704b5dd08ac93498aa4cd578be2694c87f3987f5b1332352a7b49e42",
@ -8039,7 +8039,7 @@
"T2T1_fr_test_pin.py::test_wipe_code_same_as_pin": "40f4b0505fa503476b2d3fcf5d6c78b732addb522d9c6ba5d7414048ceb6a9f5",
"T2T1_fr_test_pin.py::test_wipe_code_setup": "bdd2e5e200b8333867e017e137a80ef9678102fca527c74eac369825a73cffaa",
"T2T1_fr_test_recovery.py::test_recovery_bip39": "f59eb22db3a6b211b3dfca235479c21871138c2d3b0b771d69ec63cad3d804fb",
"T2T1_fr_test_recovery.py::test_recovery_bip39_previous_word": "46070c5379251e1bf44144cd35921126062c60906fe1c6d6666bf7515d9fadba",
"T2T1_fr_test_recovery.py::test_recovery_bip39_previous_word": "299c2e3e7647113d7711c1c61e5f14bbb7abe7f3992b83e5ab6bed7306e5d316",
"T2T1_fr_test_recovery.py::test_recovery_slip39_basic": "da87f2762c9713ad50993f6862bb34da82f4f5dc4e8a2696f2956dd3e0abceda",
"T2T1_fr_test_repeated_backup.py::test_repeated_backup": "9a280efe2de3c20a7332adca64a4d40bb009bce8dd70421f9be01970901703e9",
"T2T1_fr_test_reset_bip39.py::test_reset_bip39": "c1bcf2768d4ac54af417ad7468ba40c13c16c80cdfcf24d455e96199043dfb6d",
@ -15362,7 +15362,7 @@
"T3T1_cs_test_pin.py::test_wipe_code_same_as_pin": "6d615ea3421738485484b14e305a8c3f159bdf82925329e98b87bff0890e4366",
"T3T1_cs_test_pin.py::test_wipe_code_setup": "3566f17ed11804872e11694e5c5a8da8cfbae335ad1a2a4b10cc1f48da04cab5",
"T3T1_cs_test_recovery.py::test_recovery_bip39": "0b4ded4093e543b29799e950c3d56b8ef4c03493709a94f12e3a1b245128dbf2",
"T3T1_cs_test_recovery.py::test_recovery_bip39_previous_word": "eece72ab6ae9aa5d919aa408a70197426f1773dca0c744007963fffecb3e9f8a",
"T3T1_cs_test_recovery.py::test_recovery_bip39_previous_word": "6f2ca2bb7d573126aa25c4a70fffea973670c6865d79bbeaad8deb8736efcca5",
"T3T1_cs_test_recovery.py::test_recovery_slip39_basic": "758f8c529232f37caaa4adc3caa57382d93ee0323b924a11bbd1ef484e7d7d2b",
"T3T1_cs_test_repeated_backup.py::test_repeated_backup": "814b4b08d026372e5a8c922c814847f06742d5f27e769e0bc0cfc50dbe1899bc",
"T3T1_cs_test_reset_bip39.py::test_reset_bip39": "93d1941ad5ce363252b3365b47bd10eb933d9f2a96d12cc518fd904a9e193e37",
@ -15411,7 +15411,7 @@
"T3T1_de_test_pin.py::test_wipe_code_same_as_pin": "561db133f0d612048fd08b46d438a4a500e064d3088055c9364a5660afb01103",
"T3T1_de_test_pin.py::test_wipe_code_setup": "e20e2c935c654931b9786df91908aa544d2736e06eb78cb0ef54d44604d5aeae",
"T3T1_de_test_recovery.py::test_recovery_bip39": "f15dd2779fe059da83e5c3384e3c882fb1f11a4fc77ad2cac2cca87ce6ff48c7",
"T3T1_de_test_recovery.py::test_recovery_bip39_previous_word": "f62897d9041e6e6c38676cc8d62a1c9c0e08c40877f426c1bfeb366e15ae1e9f",
"T3T1_de_test_recovery.py::test_recovery_bip39_previous_word": "c025bd7d5e6f4609241b1dc17663a91d59f242635905d67d6be0c06ed961b3bc",
"T3T1_de_test_recovery.py::test_recovery_slip39_basic": "9c132785b4d7f79f09ad2469d5f8e427a9b67617c77b297b7d1ddd2c4c3ddb72",
"T3T1_de_test_repeated_backup.py::test_repeated_backup": "b612d5a6af5bb306b0c399ecea31fe86985d03f6f95ae954598e45f5540e1244",
"T3T1_de_test_reset_bip39.py::test_reset_bip39": "8d05181934d3331c81e7b81b94baa24a8f4db336d29e1e7f650b42b38c0c3484",
@ -15460,7 +15460,7 @@
"T3T1_en_test_pin.py::test_wipe_code_same_as_pin": "19435c69b4111ee84d73ec996aec7150c3d0c8492203d3aacd96a64a9facc2da",
"T3T1_en_test_pin.py::test_wipe_code_setup": "ab34c35e04c86f39b8ebd6da3b48a7eb3b28cf8eabbcb4cbe17fc788ea7f14f4",
"T3T1_en_test_recovery.py::test_recovery_bip39": "d80025a0c9f7c2d888eaad44e5771ae073063ecbd4a59d6e8be6141f2ad1ca0c",
"T3T1_en_test_recovery.py::test_recovery_bip39_previous_word": "22ba5126dddd99f93d19bd9391dbc88697dd499ce735f1d8db1978f18416d462",
"T3T1_en_test_recovery.py::test_recovery_bip39_previous_word": "c580851c236bbb8f8a7d11fb0555f76ebf0d24560231548aa041c5260fbd2589",
"T3T1_en_test_recovery.py::test_recovery_slip39_basic": "ef3cbbc66db078e7db645f1b7e1609a5741fc71823a1ce4105414f0a348ef214",
"T3T1_en_test_repeated_backup.py::test_repeated_backup": "3a551f8b623311790b430aae9769edd544e448ec97679bb7921791f049927bbd",
"T3T1_en_test_reset_bip39.py::test_reset_bip39": "38af86057d4d922c371d9957d05e8f0974f9a1a27589c3f286a409a8f7b03ae2",
@ -15509,7 +15509,7 @@
"T3T1_es_test_pin.py::test_wipe_code_same_as_pin": "951f98ebd0dde31c123c7d93eb98af5d0bf5147f2bd28a3014ba26d8bda58d5d",
"T3T1_es_test_pin.py::test_wipe_code_setup": "edfe089762dabc918417ca26916a6ad1d0377b8617255c169384ef8728c17381",
"T3T1_es_test_recovery.py::test_recovery_bip39": "4ab6e088de9d60283c6a9bedcd39a9447cb484c0dcc3792351c620f129903078",
"T3T1_es_test_recovery.py::test_recovery_bip39_previous_word": "b433b71921e24c77d6860fdd5c0c2648d3e3574ed3ed0becb19470fd1bc781ae",
"T3T1_es_test_recovery.py::test_recovery_bip39_previous_word": "8ce954ae8e00a8d60dc94aba2b4a332ffafbe343efb4be18ef6f400d8f7d7b39",
"T3T1_es_test_recovery.py::test_recovery_slip39_basic": "77ee2df1a216bbd3a040523ec0904384653f5bda080e77059b99715b6a297cad",
"T3T1_es_test_repeated_backup.py::test_repeated_backup": "4713a3a4d39b6a7e8bf764dfc7c57fa454ecf4b1a253981262a2241d2fb11c5a",
"T3T1_es_test_reset_bip39.py::test_reset_bip39": "0dcc22c287bd99765d79d3d393d287cfc70002213aea2679b5db004efe5da319",
@ -15558,7 +15558,7 @@
"T3T1_fr_test_pin.py::test_wipe_code_same_as_pin": "9fbf63afaf25ceec9a0b8d17ec83c0a7a39c7b106ac13519ac196474a083a31d",
"T3T1_fr_test_pin.py::test_wipe_code_setup": "943ea3640d21ae0a79655035e2aa0722cc7b79f6a9e17bef39afd9ac1c327549",
"T3T1_fr_test_recovery.py::test_recovery_bip39": "ad346e6b6f0dab29d4240f7495cb92b1546b8f545477ec02c03e6f25545adb47",
"T3T1_fr_test_recovery.py::test_recovery_bip39_previous_word": "0f89c01652f65d814aca2ebaec766479cf362772ab3b1e06fd7f9be2eb281d26",
"T3T1_fr_test_recovery.py::test_recovery_bip39_previous_word": "996f0fed4bb82ab3c815e5697fe4ac5c81e241da08fcc2de5bf59a0105911691",
"T3T1_fr_test_recovery.py::test_recovery_slip39_basic": "ae737b02fa5dcbcb89d4996f81305ba07d0cc13aeec289045b94402074a09576",
"T3T1_fr_test_repeated_backup.py::test_repeated_backup": "2bf3386dee3dd696764a4f5f59eaf76072b833cadc9c7a79496ac722c21458c9",
"T3T1_fr_test_reset_bip39.py::test_reset_bip39": "7c0ec2b343c28d167670e90cde9e41e007cc0a892042b1a846347ebb06a7a791",