aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorBruno Barbieri <bruno.barbieri@consensys.net>2019-01-23 02:23:11 +0800
committerDan Finlay <542863+danfinlay@users.noreply.github.com>2019-01-23 02:23:11 +0800
commit2cfea0b788e4c3f9420358ef62cff46850fc8146 (patch)
treee520b6133bd26a037fb954653241548bf675d587 /app
parente21dfd18622dd7f70dac51855a0052a56fb74e57 (diff)
downloadtangerine-wallet-browser-2cfea0b788e4c3f9420358ef62cff46850fc8146.tar
tangerine-wallet-browser-2cfea0b788e4c3f9420358ef62cff46850fc8146.tar.gz
tangerine-wallet-browser-2cfea0b788e4c3f9420358ef62cff46850fc8146.tar.bz2
tangerine-wallet-browser-2cfea0b788e4c3f9420358ef62cff46850fc8146.tar.lz
tangerine-wallet-browser-2cfea0b788e4c3f9420358ef62cff46850fc8146.tar.xz
tangerine-wallet-browser-2cfea0b788e4c3f9420358ef62cff46850fc8146.tar.zst
tangerine-wallet-browser-2cfea0b788e4c3f9420358ef62cff46850fc8146.zip
fix asset detection (#6049)
Diffstat (limited to 'app')
-rw-r--r--app/scripts/controllers/detect-tokens.js20
1 files changed, 18 insertions, 2 deletions
diff --git a/app/scripts/controllers/detect-tokens.js b/app/scripts/controllers/detect-tokens.js
index 62e639795..e6940c613 100644
--- a/app/scripts/controllers/detect-tokens.js
+++ b/app/scripts/controllers/detect-tokens.js
@@ -5,7 +5,8 @@ const { MAINNET } = require('./network/enums')
// By default, poll every 3 minutes
const DEFAULT_INTERVAL = 180 * 1000
const ERC20_ABI = [{'constant': true, 'inputs': [{'name': '_owner', 'type': 'address'}], 'name': 'balanceOf', 'outputs': [{'name': 'balance', 'type': 'uint256'}], 'payable': false, 'type': 'function'}]
-
+const SINGLE_CALL_BALANCES_ABI = require('single-call-balance-checker-abi')
+const SINGLE_CALL_BALANCES_ADDRESS = '0xb1f8e55c7f64d203c1400b9d8555d050f94adf39'
/**
* A controller that polls for token exchange
* rates based on a user's current token list
@@ -30,12 +31,27 @@ class DetectTokensController {
async detectNewTokens () {
if (!this.isActive) { return }
if (this._network.store.getState().provider.type !== MAINNET) { return }
+ const tokensToDetect = []
this.web3.setProvider(this._network._provider)
for (const contractAddress in contracts) {
if (contracts[contractAddress].erc20 && !(this.tokenAddresses.includes(contractAddress.toLowerCase()))) {
- this.detectTokenBalance(contractAddress)
+ tokensToDetect.push(contractAddress)
}
}
+
+ const ethContract = this.web3.eth.contract(SINGLE_CALL_BALANCES_ABI).at(SINGLE_CALL_BALANCES_ADDRESS)
+ ethContract.balances([this.selectedAddress], tokensToDetect, (error, result) => {
+ if (error) {
+ warn(`MetaMask - DetectTokensController single call balance fetch failed`, error)
+ return
+ }
+ tokensToDetect.forEach((tokenAddress, index) => {
+ const balance = result[index]
+ if (!balance.isZero()) {
+ this._preferences.addToken(tokenAddress, contracts[tokenAddress].symbol, contracts[tokenAddress].decimals)
+ }
+ })
+ })
}
/**