-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
109 lines (99 loc) · 2.71 KB
/
App.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
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
import React, { useState,createRef } from 'react'
import {
Container,
Dimmer,
Loader,
Grid,
Sticky,
Message,
} from 'semantic-ui-react'
import 'semantic-ui-css/semantic.min.css'
import { SubstrateContextProvider, useSubstrateState } from './substrate-lib'
import { DeveloperConsole } from './substrate-lib/components'
import AccountSelector from './AccountSelector'
import Balances from './Balances'
import BlockNumber from './BlockNumber'
import Events from './Events'
import Interactor from './Interactor'
import Metadata from './Metadata'
import NodeInfo from './NodeInfo'
import TemplateModule from './TemplateModule'
import Transfer from './Transfer'
import Upgrade from './Upgrade'
import Kitties from './Kitties'
function Main() {
const { apiState, apiError, keyringState ,keyring} = useSubstrateState()
const [accountAddress, setAccountAddress] = useState(null);
const accountPair =
accountAddress &&
keyringState === 'READY' &&
keyring.getPair(accountAddress);
const loader = text => (
<Dimmer active>
<Loader size="small">{text}</Loader>
</Dimmer>
)
const message = errObj => (
<Grid centered columns={2} padded>
<Grid.Column>
<Message
negative
compact
floating
header="Error Connecting to Substrate"
content={`Connection to websocket '${errObj.target.url}' failed.`}
/>
</Grid.Column>
</Grid>
)
if (apiState === 'ERROR') return message(apiError)
else if (apiState !== 'READY') return loader('Connecting to Substrate')
if (keyringState !== 'READY') {
return loader(
"Loading accounts (please review any extension's authorization)"
)
}
const contextRef = createRef()
return (
<div ref={contextRef}>
<Sticky context={contextRef}>
<AccountSelector setAccountAddress={setAccountAddress} />
</Sticky>
<Container>
<Grid stackable columns="equal">
<Grid.Row stretched>
<NodeInfo />
<Metadata />
<BlockNumber />
<BlockNumber finalized />
</Grid.Row>
<Grid.Row stretched>
<Kitties accountPair={accountPair} />
</Grid.Row>
<Grid.Row stretched>
<Balances />
</Grid.Row>
<Grid.Row>
<Transfer />
<Upgrade />
</Grid.Row>
<Grid.Row>
<Interactor />
<Events />
</Grid.Row>
<Grid.Row>
<TemplateModule />
</Grid.Row>
</Grid>
</Container>
<DeveloperConsole />
</div>
)
}
export default function App() {
return (
<SubstrateContextProvider>
<Main />
</SubstrateContextProvider>
)
}