-
Notifications
You must be signed in to change notification settings - Fork 106
/
App.tsx
75 lines (67 loc) · 1.97 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
// WAGMI Libraries
import { useWalletClient,useAccount, useConnect, useDisconnect } from "wagmi";
import { useEffect } from 'react';
import { SendTransaction } from "./sendTransaction";
import { SwitchChain } from "./switchNetwork";
import { Balance } from "./balance";
import { WriteContract } from "./writeContract";
import "./App.css";
// context to get the userInfo with web3auth.getUserInfo()
import { ContextProvider, useWeb3Auth } from "./ContextProvider";
function Profile() {
const { address, connector, isConnected } = useAccount();
const { connect, connectors, error } = useConnect();
const { disconnect } = useDisconnect();
const { data: walletClient } = useWalletClient();
let web3Auth = useWeb3Auth();
useEffect(() => {
const getUserInfo = async () => {
try {
var userInfo = await web3Auth?.getUserInfo();
} catch (e) {
console.log("Cannot get userInfo first time, likely web3Auth not fully updated");
}
console.log("/app, userInfo", userInfo);
};
getUserInfo();
}, [walletClient]);
if (isConnected) {
return (
<div className="main">
<div className="title">Connected to {connector?.name}</div>
<div>{address}</div>
<button className="card" onClick={disconnect as any}>
Disconnect
</button>
<SendTransaction />
<Balance />
<WriteContract />
<SwitchChain />
</div>
);
} else {
return (
<div className="main">
{connectors.map((connector) => {
return (
<button className="card" key={connector.id} onClick={() => connect({ connector })}>
{connector.name}
</button>
);
})}
{error && <div>{error.message}</div>}
</div>
);
}
}
// Pass client to React Context Provider
function App() {
return (
<ContextProvider>
<div className="container">
<Profile />
</div>
</ContextProvider>
);
}
export default App;