Skip to content
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

Open
wants to merge 3 commits into
base: wallet-connect-flow
Choose a base branch
from

Conversation

kristiehuang
Copy link
Contributor

@kristiehuang kristiehuang commented Aug 3, 2022

Wallet connection + swap are two separate concerns, so should be two separate components imo

Refactoring to pull wallet out of the swap component

@vercel
Copy link

vercel bot commented Aug 3, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
widgets ✅ Ready (Inspect) Visit Preview Aug 3, 2022 at 4:13PM (UTC)

@kristiehuang kristiehuang changed the base branch from main to wallet-connect-flow August 3, 2022 15:57
@vercel vercel bot temporarily deployed to Preview August 3, 2022 16:01 Inactive
@kristiehuang kristiehuang changed the title Wcf/refactor wallet connection header refactor: pull header & wallet components out of Swap component Aug 3, 2022
src/index.tsx Outdated Show resolved Hide resolved
@JFrankfurt JFrankfurt requested a review from zzmp August 3, 2022 16:08
@kristiehuang kristiehuang marked this pull request as ready for review August 3, 2022 16:08
@vercel vercel bot temporarily deployed to Preview August 3, 2022 16:13 Inactive
Copy link
Contributor

@zzmp zzmp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change would couple src/components/Header to src/components/Swap. Header needs to be updated so that it does not couple Swap, in case we want to use it for other widgets in the future.

<Row gap={1}>{children}</Row>
<Row gap={0.5}>
<ThemedText.Subhead1>
<Trans>Swap</Trans>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should widgets expand past Swap, this will need to be configurable.
Can you keep passing title into the header?

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be an interface extending the existing props:

export interface SwapWidgetProps extends HeaderProps, SwapProps, WidgetProps {}

This is slightly easier on the type system: it reduces time for type checking and it surfaces better types downstream.

const onSupportedNetwork = useOnSupportedNetwork()
const isDisabled = !(isActive && onSupportedNetwork)

const [onConnectWalletClick, setOnConnectWalletClick] = useAtom(onConnectWalletClickAtom)
Copy link
Contributor

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:

const setOnConnectWalletClick = useSetAtom(onConnectWalletClickAtom)
useEffect(() => setOnConnectWalletClick(props.onConnectWalletClick), [props.onConnectWalletClick, setOnConnectWalletClick])

</Row>
<Row gap={1}>
<Wallet disabled={props.hideConnectionUI} />
<Settings disabled={isDisabled} />
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants