Skip to content

Commit

Permalink
fix: close transaction flow if Safe changes (#2526)
Browse files Browse the repository at this point in the history
* fix: close transaction flow if Safe changes

* refactor: use `handleModalClose`

* fix: use `safeAddress` variable
  • Loading branch information
iamacook authored Sep 21, 2023
1 parent b9a5842 commit 37e6faf
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/components/tx-flow/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createContext, type ReactElement, type ReactNode, useState, useEffect, useCallback } from 'react'
import TxModalDialog from '@/components/common/TxModalDialog'
import { usePathname } from 'next/navigation'
import useSafeInfo from '@/hooks/useSafeInfo'

const noop = () => {}

Expand All @@ -23,6 +24,7 @@ export const TxModalProvider = ({ children }: { children: ReactNode }): ReactEle
const [fullWidth, setFullWidth] = useState<boolean>(false)
const pathname = usePathname()
const [, setLastPath] = useState<string>(pathname)
const { safeAddress, safe } = useSafeInfo()

const handleModalClose = useCallback(() => {
setOnClose((prevOnClose) => {
Expand Down Expand Up @@ -63,6 +65,13 @@ export const TxModalProvider = ({ children }: { children: ReactNode }): ReactEle
})
}, [txFlow, handleShowWarning, pathname])

// Close the modal when the Safe changes
useEffect(() => {
handleModalClose()
// Could have same address but different chain
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [safe.chainId, safeAddress])

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

0 comments on commit 37e6faf

Please sign in to comment.