Skip to content

Commit 94ccf41

Browse files
authored
fix: Crash when accessing liquidity with wrong query (#12455)
Page crashes querying these examples: https://pancakeswap.finance/liquidity/pool https://pancakeswap.finance/liquidity/v3 https://pancakeswap.finance/liquidity/ERC721 https://pancakeswap.finance/liquidity/pool%E2%80%A6 <!-- Before opening a pull request, please read the [contributing guidelines](https://github.com/pancakeswap/pancake-frontend/blob/develop/CONTRIBUTING.md) first --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on modifying the `LiquidityView` component to handle routing based on the `tokenIdFromUrl`. It replaces the `redirect` function with `router.replace` for improved navigation and updates the logic for parsing the `tokenIdFromUrl`. ### Detailed summary - Removed the `redirect` function calls for routing based on `tokenIdFromUrl`. - Introduced `router.replace` for navigation to `/liquidity/pools` and `/liquidity/positions`. - Updated the condition for parsing `tokenIdFromUrl` to check if it is a finite number before converting it to `BigInt`. - Added a check to return `null` if `parsedTokenId` is not defined. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 2f85fa2 commit 94ccf41

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

apps/web/src/views/Liquidity/LiquidityView.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ import { useV3PositionFromTokenId, useV3TokenIdsByAccount } from 'hooks/v3/useV3
6666
import { formatTickPrice } from 'hooks/v3/utils/formatTickPrice'
6767
import { NextSeo } from 'next-seo'
6868
import Link from 'next/link'
69-
import { redirect } from 'next/navigation'
7069
import { useRouter } from 'next/router'
7170
import { ReactNode, memo, useCallback, useMemo, useState } from 'react'
7271
import { usePoolInfo } from 'state/farmsV4/state/extendPools/hooks'
@@ -211,13 +210,7 @@ export const LiquidityView = () => {
211210

212211
const { tokenId: tokenIdFromUrl } = router.query
213212

214-
if (tokenIdFromUrl === 'pools') {
215-
redirect('/liquidity/pools')
216-
} else if (tokenIdFromUrl === 'positions') {
217-
redirect('/liquidity/positions')
218-
}
219-
220-
const parsedTokenId = tokenIdFromUrl ? BigInt(tokenIdFromUrl as string) : undefined
213+
const parsedTokenId = Number.isFinite(Number(tokenIdFromUrl)) ? BigInt(tokenIdFromUrl as string) : undefined
221214

222215
const { loading, position: positionDetails } = useV3PositionFromTokenId(parsedTokenId)
223216

@@ -553,6 +546,16 @@ export const LiquidityView = () => {
553546
</Message>
554547
) : null
555548

549+
if (tokenIdFromUrl === 'pools') {
550+
router.replace('/liquidity/pools')
551+
} else {
552+
router.replace('/liquidity/positions')
553+
}
554+
555+
if (!parsedTokenId) {
556+
return null
557+
}
558+
556559
return (
557560
<Box mb="40px">
558561
{!isLoading && <NextSeo title={`${currencyQuote?.symbol}-${currencyBase?.symbol} V3 LP #${tokenIdFromUrl}`} />}

0 commit comments

Comments
 (0)