From 5fddf312b64d75d6f4681e1b396cfa365d6c3d56 Mon Sep 17 00:00:00 2001 From: ue Date: Fri, 26 Oct 2018 15:34:45 +0300 Subject: [PATCH 1/6] added stack navigation && enhanced profile routing --- .../header/container/headerContainer.js | 2 +- src/components/postCard/view/postCardView.js | 6 ++- .../profileSummary/view/profileSummaryView.js | 2 +- .../sideMenu/view/sideMenuStyles.js | 2 +- src/config/routes.js | 38 +++++++++++++++---- 5 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/components/header/container/headerContainer.js b/src/components/header/container/headerContainer.js index 63c9acaf5..fe8ce2244 100644 --- a/src/components/header/container/headerContainer.js +++ b/src/components/header/container/headerContainer.js @@ -37,7 +37,7 @@ class HeaderContainer extends Component { _handleOnPressBackButton = () => { const { navigation } = this.props; - navigation.navigate('HomeScreen'); + navigation.goBack(); }; render() { diff --git a/src/components/postCard/view/postCardView.js b/src/components/postCard/view/postCardView.js index a0c889d9e..03cd817f1 100644 --- a/src/components/postCard/view/postCardView.js +++ b/src/components/postCard/view/postCardView.js @@ -145,7 +145,11 @@ class PostCard extends Component { - {content.author} + this._handleOnUserPress()} + > + {content.author} + {content.author_reputation} diff --git a/src/components/profileSummary/view/profileSummaryView.js b/src/components/profileSummary/view/profileSummaryView.js index 06e0bd8d6..5093d69b7 100644 --- a/src/components/profileSummary/view/profileSummaryView.js +++ b/src/components/profileSummary/view/profileSummaryView.js @@ -61,7 +61,7 @@ class ProfileSummaryView extends Component { : null; const isColumn = rowLength && DEVICE_WIDTH / rowLength <= 15; - + return ( diff --git a/src/components/sideMenu/view/sideMenuStyles.js b/src/components/sideMenu/view/sideMenuStyles.js index 0ed67b84b..cee57154d 100644 --- a/src/components/sideMenu/view/sideMenuStyles.js +++ b/src/components/sideMenu/view/sideMenuStyles.js @@ -59,7 +59,7 @@ export default EStyleSheet.create({ }, buttonText: { fontSize: 18, - fontFamily: '$primaryFontFamily', + fontFamily: '$primaryFont', textAlign: 'center', margin: 10, color: '$white', diff --git a/src/config/routes.js b/src/config/routes.js index 67d4266e3..35531e4e9 100644 --- a/src/config/routes.js +++ b/src/config/routes.js @@ -1,4 +1,4 @@ -import { DrawerNavigator, SwitchNavigator } from 'react-navigation'; +import { DrawerNavigator, SwitchNavigator, createStackNavigator } from 'react-navigation'; import { BaseNavigator } from '../navigation'; import { default as ROUTES } from '../constants/routeNames'; @@ -14,9 +14,6 @@ const mainNavigation = DrawerNavigator( { [ROUTES.SCREENS.HOME]: { screen: BaseNavigator, - navigationOptions: { - header: () => null, - }, }, }, { @@ -24,12 +21,39 @@ const mainNavigation = DrawerNavigator( }, ); +const stackNavigatior = createStackNavigator( + { + [ROUTES.DRAWER.MAIN]: { + screen: mainNavigation, + navigationOptions: { + header: () => null, + }, + }, + + [ROUTES.SCREENS.PROFILE]: { + screen: Profile, + navigationOptions: { + header: () => null, + }, + }, + [ROUTES.SCREENS.EDITOR]: { + screen: Editor, + navigationOptions: { + header: () => null, + }, + }, + }, + { + cardStyle: { + backgroundColor: 'white', + }, + }, +); + export default SwitchNavigator({ - [ROUTES.DRAWER.MAIN]: mainNavigation, - [ROUTES.SCREENS.EDITOR]: { screen: Editor }, + stackNavigatior, [ROUTES.SCREENS.LOGIN]: { screen: Login }, [ROUTES.SCREENS.PINCODE]: { screen: PinCode }, - [ROUTES.SCREENS.PROFILE]: { screen: Profile }, [ROUTES.SCREENS.SPLASH]: { screen: Splash }, [ROUTES.SCREENS.STEEM_CONNECT]: { screen: SteemConnect }, }); From 606e5397a78f707e1b732a0e9dd01610de79cb0f Mon Sep 17 00:00:00 2001 From: ue Date: Fri, 26 Oct 2018 16:09:04 +0300 Subject: [PATCH 2/6] fixed upvote bug --- src/components/postCard/view/postCardView.js | 10 +++++----- src/components/sideMenu/view/sideMenuStyles.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/postCard/view/postCardView.js b/src/components/postCard/view/postCardView.js index a0c889d9e..be10429e3 100644 --- a/src/components/postCard/view/postCardView.js +++ b/src/components/postCard/view/postCardView.js @@ -26,7 +26,6 @@ class PostCard extends Component { */ constructor(props) { super(props); - this.upvoteContent = this.upvoteContent.bind(this); this.calculateEstimatedAmount = this.calculateEstimatedAmount.bind(this); this.state = { @@ -42,7 +41,7 @@ class PostCard extends Component { componentDidMount() { const { isLoggedIn } = this.props; - isLoggedIn && this.calculateEstimatedAmount(); + true && this.calculateEstimatedAmount(); } // Component Functions @@ -68,20 +67,21 @@ class PostCard extends Component { }; upvoteContent = async () => { - const { isLoggedIn, user, content } = this.prop; + alert("ugur"); + const { isLoggedIn, user, content } = this.props; const { value } = this.state; let postingKey; let userData; - if (isLoggedIn) { + if (true) { await this.setState({ isVoting: true, }); await getUserData().then((result) => { userData = Array.from(result); - postingKey = decryptKey(userData[0].postingKey, 'pinCode'); + postingKey = decryptKey(userData[0].postingKey, '1234'); }); upvote( { diff --git a/src/components/sideMenu/view/sideMenuStyles.js b/src/components/sideMenu/view/sideMenuStyles.js index 0ed67b84b..cee57154d 100644 --- a/src/components/sideMenu/view/sideMenuStyles.js +++ b/src/components/sideMenu/view/sideMenuStyles.js @@ -59,7 +59,7 @@ export default EStyleSheet.create({ }, buttonText: { fontSize: 18, - fontFamily: '$primaryFontFamily', + fontFamily: '$primaryFont', textAlign: 'center', margin: 10, color: '$white', From 11994929469f11b32052e169f663dc19fd30993b Mon Sep 17 00:00:00 2001 From: ue Date: Fri, 26 Oct 2018 16:23:35 +0300 Subject: [PATCH 3/6] created structure for upvote --- .../view/profileSummaryStyles.js | 4 ++ .../upvote/container/upvoteContainer.js | 43 +++++++++++++++++++ src/components/upvote/index.js | 5 +++ src/components/upvote/view/upvoteStyles.js | 7 +++ src/components/upvote/view/upvoteView.js | 36 ++++++++++++++++ 5 files changed, 95 insertions(+) create mode 100644 src/components/upvote/container/upvoteContainer.js create mode 100644 src/components/upvote/index.js create mode 100644 src/components/upvote/view/upvoteStyles.js create mode 100644 src/components/upvote/view/upvoteView.js diff --git a/src/components/profileSummary/view/profileSummaryStyles.js b/src/components/profileSummary/view/profileSummaryStyles.js index bfd03f08a..c1cc653f6 100644 --- a/src/components/profileSummary/view/profileSummaryStyles.js +++ b/src/components/profileSummary/view/profileSummaryStyles.js @@ -5,6 +5,10 @@ export default EStyleSheet.create({ justifyContent: 'center', flexDirection: 'row', }, + textWithIconWrapperColumn: { + justifyContent: 'center', + flexDirection: 'column', + }, longImage: { borderRadius: 5, height: 60, diff --git a/src/components/upvote/container/upvoteContainer.js b/src/components/upvote/container/upvoteContainer.js new file mode 100644 index 000000000..af7ff73a6 --- /dev/null +++ b/src/components/upvote/container/upvoteContainer.js @@ -0,0 +1,43 @@ +import React, { Component } from 'react'; +import { connect } from 'react-redux'; + +// Services and Actions + +// Middleware + +// Constants + +// Utilities + +// Component +import { ExampleView } from '..'; + +/* + * Props Name Description Value + *@props --> props name here description here Value Type Here + * + */ + +class ExampleContainer extends Component { + constructor(props) { + super(props); + this.state = {}; + } + + // Component Life Cycle Functions + + // Component Functions + + render() { + // eslint-disable-next-line + const { } = this.props; + + return ; + } +} + +const mapStateToProps = state => ({ + user: state.user.user, +}); + +export default connect(mapStateToProps)(ExampleContainer); diff --git a/src/components/upvote/index.js b/src/components/upvote/index.js new file mode 100644 index 000000000..bac89d864 --- /dev/null +++ b/src/components/upvote/index.js @@ -0,0 +1,5 @@ +import ExampleView from './view/exampleView'; +import ExampleContainer from './container/exampleContainer'; + +export { ExampleView, ExampleContainer }; +export default ExampleContainer; diff --git a/src/components/upvote/view/upvoteStyles.js b/src/components/upvote/view/upvoteStyles.js new file mode 100644 index 000000000..7e2389661 --- /dev/null +++ b/src/components/upvote/view/upvoteStyles.js @@ -0,0 +1,7 @@ +import EStyleSheet from 'react-native-extended-stylesheet'; + +export default EStyleSheet.create({ + styleName: { + // TODO: If we need default style. We can put there. + }, +}); diff --git a/src/components/upvote/view/upvoteView.js b/src/components/upvote/view/upvoteView.js new file mode 100644 index 000000000..58c77974a --- /dev/null +++ b/src/components/upvote/view/upvoteView.js @@ -0,0 +1,36 @@ +import React, { Component } from 'react'; +import {} from 'react-native'; + +// Constants + +// Components + +// Styles +// eslint-disable-next-line +import styles from './_styles'; + +class ExampleView extends Component { + /* Props + * ------------------------------------------------ + * @prop { type } name - Description.... + */ + + constructor(props) { + super(props); + this.state = {}; + } + + // Component Life Cycles + + // Component Functions + + render() { + // eslint-disable-next-line + const {} = this.props; + + // eslint-disable-next-line + return ; + } +} + +export default ExampleView; From f35bd026741bb4b02fd155fabb9562bac2aa30b1 Mon Sep 17 00:00:00 2001 From: ue Date: Sat, 27 Oct 2018 20:59:35 +0300 Subject: [PATCH 4/6] created popover slider for upvote and created new upvote component --- src/components/postCard/view/postCardView.js | 13 +- .../upvote/container/upvoteContainer.js | 19 +- src/components/upvote/index.js | 8 +- src/components/upvote/view/upvoteStyles.js | 57 +++++- src/components/upvote/view/upvoteView.js | 170 ++++++++++++++++-- 5 files changed, 230 insertions(+), 37 deletions(-) diff --git a/src/components/postCard/view/postCardView.js b/src/components/postCard/view/postCardView.js index be10429e3..0eac0d829 100644 --- a/src/components/postCard/view/postCardView.js +++ b/src/components/postCard/view/postCardView.js @@ -13,7 +13,7 @@ import Slider from 'react-native-slider'; import { upvote, upvoteAmount } from '../../../providers/steem/dsteem'; import { decryptKey } from '../../../utils/crypto'; import { getUserData } from '../../../realm/realm'; - +import { Upvote } from '../../upvote'; // Styles import styles from './postCardStyles'; @@ -67,7 +67,7 @@ class PostCard extends Component { }; upvoteContent = async () => { - alert("ugur"); + alert('ugur'); const { isLoggedIn, user, content } = this.props; const { value } = this.state; @@ -138,9 +138,7 @@ class PostCard extends Component { - this._handleOnUserPress()} - > + this._handleOnUserPress()}> @@ -179,7 +177,8 @@ class PostCard extends Component { - + + {/* {({ openPopover, closePopover, @@ -279,7 +278,7 @@ $ )} - + */} $ diff --git a/src/components/upvote/container/upvoteContainer.js b/src/components/upvote/container/upvoteContainer.js index af7ff73a6..cf6418974 100644 --- a/src/components/upvote/container/upvoteContainer.js +++ b/src/components/upvote/container/upvoteContainer.js @@ -1,5 +1,5 @@ import React, { Component } from 'react'; -import { connect } from 'react-redux'; +// import { connect } from 'react-redux'; // Services and Actions @@ -10,7 +10,7 @@ import { connect } from 'react-redux'; // Utilities // Component -import { ExampleView } from '..'; +import { UpvoteView } from '..'; /* * Props Name Description Value @@ -18,7 +18,7 @@ import { ExampleView } from '..'; * */ -class ExampleContainer extends Component { +class UpvoteContainer extends Component { constructor(props) { super(props); this.state = {}; @@ -29,15 +29,12 @@ class ExampleContainer extends Component { // Component Functions render() { - // eslint-disable-next-line - const { } = this.props; - - return ; + return ; } } -const mapStateToProps = state => ({ - user: state.user.user, -}); +// const mapStateToProps = state => ({ +// user: state.user.user, +// }); -export default connect(mapStateToProps)(ExampleContainer); +export default UpvoteContainer; diff --git a/src/components/upvote/index.js b/src/components/upvote/index.js index bac89d864..ce27e0a66 100644 --- a/src/components/upvote/index.js +++ b/src/components/upvote/index.js @@ -1,5 +1,5 @@ -import ExampleView from './view/exampleView'; -import ExampleContainer from './container/exampleContainer'; +import UpvoteView from './view/upvoteView'; +import Upvote from './container/upvoteContainer'; -export { ExampleView, ExampleContainer }; -export default ExampleContainer; +export { UpvoteView, Upvote }; +export default Upvote; diff --git a/src/components/upvote/view/upvoteStyles.js b/src/components/upvote/view/upvoteStyles.js index 7e2389661..0f96c8fbb 100644 --- a/src/components/upvote/view/upvoteStyles.js +++ b/src/components/upvote/view/upvoteStyles.js @@ -1,7 +1,60 @@ import EStyleSheet from 'react-native-extended-stylesheet'; export default EStyleSheet.create({ - styleName: { - // TODO: If we need default style. We can put there. + upvoteButton: { + flexDirection: 'row', + alignSelf: 'center', + }, + upvoteIcon: { + alignSelf: 'flex-start', + fontSize: 22, + color: '$primaryBlue', + }, + popover: { + flexDirection: 'row', + width: '$deviceWidth - 20', + borderRadius: '$deviceWidth - 20 / 2', + paddingHorizontal: 16, + backgroundColor: '$white', + height: 48, + }, + track: { + height: 2, + borderRadius: 1, + }, + thumb: { + width: 16, + height: 16, + borderRadius: 16 / 2, + backgroundColor: '$white', + shadowColor: 'black', + shadowOffset: { width: 0, height: 2 }, + shadowRadius: 2, + shadowOpacity: 0.35, + }, + amount: { + fontSize: 10, + color: '$primaryDarkGray', + marginLeft: 8, + }, + percent: { + width: 40, + color: '$primaryDarkGray', + }, + slider: { + flex: 1, + marginHorizontal: 10, + }, + popoverWrapper: { + flex: 1, + flexDirection: 'row', + justifyContent: 'space-between', + alignItems: 'center', + }, + arrow: { + borderTopColor: 'transparent', + }, + overlay: { + backgroundColor: '#403c4449', }, }); diff --git a/src/components/upvote/view/upvoteView.js b/src/components/upvote/view/upvoteView.js index 58c77974a..8a7f20bf0 100644 --- a/src/components/upvote/view/upvoteView.js +++ b/src/components/upvote/view/upvoteView.js @@ -1,15 +1,21 @@ -import React, { Component } from 'react'; -import {} from 'react-native'; - +import React, { Component, Fragment } from 'react'; +import { View, TouchableOpacity, ActivityIndicator, Text } from 'react-native'; +import { Popover, PopoverController } from 'react-native-modal-popover'; +import Slider from 'react-native-slider'; // Constants // Components +import { Icon } from '../../icon'; + +// STEEM +import { upvote, upvoteAmount } from '../../../providers/steem/dsteem'; +import { decryptKey } from '../../../utils/crypto'; +import { getUserData } from '../../../realm/realm'; // Styles -// eslint-disable-next-line -import styles from './_styles'; +import styles from './upvoteStyles'; -class ExampleView extends Component { +class UpvoteView extends Component { /* Props * ------------------------------------------------ * @prop { type } name - Description.... @@ -17,20 +23,158 @@ class ExampleView extends Component { constructor(props) { super(props); - this.state = {}; + this.state = { + value: 0.00, + isVoting: false, + isVoted: props.content && props.content.isVoted, + amount: '0.00', + isModalVisible: false, + }; } // Component Life Cycles // Component Functions - render() { - // eslint-disable-next-line - const {} = this.props; + _calculateEstimatedAmount = async () => { + const { user } = this.props; + // Calculate total vesting shares + if (user) { + const { value } = this.state; + const totalVests = parseFloat(user.vesting_shares) + + parseFloat(user.received_vesting_shares) + - parseFloat(user.delegated_vesting_shares); - // eslint-disable-next-line - return ; + const finalVest = totalVests * 1e6; + + const power = (user.voting_power * (value * 10000)) / 10000 / 50; + + const rshares = (power * finalVest) / 10000; + + const estimated = await upvoteAmount(rshares); + + this.setState({ + amount: estimated.toFixed(3), + }); + } + }; + + _upvoteContent = () => { + alert('ugur'); + // const { isLoggedIn, user, content } = this.props; + // const { value } = this.state; + + // let postingKey; + // let userData; + + // if (true) { + // await this.setState({ + // isVoting: true, + // }); + + // await getUserData().then((result) => { + // userData = Array.from(result); + // postingKey = decryptKey(userData[0].postingKey, '1234'); + // }); + // upvote( + // { + // voter: user && user.name, + // author: content && content.author, + // permlink: content && content.permlink, + // weight: (value * 100).toFixed(0) * 100, + // }, + // postingKey, + // ) + // .then((res) => { + // console.log(res); + // this.setState({ + // isVoted: true, + // isVoting: false, + // }); + // }) + // .catch((err) => { + // console.log(err); + // this.setState({ + // isVoted: false, + // isVoting: false, + // }); + // }); + // } + }; + + render() { + const { content, user, isLoggedIn } = this.props; + const { + isVoting, isModalVisible, amount, value, isVoted, + } = this.state; + + const _percent = (value * 100).toFixed(0) + "%"; + const _amount = "$" + amount; + return ( + + {({ + openPopover, closePopover, popoverVisible, setPopoverAnchor, popoverAnchorRect, + }) => ( + + + {isVoting ? ( + + ) : ( + + )} + + + + + { + // closePopover(); + this._upvoteContent(); + }} + style={styles.upvoteButton} + > + + + {_amount} + { + this.setState({ value }, () => { + this._calculateEstimatedAmount(); + }); + }} + /> + {_percent} + + + + )} + + ); } } -export default ExampleView; +export default UpvoteView; From 911a595035d7c80b92a84bb37ca6498f962ea626 Mon Sep 17 00:00:00 2001 From: ue Date: Sun, 28 Oct 2018 01:08:06 +0300 Subject: [PATCH 5/6] created upvote functionability --- package-lock.json | 10 +- package.json | 2 +- .../postCard/view/postCardStyles.js | 3 +- src/components/postCard/view/postCardView.js | 195 +----------------- src/components/upvote/view/upvoteStyles.js | 2 +- src/components/upvote/view/upvoteView.js | 96 ++++----- src/providers/steem/dsteem.js | 13 +- src/utils/postParser.js | 47 +---- 8 files changed, 78 insertions(+), 290 deletions(-) diff --git a/package-lock.json b/package-lock.json index dde5e2d5f..b61f4679c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9918,13 +9918,13 @@ } }, "react-native-modal-popover": { - "version": "0.0.10", - "resolved": "https://registry.npmjs.org/react-native-modal-popover/-/react-native-modal-popover-0.0.10.tgz", - "integrity": "sha512-Ae7TnF9XDp19clwffRoD7qM/SfdkXdrEFpSbBEtGgZdnrqqI9kyIf626VtburNm9HAMidsvuXG4oxf/BISgy9w==", + "version": "0.0.12", + "resolved": "https://registry.npmjs.org/react-native-modal-popover/-/react-native-modal-popover-0.0.12.tgz", + "integrity": "sha512-uZQsTDcGOI8y/05L/Lb0OMBesJYYRWEc0pj2038a579LnDnJJpKay0kD654cQpA4Ozt3xbu4DMTGwenynBSEFg==", "requires": { - "@types/prop-types": "^15.5.2", + "@types/prop-types": "^15.5.5", "lodash.debounce": "^4.0.8", - "prop-types": "^15.6.0" + "prop-types": "^15.6.2" } }, "react-native-restart": { diff --git a/package.json b/package.json index 67d7d6c8e..c59e44df1 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "react-native-markdown-view": "^1.1.4", "react-native-modal": "^6.5.0", "react-native-modal-dropdown": "^0.6.2", - "react-native-modal-popover": "0.0.10", + "react-native-modal-popover": "0.0.12", "react-native-restart": "0.0.6", "react-native-slider": "^0.11.0", "react-native-vector-icons": "^4.6.0", diff --git a/src/components/postCard/view/postCardStyles.js b/src/components/postCard/view/postCardStyles.js index 4697e64a9..83ec77572 100644 --- a/src/components/postCard/view/postCardStyles.js +++ b/src/components/postCard/view/postCardStyles.js @@ -177,8 +177,9 @@ export default EStyleSheet.create({ shadowColor: 'white', paddingLeft: 5, borderRadius: 5, - fontSize: 7, + fontSize: 10, fontWeight: '100', + fontFamily: '$primaryFont', color: '#777777', }, popover: { diff --git a/src/components/postCard/view/postCardView.js b/src/components/postCard/view/postCardView.js index 0eac0d829..a6260e790 100644 --- a/src/components/postCard/view/postCardView.js +++ b/src/components/postCard/view/postCardView.js @@ -1,18 +1,13 @@ import React, { Component } from 'react'; import { - Image, TouchableOpacity, FlatList, ActivityIndicator, + Image, TouchableOpacity, FlatList, } from 'react-native'; import { Card, CardItem, Left, Right, Thumbnail, View, Icon, Body, Text, } from 'native-base'; import Modal from 'react-native-modal'; -import { Popover, PopoverController } from 'react-native-modal-popover'; -import Slider from 'react-native-slider'; // STEEM -import { upvote, upvoteAmount } from '../../../providers/steem/dsteem'; -import { decryptKey } from '../../../utils/crypto'; -import { getUserData } from '../../../realm/realm'; import { Upvote } from '../../upvote'; // Styles import styles from './postCardStyles'; @@ -26,88 +21,15 @@ class PostCard extends Component { */ constructor(props) { super(props); - this.calculateEstimatedAmount = this.calculateEstimatedAmount.bind(this); this.state = { - value: 0.0, - isVoting: false, - isVoted: props.content && props.content.isVoted, - amount: '0.00', isModalVisible: false, }; } // Component Lifecycle Functions - componentDidMount() { - const { isLoggedIn } = this.props; - - true && this.calculateEstimatedAmount(); - } // Component Functions - calculateEstimatedAmount = async () => { - const { user } = this.props; - const { value } = this.state; - // Calculate total vesting shares - const total_vests = parseFloat(user.vesting_shares) - + parseFloat(user.received_vesting_shares) - - parseFloat(user.delegated_vesting_shares); - - const final_vest = total_vests * 1e6; - - const power = (user.voting_power * (value * 10000)) / 10000 / 50; - - const rshares = (power * final_vest) / 10000; - - const estimated = await upvoteAmount(rshares); - - this.setState({ - amount: estimated.toFixed(3), - }); - }; - - upvoteContent = async () => { - alert('ugur'); - const { isLoggedIn, user, content } = this.props; - const { value } = this.state; - - let postingKey; - let userData; - - if (true) { - await this.setState({ - isVoting: true, - }); - - await getUserData().then((result) => { - userData = Array.from(result); - postingKey = decryptKey(userData[0].postingKey, '1234'); - }); - upvote( - { - voter: user && user.name, - author: content && content.author, - permlink: content && content.permlink, - weight: (value * 100).toFixed(0) * 100, - }, - postingKey, - ) - .then((res) => { - console.log(res); - this.setState({ - isVoted: true, - isVoting: false, - }); - }) - .catch((err) => { - console.log(err); - this.setState({ - isVoted: false, - isVoting: false, - }); - }); - } - }; toggleModal = () => { const { isModalVisible } = this.state; @@ -127,11 +49,9 @@ class PostCard extends Component { render() { const { - content, isLoggedIn, user, handleOnUserPress, + content, isLoggedIn, user, } = this.props; - const { - isVoted, isVoting, isModalVisible, value, - } = this.state; + const { isModalVisible } = this.state; // TODO: Should seperate bunch of component REFACTOR ME! return ( @@ -152,9 +72,7 @@ class PostCard extends Component { {content.category} - {' '} {content.created} - {' '} @@ -177,108 +95,7 @@ class PostCard extends Component { - - {/* - {({ - openPopover, - closePopover, - popoverVisible, - setPopoverAnchor, - popoverAnchorRect, - }) => ( - - - {isVoting ? ( - - ) : ( - - {isVoted ? ( - - ) : ( - - )} - - )} - - - -$ - {this.state.amount} - - - { - closePopover(); - this.upvoteContent(); - }} - style={{ - flex: 0.1, - alignSelf: 'center', - }} - > - - - { - this.setState({ value }, () => { - this.calculateEstimatedAmount(); - }); - }} - /> - - {(value * 100).toFixed(0)} -% - - - - - )} - */} + $ @@ -297,7 +114,7 @@ $ Tap to close! item.voter.toString()} renderItem={({ item }) => ( - {' '} {item.voter} - {' '} ( {item.reputation} ) diff --git a/src/components/upvote/view/upvoteStyles.js b/src/components/upvote/view/upvoteStyles.js index 0f96c8fbb..c51a8534c 100644 --- a/src/components/upvote/view/upvoteStyles.js +++ b/src/components/upvote/view/upvoteStyles.js @@ -13,10 +13,10 @@ export default EStyleSheet.create({ popover: { flexDirection: 'row', width: '$deviceWidth - 20', + height: 48, borderRadius: '$deviceWidth - 20 / 2', paddingHorizontal: 16, backgroundColor: '$white', - height: 48, }, track: { height: 2, diff --git a/src/components/upvote/view/upvoteView.js b/src/components/upvote/view/upvoteView.js index 8a7f20bf0..2d17643b1 100644 --- a/src/components/upvote/view/upvoteView.js +++ b/src/components/upvote/view/upvoteView.js @@ -1,5 +1,7 @@ import React, { Component, Fragment } from 'react'; -import { View, TouchableOpacity, ActivityIndicator, Text } from 'react-native'; +import { + View, TouchableOpacity, ActivityIndicator, Text, +} from 'react-native'; import { Popover, PopoverController } from 'react-native-modal-popover'; import Slider from 'react-native-slider'; // Constants @@ -24,9 +26,9 @@ class UpvoteView extends Component { constructor(props) { super(props); this.state = { - value: 0.00, + value: 0.0, isVoting: false, - isVoted: props.content && props.content.isVoted, + isVoted: props.content ? props.content.isVoted : false, amount: '0.00', isModalVisible: false, }; @@ -42,8 +44,8 @@ class UpvoteView extends Component { if (user) { const { value } = this.state; const totalVests = parseFloat(user.vesting_shares) - + parseFloat(user.received_vesting_shares) - - parseFloat(user.delegated_vesting_shares); + + parseFloat(user.received_vesting_shares) + - parseFloat(user.delegated_vesting_shares); const finalVest = totalVests * 1e6; @@ -59,47 +61,48 @@ class UpvoteView extends Component { } }; - _upvoteContent = () => { - alert('ugur'); - // const { isLoggedIn, user, content } = this.props; - // const { value } = this.state; + _upvoteContent = async () => { + const { user, content } = this.props; + const { value } = this.state; - // let postingKey; - // let userData; + let postingKey; + let userData; - // if (true) { - // await this.setState({ - // isVoting: true, - // }); + this.setState({ + isVoting: true, + }); - // await getUserData().then((result) => { - // userData = Array.from(result); - // postingKey = decryptKey(userData[0].postingKey, '1234'); - // }); - // upvote( - // { - // voter: user && user.name, - // author: content && content.author, - // permlink: content && content.permlink, - // weight: (value * 100).toFixed(0) * 100, - // }, - // postingKey, - // ) - // .then((res) => { - // console.log(res); - // this.setState({ - // isVoted: true, - // isVoting: false, - // }); - // }) - // .catch((err) => { - // console.log(err); - // this.setState({ - // isVoted: false, - // isVoting: false, - // }); - // }); - // } + await getUserData().then((result) => { + userData = Array.from(result); + postingKey = decryptKey(userData[0].postingKey, '1234'); + }); + + upvote( + { + voter: user && user.name, + author: content && content.author, + permlink: content && content.permlink, + weight: value ? (value * 100).toFixed(0) * 100 : 0, + }, + postingKey, + ) + .then((res) => { + this.setState({ + isVoted: true, + isVoting: false, + }); + + alert('success'); + }) + .catch((err) => { + console.log(err); + alert(err); + + this.setState({ + isVoted: false, + isVoting: false, + }); + }); }; render() { @@ -108,8 +111,8 @@ class UpvoteView extends Component { isVoting, isModalVisible, amount, value, isVoted, } = this.state; - const _percent = (value * 100).toFixed(0) + "%"; - const _amount = "$" + amount; + const _percent = `${(value * 100).toFixed(0)}%`; + const _amount = `$${amount}`; return ( {({ @@ -121,6 +124,7 @@ class UpvoteView extends Component { ref={setPopoverAnchor} onPress={openPopover} style={styles.upvoteButton} + disabled={!isLoggedIn} > {isVoting ? ( @@ -167,7 +171,7 @@ class UpvoteView extends Component { }); }} /> - {_percent} + {_percent} diff --git a/src/providers/steem/dsteem.js b/src/providers/steem/dsteem.js index 8351cc8df..f2a0b5f17 100644 --- a/src/providers/steem/dsteem.js +++ b/src/providers/steem/dsteem.js @@ -68,14 +68,7 @@ export const getUser = async (user) => { } }; -export const vestToSteem = ( - vestingShares, - totalVestingShares, - totalVestingFundSteem, -) => ( - parseFloat(totalVestingFundSteem) - * (parseFloat(vestingShares) / parseFloat(totalVestingShares)) -); +export const vestToSteem = (vestingShares, totalVestingShares, totalVestingFundSteem) => parseFloat(totalVestingFundSteem) * (parseFloat(vestingShares) / parseFloat(totalVestingShares)); /** * @method getFollows get account data @@ -222,6 +215,8 @@ export const getPostWithComments = async (user, permlink) => { return [post, comments]; }; +// export const getAccountRC = username => client.call('rc_api', 'find_rc_accounts', { accounts: [username] }); + /** * @method upvote upvote a content * @param vote vote object(author, permlink, voter, weight) @@ -233,11 +228,9 @@ export const upvote = (vote, postingKey) => { client.broadcast .vote(vote, key) .then((result) => { - console.log(result); resolve(result); }) .catch((err) => { - console.log(err); reject(err); }); }); diff --git a/src/utils/postParser.js b/src/utils/postParser.js index 79a44b4c0..83e6e88f0 100644 --- a/src/utils/postParser.js +++ b/src/utils/postParser.js @@ -22,10 +22,7 @@ export const replaceTags = input => input.replace(/(^|\s|>)(#[-a-z\d]+)/gi, (tag tag = tag.replace('>', ''); // remove closing tag const tag2 = tag.trim().substring(1); const tagLower = tag2.toLowerCase(); - return ( - `${preceding - }${tag.trim()}` - ); + return `${preceding}${tag.trim()}`; }); export const markDown2Html = (input) => { @@ -50,9 +47,7 @@ export const parsePosts = (posts, user) => { posts.map((post) => { 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, - ); + post.pending_payout_value = parseFloat(post.pending_payout_value).toFixed(2); post.created = getTimeFromNow(post.created); post.vote_count = post.active_votes.length; post.author_reputation = getReputation(post.author_reputation); @@ -66,23 +61,14 @@ export const parsePosts = (posts, user) => { + parseFloat(post.total_payout_value) + parseFloat(post.curator_payout_value); - const voteRshares = post.active_votes.reduce( - (a, b) => a + parseFloat(b.rshares), - 0, - ); + const voteRshares = post.active_votes.reduce((a, b) => a + parseFloat(b.rshares), 0); const ratio = totalPayout / voteRshares; post.isVoted = false; for (const i in post.active_votes) { - if (post.active_votes[i].voter == user) { - post.isVoted = true; - } - post.active_votes[i].value = ( - post.active_votes[i].rshares * ratio - ).toFixed(2); - post.active_votes[i].reputation = getReputation( - post.active_votes[i].reputation, - ); + post.isVoted = post.active_votes[i].voter === user.name; + post.active_votes[i].value = (post.active_votes[i].rshares * ratio).toFixed(2); + post.active_votes[i].reputation = getReputation(post.active_votes[i].reputation); post.active_votes[i].percent = post.active_votes[i].percent / 100; post.active_votes[i].avatar = `https://steemitimages.com/u/${ post.active_votes[i].voter @@ -116,19 +102,12 @@ export const parsePost = (post) => { + parseFloat(post.total_payout_value) + parseFloat(post.curator_payout_value); - const voteRshares = post.active_votes.reduce( - (a, b) => a + parseFloat(b.rshares), - 0, - ); + const voteRshares = post.active_votes.reduce((a, b) => a + parseFloat(b.rshares), 0); const ratio = totalPayout / voteRshares; for (const i in post.active_votes) { - post.active_votes[i].value = (post.active_votes[i].rshares * ratio).toFixed( - 2, - ); - post.active_votes[i].reputation = getReputation( - post.active_votes[i].reputation, - ); + post.active_votes[i].value = (post.active_votes[i].rshares * ratio).toFixed(2); + post.active_votes[i].reputation = getReputation(post.active_votes[i].reputation); post.active_votes[i].percent = post.active_votes[i].percent / 100; post.active_votes[i].avatar = `https://steemitimages.com/u/${ post.active_votes[i].voter @@ -183,15 +162,11 @@ export const protocolUrl2Obj = (url) => { export const parseComments = (comments) => { comments.map((comment) => { - comment.pending_payout_value = parseFloat( - comment.pending_payout_value, - ).toFixed(2); + comment.pending_payout_value = parseFloat(comment.pending_payout_value).toFixed(2); comment.created = getTimeFromNow(comment.created); comment.vote_count = comment.active_votes.length; comment.author_reputation = getReputation(comment.author_reputation); - comment.avatar = `https://steemitimages.com/u/${ - comment.author - }/avatar/small`; + comment.avatar = `https://steemitimages.com/u/${comment.author}/avatar/small`; comment.body = markDown2Html(comment.body); }); return comments; From 9e27964e6d878d2885f34b0d0f9fa2fee72de9f6 Mon Sep 17 00:00:00 2001 From: ue Date: Mon, 29 Oct 2018 13:10:07 +0300 Subject: [PATCH 6/6] downvoted functionability created --- src/components/upvote/view/upvoteView.js | 22 ++++++++++++++-------- src/utils/postParser.js | 24 +++++++++++++----------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/components/upvote/view/upvoteView.js b/src/components/upvote/view/upvoteView.js index 2d17643b1..92b68ad23 100644 --- a/src/components/upvote/view/upvoteView.js +++ b/src/components/upvote/view/upvoteView.js @@ -28,7 +28,7 @@ class UpvoteView extends Component { this.state = { value: 0.0, isVoting: false, - isVoted: props.content ? props.content.isVoted : false, + isVoted: props.content ? props.content.is_voted : false, amount: '0.00', isModalVisible: false, }; @@ -88,16 +88,13 @@ class UpvoteView extends Component { ) .then((res) => { this.setState({ - isVoted: true, + isVoted: !!value, isVoting: false, }); - - alert('success'); + alert(!!value ? "Upvoted" : "Downvoted"); }) .catch((err) => { - console.log(err); alert(err); - this.setState({ isVoted: false, isVoting: false, @@ -106,7 +103,7 @@ class UpvoteView extends Component { }; render() { - const { content, user, isLoggedIn } = this.props; + const { isLoggedIn } = this.props; const { isVoting, isModalVisible, amount, value, isVoted, } = this.state; @@ -155,7 +152,16 @@ class UpvoteView extends Component { }} style={styles.upvoteButton} > - + {isVoting ? ( + + ) : ( + + )} {_amount} { export const parsePosts = (posts, user) => { posts.map((post) => { post.json_metadata = JSON.parse(post.json_metadata); - post.json_metadata.image ? (post.image = post.json_metadata.image[0]) : ''; + post.json_metadata.image ? (post.image = post.json_metadata.image[0]) : null; post.pending_payout_value = parseFloat(post.pending_payout_value).toFixed(2); post.created = getTimeFromNow(post.created); post.vote_count = post.active_votes.length; @@ -63,16 +63,19 @@ export const parsePosts = (posts, user) => { const voteRshares = post.active_votes.reduce((a, b) => a + parseFloat(b.rshares), 0); const ratio = totalPayout / voteRshares; - post.isVoted = false; + post.is_voted = false; - for (const i in post.active_votes) { - post.isVoted = post.active_votes[i].voter === user.name; - post.active_votes[i].value = (post.active_votes[i].rshares * ratio).toFixed(2); - post.active_votes[i].reputation = getReputation(post.active_votes[i].reputation); - post.active_votes[i].percent = post.active_votes[i].percent / 100; - post.active_votes[i].avatar = `https://steemitimages.com/u/${ - post.active_votes[i].voter - }/avatar/small`; + if (post && post.active_votes) { + for (const i in post.active_votes) { + post.is_voted = post.active_votes[i].voter === user.name && post.active_votes[i].percent > 0; + post.vote_perecent = post.active_votes[i].voter === user.name ? post.active_votes[i].percent : null; + post.active_votes[i].value = (post.active_votes[i].rshares * ratio).toFixed(2); + post.active_votes[i].reputation = getReputation(post.active_votes[i].reputation); + post.active_votes[i].percent = post.active_votes[i].percent / 100; + post.active_votes[i].avatar = `https://steemitimages.com/u/${ + post.active_votes[i].voter + }/avatar/small`; + } } if (post.active_votes.length > 2) { @@ -108,7 +111,6 @@ export const parsePost = (post) => { for (const i in post.active_votes) { post.active_votes[i].value = (post.active_votes[i].rshares * ratio).toFixed(2); post.active_votes[i].reputation = getReputation(post.active_votes[i].reputation); - post.active_votes[i].percent = post.active_votes[i].percent / 100; post.active_votes[i].avatar = `https://steemitimages.com/u/${ post.active_votes[i].voter }/avatar/small`;