aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/metamask-controller.js
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2018-06-01 02:09:24 +0800
committerDan <danjm.com@gmail.com>2018-06-01 02:09:24 +0800
commit701611e317d120d2c0530e4794bd498a74e233b2 (patch)
tree4ec098d593de7ff5fe20907a48c56061cc14de54 /app/scripts/metamask-controller.js
parent1bde2892ec222cec1ba3265d50ed59f665afbf83 (diff)
parent2ca084b0557242b34733107701a14ba0724363b3 (diff)
downloadtangerine-wallet-browser-701611e317d120d2c0530e4794bd498a74e233b2.tar
tangerine-wallet-browser-701611e317d120d2c0530e4794bd498a74e233b2.tar.gz
tangerine-wallet-browser-701611e317d120d2c0530e4794bd498a74e233b2.tar.bz2
tangerine-wallet-browser-701611e317d120d2c0530e4794bd498a74e233b2.tar.lz
tangerine-wallet-browser-701611e317d120d2c0530e4794bd498a74e233b2.tar.xz
tangerine-wallet-browser-701611e317d120d2c0530e4794bd498a74e233b2.tar.zst
tangerine-wallet-browser-701611e317d120d2c0530e4794bd498a74e233b2.zip
Merge branch 'i3725-refactor-send-component-' into i3914-fix-newui-send-gas-estimation
Diffstat (limited to 'app/scripts/metamask-controller.js')
-rw-r--r--app/scripts/metamask-controller.js35
1 files changed, 18 insertions, 17 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index d3d15e737..9db7e186a 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -45,6 +45,7 @@ const BN = require('ethereumjs-util').BN
const GWEI_BN = new BN('1000000000')
const percentile = require('percentile')
const seedPhraseVerifier = require('./lib/seed-phrase-verifier')
+const cleanErrorStack = require('./lib/cleanErrorStack')
const log = require('loglevel')
module.exports = class MetamaskController extends EventEmitter {
@@ -350,7 +351,7 @@ module.exports = class MetamaskController extends EventEmitter {
verifySeedPhrase: nodeify(this.verifySeedPhrase, this),
clearSeedWordCache: this.clearSeedWordCache.bind(this),
resetAccount: nodeify(this.resetAccount, this),
- importAccountWithStrategy: this.importAccountWithStrategy.bind(this),
+ importAccountWithStrategy: nodeify(this.importAccountWithStrategy, this),
// vault management
submitPassword: nodeify(keyringController.submitPassword, keyringController),
@@ -610,15 +611,15 @@ module.exports = class MetamaskController extends EventEmitter {
* @param {any} args - The data required by that strategy to import an account.
* @param {Function} cb - A callback function called with a state update on success.
*/
- importAccountWithStrategy (strategy, args, cb) {
- accountImporter.importAccount(strategy, args)
- .then((privateKey) => {
- return this.keyringController.addNewKeyring('Simple Key Pair', [ privateKey ])
- })
- .then(keyring => keyring.getAccounts())
- .then((accounts) => this.preferencesController.setSelectedAddress(accounts[0]))
- .then(() => { cb(null, this.keyringController.fullUpdate()) })
- .catch((reason) => { cb(reason) })
+ async importAccountWithStrategy (strategy, args) {
+ const privateKey = await accountImporter.importAccount(strategy, args)
+ const keyring = await this.keyringController.addNewKeyring('Simple Key Pair', [ privateKey ])
+ const accounts = await keyring.getAccounts()
+ // update accounts in preferences controller
+ const allAccounts = await this.keyringController.getAccounts()
+ this.preferencesController.setAddresses(allAccounts)
+ // set new account as selected
+ await this.preferencesController.setSelectedAddress(accounts[0])
}
// ---------------------------------------------------------------------------
@@ -644,9 +645,9 @@ module.exports = class MetamaskController extends EventEmitter {
case 'signed':
return cb(null, data.rawSig)
case 'rejected':
- return cb(new Error('MetaMask Message Signature: User denied message signature.'))
+ return cb(cleanErrorStack(new Error('MetaMask Message Signature: User denied message signature.')))
default:
- return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`))
+ return cb(cleanErrorStack(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`)))
}
})
}
@@ -704,7 +705,7 @@ module.exports = class MetamaskController extends EventEmitter {
*/
newUnsignedPersonalMessage (msgParams, cb) {
if (!msgParams.from) {
- return cb(new Error('MetaMask Message Signature: from field is required.'))
+ return cb(cleanErrorStack(new Error('MetaMask Message Signature: from field is required.')))
}
const msgId = this.personalMessageManager.addUnapprovedMessage(msgParams)
@@ -715,9 +716,9 @@ module.exports = class MetamaskController extends EventEmitter {
case 'signed':
return cb(null, data.rawSig)
case 'rejected':
- return cb(new Error('MetaMask Message Signature: User denied message signature.'))
+ return cb(cleanErrorStack(new Error('MetaMask Message Signature: User denied message signature.')))
default:
- return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`))
+ return cb(cleanErrorStack(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`)))
}
})
}
@@ -783,9 +784,9 @@ module.exports = class MetamaskController extends EventEmitter {
case 'signed':
return cb(null, data.rawSig)
case 'rejected':
- return cb(new Error('MetaMask Message Signature: User denied message signature.'))
+ return cb(cleanErrorStack(new Error('MetaMask Message Signature: User denied message signature.')))
default:
- return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`))
+ return cb(cleanErrorStack(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`)))
}
})
}