Skip to content

Commit

Permalink
Merge pull request #79 from Giveth/feature_add_super_tokens_email
Browse files Browse the repository at this point in the history
Add superfluid tokens email
  • Loading branch information
RamRamez authored Apr 1, 2024
2 parents cb6dc6d + bb67e9f commit 440b665
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 0 deletions.
161 changes: 161 additions & 0 deletions migrations/1711607882826-addSuperfluidNotifications.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
import { NOTIFICATION_CATEGORY_GROUPS } from '../src/entities/notificationSetting';
import { NOTIFICATION_CATEGORY } from '../src/types/general';
import { MICRO_SERVICES } from '../src/utils/utils';
import {
NotificationType,
SCHEMA_VALIDATORS_NAMES,
} from '../src/entities/notificationType';

export const superFluidNotificationTypes = [
{
name: 'One month left in stream balance',
description: 'Stream balance of underlying token will run out in 1 month',
microService: MICRO_SERVICES.givethio,
category: NOTIFICATION_CATEGORY.GIV_ECONOMY,
icon: '',
schemaValidator: SCHEMA_VALIDATORS_NAMES.SUPERFLUID,
emailNotifierService: null,
emailNotificationId: null,
pushNotifierService: null,
categoryGroup: NOTIFICATION_CATEGORY_GROUPS.SUPERFLUID,
title: 'One Month Left in Stream Balance',
htmlTemplate: [
{
type: 'p',
content: 'Your Stream Balance of ',
},
{
type: 'a',
content: '{underlyingTokenSymbol}',
href: '#', // Placeholder for dynamic token symbol link
},
{
type: 'p',
content: ' on ',
},
{
type: 'a',
content: '{network}',
href: '#', // Placeholder for dynamic network link
},
{
type: 'p',
content: ' will run out in 1 month, ',
},
{
type: 'a',
content: 'top-up here.',
href: 'Link to my recurring donations tab', // Actual link goes here
},
],
content:
'Your Stream Balance of {underlyingTokenSymbol} on {network} will run out in 1 month, top-up here.',
},
{
name: 'One week left in stream balance',
description: 'Stream balance of underlying token will run out in 1 week',
microService: MICRO_SERVICES.givethio,
category: NOTIFICATION_CATEGORY.GIV_ECONOMY,
icon: '',
schemaValidator: SCHEMA_VALIDATORS_NAMES.SUPERFLUID,
emailNotifierService: null,
emailNotificationId: null,
pushNotifierService: null,
categoryGroup: NOTIFICATION_CATEGORY_GROUPS.SUPERFLUID,
title: 'One Week Left in Stream Balance',
htmlTemplate: [
{
type: 'p',
content: 'Your Stream Balance of ',
},
{
type: 'a',
content: '{underlyingTokenSymbol}',
href: '#', // Placeholder for dynamic token symbol link
},
{
type: 'p',
content: ' on ',
},
{
type: 'a',
content: '{network}',
href: '#', // Placeholder for dynamic network link
},
{
type: 'p',
content: ' will run out in 1 week, ',
},
{
type: 'a',
content: 'top-up here.',
href: 'Link to my recurring donations tab', // Actual link goes here
},
],
content:
'Your Stream Balance of {underlyingTokenSymbol} on {network} will run out in 1 week, top-up here.',
},
{
name: 'Stream balance depleted',
description: 'Stream balance in token has run out of funds',
microService: MICRO_SERVICES.givethio,
category: NOTIFICATION_CATEGORY.GIV_ECONOMY,
icon: '',
schemaValidator: SCHEMA_VALIDATORS_NAMES.SUPERFLUID,
emailNotifierService: null,
emailNotificationId: null,
pushNotifierService: null,
categoryGroup: NOTIFICATION_CATEGORY_GROUPS.SUPERFLUID,
title: 'Stream Balance Depleted',
htmlTemplate: [
{
type: 'p',
content: 'Your Stream Balance in ',
},
{
type: 'a',
content: '{tokenSymbol}',
href: '#', // Placeholder for dynamic token symbol link
},
{
type: 'p',
content: ' on ',
},
{
type: 'a',
content: '{network}',
href: '#', // Placeholder for dynamic network link
},
{
type: 'p',
content:
' has run out of funds, subsequently some of your recurring donations have ended. ',
},
{
type: 'a',
content: 'Manage your Recurring Donations',
href: 'Link to manage recurring donations', // Actual link goes here
},
],
content:
'Your Stream Balance in {tokenSymbol} on {network} has run out of funds, subsequently some of your recurring donations have ended. Manage your Recurring Donations',
},
];

