From 10e7be6da39a4391dd725498ab4f64e93e49a3cc Mon Sep 17 00:00:00 2001 From: u-e Date: Sun, 2 Dec 2018 19:21:14 +0300 Subject: [PATCH] first reply succesuflly shared --- src/components/comments/view/commentsView.js | 2 +- .../titleArea/view/titleAreaView.js | 11 +- .../markdownEditor/view/markdownEditorView.js | 2 +- src/components/postCard/view/postCardView.js | 2 +- .../postView/view/postDisplayView.js | 2 +- .../upvote/container/upvoteContainer.js | 21 ++-- src/components/upvote/view/upvoteView.js | 4 +- src/providers/steem/dsteem.js | 100 +++++++++++++----- .../editor/container/editorContainer.js | 69 +++++++++--- src/screens/editor/screen/editorScreen.js | 37 ++++--- src/utils/editor.js | 17 ++- 11 files changed, 180 insertions(+), 87 deletions(-) diff --git a/src/components/comments/view/commentsView.js b/src/components/comments/view/commentsView.js index fb9e60e1e..c0c756979 100644 --- a/src/components/comments/view/commentsView.js +++ b/src/components/comments/view/commentsView.js @@ -67,7 +67,7 @@ class CommentsView extends Component { > - + this._handleOnChange(text)} - value={value} - {...this.props} + // TODO: Fix it + // value={value && value} + // {...this.props} /> ); diff --git a/src/components/markdownEditor/view/markdownEditorView.js b/src/components/markdownEditor/view/markdownEditorView.js index 9402bace9..9085c8e7b 100644 --- a/src/components/markdownEditor/view/markdownEditorView.js +++ b/src/components/markdownEditor/view/markdownEditorView.js @@ -1,6 +1,6 @@ import React, { Component } from 'react'; import { - View, KeyboardAvoidingView, ScrollView, FlatList, Text, + View, KeyboardAvoidingView, ScrollView, FlatList, Text, ActionSheetIOS } from 'react-native'; import Markdown, { getUniqueID } from 'react-native-markdown-renderer'; diff --git a/src/components/postCard/view/postCardView.js b/src/components/postCard/view/postCardView.js index 1532f2dfc..12eb82117 100644 --- a/src/components/postCard/view/postCardView.js +++ b/src/components/postCard/view/postCardView.js @@ -105,7 +105,7 @@ class PostCard extends Component { - + this._handleOnVotersPress()} diff --git a/src/components/postView/view/postDisplayView.js b/src/components/postView/view/postDisplayView.js index 3540fb2d3..c68824669 100644 --- a/src/components/postView/view/postDisplayView.js +++ b/src/components/postView/view/postDisplayView.js @@ -62,7 +62,7 @@ class PostDisplayView extends Component { return ( - + props name here description here Value Type Here - * - */ + * Props Name Description Value + *@props --> props name here description here Value Type Here + * + */ class UpvoteContainer extends Component { constructor(props) { @@ -33,8 +33,11 @@ class UpvoteContainer extends Component { } } -// const mapStateToProps = state => ({ -// user: state.user.user, -// }); +const mapStateToProps = state => ({ + isLoggedIn: state.application.isLoggedIn, -export default UpvoteContainer; + // TODO: Remove users as coming props. pass follow current account + currentAccount: state.account.currentAccount, +}); + +export default connect(mapStateToProps)(UpvoteContainer); diff --git a/src/components/upvote/view/upvoteView.js b/src/components/upvote/view/upvoteView.js index e4eb05945..0c9ba4bba 100644 --- a/src/components/upvote/view/upvoteView.js +++ b/src/components/upvote/view/upvoteView.js @@ -106,7 +106,7 @@ class UpvoteView extends Component { }; render() { - const { isLoggedIn, isShowpayoutValue, content } = this.props; + const { isLoggedIn, isShowPayoutValue, content } = this.props; const { isVoting, isModalVisible, amount, value, isVoted, } = this.state; @@ -136,7 +136,7 @@ class UpvoteView extends Component { iconType="AntDesign" name={isVoted ? 'upcircle' : 'upcircleo'} /> - {isShowpayoutValue && ( + {isShowPayoutValue && ( $ {' '} diff --git a/src/providers/steem/dsteem.js b/src/providers/steem/dsteem.js index 131895b66..b6918a41c 100644 --- a/src/providers/steem/dsteem.js +++ b/src/providers/steem/dsteem.js @@ -7,6 +7,10 @@ import { Client, PrivateKey } from 'dsteem'; import { AsyncStorage } from 'react-native'; import { getUnreadActivityCount } from '../esteem/esteem'; +import sc2 from './steemConnectAPI'; + +// Utils +import { decryptKey } from '../../utils/crypto'; import { parsePosts, parsePost, parseComments, parsePostsSummary, @@ -90,10 +94,11 @@ export const getUser = async (user) => { } }; -//TODO: Move to utils folder -export const vestToSteem = async (vestingShares, totalVestingShares, totalVestingFundSteem) => { - return (parseFloat(totalVestingFundSteem) * (parseFloat(vestingShares) / parseFloat(totalVestingShares))).toFixed(0); -} +// TODO: Move to utils folder +export const vestToSteem = async (vestingShares, totalVestingShares, totalVestingFundSteem) => ( + parseFloat(totalVestingFundSteem) + * (parseFloat(vestingShares) / parseFloat(totalVestingShares)) +).toFixed(0); /** * @method getFollows get account data @@ -248,7 +253,6 @@ export const getUserComments = async (query) => { try { let comments = await client.database.getDiscussions('comments', query); comments = parseComments(comments); - console.log(comments); return comments; } catch (error) { return error; @@ -356,25 +360,6 @@ export const upvoteAmount = async (input) => { return estimated; }; -/** - * @method postComment post a comment/reply - * @param comment comment object { author, permlink, ... } - * @param PrivateKey Private posting key - */ -export const postComment = (comment, postingKey) => { - const key = PrivateKey.fromString(postingKey); - return new Promise((resolve, reject) => { - try { - client.broadcast.comment(comment, key).then((result) => { - resolve(result); - }); - } catch (error) { - console.log(error); - reject(error); - } - }); -}; - export const transferToken = (data, activeKey) => { const key = PrivateKey.fromString(activeKey); return new Promise((resolve, reject) => { @@ -624,3 +609,70 @@ export const lookupAccounts = async (username) => { throw error; } }; + +/** + * @method postComment post a comment/reply + * @param comment comment object { author, permlink, ... } + */ +export const postComment = ( + account, + digitPinCode, + parentAuthor, + parentPermlink, + permlink, + title, + body, + jsonMetadata, + options = null, + voteWeight = null, +) => { + const { name: author } = account; + + const opArray = [ + [ + 'comment', + { + parent_author: parentAuthor, + parent_permlink: parentPermlink, + author, + permlink, + title, + body, + json_metadata: JSON.stringify(jsonMetadata), + }, + ], + ]; + + if (options) { + const e = ['comment_options', options]; + opArray.push(e); + } + + if (voteWeight) { + const e = [ + 'vote', + { + voter: author, + author, + permlink, + weight: voteWeight, + }, + ]; + opArray.push(e); + } + + const key = decryptKey(account.realm_object.postingKey, digitPinCode); + const privateKey = PrivateKey.fromString(key); + + return new Promise((resolve, reject) => { + client.broadcast + .sendOperations(opArray, privateKey) + .then((result) => { + resolve(result); + }) + .catch((error) => { + console.log(error); + reject(error); + }); + }); +}; diff --git a/src/screens/editor/container/editorContainer.js b/src/screens/editor/container/editorContainer.js index b7a33f4fb..d81413f66 100644 --- a/src/screens/editor/container/editorContainer.js +++ b/src/screens/editor/container/editorContainer.js @@ -5,7 +5,7 @@ import ImagePicker from 'react-native-image-crop-picker'; // Services and Actions // import { Buffer } from 'buffer'; import { uploadImage } from '../../../providers/esteem/esteem'; -import { postContent } from '../../../providers/steem/dsteem'; +import { postContent, postComment } from '../../../providers/steem/dsteem'; import { setDraftPost, getDraftPost } from '../../../realm/realm'; import { getDigitPinCode } from '../../../providers/steem/auth'; @@ -73,13 +73,6 @@ class EditorContainer extends Component { this.setState({ autoFocusText: true }); } - // Routing action state ex if coming for video or image or only text - // if (routingAction && routingAction.action) { - // this._handleRoutingAction(routingAction.action); - // } else { - // this.setState({ autoFocusText: true }); - // } - if (!isReply) { getDraftPost(username) .then((result) => { @@ -206,15 +199,16 @@ class EditorContainer extends Component { }; _submitPost = async (fields) => { - this.setState({ isPostSending: true }); - const { navigation, currentAccount } = this.props; - const permlink = generatePermlink(fields.title); - const digitPinCode = await getDigitPinCode(); - - const postingKey = decryptKey(currentAccount.realm_object.postingKey, digitPinCode); if (currentAccount) { + this.setState({ isPostSending: true }); + + const permlink = generatePermlink(fields.title); + const digitPinCode = await getDigitPinCode(); + + const postingKey = decryptKey(currentAccount.realm_object.postingKey, digitPinCode); + const post = { ...fields, permlink, @@ -233,8 +227,53 @@ class EditorContainer extends Component { } }; + _submitReply = async (fields) => { + const { navigation, currentAccount } = this.props; + + if (currentAccount) { + this.setState({ isPostSending: true }); + + const { post } = this.state; + + const jsonMeta = makeJsonMetadataReply(post.json_metadata.tags || ['esteem']); + const permlink = generateReplyPermlink(post.author); + const digitPinCode = await getDigitPinCode(); + const author = currentAccount.name; + const options = makeOptions(author, permlink); + const parentAuthor = post.author; + const parentPermlink = post.permlink; + + await postComment( + currentAccount, + digitPinCode, + parentAuthor, + parentPermlink, + permlink, + '', + fields.body, + jsonMeta, + options, + 0, + ) + .then((result) => { + alert('Your post succesfully shared'); + navigation.goBack(); + }) + .catch((error) => { + alert(`Opps! there is a problem${error}`); + this.setState({ isPostSending: false }); + }); + } + }; + _handleSubmit = (form) => { - this._submitPost(form); + const { isReply } = this.state; + + if (isReply) { + this._submitReply(form.fields); + } else { + this._submitPost(form); + } }; _handleFormChanged = () => { diff --git a/src/screens/editor/screen/editorScreen.js b/src/screens/editor/screen/editorScreen.js index 7f9c7aa47..f836269ba 100644 --- a/src/screens/editor/screen/editorScreen.js +++ b/src/screens/editor/screen/editorScreen.js @@ -85,15 +85,21 @@ class EditorScreen extends Component { _handleIsFormValid = () => { const { fields } = this.state; + const { isReply } = this.props; + let _isFormValid; - this.setState({ - isFormValid: - fields.title + if (isReply) { + _isFormValid = fields && fields.body && fields.body.length > 0; + } else { + _isFormValid = fields + && fields.title && fields.title.length > 0 && fields.body && fields.body.length > 0 - && fields.tags.length > 0, - }); + && fields.tags.length > 0; + } + + this.setState({ isFormValid: _isFormValid }); }; _handleFormUpdate = (componentID, content) => { @@ -161,18 +167,15 @@ class EditorScreen extends Component { isFormValid={isFormValid} isPreviewActive={isPreviewActive} > - {isReply ? ( - - ) : ( - - - - + {isReply && } + {!isReply && } + {!isReply && ( + )}