fix double state update when account changed

feature/default_network_editable
Esteban MIno 6 years ago
parent fbcba8f019
commit 822c1734d6
  1. 8
      app/scripts/controllers/preferences.js

@ -195,8 +195,8 @@ class PreferencesController {
*/ */
setSelectedAddress (_address) { setSelectedAddress (_address) {
const address = normalizeAddress(_address) const address = normalizeAddress(_address)
this.store.updateState({ selectedAddress: address }) const tokens = this._updateTokens(address)
const tokens = this._updateTokens() this.store.updateState({ selectedAddress: address, tokens })
return Promise.resolve(tokens) return Promise.resolve(tokens)
} }
@ -421,14 +421,12 @@ class PreferencesController {
* *
* *
*/ */
_updateTokens () { _updateTokens (selectedAddress) {
const accountTokens = this.store.getState().accountTokens const accountTokens = this.store.getState().accountTokens
const selectedAddress = this.store.getState().selectedAddress
const providerType = this.network.providerStore.getState().type const providerType = this.network.providerStore.getState().type
if (!(selectedAddress in accountTokens)) accountTokens[selectedAddress] = {} if (!(selectedAddress in accountTokens)) accountTokens[selectedAddress] = {}
if (!(providerType in accountTokens[selectedAddress])) accountTokens[selectedAddress][providerType] = [] if (!(providerType in accountTokens[selectedAddress])) accountTokens[selectedAddress][providerType] = []
const tokens = accountTokens[selectedAddress][providerType] const tokens = accountTokens[selectedAddress][providerType]
this.store.updateState({ tokens })
return tokens return tokens
} }
} }

Loading…
Cancel
Save