-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrderBook.js
More file actions
100 lines (80 loc) · 3.23 KB
/
Copy pathOrderBook.js
File metadata and controls
100 lines (80 loc) · 3.23 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
100
import { useDispatch, useSelector } from 'react-redux'
// Import Assets
import sort from '../assets/sort.svg'
// Import Selectors
import { orderBookSelector } from '../store/selectors'
// Import Interactions
import { fillOrder } from '../store/interactions';
const OrderBook = () => {
const provider = useSelector(state => state.provider.connection)
const exchange = useSelector(state => state.exchange.contract)
const symbols = useSelector(state => state.tokens.symbols)
const orderBook = useSelector(orderBookSelector)
const dispatch = useDispatch()
const fillOrderHandler = (order) => {
fillOrder(provider, exchange, order, dispatch)
}
return (
<div className="component exchange__orderbook">
<div className='component__header flex-between'>
<h2>Order Book</h2>
</div>
<div className="flex">
{!orderBook || orderBook.sellOrders.length === 0 ? (
<p className='flex-center'>No Sell Orders Yet...</p>
) : (
<table className='exchange__orderbook--sell'>
<caption>Selling</caption>
<thead>
<tr>
<th>{symbols && symbols[0]}<img src={sort} alt="Sort" /></th>
<th>{symbols && symbols[0]}/{symbols && symbols[1]}<img src={sort} alt="Sort" /></th>
<th>{symbols && symbols[1]}<img src={sort} alt="Sort" /></th>
</tr>
</thead>
<tbody>
{/* MAPPING OF SELL ORDERS... */}
{orderBook && orderBook.sellOrders.map((order, index) => {
return(
<tr key={index} onClick={() => fillOrderHandler(order)}>
<td>{order.token0Amount}</td>
<td style={{ color: `${order.orderTypeClass}` }}>{order.tokenPrice}</td>
<td>{order.token1Amount}</td>
</tr>
)
})}
</tbody>
</table>
)}
<div className='divider'></div>
{!orderBook || orderBook.buyOrders.length === 0 ? (
<p className='flex-center'>No Buy Orders Yet...</p>
) : (
<table className='exchange__orderbook--buy'>
<caption>Buying</caption>
<thead>
<tr>
<th>{symbols && symbols[0]}<img src={sort} alt="Sort" /></th>
<th>{symbols && symbols[0]}/{symbols && symbols[1]}<img src={sort} alt="Sort" /></th>
<th>{symbols && symbols[1]}<img src={sort} alt="Sort" /></th>
</tr>
</thead>
<tbody>
{/* MAPPING OF BUY ORDERS... */}
{orderBook && orderBook.buyOrders.map((order, index) => {
return(
<tr key={index} onClick={() => fillOrderHandler(order)}>
<td>{order.token0Amount}</td>
<td style={{ color: `${order.orderTypeClass}` }}>{order.tokenPrice}</td>
<td>{order.token1Amount}</td>
</tr>
)
})}
</tbody>
</table>
)}
</div>
</div>
);
}
export default OrderBook;