forked from AztecProtocol/noir-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.tsx
42 lines (38 loc) · 1.28 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
import React, { ReactNode, useEffect } from 'react';
import ReactDOM from 'react-dom/client';
import './App.css';
import 'react-toastify/dist/ReactToastify.css';
import { ToastContainer } from 'react-toastify';
import Component from './components/index';
import initNoirC from '@noir-lang/noirc_abi';
import initACVM from '@noir-lang/acvm_js';
import { WagmiConfig } from 'wagmi';
import { config } from './utils/wagmi';
const InitWasm = ({ children }) => {
const [init, setInit] = React.useState(false);
useEffect(() => {
(async () => {
await Promise.all([
initACVM(new URL('@noir-lang/acvm_js/web/acvm_js_bg.wasm', import.meta.url).toString()),
initNoirC(
new URL('@noir-lang/noirc_abi/web/noirc_abi_wasm_bg.wasm', import.meta.url).toString(),
),
]);
setInit(true);
})();
});
return <div>{init && children}</div>;
};
export function Providers({ children }: { children: React.ReactNode }) {
const [mounted, setMounted] = React.useState(false);
React.useEffect(() => setMounted(true), []);
return <WagmiConfig config={config}>{mounted && children}</WagmiConfig>;
}
ReactDOM.createRoot(document.getElementById('root')!).render(
<Providers>
<InitWasm>
<Component />
<ToastContainer />
</InitWasm>
</Providers>,
);