Merge #1219: GUI: Fix amount rendering

e79674972d668d823d582cb01923af8598cbe674 gui: remove extra spacing for amounts and default amounts which don't contain a non-zero character to 0.00000000 (Aaron Carlucci)

Pull request description:

  This PR attempts to address #1218 by removing extra spacing for amount rendering and making the default for amounts which don' contain a non-zero character to "0.00000000".

ACKs for top commit:
  edouardparis:
    ACK e79674972d668d823d582cb01923af8598cbe674

Tree-SHA512: f9b9e957760139251c4786679fc808447909f80ab2274f6b21222d840418f5d2b79faff759a66d7a36f05ababedab42a7aba85a5ea8a3f4586713b0c873e96d9
This commit is contained in:
edouardparis 2024-08-01 10:07:41 +02:00
commit b94796828d
No known key found for this signature in database
GPG Key ID: E65F7A089C20DC8F

View File

@ -72,11 +72,10 @@ fn render_amount<'a, T: 'a>(amount: String, size: u16) -> Row<'a, T> {
let (before, after) = match split_at_first_non_zero(amount) {
Some((b, a)) => (b, a),
None => (String::from(""), String::from("")),
None => (String::from("0.00 000 000"), String::from("")),
};
let row = Row::new()
.spacing(spacing)
.push(text(before).size(size).style(color::GREY_3))
.push(text(after).size(size).bold());
@ -92,12 +91,8 @@ fn render_amount<'a, T: 'a>(amount: String, size: u16) -> Row<'a, T> {
fn render_unconfirmed_amount<'a, T: 'a>(amount: String, size: u16) -> Row<'a, T> {
let spacing = if size > P1_SIZE { 10 } else { 5 };
let row = Row::new()
.spacing(spacing)
.push(text(amount).size(size).style(color::GREY_3));
Row::with_children(vec![
row.into(),
text(amount).size(size).style(color::GREY_3).into(),
text("BTC").size(size).style(color::GREY_3).into(),
])
.spacing(spacing)
@ -122,5 +117,9 @@ mod tests {
"1 000.00 000 000",
amount_as_string(bitcoin::Amount::from_btc(1000.0).unwrap())
);
assert_eq!(
"0.00 012 340",
amount_as_string(bitcoin::Amount::from_btc(0.00012340).unwrap())
)
}
}