add default increment behavior (#157)

Co-authored-by: Noah Zinsmeister <noahwz@gmail.com>
This commit is contained in:
Ian Lapham 2021-05-05 12:12:23 -04:00 committed by GitHub
parent 1e54b97693
commit 1b798889af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 6 deletions

@ -106,6 +106,7 @@ export default function AddLiquidity({
const { independentField, typedValue, startPriceTypedValue } = useV3MintState()
const {
pool,
ticks,
dependentField,
price,
@ -348,7 +349,8 @@ export default function AddLiquidity({
quoteCurrency ?? undefined,
feeAmount,
tickLower,
tickUpper
tickUpper,
pool
)
return (

@ -420,7 +420,8 @@ export function useRangeHopCallbacks(
quoteCurrency: Currency | undefined,
feeAmount: FeeAmount | undefined,
tickLower: number | undefined,
tickUpper: number | undefined
tickUpper: number | undefined,
pool?: Pool | undefined | null
) {
const { chainId } = useActiveWeb3React()
const baseToken = useMemo(() => wrappedCurrency(baseCurrency, chainId), [baseCurrency, chainId])
@ -431,32 +432,52 @@ export function useRangeHopCallbacks(
const newPrice = tickToPrice(baseToken, quoteToken, tickLower - TICK_SPACINGS[feeAmount])
return newPrice.toSignificant(5, undefined, Rounding.ROUND_UP)
}
// use pool current tick as starting tick if we have pool but no tick input
if (!(typeof tickLower === 'number') && baseToken && quoteToken && feeAmount && pool) {
const newPrice = tickToPrice(baseToken, quoteToken, pool.tickCurrent - TICK_SPACINGS[feeAmount])
return newPrice.toSignificant(5, undefined, Rounding.ROUND_UP)
}
return ''
}, [baseToken, quoteToken, tickLower, feeAmount])
}, [baseToken, quoteToken, tickLower, feeAmount, pool])
const getIncrementLower = useCallback(() => {
if (baseToken && quoteToken && typeof tickLower === 'number' && feeAmount) {
const newPrice = tickToPrice(baseToken, quoteToken, tickLower + TICK_SPACINGS[feeAmount])
return newPrice.toSignificant(5, undefined, Rounding.ROUND_UP)
}
// use pool current tick as starting tick if we have pool but no tick input
if (!(typeof tickLower === 'number') && baseToken && quoteToken && feeAmount && pool) {
const newPrice = tickToPrice(baseToken, quoteToken, pool.tickCurrent + TICK_SPACINGS[feeAmount])
return newPrice.toSignificant(5, undefined, Rounding.ROUND_UP)
}
return ''
}, [baseToken, quoteToken, tickLower, feeAmount])
}, [baseToken, quoteToken, tickLower, feeAmount, pool])
const getDecrementUpper = useCallback(() => {
if (baseToken && quoteToken && typeof tickUpper === 'number' && feeAmount) {
const newPrice = tickToPrice(baseToken, quoteToken, tickUpper - TICK_SPACINGS[feeAmount])
return newPrice.toSignificant(5, undefined, Rounding.ROUND_UP)
}
// use pool current tick as starting tick if we have pool but no tick input
if (!(typeof tickUpper === 'number') && baseToken && quoteToken && feeAmount && pool) {
const newPrice = tickToPrice(baseToken, quoteToken, pool.tickCurrent - TICK_SPACINGS[feeAmount])
return newPrice.toSignificant(5, undefined, Rounding.ROUND_UP)
}
return ''
}, [baseToken, quoteToken, tickUpper, feeAmount])
}, [baseToken, quoteToken, tickUpper, feeAmount, pool])
const getIncrementUpper = useCallback(() => {
if (baseToken && quoteToken && typeof tickUpper === 'number' && feeAmount) {
const newPrice = tickToPrice(baseToken, quoteToken, tickUpper + TICK_SPACINGS[feeAmount])
return newPrice.toSignificant(5, undefined, Rounding.ROUND_UP)
}
// use pool current tick as starting tick if we have pool but no tick input
if (!(typeof tickUpper === 'number') && baseToken && quoteToken && feeAmount && pool) {
const newPrice = tickToPrice(baseToken, quoteToken, pool.tickCurrent + TICK_SPACINGS[feeAmount])
return newPrice.toSignificant(5, undefined, Rounding.ROUND_UP)
}
return ''
}, [baseToken, quoteToken, tickUpper, feeAmount])
}, [baseToken, quoteToken, tickUpper, feeAmount, pool])
return { getDecrementLower, getIncrementLower, getDecrementUpper, getIncrementUpper }
}