Skip to content

Commit

Permalink
feat: add function to get push notifications env
Browse files Browse the repository at this point in the history
  • Loading branch information
andyesp committed Oct 2, 2023
1 parent 20405b0 commit d730a2c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
9 changes: 2 additions & 7 deletions src/back/services/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/components/Notifications/NotificationsFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions src/utils/notifications.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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
}
}

0 comments on commit d730a2c

Please sign in to comment.