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: track banner once #2598

Merged
merged 5 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
@@ -1,7 +1,7 @@
import { Button, Chip, Grid, SvgIcon, Typography, IconButton } from '@mui/material'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { useCallback, useEffect } from 'react'
import { useCallback, useEffect, useRef } from 'react'
import type { ReactElement } from 'react'

import { CustomTooltip } from '@/components/common/CustomTooltip'
Expand Down Expand Up @@ -86,6 +86,21 @@ export const _getSafesToRegister = (
return { [chainId]: newlyAddedSafes }
}

const TrackBanner = (): null => {
const hasTracked = useRef(false)

useEffect(() => {
if (hasTracked.current) {
return
}

trackEvent(PUSH_NOTIFICATION_EVENTS.SHOW_BANNER)
hasTracked.current = true
}, [])
katspaugh marked this conversation as resolved.
Show resolved Hide resolved

return null
}

export const PushNotificationsBanner = ({ children }: { children: ReactElement }): ReactElement => {
const isNotificationsEnabled = useHasFeature(FEATURES.PUSH_NOTIFICATIONS)
const chain = useCurrentChain()
Expand All @@ -108,12 +123,6 @@ export const PushNotificationsBanner = ({ children }: { children: ReactElement }
dismissPushNotificationBanner(safe.chainId)
}, [dismissPushNotificationBanner, safe.chainId])

useEffect(() => {
if (shouldShowBanner) {
trackEvent(PUSH_NOTIFICATION_EVENTS.DISPLAY_BANNER)
}
}, [dismissBanner, shouldShowBanner])

const onEnableAll = async () => {
if (!onboard || !addedSafesOnChain) {
return
Expand Down Expand Up @@ -146,57 +155,60 @@ export const PushNotificationsBanner = ({ children }: { children: ReactElement }
}

return (
<CustomTooltip
className={css.banner}
title={
<Grid container className={css.container}>
<Grid item xs={3}>
<Chip label="New" className={css.chip} />
<SvgIcon component={PushNotificationIcon} inheritViewBox fontSize="inherit" className={css.icon} />
</Grid>
<Grid item xs={9}>
<Typography variant="subtitle2" fontWeight={700}>
Enable push notifications
</Typography>
<IconButton onClick={dismissBanner} className={css.close}>
<SvgIcon component={CloseIcon} inheritViewBox color="border" fontSize="small" />
</IconButton>
<Typography mt={0.5} mb={1.5} variant="body2">
Get notified about pending signatures, incoming and outgoing transactions for all Safe Accounts on{' '}
{chain?.chainName} when Safe
{`{Wallet}`} is in the background or closed.
</Typography>
{/* Cannot wrap singular button as it causes style inconsistencies */}
<CheckWallet>
{(isOk) => (
<div className={css.buttons}>
{totalAddedSafes > 0 && (
<Button
variant="contained"
size="small"
className={css.button}
onClick={onEnableAll}
disabled={!isOk || !onboard}
>
Enable all
</Button>
)}
{safe && (
<Link passHref href={{ pathname: AppRoutes.settings.notifications, query }} onClick={onCustomize}>
<Button variant="outlined" size="small" className={css.button}>
Customize
<>
<TrackBanner />
<CustomTooltip
className={css.banner}
title={
<Grid container className={css.container}>
<Grid item xs={3}>
<Chip label="New" className={css.chip} />
<SvgIcon component={PushNotificationIcon} inheritViewBox fontSize="inherit" className={css.icon} />
</Grid>
<Grid item xs={9}>
<Typography variant="subtitle2" fontWeight={700}>
Enable push notifications
</Typography>
<IconButton onClick={dismissBanner} className={css.close}>
<SvgIcon component={CloseIcon} inheritViewBox color="border" fontSize="small" />
</IconButton>
<Typography mt={0.5} mb={1.5} variant="body2">
Get notified about pending signatures, incoming and outgoing transactions for all Safe Accounts on{' '}
{chain?.chainName} when Safe
{`{Wallet}`} is in the background or closed.
</Typography>
{/* Cannot wrap singular button as it causes style inconsistencies */}
<CheckWallet>
{(isOk) => (
<div className={css.buttons}>
{totalAddedSafes > 0 && (
<Button
variant="contained"
size="small"
className={css.button}
onClick={onEnableAll}
disabled={!isOk || !onboard}
>
Enable all
</Button>
</Link>
)}
</div>
)}
</CheckWallet>
)}
{safe && (
<Link passHref href={{ pathname: AppRoutes.settings.notifications, query }} onClick={onCustomize}>
<Button variant="outlined" size="small" className={css.button}>
Customize
</Button>
</Link>
)}
</div>
)}
</CheckWallet>
</Grid>
</Grid>
</Grid>
}
open
>
<span>{children}</span>
</CustomTooltip>
}
open
>
<span>{children}</span>
</CustomTooltip>
</>
)
}
6 changes: 3 additions & 3 deletions src/services/analytics/events/push-notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export const PUSH_NOTIFICATION_EVENTS = {
action: 'Unregister device notifications',
category,
},
// Notification banner displayed
DISPLAY_BANNER: {
action: 'Display notification banner',
// Notification banner shown
SHOW_BANNER: {
action: 'Show notification banner',
category,
},
// User dismissed notfication banner
Expand Down
Loading