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) {
const { txParams: { nonce, from } } = txMeta
const nextNonce = await this.query.getTransactionCount(from)
if (
!transactionReceipt?.blockNumber &&
parseInt(nextNonce) > parseInt(nonce)
) {
return true
}
return false
return !transactionReceipt?.blockNumber && parseInt(nextNonce) > parseInt(nonce)
}
/**
@ -238,12 +232,11 @@ export default class PendingTransactionTracker extends EventEmitter {
async _checkIfNonceIsTaken (txMeta) {
const address = txMeta.txParams.from
const completed = this.getCompletedTransactions(address)
const sameNonce = completed.filter((otherMeta) => {
if (otherMeta.id === txMeta.id) {
return false
}
return otherMeta.txParams.nonce === txMeta.txParams.nonce
})
return sameNonce.length > 0
return completed.some((other) =>
// This is called while the transaction is in-flight, so it is possible that the
// 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
!(other.id === txMeta.id) && other.txParams.nonce === txMeta.txParams.nonce
)
}
}