vega-frontend-monorepo/apps/trading/lib/hooks/use-top-traded-markets.tsx

16 lines
538 B
TypeScript
Raw Normal View History

import orderBy from 'lodash/orderBy';
import { calcTradedFactor, useMarketList } from '@vegaprotocol/markets';
import { isMarketActive } from '../utils';
export const useTopTradedMarkets = () => {
const { data, loading, error } = useMarketList();
const activeMarkets = data?.filter(
(m) => m.data?.marketState && isMarketActive(m.data?.marketState)
);
const marketsByTopTraded = data
? orderBy(activeMarkets, (m) => calcTradedFactor(m), 'desc')
: undefined;
return { data: marketsByTopTraded, loading, error };
};