diff options
author | Dan Finlay <dan@danfinlay.com> | 2016-12-23 08:28:14 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2016-12-23 09:17:07 +0800 |
commit | a10fe6b6f4217b3984f861bb8ad69d075f672872 (patch) | |
tree | 91f0b3d1cd2969d5e4ab00e75e889a16bd3225b9 /app | |
parent | 2ab34760b0e2e006c0b87722e8397c642eb86981 (diff) | |
download | tangerine-wallet-browser-a10fe6b6f4217b3984f861bb8ad69d075f672872.tar tangerine-wallet-browser-a10fe6b6f4217b3984f861bb8ad69d075f672872.tar.gz tangerine-wallet-browser-a10fe6b6f4217b3984f861bb8ad69d075f672872.tar.bz2 tangerine-wallet-browser-a10fe6b6f4217b3984f861bb8ad69d075f672872.tar.lz tangerine-wallet-browser-a10fe6b6f4217b3984f861bb8ad69d075f672872.tar.xz tangerine-wallet-browser-a10fe6b6f4217b3984f861bb8ad69d075f672872.tar.zst tangerine-wallet-browser-a10fe6b6f4217b3984f861bb8ad69d075f672872.zip |
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.
Diffstat (limited to 'app')
-rw-r--r-- | app/scripts/keyring-controller.js | 61 | ||||
-rw-r--r-- | app/scripts/metamask-controller.js | 23 |
2 files changed, 55 insertions, 29 deletions
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js index 4e9193ab2..d53de1ab6 100644 --- a/app/scripts/keyring-controller.js +++ b/app/scripts/keyring-controller.js @@ -91,26 +91,32 @@ module.exports = class KeyringController extends EventEmitter { const address = configManager.getSelectedAccount() const wallet = configManager.getWallet() // old style vault const vault = configManager.getVault() // new style vault - - return { - seedWords: this.configManager.getSeedWords(), - isInitialized: (!!wallet || !!vault), - isUnlocked: Boolean(this.password), - isDisclaimerConfirmed: this.configManager.getConfirmedDisclaimer(), // AUDIT this.configManager.getConfirmedDisclaimer(), - unconfTxs: this.configManager.unconfirmedTxs(), - transactions: this.configManager.getTxList(), - unconfMsgs: messageManager.unconfirmedMsgs(), - messages: messageManager.getMsgList(), - selectedAccount: address, - shapeShiftTxList: this.configManager.getShapeShiftTxList(), - currentFiat: this.configManager.getCurrentFiat(), - conversionRate: this.configManager.getConversionRate(), - conversionDate: this.configManager.getConversionDate(), - keyringTypes: this.keyringTypes.map(krt => krt.type), - identities: this.identities, - } + const keyrings = this.keyrings + + return Promise.all(keyrings.map(this.displayForKeyring)) + .then((displayKeyrings) => { + return { + seedWords: this.configManager.getSeedWords(), + isInitialized: (!!wallet || !!vault), + isUnlocked: Boolean(this.password), + isDisclaimerConfirmed: this.configManager.getConfirmedDisclaimer(), + unconfTxs: this.configManager.unconfirmedTxs(), + transactions: this.configManager.getTxList(), + unconfMsgs: messageManager.unconfirmedMsgs(), + messages: messageManager.getMsgList(), + selectedAccount: address, + shapeShiftTxList: this.configManager.getShapeShiftTxList(), + currentFiat: this.configManager.getCurrentFiat(), + conversionRate: this.configManager.getConversionRate(), + conversionDate: this.configManager.getConversionDate(), + keyringTypes: this.keyringTypes.map(krt => krt.type), + identities: this.identities, + keyrings: displayKeyrings, + } + }) } + // Create New Vault And Keychain // @string password - The password to encrypt the vault with // @@ -693,7 +699,7 @@ module.exports = class KeyringController extends EventEmitter { if (typeof password === 'string') { 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()]) .then((serializedKeyringArray) => { // 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. restoreKeyring (serialized) { const { type, data } = serialized + const Keyring = this.getKeyringClassForType(type) const keyring = new Keyring() 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 // @string gas (as hexadecimal value) // diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 983a590d7..78e5a6f0a 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -53,15 +53,18 @@ module.exports = class MetamaskController { } getState () { - return extend( - this.state, - this.ethStore.getState(), - this.configManager.getConfig(), - this.keyringController.getState(), - this.noticeController.getState(), { - lostAccounts: this.configManager.getLostAccounts(), - } - ) + return this.keyringController.getState() + .then((keyringControllerState) => { + return extend( + this.state, + this.ethStore.getState(), + this.configManager.getConfig(), + keyringControllerState, + this.noticeController.getState(), { + lostAccounts: this.configManager.getLostAccounts(), + } + ) + }) } getApi () { @@ -69,7 +72,7 @@ module.exports = class MetamaskController { const noticeController = this.noticeController return { - getState: (cb) => { cb(null, this.getState()) }, + getState: nodeify(this.getState.bind(this)), setRpcTarget: this.setRpcTarget.bind(this), setProviderType: this.setProviderType.bind(this), useEtherscanProvider: this.useEtherscanProvider.bind(this), |