mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 22:38:08 +00:00
feat(core): forcing the letter to always change after selection in T2B1 recovery
[no changelog]
This commit is contained in:
parent
5ab4f1a45a
commit
a3f137d488
@ -157,19 +157,49 @@ where
|
|||||||
ChoiceFactoryWordlist::new(self.wordlist_type, self.textbox.content())
|
ChoiceFactoryWordlist::new(self.wordlist_type, self.textbox.content())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_last_textbox_letter(&self) -> Option<char> {
|
||||||
|
self.textbox.content().chars().last()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_new_page_counter(&self, new_choices: &ChoiceFactoryWordlist) -> usize {
|
||||||
|
// Starting at the random position in case of letters and at the beginning in
|
||||||
|
// case of words.
|
||||||
|
if self.offer_words {
|
||||||
|
INITIAL_PAGE_COUNTER
|
||||||
|
} else {
|
||||||
|
let choices_count = <ChoiceFactoryWordlist as ChoiceFactory<T>>::count(new_choices);
|
||||||
|
// There should be always DELETE and at least one letter
|
||||||
|
assert!(choices_count > 1);
|
||||||
|
if choices_count == 2 {
|
||||||
|
// In case there is only DELETE and one letter, starting on that letter
|
||||||
|
// (regardless of the last letter in the textbox)
|
||||||
|
return INITIAL_PAGE_COUNTER;
|
||||||
|
}
|
||||||
|
// We do not want to end up at the same letter as the last one in the textbox
|
||||||
|
loop {
|
||||||
|
let random_position = get_random_position(choices_count);
|
||||||
|
let current_action =
|
||||||
|
<ChoiceFactoryWordlist as ChoiceFactory<T>>::get(new_choices, random_position)
|
||||||
|
.1;
|
||||||
|
if let WordlistAction::Letter(current_letter) = current_action {
|
||||||
|
if let Some(last_letter) = self.get_last_textbox_letter() {
|
||||||
|
if current_letter == last_letter {
|
||||||
|
// Randomly trying again when the last and current letter match
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break random_position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Updates the whole page.
|
/// Updates the whole page.
|
||||||
fn update(&mut self, ctx: &mut EventCtx) {
|
fn update(&mut self, ctx: &mut EventCtx) {
|
||||||
self.update_chosen_letters(ctx);
|
self.update_chosen_letters(ctx);
|
||||||
let new_choices = self.get_current_choices();
|
let new_choices = self.get_current_choices();
|
||||||
self.offer_words = new_choices.offer_words;
|
self.offer_words = new_choices.offer_words;
|
||||||
// Starting at the random position in case of letters and at the beginning in
|
let new_page_counter = self.get_new_page_counter(&new_choices);
|
||||||
// case of words
|
|
||||||
let new_page_counter = if self.offer_words {
|
|
||||||
INITIAL_PAGE_COUNTER
|
|
||||||
} else {
|
|
||||||
let choices_count = <ChoiceFactoryWordlist as ChoiceFactory<T>>::count(&new_choices);
|
|
||||||
get_random_position(choices_count)
|
|
||||||
};
|
|
||||||
// Not using carousel in case of words, as that looks weird in case
|
// Not using carousel in case of words, as that looks weird in case
|
||||||
// there is only one word to choose from.
|
// there is only one word to choose from.
|
||||||
self.choice_page
|
self.choice_page
|
||||||
|
Loading…
Reference in New Issue
Block a user