import web3 from "Embark/web3" import EmbarkJS from 'Embark/EmbarkJS'; import React, {Component, Fragment} from 'react'; import { Button } from 'react-bootstrap'; import ProposalManager from 'Embark/contracts/ProposalManager'; import ProposalCuration from 'Embark/contracts/ProposalCuration'; class Voting extends Component { constructor(props) { super(props); this.state = { decision: 0, proposal: null, finalResult: null }; } componentDidMount(){ __embarkContext.execWhenReady(async () => { ProposalManager.options.address = await ProposalCuration.methods.proposalManager().call(); let _proposal = await ProposalManager.methods.getProposal(this.props.proposalId).call(); let blockNum = await web3.eth.getBlockNumber(); let _data = await ProposalManager.methods.getProposalData(this.props.proposalId).call(); this.setState({ proposal: _proposal, data: _data, decision: _proposal.vote, block: blockNum, finalResult: _data.result }); }); } async determineFinalResult(e){ e.preventDefault(); let receipt = await ProposalManager.methods.finalResult(this.props.proposalId) .send({from: web3.eth.defaultAccount}); if(receipt.status == '0x1'){ this.setState({ decision: choice, block: blockNum, finalResult: receipt.events.ProposalResult.finalResult }); } console.log(receipt); } async handleClick(e, vote){ e.preventDefault(); let choice = 0; if(vote == 'APPROVE') choice = 2; else choice = 1; let proposal = this.props.proposalId; let receipt = await ProposalManager.methods.voteProposal(this.props.proposalId, choice) .send({from: web3.eth.defaultAccount}); let blockNum = await web3.eth.getBlockNumber(); if(receipt.status == '0x1'){ this.setState({ decision: choice, block: blockNum }); } console.log(receipt); // TODO: handle error } render(){ console.log(this.state); return
You voted for: