diff --git a/apps/trading/client-pages/market/market-selector.spec.tsx b/apps/trading/client-pages/market/market-selector.spec.tsx index c49677d13..0c2f71943 100644 --- a/apps/trading/client-pages/market/market-selector.spec.tsx +++ b/apps/trading/client-pages/market/market-selector.spec.tsx @@ -10,6 +10,7 @@ import type { SortType } from './sort-dropdown'; import { SortTypeMapping } from './sort-dropdown'; import { Sort } from './sort-dropdown'; import { subDays } from 'date-fns'; +import { isMarketActive } from './use-market-selector-list'; jest.mock('@vegaprotocol/market-list'); const mockUseMarketList = useMarketList as jest.Mock; @@ -126,9 +127,7 @@ describe('MarketSelector', () => { }), ]; - const activeMarkets = markets.filter((m) => - [MarketState.STATE_ACTIVE, MarketState.STATE_SUSPENDED].includes(m.state) - ); + const activeMarkets = markets.filter((m) => isMarketActive(m.state)); mockUseMarketList.mockReturnValue({ data: markets, loading: false, diff --git a/apps/trading/client-pages/market/use-market-selector-list.spec.tsx b/apps/trading/client-pages/market/use-market-selector-list.spec.tsx index bc01ac605..62d355f90 100644 --- a/apps/trading/client-pages/market/use-market-selector-list.spec.tsx +++ b/apps/trading/client-pages/market/use-market-selector-list.spec.tsx @@ -1,6 +1,9 @@ import merge from 'lodash/merge'; import { renderHook } from '@testing-library/react'; -import { useMarketSelectorList } from './use-market-selector-list'; +import { + isMarketActive, + useMarketSelectorList, +} from './use-market-selector-list'; import { Product } from './product-selector'; import { Sort } from './sort-dropdown'; import { createMarketFragment } from '@vegaprotocol/mock'; @@ -38,6 +41,10 @@ describe('useMarketSelectorList', () => { }), createMarketFragment({ id: 'market-3', + state: MarketState.STATE_CLOSED, + }), + createMarketFragment({ + id: 'market-4', state: MarketState.STATE_PENDING, }), ]; @@ -48,7 +55,7 @@ describe('useMarketSelectorList', () => { }); const { result } = setup(); const expectedFilteredMarkets = markets.filter((m) => - [MarketState.STATE_ACTIVE, MarketState.STATE_SUSPENDED].includes(m.state) + isMarketActive(m.state) ); expect(result.current).toEqual({ data: markets, diff --git a/apps/trading/client-pages/market/use-market-selector-list.ts b/apps/trading/client-pages/market/use-market-selector-list.ts index f823c6b58..d56adaab2 100644 --- a/apps/trading/client-pages/market/use-market-selector-list.ts +++ b/apps/trading/client-pages/market/use-market-selector-list.ts @@ -18,11 +18,7 @@ export const useMarketSelectorList = ({ if (!data?.length) return []; const markets = data // only active - .filter((m) => { - return [MarketState.STATE_ACTIVE, MarketState.STATE_SUSPENDED].includes( - m.state - ); - }) + .filter((m) => isMarketActive(m.state)) // only selected product type .filter((m) => { if (m.tradableInstrument.instrument.product.__typename === product) { @@ -80,3 +76,11 @@ export const useMarketSelectorList = ({ return { markets, data, loading, error }; }; + +export const isMarketActive = (state: MarketState) => { + return [ + MarketState.STATE_ACTIVE, + MarketState.STATE_SUSPENDED, + MarketState.STATE_PENDING, + ].includes(state); +};