-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathWormholeConnect.tsx
59 lines (55 loc) · 1.94 KB
/
WormholeConnect.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import * as React from 'react';
// fixes "styled_default is not a function" error
// https://github.com/vitejs/vite/issues/12423#issuecomment-2080351394
import '@mui/material/styles/styled';
import { Provider } from 'react-redux';
import ScopedCssBaseline from '@mui/material/ScopedCssBaseline';
import { ThemeProvider } from '@mui/material/styles';
import './App.css';
import { store } from './store';
import AppRouter from './AppRouter';
import { generateTheme } from './theme';
import ErrorBoundary from './components/ErrorBoundary';
import { WormholeConnectConfig } from './config/types';
import { WormholeConnectTheme } from 'theme';
import { RouteProvider } from './contexts/RouteContext';
import { TokensProvider } from './contexts/TokensContext';
export interface WormholeConnectProps {
// theme can be updated at any time to change the colors of Connect
theme?: WormholeConnectTheme;
// config is only used once, when Connect first mounts, to initialize the global config
config?: WormholeConnectConfig;
}
export default function WormholeConnect({
config,
theme,
}: WormholeConnectProps) {
React.useEffect(() => {
// IMPORTANT: This is a workaround to expose the Redux store to the window object so it can be used in automated tests.
if (!globalThis.dispatchReduxAction) {
(window as any).dispatchReduxAction = (action: any) => {
store.dispatch(action);
};
}
}, []);
// Handle theme changes at any time
const muiTheme = React.useMemo(
() => generateTheme(theme ?? { mode: 'dark' }),
[theme],
);
return (
<Provider store={store}>
<ThemeProvider theme={muiTheme}>
<ScopedCssBaseline enableColorScheme>
<ErrorBoundary>
<TokensProvider>
<RouteProvider>
<AppRouter config={config} />
</RouteProvider>
</TokensProvider>
</ErrorBoundary>
</ScopedCssBaseline>
</ThemeProvider>
</Provider>
);
}