-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.tsx
84 lines (76 loc) · 2.51 KB
/
index.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import { Provider } from "react-redux";
import store from "./redux/store";
import reportWebVitals from "./reportWebVitals";
import type { AbstractConnector } from "@web3-react/abstract-connector";
import { Web3ReactProvider } from "@web3-react/core";
import { Web3Provider } from "@ethersproject/providers";
import { QueryClient, QueryClientProvider, QueryCache } from "react-query";
import { BigNumber, FixedNumber } from "ethers";
import {
AmbientConnectionContext,
CreateAmbientConnectionContext,
useAmbientConnection,
} from "./hooks/injectedConnectors";
import { ReactQueryDevtools } from "react-query/devtools";
const reactQueryClient = new QueryClient({
queryCache: new QueryCache(),
});
function getWeb3Library(
provider: any,
connector?: AbstractConnector | undefined
): Web3Provider {
const library = new Web3Provider(provider);
library.pollingInterval = 5000;
return library;
}
const AppWeb3ConnectionWrapper: React.FC<{}> = () => {
useAmbientConnection();
return React.useMemo(() => <App />, []);
};
const AppRoot: React.FC<{}> = () => {
const [ambientConnections, setAmbientConnections] = React.useState(() =>
CreateAmbientConnectionContext()
);
const ambientContext = React.useMemo(
() => ({
connections: ambientConnections,
setConnections: setAmbientConnections,
}),
[ambientConnections, setAmbientConnections]
);
return (
<AmbientConnectionContext.Provider value={ambientContext}>
<AppWeb3ConnectionWrapper />
</AmbientConnectionContext.Provider>
);
};
// function wrapper is used to enable HMR
function renderApp() {
ReactDOM.render(
<Web3ReactProvider getLibrary={getWeb3Library}>
<Provider store={store}>
<QueryClientProvider client={reactQueryClient}>
<React.StrictMode>
<AppRoot />
</React.StrictMode>
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
</Provider>
</Web3ReactProvider>,
document.getElementById("root")
);
}
renderApp();
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
if (process.env.NODE_ENV === "development" && module.hot) {
(window as any).FixedNumber = FixedNumber;
(window as any).BigNumber = BigNumber;
module.hot.accept("./App", renderApp);
}