Skip to content

Commit 26b5745

Browse files
committed
feat: handle close notification modal
1 parent cb1acc3 commit 26b5745

File tree

9 files changed

+54
-38
lines changed

9 files changed

+54
-38
lines changed

src/Modals.tsx

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import W3iContext from '@/contexts/W3iContext/context'
1111
import { SignatureModal } from '@/pages/Login/SignatureModal'
1212
import { useModals } from '@/utils/hooks'
1313
import { useNotificationPermissionState } from '@/utils/hooks/notificationHooks'
14-
import { notificationsEnabledInBrowser } from '@/utils/notifications'
15-
import { isMobileButNotInstalledOnHomescreen } from '@/utils/pwa'
14+
import {
15+
checkIfNotificationModalClosed,
16+
notificationsEnabledInBrowser
17+
} from '@/utils/notifications'
18+
import { isMobileButNotInstalledOnHomeScreen } from '@/utils/pwa'
1619
import { notificationPwaModalService, signatureModalService } from '@/utils/store'
1720
import { isMobile } from '@/utils/ui'
1821

@@ -29,20 +32,17 @@ export const Modals = () => {
2932

3033
const notificationsEnabled = useNotificationPermissionState()
3134

32-
console.log({perms: window.Notification.permission})
33-
35+
const notificationModalClosed = checkIfNotificationModalClosed()
3436
const explicitlyDeniedOnDesktop = !isMobile() && window.Notification?.permission === 'denied'
3537

36-
const shouldShowNotificationModal = useMemo(
37-
() =>
38-
notificationsEnabledInBrowser() &&
39-
!explicitlyDeniedOnDesktop &&
40-
!isMobileButNotInstalledOnHomescreen() &&
41-
!notificationsEnabled &&
42-
Boolean(notifyRegisteredKey) &&
43-
!isSignatureModalOpen,
44-
[explicitlyDeniedOnDesktop, notificationsEnabled, notifyRegisteredKey, isSignatureModalOpen]
45-
)
38+
const shouldShowNotificationModal =
39+
notificationsEnabledInBrowser() &&
40+
!explicitlyDeniedOnDesktop &&
41+
!isMobileButNotInstalledOnHomeScreen() &&
42+
!notificationsEnabled &&
43+
Boolean(notifyRegisteredKey) &&
44+
!isSignatureModalOpen &&
45+
!notificationModalClosed
4646

4747
useEffect(() => {
4848
const notifySignatureRequired = Boolean(notifyRegisterMessage) && !notifyRegisteredKey
@@ -66,20 +66,18 @@ export const Modals = () => {
6666
}, [shouldShowNotificationModal])
6767

6868
return (
69-
<>
70-
<AnimatePresence mode="popLayout">
71-
{isUnsubscribeModalOpen && <UnsubscribeModal />}
69+
<AnimatePresence mode="popLayout">
70+
{isUnsubscribeModalOpen && <UnsubscribeModal />}
7271

73-
{isPreferencesModalOpen && <PreferencesModal />}
72+
{isPreferencesModalOpen && <PreferencesModal />}
7473

75-
{isSignatureModalOpen && (
76-
<SignatureModal message={notifyRegisterMessage ?? ''} sender={'notify'} />
77-
)}
74+
{isSignatureModalOpen && (
75+
<SignatureModal message={notifyRegisterMessage ?? ''} sender={'notify'} />
76+
)}
7877

79-
{isMobileButNotInstalledOnHomescreen() && <PwaModal />}
78+
{isMobileButNotInstalledOnHomeScreen() && <PwaModal />}
8079

81-
{isNotificationPwaModalOpen && <NotificationPwaModal />}
82-
</AnimatePresence>
83-
</>
80+
{isNotificationPwaModalOpen && <NotificationPwaModal />}
81+
</AnimatePresence>
8482
)
8583
}

src/components/general/Icon/CrossIcon.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const CrossIcon: React.FC = () => {
55
<svg fill="none" viewBox="0 0 16 16">
66
<path
77
fill="currentColor"
8-
fill-rule="evenodd"
8+
fillRule="evenodd"
99
d="M2.54 2.54a1 1 0 0 1 1.42 0L8 6.6l4.04-4.05a1 1 0 1 1 1.42 1.42L9.4 8l4.05 4.04a1 1 0 0 1-1.42 1.42L8 9.4l-4.04 4.05a1 1 0 0 1-1.42-1.42L6.6 8 2.54 3.96a1 1 0 0 1 0-1.42Z"
1010
clipRule="evenodd"
1111
></path>

src/components/general/Icon/SignatureIcon.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const SignatureIcon: React.FC = () => {
1919
fill="#3ABDF2"
2020
d="M39.83 62.83a20.35 20.35 0 0 1 28.34 0l.95.92c.39.39.39 1 0 1.4l-3.23 3.15a.5.5 0 0 1-.7 0l-1.3-1.27a14.2 14.2 0 0 0-19.78 0l-1.39 1.36a.5.5 0 0 1-.7 0l-3.23-3.16c-.39-.38-.39-1 0-1.39l1.04-1Zm35 6.53 2.88 2.8c.39.39.39 1 0 1.4L64.77 86.21c-.39.38-1.02.38-1.41 0l-9.18-9a.25.25 0 0 0-.36 0l-9.18 9c-.39.38-1.02.38-1.41 0L30.29 73.55c-.39-.38-.39-1 0-1.39l2.87-2.8c.4-.39 1.03-.39 1.42 0l9.18 8.98c.1.1.26.1.35 0l9.18-8.98c.4-.39 1.03-.39 1.42 0l9.18 8.98c.1.1.25.1.35 0l9.18-8.98c.4-.39 1.03-.39 1.42 0Z"
2121
/>
22-
<circle cx="53.9" cy="72" r="39.5" stroke="#062B2B" stroke-opacity=".02" />
22+
<circle cx="53.9" cy="72" r="39.5" stroke="#062B2B" strokeOpacity=".02" />
2323
<defs>
2424
<clipPath id="a">
2525
<path fill="#fff" d="M85.9 33.9h76.2v76.2H85.9z" />

src/components/general/Modal/Modal.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
align-items: center;
2424
border-radius: 30px;
2525
background: var(--bg-color-1);
26-
border: 1px solid var(--border-color-2);
2726
box-shadow:
2827
0px 8px 22px -6px rgba(0, 0, 0, 0.12),
2928
0px 14px 64px -4px rgba(0, 0, 0, 0.12);

src/components/utils/NotificationPwaModal/NotificationPwaModal.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
gap: 2em;
88
position: relative;
99

10+
&__close-button {
11+
svg {
12+
color: var(--fg-color-3);
13+
}
14+
}
15+
1016
&__header {
1117
display: flex;
1218
justify-content: flex-end;

src/components/utils/NotificationPwaModal/index.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@ import React, { Fragment, useContext } from 'react'
22

33
import BackgroundImage from '@/assets/IntroBackground.png'
44
import Button from '@/components/general/Button'
5-
import WalletConnectIcon from '@/components/general/Icon/WalletConnectIcon'
5+
import CrossIcon from '@/components/general/Icon/CrossIcon'
66
import { Modal } from '@/components/general/Modal/Modal'
77
import Text from '@/components/general/Text'
88
import W3iContext from '@/contexts/W3iContext/context'
9-
import { requireNotifyPermission } from '@/utils/notifications'
9+
import { closeNotificationModal, requireNotifyPermission } from '@/utils/notifications'
1010
import { pwaModalService } from '@/utils/store'
1111

1212
import './NotificationPwaModal.scss'
13-
import CrossIcon from '@/components/general/Icon/CrossIcon'
1413

1514
export const NotificationPwaModal: React.FC = () => {
1615
const { notifyClientProxy } = useContext(W3iContext)
1716

17+
const explicitlyDeniedPermissionForNotifications = window.Notification?.permission === 'denied'
18+
1819
const handleEnableNotifications = async () => {
1920
const notificationPermissionGranted = await requireNotifyPermission()
2021

@@ -27,16 +28,14 @@ export const NotificationPwaModal: React.FC = () => {
2728
}
2829
}
2930

30-
const explicitlyDeniedPermissionForNotifications = window.Notification?.permission === 'denied'
31-
3231
return (
3332
<Modal onCloseModal={pwaModalService.closeModal}>
3433
<div className="NotificationPwaModal">
3534
<div className="NotificationPwaModal__header">
3635
<Button
37-
className="ContactsModal__close"
36+
className="NotificationPwaModal__close-button"
3837
customType="action-icon"
39-
onClick={pwaModalService.closeModal}
38+
onClick={closeNotificationModal}
4039
>
4140
<CrossIcon />
4241
</Button>

src/constants/localStorage.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const localStorageKeys = {
2+
notificationModalClosed: 'w3i:notification_modal_closed'
3+
}

src/utils/notifications.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { useEffect, useState } from 'react'
2-
31
import { NotifyClient } from '@walletconnect/notify-client'
42

3+
import { localStorageKeys } from '@/constants/localStorage'
4+
import { notificationPwaModalService } from '@/utils/store'
5+
56
import { getFirebaseToken } from './firebase'
67
import { getDbEchoRegistrations, getDbSymkeyStore } from './idb'
78

@@ -61,6 +62,16 @@ export const setupSubscriptionsSymkeys = async (topicSymkeyEntries: [string, str
6162
}
6263
}
6364

65+
export const closeNotificationModal = () => {
66+
localStorage.setItem(localStorageKeys.notificationModalClosed, 'true')
67+
notificationPwaModalService.closeModal()
68+
}
69+
70+
export const checkIfNotificationModalClosed = () => {
71+
const storageValue = localStorage.getItem(localStorageKeys.notificationModalClosed)
72+
return storageValue === 'true'
73+
}
74+
6475
export const notificationsEnabledInBrowser = () => {
6576
return 'Notification' in window
6677
}

src/utils/pwa.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ export const isInstalledOnHomescreen = () => {
88

99
export const isMobileBrowser = () => /iPhone|iPad|iPod|Android/i.test(navigator.userAgent)
1010

11-
export const isMobileButNotInstalledOnHomescreen = () =>
11+
export const isMobileButNotInstalledOnHomeScreen = () =>
1212
isMobileBrowser() && !isInstalledOnHomescreen()

0 commit comments

Comments
 (0)