1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-19 05:58:09 +00:00

fix(core/ui): fix persistent word during recovery

Remove the current word from recovery progress if a user goes to
previous word.

[no changelog]
This commit is contained in:
obrusvit 2024-08-17 16:49:03 +02:00 committed by Vít Obrusník
parent 65d3fd00f1
commit f0989e20b8
4 changed files with 15 additions and 19 deletions

View File

@ -0,0 +1 @@
Fix persistent word when going to previous word during recovery process.

View File

@ -1,10 +1,7 @@
use crate::{
strutil::TString,
ui::{
component::{
maybe::paint_overlapping, Component, Event, EventCtx, Label, Maybe, Swipe,
SwipeDirection,
},
component::{maybe::paint_overlapping, Component, Event, EventCtx, Label, Maybe},
geometry::{Alignment, Grid, Insets, Rect},
model_mercury::{
component::{Button, ButtonMsg},
@ -35,8 +32,6 @@ pub struct MnemonicKeyboard<T> {
keypad_area: Rect,
/// Key buttons.
keys: [Button; MNEMONIC_KEY_COUNT],
/// Swipe controller - allowing for going to the previous word.
swipe: Swipe,
/// Whether going back is allowed (is not on the very first word).
can_go_back: bool,
}
@ -78,7 +73,6 @@ where
input: Maybe::new(theme::BG, input, !prompt_visible),
keypad_area: Rect::zero(),
keys,
swipe: Swipe::new().right(),
can_go_back,
}
}
@ -136,7 +130,6 @@ where
let input_area = input_area.inset(Insets::left(BACK_BUTTON_RIGHT_EXPAND));
let keyboard_grid = Grid::new(keypad_area, 3, 3).with_spacing(theme::KEYBOARD_SPACING);
self.swipe.place(bounds);
self.prompt.place(prompt_area);
self.erase.place(back_btn_area);
self.back.place(back_btn_area);
@ -149,14 +142,11 @@ where
}
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
// Back button or swipe will cause going back to the previous word when allowed.
// Back button will cause going back to the previous word when allowed.
if self.can_go_back {
if let Some(ButtonMsg::Clicked) = self.back.event(ctx, event) {
return Some(MnemonicKeyboardMsg::Previous);
}
if let Some(SwipeDirection::Right) = self.swipe.event(ctx, event) {
return Some(MnemonicKeyboardMsg::Previous);
}
}
match self.input.event(ctx, event) {

View File

@ -27,14 +27,14 @@ async def request_mnemonic(
await button_request("mnemonic", code=ButtonRequestType.MnemonicInput)
# Allowing to go back to previous words, therefore cannot use just loop over range(word_count)
# Pre-allocate the list to enable going back and overwriting words.
words: list[str] = [""] * word_count
i = 0
while True:
# All the words have been entered
if i >= word_count:
break
def all_words_entered() -> bool:
return i >= word_count
while not all_words_entered():
# Prefilling the previously inputted word in case of going back
word = await request_word(
i,
@ -43,9 +43,10 @@ async def request_mnemonic(
prefill_word=words[i],
)
# User has decided to go back
if not word:
# User has decided to go back
if i > 0:
words[i] = ""
i -= 1
continue

View File

@ -222,7 +222,7 @@ def enter_seed_previous_correct(
if go_back:
go_back = False
if debug.model in (models.T2T1, models.T3T1):
if debug.model in (models.T2T1,):
debug.swipe_right(wait=True)
for _ in range(len(bad_word)):
debug.click(buttons.RECOVERY_DELETE, wait=True)
@ -237,6 +237,10 @@ def enter_seed_previous_correct(
while layout.get_middle_choice() not in DELETE_BTN_TEXTS:
layout = debug.press_left(wait=True)
layout = debug.press_middle(wait=True)
elif debug.model in (models.T3T1,):
debug.click(buttons.RECOVERY_DELETE, wait=True) # Top-left
for _ in range(len(bad_word)):
debug.click(buttons.RECOVERY_DELETE, wait=True)
continue
if i in bad_indexes: