Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Oct 27, 2023
1 parent 50e9ced commit 68655b7
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions src/components/tx-flow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,15 @@ export const TxModalProvider = ({ children }: { children: ReactNode }): ReactEle
const prevPathname = useRef<string>(pathname)

const handleModalClose = useCallback(() => {
if (shouldWarn.current && !confirmClose()) {
return
}
onClose.current()
onClose.current = noop
setFlow(undefined)
}, [])

const handleShowWarning = useCallback(() => {
if (shouldWarn.current && !confirmClose()) {
return
}
handleModalClose()
}, [handleModalClose])

// Open a new tx flow, close the previous one if any
const setTxFlow = useCallback(
(newTxFlow: TxModalContextType['txFlow'], newOnClose?: () => void, newShouldWarn?: boolean) => {
setFlow((prev) => {
Expand All @@ -68,31 +65,23 @@ export const TxModalProvider = ({ children }: { children: ReactNode }): ReactEle
[],
)

// // Close the modal when the Safe changes
// Close the modal when the user navigates to a different Safe or route
useEffect(() => {
if (safeId === prevSafeId.current) return
prevSafeId.current = safeId

if (txFlow) {
handleShowWarning()
}
}, [txFlow, safeId])
if (safeId === prevSafeId.current && pathname === prevPathname.current) return

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

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

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

<TxModalDialog open={!!txFlow} onClose={handleShowWarning} fullWidth={fullWidth}>
<TxModalDialog open={!!txFlow} onClose={handleModalClose} fullWidth={fullWidth}>
{txFlow}
</TxModalDialog>
</TxModalContext.Provider>
Expand Down

0 comments on commit 68655b7

Please sign in to comment.