Commit f45a7f92 authored by Vignesh Mohankumar's avatar Vignesh Mohankumar Committed by GitHub

fix: handle switchChain failure in swap (#6507)

* fix: handle switchChain failure in swap

* comment

* fix
parent 29db61ff
...@@ -38,6 +38,7 @@ import { TradeState } from 'state/routing/types' ...@@ -38,6 +38,7 @@ import { TradeState } from 'state/routing/types'
import styled, { useTheme } from 'styled-components/macro' import styled, { useTheme } from 'styled-components/macro'
import invariant from 'tiny-invariant' import invariant from 'tiny-invariant'
import { currencyAmountToPreciseFloat, formatTransactionAmount } from 'utils/formatNumbers' import { currencyAmountToPreciseFloat, formatTransactionAmount } from 'utils/formatNumbers'
import { didUserReject } from 'utils/swapErrorToUserReadableMessage'
import { switchChain } from 'utils/switchChain' import { switchChain } from 'utils/switchChain'
import AddressInputPanel from '../../components/AddressInputPanel' import AddressInputPanel from '../../components/AddressInputPanel'
...@@ -695,8 +696,17 @@ export function Swap({ ...@@ -695,8 +696,17 @@ export function Swap({
</TraceEvent> </TraceEvent>
) : chainId && chainId !== connectedChainId ? ( ) : chainId && chainId !== connectedChainId ? (
<ButtonPrimary <ButtonPrimary
onClick={() => { onClick={async () => {
switchChain(connector, chainId) try {
await switchChain(connector, chainId)
} catch (error) {
if (didUserReject(error)) {
// Ignore error, which keeps the user on the previous chain.
} else {
// TODO(WEB-3306): This UX could be improved to show an error state.
throw error
}
}
}} }}
> >
Connect to {getChainInfo(chainId)?.label} Connect to {getChainInfo(chainId)?.label}
......
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