-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix: fix duplicated account api calls #23864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsThese changes are HIGH RISK because they modify critical Engine infrastructure and controller behavior:
These changes affect:
The changes touch core wallet functionality (token balances, detection), multi-chain behavior (network-specific price support), account management (keyring events), and asset management. Testing should cover assets, wallet core, swaps/trade (which depend on balances), account functionality, network handling, and staking (which shows balances). |
## Explanation Extension UI: MetaMask/metamask-extension#38708 Mobile UI: MetaMask/metamask-mobile#23864 Acceptance Criteria • Replace all Account API v2 calls with Account API v4 for token auto-detection. • Continue using RPC-based detection for chains not supported by Account API v4. • If Account API v4 requests fail, fallback to RPC-based token detection. • If Account API v4 returns any unprocessed networks, fallback to RPC detection for those networks as well. <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> ## Checklist - [ ] I've updated the test suite for new or updated code as appropriate - [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [ ] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs) - [ ] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Replaces token auto-detection via Accounts API v2 with v4, delegating supported chains to TokenBalancesController, adding RPC fallbacks/new actions, and improving polling, lock handling, and tests. > > - **Breaking/Behavioral Changes** > - Replace Accounts API v2 with v4 for token auto-detection; RPC-based detection remains for unsupported chains. > - `TokenDetectionController.detectTokens()` adds `forceRpc` and is exposed via `TokenDetectionController:detectTokens`. > - **TokenDetectionController** > - Skips Accounts API–supported chains (handled by balances), performs RPC detection otherwise. > - Adds `addDetectedTokensViaPolling` and enhances `addDetectedTokensViaWs`; respects prefs/external services; metrics tracking. > - Subscribes to tx confirmed events; refactors polling restart and state helpers; minor type/utility cleanups. > - **TokenBalancesController** > - On Accounts API failure or unprocessed chains, calls `TokenDetectionController:detectTokens` with `forceRpc: true`. > - Imports untracked tokens via `TokenDetectionController:addDetectedTokensViaPolling`. > - Adds keyring lock/unlock gating (`isActive`), transaction events handling, per-chain polling grouping/updates, token address filtering, and robust state normalization. > - **Accounts API Fetcher** > - Supports v4 response shapes: handles CAIP `unprocessedNetworks`, maps to hex; maintains timeout/batching; staked balances handling. > - **Exports & Docs** > - Update `index.ts` exports for new actions; changelog documents breaking changes and new flows. > - **Tests** > - Extensive new/updated tests covering RPC fallback, polling behavior, event handling, lock state, and edge cases. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 10463da. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
Description
Changelog
CHANGELOG entry:
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist