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: Refetch owned safes after deployment #4673

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Changes from all 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
12 changes: 11 additions & 1 deletion src/features/counterfactual/hooks/usePendingSafeNotifications.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { SafeCreationEvent, safeCreationSubscribe } from '@/features/counterfactual/services/safeCreationEvents'
import useWallet from '@/hooks/wallets/useWallet'
import { useGetAllOwnedSafesQuery } from '@/store/api/gateway'
import { getBlockExplorerLink } from '@/utils/chains'
import { skipToken } from '@reduxjs/toolkit/query'
import { useEffect } from 'react'
import { formatError } from '@/utils/formatters'
import { showNotification } from '@/store/notificationsSlice'
Expand All @@ -26,6 +29,8 @@ const usePendingSafeNotifications = (): void => {
const dispatch = useAppDispatch()
const chain = useCurrentChain()
const safeAddress = useSafeAddress()
const { address = '' } = useWallet() || {}
const { refetch } = useGetAllOwnedSafesQuery(address === '' ? skipToken : { walletAddress: address })
Comment on lines +32 to +33
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its probably cleaner to create a new listener middleware for this. Wdyt @katspaugh @compojoom

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although it does require access to the connected wallet which I am not sure is possible inside a middleware. We would have to move the connected wallet state into Redux as well.


useEffect(() => {
if (!chain) return
Expand All @@ -43,6 +48,11 @@ const usePendingSafeNotifications = (): void => {
const groupKey = 'groupKey' in detail && detail.groupKey ? detail.groupKey : txHash || ''
const link = chain && txHash ? getBlockExplorerLink(chain, txHash) : undefined

// Fetch all owned safes after the Safe has been deployed
if (isSuccess) {
refetch()
}

dispatch(
showNotification({
title: 'Safe Account activation',
Expand All @@ -59,7 +69,7 @@ const usePendingSafeNotifications = (): void => {
return () => {
unsubFns.forEach((unsub) => unsub())
}
}, [dispatch, safeAddress, chain])
}, [dispatch, safeAddress, chain, refetch])
}

export default usePendingSafeNotifications

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Unnecessarily destructuring address with a default value of an empty string in useWallet(). Ensure useWallet() provides a consistent object structure.

  2. Dependencies for useEffect revised correctly, but consider removing the inline if condition for clarity: const skipTokenCondition = address === ''.

  3. Consider moving the logic from useEffect outside to maintain its primary role of side-effect management and prevent excess logic within the hook.

Loading