Added estimated value for wallet

This commit is contained in:
Mustafa Buyukcelebi 2019-01-24 12:14:09 +03:00
parent 394560ecc7
commit 593bec4d7b
3 changed files with 33 additions and 13 deletions

View File

@ -47,9 +47,11 @@ class WalletContainer extends Component {
// Components functions
_getWalletData = async (selectedUser) => {
const { setEstimatedWalletValue } = this.props;
const walletData = await groomingWalletData(selectedUser);
this.setState({ walletData });
setEstimatedWalletValue(walletData.estimatedValue);
};
_claimRewardBalance = async () => {

View File

@ -32,6 +32,7 @@ class ProfileScreen extends PureComponent {
this.state = {
isSummaryOpen: true,
collapsibleMoreHeight: 0,
estimatedWalletValue: 0,
};
}
@ -51,6 +52,10 @@ class ProfileScreen extends PureComponent {
this.setState({ collapsibleMoreHeight: height });
};
_setEstimatedWalletValue = (value) => {
if (value) this.setState({ estimatedWalletValue: value });
}
render() {
const {
about,
@ -76,7 +81,7 @@ class ProfileScreen extends PureComponent {
getReplies,
} = this.props;
const { isSummaryOpen, collapsibleMoreHeight } = this.state;
const { isSummaryOpen, collapsibleMoreHeight, estimatedWalletValue } = this.state;
let _about;
let coverImage;
@ -198,11 +203,20 @@ class ProfileScreen extends PureComponent {
)}
</View>
<View
tabLabel={intl.formatMessage({
id: 'profile.wallet',
})}
tabLabel={estimatedWalletValue
? `$${Math.round(estimatedWalletValue * 1000) / 1000}`
: intl.formatMessage({
id: 'profile.wallet',
})}
>
{selectedUser ? <Wallet selectedUser={selectedUser} /> : <WalletDetailsPlaceHolder />}
{selectedUser
? (
<Wallet
setEstimatedWalletValue={this._setEstimatedWalletValue}
selectedUser={selectedUser}
/>
)
: <WalletDetailsPlaceHolder />}
</View>
</ScrollableTabView>
</View>

View File

@ -1,7 +1,7 @@
import parseDate from './parseDate';
import parseToken from './parseToken';
import { vestsToSp } from './conversions';
import { globalProps, getState } from '../providers/steem/dsteem';
import { globalProps, getState, getFeedHistory } from '../providers/steem/dsteem';
export const groomingTransactionData = (transaction, walletData, formatNumber) => {
if (!transaction || !walletData) {
@ -129,15 +129,19 @@ export const groomingWalletData = async (user) => {
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);
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.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.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());