From d400ff62d08fc253c544a7cf7d1236c16421da8e Mon Sep 17 00:00:00 2001 From: Noah Zinsmeister Date: Wed, 18 Dec 2019 10:53:05 -0500 Subject: [PATCH] add null value checks (#568) --- src/components/CurrencyInputPanel/index.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/components/CurrencyInputPanel/index.js b/src/components/CurrencyInputPanel/index.js index eabbc60fdd..98c6f6f5f0 100644 --- a/src/components/CurrencyInputPanel/index.js +++ b/src/components/CurrencyInputPanel/index.js @@ -456,10 +456,16 @@ function CurrencySelectModal({ isOpen, onDismiss, onTokenSelect }) { let allBalances = useAllBalances() const _usdAmounts = Object.keys(allTokens).map(k => { - if (ethPrice && allBalances[account] && allBalances[account][k]) { + if (ethPrice && allBalances[account] && allBalances[account][k] && allBalances[account][k].value) { let ethRate = 1 // default for ETH let exchangeDetails = allBalances[allTokens[k].exchangeAddress] - if (exchangeDetails && exchangeDetails[k] && exchangeDetails['ETH']) { + if ( + exchangeDetails && + exchangeDetails[k] && + exchangeDetails[k].value && + exchangeDetails['ETH'] && + exchangeDetails['ETH'].value + ) { const tokenBalance = new BigNumber(exchangeDetails[k].value.toString()) const ethBalance = new BigNumber(exchangeDetails['ETH'].value.toString()) ethRate = ethBalance.div(tokenBalance) @@ -511,10 +517,10 @@ function CurrencySelectModal({ isOpen, onDismiss, onTokenSelect }) { let balance let usdBalance // only update if we have data - if (k === 'ETH' && allBalances[account] && allBalances[account][k]) { + if (k === 'ETH' && allBalances[account] && allBalances[account][k] && allBalances[account][k].value) { balance = formatEthBalance(allBalances[account][k].value) usdBalance = usdAmounts[k] - } else if (allBalances[account] && allBalances[account][k]) { + } else if (allBalances[account] && allBalances[account][k] && allBalances[account][k].value) { balance = formatTokenBalance(allBalances[account][k].value, allTokens[k].decimals) usdBalance = usdAmounts[k] }