created temporary solution && updated for get

This commit is contained in:
u-e 2019-06-18 23:45:26 +03:00
parent 0d76c08de5
commit be799c7fe9
8 changed files with 124 additions and 161 deletions

View File

@ -5,7 +5,6 @@ import { injectIntl } from 'react-intl';
import get from 'lodash/get';
import { getComments, deleteComment } from '../../../providers/steem/dsteem';
import { parseComments } from '../../../utils/postParser';
// Services and Actions
import { writeToClipboard } from '../../../utils/clipboard';
import { toastNotification } from '../../../redux/actions/uiAction';
@ -44,8 +43,8 @@ class CommentsContainer extends Component {
this._getComments();
}
if (selectedFilter !== nextProps.selectedFilter && nextProps.selectedFilter) {
const shortedComments = this._shortComments(nextProps.selectedFilter);
if (selectedFilter !== get(nextProps, 'selectedFilter') && get(nextProps, 'selectedFilter')) {
const shortedComments = this._shortComments(get(nextProps, 'selectedFilter'));
this.setState({ comments: shortedComments });
}
}
@ -81,8 +80,8 @@ class CommentsContainer extends Component {
return 0;
},
REPUTATION: (a, b) => {
const keyA = a.author_reputation;
const keyB = b.author_reputation;
const keyA = get(a, 'author_reputation');
const keyB = get(b, 'author_reputation');
if (keyA > keyB) return -1;
if (keyA < keyB) return 1;
@ -107,8 +106,8 @@ class CommentsContainer extends Component {
return -1;
}
const keyA = Date.parse(a.created);
const keyB = Date.parse(b.created);
const keyA = Date.parse(get(a, 'created'));
const keyB = Date.parse(get(b, 'created'));
if (keyA > keyB) return -1;
if (keyA < keyB) return 1;
@ -128,17 +127,14 @@ class CommentsContainer extends Component {
permlink,
currentAccount: { name },
} = this.props;
let com;
await getComments(author, permlink, name)
.then(async comments => {
com = comments;
this.setState({
comments,
});
})
.catch(() => {});
await this.setState({
comments: await parseComments(com, name),
});
};
_handleOnReplyPress = item => {
@ -223,7 +219,7 @@ class CommentsContainer extends Component {
isShowMoreButton={isShowMoreButton}
commentNumber={commentNumber || 1}
commentCount={commentCount}
comments={parseComments(_comments || comments, currentAccount.name)}
comments={_comments || comments}
currentAccountUsername={currentAccount.name}
handleOnEditPress={this._handleOnEditPress}
handleOnReplyPress={this._handleOnReplyPress}

View File

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

View File

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

View File

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

View File

@ -140,19 +140,20 @@ export const getUser = async user => {
globalProperties.total_vesting_fund_steem,
);
account[0].received_steem_power = await vestToSteem(
account[0].received_vesting_shares,
globalProperties.total_vesting_shares,
globalProperties.total_vesting_fund_steem,
get(account[0], 'received_vesting_shares'),
get(globalProperties, 'total_vesting_shares'),
get(globalProperties, 'total_vesting_fund_steem'),
);
account[0].delegated_steem_power = await vestToSteem(
account[0].delegated_vesting_shares,
globalProperties.total_vesting_shares,
globalProperties.total_vesting_fund_steem,
get(account[0], 'delegated_vesting_shares'),
get(globalProperties, 'total_vesting_shares'),
get(globalProperties, 'total_vesting_fund_steem'),
);
account[0].about = account[0].json_metadata && JSON.parse(account[0].json_metadata);
account[0].avatar = getAvatar(account[0].about);
account[0].display_name = getName(account[0].about);
account[0].about =
get(account[0], 'json_metadata') && JSON.parse(get(account[0], 'json_metadata'));
account[0].avatar = getAvatar(get(account[0], 'about'));
account[0].display_name = getName(get(account[0], 'about'));
return account[0];
} catch (error) {
@ -288,15 +289,17 @@ export const getPosts = async (by, query, user) => {
}
};
export const getActiveVotes = async (author, permlink) => {
if (!author || !permlink) return null;
try {
return await client.database.call('get_active_votes', [author, permlink]);
} catch (error) {
return error;
}
};
export const getActiveVotes = (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) => {
try {
@ -404,45 +407,17 @@ export const deleteComment = (currentAccount, pin, permlink) => {
}
};
/**
* @method getUser get user data
* @param user post author
* @param permlink post permlink
*/
// export const getComments = async (user, permlink, currentUserName) => {
// return new Promise((resolve, reject) => {
// client.database
// .call('get_content_replies', [user, permlink])
// .then(async result => {
// const comments = await parseComments(result, currentUserName);
// resolve(comments);
// })
// .catch(error => {
// reject(error);
// });
// });
// };
// export const getComments = async (user, permlink, currentUserName) => {
// try {
// const comments = client.database.call('get_content_replies', [user, permlink]);
// const groomedComments = await parseComments(comments, currentUserName);
// return groomedComments;
// } catch (error) {
// return error;
// }
// };
const wait = ms => new Promise(r => setTimeout(r, ms));
export const getComments = async (author, permlink, currentUserName = null) => {
try {
const post = await client.database.call('get_content_replies', [author, permlink]);
const comments = await client.database.call('get_content_replies', [author, permlink]);
// const ugur = await getState(`/esteem/@${author}/${permlink}`);
// console.log(post);
// console.log(ugur);
// return post ? await parseComments(post, currentUserName) : null;
return post;
const groomedComments = await parseComments(comments, currentUserName);
// WORK ARROUND
await wait(comments && comments.length * 30);
return comments ? groomedComments : null;
} catch (error) {
return error;
}
@ -548,15 +523,15 @@ export const upvoteAmount = async input => {
export const transferToken = (currentAccount, pin, data) => {
const digitPinCode = getDigitPinCode(pin);
const key = getAnyPrivateKey({ activeKey: currentAccount.local.activeKey }, digitPinCode);
const key = getAnyPrivateKey({ activeKey: get(currentAccount, 'local.activeKey') }, digitPinCode);
if (key) {
const privateKey = PrivateKey.fromString(key);
const args = {
from: data.from,
to: data.destination,
amount: data.amount,
memo: data.memo,
from: get(data, 'from'),
to: get(data, 'destination'),
amount: get(data, 'amount'),
memo: get(data, 'memo'),
};
return new Promise((resolve, reject) => {
@ -564,7 +539,7 @@ export const transferToken = (currentAccount, pin, data) => {
.transfer(args, privateKey)
.then(result => {
if (result) {
transfer(data.from, data.destination, data.ammount);
transfer(get(data, 'from'), get(data, 'destination'), get(data, 'ammount'));
resolve(result);
}
})
@ -579,7 +554,7 @@ export const transferToken = (currentAccount, pin, data) => {
export const transferToSavings = (currentAccount, pin, data) => {
const digitPinCode = getDigitPinCode(pin);
const key = getAnyPrivateKey({ activeKey: currentAccount.local.activeKey }, digitPinCode);
const key = getAnyPrivateKey({ activeKey: get(currentAccount, 'local.activeKey') }, digitPinCode);
if (key) {
const privateKey = PrivateKey.fromString(key);
@ -588,10 +563,10 @@ export const transferToSavings = (currentAccount, pin, data) => {
[
'transfer_to_savings',
{
from: data.from,
to: data.destination,
amount: data.amount,
memo: data.memo,
from: get(data, 'from'),
to: get(data, 'destination'),
amount: get(data, 'amount'),
memo: get(data, 'memo'),
},
],
];
@ -613,7 +588,7 @@ export const transferToSavings = (currentAccount, pin, data) => {
export const transferFromSavings = (currentAccount, pin, data) => {
const digitPinCode = getDigitPinCode(pin);
const key = getAnyPrivateKey({ activeKey: currentAccount.local.activeKey }, digitPinCode);
const key = getAnyPrivateKey({ activeKey: get(currentAccount, 'local.activeKey') }, digitPinCode);
if (key) {
const privateKey = PrivateKey.fromString(key);
@ -621,11 +596,11 @@ export const transferFromSavings = (currentAccount, pin, data) => {
[
'transfer_from_savings',
{
from: data.from,
to: data.destination,
amount: data.amount,
memo: data.memo,
request_id: data.requestId,
from: get(data, 'from'),
to: get(data, 'destination'),
amount: get(data, 'amount'),
memo: get(data, 'memo'),
request_id: get(data, 'requestId'),
},
],
];
@ -647,7 +622,7 @@ export const transferFromSavings = (currentAccount, pin, data) => {
export const transferToVesting = (currentAccount, pin, data) => {
const digitPinCode = getDigitPinCode(pin);
const key = getAnyPrivateKey({ activeKey: currentAccount.local.activeKey }, digitPinCode);
const key = getAnyPrivateKey({ activeKey: get(currentAccount, 'local.activeKey') }, digitPinCode);
if (key) {
const privateKey = PrivateKey.fromString(key);
@ -682,7 +657,7 @@ export const followUser = async (currentAccount, pin, data) => {
const key = getAnyPrivateKey(currentAccount.local, digitPinCode);
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({
accessToken: token,
});
@ -1013,15 +988,15 @@ const _reblog = async (account, pinCode, author, permlink) => {
export const claimRewardBalance = (account, pinCode, rewardSteem, rewardSbd, rewardVests) => {
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) {
const token = decryptKey(account.local.accessToken, pin);
const token = decryptKey(get(account, 'local.accessToken'), pin);
const api = steemConnect.Initialize({
accessToken: token,
});
return api.claimRewardBalance(account.name, rewardSteem, rewardSbd, rewardVests);
return api.claimRewardBalance(get(account, 'name'), rewardSteem, rewardSbd, rewardVests);
}
if (key) {
@ -1047,7 +1022,7 @@ export const claimRewardBalance = (account, pinCode, rewardSteem, rewardSbd, rew
export const transferPoint = (currentAccount, pinCode, data) => {
const pin = getDigitPinCode(pinCode);
const key = getActiveKey(currentAccount.local, pin);
const key = getActiveKey(get(currentAccount, 'local'), pin);
const username = get(currentAccount, 'name');
const json = JSON.stringify({

View File

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

View File

@ -4,7 +4,7 @@ import get from 'lodash/get';
import { postBodySummary, renderPostBody } from '@esteemapp/esteem-render-helpers';
// dsteem
// Dsteem
import { getActiveVotes } from '../providers/steem/dsteem';
// Utils
@ -101,34 +101,30 @@ const postImage = (metaData, body) => {
return '';
};
export const parseComments = (comments, currentUsername) =>
!comments ? null : comments.map(comment => parseComment(comment, currentUsername));
export const parseComments = async (comments, currentUserName) => {
const _comments = await comments.map(async comment => {
const activeVotes = await getActiveVotes(get(comment, 'author'), get(comment, 'permlink'));
export const parseComment = async (comment, currentUsername) => {
if (!comment) {
return null;
}
comment.pending_payout_value = parseFloat(
get(comment, 'pending_payout_value') ? get(comment, 'pending_payout_value') : 0,
).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.active_votes = activeVotes;
comment.vote_count = activeVotes && activeVotes.length;
const activeVotes = await getActiveVotes(get(comment, 'author'), get(comment, 'permlink'));
if (currentUserName && activeVotes && activeVotes.length > 0) {
comment.is_voted = isVoted(activeVotes, currentUserName);
} else {
comment.is_voted = false;
}
comment.pending_payout_value = parseFloat(
get(comment, 'pending_payout_value') ? get(comment, 'pending_payout_value') : 0,
).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.summary = `"${postBodySummary(comment, 100, true)}"`;
comment.active_votes = activeVotes;
comment.vote_count = activeVotes && activeVotes.length;
return _comments;
});
if (currentUsername && activeVotes && activeVotes.length > 0) {
comment.is_voted = isVoted(activeVotes, currentUsername);
} else {
comment.is_voted = false;
}
return comment;
return comments;
};
const isVoted = (activeVotes, currentUserName) =>