Skip to content

refactor(rewards): simplify claimable reward calculation and update tests#27473

Merged
PatrykLucka merged 2 commits into
mainfrom
MUSD-513-claim-cta-re-appears-after-claiming-even-if-claimable-amount-is-dust
Mar 16, 2026
Merged

refactor(rewards): simplify claimable reward calculation and update tests#27473
PatrykLucka merged 2 commits into
mainfrom
MUSD-513-claim-cta-re-appears-after-claiming-even-if-claimable-amount-is-dust

Conversation

@PatrykLucka

@PatrykLucka PatrykLucka commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

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:

  1. MusdAggregatedRow (Cash section): Only show the "Claim bonus" button when the claimable reward is at least $0.01. Introduced MIN_CLAIMABLE_BONUS_USD and isClaimableBonusAboveThreshold(reward); below that threshold the row shows the static "3% bonus" text instead of the CTA.

  2. 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 as unclaimedBaseUnits / 10^tokenDecimals and formats it as "< 0.01" when < 0.01, otherwise toFixed(2). This ensures amounts like 0.007401 display as "< 0.01" and the Cash section threshold logic works correctly.

  3. 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

Feature: Cash section claim bonus threshold and small-amount display

  Scenario: Claim bonus CTA hidden when claimable amount is below $0.01
    Given I am on the Wallet home screen with the Cash section visible
    And my claimable mUSD bonus is less than $0.01 (e.g. dust after claiming)

    When I view the mUSD row in the Cash section
    Then I should see "3% bonus" (green text) instead of "Claim bonus"
    And I should not see a tappable "Claim bonus" link

  Scenario: Claim bonus CTA shown when claimable amount is at least $0.01
    Given I am on the Wallet home screen with the Cash section visible
    And my claimable mUSD bonus is at least $0.01

    When I view the mUSD row in the Cash section
    Then I should see the "Claim bonus" link
    And tapping it should start the claim flow

Screenshots/Recordings

Before

claim-threshold-before.mov

After

Screenshot 2026-03-16 at 09 07 21

Pre-merge author checklist

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.

Note

Medium Risk
Changes reward amount formatting and CTA gating logic in the Cash section; incorrect numeric conversion/rounding (notably BigIntNumber) could mis-display large rewards or edge-case decimals.

Overview
Fixes dust claim UX in the Cash section. MusdAggregatedRow now 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. useMerklRewards drops renderFromTokenMinimalUnit and instead computes the decimal amount directly from base units, returning "< 0.01" for anything below $0.01 and toFixed(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.

@PatrykLucka PatrykLucka self-assigned this Mar 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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.

@PatrykLucka PatrykLucka marked this pull request as ready for review March 16, 2026 08:35
@PatrykLucka PatrykLucka requested a review from a team as a code owner March 16, 2026 08:35
@metamaskbot metamaskbot added the team-mobile-ux Mobile UX team label Mar 16, 2026
Comment thread app/components/Views/Homepage/Sections/Cash/MusdAggregatedRow.tsx
Comment thread app/components/UI/Earn/components/MerklRewards/hooks/useMerklRewards.test.ts Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

@PatrykLucka PatrykLucka force-pushed the MUSD-513-claim-cta-re-appears-after-claiming-even-if-claimable-amount-is-dust branch from 03b1479 to 1054f6f Compare March 16, 2026 09:24
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeWalletPlatform
  • Selected Performance tags: @PerformanceAssetLoading
  • Risk Level: medium
  • AI Confidence: 70%
click to see 🤖 AI reasoning details

E2E Test Selection:
The changes are limited to UI components and hooks under the Earn/Cash section of the Homepage (useMerklRewards hook and MusdAggregatedRow component). These affect how rewards and aggregated cash balances are computed and rendered on the wallet home screen. The Homepage and its sections fall under core wallet platform functionality, which is covered by SmokeWalletPlatform (transaction history, Trending integration, wallet home behaviors, and overall wallet lifecycle display). No controllers, Engine files, network logic, confirmations, swaps, perps, predictions, card, ramps, snaps, or multi-chain APIs were modified. Therefore, no additional domain-specific tags are required. Since the homepage is a critical shared surface used by many flows, running SmokeWalletPlatform ensures safe validation without over-selecting unrelated suites.

Performance Test Selection:
The changes affect reward calculation and aggregated balance rendering on the homepage, which may influence token/balance loading and render timing. Running @PerformanceAssetLoading helps detect regressions in balance fetching and asset list rendering performance. No onboarding, login, swaps, perps, or launch-specific logic was modified.

View GitHub Actions results

@github-actions

Copy link
Copy Markdown
Contributor

E2E Fixture Validation — Schema is up to date
16 value mismatches detected (expected — fixture represents an existing user).
View details

@sonarqubecloud

Copy link
Copy Markdown


const mockUseMerklBonusClaim = jest.fn(() => ({
claimableReward: { amount: '10' } as { amount: string } | null,
claimableReward: '10' as string | null,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused why this part changed - was this test wrong before?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@PatrykLucka PatrykLucka added this pull request to the merge queue Mar 16, 2026
Merged via the queue into main with commit 91c89e5 Mar 16, 2026
112 checks passed
@PatrykLucka PatrykLucka deleted the MUSD-513-claim-cta-re-appears-after-claiming-even-if-claimable-amount-is-dust branch March 16, 2026 12:34
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 16, 2026
@metamaskbot metamaskbot added the release-7.71.0 Issue or pull request that will be included in release 7.71.0 label Mar 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.71.0 Issue or pull request that will be included in release 7.71.0 size-M team-mobile-ux Mobile UX team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants