diff --git a/src/components/comment/view/commentStyles.js b/src/components/comment/view/commentStyles.js index 74f32b251..83defeda2 100644 --- a/src/components/comment/view/commentStyles.js +++ b/src/components/comment/view/commentStyles.js @@ -41,7 +41,7 @@ export default EStyleSheet.create({ alignSelf: 'center', justifyContent: 'center', alignItems: 'center', - fontSize: 10, + fontSize: 12, color: '$iconColor', }, voteCountWrapper: { diff --git a/src/components/comment/view/commentView.js b/src/components/comment/view/commentView.js index 7a0dbe157..263e60a5b 100644 --- a/src/components/comment/view/commentView.js +++ b/src/components/comment/view/commentView.js @@ -1,7 +1,8 @@ import React, { PureComponent, Fragment } from 'react'; -import { View, Text, TouchableWithoutFeedback } from 'react-native'; +import { View, TouchableWithoutFeedback } from 'react-native'; import ActionSheet from 'react-native-actionsheet'; import { injectIntl } from 'react-intl'; +import get from 'lodash/get'; import { getTimeFromNow } from '../../../utils/time'; // Constants @@ -51,6 +52,7 @@ class CommentView extends PureComponent { handleOnLongPress, handleOnReplyPress, handleOnUserPress, + handleOnVotersPress, isLoggedIn, isShowComments, isShowMoreButton, @@ -84,15 +86,23 @@ class CommentView extends PureComponent { {isLoggedIn && ( - + handleOnVotersPress && + voteCount > 0 && + handleOnVotersPress(get(comment, 'active_votes')) + } + text={voteCount} + textMarginLeft={20} + textStyle={styles.voteCountText} /> - {voteCount} 0} voteCount={get(item, 'vote_count')} diff --git a/src/components/commentsDisplay/view/commentsDisplayView.js b/src/components/commentsDisplay/view/commentsDisplayView.js index 121928a4a..76d5aa8af 100644 --- a/src/components/commentsDisplay/view/commentsDisplayView.js +++ b/src/components/commentsDisplay/view/commentsDisplayView.js @@ -31,7 +31,15 @@ class CommentsDisplayView extends PureComponent { }; render() { - const { author, commentCount, fetchPost, intl, permlink, mainAuthor } = this.props; + const { + author, + commentCount, + fetchPost, + intl, + permlink, + mainAuthor, + handleOnVotersPress, + } = this.props; const { selectedFilter } = this.state; return ( @@ -56,6 +64,7 @@ class CommentsDisplayView extends PureComponent { author={author} permlink={permlink} mainAuthor={mainAuthor} + handleOnVotersPress={handleOnVotersPress} /> diff --git a/src/components/postView/view/postDisplayView.js b/src/components/postView/view/postDisplayView.js index dab0040fd..bc19f5ecb 100644 --- a/src/components/postView/view/postDisplayView.js +++ b/src/components/postView/view/postDisplayView.js @@ -152,6 +152,7 @@ class PostDisplayView extends PureComponent { author, intl, handleOnRemovePress, + handleOnVotersPress, } = this.props; const { postHeight, scrollHeight, isLoadedComments } = this.state; @@ -211,6 +212,7 @@ class PostDisplayView extends PureComponent { permlink={post.permlink} commentCount={post.children} fetchPost={fetchPost} + handleOnVotersPress={handleOnVotersPress} /> )} diff --git a/src/utils/postParser.js b/src/utils/postParser.js index 32ea62c19..bca6cf36a 100644 --- a/src/utils/postParser.js +++ b/src/utils/postParser.js @@ -48,26 +48,7 @@ export const parsePost = async (post, currentUserName, isPromoted) => { post.is_down_voted = false; } - const totalPayout = - parseFloat(post.pending_payout_value) + - parseFloat(post.total_payout_value) + - parseFloat(post.curator_payout_value); - - post.total_payout = totalPayout.toFixed(3); - - const voteRshares = post.active_votes.reduce((a, b) => a + parseFloat(b.rshares), 0); - const ratio = totalPayout / voteRshares; - - if (!isEmpty(post.active_votes)) { - forEach(post.active_votes, value => { - post.vote_perecent = value.voter === currentUserName ? value.percent : null; - value.value = (value.rshares * ratio).toFixed(3); - value.reputation = getReputation(get(value, 'reputation')); - value.percent /= 100; - value.is_down_vote = Math.sign(value.percent) < 0; - value.avatar = `https://steemitimages.com/u/${value.voter}/avatar/small`; - }); - } + post.active_votes = parseActiveVotes(post, currentUserName); post.reblogs = await getPostReblogs(post); post.reblogCount = get(post, 'reblogs', []).length; @@ -140,6 +121,9 @@ export const parseComments = async (comments, currentUserName) => { comment.is_voted = false; comment.is_down_voted = false; } + + comment.active_votes = parseActiveVotes(comment, currentUserName); + return comment; }); @@ -167,3 +151,28 @@ const isDownVoted = (activeVotes, currentUserName) => { } return false; }; + +const parseActiveVotes = (post, currentUserName) => { + const totalPayout = + parseFloat(post.pending_payout_value) + + parseFloat(post.total_payout_value) + + parseFloat(post.curator_payout_value); + + post.total_payout = totalPayout.toFixed(3); + + const voteRshares = post.active_votes.reduce((a, b) => a + parseFloat(b.rshares), 0); + const ratio = totalPayout / voteRshares; + + if (!isEmpty(post.active_votes)) { + forEach(post.active_votes, value => { + post.vote_perecent = value.voter === currentUserName ? value.percent : null; + value.value = (value.rshares * ratio).toFixed(3); + value.reputation = getReputation(get(value, 'reputation')); + value.percent /= 100; + value.is_down_vote = Math.sign(value.percent) < 0; + value.avatar = `https://steemitimages.com/u/${value.voter}/avatar/small`; + }); + } + + return post.active_votes; +};