generated from brweisz/noir-dapp-custom-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.tsx
78 lines (70 loc) · 2.23 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
// @ts-nocheck
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.js';
import ReaderPage from './components/reader_page.jsx';
import PublisherForm from './components/publisher_page.jsx';
import initNoirC from '@noir-lang/noirc_abi';
import initACVM from '@noir-lang/acvm_js';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { WagmiProvider, createConfig, http } from 'wagmi';
import { defineChain, createClient } from 'viem';
import { injected } from 'wagmi/connectors';
import { networkConfig } from "./artifacts/deployment.json";
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
const queryClient = new QueryClient();
const { id, name, nativeCurrency, rpcUrls } = networkConfig;
const chain = defineChain({
id,
name,
nativeCurrency,
rpcUrls
});
const config = createConfig({
connectors: [
injected()
],
chains: [chain],
client({ chain}) {
return createClient({ chain, transport: http() });
}
});
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 (
<WagmiProvider config={config}>
<QueryClientProvider client={queryClient}>{mounted && children}</QueryClientProvider>
</WagmiProvider>
);
}
ReactDOM.createRoot(document.getElementById('root')!).render(
<Providers>
<InitWasm>
<Router>
<Routes>
<Route path="/publisher" element={<PublisherForm />} />
</Routes>
</Router>
<ToastContainer />
</InitWasm>
</Providers>,
);