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: only delete all preferences per chain #2556

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
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 @@ -11,6 +11,7 @@ import {
ListItemButton,
ListItemIcon,
ListItemText,
CircularProgress,
} from '@mui/material'
import { Fragment, useEffect, useMemo, useState } from 'react'
import type { ReactElement } from 'react'
Expand Down Expand Up @@ -192,6 +193,7 @@ const shouldUnregisterDevice = (
export const GlobalPushNotifications = (): ReactElement | null => {
const chains = useChains()
const addedSafes = useAppSelector(selectAllAddedSafes)
const [isLoading, setIsLoading] = useState(false)

const { dismissPushNotificationBanner } = useDismissPushNotificationsBanner()
const { getAllPreferences } = useNotificationPreferences()
Expand Down Expand Up @@ -264,11 +266,14 @@ export const GlobalPushNotifications = (): ReactElement | null => {
return
}

setIsLoading(true)

// Although the (un-)registration functions will request permission in getToken we manually
// check beforehand to prevent multiple promises in registrationPromises from throwing
const isGranted = await requestNotificationPermission()

if (!isGranted) {
setIsLoading(false)
return
}

Expand Down Expand Up @@ -299,6 +304,8 @@ export const GlobalPushNotifications = (): ReactElement | null => {
await Promise.all(registrationPromises)

trackEvent(PUSH_NOTIFICATION_EVENTS.SAVE_SETTINGS)

setIsLoading(false)
}

if (totalNotifiableSafes === 0) {
Expand All @@ -322,8 +329,8 @@ export const GlobalPushNotifications = (): ReactElement | null => {

<CheckWallet allowNonOwner>
{(isOk) => (
<Button variant="contained" disabled={!canSave || !isOk} onClick={onSave}>
Save
<Button variant="contained" disabled={!canSave || !isOk || isLoading} onClick={onSave}>
{isLoading ? <CircularProgress size={20} /> : 'Save'}
</Button>
)}
</CheckWallet>
Expand Down
Loading