2019-10-10 11:07:00 +00:00
|
|
|
import React from 'react';
|
|
|
|
import './App.css';
|
|
|
|
|
2019-11-09 17:51:04 +00:00
|
|
|
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'
|
|
|
|
}
|
|
|
|
|
2019-10-10 11:07:00 +00:00
|
|
|
class App extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
2019-10-11 06:11:57 +00:00
|
|
|
let ws = new WebSocket("ws://" + window.location.host + "/sub")
|
|
|
|
//let ws = new WebSocket("ws://127.0.0.1:2975/sub")
|
2019-10-10 11:07:00 +00:00
|
|
|
|
|
|
|
ws.onmessage = (ev) => {
|
|
|
|
console.log(ev)
|
|
|
|
let update = JSON.parse(ev.data)
|
|
|
|
|
|
|
|
this.setState( prev => ({
|
|
|
|
...prev, [update.From]: update.Update,
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
|
|
|
this.state = {}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-11-09 17:51:04 +00:00
|
|
|
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)
|
2019-10-10 11:07:00 +00:00
|
|
|
|
2019-10-11 02:45:45 +00:00
|
|
|
return <table>{Object.keys(this.state).map(k => [k, this.state[k]]).map(([k, v]) => {
|
2019-10-12 14:05:41 +00:00
|
|
|
|
|
|
|
let mnrs = v.Blocks.map(b => <span> m:{b.Miner}</span>)
|
2019-11-09 17:51:04 +00:00
|
|
|
let l = [<td>{k}</td>,
|
|
|
|
<td>{v.NodeName}</td>,
|
|
|
|
<td style={{color: bestw !== v.Weight ? '#f00' : '#afa'}}>{v.Weight}({bestw - v.Weight})</td>,
|
|
|
|
<td style={{color: colForH(besth, v.Height)}}>{v.Height}({besth - v.Height})</td>,
|
|
|
|
<td>{mnrs}</td>]
|
2019-10-11 02:45:45 +00:00
|
|
|
l = <tr>{l}</tr>
|
2019-10-10 11:07:00 +00:00
|
|
|
|
2019-10-11 02:45:45 +00:00
|
|
|
return l
|
2019-10-10 11:07:00 +00:00
|
|
|
})
|
2019-10-11 02:45:45 +00:00
|
|
|
}</table>
|
2019-10-10 11:07:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
export default App;
|