Fix use effective recipient for first-time interaction check on token transfers#8130
Open
vinistevam wants to merge 13 commits intomainfrom
Open
Fix use effective recipient for first-time interaction check on token transfers#8130vinistevam wants to merge 13 commits intomainfrom
vinistevam wants to merge 13 commits intomainfrom
Conversation
Contributor
Author
|
@metamaskbot publish-previews |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Contributor
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
Fixes the first-time interaction logic so the "first time interaction" alert correctly triggers when sending ERC20/ERC721 tokens to a new address. Previously, the alert could be skipped if the user had ever sent the same token to any other address, because the existing-transaction check compared
txParams.to(the token contract for ERC20) instead of the actual recipient.Problem
txParams.tois the token contract, not the recipient.txParams.tofor both the current and existing transactions.isFirstTimeInteractionwas skipped, so the alert never showed for a new recipient.Solution
getEffectiveRecipient(tx): for token transfer types, decodetxParams.dataand use the_to/toargument as the effective recipient; otherwise usetxParams.to.txParams.to.Changes
first-time-interaction.ts: AddedTOKEN_TRANSFER_TYPESandgetEffectiveRecipient(), and updated theexistingTransactions.find()to use effective recipient for comparison.first-time-interaction.test.ts: Added tests for (1) proceeding when existing tx has same contract but different decoded recipient, and (2) returning early when existing tx has same effective recipient.References
Checklist
Note
Medium Risk
Touches the first-time-interaction warning logic for token transfers; incorrect recipient decoding or comparison could cause the alert to be shown/hidden unexpectedly for some transfer shapes.
Overview
Fixes first-time interaction detection for token transfers. The existing-transaction short-circuit now compares transactions by effective recipient (decoded from
txParams.datafortokenMethodTransfer/tokenMethodTransferFrom) instead oftxParams.to, preventing prior sends of the same token contract from suppressing checks for new recipients.Adds
getEffectiveRecipient/TOKEN_TRANSFER_TYPES, updates matching to be case-insensitive and tolerant of missingtxParams, and extends tests to cover same-contract/different-recipient vs same-recipient scenarios. Updates thetransaction-controllerchangelog under Fixed.Written by Cursor Bugbot for commit 866997c. This will update automatically on new commits. Configure here.