Merge pull request #1757 from MetaMask/resubmit-fix

Resubmit fix
feature/default_network_editable
Frankie 8 years ago committed by GitHub
commit 2d1b7c0ee1
  1. 17
      app/scripts/controllers/transactions.js
  2. 41
      app/scripts/migrations/016.js
  3. 1
      app/scripts/migrations/index.js

@ -417,23 +417,28 @@ module.exports = class TransactionController extends EventEmitter {
// only try resubmitting if their are transactions to resubmit // only try resubmitting if their are transactions to resubmit
if (!pending.length) return if (!pending.length) return
const resubmit = denodeify(this._resubmitTx.bind(this)) const resubmit = denodeify(this._resubmitTx.bind(this))
pending.forEach((txMeta) => resubmit(txMeta) pending.forEach((txMeta) => resubmit(txMeta).catch((err) => {
.catch((reason) => {
/* /*
Dont marked as failed if the error is a "known" transaction warning Dont marked as failed if the error is a "known" transaction warning
"there is already a transaction with the same sender-nonce "there is already a transaction with the same sender-nonce
but higher/same gas price" but higher/same gas price"
*/ */
const errorMessage = reason.message.toLowerCase() const errorMessage = err.message.toLowerCase()
const isKnownTx = ( const isKnownTx = (
// geth // geth
errorMessage === 'replacement transaction underpriced' errorMessage === 'replacement transaction underpriced'
|| errorMessage.startsWith('known transaction') || errorMessage.startsWith('known transaction')
// parity // parity
|| errorMessage === 'gas price too low to replace' || errorMessage === 'gas price too low to replace'
|| errorMessage === 'transaction with the same hash was already imported.'
) )
// ignore resubmit warnings, return early // ignore resubmit warnings, return early
if (!isKnownTx) this.setTxStatusFailed(txMeta.id, reason.message) if (isKnownTx) return
// encountered real error - transition to error state
this.setTxStatusFailed(txMeta.id, {
errCode: err.errCode || err,
message: err.message,
})
})) }))
} }
@ -448,7 +453,7 @@ module.exports = class TransactionController extends EventEmitter {
// if the value of the transaction is greater then the balance, fail. // if the value of the transaction is greater then the balance, fail.
if (gtBalance) { if (gtBalance) {
const message = 'Insufficient balance.' const message = 'Insufficient balance.'
this.setTxStatusFailed(txMeta.id, message) this.setTxStatusFailed(txMeta.id, { message })
cb() cb()
return log.error(message) return log.error(message)
} }
@ -456,7 +461,7 @@ module.exports = class TransactionController extends EventEmitter {
// if the nonce of the transaction is lower then the accounts nonce, fail. // if the nonce of the transaction is lower then the accounts nonce, fail.
if (txNonce < nonce) { if (txNonce < nonce) {
const message = 'Invalid nonce.' const message = 'Invalid nonce.'
this.setTxStatusFailed(txMeta.id, message) this.setTxStatusFailed(txMeta.id, { message })
cb() cb()
return log.error(message) return log.error(message)
} }

@ -0,0 +1,41 @@
const version = 16
/*
This migration sets transactions with the 'Gave up submitting tx.' err message
to a 'failed' stated
*/
const clone = require('clone')
module.exports = {
version,
migrate: function (originalVersionedData) {
const versionedData = clone(originalVersionedData)
versionedData.meta.version = version
try {
const state = versionedData.data
const newState = transformState(state)
versionedData.data = newState
} catch (err) {
console.warn(`MetaMask Migration #${version}` + err.stack)
}
return Promise.resolve(versionedData)
},
}
function transformState (state) {
const newState = state
const transactions = newState.TransactionController.transactions
newState.TransactionController.transactions = transactions.map((txMeta) => {
if (!txMeta.err) return txMeta
if (txMeta.err === 'transaction with the same hash was already imported.') {
txMeta.status = 'submitted'
delete txMeta.err
}
return txMeta
})
return newState
}

@ -26,4 +26,5 @@ module.exports = [
require('./013'), require('./013'),
require('./014'), require('./014'),
require('./015'), require('./015'),
require('./016'),
] ]

Loading…
Cancel
Save