diff --git a/src/pages/AddLiquidityV2/index.tsx b/src/pages/AddLiquidityV2/index.tsx index 6b6de01c6f..f189814b40 100644 --- a/src/pages/AddLiquidityV2/index.tsx +++ b/src/pages/AddLiquidityV2/index.tsx @@ -88,7 +88,7 @@ import { basisPointsToPercent, calculateGasMargin, formattedNum } from 'utils' import { currencyId } from 'utils/currencyId' import { friendlyError } from 'utils/errorMessage' import { maxAmountSpend } from 'utils/maxAmountSpend' -import { formatDisplayNumber } from 'utils/numbers' +import { formatDisplayNumber, toFixed } from 'utils/numbers' import { SLIPPAGE_STATUS, checkRangeSlippage } from 'utils/slippage' import { unwrappedToken } from 'utils/wrappedCurrency' @@ -384,6 +384,10 @@ export default function AddLiquidity() { fetchPrices, refetch, } = useTokenPricesWithLoading(tokens.map(t => t?.wrapped.address || '')) + const marketPrice = + usdPrices[quoteCurrency?.wrapped.address || ''] && + usdPrices[baseCurrency?.wrapped.address || ''] && + usdPrices[baseCurrency?.wrapped.address || ''] / usdPrices[quoteCurrency?.wrapped.address || ''] useInterval(refetch, 10_000) @@ -616,14 +620,22 @@ export default function AddLiquidity() { }, [navigate, networkInfo.route, onFieldAInput, txHash]) const handleDismissConfirmationRef = useRef(handleDismissConfirmation) + + const [waitForMarketPrice, setWaitForMarketPrice] = useState(false) useEffect(() => { - if (ENV_LEVEL > ENV_TYPE.LOCAL) { - setPositionIndex(0) - onResetMintState() - handleDismissConfirmationRef.current() - } + setPositionIndex(0) + onResetMintState() + handleDismissConfirmationRef.current() + setWaitForMarketPrice(true) }, [onResetMintState, baseCurrency?.wrapped.address, quoteCurrency?.wrapped.address, feeAmount, chainId]) + useEffect(() => { + if (waitForMarketPrice && marketPrice) { + onStartPriceInput(toFixed(marketPrice)) + setWaitForMarketPrice(false) + } + }, [waitForMarketPrice, marketPrice, onStartPriceInput]) + const leftPrice = isSorted ? priceLower : priceUpper?.invert() const rightPrice = isSorted ? priceUpper : priceLower?.invert() @@ -1287,11 +1299,6 @@ export default function AddLiquidity() { const tightTokenSelect = !upToMedium && upToLarge - const marketPrice = - usdPrices[quoteCurrency?.wrapped.address || ''] && - usdPrices[baseCurrency?.wrapped.address || ''] && - usdPrices[baseCurrency?.wrapped.address || ''] / usdPrices[quoteCurrency?.wrapped.address || ''] - const onFarmRangeSelected = useCallback( (tickLower: number, tickUpper: number) => { const tickSpacing = TICK_SPACINGS[feeAmount]