aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfrankiebee <frankie.diamond@gmail.com>2017-09-27 07:55:11 +0800
committerfrankiebee <frankie.diamond@gmail.com>2017-09-27 07:55:11 +0800
commit80c98b16531db4c6a13a52df800967af2bc4a676 (patch)
treed2286824d2617cd2dd3d799c4f6169b3f1a27641
parent9fd545811226c16e11e4f2dc100a348e07f094bf (diff)
downloadtangerine-wallet-browser-80c98b16531db4c6a13a52df800967af2bc4a676.tar
tangerine-wallet-browser-80c98b16531db4c6a13a52df800967af2bc4a676.tar.gz
tangerine-wallet-browser-80c98b16531db4c6a13a52df800967af2bc4a676.tar.bz2
tangerine-wallet-browser-80c98b16531db4c6a13a52df800967af2bc4a676.tar.lz
tangerine-wallet-browser-80c98b16531db4c6a13a52df800967af2bc4a676.tar.xz
tangerine-wallet-browser-80c98b16531db4c6a13a52df800967af2bc4a676.tar.zst
tangerine-wallet-browser-80c98b16531db4c6a13a52df800967af2bc4a676.zip
transactions: make evnt names pretty and eaiser to read
-rw-r--r--app/scripts/controllers/transactions.js6
-rw-r--r--app/scripts/lib/pending-tx-tracker.js16
-rw-r--r--test/unit/pending-tx-test.js18
3 files changed, 20 insertions, 20 deletions
diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js
index 1b647a4ed..ec1524968 100644
--- a/app/scripts/controllers/transactions.js
+++ b/app/scripts/controllers/transactions.js
@@ -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
diff --git a/app/scripts/lib/pending-tx-tracker.js b/app/scripts/lib/pending-tx-tracker.js
index 4541221d5..31cf9babb 100644
--- a/app/scripts/lib/pending-tx-tracker.js
+++ b/app/scripts/lib/pending-tx-tracker.js
@@ -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
}
}
diff --git a/test/unit/pending-tx-test.js b/test/unit/pending-tx-test.js
index 8c6d287f8..2865a30e6 100644
--- a/test/unit/pending-tx-test.js
+++ b/test/unit/pending-tx-test.js
@@ -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()
})