mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-11-28 01:52:56 +03:00
Merge pull request #360 from esteemapp/feature/reward
created unclaimed reward functions
This commit is contained in:
commit
2a83842160
@ -1,4 +1,4 @@
|
||||
// import Card from './view/cardView';
|
||||
import Card from './view/card/cardView';
|
||||
import Chip from './view/chip/chipView';
|
||||
import GrayWrapper from './view/grayWrapper/grayWrapperView';
|
||||
import LineBreak from './view/lineBreak/lineBreakView';
|
||||
@ -6,29 +6,30 @@ import NoPost from './view/noPost/noPostView';
|
||||
import PostCardPlaceHolder from './view/placeHolder/postCardPlaceHolderView';
|
||||
import PostPlaceHolder from './view/placeHolder/postPlaceHolderView';
|
||||
import ProfileSummaryPlaceHolder from './view/placeHolder/profileSummaryPlaceHolder';
|
||||
import WalletDetailsPlaceHolder from './view/placeHolder/walletDetailsPlaceHolder';
|
||||
import WalletUnclaimedPlaceHolder from './view/placeHolder/walletUnclaimedPlaceHolder';
|
||||
import RefreshControl from './view/refreshControl/refreshControlView';
|
||||
import StickyBar from './view/stickyBar/stickyBarView';
|
||||
import Tag from './view/tag/tagView';
|
||||
import TextWithIcon from './view/textWithIcon/textWithIconView';
|
||||
import WalletLineItem from './view/walletLineItem/walletLineItemView';
|
||||
import StickyBar from './view/stickyBar/stickyBarView';
|
||||
import Card from './view/card/cardView';
|
||||
import UserListItem from './view/userListItem/userListItem';
|
||||
import WalletDetailsPlaceHolder from './view/placeHolder/walletDetailsPlaceHolder';
|
||||
import WalletLineItem from './view/walletLineItem/walletLineItemView';
|
||||
import WalletUnclaimedPlaceHolder from './view/placeHolder/walletUnclaimedPlaceHolder';
|
||||
|
||||
export {
|
||||
Card,
|
||||
StickyBar,
|
||||
Chip,
|
||||
GrayWrapper,
|
||||
UserListItem,
|
||||
LineBreak,
|
||||
NoPost,
|
||||
PostCardPlaceHolder,
|
||||
PostPlaceHolder,
|
||||
ProfileSummaryPlaceHolder,
|
||||
WalletDetailsPlaceHolder,
|
||||
WalletUnclaimedPlaceHolder,
|
||||
RefreshControl,
|
||||
StickyBar,
|
||||
Tag,
|
||||
TextWithIcon,
|
||||
UserListItem,
|
||||
WalletDetailsPlaceHolder,
|
||||
WalletLineItem,
|
||||
WalletUnclaimedPlaceHolder,
|
||||
};
|
||||
|
@ -4,7 +4,7 @@ export default EStyleSheet.create({
|
||||
wrapper: {
|
||||
flexDirection: 'column',
|
||||
backgroundColor: '$primaryBackgroundColor',
|
||||
shadowOpacity: 0.8,
|
||||
shadowOpacity: 0.2,
|
||||
shadowColor: '#e7e7e7',
|
||||
paddingHorizontal: 8,
|
||||
paddingVertical: 8,
|
||||
|
@ -0,0 +1,20 @@
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { RefreshControl } from 'react-native';
|
||||
|
||||
const RefreshControlView = ({ refreshing, onRefresh, isDarkTheme }) => (
|
||||
<RefreshControl
|
||||
refreshing={refreshing}
|
||||
onRefresh={onRefresh}
|
||||
progressBackgroundColor="#357CE6"
|
||||
tintColor={!isDarkTheme ? '#357ce6' : '#96c0ff'}
|
||||
titleColor="#fff"
|
||||
colors={['#fff']}
|
||||
/>
|
||||
);
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
currentAccount: state.application.isDarkTheme,
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps)(RefreshControlView);
|
@ -1,7 +1,5 @@
|
||||
import React, { Component, Fragment } from 'react';
|
||||
import {
|
||||
FlatList, View, ActivityIndicator, RefreshControl,
|
||||
} from 'react-native';
|
||||
import { FlatList, View, ActivityIndicator } from 'react-native';
|
||||
import { injectIntl } from 'react-intl';
|
||||
import { withNavigation } from 'react-navigation';
|
||||
|
||||
@ -11,7 +9,7 @@ import { getPostsSummary } from '../../../providers/steem/dsteem';
|
||||
// COMPONENTS
|
||||
import { PostCard } from '../../postCard';
|
||||
import { FilterBar } from '../../filterBar';
|
||||
import { PostCardPlaceHolder, NoPost } from '../../basicUIElements';
|
||||
import { PostCardPlaceHolder, NoPost, RefreshControl } from '../../basicUIElements';
|
||||
import { POPULAR_FILTERS, PROFILE_FILTERS } from '../../../constants/options/filters';
|
||||
|
||||
// Styles
|
||||
@ -260,17 +258,15 @@ class PostsView extends Component {
|
||||
/>
|
||||
)}
|
||||
<Fragment>
|
||||
{ getFor === 'feed'
|
||||
&& isLoginDone
|
||||
&& !isLoggedIn && (
|
||||
<NoPost
|
||||
imageStyle={styles.noImage}
|
||||
isButtonText
|
||||
defaultText={intl.formatMessage({
|
||||
id: 'profile.login_to_see',
|
||||
})}
|
||||
handleOnButtonPress={this._handleOnPressLogin}
|
||||
/>
|
||||
{getFor === 'feed' && isLoginDone && !isLoggedIn && (
|
||||
<NoPost
|
||||
imageStyle={styles.noImage}
|
||||
isButtonText
|
||||
defaultText={intl.formatMessage({
|
||||
id: 'profile.login_to_see',
|
||||
})}
|
||||
handleOnButtonPress={this._handleOnPressLogin}
|
||||
/>
|
||||
)}
|
||||
</Fragment>
|
||||
|
||||
@ -290,16 +286,9 @@ class PostsView extends Component {
|
||||
initialNumToRender={10}
|
||||
ListFooterComponent={this._renderFooter}
|
||||
onScrollBeginDrag={() => this._handleOnScrollStart()}
|
||||
refreshControl={(
|
||||
<RefreshControl
|
||||
refreshing={refreshing}
|
||||
onRefresh={this._handleOnRefreshPosts}
|
||||
progressBackgroundColor="#357CE6"
|
||||
tintColor={!isDarkTheme ? '#357ce6' : '#96c0ff'}
|
||||
titleColor="#fff"
|
||||
colors={['#fff']}
|
||||
/>
|
||||
)}
|
||||
refreshControl={
|
||||
<RefreshControl refreshing={refreshing} onRefresh={this._handleOnRefreshPosts} />
|
||||
}
|
||||
ref={(ref) => {
|
||||
this.flatList = ref;
|
||||
}}
|
||||
|
@ -1,5 +1,10 @@
|
||||
import React, { Component } from 'react';
|
||||
import { Alert } from 'react-native';
|
||||
import { connect } from 'react-redux';
|
||||
import { injectIntl } from 'react-intl';
|
||||
|
||||
// Dsteem
|
||||
import { getAccount, claimRewardBalance } from '../../../providers/steem/dsteem';
|
||||
|
||||
// Utils
|
||||
import { groomingWalletData } from '../../../utils/wallet';
|
||||
@ -20,32 +25,110 @@ class WalletContainer extends Component {
|
||||
super(props);
|
||||
this.state = {
|
||||
walletData: null,
|
||||
claiming: false,
|
||||
isRefreshing: false,
|
||||
};
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
componentDidMount() {
|
||||
const { selectedUser } = this.props;
|
||||
|
||||
this._getWalletData(selectedUser);
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
const { selectedUser } = this.props;
|
||||
|
||||
if (selectedUser.name !== nextProps.selectedUser.name) {
|
||||
this._getWalletData(nextProps.selectedUser);
|
||||
}
|
||||
}
|
||||
|
||||
// Components functions
|
||||
|
||||
_getWalletData = async (selectedUser) => {
|
||||
const walletData = await groomingWalletData(selectedUser);
|
||||
|
||||
this.setState({ walletData });
|
||||
}
|
||||
};
|
||||
|
||||
_claimRewardBalance = () => {
|
||||
const { currentAccount, intl, pinCode } = this.props;
|
||||
const { claiming } = this.state;
|
||||
|
||||
if (claiming) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setState({ claiming: true });
|
||||
|
||||
getAccount(currentAccount.name)
|
||||
.then((account) => {
|
||||
const {
|
||||
reward_steem_balance: steemBal,
|
||||
reward_sbd_balance: sbdBal,
|
||||
reward_vesting_balance: vestingBal,
|
||||
} = account[0];
|
||||
|
||||
return claimRewardBalance(currentAccount, pinCode, steemBal, sbdBal, vestingBal);
|
||||
})
|
||||
.then(() => getAccount(currentAccount.name))
|
||||
.then((account) => {
|
||||
Alert.alert(
|
||||
intl.formatMessage({
|
||||
id: 'alert.claim_reward_balance_ok',
|
||||
}),
|
||||
);
|
||||
this._getWalletData(account[0]);
|
||||
})
|
||||
.then((account) => {
|
||||
this._getWalletData(account[0]);
|
||||
})
|
||||
.catch((err) => {
|
||||
Alert.alert(err);
|
||||
})
|
||||
.finally(() => {
|
||||
this.setState({ claiming: false });
|
||||
});
|
||||
};
|
||||
|
||||
_handleOnWalletRefresh = () => {
|
||||
const { selectedUser } = this.props;
|
||||
this.setState({ isRefreshing: true });
|
||||
|
||||
getAccount(selectedUser.name)
|
||||
.then((account) => {
|
||||
this._getWalletData(account[0]);
|
||||
})
|
||||
.catch((err) => {
|
||||
Alert.alert(err);
|
||||
})
|
||||
.finally(() => {
|
||||
this.setState({ isRefreshing: false });
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
const { currentAccountUsername, selectedUser } = this.props;
|
||||
const { walletData } = this.state;
|
||||
const { currentAccount, selectedUser } = this.props;
|
||||
const { walletData, claiming, isRefreshing } = this.state;
|
||||
|
||||
return (
|
||||
<WalletView
|
||||
currentAccountUsername={currentAccountUsername}
|
||||
currentAccountUsername={currentAccount.name}
|
||||
selectedUsername={selectedUser && selectedUser.name}
|
||||
walletData={walletData}
|
||||
claimRewardBalance={this._claimRewardBalance}
|
||||
claiming={claiming}
|
||||
handleOnWalletRefresh={this._handleOnWalletRefresh}
|
||||
isRefreshing={isRefreshing}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
currentAccountUsername: state.account.currentAccount.name,
|
||||
currentAccount: state.account.currentAccount,
|
||||
pinCode: state.account.pin,
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps)(WalletContainer);
|
||||
export default injectIntl(connect(mapStateToProps)(WalletContainer));
|
||||
|
@ -8,7 +8,7 @@ import { MainButton } from '../../mainButton';
|
||||
import { CollapsibleCard } from '../../collapsibleCard';
|
||||
import { WalletDetails } from '../../walletDetails';
|
||||
import { Transaction } from '../../transaction';
|
||||
import { WalletDetailsPlaceHolder } from '../../basicUIElements';
|
||||
import { WalletDetailsPlaceHolder, RefreshControl } from '../../basicUIElements';
|
||||
|
||||
// Styles
|
||||
import styles from './walletStyles';
|
||||
@ -44,11 +44,23 @@ class WalletView extends PureComponent {
|
||||
|
||||
render() {
|
||||
const {
|
||||
currentAccountUsername, intl, selectedUsername, walletData,
|
||||
claiming,
|
||||
claimRewardBalance,
|
||||
currentAccountUsername,
|
||||
handleOnWalletRefresh,
|
||||
intl,
|
||||
isRefreshing,
|
||||
selectedUsername,
|
||||
walletData,
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
<ScrollView style={styles.scrollView}>
|
||||
<ScrollView
|
||||
refreshControl={
|
||||
<RefreshControl refreshing={isRefreshing} onRefresh={handleOnWalletRefresh} />
|
||||
}
|
||||
style={styles.scrollView}
|
||||
>
|
||||
{!walletData ? (
|
||||
<Fragment>
|
||||
<WalletDetailsPlaceHolder />
|
||||
@ -66,9 +78,10 @@ class WalletView extends PureComponent {
|
||||
>
|
||||
{currentAccountUsername === selectedUsername ? (
|
||||
<MainButton
|
||||
isLoading={claiming}
|
||||
style={styles.mainButton}
|
||||
height={50}
|
||||
onPress={this._handleOnPressLogin}
|
||||
onPress={claimRewardBalance}
|
||||
>
|
||||
<View style={styles.mainButtonWrapper}>
|
||||
{this._getUnclaimedText(walletData)}
|
||||
|
@ -124,6 +124,7 @@
|
||||
"alert": {
|
||||
"success": "Success!",
|
||||
"allRead": "Marked all notifications as read",
|
||||
"claim_reward_balance_ok": "Reward balance claimed",
|
||||
"fail": "Fail!",
|
||||
"success_shared": "Your post succesfully shared",
|
||||
"permission_denied": "Permission denied",
|
||||
|
@ -124,6 +124,7 @@
|
||||
"alert": {
|
||||
"success": "Успех!",
|
||||
"allRead": "Всё прочтено",
|
||||
"claim_reward_balance_ok": "Награда зачислена на баланс",
|
||||
"fail": "Не вышло!",
|
||||
"success_shared": "Успешно поделились постом!",
|
||||
"permission_denied": "Доступ запрещён",
|
||||
|
@ -124,6 +124,7 @@
|
||||
"alert": {
|
||||
"success": "Başarılı!",
|
||||
"allRead": "Tüm bildirimler okundu",
|
||||
"claim_reward_balance_ok": "Ödül bakiyesi talep edildi.",
|
||||
"fail": "Başarısız!",
|
||||
"success_shared": "Post'un başarıyla paylaşıldı.",
|
||||
"permission_denied": "Izin Alınamadı",
|
||||
|
@ -769,3 +769,46 @@ export const reblog = async (account, pinCode, author, permlink) => {
|
||||
return api.reblog(follower, author, permlink);
|
||||
}
|
||||
};
|
||||
|
||||
export const claimRewardBalance = (
|
||||
account,
|
||||
pinCode,
|
||||
rewardSteem,
|
||||
rewardSbd,
|
||||
rewardVests,
|
||||
) => {
|
||||
const pin = getDigitPinCode(pinCode);
|
||||
|
||||
if (account.local.authType === AUTH_TYPE.MASTER_KEY) {
|
||||
const key = decryptKey(account.local.postingKey, pin);
|
||||
const privateKey = PrivateKey.fromString(key);
|
||||
|
||||
const opArray = [
|
||||
[
|
||||
'claim_reward_balance',
|
||||
{
|
||||
account: account.name,
|
||||
reward_steem: rewardSteem,
|
||||
reward_sbd: rewardSbd,
|
||||
reward_vests: rewardVests,
|
||||
},
|
||||
],
|
||||
];
|
||||
|
||||
return client.broadcast.sendOperations(opArray, privateKey);
|
||||
}
|
||||
|
||||
if (account.local.authType === AUTH_TYPE.STEEM_CONNECT) {
|
||||
const token = decryptKey(account.local.accessToken, pin);
|
||||
const api = steemConnect.Initialize({
|
||||
accessToken: token,
|
||||
});
|
||||
|
||||
return api.claimRewardBalance(
|
||||
account.name,
|
||||
rewardSteem,
|
||||
rewardSbd,
|
||||
rewardVests,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user