-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathapp.tsx
68 lines (59 loc) · 2.12 KB
/
app.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
// This is the entrypoint to the panel app.
// It has access to chrome.* APIs, but it can't interact with other extensions such as MetaMask.
import { Info } from '@/components'
import { ProvideBridgeContext } from '@/inject-bridge'
import { ProvideInjectedWallet } from '@/providers'
import { invariant } from '@epic-web/invariant'
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import { createHashRouter, RouterProvider } from 'react-router'
import { ToastContainer } from 'react-toastify'
import 'react-toastify/dist/ReactToastify.min.css'
import '../global.css'
import { pages } from './pages'
import { ProvideState } from './state'
import { usePilotPort } from './usePilotPort'
const router = createHashRouter(pages)
const Root = () => {
const { activeWindowId } = usePilotPort()
if (activeWindowId == null) {
return (
<div className="relative top-32 flex h-full flex-col items-center gap-32 px-4">
<Info title="Current tab is incompatible">
Pilot is waiting to connect to a dApp. Open the dApp you want to
simulate and Pilot will automatically connect to it.
</Info>
</div>
)
}
return (
<StrictMode>
<ProvideBridgeContext windowId={activeWindowId}>
<ProvideState>
<ProvideInjectedWallet>
<div className="flex h-full flex-1 flex-col">
<RouterProvider router={router} />
</div>
<ToastContainer position="top-center" />
</ProvideInjectedWallet>
</ProvideState>
</ProvideBridgeContext>
</StrictMode>
)
}
const rootEl = document.getElementById('root')
invariant(rootEl != null, 'Could not find DOM node to attach app')
createRoot(rootEl).render(<Root />)
if (process.env.LIVE_RELOAD) {
new EventSource(process.env.LIVE_RELOAD).addEventListener('change', (ev) => {
const { added, removed, updated } = JSON.parse(ev.data)
if (
[...added, ...removed, ...updated].some((path) =>
path.startsWith('/build/build/panel/'),
)
) {
console.debug('🔄 detected change, reloading panel...')
location.reload()
}
})
}