aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEsteban MIno <efmino@uc.cl>2018-07-31 07:09:17 +0800
committerEsteban MIno <efmino@uc.cl>2018-07-31 07:09:17 +0800
commitfbcba8f019313c3b02429043578e044046c6cc68 (patch)
tree08e0e28d3824a709363074cdff7b74580b6e1207
parent31286673c3bd0c35925f2d41f3e24c0a9d561fa8 (diff)
downloadtangerine-wallet-browser-fbcba8f019313c3b02429043578e044046c6cc68.tar
tangerine-wallet-browser-fbcba8f019313c3b02429043578e044046c6cc68.tar.gz
tangerine-wallet-browser-fbcba8f019313c3b02429043578e044046c6cc68.tar.bz2
tangerine-wallet-browser-fbcba8f019313c3b02429043578e044046c6cc68.tar.lz
tangerine-wallet-browser-fbcba8f019313c3b02429043578e044046c6cc68.tar.xz
tangerine-wallet-browser-fbcba8f019313c3b02429043578e044046c6cc68.tar.zst
tangerine-wallet-browser-fbcba8f019313c3b02429043578e044046c6cc68.zip
create tokens storage when setadresses
-rw-r--r--app/scripts/controllers/preferences.js6
-rw-r--r--test/unit/app/controllers/preferences-controller-test.js25
2 files changed, 29 insertions, 2 deletions
diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js
index 4daa196a9..5c158288b 100644
--- a/app/scripts/controllers/preferences.js
+++ b/app/scripts/controllers/preferences.js
@@ -87,8 +87,10 @@ class PreferencesController {
ids[address] = {name: `Account ${index + 1}`, address, ...oldId}
return ids
}, {})
- const accountTokens = addresses.reduce((address) => {
- return oldAccountTokens[address] || {}
+ const accountTokens = addresses.reduce((tokens, address) => {
+ const oldTokens = oldAccountTokens[address] || {}
+ tokens[address] = oldTokens
+ return tokens
}, {})
this.store.updateState({ identities, accountTokens })
}
diff --git a/test/unit/app/controllers/preferences-controller-test.js b/test/unit/app/controllers/preferences-controller-test.js
index dcf56e91f..9b2c846bd 100644
--- a/test/unit/app/controllers/preferences-controller-test.js
+++ b/test/unit/app/controllers/preferences-controller-test.js
@@ -31,6 +31,20 @@ describe('preferences controller', function () {
})
})
+ it('should create account tokens for each account in the store', function () {
+ preferencesController.setAddresses([
+ '0xda22le',
+ '0x7e57e2',
+ ])
+
+ const accountTokens = preferencesController.store.getState().accountTokens
+
+ assert.deepEqual(accountTokens, {
+ '0xda22le': {},
+ '0x7e57e2': {},
+ })
+ })
+
it('should replace its list of addresses', function () {
preferencesController.setAddresses([
'0xda22le',
@@ -67,6 +81,17 @@ describe('preferences controller', function () {
assert.equal(preferencesController.store.getState().identities['0xda22le'], undefined)
})
+ it('should remove an address from state and respective tokens', function () {
+ preferencesController.setAddresses([
+ '0xda22le',
+ '0x7e57e2',
+ ])
+
+ preferencesController.removeAddress('0xda22le')
+
+ assert.equal(preferencesController.store.getState().accountTokens['0xda22le'], undefined)
+ })
+
it('should switch accounts if the selected address is removed', function () {
preferencesController.setAddresses([
'0xda22le',