Skip to content

Commit

Permalink
refactor: Move hooks into counterfactual folder
Browse files Browse the repository at this point in the history
  • Loading branch information
usame-algan committed Feb 13, 2024
1 parent 2787771 commit ce91d3a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { useEffect } from 'react'
import { formatError } from '@/utils/formatters'
import { showNotification } from '@/store/notificationsSlice'
import { useAppDispatch } from '@/store'
import { useCurrentChain } from './useChains'
import useSafeAddress from './useSafeAddress'
import { useCurrentChain } from '@/hooks/useChains'
import useSafeAddress from '@/hooks/useSafeAddress'
import { isWalletRejection } from '@/utils/wallets'

const SafeCreationNotifications = {
Expand All @@ -22,17 +22,11 @@ enum Variant {
ERROR = 'error',
}

const successEvents = [SafeCreationEvent.SUCCESS]

const usePendingSafeNotifications = (): void => {
const dispatch = useAppDispatch()
const chain = useCurrentChain()
const safeAddress = useSafeAddress()

/**
* Show notifications of a transaction's lifecycle
*/

useEffect(() => {
if (!chain) return

Expand All @@ -43,7 +37,7 @@ const usePendingSafeNotifications = (): void => {
const isError = 'error' in detail
if (isError && isWalletRejection(detail.error)) return

const isSuccess = successEvents.includes(event)
const isSuccess = event === SafeCreationEvent.SUCCESS
const message = isError ? `${baseMessage} ${formatError(detail.error)}` : baseMessage
const txHash = 'txHash' in detail ? detail.txHash : undefined
const groupKey = 'groupKey' in detail && detail.groupKey ? detail.groupKey : txHash || ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { checkSafeActionViaRelay, checkSafeActivation } from '@/features/counter
import { isSmartContract, useWeb3ReadOnly } from '@/hooks/wallets/web3'
import { useAppDispatch, useAppSelector } from '@/store'
import { useEffect, useRef } from 'react'
import useChainId from './useChainId'
import useSafeInfo from './useSafeInfo'
import useChainId from '@/hooks/useChainId'
import useSafeInfo from '@/hooks/useSafeInfo'

const pendingStatuses: Partial<Record<SafeCreationEvent, PendingSafeStatus | null>> = {
[SafeCreationEvent.PROCESSING]: PendingSafeStatus.PROCESSING,
Expand Down Expand Up @@ -44,19 +44,16 @@ const usePendingSafeMonitor = (): void => {
const isProcessing = status === PendingSafeStatus.PROCESSING && txHash !== undefined
const isRelaying = status === PendingSafeStatus.RELAYING && taskId !== undefined
const isMonitored = monitoredSafes.current[safeAddress]
console.log({ isMonitored })

if ((!isProcessing && !isRelaying) || isMonitored) return

monitoredSafes.current[safeAddress] = true

if (isProcessing) {
console.log(isProcessing)
checkSafeActivation(provider, txHash, safeAddress)
}

if (isRelaying) {
console.log(isRelaying)
checkSafeActionViaRelay(taskId, safeAddress)
}
}
Expand Down Expand Up @@ -110,7 +107,6 @@ const usePendingSafeStatus = (): void => {
return
}

// Or set a new status
dispatch(
updateUndeployedSafeStatus({
chainId: safe.chainId,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import usePendingSafeNotifications from '@/hooks/usePendingSafeNotifications'
import usePendingSafeStatus from '@/hooks/usePendingSafeStatuses'
import usePendingSafeNotifications from '@/features/counterfactual/hooks/usePendingSafeNotifications'
import usePendingSafeStatus from '@/features/counterfactual/hooks/usePendingSafeStatuses'
import { SentryErrorBoundary } from '@/services/sentry' // needs to be imported first
import useRehydrateSocialWallet from '@/hooks/wallets/mpc/useRehydrateSocialWallet'
import PasswordRecoveryModal from '@/services/mpc/PasswordRecoveryModal'
Expand Down

0 comments on commit ce91d3a

Please sign in to comment.