snt-voting/app/components/flow/ConnectYourWallet.js

54 lines
2.0 KiB
JavaScript
Raw Normal View History

2018-10-16 16:20:54 -04:00
import {Link} from "react-router-dom";
import Button from '@material-ui/core/Button';
2018-10-17 11:02:31 -04:00
import React, {Component} from 'react';
2018-10-16 16:20:54 -04:00
import Typography from '@material-ui/core/Typography'
2018-10-17 11:02:31 -04:00
import SNT from 'Embark/contracts/SNT';
import { withRouter } from 'react-router-dom'
import PollManager from 'Embark/contracts/PollManager';
2018-10-16 16:20:54 -04:00
2018-10-17 11:02:31 -04:00
class ConnectYourWallet extends Component {
connectWallet = async () => {
// TODO: extract this to utils, this code is repeated here, in other wallets and in How voting works
const {history, polls, updateBalances, idPoll} = this.props;
const poll = polls[idPoll];
const tknVotes = await PollManager.methods.getVote(idPoll, web3.eth.defaultAccount).call();
const votes = tknVotes.map(x => Math.sqrt(parseInt(web3.utils.fromWei(x, "ether"))));
// TODO: add EIP1102 behavior here
2018-10-18 20:01:49 -04:00
if(window.ethereum)
await ethereum.enable();
if(web3.currentProvider.isStatus){
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);
history.push('/votingCredits/' + idPoll);
} else {
window.location.href = "https://get.status.im/browse/" + location.href.replace(/^http(s?):\/\//, '');
}
2018-10-17 11:02:31 -04:00
}
2018-10-16 16:20:54 -04:00
2018-10-17 11:02:31 -04:00
render(){
const {idPoll} = this.props;
2018-10-17 11:02:31 -04:00
return <div className="section center">
<Typography variant="headline">Connect your wallet</Typography>
<Typography variant="body1">To start voting, connect to a wallet where you hold your SNT assets.</Typography>
<div className="action">
<Button color="primary" onClick={this.connectWallet} variant="contained">CONNECT USING STATUS</Button>
</div>
<div className="action">
<Link to={"/otherWallets/" + idPoll}>
2018-10-17 11:02:31 -04:00
<Button color="primary">CONNECT WITH ANOTHER WALLET</Button>
</Link>
</div>
</div>;
}
}
export default withRouter(ConnectYourWallet);