From a32a0f8a243b2d5d3de5bd3c417a4225d9f705d3 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Sat, 6 Feb 2021 19:07:42 +0200 Subject: [PATCH] fix: disallow voting when voting transaction pending --- .../src/components/PostList/PostVoting/index.jsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/concordia-app/src/components/PostList/PostVoting/index.jsx b/packages/concordia-app/src/components/PostList/PostVoting/index.jsx index 7f84bbc..6298903 100644 --- a/packages/concordia-app/src/components/PostList/PostVoting/index.jsx +++ b/packages/concordia-app/src/components/PostList/PostVoting/index.jsx @@ -59,7 +59,8 @@ const PostVoting = (props) => { useEffect(() => { const shouldGetOwnVoteFromChain = ownVote === null; - if (drizzleInitialized && !drizzleInitializationFailed && shouldGetOwnVoteFromChain && postId !== null && userAccount !== null) { + if (drizzleInitialized && !drizzleInitializationFailed && shouldGetOwnVoteFromChain + && postId !== null && userAccount !== null) { setGetVoteCallHash(getVoteChainData(postId, userAccount)); } }, [drizzleInitializationFailed, drizzleInitialized, ownVote, postId, totalVoteCount, userAccount]); @@ -87,11 +88,13 @@ const PostVoting = (props) => { }, [createVoteCacheSendStackId, transactionStack, transactions, voting]); const vote = useCallback((choice) => { + if (voting) return; + setVoting(true); if ((ownVote === CHOICE_DEFAULT || ownVote === CHOICE_DOWN) && choice === CHOICE_UP) setVoteCacheSendStackId(upvote.cacheSend(...[postId], { from: userAccount })); else if ((ownVote === CHOICE_DEFAULT || ownVote === CHOICE_UP) && choice === CHOICE_DOWN) setVoteCacheSendStackId(downvote.cacheSend(...[postId], { from: userAccount })); else if ((ownVote === CHOICE_UP && choice === CHOICE_UP) || (ownVote === CHOICE_DOWN && choice === CHOICE_DOWN)) setVoteCacheSendStackId(unvote.cacheSend(...[postId], { from: userAccount })); - }, [ownVote, postId, userAccount]); + }, [ownVote, postId, userAccount, voting]); const disableVoting = userAccount === null || !hasSignedUp || postAuthorAddress === null || userAccount === postAuthorAddress; return useMemo(() => ( @@ -121,10 +124,6 @@ const PostVoting = (props) => { ), [disableVoting, ownVote, totalVoteCount, vote]); }; -PostVoting.defaultProps = { - loading: false, -}; - PostVoting.propTypes = { postId: PropTypes.number.isRequired, postAuthorAddress: PropTypes.string,