refactor(rewards): simplify claimable reward calculation and update tests#27473
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. |
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.
03b1479 to
1054f6f
Compare
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection: Performance Test Selection: |
|
✅ E2E Fixture Validation — Schema is up to date |
|
|
|
||
| const mockUseMerklBonusClaim = jest.fn(() => ({ | ||
| claimableReward: { amount: '10' } as { amount: string } | null, | ||
| claimableReward: '10' as string | null, |
There was a problem hiding this comment.
I'm a bit confused why this part changed - was this test wrong before?
There was a problem hiding this comment.
Yep, it was not breaking tests, because it was used in Boolean(claimableReward), so it was returning true, but we changed that part, so we had to fix it




Description
Reason for change: In the Cash section (homepage), the "Claim bonus" CTA was shown even when the claimable mUSD bonus was less than $0.01 (e.g. dust after claiming). Small amounts like 0.007401 were also displayed as "0.01" because the formatting logic rounded to 2 decimals instead of showing "< 0.01".
Improvement / solution:
MusdAggregatedRow (Cash section): Only show the "Claim bonus" button when the claimable reward is at least $0.01. Introduced
MIN_CLAIMABLE_BONUS_USDandisClaimableBonusAboveThreshold(reward); below that threshold the row shows the static "3% bonus" text instead of the CTA.useMerklRewards: Removed use of
renderFromTokenMinimalUnit, which only treated values below 0.00001 as "< 0.00001" and rounded everything else (e.g. 0.007401 → "0.01"). The hook now computes the decimal value asunclaimedBaseUnits / 10^tokenDecimalsand formats it as"< 0.01"when < 0.01, otherwisetoFixed(2). This ensures amounts like 0.007401 display as "< 0.01" and the Cash section threshold logic works correctly.Tests: MusdAggregatedRow tests for the claimable-bonus threshold (hide CTA for "< 0.01", "0.01", "0.005"; show for "0.02"). useMerklRewards tests updated to assert outcomes instead of mocking
renderFromTokenMinimalUnit; added case for 7401 with 6 decimals → "< 0.01".Changelog
CHANGELOG entry: Fixed Cash section showing "Claim bonus" for amounts under $0.01 and corrected display of small claimable amounts as "< 0.01"
Related issues
Fixes: https://consensyssoftware.atlassian.net/browse/MUSD-513
Manual testing steps
Screenshots/Recordings
Before
claim-threshold-before.mov
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Changes reward amount formatting and CTA gating logic in the Cash section; incorrect numeric conversion/rounding (notably
BigInt→Number) could mis-display large rewards or edge-case decimals.Overview
Fixes dust claim UX in the Cash section.
MusdAggregatedRownow only shows the "Claim bonus" CTA when the claimable bonus is at least$0.01; otherwise it shows the static "3% bonus" label (including when the hook returns"< 0.01").Simplifies Merkl claimable reward formatting.
useMerklRewardsdropsrenderFromTokenMinimalUnitand instead computes the decimal amount directly from base units, returning"< 0.01"for anything below$0.01andtoFixed(2)otherwise.Tests updated/added. Merkl reward tests no longer mock the formatter and add coverage for sub-$0.01 amounts (including cases that previously rounded up), and Cash row tests cover the new $0.01 CTA threshold behavior.
Written by Cursor Bugbot for commit 1054f6f. This will update automatically on new commits. Configure here.