async detectNewTokens() {
    const userAddress = this.selectedAddress
    if (!userAddress) return
    if (this.network.getNetworkNameFromNetworkCode() !== MAINNET) {
      this.detectedTokensStore.updateState({ [userAddress]: [] })
      return
    }
    const tokensToDetect = []
    for (const contractAddress in contracts) {
      if (contracts[contractAddress].erc20) {
        tokensToDetect.push(contractAddress)
      }
    }
    if (tokensToDetect.length > 0) {
      const web3Instance = this.web3
      const ethContract = new web3Instance.eth.Contract(SINGLE_CALL_BALANCES_ABI, SINGLE_CALL_BALANCES_ADDRESS)
      ethContract.methods.balances([userAddress], tokensToDetect).call({ from: userAddress }, (error, result) => {
        if (error) {
          log.warn('MetaMask - DetectTokensController single call balance fetch failed', error)
          return
        }
        const nonZeroTokens = []
        tokensToDetect.forEach((tokenAddress, index) => {
          const balance = toHex(result[index])
          if (balance && balance !== '0x0') {
            // do sth else here
            nonZeroTokens.push({ ...contracts[tokenAddress], tokenAddress, balance, network: MAINNET })
            // this._preferences.addToken(tokenAddress, contracts[tokenAddress].symbol, contracts[tokenAddress].decimals)
          }
        })
        const currentTokens = this.detectedTokensStore.getState()[userAddress] || []
        this.detectedTokensStore.updateState({ [userAddress]: mergeTokenArrays(currentTokens, nonZeroTokens) })
      })
    }
  }
/**
   * For each token in @metamask/contract-metadata, find check selectedAddress balance.
   *
   */
For each token in @metamask/contract-metadata, find check selectedAddress balance.
For each token in @metamask / contract - metadata find check selectedAddress balance .
async detectNewTokens() {
    const userAddress = this.selectedAddress
    if (!userAddress) return
    if (this.network.getNetworkNameFromNetworkCode() !== MAINNET) {
      this.detectedTokensStore.updateState({ [userAddress]: [] })
      return
    }
    const tokensToDetect = []
    for (const contractAddress in contracts) {
      if (contracts[contractAddress].erc20) {
        tokensToDetect.push(contractAddress)
      }
    }
    if (tokensToDetect.length > 0) {
      const web3Instance = this.web3
      const ethContract = new web3Instance.eth.Contract(SINGLE_CALL_BALANCES_ABI, SINGLE_CALL_BALANCES_ADDRESS)
      ethContract.methods.balances([userAddress], tokensToDetect).call({ from: userAddress }, (error, result) => {
        if (error) {
          log.warn('MetaMask - DetectTokensController single call balance fetch failed', error)
          return
        }
        const nonZeroTokens = []
        tokensToDetect.forEach((tokenAddress, index) => {
          const balance = toHex(result[index])
          if (balance && balance !== '0x0') {
            nonZeroTokens.push({ ...contracts[tokenAddress], tokenAddress, balance, network: MAINNET })
          }
        })
        const currentTokens = this.detectedTokensStore.getState()[userAddress] || []
        this.detectedTokensStore.updateState({ [userAddress]: mergeTokenArrays(currentTokens, nonZeroTokens) })
      })
    }
  }
async detectNewTokens ( ) { const userAddress = this . selectedAddress if ( ! userAddress ) return if ( this . network . getNetworkNameFromNetworkCode ( ) !== MAINNET ) { this . detectedTokensStore . updateState ( { [ userAddress ] : [ ] } ) return } const tokensToDetect = [ ] for ( const contractAddress in contracts ) { if ( contracts [ contractAddress ] . erc20 ) { tokensToDetect . push ( contractAddress ) } } if ( tokensToDetect . length > 0 ) { const web3Instance = this . web3 const ethContract = new web3Instance . eth . Contract ( SINGLE_CALL_BALANCES_ABI , SINGLE_CALL_BALANCES_ADDRESS ) ethContract . methods . balances ( [ userAddress ] , tokensToDetect ) . call ( { from : userAddress } , ( error , result ) => { if ( error ) { log . warn ( 'MetaMask - DetectTokensController single call balance fetch failed' , error ) return } const nonZeroTokens = [ ] tokensToDetect . forEach ( ( tokenAddress , index ) => { const balance = toHex ( result [ index ] ) if ( balance && balance !== '0x0' ) { nonZeroTokens . push ( { ... contracts [ tokenAddress ] , tokenAddress , balance , network : MAINNET } ) } } ) const currentTokens = this . detectedTokensStore . getState ( ) [ userAddress ] || [ ] this . detectedTokensStore . updateState ( { [ userAddress ] : mergeTokenArrays ( currentTokens , nonZeroTokens ) } ) } ) } }
For each token in @metamask/contract-metadata, find check selectedAddress balance.
For each token in @metamask / contract - metadata find check selectedAddress balance .
// do sth else here // this._preferences.addToken(tokenAddress, contracts[tokenAddress].symbol, contracts[tokenAddress].decimals)