feat: check chain ID before all transactions (#7177)

* feat: check chain ID before all transactions

* fix: use WrongChainError

* fix: remove asyncs
This commit is contained in:
eddie 2023-09-12 11:20:06 -07:00 committed by GitHub
parent a9b2179eab
commit 3e05db4b87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 1 deletions

@ -26,6 +26,7 @@ import {
} from 'state/mint/v3/hooks'
import styled, { useTheme } from 'styled-components'
import { addressesAreEquivalent } from 'utils/addressesAreEquivalent'
import { WrongChainError } from 'utils/errors'
import { ButtonError, ButtonLight, ButtonPrimary, ButtonText } from '../../components/Button'
import { BlueCard, OutlineCard, YellowCard } from '../../components/Card'
@ -278,6 +279,9 @@ function AddLiquidity() {
}
}
const connectedChainId = await provider.getSigner().getChainId()
if (chainId !== connectedChainId) throw new WrongChainError()
setAttemptingTxn(true)
provider

@ -35,6 +35,7 @@ import { useIsTransactionPending, useTransactionAdder } from 'state/transactions
import styled, { useTheme } from 'styled-components'
import { ExternalLink, HideExtraSmall, HideSmall, StyledRouterLink, ThemedText } from 'theme'
import { currencyId } from 'utils/currencyId'
import { WrongChainError } from 'utils/errors'
import { formatCurrencyAmount } from 'utils/formatCurrencyAmount'
import { formatPrice, NumberType } from 'utils/formatNumbers'
import { formatTickPrice } from 'utils/formatTickPrice'
@ -491,7 +492,7 @@ function PositionPageContent() {
const addTransaction = useTransactionAdder()
const positionManager = useV3NFTPositionManagerContract()
const collect = useCallback(() => {
const collect = useCallback(async () => {
if (
!currency0ForFeeCollectionPurposes ||
!currency1ForFeeCollectionPurposes ||
@ -520,6 +521,9 @@ function PositionPageContent() {
value,
}
const connectedChainId = await provider.getSigner().getChainId()
if (chainId !== connectedChainId) throw new WrongChainError()
provider
.getSigner()
.estimateGas(txn)

@ -34,6 +34,7 @@ import { useTransactionAdder } from 'state/transactions/hooks'
import { useUserSlippageToleranceWithDefault } from 'state/user/hooks'
import { useTheme } from 'styled-components'
import { ThemedText } from 'theme'
import { WrongChainError } from 'utils/errors'
import TransactionConfirmationModal, { ConfirmationModalContent } from '../../components/TransactionConfirmationModal'
import { WRAPPED_NATIVE_CURRENCY } from '../../constants/tokens'
@ -142,6 +143,9 @@ function Remove({ tokenId }: { tokenId: BigNumber }) {
value,
}
const connectedChainId = await provider.getSigner().getChainId()
if (chainId !== connectedChainId) throw new WrongChainError()
provider
.getSigner()
.estimateGas(txn)