From deb60b835de0730e6fb695d034c4b6e2c4f9d6d6 Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 6 Mar 2024 08:22:03 -0500 Subject: [PATCH 1/3] add superfluid tokens email --- src/services/notificationService.ts | 8 ++++++++ src/types/notifications.ts | 2 ++ src/utils/validators/segmentAndMetadataValidators.ts | 11 +++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/services/notificationService.ts b/src/services/notificationService.ts index f1c9139..6f39f08 100644 --- a/src/services/notificationService.ts +++ b/src/services/notificationService.ts @@ -24,6 +24,14 @@ 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, + "str:cm:criticalDate": payload.criticalDate, + } + break; case NOTIFICATIONS_EVENT_NAMES.DONATION_RECEIVED: attributes = { "str:cm:projecttitle": payload.title, diff --git a/src/types/notifications.ts b/src/types/notifications.ts index b45be84..2eeef97 100644 --- a/src/types/notifications.ts +++ b/src/types/notifications.ts @@ -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', @@ -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', diff --git a/src/utils/validators/segmentAndMetadataValidators.ts b/src/utils/validators/segmentAndMetadataValidators.ts index cc3e8ab..c94b826 100644 --- a/src/utils/validators/segmentAndMetadataValidators.ts +++ b/src/utils/validators/segmentAndMetadataValidators.ts @@ -141,12 +141,23 @@ 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(), +}); + export const SEGMENT_METADATA_SCHEMA_VALIDATOR: { [key: string]: { segment: ObjectSchema | null; metadata: ObjectSchema | null; }; } = { + userSuperTokensCritical: { + metadata: null, + segment: superFluidTokenTrackerSchema, + }, draftedProjectSavedValidator: { metadata: projectTitleProjectLinkSchema, segment: projectRelatedTrackerSchema, From 7700be6b39d9914f405f1044407e2c5110954d6b Mon Sep 17 00:00:00 2001 From: Ramin Date: Wed, 27 Mar 2024 02:48:27 +0330 Subject: [PATCH 2/3] add isRecurringDonation and SUPER_TOKENS_CRITICAL fields and validators --- src/services/notificationService.ts | 4 +++- src/utils/validators/segmentAndMetadataValidators.ts | 2 ++ src/validators/schemaValidators.ts | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/services/notificationService.ts b/src/services/notificationService.ts index 6f39f08..f0517dc 100644 --- a/src/services/notificationService.ts +++ b/src/services/notificationService.ts @@ -28,12 +28,14 @@ const activityCreator = (payload: any, orttoEventName: NOTIFICATIONS_EVENT_NAMES attributes = { "str:cm:tokensymbol": payload.tokenSymbol, "str:cm:email": payload.email, - "str:cm:userId": payload.userId, + "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, diff --git a/src/utils/validators/segmentAndMetadataValidators.ts b/src/utils/validators/segmentAndMetadataValidators.ts index c94b826..785f5f6 100644 --- a/src/utils/validators/segmentAndMetadataValidators.ts +++ b/src/utils/validators/segmentAndMetadataValidators.ts @@ -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({ @@ -146,6 +147,7 @@ const superFluidTokenTrackerSchema = Joi.object({ email: Joi.string().required(), userId: Joi.number().required(), criticalDate: Joi.string().required(), + isEnded: Joi.boolean(), }); export const SEGMENT_METADATA_SCHEMA_VALIDATOR: { diff --git a/src/validators/schemaValidators.ts b/src/validators/schemaValidators.ts index 3ba478e..8e45ec4 100644 --- a/src/validators/schemaValidators.ts +++ b/src/validators/schemaValidators.ts @@ -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(''), From bb67e9fb43ea5cab1f4eb9f85bb453c92dc32bca Mon Sep 17 00:00:00 2001 From: Carlos Date: Thu, 28 Mar 2024 02:30:34 -0500 Subject: [PATCH 3/3] add in-app notifications for emails of superfluid --- ...711607882826-addSuperfluidNotifications.ts | 161 ++++++++++++++++++ src/entities/notificationSetting.ts | 1 + src/entities/notificationType.ts | 1 + .../segmentAndMetadataValidators.ts | 2 +- 4 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 migrations/1711607882826-addSuperfluidNotifications.ts diff --git a/migrations/1711607882826-addSuperfluidNotifications.ts b/migrations/1711607882826-addSuperfluidNotifications.ts new file mode 100644 index 0000000..681a0f1 --- /dev/null +++ b/migrations/1711607882826-addSuperfluidNotifications.ts @@ -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 { + await queryRunner.manager.save( + NotificationType, + superFluidNotificationTypes, + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `DELETE FROM notification_type WHERE "categoryGroup" = 'superfluid';`, + ); + } +} diff --git a/src/entities/notificationSetting.ts b/src/entities/notificationSetting.ts index dacea8e..fbc62d4 100644 --- a/src/entities/notificationSetting.ts +++ b/src/entities/notificationSetting.ts @@ -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', diff --git a/src/entities/notificationType.ts b/src/entities/notificationType.ts index d5c6b8d..b7c3fec 100644 --- a/src/entities/notificationType.ts +++ b/src/entities/notificationType.ts @@ -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', diff --git a/src/utils/validators/segmentAndMetadataValidators.ts b/src/utils/validators/segmentAndMetadataValidators.ts index 785f5f6..f79a84c 100644 --- a/src/utils/validators/segmentAndMetadataValidators.ts +++ b/src/utils/validators/segmentAndMetadataValidators.ts @@ -157,7 +157,7 @@ export const SEGMENT_METADATA_SCHEMA_VALIDATOR: { }; } = { userSuperTokensCritical: { - metadata: null, + metadata: superFluidTokenTrackerSchema, segment: superFluidTokenTrackerSchema, }, draftedProjectSavedValidator: {