mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge pull request #896 from MetaMask/i893-DenodeifyKeyringController
Denodeify most of KeyringController
This commit is contained in:
commit
f8fbeb88ff
File diff suppressed because it is too large
Load Diff
17
app/scripts/lib/nodeify.js
Normal file
17
app/scripts/lib/nodeify.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
module.exports = function (promiseFn) {
|
||||||
|
return function () {
|
||||||
|
var args = []
|
||||||
|
for (var i = 0; i < arguments.length - 1; i++) {
|
||||||
|
args.push(arguments[i])
|
||||||
|
}
|
||||||
|
var cb = arguments[arguments.length - 1]
|
||||||
|
|
||||||
|
return promiseFn.apply(this, args)
|
||||||
|
.then(function (result) {
|
||||||
|
cb(null, result)
|
||||||
|
})
|
||||||
|
.catch(function (reason) {
|
||||||
|
cb(reason)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,7 @@ const Web3 = require('web3')
|
|||||||
const ConfigManager = require('./lib/config-manager')
|
const ConfigManager = require('./lib/config-manager')
|
||||||
const extension = require('./lib/extension')
|
const extension = require('./lib/extension')
|
||||||
const autoFaucet = require('./lib/auto-faucet')
|
const autoFaucet = require('./lib/auto-faucet')
|
||||||
|
const nodeify = require('./lib/nodeify')
|
||||||
|
|
||||||
|
|
||||||
module.exports = class MetamaskController {
|
module.exports = class MetamaskController {
|
||||||
@ -62,21 +63,24 @@ module.exports = class MetamaskController {
|
|||||||
setGasMultiplier: this.setGasMultiplier.bind(this),
|
setGasMultiplier: this.setGasMultiplier.bind(this),
|
||||||
|
|
||||||
// forward directly to keyringController
|
// forward directly to keyringController
|
||||||
placeSeedWords: keyringController.placeSeedWords.bind(keyringController),
|
createNewVaultAndKeychain: nodeify(keyringController.createNewVaultAndKeychain).bind(keyringController),
|
||||||
createNewVaultAndKeychain: keyringController.createNewVaultAndKeychain.bind(keyringController),
|
createNewVaultAndRestore: nodeify(keyringController.createNewVaultAndRestore).bind(keyringController),
|
||||||
createNewVaultAndRestore: keyringController.createNewVaultAndRestore.bind(keyringController),
|
placeSeedWords: nodeify(keyringController.placeSeedWords).bind(keyringController),
|
||||||
clearSeedWordCache: keyringController.clearSeedWordCache.bind(keyringController),
|
clearSeedWordCache: nodeify(keyringController.clearSeedWordCache).bind(keyringController),
|
||||||
addNewKeyring: keyringController.addNewKeyring.bind(keyringController),
|
setLocked: nodeify(keyringController.setLocked).bind(keyringController),
|
||||||
addNewAccount: keyringController.addNewAccount.bind(keyringController),
|
submitPassword: nodeify(keyringController.submitPassword).bind(keyringController),
|
||||||
submitPassword: keyringController.submitPassword.bind(keyringController),
|
addNewKeyring: nodeify(keyringController.addNewKeyring).bind(keyringController),
|
||||||
setSelectedAccount: keyringController.setSelectedAccount.bind(keyringController),
|
addNewAccount: nodeify(keyringController.addNewAccount).bind(keyringController),
|
||||||
|
setSelectedAccount: nodeify(keyringController.setSelectedAccount).bind(keyringController),
|
||||||
|
saveAccountLabel: nodeify(keyringController.saveAccountLabel).bind(keyringController),
|
||||||
|
exportAccount: nodeify(keyringController.exportAccount).bind(keyringController),
|
||||||
|
|
||||||
|
// signing methods
|
||||||
approveTransaction: keyringController.approveTransaction.bind(keyringController),
|
approveTransaction: keyringController.approveTransaction.bind(keyringController),
|
||||||
cancelTransaction: keyringController.cancelTransaction.bind(keyringController),
|
cancelTransaction: keyringController.cancelTransaction.bind(keyringController),
|
||||||
signMessage: keyringController.signMessage.bind(keyringController),
|
signMessage: keyringController.signMessage.bind(keyringController),
|
||||||
cancelMessage: keyringController.cancelMessage.bind(keyringController),
|
cancelMessage: keyringController.cancelMessage.bind(keyringController),
|
||||||
setLocked: keyringController.setLocked.bind(keyringController),
|
|
||||||
exportAccount: keyringController.exportAccount.bind(keyringController),
|
|
||||||
saveAccountLabel: keyringController.saveAccountLabel.bind(keyringController),
|
|
||||||
// coinbase
|
// coinbase
|
||||||
buyEth: this.buyEth.bind(this),
|
buyEth: this.buyEth.bind(this),
|
||||||
// shapeshift
|
// shapeshift
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ap": "^0.2.0",
|
|
||||||
"async": "^1.5.2",
|
"async": "^1.5.2",
|
||||||
"bip39": "^2.2.0",
|
"bip39": "^2.2.0",
|
||||||
"browserify-derequire": "^0.9.4",
|
"browserify-derequire": "^0.9.4",
|
||||||
@ -67,6 +66,7 @@
|
|||||||
"pojo-migrator": "^2.1.0",
|
"pojo-migrator": "^2.1.0",
|
||||||
"polyfill-crypto.getrandomvalues": "^1.0.0",
|
"polyfill-crypto.getrandomvalues": "^1.0.0",
|
||||||
"post-message-stream": "^1.0.0",
|
"post-message-stream": "^1.0.0",
|
||||||
|
"promise-filter": "^1.1.0",
|
||||||
"pumpify": "^1.3.4",
|
"pumpify": "^1.3.4",
|
||||||
"qrcode-npm": "0.0.3",
|
"qrcode-npm": "0.0.3",
|
||||||
"react": "^15.0.2",
|
"react": "^15.0.2",
|
||||||
|
@ -38,8 +38,8 @@ QUnit.test('keyringController:isInitialized', function (assert) {
|
|||||||
QUnit.test('keyringController:submitPassword', function (assert) {
|
QUnit.test('keyringController:submitPassword', function (assert) {
|
||||||
var done = assert.async()
|
var done = assert.async()
|
||||||
|
|
||||||
this.keyringController.submitPassword(PASSWORD, (err, state) => {
|
this.keyringController.submitPassword(PASSWORD)
|
||||||
assert.notOk(err)
|
.then((state) => {
|
||||||
assert.ok(state.identities[FIRST_ADDRESS])
|
assert.ok(state.identities[FIRST_ADDRESS])
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
@ -49,9 +49,14 @@ QUnit.test('keyringController:setLocked', function (assert) {
|
|||||||
var done = assert.async()
|
var done = assert.async()
|
||||||
var self = this
|
var self = this
|
||||||
|
|
||||||
this.keyringController.setLocked(function(err) {
|
this.keyringController.setLocked()
|
||||||
|
.then(function() {
|
||||||
assert.notOk(self.keyringController.password, 'password should be deallocated')
|
assert.notOk(self.keyringController.password, 'password should be deallocated')
|
||||||
assert.deepEqual(self.keyringController.keyrings, [], 'keyrings should be deallocated')
|
assert.deepEqual(self.keyringController.keyrings, [], 'keyrings should be deallocated')
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
.catch((reason) => {
|
||||||
|
assert.ifError(reason)
|
||||||
|
done()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -32,8 +32,8 @@ describe('KeyringController', function() {
|
|||||||
// Browser crypto is tested in the integration test suite.
|
// Browser crypto is tested in the integration test suite.
|
||||||
keyringController.encryptor = mockEncryptor
|
keyringController.encryptor = mockEncryptor
|
||||||
|
|
||||||
keyringController.createNewVaultAndKeychain(password, function (err, newState) {
|
keyringController.createNewVaultAndKeychain(password)
|
||||||
assert.ifError(err)
|
.then(function (newState) {
|
||||||
state = newState
|
state = newState
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
@ -50,12 +50,16 @@ describe('KeyringController', function() {
|
|||||||
it('should set a vault on the configManager', function(done) {
|
it('should set a vault on the configManager', function(done) {
|
||||||
keyringController.configManager.setVault(null)
|
keyringController.configManager.setVault(null)
|
||||||
assert(!keyringController.configManager.getVault(), 'no previous vault')
|
assert(!keyringController.configManager.getVault(), 'no previous vault')
|
||||||
keyringController.createNewVaultAndKeychain(password, (err, state) => {
|
keyringController.createNewVaultAndKeychain(password)
|
||||||
assert.ifError(err)
|
.then(() => {
|
||||||
const vault = keyringController.configManager.getVault()
|
const vault = keyringController.configManager.getVault()
|
||||||
assert(vault, 'vault created')
|
assert(vault, 'vault created')
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
.catch((reason) => {
|
||||||
|
assert.ifError(reason)
|
||||||
|
done()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -124,13 +128,17 @@ describe('KeyringController', function() {
|
|||||||
const account = addresses[0]
|
const account = addresses[0]
|
||||||
var nick = 'Test nickname'
|
var nick = 'Test nickname'
|
||||||
keyringController.identities[ethUtil.addHexPrefix(account)] = {}
|
keyringController.identities[ethUtil.addHexPrefix(account)] = {}
|
||||||
keyringController.saveAccountLabel(account, nick, (err, label) => {
|
keyringController.saveAccountLabel(account, nick)
|
||||||
assert.ifError(err)
|
.then((label) => {
|
||||||
assert.equal(label, nick)
|
assert.equal(label, nick)
|
||||||
const persisted = keyringController.configManager.nicknameForWallet(account)
|
const persisted = keyringController.configManager.nicknameForWallet(account)
|
||||||
assert.equal(persisted, nick)
|
assert.equal(persisted, nick)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
.catch((reason) => {
|
||||||
|
assert.ifError(reason)
|
||||||
|
done()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
this.timeout(10000)
|
this.timeout(10000)
|
||||||
@ -138,8 +146,8 @@ describe('KeyringController', function() {
|
|||||||
const account = addresses[0]
|
const account = addresses[0]
|
||||||
var nick = 'Test nickname'
|
var nick = 'Test nickname'
|
||||||
keyringController.configManager.setNicknameForWallet(account, nick)
|
keyringController.configManager.setNicknameForWallet(account, nick)
|
||||||
keyringController.createNewVaultAndRestore(password, seedWords, (err, state) => {
|
keyringController.createNewVaultAndRestore(password, seedWords)
|
||||||
assert.ifError(err)
|
.then((state) => {
|
||||||
|
|
||||||
const identity = keyringController.identities['0x' + account]
|
const identity = keyringController.identities['0x' + account]
|
||||||
assert.equal(identity.name, nick)
|
assert.equal(identity.name, nick)
|
||||||
@ -147,6 +155,10 @@ describe('KeyringController', function() {
|
|||||||
assert(accounts)
|
assert(accounts)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
.catch((reason) => {
|
||||||
|
assert.ifError(reason)
|
||||||
|
done()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -57,13 +57,11 @@ describe('hd-keyring', function() {
|
|||||||
|
|
||||||
describe('#deserialize a private key', function() {
|
describe('#deserialize a private key', function() {
|
||||||
it('serializes what it deserializes', function(done) {
|
it('serializes what it deserializes', function(done) {
|
||||||
console.log('deserializing ' + sampleMnemonic)
|
|
||||||
keyring.deserialize({
|
keyring.deserialize({
|
||||||
mnemonic: sampleMnemonic,
|
mnemonic: sampleMnemonic,
|
||||||
numberOfAccounts: 1
|
numberOfAccounts: 1
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.dir(keyring)
|
|
||||||
assert.equal(keyring.wallets.length, 1, 'restores two accounts')
|
assert.equal(keyring.wallets.length, 1, 'restores two accounts')
|
||||||
return keyring.addAccounts(1)
|
return keyring.addAccounts(1)
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
|
22
test/unit/nodeify-test.js
Normal file
22
test/unit/nodeify-test.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
const assert = require('assert')
|
||||||
|
const nodeify = require('../../app/scripts/lib/nodeify')
|
||||||
|
|
||||||
|
describe.only('nodeify', function() {
|
||||||
|
|
||||||
|
var obj = {
|
||||||
|
foo: 'bar',
|
||||||
|
promiseFunc: function (a) {
|
||||||
|
var solution = this.foo + a
|
||||||
|
return Promise.resolve(solution)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
it('should retain original context', function(done) {
|
||||||
|
var nodified = nodeify(obj.promiseFunc).bind(obj)
|
||||||
|
nodified('baz', function (err, res) {
|
||||||
|
assert.equal(res, 'barbaz')
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
@ -154,8 +154,6 @@ PTXP.render = function () {
|
|||||||
]),
|
]),
|
||||||
]), // End of Table
|
]), // End of Table
|
||||||
|
|
||||||
this.warnIfNeeded(),
|
|
||||||
|
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -201,29 +199,6 @@ PTXP.miniAccountPanelForRecipient = function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should analyze if there is a DELEGATECALL opcode
|
|
||||||
// in the recipient contract, and show a warning if so.
|
|
||||||
PTXP.warnIfNeeded = function () {
|
|
||||||
const containsDelegateCall = !!this.props.txData.containsDelegateCall
|
|
||||||
|
|
||||||
if (!containsDelegateCall) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
return h('span.error', {
|
|
||||||
style: {
|
|
||||||
fontFamily: 'Montserrat Light',
|
|
||||||
fontSize: '13px',
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'center',
|
|
||||||
},
|
|
||||||
}, [
|
|
||||||
h('i.fa.fa-lg.fa-info-circle', { style: { margin: '5px' } }),
|
|
||||||
h('span', ' Your identity may be used in other contracts!'),
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function forwardCarrat () {
|
function forwardCarrat () {
|
||||||
return (
|
return (
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user