diff --git a/src/hooks/useCurrentBlockTimestamp.ts b/src/hooks/useCurrentBlockTimestamp.ts index 880d6c9f8e..26696befcc 100644 --- a/src/hooks/useCurrentBlockTimestamp.ts +++ b/src/hooks/useCurrentBlockTimestamp.ts @@ -1,20 +1,15 @@ import { BigNumber } from '@ethersproject/bignumber' import { useSingleCallResult } from 'lib/hooks/multicall' -import { useEffect, useState } from 'react' +import { useMemo } from 'react' import { useInterfaceMulticall } from './useContract' // gets the current timestamp from the blockchain export default function useCurrentBlockTimestamp(): BigNumber | undefined { - const [lastBlock, setLastBlock] = useState() const multicall = useInterfaceMulticall() - const block: BigNumber | undefined = useSingleCallResult(multicall, 'getCurrentBlockTimestamp')?.result?.[0] - useEffect(() => { - // If block xor lastBlock are undefined, or if block has progressed, then update lastBlock. - // This prevents updates when the block doesn't change, because the returned BigNumber will still be referentially unique. - if (Boolean(block) !== Boolean(lastBlock) || (block && lastBlock && !block.eq(lastBlock))) { - setLastBlock(block) - } - }, [block, lastBlock]) - return lastBlock + const resultStr: string | undefined = useSingleCallResult( + multicall, + 'getCurrentBlockTimestamp' + )?.result?.[0]?.toString() + return useMemo(() => (typeof resultStr === 'string' ? BigNumber.from(resultStr) : undefined), [resultStr]) } diff --git a/src/hooks/useGasPrice.ts b/src/hooks/useGasPrice.ts index 81cb33dcd0..d25287a37f 100644 --- a/src/hooks/useGasPrice.ts +++ b/src/hooks/useGasPrice.ts @@ -1,5 +1,6 @@ import JSBI from 'jsbi' import { useSingleCallResult } from 'lib/hooks/multicall' +import { useMemo } from 'react' import { useContract } from './useContract' import useENSAddress from './useENSAddress' @@ -22,5 +23,5 @@ export default function useGasPrice(): JSBI | undefined { const contract = useContract(address ?? undefined, CHAIN_DATA_ABI, false) const resultStr = useSingleCallResult(contract, 'latestAnswer').result?.[0]?.toString() - return typeof resultStr === 'string' ? JSBI.BigInt(resultStr) : undefined + return useMemo(() => (typeof resultStr === 'string' ? JSBI.BigInt(resultStr) : undefined), [resultStr]) } diff --git a/src/hooks/useIsArgentWallet.ts b/src/hooks/useIsArgentWallet.ts index 626fa9f48d..d5222439ba 100644 --- a/src/hooks/useIsArgentWallet.ts +++ b/src/hooks/useIsArgentWallet.ts @@ -9,5 +9,5 @@ export default function useIsArgentWallet(): boolean { const argentWalletDetector = useArgentWalletDetectorContract() const inputs = useMemo(() => [account ?? undefined], [account]) const call = useSingleCallResult(argentWalletDetector, 'isArgentWallet', inputs, NEVER_RELOAD) - return call?.result?.[0] ?? false + return Boolean(call?.result?.[0]) } diff --git a/src/hooks/useTotalSupply.ts b/src/hooks/useTotalSupply.ts index 90b09a0cb5..2113742582 100644 --- a/src/hooks/useTotalSupply.ts +++ b/src/hooks/useTotalSupply.ts @@ -1,6 +1,6 @@ -import { BigNumber } from '@ethersproject/bignumber' import { Currency, CurrencyAmount, Token } from '@uniswap/sdk-core' import { useSingleCallResult } from 'lib/hooks/multicall' +import { useMemo } from 'react' import { useTokenContract } from './useContract' @@ -9,7 +9,10 @@ import { useTokenContract } from './useContract' export function useTotalSupply(token?: Currency): CurrencyAmount | undefined { const contract = useTokenContract(token?.isToken ? token.address : undefined, false) - const totalSupply: BigNumber = useSingleCallResult(contract, 'totalSupply')?.result?.[0] + const totalSupplyStr: string | undefined = useSingleCallResult(contract, 'totalSupply')?.result?.[0]?.toString() - return token?.isToken && totalSupply ? CurrencyAmount.fromRawAmount(token, totalSupply.toString()) : undefined + return useMemo( + () => (token?.isToken && totalSupplyStr ? CurrencyAmount.fromRawAmount(token, totalSupplyStr) : undefined), + [token, totalSupplyStr] + ) }