mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge pull request #2261 from MetaMask/retry-warn-not-fail
Resubmit - warn not fail on error
This commit is contained in:
commit
62a022336a
@ -86,12 +86,15 @@ module.exports = class PendingTransactionTracker extends EventEmitter {
|
||||
// other
|
||||
|| errorMessage.includes('gateway timeout')
|
||||
|| errorMessage.includes('nonce too low')
|
||||
|| txMeta.retryCount > 1
|
||||
)
|
||||
// ignore resubmit warnings, return early
|
||||
if (isKnownTx) return
|
||||
// encountered real error - transition to error state
|
||||
this.emit('tx:failed', txMeta.id, err)
|
||||
txMeta.warning = {
|
||||
error: errorMessage,
|
||||
message: 'There was an error when resubmitting this transaction.',
|
||||
}
|
||||
this.emit('tx:warning', txMeta, err)
|
||||
}))
|
||||
}
|
||||
|
||||
@ -133,11 +136,10 @@ module.exports = class PendingTransactionTracker extends EventEmitter {
|
||||
}
|
||||
} catch (err) {
|
||||
txMeta.warning = {
|
||||
error: err,
|
||||
error: err.message,
|
||||
message: 'There was a problem loading this transaction.',
|
||||
}
|
||||
this.emit('tx:warning', txMeta)
|
||||
throw err
|
||||
this.emit('tx:warning', txMeta, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ describe('PendingTransactionTracker', function () {
|
||||
const block = Proxy.revocable({}, {}).revoke()
|
||||
pendingTxTracker.checkForTxInBlock(block)
|
||||
})
|
||||
it('should emit \'txFailed\' if the txMeta does not have a hash', function (done) {
|
||||
it('should emit \'tx:failed\' if the txMeta does not have a hash', function (done) {
|
||||
const block = Proxy.revocable({}, {}).revoke()
|
||||
pendingTxTracker.getPendingTransactions = () => [txMetaNoHash]
|
||||
pendingTxTracker.once('tx:failed', (txId, err) => {
|
||||
@ -105,7 +105,7 @@ describe('PendingTransactionTracker', function () {
|
||||
})
|
||||
|
||||
describe('#_checkPendingTx', function () {
|
||||
it('should emit \'txFailed\' if the txMeta does not have a hash', function (done) {
|
||||
it('should emit \'tx:failed\' if the txMeta does not have a hash', function (done) {
|
||||
pendingTxTracker.once('tx:failed', (txId, err) => {
|
||||
assert(txId, txMetaNoHash.id, 'should pass txId')
|
||||
done()
|
||||
@ -172,7 +172,7 @@ describe('PendingTransactionTracker', function () {
|
||||
.catch(done)
|
||||
pendingTxTracker.resubmitPendingTxs()
|
||||
})
|
||||
it('should not emit \'txFailed\' if the txMeta throws a known txError', function (done) {
|
||||
it('should not emit \'tx:failed\' if the txMeta throws a known txError', function (done) {
|
||||
knownErrors =[
|
||||
// geth
|
||||
' Replacement transaction Underpriced ',
|
||||
@ -199,8 +199,15 @@ describe('PendingTransactionTracker', function () {
|
||||
|
||||
pendingTxTracker.resubmitPendingTxs()
|
||||
})
|
||||
it('should emit \'txFailed\' if it encountered a real error', function (done) {
|
||||
pendingTxTracker.once('tx:failed', (id, err) => err.message === 'im some real error' ? txList[id - 1].resolve() : done(err))
|
||||
it('should emit \'tx:warning\' if it encountered a real error', function (done) {
|
||||
pendingTxTracker.once('tx:warning', (txMeta, err) => {
|
||||
if (err.message === 'im some real error') {
|
||||
const matchingTx = txList.find(tx => tx.id === txMeta.id)
|
||||
matchingTx.resolve()
|
||||
} else {
|
||||
done(err)
|
||||
}
|
||||
})
|
||||
|
||||
pendingTxTracker.getPendingTransactions = () => txList
|
||||
pendingTxTracker._resubmitTx = async (tx) => { throw new TypeError('im some real error') }
|
||||
|
@ -133,7 +133,7 @@ function recipientField (txParams, transaction, isTx, isMsg) {
|
||||
},
|
||||
}, [
|
||||
message,
|
||||
failIfFailed(transaction),
|
||||
renderErrorOrWarning(transaction),
|
||||
])
|
||||
}
|
||||
|
||||
@ -141,25 +141,35 @@ function formatDate (date) {
|
||||
return vreme.format(new Date(date), 'March 16 2014 14:30')
|
||||
}
|
||||
|
||||
function failIfFailed (transaction) {
|
||||
if (transaction.status === 'rejected') {
|
||||
function renderErrorOrWarning (transaction) {
|
||||
const { status, err, warning } = transaction
|
||||
|
||||
// show rejected
|
||||
if (status === 'rejected') {
|
||||
return h('span.error', ' (Rejected)')
|
||||
}
|
||||
if (transaction.err || transaction.warning) {
|
||||
const { err, warning = {} } = transaction
|
||||
const errFirst = !!(( err && warning ) || err)
|
||||
const message = errFirst ? err.message : warning.message
|
||||
|
||||
errFirst ? err.message : warning.message
|
||||
|
||||
// show error
|
||||
if (err) {
|
||||
const message = err.message || ''
|
||||
return (
|
||||
h(Tooltip, {
|
||||
title: message,
|
||||
position: 'bottom',
|
||||
}, [
|
||||
h(`span.error`, ` (Failed)`),
|
||||
])
|
||||
)
|
||||
}
|
||||
|
||||
// show warning
|
||||
if (warning) {
|
||||
const message = warning.message
|
||||
return h(Tooltip, {
|
||||
title: message,
|
||||
position: 'bottom',
|
||||
}, [
|
||||
h(`span.${errFirst ? 'error' : 'warning'}`,
|
||||
` (${errFirst ? 'Failed' : 'Warning'})`
|
||||
),
|
||||
h(`span.warning`, ` (Warning)`),
|
||||
])
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user