@@ -16,6 +16,7 @@ use crate::bb02_async::option_no_screensaver;
1616use core:: cell:: RefCell ;
1717
1818use alloc:: boxed:: Box ;
19+ use alloc:: string:: String ;
1920
2021pub struct UserAbort ;
2122
@@ -33,6 +34,10 @@ pub async fn verify_recipient(recipient: &str, amount: &str) -> Result<(), UserA
3334 option_no_screensaver ( & result) . await
3435}
3536
37+ fn format_percentage ( p : f64 ) -> String {
38+ format ! ( "{:.1}" , p)
39+ }
40+
3641pub async fn verify_total_fee (
3742 total : & str ,
3843 fee : & str ,
@@ -57,7 +62,10 @@ pub async fn verify_total_fee(
5762 if let Some ( fee_percentage) = fee_percentage {
5863 match super :: confirm:: confirm ( & super :: confirm:: Params {
5964 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+ ) ,
6169 longtouch : true ,
6270 ..Default :: default ( )
6371 } )
@@ -69,3 +77,17 @@ pub async fn verify_total_fee(
6977 }
7078 Ok ( ( ) )
7179}
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