Skip to content

Commit

Permalink
fix: change messages and add missing proposal title + mini refactor (#…
Browse files Browse the repository at this point in the history
…1625)

* fix: change messages and add missing proposal title + mini refactor

* refactor: notification title fn
  • Loading branch information
1emu authored Feb 1, 2024
1 parent 40288e9 commit 495d9b1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
28 changes: 11 additions & 17 deletions src/back/services/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@ import { Notification, NotificationCustomType, Recipient } from '../../shared/ty
import { ErrorCategory } from '../../utils/errorCategories'
import { isProdEnv } from '../../utils/governanceEnvs'
import logger from '../../utils/logger'
import {
NotificationBody,
NotificationTitle,
NotificationType,
getCaipAddress,
getPushNotificationsEnv,
} from '../../utils/notifications'
import { NotificationType, Notifications, getCaipAddress, getPushNotificationsEnv } from '../../utils/notifications'
import { areValidAddresses } from '../utils/validations'

import { CoauthorService } from './coauthor'
Expand Down Expand Up @@ -140,8 +134,8 @@ export class NotificationService {
throw new Error('Invalid addresses')
}

const title = NotificationTitle.GrantEnacted
const body = NotificationBody.GrantEnacted
const title = Notifications.GrantEnacted.title
const body = Notifications.GrantEnacted.body

const validatedUsers = await UserModel.getActiveDiscordIds(addresses)
for (const user of validatedUsers) {
Expand Down Expand Up @@ -176,8 +170,8 @@ export class NotificationService {
throw new Error('Invalid addresses')
}

const title = NotificationTitle.CoAuthorRequestReceived
const body = NotificationBody.CoAuthorRequestReceived
const title = Notifications.CoAuthorRequestReceived.title
const body = Notifications.CoAuthorRequestReceived.body

const validatedUsers = await UserModel.getActiveDiscordIds(coAuthors)
for (const user of validatedUsers) {
Expand Down Expand Up @@ -205,7 +199,7 @@ export class NotificationService {
}
}

static async votingEndedAuthors(proposal: ProposalAttributes) {
static async authoredProposalFinished(proposal: ProposalAttributes) {
try {
const coauthors = await CoauthorService.getAllFromProposalId(proposal.id)
const coauthorsAddresses = coauthors.length > 0 ? coauthors.map((coauthor) => coauthor.address) : []
Expand All @@ -215,8 +209,8 @@ export class NotificationService {
throw new Error('Invalid addresses')
}

const title = `${NotificationTitle.ProposalVotedFinished} ${proposal.title}`
const body = NotificationBody.ProposalVotedFinished
const title = Notifications.ProposalAuthoredFinished.title(proposal)
const body = Notifications.ProposalAuthoredFinished.body

const validatedUsers = await UserModel.getActiveDiscordIds(addresses)
for (const user of validatedUsers) {
Expand Down Expand Up @@ -250,8 +244,8 @@ export class NotificationService {
throw new Error('Invalid addresses')
}

const title = NotificationTitle.ProposalVotedFinished
const body = NotificationBody.ProposalVotedFinished
const title = Notifications.ProposalVotedFinished.title(proposal)
const body = Notifications.ProposalVotedFinished.body

const validatedUsers = await UserModel.getActiveDiscordIds(addresses)
for (const user of validatedUsers) {
Expand Down Expand Up @@ -284,7 +278,7 @@ export class NotificationService {
inBackground(async () => {
for (const proposal of proposals) {
try {
await this.votingEndedAuthors(proposal)
await this.authoredProposalFinished(proposal)
const votes = await VoteService.getVotes(proposal.id)
const voters = Object.keys(votes)
await this.votingEndedVoters(proposal, voters)
Expand Down
2 changes: 1 addition & 1 deletion src/entities/Proposal/jobs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('finishProposals', () => {
jest.spyOn(DiscordService, 'finishProposal').mockImplementation(() => {})
jest.spyOn(DiscordService, 'newProposal').mockImplementation(() => {})
jest.spyOn(DiscordService, 'newUpdate').mockImplementation(() => {})
jest.spyOn(NotificationService, 'votingEndedAuthors').mockImplementation()
jest.spyOn(NotificationService, 'authoredProposalFinished').mockImplementation()
jest.spyOn(DiscourseService, 'getCategory').mockImplementation(() => 5)
})
beforeEach(() => {
Expand Down
30 changes: 18 additions & 12 deletions src/utils/notifications.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ChainId } from '@dcl/schemas/dist/dapps/chain-id'

import { ProposalAttributes } from '../entities/Proposal/types'
import { ENV } from '../shared/types/notifications'

export const NotificationType = {
Expand All @@ -22,16 +23,21 @@ export function getPushNotificationsEnv(chainId: ChainId) {
}
}

export enum NotificationTitle {
ProposalVotedFinished = 'Voting Ended on a Proposal You Voted On',
ProposalAuthoredFinished = 'Voting Ended on Your Proposal',
CoAuthorRequestReceived = 'Co-author Request Received',
GrantEnacted = 'Grant Proposal Enacted',
}

export enum NotificationBody {
ProposalVotedFinished = 'Discover the results of the proposal you participated in as a voter. Your input matters!',
ProposalAuthoredFinished = 'The votes are in! Find out the outcome of the voting on your proposal now',
CoAuthorRequestReceived = "You've been invited to collaborate as a co-author on a published proposal. Accept it or reject it here",
GrantEnacted = 'Congratulations! Your Grant Proposal has been successfully enacted and a Vesting Contract was added',
export const Notifications = {
ProposalVotedFinished: {
title: (proposal: ProposalAttributes) => `Voting Ended on a Proposal You Voted On ${proposal.title}`,
body: 'Discover the results of the proposal you participated in as a voter. Your input matters!',
},
ProposalAuthoredFinished: {
title: (proposal: ProposalAttributes) => `Voting Ended on Your Proposal ${proposal.title}`,
body: 'The votes are in! Find out the outcome of the voting on your proposal now',
},
CoAuthorRequestReceived: {
title: 'Co-author Request Received',
body: "You've been invited to collaborate as a co-author on a published proposal. Accept it or reject it here",
},
GrantEnacted: {
title: 'Grant Proposal Enacted',
body: 'Congratulations! Your Grant Proposal has been successfully enacted and a Vesting Contract was added',
},
}

0 comments on commit 495d9b1

Please sign in to comment.