Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added GIVBACK IS READY event #25

Merged
merged 4 commits into from
Dec 27, 2022
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
32 changes: 16 additions & 16 deletions migrations/1660716115917-seedNotificationType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -892,15 +892,15 @@ export const GivethNotificationTypes = {
},
{
type: 'a',
content: '$poolName',
content: '$contractName',
href: '/givfarm',
},
{
type: 'p',
content: ' was successful.',
},
],
content: 'Staking {amount} of {poolName} was successful.',
content: 'Staking {amount} of {contractName} was successful.',
},
UN_STAKE: {
name: 'UnStake',
Expand Down Expand Up @@ -933,40 +933,40 @@ export const GivethNotificationTypes = {
},
{
type: 'a',
content: '$poolName',
content: '$contractName',
href: '/givfarm',
},
{
type: 'p',
content: ' was successful.',
},
],
content: 'Unstaking {amount} of {poolname} was successful.',
content: 'Unstaking {amount} of {contractName} was successful.',
},
GIV_BACKS_ARE_READY_TO_CLAIM: {
name: 'GIVbacks are ready to claim',
title: 'GIVbacks',
description: 'When GIVbacks are ready to be claimed after each round',
GIV_BACK_IS_READY_TO_CLAIM: {
name: 'GIVback is ready to claim',
title: 'GIVback',
description: 'When GIVback is ready to be claimed after each round',
showOnSettingPage: true,
microService: MICRO_SERVICES.givethio,
category: NOTIFICATION_CATEGORY.GIV_ECONOMY,
icon: 'IconUnstake',
schemaValidator: SCHEMA_VALIDATORS_NAMES.GIV_FARM_READY_TO_CLAIM,
emailNotifierService: THIRD_PARTY_EMAIL_SERVICES.SEGMENT,
emailNotificationId: SegmentEvents.PROJECT_REJECTED,
icon: 'IconGIVBack',
schemaValidator: SCHEMA_VALIDATORS_NAMES.GIV_BACK_IS_READY_TO_CLAIM,
emailNotifierService: null,
emailNotificationId: null,
pushNotifierService: null,
htmlTemplate: [
{
type: 'p',
content: 'Your GIVbacks for round ',
content: 'Your GIVback ',
},
{
type: 'b',
content: '$round',
content: '$amount',
},
{
type: 'p',
content: ' are ready to claim! ',
content: ' GIV is ready to claim! ',
},
{ type: 'br' },
{
Expand All @@ -980,7 +980,7 @@ export const GivethNotificationTypes = {
},
],
content:
'Your GIVbacks for round {round number} are ready to claim! \n{Click here} to take a shortcut.',
'Your GIVback {amount} GIV is ready to claim! \n{Click here} to take a shortcut.',
},
PROJECT_EDITED: {
name: 'Project edited',
Expand Down
1 change: 1 addition & 0 deletions src/entities/notificationType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const SCHEMA_VALIDATORS_NAMES = {
USER_UNLOCKED_GIVPOWER: 'givPowerUserUnlockedGivPower',
USER_GIVPOWER_RELOCKED_AUTOMATICALLY:
'givPowerUserGivPowerRelockedAutoMatically',
GIV_BACK_IS_READY_TO_CLAIM: 'givBackReadyToClaim',
};
export type HtmlTemplate = { type: string; content: string; href?: string }[];

Expand Down
29 changes: 18 additions & 11 deletions src/routes/v1/notificationRouter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ function sendNotificationTestCases() {
sendSegment: false,
userWalletAddress: generateRandomEthereumAddress(),
metadata: {
poolName: 'GIV farm',
contractName: 'GIV farm',
amount: '10',
network: 100,
transactionHash: generateRandomTxHash(),
Expand All @@ -1298,7 +1298,7 @@ function sendNotificationTestCases() {
sendSegment: false,
userWalletAddress: generateRandomEthereumAddress(),
metadata: {
poolName: 'GIV farm',
contractName: 'GIV farm',
network: 100,
transactionHash: generateRandomTxHash(),
},
Expand Down Expand Up @@ -1327,7 +1327,7 @@ function sendNotificationTestCases() {
sendSegment: false,
userWalletAddress: generateRandomEthereumAddress(),
metadata: {
poolName: 'GIVpower',
contractName: 'GIVpower',
amount: '10',
round: 13,
transactionHash: generateRandomTxHash(),
Expand All @@ -1353,7 +1353,7 @@ function sendNotificationTestCases() {
userWalletAddress: generateRandomEthereumAddress(),
metadata: {
round: 11,
poolName: 'GIVpower',
contractName: 'GIVpower',
transactionHash: generateRandomTxHash(),
network: 100,
},
Expand Down Expand Up @@ -1383,7 +1383,7 @@ function sendNotificationTestCases() {
sendSegment: false,
userWalletAddress: generateRandomEthereumAddress(),
metadata: {
poolName: 'GIV farm',
contractName: 'GIV farm',
amount: '10',
network: 100,
transactionHash: generateRandomTxHash(),
Expand All @@ -1407,7 +1407,7 @@ function sendNotificationTestCases() {
sendSegment: false,
userWalletAddress: generateRandomEthereumAddress(),
metadata: {
poolName: 'GIV farm',
contractName: 'GIV farm',
network: 100,
transactionHash: generateRandomTxHash(),
},
Expand All @@ -1431,12 +1431,15 @@ function sendNotificationTestCases() {

it('should create *GIVbacks are ready to claim* notification, success, segment is off', async () => {
const data = {
eventName: 'GIVbacks are ready to claim',
eventName: 'GIVback is ready to claim',
sendEmail: false,
sendSegment: false,
userWalletAddress: generateRandomEthereumAddress(),
metadata: {
round: 5,
contractName: 'Gnosis Chain Token Distro',
amount: '10',
network: 100,
transactionHash: generateRandomTxHash(),
},
};

Expand All @@ -1452,11 +1455,15 @@ function sendNotificationTestCases() {
it('should create *GIVbacks are ready to claim* notification, failed invalid metadata, segment is off', async () => {
try {
const data = {
eventName: 'GIVbacks are ready to claim',
eventName: 'GIVback is ready to claim',
sendEmail: false,
sendSegment: false,
userWalletAddress: generateRandomEthereumAddress(),
metadata: {},
metadata: {
contractName: 'Gnosis Chain Token Distro',
network: 100,
transactionHash: generateRandomTxHash(),
},
};

await axios.post(sendNotificationUrl, data, {
Expand All @@ -1471,7 +1478,7 @@ function sendNotificationTestCases() {
e.response.data.message,
errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message,
);
assert.equal(e.response.data.description, '"round" is required');
assert.equal(e.response.data.description, '"amount" is required');
}
});

Expand Down
3 changes: 2 additions & 1 deletion src/services/segment/segmentAnalyticsSingleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export enum SegmentEvents {
PROJECT_BADGE_UP_FOR_REVOKING = 'Project badge up for revoking',
PROJECT_VERIFIED = 'Project verified',
PROJECT_REJECTED = 'Project rejected',
GIVBACK_ARE_READY_TO_CLAIM = 'We dont have event yet',
GIVBACKS_ARE_READY_TO_CLAIM = 'We dont have event yet',
GIVBACK_IS_READY_TO_CLAIM = 'We dont have event yet',
PROJECT_UNVERIFIED = 'Project unverified',
PROJECT_UNVERIFIED_USERS_WHO_BOOSTED = 'Project unverified - Users Who Boosted',
PROJECT_ACTIVATED = 'Project activated',
Expand Down
16 changes: 13 additions & 3 deletions src/utils/validators/segmentAndMetadataValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ const projectBoostedSchema = Joi.object({
});

const givPowerLockedSchema = Joi.object({
poolName: Joi.string().required(),
contractName: Joi.string().required(),
amount: Joi.string().required(),
round: Joi.number()?.greater(0).required(),
transactionHash: Joi.string().required(),
network: Joi.number().required(),
});
const givPowerUnLockedSchema = Joi.object({
poolName: Joi.string().required(),
contractName: Joi.string().required(),
amount: Joi.string().required(),
round: Joi.number()?.greater(0).required(),
transactionHash: Joi.string().required(),
Expand Down Expand Up @@ -100,7 +100,7 @@ const getDonationPriceFailedMetadataSchema = Joi.object({
txLink: Joi.string().required(),
});
const stakeUnStakeSchema = Joi.object({
poolName: Joi.string().required(),
contractName: Joi.string().required(),
transactionHash: Joi.string().required(),
network: Joi.number().required(),
amount: Joi.string().required(),
Expand All @@ -115,6 +115,12 @@ const adminMessageSchema = Joi.object({
instruction: Joi.string().required(),
href: Joi.string().required(),
});
const givBackReadyClaimSchema = Joi.object({
contractName: Joi.string().required(),
transactionHash: Joi.string().required(),
network: Joi.number().required(),
amount: Joi.string().required(),
});

export const SEGMENT_METADATA_SCHEMA_VALIDATOR: {
[key: string]: {
Expand Down Expand Up @@ -259,6 +265,10 @@ export const SEGMENT_METADATA_SCHEMA_VALIDATOR: {
metadata: givPowerLockedSchema,
segment: null,
},
givBackReadyToClaim: {
metadata: givBackReadyClaimSchema,
segment: null,
}
};

function throwHttpErrorIfJoiValidatorFails(
Expand Down