-
Notifications
You must be signed in to change notification settings - Fork 192
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
refactor: pull header & wallet components out of Swap component #123
base: wallet-connect-flow
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
import { Trans } from '@lingui/macro' | ||
import { useWeb3React } from '@web3-react/core' | ||
import useOnSupportedNetwork from 'hooks/useOnSupportedNetwork' | ||
import { largeIconCss } from 'icons' | ||
import { ReactElement, ReactNode } from 'react' | ||
import { useAtom } from 'jotai' | ||
import { useEffect } from 'react' | ||
import { onConnectWalletClickAtom } from 'state/swap' | ||
import styled from 'styled-components/macro' | ||
import { ThemedText } from 'theme' | ||
|
||
import Wallet from './ConnectWallet' | ||
import Row from './Row' | ||
import Settings from './Swap/Settings' | ||
|
||
const HeaderRow = styled(Row)` | ||
height: 1.75em; | ||
|
@@ -13,15 +20,33 @@ const HeaderRow = styled(Row)` | |
` | ||
|
||
export interface HeaderProps { | ||
title?: ReactElement | ||
children: ReactNode | ||
hideConnectionUI?: boolean | ||
onConnectWalletClick?: () => void | Promise<boolean> | ||
} | ||
|
||
export default function Header({ title, children }: HeaderProps) { | ||
export default function Header(props: HeaderProps) { | ||
const { isActive } = useWeb3React() | ||
const onSupportedNetwork = useOnSupportedNetwork() | ||
const isDisabled = !(isActive && onSupportedNetwork) | ||
|
||
const [onConnectWalletClick, setOnConnectWalletClick] = useAtom(onConnectWalletClickAtom) | ||
useEffect(() => { | ||
if (props.onConnectWalletClick !== onConnectWalletClick) { | ||
setOnConnectWalletClick((old: (() => void | Promise<boolean>) | undefined) => (old = props.onConnectWalletClick)) | ||
} | ||
}, [props.onConnectWalletClick, onConnectWalletClick, setOnConnectWalletClick]) | ||
|
||
return ( | ||
<HeaderRow iconSize={1.2}> | ||
<Row gap={0.5}>{title && <ThemedText.Subhead1>{title}</ThemedText.Subhead1>}</Row> | ||
<Row gap={1}>{children}</Row> | ||
<Row gap={0.5}> | ||
<ThemedText.Subhead1> | ||
<Trans>Swap</Trans> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should widgets expand past |
||
</ThemedText.Subhead1> | ||
</Row> | ||
<Row gap={1}> | ||
<Wallet disabled={props.hideConnectionUI} /> | ||
<Settings disabled={isDisabled} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Settings is specific to the Swap widget (similar to the title) - this either needs to be a prop, or a callback to activate the Swap's settings. |
||
</Row> | ||
</HeaderRow> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import 'polyfills' | ||
|
||
import Header, { HeaderProps } from 'components/Header' | ||
import Swap, { SwapProps } from 'components/Swap' | ||
import Widget, { WidgetProps } from 'components/Widget' | ||
export type { Provider as EthersProvider } from '@ethersproject/abstract-provider' | ||
|
@@ -14,11 +15,12 @@ export type { DefaultAddress, TokenDefaults } from 'hooks/swap/useSyncTokenDefau | |
export type { Theme } from 'theme' | ||
export { darkTheme, defaultTheme, lightTheme } from 'theme' | ||
|
||
export type SwapWidgetProps = SwapProps & WidgetProps | ||
export type SwapWidgetProps = HeaderProps & SwapProps & WidgetProps | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be an interface extending the existing props:
This is slightly easier on the type system: it reduces time for type checking and it surfaces better types downstream. |
||
|
||
export function SwapWidget(props: SwapWidgetProps) { | ||
return ( | ||
<Widget {...props}> | ||
<Header {...props} /> | ||
<Swap {...props} /> | ||
</Widget> | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to set this without referencing the already-set value: