Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions apps/web/src/pages/Pool/Positions/create/RangeSelectionStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useCreatePositionContext, usePriceRangeContext } from 'pages/Pool/Posit
import { PoolOutOfSyncError } from 'pages/Pool/Positions/create/PoolOutOfSyncError'
import { Container } from 'pages/Pool/Positions/create/shared'
import { getInvertedTuple } from 'pages/Pool/Positions/create/utils'
import { useCallback, useMemo, useState } from 'react'
import { useCallback, useMemo, useRef, useState } from 'react'
import { Minus, Plus } from 'react-feather'
import { Trans, useTranslation } from 'react-i18next'
import { useRangeHopCallbacks } from 'state/mint/v3/hooks'
Expand Down Expand Up @@ -184,16 +184,31 @@ function RangeInput({
const [baseCurrency, quoteCurrency] = getInvertedTuple(derivedPositionInfo.currencies, priceInverted)
const [displayUserTypedValue, setDisplayUserTypedValue] = useState(false)

const handlePriceRangeInput = useCallback(
(input: RangeSelectionInput, value: string) => {
if (input === RangeSelectionInput.MIN) {
setPriceRangeState((prev) => ({ ...prev, minPrice: value, fullRange: false }))
} else {
setPriceRangeState((prev) => ({ ...prev, maxPrice: value, fullRange: false }))
}
const handleTimer = useRef<NodeJS.Timer>()
const debounceTimer = 350

const handlePriceRangeInput = useCallback(
(input: RangeSelectionInput, value: string, debounce = false) => {
setTypedValue(value)
setDisplayUserTypedValue(true)
const mutateContext = () => {
if (input === RangeSelectionInput.MIN) {
setPriceRangeState((prev) => ({ ...prev, minPrice: value, fullRange: false }))
} else {
setPriceRangeState((prev) => ({ ...prev, maxPrice: value, fullRange: false }))
}
}

if (!debounce) {
mutateContext()

return
}

handleTimer.current && clearTimeout(handleTimer.current)
handleTimer.current = setTimeout(() => {
mutateContext()
}, debounceTimer)
},
[setPriceRangeState],
)
Expand Down Expand Up @@ -239,7 +254,7 @@ function RangeInput({
px="$none"
py="$none"
value={displayUserTypedValue ? typedValue : value}
onChangeText={(text) => handlePriceRangeInput(input, text)}
onChangeText={(text) => handlePriceRangeInput(input, text, true)}
onBlur={() => setDisplayUserTypedValue(false)}
inputEnforcer={numericInputEnforcerWithInfinity}
$md={{
Expand Down