diff --git a/packages/concordia-app/src/components/PollView/index.jsx b/packages/concordia-app/src/components/PollView/index.jsx index 4f9c3c8..801b7a2 100644 --- a/packages/concordia-app/src/components/PollView/index.jsx +++ b/packages/concordia-app/src/components/PollView/index.jsx @@ -18,11 +18,20 @@ import { POLL_OPTIONS, POLL_QUESTION } from '../../constants/orbit/PollsDatabase import PollDataInvalid from './PollDataInvalid'; 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 PollView = (props) => { - const { topicId } = props; + const { topicId, topicAuthorAddress } = props; const userAddress = useSelector((state) => state.user.address); const hasSignedUp = useSelector((state) => state.user.hasSignedUp); const getPollResults = useSelector((state) => state.contracts[VOTING_CONTRACT].getPoll); @@ -51,24 +60,25 @@ const PollView = (props) => { type: FETCH_USER_DATABASE, orbit, dbName: POLLS_DATABASE, - userAddress, + userAddress: topicAuthorAddress, }); - }, [dispatch, userAddress]); + }, [dispatch, topicAuthorAddress]); useEffect(() => { if (getPollCallHash && getPollResults && getPollResults[getPollCallHash]) { - setPollHash(getPollResults[getPollCallHash].value[1]); - setPollChangeVoteEnabled(getPollResults[getPollCallHash].value[2]); - setVoteCounts(getPollResults[getPollCallHash].value[4].map((voteCount) => parseInt(voteCount, 10))); + const pollResults = getPollResults[getPollCallHash]; + setPollHash(pollResults.value[1]); + 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)) .reduce((accumulator, voteCount) => (accumulator.length === 0 ? [voteCount] : [...accumulator, accumulator[accumulator.length - 1] + voteCount]), []); setVoters(cumulativeSum - .map((subArrayEnd, index) => getPollResults[getPollCallHash].value[5] + .map((subArrayEnd, index) => pollResults.value[5] .slice(index > 0 ? cumulativeSum[index - 1] : 0, subArrayEnd))); @@ -160,6 +170,10 @@ const PollView = (props) => { ]); }, [chainDataLoading, orbitDataLoading, pollGraphTab, pollVoteTab, t]); + useEffect(() => () => { + clearGetPollChainData(); + }, []); + return ( {pollHashValid @@ -183,6 +197,7 @@ const PollView = (props) => { PollView.propTypes = { topicId: PropTypes.number.isRequired, + topicAuthorAddress: PropTypes.string, }; export default PollView; diff --git a/packages/concordia-app/src/views/Topic/TopicCreate/index.jsx b/packages/concordia-app/src/views/Topic/TopicCreate/index.jsx index 620339c..41e03da 100644 --- a/packages/concordia-app/src/views/Topic/TopicCreate/index.jsx +++ b/packages/concordia-app/src/views/Topic/TopicCreate/index.jsx @@ -54,10 +54,7 @@ const TopicCreate = (props) => { const goToTopic = useCallback((topicId) => { if (topicId) history.push(`/topics/${topicId}`); - else { - console.error('Error creating poll!'); - history.push(`/topics/${newTopicId}`); - } + else history.push(`/topics/${newTopicId}`); }, [history, newTopicId]); useEffect(() => { diff --git a/packages/concordia-app/src/views/Topic/TopicView/index.jsx b/packages/concordia-app/src/views/Topic/TopicView/index.jsx index 7546616..5d1d1b2 100644 --- a/packages/concordia-app/src/views/Topic/TopicView/index.jsx +++ b/packages/concordia-app/src/views/Topic/TopicView/index.jsx @@ -22,7 +22,13 @@ import targetBlank from '../../../utils/markdownUtils'; const { contracts: { [FORUM_CONTRACT]: { methods: { getTopic: { cacheCall: getTopicChainData } } }, - [VOTING_CONTRACT]: { methods: { pollExists: { cacheCall: pollExistsChainData } } }, + [VOTING_CONTRACT]: { + methods: { + pollExists: { + cacheCall: pollExistsChainData, clearCacheCall: clearPollExistsChainData, + }, + }, + }, }, } = drizzle; const { orbit } = breeze; @@ -132,12 +138,22 @@ const TopicView = (props) => { } }, [topicId, topics]); - const poll = useMemo(() => hasPoll && , [hasPoll, topicId]); + const poll = useMemo(() => hasPoll + && ( + + ), [hasPoll, topicAuthorAddress, topicId]); const stopClickPropagation = (event) => { event.stopPropagation(); }; + useEffect(() => () => { + clearPollExistsChainData(); + }, []); + return (