Fix use effective recipient for first-time interaction check on token transfers#8130
Merged
vinistevam merged 16 commits intomainfrom Mar 10, 2026
Merged
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. |
jpuri
previously approved these changes
Mar 9, 2026
OGPoyraz
reviewed
Mar 10, 2026
| tx.txParams.to?.toLowerCase() === to?.toLowerCase() && | ||
| tx.id !== transactionId, | ||
| tx.txParams?.from?.toLowerCase() === from?.toLowerCase() && | ||
| getEffectiveRecipient(tx)?.toLowerCase() === recipientLower, |
Comment on lines
84
to
92
Member
There was a problem hiding this comment.
Shall we use new getEffectiveRecipient utility to prevent duplication?
recipient = getEffectiveRecipient(transactionMeta);
Contributor
Author
There was a problem hiding this comment.
Great catch! I pushed the changes here 80b82cc
OGPoyraz
previously approved these changes
Mar 10, 2026
OGPoyraz
approved these changes
Mar 10, 2026
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
Fixes MetaMask/metamask-mobile#26319
Checklist
Note
Medium Risk
Changes how
updateFirstTimeInteractiondecides to skip the accounts-API call by decoding token-transfer recipients; this affects when first-time-interaction warnings are set and may increase API calls for token transfers if decoding differs or fails.Overview
Fixes first-time interaction detection for token transfers by comparing effective recipients (decoded from
txParams.data) rather thantxParams.towhen deciding whether an existing transaction already covers the interaction.Adds
getEffectiveRecipientand updates the existing-transaction short-circuit to match onchainId+from+ decoded recipient, plus new tests covering ERC20 same-contract/different-recipient vs same-recipient behavior; changelog updated.Written by Cursor Bugbot for commit 9117a7e. This will update automatically on new commits. Configure here.