diff options
author | Thomas Huang <tmashuang@users.noreply.github.com> | 2017-06-29 01:07:49 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-29 01:07:49 +0800 |
commit | ffd3773ef3c400c89c362580e7ae3969d00ae20c (patch) | |
tree | 13cc622a66025476bdcb8840c316c05c0146a533 /app/scripts/controllers | |
parent | ddba2af4152668a5767ce874a4727873c72bac72 (diff) | |
parent | 8642feee09f57d5756c682a053434a196cff4af3 (diff) | |
download | tangerine-wallet-browser-ffd3773ef3c400c89c362580e7ae3969d00ae20c.tar tangerine-wallet-browser-ffd3773ef3c400c89c362580e7ae3969d00ae20c.tar.gz tangerine-wallet-browser-ffd3773ef3c400c89c362580e7ae3969d00ae20c.tar.bz2 tangerine-wallet-browser-ffd3773ef3c400c89c362580e7ae3969d00ae20c.tar.lz tangerine-wallet-browser-ffd3773ef3c400c89c362580e7ae3969d00ae20c.tar.xz tangerine-wallet-browser-ffd3773ef3c400c89c362580e7ae3969d00ae20c.tar.zst tangerine-wallet-browser-ffd3773ef3c400c89c362580e7ae3969d00ae20c.zip |
Merge pull request #1620 from MetaMask/i1616-AddTokenAdding
Add ability to add tokens to token list
Diffstat (limited to 'app/scripts/controllers')
-rw-r--r-- | app/scripts/controllers/preferences.js | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index aa8e05fcc..e45224593 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -8,13 +8,11 @@ class PreferencesController { const initState = extend({ frequentRpcList: [], currentAccountTab: 'history', + tokens: [], }, opts.initState) this.store = new ObservableStore(initState) } - - // - // PUBLIC METHODS - // +// PUBLIC METHODS setSelectedAddress (_address) { return new Promise((resolve, reject) => { @@ -28,6 +26,29 @@ class PreferencesController { return this.store.getState().selectedAddress } + addToken (rawAddress, symbol, decimals) { + const address = normalizeAddress(rawAddress) + const newEntry = { address, symbol, decimals } + + const tokens = this.store.getState().tokens + const previousIndex = tokens.find((token, index) => { + return token.address === address + }) + + if (previousIndex) { + tokens[previousIndex] = newEntry + } else { + tokens.push(newEntry) + } + + this.store.updateState({ tokens }) + return Promise.resolve() + } + + getTokens () { + return this.store.getState().tokens + } + updateFrequentRpcList (_url) { return this.addToFrequentRpcList(_url) .then((rpcList) => { |