Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: don't show push notifications banner if wallet not conencted #2605

Merged
merged 2 commits into from
Oct 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading