diff options
author | Frankie <frankie.diamond@gmail.com> | 2017-02-02 03:54:01 +0800 |
---|---|---|
committer | Frankie <frankie.diamond@gmail.com> | 2017-02-02 03:54:01 +0800 |
commit | 1b16b4624186265ccbb6f8106e1bf9ff997e2528 (patch) | |
tree | 56dad7e72c2983b786c454a398ed098415eff290 /app/scripts/metamask-controller.js | |
parent | f40629e5ae7d284e871d9dcd8b62fce34b6f2b39 (diff) | |
download | tangerine-wallet-browser-1b16b4624186265ccbb6f8106e1bf9ff997e2528.tar tangerine-wallet-browser-1b16b4624186265ccbb6f8106e1bf9ff997e2528.tar.gz tangerine-wallet-browser-1b16b4624186265ccbb6f8106e1bf9ff997e2528.tar.bz2 tangerine-wallet-browser-1b16b4624186265ccbb6f8106e1bf9ff997e2528.tar.lz tangerine-wallet-browser-1b16b4624186265ccbb6f8106e1bf9ff997e2528.tar.xz tangerine-wallet-browser-1b16b4624186265ccbb6f8106e1bf9ff997e2528.tar.zst tangerine-wallet-browser-1b16b4624186265ccbb6f8106e1bf9ff997e2528.zip |
code clan up and tests
Diffstat (limited to 'app/scripts/metamask-controller.js')
-rw-r--r-- | app/scripts/metamask-controller.js | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index bab005af2..38358f04b 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -224,7 +224,7 @@ module.exports = class MetamaskController extends EventEmitter { approveTransaction: txManager.approveTransaction.bind(txManager), cancelTransaction: txManager.cancelTransaction.bind(txManager), signMessage: this.signMessage.bind(this), - cancelMessage: messageManager.cancelMessage.bind(messageManager), + cancelMessage: messageManager.rejectMsg.bind(messageManager), // notices checkNotices: noticeController.updateNoticesList.bind(noticeController), @@ -369,31 +369,33 @@ module.exports = class MetamaskController extends EventEmitter { } newUnsignedMessage (msgParams, cb) { - this.keyringController.getState() - .then((state) => { - let msgId = this.messageManager.addUnapprovedMessage(msgParams) - this.sendUpdate() - state.isUnlocked ? this.opts.unlockAccountMessage() : this.opts.showUnconfirmedMessage() - this.messageManager.once(`${msgId}:finished`, (data) => { - switch (data.status) { - case 'approved': - return cb(null, data.rawSig) - case 'rejected': - return cb(new Error('MetaMask Tx Signature: User denied transaction signature.')) - default: - return cb(new Error(`MetaMask Tx Signature: Unknown problem: ${JSON.stringify(msgParams)}`)) - } - }) + let msgId = this.messageManager.addUnapprovedMessage(msgParams) + this.sendUpdate() + this.opts.showUnconfirmedMessage() + this.messageManager.once(`${msgId}:finished`, (data) => { + switch (data.status) { + case 'approved': + return cb(null, data.rawSig) + case 'rejected': + return cb(new Error('MetaMask Message Signature: User denied transaction signature.')) + default: + return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`)) + } }) } signMessage (msgParams, cb) { const msgId = msgParams.metamaskId + // sets the status op the message to 'approved' + // and removes the metamaskId for signing return this.messageManager.approveMessage(msgParams) .then((cleanMsgParams) => { + // signs the message return this.keyringController.signMessage(cleanMsgParams) }) .then((rawSig) => { + // tells the listener that the message has been signed + // and can be returned to the dapp this.messageManager.brodcastMessage(rawSig, msgId, 'approved') }).then(() => { cb() |