diff --git a/app/dapp.js b/app/dapp.js index 90e8ed0..9ba85a0 100644 --- a/app/dapp.js +++ b/app/dapp.js @@ -9,21 +9,13 @@ import SNT from 'Embark/contracts/SNT'; import { VotingContext } from './context'; import Web3Render from './components/standard/Web3Render'; import fetchIdeas from './utils/fetchIdeas'; +import { getPolls, omitUnvotedDupes } from './utils/polls'; window['SNT'] = SNT; import './dapp.css'; const MAINNET = 1; -const getPolls = (number, pollMethod) => { - const polls = []; - for (let i = number-1; i >= 0; i--) { - const poll = pollMethod(i).call(); - polls.push(poll); - } - return Promise.all(polls.reverse()); -} - class App extends React.Component { constructor(props) { @@ -52,7 +44,7 @@ class App extends React.Component { _getPolls = async () => { const { nPolls, poll } = PollManager.methods; const polls = await nPolls().call(); - if (polls) getPolls(polls, poll).then(rawPolls => { this.setState({ rawPolls })}); + if (polls) getPolls(polls, poll).then(omitUnvotedDupes).then(rawPolls => { this.setState({ rawPolls })}); else this.setState({ rawPolls: [] }); } diff --git a/app/utils/polls.js b/app/utils/polls.js new file mode 100644 index 0000000..a420fbe --- /dev/null +++ b/app/utils/polls.js @@ -0,0 +1,13 @@ + +export const getPolls = (number, pollMethod) => { + const polls = []; + for (let i = number-1; i >= 0; i--) { + const poll = pollMethod(i).call(); + polls.push(poll); + } + return Promise.all(polls.reverse()); +} + +const unVotedDupes = new Set([3]); +const filterDupes = (poll, idx) => !unVotedDupes.has(idx); +export const omitUnvotedDupes = polls => polls.filter(filterDupes);