import React from 'react' import Window from "./Window"; import CID from "cids"; import * as multihash from "multihashes"; import code from "./chain/code"; import Address from "./Address"; class State extends React.Component { byCode = { [code.init]: InitState, [code.power]: PowerState, [code.market]: MarketState, } constructor(props) { super(props) this.state = {Balance: -2, State: {}} } async componentDidMount() { const tipset = this.props.tipset || await this.props.client.call("Filecoin.ChainHead", []) const actstate = await this.props.client.call('Filecoin.StateReadState', [this.props.actor, tipset]) const c = new CID(this.props.actor.Code['/']) const mh = multihash.decode(c.multihash) let code = mh.digest.toString() this.setState({...actstate, code: code}) } render() { let state if(this.byCode[this.state.code]) { const Stelem = this.byCode[this.state.code] state = } else { state =
{Object.keys(this.state.State).map(k =>
{k}: {JSON.stringify(this.state.State[k])}
)}
} const content =
Balance: {this.state.Balance}
---
{state}
return {content} } } class InitState extends React.Component { constructor(props) { super(props) this.state = {actors: []} } async componentDidMount() { const tipset = await this.props.client.call("Filecoin.ChainHead", []) // TODO: from props const actors = await this.props.client.call("Filecoin.StateListActors", [tipset]) this.setState({actors: actors}) } render() { return this.state.actors.sort((a, b) => (Number(a.substr(1)) > Number(b.substr(1)))) .map(addr =>
) } } class PowerState extends React.Component { constructor(props) { super(props) this.state = {actors: []} } async componentDidMount() { const tipset = await this.props.client.call("Filecoin.ChainHead", []) // TODO: from props const actors = await this.props.client.call("Filecoin.StateListMiners", [tipset]) this.setState({actors: actors}) } render() { return this.state.actors.sort((a, b) => (Number(a.substr(1)) > Number(b.substr(1)))) .map(addr =>
) } } class MarketState extends React.Component { constructor(props) { super(props) this.state = {participants: {}, deals: []} } async componentDidMount() { const tipset = await this.props.client.call("Filecoin.ChainHead", []) // TODO: from props const participants = await this.props.client.call("Filecoin.StateMarketParticipants", [tipset]) const deals = await this.props.client.call("Filecoin.StateMarketDeals", [tipset]) this.setState({participants, deals}) } render() { return
Participants:
{Object.keys(this.state.participants).map(p => {p})}
Deals:
{this.state.deals.map(d => {d})}
} } export default State