Transaction info by poll

This commit is contained in:
Richard Ramos 2018-12-03 10:05:44 -04:00
parent 2302945203
commit be5f68da30
4 changed files with 25 additions and 20 deletions

View File

@ -26,8 +26,8 @@ class Voting extends PureComponent {
addPoll: false, addPoll: false,
pollTokenBalances: [], pollTokenBalances: [],
votes: [], votes: [],
transaction: null, transaction: {},
transactionHash: '' transactionHash: {}
}; };
updatePollBalance = (pollId, tokenBalance, ethBalance, votes) => { updatePollBalance = (pollId, tokenBalance, ethBalance, votes) => {
@ -40,12 +40,17 @@ class Voting extends PureComponent {
this.setState({votes}); this.setState({votes});
} }
setTransactionHash = (transactionHash) => { setTransactionHash = (idPoll, transactionHash) => {
this.setState({transactionHash}); const stHash = this.state.transactionHash;
stHash[idPoll] = transactionHash;
this.setState({transactionHash: stHash[idPoll]});
} }
setTransactionPromise = (transaction) => { setTransactionPromise = (idPoll, transaction) => {
this.setState({transaction}); const sTrx = this.state.transaction;
sTrx[idPoll] = transaction;
this.setState({transaction: sTrx});
} }

View File

@ -129,13 +129,13 @@ class LandingPage extends Component {
<h2 className="pollTypeTitle">Closed Polls</h2> <h2 className="pollTypeTitle">Closed Polls</h2>
<Card className="card poll"> <Card className="card poll">
<CardContent> <CardContent>
<Typography gutterBottom component="h2">{openPoll.content.title}</Typography> <Typography gutterBottom component="h2">{closedPoll.content.title}</Typography>
<p className="stats"> <p className="stats">
Voters: {openPoll._voters}<br /> Voters: {closedPoll._voters}<br />
Total votes: {openPoll._votesSum}<br /> Total votes: {closedPoll._votesSum}<br />
Total SNT: {openPoll._tokenSum}<br /> Total SNT: {closedPoll._tokenSum}<br />
</p> </p>
<Link to={"/results/" + openPoll.idPoll} className="arrowRightLink">See results</Link> <Link to={"/results/" + closedPoll.idPoll} className="arrowRightLink">See results</Link>
</CardContent> </CardContent>
</Card> </Card>
<div style={{textAlign: "center", marginTop: "35px"}}> <div style={{textAlign: "center", marginTop: "35px"}}>

View File

@ -53,8 +53,8 @@ class Results extends Component {
this.setState({netId}); this.setState({netId});
}); });
if(transaction){ if(transaction[idPoll]){
transaction.catch(x => { transaction[idPoll].catch(x => {
this.setState({isError: true}); this.setState({isError: true});
}).then(() => { }).then(() => {
this.updatePoll(); this.updatePoll();
@ -62,10 +62,10 @@ class Results extends Component {
let req = false; let req = false;
let interval = setInterval(async () => { let interval = setInterval(async () => {
if(req || !transactionHash) return; if(req || !transactionHash[idPoll]) return;
req = true; req = true;
const receipt = await web3.eth.getTransactionReceipt(transactionHash); const receipt = await web3.eth.getTransactionReceipt(transactionHash[idPoll]);
if(receipt){ if(receipt){
clearInterval(interval); clearInterval(interval);
@ -110,7 +110,7 @@ class Results extends Component {
</Link> </Link>
</div> } </div> }
{ !isError && transaction && <div className="transactionArea"> { !isError && transaction[idPoll] && <div className="transactionArea">
{ isPending && <div className="pending"> { isPending && <div className="pending">
<div className="spinner"> <div className="spinner">
<div className="bounce1"></div> <div className="bounce1"></div>
@ -121,12 +121,12 @@ class Results extends Component {
<Typography variant="body1">Your vote is in the process of being confirmed in the blockchain</Typography> <Typography variant="body1">Your vote is in the process of being confirmed in the blockchain</Typography>
</div> </div>
} }
{ !isPending && transaction && <div className="confirmed"> { !isPending && transaction[idPoll] && <div className="confirmed">
<img src="images/confirmed.svg" width="40" /> <img src="images/confirmed.svg" width="40" />
<Typography variant="headline">Transaction confirmed!<br /> <Typography variant="headline">Transaction confirmed!<br />
Your vote was posted.</Typography> Your vote was posted.</Typography>
</div>} </div>}
{ transactionHash && etherscanURL && <Typography variant="body1"><a target="_blank" href={ etherscanURL + transactionHash}>View details on Etherscan</a></Typography> } { transactionHash[idPoll] && etherscanURL && <Typography variant="body1"><a target="_blank" href={ etherscanURL + transactionHash[idPoll]}>View details on Etherscan</a></Typography> }
</div> </div>
} }
<div className="section"> <div className="section">

View File

@ -45,8 +45,8 @@ class ReviewVotes extends Component {
const transaction = toSend.send({gas: gasEstimated + 100000}); const transaction = toSend.send({gas: gasEstimated + 100000});
transaction.on('transactionHash', hash => { transaction.on('transactionHash', hash => {
this.props.setTransactionHash(hash); this.props.setTransactionHash(idPoll, hash);
this.props.setTransactionPromise(transaction); this.props.setTransactionPromise(idPoll, transaction);
history.push('/results/' + idPoll); history.push('/results/' + idPoll);
}); });