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 })}; const togglePoll = () => { this.setState({ addPoll: !addPoll })};
return ( return (
<VotingContext.Consumer> <VotingContext.Consumer>
{({ getPolls, rawPolls, toggleAdmin }) => {({ getPolls, rawPolls }) =>
<Fragment> <Fragment>
<CssBaseline /> <CssBaseline />
<AppBar toggleAdmin={toggleAdmin} togglePoll={togglePoll} /> <AppBar togglePoll={togglePoll} />
<div style={{ margin: '30px', textAlign: 'center' }}> <div style={{ margin: '30px', textAlign: 'center' }}>
<img src="images/logo.png" width="200" /> <img src="images/logo.png" width="200" />
</div> </div>

View File

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

View File

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