Commit e9ef3193 authored by Jesse's avatar Jesse Committed by GitHub

refactor: remaining changes from the large celo merge (#4088)

* refactor: useUSDCValue -> useStablecoinValue

* refactor: use the isCelo() helper

* refactor: remove unneeded white space
parent 6a1506ad
...@@ -6,7 +6,7 @@ import { Text } from 'rebass' ...@@ -6,7 +6,7 @@ import { Text } from 'rebass'
import { InterfaceTrade } from 'state/routing/types' import { InterfaceTrade } from 'state/routing/types'
import styled, { ThemeContext } from 'styled-components/macro' import styled, { ThemeContext } from 'styled-components/macro'
import { useUSDCValue } from '../../hooks/useStablecoinPrice' import { useStablecoinValue } from '../../hooks/useStablecoinPrice'
import { ThemedText } from '../../theme' import { ThemedText } from '../../theme'
import { isAddress, shortenAddress } from '../../utils' import { isAddress, shortenAddress } from '../../utils'
import { computeFiatValuePriceImpact } from '../../utils/computeFiatValuePriceImpact' import { computeFiatValuePriceImpact } from '../../utils/computeFiatValuePriceImpact'
...@@ -55,8 +55,8 @@ export default function SwapModalHeader({ ...@@ -55,8 +55,8 @@ export default function SwapModalHeader({
const [showInverted, setShowInverted] = useState<boolean>(false) const [showInverted, setShowInverted] = useState<boolean>(false)
const fiatValueInput = useUSDCValue(trade.inputAmount) const fiatValueInput = useStablecoinValue(trade.inputAmount)
const fiatValueOutput = useUSDCValue(trade.outputAmount) const fiatValueOutput = useStablecoinValue(trade.outputAmount)
return ( return (
<AutoColumn gap={'4px'} style={{ marginTop: '1rem' }}> <AutoColumn gap={'4px'} style={{ marginTop: '1rem' }}>
......
...@@ -9,7 +9,7 @@ import { useMemo } from 'react' ...@@ -9,7 +9,7 @@ import { useMemo } from 'react'
import { InterfaceTrade } from 'state/routing/types' import { InterfaceTrade } from 'state/routing/types'
import useGasPrice from './useGasPrice' import useGasPrice from './useGasPrice'
import useStablecoinPrice, { useUSDCValue } from './useStablecoinPrice' import useStablecoinPrice, { useStablecoinValue } from './useStablecoinPrice'
const V3_SWAP_DEFAULT_SLIPPAGE = new Percent(50, 10_000) // .50% const V3_SWAP_DEFAULT_SLIPPAGE = new Percent(50, 10_000) // .50%
const ONE_TENTHS_PERCENT = new Percent(10, 10_000) // .10% const ONE_TENTHS_PERCENT = new Percent(10, 10_000) // .10%
...@@ -37,7 +37,7 @@ export default function useAutoSlippageTolerance( ...@@ -37,7 +37,7 @@ export default function useAutoSlippageTolerance(
): Percent { ): Percent {
const { chainId } = useWeb3React() const { chainId } = useWeb3React()
const onL2 = chainId && L2_CHAIN_IDS.includes(chainId) const onL2 = chainId && L2_CHAIN_IDS.includes(chainId)
const outputDollarValue = useUSDCValue(trade?.outputAmount) const outputDollarValue = useStablecoinValue(trade?.outputAmount)
const nativeGasPrice = useGasPrice() const nativeGasPrice = useGasPrice()
const gasEstimate = guesstimateGas(trade) const gasEstimate = guesstimateGas(trade)
......
...@@ -7,6 +7,7 @@ import { useSingleContractWithCallData } from 'lib/hooks/multicall' ...@@ -7,6 +7,7 @@ import { useSingleContractWithCallData } from 'lib/hooks/multicall'
import { useMemo } from 'react' import { useMemo } from 'react'
import { InterfaceTrade, TradeState } from 'state/routing/types' import { InterfaceTrade, TradeState } from 'state/routing/types'
import { isCelo } from '../constants/tokens'
import { useAllV3Routes } from './useAllV3Routes' import { useAllV3Routes } from './useAllV3Routes'
import { useQuoter } from './useContract' import { useQuoter } from './useContract'
...@@ -36,10 +37,7 @@ export function useClientSideV3Trade<TTradeType extends TradeType>( ...@@ -36,10 +37,7 @@ export function useClientSideV3Trade<TTradeType extends TradeType>(
const { chainId } = useWeb3React() const { chainId } = useWeb3React()
// Chains deployed using the deploy-v3 script only deploy QuoterV2. // Chains deployed using the deploy-v3 script only deploy QuoterV2.
const useQuoterV2 = useMemo( const useQuoterV2 = useMemo(() => Boolean(chainId && isCelo(chainId)), [chainId])
() => Boolean(chainId && [SupportedChainId.CELO, SupportedChainId.CELO_ALFAJORES].includes(chainId)),
[chainId]
)
const quoter = useQuoter(useQuoterV2) const quoter = useQuoter(useQuoterV2)
const callData = useMemo( const callData = useMemo(
() => () =>
......
...@@ -62,7 +62,7 @@ export default function useStablecoinPrice(currency?: Currency): Price<Currency, ...@@ -62,7 +62,7 @@ export default function useStablecoinPrice(currency?: Currency): Price<Currency,
return lastPrice.current return lastPrice.current
} }
export function useUSDCValue(currencyAmount: CurrencyAmount<Currency> | undefined | null) { export function useStablecoinValue(currencyAmount: CurrencyAmount<Currency> | undefined | null) {
const price = useStablecoinPrice(currencyAmount?.currency) const price = useStablecoinPrice(currencyAmount?.currency)
return useMemo(() => { return useMemo(() => {
......
...@@ -8,7 +8,6 @@ import { useMemo } from 'react' ...@@ -8,7 +8,6 @@ import { useMemo } from 'react'
import { getTxOptimizedSwapRouter, SwapRouterVersion } from 'utils/getTxOptimizedSwapRouter' import { getTxOptimizedSwapRouter, SwapRouterVersion } from 'utils/getTxOptimizedSwapRouter'
import { ApprovalState, useApproval, useApprovalStateForSpender } from '../useApproval' import { ApprovalState, useApproval, useApprovalStateForSpender } from '../useApproval'
export { ApprovalState } from '../useApproval' export { ApprovalState } from '../useApproval'
/** Returns approval state for all known swap routers */ /** Returns approval state for all known swap routers */
......
...@@ -43,7 +43,7 @@ import { useArgentWalletContract } from '../../hooks/useArgentWalletContract' ...@@ -43,7 +43,7 @@ import { useArgentWalletContract } from '../../hooks/useArgentWalletContract'
import { useV3NFTPositionManagerContract } from '../../hooks/useContract' import { useV3NFTPositionManagerContract } from '../../hooks/useContract'
import { useDerivedPositionInfo } from '../../hooks/useDerivedPositionInfo' import { useDerivedPositionInfo } from '../../hooks/useDerivedPositionInfo'
import { useIsSwapUnsupported } from '../../hooks/useIsSwapUnsupported' import { useIsSwapUnsupported } from '../../hooks/useIsSwapUnsupported'
import { useUSDCValue } from '../../hooks/useStablecoinPrice' import { useStablecoinValue } from '../../hooks/useStablecoinPrice'
import useTransactionDeadline from '../../hooks/useTransactionDeadline' import useTransactionDeadline from '../../hooks/useTransactionDeadline'
import { useV3PositionFromTokenId } from '../../hooks/useV3Positions' import { useV3PositionFromTokenId } from '../../hooks/useV3Positions'
import { useToggleWalletModal } from '../../state/application/hooks' import { useToggleWalletModal } from '../../state/application/hooks'
...@@ -183,8 +183,8 @@ export default function AddLiquidity({ ...@@ -183,8 +183,8 @@ export default function AddLiquidity({
} }
const usdcValues = { const usdcValues = {
[Field.CURRENCY_A]: useUSDCValue(parsedAmounts[Field.CURRENCY_A]), [Field.CURRENCY_A]: useStablecoinValue(parsedAmounts[Field.CURRENCY_A]),
[Field.CURRENCY_B]: useUSDCValue(parsedAmounts[Field.CURRENCY_B]), [Field.CURRENCY_B]: useStablecoinValue(parsedAmounts[Field.CURRENCY_B]),
} }
// get the max amounts user can add // get the max amounts user can add
......
...@@ -42,7 +42,7 @@ import useENSAddress from '../../hooks/useENSAddress' ...@@ -42,7 +42,7 @@ import useENSAddress from '../../hooks/useENSAddress'
import { useERC20PermitFromTrade, UseERC20PermitState } from '../../hooks/useERC20Permit' import { useERC20PermitFromTrade, UseERC20PermitState } from '../../hooks/useERC20Permit'
import useIsArgentWallet from '../../hooks/useIsArgentWallet' import useIsArgentWallet from '../../hooks/useIsArgentWallet'
import { useIsSwapUnsupported } from '../../hooks/useIsSwapUnsupported' import { useIsSwapUnsupported } from '../../hooks/useIsSwapUnsupported'
import { useUSDCValue } from '../../hooks/useStablecoinPrice' import { useStablecoinValue } from '../../hooks/useStablecoinPrice'
import useWrapCallback, { WrapErrorText, WrapType } from '../../hooks/useWrapCallback' import useWrapCallback, { WrapErrorText, WrapType } from '../../hooks/useWrapCallback'
import { useToggleWalletModal } from '../../state/application/hooks' import { useToggleWalletModal } from '../../state/application/hooks'
import { Field } from '../../state/swap/actions' import { Field } from '../../state/swap/actions'
...@@ -153,8 +153,8 @@ export default function Swap({ history }: RouteComponentProps) { ...@@ -153,8 +153,8 @@ export default function Swap({ history }: RouteComponentProps) {
// show price estimates based on wrap trade // show price estimates based on wrap trade
const inputValue = showWrap ? parsedAmount : trade?.inputAmount const inputValue = showWrap ? parsedAmount : trade?.inputAmount
const outputValue = showWrap ? parsedAmount : trade?.outputAmount const outputValue = showWrap ? parsedAmount : trade?.outputAmount
const fiatValueInput = useUSDCValue(inputValue) const fiatValueInput = useStablecoinValue(inputValue)
const fiatValueOutput = useUSDCValue(outputValue) const fiatValueOutput = useStablecoinValue(outputValue)
const priceImpact = useMemo( const priceImpact = useMemo(
() => (routeIsSyncing ? undefined : computeFiatValuePriceImpact(fiatValueInput, fiatValueOutput)), () => (routeIsSyncing ? undefined : computeFiatValuePriceImpact(fiatValueInput, fiatValueOutput)),
[fiatValueInput, fiatValueOutput, routeIsSyncing] [fiatValueInput, fiatValueOutput, routeIsSyncing]
......
...@@ -7,6 +7,7 @@ import { useCallback, useEffect } from 'react' ...@@ -7,6 +7,7 @@ import { useCallback, useEffect } from 'react'
import { useAppDispatch } from 'state/hooks' import { useAppDispatch } from 'state/hooks'
import { useAllLists } from 'state/lists/hooks' import { useAllLists } from 'state/lists/hooks'
import { isCelo } from '../../constants/tokens'
import { useFetchListCallback } from '../../hooks/useFetchListCallback' import { useFetchListCallback } from '../../hooks/useFetchListCallback'
import useIsWindowVisible from '../../hooks/useIsWindowVisible' import useIsWindowVisible from '../../hooks/useIsWindowVisible'
import { acceptListUpdate, enableList } from './actions' import { acceptListUpdate, enableList } from './actions'
...@@ -36,7 +37,7 @@ export default function Updater(): null { ...@@ -36,7 +37,7 @@ export default function Updater(): null {
if (chainId && [SupportedChainId.ARBITRUM_ONE, SupportedChainId.ARBITRUM_RINKEBY].includes(chainId)) { if (chainId && [SupportedChainId.ARBITRUM_ONE, SupportedChainId.ARBITRUM_RINKEBY].includes(chainId)) {
dispatch(enableList(ARBITRUM_LIST)) dispatch(enableList(ARBITRUM_LIST))
} }
if (chainId && [SupportedChainId.CELO, SupportedChainId.CELO_ALFAJORES].includes(chainId)) { if (chainId && isCelo(chainId)) {
dispatch(enableList(CELO_LIST)) dispatch(enableList(CELO_LIST))
} }
}, [chainId, dispatch]) }, [chainId, dispatch])
......
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