refactor(core): address review of the passphrase eye hint
What changed, and why it matters
This commit is a small internal cleanup of the passphrase-entry animation on Trezor hardware wallets. It renames timers, computes an animation value once instead of twice, and moves responsibility for redrawing to the caller. There is no indication this fixes a security bug or changes user-visible behavior beyond making the animation code tidier.
No security action required; treat as normal code-quality refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change refactors EyeHintAnimation in the Rust UI code. It replaces separate icon_progress/content_progress calculations with a single progress() value and a derived content_progress(progress) helper, renames delay/timer fields for clarity, and changes process() so it returns true when the animation advanced but no longer calls ctx.request_paint() itself; callers now call request_paint() after process() returns true. The passphrase input event handlers in Delizia and Eckhart layouts are updated accordingly. No cryptographic, input-validation, or access-control logic is touched.
Changed components
core/embed/rust/src/ui/component/eye_hint.rscore/embed/rust/src/ui/layout_delizia/component/keyboard/passphrase.rscore/embed/rust/src/ui/layout_eckhart/firmware/keyboard/passphrase.rsInspect captured patch +53 / −49
### core/embed/rust/src/ui/component/eye_hint.rs
@@ -11,16 +11,17 @@ use crate::ui::util::animation_disabled;
/// while the hidden characters move right to make room for it.
pub struct EyeHintAnimation {
/// One-shot timer for the pause before the slide-in.
- delay: Timer,
- timer: Stopwatch,
+ delay_timer: Timer,
+ /// Measures the slide-in once it starts.
+ animation_watch: Stopwatch,
visible: bool,
}
impl Default for EyeHintAnimation {
fn default() -> Self {
Self {
- delay: Timer::new(),
- timer: Stopwatch::new_stopped(),
+ delay_timer: Timer::new(),
+ animation_watch: Stopwatch::new_stopped(),
visible: false,
}
}
@@ -29,78 +30,73 @@ impl Default for EyeHintAnimation {
impl EyeHintAnimation {
/// Pause between the first character being hidden and the slide-in.
const START_DELAY: Duration = Duration::from_millis(200);
- /// Duration of the eye icon slide-in.
+ /// Duration of the slide-in.
const DURATION: Duration = Duration::from_millis(205);
/// Delay before the hidden characters start moving, from the slide-in
/// start.
const CONTENT_DELAY: Duration = Duration::from_millis(65);
+ const INV_DURATION_MS: f32 = 1.0 / Self::DURATION.to_millis() as f32;
+ /// Slide-in progress at which the hidden characters start moving.
+ const CONTENT_START: f32 = Self::CONTENT_DELAY.to_millis() as f32 * Self::INV_DURATION_MS;
+ const CONTENT_SCALE: f32 = 1.0 / (1.0 - Self::CONTENT_START);
+
/// Start the slide-in when the icon becomes visible, reset it when the
/// icon is hidden.
pub fn set_visible(&mut self, ctx: &mut EventCtx, visible: bool) {
if visible == self.visible {
return;
}
self.visible = visible;
- self.delay.stop();
- self.timer = Stopwatch::new_stopped();
+ self.delay_timer.stop();
+ self.animation_watch = Stopwatch::new_stopped();
if visible && !animation_disabled() {
- self.delay.start(ctx, Self::START_DELAY);
+ self.delay_timer.start(ctx, Self::START_DELAY);
}
ctx.request_paint();
}
/// Start the slide-in once the pause is over and keep requesting animation
- /// frames while it runs. Returns `true` when the input should be
- /// repainted.
+ /// frames while it runs. Returns `true` when the slide-in has moved and
+ /// the input needs to be repainted; repainting is left to the caller.
pub fn process(&mut self, ctx: &mut EventCtx, event: Event) -> bool {
- if self.delay.expire(event) {
- self.timer.start();
+ if self.delay_timer.expire(event) {
+ self.animation_watch.start();
ctx.request_anim_frame();
return false;
}
- if !matches!(event, Event::Timer(EventCtx::ANIM_FRAME_TIMER)) || !self.timer.is_running() {
+ if !EventCtx::is_anim_frame(event) || !self.animation_watch.is_running() {
return false;
}
- if self.timer.is_running_within(Self::DURATION) {
+ if self.animation_watch.is_running_within(Self::DURATION) {
ctx.request_anim_frame();
} else {
- self.timer = Stopwatch::new_stopped();
+ self.animation_watch = Stopwatch::new_stopped();
}
- ctx.request_paint();
true
}
pub fn is_visible(&self) -> bool {
self.visible
}
- /// Progress of the eye icon, from 0.0 (off its place) to 1.0 (in place).
- pub fn icon_progress(&self) -> f32 {
- self.progress(Duration::ZERO)
- }
-
- /// Progress of the hidden characters, from 0.0 (start position) to 1.0
- /// (in place next to the icon).
- pub fn content_progress(&self) -> f32 {
- self.progress(Self::CONTENT_DELAY)
- }
-
- fn progress(&self, delay: Duration) -> f32 {
- if !self.visible || self.delay.is_running() {
+ /// Progress of the slide-in, from 0.0 (eye icon off its place) to 1.0 (in
+ /// place).
+ pub fn progress(&self) -> f32 {
+ if !self.visible || self.delay_timer.is_running() {
return 0.0;
}
- if !self.timer.is_running() {
+ if !self.animation_watch.is_running() {
return 1.0;
}
- let elapsed = self.timer.elapsed();
- match (
- elapsed.checked_sub(delay),
- Self::DURATION.checked_sub(delay),
- ) {
- (Some(elapsed), Some(duration)) => (elapsed / duration).min(1.0),
- _ => 0.0,
- }
+ let elapsed_ms = self.animation_watch.elapsed().to_millis() as f32;
+ (elapsed_ms * Self::INV_DURATION_MS).min(1.0)
+ }
+
+ /// Progress of the hidden characters for a given slide-in `progress`. They
+ /// start moving after `CONTENT_DELAY` and arrive together with the icon.
+ pub fn content_progress(progress: f32) -> f32 {
+ ((progress - Self::CONTENT_START) * Self::CONTENT_SCALE).clamp(0.0, 1.0)
}
/// Offset of an element sliding `distance` pixels into place.
### core/embed/rust/src/ui/layout_delizia/component/keyboard/passphrase.rs
@@ -612,8 +612,12 @@ impl Input {
debug_assert_ne!(self.display_style, DisplayStyle::Shown);
let style = theme::label_keyboard();
+ let eye_progress = self.eye_hint.progress();
let dots_offset = Self::DOTS_OFFSET
- + EyeHintAnimation::offset(self.eye_hint.content_progress(), Self::DOTS_SLIDE);
+ + EyeHintAnimation::offset(
+ EyeHintAnimation::content_progress(eye_progress),
+ Self::DOTS_SLIDE,
+ );
let mut cursor = self.area.left_center().ofs(Offset::x(dots_offset));
let pp_len = self.textbox.count();
@@ -629,7 +633,7 @@ impl Input {
// Eye icon hinting that holding the input reveals the passphrase
if self.eye_hint.is_visible() {
let eye_offset = Self::EYE_ICON_PADDING
- + EyeHintAnimation::offset(self.eye_hint.icon_progress(), Self::EYE_ICON_SLIDE);
+ + EyeHintAnimation::offset(eye_progress, Self::EYE_ICON_SLIDE);
ToifImage::new(
self.area.left_center().ofs(Offset::x(eye_offset)),
theme::ICON_EYE.toif,
@@ -713,14 +717,12 @@ impl Component for Input {
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
if self.eye_hint.process(ctx, event) {
self.pad.clear();
- }
-
- if self.textbox.is_empty() {
- self.update_eye_hint(ctx);
- return None;
+ ctx.request_paint();
}
match event {
+ // No touch events are handled when the textbox is empty
+ _ if self.textbox.is_empty() => {}
// Reveal on touch start within the input area
Event::Touch(TouchEvent::TouchStart(pos)) if self.area.contains(pos) => {
self.multi_tap.clear_pending_state(ctx);
### core/embed/rust/src/ui/layout_eckhart/firmware/keyboard/passphrase.rs
@@ -127,10 +127,11 @@ impl PassphraseInput {
return;
}
+ let eye_progress = self.eye_hint.progress();
+
// Eye icon hinting that holding the input reveals the passphrase
if self.eye_hint.is_visible() {
- let eye_offset =
- EyeHintAnimation::offset(self.eye_hint.icon_progress(), Self::EYE_ICON_SLIDE);
+ let eye_offset = EyeHintAnimation::offset(eye_progress, Self::EYE_ICON_SLIDE);
ToifImage::new(
hidden_area.left_center().ofs(Offset::x(eye_offset)),
theme::ICON_EYE.toif,
@@ -142,7 +143,10 @@ impl PassphraseInput {
let dashes_offset = theme::ICON_EYE.toif.width()
+ Self::EYE_ICON_SPACE
- + EyeHintAnimation::offset(self.eye_hint.content_progress(), Self::DASHES_SLIDE);
+ + EyeHintAnimation::offset(
+ EyeHintAnimation::content_progress(eye_progress),
+ Self::DASHES_SLIDE,
+ );
let mut cursor = hidden_area.left_center().ofs(Offset::x(dashes_offset));
// Number of visible icons + characters
@@ -368,7 +372,9 @@ impl Component for PassphraseInput {
}
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
- self.eye_hint.process(ctx, event);
+ if self.eye_hint.process(ctx, event) {
+ ctx.request_paint();
+ }
let msg = self.handle_event(ctx, event);
self.update_eye_hint(ctx);
msgWhy this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.