2022-05-23 12:21:54 +00:00
|
|
|
import { gql, useQuery } from '@apollo/client';
|
|
|
|
import { AsyncRenderer } from '@vegaprotocol/ui-toolkit';
|
2022-07-13 14:23:46 +00:00
|
|
|
import orderBy from 'lodash/orderBy';
|
2022-06-01 14:21:36 +00:00
|
|
|
import { useRouter } from 'next/router';
|
|
|
|
import { useEffect } from 'react';
|
|
|
|
import { useGlobalStore } from '../stores';
|
2022-05-23 12:21:54 +00:00
|
|
|
import type { MarketsLanding } from './__generated__/MarketsLanding';
|
|
|
|
|
|
|
|
const MARKETS_QUERY = gql`
|
|
|
|
query MarketsLanding {
|
|
|
|
markets {
|
|
|
|
id
|
|
|
|
tradingMode
|
2022-07-13 14:23:46 +00:00
|
|
|
state
|
2022-05-23 12:21:54 +00:00
|
|
|
marketTimestamps {
|
|
|
|
open
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2022-07-20 16:40:28 +00:00
|
|
|
const getMarketList = ({ markets = [] }: MarketsLanding) => {
|
feat: market list mega dropdown (rich popover) (#889)
* feat: use MarketList query only
* fix: remove Market.ts from index
* feat: 30 refactor dialog, market list, change query
* feat: #30 add indicativeVolume, total fees, tooltip, large dialog, tooltip accepts html description
* fix: #30 total fees display in tooltip
* fix: #30 toggle title on dialog open
* fix: #30 fix order, price, high, low utils
* fix: #30 fix test for market utils
* feat: #30 add popover with markets to select
* feat: #30 storybook popover
* feat: #30 remove border on trigger and add some other classes
* fix: #30 fix format check with format:write
* feat: #30 add tooltip on taker fee
* feat: #30 add tooltip on taker fee
* fix: #30 format on select market list
* fix: #30 remove unknown cast in test mock data
* fix: #30 show markets where you have open positions
* fix: #30 double check if open positions
* fix: #30 dialog has only small/large sizes
* feat: #30 add border on trigger and change padding and no wrap
* fix: #30 if fees or factors are not found
* fix: #30 remove markets.cy tests as markets page is now gone
* fix #30 remove view full market list test
* fix: #30 add rotating arrow on market title
* fix: #30 add ease-in-out on popover
* fix: #30 add ease-in-out on popover
* fix: #30 align select a market table
* fix: #30 select a market title
* fix: #30 select a market title
* fix: #30 fix any validateDOMnesting issues
* fix: #30 show loading market data
* fix: #30 add list of header columns
* fix: #30 add list of header columns
* fix: #30 small refactoring after review
* fix: #30 update bold undreline class names
* fix: #30 add large-mobile size
* feat: #30 refactor select markets tables to render array of columns
* fix: #30 remove size from select market dialog
* fix: #30 add extra file for columns
* fix: #30 update formtting
* fix: #30 make sure popup closes on same market navigation
* fix: rename market-utils, add calcCandle methods, store market id on select
* fix: useMemo ondata and marketPositionData + orderbook stories fix
* feat: #30 add open volume positions
* fix: add market summary back
* fix: update formatting
* fix: use currentcolor on arrow
* fix: create all markets page
* fix: add overflow-y auto
* fix: enlarge select market to get started dialog
* fix: revert markets container
* fix: use query to fix flickering on position markets
* fix: edit unordered list in tooltips
* fix: fix tooltip table
* fix: fix home.cy.ts
* chore: skip /markets tests
2022-08-11 11:56:35 +00:00
|
|
|
return orderBy(markets, ['marketTimestamps.open', 'id'], ['asc', 'asc']);
|
2022-07-20 16:40:28 +00:00
|
|
|
};
|
2022-02-23 17:57:44 +00:00
|
|
|
|
|
|
|
export function Index() {
|
2022-06-01 14:21:36 +00:00
|
|
|
const { replace } = useRouter();
|
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-06-01 14:21:36 +00:00
|
|
|
const setLandingDialog = useGlobalStore((state) => state.setLandingDialog);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (data) {
|
2022-07-20 16:40:28 +00:00
|
|
|
const marketId = getMarketList(data)[0]?.id;
|
2022-06-01 14:21:36 +00:00
|
|
|
|
|
|
|
// If a default market is found, go to it with the landing dialog open
|
|
|
|
if (marketId) {
|
|
|
|
setLandingDialog(true);
|
|
|
|
replace(`/markets/${marketId}`);
|
|
|
|
}
|
|
|
|
// Fallback to the markets list page
|
|
|
|
else {
|
|
|
|
replace('/markets');
|
|
|
|
}
|
|
|
|
}
|
2022-06-08 08:47:31 +00:00
|
|
|
}, [data, replace, setLandingDialog]);
|
2022-06-01 14:21:36 +00:00
|
|
|
|
2022-02-11 13:56:28 +00:00
|
|
|
return (
|
2022-06-01 14:21:36 +00:00
|
|
|
<AsyncRenderer data={data} loading={loading} error={error}>
|
|
|
|
{/* Render a loading and error state but we will redirect if markets are found */}
|
|
|
|
{null}
|
|
|
|
</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;
|