Fix mobile sync of ERC20 tokens (#10591)

In #10510 we changed how tokens are stored, keying them by `chainId`
rather than network type. However we didn't update our mobile sync
function to account for this, which ended up breaking the filtering
logic used to prepare the data that is synced.

Specifically, custom tokens added by users are filtered out to just
those that are confirmed to be ERC20 tokens in our built-in list of
tokens. This filters out unrecognized tokens and NFTs.

The filtering logic has been restored to the pre-#10510 behaviour.
feature/default_network_editable
Mark Stacey 4 years ago committed by GitHub
parent 40ffaa7265
commit 79a7199a2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      app/scripts/metamask-controller.js

@ -26,6 +26,7 @@ import {
} from '@metamask/controllers'; } from '@metamask/controllers';
import { getBackgroundMetaMetricState } from '../../ui/app/selectors'; import { getBackgroundMetaMetricState } from '../../ui/app/selectors';
import { TRANSACTION_STATUSES } from '../../shared/constants/transaction'; import { TRANSACTION_STATUSES } from '../../shared/constants/transaction';
import { MAINNET_CHAIN_ID } from '../../shared/constants/network';
import ComposableObservableStore from './lib/ComposableObservableStore'; import ComposableObservableStore from './lib/ComposableObservableStore';
import AccountTracker from './lib/account-tracker'; import AccountTracker from './lib/account-tracker';
import createLoggerMiddleware from './lib/createLoggerMiddleware'; import createLoggerMiddleware from './lib/createLoggerMiddleware';
@ -1074,10 +1075,10 @@ export default class MetamaskController extends EventEmitter {
Object.keys(accountTokens).forEach((address) => { Object.keys(accountTokens).forEach((address) => {
const checksummedAddress = ethUtil.toChecksumAddress(address); const checksummedAddress = ethUtil.toChecksumAddress(address);
filteredAccountTokens[checksummedAddress] = {}; filteredAccountTokens[checksummedAddress] = {};
Object.keys(accountTokens[address]).forEach((networkType) => { Object.keys(accountTokens[address]).forEach((chainId) => {
filteredAccountTokens[checksummedAddress][networkType] = filteredAccountTokens[checksummedAddress][chainId] =
networkType === 'mainnet' chainId === MAINNET_CHAIN_ID
? accountTokens[address][networkType].filter( ? accountTokens[address][chainId].filter(
({ address: tokenAddress }) => { ({ address: tokenAddress }) => {
const checksumAddress = ethUtil.toChecksumAddress( const checksumAddress = ethUtil.toChecksumAddress(
tokenAddress, tokenAddress,
@ -1087,7 +1088,7 @@ export default class MetamaskController extends EventEmitter {
: true; : true;
}, },
) )
: accountTokens[address][networkType]; : accountTokens[address][chainId];
}); });
}); });

Loading…
Cancel
Save