2018-07-17 16:02:32 -04:00
|
|
|
import web3 from "Embark/web3"
|
|
|
|
import MiniMeTokenInterface from 'Embark/contracts/MiniMeTokenInterface';
|
2018-07-17 17:21:24 -04:00
|
|
|
import PollManager from 'Embark/contracts/PollManager';
|
2018-12-05 10:24:45 -04:00
|
|
|
import DappToken from 'Embark/contracts/DappToken';
|
2018-07-17 16:02:32 -04:00
|
|
|
|
2018-07-16 09:20:42 -04:00
|
|
|
const excluded = {
|
2018-09-25 20:45:33 -04:00
|
|
|
// PROPER_LIGHT_CLIENT_SUPPORT : 3,
|
2018-07-16 09:20:42 -04:00
|
|
|
};
|
2018-07-13 10:15:27 -04:00
|
|
|
|
2018-09-25 15:24:34 -04:00
|
|
|
export const getBalance = async (startBlock) => {
|
2018-07-17 16:02:32 -04:00
|
|
|
const { fromWei } = web3.utils;
|
2018-12-05 10:24:45 -04:00
|
|
|
const { balanceOfAt } = DappToken.methods;
|
2018-07-17 16:02:32 -04:00
|
|
|
const balance = await balanceOfAt(web3.eth.defaultAccount, startBlock - 1).call();
|
|
|
|
return fromWei(balance);
|
|
|
|
}
|
2018-07-17 17:21:24 -04:00
|
|
|
export const getVote = async(idPoll) => {
|
|
|
|
const { fromWei } = web3.utils;
|
2018-07-18 06:29:59 -04:00
|
|
|
const votes = await PollManager.methods.getVote(idPoll, web3.eth.defaultAccount).call();
|
2018-09-26 10:34:02 -04:00
|
|
|
return votes.map(el => Math.floor(Math.sqrt(parseInt(fromWei(el)))));
|
2018-07-17 17:21:24 -04:00
|
|
|
}
|
|
|
|
|
2018-07-18 06:29:59 -04:00
|
|
|
const fetchPollData = async (index, pollMethod) => {
|
2018-10-30 16:53:53 -04:00
|
|
|
const poll = await pollMethod(index).call({from: web3.eth.defaultAccount});
|
2018-10-27 05:55:22 -04:00
|
|
|
const blockInfo = await web3.eth.getBlock(poll._startBlock);
|
2018-10-27 13:12:35 -04:00
|
|
|
return { ...poll, idPoll: index, blockInfo };
|
2018-07-18 06:29:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export const getPolls = (number, pollMethod) => {
|
2018-10-27 05:55:22 -04:00
|
|
|
const polls = [];
|
2018-11-06 13:49:25 -04:00
|
|
|
for (let i = number-1; i >= 0; i--) {
|
|
|
|
polls.push(fetchPollData(i, pollMethod));
|
|
|
|
}
|
2018-07-18 06:29:59 -04:00
|
|
|
return Promise.all(polls.reverse());
|
2018-07-13 10:15:27 -04:00
|
|
|
}
|
|
|
|
|
2018-07-16 09:20:42 -04:00
|
|
|
const excludedPolls = new Set(Object.values(excluded));
|
|
|
|
const exclusionFilter = (poll, idx) => !excludedPolls.has(idx);
|
|
|
|
export const omitPolls = polls => polls.filter(exclusionFilter);
|