import React from 'react'; import './App.css'; import {Client} from "rpc-websockets"; import FullNode from "./FullNode"; class SingleNode extends React.Component { constructor(props) { super(props) const nodes = JSON.parse(window.localStorage.getItem('saved-nodes')) const node = nodes[this.props.match.params.node] const client = new Client(`${node.addr}?token=${node.token}`) client.on('open', async () => { this.setState(() => ({client: client})) }) this.state = { windows: {}, nextWindow: 0, addr: node.addr } } mountWindow = (cb) => { const id = this.state.nextWindow this.setState({nextWindow: id + 1}) const window = cb(() => { this.setState(prev => ({windows: {...prev.windows, [id]: undefined}})) }) this.setState(prev => ({windows: {...prev.windows, [id]: window}})) } render() { if (this.state.client === undefined) { return (
Connecting to Node RPC:
{`${this.state.addr}?token=****`}
) } let node = return (
{node}
{Object.keys(this.state.windows).map((w, i) =>
{this.state.windows[w]}
)}
) } } export default SingleNode;