import React from 'react'; import {BlockLinks} from "./BlockLink"; import Window from "./Window"; function styleForHDiff(max, act) { switch (max - act) { case 0: return {background: '#004400'} 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 let keys = Object.keys(nodes).filter(k => !nodes[k].Storage) 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() { return (
Max Height: {this.state.maxH}
{this.state.tipsets.map(([k, ts]) => { return ( ) })}
NodeHeightTipSet
{k}{ts.Height}
) } } export default Consensus