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' } from 'state/mint/v3/hooks'
import styled, { useTheme } from 'styled-components' import styled, { useTheme } from 'styled-components'
import { addressesAreEquivalent } from 'utils/addressesAreEquivalent' import { addressesAreEquivalent } from 'utils/addressesAreEquivalent'
import { WrongChainError } from 'utils/errors'
import { ButtonError, ButtonLight, ButtonPrimary, ButtonText } from '../../components/Button' import { ButtonError, ButtonLight, ButtonPrimary, ButtonText } from '../../components/Button'
import { BlueCard, OutlineCard, YellowCard } from '../../components/Card' 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) setAttemptingTxn(true)
provider provider

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

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