Skip to content

Commit 2f8e2e0

Browse files
committed
Merge remote-tracking branch 'benma/feerate'
2 parents a74df47 + 61a82ff commit 2f8e2e0

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

.ci/ci

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ make -j8 factory-setup
5353
make -j8 bootloader-semihosting
5454
make -j8 firmware-semihosting
5555

56+
# Disallow some symbols in the final binary that we don't want.
57+
if arm-none-eabi-nm build/bin/firmware.elf | grep -q "float_to_decimal_common_shortest"; then
58+
echo "Rust fmt float formatting like {.1} adds significant binary bloat."
59+
echo "Use something simpler like (float*10).round() as u64, then format with util::decimal::format"
60+
exit 1
61+
fi
62+
5663
(cd tools/atecc608; go test ./...)
5764

5865
# Don't generate graphics in CI

src/rust/bitbox02-rust/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ sha3 = { workspace = true, optional = true }
3838
digest = "0.10.6"
3939
zeroize = { workspace = true }
4040
num-bigint = { workspace = true, optional = true }
41-
num-traits = { version = "0.2", default-features = false, optional = true }
41+
num-traits = { version = "0.2", default-features = false }
4242
# If you change this, also change src/rust/.cargo/config.toml.
4343
bip32-ed25519 = { git = "https://github.com/digitalbitbox/rust-bip32-ed25519", tag = "v0.1.2", optional = true }
4444
bech32 = { version = "0.11.0", default-features = false, features = ["alloc"], optional = true }
@@ -74,7 +74,6 @@ app-ethereum = [
7474
"erc20_params",
7575
"sha3",
7676
"num-bigint",
77-
"num-traits",
7877
# enable this feature in the deps
7978
"bitbox02/app-ethereum",
8079
]

src/rust/bitbox02-rust/src/workflow/transaction.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::bb02_async::option_no_screensaver;
1616
use core::cell::RefCell;
1717

1818
use alloc::boxed::Box;
19+
use alloc::string::String;
1920

2021
pub struct UserAbort;
2122

@@ -33,6 +34,11 @@ 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+
let int: u64 = num_traits::float::FloatCore::round(p * 10.) as _;
39+
util::decimal::format_no_trim(int, 1)
40+
}
41+
3642
pub async fn verify_total_fee(
3743
total: &str,
3844
fee: &str,
@@ -57,7 +63,10 @@ pub async fn verify_total_fee(
5763
if let Some(fee_percentage) = fee_percentage {
5864
match super::confirm::confirm(&super::confirm::Params {
5965
title: "High fee",
60-
body: &format!("The fee is {:.1}%\nthe send amount.\nProceed?", fee_percentage),
66+
body: &format!(
67+
"The fee is {}%\nthe send amount.\nProceed?",
68+
format_percentage(fee_percentage)
69+
),
6170
longtouch: true,
6271
..Default::default()
6372
})
@@ -69,3 +78,17 @@ pub async fn verify_total_fee(
6978
}
7079
Ok(())
7180
}
81+
82+
#[cfg(test)]
83+
mod tests {
84+
use super::*;
85+
86+
#[test]
87+
fn test_format_percentage() {
88+
assert_eq!(format_percentage(0.), "0.0");
89+
assert_eq!(format_percentage(10.0), "10.0");
90+
assert_eq!(format_percentage(10.1), "10.1");
91+
assert_eq!(format_percentage(10.14), "10.1");
92+
assert_eq!(format_percentage(10.15), "10.2");
93+
}
94+
}

0 commit comments

Comments
 (0)