From 2cc4478553695dfb7b03b127be2b6cbbe9480a39 Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Wed, 27 Jun 2018 13:54:36 -0400 Subject: [PATCH] add get voting option store proposals in indexed order --- app/components/simple-voting/PollsList.js | 2 +- app/dapp.js | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/components/simple-voting/PollsList.js b/app/components/simple-voting/PollsList.js index c2b0958..52f63fd 100644 --- a/app/components/simple-voting/PollsList.js +++ b/app/components/simple-voting/PollsList.js @@ -20,7 +20,7 @@ const Poll = ({ _question, _totalCensus, _voters }) => ( const PollsList = ({ rawPolls }) => ( - {rawPolls.map(poll => )} + {rawPolls.map((poll, idx) => )} ) diff --git a/app/dapp.js b/app/dapp.js index 39e275f..4d9c603 100644 --- a/app/dapp.js +++ b/app/dapp.js @@ -2,6 +2,7 @@ import React, { Fragment } from 'react'; import ReactDOM from 'react-dom'; import EmbarkJS from 'Embark/EmbarkJS'; import PollManager from 'Embark/contracts/PollManager'; +import SingleChoice from 'Embark/contracts/SingleChoice'; import AdminView from './components/AdminView'; import Voting from './components/Voting'; import SNT from 'Embark/contracts/SNT'; @@ -15,7 +16,7 @@ const getPolls = (number, pollMethod) => { const poll = pollMethod(i).call(); polls.push(poll); } - return Promise.all(polls); + return Promise.all(polls.reverse()); } class App extends React.Component { @@ -28,6 +29,7 @@ class App extends React.Component { componentDidMount(){ __embarkContext.execWhenReady(() => { this._getPolls(); + this._setVotingOptions(); }); } @@ -39,9 +41,18 @@ class App extends React.Component { const { nPolls, poll } = PollManager.methods; const polls = await nPolls.call(); const total = await polls.call(); + if (total) this._setVotingOptions(); getPolls(total, poll).then(rawPolls => { this.setState({ rawPolls })}); } + async _setVotingOptions(){ + const poll = await PollManager.methods.poll(0).call(); + SingleChoice.options.address = poll._pollContract; + const yes = await SingleChoice.methods.getBallot(0).call(); + const no = await SingleChoice.methods.getBallot(1).call(); + this.setState({ votingOptions: { yes, no } }) + } + _renderStatus(title, available) { let className = available ? 'pull-right status-online' : 'pull-right status-offline'; return