Loading vote information and balance available for voting

This commit is contained in:
Richard Ramos 2018-06-27 21:18:49 -04:00
parent b7528bbdee
commit c2ba506f5e
2 changed files with 24 additions and 12 deletions

View File

@ -7,13 +7,13 @@ import Typography from '@material-ui/core/Typography';
import Slider from '@material-ui/lab/Slider'; import Slider from '@material-ui/lab/Slider';
import Tooltip from '@material-ui/core/Tooltip'; import Tooltip from '@material-ui/core/Tooltip';
import PollManager from 'Embark/contracts/PollManager'; import PollManager from 'Embark/contracts/PollManager';
import MiniMeTokenInterface from 'Embark/contracts/MiniMeTokenInterface';
class Poll extends Component { class Poll extends Component {
constructor(props){ constructor(props){
super(props); super(props);
this.state = { value: 0, balance: 0, isSubmitting: false, ...props };
this.state = { value: 0, isSubmitting: false, ...props };
} }
handleChange = (event, value) => { handleChange = (event, value) => {
@ -52,6 +52,22 @@ class Poll extends Component {
}); });
} }
componentDidMount() {
MiniMeTokenInterface.options.address = this.props._token;
MiniMeTokenInterface.methods.balanceOfAt(web3.eth.defaultAccount, this.props._startBlock - 1)
.call()
.then(balance => {
this.setState({balance});
});
PollManager.methods.getVote(this.props.idPoll, web3.eth.defaultAccount)
.call()
.then(vote => {
this.setState({value: Math.sqrt(vote)});
})
}
render(){ render(){
const { _description, const { _description,
_totalCensus, _totalCensus,
@ -60,16 +76,12 @@ class Poll extends Component {
_results, _results,
_canVote, _canVote,
value, value,
isSubmitting } = this.state; isSubmitting,
balance,
votes } = this.state;
const disableVote = !_canVote || isSubmitting; const disableVote = !_canVote || isSubmitting;
const maxValue = Math.floor(Math.sqrt(balance));
const tokenBalance = 100; // TODO: read balance from cloned token
const maxValue = Math.floor(Math.sqrt(tokenBalance));
return ( return (
<Card> <Card>

View File

@ -86,7 +86,7 @@ contract PollManager is Controlled {
if(_idPoll >= _polls.length) return false; if(_idPoll >= _polls.length) return false;
Poll storage p = _polls[_idPoll]; Poll storage p = _polls[_idPoll];
uint balance = MiniMeToken(p.token).balanceOf(msg.sender); uint balance = MiniMeToken(p.token).balanceOfAt(msg.sender, p.startBlock - 1);
return block.number >= p.startBlock && return block.number >= p.startBlock &&
block.number <= p.endBlock && block.number <= p.endBlock &&