import React from 'react'; import './App.css'; function colForH(besth, height) { const diff = besth - height if(diff === 0) return '#6f6' if(diff === 1) return '#df4' if(diff < 4) return '#ff0' if(diff < 10) return '#f60' return '#f00' } function colLag(lag) { if(lag < 100) return '#6f6' if(lag < 400) return '#df4' if(lag < 1000) return '#ff0' if(lag < 4000) return '#f60' return '#f00' } function lagCol(lag, good) { return {lag} ms } class App extends React.Component { constructor(props) { super(props); let ws = new WebSocket("ws://" + window.location.host + "/sub") //let ws = new WebSocket("ws://127.0.0.1:2975/sub") ws.onmessage = (ev) => { console.log(ev) let update = JSON.parse(ev.data) let wdiff = update.Update.Weight - (this.state[update.From] || {Weight: update.Update.Weight}).Weight wdiff = {wdiff} this.setState( prev => ({ ...prev, [update.From]: {...update.Update, utime: update.Time, wdiff: wdiff}, })) } ws.onclose = () => { this.setState({disconnected: true}) } this.state = {} } render() { if(this.state.disconnected) { return Error: disconnected } let besth = Object.keys(this.state).map(k => this.state[k]).reduce((p, n) => p > n.Height ? p : n.Height, -1) let bestw = Object.keys(this.state).map(k => this.state[k]).reduce((p, n) => p > n.Weight ? p : n.Weight, -1) return {Object.keys(this.state).map(k => [k, this.state[k]]).map(([k, v]) => { let mnrs = v.Blocks.map(b => ) let l = [ , , , , , ...mnrs, ] l = {l} return l }) }
PeerIDNicknameLagWeight(best, prev)HeightBlocks
 m:{b.Miner}({lagCol(v.Time ? v.Time - (b.Timestamp*1000) : v.utime - (b.Timestamp*1000), v.Time)}){k}{v.NodeName}{v.Time ? lagCol(v.utime - v.Time, true) : ""}{v.Weight}({bestw - v.Weight}, {v.wdiff}){v.Height}({besth - v.Height})
} } export default App;