fix: hide claim bonus badge when no rewards are available#40299
fix: hide claim bonus badge when no rewards are available#40299
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-assets (2 files, +22 -21)
👨🔧 @MetaMask/metamask-earn (7 files, +691 -29)
|
Builds ready [e25afc4]
⚡ Performance Benchmarks (1437 ± 101 ms)
🌐 Dapp Page Load BenchmarksCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
|
bugbot run |
| 'useMerklRewards: Error fetching claimable rewards', | ||
| error, | ||
| ); | ||
| } |
There was a problem hiding this comment.
Refetch errors can leave stale CTA visible
Medium Severity
When fetchMerklRewardsForAsset/getClaimedAmountFromContract throws, the catch path logs but never clears claimableReward. After useOnMerklClaimConfirmed(refetch) runs, a transient error can keep the previous non-null claimableReward and leave the “Claim bonus” CTA visible even if rewards are no longer claimable.
Builds ready [fa3fd61]
⚡ Performance Benchmarks (1365 ± 97 ms)
🌐 Dapp Page Load BenchmarksCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
| tokenAddress={token.address as string} | ||
| chainId={token.chainId as Hex} | ||
| label={t('merklRewardsClaimBonus')} | ||
| fallback={<TokenCellPercentChange token={displayToken} />} |
There was a problem hiding this comment.
Do we need a fallBack param to handle this? Maybe instead we can wrap the merkle claim related logic in this component in a hook that decide whether or not to show the ClaimBonusBadge so that we don't need to pass a fallback component.
There was a problem hiding this comment.
There's a few cases where we don't show the claim badge. Firstly, we don't never want to show it if the token / chain aren't ones we provide merkl rewards for, or if the the feature flag isn't turned on. Secondly, we don't want to show it if there are no rewards to claim.
The second case requires us to make some API calls in order to find out if there are claimable rewards. We want to avoid making these calls if we already know we can't offer claims for the token in question. That's why I ended up taking this approach - with having a fallback at two levels.
I guess it would be possible to instead write a hook that only makes the API calls if the first case if false. Let me give that a try and see how it looks.
There was a problem hiding this comment.
Sounds good. Doing this also helps contain the logic such that it is re-usable elsewhere if needed
Builds ready [c203d86]
⚡ Performance Benchmarks (1395 ± 102 ms)
🌐 Dapp Page Load BenchmarksCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [39799ba]
⚡ Performance Benchmarks (1376 ± 119 ms)
🌐 Dapp Page Load BenchmarksCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚀 Bundle size reduced!]
|
Add useMerklRewards hook to check claimable reward amounts and useOnMerklClaimConfirmed to refetch after a claim confirms. The badge now returns null when there is nothing to claim. Also deduplicates isEligibleForMerklRewards into useMerklRewards. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
39799ba to
7edeb2a
Compare
Builds ready [7edeb2a]
⚡ Performance Benchmarks (1345 ± 103 ms)
🌐 Dapp Page Load BenchmarksCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
|
Builds ready [4db6303]
⚡ Performance Benchmarks (1351 ± 93 ms)
🌐 Dapp Page Load BenchmarksCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|







Description
This fixes an error in the previous implementation where the claim bonus CTA was always shown. Now we only show the CTA in the case that there is a bonus to claim
Changelog
CHANGELOG entry: Only show MUSD claim bonus CTA if there are rewards to claim
Related issues
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Introduces new reward-fetching and transaction-watching hooks that affect when claim CTAs render and trigger network/contract reads; errors or selector misuse could incorrectly hide/show the badge or cause extra requests.
Overview
Updates
TokenCellto show the Merkl “Claim bonus” CTA only when the user has claimable rewards, swapping the previous eligibility/feature-flag check for a newuseMerklRewardshook and reordering the footer layout to render the badge in the primary slot.Adds
useMerklRewardsto fetch reward data (with abort/refetch support) and determine claimability using on-chain claimed amounts as the source of truth (with API fallback), and addsuseOnMerklClaimConfirmedsoClaimBonusBadgecan refetch rewards when a pending Merkl claim transaction confirms. Includes new unit tests for both hooks and updates existingTokenCelltests to mock the new module API.Written by Cursor Bugbot for commit 4db6303. This will update automatically on new commits. Configure here.