2022-09-02 14:53:38 +00:00
|
|
|
import Head from 'next/head';
|
2022-12-27 15:46:44 +00:00
|
|
|
import dynamic from 'next/dynamic';
|
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-12-21 02:55:35 +00:00
|
|
|
import { t } from '@vegaprotocol/react-helpers';
|
2022-12-07 09:24:40 +00:00
|
|
|
import {
|
|
|
|
useEagerConnect as useVegaEagerConnect,
|
|
|
|
VegaWalletProvider,
|
2022-12-21 09:29:32 +00:00
|
|
|
useVegaTransactionManager,
|
|
|
|
useVegaTransactionUpdater,
|
2023-01-19 11:16:21 +00:00
|
|
|
useVegaWallet,
|
2022-12-07 09:24:40 +00:00
|
|
|
} from '@vegaprotocol/wallet';
|
2022-12-21 09:29:32 +00:00
|
|
|
import {
|
|
|
|
useEagerConnect as useEthereumEagerConnect,
|
|
|
|
useEthTransactionManager,
|
|
|
|
useEthTransactionUpdater,
|
|
|
|
useEthWithdrawApprovalsManager,
|
|
|
|
} from '@vegaprotocol/web3';
|
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-12-07 09:24:40 +00:00
|
|
|
import { AppLoader, Web3Provider } from '../components/app-loader';
|
2022-03-14 13:18:11 +00:00
|
|
|
import './styles.css';
|
2022-12-27 15:46:44 +00:00
|
|
|
import './gen-styles.scss';
|
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-12-21 09:29:32 +00:00
|
|
|
import ToastsManager from './toasts-manager';
|
2023-01-19 11:16:21 +00:00
|
|
|
import { HashRouter, useLocation, useSearchParams } from 'react-router-dom';
|
2022-12-07 09:24:40 +00:00
|
|
|
import { Connectors } from '../lib/vega-connectors';
|
2023-01-19 11:16:21 +00:00
|
|
|
import { ViewingBanner } from '../components/viewing-banner';
|
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-12-21 09:29:32 +00:00
|
|
|
const TransactionsHandler = () => {
|
|
|
|
useVegaTransactionManager();
|
|
|
|
useVegaTransactionUpdater();
|
|
|
|
useEthTransactionManager();
|
|
|
|
useEthTransactionUpdater();
|
|
|
|
useEthWithdrawApprovalsManager();
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
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-11-08 07:23:38 +00:00
|
|
|
|
2022-06-10 09:15:38 +00:00
|
|
|
return (
|
2022-12-27 15:46:44 +00:00
|
|
|
<div className="h-full dark:bg-black dark:text-white">
|
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 />
|
2022-12-07 09:24:40 +00:00
|
|
|
<VegaWalletProvider>
|
2022-06-24 03:16:01 +00:00
|
|
|
<AppLoader>
|
2022-12-07 09:24:40 +00:00
|
|
|
<Web3Provider>
|
2023-01-19 11:16:21 +00:00
|
|
|
<div className="h-full relative z-0 grid grid-rows-[min-content,min-content,1fr,min-content]">
|
2022-12-07 09:24:40 +00:00
|
|
|
<Navbar
|
|
|
|
navbarTheme={VEGA_ENV === Networks.TESTNET ? 'yellow' : 'dark'}
|
|
|
|
/>
|
2023-01-19 11:16:21 +00:00
|
|
|
<ViewingBanner />
|
2022-12-07 09:24:40 +00:00
|
|
|
<main data-testid={location.pathname}>
|
|
|
|
<Component />
|
|
|
|
</main>
|
|
|
|
<Footer />
|
|
|
|
<DialogsContainer />
|
2022-12-21 09:29:32 +00:00
|
|
|
<ToastsManager />
|
|
|
|
<TransactionsHandler />
|
2022-12-07 09:24:40 +00:00
|
|
|
<MaybeConnectEagerly />
|
|
|
|
</div>
|
|
|
|
</Web3Provider>
|
2022-06-24 03:16:01 +00:00
|
|
|
</AppLoader>
|
2022-12-07 09:24:40 +00:00
|
|
|
</VegaWalletProvider>
|
2022-12-27 15:46:44 +00:00
|
|
|
</div>
|
2022-06-10 09:15:38 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-27 15:46:44 +00:00
|
|
|
const DynamicLoader = dynamic(
|
|
|
|
() => import('../components/preloader/preloader'),
|
|
|
|
{
|
|
|
|
loading: () => <>Loading...</>,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
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);
|
|
|
|
}, []);
|
|
|
|
|
2022-12-27 15:46:44 +00:00
|
|
|
if (!mounted) {
|
|
|
|
return <DynamicLoader />;
|
|
|
|
}
|
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>
|
|
|
|
<EnvironmentProvider>
|
2022-12-07 09:24:40 +00:00
|
|
|
<AppBody {...props} />
|
2022-11-08 07:23:38 +00:00
|
|
|
</EnvironmentProvider>
|
|
|
|
</HashRouter>
|
2022-02-11 13:56:28 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-02-17 05:03:46 +00:00
|
|
|
export default VegaTradingApp;
|
2022-12-07 09:24:40 +00:00
|
|
|
|
|
|
|
const MaybeConnectEagerly = () => {
|
|
|
|
useVegaEagerConnect(Connectors);
|
|
|
|
useEthereumEagerConnect();
|
2023-01-19 11:16:21 +00:00
|
|
|
|
|
|
|
const { pubKey, connect } = useVegaWallet();
|
|
|
|
const [searchParams] = useSearchParams();
|
|
|
|
const [query] = useState(searchParams.get('address'));
|
|
|
|
if (query && !pubKey) {
|
|
|
|
connect(Connectors['view']);
|
|
|
|
}
|
2022-12-07 09:24:40 +00:00
|
|
|
return null;
|
|
|
|
};
|