Skip to content

Commit

Permalink
feat: autofill starting price
Browse files Browse the repository at this point in the history
  • Loading branch information
namgold committed Sep 13, 2023
1 parent ca1c8fd commit 808391c
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/pages/AddLiquidityV2/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 808391c

Please sign in to comment.