fix(ui): replace f64 precision-lossy max amount calculation with integer arithmetic#622
fix(ui): replace f64 precision-lossy max amount calculation with integer arithmetic#622thepastaclaw wants to merge 1 commit intodashpay:v1.0-devfrom
Conversation
… calculations Replace floating-point round-trip (u64→f64→u64) with integer saturating_sub for fee reservation in Max button calculations. This eliminates precision loss that could cause incorrect max amounts in transfer and withdraw screens. - transfer_screen: 0.0002 DASH = 20_000_000 credits - withdraw_screen: 0.005 DASH = 500_000_000 credits
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Replace floating-point round-trip (
u64→f64→u64) with integersaturating_subfor fee reservation in Max button calculations on transfer and withdraw screens.Problem
The original code converted credits to DASH as
f64, subtracted a fee constant, then converted back tou64:This loses precision in the floating-point round-trip. For example, a balance of exactly
20_000_001credits would produce0.00000000020000001in f64, subtract0.0002, multiply back — and the result may differ from the mathematically correct1due to IEEE 754 representation.Fix
Use integer arithmetic directly on the credit value:
Cherry-picked from
ralph/improvements(commit 1909415).Validation
What was tested:
cargo clippy --all-features --all-targets -- -D warnings— lint checkcargo test --all-features --workspace— full workspace test suiteResults:
ClippyCI check — pass (5m45s)Test SuiteCI check — pass (8m27s)Environment: Local macOS arm64; GitHub Actions CI (ubuntu-latest)