-
Notifications
You must be signed in to change notification settings - Fork 2
/
BlockCard.js
86 lines (71 loc) · 2.09 KB
/
BlockCard.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
import React, { Component } from "react";
import connect from "../helpers/connect";
import * as Blocks from "../../../common/redux/blocks/actions";
import Moment from "react-moment";
import { hashHistory } from "react-router";
import TxList from "../transactions/TxList";
class BlockCard extends Component {
constructor(props) {
super(props);
}
componentDidMount() {
this.props.dispatch(Blocks.showBlock(this.props.blockNumber));
}
componentDidUpdate(prevProps) {
if (this.props.blockNumber !== prevProps.blockNumber) {
this.props.dispatch(Blocks.showBlock(prevProps.blockNumber));
}
}
render() {
const block = this.props.blocks.currentBlock;
if (!block) {
return <div />;
}
return (
<section className="BlockCard">
<header className="Header">
<button className="Button" onClick={hashHistory.goBack}>
← Back
</button>
<div className="BlockNumber">
<h1>BLOCK {block.number}</h1>
</div>
</header>
<div className="BlockBody">
<div className="HeaderSecondaryInfo">
<div>
<div className="Label">GAS USED</div>
<div className="Value">{block.gasUsed}</div>
</div>
<div>
<div className="Label">GAS LIMIT</div>
<div className="Value">{block.gasLimit}</div>
</div>
<div>
<div className="Label">MINED ON</div>
<div className="Value">
<Moment unix format="YYYY-MM-DD HH:mm:ss">
{block.timestamp}
</Moment>
</div>
</div>
<div className="BlockHash">
<div className="Label">BLOCK HASH</div>
<div className="Value">{block.hash}</div>
</div>
</div>
</div>
<TxList
loading={false}
transactions={block.transactions}
receipts={block.receipts}
/>
</section>
);
}
}
export default connect(
BlockCard,
"blocks",
"transactions",
);