coin card calculations tuning

This commit is contained in:
noumantahir 2022-02-20 04:48:04 +05:00
parent 4cf5664d09
commit e7cdf9c8a4
2 changed files with 10 additions and 7 deletions

View File

@ -44,7 +44,7 @@ export const CoinCard = ({
</View>
<Text
style={styles.textCurValue}>
<Text style={{fontWeight:'500'}}>{`${ownedTokens} ${symbol}`}</Text>
<Text style={{fontWeight:'500'}}>{`${ownedTokens.toFixed(3)} ${symbol}`}</Text>
{`/${(ownedTokens * currentValue).toFixed(2)}${currencySymbol}`}
</Text>
</View>

View File

@ -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 (
<CoinCard
chartData={_tokenMarketData || []}