aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorThomas Huang <tmashuang@users.noreply.github.com>2017-06-29 01:07:49 +0800
committerGitHub <noreply@github.com>2017-06-29 01:07:49 +0800
commitffd3773ef3c400c89c362580e7ae3969d00ae20c (patch)
tree13cc622a66025476bdcb8840c316c05c0146a533 /app
parentddba2af4152668a5767ce874a4727873c72bac72 (diff)
parent8642feee09f57d5756c682a053434a196cff4af3 (diff)
downloadtangerine-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')
-rw-r--r--app/scripts/controllers/preferences.js29
-rw-r--r--app/scripts/metamask-controller.js1
2 files changed, 26 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) => {
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 1a83c70f5..782641b3f 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -293,6 +293,7 @@ module.exports = class MetamaskController extends EventEmitter {
// PreferencesController
setSelectedAddress: nodeify(preferencesController.setSelectedAddress).bind(preferencesController),
+ addToken: nodeify(preferencesController.addToken).bind(preferencesController),
setCurrentAccountTab: nodeify(preferencesController.setCurrentAccountTab).bind(preferencesController),
setDefaultRpc: nodeify(this.setDefaultRpc).bind(this),
setCustomRpc: nodeify(this.setCustomRpc).bind(this),