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

Simplify logic in PTT helper fns (#8430)

This commit is contained in:
Whymarrh Whitby 2020-04-27 18:38:16 -02:30 committed by GitHub
parent 65ad3ba9e6
commit 306f04be8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -220,13 +220,7 @@ export default class PendingTransactionTracker extends EventEmitter {
async _checkIfTxWasDropped (txMeta, transactionReceipt) { async _checkIfTxWasDropped (txMeta, transactionReceipt) {
const { txParams: { nonce, from } } = txMeta const { txParams: { nonce, from } } = txMeta
const nextNonce = await this.query.getTransactionCount(from) const nextNonce = await this.query.getTransactionCount(from)
if ( return !transactionReceipt?.blockNumber && parseInt(nextNonce) > parseInt(nonce)
!transactionReceipt?.blockNumber &&
parseInt(nextNonce) > parseInt(nonce)
) {
return true
}
return false
} }
/** /**
@ -238,12 +232,11 @@ export default class PendingTransactionTracker extends EventEmitter {
async _checkIfNonceIsTaken (txMeta) { async _checkIfNonceIsTaken (txMeta) {
const address = txMeta.txParams.from const address = txMeta.txParams.from
const completed = this.getCompletedTransactions(address) const completed = this.getCompletedTransactions(address)
const sameNonce = completed.filter((otherMeta) => { return completed.some((other) =>
if (otherMeta.id === txMeta.id) { // This is called while the transaction is in-flight, so it is possible that the
return false // list of completed transactions now includes the transaction we were looking at
} // and if that is the case, don't consider the transaction to have taken its own nonce
return otherMeta.txParams.nonce === txMeta.txParams.nonce !(other.id === txMeta.id) && other.txParams.nonce === txMeta.txParams.nonce
}) )
return sameNonce.length > 0
} }
} }