mirror of
https://github.com/status-im/snt-voting.git
synced 2025-02-23 07:38:07 +00:00
clean up poll retrieval
This commit is contained in:
parent
d83c17ec62
commit
93d02aaa8c
12
app/dapp.js
12
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: [] });
|
||||
}
|
||||
|
||||
|
13
app/utils/polls.js
Normal file
13
app/utils/polls.js
Normal file
@ -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);
|
Loading…
x
Reference in New Issue
Block a user