1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

show failed token balance updates (#9896)

This commit is contained in:
Brad Decker 2020-11-18 16:13:28 -06:00 committed by GitHub
parent e90bddf44f
commit 5be20d105e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 16 deletions

View File

@ -10,7 +10,7 @@ import { useTokenFiatAmount } from '../../../hooks/useTokenFiatAmount'
export default function TokenCell({ export default function TokenCell({
address, address,
decimals, decimals,
outdatedBalance, balanceError,
symbol, symbol,
string, string,
image, image,
@ -21,13 +21,14 @@ export default function TokenCell({
const formattedFiat = useTokenFiatAmount(address, string, symbol) const formattedFiat = useTokenFiatAmount(address, string, symbol)
const warning = outdatedBalance ? ( const warning = balanceError ? (
<span> <span>
{t('troubleTokenBalances')} {t('troubleTokenBalances')}
<a <a
href={`https://ethplorer.io/address/${userAddress}`} href={`https://ethplorer.io/address/${userAddress}`}
rel="noopener noreferrer" rel="noopener noreferrer"
target="_blank" target="_blank"
onClick={(event) => event.stopPropagation()}
style={{ color: '#F7861C' }} style={{ color: '#F7861C' }}
> >
{t('here')} {t('here')}
@ -38,7 +39,7 @@ export default function TokenCell({
return ( return (
<AssetListItem <AssetListItem
className={classnames('token-cell', { className={classnames('token-cell', {
'token-cell--outdated': outdatedBalance, 'token-cell--outdated': Boolean(balanceError),
})} })}
iconClassName="token-cell__icon" iconClassName="token-cell__icon"
onClick={onClick.bind(null, address)} onClick={onClick.bind(null, address)}
@ -55,7 +56,7 @@ export default function TokenCell({
TokenCell.propTypes = { TokenCell.propTypes = {
address: PropTypes.string, address: PropTypes.string,
outdatedBalance: PropTypes.bool, balanceError: PropTypes.object,
symbol: PropTypes.string, symbol: PropTypes.string,
decimals: PropTypes.number, decimals: PropTypes.number,
string: PropTypes.string, string: PropTypes.string,
@ -64,5 +65,5 @@ TokenCell.propTypes = {
} }
TokenCell.defaultProps = { TokenCell.defaultProps = {
outdatedBalance: false, balanceError: null,
} }

View File

@ -16,7 +16,7 @@ export default function TokenList({ onTokenClick }) {
// from the background so it has a new reference with each background update, // from the background so it has a new reference with each background update,
// even if the tokens haven't changed // even if the tokens haven't changed
const tokens = useSelector(getTokens, isEqual) const tokens = useSelector(getTokens, isEqual)
const { loading, error, tokensWithBalances } = useTokenTracker(tokens) const { loading, tokensWithBalances } = useTokenTracker(tokens, true)
if (loading) { if (loading) {
return ( return (
@ -38,14 +38,7 @@ export default function TokenList({ onTokenClick }) {
<div> <div>
{tokensWithBalances.map((tokenData, index) => { {tokensWithBalances.map((tokenData, index) => {
tokenData.image = assetImages[tokenData.address] tokenData.image = assetImages[tokenData.address]
return ( return <TokenCell key={index} {...tokenData} onClick={onTokenClick} />
<TokenCell
key={index}
{...tokenData}
outdatedBalance={Boolean(error)}
onClick={onTokenClick}
/>
)
})} })}
</div> </div>
) )

View File

@ -4,7 +4,7 @@ import { useSelector } from 'react-redux'
import { getCurrentNetwork, getSelectedAddress } from '../selectors' import { getCurrentNetwork, getSelectedAddress } from '../selectors'
import { useEqualityCheck } from './useEqualityCheck' import { useEqualityCheck } from './useEqualityCheck'
export function useTokenTracker(tokens) { export function useTokenTracker(tokens, includeFailedTokens = false) {
const network = useSelector(getCurrentNetwork) const network = useSelector(getCurrentNetwork)
const userAddress = useSelector(getSelectedAddress) const userAddress = useSelector(getSelectedAddress)
@ -42,6 +42,7 @@ export function useTokenTracker(tokens) {
userAddress: address, userAddress: address,
provider: global.ethereumProvider, provider: global.ethereumProvider,
tokens: tokenList, tokens: tokenList,
includeFailedTokens,
pollingInterval: 8000, pollingInterval: 8000,
}) })
@ -49,7 +50,7 @@ export function useTokenTracker(tokens) {
tokenTracker.current.on('error', showError) tokenTracker.current.on('error', showError)
tokenTracker.current.updateBalances() tokenTracker.current.updateBalances()
}, },
[updateBalances, showError, teardownTracker], [updateBalances, includeFailedTokens, showError, teardownTracker],
) )
// Effect to remove the tracker when the component is removed from DOM // Effect to remove the tracker when the component is removed from DOM