Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/assets-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -367,17 +400,17 @@ export class AccountsApiDataSource extends AbstractDataSource<
async #fetchActiveChains(): Promise<ChainId[]> {
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),
);
}

// ============================================================================
Expand Down