-
Notifications
You must be signed in to change notification settings - Fork 41
/
App.tsx
48 lines (42 loc) · 994 Bytes
/
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
import React from 'react'
import {useMoralis} from 'react-moralis'
import connectors from './connectors'
const App: React.FC = () => {
const {authenticate, account, logout, isAuthenticated} = useMoralis()
function createConnectHandler(connectorId: string) {
return async () => {
try {
const connector = connectors[connectorId]
console.log(connector)
await authenticate(connector)
} catch (error) {
console.error(error)
}
}
}
async function handleDisconnect() {
try {
logout()
} catch (error) {
console.error(error)
}
}
if (isAuthenticated) {
return (
<>
<div>Connected to {account}</div>
<button onClick={handleDisconnect}>Disconnect</button>
</>
)
}
return (
<>
{Object.keys(connectors).map(v => (
<button key={v} onClick={createConnectHandler(v)}>
Connect to {v}
</button>
))}
</>
)
}
export default App