import React from 'react' import CID from 'cids' import * as multihash from "multihashes"; import State from "./State"; function truncAddr(addr) { if (addr.length > 21) { return {addr.substr(0, 18) + '..'} } return addr } class Address extends React.Component { constructor(props) { super(props) this.openState = this.openState.bind(this) this.state = {balance: -2} this.refresh = this.refresh.bind(this) } componentDidMount() { this.refresh() if(!this.props.ts) setInterval(this.refresh, 2050) } async refresh() { let balance = 0 let actor = {} try { balance = await this.props.client.call('Filecoin.WalletBalance', [this.props.addr]) actor = await this.props.client.call('Filecoin.ChainGetActor', [this.props.addr, this.props.ts || null]) } catch (err) { balance = -1 } this.setState({balance, actor}) } openState() { this.props.mountWindow((onClose) => ) } render() { let add1k = if(this.props.add1k) { add1k = this.props.add1k(this.props.addr)}>[+1k] } let addr = truncAddr(this.props.addr) let actInfo = (?) if(this.state.balance >= 0) { const c = new CID(this.state.actor.Code['/']) const mh = multihash.decode(c.multihash) // TODO: check identity actInfo = ({mh.digest.toString()}) addr = {addr} } return {addr}: {this.state.balance} {actInfo} {add1k} } } export default Address