2023-10-16 14:49:23 +00:00
|
|
|
import { useMemo } from 'react';
|
2022-09-02 14:53:38 +00:00
|
|
|
import Head from 'next/head';
|
2022-11-08 07:23:38 +00:00
|
|
|
import type { AppProps } from 'next/app';
|
2023-02-28 18:56:29 +00:00
|
|
|
import { t } from '@vegaprotocol/i18n';
|
2022-09-23 14:29:35 +00:00
|
|
|
import {
|
|
|
|
envTriggerMapping,
|
2023-07-31 16:08:55 +00:00
|
|
|
Networks,
|
2023-02-16 03:52:54 +00:00
|
|
|
NodeSwitcherDialog,
|
2022-09-23 14:29:35 +00:00
|
|
|
useEnvironment,
|
2023-02-16 03:52:54 +00:00
|
|
|
useInitializeEnv,
|
2023-05-09 19:58:09 +00:00
|
|
|
useNodeSwitcherStore,
|
2022-09-23 14:29:35 +00:00
|
|
|
} from '@vegaprotocol/environment';
|
2022-03-14 13:18:11 +00:00
|
|
|
import './styles.css';
|
2023-10-16 14:49:23 +00:00
|
|
|
import { usePageTitleStore } from '../stores';
|
2022-10-14 15:42:53 +00:00
|
|
|
import DialogsContainer from './dialogs-container';
|
2022-12-21 09:29:32 +00:00
|
|
|
import ToastsManager from './toasts-manager';
|
2023-10-16 14:49:23 +00:00
|
|
|
import { HashRouter, useLocation, Route, Routes } from 'react-router-dom';
|
2023-10-13 14:02:33 +00:00
|
|
|
import { Bootstrapper } from '../components/bootstrapper';
|
2023-09-22 08:39:26 +00:00
|
|
|
import { AnnouncementBanner } from '../components/banner';
|
2023-07-24 08:37:18 +00:00
|
|
|
import { Navbar } from '../components/navbar';
|
|
|
|
import classNames from 'classnames';
|
2023-05-04 07:51:24 +00:00
|
|
|
import {
|
|
|
|
ProtocolUpgradeCountdownMode,
|
2023-08-16 14:50:38 +00:00
|
|
|
ProtocolUpgradeInProgressNotification,
|
2023-05-04 07:51:24 +00:00
|
|
|
ProtocolUpgradeProposalNotification,
|
|
|
|
} from '@vegaprotocol/proposals';
|
2023-07-24 08:37:18 +00:00
|
|
|
import { ViewingBanner } from '../components/viewing-banner';
|
2023-07-31 16:08:55 +00:00
|
|
|
import { NavHeader } from '../components/navbar/nav-header';
|
2023-09-14 19:10:33 +00:00
|
|
|
import { Telemetry } from '../components/telemetry';
|
2023-09-20 20:28:34 +00:00
|
|
|
import { Routes as AppRoutes } from '../lib/links';
|
2023-10-13 14:02:33 +00:00
|
|
|
import { SSRLoader } from './ssr-loader';
|
2023-10-16 14:49:23 +00:00
|
|
|
import { PartyActiveOrdersHandler } from './party-active-orders-handler';
|
|
|
|
import { MaybeConnectEagerly } from './maybe-connect-eagerly';
|
|
|
|
import { TransactionHandlers } from './transaction-handlers';
|
2022-09-23 14:29:35 +00:00
|
|
|
|
|
|
|
const DEFAULT_TITLE = t('Welcome to Vega trading!');
|
2022-03-14 13:18:11 +00:00
|
|
|
|
2022-10-14 15:42:53 +00:00
|
|
|
const Title = () => {
|
|
|
|
const { pageTitle } = usePageTitleStore((store) => ({
|
2022-09-23 14:29:35 +00:00
|
|
|
pageTitle: store.pageTitle,
|
2022-09-05 14:25:33 +00:00
|
|
|
}));
|
2022-06-10 09:15:38 +00:00
|
|
|
|
2022-09-23 14:29:35 +00:00
|
|
|
const { VEGA_ENV } = useEnvironment();
|
|
|
|
const networkName = envTriggerMapping[VEGA_ENV];
|
|
|
|
|
|
|
|
const title = useMemo(() => {
|
|
|
|
if (!pageTitle) return DEFAULT_TITLE;
|
|
|
|
if (networkName) return `${pageTitle} [${networkName}]`;
|
|
|
|
return pageTitle;
|
|
|
|
}, [pageTitle, networkName]);
|
2022-11-08 07:23:38 +00:00
|
|
|
|
2022-10-14 15:42:53 +00:00
|
|
|
return (
|
|
|
|
<Head>
|
|
|
|
<title>{title}</title>
|
|
|
|
</Head>
|
|
|
|
);
|
|
|
|
};
|
2022-09-23 14:29:35 +00:00
|
|
|
|
2022-11-08 07:23:38 +00:00
|
|
|
function AppBody({ Component }: AppProps) {
|
|
|
|
const location = useLocation();
|
2023-07-31 16:08:55 +00:00
|
|
|
const { VEGA_ENV } = useEnvironment();
|
2023-02-03 10:34:32 +00:00
|
|
|
const gridClasses = classNames(
|
|
|
|
'h-full relative z-0 grid',
|
2023-05-16 16:57:36 +00:00
|
|
|
'grid-rows-[repeat(3,min-content),minmax(0,1fr)]'
|
2023-02-03 10:34:32 +00:00
|
|
|
);
|
2022-06-10 09:15:38 +00:00
|
|
|
return (
|
2023-07-24 08:37:18 +00:00
|
|
|
<div className="h-full overflow-hidden">
|
2022-12-02 23:24:15 +00:00
|
|
|
<Head>
|
|
|
|
{/* Cannot use meta tags in _document.page.tsx see https://nextjs.org/docs/messages/no-document-viewport-meta */}
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
|
|
</Head>
|
2022-10-14 15:42:53 +00:00
|
|
|
<Title />
|
2023-02-16 03:52:54 +00:00
|
|
|
<div className={gridClasses}>
|
2023-04-21 16:31:52 +00:00
|
|
|
<AnnouncementBanner />
|
2023-07-31 16:08:55 +00:00
|
|
|
<Navbar theme={VEGA_ENV === Networks.TESTNET ? 'yellow' : 'system'}>
|
|
|
|
<Routes>
|
|
|
|
<Route
|
|
|
|
path={AppRoutes.MARKETS}
|
|
|
|
// render nothing for markets/all, otherwise markets/:marketId will match with markets/all
|
|
|
|
element={null}
|
|
|
|
/>
|
|
|
|
<Route path={AppRoutes.MARKET} element={<NavHeader />} />
|
|
|
|
</Routes>
|
|
|
|
</Navbar>
|
2023-05-04 07:51:24 +00:00
|
|
|
<div data-testid="banners">
|
|
|
|
<ProtocolUpgradeProposalNotification
|
|
|
|
mode={ProtocolUpgradeCountdownMode.IN_ESTIMATED_TIME_REMAINING}
|
|
|
|
/>
|
2023-08-16 14:50:38 +00:00
|
|
|
<ProtocolUpgradeInProgressNotification />
|
2023-05-04 07:51:24 +00:00
|
|
|
<ViewingBanner />
|
|
|
|
</div>
|
2023-07-24 08:37:18 +00:00
|
|
|
<div data-testid={`pathname-${location.pathname}`}>
|
2023-02-16 03:52:54 +00:00
|
|
|
<Component />
|
2023-07-24 08:37:18 +00:00
|
|
|
</div>
|
2023-02-16 03:52:54 +00:00
|
|
|
</div>
|
|
|
|
<DialogsContainer />
|
|
|
|
<ToastsManager />
|
2023-10-16 14:49:23 +00:00
|
|
|
<TransactionHandlers />
|
2023-02-16 03:52:54 +00:00
|
|
|
<MaybeConnectEagerly />
|
2023-10-16 14:49:23 +00:00
|
|
|
<PartyActiveOrdersHandler />
|
2023-09-14 19:10:33 +00:00
|
|
|
<Telemetry />
|
2022-12-27 15:46:44 +00:00
|
|
|
</div>
|
2022-06-10 09:15:38 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function VegaTradingApp(props: AppProps) {
|
2023-02-16 03:52:54 +00:00
|
|
|
const status = useEnvironment((store) => store.status);
|
2023-05-09 19:58:09 +00:00
|
|
|
const [nodeSwitcherOpen, setNodeSwitcher] = useNodeSwitcherStore((store) => [
|
|
|
|
store.dialogOpen,
|
|
|
|
store.setDialogOpen,
|
|
|
|
]);
|
2022-11-08 07:23:38 +00:00
|
|
|
|
2023-10-16 14:49:23 +00:00
|
|
|
// Start validation of env vars and determine VEGA_URL
|
2023-02-16 03:52:54 +00:00
|
|
|
useInitializeEnv();
|
2022-11-08 07:23:38 +00:00
|
|
|
|
2023-02-16 03:52:54 +00:00
|
|
|
// Prevent HashRouter from being server side rendered as it
|
|
|
|
// relies on presence of document object
|
2023-10-16 14:49:23 +00:00
|
|
|
//
|
|
|
|
// This is the last point at which we get pregenerated
|
|
|
|
// HTML so render a ssr friendly loader component
|
2023-02-16 03:52:54 +00:00
|
|
|
if (status === 'default') {
|
2023-10-13 14:02:33 +00:00
|
|
|
return <SSRLoader />;
|
2022-12-27 15:46:44 +00:00
|
|
|
}
|
2022-11-08 07:23:38 +00:00
|
|
|
|
2022-02-11 13:56:28 +00:00
|
|
|
return (
|
2022-11-08 07:23:38 +00:00
|
|
|
<HashRouter>
|
2023-10-13 14:02:33 +00:00
|
|
|
<Bootstrapper>
|
2022-12-07 09:24:40 +00:00
|
|
|
<AppBody {...props} />
|
2023-10-13 14:02:33 +00:00
|
|
|
</Bootstrapper>
|
2023-02-16 03:52:54 +00:00
|
|
|
<NodeSwitcherDialog open={nodeSwitcherOpen} setOpen={setNodeSwitcher} />
|
2022-11-08 07:23:38 +00:00
|
|
|
</HashRouter>
|
2022-02-11 13:56:28 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-02-17 05:03:46 +00:00
|
|
|
export default VegaTradingApp;
|