mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-27 01:48:17 +00:00
feat(core/rust): show last entered passphrase character for T2B1
[no changelog]
This commit is contained in:
parent
afa6f84174
commit
272fb4842a
@ -236,6 +236,7 @@ pub struct PassphraseEntry<T: StringType + Clone> {
|
|||||||
choice_page: ChoicePage<ChoiceFactoryPassphrase, T, PassphraseAction>,
|
choice_page: ChoicePage<ChoiceFactoryPassphrase, T, PassphraseAction>,
|
||||||
passphrase_dots: Child<ChangingTextLine<String<MAX_PASSPHRASE_LENGTH>>>,
|
passphrase_dots: Child<ChangingTextLine<String<MAX_PASSPHRASE_LENGTH>>>,
|
||||||
show_plain_passphrase: bool,
|
show_plain_passphrase: bool,
|
||||||
|
show_last_digit: bool,
|
||||||
textbox: TextBox<MAX_PASSPHRASE_LENGTH>,
|
textbox: TextBox<MAX_PASSPHRASE_LENGTH>,
|
||||||
current_category: ChoiceCategory,
|
current_category: ChoiceCategory,
|
||||||
}
|
}
|
||||||
@ -251,6 +252,7 @@ where
|
|||||||
.with_initial_page_counter(random_menu_position()),
|
.with_initial_page_counter(random_menu_position()),
|
||||||
passphrase_dots: Child::new(ChangingTextLine::center_mono(String::new())),
|
passphrase_dots: Child::new(ChangingTextLine::center_mono(String::new())),
|
||||||
show_plain_passphrase: false,
|
show_plain_passphrase: false,
|
||||||
|
show_last_digit: false,
|
||||||
textbox: TextBox::empty(),
|
textbox: TextBox::empty(),
|
||||||
current_category: ChoiceCategory::Menu,
|
current_category: ChoiceCategory::Menu,
|
||||||
}
|
}
|
||||||
@ -259,11 +261,20 @@ where
|
|||||||
fn update_passphrase_dots(&mut self, ctx: &mut EventCtx) {
|
fn update_passphrase_dots(&mut self, ctx: &mut EventCtx) {
|
||||||
let text_to_show = if self.show_plain_passphrase {
|
let text_to_show = if self.show_plain_passphrase {
|
||||||
String::from(self.passphrase())
|
String::from(self.passphrase())
|
||||||
|
} else if self.is_empty() {
|
||||||
|
String::from("")
|
||||||
} else {
|
} else {
|
||||||
|
// Showing asterisks and possibly the last digit.
|
||||||
let mut dots: String<MAX_PASSPHRASE_LENGTH> = String::new();
|
let mut dots: String<MAX_PASSPHRASE_LENGTH> = String::new();
|
||||||
for _ in 0..self.textbox.len() {
|
for _ in 0..self.textbox.len() - 1 {
|
||||||
unwrap!(dots.push_str("*"));
|
unwrap!(dots.push('*'));
|
||||||
}
|
}
|
||||||
|
let last_char = if self.show_last_digit {
|
||||||
|
unwrap!(self.textbox.content().chars().last())
|
||||||
|
} else {
|
||||||
|
'*'
|
||||||
|
};
|
||||||
|
unwrap!(dots.push(last_char));
|
||||||
dots
|
dots
|
||||||
};
|
};
|
||||||
self.passphrase_dots.mutate(ctx, |ctx, passphrase_dots| {
|
self.passphrase_dots.mutate(ctx, |ctx, passphrase_dots| {
|
||||||
@ -332,10 +343,17 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
|
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
|
||||||
// Any event when showing real passphrase should hide it
|
// Any non-timer event when showing real passphrase should hide it
|
||||||
if self.show_plain_passphrase {
|
// Same with showing last digit
|
||||||
self.show_plain_passphrase = false;
|
if !matches!(event, Event::Timer(_)) {
|
||||||
self.update_passphrase_dots(ctx);
|
if self.show_plain_passphrase {
|
||||||
|
self.show_plain_passphrase = false;
|
||||||
|
self.update_passphrase_dots(ctx);
|
||||||
|
}
|
||||||
|
if self.show_last_digit {
|
||||||
|
self.show_last_digit = false;
|
||||||
|
self.update_passphrase_dots(ctx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(action) = self.choice_page.event(ctx, event) {
|
if let Some(action) = self.choice_page.event(ctx, event) {
|
||||||
@ -373,6 +391,7 @@ where
|
|||||||
}
|
}
|
||||||
PassphraseAction::Character(ch) if !self.is_full() => {
|
PassphraseAction::Character(ch) if !self.is_full() => {
|
||||||
self.append_char(ctx, ch);
|
self.append_char(ctx, ch);
|
||||||
|
self.show_last_digit = true;
|
||||||
self.update_passphrase_dots(ctx);
|
self.update_passphrase_dots(ctx);
|
||||||
self.randomize_category_position(ctx);
|
self.randomize_category_position(ctx);
|
||||||
ctx.request_paint();
|
ctx.request_paint();
|
||||||
|
Loading…
Reference in New Issue
Block a user