Commit 4deab755 authored by cartcrom's avatar cartcrom Committed by GitHub

fix: search crash and explore row numbering (#4715)

fixed
parent b92c8007
import clsx from 'clsx' import clsx from 'clsx'
import { useGlobalChainName } from 'graphql/data/util'
import uriToHttp from 'lib/utils/uriToHttp' import uriToHttp from 'lib/utils/uriToHttp'
import { Box } from 'nft/components/Box' import { Box } from 'nft/components/Box'
import { Column, Row } from 'nft/components/Flex' import { Column, Row } from 'nft/components/Flex'
...@@ -128,7 +129,7 @@ export const TokenRow = ({ token, isHovered, setHoveredIndex, toggleOpen, index ...@@ -128,7 +129,7 @@ export const TokenRow = ({ token, isHovered, setHoveredIndex, toggleOpen, index
return ( return (
<Link <Link
to={`/tokens/${token.address}`} to={`/tokens/${useGlobalChainName().toLowerCase()}/${token.address}`}
onClick={handleClick} onClick={handleClick}
onMouseEnter={() => !isHovered && setHoveredIndex(index)} onMouseEnter={() => !isHovered && setHoveredIndex(index)}
onMouseLeave={() => isHovered && setHoveredIndex(undefined)} onMouseLeave={() => isHovered && setHoveredIndex(undefined)}
......
...@@ -72,7 +72,8 @@ export default function TokenTable() { ...@@ -72,7 +72,8 @@ export default function TokenTable() {
// TODO: consider moving prefetched call into app.tsx and passing it here, use a preloaded call & updated on interval every 60s // TODO: consider moving prefetched call into app.tsx and passing it here, use a preloaded call & updated on interval every 60s
const chainName = validateUrlChainParam(useParams<{ chainName?: string }>().chainName) const chainName = validateUrlChainParam(useParams<{ chainName?: string }>().chainName)
const { loading, tokens, tokensWithoutPriceHistoryCount, hasMore, loadMoreTokens } = useTopTokens(chainName) const { loading, tokens, tokensWithoutPriceHistoryCount, hasMore, loadMoreTokens, maxFetchable } =
useTopTokens(chainName)
const showMoreLoadingRows = Boolean(loading && hasMore) const showMoreLoadingRows = Boolean(loading && hasMore)
const observer = useRef<IntersectionObserver>() const observer = useRef<IntersectionObserver>()
...@@ -123,7 +124,7 @@ export default function TokenTable() { ...@@ -123,7 +124,7 @@ export default function TokenTable() {
<LoadedRow <LoadedRow
key={token?.address} key={token?.address}
tokenListIndex={index} tokenListIndex={index}
tokenListLength={tokens?.length ?? 0} tokenListLength={maxFetchable}
token={token} token={token}
ref={index + 1 === tokens.length ? lastTokenRef : undefined} ref={index + 1 === tokens.length ? lastTokenRef : undefined}
/> />
......
...@@ -162,6 +162,7 @@ interface UseTopTokensReturnValue { ...@@ -162,6 +162,7 @@ interface UseTopTokensReturnValue {
tokensWithoutPriceHistoryCount: number tokensWithoutPriceHistoryCount: number
hasMore: boolean hasMore: boolean
loadMoreTokens: () => void loadMoreTokens: () => void
maxFetchable: number
} }
export function useTopTokens(chain: Chain): UseTopTokensReturnValue { export function useTopTokens(chain: Chain): UseTopTokensReturnValue {
const duration = toHistoryDuration(useAtomValue(filterTimeAtom)) const duration = toHistoryDuration(useAtomValue(filterTimeAtom))
...@@ -170,6 +171,10 @@ export function useTopTokens(chain: Chain): UseTopTokensReturnValue { ...@@ -170,6 +171,10 @@ export function useTopTokens(chain: Chain): UseTopTokensReturnValue {
const [page, setPage] = useState(0) const [page, setPage] = useState(0)
const prefetchedData = usePrefetchTopTokens(duration, chain) const prefetchedData = usePrefetchTopTokens(duration, chain)
const prefetchedSelectedTokensWithoutPriceHistory = useFilteredTokens(useSortedTokens(prefetchedData.topTokens)) const prefetchedSelectedTokensWithoutPriceHistory = useFilteredTokens(useSortedTokens(prefetchedData.topTokens))
const maxFetchable = useMemo(
() => prefetchedSelectedTokensWithoutPriceHistory.length,
[prefetchedSelectedTokensWithoutPriceHistory]
)
const hasMore = !tokens || tokens.length < prefetchedSelectedTokensWithoutPriceHistory.length const hasMore = !tokens || tokens.length < prefetchedSelectedTokensWithoutPriceHistory.length
...@@ -239,6 +244,7 @@ export function useTopTokens(chain: Chain): UseTopTokensReturnValue { ...@@ -239,6 +244,7 @@ export function useTopTokens(chain: Chain): UseTopTokensReturnValue {
hasMore, hasMore,
tokensWithoutPriceHistoryCount: prefetchedSelectedTokensWithoutPriceHistory.length, tokensWithoutPriceHistoryCount: prefetchedSelectedTokensWithoutPriceHistory.length,
loadMoreTokens, loadMoreTokens,
maxFetchable,
} }
} }
......
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