Skip to content

Commit

Permalink
fix(price-printer): make amount stay >0.
Browse files Browse the repository at this point in the history
Fix a bug where the amount would become 0 if there was a negative decimals difference between previous and current token in.
  • Loading branch information
zizou0x committed Mar 6, 2025
1 parent a606597 commit 6d8cf77
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion examples/price_printer/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ impl App {
if decimals >= prev_decimals {
self.quote_amount *= BigUint::from(10u64).pow((decimals - prev_decimals) as u32);
} else {
self.quote_amount /= BigUint::from(10u64).pow((prev_decimals - decimals) as u32);
let new_amount = self.quote_amount.clone() /
BigUint::from(10u64).pow((prev_decimals - decimals) as u32);
self.quote_amount =
if new_amount > BigUint::ZERO { new_amount } else { BigUint::one() };
}
}
}
Expand Down

0 comments on commit 6d8cf77

Please sign in to comment.