a08f63c7d8
* feat(#1243): Market data providers * feat(#1243): Market data providers * feat(#1243): Market data providers * feat(#1243): refactor market lists * feat(#1243): refactor market lists * feat(#1243): refactor market lists * feat(#1243): refactor orderbook data providers * feat(#1243): refactor orderbook data providers * feat(#1243): refactor depth chart data layer * feat(#1243): fix market depth typing * fixed unit tests * feat(#1243): e2e test fixes * feat(#1243): code style fixes * feat(#1243): post merge fixes * feat(#1243): fix lint issues * feat(#1243): post merge fixes * feat(#1243): remove market name from market * feat(#1243): fix console lite e2e data depth mocks * feat(#1243): fix console lite e2e market trade test * feat(#1243): fix lint issues * feat(#1243): fix trading e2e home test Co-authored-by: asiaznik <artur@vegaprotocol.io>
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { activeMarketsProvider } from '@vegaprotocol/market-list';
|
|
import { useDataProvider } from '@vegaprotocol/react-helpers';
|
|
import { AsyncRenderer } from '@vegaprotocol/ui-toolkit';
|
|
import { useRouter } from 'next/router';
|
|
import { useEffect } from 'react';
|
|
import { useGlobalStore } from '../stores';
|
|
|
|
export function Index() {
|
|
const { replace } = useRouter();
|
|
// 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 } = useDataProvider({
|
|
dataProvider: activeMarketsProvider,
|
|
noUpdate: true,
|
|
});
|
|
const { riskNoticeDialog, update } = useGlobalStore((store) => ({
|
|
riskNoticeDialog: store.riskNoticeDialog,
|
|
update: store.update,
|
|
}));
|
|
|
|
useEffect(() => {
|
|
update({ landingDialog: true });
|
|
|
|
if (data) {
|
|
const marketId = data[0]?.id;
|
|
|
|
if (marketId) {
|
|
replace(`/markets/${marketId}`);
|
|
update({ marketId });
|
|
}
|
|
// Fallback to the markets list page
|
|
else {
|
|
replace('/markets');
|
|
}
|
|
}
|
|
}, [data, replace, riskNoticeDialog, update]);
|
|
|
|
return (
|
|
<AsyncRenderer data={data} loading={loading} error={error}>
|
|
{/* Render a loading and error state but we will redirect if markets are found */}
|
|
{null}
|
|
</AsyncRenderer>
|
|
);
|
|
}
|
|
|
|
Index.getInitialProps = () => ({
|
|
page: 'home',
|
|
});
|
|
|
|
export default Index;
|