Commit 8c731576 authored by eddie's avatar eddie Committed by GitHub

fix: make WrongChainError more specific (#7175)

* fix: setTraceError in swap callback

* fix: move error class to util file
parent 290083b4
...@@ -12,7 +12,7 @@ import { useCallback } from 'react' ...@@ -12,7 +12,7 @@ import { useCallback } from 'react'
import { ClassicTrade, TradeFillType } from 'state/routing/types' import { ClassicTrade, TradeFillType } from 'state/routing/types'
import { trace } from 'tracing/trace' import { trace } from 'tracing/trace'
import { calculateGasMargin } from 'utils/calculateGasMargin' import { calculateGasMargin } from 'utils/calculateGasMargin'
import { UserRejectedRequestError } from 'utils/errors' import { UserRejectedRequestError, WrongChainError } from 'utils/errors'
import isZero from 'utils/isZero' import isZero from 'utils/isZero'
import { didUserReject, swapErrorToUserReadableMessage } from 'utils/swapErrorToUserReadableMessage' import { didUserReject, swapErrorToUserReadableMessage } from 'utils/swapErrorToUserReadableMessage'
...@@ -61,7 +61,7 @@ export function useUniversalRouterSwapCallback( ...@@ -61,7 +61,7 @@ export function useUniversalRouterSwapCallback(
if (!provider) throw new Error('missing provider') if (!provider) throw new Error('missing provider')
if (!trade) throw new Error('missing trade') if (!trade) throw new Error('missing trade')
const connectedChainId = await provider.getSigner().getChainId() const connectedChainId = await provider.getSigner().getChainId()
if (chainId !== connectedChainId) throw new Error('signer chainId does not match') if (chainId !== connectedChainId) throw new WrongChainError()
setTraceData('slippageTolerance', options.slippageTolerance.toFixed(2)) setTraceData('slippageTolerance', options.slippageTolerance.toFixed(2))
const { calldata: data, value } = SwapRouter.swapERC20CallParameters(trade, { const { calldata: data, value } = SwapRouter.swapERC20CallParameters(trade, {
......
// You may throw an instance of this class when the user rejects a request in their wallet. // You may throw an instance of this class when the user rejects a request in their wallet.
import { t } from '@lingui/macro'
// The benefit is that you can distinguish this error from other errors using didUserReject(). // The benefit is that you can distinguish this error from other errors using didUserReject().
export class UserRejectedRequestError extends Error { export class UserRejectedRequestError extends Error {
constructor(message: string) { constructor(message: string) {
...@@ -14,3 +17,9 @@ export function toReadableError(errorText: string, error: unknown) { ...@@ -14,3 +17,9 @@ export function toReadableError(errorText: string, error: unknown) {
} }
return new Error(`${errorText} 👺 ${error}`) return new Error(`${errorText} 👺 ${error}`)
} }
export class WrongChainError extends Error {
constructor() {
super(t`Your wallet is connected to the wrong 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