-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathBlocklist.jsx
135 lines (125 loc) · 4.65 KB
/
Blocklist.jsx
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import React, { useEffect, useState } from 'react';
import { CardBody, Col, Row } from 'reactstrap';
import { connect } from 'react-redux';
import { push } from 'connected-react-router'
import styled from 'styled-components';
import isObjectEmpty from 'helpers/is-object-empty';
import { LoadingSpinner, LimitSelectDropdown } from 'components';
import { CardStyled,CardHeaderStyled, TableStyled, ButtonPrimary, ErrorButton, CheckBoxDivStyled, InputStyled } from 'styled';
import { pollingStart, pollingStop, filterToggle, recordsUpdate } from './BlocklistReducer';
const FirstCardStyled = styled(CardStyled)`
border-top: solid 2px #1173a4;
`
const SearchInputStyled = styled(InputStyled)`
width: 65%;
margin-right: 10px;
`
const DivFlexStyled = styled.div`
display: flex;
justify-content: flex-end;
padding-bottom: 20px;
`
const Blocklist = (props) => {
useEffect(()=>{
props.pollingStart()
return () => { props.pollingStop() }
}, [])
const [inputValue, setInputValue] = useState("");
let { blocklist: { isPolling, data, filter, records } } = props;
let { payload = [], error } = data;
return (
<div className="Blocklist">
<FirstCardStyled>
<CardHeaderStyled>Block List</CardHeaderStyled>
<CardBody>
<Row>
<Col sm="5">
<CheckBoxDivStyled>
<label className="checkboxContainer">No empty blocks
<input onChange={props.filterToggle} type="checkbox" checked={filter} />
<span className="checkmark"></span>
</label>
</CheckBoxDivStyled>
</Col>
<Col sm="7">
<DivFlexStyled>
<SearchInputStyled
placeholder="Block number / Block ID"
value={inputValue}
onKeyDown={
evt => {
if (evt.key === 'Enter') {
setInputValue("");
if(inputValue !== "")
props.push('/block/'+inputValue)
}
}
}
onChange={evt=>{setInputValue(evt.target.value)}}/>
<ButtonPrimary
onClick={evt=> {
setInputValue("");
if(inputValue !== "")
props.push('/block/'+inputValue)
}}>
SEARCH</ButtonPrimary>
</DivFlexStyled>
</Col>
</Row>
<div>
{ error
?
<>
{!isObjectEmpty(error) && <p className="text-danger">{JSON.stringify(error)}</p>}
<ErrorButton onClick={props.pollingStart}>Connection error, click to reload</ErrorButton>
</>
:
<Row>
<Col xs="12">
<TableStyled borderless>
<thead>
<tr>
<th width="15%">Block Number</th>
<th width="45%">Block ID</th>
<th width="20%">No. of Transactions</th>
<th width="20%">Timestamp</th>
</tr>
</thead>
<tbody className="hashText">
{(isPolling || payload.length <= 0) ? (
<tr><td colSpan="4" className="text-center"><LoadingSpinner /></td></tr>
) : payload.map(eachBlock=>
<tr onClick={evt=>props.push(`/block/${eachBlock.block_num}`)} key={eachBlock.block_num}>
<td>{eachBlock.block_num}</td>
<td>{eachBlock.block_id}</td>
<td>{eachBlock.transaction_count}</td>
<td>{eachBlock.timestamp}</td>
</tr>)}
</tbody>
</TableStyled>
</Col>
{payload.length > 0 &&
<Col xs="12" className="text-right">
<LimitSelectDropdown limit={records} onChange={(limit) => { props.recordsUpdate(limit) }} />
</Col>
}
</Row>
}
</div>
</CardBody>
</FirstCardStyled>
</div>
);
}
export default connect(
({ blocklistPage: { blocklist }}) => ({
blocklist
}),
{
pollingStart,
pollingStop,
filterToggle,
recordsUpdate,
push
}
)(Blocklist);