Merge branch '000-snt-voting-dapp' of https://github.com/status-im/contracts into 000-snt-voting-dapp
This commit is contained in:
commit
4a985e76c1
|
@ -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>
|
||||
|
|
|
@ -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,8 +26,10 @@ const styles = {
|
|||
};
|
||||
|
||||
function ButtonAppBar(props) {
|
||||
const { classes, toggleAdmin, togglePoll } = props;
|
||||
const { classes, togglePoll } = props;
|
||||
return (
|
||||
<VotingContext.Consumer>
|
||||
{({ snt, toggleAdmin }) =>
|
||||
<div className={classes.root} >
|
||||
<AppBar position="static">
|
||||
<Toolbar>
|
||||
|
@ -34,10 +39,12 @@ function ButtonAppBar(props) {
|
|||
<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>
|
||||
{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>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
15
app/dapp.js
15
app/dapp.js
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue