diff options
background - return txHash to provider-engine on done
-rw-r--r-- | app/scripts/metamask-controller.js | 24 | ||||
-rw-r--r-- | app/scripts/transaction-manager.js | 3 |
2 files changed, 13 insertions, 14 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 13008893b..b94b98eac 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -246,20 +246,16 @@ module.exports = class MetamaskController extends EventEmitter { self.sendUpdate() self.opts.showUnapprovedTx(txMeta) // listen for tx completion (success, fail) - self.txManager.once(`${txMeta.id}:submitted`, successHandler) - self.txManager.once(`${txMeta.id}:rejected`, failHandler) - function successHandler(rawTx) { - removeHandlers() - cb(null, rawTx) - } - function failHandler() { - removeHandlers() - cb(new Error('User denied message signature.')) - } - function removeHandlers() { - self.txManager.removeListener(`${txMeta.id}:submitted`, successHandler) - self.txManager.removeListener(`${txMeta.id}:rejected`, failHandler) - } + self.txManager.once(`${txMeta.id}:finished`, (status) => { + switch (status) { + case 'submitted': + return cb(null, txMeta.hash) + 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(txMeta.txParams)}`)) + } + }) }) } diff --git a/app/scripts/transaction-manager.js b/app/scripts/transaction-manager.js index 7dbfc0dbc..5a44705b7 100644 --- a/app/scripts/transaction-manager.js +++ b/app/scripts/transaction-manager.js @@ -342,6 +342,9 @@ module.exports = class TransactionManager extends EventEmitter { var txMeta = this.getTx(txId) txMeta.status = status this.emit(`${txMeta.id}:${status}`, txId) + if (status === 'submitted' || status === 'rejected') { + this.emit(`${txMeta.id}:finished`, status) + } this.emit('updateBadge') this.updateTx(txMeta) } |