Skip to content

Commit

Permalink
filter non erc20 assets
Browse files Browse the repository at this point in the history
  • Loading branch information
estebanmino committed Aug 19, 2019
1 parent 8215296 commit 476e56c
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const HW_WALLETS_KEYRINGS = [TrezorKeyring.type, LedgerBridgeKeyring.type]
const EthQuery = require('eth-query')
const ethUtil = require('ethereumjs-util')
const sigUtil = require('eth-sig-util')
const contractMap = require('eth-contract-metadata')
const {
AddressBookController,
CurrencyRateController,
Expand All @@ -63,7 +64,6 @@ const {
} = require('gaba')
const backEndMetaMetricsEvent = require('./lib/backend-metametrics')


module.exports = class MetamaskController extends EventEmitter {

/**
Expand Down Expand Up @@ -648,8 +648,24 @@ module.exports = class MetamaskController extends EventEmitter {
tokens,
} = this.preferencesController.store.getState()

// Filter ERC20 tokens
const filteredAccountTokens = {}
Object.keys(accountTokens).forEach(address => {
const checksummedAddress = ethUtil.toChecksumAddress(address)
filteredAccountTokens[checksummedAddress] = {}
Object.keys(accountTokens[address]).forEach(
networkType => (filteredAccountTokens[checksummedAddress][networkType] = networkType !== 'mainnet' ?
accountTokens[address][networkType] :
accountTokens[address][networkType].filter(({ address }) => {
const tokenAddress = ethUtil.toChecksumAddress(address)
return contractMap[tokenAddress] ? contractMap[tokenAddress].erc20 : true
})
)
)
})

const preferences = {
accountTokens,
accountTokens: filteredAccountTokens,
currentLocale,
frequentRpcList,
identities,
Expand Down

0 comments on commit 476e56c

Please sign in to comment.