Skip to content

Commit

Permalink
fix: collapse toolbar when missing inputs (Uniswap#562)
Browse files Browse the repository at this point in the history
  • Loading branch information
just-toby authored Mar 16, 2023
1 parent e3c9a20 commit 7bae76a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/components/Swap/Toolbar/ToolbarContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useSwapInfo } from 'hooks/swap'
import { useIsWrap } from 'hooks/swap/useWrapCallback'
import { createContext, PropsWithChildren, useContext, useEffect, useState } from 'react'
import { Field } from 'state/swap'

export const Context = createContext<{
open: boolean
Expand All @@ -15,13 +17,20 @@ export function Provider({ children }: PropsWithChildren) {
const [open, setOpen] = useState(false)
const onToggleOpen = () => setOpen((open) => !open)
const collapse = () => setOpen(false)
const {
[Field.INPUT]: { currency: inputCurrency },
[Field.OUTPUT]: { currency: outputCurrency },
} = useSwapInfo()

const isWrap = useIsWrap()
useEffect(() => {
if (isWrap) {
collapse()
}
}, [isWrap])
if (!inputCurrency || !outputCurrency) {
collapse()
}
}, [isWrap, inputCurrency, outputCurrency])

return <Context.Provider value={{ open, onToggleOpen, collapse }}>{children}</Context.Provider>
}
Expand Down

0 comments on commit 7bae76a

Please sign in to comment.