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"; import Fil from "./Fil"; class State extends React.Component { byCode = { [code.init]: InitState, [code.power]: PowerState, [code.market]: MarketState, [code.miner]: MinerState, } 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.addr, tipset.Cids]) 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.Cids]) 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: [], state: {State: {}}} } async componentDidMount() { const tipset = await this.props.client.call("Filecoin.ChainHead", []) // TODO: from props const actors = await this.props.client.call("Filecoin.StateListMiners", [tipset.Cids]) const state = await this.props.client.call('Filecoin.StateReadState', [this.props.addr, tipset.Cids]) this.setState({actors, state}) } render() { return
Total Power: {this.state.state.State.TotalStorage}
---
{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.Cids]) const deals = await this.props.client.call("Filecoin.StateMarketDeals", [tipset.Cids]) const state = await this.props.client.call('Filecoin.StateReadState', [this.props.addr, tipset.Cids]) this.setState({participants, deals, nextDeal: state.State.NextDealID}) } render() { return
Participants:
{Object.keys(this.state.participants).map(p => )}
AddressAvailableLocked
{this.state.participants[p].Available} {this.state.participants[p].Locked}
---
Deals ({this.state.nextDeal} Total):
{Object.keys(this.state.deals).map(d => )}
idStartedClientProviderSizePriceDuration
{d} {this.state.deals[d].State.SectorStartEpoch || "No"}
{this.state.deals[d].Proposal.PieceSize}B {this.state.deals[d].Proposal.StoragePricePerEpoch*(this.state.deals[d].Proposal.EndEpoch-this.state.deals[d].Proposal.StartEpoch)} {this.state.deals[d].Proposal.EndEpoch-this.state.deals[d].Proposal.StartEpoch}
} } class MinerState extends React.Component { constructor(props) { super(props) this.state = {state: {}, sectorSize: -1, worker: "", networkPower: 0, sectors: {}} } async componentDidMount() { const tipset = await this.props.client.call("Filecoin.ChainHead", []) // TODO: from props const state = await this.props.client.call('Filecoin.StateReadState', [this.props.addr, tipset.Cids]) const sectorSize = await this.props.client.call("Filecoin.StateMinerSectorSize", [this.props.addr, tipset.Cids]) const worker = await this.props.client.call("Filecoin.StateMinerWorker", [this.props.addr, tipset.Cids]) const tpow = await this.props.client.call("Filecoin.StateMinerPower", [this.props.addr, tipset.Cids]) const networkPower = tpow.TotalPower let sectors = {} const sset = await this.props.client.call("Filecoin.StateMinerSectors", [this.props.addr, tipset.Cids]) || [] const pset = await this.props.client.call("Filecoin.StateMinerProvingSet", [this.props.addr, tipset.Cids]) || [] sset.forEach(s => sectors[s.SectorID] = {...s, sectorSet: true}) pset.forEach(s => sectors[s.SectorID] = {...(sectors[s.SectorID] || s), provingSet: true}) this.setState({state, sectorSize, worker, networkPower, sectors}) } render() { if (!this.state.worker) { return (...) } let state = this.state.state.State return
Worker:
Sector Size: {this.state.sectorSize/1024} KiB
Power: todoPower ({1/this.state.networkPower*100}%)
Election Period Start: {state.ElectionPeriodStart}
Slashed: {state.SlashedAt === 0 ? "NO" : state.SlashedAt}
----
Sectors:
{Object.keys(this.state.sectors).map(sid => )}
IDCommDCommRSectorSetProving
{sid} {this.state.sectors[sid].CommD} {this.state.sectors[sid].CommR} {this.state.sectors[sid].sectorSet ? 'X' : ' '} {this.state.sectors[sid].provingSet ? 'X' : ' '}
} } export default State