diff --git a/src/config/locales/en-US.json b/src/config/locales/en-US.json index cbbc41ee3..0ad3a7c58 100644 --- a/src/config/locales/en-US.json +++ b/src/config/locales/en-US.json @@ -306,7 +306,11 @@ "title": "Promote", "days": "days", "user": "User", - "permlink": "Permlink", + "permlink": "Post", + "permlinkPlaceholder": "author/permlink", "information": "Are you sure to transfer to promote?" + }, + "boostPost": { + "title": "Boost" } } diff --git a/src/containers/pointsContainer.js b/src/containers/pointsContainer.js index d98e2e747..a3db20c97 100644 --- a/src/containers/pointsContainer.js +++ b/src/containers/pointsContainer.js @@ -8,7 +8,7 @@ import { withNavigation } from 'react-navigation'; // Services and Actions import { getUser, getUserPoints, claim } from '../providers/esteem/ePoint'; import { openPinCodeModal } from '../redux/actions/applicationActions'; -import { promote, getAccount } from '../providers/steem/dsteem'; +import { promote, getAccount, boost } from '../providers/steem/dsteem'; import { getUserDataWithUsername } from '../realm/realm'; import { toastNotification } from '../redux/actions/uiAction'; @@ -212,6 +212,33 @@ class PointsContainer extends Component { }); }; + _boost = async (point, permlink, author, user) => { + const { currentAccount, pinCode, dispatch, intl, navigation } = this.props; + this.setState({ isLoading: true }); + + await boost(user || currentAccount, pinCode, point, permlink, author) + .then(() => { + this.setState({ isLoading: false }); + navigation.goBack(); + dispatch(toastNotification(intl.formatMessage({ id: 'alert.successful' }))); + }) + .catch(error => { + Alert.alert( + `Fetching data from server failed, please try again or notify us at info@esteem.app \n${error.message.substr( + 0, + 20, + )}`, + ); + }); + }; + + _getESTMPrice = points => { + const { globalProps } = this.props; + const { base, quote } = globalProps; + + return points * 0.01 * (base / quote); + }; + render() { const { balance, @@ -247,6 +274,8 @@ class PointsContainer extends Component { userActivities, userPoints, handleOnDropdownSelected: this._handleOnDropdownSelected, + getESTMPrice: this._getESTMPrice, + boost: this._boost, balance, getUserBalance: this._getUserBalance, promote: this._promote, @@ -266,6 +295,7 @@ const mapStateToProps = state => ({ currentAccount: state.account.currentAccount, pinCode: state.application.pin, isPinCodeOpen: state.application.isPinCodeOpen, + globalProps: state.account.globalProps, }); export default withNavigation(connect(mapStateToProps)(injectIntl(PointsContainer))); diff --git a/src/providers/steem/dsteem.js b/src/providers/steem/dsteem.js index a69392645..c06eaf57f 100644 --- a/src/providers/steem/dsteem.js +++ b/src/providers/steem/dsteem.js @@ -1137,7 +1137,7 @@ export const boost = (currentAccount, pinCode, point, permlink, author) => { const pin = getDigitPinCode(pinCode); const key = getActiveKey(get(currentAccount, 'local'), pin); - if (key) { + if (key && point) { const privateKey = PrivateKey.fromString(key); const user = get(currentAccount, 'name'); @@ -1147,7 +1147,7 @@ export const boost = (currentAccount, pinCode, point, permlink, author) => { user, author, permlink, - amount: `${point} POINT`, + amount: `${point.toFixed(3)} POINT`, }), required_auths: [user], required_posting_auths: [], diff --git a/src/screens/boostPost/screen/boostPostScreen.js b/src/screens/boostPost/screen/boostPostScreen.js index 77cfc28d8..bec1c0b32 100644 --- a/src/screens/boostPost/screen/boostPostScreen.js +++ b/src/screens/boostPost/screen/boostPostScreen.js @@ -4,7 +4,7 @@ import { Text, View, WebView, ScrollView, TouchableOpacity, Alert } from 'react- import get from 'lodash/get'; import ActionSheet from 'react-native-actionsheet'; import Autocomplete from 'react-native-autocomplete-input'; -import { ScaleSlider, TextInput } from '../../../components'; +import { Icon, TextInput } from '../../../components'; import { steemConnectOptions } from '../../../constants/steemConnectOptions'; // Container @@ -21,7 +21,7 @@ import { MainButton } from '../../../components/mainButton'; import { DropdownButton } from '../../../components/dropdownButton'; import { Modal } from '../../../components/modal'; -import { PROMOTE_PRICING, PROMOTE_DAYS } from '../../../constants/options/points'; +// import { PROMOTE_PRICING, PROMOTE_DAYS } from '../../../constants/options/points'; // Styles import styles from './boostPostStyles'; @@ -38,11 +38,12 @@ class BoostPostScreen extends PureComponent { permlink: '', selectedUser: '', balance: '', - day: 1, + factor: 0, isSCModalOpen: false, SCPath: '', permlinkSuggestions: [], isValid: false, + calculatedESTM: 150, }; this.startActionSheet = React.createRef(); @@ -108,23 +109,24 @@ class BoostPostScreen extends PureComponent { }); }; - _promote = async (promote, currentAccount, getUserDataWithUsername, navigationParams) => { - const { day, permlink, selectedUser } = this.state; + _boost = async (boost, currentAccount, getUserDataWithUsername, navigationParams) => { + const { factor, permlink, selectedUser } = this.state; const fullPermlink = permlink || get(navigationParams, 'permlink'); const seperatedPermlink = fullPermlink.split('/'); const _author = get(seperatedPermlink, '[0]'); const _permlink = get(seperatedPermlink, '[1]'); + const amount = 150 + 50 * factor; if (get(currentAccount, 'local.authType') === 'steemConnect') { const json = JSON.stringify({ user: selectedUser, _author, _permlink, - duration: day, + amount, }); - const uri = `sign/custom-json?authority=active&required_auths=%5B%22${selectedUser}%22%5D&required_posting_auths=%5B%5D&id=esteem_promote&json=${encodeURIComponent( + const uri = `sign/custom-json?authority=active&required_auths=%5B%22${selectedUser}%22%5D&required_posting_auths=%5B%5D&id=esteem_boost&json=${encodeURIComponent( json, )}`; @@ -132,7 +134,7 @@ class BoostPostScreen extends PureComponent { isSCModalOpen: true, SCPath: uri, }); - } else if (promote) { + } else if (boost) { let userFromRealm; if (selectedUser) { @@ -146,7 +148,7 @@ class BoostPostScreen extends PureComponent { } : currentAccount; - promote(day, _permlink, _author, user); + if (amount && _permlink) boost(amount, _permlink, _author, user); } }; @@ -155,7 +157,7 @@ class BoostPostScreen extends PureComponent { const { selectedUser, balance, - day, + factor, SCPath, isSCModalOpen, permlinkSuggestions, @@ -163,6 +165,8 @@ class BoostPostScreen extends PureComponent { isValid, } = this.state; + const calculatedESTM = 150 + 50 * factor; + return ( {({ @@ -170,13 +174,14 @@ class BoostPostScreen extends PureComponent { accounts, currentAccountName, balance: _balance, - promote, currentAccount, getUserDataWithUsername, navigationParams, + getESTMPrice, + boost, }) => ( - + @@ -186,7 +191,7 @@ class BoostPostScreen extends PureComponent { this._renderDropdown(accounts, selectedUser || currentAccountName) } /> - {`${balance || _balance} eSteem Points`} + {`${balance || _balance} ESTM`} @@ -210,7 +215,7 @@ class BoostPostScreen extends PureComponent { style={styles.input} onChangeText={text => this._handleOnPermlinkChange(text)} value={permlink || get(navigationParams, 'permlink', '')} - placeholder={intl.formatMessage({ id: 'promote.permlink' })} + placeholder={intl.formatMessage({ id: 'promote.permlinkPlaceholder' })} placeholderTextColor="#c1c5c7" autoCapitalize="none" /> @@ -235,23 +240,54 @@ class BoostPostScreen extends PureComponent { - {`${day} ${intl.formatMessage({ - id: 'promote.days', - })} `} - - - {`${get(PROMOTE_PRICING[PROMOTE_DAYS.indexOf(day)], 'price')} eSteem points`} + {`${getESTMPrice(calculatedESTM).toFixed(3)} $ `} + {`${calculatedESTM} ESTM`} - this.setState({ day: _day })} - single - /> + + factor + 4)} + onPress={() => + this.setState({ + factor: _balance / 50 > factor + 4 ? factor + 1 : factor, + }) + } + > + + + + 150)} + onPress={() => + this.setState({ + factor: calculatedESTM > 150 ? factor - 1 : factor, + }) + } + > + + + + { index === 0 && - this._promote(promote, currentAccount, getUserDataWithUsername, navigationParams); + this._boost(boost, currentAccount, getUserDataWithUsername, navigationParams); }} /> + - {`${balance || _balance} eSteem Points`} + {`${balance || _balance} ESTM`} diff --git a/src/screens/promote/screen/promoteStyles.js b/src/screens/promote/screen/promoteStyles.js index cd70ec52b..3469c262a 100644 --- a/src/screens/promote/screen/promoteStyles.js +++ b/src/screens/promote/screen/promoteStyles.js @@ -10,7 +10,7 @@ export default EStyleSheet.create({ fontSize: 14, color: '$primaryDarkGray', alignSelf: 'center', - marginLeft: 70, + marginLeft: 20, marginBottom: 10, }, topContent: {