Skip to content

Commit

Permalink
fix(CR-959): user positions screen crash
Browse files Browse the repository at this point in the history
  • Loading branch information
tienkane authored Feb 21, 2025
1 parent 962cc92 commit 8319666
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/pages/Earns/PositionDetail/LiquidityChart/uniswapv3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,7 @@ export function priceToClosestTick(
token1Decimal: number,
revert = false,
): number | undefined {
if (!value.match(/^\d*\.?\d+$/)) {
return undefined
}
if (!value.match(/^\d*\.?\d+$/)) return
const [whole, fraction] = value.split('.')

const decimals = fraction?.length ?? 0
Expand All @@ -286,7 +284,13 @@ export function priceToClosestTick(
//const sqrtRatioX96 = encodeSqrtRatioX96(numerator, denominator);
const sqrtRatioX96 = !revert ? encodeSqrtRatioX96(numerator, denominator) : encodeSqrtRatioX96(denominator, numerator)

let tick = getTickAtSqrtRatio(sqrtRatioX96)
let tick
try {
tick = getTickAtSqrtRatio(sqrtRatioX96)
} catch (error) {
console.log(error)
}
if (!tick) return
const nextTickPrice = tickToPrice(tick + 1, token0Decimal, token1Decimal, revert)

if (!revert) {
Expand Down
6 changes: 5 additions & 1 deletion src/pages/Earns/UserPositions/PriceRange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function PriceRange({
const [currentPriceHover, setCurrentPriceHover] = useState(false)
const outOfRange = currentPrice < minPrice || currentPrice > maxPrice

const ticksAtLimit = useMemo(() => {
const ticksAtLimit: { lower: boolean; upper: boolean } | undefined = useMemo(() => {
const minTick = nearestUsableTick(MIN_TICK, tickSpacing)
const maxTick = nearestUsableTick(MAX_TICK, tickSpacing)
const parsedMinPrice = toString(Number(minPrice.toFixed(18)))
Expand All @@ -46,6 +46,8 @@ export default function PriceRange({
? maxTick
: priceToClosestTick(parsedMaxPrice, token0Decimals, token1Decimals, false)

if (tickLower === undefined || tickUpper === undefined) return undefined

const usableTickLower = nearestUsableTick(Number(tickLower), tickSpacing)
const usableTickUpper = nearestUsableTick(Number(tickUpper), tickSpacing)

Expand All @@ -55,6 +57,8 @@ export default function PriceRange({
}
}, [maxPrice, minPrice, tickSpacing, token0Decimals, token1Decimals])

if (!ticksAtLimit) return null

return (
<PriceRangeWrapper outOfRange={outOfRange}>
{outOfRange && (
Expand Down

0 comments on commit 8319666

Please sign in to comment.