export class addSuperfluidNotifications1711607882826
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.manager.save(
NotificationType,
superFluidNotificationTypes,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DELETE FROM notification_type WHERE "categoryGroup" = 'superfluid';`,
);
}
}
1 change: 1 addition & 0 deletions src/entities/notificationSetting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { NotificationType } from './notificationType';
import { UserAddress } from './userAddress';

export const NOTIFICATION_CATEGORY_GROUPS = {
SUPERFLUID: 'superfluid',
GIVPOWER_ALLOCATIONS: 'givPowerAllocations',
PROJECT_BOOSTING_STATUS: 'projectBoostStatus',
SELF_BOOSTING_STATUS: 'yourBoostStatus',
Expand Down
1 change: 1 addition & 0 deletions src/entities/notificationType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { NotificationSetting } from './notificationSetting';

// Export Object with Schemas to N1 lookup
export const SCHEMA_VALIDATORS_NAMES = {
SUPERFLUID: 'superFluidTokenTrackerSchema',
ADMIN_MESSAGE: 'adminMessage',
RAW_HTML_BROADCAST: 'rawHtmlBroadcast',
DRAFTED_PROJECT_SAVED: 'draftedProjectSavedValidator',
Expand Down
10 changes: 10 additions & 0 deletions src/services/notificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,18 @@ const activityCreator = (payload: any, orttoEventName: NOTIFICATIONS_EVENT_NAMES
}
let attributes;
switch (orttoEventName) {
case NOTIFICATIONS_EVENT_NAMES.USER_SUPER_TOKENS_CRITICAL:
attributes = {
"str:cm:tokensymbol": payload.tokenSymbol,
"str:cm:email": payload.email,
"str:cm:userId": payload.userId?.toString(),
"str:cm:criticalDate": payload.criticalDate,
"bol:cm:isended": payload.isEnded,
}
break;
case NOTIFICATIONS_EVENT_NAMES.DONATION_RECEIVED:
attributes = {
"bol:cm:isrecurringdonation": !!payload.isRecurringDonation,
"str:cm:projecttitle": payload.title,
"str:cm:donationamount": payload.amount.toString(),
"str:cm:donationtoken": payload.token,
Expand Down
2 changes: 2 additions & 0 deletions src/types/notifications.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export enum NOTIFICATIONS_EVENT_NAMES {
USER_SUPER_TOKENS_CRITICAL = 'Supertokens critical',
DRAFTED_PROJECT_ACTIVATED = 'Draft published',
PROJECT_LISTED = 'Project listed',
PROJECT_UNLISTED = 'Project unlisted',
Expand Down Expand Up @@ -47,6 +48,7 @@ export enum NOTIFICATIONS_EVENT_NAMES {
}

export const ORTTO_EVENT_NAMES = {
[NOTIFICATIONS_EVENT_NAMES.USER_SUPER_TOKENS_CRITICAL]: 'superfluid-balance-warning',
[NOTIFICATIONS_EVENT_NAMES.DONATION_RECEIVED]: 'testing-donation-received',
[NOTIFICATIONS_EVENT_NAMES.DRAFTED_PROJECT_ACTIVATED]: 'project-created',
[NOTIFICATIONS_EVENT_NAMES.PROJECT_LISTED]: 'project-listed',
Expand Down
13 changes: 13 additions & 0 deletions src/utils/validators/segmentAndMetadataValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const donationTrackerSchema = Joi.object({
donationValueEth: Joi.number().greater(0).allow(null),
verified: Joi.boolean().allow(null),
transakStatus: Joi.string().allow(null),
isRecurringDonation: Joi.boolean().allow(null),
});

const projectTitleProjectLinkSchema = Joi.object({
Expand Down Expand Up @@ -141,12 +142,24 @@ const givBackReadyClaimSchema = Joi.object({
amount: Joi.string().required(),
});

const superFluidTokenTrackerSchema = Joi.object({
tokenSymbol: Joi.string().required(),
email: Joi.string().required(),
userId: Joi.number().required(),
criticalDate: Joi.string().required(),
isEnded: Joi.boolean(),
});

export const SEGMENT_METADATA_SCHEMA_VALIDATOR: {
[key: string]: {
segment: ObjectSchema | null;
metadata: ObjectSchema | null;
};
} = {
userSuperTokensCritical: {
metadata: superFluidTokenTrackerSchema,
segment: superFluidTokenTrackerSchema,
},
draftedProjectSavedValidator: {
metadata: projectTitleProjectLinkSchema,
segment: projectRelatedTrackerSchema,
Expand Down
6 changes: 6 additions & 0 deletions src/validators/schemaValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ export const sendNotificationValidator = Joi.object({
donationValueEth: Joi.number().allow(null),
verified: Joi.boolean(),
transakStatus: Joi.string().allow(null).allow(''),
isRecurringDonation: Joi.boolean().allow(null),

//Super token critical attributes
criticalDate: Joi.string(),
isEnded: Joi.boolean(),
tokenSymbol: Joi.string(),

//Project related attributes
lastName: Joi.string().allow(null).allow(''),
Expand Down

0 comments on commit 440b665

Please sign in to comment.