|
@ -18,11 +18,20 @@ import { POLL_OPTIONS, POLL_QUESTION } from '../../constants/orbit/PollsDatabase |
|
|
import PollDataInvalid from './PollDataInvalid'; |
|
|
import PollDataInvalid from './PollDataInvalid'; |
|
|
import PollGuestView from './PollGuestView'; |
|
|
import PollGuestView from './PollGuestView'; |
|
|
|
|
|
|
|
|
const { contracts: { [VOTING_CONTRACT]: { methods: { getPoll: { cacheCall: getPollChainData } } } } } = drizzle; |
|
|
const { |
|
|
|
|
|
contracts: { |
|
|
|
|
|
[VOTING_CONTRACT]: { |
|
|
|
|
|
methods: { |
|
|
|
|
|
getPoll: |
|
|
|
|
|
{ cacheCall: getPollChainData, clearCacheCall: clearGetPollChainData }, |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
} = drizzle; |
|
|
const { orbit } = breeze; |
|
|
const { orbit } = breeze; |
|
|
|
|
|
|
|
|
const PollView = (props) => { |
|
|
const PollView = (props) => { |
|
|
const { topicId } = props; |
|
|
const { topicId, topicAuthorAddress } = props; |
|
|
const userAddress = useSelector((state) => state.user.address); |
|
|
const userAddress = useSelector((state) => state.user.address); |
|
|
const hasSignedUp = useSelector((state) => state.user.hasSignedUp); |
|
|
const hasSignedUp = useSelector((state) => state.user.hasSignedUp); |
|
|
const getPollResults = useSelector((state) => state.contracts[VOTING_CONTRACT].getPoll); |
|
|
const getPollResults = useSelector((state) => state.contracts[VOTING_CONTRACT].getPoll); |
|
@ -51,24 +60,25 @@ const PollView = (props) => { |
|
|
type: FETCH_USER_DATABASE, |
|
|
type: FETCH_USER_DATABASE, |
|
|
orbit, |
|
|
orbit, |
|
|
dbName: POLLS_DATABASE, |
|
|
dbName: POLLS_DATABASE, |
|
|
userAddress, |
|
|
userAddress: topicAuthorAddress, |
|
|
}); |
|
|
}); |
|
|
}, [dispatch, userAddress]); |
|
|
}, [dispatch, topicAuthorAddress]); |
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
useEffect(() => { |
|
|
if (getPollCallHash && getPollResults && getPollResults[getPollCallHash]) { |
|
|
if (getPollCallHash && getPollResults && getPollResults[getPollCallHash]) { |
|
|
setPollHash(getPollResults[getPollCallHash].value[1]); |
|
|
const pollResults = getPollResults[getPollCallHash]; |
|
|
setPollChangeVoteEnabled(getPollResults[getPollCallHash].value[2]); |
|
|
setPollHash(pollResults.value[1]); |
|
|
setVoteCounts(getPollResults[getPollCallHash].value[4].map((voteCount) => parseInt(voteCount, 10))); |
|
|
setPollChangeVoteEnabled(pollResults.value[2]); |
|
|
|
|
|
setVoteCounts(pollResults.value[4].map((voteCount) => parseInt(voteCount, 10))); |
|
|
|
|
|
|
|
|
const cumulativeSum = getPollResults[getPollCallHash].value[4] |
|
|
const cumulativeSum = pollResults.value[4] |
|
|
.map((voteCount) => parseInt(voteCount, 10)) |
|
|
.map((voteCount) => parseInt(voteCount, 10)) |
|
|
.reduce((accumulator, voteCount) => (accumulator.length === 0 |
|
|
.reduce((accumulator, voteCount) => (accumulator.length === 0 |
|
|
? [voteCount] |
|
|
? [voteCount] |
|
|
: [...accumulator, accumulator[accumulator.length - 1] + voteCount]), []); |
|
|
: [...accumulator, accumulator[accumulator.length - 1] + voteCount]), []); |
|
|
|
|
|
|
|
|
setVoters(cumulativeSum |
|
|
setVoters(cumulativeSum |
|
|
.map((subArrayEnd, index) => getPollResults[getPollCallHash].value[5] |
|
|
.map((subArrayEnd, index) => pollResults.value[5] |
|
|
.slice(index > 0 ? cumulativeSum[index - 1] : 0, |
|
|
.slice(index > 0 ? cumulativeSum[index - 1] : 0, |
|
|
subArrayEnd))); |
|
|
subArrayEnd))); |
|
|
|
|
|
|
|
@ -160,6 +170,10 @@ const PollView = (props) => { |
|
|
]); |
|
|
]); |
|
|
}, [chainDataLoading, orbitDataLoading, pollGraphTab, pollVoteTab, t]); |
|
|
}, [chainDataLoading, orbitDataLoading, pollGraphTab, pollVoteTab, t]); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => () => { |
|
|
|
|
|
clearGetPollChainData(); |
|
|
|
|
|
}, []); |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<Container id="topic-poll-container" textAlign="left"> |
|
|
<Container id="topic-poll-container" textAlign="left"> |
|
|
{pollHashValid |
|
|
{pollHashValid |
|
@ -183,6 +197,7 @@ const PollView = (props) => { |
|
|
|
|
|
|
|
|
PollView.propTypes = { |
|
|
PollView.propTypes = { |
|
|
topicId: PropTypes.number.isRequired, |
|
|
topicId: PropTypes.number.isRequired, |
|
|
|
|
|
topicAuthorAddress: PropTypes.string, |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
export default PollView; |
|
|
export default PollView; |
|
|