2019-07-25 16:13:46 +00:00
|
|
|
import React from 'react';
|
2019-07-25 17:06:10 +00:00
|
|
|
import {BlockLinks} from "./BlockLink";
|
2019-09-19 14:27:01 +00:00
|
|
|
import Window from "./Window";
|
2019-07-25 16:13:46 +00:00
|
|
|
|
|
|
|
function styleForHDiff(max, act) {
|
|
|
|
switch (max - act) {
|
|
|
|
case 0:
|
2019-10-28 18:22:40 +00:00
|
|
|
return {background: '#004400'}
|
2019-07-25 16:13:46 +00:00
|
|
|
case 1:
|
|
|
|
return {background: '#aaaa00'}
|
|
|
|
default:
|
|
|
|
return {background: '#aa0000'}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Consensus extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
maxH: -1,
|
|
|
|
tipsets: []
|
|
|
|
}
|
|
|
|
|
|
|
|
this.updateNodes = this.updateNodes.bind(this)
|
|
|
|
|
|
|
|
setInterval(this.updateNodes, 333)
|
|
|
|
}
|
|
|
|
|
|
|
|
async updateNodes() {
|
|
|
|
const nodes = this.props.nodes
|
2019-08-16 12:38:36 +00:00
|
|
|
let keys = Object.keys(nodes).filter(k => !nodes[k].Storage)
|
2019-07-25 16:13:46 +00:00
|
|
|
|
|
|
|
const tipsets = await keys.map(async k => {
|
|
|
|
const tipset = await nodes[k].conn.call("Filecoin.ChainHead", [])
|
|
|
|
return [k, tipset]
|
|
|
|
}).reduce(async(p, i) => ([...await p, await i]), Promise.resolve([]))
|
|
|
|
|
|
|
|
const maxH = tipsets.reduce((p, [_, i]) => Math.max(p, i.Height), -1)
|
|
|
|
|
|
|
|
this.setState({maxH, tipsets})
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-09-19 14:27:01 +00:00
|
|
|
return (<Window title={`Consensus`}>
|
2019-07-25 16:13:46 +00:00
|
|
|
<div className='Consensus'>
|
|
|
|
<div>Max Height: {this.state.maxH}</div>
|
|
|
|
<div>
|
|
|
|
<table cellSpacing={0}>
|
|
|
|
<thead>
|
|
|
|
<tr><td>Node</td><td>Height</td><td>TipSet</td></tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{this.state.tipsets.map(([k, ts]) => {
|
|
|
|
return (
|
|
|
|
<tr style={styleForHDiff(this.state.maxH, ts.Height)}>
|
2019-07-25 17:06:10 +00:00
|
|
|
<td>{k}</td><td>{ts.Height}</td><td><BlockLinks cids={ts.Cids} conn={this.props.nodes[k].conn} mountWindow={this.props.mountWindow}/></td>
|
2019-07-25 16:13:46 +00:00
|
|
|
</tr>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-09-19 14:27:01 +00:00
|
|
|
</Window>)
|
2019-07-25 16:13:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Consensus
|