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: close transaction flow if Safe changes #2526

Merged
merged 3 commits into from
Sep 21, 2023
Merged
Changes from 2 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
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 { safe } = useSafeInfo()
katspaugh marked this conversation as resolved.
Show resolved Hide resolved

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, safe.address.value])

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