|
@ -59,7 +59,8 @@ const PostVoting = (props) => { |
|
|
useEffect(() => { |
|
|
useEffect(() => { |
|
|
const shouldGetOwnVoteFromChain = ownVote === null; |
|
|
const shouldGetOwnVoteFromChain = ownVote === null; |
|
|
|
|
|
|
|
|
if (drizzleInitialized && !drizzleInitializationFailed && shouldGetOwnVoteFromChain && postId !== null && userAccount !== null) { |
|
|
if (drizzleInitialized && !drizzleInitializationFailed && shouldGetOwnVoteFromChain |
|
|
|
|
|
&& postId !== null && userAccount !== null) { |
|
|
setGetVoteCallHash(getVoteChainData(postId, userAccount)); |
|
|
setGetVoteCallHash(getVoteChainData(postId, userAccount)); |
|
|
} |
|
|
} |
|
|
}, [drizzleInitializationFailed, drizzleInitialized, ownVote, postId, totalVoteCount, userAccount]); |
|
|
}, [drizzleInitializationFailed, drizzleInitialized, ownVote, postId, totalVoteCount, userAccount]); |
|
@ -87,11 +88,13 @@ const PostVoting = (props) => { |
|
|
}, [createVoteCacheSendStackId, transactionStack, transactions, voting]); |
|
|
}, [createVoteCacheSendStackId, transactionStack, transactions, voting]); |
|
|
|
|
|
|
|
|
const vote = useCallback((choice) => { |
|
|
const vote = useCallback((choice) => { |
|
|
|
|
|
if (voting) return; |
|
|
|
|
|
|
|
|
setVoting(true); |
|
|
setVoting(true); |
|
|
if ((ownVote === CHOICE_DEFAULT || ownVote === CHOICE_DOWN) && choice === CHOICE_UP) setVoteCacheSendStackId(upvote.cacheSend(...[postId], { from: userAccount })); |
|
|
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_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 })); |
|
|
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; |
|
|
const disableVoting = userAccount === null || !hasSignedUp || postAuthorAddress === null || userAccount === postAuthorAddress; |
|
|
return useMemo(() => ( |
|
|
return useMemo(() => ( |
|
@ -121,10 +124,6 @@ const PostVoting = (props) => { |
|
|
), [disableVoting, ownVote, totalVoteCount, vote]); |
|
|
), [disableVoting, ownVote, totalVoteCount, vote]); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
PostVoting.defaultProps = { |
|
|
|
|
|
loading: false, |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
PostVoting.propTypes = { |
|
|
PostVoting.propTypes = { |
|
|
postId: PropTypes.number.isRequired, |
|
|
postId: PropTypes.number.isRequired, |
|
|
postAuthorAddress: PropTypes.string, |
|
|
postAuthorAddress: PropTypes.string, |
|
|