vega-frontend-monorepo/apps/trading/pages/_app.page.tsx

77 lines
2.2 KiB
TypeScript
Raw Normal View History

2022-02-28 23:43:36 +00:00
import { ApolloProvider } from '@apollo/client';
import { AppProps } from 'next/app';
import Head from 'next/head';
import { useCallback, useMemo } from 'react';
2022-02-17 05:08:17 +00:00
import { Navbar } from '../components/navbar';
2022-02-28 23:43:36 +00:00
import { createClient } from '../lib/apollo-client';
import { ThemeSwitcher } from '@vegaprotocol/ui-toolkit';
import { useVegaWallet } from '@vegaprotocol/react-helpers';
2022-02-23 17:57:44 +00:00
import './styles.css';
2022-02-17 05:03:46 +00:00
function VegaTradingApp({ Component, pageProps }: AppProps) {
2022-02-28 23:43:36 +00:00
const client = useMemo(() => createClient(process.env['NX_VEGA_URL']), []);
useCallback(() => {
if (
localStorage.theme === 'dark' ||
(!('theme' in localStorage) &&
window.matchMedia('(prefers-color-scheme: dark)').matches)
) {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}
}, []);
const setTheme = () => {
localStorage.theme = document.documentElement.classList.toggle('dark')
? 'dark'
: undefined;
};
return (
2022-02-28 23:43:36 +00:00
<ApolloProvider client={client}>
<Head>
<title>Welcome to trading!</title>
<link
rel="icon"
href="https://vega.xyz/favicon-32x32.png"
type="image/png"
/>
</Head>
<div className="h-full dark:bg-black dark:text-white-60 bg-white text-black-60">
<div className="flex items-center border-b-[7px] border-vega-yellow">
<Navbar />
<VegaWalletButton />
<ThemeSwitcher onToggle={setTheme} className="ml-auto mr-8 -my-2" />
</div>
<main>
<Component {...pageProps} />
</main>
</div>
2022-02-28 23:43:36 +00:00
</ApolloProvider>
);
}
interface VegaWalletButtonProps {
setConnectDialog: (isOpen: boolean) => void;
}
const VegaWalletButton = ({ setConnectDialog }: VegaWalletButtonProps) => {
const { disconnect, publicKeys } = useVegaWallet();
const isConnected = publicKeys !== null;
const handleClick = () => {
if (isConnected) {
disconnect();
} else {
setConnectDialog(true);
}
};
return (
<button onClick={handleClick}>
{isConnected ? 'Disconnect' : 'Connect Vega wallet'}
</button>
);
};
2022-02-17 05:03:46 +00:00
export default VegaTradingApp;