Skip to content

Commit b9b406a

Browse files
fix: handle rewards linking failure cp-13.13.0 (#38579)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/38579?quickstart=1) ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: handle rewards-link errors and allow retry (re-link) ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/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-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] 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] > Adds a "Link Rewards" button in Transaction Shield settings to manually link claimed points to the subscription and logs linking failures; updates locales. > > - **UI (Transaction Shield settings `ui/pages/settings/transaction-shield-tab/transaction-shield.tsx`)**: > - Add conditional "Link Rewards" button to link claimed points to the current Shield subscription (`linkRewardToShieldSubscription`) when opted into rewards and no `rewardAccountId` is present. > - Type tweak for `displayedShieldSubscription` to include optional `rewardAccountId`. > - Log warnings on reward-link failures. > - **Rewards Hook (`ui/hooks/rewards/useOptIn.ts`)**: > - Log warnings if `linkRewardToShieldSubscription` fails during opt-in (previously silent). > - **Locales (`app/_locales/en/messages.json`, `app/_locales/en_GB/messages.json`)**: > - Add `shieldTxDetails3DescriptionLinkReward` message ("Link Rewards"). > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 5ac21dc. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: MetaMask Bot <[email protected]>
1 parent 5f45182 commit b9b406a

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

app/_locales/en/messages.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/_locales/en_GB/messages.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/hooks/rewards/useOptIn.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useCallback, useState, useContext, useMemo } from 'react';
22
import { useDispatch, useSelector } from 'react-redux';
33
import { AccountGroupId, AccountWalletId } from '@metamask/account-api';
4+
import log from 'loglevel';
45
import {
56
getMultichainAccountsByWalletId,
67
getWalletIdAndNameByAccountAddress,
@@ -173,8 +174,9 @@ export const useOptIn = (options?: UseOptInOptions): UseOptinResult => {
173174
options.rewardPoints,
174175
),
175176
);
176-
} catch {
177+
} catch (error) {
177178
// Silently fail - reward linking should not block opt-in
179+
log.warn('Failed to link reward to shield subscription', error);
178180
}
179181
}
180182
}

ui/pages/settings/transaction-shield-tab/transaction-shield.tsx

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
Product,
55
PRODUCT_TYPES,
66
RECURRING_INTERVALS,
7+
Subscription,
78
SUBSCRIPTION_STATUSES,
89
} from '@metamask/subscription-controller';
910
import { useLocation, useNavigate } from 'react-router-dom-v5-compat';
@@ -17,6 +18,7 @@ import {
1718
IconSize,
1819
} from '@metamask/design-system-react';
1920
import { useDispatch, useSelector } from 'react-redux';
21+
import log from 'loglevel';
2022
import {
2123
BannerAlert,
2224
BannerAlertSeverity,
@@ -83,6 +85,7 @@ import { useHandlePayment } from '../../../hooks/subscription/useHandlePayment';
8385
import { MetaMaskReduxDispatch } from '../../../store/store';
8486
import { setOnboardingModalOpen } from '../../../ducks/rewards';
8587
import { getIntlLocale } from '../../../ducks/locale/locale';
88+
import { linkRewardToShieldSubscription } from '../../../store/actions';
8689
import CancelMembershipModal from './cancel-membership-modal';
8790
import { isCardPaymentMethod, isCryptoPaymentMethod } from './types';
8891
import ShieldBannerAnimation from './shield-banner-animation';
@@ -126,8 +129,9 @@ const TransactionShield = () => {
126129
lastSubscription,
127130
);
128131
// show current active shield subscription or last subscription if no active subscription
129-
const displayedShieldSubscription =
130-
currentShieldSubscription ?? lastShieldSubscription;
132+
const displayedShieldSubscription:
133+
| (Subscription & { rewardAccountId?: string }) // TODO: fix this type once we have controller released.
134+
| undefined = currentShieldSubscription ?? lastShieldSubscription;
131135

132136
const [timeoutCancelled, setTimeoutCancelled] = useState(false);
133137
useEffect(() => {
@@ -280,6 +284,20 @@ const TransactionShield = () => {
280284
padding: 4,
281285
};
282286

287+
const handleLinkRewardToShieldSubscription = useCallback(
288+
async (subscriptionId: string, rewardPoints: number) => {
289+
// link to shield only coz already opted in to rewards
290+
try {
291+
await dispatch(
292+
linkRewardToShieldSubscription(subscriptionId, rewardPoints),
293+
);
294+
} catch (error) {
295+
log.warn('Failed to link reward to shield subscription', error);
296+
}
297+
},
298+
[dispatch],
299+
);
300+
283301
const buttonRow = (label: string, onClick: () => void, id?: string) => {
284302
return (
285303
<Box
@@ -682,6 +700,26 @@ const TransactionShield = () => {
682700
</Button>
683701
</Box>
684702
)}
703+
{hasOptedIntoRewards &&
704+
displayedShieldSubscription?.id &&
705+
claimedRewardsPoints &&
706+
!displayedShieldSubscription?.rewardAccountId && (
707+
<Box className="flex-shrink-0">
708+
<Button
709+
className="px-3"
710+
variant={ButtonVariant.Secondary}
711+
size={ButtonSize.Sm}
712+
onClick={async () =>
713+
handleLinkRewardToShieldSubscription(
714+
displayedShieldSubscription?.id,
715+
claimedRewardsPoints,
716+
)
717+
}
718+
>
719+
{t('shieldTxDetails3DescriptionLinkReward')}
720+
</Button>
721+
</Box>
722+
)}
685723
</Box>
686724
)}
687725
</Box>

0 commit comments

Comments
 (0)