mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
metamask - move selectedAccount set/get to preferencesController
This commit is contained in:
parent
0a1918f71a
commit
4dafb09db2
@ -88,8 +88,6 @@ class KeyringController extends EventEmitter {
|
|||||||
keyringTypes: this.keyringTypes.map(krt => krt.type),
|
keyringTypes: this.keyringTypes.map(krt => krt.type),
|
||||||
// memStore
|
// memStore
|
||||||
identities: this.identities,
|
identities: this.identities,
|
||||||
// diskStore
|
|
||||||
selectedAccount: state.selectedAccount,
|
|
||||||
// configManager
|
// configManager
|
||||||
seedWords: this.configManager.getSeedWords(),
|
seedWords: this.configManager.getSeedWords(),
|
||||||
isDisclaimerConfirmed: this.configManager.getConfirmedDisclaimer(),
|
isDisclaimerConfirmed: this.configManager.getConfirmedDisclaimer(),
|
||||||
@ -231,28 +229,6 @@ class KeyringController extends EventEmitter {
|
|||||||
.then(this.fullUpdate.bind(this))
|
.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
|
// Save Account Label
|
||||||
// @string account
|
// @string account
|
||||||
// @string label
|
// @string label
|
||||||
|
@ -42,8 +42,8 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
this.configManager.updateConversionRate()
|
this.configManager.updateConversionRate()
|
||||||
|
|
||||||
// preferences controller
|
// preferences controller
|
||||||
this.prefencesController = new PreferencesController({
|
this.preferencesController = new PreferencesController({
|
||||||
initState: initState.PrefencesController,
|
initState: initState.PreferencesController,
|
||||||
})
|
})
|
||||||
|
|
||||||
// rpc provider
|
// rpc provider
|
||||||
@ -71,7 +71,7 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
txList: this.configManager.getTxList(),
|
txList: this.configManager.getTxList(),
|
||||||
txHistoryLimit: 40,
|
txHistoryLimit: 40,
|
||||||
setTxList: this.configManager.setTxList.bind(this.configManager),
|
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),
|
getGasMultiplier: this.configManager.getGasMultiplier.bind(this.configManager),
|
||||||
getNetwork: this.getStateNetwork.bind(this),
|
getNetwork: this.getStateNetwork.bind(this),
|
||||||
signTransaction: this.keyringController.signTransaction.bind(this.keyringController),
|
signTransaction: this.keyringController.signTransaction.bind(this.keyringController),
|
||||||
@ -107,8 +107,8 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
this.keyringController.store.subscribe((state) => {
|
this.keyringController.store.subscribe((state) => {
|
||||||
this.store.updateState({ KeyringController: state })
|
this.store.updateState({ KeyringController: state })
|
||||||
})
|
})
|
||||||
this.prefencesController.store.subscribe((state) => {
|
this.preferencesController.store.subscribe((state) => {
|
||||||
this.store.updateState({ PrefencesController: state })
|
this.store.updateState({ PreferencesController: state })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
rpcUrl: this.configManager.getCurrentRpcAddress(),
|
rpcUrl: this.configManager.getCurrentRpcAddress(),
|
||||||
// account mgmt
|
// account mgmt
|
||||||
getAccounts: (cb) => {
|
getAccounts: (cb) => {
|
||||||
let selectedAccount = this.keyringController.getSelectedAccount()
|
let selectedAccount = this.preferencesController.getSelectedAccount()
|
||||||
let result = selectedAccount ? [selectedAccount] : []
|
let result = selectedAccount ? [selectedAccount] : []
|
||||||
cb(null, result)
|
cb(null, result)
|
||||||
},
|
},
|
||||||
@ -191,6 +191,7 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
|
|
||||||
getApi () {
|
getApi () {
|
||||||
const keyringController = this.keyringController
|
const keyringController = this.keyringController
|
||||||
|
const preferencesController = this.preferencesController
|
||||||
const txManager = this.txManager
|
const txManager = this.txManager
|
||||||
const noticeController = this.noticeController
|
const noticeController = this.noticeController
|
||||||
|
|
||||||
@ -221,12 +222,14 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
// vault management
|
// vault management
|
||||||
submitPassword: this.submitPassword.bind(this),
|
submitPassword: this.submitPassword.bind(this),
|
||||||
|
|
||||||
|
// PreferencesController
|
||||||
|
setSelectedAccount: nodeify(preferencesController.setSelectedAccount).bind(preferencesController),
|
||||||
|
|
||||||
// KeyringController
|
// KeyringController
|
||||||
setLocked: nodeify(keyringController.setLocked).bind(keyringController),
|
setLocked: nodeify(keyringController.setLocked).bind(keyringController),
|
||||||
createNewVaultAndKeychain: nodeify(keyringController.createNewVaultAndKeychain).bind(keyringController),
|
createNewVaultAndKeychain: nodeify(keyringController.createNewVaultAndKeychain).bind(keyringController),
|
||||||
createNewVaultAndRestore: nodeify(keyringController.createNewVaultAndRestore).bind(keyringController),
|
createNewVaultAndRestore: nodeify(keyringController.createNewVaultAndRestore).bind(keyringController),
|
||||||
addNewKeyring: nodeify(keyringController.addNewKeyring).bind(keyringController),
|
addNewKeyring: nodeify(keyringController.addNewKeyring).bind(keyringController),
|
||||||
setSelectedAccount: nodeify(keyringController.setSelectedAccount).bind(keyringController),
|
|
||||||
saveAccountLabel: nodeify(keyringController.saveAccountLabel).bind(keyringController),
|
saveAccountLabel: nodeify(keyringController.saveAccountLabel).bind(keyringController),
|
||||||
exportAccount: nodeify(keyringController.exportAccount).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.
|
// ensuring they are only ever available in the background process.
|
||||||
clearSeedWordCache (cb) {
|
clearSeedWordCache (cb) {
|
||||||
this.configManager.setSeedWords(null)
|
this.configManager.setSeedWords(null)
|
||||||
cb(null, this.keyringController.getSelectedAccount())
|
cb(null, this.preferencesController.getSelectedAccount())
|
||||||
}
|
}
|
||||||
|
|
||||||
importAccountWithStrategy (strategy, args, cb) {
|
importAccountWithStrategy (strategy, args, cb) {
|
||||||
@ -348,7 +351,7 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
return this.keyringController.addNewKeyring('Simple Key Pair', [ privateKey ])
|
return this.keyringController.addNewKeyring('Simple Key Pair', [ privateKey ])
|
||||||
})
|
})
|
||||||
.then(keyring => keyring.getAccounts())
|
.then(keyring => keyring.getAccounts())
|
||||||
.then((accounts) => this.keyringController.setSelectedAccount(accounts[0]))
|
.then((accounts) => this.preferencesController.setSelectedAccount(accounts[0]))
|
||||||
.then(() => { cb(null, this.keyringController.fullUpdate()) })
|
.then(() => { cb(null, this.keyringController.fullUpdate()) })
|
||||||
.catch((reason) => { cb(reason) })
|
.catch((reason) => { cb(reason) })
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user