Skip to content

Commit

Permalink
feat: add feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacook committed Sep 25, 2023
1 parent 75b6177 commit 21bdb3d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { useNotificationPreferences } from '../hooks/useNotificationPreferences'
import { sameAddress } from '@/utils/addresses'
import useOnboard from '@/hooks/wallets/useOnboard'
import { assertWalletChain } from '@/services/tx/tx-sender/sdk'
import { useHasFeature } from '@/hooks/useChains'
import { FEATURES } from '@/utils/chains'
import type { AddedSafesState } from '@/store/addedSafesSlice'
import type { PushNotificationPreferences } from '@/services/push-notifications/preferences'
import type { NotifiableSafes } from '../logic'
Expand Down Expand Up @@ -88,6 +90,7 @@ const getSafesToRegister = (addedSafes: AddedSafesState, allPreferences: PushNot
}

export const PushNotificationsBanner = ({ children }: { children: ReactElement }): ReactElement => {
const isNotificationsEnabled = useHasFeature(FEATURES.PUSH_NOTIFICATIONS)
const addedSafes = useAppSelector(selectAllAddedSafes)
const totalAddedSafes = useAppSelector(selectTotalAdded)
const { safe } = useSafeInfo()
Expand Down Expand Up @@ -136,7 +139,7 @@ export const PushNotificationsBanner = ({ children }: { children: ReactElement }
dismissBanner()
}

if (!shouldShowBanner) {
if (!shouldShowBanner || !isNotificationsEnabled) {
return children
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import ErrorCodes from '@/services/exceptions/ErrorCodes'
import { logError } from '@/services/exceptions'
import type { NotificationTracking, NotificationTrackingKey } from '@/services/push-notifications/tracking'
import type { WebhookType } from '@/service-workers/firebase-messaging/webhook-types'
import { useHasFeature } from '@/hooks/useChains'
import { FEATURES } from '@/utils/chains'

const trackNotificationEvents = (
chainId: string,
Expand Down Expand Up @@ -68,9 +70,11 @@ const handleTrackCachedNotificationEvents = async (
}

export const useNotificationTracking = (): void => {
const isNotificationsEnabled = useHasFeature(FEATURES.PUSH_NOTIFICATIONS)

useEffect(() => {
if (typeof indexedDB !== 'undefined') {
if (typeof indexedDB !== 'undefined' && isNotificationsEnabled) {
handleTrackCachedNotificationEvents(createNotificationTrackingIndexedDb())
}
}, [])
}, [isNotificationsEnabled])
}
11 changes: 10 additions & 1 deletion src/components/settings/SettingsHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,25 @@ import PageHeader from '@/components/common/PageHeader'
import { generalSettingsNavItems, settingsNavItems } from '@/components/sidebar/SidebarNavigation/config'
import css from '@/components/common/PageHeader/styles.module.css'
import useSafeAddress from '@/hooks/useSafeAddress'
import { AppRoutes } from '@/config/routes'
import { useHasFeature } from '@/hooks/useChains'
import { FEATURES } from '@/utils/chains'

const SettingsHeader = (): ReactElement => {
const safeAddress = useSafeAddress()
const isNotificationsEnabled = useHasFeature(FEATURES.PUSH_NOTIFICATIONS)

const navItems = safeAddress ? settingsNavItems : generalSettingsNavItems
const filteredNavItems = isNotificationsEnabled
? navItems
: navItems.filter((item) => item.href !== AppRoutes.settings.notifications)

return (
<PageHeader
title={safeAddress ? 'Settings' : 'Preferences'}
action={
<div className={css.navWrapper}>
<NavTabs tabs={safeAddress ? settingsNavItems : generalSettingsNavItems} />
<NavTabs tabs={filteredNavItems} />
</div>
}
/>
Expand Down
8 changes: 8 additions & 0 deletions src/pages/settings/notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ import type { NextPage } from 'next'

import SettingsHeader from '@/components/settings/SettingsHeader'
import { PushNotifications } from '@/components/settings/PushNotifications'
import { useHasFeature } from '@/hooks/useChains'
import { FEATURES } from '@/utils/chains'

const NotificationsPage: NextPage = () => {
const isNotificationsEnabled = useHasFeature(FEATURES.PUSH_NOTIFICATIONS)

if (!isNotificationsEnabled) {
return null
}

return (
<>
<Head>
Expand Down
1 change: 1 addition & 0 deletions src/utils/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export enum FEATURES {
RELAYING = 'RELAYING',
EIP1271 = 'EIP1271',
RISK_MITIGATION = 'RISK_MITIGATION',
PUSH_NOTIFICATIONS = 'PUSH_NOTIFICATIONS',
}

export const hasFeature = (chain: ChainInfo, feature: FEATURES): boolean => {
Expand Down

0 comments on commit 21bdb3d

Please sign in to comment.