From 25229dbd2706b1310a10ab07c6c1175aa4ffb36e Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Thu, 28 Jun 2018 16:24:28 -0400 Subject: [PATCH] disable add proposal when no SNT --- app/components/Voting.js | 4 ++-- app/components/standard/AppBar.js | 35 ++++++++++++++++++------------- app/dapp.js | 15 ++++++++++--- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/app/components/Voting.js b/app/components/Voting.js index a465edc..bbc5e6d 100644 --- a/app/components/Voting.js +++ b/app/components/Voting.js @@ -16,10 +16,10 @@ class Voting extends PureComponent { const togglePoll = () => { this.setState({ addPoll: !addPoll })}; return ( - {({ getPolls, rawPolls, toggleAdmin }) => + {({ getPolls, rawPolls }) => - +
diff --git a/app/components/standard/AppBar.js b/app/components/standard/AppBar.js index 0c9ef45..2f6715a 100644 --- a/app/components/standard/AppBar.js +++ b/app/components/standard/AppBar.js @@ -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 ( -
- - - - - - - What should we build next? - - - - -
+ + {({ snt, toggleAdmin }) => +
+ + + + + + + What should we build next? + + {snt && } + + +
+ } +
); } diff --git a/app/dapp.js b/app/dapp.js index aa3407a..5ac452d 100644 --- a/app/dapp.js +++ b/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 (