2023-11-16 03:10:39 +00:00
|
|
|
import { useMemo, Suspense } 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';
|
2022-09-23 14:29:35 +00:00
|
|
|
import {
|
2023-11-15 05:10:06 +00:00
|
|
|
useEnvTriggerMapping,
|
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,
|
2023-11-16 03:10:39 +00:00
|
|
|
AppLoader,
|
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';
|
2023-11-16 03:10:39 +00:00
|
|
|
import { useT } from '../lib/use-t';
|
2022-03-14 13:18:11 +00:00
|
|
|
|
2022-10-14 15:42:53 +00:00
|
|
|
const Title = () => {
|
2023-11-16 03:10:39 +00:00
|
|
|
const t = useT();
|
|
|
|
const DEFAULT_TITLE = t('Welcome to Vega trading!');
|
2022-10-14 15:42:53 +00:00
|
|
|
const { pageTitle } = usePageTitleStore((store) => ({
|
2022-09-23 14:29:35 +00:00
|
|
|
pageTitle: store.pageTitle,
|
2022-09-05 14:25:33 +00:00
|
|
|
}));
|
2023-11-15 05:10:06 +00:00
|
|
|
const envTriggerMapping = useEnvTriggerMapping();
|
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;
|
2023-11-16 03:10:39 +00:00
|
|
|
}, [pageTitle, networkName, DEFAULT_TITLE]);
|
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(
|
2023-11-14 14:25:29 +00:00
|
|
|
'grid relative h-full z-0',
|
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 (
|
2023-11-16 03:10:39 +00:00
|
|
|
<Suspense fallback={<AppLoader />}>
|
|
|
|
<HashRouter>
|
|
|
|
<Bootstrapper>
|
|
|
|
<AppBody {...props} />
|
|
|
|
</Bootstrapper>
|
|
|
|
<NodeSwitcherDialog open={nodeSwitcherOpen} setOpen={setNodeSwitcher} />
|
|
|
|
</HashRouter>
|
|
|
|
</Suspense>
|
2022-02-11 13:56:28 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-02-17 05:03:46 +00:00
|
|
|
export default VegaTradingApp;
|