diff options
author | Frankie <frankie.diamond@gmail.com> | 2017-01-05 05:05:29 +0800 |
---|---|---|
committer | Frankie <frankie.diamond@gmail.com> | 2017-01-05 05:05:29 +0800 |
commit | 354fa763d4962deeeb4584c5d5bd5f6d007e211a (patch) | |
tree | 0b3996c83748803caa47268d90cd1c7fdaf462d6 /app | |
parent | e6da8e2762cd54975c334314357f1cd27cc980c8 (diff) | |
parent | c22da8450cf5014fb2bf3c96e0df88c70aa39465 (diff) | |
download | tangerine-wallet-browser-354fa763d4962deeeb4584c5d5bd5f6d007e211a.tar tangerine-wallet-browser-354fa763d4962deeeb4584c5d5bd5f6d007e211a.tar.gz tangerine-wallet-browser-354fa763d4962deeeb4584c5d5bd5f6d007e211a.tar.bz2 tangerine-wallet-browser-354fa763d4962deeeb4584c5d5bd5f6d007e211a.tar.lz tangerine-wallet-browser-354fa763d4962deeeb4584c5d5bd5f6d007e211a.tar.xz tangerine-wallet-browser-354fa763d4962deeeb4584c5d5bd5f6d007e211a.tar.zst tangerine-wallet-browser-354fa763d4962deeeb4584c5d5bd5f6d007e211a.zip |
Merge branch 'dev' into fixtTxManager
Diffstat (limited to 'app')
-rw-r--r-- | app/manifest.json | 2 | ||||
-rw-r--r-- | app/scripts/keyring-controller.js | 55 | ||||
-rw-r--r-- | app/scripts/keyrings/simple.js | 9 | ||||
-rw-r--r-- | app/scripts/metamask-controller.js | 39 |
4 files changed, 68 insertions, 37 deletions
diff --git a/app/manifest.json b/app/manifest.json index 61775ed93..95dcfc31a 100644 --- a/app/manifest.json +++ b/app/manifest.json @@ -56,9 +56,7 @@ ], "permissions": [ "storage", - "tabs", "clipboardWrite", - "clipboardRead", "http://localhost:8545/" ], "web_accessible_resources": [ diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js index acec8feb1..1a26a887f 100644 --- a/app/scripts/keyring-controller.js +++ b/app/scripts/keyring-controller.js @@ -86,22 +86,28 @@ 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(), - 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(), + 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 @@ -555,6 +561,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) @@ -627,6 +634,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/keyrings/simple.js b/app/scripts/keyrings/simple.js index 8f339cf80..9717f1c45 100644 --- a/app/scripts/keyrings/simple.js +++ b/app/scripts/keyrings/simple.js @@ -19,10 +19,11 @@ class SimpleKeyring extends EventEmitter { return Promise.resolve(this.wallets.map(w => w.getPrivateKey().toString('hex'))) } - deserialize (wallets = []) { - this.wallets = wallets.map((w) => { - var b = new Buffer(w, 'hex') - const wallet = Wallet.fromPrivateKey(b) + deserialize (privateKeys = []) { + this.wallets = privateKeys.map((privateKey) => { + const stripped = ethUtil.stripHexPrefix(privateKey) + const buffer = new Buffer(stripped, 'hex') + const wallet = Wallet.fromPrivateKey(buffer) return wallet }) return Promise.resolve() diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 32e9faab2..4caad46e1 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -60,19 +60,24 @@ module.exports = class MetamaskController { this.idStoreMigrator = new IdStoreMigrator({ configManager: this.configManager, }) + + this.ethStore.on('update', this.sendUpdate.bind(this)) } getState () { - return extend( - this.state, - this.ethStore.getState(), - this.configManager.getConfig(), - this.keyringController.getState(), - this.txManager.getState(), - this.noticeController.getState(), { - lostAccounts: this.configManager.getLostAccounts(), - } - ) + return this.keyringController.getState() + .then((keyringControllerState) => { + return extend( + this.state, + this.ethStore.getState(), + this.configManager.getConfig(), + this.txManager.getState(), + keyringControllerState, + this.noticeController.getState(), { + lostAccounts: this.configManager.getLostAccounts(), + } + ) + }) } getApi () { @@ -81,7 +86,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), @@ -101,7 +106,7 @@ module.exports = class MetamaskController { setLocked: nodeify(keyringController.setLocked).bind(keyringController), submitPassword: (password, cb) => { this.migrateOldVaultIfAny(password) - .then(keyringController.submitPassword.bind(keyringController)) + .then(keyringController.submitPassword.bind(keyringController, password)) .then((newState) => { cb(null, newState) }) .catch((reason) => { cb(reason) }) }, @@ -158,8 +163,12 @@ module.exports = class MetamaskController { } sendUpdate () { - this.listeners.forEach((remote) => { - remote.sendUpdate(this.getState()) + this.getState() + .then((state) => { + + this.listeners.forEach((remote) => { + remote.sendUpdate(state) + }) }) } @@ -479,7 +488,7 @@ module.exports = class MetamaskController { return this.idStoreMigrator.migratedVaultForPassword(password) .then(this.restoreOldVaultAccounts.bind(this)) .then(this.restoreOldLostAccounts.bind(this)) - .then(keyringController.persistAllKeyrings.bind(keyringController)) + .then(keyringController.persistAllKeyrings.bind(keyringController, password)) .then(() => password) } |