Skip to content

Commit

Permalink
fix: collapse toolbar for wrap transactions (Uniswap#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
just-toby committed Mar 7, 2023
1 parent ce25f36 commit f74946e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
11 changes: 10 additions & 1 deletion src/components/Swap/Toolbar/ToolbarContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createContext, PropsWithChildren, useContext, useState } from 'react'
import { useIsWrap } from 'hooks/swap/useWrapCallback'
import { createContext, PropsWithChildren, useContext, useEffect, useState } from 'react'

export const Context = createContext<{
open: boolean
Expand All @@ -14,6 +15,14 @@ export function Provider({ children }: PropsWithChildren) {
const [open, setOpen] = useState(false)
const onToggleOpen = () => setOpen((open) => !open)
const collapse = () => setOpen(false)

const isWrap = useIsWrap()
useEffect(() => {
if (isWrap) {
collapse()
}
}, [isWrap])

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

Expand Down
14 changes: 5 additions & 9 deletions src/components/Swap/Toolbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ const ToolbarRow = styled(Row)<{ isExpandable?: true }>`
padding: 0 1rem;
`

interface ToolbarProps {
hideConnectionUI?: boolean
}

function CaptionRow() {
const {
[Field.INPUT]: { currency: inputCurrency },
Expand Down Expand Up @@ -187,7 +183,7 @@ function CaptionRow() {
)
}

function ToolbarActionButton({ hideConnectionUI }: ToolbarProps) {
function ToolbarActionButton() {
const {
[Field.INPUT]: { currency: inputCurrency, balance: inputBalance, amount: inputAmount },
[Field.OUTPUT]: { currency: outputCurrency },
Expand Down Expand Up @@ -217,19 +213,19 @@ function ToolbarActionButton({ hideConnectionUI }: ToolbarProps) {
return <SwapActionButton />
}

function Toolbar({ hideConnectionUI }: ToolbarProps) {
function Toolbar() {
return (
<>
<CaptionRow />
<ToolbarActionButton hideConnectionUI={hideConnectionUI} />
<ToolbarActionButton />
</>
)
}

export default memo(function WrappedToolbar(props: ToolbarProps) {
export default memo(function WrappedToolbar() {
return (
<ToolbarContextProvider>
<Toolbar {...props} />
<Toolbar />
</ToolbarContextProvider>
)
})
2 changes: 1 addition & 1 deletion src/components/Swap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default function Swap(props: SwapProps) {
<Input />
<ReverseButton />
<Output />
<Toolbar hideConnectionUI={props.hideConnectionUI} />
<Toolbar />
{useBrandedFooter() && <BrandedFooter />}
</SwapInfoProvider>
</PopoverBoundaryProvider>
Expand Down

0 comments on commit f74946e

Please sign in to comment.