Commit 2de43a8c authored by David Mihal's avatar David Mihal Committed by GitHub

feat: take tick range from URL (#3208)

* Take tick range from URL

* Keep minPrice/maxPrice in the URL
parent 5383436c
...@@ -5,6 +5,7 @@ import { Currency, CurrencyAmount, Percent } from '@uniswap/sdk-core' ...@@ -5,6 +5,7 @@ import { Currency, CurrencyAmount, Percent } from '@uniswap/sdk-core'
import { FeeAmount, NonfungiblePositionManager } from '@uniswap/v3-sdk' import { FeeAmount, NonfungiblePositionManager } from '@uniswap/v3-sdk'
import UnsupportedCurrencyFooter from 'components/swap/UnsupportedCurrencyFooter' import UnsupportedCurrencyFooter from 'components/swap/UnsupportedCurrencyFooter'
import useActiveWeb3React from 'hooks/useActiveWeb3React' import useActiveWeb3React from 'hooks/useActiveWeb3React'
import useParsedQueryString from 'hooks/useParsedQueryString'
import { useCallback, useContext, useEffect, useState } from 'react' import { useCallback, useContext, useEffect, useState } from 'react'
import { AlertTriangle } from 'react-feather' import { AlertTriangle } from 'react-feather'
import ReactGA from 'react-ga4' import ReactGA from 'react-ga4'
...@@ -86,6 +87,7 @@ export default function AddLiquidity({ ...@@ -86,6 +87,7 @@ export default function AddLiquidity({
const expertMode = useIsExpertMode() const expertMode = useIsExpertMode()
const addTransaction = useTransactionAdder() const addTransaction = useTransactionAdder()
const positionManager = useV3NFTPositionManagerContract() const positionManager = useV3NFTPositionManagerContract()
const parsedQs = useParsedQueryString()
// check for existing position if tokenId in url // check for existing position if tokenId in url
const { position: existingPositionDetails, loading: positionLoading } = useV3PositionFromTokenId( const { position: existingPositionDetails, loading: positionLoading } = useV3PositionFromTokenId(
...@@ -107,7 +109,8 @@ export default function AddLiquidity({ ...@@ -107,7 +109,8 @@ export default function AddLiquidity({
baseCurrency && currencyB && baseCurrency.wrapped.equals(currencyB.wrapped) ? undefined : currencyB baseCurrency && currencyB && baseCurrency.wrapped.equals(currencyB.wrapped) ? undefined : currencyB
// mint state // mint state
const { independentField, typedValue, startPriceTypedValue } = useV3MintState() const { independentField, typedValue, startPriceTypedValue, rightRangeTypedValue, leftRangeTypedValue } =
useV3MintState()
const { const {
pool, pool,
...@@ -150,6 +153,24 @@ export default function AddLiquidity({ ...@@ -150,6 +153,24 @@ export default function AddLiquidity({
useEffect(() => setShowCapitalEfficiencyWarning(false), [baseCurrency, quoteCurrency, feeAmount]) useEffect(() => setShowCapitalEfficiencyWarning(false), [baseCurrency, quoteCurrency, feeAmount])
useEffect(() => {
if (
typeof parsedQs.minPrice === 'string' &&
parsedQs.minPrice !== leftRangeTypedValue &&
!isNaN(parsedQs.minPrice as any)
) {
onLeftRangeInput(parsedQs.minPrice)
}
if (
typeof parsedQs.maxPrice === 'string' &&
parsedQs.maxPrice !== rightRangeTypedValue &&
!isNaN(parsedQs.maxPrice as any)
) {
onRightRangeInput(parsedQs.maxPrice)
}
}, [parsedQs, rightRangeTypedValue, leftRangeTypedValue, onRightRangeInput, onLeftRangeInput])
// txn values // txn values
const deadline = useTransactionDeadline() // custom from users settings const deadline = useTransactionDeadline() // custom from users settings
......
...@@ -16,8 +16,10 @@ import { usePool } from 'hooks/usePools' ...@@ -16,8 +16,10 @@ import { usePool } from 'hooks/usePools'
import JSBI from 'jsbi' import JSBI from 'jsbi'
import tryParseCurrencyAmount from 'lib/utils/tryParseCurrencyAmount' import tryParseCurrencyAmount from 'lib/utils/tryParseCurrencyAmount'
import { ReactNode, useCallback, useMemo } from 'react' import { ReactNode, useCallback, useMemo } from 'react'
import { useHistory } from 'react-router-dom'
import { useAppDispatch, useAppSelector } from 'state/hooks' import { useAppDispatch, useAppSelector } from 'state/hooks'
import { getTickToPrice } from 'utils/getTickToPrice' import { getTickToPrice } from 'utils/getTickToPrice'
import { replaceURLParam } from 'utils/routes'
import { BIG_INT_ZERO } from '../../../constants/misc' import { BIG_INT_ZERO } from '../../../constants/misc'
import { PoolState } from '../../../hooks/usePools' import { PoolState } from '../../../hooks/usePools'
...@@ -46,6 +48,7 @@ export function useV3MintActionHandlers(noLiquidity: boolean | undefined): { ...@@ -46,6 +48,7 @@ export function useV3MintActionHandlers(noLiquidity: boolean | undefined): {
onStartPriceInput: (typedValue: string) => void onStartPriceInput: (typedValue: string) => void
} { } {
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
const history = useHistory()
const onFieldAInput = useCallback( const onFieldAInput = useCallback(
(typedValue: string) => { (typedValue: string) => {
...@@ -64,15 +67,17 @@ export function useV3MintActionHandlers(noLiquidity: boolean | undefined): { ...@@ -64,15 +67,17 @@ export function useV3MintActionHandlers(noLiquidity: boolean | undefined): {
const onLeftRangeInput = useCallback( const onLeftRangeInput = useCallback(
(typedValue: string) => { (typedValue: string) => {
dispatch(typeLeftRangeInput({ typedValue })) dispatch(typeLeftRangeInput({ typedValue }))
history.replace({ search: replaceURLParam(history.location.search, 'minPrice', typedValue) })
}, },
[dispatch] [dispatch, history]
) )
const onRightRangeInput = useCallback( const onRightRangeInput = useCallback(
(typedValue: string) => { (typedValue: string) => {
dispatch(typeRightRangeInput({ typedValue })) dispatch(typeRightRangeInput({ typedValue }))
history.replace({ search: replaceURLParam(history.location.search, 'maxPrice', typedValue) })
}, },
[dispatch] [dispatch, history]
) )
const onStartPriceInput = useCallback( const onStartPriceInput = useCallback(
......
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