aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
authorEsteban MIno <efmino@uc.cl>2018-07-12 03:59:05 +0800
committerEsteban MIno <efmino@uc.cl>2018-07-12 03:59:05 +0800
commit910713c6b3c5b8f865fdcb989bfe3ee0b14eb364 (patch)
tree8bd0c9d2b2f801738f7daaf6617d1fa56ebde952 /app/scripts
parent63b9c8796bf744f05a3b7d88319460eed772efa9 (diff)
downloadtangerine-wallet-browser-910713c6b3c5b8f865fdcb989bfe3ee0b14eb364.tar
tangerine-wallet-browser-910713c6b3c5b8f865fdcb989bfe3ee0b14eb364.tar.gz
tangerine-wallet-browser-910713c6b3c5b8f865fdcb989bfe3ee0b14eb364.tar.bz2
tangerine-wallet-browser-910713c6b3c5b8f865fdcb989bfe3ee0b14eb364.tar.lz
tangerine-wallet-browser-910713c6b3c5b8f865fdcb989bfe3ee0b14eb364.tar.xz
tangerine-wallet-browser-910713c6b3c5b8f865fdcb989bfe3ee0b14eb364.tar.zst
tangerine-wallet-browser-910713c6b3c5b8f865fdcb989bfe3ee0b14eb364.zip
improve tests
Diffstat (limited to 'app/scripts')
-rw-r--r--app/scripts/controllers/detect-tokens.js29
-rw-r--r--app/scripts/metamask-controller.js2
2 files changed, 14 insertions, 17 deletions
diff --git a/app/scripts/controllers/detect-tokens.js b/app/scripts/controllers/detect-tokens.js
index 1ea855356..fd8412078 100644
--- a/app/scripts/controllers/detect-tokens.js
+++ b/app/scripts/controllers/detect-tokens.js
@@ -20,7 +20,6 @@ class DetectTokensController {
this.preferences = preferences
this.interval = interval
this.network = network
- this.contracts = contracts
}
/**
@@ -30,18 +29,16 @@ class DetectTokensController {
async exploreNewTokens () {
if (!this.isActive) { return }
if (this._network.getState().provider.type !== MAINNET) { return }
- let detectedTokenAddress, token
- for (const address in this.contracts) {
- const contract = this.contracts[address]
- if (contract.erc20 && !(address in this.tokens)) {
- detectedTokenAddress = await this.fetchContractAccountBalance(address)
- if (detectedTokenAddress) {
- token = this.contracts[detectedTokenAddress]
- this._preferences.addToken(detectedTokenAddress, token['symbol'], token['decimals'])
+ let detectedTokenBalance, token
+ for (const contractAddress in contracts) {
+ const contract = contracts[contractAddress]
+ if (contract.erc20 && !(contractAddress in this.tokens)) {
+ detectedTokenBalance = await this.detectTokenBalance(contractAddress)
+ if (detectedTokenBalance) {
+ token = contracts[contractAddress]
+ this._preferences.addToken(contractAddress, token['symbol'], token['decimals'])
}
}
- // etherscan restriction, 5 request/second, lazy scan
- setTimeout(() => {}, 200)
}
}
@@ -49,17 +46,17 @@ class DetectTokensController {
* Find if selectedAddress has tokens with contract in contractAddress.
*
* @param {string} contractAddress Hex address of the token contract to explore.
- * @returns {string} Contract address to be added to tokens.
+ * @returns {boolean} If balance is detected in token contract for address.
*
*/
- async fetchContractAccountBalance (contractAddress) {
+ async detectTokenBalance (contractAddress) {
const address = this._preferences.store.getState().selectedAddress
const response = await fetch(`https://api.etherscan.io/api?module=account&action=tokenbalance&contractaddress=${contractAddress}&address=${address}&tag=latest&apikey=NCKS6GTY41KPHWRJB62ES1MDNRBIT174PV`)
const parsedResponse = await response.json()
if (parsedResponse.result !== '0') {
- return contractAddress
+ return true
}
- return null
+ return false
}
/**
@@ -81,7 +78,7 @@ class DetectTokensController {
}
- /**
+ /**
* @type {Object}
*/
set network (network) {
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 9a93cf584..eed3fc8e7 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -113,7 +113,7 @@ module.exports = class MetamaskController extends EventEmitter {
preferences: this.preferencesController.store,
})
- // detect tokens controller
+ // detect tokens controller
this.detectTokensController = new DetectTokensController({
preferences: this.preferencesController,
network: this.networkController.store,