aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-06-16 07:22:53 +0800
committerDan Finlay <dan@danfinlay.com>2017-06-16 07:22:53 +0800
commit48789f2a3df2c820b61902fb49057f9f7b6cbd8c (patch)
tree944ddfc812be289c1e7d50f08032e46242776152 /app
parent711a4def86d9e8c626ee554a976d9eab6abdcbee (diff)
downloadtangerine-wallet-browser-48789f2a3df2c820b61902fb49057f9f7b6cbd8c.tar
tangerine-wallet-browser-48789f2a3df2c820b61902fb49057f9f7b6cbd8c.tar.gz
tangerine-wallet-browser-48789f2a3df2c820b61902fb49057f9f7b6cbd8c.tar.bz2
tangerine-wallet-browser-48789f2a3df2c820b61902fb49057f9f7b6cbd8c.tar.lz
tangerine-wallet-browser-48789f2a3df2c820b61902fb49057f9f7b6cbd8c.tar.xz
tangerine-wallet-browser-48789f2a3df2c820b61902fb49057f9f7b6cbd8c.tar.zst
tangerine-wallet-browser-48789f2a3df2c820b61902fb49057f9f7b6cbd8c.zip
Add ability to add tokens to token list
Fiex #1616
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 410693df4..e4267381d 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -275,6 +275,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),