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 Tooltip from '@material-ui/core/Tooltip';
import PollManager from 'Embark/contracts/PollManager';
import MiniMeTokenInterface from 'Embark/contracts/MiniMeTokenInterface';
class Poll extends Component {
constructor(props){
super(props);
this.state = { value: 0, isSubmitting: false, ...props };
this.state = { value: 0, balance: 0, isSubmitting: false, ...props };
}
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(){
const { _description,
_totalCensus,
@ -60,16 +76,12 @@ class Poll extends Component {
_results,
_canVote,
value,
isSubmitting } = this.state;
isSubmitting,
balance,
votes } = this.state;
const disableVote = !_canVote || isSubmitting;
const tokenBalance = 100; // TODO: read balance from cloned token
const maxValue = Math.floor(Math.sqrt(tokenBalance));
const maxValue = Math.floor(Math.sqrt(balance));
return (
<Card>

View File

@ -86,8 +86,8 @@ contract PollManager is Controlled {
if(_idPoll >= _polls.length) return false;
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 &&
block.number <= p.endBlock &&
!p.canceled &&