chore(trading): show markets in opening auction in market selector (#3814)

This commit is contained in:
Matthew Russell 2023-05-18 01:49:44 -07:00 committed by GitHub
parent 69c6db8ec2
commit de637fee13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 10 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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);
};