Commit f5e436e
feat: malicious token screening on transactions (#22688)
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->
## **Description**
<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->
Introduces token screening on incoming tokens received in transactions.
This comes in the form of two different alerts (yellow and red).
## **Changelog**
<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
2. Label with `no-changelog`
If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`
(This helps the Release Engineer do their job more quickly and
accurately)
-->
CHANGELOG entry: Added an alert if an incoming token is malicious or
suspicious.
## **Related issues**
Fixes:
## **Manual testing steps**
```gherkin
Feature: Token screening on incoming tokens in transactions
Scenario: user initiates a transaction where they receive malicious tokens
Given the user is on the `Transaction request` screen
And they are receiving tokens that is flagged as malicious
When user views the screen
Then they will see a red alert on `You receive`
And a red `Review alert` button
Scenario: user initiates a transaction where they receive suspicious tokens
Given the user is on the `Transaction request` screen
And they are receiving tokens that is flagged as suspicious
When user views the screen
Then they will see a yellow alert on `You receive`
```
- For a malicious token, you can swap for
`0x69e8b9528cabda89fe846c67675b5d73d463a916` on a swap website.
- For a suspicious token, you can swap for
`0xd0cd466b34a24fcb2f87676278af2005ca8a78c4` on a swap website.
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
**1. No yellow alert**
<img width="402" height="853" alt="Screenshot 2025-11-18 at 12 00 50 PM"
src="https://github.com/user-attachments/assets/c176193c-26ff-44eb-9b10-160381da3356"
/>
**2. No red alert**
<img width="398" height="843" alt="Screenshot 2025-11-18 at 12 01 34 PM"
src="https://github.com/user-attachments/assets/148f9c4e-6f5c-4d79-b0d2-11932c39dbfb"
/>
### **After**
<!-- [screenshots/recordings] -->
**1. Yellow alert**
<img width="386" height="841" alt="Screenshot 2025-11-18 at 11 41 51 AM"
src="https://github.com/user-attachments/assets/4028a106-357a-42fd-a7e9-2b60301b1185"
/>
**2. Red alert**
<img width="383" height="618" alt="Screenshot 2025-11-19 at 9 15 25 AM"
src="https://github.com/user-attachments/assets/01e04dfe-5abc-42fa-84f6-dca1bf05477c"
/>
**When you click the inline alert**
<img width="403" height="667" alt="Screenshot 2025-11-19 at 9 15 40 AM"
src="https://github.com/user-attachments/assets/1ddeed60-64e7-4c2e-8305-3fecca11e715"
/>
**When you click the 'Review alert' button**
<img width="389" height="641" alt="Screenshot 2025-11-19 at 9 17 41 AM"
src="https://github.com/user-attachments/assets/9c305ec1-534e-49a6-bc8c-6ea39a4d28cc"
/>
## **Pre-merge author checklist**
- [ ] I’ve followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **Pre-merge reviewer checklist**
- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Adds malicious/suspicious token screening to transaction confirmations
with inline alerts, selectors, strings, and tests.
>
> - **Confirmations UI/UX**:
> - Show `AlertRow` on `BalanceChangeRow` label when `hasIncomingTokens`
is true, with style override in `alert-row.styles`.
> - Compute `hasIncomingTokens` in `BalanceChangeList` and pass to rows.
> - **Alerts System**:
> - New `useTokenTrustSignalAlerts` hook to derive alerts from token
scan results; integrated into `useConfirmationAlerts`.
> - Added `RowAlertKey.IncomingTokens` and new alert keys
`TokenTrustSignalMalicious`/`TokenTrustSignalWarning` with metrics
mappings.
> - **State Selectors**:
> - New `selectMultipleTokenScanResults` to read
`PhishingController.tokenScanCache` for multiple tokens.
> - **Localization**:
> - English strings for malicious/suspicious token alerts.
> - **Dependencies**:
> - Upgrade `@metamask/phishing-controller` to `^16.1.0`.
> - **Tests**:
> - Unit tests for `BalanceChangeRow`, `AlertRow`,
`useTokenTrustSignalAlerts`, `useConfirmationAlerts`, and phishing
selectors.
> - **Test fixtures**:
> - Update initial background state to include `addressScanCache` and
`tokenScanCache`.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
ff7ae25. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: sethkfman <setk.kaufman@consensys.net>1 parent df8533b commit f5e436e
File tree
19 files changed
+786
-17
lines changed- app
- components
- UI/SimulationDetails
- BalanceChangeList
- BalanceChangeRow
- Views/confirmations
- components/UI/info-row/alert-row
- constants
- hooks
- alerts
- metrics
- selectors
- util/test
- locales/languages
19 files changed
+786
-17
lines changedLines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
31 | 38 | | |
32 | 39 | | |
33 | 40 | | |
| |||
45 | 52 | | |
46 | 53 | | |
47 | 54 | | |
| 55 | + | |
48 | 56 | | |
49 | 57 | | |
50 | 58 | | |
| |||
Lines changed: 37 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
83 | 120 | | |
Lines changed: 32 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
| |||
24 | 27 | | |
25 | 28 | | |
26 | 29 | | |
| 30 | + | |
27 | 31 | | |
28 | 32 | | |
29 | 33 | | |
| |||
32 | 36 | | |
33 | 37 | | |
34 | 38 | | |
| 39 | + | |
35 | 40 | | |
36 | 41 | | |
| 42 | + | |
37 | 43 | | |
38 | 44 | | |
39 | 45 | | |
40 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
41 | 72 | | |
42 | 73 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
| 74 | + | |
52 | 75 | | |
53 | 76 | | |
54 | 77 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
9 | 13 | | |
10 | 14 | | |
11 | 15 | | |
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
135 | 136 | | |
136 | 137 | | |
137 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
138 | 154 | | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
16 | 18 | | |
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| 33 | + | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
| |||
133 | 135 | | |
134 | 136 | | |
135 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
136 | 147 | | |
137 | 148 | | |
138 | 149 | | |
| |||
146 | 157 | | |
147 | 158 | | |
148 | 159 | | |
| 160 | + | |
149 | 161 | | |
150 | 162 | | |
151 | 163 | | |
| |||
211 | 223 | | |
212 | 224 | | |
213 | 225 | | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
214 | 229 | | |
215 | 230 | | |
216 | 231 | | |
| |||
225 | 240 | | |
226 | 241 | | |
227 | 242 | | |
| 243 | + | |
228 | 244 | | |
229 | 245 | | |
230 | 246 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| |||
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
| 44 | + | |
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
| |||
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
| 55 | + | |
52 | 56 | | |
53 | 57 | | |
54 | 58 | | |
| |||
0 commit comments