Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions app/scripts/controllers/rewards/rewards-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import {
KeyringControllerSignPersonalMessageAction,
KeyringControllerUnlockEvent,
} from '@metamask/keyring-controller';
import {
RECURRING_INTERVALS,
RecurringInterval,
} from '@metamask/subscription-controller';
import { HardwareDeviceNames } from '../../../../shared/constants/hardware-wallets';
import {
RewardsControllerActions,
Expand Down Expand Up @@ -1106,6 +1110,42 @@ describe('RewardsController', () => {
},
);
});

it('should estimate points for shield activity', async () => {
await withController(
{ isDisabled: false },
async ({ controller, mockMessengerCall }) => {
const recurringInterval: RecurringInterval =
RECURRING_INTERVALS.month;
const mockEstimatedPoints: EstimatedPointsDto = {
pointsEstimate:
recurringInterval === RECURRING_INTERVALS.month ? 1000 : 10000,
bonusBips: 0,
};

mockMessengerCall.mockImplementation((actionType) => {
if (actionType === 'RewardsDataService:estimatePoints') {
return Promise.resolve(mockEstimatedPoints);
}
return undefined;
});

const request: EstimatePointsDto = {
activityType: 'SHIELD',
account: MOCK_CAIP_ACCOUNT,
activityContext: {
shieldContext: {
recurringInterval,
},
},
};

const result = await controller.estimatePoints(request);

expect(result).toEqual(mockEstimatedPoints);
},
);
});
});

describe('getSeasonMetadata', () => {
Expand Down
18 changes: 17 additions & 1 deletion shared/types/rewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* These types are used across UI and background to avoid import restrictions
*/

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

export enum SeasonRewardType {
Expand Down Expand Up @@ -160,6 +161,15 @@ export type EstimatePerpsContextDto = {
coin: string;
};

export type EstimateShieldContextDto = {
/**
* Recurring interval of the shield subscription
*
* @example 'month'
*/
recurringInterval: RecurringInterval;
};

export type EstimatePointsContextDto = {
/**
* Swap context data, must be present for SWAP activity
Expand All @@ -170,6 +180,11 @@ export type EstimatePointsContextDto = {
* PERPS context data, must be present for PERPS activity
*/
perpsContext?: EstimatePerpsContextDto;

/**
* Shield context data, must be present for SHIELD activity
*/
shieldContext?: EstimateShieldContextDto;
};

/**
Expand All @@ -183,7 +198,8 @@ export type PointsEventEarnType =
| 'REFERRAL'
| 'SIGN_UP_BONUS'
| 'LOYALTY_BONUS'
| 'ONE_TIME_BONUS';
| 'ONE_TIME_BONUS'
| 'SHIELD';

export type EstimatedPointsDto = {
/**
Expand Down
Loading