2022-05-23 12:21:54 +00:00
|
|
|
import { gql, useQuery } from '@apollo/client';
|
|
|
|
import { LandingDialog } from '@vegaprotocol/market-list';
|
|
|
|
import { MarketTradingMode } from '@vegaprotocol/types';
|
|
|
|
import { AsyncRenderer } from '@vegaprotocol/ui-toolkit';
|
|
|
|
import sortBy from 'lodash/sortBy';
|
|
|
|
import MarketPage from './markets/[marketId].page';
|
|
|
|
import type { MarketsLanding } from './__generated__/MarketsLanding';
|
|
|
|
|
|
|
|
const MARKETS_QUERY = gql`
|
|
|
|
query MarketsLanding {
|
|
|
|
markets {
|
|
|
|
id
|
|
|
|
tradingMode
|
|
|
|
marketTimestamps {
|
|
|
|
open
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const marketList = ({ markets }: MarketsLanding) =>
|
|
|
|
sortBy(
|
|
|
|
markets?.filter(
|
|
|
|
({ marketTimestamps, tradingMode }) =>
|
|
|
|
marketTimestamps.open && tradingMode === MarketTradingMode.Continuous
|
|
|
|
) || [],
|
|
|
|
'marketTimestamps.open',
|
|
|
|
'id'
|
|
|
|
);
|
2022-02-23 17:57:44 +00:00
|
|
|
|
|
|
|
export function Index() {
|
2022-05-23 12:21:54 +00:00
|
|
|
// The default market selected in the platform behind the overlay
|
|
|
|
// should be the oldest market that is currently trading in continuous mode(i.e. not in auction).
|
|
|
|
const { data, error, loading } = useQuery<MarketsLanding>(MARKETS_QUERY);
|
2022-02-11 13:56:28 +00:00
|
|
|
return (
|
2022-05-23 12:21:54 +00:00
|
|
|
<>
|
|
|
|
<LandingDialog />
|
|
|
|
<AsyncRenderer data={data} error={error} loading={loading}>
|
|
|
|
<MarketPage id={data && marketList(data)[0]?.id} />
|
|
|
|
</AsyncRenderer>
|
|
|
|
</>
|
2022-02-11 13:56:28 +00:00
|
|
|
);
|
|
|
|
}
|
2022-02-23 17:57:44 +00:00
|
|
|
|
2022-04-12 11:04:26 +00:00
|
|
|
Index.getInitialProps = () => ({
|
|
|
|
page: 'home',
|
|
|
|
});
|
|
|
|
|
2022-02-23 17:57:44 +00:00
|
|
|
export default Index;
|