-
-
Notifications
You must be signed in to change notification settings - Fork 295
fix: guard ws by feature flag #9647
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,16 +8,14 @@ import type { | |
| BalanceUpdate, | ||
| } from '@metamask/core-backend'; | ||
| import type { ApiPlatformClient } from '@metamask/core-backend'; | ||
| import { | ||
| isCaipChainId, | ||
| KnownCaipNamespace, | ||
| toCaipChainId, | ||
| } from '@metamask/utils'; | ||
| import type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller'; | ||
|
|
||
| import type { AssetsControllerMessenger } from '../AssetsController.js'; | ||
| import { projectLogger, createModuleLogger } from '../logger.js'; | ||
| import type { ChainId, Caip19AssetId, DataResponse } from '../types.js'; | ||
| import { decimalToChainId } from '../utils/caip.js'; | ||
| import { processAccountActivityBalanceUpdates } from '../utils/processAccountActivityBalanceUpdates.js'; | ||
| import { shouldSupportChain } from '../utils/snaps-assets-migration.js'; | ||
| import { AbstractDataSource } from './AbstractDataSource.js'; | ||
| import type { | ||
| DataSourceState, | ||
|
|
@@ -39,7 +37,8 @@ const log = createModuleLogger(projectLogger, CONTROLLER_NAME); | |
|
|
||
| // Allowed actions that BackendWebsocketDataSource can call | ||
| export type BackendWebsocketDataSourceAllowedActions = | ||
| BackendWebSocketServiceActions; | ||
| | BackendWebSocketServiceActions | ||
| | RemoteFeatureFlagControllerGetStateAction; | ||
|
|
||
| // Allowed events that BackendWebsocketDataSource can subscribe to | ||
| export type BackendWebsocketDataSourceAllowedEvents = | ||
|
|
@@ -190,25 +189,6 @@ function haveAddressesChanged( | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Normalize API chain identifier to CAIP-2 ChainId. | ||
| * Passes through strings already in CAIP-2 form (e.g. eip155:1, solana:5eykt...). | ||
| * Converts bare decimals to eip155:decimal. | ||
| * Uses @metamask/utils for CAIP parsing. | ||
| * | ||
| * @param chainIdOrDecimal - Chain ID string (CAIP-2 or decimal) or decimal number. | ||
| * @returns CAIP-2 ChainId. | ||
| */ | ||
| function toChainId(chainIdOrDecimal: number | string): ChainId { | ||
| if (typeof chainIdOrDecimal === 'string') { | ||
| if (isCaipChainId(chainIdOrDecimal)) { | ||
| return chainIdOrDecimal; | ||
| } | ||
| return toCaipChainId(KnownCaipNamespace.Eip155, chainIdOrDecimal); | ||
| } | ||
| return toCaipChainId(KnownCaipNamespace.Eip155, String(chainIdOrDecimal)); | ||
| } | ||
|
|
||
| // Note: AccountActivityMessage and BalanceUpdate types are imported from @metamask/core-backend | ||
|
|
||
| // ============================================================================ | ||
|
|
@@ -242,6 +222,7 @@ function toChainId(chainIdOrDecimal: number | string): ChainId { | |
| * - BackendWebSocketService:findSubscriptionsByChannelPrefix | ||
| * - BackendWebSocketService:addChannelCallback | ||
| * - BackendWebSocketService:removeChannelCallback | ||
| * - RemoteFeatureFlagController:getState | ||
| */ | ||
| const DEFAULT_CHAINS_REFRESH_INTERVAL_MS = 20 * 60 * 1000; // 20 minutes | ||
|
|
||
|
|
@@ -371,7 +352,17 @@ export class BackendWebsocketDataSource extends AbstractDataSource< | |
|
|
||
| async #fetchActiveChains(): Promise<ChainId[]> { | ||
| const response = await this.#apiClient.accounts.fetchV2SupportedNetworks(); | ||
| return response.fullSupport.map(toChainId); | ||
| // 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 | ||
| // ReadAssetsControllerWithFallback. | ||
| const { remoteFeatureFlags } = this.#messenger.call( | ||
| 'RemoteFeatureFlagController:getState', | ||
| ); | ||
| return response.fullSupport | ||
| .map(decimalToChainId) | ||
|
Comment on lines
+360
to
+364
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is the same for accounts API |
||
| .filter((chainId) => shouldSupportChain(chainId, remoteFeatureFlags)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WebSocket ignores live flag changesMedium Severity
Additional Locations (1)Reviewed by Cursor Bugbot for commit 5baa62b. Configure here. |
||
| } | ||
|
|
||
| #subscribeToEvents(): void { | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.