diff options
metamask - move selectedAccount set/get to preferencesController
-rw-r--r-- | app/scripts/keyring-controller.js | 24 | ||||
-rw-r--r-- | app/scripts/metamask-controller.js | 21 |
2 files changed, 12 insertions, 33 deletions
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js index 40cc975f9..3e329cb3f 100644 --- a/app/scripts/keyring-controller.js +++ b/app/scripts/keyring-controller.js @@ -88,8 +88,6 @@ class KeyringController extends EventEmitter { keyringTypes: this.keyringTypes.map(krt => krt.type), // memStore identities: this.identities, - // diskStore - selectedAccount: state.selectedAccount, // configManager seedWords: this.configManager.getSeedWords(), isDisclaimerConfirmed: this.configManager.getConfirmedDisclaimer(), @@ -231,28 +229,6 @@ class KeyringController extends EventEmitter { .then(this.fullUpdate.bind(this)) } - // Set Selected Account - // @string address - // - // returns Promise( @string address ) - // - // Sets the state's `selectedAccount` value - // to the specified address. - setSelectedAccount (account) { - var address = normalizeAddress(account) - this.store.updateState({ selectedAccount: address }) - return this.fullUpdate() - } - - // Get Selected Account - // - // returns String - // - // Gets the state's `selectedAccount` value - getSelectedAccount () { - return this.store.getState().selectedAccount - } - // Save Account Label // @string account // @string label diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index c0673dda4..2f9e37cee 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -42,8 +42,8 @@ module.exports = class MetamaskController extends EventEmitter { this.configManager.updateConversionRate() // preferences controller - this.prefencesController = new PreferencesController({ - initState: initState.PrefencesController, + this.preferencesController = new PreferencesController({ + initState: initState.PreferencesController, }) // rpc provider @@ -71,7 +71,7 @@ module.exports = class MetamaskController extends EventEmitter { txList: this.configManager.getTxList(), txHistoryLimit: 40, setTxList: this.configManager.setTxList.bind(this.configManager), - getSelectedAccount: this.keyringController.getSelectedAccount.bind(this.keyringController), + getSelectedAccount: this.preferencesController.getSelectedAccount.bind(this.preferencesController), getGasMultiplier: this.configManager.getGasMultiplier.bind(this.configManager), getNetwork: this.getStateNetwork.bind(this), signTransaction: this.keyringController.signTransaction.bind(this.keyringController), @@ -107,8 +107,8 @@ module.exports = class MetamaskController extends EventEmitter { this.keyringController.store.subscribe((state) => { this.store.updateState({ KeyringController: state }) }) - this.prefencesController.store.subscribe((state) => { - this.store.updateState({ PrefencesController: state }) + this.preferencesController.store.subscribe((state) => { + this.store.updateState({ PreferencesController: state }) }) } @@ -125,7 +125,7 @@ module.exports = class MetamaskController extends EventEmitter { rpcUrl: this.configManager.getCurrentRpcAddress(), // account mgmt getAccounts: (cb) => { - let selectedAccount = this.keyringController.getSelectedAccount() + let selectedAccount = this.preferencesController.getSelectedAccount() let result = selectedAccount ? [selectedAccount] : [] cb(null, result) }, @@ -191,6 +191,7 @@ module.exports = class MetamaskController extends EventEmitter { getApi () { const keyringController = this.keyringController + const preferencesController = this.preferencesController const txManager = this.txManager const noticeController = this.noticeController @@ -221,12 +222,14 @@ module.exports = class MetamaskController extends EventEmitter { // vault management submitPassword: this.submitPassword.bind(this), + // PreferencesController + setSelectedAccount: nodeify(preferencesController.setSelectedAccount).bind(preferencesController), + // KeyringController setLocked: nodeify(keyringController.setLocked).bind(keyringController), createNewVaultAndKeychain: nodeify(keyringController.createNewVaultAndKeychain).bind(keyringController), createNewVaultAndRestore: nodeify(keyringController.createNewVaultAndRestore).bind(keyringController), addNewKeyring: nodeify(keyringController.addNewKeyring).bind(keyringController), - setSelectedAccount: nodeify(keyringController.setSelectedAccount).bind(keyringController), saveAccountLabel: nodeify(keyringController.saveAccountLabel).bind(keyringController), exportAccount: nodeify(keyringController.exportAccount).bind(keyringController), @@ -339,7 +342,7 @@ module.exports = class MetamaskController extends EventEmitter { // ensuring they are only ever available in the background process. clearSeedWordCache (cb) { this.configManager.setSeedWords(null) - cb(null, this.keyringController.getSelectedAccount()) + cb(null, this.preferencesController.getSelectedAccount()) } importAccountWithStrategy (strategy, args, cb) { @@ -348,7 +351,7 @@ module.exports = class MetamaskController extends EventEmitter { return this.keyringController.addNewKeyring('Simple Key Pair', [ privateKey ]) }) .then(keyring => keyring.getAccounts()) - .then((accounts) => this.keyringController.setSelectedAccount(accounts[0])) + .then((accounts) => this.preferencesController.setSelectedAccount(accounts[0])) .then(() => { cb(null, this.keyringController.fullUpdate()) }) .catch((reason) => { cb(reason) }) } |