From 7bae76af7cb6b36cbbab65a26253d3b1a5c08b78 Mon Sep 17 00:00:00 2001 From: eddie <66155195+just-toby@users.noreply.github.com> Date: Thu, 16 Mar 2023 10:31:09 -0700 Subject: [PATCH] fix: collapse toolbar when missing inputs (#562) --- src/components/Swap/Toolbar/ToolbarContext.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/Swap/Toolbar/ToolbarContext.tsx b/src/components/Swap/Toolbar/ToolbarContext.tsx index a9a952cea..46662f47b 100644 --- a/src/components/Swap/Toolbar/ToolbarContext.tsx +++ b/src/components/Swap/Toolbar/ToolbarContext.tsx @@ -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 @@ -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 {children} }