From 840295bb270d934a67792ca33d59e1624975cbf6 Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Wed, 27 Jun 2018 10:27:16 -0400 Subject: [PATCH] add rawPolls to top level state --- app/dapp.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/app/dapp.js b/app/dapp.js index 777b0e4..22c00ab 100644 --- a/app/dapp.js +++ b/app/dapp.js @@ -1,7 +1,7 @@ import React, { Fragment } from 'react'; import ReactDOM from 'react-dom'; - import EmbarkJS from 'Embark/EmbarkJS'; +import PollManager from 'Embark/contracts/PollManager'; import AdminView from './components/AdminView'; import Voting from './components/Voting'; import SNT from 'Embark/contracts/SNT'; @@ -9,6 +9,15 @@ window['SNT'] = SNT; import './dapp.css'; +const getPolls = (number, pollMethod) => { + const polls = []; + for (let i = number-1; i >= 0; i--) { + const poll = pollMethod(i).call(); + polls.push(poll); + } + return Promise.all(polls); +} + class App extends React.Component { constructor(props) { @@ -18,6 +27,7 @@ class App extends React.Component { componentDidMount(){ __embarkContext.execWhenReady(() => { + this._getPolls(); }); } @@ -25,6 +35,13 @@ class App extends React.Component { this.setState({account: _account}); } + async _getPolls(){ + const { nPolls, poll } = PollManager.methods; + const polls = await nPolls.call(); + const total = await polls.call(); + getPolls(total, poll).then(rawPolls => { this.setState({ rawPolls })}); + } + _renderStatus(title, available) { let className = available ? 'pull-right status-online' : 'pull-right status-offline'; return