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'
|
2018-10-18 08:47:35 -04:00
|
|
|
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 () => {
|
|
|
|
const {history, polls, updateBalances} = this.props;
|
2018-10-17 15:30:11 -04:00
|
|
|
|
2018-10-18 08:47:35 -04:00
|
|
|
|
|
|
|
// TODO:
|
2018-10-18 20:01:49 -04:00
|
|
|
web3.currentProvider.isStatus = true;
|
2018-10-18 08:47:35 -04:00
|
|
|
|
|
|
|
const poll = polls[0];
|
|
|
|
const idPoll = 0;
|
|
|
|
|
|
|
|
const tknVotes = await PollManager.methods.getVote(idPoll, web3.eth.defaultAccount).call();
|
|
|
|
const votes = tknVotes.map(x => Math.sqrt(parseInt(web3.utils.fromWei(x, "ether"))));
|
|
|
|
|
2018-10-18 20:01:49 -04:00
|
|
|
if(window.ethereum)
|
|
|
|
await ethereum.enable();
|
|
|
|
|
2018-10-17 15:30:11 -04:00
|
|
|
if(web3.currentProvider.isStatus){
|
2018-10-18 08:47:35 -04:00
|
|
|
const tokenBalance = await SNT.methods.balanceOfAt(web3.eth.defaultAccount, poll._startBlock).call();
|
2018-10-17 15:30:11 -04:00
|
|
|
const ethBalance = await web3.eth.getBalance(web3.eth.defaultAccount);
|
2018-10-18 08:47:35 -04:00
|
|
|
updateBalances(0, tokenBalance, ethBalance, votes);
|
2018-10-17 15:30:11 -04:00
|
|
|
history.push('/votingCredits');
|
|
|
|
} 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(){
|
|
|
|
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">
|
|
|
|
<Button color="primary">CONNECT WITH ANOTHER WALLET</Button>
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withRouter(ConnectYourWallet);
|