diff --git a/packages/assets-controller/CHANGELOG.md b/packages/assets-controller/CHANGELOG.md index 81d4df26300..29d8ae7c06f 100644 --- a/packages/assets-controller/CHANGELOG.md +++ b/packages/assets-controller/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- `AccountsApiDataSource` now treats Accounts API `/v2/supportedNetworks` `partialSupport.balances` as active chains in addition to `fullSupport`, still gated by the Snaps assets migration feature flags ([#10144](https://github.com/MetaMask/core/pull/10144)) + ## [15.1.0] ### Changed diff --git a/packages/assets-controller/src/data-sources/AccountsApiDataSource.ts b/packages/assets-controller/src/data-sources/AccountsApiDataSource.ts index 31e55cdfa72..8fa0dcf82c5 100644 --- a/packages/assets-controller/src/data-sources/AccountsApiDataSource.ts +++ b/packages/assets-controller/src/data-sources/AccountsApiDataSource.ts @@ -124,6 +124,39 @@ function decimalToChainId(decimalChainId: number | string): ChainId { return toCaipChainId(KnownCaipNamespace.Eip155, String(decimalChainId)); } +/** + * Collect chain ids from Accounts API `/v2/supportedNetworks`. + * + * `fullSupport` is the primary list. `partialSupport.balances` is included so + * networks that are not yet promoted to full support (e.g. Tron) can still be + * claimed by this data source on current clients. A raw array `partialSupport` + * (legacy / unused v2 mock shape) is ignored — only `{ balances }` is read. + * + * @param response - The v2 supported-networks payload. + * @param response.fullSupport - Fully supported chain ids (decimals or CAIP-2). + * @param response.partialSupport - Partial support object or legacy array; only `{ balances }` is read. + * @returns Unique normalized chain ids, `fullSupport` first then `partialSupport.balances`. + */ +function collectSupportedNetworkIds(response: { + fullSupport?: (number | string)[]; + partialSupport?: { balances?: (number | string)[] } | (number | string)[]; +}): ChainId[] { + const fullSupport = response.fullSupport ?? []; + const { partialSupport } = response; + const partialBalances = + partialSupport && !Array.isArray(partialSupport) + ? (partialSupport.balances ?? []) + : []; + + return [ + ...new Set( + [...fullSupport, ...partialBalances].map((rawChainId) => + decimalToChainId(rawChainId), + ), + ), + ]; +} + /** * Convert a CAIP-2 chain ID from the API response to our ChainId type. * Handles both formats: "eip155:1" or just "1" (decimal). @@ -367,17 +400,17 @@ export class AccountsApiDataSource extends AbstractDataSource< async #fetchActiveChains(): Promise { const response = await this.#apiClient.accounts.fetchV2SupportedNetworks(); - // Use fullSupport networks as active chains, gated by the Snaps → - // AssetsController migration FF: non-migration namespaces (e.g. `eip155`) - // are always surfaced, while migration networks (Solana, Stellar, Tron) are - // only surfaced once their per-network stage reaches + // Use fullSupport and partialSupport.balances as active chains, gated by + // the Snaps → AssetsController migration FF: non-migration namespaces + // (e.g. `eip155`) are always surfaced, while migration networks (Solana, + // Stellar, Tron) are only surfaced once their per-network stage reaches // ReadAssetsControllerWithFallback. const { remoteFeatureFlags } = this.#messenger.call( 'RemoteFeatureFlagController:getState', ); - return response.fullSupport - .map(decimalToChainId) - .filter((chainId) => shouldSupportChain(chainId, remoteFeatureFlags)); + return collectSupportedNetworkIds(response).filter((chainId) => + shouldSupportChain(chainId, remoteFeatureFlags), + ); } // ============================================================================