Fix on poll Ids when omitting some idx, and extracting getVote
This commit is contained in:
parent
33aaa4f679
commit
fce74ddcd8
|
@ -54,7 +54,7 @@ class Poll extends PureComponent {
|
||||||
|
|
||||||
constructor(props){
|
constructor(props){
|
||||||
super(props);
|
super(props);
|
||||||
this.state = { value: 0, balance: 0, isSubmitting: false, open: false };
|
this.state = { value: props.votes, originalValue: props.votes, balance: 0, isSubmitting: false, open: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClickOpen = () => {
|
handleClickOpen = () => {
|
||||||
|
@ -101,21 +101,6 @@ class Poll extends PureComponent {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
this.getVote();
|
|
||||||
}
|
|
||||||
|
|
||||||
getVote() {
|
|
||||||
const { fromWei } = web3.utils;
|
|
||||||
const { idPoll } = this.props;
|
|
||||||
PollManager.methods.getVote(idPoll, web3.eth.defaultAccount)
|
|
||||||
.call()
|
|
||||||
.then(vote => {
|
|
||||||
const value = parseInt(Math.sqrt(fromWei(vote)));
|
|
||||||
this.setState({ value, originalValue: value });
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
render(){
|
render(){
|
||||||
const {
|
const {
|
||||||
_description,
|
_description,
|
||||||
|
@ -198,7 +183,6 @@ const PollsList = ({ classes }) => (
|
||||||
{({ updatePoll, rawPolls, pollOrder, appendToPoll, ideaSites }) =>
|
{({ updatePoll, rawPolls, pollOrder, appendToPoll, ideaSites }) =>
|
||||||
<Fragment>
|
<Fragment>
|
||||||
{rawPolls
|
{rawPolls
|
||||||
.map((poll, i) => ({ ...poll, idPoll: i }) )
|
|
||||||
.sort(sortingFn[pollOrder])
|
.sort(sortingFn[pollOrder])
|
||||||
.map((poll) => <Poll key={poll._token} classes={classes} appendToPoll={appendToPoll} updatePoll={updatePoll} ideaSites={ideaSites} {...poll} />)}
|
.map((poll) => <Poll key={poll._token} classes={classes} appendToPoll={appendToPoll} updatePoll={updatePoll} ideaSites={ideaSites} {...poll} />)}
|
||||||
</Fragment>
|
</Fragment>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import web3 from "Embark/web3"
|
import web3 from "Embark/web3"
|
||||||
import MiniMeTokenInterface from 'Embark/contracts/MiniMeTokenInterface';
|
import MiniMeTokenInterface from 'Embark/contracts/MiniMeTokenInterface';
|
||||||
|
import PollManager from 'Embark/contracts/PollManager';
|
||||||
|
|
||||||
const excluded = {
|
const excluded = {
|
||||||
PROPER_LIGHT_CLIENT_SUPPORT : 3,
|
PROPER_LIGHT_CLIENT_SUPPORT : 3,
|
||||||
|
@ -15,12 +16,22 @@ export const getBalance = async (idPoll, token, startBlock) => {
|
||||||
return fromWei(balance);
|
return fromWei(balance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getVote = async(idPoll) => {
|
||||||
|
const { fromWei } = web3.utils;
|
||||||
|
|
||||||
|
const votes = await PollManager.methods.getVote(idPoll, web3.eth.defaultAccount)
|
||||||
|
.call();
|
||||||
|
|
||||||
|
return parseInt(Math.sqrt(fromWei(votes)));
|
||||||
|
}
|
||||||
|
|
||||||
export const getPolls = async (number, pollMethod) => {
|
export const getPolls = async (number, pollMethod) => {
|
||||||
const polls = [];
|
const polls = [];
|
||||||
for (let i = number-1; i >= 0; i--) {
|
for (let i = number-1; i >= 0; i--) {
|
||||||
const poll = await pollMethod(i).call();
|
const poll = await pollMethod(i).call();
|
||||||
const balance = await getBalance(i, poll._token, poll._startBlock);
|
const balance = await getBalance(i, poll._token, poll._startBlock);
|
||||||
polls.push({ ...poll, balance });
|
const votes = await getVote(i);
|
||||||
|
polls.push({ ...poll, idPoll: i, balance, votes });
|
||||||
}
|
}
|
||||||
return polls.reverse();
|
return polls.reverse();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue