-
-
Notifications
You must be signed in to change notification settings - Fork 242
fix: preserve transaction type of batched transactions #6056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
expect(publishBatchHook.mock.calls[0][0].transactions[0].type).toBe( | ||
TransactionType.swap, | ||
); | ||
expect(publishBatchHook.mock.calls[0][0].transactions[1].type).toBe( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than asserting the hook is called with the type, ideally the hook wouldn't know, and instead we could verify that addTransaction
is called multiple times with the correct types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call - I updated the test to do this! I also removed the type
key from the PublishBatchHookTransaction
type, which I added for this test.
@@ -837,6 +932,50 @@ describe('Batch Utils', () => { | |||
PUBLISH_BATCH_HOOK_PARAMS, | |||
); | |||
}); | |||
// const publishBatchHook: jest.MockedFn<PublishBatchHook> = jest.fn(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accident?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure how this happened - will update
@@ -606,6 +607,7 @@ async function processTransactionWithHook( | |||
networkClientId, | |||
publishHook, | |||
requireApproval: false, | |||
type, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @micaelae , I was debugging the metric issues due to swaps and bridge transaction events and origin
was also not preserving to the individual batched transactions. If you don't mind we could add origin
here too. Otherwise source will be dapp
in metrics which is incorrect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the age of this PR, are we okay to do that in a separate PR @OGPoyraz ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR was merged before I could add this. Can you open a new PR for this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good, we will do it in a separate fix!
@@ -606,6 +607,7 @@ async function processTransactionWithHook( | |||
networkClientId, | |||
publishHook, | |||
requireApproval: false, | |||
type, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On another note if we are correctly preserving the type with this fix now - do we want to remove this temporary type update from bridge-status-controller
? https://github.com/MetaMask/core/blob/main/packages/bridge-status-controller/src/utils/transaction.ts#L355
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! I have a draft for removing this, will just need to re-test once this version is published
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Inconsistent Transaction Type Handling
The processTransactionWithHook
function has two issues concerning the type
field:
- It inconsistently returns the
type
field: it's included for new transactions but omitted for existing ones, leading to inconsistent object shapes. - Additionally, when the
type
field is returned, it creates a type mismatch with thehookTransactions
array, which expectsPublishBatchHookTransaction
(a type intentionally designed to omit thetype
field).
packages/transaction-controller/src/utils/batch.ts#L564-L584
core/packages/transaction-controller/src/utils/batch.ts
Lines 564 to 584 in eede76b
if (existingTransaction) { | |
const { id, onPublish, signedTransaction } = existingTransaction; | |
const transactionMeta = getTransaction(id); | |
updateTransaction({ transactionId: id }, (_transactionMeta) => { | |
_transactionMeta.batchId = batchId; | |
}); | |
publishHook(transactionMeta, signedTransaction) | |
.then(onPublish) | |
.catch(() => { | |
// Intentionally empty | |
}); | |
log('Processed existing transaction with hook', { | |
id, | |
params, | |
}); | |
return { |
packages/transaction-controller/src/utils/batch.ts#L636-L641
core/packages/transaction-controller/src/utils/batch.ts
Lines 636 to 641 in eede76b
return { | |
id, | |
params: newParams, | |
type, | |
}; |
Was this report helpful? Give feedback by reacting with 👍 or 👎
Explanation
When a batch of transactions with specific TransactionType values is submitted (example: bridgeApproval, swap, bridge), the txs get published with generic types like
contractInteraction
andapprove
, and the requested types are not preservedThe
type
values are needed in the swaps and bridge experiences in order to track and display accurate transaction statuses so they need to be propagatedReferences
Changelog
Checklist