84 lines
3.9 KiB
JavaScript
Raw Normal View History

2018-10-16 16:20:54 -04:00
import React, { PureComponent } from 'react';
import CssBaseline from '@material-ui/core/CssBaseline';
import 'typeface-roboto';
import AppBar from './standard/AppBar';
2018-06-26 16:34:52 -04:00
import AddPoll from './simple-voting/AddPoll';
2018-06-28 11:03:59 -04:00
import Collapse from '@material-ui/core/Collapse';
import LinearProgress from '@material-ui/core/LinearProgress';
import { VotingContext } from '../context';
2018-10-16 16:20:54 -04:00
import { Route, Switch } from "react-router-dom";
2018-10-22 09:46:11 -04:00
import AdminView from '../components/AdminView';
2018-10-16 16:20:54 -04:00
import TitleScreen from './flow/TitleScreen';
import LearnAboutBallots from './flow/LearnAboutBallots';
import HowVotingWorks from './flow/HowVotingWorks';
import ConnectYourWallet from './flow/ConnectYourWallet';
import OtherWallets from './flow/OtherWallets';
import ExternalWallet from './flow/ExternalWallet';
import VotingCredits from './flow/VotingCredits';
import PollVoting from './flow/PollVoting';
import ReviewVotes from './flow/ReviewVotes';
2018-10-18 10:32:38 -04:00
import Results from './flow/Results';
2018-10-16 16:20:54 -04:00
class Voting extends PureComponent {
2018-10-17 11:02:31 -04:00
state = {
addPoll: false,
pollTokenBalances: [],
2018-10-18 10:32:38 -04:00
votes: [],
2018-10-21 08:23:53 -04:00
transaction: null,
transactionHash: ''
2018-10-17 11:02:31 -04:00
};
updatePollBalance = (pollId, tokenBalance, ethBalance, votes) => {
2018-10-17 11:02:31 -04:00
const {pollTokenBalances} = this.state;
pollTokenBalances[pollId] = { tokenBalance, ethBalance };
this.setState({pollTokenBalances, votes});
2018-10-17 11:02:31 -04:00
}
setVotesToReview = (votes) => {
this.setState({votes});
}
2018-10-21 08:23:53 -04:00
setTransactionHash = (transactionHash) => {
this.setState({transactionHash});
}
2018-10-18 10:32:38 -04:00
setTransactionPromise = (transaction) => {
this.setState({transaction});
}
render(){
2018-10-21 08:23:53 -04:00
const { addPoll, pollTokenBalances, votes, transaction, transactionHash } = this.state;
const togglePoll = () => { this.setState({ addPoll: !addPoll })};
return (
<VotingContext.Consumer>
2018-09-27 15:30:23 -04:00
{({ getPolls, rawPolls, loading, symbol }) =>
2018-06-29 07:22:07 -04:00
<div>
<CssBaseline />
{loading && <LinearProgress />}
2018-10-16 16:20:54 -04:00
<div id="votingDapp">
<Switch>
<Route exact path="/" render={() => <TitleScreen polls={rawPolls} />} />
<Route path="/learn/:id" render={props => <LearnAboutBallots polls={rawPolls} idPoll={props.match.params.id} />} />
<Route path="/votingHelp/:id" render={props => <HowVotingWorks idPoll={props.match.params.id} />} />
<Route path="/wallet/:id" render={props => <ConnectYourWallet polls={rawPolls} idPoll={props.match.params.id} updateBalances={this.updatePollBalance} />} />
<Route path="/otherWallets/:id" render={props => <OtherWallets idPoll={props.match.params.id} />} />
<Route path="/externalWallet/:id" render={props => <ExternalWallet polls={rawPolls} idPoll={props.match.params.id} updateBalances={this.updatePollBalance} />} />
<Route path="/votingCredits/:id" render={props => <VotingCredits polls={rawPolls} idPoll={props.match.params.id} balances={pollTokenBalances} />} />
<Route path="/voting/:id/:back?" render={props => <PollVoting polls={rawPolls} idPoll={props.match.params.id} balances={pollTokenBalances} originalVotes={votes} back={!!props.match.params.back} setVotesToReview={this.setVotesToReview} />} />
2018-10-21 08:23:53 -04:00
<Route path="/review/:id" render={props => <ReviewVotes polls={rawPolls} idPoll={props.match.params.id} votes={votes} balances={pollTokenBalances} setTransactionPromise={this.setTransactionPromise} setTransactionHash={this.setTransactionHash} />} />
<Route path="/results/:id" render={props => <Results polls={rawPolls} idPoll={props.match.params.id} transaction={transaction} transactionHash={transactionHash} />} />
2018-10-22 09:46:11 -04:00
<Route path="/admin" render={() => <AdminView />} />
<Route path="/addPoll" render={() => <AddPoll togglePoll={togglePoll} getPolls={getPolls} />} />
2018-10-16 16:20:54 -04:00
</Switch>
</div>
2018-06-29 07:22:07 -04:00
</div>
}
</VotingContext.Consumer>
)
}
}
2018-10-16 16:20:54 -04:00
export default Voting;