2018-10-16 16:20:54 -04:00
|
|
|
import Button from '@material-ui/core/Button';
|
2018-10-24 14:31:10 -04:00
|
|
|
import React, {Component, Fragment} from 'react';
|
2018-10-16 16:20:54 -04:00
|
|
|
import Card from '@material-ui/core/Card';
|
|
|
|
import CardContent from '@material-ui/core/CardContent';
|
|
|
|
import Typography from '@material-ui/core/Typography';
|
2018-10-24 14:31:10 -04:00
|
|
|
import { withRouter } from 'react-router-dom';
|
|
|
|
import SNT from 'Embark/contracts/SNT';
|
|
|
|
import PollManager from 'Embark/contracts/PollManager';
|
2018-10-16 16:20:54 -04:00
|
|
|
|
2018-10-30 16:22:49 -04:00
|
|
|
|
2018-10-24 14:31:10 -04:00
|
|
|
class HowVotingWorks extends Component {
|
|
|
|
|
|
|
|
checkWeb3 = async () => {
|
|
|
|
if(!window.web3){
|
|
|
|
this.props.history.push("/wallet/" + this.props.idPoll);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const {history, polls, updateBalances, idPoll} = this.props;
|
|
|
|
if(!polls || !polls.length) return;
|
|
|
|
|
2018-10-30 16:22:49 -04:00
|
|
|
let cont = true;
|
|
|
|
if (window.ethereum) {
|
|
|
|
try {
|
|
|
|
await ethereum.enable();
|
|
|
|
web3.setProvider(ethereum);
|
|
|
|
const accounts = await web3.eth.getAccounts();
|
|
|
|
web3.eth.defaultAccount = accounts[0];
|
|
|
|
} catch (error) {
|
|
|
|
cont = false;
|
|
|
|
}
|
|
|
|
}
|
2018-10-24 14:31:10 -04:00
|
|
|
|
2018-10-30 16:22:49 -04:00
|
|
|
if(cont){
|
|
|
|
// TODO: extract this code to utils. It's repeated in ConnectYourWallt, ExternalWallet and HowVotingWorks
|
|
|
|
const poll = polls[polls.length - 1];
|
|
|
|
const tknVotes = await PollManager.methods.getVote(idPoll, web3.eth.defaultAccount).call();
|
|
|
|
const votes = tknVotes.map(x => Math.sqrt(parseInt(web3.utils.fromWei(x, "ether"))));
|
|
|
|
const tokenBalance = await SNT.methods.balanceOfAt(web3.eth.defaultAccount, poll._startBlock).call();
|
|
|
|
const ethBalance = await web3.eth.getBalance(web3.eth.defaultAccount);
|
|
|
|
updateBalances(idPoll, tokenBalance, ethBalance, votes);
|
2018-10-24 14:31:10 -04:00
|
|
|
|
2018-10-30 16:22:49 -04:00
|
|
|
history.push('/votingCredits/' + idPoll);
|
|
|
|
}
|
2018-10-24 14:31:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const props = this.props;
|
|
|
|
return <Fragment><div className="section">
|
2018-10-16 16:20:54 -04:00
|
|
|
<Typography variant="headline">How voting works</Typography>
|
2018-10-16 18:52:40 -04:00
|
|
|
<Card className="card">
|
2018-10-16 16:20:54 -04:00
|
|
|
<CardContent>
|
2018-10-18 20:01:49 -04:00
|
|
|
<div className="left">
|
|
|
|
<span><img src="images/wallet.svg" width="23" /></span>
|
|
|
|
</div>
|
2018-10-27 05:03:11 -04:00
|
|
|
<div className="right">
|
2018-10-18 20:01:49 -04:00
|
|
|
<Typography gutterBottom component="h2">
|
|
|
|
Any wallet with SNT can vote
|
|
|
|
</Typography>
|
|
|
|
<Typography component="p">
|
|
|
|
When a poll is created a snapshot is taken of every wallet that holds Status Network Tokens (SNT).
|
|
|
|
</Typography>
|
|
|
|
</div>
|
2018-10-16 16:20:54 -04:00
|
|
|
</CardContent>
|
|
|
|
</Card>
|
2018-10-16 18:52:40 -04:00
|
|
|
<Card className="card">
|
2018-10-16 16:20:54 -04:00
|
|
|
<CardContent>
|
2018-10-18 20:01:49 -04:00
|
|
|
<div className="left">
|
|
|
|
<span><img src="images/happy-face.svg" width="23" /></span>
|
|
|
|
</div>
|
2018-10-27 05:03:11 -04:00
|
|
|
<div className="right">
|
2018-10-18 20:01:49 -04:00
|
|
|
<Typography gutterBottom component="h2">
|
|
|
|
You don't spend your SNT!
|
|
|
|
</Typography>
|
|
|
|
<Typography component="p">
|
|
|
|
Your wallet gets one voting credit for every SNT it holds. To cast your vote, you sign a transaction, but you only spend a small amount of ETH for the transaction fee.
|
|
|
|
</Typography>
|
|
|
|
</div>
|
2018-10-16 16:20:54 -04:00
|
|
|
</CardContent>
|
|
|
|
</Card>
|
2018-10-16 18:52:40 -04:00
|
|
|
<Card className="card">
|
2018-10-16 16:20:54 -04:00
|
|
|
<CardContent>
|
2018-10-18 20:01:49 -04:00
|
|
|
<div className="left">
|
|
|
|
<span><img src="images/envelope.svg" width="23" /></span>
|
|
|
|
</div>
|
2018-10-27 05:03:11 -04:00
|
|
|
<div className="right">
|
2018-10-18 20:01:49 -04:00
|
|
|
<Typography gutterBottom component="h2">
|
|
|
|
Your vote counts
|
|
|
|
</Typography>
|
|
|
|
<Typography component="p">
|
|
|
|
Most votes when poll ends wins! Multiple votes cost more to prevent whales from controlling the vote
|
|
|
|
</Typography>
|
|
|
|
</div>
|
2018-10-16 16:20:54 -04:00
|
|
|
</CardContent>
|
|
|
|
</Card>
|
2018-10-18 16:10:48 -04:00
|
|
|
</div>
|
|
|
|
<div className="buttonNav">
|
2018-10-29 02:51:25 -04:00
|
|
|
<Button onClick={this.checkWeb3}>Next</Button>
|
2018-10-18 16:10:48 -04:00
|
|
|
</div>
|
2018-10-24 14:31:10 -04:00
|
|
|
|
2018-10-18 16:10:48 -04:00
|
|
|
</Fragment>;
|
2018-10-24 14:31:10 -04:00
|
|
|
}
|
|
|
|
}
|
2018-10-16 16:20:54 -04:00
|
|
|
|
2018-10-24 14:31:10 -04:00
|
|
|
export default withRouter(HowVotingWorks);
|