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-02-17 05:08:17 +00:00
|
|
|
import { Navbar } from '../components/navbar';
|
2022-03-31 17:16:30 +00:00
|
|
|
import { t, ThemeContext, useThemeSwitcher } from '@vegaprotocol/react-helpers';
|
2022-10-14 15:42:53 +00:00
|
|
|
import { VegaWalletProvider } from '@vegaprotocol/wallet';
|
2022-09-23 14:29:35 +00:00
|
|
|
import {
|
|
|
|
EnvironmentProvider,
|
|
|
|
envTriggerMapping,
|
2022-10-28 15:13:14 +00:00
|
|
|
Networks,
|
2022-09-23 14:29:35 +00:00
|
|
|
useEnvironment,
|
|
|
|
} from '@vegaprotocol/environment';
|
2022-03-11 00:28:48 +00:00
|
|
|
import { AppLoader } from '../components/app-loader';
|
2022-03-14 13:18:11 +00:00
|
|
|
import './styles.css';
|
2022-10-14 15:42:53 +00:00
|
|
|
import { usePageTitleStore } from '../stores';
|
2022-08-31 04:35:46 +00:00
|
|
|
import { Footer } from '../components/footer';
|
2022-11-08 07:23:38 +00:00
|
|
|
import { useEffect, useMemo, useState } from 'react';
|
2022-10-14 15:42:53 +00:00
|
|
|
import DialogsContainer from './dialogs-container';
|
2022-11-08 07:23:38 +00:00
|
|
|
import { HashRouter, useLocation } from 'react-router-dom';
|
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();
|
2022-10-28 15:13:14 +00:00
|
|
|
const { VEGA_ENV } = useEnvironment();
|
2022-10-14 15:42:53 +00:00
|
|
|
const [theme, toggleTheme] = useThemeSwitcher();
|
2022-11-08 07:23:38 +00:00
|
|
|
|
2022-06-10 09:15:38 +00:00
|
|
|
return (
|
2022-06-24 03:16:01 +00:00
|
|
|
<ThemeContext.Provider value={theme}>
|
2022-10-27 18:12:03 +00:00
|
|
|
<Head>
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
2022-11-18 17:08:48 +00:00
|
|
|
<link
|
|
|
|
rel="preload"
|
|
|
|
href="https://static.vega.xyz/AlphaLyrae-Medium.woff2"
|
|
|
|
as="font"
|
|
|
|
type="font/woff2"
|
|
|
|
crossOrigin="anonymous"
|
|
|
|
/>
|
|
|
|
<link
|
|
|
|
rel="icon"
|
|
|
|
type="image/x-icon"
|
|
|
|
href="https://static.vega.xyz/favicon.ico"
|
|
|
|
/>
|
|
|
|
<link rel="stylesheet" href="https://static.vega.xyz/fonts.css" />
|
2022-10-27 18:12:03 +00:00
|
|
|
</Head>
|
2022-10-14 15:42:53 +00:00
|
|
|
<Title />
|
2022-08-31 04:35:46 +00:00
|
|
|
<div className="h-full relative dark:bg-black dark:text-white z-0 grid grid-rows-[min-content,1fr,min-content]">
|
2022-06-24 03:16:01 +00:00
|
|
|
<AppLoader>
|
2022-10-28 15:13:14 +00:00
|
|
|
<Navbar
|
|
|
|
theme={theme}
|
|
|
|
toggleTheme={toggleTheme}
|
|
|
|
navbarTheme={VEGA_ENV === Networks.TESTNET ? 'yellow' : 'dark'}
|
|
|
|
/>
|
2022-11-08 07:23:38 +00:00
|
|
|
<main data-testid={location.pathname}>
|
|
|
|
<Component />
|
2022-06-24 03:16:01 +00:00
|
|
|
</main>
|
2022-08-31 04:35:46 +00:00
|
|
|
<Footer />
|
2022-10-14 15:42:53 +00:00
|
|
|
<DialogsContainer />
|
2022-06-24 03:16:01 +00:00
|
|
|
</AppLoader>
|
|
|
|
</div>
|
|
|
|
</ThemeContext.Provider>
|
2022-06-10 09:15:38 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function VegaTradingApp(props: AppProps) {
|
2022-11-08 07:23:38 +00:00
|
|
|
const [mounted, setMounted] = useState(false);
|
|
|
|
|
|
|
|
// Hash router requires access to the document object. At compile time that doesn't exist
|
|
|
|
// so we need to ensure client side rendering only from this point onwards in
|
|
|
|
// the component tree
|
|
|
|
useEffect(() => {
|
|
|
|
setMounted(true);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
if (!mounted) return null;
|
|
|
|
|
2022-02-11 13:56:28 +00:00
|
|
|
return (
|
2022-11-08 07:23:38 +00:00
|
|
|
<HashRouter>
|
|
|
|
<EnvironmentProvider>
|
|
|
|
<VegaWalletProvider>
|
|
|
|
<AppBody {...props} />
|
|
|
|
</VegaWalletProvider>
|
|
|
|
</EnvironmentProvider>
|
|
|
|
</HashRouter>
|
2022-02-11 13:56:28 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-02-17 05:03:46 +00:00
|
|
|
export default VegaTradingApp;
|