fix: only show claim button if there is at least 1 cent of rewards#40444
fix: only show claim button if there is at least 1 cent of rewards#40444
Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
✨ Files requiring CODEOWNER review ✨👨🔧 @MetaMask/metamask-earn (2 files, +67 -1)
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
| if (!abortController.signal.aborted) { | ||
| setHasClaimableReward(unclaimedBaseUnits > 0n); | ||
| const oneCentInBaseUnits = | ||
| 10n ** BigInt(matchingReward.token.decimals - 2); |
There was a problem hiding this comment.
Negative BigInt exponent crashes for low-decimal tokens
Low Severity
The expression 10n ** BigInt(matchingReward.token.decimals - 2) throws a RangeError if decimals is 0 or 1, since BigInt exponentiation doesn't support negative exponents. The decimals field comes from an external API (MerklReward.token.decimals typed as number), so there's no compile-time guarantee it's >= 2. While the surrounding try-catch prevents a full crash, it silently causes hasClaimableReward to remain false, hiding legitimate claimable rewards from the user.
Builds ready [37b3a22]
⚡ Performance Benchmarks
🌐 Dapp Page Load BenchmarksCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
|





Description
Updates the useMerklRewards hook to only say that there are claimable rewards, if those rewards are at least $0.01 MUSD. Adds tests for the failure case, and the case where we have exactly 1 cent!
Changelog
CHANGELOG entry: only show claim bonus CTA if there is at least 1 cent to claim
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Low Risk
Low risk: small UI gating change in
useMerklRewardsplus unit tests; main risk is edge-case handling for unusual token decimals affecting the 1-cent threshold calculation.Overview
Updates
useMerklRewardsto only sethasClaimableRewardwhen unclaimed rewards are at least $0.01 (computed as10^(decimals-2)base units) instead of any positive amount.Adds tests to assert sub-cent unclaimed amounts return false and an exact 1-cent amount returns true.
Written by Cursor Bugbot for commit 37b3a22. This will update automatically on new commits. Configure here.