Merge pull request #4131 from MetaMask/emitter-cleanup

transactions - run event emitters outside context of _setTxStatus
feature/default_network_editable
kumavis 7 years ago committed by GitHub
commit 099fc0917d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      app/scripts/controllers/transactions/tx-state-manager.js

@ -2,6 +2,7 @@ const extend = require('xtend')
const EventEmitter = require('events')
const ObservableStore = require('obs-store')
const ethUtil = require('ethereumjs-util')
const log = require('loglevel')
const txStateHistoryHelper = require('./lib/tx-state-history-helper')
const createId = require('../../lib/random-id')
const { getFinalStates } = require('./lib/util')
@ -398,13 +399,19 @@ class TransactionStateManager extends EventEmitter {
_setTxStatus (txId, status) {
const txMeta = this.getTx(txId)
txMeta.status = status
setTimeout(() => {
try {
this.updateTx(txMeta, `txStateManager: setting status to ${status}`)
this.emit(`${txMeta.id}:${status}`, txId)
this.emit(`tx:status-update`, txId, status)
if (['submitted', 'rejected', 'failed'].includes(status)) {
this.emit(`${txMeta.id}:finished`, txMeta)
}
this.updateTx(txMeta, `txStateManager: setting status to ${status}`)
this.emit('update:badge')
} catch (error) {
log.error(error)
}
})
}
/**

Loading…
Cancel
Save