From e7cdf9c8a4f456111fab61b54a5f901b0f49a100 Mon Sep 17 00:00:00 2001 From: noumantahir Date: Sun, 20 Feb 2022 04:48:04 +0500 Subject: [PATCH] coin card calculations tuning --- src/screens/wallet/children/coinCard.tsx | 2 +- src/screens/wallet/screen/walletScreen.tsx | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/screens/wallet/children/coinCard.tsx b/src/screens/wallet/children/coinCard.tsx index 3bcb0b423..9854d2c7b 100644 --- a/src/screens/wallet/children/coinCard.tsx +++ b/src/screens/wallet/children/coinCard.tsx @@ -44,7 +44,7 @@ export const CoinCard = ({ - {`${ownedTokens} ${symbol}`} + {`${ownedTokens.toFixed(3)} ${symbol}`} {`/${(ownedTokens * currentValue).toFixed(2)}${currencySymbol}`} diff --git a/src/screens/wallet/screen/walletScreen.tsx b/src/screens/wallet/screen/walletScreen.tsx index 3924b4c5e..559a3f07b 100644 --- a/src/screens/wallet/screen/walletScreen.tsx +++ b/src/screens/wallet/screen/walletScreen.tsx @@ -90,14 +90,17 @@ const WalletScreen = ({navigation}) => { const coinData = coinsData[item.id] || {}; - const _tokenMarketData = priceHistories[item.id] ? priceHistories[item.id].data : []; + 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 _changePercent = - _tokenMarketData.length > 0 ? - ((_tokenMarketData[_tokenMarketData.length - 1] - _tokenMarketData[0])/(_tokenMarketData[_tokenMarketData.length - 1]))*100 - : - 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 + const _pastPrice = _tokenMarketData.length > 0 && _tokenMarketData[0]; + const _latestPrice = _tokenMarketData.length > 0 && _tokenMarketData.lastItem; + const _changePercent = _pastPrice && _latestPrice + ? ((_latestPrice - _pastPrice)/(_latestPrice)) * 100 : 0; + return (