porse parser enhanced && upvote component fixed

This commit is contained in:
u-e 2018-12-06 00:38:11 +03:00
parent bfe6cbd43c
commit f8614249cf
18 changed files with 122 additions and 123 deletions

View File

@ -2,6 +2,4 @@ import 'core-js';
import { AppRegistry } from 'react-native';
import { name as appName } from './app.json';
global.Intl = require('intl');
AppRegistry.registerComponent(appName, () => require('./App').default);

View File

@ -36,7 +36,6 @@ class CommentsView extends Component {
avatarSize,
marginLeft,
handleOnUserPress,
currentUser,
commentNumber,
handleOnReplyPress,
isProfilePreview,

View File

@ -29,9 +29,7 @@ class CommentsDisplayView extends Component {
};
render() {
const {
currentUser, author, permlink, commentCount,
} = this.props;
const { author, permlink, commentCount } = this.props;
return (
<Fragment>
@ -44,7 +42,7 @@ class CommentsDisplayView extends Component {
onDropdownSelect={this._handleOnDropdownSelect}
/>
<View style={{ padding: 16 }}>
<Comments currentUser={currentUser} author={author} permlink={permlink} />
<Comments author={author} permlink={permlink} />
</View>
</Fragment>
)}

View File

@ -152,13 +152,14 @@ export default class MarkdownEditorView extends Component {
iconType="FontAwesome"
name="image"
/>
<DropdownButton
{/* TODO: After alpha */}
{/* <DropdownButton
style={styles.dropdownStyle}
options={['option1', 'option2', 'option3', 'option4']}
iconName="md-more"
iconStyle={styles.dropdownIconStyle}
isHasChildIcon
/>
/> */}
</View>
</StickyBar>
);

View File

@ -4,7 +4,6 @@ import {
} from 'react-native';
// import FastImage from 'react-native-fast-image';
import { PostHeaderDescription } from '../../postElements';
import { DropdownButton } from '../../dropdownButton';
import { PostDropdown } from '../../postDropdown';
import { Icon } from '../../icon';
import { LineBreak } from '../../basicUIElements';

View File

@ -53,13 +53,13 @@ class PostDisplayContainer extends Component {
};
render() {
const { post, currentUser } = this.props;
const { post, currentAccount } = this.props;
return (
<PostDisplayView
handleOnVotersPress={this._handleOnVotersPress}
handleOnReplyPress={this._handleOnReplyPress}
currentUser={currentUser}
currentAccount={currentAccount}
post={post}
/>
);

View File

@ -53,7 +53,7 @@ class PostDisplayView extends Component {
_getTabBar = (isFixedFooter = false) => {
const {
post,
currentUser,
currentAccount,
handleOnReplyPress,
handleOnEditPress,
handleOnVotersPress,
@ -80,7 +80,7 @@ class PostDisplayView extends Component {
iconType="FontAwesome"
/>
<View style={styles.stickyRightWrapper}>
{post && currentUser && currentUser.name === post.author && (
{post && currentAccount && currentAccount.name === post.author && (
<IconButton
iconStyle={styles.barIconRight}
style={styles.barIconButton}
@ -103,7 +103,7 @@ class PostDisplayView extends Component {
};
render() {
const { post, currentUser } = this.props;
const { post } = this.props;
const { postHeight, scrollHeight, isLoadedComments } = this.state;
const isPostEnd = scrollHeight > postHeight;
@ -145,7 +145,6 @@ class PostDisplayView extends Component {
</View>
{post && (isGetComment || isLoadedComments) && (
<CommentsDisplay
currentUser={currentUser}
author={post.author}
permlink={post.permlink}
commentCount={post.children}

View File

@ -1,14 +1,6 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
// Services and Actions
// Middleware
// Constants
// Utilities
// Component
import { UpvoteView } from '..';
@ -29,7 +21,32 @@ class UpvoteContainer extends Component {
// Component Functions
render() {
return <UpvoteView {...this.props} />;
const {
content, currentAccount, isLoggedIn, isShowPayoutValue,
} = this.props;
let author;
let isVoted;
let pendingPayoutValue;
let permlink;
if (content) {
author = content.author;
isVoted = content.is_voted;
pendingPayoutValue = content.pending_payout_value;
permlink = content.permlink;
}
return (
<UpvoteView
author={author}
currentAccount={currentAccount}
isLoggedIn={isLoggedIn}
isShowPayoutValue={isShowPayoutValue}
isVoted={isVoted}
pendingPayoutValue={pendingPayoutValue}
permlink={permlink}
/>
);
}
}

View File

@ -1,6 +1,6 @@
import React, { Component, Fragment } from 'react';
import {
View, TouchableOpacity, ActivityIndicator, Text,
View, TouchableOpacity, ActivityIndicator, Text, Alert,
} from 'react-native';
import { Popover, PopoverController } from 'react-native-modal-popover';
import Slider from 'react-native-slider';
@ -28,16 +28,22 @@ class UpvoteView extends Component {
this.state = {
sliderValue: 0.0,
isVoting: false,
isVoted: props.content ? props.content.is_voted : false,
amount: '0.00',
isModalVisible: false,
isVoted: false,
amount: '0.00000',
};
}
// Component Life Cycles
// Component Functions
componentWillReceiveProps(nextProps) {
const { isVoted } = this.props;
if (isVoted !== nextProps.isVoted) {
this.setState({ isVoted: nextProps.isVoted });
}
}
// Component Functions
_calculateEstimatedAmount = async () => {
const { currentAccount } = this.props;
// Calculate total vesting shares
@ -62,7 +68,7 @@ class UpvoteView extends Component {
};
_upvoteContent = async () => {
const { currentAccount, content } = this.props;
const { currentAccount, author, permlink } = this.props;
const { sliderValue } = this.state;
this.setState({
@ -70,25 +76,26 @@ class UpvoteView extends Component {
});
const digitPinCode = await getDigitPinCode();
const postingKey = decryptKey(currentAccount.realm_object.postingKey, digitPinCode);
const postingKey = decryptKey(currentAccount.local.postingKey, digitPinCode);
const _weight = sliderValue ? (sliderValue * 100).toFixed(0) * 100 : 0;
upvote(
{
voter: currentAccount && currentAccount.username,
author: content && content.author,
permlink: content && content.permlink,
weight: sliderValue ? (sliderValue * 100).toFixed(0) * 100 : 0,
author,
permlink,
weight: _weight,
},
postingKey,
)
.then((res) => {
.then(() => {
this.setState({
isVoted: !!sliderValue,
isVoting: false,
});
})
.catch((err) => {
alert(err);
Alert.alert('Failed!', err);
this.setState({
isVoted: false,
isVoting: false,
@ -97,10 +104,17 @@ class UpvoteView extends Component {
};
render() {
const { isLoggedIn, isShowPayoutValue, content } = this.props;
const { isLoggedIn, isShowPayoutValue, pendingPayoutValue } = this.props;
const {
isVoting, isModalVisible, amount, sliderValue, isVoted,
isVoting, amount, sliderValue, isVoted,
} = this.state;
let iconName = 'ios-arrow-dropup';
let iconType;
if (isVoted) {
iconName = 'upcircle';
iconType = 'AntDesign';
}
const _percent = `${(sliderValue * 100).toFixed(0)}%`;
const _amount = `$${amount}`;
@ -124,14 +138,14 @@ class UpvoteView extends Component {
<Icon
style={[styles.upvoteIcon]}
active={!isLoggedIn}
iconType={isVoted && isLoggedIn && 'AntDesign'}
name={isVoted && isLoggedIn ? 'upcircle' : 'ios-arrow-dropup'}
iconType={iconType}
name={iconName}
/>
{isShowPayoutValue && (
<Text style={styles.payoutValue}>
$
{' '}
{content && content.pending_payout_value}
{pendingPayoutValue}
</Text>
)}
</Fragment>

View File

@ -263,13 +263,13 @@ export const getUserComments = async (query) => {
* @method getUser get user data
* @param user post author
* @param permlink post permlink
* @param currentUserName active accounts username
*/
export const getPost = async (user, permlink, currentUser) => {
export const getPost = async (author, permlink, currentUserName) => {
try {
let posts = await client.database.call('get_content', [user, permlink]);
const post = await client.database.call('get_content', [author, permlink]);
posts = await parsePost(posts, user, currentUser);
return posts;
return await parsePost(post, currentUserName);
} catch (error) {
return error;
}
@ -640,7 +640,7 @@ export const postComment = (
opArray.push(e);
}
const key = decryptKey(account.realm_object.postingKey, digitPinCode);
const key = decryptKey(account.local.postingKey, digitPinCode);
const privateKey = PrivateKey.fromString(key);
return new Promise((resolve, reject) => {
@ -657,7 +657,7 @@ export const postComment = (
export const reblog = async (account, author, permlink) => {
const pin = await getDigitPinCode();
const key = decryptKey(account.realm_object.postingKey, pin);
const key = decryptKey(account.local.postingKey, pin);
const privateKey = PrivateKey.fromString(key);
const follower = account.name;

View File

@ -57,9 +57,9 @@ class ApplicationContainer extends Component {
};
componentWillReceiveProps(nextProps) {
const { isDarkTheme, selectedLanguage } = this.props;
const { isDarkTheme: _isDarkTheme, selectedLanguage } = this.props;
if (isDarkTheme !== nextProps.isDarkTheme || selectedLanguage !== nextProps.selectedLanguage) {
if (_isDarkTheme !== nextProps.isDarkTheme || selectedLanguage !== nextProps.selectedLanguage) {
this.setState({ isRenderRequire: false }, () => this.setState({ isRenderRequire: true }));
}
}
@ -71,6 +71,8 @@ class ApplicationContainer extends Component {
if (res.isLoggedIn) {
getUserData().then((response) => {
if (response.length > 0) {
// Initial login
response.forEach((accountData) => {
dispatch(
addOtherAccount({ username: accountData.username, avatar: accountData.avatar }),
@ -78,12 +80,14 @@ class ApplicationContainer extends Component {
});
getUser(response[response.length - 1].username)
.then((accountData) => {
const realmObject = response[response.length - 1];
accountData.realm_object = realmObject;
dispatch(login());
const realmObject = response[response.length - 1];
accountData.local = realmObject;
dispatch(updateCurrentAccount(accountData));
dispatch(activeApplication());
// If in dev mode pin code does not show
if (__DEV__ === false) {
dispatch(openPinCodeModal());
}

View File

@ -138,7 +138,7 @@ class EditorContainer extends Component {
// For new image api
// const { currentAccount } = this.props;
// const digitPinCode = await getDigitPinCode();
// const privateKey = decryptKey(currentAccount.realm_object.postingKey, digitPinCode);
// const privateKey = decryptKey(currentAccount.local.postingKey, digitPinCode);
// const sign = generateSignature(media, privateKey);
// const data = new Buffer(media.data, 'base64');
};
@ -208,7 +208,7 @@ class EditorContainer extends Component {
const permlink = generatePermlink(fields.title);
const digitPinCode = await getDigitPinCode();
const postingKey = decryptKey(currentAccount.realm_object.postingKey, digitPinCode);
const postingKey = decryptKey(currentAccount.local.postingKey, digitPinCode);
const post = {
...fields,

View File

@ -1,5 +1,5 @@
import React, { PureComponent, Fragment } from 'react';
import { View, Alert } from 'react-native';
import { View } from 'react-native';
import ScrollableTabView from '@esteemapp/react-native-scrollable-tab-view';
import { injectIntl } from 'react-intl';
@ -19,9 +19,7 @@ class HomeScreen extends PureComponent {
}
render() {
const {
componentId, isLoggedIn, currentAccount, intl,
} = this.props;
const { isLoggedIn, currentAccount, intl } = this.props;
const _filterOptions = [
'FEED',
'TRENDING',
@ -33,12 +31,17 @@ class HomeScreen extends PureComponent {
'COMMENTS',
'PAYOUT',
];
let tag;
if (!isLoggedIn || (!currentAccount && !currentAccount.name)) {
tag = 'esteemapp';
}
return (
<Fragment>
<Header />
<View style={styles.container} key="overlay">
<View style={styles.container}>
<ScrollableTabView
style={styles.tabView}
renderTabBar={() => (
@ -59,10 +62,9 @@ class HomeScreen extends PureComponent {
<Posts
filterOptions={_filterOptions}
getFor="feed"
tag={isLoggedIn ? currentAccount.name : 'esteemapp'}
tag={tag || currentAccount.name}
user={currentAccount}
isLoggedIn={isLoggedIn}
componentId={componentId}
/>
</View>
<View
@ -76,7 +78,6 @@ class HomeScreen extends PureComponent {
getFor="trending"
user={currentAccount}
isLoggedIn={isLoggedIn}
componentId={componentId}
/>
</View>
</ScrollableTabView>

View File

@ -27,6 +27,7 @@ export default EStyleSheet.create({
informationView: {
flex: 1,
alignItems: 'center',
color: '$primaryBlack',
},
animatedView: {
flex: 1,

View File

@ -1,23 +1,17 @@
import React, { Component } from 'react';
// import { connect } from 'react-redux';
import { connect } from 'react-redux';
// Services and Actions
import { getUserData, getAuthStatus } from '../../../realm/realm';
import { getPost, getUser } from '../../../providers/steem/dsteem';
import { getPost } from '../../../providers/steem/dsteem';
// Middleware
// Constants
// Utilities
// Component
import { PostScreen } from '..';
/*
* Props Name Description Value
*@props --> content which is include all post data Object
*
*/
* Props Name Description Value
*@props --> content which is include all post data Object
*
*/
class PostContainer extends Component {
constructor(props) {
@ -25,25 +19,23 @@ class PostContainer extends Component {
this.state = {
post: null,
error: null,
currentUser: null,
};
}
// Component Life Cycle Functions
componentDidMount() {
async componentDidMount() {
const { navigation } = this.props;
const { author, permlink } = navigation.state && navigation.state.params;
this._loadPost(author, permlink);
this._getUser();
await this._loadPost(author, permlink);
}
// Component Functions
_loadPost = (author, permlink) => {
const { currentUser } = this.state;
// TODO: get from redux for cureentUser
getPost(author, permlink, currentUser && currentUser.name)
_loadPost = async (author, permlink) => {
const { currentAccount } = this.props;
await getPost(author, permlink, currentAccount && currentAccount.name)
.then((result) => {
if (result) {
this.setState({ post: result });
@ -54,35 +46,16 @@ class PostContainer extends Component {
});
};
async _getUser() {
let _currentUser;
let userData;
let isLoggedIn;
await getAuthStatus().then((res) => {
isLoggedIn = res.isLoggedIn;
});
if (isLoggedIn) {
await getUserData().then((res) => {
_currentUser = Array.from(res);
});
userData = _currentUser && (await getUser(_currentUser[0].username));
await this.setState({
currentUser: userData,
});
}
}
render() {
const { post, error, currentUser } = this.state;
const { currentAccount } = this.props;
const { post, error } = this.state;
return (
<PostScreen currentUser={currentUser} key={Math.random * 100} post={post} error={error} />
);
return <PostScreen currentAccount={currentAccount} post={post} error={error} />;
}
}
export default PostContainer;
const mapStateToProps = state => ({
currentAccount: state.account.currentAccount,
});
export default connect(mapStateToProps)(PostContainer);

View File

@ -23,7 +23,7 @@ class PostScreen extends Component {
// Component Functions
render() {
const { post, currentUser } = this.props;
const { post, currentAccount } = this.props;
return (
<Fragment>
@ -33,7 +33,7 @@ class PostScreen extends Component {
content={post}
dropdownComponent={<PostDropdown content={post} />}
/>
<PostDisplay post={post} currentUser={currentUser} />
<PostDisplay post={post} currentAccount={currentAccount} />
</Fragment>
);
}

View File

@ -84,7 +84,7 @@ class ProfileContainer extends Component {
const { currentAccount } = this.props;
const digitPinCode = await getDigitPinCode();
const privateKey = decryptKey(currentAccount.realm_object.postingKey, digitPinCode);
const privateKey = decryptKey(currentAccount.local.postingKey, digitPinCode);
this.setState({
isProfileLoading: true,
@ -102,7 +102,7 @@ class ProfileContainer extends Component {
const { currentAccount } = this.props;
const digitPinCode = await getDigitPinCode();
const privateKey = decryptKey(currentAccount.realm_object.postingKey, digitPinCode);
const privateKey = decryptKey(currentAccount.local.postingKey, digitPinCode);
this.setState({
isProfileLoading: true,

View File

@ -131,7 +131,7 @@ export const parsePostsSummary = (posts, currentUser) => {
return posts;
};
export const parsePost = (post, currentUser) => {
export const parsePost = (post, currentUserName) => {
post.json_metadata = JSON.parse(post.json_metadata);
post.json_metadata.image ? (post.image = post.json_metadata.image[0]) : '';
post.pending_payout_value = parseFloat(post.pending_payout_value).toFixed(2);
@ -152,7 +152,7 @@ export const parsePost = (post, currentUser) => {
post.is_voted = false;
for (const i in post.active_votes) {
if (post.active_votes[i].voter === currentUser && post.active_votes[i].percent > 0) {
if (post.active_votes[i].voter === currentUserName && post.active_votes[i].percent > 0) {
post.is_voted = true;
}
post.active_votes[i].value = (post.active_votes[i].rshares * ratio).toFixed(2);
@ -162,16 +162,11 @@ export const parsePost = (post, currentUser) => {
}/avatar/small`;
}
if (post.active_votes.length > 2) {
post.top_likers = [
post.active_votes[0].voter,
post.active_votes[1].voter,
post.active_votes[2].voter,
];
}
return post;
};
const groomVotes = (activeVotes, currentUserName) => {};
export const protocolUrl2Obj = (url) => {
let urlPart = url.split('://')[1];