Skip to content

Commit 50cc11f

Browse files
authored
feat: add Shield activity to rewards pts estimation (#38462)
<!-- 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? --> This PR adds Shield activity to rewards pts estimation. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/38462?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: estimate rewards points for shield subscription ## **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.
1 parent 820f60a commit 50cc11f

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

app/scripts/controllers/rewards/rewards-controller.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ import {
2222
KeyringControllerSignPersonalMessageAction,
2323
KeyringControllerUnlockEvent,
2424
} from '@metamask/keyring-controller';
25+
import {
26+
RECURRING_INTERVALS,
27+
RecurringInterval,
28+
} from '@metamask/subscription-controller';
2529
import { HardwareDeviceNames } from '../../../../shared/constants/hardware-wallets';
2630
import {
2731
RewardsControllerActions,
@@ -1106,6 +1110,42 @@ describe('RewardsController', () => {
11061110
},
11071111
);
11081112
});
1113+
1114+
it('should estimate points for shield activity', async () => {
1115+
await withController(
1116+
{ isDisabled: false },
1117+
async ({ controller, mockMessengerCall }) => {
1118+
const recurringInterval: RecurringInterval =
1119+
RECURRING_INTERVALS.month;
1120+
const mockEstimatedPoints: EstimatedPointsDto = {
1121+
pointsEstimate:
1122+
recurringInterval === RECURRING_INTERVALS.month ? 1000 : 10000,
1123+
bonusBips: 0,
1124+
};
1125+
1126+
mockMessengerCall.mockImplementation((actionType) => {
1127+
if (actionType === 'RewardsDataService:estimatePoints') {
1128+
return Promise.resolve(mockEstimatedPoints);
1129+
}
1130+
return undefined;
1131+
});
1132+
1133+
const request: EstimatePointsDto = {
1134+
activityType: 'SHIELD',
1135+
account: MOCK_CAIP_ACCOUNT,
1136+
activityContext: {
1137+
shieldContext: {
1138+
recurringInterval,
1139+
},
1140+
},
1141+
};
1142+
1143+
const result = await controller.estimatePoints(request);
1144+
1145+
expect(result).toEqual(mockEstimatedPoints);
1146+
},
1147+
);
1148+
});
11091149
});
11101150

11111151
describe('getSeasonMetadata', () => {

shared/types/rewards.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* These types are used across UI and background to avoid import restrictions
44
*/
55

6+
import { RecurringInterval } from '@metamask/subscription-controller';
67
import { CaipAccountId, CaipAssetType } from '@metamask/utils';
78

89
export enum SeasonRewardType {
@@ -160,6 +161,15 @@ export type EstimatePerpsContextDto = {
160161
coin: string;
161162
};
162163

164+
export type EstimateShieldContextDto = {
165+
/**
166+
* Recurring interval of the shield subscription
167+
*
168+
* @example 'month'
169+
*/
170+
recurringInterval: RecurringInterval;
171+
};
172+
163173
export type EstimatePointsContextDto = {
164174
/**
165175
* Swap context data, must be present for SWAP activity
@@ -170,6 +180,11 @@ export type EstimatePointsContextDto = {
170180
* PERPS context data, must be present for PERPS activity
171181
*/
172182
perpsContext?: EstimatePerpsContextDto;
183+
184+
/**
185+
* Shield context data, must be present for SHIELD activity
186+
*/
187+
shieldContext?: EstimateShieldContextDto;
173188
};
174189

175190
/**
@@ -183,7 +198,8 @@ export type PointsEventEarnType =
183198
| 'REFERRAL'
184199
| 'SIGN_UP_BONUS'
185200
| 'LOYALTY_BONUS'
186-
| 'ONE_TIME_BONUS';
201+
| 'ONE_TIME_BONUS'
202+
| 'SHIELD';
187203

188204
export type EstimatedPointsDto = {
189205
/**

0 commit comments

Comments
 (0)