1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Return keyring metadata on metamask state object

Required making the getState methods for both keyringController and metamaskController async.
They both now return promises, and the main metamask-controller.getState method is now nodeified.

Will allow the UI to render loose keys differently than persisted keys.
This commit is contained in:
Dan Finlay 2016-12-22 16:28:14 -08:00
parent 2ab34760b0
commit a10fe6b6f4
2 changed files with 54 additions and 28 deletions

View File

@ -91,26 +91,32 @@ module.exports = class KeyringController extends EventEmitter {
const address = configManager.getSelectedAccount() const address = configManager.getSelectedAccount()
const wallet = configManager.getWallet() // old style vault const wallet = configManager.getWallet() // old style vault
const vault = configManager.getVault() // new style vault const vault = configManager.getVault() // new style vault
const keyrings = this.keyrings
return { return Promise.all(keyrings.map(this.displayForKeyring))
seedWords: this.configManager.getSeedWords(), .then((displayKeyrings) => {
isInitialized: (!!wallet || !!vault), return {
isUnlocked: Boolean(this.password), seedWords: this.configManager.getSeedWords(),
isDisclaimerConfirmed: this.configManager.getConfirmedDisclaimer(), // AUDIT this.configManager.getConfirmedDisclaimer(), isInitialized: (!!wallet || !!vault),
unconfTxs: this.configManager.unconfirmedTxs(), isUnlocked: Boolean(this.password),
transactions: this.configManager.getTxList(), isDisclaimerConfirmed: this.configManager.getConfirmedDisclaimer(),
unconfMsgs: messageManager.unconfirmedMsgs(), unconfTxs: this.configManager.unconfirmedTxs(),
messages: messageManager.getMsgList(), transactions: this.configManager.getTxList(),
selectedAccount: address, unconfMsgs: messageManager.unconfirmedMsgs(),
shapeShiftTxList: this.configManager.getShapeShiftTxList(), messages: messageManager.getMsgList(),
currentFiat: this.configManager.getCurrentFiat(), selectedAccount: address,
conversionRate: this.configManager.getConversionRate(), shapeShiftTxList: this.configManager.getShapeShiftTxList(),
conversionDate: this.configManager.getConversionDate(), currentFiat: this.configManager.getCurrentFiat(),
keyringTypes: this.keyringTypes.map(krt => krt.type), conversionRate: this.configManager.getConversionRate(),
identities: this.identities, conversionDate: this.configManager.getConversionDate(),
} keyringTypes: this.keyringTypes.map(krt => krt.type),
identities: this.identities,
keyrings: displayKeyrings,
}
})
} }
// Create New Vault And Keychain // Create New Vault And Keychain
// @string password - The password to encrypt the vault with // @string password - The password to encrypt the vault with
// //
@ -693,7 +699,7 @@ module.exports = class KeyringController extends EventEmitter {
if (typeof password === 'string') { if (typeof password === 'string') {
this.password = password this.password = password
} }
return Promise.all(this.keyrings.map((keyring) => { return Promise.all(this.keyrings.map((keyring, i) => {
return Promise.all([keyring.type, keyring.serialize()]) return Promise.all([keyring.type, keyring.serialize()])
.then((serializedKeyringArray) => { .then((serializedKeyringArray) => {
// Label the output values on each serialized Keyring: // Label the output values on each serialized Keyring:
@ -744,6 +750,7 @@ module.exports = class KeyringController extends EventEmitter {
// On success, returns the resulting @Keyring instance. // On success, returns the resulting @Keyring instance.
restoreKeyring (serialized) { restoreKeyring (serialized) {
const { type, data } = serialized const { type, data } = serialized
const Keyring = this.getKeyringClassForType(type) const Keyring = this.getKeyringClassForType(type)
const keyring = new Keyring() const keyring = new Keyring()
return keyring.deserialize(data) return keyring.deserialize(data)
@ -816,6 +823,22 @@ module.exports = class KeyringController extends EventEmitter {
}) })
} }
// Display For Keyring
// @Keyring keyring
//
// returns Promise( @Object { type:String, accounts:Array } )
//
// Is used for adding the current keyrings to the state object.
displayForKeyring (keyring) {
return keyring.getAccounts()
.then((accounts) => {
return {
type: keyring.type,
accounts: accounts,
}
})
}
// Add Gas Buffer // Add Gas Buffer
// @string gas (as hexadecimal value) // @string gas (as hexadecimal value)
// //

View File

@ -53,15 +53,18 @@ module.exports = class MetamaskController {
} }
getState () { getState () {
return extend( return this.keyringController.getState()
this.state, .then((keyringControllerState) => {
this.ethStore.getState(), return extend(
this.configManager.getConfig(), this.state,
this.keyringController.getState(), this.ethStore.getState(),
this.noticeController.getState(), { this.configManager.getConfig(),
lostAccounts: this.configManager.getLostAccounts(), keyringControllerState,
} this.noticeController.getState(), {
) lostAccounts: this.configManager.getLostAccounts(),
}
)
})
} }
getApi () { getApi () {
@ -69,7 +72,7 @@ module.exports = class MetamaskController {
const noticeController = this.noticeController const noticeController = this.noticeController
return { return {
getState: (cb) => { cb(null, this.getState()) }, getState: nodeify(this.getState.bind(this)),
setRpcTarget: this.setRpcTarget.bind(this), setRpcTarget: this.setRpcTarget.bind(this),
setProviderType: this.setProviderType.bind(this), setProviderType: this.setProviderType.bind(this),
useEtherscanProvider: this.useEtherscanProvider.bind(this), useEtherscanProvider: this.useEtherscanProvider.bind(this),