Skip to content

Commit

Permalink
Close modal on path change
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Oct 26, 2023
1 parent 2a67f33 commit 752cd04
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/components/tx-flow/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createContext, type ReactElement, type ReactNode, useState, useEffect, useCallback, useRef } from 'react'
import { usePathname } from 'next/navigation'
import TxModalDialog from '@/components/common/TxModalDialog'
import { SuccessScreen } from './flows/SuccessScreen'
import useSafeAddress from '@/hooks/useSafeAddress'
Expand Down Expand Up @@ -29,6 +30,8 @@ export const TxModalProvider = ({ children }: { children: ReactNode }): ReactEle
const onClose = useRef<() => void>(noop)
const safeId = useChainId() + useSafeAddress()
const prevSafeId = useRef<string>(safeId ?? '')
const pathname = usePathname()
const prevPathname = useRef<string>(pathname)

const handleModalClose = useCallback(() => {
onClose.current()
Expand Down Expand Up @@ -73,9 +76,18 @@ export const TxModalProvider = ({ children }: { children: ReactNode }): ReactEle
if (txFlow) {
handleShowWarning()
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [txFlow, safeId])

Check warning on line 79 in src/components/tx-flow/index.tsx

View workflow job for this annotation

GitHub Actions / ESLint Results

react-hooks/exhaustive-deps

React Hook useEffect has a missing dependency: 'handleShowWarning'. Either include it or remove the dependency array. * [SUGGESTION] Update the dependencies array to be: [txFlow, safeId, handleShowWarning]

// // Close the modal when the path changes
useEffect(() => {
if (pathname === prevPathname.current) return
prevPathname.current = pathname

if (txFlow) {
handleShowWarning()
}
}, [txFlow, pathname])

Check warning on line 89 in src/components/tx-flow/index.tsx

View workflow job for this annotation

GitHub Actions / ESLint Results

react-hooks/exhaustive-deps

React Hook useEffect has a missing dependency: 'handleShowWarning'. Either include it or remove the dependency array. * [SUGGESTION] Update the dependencies array to be: [txFlow, pathname, handleShowWarning]

return (
<TxModalContext.Provider value={{ txFlow, setTxFlow, setFullWidth }}>
{children}
Expand Down

0 comments on commit 752cd04

Please sign in to comment.