From 07c0e8fb361ca3abc7fe13989d7729191cb7f4bc Mon Sep 17 00:00:00 2001 From: noumantahir Date: Sun, 20 Feb 2022 07:57:01 +0500 Subject: [PATCH] processing hive power base data --- src/redux/reducers/walletReducer.ts | 1 + src/screens/wallet/children/coinCard.tsx | 2 +- src/screens/wallet/screen/walletScreen.tsx | 2 +- src/utils/wallet.ts | 37 ++++++++++++++++------ 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/redux/reducers/walletReducer.ts b/src/redux/reducers/walletReducer.ts index c17ce716f..530bb699f 100644 --- a/src/redux/reducers/walletReducer.ts +++ b/src/redux/reducers/walletReducer.ts @@ -12,6 +12,7 @@ export interface CoinData { currentPrice:number; balance:number; savings:number; + unclaimedBalance:string, estimateValue:number; vsCurrency:string; } diff --git a/src/screens/wallet/children/coinCard.tsx b/src/screens/wallet/children/coinCard.tsx index 9854d2c7b..bfb776498 100644 --- a/src/screens/wallet/children/coinCard.tsx +++ b/src/screens/wallet/children/coinCard.tsx @@ -30,7 +30,7 @@ export const CoinCard = ({ onPress }:CoinCardProps) => { - console.log(chartData); + if(!notCrypto && !chartData.length){ return null } diff --git a/src/screens/wallet/screen/walletScreen.tsx b/src/screens/wallet/screen/walletScreen.tsx index 559a3f07b..0e700c24e 100644 --- a/src/screens/wallet/screen/walletScreen.tsx +++ b/src/screens/wallet/screen/walletScreen.tsx @@ -92,7 +92,7 @@ const WalletScreen = ({navigation}) => { const _tokenMarketData:number[] = priceHistories[item.id] ? priceHistories[item.id].data : []; const _currentValue = item.id == 'ecency' ? 1/150 : (coinData.currentPrice || 0); - const _balance = item.id === 'ececny' ? 3 : (coinData.balance + coinData.savings); + const _balance = item.id === 'ecency' ? 3 : (coinData.balance + (coinData.savings || 0)); //calculate percentage change //TODO: verify or find a way to get exact percent change. current change value slightly differs from coingecko wep app values diff --git a/src/utils/wallet.ts b/src/utils/wallet.ts index 2f7bd441e..7a0741a9e 100644 --- a/src/utils/wallet.ts +++ b/src/utils/wallet.ts @@ -7,6 +7,7 @@ import { getCurrencyTokenRate } from '../providers/ecency/ecency'; import { CoinBase, CoinData } from '../redux/reducers/walletReducer'; import { GlobalProps } from '../redux/reducers/accountReducer'; import { COIN_IDS } from '../constants/defaultCoins'; +import { getEstimatedAmount } from './vote'; export const transferTypes = [ 'curation_reward', @@ -259,10 +260,12 @@ export const fetchCoinsData = async ( ) : Promise<{[key:string]:CoinData}> => { - const coinData = {} as {[key:string]:CoinData}; + const {base, quote, hivePerMVests} = globalProps + const coinData = {} as {[key:string]:CoinData}; const walletData = {} as any; + if (!username) { return walletData; } @@ -286,7 +289,8 @@ export const fetchCoinsData = async ( estimateValue: (balance + savings) * ppHive, savings:Math.round(savings * 1000) / 1000, vsCurrency:vsCurrency, - currentPrice:ppHive + currentPrice:ppHive, + unclaimedBalance:'', } break; } @@ -300,20 +304,33 @@ export const fetchCoinsData = async ( estimateValue: (balance + savings) * ppHbd, savings:Math.round(savings * 1000) / 1000, vsCurrency:vsCurrency, - currentPrice:ppHbd + currentPrice:ppHbd, + unclaimedBalance:'', } break; } case COIN_IDS.HP:{ - //TODO: set correct values - const balance = parseToken(userdata.hbd_balance); - const savings = parseToken(userdata.savings_hbd_balance); + const _getBalance = (val:number, cur:string) => (val ? Math.round(val * 1000) / 1000 + cur : ''); + const balance = Math.round( + vestsToHp(parseToken(userdata.vesting_shares), hivePerMVests) * 1000, + ) / 1000; + + const unclaimedBalance = + `${_getBalance(parseToken(userdata.reward_hive_balance), ' HIVE')} ` + + `${_getBalance(parseToken(userdata.reward_hive_balance),' HBD')} ` + + `${_getBalance(parseToken(userdata.reward_vesting_hive), ' HP')}` + + //TODO: assess how we can make this value change live. + const estimateValueStr = getEstimatedAmount(userdata, globalProps); + + coinData[coinBase.id] = { balance: Math.round(balance * 1000) / 1000, - estimateValue: (balance + savings) * ppHbd, - savings:Math.round(savings * 1000) / 1000, + estimateValue: parseFloat(estimateValueStr), + unclaimedBalance, vsCurrency:vsCurrency, - currentPrice:ppHbd + currentPrice:ppHbd, + savings:0, } break; } @@ -343,7 +360,7 @@ export const fetchCoinsData = async ( walletData.savingBalanceHbd = parseToken(userdata.savings_hbd_balance); - const {base, quote, hivePerMVests} = globalProps + walletData.hivePerMVests = hivePerMVests; const pricePerHive = base / quote;