aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/controllers
diff options
context:
space:
mode:
authorEsteban MIno <efmino@uc.cl>2018-08-21 09:32:14 +0800
committerEsteban MIno <efmino@uc.cl>2018-08-21 09:32:14 +0800
commit68c1b4c17049e3ef18397ae83b0eb9da8cccab2c (patch)
tree4a708ae87adeb67d855f9200c8b7e02415b48153 /app/scripts/controllers
parent81cd29df43feb2469b78c6240d12ffcb9a68678e (diff)
downloadtangerine-wallet-browser-68c1b4c17049e3ef18397ae83b0eb9da8cccab2c.tar.gz
tangerine-wallet-browser-68c1b4c17049e3ef18397ae83b0eb9da8cccab2c.tar.zst
tangerine-wallet-browser-68c1b4c17049e3ef18397ae83b0eb9da8cccab2c.zip
watchAsset returns result wether token was added or not
Diffstat (limited to 'app/scripts/controllers')
-rw-r--r--app/scripts/controllers/preferences.js16
1 files changed, 9 insertions, 7 deletions
diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js
index 611d2d067..11f36e284 100644
--- a/app/scripts/controllers/preferences.js
+++ b/app/scripts/controllers/preferences.js
@@ -41,7 +41,7 @@ class PreferencesController {
this.diagnostics = opts.diagnostics
this.network = opts.network
this.store = new ObservableStore(initState)
- this.showAddTokenUi = opts.showAddTokenUi
+ this.showWatchAssetUi = opts.showWatchAssetUi
this._subscribeProviderType()
}
// PUBLIC METHODS
@@ -82,13 +82,12 @@ class PreferencesController {
* @param {Function} - next
* @param {Function} - end
*/
- requestAddToken (req, res, next, end) {
+ async requestWatchAsset (req, res, next, end) {
if (req.method === 'metamask_watchAsset') {
const { type, options } = req.params
switch (type) {
case 'ERC20':
- this._handleWatchAssetERC20(options, res)
- res.result = options.address
+ res.result = await this._handleWatchAssetERC20(options)
end()
break
default:
@@ -521,17 +520,20 @@ class PreferencesController {
/**
* Handle the suggestion of an ERC20 asset through `watchAsset`
* *
- * @param {Object} options Parameters according to addition of ERC20 token
+ * @param {Boolean} assetAdded Boolean according to addition of ERC20 token
*
*/
- _handleWatchAssetERC20 (options) {
+ async _handleWatchAssetERC20 (options) {
// TODO handle bad parameters
const { address, symbol, decimals, imageUrl } = options
const rawAddress = address
this._validateSuggestedTokenParams({ rawAddress, symbol, decimals })
const tokenOpts = { rawAddress, decimals, symbol, imageUrl }
this.addSuggestedToken(tokenOpts)
- this.showAddTokenUi()
+ return this.showWatchAssetUi().then(() => {
+ const tokenAddresses = this.getTokens().filter(token => token.address === normalizeAddress(rawAddress))
+ return tokenAddresses.length > 0
+ })
}
}