-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
99 lines (72 loc) · 2.16 KB
/
Copy pathApp.js
File metadata and controls
99 lines (72 loc) · 2.16 KB
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
import { useEffect } from 'react';
import { useDispatch } from 'react-redux';
import config from '../config.json';
import {
loadProvider,
loadNetwork,
loadAccount,
loadTokens,
loadExchange,
loadAllOrders,
subscribeToEvents
} from '../store/interactions';
import Navbar from './Navbar'
import Markets from './Markets'
import Balance from './Balance'
import Order from './Order'
import PriceChart from './PriceChart'
import Transactions from './Transactions'
import Trades from './Trades'
import OrderBook from './OrderBook'
import Alert from './Alert'
function App() {
const dispatch = useDispatch()
const loadBlockchainData = async () => {
// Connect Ethers to blockchain
const provider = loadProvider(dispatch)
// Fetch current network's ChainId (e.g. hardhat: 31337, kovan: 42)
const chainId = await loadNetwork(provider, dispatch)
// Reload page when network changes
window.ethereum.on('chainChanged', () => {
window.location.reload()
})
// Fetch current account & balance from Metamask when changed
window.ethereum.on('accountsChanged', () => {
loadAccount(provider, dispatch)
})
// Load token smart contracts
const DApp = config[chainId].DApp
const mETH = config[chainId].mETH
await loadTokens(provider, [DApp.address, mETH.address], dispatch)
// Load Exchange smart contract
const exchangeConfig = config[chainId].exchange
const exchange = await loadExchange(provider, exchangeConfig.address, dispatch)
// Fetch all orders: open, filled, cancelled
loadAllOrders(provider, exchange, dispatch)
// Listen to events
subscribeToEvents(exchange, dispatch)
}
useEffect(() => {
loadBlockchainData()
})
return (
<div>
<Navbar />
<main className='exchange grid'>
<section className='exchange__section--left grid'>
<Markets />
<Balance />
<Order />
</section>
<section className='exchange__section--right grid'>
<PriceChart />
<Transactions />
<Trades />
<OrderBook />
</section>
</main>
<Alert />
</div>
);
}
export default App;