diff --git a/core/embed/rust/src/ui/model_tt/component/number_input.rs b/core/embed/rust/src/ui/model_tt/component/number_input.rs index 619583d861..c36df7ae9d 100644 --- a/core/embed/rust/src/ui/model_tt/component/number_input.rs +++ b/core/embed/rust/src/ui/model_tt/component/number_input.rs @@ -1,13 +1,15 @@ -use crate::ui::{ - component::{ - base::ComponentExt, - paginated::Paginate, - text::paragraphs::{Paragraph, ParagraphStrType, Paragraphs}, - Child, Component, Event, EventCtx, Pad, +use crate::{ + strutil, + ui::{ + component::{ + base::ComponentExt, + paginated::Paginate, + text::paragraphs::{Paragraph, ParagraphStrType, Paragraphs}, + Child, Component, Event, EventCtx, Pad, + }, + display::{self, Font}, + geometry::{Grid, Insets, Offset, Rect}, }, - display::{self, Font}, - geometry::{Grid, Insets, Offset, Rect}, - util, }; use super::{theme, Button, ButtonMsg}; @@ -210,7 +212,7 @@ impl Component for NumberInput { fn paint(&mut self) { let mut buf = [0u8; 10]; - if let Some(text) = util::u32_to_str(self.value, &mut buf) { + if let Some(text) = strutil::format_i64(self.value as i64, &mut buf) { let digit_font = Font::DEMIBOLD; let y_offset = digit_font.text_height() / 2 + Button::<&str>::BASELINE_OFFSET; display::rect_fill(self.area, theme::BG); diff --git a/core/embed/rust/src/ui/util.rs b/core/embed/rust/src/ui/util.rs index ae74212549..c332c5cbdc 100644 --- a/core/embed/rust/src/ui/util.rs +++ b/core/embed/rust/src/ui/util.rs @@ -20,26 +20,6 @@ impl ResultExt for Result { } } -pub fn u32_to_str(num: u32, buffer: &mut [u8]) -> Option<&str> { - let mut i = 0; - let mut num = num; - - while num > 0 && i < buffer.len() { - buffer[i] = b'0' + ((num % 10) as u8); - num /= 10; - i += 1; - } - match i { - 0 => Some("0"), - _ if num > 0 => None, - _ => { - let result = &mut buffer[..i]; - result.reverse(); - Some(core::str::from_utf8(result).unwrap()) - } - } -} - /// Constructs a string from a C string. /// /// # Safety @@ -140,7 +120,7 @@ pub fn icon_text_center( #[cfg(test)] mod tests { - use super::*; + use crate::strutil; #[test] fn u32_to_str_valid() { @@ -148,7 +128,7 @@ mod tests { let mut b = [0; 10]; for test in testcases { - let converted = u32_to_str(test, &mut b).unwrap(); + let converted = strutil::format_i64(test as i64, &mut b).unwrap(); let s = test.to_string(); assert_eq!(converted, s); } @@ -160,7 +140,7 @@ mod tests { let mut b = [0; 3]; for test in testcases { - let converted = u32_to_str(test, &mut b); + let converted = strutil::format_i64(test as i64, &mut b); assert_eq!(converted, None) } }