Skip to content

Commit

Permalink
fix: clear awaiting confirmation notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacook committed Oct 4, 2023
1 parent ca9892c commit 5c12eef
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/hooks/useTxNotifications.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useMemo } from 'react'
import { useEffect, useMemo, useRef } from 'react'
import { formatError } from '@/utils/formatters'
import type { LinkProps } from 'next/link'
import { selectNotifications, showNotification } from '@/store/notificationsSlice'
Expand Down Expand Up @@ -110,6 +110,7 @@ const useTxNotifications = (): void => {
const pendingTxs = useAppSelector(selectPendingTxs)
const notifications = useAppSelector(selectNotifications)
const wallet = useWallet()
const notifiedAwaitingTxIds = useRef<Array<string>>([])

const txsAwaitingConfirmation = useMemo(() => {
if (!page?.results) {
Expand All @@ -130,18 +131,22 @@ const useTxNotifications = (): void => {
}

const txId = txsAwaitingConfirmation[0].transaction.id
const hasNotified = notifications.some(({ groupKey }) => groupKey === txId)

if (!hasNotified) {
dispatch(
showNotification({
variant: 'info',
message: 'A transaction requires your confirmation.',
link: chain && getTxLink(txId, chain, safeAddress),
groupKey: txId,
}),
)
const hasNotified = notifiedAwaitingTxIds.current.includes(txId)

if (hasNotified) {
return
}

dispatch(
showNotification({
variant: 'info',
message: 'A transaction requires your confirmation.',
link: chain && getTxLink(txId, chain, safeAddress),
groupKey: txId,
}),
)

notifiedAwaitingTxIds.current.push(txId)
}, [chain, dispatch, isOwner, notifications, safeAddress, txsAwaitingConfirmation])
}

Expand Down

0 comments on commit 5c12eef

Please sign in to comment.