This repository was archived by the owner on Jun 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 187
refactor: pull header & wallet components out of Swap component #123
Open
kristiehuang
wants to merge
3
commits into
wallet-connect-flow
Choose a base branch
from
wcf/refactor-wallet-connection-header
base: wallet-connect-flow
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+36
−31
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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,36 @@ const HeaderRow = styled(Row)` | |
| ` | ||
|
|
||
| export interface HeaderProps { | ||
| title?: ReactElement | ||
| children: ReactNode | ||
| title?: string | ||
| 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}> | ||
| {props.title && ( | ||
| <ThemedText.Subhead1> | ||
| <Trans>{props.title}</Trans> | ||
| </ThemedText.Subhead1> | ||
| )} | ||
| </Row> | ||
| <Row gap={1}> | ||
| <Wallet disabled={props.hideConnectionUI} /> | ||
| <Settings disabled={isDisabled} /> | ||
|
Contributor
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> | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
Contributor
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 title="Swap" {...props} /> | ||
|
kristiehuang marked this conversation as resolved.
Outdated
|
||
| <Swap {...props} /> | ||
| </Widget> | ||
| ) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: