import React from 'react'; import Address from "./Address"; import Window from "./Window"; import Fil from "./Fil"; const dealStates = [ "Unknown", "Rejected", "Accepted", "Staged", "Sealing", "Failed", "Complete", "Error", ] class Client extends React.Component { constructor(props) { super(props) this.state = { miners: ["t0101"], ask: {Price: "500000000"}, kbs: 1, blocks: 12, total: 36000, miner: "t0101", deals: [], blockDelay: 10, } } async componentDidMount() { let ver = await this.props.client.call('Filecoin.Version', []) this.setState({blockDelay: ver.BlockDelay}) this.getDeals() setInterval(this.getDeals, 1325) } getDeals = async () => { let miners = await this.props.client.call('Filecoin.StateListMiners', [null]) let deals = await this.props.client.call('Filecoin.ClientListDeals', []) miners.sort() this.setState({deals, miners}) } update = (name) => (e) => this.setState({ [name]: e.target.value }); makeDeal = async () => { let perBlk = this.state.ask.Price * this.state.kbs * 1000 / (1 << 30) let file = await this.props.pondClient.call('Pond.CreateRandomFile', [this.state.kbs * 1000]) // 1024 won't fit in 1k blocks :( let cid = await this.props.client.call('Filecoin.ClientImport', [file]) let dealcid = await this.props.client.call('Filecoin.ClientStartDeal', [cid, this.state.miner, `${Math.round(perBlk)}`, Number(this.state.blocks)]) console.log("deal cid: ", dealcid) } retrieve = (deal) => async () => { console.log(deal) let client = await this.props.client.call('Filecoin.WalletDefaultAddress', []) let order = { Root: deal.PieceRef, Size: deal.Size, // TODO: support offset Total: String(deal.Size * 2), Client: client, Miner: deal.Miner } await this.props.client.call('Filecoin.ClientRetrieve', [order, '/dev/null']) } render() { let perBlk = this.state.ask.Price * this.state.kbs * 1000 let total = perBlk * this.state.blocks let days = (this.state.blocks * this.state.blockDelay) / 60 / 60 / 24 let dealMaker =