Merge branch '000-snt-voting-dapp' of https://github.com/status-im/contracts into 000-snt-voting-dapp

This commit is contained in:
Richard Ramos 2018-06-28 16:26:30 -04:00
commit 4a985e76c1
3 changed files with 35 additions and 19 deletions

View File

@ -16,10 +16,10 @@ class Voting extends PureComponent {
const togglePoll = () => { this.setState({ addPoll: !addPoll })};
return (
<VotingContext.Consumer>
{({ getPolls, rawPolls, toggleAdmin }) =>
{({ getPolls, rawPolls }) =>
<Fragment>
<CssBaseline />
<AppBar toggleAdmin={toggleAdmin} togglePoll={togglePoll} />
<AppBar togglePoll={togglePoll} />
<div style={{ margin: '30px', textAlign: 'center' }}>
<img src="images/logo.png" width="200" />
</div>

View File

@ -7,6 +7,9 @@ import Typography from '@material-ui/core/Typography';
import Button from '@material-ui/core/Button';
import IconButton from '@material-ui/core/IconButton';
import MenuIcon from '@material-ui/icons/Menu';
import { VotingContext } from '../../context';
const hasSnt = snt => Number(snt.balance) > 0;
const styles = {
root: {
@ -23,21 +26,25 @@ const styles = {
};
function ButtonAppBar(props) {
const { classes, toggleAdmin, togglePoll } = props;
const { classes, togglePoll } = props;
return (
<div className={classes.root} >
<AppBar position="static">
<Toolbar>
<IconButton className={classes.menuButton} color="inherit" aria-label="Menu">
<MenuIcon onClick={toggleAdmin} />
</IconButton>
<Typography variant="display1" color="inherit" className={classes.flex}>
What should we build next?
</Typography>
<Button variant="outlined" color="inherit" style={{ fontSize: '16px' }} onClick={togglePoll}>Add Proposal</Button>
</Toolbar>
</AppBar>
</div>
<VotingContext.Consumer>
{({ snt, toggleAdmin }) =>
<div className={classes.root} >
<AppBar position="static">
<Toolbar>
<IconButton className={classes.menuButton} color="inherit" aria-label="Menu">
<MenuIcon onClick={toggleAdmin} />
</IconButton>
<Typography variant="display1" color="inherit" className={classes.flex}>
What should we build next?
</Typography>
{snt && <Button disabled={!hasSnt(snt)} variant="outlined" color="inherit" style={{ fontSize: '16px' }} onClick={togglePoll}>{hasSnt(snt) ? 'Add Proposal' : 'Your account has no SNT'}</Button>}
</Toolbar>
</AppBar>
</div>
}
</VotingContext.Consumer>
);
}

View File

@ -1,5 +1,6 @@
import React, { Fragment } from 'react';
import ReactDOM from 'react-dom';
import web3 from "Embark/web3"
import EmbarkJS from 'Embark/EmbarkJS';
import PollManager from 'Embark/contracts/PollManager';
import AdminView from './components/AdminView';
@ -29,7 +30,7 @@ class App extends React.Component {
componentDidMount(){
__embarkContext.execWhenReady(() => {
this._getPolls();
this._setVotingOptions();
this._setAccounts();
});
}
@ -45,6 +46,14 @@ class App extends React.Component {
else this.setState({ rawPolls: [] });
}
_setAccounts() {
const { fromWei } = web3.utils;
web3.eth.getAccounts(async (err, [address]) => {
const balance = await SNT.methods.balanceOf(address).call();
this.setState({ snt: { balance: fromWei(balance) }});
})
}
updatePoll = async (idPoll) => {
const { poll } = PollManager.methods;
const { rawPolls } = this.state;
@ -63,10 +72,10 @@ class App extends React.Component {
}
render(){
const { admin, rawPolls } = this.state;
const { admin, rawPolls, snt } = this.state;
const { _getPolls, updatePoll } = this;
const toggleAdmin = () => this.setState({ admin: true });
const votingContext = { getPolls: _getPolls, rawPolls, toggleAdmin, updatePoll };
const votingContext = { getPolls: _getPolls, rawPolls, toggleAdmin, updatePoll, snt };
return (
<VotingContext.Provider value={votingContext}>
<Fragment>