#fixed clclosed #326

This commit is contained in:
u-e 2019-01-04 15:11:48 +03:00
parent b399ec25b3
commit 06222356f7
5 changed files with 87 additions and 78 deletions

View File

@ -2,7 +2,7 @@ import React, { PureComponent, Fragment } from 'react';
import { injectIntl } from 'react-intl';
// Utilities
import { getTransactionData } from '../../../utils/wallet';
import { groomingTransactionData } from '../../../utils/wallet';
// Components
// import { FilterBar } from '../../filterBar';
@ -48,7 +48,7 @@ class TransactionView extends PureComponent {
<Card>
{transactions
&& transactions.map((item, index) => {
const transactionData = getTransactionData(item, walletData, formatNumber);
const transactionData = groomingTransactionData(item, walletData, formatNumber);
return (
<CollapsibleCard

View File

@ -1,23 +1,17 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
// Services and Actions
import { globalProps, getState } from '../../../providers/steem/dsteem';
// Middleware
// Constants
// Utilities
import parseToken from '../../../utils/parseToken';
import parseDate from '../../../utils/parseDate';
// Utils
import { groomingWalletData } from '../../../utils/wallet';
// Component
import WalletView from '../view/walletView';
/*
* Props Name Description Value
*@props --> props name here description here Value Type Here
* Props Name Description Value
* @props --> currentAccountUsername description here Value Type Here
@ props --> selectedUsername
@ props --> walletData
*
*/
@ -29,76 +23,30 @@ class WalletContainer extends Component {
};
}
// Component Life Cycle Functions
async componentWillMount() {
const { user } = this.props;
const walletData = {};
// TODO: move them to utils these so big for a lifecycle function
walletData.rewardSteemBalance = parseToken(user.reward_steem_balance);
walletData.rewardSbdBalance = parseToken(user.reward_sbd_balance);
walletData.rewardVestingSteem = parseToken(user.reward_vesting_steem);
walletData.hasUnclaimedRewards = walletData.rewardSteemBalance > 0
|| walletData.rewardSbdBalance > 0
|| walletData.rewardVestingSteem > 0;
walletData.balance = parseToken(user.balance);
walletData.vestingShares = parseToken(user.vesting_shares);
walletData.vestingSharesDelegated = parseToken(user.delegated_vesting_shares);
walletData.vestingSharesReceived = parseToken(user.received_vesting_shares);
walletData.vestingSharesTotal = walletData.vestingShares
- walletData.vestingSharesDelegated
+ walletData.vestingSharesReceived;
walletData.sbdBalance = parseToken(user.sbd_balance);
walletData.savingBalance = parseToken(user.savings_balance);
walletData.savingBalanceSbd = parseToken(user.savings_sbd_balance);
const global = await globalProps();
// const feedHistory = await getFeedHistory();
// const base = parseToken(feedHistory.current_median_history.base);
// const quote = parseToken(feedHistory.current_median_history.quote);
walletData.steemPerMVests = (parseToken(global.total_vesting_fund_steem) / parseToken(global.total_vesting_shares)) * 1e6;
// walletData.estimatedValue = vestsToSp(walletData.vestingShares, walletData.steemPerMVests) * (base / quote)
// + walletData.balance * (base / quote)
// + walletData.sbdBalance;
walletData.showPowerDown = user.next_vesting_withdrawal !== '1969-12-31T23:59:59';
const timeDiff = Math.abs(parseDate(user.next_vesting_withdrawal) - new Date());
walletData.nextVestingWithdrawal = Math.ceil(timeDiff / (1000 * 3600 * 24));
const state = await getState(`/@${user.name}/transfers`);
const { accounts } = state;
const { transfer_history: transferHistory } = accounts[user.name];
walletData.transactions = transferHistory
.slice(Math.max(transferHistory.length - 20, 0))
.reverse();
async componentDidMount() {
const { selectedUser } = this.props;
const walletData = await groomingWalletData(selectedUser);
this.setState({ walletData });
}
// Component Functions
render() {
const { currentAccountUsername, selectedUser, intl } = this.props;
const { walletData } = this.state;
const { currentAccount, user } = this.props;
return (
<WalletView
currentAccountUsername={currentAccount.username}
selectedUsername={user.username}
{...this.props}
currentAccountUsername={currentAccountUsername}
selectedUsername={selectedUser && selectedUser.name}
walletData={walletData}
intl={intl}
/>
);
}
}
const mapStateToProps = state => ({
currentAccount: state.account.currentAccount,
currentAccountUsername: state.account.currentAccount.name,
});
export default connect(mapStateToProps)(WalletContainer);

View File

@ -296,7 +296,7 @@ class ProfileContainer extends Component {
isProfileLoading={isProfileLoading}
isReady={isReady}
isReverseHeader={isReverseHeader}
user={user}
selectedUser={user}
username={username}
/>
</Fragment>

View File

@ -7,7 +7,11 @@ import ScrollableTabView from '@esteemapp/react-native-scrollable-tab-view';
import { Comments } from '../../../components/comments';
import { CollapsibleCard } from '../../../components/collapsibleCard';
import { Header } from '../../../components/header';
import { NoPost, ProfileSummaryPlaceHolder } from '../../../components/basicUIElements';
import {
NoPost,
ProfileSummaryPlaceHolder,
WalletDetailsPlaceHolder,
} from '../../../components/basicUIElements';
import { Posts } from '../../../components/posts';
import { ProfileSummary } from '../../../components/profileSummary';
import { TabBar } from '../../../components/tabBar';
@ -63,7 +67,7 @@ class ProfileScreen extends PureComponent {
isReady,
isReverseHeader,
selectedQuickProfile,
user,
selectedUser,
username,
} = this.props;
@ -78,9 +82,9 @@ class ProfileScreen extends PureComponent {
let fullInHourVP;
let fullInHourRC;
if (user) {
votingPower = getVotingPower(user).toFixed(1);
resourceCredits = getRcPower(user).toFixed(1);
if (selectedUser) {
votingPower = getVotingPower(selectedUser).toFixed(1);
resourceCredits = getRcPower(selectedUser).toFixed(1);
fullInHourVP = Math.ceil((100 - votingPower) * 0.833333);
fullInHourRC = Math.ceil((100 - resourceCredits) * 0.833333);
}
@ -117,7 +121,7 @@ class ProfileScreen extends PureComponent {
>
<ProfileSummary
coverImage={coverImage}
date={getFormatedCreatedDate(user && user.created)}
date={getFormatedCreatedDate(selectedUser && selectedUser.created)}
followerCount={follows.follower_count}
followingCount={follows.following_count}
handleFollowUnfollowUser={handleFollowUnfollowUser}
@ -190,7 +194,13 @@ class ProfileScreen extends PureComponent {
id: 'profile.wallet',
})}
>
<Wallet user={user} intl={intl} />
{selectedUser ? (
<Wallet selectedUser={selectedUser} intl={intl} />
) : (
<Fragment>
<WalletDetailsPlaceHolder />
</Fragment>
)}
</View>
</ScrollableTabView>
</View>

View File

@ -1,8 +1,9 @@
// import parseDate from './parseDate';
import parseDate from './parseDate';
import parseToken from './parseToken';
import { vestsToSp } from './conversions';
import { globalProps, getState } from '../providers/steem/dsteem';
export const getTransactionData = (transaction, walletData, formatNumber) => {
export const groomingTransactionData = (transaction, walletData, formatNumber) => {
if (!transaction || !walletData) {
return [];
}
@ -99,3 +100,53 @@ export const getTransactionData = (transaction, walletData, formatNumber) => {
}
return result;
};
export const groomingWalletData = async (user) => {
const walletData = {};
if (!user) {
return walletData;
}
const global = await globalProps();
const state = await getState(`/@${user.name}/transfers`);
const { accounts } = state;
// TODO: move them to utils these so big for a lifecycle function
walletData.rewardSteemBalance = parseToken(user.reward_steem_balance);
walletData.rewardSbdBalance = parseToken(user.reward_sbd_balance);
walletData.rewardVestingSteem = parseToken(user.reward_vesting_steem);
walletData.hasUnclaimedRewards = walletData.rewardSteemBalance > 0
|| walletData.rewardSbdBalance > 0
|| walletData.rewardVestingSteem > 0;
walletData.balance = parseToken(user.balance);
walletData.vestingShares = parseToken(user.vesting_shares);
walletData.vestingSharesDelegated = parseToken(user.delegated_vesting_shares);
walletData.vestingSharesReceived = parseToken(user.received_vesting_shares);
walletData.vestingSharesTotal = walletData.vestingShares - walletData.vestingSharesDelegated + walletData.vestingSharesReceived;
walletData.sbdBalance = parseToken(user.sbd_balance);
walletData.savingBalance = parseToken(user.savings_balance);
walletData.savingBalanceSbd = parseToken(user.savings_sbd_balance);
// const feedHistory = await getFeedHistory();
// const base = parseToken(feedHistory.current_median_history.base);
// const quote = parseToken(feedHistory.current_median_history.quote);
walletData.steemPerMVests = (parseToken(global.total_vesting_fund_steem) / parseToken(global.total_vesting_shares)) * 1e6;
// walletData.estimatedValue = vestsToSp(walletData.vestingShares, walletData.steemPerMVests) * (base / quote)
// + walletData.balance * (base / quote)
// + walletData.sbdBalance;
walletData.showPowerDown = user.next_vesting_withdrawal !== '1969-12-31T23:59:59';
const timeDiff = Math.abs(parseDate(user.next_vesting_withdrawal) - new Date());
walletData.nextVestingWithdrawal = Math.ceil(timeDiff / (1000 * 3600 * 24));
const { transfer_history: transferHistory } = accounts[user.name];
walletData.transactions = transferHistory
.slice(Math.max(transferHistory.length - 20, 0))
.reverse();
return walletData;
};