Skip to content

Commit

Permalink
Fix: don't show push notifications banner if wallet not conencted; do…
Browse files Browse the repository at this point in the history
…n't track banner dismissal on enable all/customize
  • Loading branch information
katspaugh committed Oct 9, 2023
1 parent 011a0c6 commit ec2a98c
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import type { PushNotificationPreferences } from '@/services/push-notifications/
import type { NotifiableSafes } from '../logic'

import css from './styles.module.css'
import useWallet from '@/hooks/wallets/useWallet'

const DISMISS_PUSH_NOTIFICATIONS_KEY = 'dismissPushNotifications'

Expand Down Expand Up @@ -109,22 +110,27 @@ export const PushNotificationsBanner = ({ children }: { children: ReactElement }
const addedSafesOnChain = useAppSelector((state) => selectAddedSafes(state, safe.chainId))
const { query } = useRouter()
const onboard = useOnboard()
const wallet = useWallet()

const { getPreferences, getAllPreferences } = useNotificationPreferences()
const { dismissPushNotificationBanner, isPushNotificationBannerDismissed } = useDismissPushNotificationsBanner()

const isSafeAdded = !!addedSafesOnChain?.[safeAddress]
const isSafeRegistered = getPreferences(safe.chainId, safeAddress)
const shouldShowBanner =
isNotificationFeatureEnabled && !isPushNotificationBannerDismissed && isSafeAdded && !isSafeRegistered
isNotificationFeatureEnabled && !isPushNotificationBannerDismissed && isSafeAdded && !isSafeRegistered && !!wallet

const { registerNotifications } = useNotificationRegistrations()

const dismissBanner = useCallback(() => {
trackEvent(PUSH_NOTIFICATION_EVENTS.DISMISS_BANNER)
dismissPushNotificationBanner(safe.chainId)
}, [dismissPushNotificationBanner, safe.chainId])

const onDismiss = () => {
trackEvent(PUSH_NOTIFICATION_EVENTS.DISMISS_BANNER)
dismissBanner()
}

const onEnableAll = async () => {
if (!onboard || !addedSafesOnChain) {
return
Expand Down Expand Up @@ -171,7 +177,7 @@ export const PushNotificationsBanner = ({ children }: { children: ReactElement }
<Typography variant="subtitle2" fontWeight={700}>
Enable push notifications
</Typography>
<IconButton onClick={dismissBanner} className={css.close}>
<IconButton onClick={onDismiss} className={css.close}>
<SvgIcon component={CloseIcon} inheritViewBox color="border" fontSize="small" />
</IconButton>
<Typography mt={0.5} mb={1.5} variant="body2">
Expand Down

0 comments on commit ec2a98c

Please sign in to comment.