1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00

Ensures the tx controller + state-manager orders transactions as received (#7484)

* Ensures the tx controller + tx-state-manager orders transactions in the order they are received

* Handle transaction ordering in cases where tx ids are off by more than 1 in tx-state-manager

* Add comment to addUnapprovedTransaction explaining calling _determineTransactionCategory after generateTxMeta

* Sort txes by timestamp of creation instead of id
This commit is contained in:
Dan J Miller 2019-11-27 09:28:03 -03:30 committed by GitHub
parent 4a59fb432f
commit 724bd42e2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View File

@ -192,13 +192,18 @@ class TransactionController extends EventEmitter {
throw new Error(`Transaction from address isn't valid for this account`)
}
txUtils.validateTxParams(normalizedTxParams)
// construct txMeta
const { transactionCategory, getCodeResponse } = await this._determineTransactionCategory(txParams)
/**
`generateTxMeta` adds the default txMeta properties to the passed object.
These include the tx's `id`. As we use the id for determining order of
txes in the tx-state-manager, it is necessary to call the asynchronous
method `this._determineTransactionCategory` after `generateTxMeta`.
*/
let txMeta = this.txStateManager.generateTxMeta({
txParams: normalizedTxParams,
type: TRANSACTION_TYPE_STANDARD,
transactionCategory,
})
const { transactionCategory, getCodeResponse } = await this._determineTransactionCategory(txParams)
txMeta.transactionCategory = transactionCategory
this.addTx(txMeta)
this.emit('newUnapprovedTx', txMeta)

View File

@ -167,7 +167,12 @@ class TransactionStateManager extends EventEmitter {
transactions.splice(index, 1)
}
}
transactions.push(txMeta)
const newTxIndex = transactions
.findIndex((currentTxMeta) => currentTxMeta.time > txMeta.time)
newTxIndex === -1
? transactions.push(txMeta)
: transactions.splice(newTxIndex, 0, txMeta)
this._saveTxList(transactions)
return txMeta
}