Skip to content

Commit

Permalink
Rename into_decimal_str to into_percentage_str in PerThousand
Browse files Browse the repository at this point in the history
  • Loading branch information
TheQuantumPhysicist committed Feb 1, 2024
1 parent c48230d commit d00262c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion common/src/chain/transaction/printout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub fn transaction_summary(tx: &Transaction, chain_config: &ChainConfig) -> Stri
fmt_dest(p.staker()),
fmt_vrf(p.vrf_public_key()),
fmt_dest(p.decommission_key()),
p.margin_ratio_per_thousand().into_decimal_str(),
p.margin_ratio_per_thousand().into_percentage_str(),
fmt_ml(&p.cost_per_block())
)
};
Expand Down
38 changes: 25 additions & 13 deletions common/src/primitives/per_thousand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl PerThousand {
Some(result)
}

pub fn into_decimal_str(&self) -> String {
pub fn into_percentage_str(&self) -> String {
format!(
"{}%",
Amount::from_atoms(self.0.into()).into_fixedpoint_str(1)
Expand Down Expand Up @@ -120,18 +120,30 @@ mod tests {

#[test]
fn test_into_decimal_str() {
assert_eq!(PerThousand::new(1).unwrap().into_decimal_str(), "0.1%");
assert_eq!(PerThousand::new(10).unwrap().into_decimal_str(), "1%");
assert_eq!(PerThousand::new(100).unwrap().into_decimal_str(), "10%");
assert_eq!(PerThousand::new(1000).unwrap().into_decimal_str(), "100%");

assert_eq!(PerThousand::new(11).unwrap().into_decimal_str(), "1.1%");
assert_eq!(PerThousand::new(23).unwrap().into_decimal_str(), "2.3%");
assert_eq!(PerThousand::new(98).unwrap().into_decimal_str(), "9.8%");

assert_eq!(PerThousand::new(311).unwrap().into_decimal_str(), "31.1%");
assert_eq!(PerThousand::new(564).unwrap().into_decimal_str(), "56.4%");
assert_eq!(PerThousand::new(827).unwrap().into_decimal_str(), "82.7%");
assert_eq!(PerThousand::new(1).unwrap().into_percentage_str(), "0.1%");
assert_eq!(PerThousand::new(10).unwrap().into_percentage_str(), "1%");
assert_eq!(PerThousand::new(100).unwrap().into_percentage_str(), "10%");
assert_eq!(
PerThousand::new(1000).unwrap().into_percentage_str(),
"100%"
);

assert_eq!(PerThousand::new(11).unwrap().into_percentage_str(), "1.1%");
assert_eq!(PerThousand::new(23).unwrap().into_percentage_str(), "2.3%");
assert_eq!(PerThousand::new(98).unwrap().into_percentage_str(), "9.8%");

assert_eq!(
PerThousand::new(311).unwrap().into_percentage_str(),
"31.1%"
);
assert_eq!(
PerThousand::new(564).unwrap().into_percentage_str(),
"56.4%"
);
assert_eq!(
PerThousand::new(827).unwrap().into_percentage_str(),
"82.7%"
);
}

#[rstest]
Expand Down
2 changes: 1 addition & 1 deletion node-gui/src/main_window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn print_coin_amount(chain_config: &ChainConfig, value: Amount) -> String {
}

fn print_margin_ratio(value: PerThousand) -> String {
value.into_decimal_str()
value.into_percentage_str()
}

fn print_coin_amount_with_ticker(chain_config: &ChainConfig, value: Amount) -> String {
Expand Down

0 comments on commit d00262c

Please sign in to comment.