mirror of
https://github.com/status-im/snt-voting.git
synced 2025-02-23 23:58:13 +00:00
disable add proposal when no SNT
This commit is contained in:
parent
882dd64128
commit
25229dbd27
@ -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>
|
||||||
|
@ -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,8 +26,10 @@ const styles = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function ButtonAppBar(props) {
|
function ButtonAppBar(props) {
|
||||||
const { classes, toggleAdmin, togglePoll } = props;
|
const { classes, togglePoll } = props;
|
||||||
return (
|
return (
|
||||||
|
<VotingContext.Consumer>
|
||||||
|
{({ snt, toggleAdmin }) =>
|
||||||
<div className={classes.root} >
|
<div className={classes.root} >
|
||||||
<AppBar position="static">
|
<AppBar position="static">
|
||||||
<Toolbar>
|
<Toolbar>
|
||||||
@ -34,10 +39,12 @@ function ButtonAppBar(props) {
|
|||||||
<Typography variant="display1" color="inherit" className={classes.flex}>
|
<Typography variant="display1" color="inherit" className={classes.flex}>
|
||||||
What should we build next?
|
What should we build next?
|
||||||
</Typography>
|
</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>
|
</Toolbar>
|
||||||
</AppBar>
|
</AppBar>
|
||||||
</div>
|
</div>
|
||||||
|
}
|
||||||
|
</VotingContext.Consumer>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
app/dapp.js
15
app/dapp.js
@ -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>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user