Skip to content

Commit

Permalink
Merge pull request #2830 from ecency/boost-plus
Browse files Browse the repository at this point in the history
Boost+
  • Loading branch information
feruzm authored Feb 13, 2024
2 parents 3b8f9f3 + 7b733e0 commit 18a2510
Show file tree
Hide file tree
Showing 16 changed files with 571 additions and 30 deletions.
13 changes: 12 additions & 1 deletion src/components/header/container/headerContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import HeaderView from '../view/headerView';
import { AccountContainer } from '../../../containers';
import { parseReputation } from '../../../utils/user';
import { toggleQRModal } from '../../../redux/actions/uiAction';
import ROUTES from '../../../constants/routeNames';

const HeaderContainer = ({ selectedUser, isReverse, handleOnBackPress, hideUser, showQR }) => {
const HeaderContainer = ({ selectedUser, isReverse, handleOnBackPress, hideUser, showQR, showBoost }) => {
const navigation = useNavigation();
const dispatch = useDispatch();
const isDarkTheme = useSelector((state) => state.application.isDarkTheme);
Expand All @@ -33,6 +34,13 @@ const HeaderContainer = ({ selectedUser, isReverse, handleOnBackPress, hideUser,
dispatch(toggleQRModal(true));
};

const _handleOnBoostPress = () => {
//TODO: navigate to boost plus screen;
navigation.navigate(ROUTES.SCREENS.REDEEM, {
redeemType:'boost_plus'
})
}

return (
<AccountContainer>
{({ currentAccount, isLoggedIn, isLoginDone }) => {
Expand All @@ -45,6 +53,7 @@ const HeaderContainer = ({ selectedUser, isReverse, handleOnBackPress, hideUser,
handleOnPressBackButton={_handleOnPressBackButton}
handleOnQRPress={_handleQRPress}
handleOpenDrawer={_handleOpenDrawer}
handleOnBoostPress={_handleOnBoostPress}
isDarkTheme={isDarkTheme}
isLoggedIn={isLoggedIn}
isLoginDone={isLoginDone}
Expand All @@ -53,6 +62,8 @@ const HeaderContainer = ({ selectedUser, isReverse, handleOnBackPress, hideUser,
username={get(_user, 'name')}
hideUser={hideUser}
showQR={showQR}
showBoost={showBoost}

/>
);
}}
Expand Down
17 changes: 16 additions & 1 deletion src/components/header/view/headerStyles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import EStyleSheet from 'react-native-extended-stylesheet';
import { Platform } from 'react-native';
import { Platform, ViewStyle } from 'react-native';

export default EStyleSheet.create({
container: {
Expand Down Expand Up @@ -75,6 +75,21 @@ export default EStyleSheet.create({
color: '$iconColor',
justifyContent: 'center',
},
boostContainer:{
flexDirection:'row',
marginRight:10,
},
plusIcon: {
fontSize: 12,
color: '$primaryBlue',
justifyContent: 'center',

} as ViewStyle,
boostPlusIcon: {
fontSize: 22,
color: '$primaryBlue',
justifyContent: 'center',
},
backButton: {
marginLeft: 24,
},
Expand Down
20 changes: 20 additions & 0 deletions src/components/header/view/headerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import ROUTES from '../../../constants/routeNames';

// Styles
import styles from './headerStyles';
import Icon from '../../icon';

const HeaderView = ({
displayName,
handleOnPressBackButton,
handleOnQRPress,
handleOpenDrawer,
handleOnBoostPress,
isDarkTheme,
isLoggedIn,
isLoginDone,
Expand All @@ -28,6 +30,7 @@ const HeaderView = ({
username,
hideUser,
showQR,
showBoost
}) => {
const navigation = useNavigation();

Expand Down Expand Up @@ -106,6 +109,23 @@ const HeaderView = ({
</View>
) : (
<View style={styles.backButtonWrapper}>
{showBoost && (
<TouchableOpacity onPress={handleOnBoostPress} >
<View style={styles.boostContainer}>
<Icon
style={styles.boostPlusIcon}
name="fire"
iconType="FontAwesome5"
/>
<Icon
style={styles.plusIcon}
name="plus"
iconType="FontAwesome5"
/>
</View>

</TouchableOpacity>
)}
{showQR && (
<IconButton
style={styles.viewIconContainer}
Expand Down
5 changes: 5 additions & 0 deletions src/config/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,11 @@
"boostPost": {
"title": "Boost"
},
"boost_plus":{
"title":"Boost+",
"confirm_boost":"Are you sure to boost?",
"already_boosted":"Account already boosted till {date}"
},
"voters_dropdown": {
"rewards": "REWARDS",
"percent": "PERCENT",
Expand Down
3 changes: 2 additions & 1 deletion src/constants/options/post.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export default [
'promote',
'boost',
//NOTE: post boost option can be enabled later if need by uncommenting option below
//'boost',
'copy',
'reply',
'translate',
Expand Down
2 changes: 2 additions & 0 deletions src/containers/inAppPurchaseContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class InAppPurchaseContainer extends Component {
fetchData,
username,
email,
referral,
handleOnPurchaseFailure,
handleOnPurchaseSuccess,
} = this.props;
Expand Down Expand Up @@ -116,6 +117,7 @@ class InAppPurchaseContainer extends Component {
data.meta = {
username,
email,
referral,
};
}

Expand Down
60 changes: 38 additions & 22 deletions src/containers/redeemContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import get from 'lodash/get';
import { injectIntl } from 'react-intl';

import { useNavigation } from '@react-navigation/native';
import { promote, boost, isPostAvailable } from '../providers/hive/dhive';
import { promote, boost, isPostAvailable, boostPlus } from '../providers/hive/dhive';
import { toastNotification } from '../redux/actions/uiAction';

/*
Expand All @@ -28,41 +28,46 @@ class RedeemContainer extends Component {

// Component Functions

_redeemAction = async (redeemType = 'promote', actionSpecificParam, permlink, author, user) => {
_redeemAction = async (user, redeemType = 'promote', actionSpecificParam, author, permlink) => {
this.setState({ isLoading: true });

const { currentAccount, pinCode, dispatch, intl, navigation } = this.props;
let action;
let specificParam;
let specificParams;
let hiveActionId;

switch (redeemType) {
case 'promote':
action = promote;
specificParam = { duration: actionSpecificParam };
specificParams = { author, permlink, duration: actionSpecificParam };
hiveActionId = 'ecency_promote';
break;

case 'boost':
action = boost;
specificParam = { amount: `${actionSpecificParam.toFixed(3)} POINT` };
specificParams = { author, permlink, amount: `${actionSpecificParam.toFixed(3)} POINT` };
hiveActionId = 'ecency_boost';
break;

case 'boost_plus':
action = boostPlus;
specificParams = { account: author, duration: actionSpecificParam };
hiveActionId = 'ecency_boost_plus';
break;
default:
break;
}

if (get(user, 'local.authType') === 'steemConnect') {
const json = JSON.stringify({
user: get(user, 'name'),
author,
permlink,
...specificParam,
...specificParams,
});
const uriType = redeemType === 'promote' ? 'ecency_promote' : 'ecency_boost';

const uri = `sign/custom-json?authority=active&required_auths=%5B%22${get(
user,
'name',
)}%22%5D&required_posting_auths=%5B%5D&id=${uriType}&json=${encodeURIComponent(json)}`;
)}%22%5D&required_posting_auths=%5B%5D&id=${hiveActionId}&json=${encodeURIComponent(json)}`;

this.setState({
isSCModalOpen: true,
Expand All @@ -72,7 +77,7 @@ class RedeemContainer extends Component {
return;
}

await action(user || currentAccount, pinCode, actionSpecificParam, permlink, author)
await action(user || currentAccount, pinCode, actionSpecificParam, author, permlink)
.then(() => {
navigation.goBack();
dispatch(toastNotification(intl.formatMessage({ id: 'alert.successful' })));
Expand All @@ -90,24 +95,36 @@ class RedeemContainer extends Component {
this.setState({ isLoading: false });
};

_handleOnSubmit = async (redeemType, actionSpecificParam, fullPermlink, selectedUser) => {
_handleOnSubmit = async (
redeemType,
actionSpecificParam,
fullPermlinkOrUsername,
selectedUser,
) => {
const { intl, currentAccount, accounts } = this.props;
const separatedPermlink = fullPermlink.split('/');
const _author = get(separatedPermlink, '[0]');
const _permlink = get(separatedPermlink, '[1]');
const _isPostAvailable = await isPostAvailable(_author, _permlink);

if (!_isPostAvailable) {
Alert.alert(intl.formatMessage({ id: 'alert.not_existing_post' }));
return;
let _author;
let _permlink;

if (redeemType !== 'boost_plus') {
const separatedPermlink = fullPermlinkOrUsername.split('/');
_author = get(separatedPermlink, '[0]');
_permlink = get(separatedPermlink, '[1]');
const _isPostAvailable = await isPostAvailable(_author, _permlink);

if (!_isPostAvailable) {
Alert.alert(intl.formatMessage({ id: 'alert.not_existing_post' }));
return;
}
} else {
_author = fullPermlinkOrUsername;
}

const user =
selectedUser !== currentAccount.username
? currentAccount
: accounts.find((item) => item.username === selectedUser);

this._redeemAction(redeemType, actionSpecificParam, _permlink, _author, user);
this._redeemAction(user, redeemType, actionSpecificParam, _author, _permlink);
};

_handleOnSCModalClose = () => {
Expand All @@ -122,7 +139,6 @@ class RedeemContainer extends Component {
children &&
children({
isLoading,
redeemAction: this._redeemAction,
isSCModalOpen,
SCPath,
handleOnSubmit: this._handleOnSubmit,
Expand Down
42 changes: 40 additions & 2 deletions src/providers/ecency/ecency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -797,11 +797,49 @@ export const getPromotedEntries = async (username: string) => {
}
};

/**
* fetches boost plus prices
* @returns array of prices
*/
export const getBoostPlusPrice = async () => {
try {
console.log('Fetching boost plus prices');
return ecencyApi.post('/private-api/boost-plus-price').then((resp) => {
return resp.data;
});
} catch (error) {
console.warn('Failed to get boost plus prices');
bugsnagInstance.notify(error);
return error;
}
};

/**
* fetches boost plus account
* @param account for knowing if already boosted
* @returns array
*/
export const getBoostPlusAccount = async (account: string) => {
const data = {
account,
};
try {
console.log('Fetching boosted plus account');
return ecencyApi.post('/private-api/boosted-plus-account', data).then((resp) => {
return resp.data;
});
} catch (error) {
console.warn('Failed to get boost plus prices');
bugsnagInstance.notify(error);
return error;
}
};

/**
* TOOD:
* POST /private-api/purchase-order
*
* body:
*
* body:
* platform:string
* product:string
* receipt:string
Expand Down
1 change: 1 addition & 0 deletions src/providers/ecency/ecency.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export interface PurchaseRequestData {
meta?: {
username: string;
email: string;
referral?: string;
};
}

Expand Down
36 changes: 34 additions & 2 deletions src/providers/hive/dhive.js
Original file line number Diff line number Diff line change
Expand Up @@ -1856,7 +1856,7 @@ export const transferPoint = (currentAccount, pinCode, data) => {
}
};

export const promote = (currentAccount, pinCode, duration, permlink, author) => {
export const promote = (currentAccount, pinCode, duration, author, permlink) => {
const pin = getDigitPinCode(pinCode);
const key = getActiveKey(get(currentAccount, 'local'), pin);

Expand Down Expand Up @@ -1889,7 +1889,39 @@ export const promote = (currentAccount, pinCode, duration, permlink, author) =>
}
};

export const boost = (currentAccount, pinCode, point, permlink, author) => {
export const boostPlus = (currentAccount, pinCode, duration, account) => {
const pin = getDigitPinCode(pinCode);
const key = getActiveKey(get(currentAccount, 'local'), pin);

if (key) {
const privateKey = PrivateKey.fromString(key);
const user = get(currentAccount, 'name');

const json = {
id: 'ecency_boost_plus',
json: JSON.stringify({
user,
account,
duration,
}),
required_auths: [user],
required_posting_auths: [],
};
const opArray = [['custom_json', json]];

return sendHiveOperations(opArray, privateKey);
} else {
const err = new Error('Check private key permission! Required private active key or above.');
bugsnagInstance.notify(err, (event) => {
event.setUser(currentAccount.username);
event.context('boost-plus-content');
event.setMetaData('encryptedLocal', currentAccount.local);
});
return Promise.reject(err);
}
};

export const boost = (currentAccount, pinCode, point, author, permlink) => {
const pin = getDigitPinCode(pinCode);
const key = getActiveKey(get(currentAccount, 'local'), pin);

Expand Down
Loading

0 comments on commit 18a2510

Please sign in to comment.