aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/metamask-controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/scripts/metamask-controller.js')
-rw-r--r--app/scripts/metamask-controller.js47
1 files changed, 26 insertions, 21 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index b0666d9f9..a570f2567 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -145,7 +145,8 @@ module.exports = class MetamaskController extends EventEmitter {
// address book controller
this.addressBookController = new AddressBookController({
initState: initState.AddressBookController,
- }, this.keyringController)
+ preferencesStore: this.preferencesController.store,
+ })
// tx mgmt
this.txController = new TransactionController({
@@ -350,13 +351,12 @@ module.exports = class MetamaskController extends EventEmitter {
verifySeedPhrase: nodeify(this.verifySeedPhrase, this),
clearSeedWordCache: this.clearSeedWordCache.bind(this),
resetAccount: nodeify(this.resetAccount, this),
- importAccountWithStrategy: this.importAccountWithStrategy.bind(this),
+ importAccountWithStrategy: nodeify(this.importAccountWithStrategy, this),
// vault management
submitPassword: nodeify(keyringController.submitPassword, keyringController),
// network management
- setNetworkEndpoints: nodeify(networkController.setNetworkEndpoints, networkController),
setProviderType: nodeify(networkController.setProviderType, networkController),
setCustomRpc: nodeify(this.setCustomRpc, this),
@@ -365,6 +365,7 @@ module.exports = class MetamaskController extends EventEmitter {
addToken: nodeify(preferencesController.addToken, preferencesController),
removeToken: nodeify(preferencesController.removeToken, preferencesController),
setCurrentAccountTab: nodeify(preferencesController.setCurrentAccountTab, preferencesController),
+ setAccountLabel: nodeify(preferencesController.setAccountLabel, preferencesController),
setFeatureFlag: nodeify(preferencesController.setFeatureFlag, preferencesController),
// AddressController
@@ -375,7 +376,6 @@ module.exports = class MetamaskController extends EventEmitter {
createNewVaultAndKeychain: nodeify(this.createNewVaultAndKeychain, this),
createNewVaultAndRestore: nodeify(this.createNewVaultAndRestore, this),
addNewKeyring: nodeify(keyringController.addNewKeyring, keyringController),
- saveAccountLabel: nodeify(keyringController.saveAccountLabel, keyringController),
exportAccount: nodeify(keyringController.exportAccount, keyringController),
// txController
@@ -383,6 +383,7 @@ module.exports = class MetamaskController extends EventEmitter {
updateTransaction: nodeify(txController.updateTransaction, txController),
updateAndApproveTransaction: nodeify(txController.updateAndApproveTransaction, txController),
retryTransaction: nodeify(this.retryTransaction, this),
+ getFilteredTxList: nodeify(txController.getFilteredTxList, txController),
// messageManager
signMessage: nodeify(this.signMessage, this),
@@ -434,7 +435,9 @@ module.exports = class MetamaskController extends EventEmitter {
} else {
vault = await this.keyringController.createNewVaultAndKeychain(password)
- this.selectFirstIdentity(vault)
+ const accounts = await this.keyringController.getAccounts()
+ this.preferencesController.setAddresses(accounts)
+ this.selectFirstIdentity()
}
release()
} catch (err) {
@@ -454,7 +457,9 @@ module.exports = class MetamaskController extends EventEmitter {
const release = await this.createVaultMutex.acquire()
try {
const vault = await this.keyringController.createNewVaultAndRestore(password, seed)
- this.selectFirstIdentity(vault)
+ const accounts = await this.keyringController.getAccounts()
+ this.preferencesController.setAddresses(accounts)
+ this.selectFirstIdentity()
release()
return vault
} catch (err) {
@@ -472,12 +477,10 @@ module.exports = class MetamaskController extends EventEmitter {
*/
/**
- * Retrieves the first Identiy from the passed Vault and selects the related address
- *
- * @param {} vault
+ * Sets the first address in the state to the selected address
*/
- selectFirstIdentity (vault) {
- const { identities } = vault
+ selectFirstIdentity () {
+ const { identities } = this.preferencesController.store.getState()
const address = Object.keys(identities)[0]
this.preferencesController.setSelectedAddress(address)
}
@@ -503,13 +506,15 @@ module.exports = class MetamaskController extends EventEmitter {
await this.verifySeedPhrase()
+ this.preferencesController.setAddresses(newAccounts)
newAccounts.forEach((address) => {
if (!oldAccounts.includes(address)) {
this.preferencesController.setSelectedAddress(address)
}
})
- return keyState
+ const {identities} = this.preferencesController.store.getState()
+ return {...keyState, identities}
}
/**
@@ -604,15 +609,15 @@ module.exports = class MetamaskController extends EventEmitter {
* @param {any} args - The data required by that strategy to import an account.
* @param {Function} cb - A callback function called with a state update on success.
*/
- importAccountWithStrategy (strategy, args, cb) {
- accountImporter.importAccount(strategy, args)
- .then((privateKey) => {
- return this.keyringController.addNewKeyring('Simple Key Pair', [ privateKey ])
- })
- .then(keyring => keyring.getAccounts())
- .then((accounts) => this.preferencesController.setSelectedAddress(accounts[0]))
- .then(() => { cb(null, this.keyringController.fullUpdate()) })
- .catch((reason) => { cb(reason) })
+ async importAccountWithStrategy (strategy, args) {
+ const privateKey = await accountImporter.importAccount(strategy, args)
+ const keyring = await this.keyringController.addNewKeyring('Simple Key Pair', [ privateKey ])
+ const accounts = await keyring.getAccounts()
+ // update accounts in preferences controller
+ const allAccounts = await this.keyringController.getAccounts()
+ this.preferencesController.setAddresses(allAccounts)
+ // set new account as selected
+ await this.preferencesController.setSelectedAddress(accounts[0])
}
// ---------------------------------------------------------------------------