-
Notifications
You must be signed in to change notification settings - Fork 352
/
NodeInfo.js
53 lines (48 loc) · 1.33 KB
/
NodeInfo.js
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
import React, { useEffect, useState } from 'react'
import { Card, Icon, Grid } from 'semantic-ui-react'
import { useSubstrateState } from './substrate-lib'
function Main(props) {
const { api, socket } = useSubstrateState()
const [nodeInfo, setNodeInfo] = useState({})
useEffect(() => {
const getInfo = async () => {
try {
const [chain, nodeName, nodeVersion] = await Promise.all([
api.rpc.system.chain(),
api.rpc.system.name(),
api.rpc.system.version(),
])
setNodeInfo({ chain, nodeName, nodeVersion })
} catch (e) {
console.error(e)
}
}
getInfo()
}, [api.rpc.system])
return (
<Grid.Column>
<Card>
<Card.Content>
<Card.Header>{nodeInfo.nodeName}</Card.Header>
<Card.Meta>
<span>{nodeInfo.chain}</span>
</Card.Meta>
<Card.Description>{socket}</Card.Description>
</Card.Content>
<Card.Content extra>
<Icon name="setting" />v{nodeInfo.nodeVersion}
</Card.Content>
</Card>
</Grid.Column>
)
}
export default function NodeInfo(props) {
const { api } = useSubstrateState()
return api.rpc &&
api.rpc.system &&
api.rpc.system.chain &&
api.rpc.system.name &&
api.rpc.system.version ? (
<Main {...props} />
) : null
}