diff --git a/src/back/services/notification.ts b/src/back/services/notification.ts index 1af0c3363..bc7121d11 100644 --- a/src/back/services/notification.ts +++ b/src/back/services/notification.ts @@ -8,18 +8,13 @@ import { ErrorService } from '../../services/ErrorService' import { NotificationCustomType } from '../../shared/types/notifications' import { ErrorCategory } from '../../utils/errorCategories' import { isProdEnv } from '../../utils/governanceEnvs' -import { NotificationType, PUSH_CHANNEL_ID, getCaipAddress } from '../../utils/notifications' +import { NotificationType, PUSH_CHANNEL_ID, getCaipAddress, getPushNotificationsEnv } from '../../utils/notifications' import { areValidAddresses } from '../utils/validations' import { CoauthorService } from './coauthor' const PushAPI = NOTIFICATIONS_SERVICE_ENABLED ? require('@pushprotocol/restapi') : null -enum ENV { - PROD = 'prod', - STAGING = 'staging', -} - const chainId = isProdEnv() ? ChainId.ETHEREUM_MAINNET : ChainId.ETHEREUM_GOERLI const PUSH_CHANNEL_OWNER_PK = process.env.PUSH_CHANNEL_OWNER_PK const PUSH_API_URL = process.env.PUSH_API_URL @@ -74,7 +69,7 @@ export class NotificationService { recipients: this.getRecipients(recipient), channel: getCaipAddress(PUSH_CHANNEL_ID, chainId), - env: isProdEnv() ? ENV.PROD : ENV.STAGING, + env: getPushNotificationsEnv(chainId), }) return response.data diff --git a/src/components/Notifications/NotificationsFeed.tsx b/src/components/Notifications/NotificationsFeed.tsx index db1650d61..ac5ccdd56 100644 --- a/src/components/Notifications/NotificationsFeed.tsx +++ b/src/components/Notifications/NotificationsFeed.tsx @@ -14,8 +14,8 @@ import { isSameAddress } from '../../entities/Snapshot/utils' import { DEFAULT_QUERY_STALE_TIME } from '../../hooks/constants' import { useClickOutside } from '../../hooks/useClickOutside' import useFormatMessage from '../../hooks/useFormatMessage' -import { ENV, Notification } from '../../shared/types/notifications' -import { PUSH_CHANNEL_ID, getCaipAddress } from '../../utils/notifications' +import { Notification } from '../../shared/types/notifications' +import { PUSH_CHANNEL_ID, getCaipAddress, getPushNotificationsEnv } from '../../utils/notifications' import FullWidthButton from '../Common/FullWidthButton' import Heading from '../Common/Typography/Heading' import Text from '../Common/Typography/Text' @@ -41,7 +41,7 @@ export default function NotificationsFeed({ isOpen, onClose }: Props) { useClickOutside('.NotificationsFeed', isOpen, onClose) const chainId = userState.chainId || ChainId.ETHEREUM_GOERLI - const env = ENV.STAGING // TODO: check if it is prod or staging according to chain id + const env = getPushNotificationsEnv(chainId) const { data: subscriptions, diff --git a/src/utils/notifications.ts b/src/utils/notifications.ts index 6375b1877..67e7e6667 100644 --- a/src/utils/notifications.ts +++ b/src/utils/notifications.ts @@ -1,3 +1,7 @@ +import { ChainId } from '@dcl/schemas/dist/dapps/chain-id' + +import { ENV } from '../shared/types/notifications' + import { clientEnv } from './clientEnv' export const NotificationType = { @@ -11,3 +15,13 @@ export function getCaipAddress(address: string, chainId: number) { } export const PUSH_CHANNEL_ID = process.env.GATSBY_PUSH_CHANNEL_ID || clientEnv('GATSBY_PUSH_CHANNEL_ID') + +export function getPushNotificationsEnv(chainId: ChainId) { + switch (chainId) { + case ChainId.ETHEREUM_MAINNET: + return ENV.PROD + case ChainId.ETHEREUM_GOERLI: + default: + return ENV.STAGING + } +}