mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +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:
parent
4a59fb432f
commit
724bd42e2c
@ -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)
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user