import React from 'react'; import Address from "./Address"; import Window from "./Window"; const dealStates = [ "Unknown", "Rejected", "Accepted", "Started", "Failed", "Staged", "Sealing", "Complete", "Error", "Expired" ] class Client extends React.Component { constructor(props) { super(props) this.state = { kbs: 1, blocks: 12, total: 36000, miner: "t0101", deals: [] } } componentDidMount() { this.getDeals() setInterval(this.getDeals, 1325) } getDeals = async () => { let deals = await this.props.client.call('Filecoin.ClientListDeals', []) this.setState({deals}) } update = (name) => (e) => this.setState({ [name]: e.target.value }); makeDeal = async () => { 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(this.state.total / this.state.blocks)}`, 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 ppb = Math.round(this.state.total / this.state.blocks * 100) / 100 let ppmbb = Math.round(ppb / (this.state.kbs / 1000) * 100) / 100 let dealMaker =