diff --git a/src/components/explorer/ExplorerHeader.tsx b/src/components/explorer/ExplorerHeader.tsx index 8db7936b3..38cb2276f 100644 --- a/src/components/explorer/ExplorerHeader.tsx +++ b/src/components/explorer/ExplorerHeader.tsx @@ -8,7 +8,7 @@ import { useTrending, } from 'libs/queries/extApi/tradeCount'; import { Link } from 'libs/routing'; -import { useEffect, useRef } from 'react'; +import { CSSProperties, useEffect, useRef } from 'react'; import { toPairSlug } from 'utils/pairSearch'; const useTrendingPairs = (trending?: Trending) => { @@ -81,38 +81,39 @@ const useTrendStrategies = ( }; export const ExplorerHeader = () => { - const { data: trending, isLoading } = useTrending(); + const { data: trending, isLoading, isError } = useTrending(); const trendingStrategies = useTrendStrategies(trending); const trendingPairs = useTrendingPairs(trending); const strategies = trendingStrategies.data; const pairs = trendingPairs.data; - const total = Object.values(trending?.tradeCount ?? {}).reduce((acc, v) => { - return acc + v.strategyTrades; - }, 0); + const strategiesLoading = trendingStrategies.isLoading || isLoading; const pairLoading = trendingPairs.isLoading || isLoading; + if (isError) return; return (
-

Total Trades

- +

+ Total Trades +

+
- Trade + Create Strategy - Create Strategy + Trade
-

Popular Pairs

+

Popular Pairs

@@ -125,10 +126,10 @@ export const ExplorerHeader = () => { [1, 2, 3].map((id) => ( ))} @@ -169,7 +170,7 @@ export const ExplorerHeader = () => {
- + - +
-

+

Trending Strategies

@@ -184,10 +185,10 @@ export const ExplorerHeader = () => { [1, 2, 3].map((id) => ( ))} @@ -223,8 +224,8 @@ export const ExplorerHeader = () => { ); }; -const Loading = () => ( -
+const Loading = (style: CSSProperties) => ( +
); @@ -234,7 +235,7 @@ const formatter = new Intl.NumberFormat(undefined, { }); interface TradesProps { - trades: number; + trades?: number; } const Trades = ({ trades }: TradesProps) => { @@ -244,6 +245,7 @@ const Trades = ({ trades }: TradesProps) => { const initDelta = 60; useEffect(() => { + if (typeof trades !== 'number') return; let tradesChanged = false; const start = async () => { const from = lastTrades.current || trades - initDelta; @@ -302,12 +304,13 @@ const Trades = ({ trades }: TradesProps) => { }; }, [trades]); + if (typeof trades !== 'number') { + return ; + } + const initial = trades ? formatter.format(trades - initDelta) : '0'; return ( -

+

{initial.split('').map((v, i) => { if (!'0123456789'.includes(v)) return {v}; return ( diff --git a/src/libs/queries/extApi/tradeCount.ts b/src/libs/queries/extApi/tradeCount.ts index cfa18a05d..1cf30770a 100644 --- a/src/libs/queries/extApi/tradeCount.ts +++ b/src/libs/queries/extApi/tradeCount.ts @@ -34,7 +34,7 @@ export interface Trending { export const useTrending = () => { return useQuery({ - queryKey: QueryKey.tradeCount(), + queryKey: QueryKey.trending(), queryFn: carbonApi.getTrending, staleTime: ONE_HOUR_IN_MS, refetchInterval: 120_000, diff --git a/src/libs/queries/queryKey.ts b/src/libs/queries/queryKey.ts index 85c8ea6ed..a800d9475 100644 --- a/src/libs/queries/queryKey.ts +++ b/src/libs/queries/queryKey.ts @@ -39,7 +39,7 @@ export namespace QueryKey { 'token-price-history', params, ]; - export const tradeCount = () => [...extAPI, 'trade-count']; + export const trending = () => [...extAPI, 'trending']; export const strategy = (id: string) => [...sdk, 'strategy', id]; export const strategyList = (ids: string[]) => [...sdk, 'strategy', ...ids];

- + - +