1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

transactions: make evnt names pretty and eaiser to read

This commit is contained in:
frankiebee 2017-09-26 16:55:11 -07:00
parent 9fd5458112
commit 80c98b1653
3 changed files with 20 additions and 20 deletions

View File

@ -72,9 +72,9 @@ module.exports = class TransactionController extends EventEmitter {
this.txStateManager.store.subscribe(() => this.emit('update:badge'))
this.pendingTxTracker.on('txWarning', this.txStateManager.updateTx.bind(this.txStateManager))
this.pendingTxTracker.on('txFailed', this.txStateManager.setTxStatusFailed.bind(this.txStateManager))
this.pendingTxTracker.on('txConfirmed', this.txStateManager.setTxStatusConfirmed.bind(this.txStateManager))
this.pendingTxTracker.on('tx:warning', this.txStateManager.updateTx.bind(this.txStateManager))
this.pendingTxTracker.on('tx:failed', this.txStateManager.setTxStatusFailed.bind(this.txStateManager))
this.pendingTxTracker.on('tx:confirmed', this.txStateManager.setTxStatusConfirmed.bind(this.txStateManager))
this.blockTracker.on('rawBlock', this.pendingTxTracker.checkForTxInBlock.bind(this.pendingTxTracker))
// this is a little messy but until ethstore has been either

View File

@ -42,13 +42,13 @@ module.exports = class PendingTransactionTracker extends EventEmitter {
if (!txHash) {
const noTxHashErr = new Error('We had an error while submitting this transaction, please try again.')
noTxHashErr.name = 'NoTxHashError'
this.emit('txFailed', txId, noTxHashErr)
this.emit('tx:failed', txId, noTxHashErr)
return
}
block.transactions.forEach((tx) => {
if (tx.hash === txHash) this.emit('txConfirmed', txId)
if (tx.hash === txHash) this.emit('tx:confirmed', txId)
})
})
}
@ -94,7 +94,7 @@ module.exports = class PendingTransactionTracker extends EventEmitter {
// ignore resubmit warnings, return early
if (isKnownTx) return
// encountered real error - transition to error state
this.emit('txFailed', txMeta.id, err)
this.emit('tx:failed', txMeta.id, err)
}))
}
@ -106,13 +106,13 @@ module.exports = class PendingTransactionTracker extends EventEmitter {
if (txMeta.retryCount > this.retryLimit) {
const err = new Error(`Gave up submitting after ${this.retryLimit} blocks un-mined.`)
return this.emit('txFailed', txMeta.id, err)
return this.emit('tx:failed', txMeta.id, err)
}
// if the value of the transaction is greater then the balance, fail.
if (!sufficientBalance(txMeta.txParams, balance)) {
const insufficientFundsError = new Error('Insufficient balance during rebroadcast.')
this.emit('txFailed', txMeta.id, insufficientFundsError)
this.emit('tx:failed', txMeta.id, insufficientFundsError)
log.error(insufficientFundsError)
return
}
@ -136,7 +136,7 @@ module.exports = class PendingTransactionTracker extends EventEmitter {
if (!txHash) {
const noTxHashErr = new Error('We had an error while submitting this transaction, please try again.')
noTxHashErr.name = 'NoTxHashError'
this.emit('txFailed', txId, noTxHashErr)
this.emit('tx:failed', txId, noTxHashErr)
return
}
// get latest transaction status
@ -145,14 +145,14 @@ module.exports = class PendingTransactionTracker extends EventEmitter {
txParams = await this.query.getTransactionByHash(txHash)
if (!txParams) return
if (txParams.blockNumber) {
this.emit('txConfirmed', txId)
this.emit('tx:confirmed', txId)
}
} catch (err) {
txMeta.warning = {
error: err,
message: 'There was a problem loading this transaction.',
}
this.emit('txWarning', txMeta)
this.emit('tx:warning', txMeta)
throw err
}
}

View File

@ -62,7 +62,7 @@ describe('PendingTransactionTracker', function () {
it('should emit \'txFailed\' if the txMeta does not have a hash', function (done) {
const block = Proxy.revocable({}, {}).revoke()
pendingTxTracker.getPendingTransactions = () => [txMetaNoHash]
pendingTxTracker.once('txFailed', (txId, err) => {
pendingTxTracker.once('tx:failed', (txId, err) => {
assert(txId, txMetaNoHash.id, 'should pass txId')
done()
})
@ -71,11 +71,11 @@ describe('PendingTransactionTracker', function () {
it('should emit \'txConfirmed\' if the tx is in the block', function (done) {
const block = { transactions: [txMeta]}
pendingTxTracker.getPendingTransactions = () => [txMeta]
pendingTxTracker.once('txConfirmed', (txId) => {
pendingTxTracker.once('tx:confirmed', (txId) => {
assert(txId, txMeta.id, 'should pass txId')
done()
})
pendingTxTracker.once('txFailed', (_, err) => { done(err) })
pendingTxTracker.once('tx:failed', (_, err) => { done(err) })
pendingTxTracker.checkForTxInBlock(block)
})
})
@ -108,7 +108,7 @@ describe('PendingTransactionTracker', function () {
describe('#_checkPendingTx', function () {
it('should emit \'txFailed\' if the txMeta does not have a hash', function (done) {
pendingTxTracker.once('txFailed', (txId, err) => {
pendingTxTracker.once('tx:failed', (txId, err) => {
assert(txId, txMetaNoHash.id, 'should pass txId')
done()
})
@ -122,11 +122,11 @@ describe('PendingTransactionTracker', function () {
it('should emit \'txConfirmed\'', function (done) {
providerResultStub.eth_getTransactionByHash = {blockNumber: '0x01'}
pendingTxTracker.once('txConfirmed', (txId) => {
pendingTxTracker.once('tx:confirmed', (txId) => {
assert(txId, txMeta.id, 'should pass txId')
done()
})
pendingTxTracker.once('txFailed', (_, err) => { done(err) })
pendingTxTracker.once('tx:failed', (_, err) => { done(err) })
pendingTxTracker._checkPendingTx(txMeta)
})
})
@ -188,7 +188,7 @@ describe('PendingTransactionTracker', function () {
]
const enoughForAllErrors = txList.concat(txList)
pendingTxTracker.on('txFailed', (_, err) => done(err))
pendingTxTracker.on('tx:failed', (_, err) => done(err))
pendingTxTracker.getPendingTransactions = () => enoughForAllErrors
pendingTxTracker._resubmitTx = async (tx) => {
@ -202,7 +202,7 @@ describe('PendingTransactionTracker', function () {
pendingTxTracker.resubmitPendingTxs()
})
it('should emit \'txFailed\' if it encountered a real error', function (done) {
pendingTxTracker.once('txFailed', (id, err) => err.message === 'im some real error' ? txList[id - 1].resolve() : done(err))
pendingTxTracker.once('tx:failed', (id, err) => err.message === 'im some real error' ? txList[id - 1].resolve() : done(err))
pendingTxTracker.getPendingTransactions = () => txList
pendingTxTracker._resubmitTx = async (tx) => { throw new TypeError('im some real error') }
@ -226,7 +226,7 @@ describe('PendingTransactionTracker', function () {
// Stubbing out current account state:
// Adding the fake tx:
pendingTxTracker.once('txFailed', (txId, err) => {
pendingTxTracker.once('tx:failed', (txId, err) => {
assert(err, 'Should have a error')
done()
})