Commit 5dec0cf7 authored by Jordan Frankfurt's avatar Jordan Frankfurt Committed by GitHub

show wrong chain message instead of throwing on incorrect chain connection (#3153)

parent 1efda07e
import { ALL_SUPPORTED_CHAIN_IDS } from 'constants/chains' import { IntegrationError } from 'lib/errors'
import { ChainIdError, IntegrationError } from 'lib/errors'
import useActiveWeb3React from 'lib/hooks/useActiveWeb3React'
import { SwapWidgetProps } from 'lib/index' import { SwapWidgetProps } from 'lib/index'
import { useEffect } from 'react' import { useEffect } from 'react'
...@@ -14,13 +12,6 @@ export default function ErrorGenerator(swapWidgetProps: SwapWidgetProps) { ...@@ -14,13 +12,6 @@ export default function ErrorGenerator(swapWidgetProps: SwapWidgetProps) {
} }
}, [provider, jsonRpcEndpoint]) }, [provider, jsonRpcEndpoint])
const { chainId } = useActiveWeb3React()
useEffect(() => {
if (chainId && !ALL_SUPPORTED_CHAIN_IDS.includes(chainId)) {
throw new ChainIdError('Switch to a network supported by the Uniswap Protocol.')
}
}, [chainId])
// size constraints // size constraints
const { width } = swapWidgetProps const { width } = swapWidgetProps
useEffect(() => { useEffect(() => {
......
import { Trans } from '@lingui/macro' import { Trans } from '@lingui/macro'
import { ALL_SUPPORTED_CHAIN_IDS } from 'constants/chains'
import { useAtomValue } from 'jotai/utils' import { useAtomValue } from 'jotai/utils'
import useActiveWeb3React from 'lib/hooks/useActiveWeb3React'
import { AlertTriangle, Info, largeIconCss, Spinner } from 'lib/icons' import { AlertTriangle, Info, largeIconCss, Spinner } from 'lib/icons'
import { Field, Input, inputAtom, outputAtom, stateAtom, swapAtom } from 'lib/state/swap' import { Field, Input, inputAtom, outputAtom, stateAtom, swapAtom } from 'lib/state/swap'
import styled, { ThemedText, ThemeProvider } from 'lib/theme' import styled, { ThemedText, ThemeProvider } from 'lib/theme'
...@@ -65,6 +67,7 @@ export default function Toolbar({ disabled }: { disabled?: boolean }) { ...@@ -65,6 +67,7 @@ export default function Toolbar({ disabled }: { disabled?: boolean }) {
const input = useAtomValue(inputAtom) const input = useAtomValue(inputAtom)
const output = useAtomValue(outputAtom) const output = useAtomValue(outputAtom)
const balance = mockBalance const balance = mockBalance
const { chainId } = useActiveWeb3React()
const caption = useMemo(() => { const caption = useMemo(() => {
const filledInput = asFilledInput(input) const filledInput = asFilledInput(input)
...@@ -77,6 +80,14 @@ export default function Toolbar({ disabled }: { disabled?: boolean }) { ...@@ -77,6 +80,14 @@ export default function Toolbar({ disabled }: { disabled?: boolean }) {
</> </>
) )
} }
if (chainId && !ALL_SUPPORTED_CHAIN_IDS.includes(chainId)) {
return (
<>
<AlertTriangle color="secondary" />
<Trans>Unsupported network&#8211;switch to another to trade.</Trans>
</>
)
}
if (activeInput === Field.INPUT ? filledInput && output.token : filledOutput && input.token) { if (activeInput === Field.INPUT ? filledInput && output.token : filledOutput && input.token) {
if (!swap) { if (!swap) {
return ( return (
...@@ -109,7 +120,7 @@ export default function Toolbar({ disabled }: { disabled?: boolean }) { ...@@ -109,7 +120,7 @@ export default function Toolbar({ disabled }: { disabled?: boolean }) {
<Trans>Enter an amount</Trans> <Trans>Enter an amount</Trans>
</> </>
) )
}, [activeInput, balance, disabled, input, output, swap]) }, [activeInput, balance, chainId, disabled, input, output, swap])
return ( return (
<> <>
......
...@@ -4,10 +4,3 @@ export class IntegrationError extends Error { ...@@ -4,10 +4,3 @@ export class IntegrationError extends Error {
this.name = 'Integration Error' this.name = 'Integration Error'
} }
} }
export class ChainIdError extends Error {
constructor(message: string) {
super(message)
this.name = 'Unsupported network'
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment