Repository navigation
Commit 76f35ff
release(runway): cherry-pick fix(assets): make mainnet-address warning non-blocking in custom token import (#47983)
- fix(assets): make mainnet-address warning non-blocking in custom token
import cp-13.58.0 (#47928)
## **Description**
Fixes a defect that prevented importing PulseChain (chain id 369 /
`0x171`) ERC-20 tokens through the custom token import form. PulseChain
is a fork of Ethereum Mainnet state, so every Mainnet token contract
exists at the same address on PulseChain — which makes the extension's
mainnet-address check fire for nearly every legitimate token there.
### Problem — Custom token import: blocking "Mainnet token" warning
Entering any address that matches a known Ethereum Mainnet token while
on a non-Mainnet network showed *"This address matches a known Ethereum
Mainnet token address…"* and disabled import entirely. On PulseChain
this fires for nearly every legitimate token.
**Root cause:** the custom token import page (introduced in ef8fed1
/ #42574, replacing the old `ImportTokensModal` deleted in a93e640 /
#43712) treated the mainnet-address match as a blocking error:
`handleAddressChange` early-returned after
`setWarning(t('mainnetToken'))` (also suppressing on-chain autofill),
and `isValid` gated submission on `!warning`. The old modal showed the
same warning but **excluded it from its error gate** (`hasError()`), so
import stayed possible. Stale community PR #31864 had flagged this exact
PulseChain scenario but targets the deleted file.
**Fix:** the warning is now non-blocking and the on-chain lookup
continues, so symbol/decimals autofill from the selected network (on a
fork chain the contract at that address is real and answers correctly).
The warning banner still renders to caution users who are genuinely on
the wrong network. Compared to the old modal (which cleared/hid
symbol+decimals under the warning), autofill gives the user real
on-chain data to review before submitting.
**dApp `wallet_watchAsset` path:** verified working on current builds;
the reported `Unauthorized` was not reproducible (see investigation).
## **Changelog**
CHANGELOG entry: Fixed a bug that blocked custom token imports on chains
that forked Ethereum Mainnet (such as PulseChain) whenever the token
address matched a known Ethereum Mainnet token
## **Related issues**
Fixes:
[ASSETS-4371](https://consensyssoftware.atlassian.net/browse/ASSETS-4371)
(Jira)
## **Manual testing steps**
**Setup:** run a dev/test build, then add PulseChain as a custom network
(RPC `https://rpc.pulsechain.com`, chain id `369`, ticker `PLS`) and
select it. Use a wallet funded on PulseChain, or any wallet — a zero
balance is fine.
**Custom token import path:**
1. On the home screen, open the token list options (⋯) → *Manage tokens*
→ *Add a custom token*.
2. Enter a known Mainnet token address, e.g. DAI
`0x6B175474E89094C44Da98b954EedeAC495271d0F` or USDC
`0xA0b86991C6218b36C1D19D4a2e9EB0cE3606eB48`.
3. Verify the yellow "This address matches a known Ethereum Mainnet
token address…" warning appears.
4. Verify symbol and decimals still autofill from PulseChain (e.g. USDC
→ symbol `USDC`, decimals `6`) and that the import button is
**enabled**.
5. Submit and verify the token appears in the token list on PulseChain.
6. Repeat on Ethereum Mainnet with the same address and verify no
warning shows.
### Automated E2E coverage
New and extended Selenium E2E coverage (local Anvil chain `0x539`, MV3
test build,
[1391a9c](1391a9cf5dd)).
Both specs were run on **two builds**: `origin/main` (fix reverted,
tests kept) and this branch — same spec files, same commands.
| Test | `origin/main` | This branch |
| --- | --- | --- |
| `import-custom-token-mainnet-address.spec.ts` — mainnet warning shown,
import button enabled, token listed | ❌ **Fails**: warning renders, then
`TimeoutError: Waiting for element to be located By(css selector,
[data-testid="custom-token-import-submit-button"]:not([disabled])) —
Wait timed out after 10033ms` (import stays blocked — this is the bug) |
✅ **Passes 3/3**: warning renders, import enabled, token imported and
listed as `100 DAI` |
| `watch-asset-call-add-token.spec.ts` (new mainnet-listed-address case)
— dapp `wallet_watchAsset` approved, token added | ✅ **Passes 2/2** (all
4 cases in the spec green) | ✅ **Passes 3/3** (all 4 cases green) |
Exact commands (identical on both builds; `yarn build:test` rebuilt per
tree):
```sh
yarn test:e2e:single test/e2e/tests/tokens/import-custom-token-mainnet-address.spec.ts --browser=chrome
yarn test:e2e:single test/e2e/tests/tokens/watch-asset-call-add-token.spec.ts --browser=chrome
```
On the `origin/main` run, the branch's spec files were overlaid
unmodified before building (`git checkout origin/main` then `git
checkout fm/assets-4371-pulsechain-tokens -- <spec/helper/page-object
files>`), so main was tested against the exact same tests with only the
product fix absent.
-
**`test/e2e/tests/tokens/import-custom-token-mainnet-address.spec.ts`**
(new): deploys the test ERC-20 with DAI metadata and moves its code +
storage — including the mapping-derived balance entry — to the Mainnet
DAI address with `anvil_setCode`/`anvil_setStorageAt`, so a *real*
contract lives at a `STATIC_MAINNET_TOKEN_LIST` address on a non-Mainnet
network. That is the exact PulseChain situation (a fork chain reusing
Mainnet addresses). Asserts: (a) the mainnet warning is displayed, (b)
the import button is **enabled**, (c) the token (`100 DAI`) is listed
after import.
- Fails on `origin/main`: after the warning renders, the spec times out
waiting for
`[data-testid="custom-token-import-submit-button"]:not([disabled])` —
import stays blocked.
- Passes on this branch: 3/3 local runs.
- **`test/e2e/tests/tokens/watch-asset-call-add-token.spec.ts`** (new
case): the same Mainnet-listed address offered through
`wallet_watchAsset` from the test dapp on the non-Mainnet local chain;
after approval the token is added (`100 DAI`). This case **also passes
on `origin/main`** (2/2 runs) — kept as regression coverage, and it
confirms the mainnet-address check is **not** what breaks the dApp
watchAsset path; the reported dApp failure was not reproducible on
current builds.
- Page-object additions in `custom-token-import-page.ts`
(`enterTokenAddress`, `submitTokenImport`,
`checkMainnetAddressWarningIsDisplayed`, `checkImportButtonIsEnabled`);
the chain setup lives in
`test/e2e/tests/tokens/mainnet-listed-token.helpers.ts`. Each spec was
run 3× locally with no flakes.
## **Screenshots/Recordings**
Before (origin/main) vs. after (this branch) — live runs on real
PulseChain RPC (chain 369) with the DAI Mainnet address
(`0x6B17...1d0F`), a real contract on PulseChain:
| Before (main): Save disabled | 1. Address entered | 2. Warning +
autofill, Save enabled | 3. Added toast | 4. Home token list |
| --- | --- | --- | --- | --- |
| <img
src="https://github.com/user-attachments/assets/8961ba7c-15dc-4af0-8a36-7df0343a67fd"
width="220" alt="origin/main: custom token import on PulseChain with DAI
address, warning shown, Save disabled"> | <img
src="https://github.com/user-attachments/assets/693e9eae-d9e3-48eb-a412-16716b18f66c"
width="220" alt="Custom token import form on PulseChain with the DAI
address typed"> | <img
src="https://github.com/user-attachments/assets/2142cb69-d4dc-4e6c-8d7c-68e92e341fcd"
width="220" alt="Mainnet warning shown plus DAI symbol and 18 decimals
autofilled, Save enabled"> | <img
src="https://github.com/user-attachments/assets/bbb80a15-b11b-4776-a8e4-bcc4c63f25cc"
width="220" alt="Success toast: USDC was successfully added, DAI and
USDC listed on PulseChain"> | <img
src="https://github.com/user-attachments/assets/3fb5bf75-af15-41f9-a522-a3a7254a8a77"
width="220" alt="Home tokens tab on PulseChain listing PLS, DAI, and
USDC"> |
Evidence from the full E2E run on a local MV3 test build (`mm` CLI):
- **Import form**: with the USDC Mainnet address pasted on PulseChain,
the Mainnet-address warning is shown **and** symbol/decimals autofill
from the chain (`USDC` / `6`), with the submit button enabled.
### **Video walkthrough**
https://github.com/user-attachments/assets/a2385674-9d46-4ce8-8ec1-b0f2fadfabae
> 🤖 AI-generated walkthrough — script, animation, and voice made by an
agent
## **Pre-merge author checklist**
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and MetaMask
Extension Coding Standards
- [x] I've completed the PR template to the best of my ability
- [x] I've included tests if applicable
- [x] I've documented my code using JSDoc format if applicable
- [x] I've applied the right labels on the PR (see labeling guidelines).
Not required for external contributors.
## **Adversarial review (adverse)**
The change was reviewed with a three-round multi-perspective adversarial
review loop (auditor / adversary / pragmatist, cross-examination,
deterministic synthesis). Round 1: **SHIP-WITH-CAVEATS** (0 critical · 6
warning · 6 info, 3/3 ship). Round 2: **SHIP-WITH-CAVEATS** (0 critical
· 6 warning · 7 info). Round 3: **SHIP-WITH-CAVEATS** (0 critical · 6
warning · 7 info; 2 conditional + 1 approve). No critical or blocking
findings in any round; rounds 2 and 3 converged on the same trade-off
discussion. **Scope note:** rounds 1–3 reviewed a superset of this diff
that also decoupled the dApp `wallet_watchAsset` persist; that change
was **removed at review**
([2645a3a](2645a3a9c71))
as unproven against the user-reported failure. Findings and dispositions
are kept for the record:
**Addressed in code:**
- *Dropping `!warning` unblocks every future warning, not just the
mainnet one* (consensus, round 1) → applied in rounds 1–3 as a rename to
a dedicated `mainnetWarning` state; **reverted during human review**
([534cdbb](534cdbb50eb))
to keep the diff minimal — the original `warning` state/prop names are
kept and blocking conditions continue to use the error states that still
gate submission.
- *Rejection path's only observable behavior (Sentry) untested*
(consensus, round 1) → `captureException` was mocked and asserted in the
controller test — *change removed at review*
([2645a3a](2645a3a9c71)).
- *Test data mislabeled DAI as symbol 'APE'* (round 1) → the test now
stubs DAI-accurate on-chain metadata, and additionally asserts the
warning clears when the address changes to a non-mainnet token and
reappears for the mainnet one.
- *Failure report lacks context / hard to group* (rounds 2–3) → `{
extra: { assetId, chainId } }` was added so triage could correlate
failures without attaching account or origin identifiers; **reverted
during human review**
([534cdbb](534cdbb50eb))
to shrink the diff, and the whole change was then **removed at review**
([2645a3a](2645a3a9c71)).
**Answered with source evidence (no change needed):**
- *"Asset may be absent from state right after the promise resolves"*
(rounds 2–3, on the removed change) → `AssetsController.addCustomAsset`
persists `customAssets`/`assetsInfo`/zero-balance **synchronously,
before its first `await`** (the account refresh). The persist therefore
completes during the call itself, before `handleWatchAssetRequest`
resolves; the token is in state and renderable at that point. The only
resolve-without-persist path is a synchronous throw before the state
update — pre-validated inputs (`toAssetId` construction, decimals
bounds) make that a narrow unexpected-error window, and it is reported
to Sentry.
- *"Failures leave no local trace / Sentry is consent-gated"* (rounds
2–3, on the removed change) → `shared/lib/sentry` `captureException`
unconditionally `console.error`s the exception locally (the Sentry
*upload* is the consent-gated part), so a service-worker console
breadcrumb always exists.
- *"Stale async address lookup can set the mainnet warning for a
different address"* (round 2) → the handler bumps an `addressLookupRef`
and checks `isLatestLookup()` **after the awaited chain probe and before
every validation branch**, including the mainnet-warning one; stale
lookups return early.
- *"Autofill on fork chains lets attackers spoof trusted mainnet
identities"* (rounds 1–3, repeatedly challenged by co-reviewers) →
autofill metadata comes from the **selected network's contract**, not
the mainnet list; on any custom network a user could already import an
arbitrary contract with a typed symbol, and fiat-value lookups in the
wallet are keyed by chain-scoped asset ids, not bare addresses. The
warning banner still displays.
**Accepted as documented trade-offs / follow-ups:**
- *(removed change)* The fire-and-forget decoupling changed
`wallet_watchAsset`'s resolution semantics from "pipeline finished" to
"approved and persisted; enrichment continues in the background". A
bounded-timeout alternative was considered and rejected: it would add
arbitrary latency to healthy chains and still swallow the failure after
the timeout. EIP-747's boolean result indicates the request was handled
— a dApp cannot rely on balance data being present in any case, since
enrichment timing was always chain-dependent.
- The underlying fragility (no per-request timeout in the custom-network
RPC client; `addCustomAsset` coupling persist with a full account
refresh; no data-source support for chains like 369) was the working
hypothesis behind the removed change; the dApp path was verified working
on current builds and the reported failure was not reproducible.
- The advisory banner's copy (`mainnetToken` message) still reads as
cautionary advice and may deserve a copy pass for the now-advisory
context.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> UI validation tweak on custom token import with unit and E2E coverage;
no auth, payments, or persistence logic changes beyond allowing submit
when only the advisory warning is set.
>
> **Overview**
> On **custom token import**, an address that matches a known Ethereum
Mainnet token on a **non-Mainnet** network (e.g. PulseChain) no longer
blocks submission. The yellow mainnet warning still shows, but
validation continues so symbol/decimals autofill from the selected chain
runs and the import button can stay enabled when other checks pass.
>
> **Product change** in `custom-token-import.tsx`: after setting the
mainnet warning, `handleAddressChange` no longer early-returns, and
`isValid` no longer requires `!warning`.
>
> **Tests**: unit cases for warning on/off-network and enabled submit;
E2E that deploys an ERC-20 at the Mainnet DAI address on a local chain
(fork-style setup), asserts warning + enabled import + listed balance;
page-object helpers; an extra `wallet_watchAsset` E2E case for the same
address pattern.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
382a2a3. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
[ASSETS-4371]:
https://consensyssoftware.atlassian.net/browse/ASSETS-4371?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[9f80e4c](9f80e4c)
[ASSETS-4371]:
https://consensyssoftware.atlassian.net/browse/ASSETS-4371?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
Co-authored-by: Prithpal Sooriya <prithpal.sooriya@gmail.com>1 parent 82cc434 commit 76f35ff
6 files changed
Lines changed: 359 additions & 8 deletions
File tree
- test/e2e
- page-objects/pages/token-management
- tests/tokens
- ui/pages/custom-token-import
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
24 | 27 | | |
25 | 28 | | |
26 | 29 | | |
| |||
35 | 38 | | |
36 | 39 | | |
37 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
38 | 51 | | |
39 | 52 | | |
40 | 53 | | |
41 | 54 | | |
42 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
43 | 66 | | |
44 | 67 | | |
45 | 68 | | |
46 | 69 | | |
47 | 70 | | |
48 | 71 | | |
49 | 72 | | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
56 | 79 | | |
57 | 80 | | |
58 | 81 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 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 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
14 | 21 | | |
15 | 22 | | |
16 | 23 | | |
| |||
138 | 145 | | |
139 | 146 | | |
140 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
141 | 195 | | |
0 commit comments