-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.tsx
164 lines (154 loc) · 4.54 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import { NavBar } from "@components/navbar";
import { StandardPageContainer } from "@components/StandardPageContainer";
import { CustomToaster } from "@components/toasts/CustomToaster";
import { PageFooter } from "@layouts/PageFooter";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { Grid } from "@tw/Grid";
import { MainPanel } from "@ui/MainPanel";
import { Splash } from "@ui/Splash";
import { useEffect, useState } from "react";
import toast from "react-hot-toast";
import { http, toHex, webSocket } from "viem";
import { arbitrum, base, mainnet, optimism } from "viem/chains";
import {
createConfig,
fallback,
unstable_connector,
useAccount,
WagmiProvider,
} from "wagmi";
import { injected, walletConnect } from "wagmi/connectors";
export const Main = () => {
const { address, chain } = useAccount();
const [pub, setPub] = useState(toHex("", { size: 32 }));
const [ready, setReady] = useState(false);
const [locked, setLocked] = useState(false);
const [secret, setSecret] = useState(undefined);
const [registered, setRegistered] = useState(false);
const logOut = () => {
setPub(toHex("", { size: 32 }));
setSecret(undefined);
setReady(false);
setRegistered(true); // hard to imagine a case where this is necessary.
};
// really the below two useEffects can (apparently) go essentially anywhere.
useEffect(() => {
// watchChainId
if (chain === undefined)
toast.error("Switched to an unsupported chain."); // Your wallet has been disconnected.
else
toast(
<span>
Switched the chain to <b>{chain.name}</b>.
</span>,
);
logOut();
}, [chain]);
useEffect(() => {
// watchAccount
if (address)
toast(
<span>
Switched account to{" "}
<code>
{address.slice(0, 6)}...{address.slice(-4)}
</code>
.
</span>,
);
}, [address]);
return (
<div className="text-slate-400 bg-black min-h-screen overflow-hidden">
<NavBar {...{ logOut, pub, locked, setLocked }} />
<StandardPageContainer>
<Grid
cols={{ xs: 1 }}
className="justify-center place-content-center place-items-center"
>
<div className="max-w-[46.3rem] w-full">
{secret === undefined ? (
<Splash
{...{ setSecret, setPub, locked, setLocked, setRegistered }}
/>
) : (
<MainPanel
{...{
pub,
secret,
locked,
setLocked,
ready,
setReady,
registered,
setRegistered,
}}
/>
)}
</div>
</Grid>
</StandardPageContainer>
<PageFooter locked={locked} setLocked={setLocked} />
</div>
);
};
const queryClient = new QueryClient();
const config = createConfig({
chains: [mainnet, arbitrum, optimism, base],
pollingInterval: 10000,
connectors: [
walletConnect({ projectId: "0123456789abcdef0123456789abcdef" }), // your walletconnect project ID
],
transports: {
[mainnet.id]: fallback([
webSocket(
"wss://eth-mainnet.g.alchemy.com/v2/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef",
),
http(
"https://eth-mainnet.g.alchemy.com/v2/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef",
),
http(),
unstable_connector(injected),
]),
[arbitrum.id]: fallback([
webSocket(
"wss://arb-mainnet.g.alchemy.com/v2/ghijklmnopqrstuvwxyz0123456789-_",
),
http(
"https://arb-mainnet.g.alchemy.com/v2/ghijklmnopqrstuvwxyz0123456789-_",
),
http(),
unstable_connector(injected),
]),
[optimism.id]: fallback([
webSocket(
"wss://opt-mainnet.g.alchemy.com/v2/firnfirnfirnfirnfirnfirnfirnfirn",
),
http(
"https://opt-mainnet.g.alchemy.com/v2/firnfirnfirnfirnfirnfirnfirnfirn",
),
http(),
unstable_connector(injected),
]),
[base.id]: fallback([
webSocket(
"wss://base-mainnet.g.alchemy.com/v2/protocolprotocolprotocolprotocol",
),
http(
"https://base-mainnet.g.alchemy.com/v2/protocolprotocolprotocolprotocol",
),
http(),
unstable_connector(injected),
]),
},
});
const App = () => {
return (
<WagmiProvider config={config}>
<QueryClientProvider client={queryClient}>
<CustomToaster />
<Main />
</QueryClientProvider>
</WagmiProvider>
);
};
export default App;