From c53c5d5c9e2a384c6b0a17b844919f9fff9f960e Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 6 Jun 2018 16:46:39 -0700 Subject: [PATCH] Fix bug where reset account would not work. Fixes #4462 Ensures that resetAccount() can work on non-stock providers. I'm unclear how this was ever working, this code hasn't moved in months, but users report it recently breaking. Maybe we only recently pushed it to prod. --- CHANGELOG.md | 2 ++ app/scripts/controllers/network/network.js | 11 +++++++++-- app/scripts/metamask-controller.js | 5 +---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19287f0462e1..9fef15109e45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Current Master +- Fix bug where account reset did not work with custom RPC providers. + ## 4.7.4 Tue Jun 05 2018 - Add diagnostic reporting for users with multiple HD keyrings diff --git a/app/scripts/controllers/network/network.js b/app/scripts/controllers/network/network.js index 93fde7c57d03..5e0c63e7d2de 100644 --- a/app/scripts/controllers/network/network.js +++ b/app/scripts/controllers/network/network.js @@ -89,14 +89,21 @@ module.exports = class NetworkController extends EventEmitter { type: 'rpc', rpcTarget, } - this.providerStore.updateState(providerConfig) - this._switchNetwork(providerConfig) + this.providerConfig = providerConfig } async setProviderType (type) { assert.notEqual(type, 'rpc', `NetworkController - cannot call "setProviderType" with type 'rpc'. use "setRpcTarget"`) assert(INFURA_PROVIDER_TYPES.includes(type) || type === LOCALHOST, `NetworkController - Unknown rpc type "${type}"`) const providerConfig = { type } + this.providerConfig = providerConfig + } + + resetConnection () { + this.providerConfig = this.getProviderConfig() + } + + set providerConfig (providerConfig) { this.providerStore.updateState(providerConfig) this._switchNetwork(providerConfig) } diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 1bb0af5eef3b..873ba79958fe 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -628,10 +628,7 @@ module.exports = class MetamaskController extends EventEmitter { async resetAccount () { const selectedAddress = this.preferencesController.getSelectedAddress() this.txController.wipeTransactions(selectedAddress) - - const networkController = this.networkController - const oldType = networkController.getProviderConfig().type - await networkController.setProviderType(oldType, true) + this.networkController.resetConnection() return selectedAddress }