2019-07-24 17:10:44 +00:00
|
|
|
import React from 'react';
|
|
|
|
import './App.css';
|
2019-09-18 17:53:48 +00:00
|
|
|
import { BrowserRouter as Router, Route, Link } from "react-router-dom";
|
|
|
|
import Pond from "./Pond";
|
|
|
|
import SingleNode from "./SingleNode";
|
2019-07-24 17:10:44 +00:00
|
|
|
|
2019-09-18 17:53:48 +00:00
|
|
|
class Index extends React.Component {
|
2019-07-24 17:10:44 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
|
2019-09-18 17:53:48 +00:00
|
|
|
this.state = {rpcUrl: "ws://127.0.0.1:1234/rpc/v0", rpcToken: ''}
|
2019-07-24 17:10:44 +00:00
|
|
|
|
2019-09-18 17:53:48 +00:00
|
|
|
const initialState = JSON.parse(window.localStorage.getItem('saved-nodes'))
|
|
|
|
if (initialState) {
|
|
|
|
this.state.nodes = initialState
|
|
|
|
} else {
|
|
|
|
this.state.nodes = []
|
2019-07-30 23:21:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-18 17:53:48 +00:00
|
|
|
componentDidUpdate(prevProps, prevState, snapshot) {
|
|
|
|
window.localStorage.setItem('saved-nodes', JSON.stringify(this.state.nodes))
|
|
|
|
}
|
2019-07-30 23:21:57 +00:00
|
|
|
|
2019-09-18 17:53:48 +00:00
|
|
|
onAdd = () => {
|
|
|
|
this.setState({addingNode: true})
|
2019-07-24 17:10:44 +00:00
|
|
|
}
|
|
|
|
|
2019-09-18 17:53:48 +00:00
|
|
|
update = (name) => (e) => this.setState({ [name]: e.target.value })
|
|
|
|
|
|
|
|
tokenOk = () => {
|
|
|
|
let m = this.state.rpcToken.match(/\.(.+)\./)
|
|
|
|
// TODO: eww
|
|
|
|
if(m && atob(m[1]) === '{"Allow":["read","write","sign","admin"]}') {
|
2019-07-24 17:10:44 +00:00
|
|
|
return (
|
2019-09-18 17:53:48 +00:00
|
|
|
<span>-Token OK-
|
2019-07-24 17:10:44 +00:00
|
|
|
<div>
|
2019-09-18 17:53:48 +00:00
|
|
|
<button onClick={this.addNode}>Add Node</button>
|
2019-07-24 17:10:44 +00:00
|
|
|
</div>
|
2019-09-18 17:53:48 +00:00
|
|
|
</span>
|
2019-07-24 17:10:44 +00:00
|
|
|
)
|
|
|
|
}
|
2019-09-18 17:53:48 +00:00
|
|
|
return <span>-Expecting valid admin token-</span>
|
|
|
|
}
|
|
|
|
|
|
|
|
addNode = async () => {
|
|
|
|
this.setState(p => ({nodes: [...p.nodes, {addr: this.state.rpcUrl, token: this.state.rpcToken}], addingNode: true}))
|
|
|
|
}
|
2019-07-24 17:10:44 +00:00
|
|
|
|
2019-09-18 17:53:48 +00:00
|
|
|
render() {
|
2019-07-24 17:10:44 +00:00
|
|
|
return (
|
2019-09-19 00:50:23 +00:00
|
|
|
<div className="Index">
|
|
|
|
<div className="Index-nodes">
|
2019-07-30 23:21:57 +00:00
|
|
|
<div>
|
2019-09-19 00:50:23 +00:00
|
|
|
{
|
|
|
|
this.state.nodes.map((node, i) => <div className="Index-node">
|
|
|
|
<span>{i}. {node.addr} <Link to={`/app/node/${i}`}>[OPEN UI]</Link></span>
|
|
|
|
</div>)
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
<a hidden={this.state.addingNode} href='#' onClick={this.onAdd} className="Button">[Add Node]</a>
|
|
|
|
<div hidden={!this.state.addingNode}>
|
|
|
|
<div>---------------</div>
|
|
|
|
<div>
|
|
|
|
+ RPC:<input defaultValue={"ws://127.0.0.1:1234/rpc/v0"} onChange={this.update("rpcUrl")}/>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
Token (<code>lotus auth create-admin-token</code>): <input onChange={this.update("rpcToken")}/>{this.tokenOk()}
|
|
|
|
</div>
|
2019-09-18 17:53:48 +00:00
|
|
|
</div>
|
2019-09-19 00:50:23 +00:00
|
|
|
</div>
|
|
|
|
<div className="Index-footer">
|
2019-09-18 17:53:48 +00:00
|
|
|
<div>
|
2019-09-19 00:50:23 +00:00
|
|
|
<Link to={"/app/pond"}>Open Pond</Link>
|
2019-07-30 23:21:57 +00:00
|
|
|
</div>
|
2019-07-24 17:10:44 +00:00
|
|
|
</div>
|
2019-09-18 17:53:48 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class App extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Router>
|
|
|
|
<Route path="/" exact component={Index} />
|
|
|
|
<Route path="/app/pond/" component={Pond} />
|
|
|
|
<Route path="/app/node/:node" component={SingleNode} />
|
|
|
|
</Router>
|
2019-07-24 17:10:44 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default App
|