Skip to content

fix(ui): replace f64 precision-lossy max amount calculation with integer arithmetic#622

Draft
thepastaclaw wants to merge 1 commit intodashpay:v1.0-devfrom
thepastaclaw:fix/integer-max-amount
Draft

fix(ui): replace f64 precision-lossy max amount calculation with integer arithmetic#622
thepastaclaw wants to merge 1 commit intodashpay:v1.0-devfrom
thepastaclaw:fix/integer-max-amount

Conversation

@thepastaclaw
Copy link
Collaborator

@thepastaclaw thepastaclaw commented Feb 22, 2026

Replace floating-point round-trip (u64→f64→u64) with integer saturating_sub for 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 to u64:

let max_amount_minus_fee = (self.max_amount as f64 / 100_000_000_000.0 - 0.0002).max(0.0);
let max_amount_credits = (max_amount_minus_fee * 100_000_000_000.0) as u64;

This loses precision in the floating-point round-trip. For example, a balance of exactly 20_000_001 credits would produce 0.00000000020000001 in f64, subtract 0.0002, multiply back — and the result may differ from the mathematically correct 1 due to IEEE 754 representation.

Fix

Use integer arithmetic directly on the credit value:

// 0.0002 DASH = 20_000_000 credits
let max_amount_credits = self.max_amount.saturating_sub(20_000_000);

Cherry-picked from ralph/improvements (commit 1909415).

Validation

What was tested:

  • cargo clippy --all-features --all-targets -- -D warnings — lint check
  • cargo test --all-features --workspace — full workspace test suite

Results:

  • All local commands passed
  • Clippy CI check — pass (5m45s)
  • Test Suite CI check — pass (8m27s)

Environment: Local macOS arm64; GitHub Actions CI (ubuntu-latest)

… 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
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 22, 2026

Warning

Rate limit exceeded

@thepastaclaw has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 6 minutes and 49 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@thepastaclaw
Copy link
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 22, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@thepastaclaw thepastaclaw marked this pull request as draft February 25, 2026 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants