created boost post feature

This commit is contained in:
u-e 2019-07-27 17:04:51 +03:00
parent 9b87efd4cb
commit e2b69b65bb
7 changed files with 106 additions and 35 deletions

View File

@ -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"
}
}

View File

@ -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)));

View File

@ -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: [],

View File

@ -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 (
<PointsContainer>
{({
@ -170,13 +174,14 @@ class BoostPostScreen extends PureComponent {
accounts,
currentAccountName,
balance: _balance,
promote,
currentAccount,
getUserDataWithUsername,
navigationParams,
getESTMPrice,
boost,
}) => (
<Fragment>
<BasicHeader title={intl.formatMessage({ id: 'promote.title' })} />
<BasicHeader title={intl.formatMessage({ id: 'boostPost.title' })} />
<View style={styles.container}>
<ScrollView>
<View style={styles.middleContent}>
@ -186,7 +191,7 @@ class BoostPostScreen extends PureComponent {
this._renderDropdown(accounts, selectedUser || currentAccountName)
}
/>
<Text style={styles.balanceText}>{`${balance || _balance} eSteem Points`}</Text>
<Text style={styles.balanceText}>{`${balance || _balance} ESTM`}</Text>
<Fragment>
<View style={styles.autocomplateLineContainer}>
<View style={styles.autocomplateLabelContainer}>
@ -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 {
<View style={styles.total}>
<Text style={styles.day}>
{`${day} ${intl.formatMessage({
id: 'promote.days',
})} `}
</Text>
<Text style={styles.price}>
{`${get(PROMOTE_PRICING[PROMOTE_DAYS.indexOf(day)], 'price')} eSteem points`}
{`${getESTMPrice(calculatedESTM).toFixed(3)} $ `}
</Text>
<Text style={styles.price}>{`${calculatedESTM} ESTM`}</Text>
</View>
<ScaleSlider
values={[1, 2, 3, 7, 14]}
LRpadding={50}
activeValue={day}
handleOnValueChange={_day => this.setState({ day: _day })}
single
/>
<View
style={{
justifyContent: 'center',
alignItems: 'center',
flexDirection: 'row',
}}
>
<MainButton
style={{ width: 55, height: 55, justifyContent: 'center' }}
isDisable={!(_balance / 50 > factor + 4)}
onPress={() =>
this.setState({
factor: _balance / 50 > factor + 4 ? factor + 1 : factor,
})
}
>
<Icon
size={24}
style={{ color: 'white' }}
iconType="MaterialIcons"
name="add"
/>
</MainButton>
<MainButton
style={{ width: 55, height: 55, justifyContent: 'center' }}
isDisable={!(calculatedESTM > 150)}
onPress={() =>
this.setState({
factor: calculatedESTM > 150 ? factor - 1 : factor,
})
}
>
<Icon
size={24}
style={{ color: 'white' }}
iconType="MaterialCommunityIcons"
name="minus"
/>
</MainButton>
</View>
</View>
<View style={styles.bottomContent}>
<MainButton
style={styles.button}
@ -280,9 +316,10 @@ class BoostPostScreen extends PureComponent {
destructiveButtonIndex={0}
onPress={index => {
index === 0 &&
this._promote(promote, currentAccount, getUserDataWithUsername, navigationParams);
this._boost(boost, currentAccount, getUserDataWithUsername, navigationParams);
}}
/>
<Modal
isOpen={isSCModalOpen}
isFullScreen

View File

@ -10,7 +10,7 @@ export default EStyleSheet.create({
fontSize: 14,
color: '$primaryDarkGray',
alignSelf: 'center',
marginLeft: 70,
marginLeft: 20,
marginBottom: 10,
},
topContent: {

View File

@ -186,7 +186,7 @@ class PointsScreen extends PureComponent {
this._renderDropdown(accounts, selectedUser || currentAccountName)
}
/>
<Text style={styles.balanceText}>{`${balance || _balance} eSteem Points`}</Text>
<Text style={styles.balanceText}>{`${balance || _balance} ESTM`}</Text>
<Fragment>
<View style={styles.autocomplateLineContainer}>
<View style={styles.autocomplateLabelContainer}>

View File

@ -10,7 +10,7 @@ export default EStyleSheet.create({
fontSize: 14,
color: '$primaryDarkGray',
alignSelf: 'center',
marginLeft: 70,
marginLeft: 20,
marginBottom: 10,
},
topContent: {