@@ -16,6 +16,7 @@ use crate::bb02_async::option_no_screensaver;
16
16
use core:: cell:: RefCell ;
17
17
18
18
use alloc:: boxed:: Box ;
19
+ use alloc:: string:: String ;
19
20
20
21
pub struct UserAbort ;
21
22
@@ -33,6 +34,10 @@ pub async fn verify_recipient(recipient: &str, amount: &str) -> Result<(), UserA
33
34
option_no_screensaver ( & result) . await
34
35
}
35
36
37
+ fn format_percentage ( p : f64 ) -> String {
38
+ format ! ( "{:.1}" , p)
39
+ }
40
+
36
41
pub async fn verify_total_fee (
37
42
total : & str ,
38
43
fee : & str ,
@@ -57,7 +62,10 @@ pub async fn verify_total_fee(
57
62
if let Some ( fee_percentage) = fee_percentage {
58
63
match super :: confirm:: confirm ( & super :: confirm:: Params {
59
64
title : "High fee" ,
60
- body : & format ! ( "The fee is {:.1}%\n the send amount.\n Proceed?" , fee_percentage) ,
65
+ body : & format ! (
66
+ "The fee is {}%\n the send amount.\n Proceed?" ,
67
+ format_percentage( fee_percentage)
68
+ ) ,
61
69
longtouch : true ,
62
70
..Default :: default ( )
63
71
} )
@@ -69,3 +77,17 @@ pub async fn verify_total_fee(
69
77
}
70
78
Ok ( ( ) )
71
79
}
80
+
81
+ #[ cfg( test) ]
82
+ mod tests {
83
+ use super :: * ;
84
+
85
+ #[ test]
86
+ fn test_format_percentage ( ) {
87
+ assert_eq ! ( format_percentage( 0. ) , "0.0" ) ;
88
+ assert_eq ! ( format_percentage( 10.0 ) , "10.0" ) ;
89
+ assert_eq ! ( format_percentage( 10.1 ) , "10.1" ) ;
90
+ assert_eq ! ( format_percentage( 10.14 ) , "10.1" ) ;
91
+ assert_eq ! ( format_percentage( 10.15 ) , "10.2" ) ;
92
+ }
93
+ }
0 commit comments