MetaMask / MetaMask/metamask-mobile
[Bug]: wallet_watchAsset validates against the wallet's global network instead of the dapp-selected network; after approval token does not appear in the token list
- Dominant language
- TypeScript
- Stars
- 3k
- Forks
- 1.7k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 669
Description
### Describe the bug
Hi,
There are 2 issues in the mobile wallet (tested on android latest release) :
1) Wallet's global network doesn't change when requested by Dapp in inbuilt web browser, for example using `wallet_switchEthereumChain` to switch chain to BSC shows success, the transactions etc go through as expected through BSC but the overall wallet network still remains Ethereum (or other which was before present before opening the Dapp)
This results in error `This token is not supported on this network` , when using `wallet_watchAsset` when adding a token on BSC, switching the network manually allows to add the token.
2) When using `wallet_watchAsset` through a Dapp to add a token, for example USDT on BSC, it prompts to approve adding, shows success, but never adds the token and user is unable to view.
### Expected behavior
_No response_
### Screenshots/Recordings
_No response_
### Steps to reproduce
1) Open the wallet explore section, make sure its set to Ethereum
2) Visit a webpage with the following code or simillar
```
async function addUsdtOnBsc() {
const eth = window.ethereum;
// 1. switch wallet to BSC
try {
await eth.request({
method: "wallet_switchEthereumChain",
params: [{ chainId: "0x38" }],
});
} catch (e) {
if (e.code === 4902) {
await eth.request({
method: "wallet_addEthereumChain",
params: [{
chainId: "0x38",
chainName: "BNB Smart Chain",
nativeCurrency: { name: "BNB", symbol: "BNB", decimals: 18 },
rpcUrls: ["https://bsc-dataseed.binance.org/"],
blockExplorerUrls: ["https://bscscan.com/"],
}],
});
} else throw e;
}
// 2. add USDT
const added = await eth.request({
method: "wallet_watchAsset",
params: {
type: "ERC20",
options: {
address: "0x55d398326f99059fF775485246999027B3197955",
symbol: "USDT",
decimals: 18,
},
},
});
alert("watchAsset returned: " + added);
}
Add USDT on BSC```
3) This will first throw the `This token is not supported on this network`
4) Switch to BSC in global, do this by clicking on the square wallet connected icon on top right, then clicking the site favicon icon it shows with bsc symbol, then change chain to BSC (would have ETH as selected)
5) Click on Add USDT again, the token will show up added but wont be found in token list
### Error messages or log output
```shell
```
### Where was this bug found?
Live version (from official store)
### Version
v8.3.0
### Build number
6134
### Build type
None
### Device
Samsung
### Operating system
Android
### Additional context
_No response_
### Severity
_No response_
Contributor guide
Research direction
Start by tracing the mobile dapp browser handling for wallet_switchEthereumChain, wallet_addEthereumChain, and wallet_watchAsset, then follow how the selected network reaches token validation and the token list. Reproduce the BSC USDT flow from the steps above; done means the selected dapp network is used, approval succeeds, and the token appears in the BSC token list.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react-native, typescript
- Domain
- api, blockchain, mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100