Skip to content

Commit

Permalink
fix: dedup types (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzmp authored Oct 11, 2022
1 parent 96dcf22 commit 4c1d787
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
17 changes: 9 additions & 8 deletions src/components/Swap/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { JsonRpcProvider } from '@ethersproject/providers'
import { Trans } from '@lingui/macro'
import { Provider as Eip1193Provider } from '@web3-react/types'
import BrandedFooter from 'components/BrandedFooter'
import Wallet from 'components/ConnectWallet'
import { SwapInfoProvider } from 'hooks/swap/useSwapInfo'
import useSyncController, { SwapController, SwapSettingsController } from 'hooks/swap/useSyncController'
import useSyncController, { SwapController } from 'hooks/swap/useSyncController'
import useSyncConvenienceFee, { FeeOptions } from 'hooks/swap/useSyncConvenienceFee'
import useSyncSwapEventHandlers, { SwapEventHandlers } from 'hooks/swap/useSyncSwapEventHandlers'
import useSyncTokenDefaults, { TokenDefaults } from 'hooks/swap/useSyncTokenDefaults'
Expand All @@ -31,17 +29,20 @@ import useValidate from './useValidate'
// since the wallet connection component exists within the Swap component.
// This includes useSyncWidgetEventHandlers.
// TODO(zzmp): refactor WalletConnection outside of Swap component
export interface SwapProps extends BrandingSettings, FeeOptions, SwapEventHandlers, TokenDefaults, WidgetEventHandlers {
export interface SwapProps
extends BrandingSettings,
FeeOptions,
SwapController,
SwapEventHandlers,
TokenDefaults,
WidgetEventHandlers {
hideConnectionUI?: boolean
provider?: Eip1193Provider | JsonRpcProvider
routerUrl?: string
settings?: SwapSettingsController
value?: SwapController
}

export default function Swap(props: SwapProps) {
useValidate(props)
useSyncController(props)
useSyncController(props as SwapController)
useSyncConvenienceFee(props as FeeOptions)
useSyncSwapEventHandlers(props as SwapEventHandlers)
useSyncTokenDefaults(props as TokenDefaults)
Expand Down
3 changes: 1 addition & 2 deletions src/components/Widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ALL_SUPPORTED_CHAIN_IDS, SupportedChainId } from 'constants/chains'
import { DEFAULT_LOCALE, SUPPORTED_LOCALES, SupportedLocale } from 'constants/locales'
import { TransactionEventHandlers, TransactionsUpdater } from 'hooks/transactions'
import { BlockNumberProvider } from 'hooks/useBlockNumber'
import { BrandingSettings } from 'hooks/useSyncBrandingSetting'
import { TokenListProvider } from 'hooks/useTokenList'
import { Provider as Web3ReactProvider } from 'hooks/web3'
import { JsonRpcConnectionMap } from 'hooks/web3/useJsonRpcUrlsMap'
Expand Down Expand Up @@ -95,7 +94,7 @@ export const DialogWrapper = styled.div`
}
`

export interface WidgetProps extends BrandingSettings, TransactionEventHandlers {
export interface WidgetProps extends TransactionEventHandlers {
theme?: Theme
locale?: SupportedLocale
provider?: Eip1193Provider | JsonRpcProvider | null
Expand Down
14 changes: 5 additions & 9 deletions src/hooks/swap/useSyncController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ import { useEffect, useRef } from 'react'
import { controlledAtom as swapAtom, Swap } from 'state/swap'
import { controlledAtom as settingsAtom, Settings } from 'state/swap/settings'

export type SwapSettingsController = Settings
export type SwapController = Swap
export interface SwapController {
value?: Swap
settings?: Settings
}

export default function useSyncController({
value,
settings,
}: {
value?: SwapController
settings?: SwapSettingsController
}): void {
export default function useSyncController({ value, settings }: SwapController): void {
// Log an error if the component changes from uncontrolled to controlled (or vice versa).
const isSwapControlled = useRef(Boolean(value))
const isSettingsControlled = useRef(Boolean(settings))
Expand Down
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export { SwapWidgetSkeleton } from 'components/Swap/Skeleton'
export { SupportedChainId } from 'constants/chains'
export type { SupportedLocale } from 'constants/locales'
export { DEFAULT_LOCALE, SUPPORTED_LOCALES } from 'constants/locales'
export type { SwapController, SwapSettingsController } from 'hooks/swap/useSyncController'
export type { SwapController } from 'hooks/swap/useSyncController'
export type { FeeOptions } from 'hooks/swap/useSyncConvenienceFee'
export type { DefaultAddress, TokenDefaults } from 'hooks/swap/useSyncTokenDefaults'
export type { OnTxFail, OnTxSubmit, OnTxSuccess, TransactionEventHandlers } from 'hooks/transactions'
Expand Down

1 comment on commit 4c1d787

@vercel
Copy link

@vercel vercel bot commented on 4c1d787 Oct 11, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

widgets – ./

widgets-uniswap.vercel.app
widgets-git-main-uniswap.vercel.app
widgets-seven-tau.vercel.app

Please sign in to comment.