aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorEsteban MIno <efmino@uc.cl>2018-07-26 05:46:31 +0800
committerEsteban MIno <efmino@uc.cl>2018-07-26 05:46:31 +0800
commitadee549c43ace4809e9e9779a3bd9c0dc75aaa17 (patch)
tree435e17f82d749b93e5dc7791fb3358c857d804da /app
parent2770df80e3cdd4d539b88c6d018108cb07211748 (diff)
downloadtangerine-wallet-browser-adee549c43ace4809e9e9779a3bd9c0dc75aaa17.tar
tangerine-wallet-browser-adee549c43ace4809e9e9779a3bd9c0dc75aaa17.tar.gz
tangerine-wallet-browser-adee549c43ace4809e9e9779a3bd9c0dc75aaa17.tar.bz2
tangerine-wallet-browser-adee549c43ace4809e9e9779a3bd9c0dc75aaa17.tar.lz
tangerine-wallet-browser-adee549c43ace4809e9e9779a3bd9c0dc75aaa17.tar.xz
tangerine-wallet-browser-adee549c43ace4809e9e9779a3bd9c0dc75aaa17.tar.zst
tangerine-wallet-browser-adee549c43ace4809e9e9779a3bd9c0dc75aaa17.zip
preferences test fixes for tokens per account
Diffstat (limited to 'app')
-rw-r--r--app/scripts/controllers/preferences.js25
1 files changed, 16 insertions, 9 deletions
diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js
index 878333481..1b1044955 100644
--- a/app/scripts/controllers/preferences.js
+++ b/app/scripts/controllers/preferences.js
@@ -40,10 +40,9 @@ class PreferencesController {
Object.defineProperty(this.store._state, 'tokens', {
get: () => {
const selectedAddress = this.store.getState().selectedAddress
- const tokens = this.store.getState().addressTokens
- // TODO when create vault
- if (!(selectedAddress in tokens)) return []
- return tokens[selectedAddress]
+ const addressTokens = this.store.getState().addressTokens
+ if (!(selectedAddress in addressTokens)) return []
+ return addressTokens[selectedAddress]
},
})
}
@@ -88,12 +87,16 @@ class PreferencesController {
*/
setAddresses (addresses) {
const oldIdentities = this.store.getState().identities
+ const addressTokens = this.store.getState().addressTokens
const identities = addresses.reduce((ids, address, index) => {
const oldId = oldIdentities[address] || {}
ids[address] = {name: `Account ${index + 1}`, address, ...oldId}
return ids
}, {})
- this.store.updateState({ identities })
+ for (const address in identities) {
+ if (!(address in addressTokens)) addressTokens[address] = []
+ }
+ this.store.updateState({ identities, addressTokens })
}
/**
@@ -104,11 +107,13 @@ class PreferencesController {
*/
removeAddress (address) {
const identities = this.store.getState().identities
+ const addressTokens = this.store.getState().addressTokens
if (!identities[address]) {
throw new Error(`${address} can't be deleted cause it was not found`)
}
delete identities[address]
- this.store.updateState({ identities })
+ delete addressTokens[address]
+ this.store.updateState({ identities, addressTokens })
// If the selected account is no longer valid,
// select an arbitrary other account:
@@ -194,8 +199,10 @@ class PreferencesController {
setSelectedAddress (_address) {
return new Promise((resolve, reject) => {
const address = normalizeAddress(_address)
- const tokens = this.store.getState().addressTokens[_address]
- this.store.updateState({ selectedAddress: address, tokens: tokens })
+ const addressTokens = this.store.getState().addressTokens
+ if (!(address in addressTokens)) addressTokens[address] = []
+ const tokens = addressTokens[address]
+ this.store.updateState({ selectedAddress: address, tokens })
resolve()
})
}
@@ -265,7 +272,7 @@ class PreferencesController {
removeToken (rawAddress) {
const addressTokens = this.store.getState().addressTokens
const selectedAddress = this.store.getState().selectedAddress
-
+
const updatedTokens = addressTokens[selectedAddress].filter(token => token.address !== rawAddress)
addressTokens[selectedAddress] = updatedTokens
this.store.updateState({ addressTokens, tokens: updatedTokens })