Commit 3574cb5
authored
fix(predict): round fee decimals to avoid underflow errors (#22361)
## **Description**
Fixed a floating-point precision issue in the Polymarket fee calculation
that was causing order placement failures. When calculating fees (e.g.,
for a $7.40 bet), JavaScript floating-point arithmetic would produce
values with excessive decimal places (e.g., 0.29600000000000004), which
would later fail when passed to `parseUnits`. The fix rounds the fee to
4 decimal places to prevent these precision errors while maintaining
sufficient accuracy for fee calculations.
## **Changelog**
CHANGELOG entry: null
## **Related issues**
Fixes:
## **Manual testing steps**
```gherkin
Feature: Polymarket bet placement
Scenario: user places a bet with amount that triggers floating-point precision issue
Given user is on the Predict feature
And user has selected a Polymarket prediction market
When user enters a bet amount of $7.40
And user confirms the bet placement
Then the order should be successfully placed without errors
```
## **Screenshots/Recordings**
### **Before**
Order placement would fail with parseUnits error when fee calculation
resulted in values like 0.29600000000000004
### **After**
Order placement succeeds as fee is properly rounded to 0.2960 (4 decimal
places)
## **Pre-merge author checklist**
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I've included tests if applicable
- [x] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I've applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **Pre-merge reviewer checklist**
- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Round `totalFee` to 4 decimals in `calculateFees` to prevent
floating-point precision issues.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
b198cda. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent deb715d commit 3574cb5
1 file changed
+3
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
756 | 756 | | |
757 | 757 | | |
758 | 758 | | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
759 | 762 | | |
760 | 763 | | |
761 | 764 | | |
| |||
0 commit comments