This commit is contained in:
Mustafa Buyukcelebi 2019-06-22 20:05:16 +03:00
commit 997bd99527
15 changed files with 184 additions and 148 deletions

View File

@ -5,7 +5,6 @@ import { injectIntl } from 'react-intl';
import get from 'lodash/get'; import get from 'lodash/get';
import { getComments, deleteComment } from '../../../providers/steem/dsteem'; import { getComments, deleteComment } from '../../../providers/steem/dsteem';
// Services and Actions // Services and Actions
import { writeToClipboard } from '../../../utils/clipboard'; import { writeToClipboard } from '../../../utils/clipboard';
import { toastNotification } from '../../../redux/actions/uiAction'; import { toastNotification } from '../../../redux/actions/uiAction';
@ -44,8 +43,8 @@ class CommentsContainer extends Component {
this._getComments(); this._getComments();
} }
if (selectedFilter !== nextProps.selectedFilter && nextProps.selectedFilter) { if (selectedFilter !== get(nextProps, 'selectedFilter') && get(nextProps, 'selectedFilter')) {
const shortedComments = this._shortComments(nextProps.selectedFilter); const shortedComments = this._shortComments(get(nextProps, 'selectedFilter'));
this.setState({ comments: shortedComments }); this.setState({ comments: shortedComments });
} }
} }
@ -56,9 +55,9 @@ class CommentsContainer extends Component {
const { comments: parent } = this.state; const { comments: parent } = this.state;
const allPayout = c => const allPayout = c =>
parseFloat(c.pending_payout_value.split(' ')[0]) + parseFloat(get(c, 'pending_payout_value').split(' ')[0]) +
parseFloat(c.total_payout_value.split(' ')[0]) + parseFloat(get(c, 'total_payout_value').split(' ')[0]) +
parseFloat(c.curator_payout_value.split(' ')[0]); parseFloat(get(c, 'curator_payout_value').split(' ')[0]);
const absNegative = a => a.net_rshares < 0; const absNegative = a => a.net_rshares < 0;
@ -81,8 +80,8 @@ class CommentsContainer extends Component {
return 0; return 0;
}, },
REPUTATION: (a, b) => { REPUTATION: (a, b) => {
const keyA = a.author_reputation; const keyA = get(a, 'author_reputation');
const keyB = b.author_reputation; const keyB = get(b, 'author_reputation');
if (keyA > keyB) return -1; if (keyA > keyB) return -1;
if (keyA < keyB) return 1; if (keyA < keyB) return 1;
@ -107,8 +106,8 @@ class CommentsContainer extends Component {
return -1; return -1;
} }
const keyA = Date.parse(a.created); const keyA = Date.parse(get(a, 'created'));
const keyB = Date.parse(b.created); const keyB = Date.parse(get(b, 'created'));
if (keyA > keyB) return -1; if (keyA > keyB) return -1;
if (keyA < keyB) return 1; if (keyA < keyB) return 1;
@ -122,14 +121,20 @@ class CommentsContainer extends Component {
return parent; return parent;
}; };
_getComments = () => { _getComments = async () => {
const { author, permlink } = this.props; const {
author,
permlink,
currentAccount: { name },
} = this.props;
getComments(author, permlink).then(comments => { await getComments(author, permlink, name)
this.setState({ .then(comments => {
comments, this.setState({
}); comments,
}); });
})
.catch(() => {});
}; };
_handleOnReplyPress = item => { _handleOnReplyPress = item => {

View File

@ -67,7 +67,7 @@ class CommentsView extends PureComponent {
mainAuthor={mainAuthor} mainAuthor={mainAuthor}
avatarSize={avatarSize} avatarSize={avatarSize}
comment={item} comment={item}
commentCount={commentCount || item.children} commentCount={commentCount || get(item.children)}
commentNumber={commentNumber} commentNumber={commentNumber}
handleDeleteComment={handleDeleteComment} handleDeleteComment={handleDeleteComment}
currentAccountUsername={currentAccountUsername} currentAccountUsername={currentAccountUsername}
@ -76,8 +76,8 @@ class CommentsView extends PureComponent {
handleOnReplyPress={handleOnReplyPress} handleOnReplyPress={handleOnReplyPress}
handleOnUserPress={handleOnUserPress} handleOnUserPress={handleOnUserPress}
isLoggedIn={isLoggedIn} isLoggedIn={isLoggedIn}
isShowMoreButton={commentNumber === 1 && item.children > 0} isShowMoreButton={commentNumber === 1 && get(item, 'children') > 0}
voteCount={item.net_votes} voteCount={get(item, 'vote_count')}
isShowSubComments={isShowSubComments} isShowSubComments={isShowSubComments}
key={item.permlink} key={item.permlink}
marginLeft={marginLeft} marginLeft={marginLeft}

View File

@ -82,7 +82,7 @@ class PostCardContainer extends PureComponent {
}; };
render() { render() {
const { content, isHideImage, nsfw } = this.props; const { content, isHideImage, nsfw, isHideReblogOption } = this.props;
const { _content } = this.state; const { _content } = this.state;
const isNsfwPost = nsfw === '1'; const isNsfwPost = nsfw === '1';
@ -96,6 +96,7 @@ class PostCardContainer extends PureComponent {
content={_content || content} content={_content || content}
isHideImage={isHideImage} isHideImage={isHideImage}
isNsfwPost={isNsfwPost} isNsfwPost={isNsfwPost}
isHideReblogOption={isHideReblogOption}
/> />
); );
} }

View File

@ -68,7 +68,7 @@ class PostCardView extends Component {
}; };
render() { render() {
const { content, isHideImage, fetchPost, isNsfwPost } = this.props; const { content, isHideImage, fetchPost, isNsfwPost, isHideReblogOption } = this.props;
const _image = this._getPostImage(content, isNsfwPost); const _image = this._getPostImage(content, isNsfwPost);
const reblogedBy = content.reblogged_by && content.reblogged_by[0]; const reblogedBy = content.reblogged_by && content.reblogged_by[0];
@ -88,7 +88,11 @@ class PostCardView extends Component {
reblogedBy={reblogedBy} reblogedBy={reblogedBy}
/> />
<View style={styles.dropdownWrapper}> <View style={styles.dropdownWrapper}>
<PostDropdown content={content} fetchPost={fetchPost} /> <PostDropdown
isHideReblogOption={isHideReblogOption}
content={content}
fetchPost={fetchPost}
/>
</View> </View>
</View> </View>
<View style={styles.postBodyWrapper}> <View style={styles.postBodyWrapper}>

View File

@ -173,10 +173,10 @@ class PostDropdownContainer extends PureComponent {
}; };
render() { render() {
const { intl, currentAccount, content } = this.props; const { intl, currentAccount, content, isHideReblogOption } = this.props;
let _OPTIONS = OPTIONS; let _OPTIONS = OPTIONS;
if (content && content.author === currentAccount.name) { if ((content && content.author === currentAccount.name) || isHideReblogOption) {
_OPTIONS = OPTIONS.filter(item => item !== 'reblog'); _OPTIONS = OPTIONS.filter(item => item !== 'reblog');
} }

View File

@ -186,7 +186,7 @@ class PostDisplayView extends PureComponent {
<Tags tags={post.json_metadata && post.json_metadata.tags} /> <Tags tags={post.json_metadata && post.json_metadata.tags} />
<Text style={styles.footerText}> <Text style={styles.footerText}>
Posted by Posted by
<Text style={styles.footerName}>{author || post.author}</Text> <Text style={styles.footerName}>{` ${author || post.author} `}</Text>
{formatedTime} {formatedTime}
</Text> </Text>
{/* {isPostEnd && this._getTabBar()} */} {/* {isPostEnd && this._getTabBar()} */}

View File

@ -233,6 +233,7 @@ class PostsView extends Component {
isLoginDone, isLoginDone,
tag, tag,
isDarkTheme, isDarkTheme,
isHideReblogOption,
} = this.props; } = this.props;
return ( return (
@ -267,7 +268,12 @@ class PostsView extends Component {
data={posts} data={posts}
showsVerticalScrollIndicator={false} showsVerticalScrollIndicator={false}
renderItem={({ item }) => ( renderItem={({ item }) => (
<PostCard isRefresh={refreshing} content={item} isHideImage={isHideImage} /> <PostCard
isHideReblogOption={isHideReblogOption}
isRefresh={refreshing}
content={item}
isHideImage={isHideImage}
/>
)} )}
keyExtractor={(post, index) => index.toString()} keyExtractor={(post, index) => index.toString()}
onEndReached={() => this._loadPosts()} onEndReached={() => this._loadPosts()}

View File

@ -1,5 +1,6 @@
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import get from 'lodash/get';
// Realm // Realm
import { setUpvotePercent } from '../../../realm/realm'; import { setUpvotePercent } from '../../../realm/realm';
@ -50,31 +51,21 @@ class UpvoteContainer extends PureComponent {
upvotePercent, upvotePercent,
globalProps, globalProps,
} = this.props; } = this.props;
let author;
let authorPayout;
let curationPayout;
let isDecinedPayout;
let isVoted;
let payoutDate;
let pendingPayout;
let permlink;
let promotedPayout;
let totalPayout;
if (content) { const author = get(content, 'author');
({ author } = content); const isVoted = get(content, 'is_voted');
isVoted = content.is_voted; const totalPayout = get(content, 'total_payout');
totalPayout = content.total_payout; const isDecinedPayout = get(content, 'is_declined_payout');
isDecinedPayout = content.is_declined_payout; const permlink = get(content, 'permlink');
({ permlink } = content); const pendingPayout = parseToken(get(content, 'pending_payout_value', 0)).toFixed(3);
pendingPayout = parseToken(content.pending_payout_value).toFixed(3); const promotedPayout = parseToken(get(content, 'promoted', 0)).toFixed(3);
promotedPayout = parseToken(content.promoted).toFixed(3); const authorPayout = parseToken(get(content, 'total_payout_value', 0)).toFixed(3);
authorPayout = parseToken(content.total_payout_value).toFixed(3); const curationPayout = parseToken(get(content, 'curator_payout_value', 0)).toFixed(3);
curationPayout = parseToken(content.curator_payout_value).toFixed(3); const payoutDate = getTimeFromNow(
payoutDate = getTimeFromNow( isEmptyContentDate(get(content, 'last_payout'))
isEmptyContentDate(content.last_payout) ? content.cashout_time : content.last_payout, ? get(content, 'cashout_time')
); : get(content, 'last_payout'),
} );
return ( return (
<UpvoteView <UpvoteView

View File

@ -3,6 +3,7 @@ import { View, TouchableOpacity, Text, Alert } from 'react-native';
import { injectIntl } from 'react-intl'; import { injectIntl } from 'react-intl';
import { Popover, PopoverController } from 'react-native-modal-popover'; import { Popover, PopoverController } from 'react-native-modal-popover';
import Slider from 'react-native-slider'; import Slider from 'react-native-slider';
import get from 'lodash/get';
// Utils // Utils
import parseToken from '../../../utils/parseToken'; import parseToken from '../../../utils/parseToken';
@ -29,9 +30,9 @@ class UpvoteView extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
sliderValue: props.upvotePercent || 1, sliderValue: get(props, 'upvotePercent', 1),
isVoting: false, isVoting: false,
isVoted: props.isVoted, isVoted: get(props, 'isVoted', false),
amount: '0.00000', amount: '0.00000',
isShowDetails: false, isShowDetails: false,
}; };
@ -46,12 +47,12 @@ class UpvoteView extends Component {
const { isVoted, upvotePercent } = this.props; const { isVoted, upvotePercent } = this.props;
const { isVoted: localIsVoted } = this.state; const { isVoted: localIsVoted } = this.state;
if (isVoted !== nextProps.isVoted && localIsVoted !== nextProps.isVoted) { if (isVoted !== get(nextProps, 'isVoted') && localIsVoted !== get(nextProps, 'isVoted')) {
this.setState({ isVoted: nextProps.isVoted }); this.setState({ isVoted: get(nextProps, 'isVoted') });
} }
if (upvotePercent !== nextProps.upvotePercent) { if (upvotePercent !== get(nextProps, 'upvotePercent')) {
this.setState({ sliderValue: nextProps.upvotePercent }); this.setState({ sliderValue: get(nextProps, 'upvotePercent') });
} }
} }
@ -65,9 +66,9 @@ class UpvoteView extends Component {
const votingPower = currentAccount.voting_power; const votingPower = currentAccount.voting_power;
const totalVests = const totalVests =
parseToken(currentAccount.vesting_shares) + parseToken(get(currentAccount, 'vesting_shares')) +
parseToken(currentAccount.received_vesting_shares) - parseToken(get(currentAccount, 'received_vesting_shares')) -
parseToken(currentAccount.delegated_vesting_shares); parseToken(get(currentAccount, 'delegated_vesting_shares'));
const votePct = sliderValue * 10000; const votePct = sliderValue * 10000;
const rShares = vestsToRshares(totalVests, votingPower, votePct); const rShares = vestsToRshares(totalVests, votingPower, votePct);

View File

@ -65,13 +65,13 @@ export const fetchGlobalProps = async () => {
} }
const steemPerMVests = const steemPerMVests =
(parseToken(globalDynamic.total_vesting_fund_steem) / (parseToken(get(globalDynamic, 'total_vesting_fund_steem')) /
parseToken(globalDynamic.total_vesting_shares)) * parseToken(get(globalDynamic, 'total_vesting_shares'))) *
1e6; 1e6;
const base = parseToken(feedHistory.current_median_history.base); const base = parseToken(get(feedHistory, 'current_median_history.base'));
const quote = parseToken(feedHistory.current_median_history.quote); const quote = parseToken(get(feedHistory, 'current_median_history.quote'));
const fundRecentClaims = rewardFund.recent_claims; const fundRecentClaims = get(rewardFund, 'recent_claims');
const fundRewardBalance = parseToken(rewardFund.reward_balance); const fundRewardBalance = parseToken(get(rewardFund, 'reward_balance'));
const globalProps = { const globalProps = {
steemPerMVests, steemPerMVests,
base, base,
@ -140,19 +140,20 @@ export const getUser = async user => {
globalProperties.total_vesting_fund_steem, globalProperties.total_vesting_fund_steem,
); );
account[0].received_steem_power = await vestToSteem( account[0].received_steem_power = await vestToSteem(
account[0].received_vesting_shares, get(account[0], 'received_vesting_shares'),
globalProperties.total_vesting_shares, get(globalProperties, 'total_vesting_shares'),
globalProperties.total_vesting_fund_steem, get(globalProperties, 'total_vesting_fund_steem'),
); );
account[0].delegated_steem_power = await vestToSteem( account[0].delegated_steem_power = await vestToSteem(
account[0].delegated_vesting_shares, get(account[0], 'delegated_vesting_shares'),
globalProperties.total_vesting_shares, get(globalProperties, 'total_vesting_shares'),
globalProperties.total_vesting_fund_steem, get(globalProperties, 'total_vesting_fund_steem'),
); );
account[0].about = account[0].json_metadata && JSON.parse(account[0].json_metadata); account[0].about =
account[0].avatar = getAvatar(account[0].about); get(account[0], 'json_metadata') && JSON.parse(get(account[0], 'json_metadata'));
account[0].display_name = getName(account[0].about); account[0].avatar = getAvatar(get(account[0], 'about'));
account[0].display_name = getName(get(account[0], 'about'));
return account[0]; return account[0];
} catch (error) { } catch (error) {
@ -289,7 +290,16 @@ export const getPosts = async (by, query, user) => {
}; };
export const getActiveVotes = (author, permlink) => export const getActiveVotes = (author, permlink) =>
client.database.call('get_active_votes', [author, permlink]); new Promise((resolve, reject) => {
client.database
.call('get_active_votes', [author, permlink])
.then(result => {
resolve(result);
})
.catch(err => {
reject(err);
});
});
export const getPostsSummary = async (by, query, currentUserName, filterNsfw) => { export const getPostsSummary = async (by, query, currentUserName, filterNsfw) => {
try { try {
@ -312,7 +322,7 @@ export const getPostsSummary = async (by, query, currentUserName, filterNsfw) =>
export const getUserComments = async query => { export const getUserComments = async query => {
try { try {
let comments = await client.database.getDiscussions('comments', query); let comments = await client.database.getDiscussions('comments', query);
comments = parseComments(comments); comments = await parseComments(comments);
return comments; return comments;
} catch (error) { } catch (error) {
return error; return error;
@ -326,7 +336,7 @@ export const getRepliesByLastUpdate = async query => {
query.start_permlink, query.start_permlink,
query.limit, query.limit,
]); ]);
replies = parseComments(replies); replies = await parseComments(replies);
return replies; return replies;
} catch (error) { } catch (error) {
return error; return error;
@ -395,26 +405,20 @@ export const deleteComment = (currentAccount, pin, permlink) => {
} }
}; };
/** const wait = ms => new Promise(r => setTimeout(r, ms));
* @method getUser get user data
* @param user post author export const getComments = async (author, permlink, currentUserName = null) => {
* @param permlink post permlink try {
*/ const comments = await client.database.call('get_content_replies', [author, permlink]);
export const getComments = (user, permlink) => {
let comments; const groomedComments = await parseComments(comments, currentUserName);
return new Promise((resolve, reject) => { // WORK ARROUND
client.database await wait(comments && comments.length * 30);
.call('get_content_replies', [user, permlink])
.then(result => { return comments ? groomedComments : null;
comments = parseComments(result); } catch (error) {
}) return error;
.then(() => { }
resolve(comments);
})
.catch(error => {
reject(error);
});
});
}; };
/** /**
@ -517,15 +521,15 @@ export const upvoteAmount = async input => {
export const transferToken = (currentAccount, pin, data) => { export const transferToken = (currentAccount, pin, data) => {
const digitPinCode = getDigitPinCode(pin); const digitPinCode = getDigitPinCode(pin);
const key = getAnyPrivateKey({ activeKey: currentAccount.local.activeKey }, digitPinCode); const key = getAnyPrivateKey({ activeKey: get(currentAccount, 'local.activeKey') }, digitPinCode);
if (key) { if (key) {
const privateKey = PrivateKey.fromString(key); const privateKey = PrivateKey.fromString(key);
const args = { const args = {
from: data.from, from: get(data, 'from'),
to: data.destination, to: get(data, 'destination'),
amount: data.amount, amount: get(data, 'amount'),
memo: data.memo, memo: get(data, 'memo'),
}; };
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -533,7 +537,7 @@ export const transferToken = (currentAccount, pin, data) => {
.transfer(args, privateKey) .transfer(args, privateKey)
.then(result => { .then(result => {
if (result) { if (result) {
transfer(data.from, data.destination, data.ammount); transfer(get(data, 'from'), get(data, 'destination'), get(data, 'ammount'));
resolve(result); resolve(result);
} }
}) })
@ -548,7 +552,7 @@ export const transferToken = (currentAccount, pin, data) => {
export const transferToSavings = (currentAccount, pin, data) => { export const transferToSavings = (currentAccount, pin, data) => {
const digitPinCode = getDigitPinCode(pin); const digitPinCode = getDigitPinCode(pin);
const key = getAnyPrivateKey({ activeKey: currentAccount.local.activeKey }, digitPinCode); const key = getAnyPrivateKey({ activeKey: get(currentAccount, 'local.activeKey') }, digitPinCode);
if (key) { if (key) {
const privateKey = PrivateKey.fromString(key); const privateKey = PrivateKey.fromString(key);
@ -557,10 +561,10 @@ export const transferToSavings = (currentAccount, pin, data) => {
[ [
'transfer_to_savings', 'transfer_to_savings',
{ {
from: data.from, from: get(data, 'from'),
to: data.destination, to: get(data, 'destination'),
amount: data.amount, amount: get(data, 'amount'),
memo: data.memo, memo: get(data, 'memo'),
}, },
], ],
]; ];
@ -582,7 +586,7 @@ export const transferToSavings = (currentAccount, pin, data) => {
export const transferFromSavings = (currentAccount, pin, data) => { export const transferFromSavings = (currentAccount, pin, data) => {
const digitPinCode = getDigitPinCode(pin); const digitPinCode = getDigitPinCode(pin);
const key = getAnyPrivateKey({ activeKey: currentAccount.local.activeKey }, digitPinCode); const key = getAnyPrivateKey({ activeKey: get(currentAccount, 'local.activeKey') }, digitPinCode);
if (key) { if (key) {
const privateKey = PrivateKey.fromString(key); const privateKey = PrivateKey.fromString(key);
@ -590,11 +594,11 @@ export const transferFromSavings = (currentAccount, pin, data) => {
[ [
'transfer_from_savings', 'transfer_from_savings',
{ {
from: data.from, from: get(data, 'from'),
to: data.destination, to: get(data, 'destination'),
amount: data.amount, amount: get(data, 'amount'),
memo: data.memo, memo: get(data, 'memo'),
request_id: data.requestId, request_id: get(data, 'requestId'),
}, },
], ],
]; ];
@ -616,7 +620,7 @@ export const transferFromSavings = (currentAccount, pin, data) => {
export const transferToVesting = (currentAccount, pin, data) => { export const transferToVesting = (currentAccount, pin, data) => {
const digitPinCode = getDigitPinCode(pin); const digitPinCode = getDigitPinCode(pin);
const key = getAnyPrivateKey({ activeKey: currentAccount.local.activeKey }, digitPinCode); const key = getAnyPrivateKey({ activeKey: get(currentAccount, 'local.activeKey') }, digitPinCode);
if (key) { if (key) {
const privateKey = PrivateKey.fromString(key); const privateKey = PrivateKey.fromString(key);
@ -651,7 +655,7 @@ export const followUser = async (currentAccount, pin, data) => {
const key = getAnyPrivateKey(currentAccount.local, digitPinCode); const key = getAnyPrivateKey(currentAccount.local, digitPinCode);
if (currentAccount.local.authType === AUTH_TYPE.STEEM_CONNECT) { if (currentAccount.local.authType === AUTH_TYPE.STEEM_CONNECT) {
const token = decryptKey(currentAccount.local.accessToken, digitPinCode); const token = decryptKey(get(currentAccount, 'local.accessToken'), digitPinCode);
const api = steemConnect.Initialize({ const api = steemConnect.Initialize({
accessToken: token, accessToken: token,
}); });
@ -982,15 +986,15 @@ const _reblog = async (account, pinCode, author, permlink) => {
export const claimRewardBalance = (account, pinCode, rewardSteem, rewardSbd, rewardVests) => { export const claimRewardBalance = (account, pinCode, rewardSteem, rewardSbd, rewardVests) => {
const pin = getDigitPinCode(pinCode); const pin = getDigitPinCode(pinCode);
const key = getAnyPrivateKey(account.local, pin); const key = getAnyPrivateKey(get(account, 'local'), pin);
if (account.local.authType === AUTH_TYPE.STEEM_CONNECT) { if (account.local.authType === AUTH_TYPE.STEEM_CONNECT) {
const token = decryptKey(account.local.accessToken, pin); const token = decryptKey(get(account, 'local.accessToken'), pin);
const api = steemConnect.Initialize({ const api = steemConnect.Initialize({
accessToken: token, accessToken: token,
}); });
return api.claimRewardBalance(account.name, rewardSteem, rewardSbd, rewardVests); return api.claimRewardBalance(get(account, 'name'), rewardSteem, rewardSbd, rewardVests);
} }
if (key) { if (key) {
@ -1016,7 +1020,7 @@ export const claimRewardBalance = (account, pinCode, rewardSteem, rewardSbd, rew
export const transferPoint = (currentAccount, pinCode, data) => { export const transferPoint = (currentAccount, pinCode, data) => {
const pin = getDigitPinCode(pinCode); const pin = getDigitPinCode(pinCode);
const key = getActiveKey(currentAccount.local, pin); const key = getActiveKey(get(currentAccount, 'local'), pin);
const username = get(currentAccount, 'name'); const username = get(currentAccount, 'name');
const json = JSON.stringify({ const json = JSON.stringify({

View File

@ -1,10 +1,8 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import get from 'lodash/get';
// Middleware // Middleware
// Constants
import { default as ROUTES } from '../../../constants/routeNames';
// Utilities // Utilities
// Services and Actions // Services and Actions
@ -83,11 +81,13 @@ class FollowsContainer extends Component {
}; };
_handleSearch = async text => { _handleSearch = async text => {
const { users, username } = this.state; const { users, username, isFollowingPress } = this.state;
let newData; let newData;
newData = users.filter(item => { newData = users.filter(item => {
const itemName = item.follower.toUpperCase(); const itemName = isFollowingPress
? get(item, 'following').toUpperCase()
: get(item, 'follower').toUpperCase();
const _text = text.toUpperCase(); const _text = text.toUpperCase();
return itemName.indexOf(_text) > -1; return itemName.indexOf(_text) > -1;

View File

@ -1,6 +1,8 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { withNavigation } from 'react-navigation'; import { withNavigation } from 'react-navigation';
import get from 'lodash/get';
// Services and Actions // Services and Actions
import { getPost } from '../../../providers/steem/dsteem'; import { getPost } from '../../../providers/steem/dsteem';
@ -29,8 +31,10 @@ class PostContainer extends Component {
// Component Life Cycle Functions // Component Life Cycle Functions
componentDidMount() { componentDidMount() {
const { navigation } = this.props; const { navigation } = this.props;
const { content, permlink, author, isNewPost, isHasParentPost } = const { content, permlink, author, isNewPost, isHasParentPost } = get(
navigation.state && navigation.state.params; navigation,
'state.params',
);
if (isNewPost) this.setState({ isNewPost }); if (isNewPost) this.setState({ isNewPost });
@ -45,11 +49,10 @@ class PostContainer extends Component {
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
const { navigation } = this.props; const { navigation } = this.props;
const { isFetch: nextIsFetch } = const { isFetch: nextIsFetch } = get(nextProps, 'navigation.state.params');
nextProps.navigation.state && nextProps.navigation.state.params;
if (nextIsFetch) { if (nextIsFetch) {
const { author, permlink } = navigation.state && navigation.state.params; const { author, permlink } = get(navigation, 'state.params');
this._loadPost(author, permlink); this._loadPost(author, permlink);
} }
@ -61,12 +64,12 @@ class PostContainer extends Component {
const { currentAccount, isLoggedIn } = this.props; const { currentAccount, isLoggedIn } = this.props;
const { post } = this.state; const { post } = this.state;
const _author = author || post.author; const _author = author || get(post, 'author');
const _permlink = permlink || post.permlink; const _permlink = permlink || get(post, 'permlink');
await getPost(_author, _permlink, isLoggedIn && currentAccount.username) await getPost(_author, _permlink, isLoggedIn && get(currentAccount, 'username'))
.then(result => { .then(result => {
if (result && result.id > 0) { if (get(result, 'id', 0) > 0) {
if (isParentPost) { if (isParentPost) {
this.setState({ parentPost: result }); this.setState({ parentPost: result });
} else { } else {
@ -93,7 +96,8 @@ class PostContainer extends Component {
author, author,
} = this.state; } = this.state;
if (isHasParentPost && post) this._loadPost(post.parent_author, post.parent_permlink, true); if (isHasParentPost && post)
this._loadPost(get(post, 'parent_author'), get(post, 'parent_permlink'), true);
return ( return (
<PostScreen <PostScreen

View File

@ -210,6 +210,7 @@ class ProfileScreen extends PureComponent {
handleOnScroll={this._handleOnScroll} handleOnScroll={this._handleOnScroll}
forceLoadPost={forceLoadPost} forceLoadPost={forceLoadPost}
changeForceLoadPostState={changeForceLoadPostState} changeForceLoadPostState={changeForceLoadPostState}
isHideReblogOption
/> />
</View> </View>
<View <View

View File

@ -1,6 +1,12 @@
import isEmpty from 'lodash/isEmpty'; import isEmpty from 'lodash/isEmpty';
import forEach from 'lodash/forEach'; import forEach from 'lodash/forEach';
import get from 'lodash/get';
import { postBodySummary, renderPostBody } from '@esteemapp/esteem-render-helpers'; import { postBodySummary, renderPostBody } from '@esteemapp/esteem-render-helpers';
// Dsteem
import { getActiveVotes } from '../providers/steem/dsteem';
// Utils // Utils
import { getReputation } from './reputation'; import { getReputation } from './reputation';
@ -47,7 +53,7 @@ export const parsePost = (post, currentUserName) => {
forEach(post.active_votes, value => { forEach(post.active_votes, value => {
post.vote_perecent = value.voter === currentUserName ? value.percent : null; post.vote_perecent = value.voter === currentUserName ? value.percent : null;
value.value = (value.rshares * ratio).toFixed(3); value.value = (value.rshares * ratio).toFixed(3);
value.reputation = getReputation(value.reputation); value.reputation = getReputation(get(value, 'reputation'));
value.percent /= 100; value.percent /= 100;
value.is_down_vote = Math.sign(value.percent) < 0; value.is_down_vote = Math.sign(value.percent) < 0;
value.avatar = `https://steemitimages.com/u/${value.voter}/avatar/small`; value.avatar = `https://steemitimages.com/u/${value.voter}/avatar/small`;
@ -57,9 +63,6 @@ export const parsePost = (post, currentUserName) => {
return post; return post;
}; };
const isVoted = (activeVotes, currentUserName) =>
activeVotes.some(v => v.voter === currentUserName && v.percent > 0);
const postImage = (metaData, body) => { const postImage = (metaData, body) => {
const imgTagRegex = /(<img[^>]*>)/g; const imgTagRegex = /(<img[^>]*>)/g;
const markdownImageRegex = /!\[[^\]]*\]\((.*?)\s*("(?:.*[^"])")?\s*\)/g; const markdownImageRegex = /!\[[^\]]*\]\((.*?)\s*("(?:.*[^"])")?\s*\)/g;
@ -98,15 +101,31 @@ const postImage = (metaData, body) => {
return ''; return '';
}; };
export const parseComments = comments => { export const parseComments = async (comments, currentUserName) => {
forEach(comments, comment => { const _comments = await comments.map(async comment => {
comment.pending_payout_value = parseFloat(comment.pending_payout_value).toFixed(3); const activeVotes = await getActiveVotes(get(comment, 'author'), get(comment, 'permlink'));
comment.vote_count = comment.active_votes.length;
comment.author_reputation = getReputation(comment.author_reputation); comment.pending_payout_value = parseFloat(
comment.avatar = `https://steemitimages.com/u/${comment.author}/avatar/small`; get(comment, 'pending_payout_value') ? get(comment, 'pending_payout_value') : 0,
comment.markdownBody = comment.body; ).toFixed(3);
comment.author_reputation = getReputation(get(comment, 'author_reputation'));
comment.avatar = `https://steemitimages.com/u/${get(comment, 'author')}/avatar/small`;
comment.markdownBody = get(comment, 'body');
comment.body = renderPostBody(comment); comment.body = renderPostBody(comment);
comment.summary = `"${postBodySummary(comment, 100, true)}"`; comment.active_votes = activeVotes;
comment.vote_count = activeVotes && activeVotes.length;
if (currentUserName && activeVotes && activeVotes.length > 0) {
comment.is_voted = isVoted(activeVotes, currentUserName);
} else {
comment.is_voted = false;
}
return _comments;
}); });
return comments; return comments;
}; };
const isVoted = (activeVotes, currentUserName) =>
activeVotes.some(v => v.voter === currentUserName && v.percent > 0);