@metamask/smart-transactions-controller
Advanced tools
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.getSmartTransactionsFeatureFlagsForChain = exports.getSmartTransactionsFeatureFlags = exports.processSmartTransactionsFeatureFlags = exports.normalizeChainId = void 0; | ||
| const utils_1 = require("@metamask/utils"); | ||
| const constants_1 = require("../constants.cjs"); | ||
| const validators_1 = require("./validators.cjs"); | ||
| /** | ||
| * Normalizes a chain ID to hex format for EVM chains. | ||
| * - CAIP-2 EVM format (eip155:X) is converted to hex (0xY) | ||
| * - Hex format is returned as-is | ||
| * - Non-EVM CAIP-2 formats are returned as-is (exact match) | ||
| * - Invalid eip155 formats (non-numeric reference) are returned as-is | ||
| * - This is used because the current STX chains are EVM and declared as hex chain IDs in the existing flag. | ||
| * | ||
| * @param chainId - The chain ID in any supported format | ||
| * @returns Normalized chain ID (hex for EVM, original for non-EVM) | ||
| * @example | ||
| * ```ts | ||
| * normalizeChainId('0x1') // → '0x1' | ||
| * normalizeChainId('eip155:1') // → '0x1' | ||
| * normalizeChainId('eip155:137') // → '0x89' | ||
| * normalizeChainId('solana:...') // → 'solana:...' (unchanged) | ||
| * normalizeChainId('eip155:abc') // → 'eip155:abc' (invalid, unchanged) | ||
| * ``` | ||
| */ | ||
| function normalizeChainId(chainId) { | ||
| // If it's already hex or not a valid CAIP chain ID, return as-is | ||
| if (!(0, utils_1.isCaipChainId)(chainId)) { | ||
| return chainId; | ||
| } | ||
| const { namespace, reference } = (0, utils_1.parseCaipChainId)(chainId); | ||
| // Only normalize EVM CAIP-2 chains with valid numeric references to hex | ||
| if (namespace === utils_1.KnownCaipNamespace.Eip155) { | ||
| const decimal = parseInt(reference, 10); | ||
| // If reference is not a valid number, return as-is | ||
| if (Number.isNaN(decimal)) { | ||
| return chainId; | ||
| } | ||
| return (0, utils_1.numberToHex)(decimal); | ||
| } | ||
| // Non-EVM CAIP chains remain unchanged | ||
| return chainId; | ||
| } | ||
| exports.normalizeChainId = normalizeChainId; | ||
| /** | ||
| * Processes raw feature flags data and returns a validated configuration. | ||
| * Invalid chain configs are silently removed. Error reporting is handled by | ||
| * the SmartTransactionsController via ErrorReportingService. | ||
| * | ||
| * @param rawFeatureFlags - The raw feature flags data from the remote feature flag controller | ||
| * @returns The validated feature flags configuration (partial if some chains were invalid) | ||
| */ | ||
| function processSmartTransactionsFeatureFlags(rawFeatureFlags) { | ||
| const { config } = (0, validators_1.validateSmartTransactionsFeatureFlags)(rawFeatureFlags); | ||
| // Return config if it has any valid data, otherwise return defaults | ||
| if (Object.keys(config).length > 0) { | ||
| return config; | ||
| } | ||
| return constants_1.DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS; | ||
| } | ||
| exports.processSmartTransactionsFeatureFlags = processSmartTransactionsFeatureFlags; | ||
| /** | ||
| * Gets the smart transactions feature flags from the remote feature flag controller. | ||
| * | ||
| * @param messenger - Any messenger with access to RemoteFeatureFlagController:getState | ||
| * @returns The smart transactions feature flags configuration | ||
| * @example | ||
| * ```ts | ||
| * const featureFlags = getSmartTransactionsFeatureFlags(messenger); | ||
| * const chainConfig = featureFlags['0x1'] ?? featureFlags.default; | ||
| * ``` | ||
| */ | ||
| function getSmartTransactionsFeatureFlags(messenger) { | ||
| var _a; | ||
| const remoteFeatureFlagControllerState = messenger.call('RemoteFeatureFlagController:getState'); | ||
| const rawSmartTransactionsNetworks = (_a = remoteFeatureFlagControllerState === null || remoteFeatureFlagControllerState === void 0 ? void 0 : remoteFeatureFlagControllerState.remoteFeatureFlags) === null || _a === void 0 ? void 0 : _a.smartTransactionsNetworks; | ||
| return processSmartTransactionsFeatureFlags(rawSmartTransactionsNetworks); | ||
| } | ||
| exports.getSmartTransactionsFeatureFlags = getSmartTransactionsFeatureFlags; | ||
| /** | ||
| * Gets the merged feature flags configuration for a specific chain. | ||
| * Chain-specific configuration takes precedence over default configuration. | ||
| * | ||
| * For EVM chains, the chain ID is normalized to hex format before lookup. | ||
| * This means both '0x1' and 'eip155:1' will resolve to the same configuration. | ||
| * Non-EVM chains (e.g., Solana, Bitcoin) use exact match. | ||
| * | ||
| * @param featureFlags - The full feature flags configuration | ||
| * @param chainId - The chain ID to get configuration for. | ||
| * Supports both hex (e.g., "0x1") and CAIP-2 format (e.g., "eip155:1", "solana:...") | ||
| * @returns The merged configuration for the specified chain | ||
| * @example | ||
| * ```ts | ||
| * const featureFlags = getSmartTransactionsFeatureFlags(messenger); | ||
| * | ||
| * // Both resolve to the same config (normalized to 0x1) | ||
| * const chainConfig = getSmartTransactionsFeatureFlagsForChain(featureFlags, '0x1'); | ||
| * const sameConfig = getSmartTransactionsFeatureFlagsForChain(featureFlags, 'eip155:1'); | ||
| * | ||
| * // Non-EVM uses exact match | ||
| * const solanaConfig = getSmartTransactionsFeatureFlagsForChain(featureFlags, 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'); | ||
| * | ||
| * if (chainConfig.extensionActive) { | ||
| * // Smart transactions are enabled for this chain | ||
| * } | ||
| * ``` | ||
| */ | ||
| function getSmartTransactionsFeatureFlagsForChain(featureFlags, chainId) { | ||
| var _a; | ||
| const normalizedChainId = normalizeChainId(chainId); | ||
| const defaultRemoteConfig = (_a = featureFlags.default) !== null && _a !== void 0 ? _a : {}; | ||
| const chainRemoteConfig = featureFlags[normalizedChainId]; | ||
| if (chainRemoteConfig === undefined) { | ||
| return constants_1.DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS.default; | ||
| } | ||
| return Object.assign(Object.assign({}, defaultRemoteConfig), chainRemoteConfig); | ||
| } | ||
| exports.getSmartTransactionsFeatureFlagsForChain = getSmartTransactionsFeatureFlagsForChain; | ||
| //# sourceMappingURL=feature-flags.cjs.map |
| {"version":3,"file":"feature-flags.cjs","sourceRoot":"","sources":["../../src/featureFlags/feature-flags.ts"],"names":[],"mappings":";;;AAEA,2CAKyB;AAEzB,gDAAiF;AAKjF,iDAAqE;AAErE;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,gBAAgB,CAC9B,OAA0B;IAE1B,iEAAiE;IACjE,IAAI,CAAC,IAAA,qBAAa,EAAC,OAAO,CAAC,EAAE;QAC3B,OAAO,OAAO,CAAC;KAChB;IAED,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,OAAO,CAAC,CAAC;IAE3D,wEAAwE;IACxE,IAAI,SAAS,KAAK,0BAAkB,CAAC,MAAM,EAAE;QAC3C,MAAM,OAAO,GAAG,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;QACxC,mDAAmD;QACnD,IAAI,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE;YACzB,OAAO,OAAO,CAAC;SAChB;QACD,OAAO,IAAA,mBAAW,EAAC,OAAO,CAAC,CAAC;KAC7B;IAED,uCAAuC;IACvC,OAAO,OAAO,CAAC;AACjB,CAAC;AAtBD,4CAsBC;AAED;;;;;;;GAOG;AACH,SAAgB,oCAAoC,CAClD,eAAwB;IAExB,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,kDAAqC,EAAC,eAAe,CAAC,CAAC;IAE1E,oEAAoE;IACpE,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;QAClC,OAAO,MAAM,CAAC;KACf;IAED,OAAO,6DAAiD,CAAC;AAC3D,CAAC;AAXD,oFAWC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,gCAAgC,CAM9C,SAAY;;IACZ,MAAM,gCAAgC,GAAG,SAAS,CAAC,IAAI,CACrD,sCAAsC,CACvC,CAAC;IAEF,MAAM,4BAA4B,GAChC,MAAA,gCAAgC,aAAhC,gCAAgC,uBAAhC,gCAAgC,CAAE,kBAAkB,0CAChD,yBAAyB,CAAC;IAEhC,OAAO,oCAAoC,CAAC,4BAA4B,CAAC,CAAC;AAC5E,CAAC;AAhBD,4EAgBC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,SAAgB,wCAAwC,CACtD,YAAiD,EACjD,OAA0B;;IAE1B,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACpD,MAAM,mBAAmB,GAAG,MAAA,YAAY,CAAC,OAAO,mCAAI,EAAE,CAAC;IACvD,MAAM,iBAAiB,GAAG,YAAY,CAAC,iBAAiB,CAAC,CAAC;IAE1D,IAAI,iBAAiB,KAAK,SAAS,EAAE;QACnC,OAAO,6DAAiD,CAAC,OAAO,CAAC;KAClE;IAED,uCACK,mBAAmB,GACnB,iBAAiB,EACpB;AACJ,CAAC;AAhBD,4FAgBC","sourcesContent":["import type { RemoteFeatureFlagControllerState } from '@metamask/remote-feature-flag-controller';\nimport type { CaipChainId, Hex } from '@metamask/utils';\nimport {\n isCaipChainId,\n KnownCaipNamespace,\n numberToHex,\n parseCaipChainId,\n} from '@metamask/utils';\n\nimport { DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS } from '../constants';\nimport type {\n SmartTransactionsFeatureFlagsConfig,\n SmartTransactionsNetworkConfig,\n} from '../types';\nimport { validateSmartTransactionsFeatureFlags } from './validators';\n\n/**\n * Normalizes a chain ID to hex format for EVM chains.\n * - CAIP-2 EVM format (eip155:X) is converted to hex (0xY)\n * - Hex format is returned as-is\n * - Non-EVM CAIP-2 formats are returned as-is (exact match)\n * - Invalid eip155 formats (non-numeric reference) are returned as-is\n * - This is used because the current STX chains are EVM and declared as hex chain IDs in the existing flag.\n *\n * @param chainId - The chain ID in any supported format\n * @returns Normalized chain ID (hex for EVM, original for non-EVM)\n * @example\n * ```ts\n * normalizeChainId('0x1') // → '0x1'\n * normalizeChainId('eip155:1') // → '0x1'\n * normalizeChainId('eip155:137') // → '0x89'\n * normalizeChainId('solana:...') // → 'solana:...' (unchanged)\n * normalizeChainId('eip155:abc') // → 'eip155:abc' (invalid, unchanged)\n * ```\n */\nexport function normalizeChainId(\n chainId: Hex | CaipChainId,\n): Hex | CaipChainId {\n // If it's already hex or not a valid CAIP chain ID, return as-is\n if (!isCaipChainId(chainId)) {\n return chainId;\n }\n\n const { namespace, reference } = parseCaipChainId(chainId);\n\n // Only normalize EVM CAIP-2 chains with valid numeric references to hex\n if (namespace === KnownCaipNamespace.Eip155) {\n const decimal = parseInt(reference, 10);\n // If reference is not a valid number, return as-is\n if (Number.isNaN(decimal)) {\n return chainId;\n }\n return numberToHex(decimal);\n }\n\n // Non-EVM CAIP chains remain unchanged\n return chainId;\n}\n\n/**\n * Processes raw feature flags data and returns a validated configuration.\n * Invalid chain configs are silently removed. Error reporting is handled by\n * the SmartTransactionsController via ErrorReportingService.\n *\n * @param rawFeatureFlags - The raw feature flags data from the remote feature flag controller\n * @returns The validated feature flags configuration (partial if some chains were invalid)\n */\nexport function processSmartTransactionsFeatureFlags(\n rawFeatureFlags: unknown,\n): SmartTransactionsFeatureFlagsConfig {\n const { config } = validateSmartTransactionsFeatureFlags(rawFeatureFlags);\n\n // Return config if it has any valid data, otherwise return defaults\n if (Object.keys(config).length > 0) {\n return config;\n }\n\n return DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS;\n}\n\n/**\n * Gets the smart transactions feature flags from the remote feature flag controller.\n *\n * @param messenger - Any messenger with access to RemoteFeatureFlagController:getState\n * @returns The smart transactions feature flags configuration\n * @example\n * ```ts\n * const featureFlags = getSmartTransactionsFeatureFlags(messenger);\n * const chainConfig = featureFlags['0x1'] ?? featureFlags.default;\n * ```\n */\nexport function getSmartTransactionsFeatureFlags<\n T extends {\n call(\n action: 'RemoteFeatureFlagController:getState',\n ): RemoteFeatureFlagControllerState;\n },\n>(messenger: T): SmartTransactionsFeatureFlagsConfig {\n const remoteFeatureFlagControllerState = messenger.call(\n 'RemoteFeatureFlagController:getState',\n );\n\n const rawSmartTransactionsNetworks =\n remoteFeatureFlagControllerState?.remoteFeatureFlags\n ?.smartTransactionsNetworks;\n\n return processSmartTransactionsFeatureFlags(rawSmartTransactionsNetworks);\n}\n\n/**\n * Gets the merged feature flags configuration for a specific chain.\n * Chain-specific configuration takes precedence over default configuration.\n *\n * For EVM chains, the chain ID is normalized to hex format before lookup.\n * This means both '0x1' and 'eip155:1' will resolve to the same configuration.\n * Non-EVM chains (e.g., Solana, Bitcoin) use exact match.\n *\n * @param featureFlags - The full feature flags configuration\n * @param chainId - The chain ID to get configuration for.\n * Supports both hex (e.g., \"0x1\") and CAIP-2 format (e.g., \"eip155:1\", \"solana:...\")\n * @returns The merged configuration for the specified chain\n * @example\n * ```ts\n * const featureFlags = getSmartTransactionsFeatureFlags(messenger);\n *\n * // Both resolve to the same config (normalized to 0x1)\n * const chainConfig = getSmartTransactionsFeatureFlagsForChain(featureFlags, '0x1');\n * const sameConfig = getSmartTransactionsFeatureFlagsForChain(featureFlags, 'eip155:1');\n *\n * // Non-EVM uses exact match\n * const solanaConfig = getSmartTransactionsFeatureFlagsForChain(featureFlags, 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp');\n *\n * if (chainConfig.extensionActive) {\n * // Smart transactions are enabled for this chain\n * }\n * ```\n */\nexport function getSmartTransactionsFeatureFlagsForChain(\n featureFlags: SmartTransactionsFeatureFlagsConfig,\n chainId: Hex | CaipChainId,\n): SmartTransactionsNetworkConfig {\n const normalizedChainId = normalizeChainId(chainId);\n const defaultRemoteConfig = featureFlags.default ?? {};\n const chainRemoteConfig = featureFlags[normalizedChainId];\n\n if (chainRemoteConfig === undefined) {\n return DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS.default;\n }\n\n return {\n ...defaultRemoteConfig,\n ...chainRemoteConfig,\n };\n}\n"]} |
| import type { RemoteFeatureFlagControllerState } from "@metamask/remote-feature-flag-controller"; | ||
| import type { CaipChainId, Hex } from "@metamask/utils"; | ||
| import type { SmartTransactionsFeatureFlagsConfig, SmartTransactionsNetworkConfig } from "../types.cjs"; | ||
| /** | ||
| * Normalizes a chain ID to hex format for EVM chains. | ||
| * - CAIP-2 EVM format (eip155:X) is converted to hex (0xY) | ||
| * - Hex format is returned as-is | ||
| * - Non-EVM CAIP-2 formats are returned as-is (exact match) | ||
| * - Invalid eip155 formats (non-numeric reference) are returned as-is | ||
| * - This is used because the current STX chains are EVM and declared as hex chain IDs in the existing flag. | ||
| * | ||
| * @param chainId - The chain ID in any supported format | ||
| * @returns Normalized chain ID (hex for EVM, original for non-EVM) | ||
| * @example | ||
| * ```ts | ||
| * normalizeChainId('0x1') // → '0x1' | ||
| * normalizeChainId('eip155:1') // → '0x1' | ||
| * normalizeChainId('eip155:137') // → '0x89' | ||
| * normalizeChainId('solana:...') // → 'solana:...' (unchanged) | ||
| * normalizeChainId('eip155:abc') // → 'eip155:abc' (invalid, unchanged) | ||
| * ``` | ||
| */ | ||
| export declare function normalizeChainId(chainId: Hex | CaipChainId): Hex | CaipChainId; | ||
| /** | ||
| * Processes raw feature flags data and returns a validated configuration. | ||
| * Invalid chain configs are silently removed. Error reporting is handled by | ||
| * the SmartTransactionsController via ErrorReportingService. | ||
| * | ||
| * @param rawFeatureFlags - The raw feature flags data from the remote feature flag controller | ||
| * @returns The validated feature flags configuration (partial if some chains were invalid) | ||
| */ | ||
| export declare function processSmartTransactionsFeatureFlags(rawFeatureFlags: unknown): SmartTransactionsFeatureFlagsConfig; | ||
| /** | ||
| * Gets the smart transactions feature flags from the remote feature flag controller. | ||
| * | ||
| * @param messenger - Any messenger with access to RemoteFeatureFlagController:getState | ||
| * @returns The smart transactions feature flags configuration | ||
| * @example | ||
| * ```ts | ||
| * const featureFlags = getSmartTransactionsFeatureFlags(messenger); | ||
| * const chainConfig = featureFlags['0x1'] ?? featureFlags.default; | ||
| * ``` | ||
| */ | ||
| export declare function getSmartTransactionsFeatureFlags<T extends { | ||
| call(action: 'RemoteFeatureFlagController:getState'): RemoteFeatureFlagControllerState; | ||
| }>(messenger: T): SmartTransactionsFeatureFlagsConfig; | ||
| /** | ||
| * Gets the merged feature flags configuration for a specific chain. | ||
| * Chain-specific configuration takes precedence over default configuration. | ||
| * | ||
| * For EVM chains, the chain ID is normalized to hex format before lookup. | ||
| * This means both '0x1' and 'eip155:1' will resolve to the same configuration. | ||
| * Non-EVM chains (e.g., Solana, Bitcoin) use exact match. | ||
| * | ||
| * @param featureFlags - The full feature flags configuration | ||
| * @param chainId - The chain ID to get configuration for. | ||
| * Supports both hex (e.g., "0x1") and CAIP-2 format (e.g., "eip155:1", "solana:...") | ||
| * @returns The merged configuration for the specified chain | ||
| * @example | ||
| * ```ts | ||
| * const featureFlags = getSmartTransactionsFeatureFlags(messenger); | ||
| * | ||
| * // Both resolve to the same config (normalized to 0x1) | ||
| * const chainConfig = getSmartTransactionsFeatureFlagsForChain(featureFlags, '0x1'); | ||
| * const sameConfig = getSmartTransactionsFeatureFlagsForChain(featureFlags, 'eip155:1'); | ||
| * | ||
| * // Non-EVM uses exact match | ||
| * const solanaConfig = getSmartTransactionsFeatureFlagsForChain(featureFlags, 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'); | ||
| * | ||
| * if (chainConfig.extensionActive) { | ||
| * // Smart transactions are enabled for this chain | ||
| * } | ||
| * ``` | ||
| */ | ||
| export declare function getSmartTransactionsFeatureFlagsForChain(featureFlags: SmartTransactionsFeatureFlagsConfig, chainId: Hex | CaipChainId): SmartTransactionsNetworkConfig; | ||
| //# sourceMappingURL=feature-flags.d.cts.map |
| {"version":3,"file":"feature-flags.d.cts","sourceRoot":"","sources":["../../src/featureFlags/feature-flags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gCAAgC,EAAE,iDAAiD;AACjG,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,wBAAwB;AASxD,OAAO,KAAK,EACV,mCAAmC,EACnC,8BAA8B,EAC/B,qBAAiB;AAGlB;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,GAAG,GAAG,WAAW,GACzB,GAAG,GAAG,WAAW,CAoBnB;AAED;;;;;;;GAOG;AACH,wBAAgB,oCAAoC,CAClD,eAAe,EAAE,OAAO,GACvB,mCAAmC,CASrC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gCAAgC,CAC9C,CAAC,SAAS;IACR,IAAI,CACF,MAAM,EAAE,sCAAsC,GAC7C,gCAAgC,CAAC;CACrC,EACD,SAAS,EAAE,CAAC,GAAG,mCAAmC,CAUnD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,wCAAwC,CACtD,YAAY,EAAE,mCAAmC,EACjD,OAAO,EAAE,GAAG,GAAG,WAAW,GACzB,8BAA8B,CAahC"} |
| import type { RemoteFeatureFlagControllerState } from "@metamask/remote-feature-flag-controller"; | ||
| import type { CaipChainId, Hex } from "@metamask/utils"; | ||
| import type { SmartTransactionsFeatureFlagsConfig, SmartTransactionsNetworkConfig } from "../types.mjs"; | ||
| /** | ||
| * Normalizes a chain ID to hex format for EVM chains. | ||
| * - CAIP-2 EVM format (eip155:X) is converted to hex (0xY) | ||
| * - Hex format is returned as-is | ||
| * - Non-EVM CAIP-2 formats are returned as-is (exact match) | ||
| * - Invalid eip155 formats (non-numeric reference) are returned as-is | ||
| * - This is used because the current STX chains are EVM and declared as hex chain IDs in the existing flag. | ||
| * | ||
| * @param chainId - The chain ID in any supported format | ||
| * @returns Normalized chain ID (hex for EVM, original for non-EVM) | ||
| * @example | ||
| * ```ts | ||
| * normalizeChainId('0x1') // → '0x1' | ||
| * normalizeChainId('eip155:1') // → '0x1' | ||
| * normalizeChainId('eip155:137') // → '0x89' | ||
| * normalizeChainId('solana:...') // → 'solana:...' (unchanged) | ||
| * normalizeChainId('eip155:abc') // → 'eip155:abc' (invalid, unchanged) | ||
| * ``` | ||
| */ | ||
| export declare function normalizeChainId(chainId: Hex | CaipChainId): Hex | CaipChainId; | ||
| /** | ||
| * Processes raw feature flags data and returns a validated configuration. | ||
| * Invalid chain configs are silently removed. Error reporting is handled by | ||
| * the SmartTransactionsController via ErrorReportingService. | ||
| * | ||
| * @param rawFeatureFlags - The raw feature flags data from the remote feature flag controller | ||
| * @returns The validated feature flags configuration (partial if some chains were invalid) | ||
| */ | ||
| export declare function processSmartTransactionsFeatureFlags(rawFeatureFlags: unknown): SmartTransactionsFeatureFlagsConfig; | ||
| /** | ||
| * Gets the smart transactions feature flags from the remote feature flag controller. | ||
| * | ||
| * @param messenger - Any messenger with access to RemoteFeatureFlagController:getState | ||
| * @returns The smart transactions feature flags configuration | ||
| * @example | ||
| * ```ts | ||
| * const featureFlags = getSmartTransactionsFeatureFlags(messenger); | ||
| * const chainConfig = featureFlags['0x1'] ?? featureFlags.default; | ||
| * ``` | ||
| */ | ||
| export declare function getSmartTransactionsFeatureFlags<T extends { | ||
| call(action: 'RemoteFeatureFlagController:getState'): RemoteFeatureFlagControllerState; | ||
| }>(messenger: T): SmartTransactionsFeatureFlagsConfig; | ||
| /** | ||
| * Gets the merged feature flags configuration for a specific chain. | ||
| * Chain-specific configuration takes precedence over default configuration. | ||
| * | ||
| * For EVM chains, the chain ID is normalized to hex format before lookup. | ||
| * This means both '0x1' and 'eip155:1' will resolve to the same configuration. | ||
| * Non-EVM chains (e.g., Solana, Bitcoin) use exact match. | ||
| * | ||
| * @param featureFlags - The full feature flags configuration | ||
| * @param chainId - The chain ID to get configuration for. | ||
| * Supports both hex (e.g., "0x1") and CAIP-2 format (e.g., "eip155:1", "solana:...") | ||
| * @returns The merged configuration for the specified chain | ||
| * @example | ||
| * ```ts | ||
| * const featureFlags = getSmartTransactionsFeatureFlags(messenger); | ||
| * | ||
| * // Both resolve to the same config (normalized to 0x1) | ||
| * const chainConfig = getSmartTransactionsFeatureFlagsForChain(featureFlags, '0x1'); | ||
| * const sameConfig = getSmartTransactionsFeatureFlagsForChain(featureFlags, 'eip155:1'); | ||
| * | ||
| * // Non-EVM uses exact match | ||
| * const solanaConfig = getSmartTransactionsFeatureFlagsForChain(featureFlags, 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'); | ||
| * | ||
| * if (chainConfig.extensionActive) { | ||
| * // Smart transactions are enabled for this chain | ||
| * } | ||
| * ``` | ||
| */ | ||
| export declare function getSmartTransactionsFeatureFlagsForChain(featureFlags: SmartTransactionsFeatureFlagsConfig, chainId: Hex | CaipChainId): SmartTransactionsNetworkConfig; | ||
| //# sourceMappingURL=feature-flags.d.mts.map |
| {"version":3,"file":"feature-flags.d.mts","sourceRoot":"","sources":["../../src/featureFlags/feature-flags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gCAAgC,EAAE,iDAAiD;AACjG,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,wBAAwB;AASxD,OAAO,KAAK,EACV,mCAAmC,EACnC,8BAA8B,EAC/B,qBAAiB;AAGlB;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,GAAG,GAAG,WAAW,GACzB,GAAG,GAAG,WAAW,CAoBnB;AAED;;;;;;;GAOG;AACH,wBAAgB,oCAAoC,CAClD,eAAe,EAAE,OAAO,GACvB,mCAAmC,CASrC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gCAAgC,CAC9C,CAAC,SAAS;IACR,IAAI,CACF,MAAM,EAAE,sCAAsC,GAC7C,gCAAgC,CAAC;CACrC,EACD,SAAS,EAAE,CAAC,GAAG,mCAAmC,CAUnD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,wCAAwC,CACtD,YAAY,EAAE,mCAAmC,EACjD,OAAO,EAAE,GAAG,GAAG,WAAW,GACzB,8BAA8B,CAahC"} |
| import { isCaipChainId, KnownCaipNamespace, numberToHex, parseCaipChainId } from "@metamask/utils"; | ||
| import { DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS } from "../constants.mjs"; | ||
| import { validateSmartTransactionsFeatureFlags } from "./validators.mjs"; | ||
| /** | ||
| * Normalizes a chain ID to hex format for EVM chains. | ||
| * - CAIP-2 EVM format (eip155:X) is converted to hex (0xY) | ||
| * - Hex format is returned as-is | ||
| * - Non-EVM CAIP-2 formats are returned as-is (exact match) | ||
| * - Invalid eip155 formats (non-numeric reference) are returned as-is | ||
| * - This is used because the current STX chains are EVM and declared as hex chain IDs in the existing flag. | ||
| * | ||
| * @param chainId - The chain ID in any supported format | ||
| * @returns Normalized chain ID (hex for EVM, original for non-EVM) | ||
| * @example | ||
| * ```ts | ||
| * normalizeChainId('0x1') // → '0x1' | ||
| * normalizeChainId('eip155:1') // → '0x1' | ||
| * normalizeChainId('eip155:137') // → '0x89' | ||
| * normalizeChainId('solana:...') // → 'solana:...' (unchanged) | ||
| * normalizeChainId('eip155:abc') // → 'eip155:abc' (invalid, unchanged) | ||
| * ``` | ||
| */ | ||
| export function normalizeChainId(chainId) { | ||
| // If it's already hex or not a valid CAIP chain ID, return as-is | ||
| if (!isCaipChainId(chainId)) { | ||
| return chainId; | ||
| } | ||
| const { namespace, reference } = parseCaipChainId(chainId); | ||
| // Only normalize EVM CAIP-2 chains with valid numeric references to hex | ||
| if (namespace === KnownCaipNamespace.Eip155) { | ||
| const decimal = parseInt(reference, 10); | ||
| // If reference is not a valid number, return as-is | ||
| if (Number.isNaN(decimal)) { | ||
| return chainId; | ||
| } | ||
| return numberToHex(decimal); | ||
| } | ||
| // Non-EVM CAIP chains remain unchanged | ||
| return chainId; | ||
| } | ||
| /** | ||
| * Processes raw feature flags data and returns a validated configuration. | ||
| * Invalid chain configs are silently removed. Error reporting is handled by | ||
| * the SmartTransactionsController via ErrorReportingService. | ||
| * | ||
| * @param rawFeatureFlags - The raw feature flags data from the remote feature flag controller | ||
| * @returns The validated feature flags configuration (partial if some chains were invalid) | ||
| */ | ||
| export function processSmartTransactionsFeatureFlags(rawFeatureFlags) { | ||
| const { config } = validateSmartTransactionsFeatureFlags(rawFeatureFlags); | ||
| // Return config if it has any valid data, otherwise return defaults | ||
| if (Object.keys(config).length > 0) { | ||
| return config; | ||
| } | ||
| return DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS; | ||
| } | ||
| /** | ||
| * Gets the smart transactions feature flags from the remote feature flag controller. | ||
| * | ||
| * @param messenger - Any messenger with access to RemoteFeatureFlagController:getState | ||
| * @returns The smart transactions feature flags configuration | ||
| * @example | ||
| * ```ts | ||
| * const featureFlags = getSmartTransactionsFeatureFlags(messenger); | ||
| * const chainConfig = featureFlags['0x1'] ?? featureFlags.default; | ||
| * ``` | ||
| */ | ||
| export function getSmartTransactionsFeatureFlags(messenger) { | ||
| var _a; | ||
| const remoteFeatureFlagControllerState = messenger.call('RemoteFeatureFlagController:getState'); | ||
| const rawSmartTransactionsNetworks = (_a = remoteFeatureFlagControllerState === null || remoteFeatureFlagControllerState === void 0 ? void 0 : remoteFeatureFlagControllerState.remoteFeatureFlags) === null || _a === void 0 ? void 0 : _a.smartTransactionsNetworks; | ||
| return processSmartTransactionsFeatureFlags(rawSmartTransactionsNetworks); | ||
| } | ||
| /** | ||
| * Gets the merged feature flags configuration for a specific chain. | ||
| * Chain-specific configuration takes precedence over default configuration. | ||
| * | ||
| * For EVM chains, the chain ID is normalized to hex format before lookup. | ||
| * This means both '0x1' and 'eip155:1' will resolve to the same configuration. | ||
| * Non-EVM chains (e.g., Solana, Bitcoin) use exact match. | ||
| * | ||
| * @param featureFlags - The full feature flags configuration | ||
| * @param chainId - The chain ID to get configuration for. | ||
| * Supports both hex (e.g., "0x1") and CAIP-2 format (e.g., "eip155:1", "solana:...") | ||
| * @returns The merged configuration for the specified chain | ||
| * @example | ||
| * ```ts | ||
| * const featureFlags = getSmartTransactionsFeatureFlags(messenger); | ||
| * | ||
| * // Both resolve to the same config (normalized to 0x1) | ||
| * const chainConfig = getSmartTransactionsFeatureFlagsForChain(featureFlags, '0x1'); | ||
| * const sameConfig = getSmartTransactionsFeatureFlagsForChain(featureFlags, 'eip155:1'); | ||
| * | ||
| * // Non-EVM uses exact match | ||
| * const solanaConfig = getSmartTransactionsFeatureFlagsForChain(featureFlags, 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'); | ||
| * | ||
| * if (chainConfig.extensionActive) { | ||
| * // Smart transactions are enabled for this chain | ||
| * } | ||
| * ``` | ||
| */ | ||
| export function getSmartTransactionsFeatureFlagsForChain(featureFlags, chainId) { | ||
| var _a; | ||
| const normalizedChainId = normalizeChainId(chainId); | ||
| const defaultRemoteConfig = (_a = featureFlags.default) !== null && _a !== void 0 ? _a : {}; | ||
| const chainRemoteConfig = featureFlags[normalizedChainId]; | ||
| if (chainRemoteConfig === undefined) { | ||
| return DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS.default; | ||
| } | ||
| return Object.assign(Object.assign({}, defaultRemoteConfig), chainRemoteConfig); | ||
| } | ||
| //# sourceMappingURL=feature-flags.mjs.map |
| {"version":3,"file":"feature-flags.mjs","sourceRoot":"","sources":["../../src/featureFlags/feature-flags.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,WAAW,EACX,gBAAgB,EACjB,wBAAwB;AAEzB,OAAO,EAAE,iDAAiD,EAAE,yBAAqB;AAKjF,OAAO,EAAE,qCAAqC,EAAE,yBAAqB;AAErE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,gBAAgB,CAC9B,OAA0B;IAE1B,iEAAiE;IACjE,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE;QAC3B,OAAO,OAAO,CAAC;KAChB;IAED,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAE3D,wEAAwE;IACxE,IAAI,SAAS,KAAK,kBAAkB,CAAC,MAAM,EAAE;QAC3C,MAAM,OAAO,GAAG,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;QACxC,mDAAmD;QACnD,IAAI,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE;YACzB,OAAO,OAAO,CAAC;SAChB;QACD,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC;KAC7B;IAED,uCAAuC;IACvC,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,oCAAoC,CAClD,eAAwB;IAExB,MAAM,EAAE,MAAM,EAAE,GAAG,qCAAqC,CAAC,eAAe,CAAC,CAAC;IAE1E,oEAAoE;IACpE,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;QAClC,OAAO,MAAM,CAAC;KACf;IAED,OAAO,iDAAiD,CAAC;AAC3D,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gCAAgC,CAM9C,SAAY;;IACZ,MAAM,gCAAgC,GAAG,SAAS,CAAC,IAAI,CACrD,sCAAsC,CACvC,CAAC;IAEF,MAAM,4BAA4B,GAChC,MAAA,gCAAgC,aAAhC,gCAAgC,uBAAhC,gCAAgC,CAAE,kBAAkB,0CAChD,yBAAyB,CAAC;IAEhC,OAAO,oCAAoC,CAAC,4BAA4B,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,wCAAwC,CACtD,YAAiD,EACjD,OAA0B;;IAE1B,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACpD,MAAM,mBAAmB,GAAG,MAAA,YAAY,CAAC,OAAO,mCAAI,EAAE,CAAC;IACvD,MAAM,iBAAiB,GAAG,YAAY,CAAC,iBAAiB,CAAC,CAAC;IAE1D,IAAI,iBAAiB,KAAK,SAAS,EAAE;QACnC,OAAO,iDAAiD,CAAC,OAAO,CAAC;KAClE;IAED,uCACK,mBAAmB,GACnB,iBAAiB,EACpB;AACJ,CAAC","sourcesContent":["import type { RemoteFeatureFlagControllerState } from '@metamask/remote-feature-flag-controller';\nimport type { CaipChainId, Hex } from '@metamask/utils';\nimport {\n isCaipChainId,\n KnownCaipNamespace,\n numberToHex,\n parseCaipChainId,\n} from '@metamask/utils';\n\nimport { DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS } from '../constants';\nimport type {\n SmartTransactionsFeatureFlagsConfig,\n SmartTransactionsNetworkConfig,\n} from '../types';\nimport { validateSmartTransactionsFeatureFlags } from './validators';\n\n/**\n * Normalizes a chain ID to hex format for EVM chains.\n * - CAIP-2 EVM format (eip155:X) is converted to hex (0xY)\n * - Hex format is returned as-is\n * - Non-EVM CAIP-2 formats are returned as-is (exact match)\n * - Invalid eip155 formats (non-numeric reference) are returned as-is\n * - This is used because the current STX chains are EVM and declared as hex chain IDs in the existing flag.\n *\n * @param chainId - The chain ID in any supported format\n * @returns Normalized chain ID (hex for EVM, original for non-EVM)\n * @example\n * ```ts\n * normalizeChainId('0x1') // → '0x1'\n * normalizeChainId('eip155:1') // → '0x1'\n * normalizeChainId('eip155:137') // → '0x89'\n * normalizeChainId('solana:...') // → 'solana:...' (unchanged)\n * normalizeChainId('eip155:abc') // → 'eip155:abc' (invalid, unchanged)\n * ```\n */\nexport function normalizeChainId(\n chainId: Hex | CaipChainId,\n): Hex | CaipChainId {\n // If it's already hex or not a valid CAIP chain ID, return as-is\n if (!isCaipChainId(chainId)) {\n return chainId;\n }\n\n const { namespace, reference } = parseCaipChainId(chainId);\n\n // Only normalize EVM CAIP-2 chains with valid numeric references to hex\n if (namespace === KnownCaipNamespace.Eip155) {\n const decimal = parseInt(reference, 10);\n // If reference is not a valid number, return as-is\n if (Number.isNaN(decimal)) {\n return chainId;\n }\n return numberToHex(decimal);\n }\n\n // Non-EVM CAIP chains remain unchanged\n return chainId;\n}\n\n/**\n * Processes raw feature flags data and returns a validated configuration.\n * Invalid chain configs are silently removed. Error reporting is handled by\n * the SmartTransactionsController via ErrorReportingService.\n *\n * @param rawFeatureFlags - The raw feature flags data from the remote feature flag controller\n * @returns The validated feature flags configuration (partial if some chains were invalid)\n */\nexport function processSmartTransactionsFeatureFlags(\n rawFeatureFlags: unknown,\n): SmartTransactionsFeatureFlagsConfig {\n const { config } = validateSmartTransactionsFeatureFlags(rawFeatureFlags);\n\n // Return config if it has any valid data, otherwise return defaults\n if (Object.keys(config).length > 0) {\n return config;\n }\n\n return DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS;\n}\n\n/**\n * Gets the smart transactions feature flags from the remote feature flag controller.\n *\n * @param messenger - Any messenger with access to RemoteFeatureFlagController:getState\n * @returns The smart transactions feature flags configuration\n * @example\n * ```ts\n * const featureFlags = getSmartTransactionsFeatureFlags(messenger);\n * const chainConfig = featureFlags['0x1'] ?? featureFlags.default;\n * ```\n */\nexport function getSmartTransactionsFeatureFlags<\n T extends {\n call(\n action: 'RemoteFeatureFlagController:getState',\n ): RemoteFeatureFlagControllerState;\n },\n>(messenger: T): SmartTransactionsFeatureFlagsConfig {\n const remoteFeatureFlagControllerState = messenger.call(\n 'RemoteFeatureFlagController:getState',\n );\n\n const rawSmartTransactionsNetworks =\n remoteFeatureFlagControllerState?.remoteFeatureFlags\n ?.smartTransactionsNetworks;\n\n return processSmartTransactionsFeatureFlags(rawSmartTransactionsNetworks);\n}\n\n/**\n * Gets the merged feature flags configuration for a specific chain.\n * Chain-specific configuration takes precedence over default configuration.\n *\n * For EVM chains, the chain ID is normalized to hex format before lookup.\n * This means both '0x1' and 'eip155:1' will resolve to the same configuration.\n * Non-EVM chains (e.g., Solana, Bitcoin) use exact match.\n *\n * @param featureFlags - The full feature flags configuration\n * @param chainId - The chain ID to get configuration for.\n * Supports both hex (e.g., \"0x1\") and CAIP-2 format (e.g., \"eip155:1\", \"solana:...\")\n * @returns The merged configuration for the specified chain\n * @example\n * ```ts\n * const featureFlags = getSmartTransactionsFeatureFlags(messenger);\n *\n * // Both resolve to the same config (normalized to 0x1)\n * const chainConfig = getSmartTransactionsFeatureFlagsForChain(featureFlags, '0x1');\n * const sameConfig = getSmartTransactionsFeatureFlagsForChain(featureFlags, 'eip155:1');\n *\n * // Non-EVM uses exact match\n * const solanaConfig = getSmartTransactionsFeatureFlagsForChain(featureFlags, 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp');\n *\n * if (chainConfig.extensionActive) {\n * // Smart transactions are enabled for this chain\n * }\n * ```\n */\nexport function getSmartTransactionsFeatureFlagsForChain(\n featureFlags: SmartTransactionsFeatureFlagsConfig,\n chainId: Hex | CaipChainId,\n): SmartTransactionsNetworkConfig {\n const normalizedChainId = normalizeChainId(chainId);\n const defaultRemoteConfig = featureFlags.default ?? {};\n const chainRemoteConfig = featureFlags[normalizedChainId];\n\n if (chainRemoteConfig === undefined) {\n return DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS.default;\n }\n\n return {\n ...defaultRemoteConfig,\n ...chainRemoteConfig,\n };\n}\n"]} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.normalizeChainId = exports.getSmartTransactionsFeatureFlagsForChain = exports.processSmartTransactionsFeatureFlags = exports.getSmartTransactionsFeatureFlags = exports.SmartTransactionsFeatureFlagsConfigSchema = exports.SmartTransactionsNetworkConfigSchema = exports.validateSmartTransactionsNetworkConfig = exports.validateSmartTransactionsFeatureFlags = void 0; | ||
| var validators_1 = require("./validators.cjs"); | ||
| Object.defineProperty(exports, "validateSmartTransactionsFeatureFlags", { enumerable: true, get: function () { return validators_1.validateSmartTransactionsFeatureFlags; } }); | ||
| Object.defineProperty(exports, "validateSmartTransactionsNetworkConfig", { enumerable: true, get: function () { return validators_1.validateSmartTransactionsNetworkConfig; } }); | ||
| Object.defineProperty(exports, "SmartTransactionsNetworkConfigSchema", { enumerable: true, get: function () { return validators_1.SmartTransactionsNetworkConfigSchema; } }); | ||
| Object.defineProperty(exports, "SmartTransactionsFeatureFlagsConfigSchema", { enumerable: true, get: function () { return validators_1.SmartTransactionsFeatureFlagsConfigSchema; } }); | ||
| var feature_flags_1 = require("./feature-flags.cjs"); | ||
| Object.defineProperty(exports, "getSmartTransactionsFeatureFlags", { enumerable: true, get: function () { return feature_flags_1.getSmartTransactionsFeatureFlags; } }); | ||
| Object.defineProperty(exports, "processSmartTransactionsFeatureFlags", { enumerable: true, get: function () { return feature_flags_1.processSmartTransactionsFeatureFlags; } }); | ||
| Object.defineProperty(exports, "getSmartTransactionsFeatureFlagsForChain", { enumerable: true, get: function () { return feature_flags_1.getSmartTransactionsFeatureFlagsForChain; } }); | ||
| Object.defineProperty(exports, "normalizeChainId", { enumerable: true, get: function () { return feature_flags_1.normalizeChainId; } }); | ||
| //# sourceMappingURL=index.cjs.map |
| {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/featureFlags/index.ts"],"names":[],"mappings":";;;AAAA,+CASsB;AARpB,mIAAA,qCAAqC,OAAA;AACrC,oIAAA,sCAAsC,OAAA;AACtC,kIAAA,oCAAoC,OAAA;AACpC,uIAAA,yCAAyC,OAAA;AAO3C,qDAKyB;AAJvB,iIAAA,gCAAgC,OAAA;AAChC,qIAAA,oCAAoC,OAAA;AACpC,yIAAA,wCAAwC,OAAA;AACxC,iHAAA,gBAAgB,OAAA","sourcesContent":["export {\n validateSmartTransactionsFeatureFlags,\n validateSmartTransactionsNetworkConfig,\n SmartTransactionsNetworkConfigSchema,\n SmartTransactionsFeatureFlagsConfigSchema,\n type SmartTransactionsNetworkConfigFromSchema,\n type SmartTransactionsNetworkConfigFromSchema as SmartTransactionsNetworkConfig,\n type SmartTransactionsFeatureFlagsConfigFromSchema,\n type FeatureFlagsProcessResult,\n} from './validators';\n\nexport {\n getSmartTransactionsFeatureFlags,\n processSmartTransactionsFeatureFlags,\n getSmartTransactionsFeatureFlagsForChain,\n normalizeChainId,\n} from './feature-flags';\n"]} |
| export { validateSmartTransactionsFeatureFlags, validateSmartTransactionsNetworkConfig, SmartTransactionsNetworkConfigSchema, SmartTransactionsFeatureFlagsConfigSchema, type SmartTransactionsNetworkConfigFromSchema, type SmartTransactionsNetworkConfigFromSchema as SmartTransactionsNetworkConfig, type SmartTransactionsFeatureFlagsConfigFromSchema, type FeatureFlagsProcessResult, } from "./validators.cjs"; | ||
| export { getSmartTransactionsFeatureFlags, processSmartTransactionsFeatureFlags, getSmartTransactionsFeatureFlagsForChain, normalizeChainId, } from "./feature-flags.cjs"; | ||
| //# sourceMappingURL=index.d.cts.map |
| {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/featureFlags/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qCAAqC,EACrC,sCAAsC,EACtC,oCAAoC,EACpC,yCAAyC,EACzC,KAAK,wCAAwC,EAC7C,KAAK,wCAAwC,IAAI,8BAA8B,EAC/E,KAAK,6CAA6C,EAClD,KAAK,yBAAyB,GAC/B,yBAAqB;AAEtB,OAAO,EACL,gCAAgC,EAChC,oCAAoC,EACpC,wCAAwC,EACxC,gBAAgB,GACjB,4BAAwB"} |
| export { validateSmartTransactionsFeatureFlags, validateSmartTransactionsNetworkConfig, SmartTransactionsNetworkConfigSchema, SmartTransactionsFeatureFlagsConfigSchema, type SmartTransactionsNetworkConfigFromSchema, type SmartTransactionsNetworkConfigFromSchema as SmartTransactionsNetworkConfig, type SmartTransactionsFeatureFlagsConfigFromSchema, type FeatureFlagsProcessResult, } from "./validators.mjs"; | ||
| export { getSmartTransactionsFeatureFlags, processSmartTransactionsFeatureFlags, getSmartTransactionsFeatureFlagsForChain, normalizeChainId, } from "./feature-flags.mjs"; | ||
| //# sourceMappingURL=index.d.mts.map |
| {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/featureFlags/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qCAAqC,EACrC,sCAAsC,EACtC,oCAAoC,EACpC,yCAAyC,EACzC,KAAK,wCAAwC,EAC7C,KAAK,wCAAwC,IAAI,8BAA8B,EAC/E,KAAK,6CAA6C,EAClD,KAAK,yBAAyB,GAC/B,yBAAqB;AAEtB,OAAO,EACL,gCAAgC,EAChC,oCAAoC,EACpC,wCAAwC,EACxC,gBAAgB,GACjB,4BAAwB"} |
| export { validateSmartTransactionsFeatureFlags, validateSmartTransactionsNetworkConfig, SmartTransactionsNetworkConfigSchema, SmartTransactionsFeatureFlagsConfigSchema } from "./validators.mjs"; | ||
| export { getSmartTransactionsFeatureFlags, processSmartTransactionsFeatureFlags, getSmartTransactionsFeatureFlagsForChain, normalizeChainId } from "./feature-flags.mjs"; | ||
| //# sourceMappingURL=index.mjs.map |
| {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/featureFlags/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qCAAqC,EACrC,sCAAsC,EACtC,oCAAoC,EACpC,yCAAyC,EAK1C,yBAAqB;AAEtB,OAAO,EACL,gCAAgC,EAChC,oCAAoC,EACpC,wCAAwC,EACxC,gBAAgB,EACjB,4BAAwB","sourcesContent":["export {\n validateSmartTransactionsFeatureFlags,\n validateSmartTransactionsNetworkConfig,\n SmartTransactionsNetworkConfigSchema,\n SmartTransactionsFeatureFlagsConfigSchema,\n type SmartTransactionsNetworkConfigFromSchema,\n type SmartTransactionsNetworkConfigFromSchema as SmartTransactionsNetworkConfig,\n type SmartTransactionsFeatureFlagsConfigFromSchema,\n type FeatureFlagsProcessResult,\n} from './validators';\n\nexport {\n getSmartTransactionsFeatureFlags,\n processSmartTransactionsFeatureFlags,\n getSmartTransactionsFeatureFlagsForChain,\n normalizeChainId,\n} from './feature-flags';\n"]} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.validateSmartTransactionsNetworkConfig = exports.validateSmartTransactionsFeatureFlags = exports.SmartTransactionsFeatureFlagsConfigSchema = exports.SmartTransactionsNetworkConfigSchema = void 0; | ||
| const superstruct_1 = require("@metamask/superstruct"); | ||
| const utils_1 = require("@metamask/utils"); | ||
| /** | ||
| * Validates that a key is a valid chain ID (hex or CAIP-2 format). | ||
| * Supports both EVM hex chain IDs and chain-agnostic CAIP-2 identifiers. | ||
| * | ||
| * @param key - The key to validate | ||
| * @returns True if the key is a valid chain ID format | ||
| */ | ||
| function isValidChainIdKey(key) { | ||
| return (0, utils_1.isStrictHexString)(key) || (0, utils_1.isCaipChainId)(key); | ||
| } | ||
| /** | ||
| * Schema for validating per-network smart transactions configuration. | ||
| * All fields are optional to allow partial configuration and merging with defaults. | ||
| */ | ||
| exports.SmartTransactionsNetworkConfigSchema = (0, superstruct_1.type)({ | ||
| /** Whether smart transactions are active for the extension client */ | ||
| extensionActive: (0, superstruct_1.optional)((0, superstruct_1.boolean)()), | ||
| /** Whether smart transactions are active for mobile clients (generic) */ | ||
| mobileActive: (0, superstruct_1.optional)((0, superstruct_1.boolean)()), | ||
| /** Whether smart transactions are active for iOS specifically */ | ||
| mobileActiveIOS: (0, superstruct_1.optional)((0, superstruct_1.boolean)()), | ||
| /** Whether smart transactions are active for Android specifically */ | ||
| mobileActiveAndroid: (0, superstruct_1.optional)((0, superstruct_1.boolean)()), | ||
| /** Expected time in seconds for a smart transaction to be mined */ | ||
| expectedDeadline: (0, superstruct_1.optional)((0, superstruct_1.number)()), | ||
| /** Maximum time in seconds before a smart transaction is considered failed */ | ||
| maxDeadline: (0, superstruct_1.optional)((0, superstruct_1.number)()), | ||
| /** Whether extension should return tx hash immediately without waiting for confirmation */ | ||
| extensionReturnTxHashAsap: (0, superstruct_1.optional)((0, superstruct_1.boolean)()), | ||
| /** Whether extension should return tx hash immediately for batch transactions */ | ||
| extensionReturnTxHashAsapBatch: (0, superstruct_1.optional)((0, superstruct_1.boolean)()), | ||
| /** Whether mobile should return tx hash immediately without waiting for confirmation */ | ||
| mobileReturnTxHashAsap: (0, superstruct_1.optional)((0, superstruct_1.boolean)()), | ||
| /** Whether extension should skip the smart transaction status page */ | ||
| extensionSkipSmartTransactionStatusPage: (0, superstruct_1.optional)((0, superstruct_1.boolean)()), | ||
| /** Polling interval in milliseconds for batch status updates */ | ||
| batchStatusPollingInterval: (0, superstruct_1.optional)((0, superstruct_1.number)()), | ||
| /** Custom sentinel URL for the network */ | ||
| sentinelUrl: (0, superstruct_1.optional)((0, superstruct_1.string)()), | ||
| }); | ||
| /** | ||
| * Schema for validating the complete smart transactions feature flags configuration. | ||
| * This includes a default configuration and optional chain-specific overrides. | ||
| */ | ||
| exports.SmartTransactionsFeatureFlagsConfigSchema = (0, superstruct_1.type)({ | ||
| /** Default configuration applied to all chains unless overridden */ | ||
| default: (0, superstruct_1.optional)(exports.SmartTransactionsNetworkConfigSchema), | ||
| }); | ||
| /** | ||
| * Validates smart transactions feature flags with per-chain validation. | ||
| * - If the input is not an object, returns empty config with error | ||
| * - If `default` is present and invalid, returns empty config with error | ||
| * - For each chain: if invalid, removes it and collects error; if valid, includes it | ||
| * | ||
| * @param data - The data to validate | ||
| * @returns The validated config and any validation errors | ||
| */ | ||
| function validateSmartTransactionsFeatureFlags(data) { | ||
| const errors = []; | ||
| // Step 1: Check if it's a valid object | ||
| if (typeof data !== 'object' || data === null || Array.isArray(data)) { | ||
| const typeDescription = data === null ? 'null' : typeof data; | ||
| const arraySuffix = Array.isArray(data) ? ' (array)' : ''; | ||
| return { | ||
| config: {}, | ||
| errors: [ | ||
| new Error(`Expected an object, received ${typeDescription}${arraySuffix}`), | ||
| ], | ||
| }; | ||
| } | ||
| const dataRecord = data; | ||
| const validConfig = {}; | ||
| // Step 2: Validate 'default' - if present and invalid, reject everything | ||
| if (dataRecord.default !== undefined) { | ||
| const [defaultError, validatedDefault] = (0, superstruct_1.validate)(dataRecord.default, exports.SmartTransactionsNetworkConfigSchema); | ||
| if (defaultError) { | ||
| return { | ||
| config: {}, | ||
| errors: [ | ||
| new Error(`Invalid 'default' config: ${defaultError.message}`), | ||
| ], | ||
| }; | ||
| } | ||
| // validatedDefault is properly typed from superstruct | ||
| validConfig.default = validatedDefault; | ||
| } | ||
| // Step 3: Validate chain-specific configs, keeping valid ones | ||
| for (const [key, value] of Object.entries(dataRecord)) { | ||
| if (key === 'default') { | ||
| continue; | ||
| } | ||
| // Check chain ID format | ||
| if (!isValidChainIdKey(key)) { | ||
| errors.push(new Error(`Invalid chain ID key "${key}". Expected hex string (e.g., "0x1") or CAIP-2 format (e.g., "eip155:1", "solana:...")`)); | ||
| continue; // Skip this chain, don't add to result | ||
| } | ||
| // Validate chain config | ||
| if (value !== undefined) { | ||
| const [chainError, validatedChain] = (0, superstruct_1.validate)(value, exports.SmartTransactionsNetworkConfigSchema); | ||
| if (chainError) { | ||
| errors.push(new Error(`Chain "${key}": ${chainError.message}`)); | ||
| continue; // Skip this chain, don't add to result | ||
| } | ||
| // validatedChain is properly typed from superstruct | ||
| validConfig[key] = validatedChain; | ||
| } | ||
| } | ||
| return { config: validConfig, errors }; | ||
| } | ||
| exports.validateSmartTransactionsFeatureFlags = validateSmartTransactionsFeatureFlags; | ||
| /** | ||
| * Validates that the given data conforms to the SmartTransactionsNetworkConfig schema. | ||
| * | ||
| * @param data - The data to validate | ||
| * @returns True if the data is valid, false otherwise | ||
| */ | ||
| function validateSmartTransactionsNetworkConfig(data) { | ||
| return (0, superstruct_1.is)(data, exports.SmartTransactionsNetworkConfigSchema); | ||
| } | ||
| exports.validateSmartTransactionsNetworkConfig = validateSmartTransactionsNetworkConfig; | ||
| //# sourceMappingURL=validators.cjs.map |
| {"version":3,"file":"validators.cjs","sourceRoot":"","sources":["../../src/featureFlags/validators.ts"],"names":[],"mappings":";;;AAAA,uDAQ+B;AAE/B,2CAAmE;AAEnE;;;;;;GAMG;AACH,SAAS,iBAAiB,CAAC,GAAW;IACpC,OAAO,IAAA,yBAAiB,EAAC,GAAG,CAAC,IAAI,IAAA,qBAAa,EAAC,GAAG,CAAC,CAAC;AACtD,CAAC;AAED;;;GAGG;AACU,QAAA,oCAAoC,GAAG,IAAA,kBAAI,EAAC;IACvD,qEAAqE;IACrE,eAAe,EAAE,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC;IACpC,yEAAyE;IACzE,YAAY,EAAE,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC;IACjC,iEAAiE;IACjE,eAAe,EAAE,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC;IACpC,qEAAqE;IACrE,mBAAmB,EAAE,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC;IACxC,mEAAmE;IACnE,gBAAgB,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IACpC,8EAA8E;IAC9E,WAAW,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC/B,2FAA2F;IAC3F,yBAAyB,EAAE,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC;IAC9C,iFAAiF;IACjF,8BAA8B,EAAE,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC;IACnD,wFAAwF;IACxF,sBAAsB,EAAE,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC;IAC3C,sEAAsE;IACtE,uCAAuC,EAAE,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC;IAC5D,gEAAgE;IAChE,0BAA0B,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC9C,0CAA0C;IAC1C,WAAW,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;CAChC,CAAC,CAAC;AAEH;;;GAGG;AACU,QAAA,yCAAyC,GAAG,IAAA,kBAAI,EAAC;IAC5D,oEAAoE;IACpE,OAAO,EAAE,IAAA,sBAAQ,EAAC,4CAAoC,CAAC;CACxD,CAAC,CAAC;AA4BH;;;;;;;;GAQG;AACH,SAAgB,qCAAqC,CACnD,IAAa;IAEb,MAAM,MAAM,GAAY,EAAE,CAAC;IAE3B,uCAAuC;IACvC,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACpE,MAAM,eAAe,GAAG,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC;QAC7D,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1D,OAAO;YACL,MAAM,EAAE,EAAE;YACV,MAAM,EAAE;gBACN,IAAI,KAAK,CACP,gCAAgC,eAAe,GAAG,WAAW,EAAE,CAChE;aACF;SACF,CAAC;KACH;IAED,MAAM,UAAU,GAAG,IAA+B,CAAC;IACnD,MAAM,WAAW,GAAwC,EAAE,CAAC;IAE5D,yEAAyE;IACzE,IAAI,UAAU,CAAC,OAAO,KAAK,SAAS,EAAE;QACpC,MAAM,CAAC,YAAY,EAAE,gBAAgB,CAAC,GAAG,IAAA,sBAAQ,EAC/C,UAAU,CAAC,OAAO,EAClB,4CAAoC,CACrC,CAAC;QACF,IAAI,YAAY,EAAE;YAChB,OAAO;gBACL,MAAM,EAAE,EAAE;gBACV,MAAM,EAAE;oBACN,IAAI,KAAK,CAAC,6BAA6B,YAAY,CAAC,OAAO,EAAE,CAAC;iBAC/D;aACF,CAAC;SACH;QACD,sDAAsD;QACtD,WAAW,CAAC,OAAO,GAAG,gBAAgB,CAAC;KACxC;IAED,8DAA8D;IAC9D,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;QACrD,IAAI,GAAG,KAAK,SAAS,EAAE;YACrB,SAAS;SACV;QAED,wBAAwB;QACxB,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE;YAC3B,MAAM,CAAC,IAAI,CACT,IAAI,KAAK,CACP,yBAAyB,GAAG,wFAAwF,CACrH,CACF,CAAC;YACF,SAAS,CAAC,uCAAuC;SAClD;QAED,wBAAwB;QACxB,IAAI,KAAK,KAAK,SAAS,EAAE;YACvB,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,GAAG,IAAA,sBAAQ,EAC3C,KAAK,EACL,4CAAoC,CACrC,CAAC;YACF,IAAI,UAAU,EAAE;gBACd,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,UAAU,GAAG,MAAM,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;gBAChE,SAAS,CAAC,uCAAuC;aAClD;YACD,oDAAoD;YACpD,WAAW,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC;SACnC;KACF;IAED,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;AACzC,CAAC;AAxED,sFAwEC;AAED;;;;;GAKG;AACH,SAAgB,sCAAsC,CACpD,IAAa;IAEb,OAAO,IAAA,gBAAE,EAAC,IAAI,EAAE,4CAAoC,CAAC,CAAC;AACxD,CAAC;AAJD,wFAIC","sourcesContent":["import {\n boolean,\n number,\n optional,\n string,\n type,\n is,\n validate,\n} from '@metamask/superstruct';\nimport type { Infer } from '@metamask/superstruct';\nimport { isCaipChainId, isStrictHexString } from '@metamask/utils';\n\n/**\n * Validates that a key is a valid chain ID (hex or CAIP-2 format).\n * Supports both EVM hex chain IDs and chain-agnostic CAIP-2 identifiers.\n *\n * @param key - The key to validate\n * @returns True if the key is a valid chain ID format\n */\nfunction isValidChainIdKey(key: string): boolean {\n return isStrictHexString(key) || isCaipChainId(key);\n}\n\n/**\n * Schema for validating per-network smart transactions configuration.\n * All fields are optional to allow partial configuration and merging with defaults.\n */\nexport const SmartTransactionsNetworkConfigSchema = type({\n /** Whether smart transactions are active for the extension client */\n extensionActive: optional(boolean()),\n /** Whether smart transactions are active for mobile clients (generic) */\n mobileActive: optional(boolean()),\n /** Whether smart transactions are active for iOS specifically */\n mobileActiveIOS: optional(boolean()),\n /** Whether smart transactions are active for Android specifically */\n mobileActiveAndroid: optional(boolean()),\n /** Expected time in seconds for a smart transaction to be mined */\n expectedDeadline: optional(number()),\n /** Maximum time in seconds before a smart transaction is considered failed */\n maxDeadline: optional(number()),\n /** Whether extension should return tx hash immediately without waiting for confirmation */\n extensionReturnTxHashAsap: optional(boolean()),\n /** Whether extension should return tx hash immediately for batch transactions */\n extensionReturnTxHashAsapBatch: optional(boolean()),\n /** Whether mobile should return tx hash immediately without waiting for confirmation */\n mobileReturnTxHashAsap: optional(boolean()),\n /** Whether extension should skip the smart transaction status page */\n extensionSkipSmartTransactionStatusPage: optional(boolean()),\n /** Polling interval in milliseconds for batch status updates */\n batchStatusPollingInterval: optional(number()),\n /** Custom sentinel URL for the network */\n sentinelUrl: optional(string()),\n});\n\n/**\n * Schema for validating the complete smart transactions feature flags configuration.\n * This includes a default configuration and optional chain-specific overrides.\n */\nexport const SmartTransactionsFeatureFlagsConfigSchema = type({\n /** Default configuration applied to all chains unless overridden */\n default: optional(SmartTransactionsNetworkConfigSchema),\n});\n\n/**\n * Type inferred from the SmartTransactionsNetworkConfigSchema\n */\nexport type SmartTransactionsNetworkConfigFromSchema = Infer<\n typeof SmartTransactionsNetworkConfigSchema\n>;\n\n/**\n * Type inferred from the SmartTransactionsFeatureFlagsConfigSchema\n */\nexport type SmartTransactionsFeatureFlagsConfigFromSchema = Infer<\n typeof SmartTransactionsFeatureFlagsConfigSchema\n>;\n\n/**\n * Result of processing feature flags with collected validation errors.\n * Uses per-chain validation: invalid chains are removed, valid ones are kept.\n */\nexport type FeatureFlagsProcessResult = {\n /** The validated configuration (may be partial if some chains were invalid) */\n config: SmartTransactionsFeatureFlagsConfigFromSchema &\n Record<string, SmartTransactionsNetworkConfigFromSchema | undefined>;\n /** Validation errors for invalid parts of the configuration */\n errors: Error[];\n};\n\n/**\n * Validates smart transactions feature flags with per-chain validation.\n * - If the input is not an object, returns empty config with error\n * - If `default` is present and invalid, returns empty config with error\n * - For each chain: if invalid, removes it and collects error; if valid, includes it\n *\n * @param data - The data to validate\n * @returns The validated config and any validation errors\n */\nexport function validateSmartTransactionsFeatureFlags(\n data: unknown,\n): FeatureFlagsProcessResult {\n const errors: Error[] = [];\n\n // Step 1: Check if it's a valid object\n if (typeof data !== 'object' || data === null || Array.isArray(data)) {\n const typeDescription = data === null ? 'null' : typeof data;\n const arraySuffix = Array.isArray(data) ? ' (array)' : '';\n return {\n config: {},\n errors: [\n new Error(\n `Expected an object, received ${typeDescription}${arraySuffix}`,\n ),\n ],\n };\n }\n\n const dataRecord = data as Record<string, unknown>;\n const validConfig: FeatureFlagsProcessResult['config'] = {};\n\n // Step 2: Validate 'default' - if present and invalid, reject everything\n if (dataRecord.default !== undefined) {\n const [defaultError, validatedDefault] = validate(\n dataRecord.default,\n SmartTransactionsNetworkConfigSchema,\n );\n if (defaultError) {\n return {\n config: {},\n errors: [\n new Error(`Invalid 'default' config: ${defaultError.message}`),\n ],\n };\n }\n // validatedDefault is properly typed from superstruct\n validConfig.default = validatedDefault;\n }\n\n // Step 3: Validate chain-specific configs, keeping valid ones\n for (const [key, value] of Object.entries(dataRecord)) {\n if (key === 'default') {\n continue;\n }\n\n // Check chain ID format\n if (!isValidChainIdKey(key)) {\n errors.push(\n new Error(\n `Invalid chain ID key \"${key}\". Expected hex string (e.g., \"0x1\") or CAIP-2 format (e.g., \"eip155:1\", \"solana:...\")`,\n ),\n );\n continue; // Skip this chain, don't add to result\n }\n\n // Validate chain config\n if (value !== undefined) {\n const [chainError, validatedChain] = validate(\n value,\n SmartTransactionsNetworkConfigSchema,\n );\n if (chainError) {\n errors.push(new Error(`Chain \"${key}\": ${chainError.message}`));\n continue; // Skip this chain, don't add to result\n }\n // validatedChain is properly typed from superstruct\n validConfig[key] = validatedChain;\n }\n }\n\n return { config: validConfig, errors };\n}\n\n/**\n * Validates that the given data conforms to the SmartTransactionsNetworkConfig schema.\n *\n * @param data - The data to validate\n * @returns True if the data is valid, false otherwise\n */\nexport function validateSmartTransactionsNetworkConfig(\n data: unknown,\n): data is SmartTransactionsNetworkConfigFromSchema {\n return is(data, SmartTransactionsNetworkConfigSchema);\n}\n"]} |
| import type { Infer } from "@metamask/superstruct"; | ||
| /** | ||
| * Schema for validating per-network smart transactions configuration. | ||
| * All fields are optional to allow partial configuration and merging with defaults. | ||
| */ | ||
| export declare const SmartTransactionsNetworkConfigSchema: import("@metamask/superstruct").Struct<{ | ||
| extensionActive?: boolean | undefined; | ||
| mobileActive?: boolean | undefined; | ||
| mobileActiveIOS?: boolean | undefined; | ||
| mobileActiveAndroid?: boolean | undefined; | ||
| expectedDeadline?: number | undefined; | ||
| maxDeadline?: number | undefined; | ||
| extensionReturnTxHashAsap?: boolean | undefined; | ||
| extensionReturnTxHashAsapBatch?: boolean | undefined; | ||
| mobileReturnTxHashAsap?: boolean | undefined; | ||
| extensionSkipSmartTransactionStatusPage?: boolean | undefined; | ||
| batchStatusPollingInterval?: number | undefined; | ||
| sentinelUrl?: string | undefined; | ||
| }, { | ||
| /** Whether smart transactions are active for the extension client */ | ||
| extensionActive: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Whether smart transactions are active for mobile clients (generic) */ | ||
| mobileActive: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Whether smart transactions are active for iOS specifically */ | ||
| mobileActiveIOS: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Whether smart transactions are active for Android specifically */ | ||
| mobileActiveAndroid: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Expected time in seconds for a smart transaction to be mined */ | ||
| expectedDeadline: import("@metamask/superstruct").Struct<number | undefined, null>; | ||
| /** Maximum time in seconds before a smart transaction is considered failed */ | ||
| maxDeadline: import("@metamask/superstruct").Struct<number | undefined, null>; | ||
| /** Whether extension should return tx hash immediately without waiting for confirmation */ | ||
| extensionReturnTxHashAsap: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Whether extension should return tx hash immediately for batch transactions */ | ||
| extensionReturnTxHashAsapBatch: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Whether mobile should return tx hash immediately without waiting for confirmation */ | ||
| mobileReturnTxHashAsap: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Whether extension should skip the smart transaction status page */ | ||
| extensionSkipSmartTransactionStatusPage: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Polling interval in milliseconds for batch status updates */ | ||
| batchStatusPollingInterval: import("@metamask/superstruct").Struct<number | undefined, null>; | ||
| /** Custom sentinel URL for the network */ | ||
| sentinelUrl: import("@metamask/superstruct").Struct<string | undefined, null>; | ||
| }>; | ||
| /** | ||
| * Schema for validating the complete smart transactions feature flags configuration. | ||
| * This includes a default configuration and optional chain-specific overrides. | ||
| */ | ||
| export declare const SmartTransactionsFeatureFlagsConfigSchema: import("@metamask/superstruct").Struct<{ | ||
| default?: { | ||
| extensionActive?: boolean | undefined; | ||
| mobileActive?: boolean | undefined; | ||
| mobileActiveIOS?: boolean | undefined; | ||
| mobileActiveAndroid?: boolean | undefined; | ||
| expectedDeadline?: number | undefined; | ||
| maxDeadline?: number | undefined; | ||
| extensionReturnTxHashAsap?: boolean | undefined; | ||
| extensionReturnTxHashAsapBatch?: boolean | undefined; | ||
| mobileReturnTxHashAsap?: boolean | undefined; | ||
| extensionSkipSmartTransactionStatusPage?: boolean | undefined; | ||
| batchStatusPollingInterval?: number | undefined; | ||
| sentinelUrl?: string | undefined; | ||
| } | undefined; | ||
| }, { | ||
| /** Default configuration applied to all chains unless overridden */ | ||
| default: import("@metamask/superstruct").Struct<{ | ||
| extensionActive?: boolean | undefined; | ||
| mobileActive?: boolean | undefined; | ||
| mobileActiveIOS?: boolean | undefined; | ||
| mobileActiveAndroid?: boolean | undefined; | ||
| expectedDeadline?: number | undefined; | ||
| maxDeadline?: number | undefined; | ||
| extensionReturnTxHashAsap?: boolean | undefined; | ||
| extensionReturnTxHashAsapBatch?: boolean | undefined; | ||
| mobileReturnTxHashAsap?: boolean | undefined; | ||
| extensionSkipSmartTransactionStatusPage?: boolean | undefined; | ||
| batchStatusPollingInterval?: number | undefined; | ||
| sentinelUrl?: string | undefined; | ||
| } | undefined, { | ||
| /** Whether smart transactions are active for the extension client */ | ||
| extensionActive: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Whether smart transactions are active for mobile clients (generic) */ | ||
| mobileActive: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Whether smart transactions are active for iOS specifically */ | ||
| mobileActiveIOS: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Whether smart transactions are active for Android specifically */ | ||
| mobileActiveAndroid: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Expected time in seconds for a smart transaction to be mined */ | ||
| expectedDeadline: import("@metamask/superstruct").Struct<number | undefined, null>; | ||
| /** Maximum time in seconds before a smart transaction is considered failed */ | ||
| maxDeadline: import("@metamask/superstruct").Struct<number | undefined, null>; | ||
| /** Whether extension should return tx hash immediately without waiting for confirmation */ | ||
| extensionReturnTxHashAsap: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Whether extension should return tx hash immediately for batch transactions */ | ||
| extensionReturnTxHashAsapBatch: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Whether mobile should return tx hash immediately without waiting for confirmation */ | ||
| mobileReturnTxHashAsap: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Whether extension should skip the smart transaction status page */ | ||
| extensionSkipSmartTransactionStatusPage: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Polling interval in milliseconds for batch status updates */ | ||
| batchStatusPollingInterval: import("@metamask/superstruct").Struct<number | undefined, null>; | ||
| /** Custom sentinel URL for the network */ | ||
| sentinelUrl: import("@metamask/superstruct").Struct<string | undefined, null>; | ||
| }>; | ||
| }>; | ||
| /** | ||
| * Type inferred from the SmartTransactionsNetworkConfigSchema | ||
| */ | ||
| export declare type SmartTransactionsNetworkConfigFromSchema = Infer<typeof SmartTransactionsNetworkConfigSchema>; | ||
| /** | ||
| * Type inferred from the SmartTransactionsFeatureFlagsConfigSchema | ||
| */ | ||
| export declare type SmartTransactionsFeatureFlagsConfigFromSchema = Infer<typeof SmartTransactionsFeatureFlagsConfigSchema>; | ||
| /** | ||
| * Result of processing feature flags with collected validation errors. | ||
| * Uses per-chain validation: invalid chains are removed, valid ones are kept. | ||
| */ | ||
| export declare type FeatureFlagsProcessResult = { | ||
| /** The validated configuration (may be partial if some chains were invalid) */ | ||
| config: SmartTransactionsFeatureFlagsConfigFromSchema & Record<string, SmartTransactionsNetworkConfigFromSchema | undefined>; | ||
| /** Validation errors for invalid parts of the configuration */ | ||
| errors: Error[]; | ||
| }; | ||
| /** | ||
| * Validates smart transactions feature flags with per-chain validation. | ||
| * - If the input is not an object, returns empty config with error | ||
| * - If `default` is present and invalid, returns empty config with error | ||
| * - For each chain: if invalid, removes it and collects error; if valid, includes it | ||
| * | ||
| * @param data - The data to validate | ||
| * @returns The validated config and any validation errors | ||
| */ | ||
| export declare function validateSmartTransactionsFeatureFlags(data: unknown): FeatureFlagsProcessResult; | ||
| /** | ||
| * Validates that the given data conforms to the SmartTransactionsNetworkConfig schema. | ||
| * | ||
| * @param data - The data to validate | ||
| * @returns True if the data is valid, false otherwise | ||
| */ | ||
| export declare function validateSmartTransactionsNetworkConfig(data: unknown): data is SmartTransactionsNetworkConfigFromSchema; | ||
| //# sourceMappingURL=validators.d.cts.map |
| {"version":3,"file":"validators.d.cts","sourceRoot":"","sources":["../../src/featureFlags/validators.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAcnD;;;GAGG;AACH,eAAO,MAAM,oCAAoC;;;;;;;;;;;;;;IAC/C,qEAAqE;;IAErE,yEAAyE;;IAEzE,iEAAiE;;IAEjE,qEAAqE;;IAErE,mEAAmE;;IAEnE,8EAA8E;;IAE9E,2FAA2F;;IAE3F,iFAAiF;;IAEjF,wFAAwF;;IAExF,sEAAsE;;IAEtE,gEAAgE;;IAEhE,0CAA0C;;EAE1C,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,yCAAyC;;;;;;;;;;;;;;;;IACpD,oEAAoE;;;;;;;;;;;;;;;QA/BpE,qEAAqE;;QAErE,yEAAyE;;QAEzE,iEAAiE;;QAEjE,qEAAqE;;QAErE,mEAAmE;;QAEnE,8EAA8E;;QAE9E,2FAA2F;;QAE3F,iFAAiF;;QAEjF,wFAAwF;;QAExF,sEAAsE;;QAEtE,gEAAgE;;QAEhE,0CAA0C;;;EAW1C,CAAC;AAEH;;GAEG;AACH,oBAAY,wCAAwC,GAAG,KAAK,CAC1D,OAAO,oCAAoC,CAC5C,CAAC;AAEF;;GAEG;AACH,oBAAY,6CAA6C,GAAG,KAAK,CAC/D,OAAO,yCAAyC,CACjD,CAAC;AAEF;;;GAGG;AACH,oBAAY,yBAAyB,GAAG;IACtC,+EAA+E;IAC/E,MAAM,EAAE,6CAA6C,GACnD,MAAM,CAAC,MAAM,EAAE,wCAAwC,GAAG,SAAS,CAAC,CAAC;IACvE,+DAA+D;IAC/D,MAAM,EAAE,KAAK,EAAE,CAAC;CACjB,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,qCAAqC,CACnD,IAAI,EAAE,OAAO,GACZ,yBAAyB,CAsE3B;AAED;;;;;GAKG;AACH,wBAAgB,sCAAsC,CACpD,IAAI,EAAE,OAAO,GACZ,IAAI,IAAI,wCAAwC,CAElD"} |
| import type { Infer } from "@metamask/superstruct"; | ||
| /** | ||
| * Schema for validating per-network smart transactions configuration. | ||
| * All fields are optional to allow partial configuration and merging with defaults. | ||
| */ | ||
| export declare const SmartTransactionsNetworkConfigSchema: import("@metamask/superstruct").Struct<{ | ||
| extensionActive?: boolean | undefined; | ||
| mobileActive?: boolean | undefined; | ||
| mobileActiveIOS?: boolean | undefined; | ||
| mobileActiveAndroid?: boolean | undefined; | ||
| expectedDeadline?: number | undefined; | ||
| maxDeadline?: number | undefined; | ||
| extensionReturnTxHashAsap?: boolean | undefined; | ||
| extensionReturnTxHashAsapBatch?: boolean | undefined; | ||
| mobileReturnTxHashAsap?: boolean | undefined; | ||
| extensionSkipSmartTransactionStatusPage?: boolean | undefined; | ||
| batchStatusPollingInterval?: number | undefined; | ||
| sentinelUrl?: string | undefined; | ||
| }, { | ||
| /** Whether smart transactions are active for the extension client */ | ||
| extensionActive: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Whether smart transactions are active for mobile clients (generic) */ | ||
| mobileActive: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Whether smart transactions are active for iOS specifically */ | ||
| mobileActiveIOS: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Whether smart transactions are active for Android specifically */ | ||
| mobileActiveAndroid: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Expected time in seconds for a smart transaction to be mined */ | ||
| expectedDeadline: import("@metamask/superstruct").Struct<number | undefined, null>; | ||
| /** Maximum time in seconds before a smart transaction is considered failed */ | ||
| maxDeadline: import("@metamask/superstruct").Struct<number | undefined, null>; | ||
| /** Whether extension should return tx hash immediately without waiting for confirmation */ | ||
| extensionReturnTxHashAsap: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Whether extension should return tx hash immediately for batch transactions */ | ||
| extensionReturnTxHashAsapBatch: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Whether mobile should return tx hash immediately without waiting for confirmation */ | ||
| mobileReturnTxHashAsap: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Whether extension should skip the smart transaction status page */ | ||
| extensionSkipSmartTransactionStatusPage: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Polling interval in milliseconds for batch status updates */ | ||
| batchStatusPollingInterval: import("@metamask/superstruct").Struct<number | undefined, null>; | ||
| /** Custom sentinel URL for the network */ | ||
| sentinelUrl: import("@metamask/superstruct").Struct<string | undefined, null>; | ||
| }>; | ||
| /** | ||
| * Schema for validating the complete smart transactions feature flags configuration. | ||
| * This includes a default configuration and optional chain-specific overrides. | ||
| */ | ||
| export declare const SmartTransactionsFeatureFlagsConfigSchema: import("@metamask/superstruct").Struct<{ | ||
| default?: { | ||
| extensionActive?: boolean | undefined; | ||
| mobileActive?: boolean | undefined; | ||
| mobileActiveIOS?: boolean | undefined; | ||
| mobileActiveAndroid?: boolean | undefined; | ||
| expectedDeadline?: number | undefined; | ||
| maxDeadline?: number | undefined; | ||
| extensionReturnTxHashAsap?: boolean | undefined; | ||
| extensionReturnTxHashAsapBatch?: boolean | undefined; | ||
| mobileReturnTxHashAsap?: boolean | undefined; | ||
| extensionSkipSmartTransactionStatusPage?: boolean | undefined; | ||
| batchStatusPollingInterval?: number | undefined; | ||
| sentinelUrl?: string | undefined; | ||
| } | undefined; | ||
| }, { | ||
| /** Default configuration applied to all chains unless overridden */ | ||
| default: import("@metamask/superstruct").Struct<{ | ||
| extensionActive?: boolean | undefined; | ||
| mobileActive?: boolean | undefined; | ||
| mobileActiveIOS?: boolean | undefined; | ||
| mobileActiveAndroid?: boolean | undefined; | ||
| expectedDeadline?: number | undefined; | ||
| maxDeadline?: number | undefined; | ||
| extensionReturnTxHashAsap?: boolean | undefined; | ||
| extensionReturnTxHashAsapBatch?: boolean | undefined; | ||
| mobileReturnTxHashAsap?: boolean | undefined; | ||
| extensionSkipSmartTransactionStatusPage?: boolean | undefined; | ||
| batchStatusPollingInterval?: number | undefined; | ||
| sentinelUrl?: string | undefined; | ||
| } | undefined, { | ||
| /** Whether smart transactions are active for the extension client */ | ||
| extensionActive: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Whether smart transactions are active for mobile clients (generic) */ | ||
| mobileActive: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Whether smart transactions are active for iOS specifically */ | ||
| mobileActiveIOS: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Whether smart transactions are active for Android specifically */ | ||
| mobileActiveAndroid: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Expected time in seconds for a smart transaction to be mined */ | ||
| expectedDeadline: import("@metamask/superstruct").Struct<number | undefined, null>; | ||
| /** Maximum time in seconds before a smart transaction is considered failed */ | ||
| maxDeadline: import("@metamask/superstruct").Struct<number | undefined, null>; | ||
| /** Whether extension should return tx hash immediately without waiting for confirmation */ | ||
| extensionReturnTxHashAsap: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Whether extension should return tx hash immediately for batch transactions */ | ||
| extensionReturnTxHashAsapBatch: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Whether mobile should return tx hash immediately without waiting for confirmation */ | ||
| mobileReturnTxHashAsap: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Whether extension should skip the smart transaction status page */ | ||
| extensionSkipSmartTransactionStatusPage: import("@metamask/superstruct").Struct<boolean | undefined, null>; | ||
| /** Polling interval in milliseconds for batch status updates */ | ||
| batchStatusPollingInterval: import("@metamask/superstruct").Struct<number | undefined, null>; | ||
| /** Custom sentinel URL for the network */ | ||
| sentinelUrl: import("@metamask/superstruct").Struct<string | undefined, null>; | ||
| }>; | ||
| }>; | ||
| /** | ||
| * Type inferred from the SmartTransactionsNetworkConfigSchema | ||
| */ | ||
| export declare type SmartTransactionsNetworkConfigFromSchema = Infer<typeof SmartTransactionsNetworkConfigSchema>; | ||
| /** | ||
| * Type inferred from the SmartTransactionsFeatureFlagsConfigSchema | ||
| */ | ||
| export declare type SmartTransactionsFeatureFlagsConfigFromSchema = Infer<typeof SmartTransactionsFeatureFlagsConfigSchema>; | ||
| /** | ||
| * Result of processing feature flags with collected validation errors. | ||
| * Uses per-chain validation: invalid chains are removed, valid ones are kept. | ||
| */ | ||
| export declare type FeatureFlagsProcessResult = { | ||
| /** The validated configuration (may be partial if some chains were invalid) */ | ||
| config: SmartTransactionsFeatureFlagsConfigFromSchema & Record<string, SmartTransactionsNetworkConfigFromSchema | undefined>; | ||
| /** Validation errors for invalid parts of the configuration */ | ||
| errors: Error[]; | ||
| }; | ||
| /** | ||
| * Validates smart transactions feature flags with per-chain validation. | ||
| * - If the input is not an object, returns empty config with error | ||
| * - If `default` is present and invalid, returns empty config with error | ||
| * - For each chain: if invalid, removes it and collects error; if valid, includes it | ||
| * | ||
| * @param data - The data to validate | ||
| * @returns The validated config and any validation errors | ||
| */ | ||
| export declare function validateSmartTransactionsFeatureFlags(data: unknown): FeatureFlagsProcessResult; | ||
| /** | ||
| * Validates that the given data conforms to the SmartTransactionsNetworkConfig schema. | ||
| * | ||
| * @param data - The data to validate | ||
| * @returns True if the data is valid, false otherwise | ||
| */ | ||
| export declare function validateSmartTransactionsNetworkConfig(data: unknown): data is SmartTransactionsNetworkConfigFromSchema; | ||
| //# sourceMappingURL=validators.d.mts.map |
| {"version":3,"file":"validators.d.mts","sourceRoot":"","sources":["../../src/featureFlags/validators.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAcnD;;;GAGG;AACH,eAAO,MAAM,oCAAoC;;;;;;;;;;;;;;IAC/C,qEAAqE;;IAErE,yEAAyE;;IAEzE,iEAAiE;;IAEjE,qEAAqE;;IAErE,mEAAmE;;IAEnE,8EAA8E;;IAE9E,2FAA2F;;IAE3F,iFAAiF;;IAEjF,wFAAwF;;IAExF,sEAAsE;;IAEtE,gEAAgE;;IAEhE,0CAA0C;;EAE1C,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,yCAAyC;;;;;;;;;;;;;;;;IACpD,oEAAoE;;;;;;;;;;;;;;;QA/BpE,qEAAqE;;QAErE,yEAAyE;;QAEzE,iEAAiE;;QAEjE,qEAAqE;;QAErE,mEAAmE;;QAEnE,8EAA8E;;QAE9E,2FAA2F;;QAE3F,iFAAiF;;QAEjF,wFAAwF;;QAExF,sEAAsE;;QAEtE,gEAAgE;;QAEhE,0CAA0C;;;EAW1C,CAAC;AAEH;;GAEG;AACH,oBAAY,wCAAwC,GAAG,KAAK,CAC1D,OAAO,oCAAoC,CAC5C,CAAC;AAEF;;GAEG;AACH,oBAAY,6CAA6C,GAAG,KAAK,CAC/D,OAAO,yCAAyC,CACjD,CAAC;AAEF;;;GAGG;AACH,oBAAY,yBAAyB,GAAG;IACtC,+EAA+E;IAC/E,MAAM,EAAE,6CAA6C,GACnD,MAAM,CAAC,MAAM,EAAE,wCAAwC,GAAG,SAAS,CAAC,CAAC;IACvE,+DAA+D;IAC/D,MAAM,EAAE,KAAK,EAAE,CAAC;CACjB,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,qCAAqC,CACnD,IAAI,EAAE,OAAO,GACZ,yBAAyB,CAsE3B;AAED;;;;;GAKG;AACH,wBAAgB,sCAAsC,CACpD,IAAI,EAAE,OAAO,GACZ,IAAI,IAAI,wCAAwC,CAElD"} |
| import { boolean, number, optional, string, type, is, validate } from "@metamask/superstruct"; | ||
| import { isCaipChainId, isStrictHexString } from "@metamask/utils"; | ||
| /** | ||
| * Validates that a key is a valid chain ID (hex or CAIP-2 format). | ||
| * Supports both EVM hex chain IDs and chain-agnostic CAIP-2 identifiers. | ||
| * | ||
| * @param key - The key to validate | ||
| * @returns True if the key is a valid chain ID format | ||
| */ | ||
| function isValidChainIdKey(key) { | ||
| return isStrictHexString(key) || isCaipChainId(key); | ||
| } | ||
| /** | ||
| * Schema for validating per-network smart transactions configuration. | ||
| * All fields are optional to allow partial configuration and merging with defaults. | ||
| */ | ||
| export const SmartTransactionsNetworkConfigSchema = type({ | ||
| /** Whether smart transactions are active for the extension client */ | ||
| extensionActive: optional(boolean()), | ||
| /** Whether smart transactions are active for mobile clients (generic) */ | ||
| mobileActive: optional(boolean()), | ||
| /** Whether smart transactions are active for iOS specifically */ | ||
| mobileActiveIOS: optional(boolean()), | ||
| /** Whether smart transactions are active for Android specifically */ | ||
| mobileActiveAndroid: optional(boolean()), | ||
| /** Expected time in seconds for a smart transaction to be mined */ | ||
| expectedDeadline: optional(number()), | ||
| /** Maximum time in seconds before a smart transaction is considered failed */ | ||
| maxDeadline: optional(number()), | ||
| /** Whether extension should return tx hash immediately without waiting for confirmation */ | ||
| extensionReturnTxHashAsap: optional(boolean()), | ||
| /** Whether extension should return tx hash immediately for batch transactions */ | ||
| extensionReturnTxHashAsapBatch: optional(boolean()), | ||
| /** Whether mobile should return tx hash immediately without waiting for confirmation */ | ||
| mobileReturnTxHashAsap: optional(boolean()), | ||
| /** Whether extension should skip the smart transaction status page */ | ||
| extensionSkipSmartTransactionStatusPage: optional(boolean()), | ||
| /** Polling interval in milliseconds for batch status updates */ | ||
| batchStatusPollingInterval: optional(number()), | ||
| /** Custom sentinel URL for the network */ | ||
| sentinelUrl: optional(string()), | ||
| }); | ||
| /** | ||
| * Schema for validating the complete smart transactions feature flags configuration. | ||
| * This includes a default configuration and optional chain-specific overrides. | ||
| */ | ||
| export const SmartTransactionsFeatureFlagsConfigSchema = type({ | ||
| /** Default configuration applied to all chains unless overridden */ | ||
| default: optional(SmartTransactionsNetworkConfigSchema), | ||
| }); | ||
| /** | ||
| * Validates smart transactions feature flags with per-chain validation. | ||
| * - If the input is not an object, returns empty config with error | ||
| * - If `default` is present and invalid, returns empty config with error | ||
| * - For each chain: if invalid, removes it and collects error; if valid, includes it | ||
| * | ||
| * @param data - The data to validate | ||
| * @returns The validated config and any validation errors | ||
| */ | ||
| export function validateSmartTransactionsFeatureFlags(data) { | ||
| const errors = []; | ||
| // Step 1: Check if it's a valid object | ||
| if (typeof data !== 'object' || data === null || Array.isArray(data)) { | ||
| const typeDescription = data === null ? 'null' : typeof data; | ||
| const arraySuffix = Array.isArray(data) ? ' (array)' : ''; | ||
| return { | ||
| config: {}, | ||
| errors: [ | ||
| new Error(`Expected an object, received ${typeDescription}${arraySuffix}`), | ||
| ], | ||
| }; | ||
| } | ||
| const dataRecord = data; | ||
| const validConfig = {}; | ||
| // Step 2: Validate 'default' - if present and invalid, reject everything | ||
| if (dataRecord.default !== undefined) { | ||
| const [defaultError, validatedDefault] = validate(dataRecord.default, SmartTransactionsNetworkConfigSchema); | ||
| if (defaultError) { | ||
| return { | ||
| config: {}, | ||
| errors: [ | ||
| new Error(`Invalid 'default' config: ${defaultError.message}`), | ||
| ], | ||
| }; | ||
| } | ||
| // validatedDefault is properly typed from superstruct | ||
| validConfig.default = validatedDefault; | ||
| } | ||
| // Step 3: Validate chain-specific configs, keeping valid ones | ||
| for (const [key, value] of Object.entries(dataRecord)) { | ||
| if (key === 'default') { | ||
| continue; | ||
| } | ||
| // Check chain ID format | ||
| if (!isValidChainIdKey(key)) { | ||
| errors.push(new Error(`Invalid chain ID key "${key}". Expected hex string (e.g., "0x1") or CAIP-2 format (e.g., "eip155:1", "solana:...")`)); | ||
| continue; // Skip this chain, don't add to result | ||
| } | ||
| // Validate chain config | ||
| if (value !== undefined) { | ||
| const [chainError, validatedChain] = validate(value, SmartTransactionsNetworkConfigSchema); | ||
| if (chainError) { | ||
| errors.push(new Error(`Chain "${key}": ${chainError.message}`)); | ||
| continue; // Skip this chain, don't add to result | ||
| } | ||
| // validatedChain is properly typed from superstruct | ||
| validConfig[key] = validatedChain; | ||
| } | ||
| } | ||
| return { config: validConfig, errors }; | ||
| } | ||
| /** | ||
| * Validates that the given data conforms to the SmartTransactionsNetworkConfig schema. | ||
| * | ||
| * @param data - The data to validate | ||
| * @returns True if the data is valid, false otherwise | ||
| */ | ||
| export function validateSmartTransactionsNetworkConfig(data) { | ||
| return is(data, SmartTransactionsNetworkConfigSchema); | ||
| } | ||
| //# sourceMappingURL=validators.mjs.map |
| {"version":3,"file":"validators.mjs","sourceRoot":"","sources":["../../src/featureFlags/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,MAAM,EACN,QAAQ,EACR,MAAM,EACN,IAAI,EACJ,EAAE,EACF,QAAQ,EACT,8BAA8B;AAE/B,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,wBAAwB;AAEnE;;;;;;GAMG;AACH,SAAS,iBAAiB,CAAC,GAAW;IACpC,OAAO,iBAAiB,CAAC,GAAG,CAAC,IAAI,aAAa,CAAC,GAAG,CAAC,CAAC;AACtD,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,oCAAoC,GAAG,IAAI,CAAC;IACvD,qEAAqE;IACrE,eAAe,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;IACpC,yEAAyE;IACzE,YAAY,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;IACjC,iEAAiE;IACjE,eAAe,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;IACpC,qEAAqE;IACrE,mBAAmB,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;IACxC,mEAAmE;IACnE,gBAAgB,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IACpC,8EAA8E;IAC9E,WAAW,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC/B,2FAA2F;IAC3F,yBAAyB,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC9C,iFAAiF;IACjF,8BAA8B,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;IACnD,wFAAwF;IACxF,sBAAsB,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC3C,sEAAsE;IACtE,uCAAuC,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC5D,gEAAgE;IAChE,0BAA0B,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC9C,0CAA0C;IAC1C,WAAW,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;CAChC,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,yCAAyC,GAAG,IAAI,CAAC;IAC5D,oEAAoE;IACpE,OAAO,EAAE,QAAQ,CAAC,oCAAoC,CAAC;CACxD,CAAC,CAAC;AA4BH;;;;;;;;GAQG;AACH,MAAM,UAAU,qCAAqC,CACnD,IAAa;IAEb,MAAM,MAAM,GAAY,EAAE,CAAC;IAE3B,uCAAuC;IACvC,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACpE,MAAM,eAAe,GAAG,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC;QAC7D,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1D,OAAO;YACL,MAAM,EAAE,EAAE;YACV,MAAM,EAAE;gBACN,IAAI,KAAK,CACP,gCAAgC,eAAe,GAAG,WAAW,EAAE,CAChE;aACF;SACF,CAAC;KACH;IAED,MAAM,UAAU,GAAG,IAA+B,CAAC;IACnD,MAAM,WAAW,GAAwC,EAAE,CAAC;IAE5D,yEAAyE;IACzE,IAAI,UAAU,CAAC,OAAO,KAAK,SAAS,EAAE;QACpC,MAAM,CAAC,YAAY,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAC/C,UAAU,CAAC,OAAO,EAClB,oCAAoC,CACrC,CAAC;QACF,IAAI,YAAY,EAAE;YAChB,OAAO;gBACL,MAAM,EAAE,EAAE;gBACV,MAAM,EAAE;oBACN,IAAI,KAAK,CAAC,6BAA6B,YAAY,CAAC,OAAO,EAAE,CAAC;iBAC/D;aACF,CAAC;SACH;QACD,sDAAsD;QACtD,WAAW,CAAC,OAAO,GAAG,gBAAgB,CAAC;KACxC;IAED,8DAA8D;IAC9D,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;QACrD,IAAI,GAAG,KAAK,SAAS,EAAE;YACrB,SAAS;SACV;QAED,wBAAwB;QACxB,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE;YAC3B,MAAM,CAAC,IAAI,CACT,IAAI,KAAK,CACP,yBAAyB,GAAG,wFAAwF,CACrH,CACF,CAAC;YACF,SAAS,CAAC,uCAAuC;SAClD;QAED,wBAAwB;QACxB,IAAI,KAAK,KAAK,SAAS,EAAE;YACvB,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,GAAG,QAAQ,CAC3C,KAAK,EACL,oCAAoC,CACrC,CAAC;YACF,IAAI,UAAU,EAAE;gBACd,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,UAAU,GAAG,MAAM,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;gBAChE,SAAS,CAAC,uCAAuC;aAClD;YACD,oDAAoD;YACpD,WAAW,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC;SACnC;KACF;IAED,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;AACzC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sCAAsC,CACpD,IAAa;IAEb,OAAO,EAAE,CAAC,IAAI,EAAE,oCAAoC,CAAC,CAAC;AACxD,CAAC","sourcesContent":["import {\n boolean,\n number,\n optional,\n string,\n type,\n is,\n validate,\n} from '@metamask/superstruct';\nimport type { Infer } from '@metamask/superstruct';\nimport { isCaipChainId, isStrictHexString } from '@metamask/utils';\n\n/**\n * Validates that a key is a valid chain ID (hex or CAIP-2 format).\n * Supports both EVM hex chain IDs and chain-agnostic CAIP-2 identifiers.\n *\n * @param key - The key to validate\n * @returns True if the key is a valid chain ID format\n */\nfunction isValidChainIdKey(key: string): boolean {\n return isStrictHexString(key) || isCaipChainId(key);\n}\n\n/**\n * Schema for validating per-network smart transactions configuration.\n * All fields are optional to allow partial configuration and merging with defaults.\n */\nexport const SmartTransactionsNetworkConfigSchema = type({\n /** Whether smart transactions are active for the extension client */\n extensionActive: optional(boolean()),\n /** Whether smart transactions are active for mobile clients (generic) */\n mobileActive: optional(boolean()),\n /** Whether smart transactions are active for iOS specifically */\n mobileActiveIOS: optional(boolean()),\n /** Whether smart transactions are active for Android specifically */\n mobileActiveAndroid: optional(boolean()),\n /** Expected time in seconds for a smart transaction to be mined */\n expectedDeadline: optional(number()),\n /** Maximum time in seconds before a smart transaction is considered failed */\n maxDeadline: optional(number()),\n /** Whether extension should return tx hash immediately without waiting for confirmation */\n extensionReturnTxHashAsap: optional(boolean()),\n /** Whether extension should return tx hash immediately for batch transactions */\n extensionReturnTxHashAsapBatch: optional(boolean()),\n /** Whether mobile should return tx hash immediately without waiting for confirmation */\n mobileReturnTxHashAsap: optional(boolean()),\n /** Whether extension should skip the smart transaction status page */\n extensionSkipSmartTransactionStatusPage: optional(boolean()),\n /** Polling interval in milliseconds for batch status updates */\n batchStatusPollingInterval: optional(number()),\n /** Custom sentinel URL for the network */\n sentinelUrl: optional(string()),\n});\n\n/**\n * Schema for validating the complete smart transactions feature flags configuration.\n * This includes a default configuration and optional chain-specific overrides.\n */\nexport const SmartTransactionsFeatureFlagsConfigSchema = type({\n /** Default configuration applied to all chains unless overridden */\n default: optional(SmartTransactionsNetworkConfigSchema),\n});\n\n/**\n * Type inferred from the SmartTransactionsNetworkConfigSchema\n */\nexport type SmartTransactionsNetworkConfigFromSchema = Infer<\n typeof SmartTransactionsNetworkConfigSchema\n>;\n\n/**\n * Type inferred from the SmartTransactionsFeatureFlagsConfigSchema\n */\nexport type SmartTransactionsFeatureFlagsConfigFromSchema = Infer<\n typeof SmartTransactionsFeatureFlagsConfigSchema\n>;\n\n/**\n * Result of processing feature flags with collected validation errors.\n * Uses per-chain validation: invalid chains are removed, valid ones are kept.\n */\nexport type FeatureFlagsProcessResult = {\n /** The validated configuration (may be partial if some chains were invalid) */\n config: SmartTransactionsFeatureFlagsConfigFromSchema &\n Record<string, SmartTransactionsNetworkConfigFromSchema | undefined>;\n /** Validation errors for invalid parts of the configuration */\n errors: Error[];\n};\n\n/**\n * Validates smart transactions feature flags with per-chain validation.\n * - If the input is not an object, returns empty config with error\n * - If `default` is present and invalid, returns empty config with error\n * - For each chain: if invalid, removes it and collects error; if valid, includes it\n *\n * @param data - The data to validate\n * @returns The validated config and any validation errors\n */\nexport function validateSmartTransactionsFeatureFlags(\n data: unknown,\n): FeatureFlagsProcessResult {\n const errors: Error[] = [];\n\n // Step 1: Check if it's a valid object\n if (typeof data !== 'object' || data === null || Array.isArray(data)) {\n const typeDescription = data === null ? 'null' : typeof data;\n const arraySuffix = Array.isArray(data) ? ' (array)' : '';\n return {\n config: {},\n errors: [\n new Error(\n `Expected an object, received ${typeDescription}${arraySuffix}`,\n ),\n ],\n };\n }\n\n const dataRecord = data as Record<string, unknown>;\n const validConfig: FeatureFlagsProcessResult['config'] = {};\n\n // Step 2: Validate 'default' - if present and invalid, reject everything\n if (dataRecord.default !== undefined) {\n const [defaultError, validatedDefault] = validate(\n dataRecord.default,\n SmartTransactionsNetworkConfigSchema,\n );\n if (defaultError) {\n return {\n config: {},\n errors: [\n new Error(`Invalid 'default' config: ${defaultError.message}`),\n ],\n };\n }\n // validatedDefault is properly typed from superstruct\n validConfig.default = validatedDefault;\n }\n\n // Step 3: Validate chain-specific configs, keeping valid ones\n for (const [key, value] of Object.entries(dataRecord)) {\n if (key === 'default') {\n continue;\n }\n\n // Check chain ID format\n if (!isValidChainIdKey(key)) {\n errors.push(\n new Error(\n `Invalid chain ID key \"${key}\". Expected hex string (e.g., \"0x1\") or CAIP-2 format (e.g., \"eip155:1\", \"solana:...\")`,\n ),\n );\n continue; // Skip this chain, don't add to result\n }\n\n // Validate chain config\n if (value !== undefined) {\n const [chainError, validatedChain] = validate(\n value,\n SmartTransactionsNetworkConfigSchema,\n );\n if (chainError) {\n errors.push(new Error(`Chain \"${key}\": ${chainError.message}`));\n continue; // Skip this chain, don't add to result\n }\n // validatedChain is properly typed from superstruct\n validConfig[key] = validatedChain;\n }\n }\n\n return { config: validConfig, errors };\n}\n\n/**\n * Validates that the given data conforms to the SmartTransactionsNetworkConfig schema.\n *\n * @param data - The data to validate\n * @returns True if the data is valid, false otherwise\n */\nexport function validateSmartTransactionsNetworkConfig(\n data: unknown,\n): data is SmartTransactionsNetworkConfigFromSchema {\n return is(data, SmartTransactionsNetworkConfigSchema);\n}\n"]} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.selectSmartTransactionsFeatureFlagsForChain = exports.selectSmartTransactionsFeatureFlags = void 0; | ||
| const reselect_1 = require("reselect"); | ||
| const feature_flags_1 = require("./featureFlags/feature-flags.cjs"); | ||
| /** | ||
| * Creates a typed selector for smart transactions feature flags | ||
| */ | ||
| const createSelector = reselect_1.createSelector.withTypes(); | ||
| /** | ||
| * Selects and validates the smart transactions feature flags from state. | ||
| * Returns the validated configuration or defaults if invalid. | ||
| * If you need to get the feature flags for a specific chain, use `selectSmartTransactionsFeatureFlagsForChain`. | ||
| * | ||
| * @param state - The state containing remoteFeatureFlags.smartTransactionsNetworks | ||
| * @returns The validated smart transactions feature flags configuration | ||
| * @example | ||
| * ```ts | ||
| * // In a React component | ||
| * const featureFlags = useSelector(selectSmartTransactionsFeatureFlags); | ||
| * | ||
| * // Or with reselect composition | ||
| * const selectIsExtensionActive = createSelector( | ||
| * selectSmartTransactionsFeatureFlags, | ||
| * (flags) => flags.default?.extensionActive ?? false | ||
| * ); | ||
| * ``` | ||
| */ | ||
| exports.selectSmartTransactionsFeatureFlags = createSelector([(state) => { var _a; return (_a = state.remoteFeatureFlags) === null || _a === void 0 ? void 0 : _a.smartTransactionsNetworks; }], (rawFeatureFlags) => (0, feature_flags_1.processSmartTransactionsFeatureFlags)(rawFeatureFlags)); | ||
| /** | ||
| * Selects the merged feature flags configuration for a specific chain. | ||
| * Chain-specific configuration takes precedence over default configuration. | ||
| * | ||
| * For EVM chains, the chain ID is normalized to hex format before lookup. | ||
| * This means both '0x1' and 'eip155:1' will resolve to the same configuration. | ||
| * Non-EVM chains (e.g., Solana, Bitcoin) use exact match. | ||
| * | ||
| * @param _state - The state containing remoteFeatureFlags.smartTransactionsNetworks | ||
| * @param chainId - The chain ID to get configuration for. | ||
| * Supports both hex (e.g., "0x1") and CAIP-2 format (e.g., "eip155:1", "solana:...") | ||
| * @returns The merged configuration for the specified chain | ||
| * @example | ||
| * ```ts | ||
| * // Both resolve to the same config (normalized to 0x1) | ||
| * const chainConfig = useSelector((state) => | ||
| * selectSmartTransactionsFeatureFlagsForChain(state, '0x1') | ||
| * ); | ||
| * const sameConfig = useSelector((state) => | ||
| * selectSmartTransactionsFeatureFlagsForChain(state, 'eip155:1') | ||
| * ); | ||
| * | ||
| * // Non-EVM uses exact match | ||
| * const solanaConfig = useSelector((state) => | ||
| * selectSmartTransactionsFeatureFlagsForChain(state, 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp') | ||
| * ); | ||
| * | ||
| * if (chainConfig.extensionActive) { | ||
| * // Smart transactions are enabled | ||
| * } | ||
| * ``` | ||
| */ | ||
| exports.selectSmartTransactionsFeatureFlagsForChain = createSelector([ | ||
| exports.selectSmartTransactionsFeatureFlags, | ||
| (_state, chainId) => chainId, | ||
| ], (featureFlags, chainId) => (0, feature_flags_1.getSmartTransactionsFeatureFlagsForChain)(featureFlags, chainId)); | ||
| //# sourceMappingURL=selectors.cjs.map |
| {"version":3,"file":"selectors.cjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":";;;AACA,uCAA6D;AAE7D,oEAGsC;AAgBtC;;GAEG;AACH,MAAM,cAAc,GAClB,yBAAe,CAAC,SAAS,EAAsC,CAAC;AAElE;;;;;;;;;;;;;;;;;;GAkBG;AACU,QAAA,mCAAmC,GAAG,cAAc,CAC/D,CAAC,CAAC,KAAK,EAAE,EAAE,WAAC,OAAA,MAAA,KAAK,CAAC,kBAAkB,0CAAE,yBAAyB,CAAA,EAAA,CAAC,EAChE,CAAC,eAAe,EAAuC,EAAE,CACvD,IAAA,oDAAoC,EAAC,eAAe,CAAC,CACxD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACU,QAAA,2CAA2C,GAAG,cAAc,CACvE;IACE,2CAAmC;IACnC,CAAC,MAA0C,EAAE,OAA0B,EAAE,EAAE,CACzE,OAAO;CACV,EACD,CAAC,YAAY,EAAE,OAAO,EAAkC,EAAE,CACxD,IAAA,wDAAwC,EAAC,YAAY,EAAE,OAAO,CAAC,CAClE,CAAC","sourcesContent":["import type { CaipChainId, Hex } from '@metamask/utils';\nimport { createSelector as createSelector_ } from 'reselect';\n\nimport {\n processSmartTransactionsFeatureFlags,\n getSmartTransactionsFeatureFlagsForChain,\n} from './featureFlags/feature-flags';\nimport type {\n SmartTransactionsFeatureFlagsConfig,\n SmartTransactionsNetworkConfig,\n} from './types';\n\n/**\n * The state shape expected by the smart transactions feature flag selectors.\n * This represents the relevant portion of the remote feature flag controller state.\n */\nexport type SmartTransactionsFeatureFlagsState = {\n remoteFeatureFlags?: {\n smartTransactionsNetworks?: unknown;\n };\n};\n\n/**\n * Creates a typed selector for smart transactions feature flags\n */\nconst createSelector =\n createSelector_.withTypes<SmartTransactionsFeatureFlagsState>();\n\n/**\n * Selects and validates the smart transactions feature flags from state.\n * Returns the validated configuration or defaults if invalid.\n * If you need to get the feature flags for a specific chain, use `selectSmartTransactionsFeatureFlagsForChain`.\n *\n * @param state - The state containing remoteFeatureFlags.smartTransactionsNetworks\n * @returns The validated smart transactions feature flags configuration\n * @example\n * ```ts\n * // In a React component\n * const featureFlags = useSelector(selectSmartTransactionsFeatureFlags);\n *\n * // Or with reselect composition\n * const selectIsExtensionActive = createSelector(\n * selectSmartTransactionsFeatureFlags,\n * (flags) => flags.default?.extensionActive ?? false\n * );\n * ```\n */\nexport const selectSmartTransactionsFeatureFlags = createSelector(\n [(state) => state.remoteFeatureFlags?.smartTransactionsNetworks],\n (rawFeatureFlags): SmartTransactionsFeatureFlagsConfig =>\n processSmartTransactionsFeatureFlags(rawFeatureFlags),\n);\n\n/**\n * Selects the merged feature flags configuration for a specific chain.\n * Chain-specific configuration takes precedence over default configuration.\n *\n * For EVM chains, the chain ID is normalized to hex format before lookup.\n * This means both '0x1' and 'eip155:1' will resolve to the same configuration.\n * Non-EVM chains (e.g., Solana, Bitcoin) use exact match.\n *\n * @param _state - The state containing remoteFeatureFlags.smartTransactionsNetworks\n * @param chainId - The chain ID to get configuration for.\n * Supports both hex (e.g., \"0x1\") and CAIP-2 format (e.g., \"eip155:1\", \"solana:...\")\n * @returns The merged configuration for the specified chain\n * @example\n * ```ts\n * // Both resolve to the same config (normalized to 0x1)\n * const chainConfig = useSelector((state) =>\n * selectSmartTransactionsFeatureFlagsForChain(state, '0x1')\n * );\n * const sameConfig = useSelector((state) =>\n * selectSmartTransactionsFeatureFlagsForChain(state, 'eip155:1')\n * );\n *\n * // Non-EVM uses exact match\n * const solanaConfig = useSelector((state) =>\n * selectSmartTransactionsFeatureFlagsForChain(state, 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp')\n * );\n *\n * if (chainConfig.extensionActive) {\n * // Smart transactions are enabled\n * }\n * ```\n */\nexport const selectSmartTransactionsFeatureFlagsForChain = createSelector(\n [\n selectSmartTransactionsFeatureFlags,\n (_state: SmartTransactionsFeatureFlagsState, chainId: Hex | CaipChainId) =>\n chainId,\n ],\n (featureFlags, chainId): SmartTransactionsNetworkConfig =>\n getSmartTransactionsFeatureFlagsForChain(featureFlags, chainId),\n);\n"]} |
| import type { CaipChainId, Hex } from "@metamask/utils"; | ||
| import type { SmartTransactionsFeatureFlagsConfig } from "./types.cjs"; | ||
| /** | ||
| * The state shape expected by the smart transactions feature flag selectors. | ||
| * This represents the relevant portion of the remote feature flag controller state. | ||
| */ | ||
| export declare type SmartTransactionsFeatureFlagsState = { | ||
| remoteFeatureFlags?: { | ||
| smartTransactionsNetworks?: unknown; | ||
| }; | ||
| }; | ||
| /** | ||
| * Selects and validates the smart transactions feature flags from state. | ||
| * Returns the validated configuration or defaults if invalid. | ||
| * If you need to get the feature flags for a specific chain, use `selectSmartTransactionsFeatureFlagsForChain`. | ||
| * | ||
| * @param state - The state containing remoteFeatureFlags.smartTransactionsNetworks | ||
| * @returns The validated smart transactions feature flags configuration | ||
| * @example | ||
| * ```ts | ||
| * // In a React component | ||
| * const featureFlags = useSelector(selectSmartTransactionsFeatureFlags); | ||
| * | ||
| * // Or with reselect composition | ||
| * const selectIsExtensionActive = createSelector( | ||
| * selectSmartTransactionsFeatureFlags, | ||
| * (flags) => flags.default?.extensionActive ?? false | ||
| * ); | ||
| * ``` | ||
| */ | ||
| export declare const selectSmartTransactionsFeatureFlags: ((state: SmartTransactionsFeatureFlagsState) => SmartTransactionsFeatureFlagsConfig) & { | ||
| clearCache: () => void; | ||
| resultsCount: () => number; | ||
| resetResultsCount: () => void; | ||
| } & { | ||
| resultFunc: (resultFuncArgs_0: any) => SmartTransactionsFeatureFlagsConfig; | ||
| memoizedResultFunc: ((resultFuncArgs_0: any) => SmartTransactionsFeatureFlagsConfig) & { | ||
| clearCache: () => void; | ||
| resultsCount: () => number; | ||
| resetResultsCount: () => void; | ||
| }; | ||
| lastResult: () => SmartTransactionsFeatureFlagsConfig; | ||
| dependencies: [(state: SmartTransactionsFeatureFlagsState) => unknown]; | ||
| recomputations: () => number; | ||
| resetRecomputations: () => void; | ||
| dependencyRecomputations: () => number; | ||
| resetDependencyRecomputations: () => void; | ||
| } & { | ||
| memoize: typeof import("reselect").weakMapMemoize; | ||
| argsMemoize: typeof import("reselect").weakMapMemoize; | ||
| }; | ||
| /** | ||
| * Selects the merged feature flags configuration for a specific chain. | ||
| * Chain-specific configuration takes precedence over default configuration. | ||
| * | ||
| * For EVM chains, the chain ID is normalized to hex format before lookup. | ||
| * This means both '0x1' and 'eip155:1' will resolve to the same configuration. | ||
| * Non-EVM chains (e.g., Solana, Bitcoin) use exact match. | ||
| * | ||
| * @param _state - The state containing remoteFeatureFlags.smartTransactionsNetworks | ||
| * @param chainId - The chain ID to get configuration for. | ||
| * Supports both hex (e.g., "0x1") and CAIP-2 format (e.g., "eip155:1", "solana:...") | ||
| * @returns The merged configuration for the specified chain | ||
| * @example | ||
| * ```ts | ||
| * // Both resolve to the same config (normalized to 0x1) | ||
| * const chainConfig = useSelector((state) => | ||
| * selectSmartTransactionsFeatureFlagsForChain(state, '0x1') | ||
| * ); | ||
| * const sameConfig = useSelector((state) => | ||
| * selectSmartTransactionsFeatureFlagsForChain(state, 'eip155:1') | ||
| * ); | ||
| * | ||
| * // Non-EVM uses exact match | ||
| * const solanaConfig = useSelector((state) => | ||
| * selectSmartTransactionsFeatureFlagsForChain(state, 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp') | ||
| * ); | ||
| * | ||
| * if (chainConfig.extensionActive) { | ||
| * // Smart transactions are enabled | ||
| * } | ||
| * ``` | ||
| */ | ||
| export declare const selectSmartTransactionsFeatureFlagsForChain: ((state: SmartTransactionsFeatureFlagsState, chainId: `0x${string}` | `${string}:${string}`) => { | ||
| extensionActive?: boolean | undefined; | ||
| mobileActive?: boolean | undefined; | ||
| mobileActiveIOS?: boolean | undefined; | ||
| mobileActiveAndroid?: boolean | undefined; | ||
| expectedDeadline?: number | undefined; | ||
| maxDeadline?: number | undefined; | ||
| extensionReturnTxHashAsap?: boolean | undefined; | ||
| extensionReturnTxHashAsapBatch?: boolean | undefined; | ||
| mobileReturnTxHashAsap?: boolean | undefined; | ||
| extensionSkipSmartTransactionStatusPage?: boolean | undefined; | ||
| batchStatusPollingInterval?: number | undefined; | ||
| sentinelUrl?: string | undefined; | ||
| }) & { | ||
| clearCache: () => void; | ||
| resultsCount: () => number; | ||
| resetResultsCount: () => void; | ||
| } & { | ||
| resultFunc: (resultFuncArgs_0: SmartTransactionsFeatureFlagsConfig, resultFuncArgs_1: `0x${string}` | `${string}:${string}`) => { | ||
| extensionActive?: boolean | undefined; | ||
| mobileActive?: boolean | undefined; | ||
| mobileActiveIOS?: boolean | undefined; | ||
| mobileActiveAndroid?: boolean | undefined; | ||
| expectedDeadline?: number | undefined; | ||
| maxDeadline?: number | undefined; | ||
| extensionReturnTxHashAsap?: boolean | undefined; | ||
| extensionReturnTxHashAsapBatch?: boolean | undefined; | ||
| mobileReturnTxHashAsap?: boolean | undefined; | ||
| extensionSkipSmartTransactionStatusPage?: boolean | undefined; | ||
| batchStatusPollingInterval?: number | undefined; | ||
| sentinelUrl?: string | undefined; | ||
| }; | ||
| memoizedResultFunc: ((resultFuncArgs_0: SmartTransactionsFeatureFlagsConfig, resultFuncArgs_1: `0x${string}` | `${string}:${string}`) => { | ||
| extensionActive?: boolean | undefined; | ||
| mobileActive?: boolean | undefined; | ||
| mobileActiveIOS?: boolean | undefined; | ||
| mobileActiveAndroid?: boolean | undefined; | ||
| expectedDeadline?: number | undefined; | ||
| maxDeadline?: number | undefined; | ||
| extensionReturnTxHashAsap?: boolean | undefined; | ||
| extensionReturnTxHashAsapBatch?: boolean | undefined; | ||
| mobileReturnTxHashAsap?: boolean | undefined; | ||
| extensionSkipSmartTransactionStatusPage?: boolean | undefined; | ||
| batchStatusPollingInterval?: number | undefined; | ||
| sentinelUrl?: string | undefined; | ||
| }) & { | ||
| clearCache: () => void; | ||
| resultsCount: () => number; | ||
| resetResultsCount: () => void; | ||
| }; | ||
| lastResult: () => { | ||
| extensionActive?: boolean | undefined; | ||
| mobileActive?: boolean | undefined; | ||
| mobileActiveIOS?: boolean | undefined; | ||
| mobileActiveAndroid?: boolean | undefined; | ||
| expectedDeadline?: number | undefined; | ||
| maxDeadline?: number | undefined; | ||
| extensionReturnTxHashAsap?: boolean | undefined; | ||
| extensionReturnTxHashAsapBatch?: boolean | undefined; | ||
| mobileReturnTxHashAsap?: boolean | undefined; | ||
| extensionSkipSmartTransactionStatusPage?: boolean | undefined; | ||
| batchStatusPollingInterval?: number | undefined; | ||
| sentinelUrl?: string | undefined; | ||
| }; | ||
| dependencies: [((state: SmartTransactionsFeatureFlagsState) => SmartTransactionsFeatureFlagsConfig) & { | ||
| clearCache: () => void; | ||
| resultsCount: () => number; | ||
| resetResultsCount: () => void; | ||
| } & { | ||
| resultFunc: (resultFuncArgs_0: any) => SmartTransactionsFeatureFlagsConfig; | ||
| memoizedResultFunc: ((resultFuncArgs_0: any) => SmartTransactionsFeatureFlagsConfig) & { | ||
| clearCache: () => void; | ||
| resultsCount: () => number; | ||
| resetResultsCount: () => void; | ||
| }; | ||
| lastResult: () => SmartTransactionsFeatureFlagsConfig; | ||
| dependencies: [(state: SmartTransactionsFeatureFlagsState) => unknown]; | ||
| recomputations: () => number; | ||
| resetRecomputations: () => void; | ||
| dependencyRecomputations: () => number; | ||
| resetDependencyRecomputations: () => void; | ||
| } & { | ||
| memoize: typeof import("reselect").weakMapMemoize; | ||
| argsMemoize: typeof import("reselect").weakMapMemoize; | ||
| }, (_state: SmartTransactionsFeatureFlagsState, chainId: Hex | CaipChainId) => `0x${string}` | `${string}:${string}`]; | ||
| recomputations: () => number; | ||
| resetRecomputations: () => void; | ||
| dependencyRecomputations: () => number; | ||
| resetDependencyRecomputations: () => void; | ||
| } & { | ||
| memoize: typeof import("reselect").weakMapMemoize; | ||
| argsMemoize: typeof import("reselect").weakMapMemoize; | ||
| }; | ||
| //# sourceMappingURL=selectors.d.cts.map |
| {"version":3,"file":"selectors.d.cts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,wBAAwB;AAOxD,OAAO,KAAK,EACV,mCAAmC,EAEpC,oBAAgB;AAEjB;;;GAGG;AACH,oBAAY,kCAAkC,GAAG;IAC/C,kBAAkB,CAAC,EAAE;QACnB,yBAAyB,CAAC,EAAE,OAAO,CAAC;KACrC,CAAC;CACH,CAAC;AAQF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,mCAAmC;;;;;;;;;;;;;;;;;;;;CAI/C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,2CAA2C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBAG3C,kCAAkC,WAAW,GAAG,GAAG,WAAW;;;;;;;;CAK1E,CAAC"} |
| import type { CaipChainId, Hex } from "@metamask/utils"; | ||
| import type { SmartTransactionsFeatureFlagsConfig } from "./types.mjs"; | ||
| /** | ||
| * The state shape expected by the smart transactions feature flag selectors. | ||
| * This represents the relevant portion of the remote feature flag controller state. | ||
| */ | ||
| export declare type SmartTransactionsFeatureFlagsState = { | ||
| remoteFeatureFlags?: { | ||
| smartTransactionsNetworks?: unknown; | ||
| }; | ||
| }; | ||
| /** | ||
| * Selects and validates the smart transactions feature flags from state. | ||
| * Returns the validated configuration or defaults if invalid. | ||
| * If you need to get the feature flags for a specific chain, use `selectSmartTransactionsFeatureFlagsForChain`. | ||
| * | ||
| * @param state - The state containing remoteFeatureFlags.smartTransactionsNetworks | ||
| * @returns The validated smart transactions feature flags configuration | ||
| * @example | ||
| * ```ts | ||
| * // In a React component | ||
| * const featureFlags = useSelector(selectSmartTransactionsFeatureFlags); | ||
| * | ||
| * // Or with reselect composition | ||
| * const selectIsExtensionActive = createSelector( | ||
| * selectSmartTransactionsFeatureFlags, | ||
| * (flags) => flags.default?.extensionActive ?? false | ||
| * ); | ||
| * ``` | ||
| */ | ||
| export declare const selectSmartTransactionsFeatureFlags: ((state: SmartTransactionsFeatureFlagsState) => SmartTransactionsFeatureFlagsConfig) & { | ||
| clearCache: () => void; | ||
| resultsCount: () => number; | ||
| resetResultsCount: () => void; | ||
| } & { | ||
| resultFunc: (resultFuncArgs_0: any) => SmartTransactionsFeatureFlagsConfig; | ||
| memoizedResultFunc: ((resultFuncArgs_0: any) => SmartTransactionsFeatureFlagsConfig) & { | ||
| clearCache: () => void; | ||
| resultsCount: () => number; | ||
| resetResultsCount: () => void; | ||
| }; | ||
| lastResult: () => SmartTransactionsFeatureFlagsConfig; | ||
| dependencies: [(state: SmartTransactionsFeatureFlagsState) => unknown]; | ||
| recomputations: () => number; | ||
| resetRecomputations: () => void; | ||
| dependencyRecomputations: () => number; | ||
| resetDependencyRecomputations: () => void; | ||
| } & { | ||
| memoize: typeof import("reselect").weakMapMemoize; | ||
| argsMemoize: typeof import("reselect").weakMapMemoize; | ||
| }; | ||
| /** | ||
| * Selects the merged feature flags configuration for a specific chain. | ||
| * Chain-specific configuration takes precedence over default configuration. | ||
| * | ||
| * For EVM chains, the chain ID is normalized to hex format before lookup. | ||
| * This means both '0x1' and 'eip155:1' will resolve to the same configuration. | ||
| * Non-EVM chains (e.g., Solana, Bitcoin) use exact match. | ||
| * | ||
| * @param _state - The state containing remoteFeatureFlags.smartTransactionsNetworks | ||
| * @param chainId - The chain ID to get configuration for. | ||
| * Supports both hex (e.g., "0x1") and CAIP-2 format (e.g., "eip155:1", "solana:...") | ||
| * @returns The merged configuration for the specified chain | ||
| * @example | ||
| * ```ts | ||
| * // Both resolve to the same config (normalized to 0x1) | ||
| * const chainConfig = useSelector((state) => | ||
| * selectSmartTransactionsFeatureFlagsForChain(state, '0x1') | ||
| * ); | ||
| * const sameConfig = useSelector((state) => | ||
| * selectSmartTransactionsFeatureFlagsForChain(state, 'eip155:1') | ||
| * ); | ||
| * | ||
| * // Non-EVM uses exact match | ||
| * const solanaConfig = useSelector((state) => | ||
| * selectSmartTransactionsFeatureFlagsForChain(state, 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp') | ||
| * ); | ||
| * | ||
| * if (chainConfig.extensionActive) { | ||
| * // Smart transactions are enabled | ||
| * } | ||
| * ``` | ||
| */ | ||
| export declare const selectSmartTransactionsFeatureFlagsForChain: ((state: SmartTransactionsFeatureFlagsState, chainId: `0x${string}` | `${string}:${string}`) => { | ||
| extensionActive?: boolean | undefined; | ||
| mobileActive?: boolean | undefined; | ||
| mobileActiveIOS?: boolean | undefined; | ||
| mobileActiveAndroid?: boolean | undefined; | ||
| expectedDeadline?: number | undefined; | ||
| maxDeadline?: number | undefined; | ||
| extensionReturnTxHashAsap?: boolean | undefined; | ||
| extensionReturnTxHashAsapBatch?: boolean | undefined; | ||
| mobileReturnTxHashAsap?: boolean | undefined; | ||
| extensionSkipSmartTransactionStatusPage?: boolean | undefined; | ||
| batchStatusPollingInterval?: number | undefined; | ||
| sentinelUrl?: string | undefined; | ||
| }) & { | ||
| clearCache: () => void; | ||
| resultsCount: () => number; | ||
| resetResultsCount: () => void; | ||
| } & { | ||
| resultFunc: (resultFuncArgs_0: SmartTransactionsFeatureFlagsConfig, resultFuncArgs_1: `0x${string}` | `${string}:${string}`) => { | ||
| extensionActive?: boolean | undefined; | ||
| mobileActive?: boolean | undefined; | ||
| mobileActiveIOS?: boolean | undefined; | ||
| mobileActiveAndroid?: boolean | undefined; | ||
| expectedDeadline?: number | undefined; | ||
| maxDeadline?: number | undefined; | ||
| extensionReturnTxHashAsap?: boolean | undefined; | ||
| extensionReturnTxHashAsapBatch?: boolean | undefined; | ||
| mobileReturnTxHashAsap?: boolean | undefined; | ||
| extensionSkipSmartTransactionStatusPage?: boolean | undefined; | ||
| batchStatusPollingInterval?: number | undefined; | ||
| sentinelUrl?: string | undefined; | ||
| }; | ||
| memoizedResultFunc: ((resultFuncArgs_0: SmartTransactionsFeatureFlagsConfig, resultFuncArgs_1: `0x${string}` | `${string}:${string}`) => { | ||
| extensionActive?: boolean | undefined; | ||
| mobileActive?: boolean | undefined; | ||
| mobileActiveIOS?: boolean | undefined; | ||
| mobileActiveAndroid?: boolean | undefined; | ||
| expectedDeadline?: number | undefined; | ||
| maxDeadline?: number | undefined; | ||
| extensionReturnTxHashAsap?: boolean | undefined; | ||
| extensionReturnTxHashAsapBatch?: boolean | undefined; | ||
| mobileReturnTxHashAsap?: boolean | undefined; | ||
| extensionSkipSmartTransactionStatusPage?: boolean | undefined; | ||
| batchStatusPollingInterval?: number | undefined; | ||
| sentinelUrl?: string | undefined; | ||
| }) & { | ||
| clearCache: () => void; | ||
| resultsCount: () => number; | ||
| resetResultsCount: () => void; | ||
| }; | ||
| lastResult: () => { | ||
| extensionActive?: boolean | undefined; | ||
| mobileActive?: boolean | undefined; | ||
| mobileActiveIOS?: boolean | undefined; | ||
| mobileActiveAndroid?: boolean | undefined; | ||
| expectedDeadline?: number | undefined; | ||
| maxDeadline?: number | undefined; | ||
| extensionReturnTxHashAsap?: boolean | undefined; | ||
| extensionReturnTxHashAsapBatch?: boolean | undefined; | ||
| mobileReturnTxHashAsap?: boolean | undefined; | ||
| extensionSkipSmartTransactionStatusPage?: boolean | undefined; | ||
| batchStatusPollingInterval?: number | undefined; | ||
| sentinelUrl?: string | undefined; | ||
| }; | ||
| dependencies: [((state: SmartTransactionsFeatureFlagsState) => SmartTransactionsFeatureFlagsConfig) & { | ||
| clearCache: () => void; | ||
| resultsCount: () => number; | ||
| resetResultsCount: () => void; | ||
| } & { | ||
| resultFunc: (resultFuncArgs_0: any) => SmartTransactionsFeatureFlagsConfig; | ||
| memoizedResultFunc: ((resultFuncArgs_0: any) => SmartTransactionsFeatureFlagsConfig) & { | ||
| clearCache: () => void; | ||
| resultsCount: () => number; | ||
| resetResultsCount: () => void; | ||
| }; | ||
| lastResult: () => SmartTransactionsFeatureFlagsConfig; | ||
| dependencies: [(state: SmartTransactionsFeatureFlagsState) => unknown]; | ||
| recomputations: () => number; | ||
| resetRecomputations: () => void; | ||
| dependencyRecomputations: () => number; | ||
| resetDependencyRecomputations: () => void; | ||
| } & { | ||
| memoize: typeof import("reselect").weakMapMemoize; | ||
| argsMemoize: typeof import("reselect").weakMapMemoize; | ||
| }, (_state: SmartTransactionsFeatureFlagsState, chainId: Hex | CaipChainId) => `0x${string}` | `${string}:${string}`]; | ||
| recomputations: () => number; | ||
| resetRecomputations: () => void; | ||
| dependencyRecomputations: () => number; | ||
| resetDependencyRecomputations: () => void; | ||
| } & { | ||
| memoize: typeof import("reselect").weakMapMemoize; | ||
| argsMemoize: typeof import("reselect").weakMapMemoize; | ||
| }; | ||
| //# sourceMappingURL=selectors.d.mts.map |
| {"version":3,"file":"selectors.d.mts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,wBAAwB;AAOxD,OAAO,KAAK,EACV,mCAAmC,EAEpC,oBAAgB;AAEjB;;;GAGG;AACH,oBAAY,kCAAkC,GAAG;IAC/C,kBAAkB,CAAC,EAAE;QACnB,yBAAyB,CAAC,EAAE,OAAO,CAAC;KACrC,CAAC;CACH,CAAC;AAQF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,mCAAmC;;;;;;;;;;;;;;;;;;;;CAI/C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,2CAA2C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBAG3C,kCAAkC,WAAW,GAAG,GAAG,WAAW;;;;;;;;CAK1E,CAAC"} |
| import { createSelector as createSelector_ } from "reselect"; | ||
| import { processSmartTransactionsFeatureFlags, getSmartTransactionsFeatureFlagsForChain } from "./featureFlags/feature-flags.mjs"; | ||
| /** | ||
| * Creates a typed selector for smart transactions feature flags | ||
| */ | ||
| const createSelector = createSelector_.withTypes(); | ||
| /** | ||
| * Selects and validates the smart transactions feature flags from state. | ||
| * Returns the validated configuration or defaults if invalid. | ||
| * If you need to get the feature flags for a specific chain, use `selectSmartTransactionsFeatureFlagsForChain`. | ||
| * | ||
| * @param state - The state containing remoteFeatureFlags.smartTransactionsNetworks | ||
| * @returns The validated smart transactions feature flags configuration | ||
| * @example | ||
| * ```ts | ||
| * // In a React component | ||
| * const featureFlags = useSelector(selectSmartTransactionsFeatureFlags); | ||
| * | ||
| * // Or with reselect composition | ||
| * const selectIsExtensionActive = createSelector( | ||
| * selectSmartTransactionsFeatureFlags, | ||
| * (flags) => flags.default?.extensionActive ?? false | ||
| * ); | ||
| * ``` | ||
| */ | ||
| export const selectSmartTransactionsFeatureFlags = createSelector([(state) => { var _a; return (_a = state.remoteFeatureFlags) === null || _a === void 0 ? void 0 : _a.smartTransactionsNetworks; }], (rawFeatureFlags) => processSmartTransactionsFeatureFlags(rawFeatureFlags)); | ||
| /** | ||
| * Selects the merged feature flags configuration for a specific chain. | ||
| * Chain-specific configuration takes precedence over default configuration. | ||
| * | ||
| * For EVM chains, the chain ID is normalized to hex format before lookup. | ||
| * This means both '0x1' and 'eip155:1' will resolve to the same configuration. | ||
| * Non-EVM chains (e.g., Solana, Bitcoin) use exact match. | ||
| * | ||
| * @param _state - The state containing remoteFeatureFlags.smartTransactionsNetworks | ||
| * @param chainId - The chain ID to get configuration for. | ||
| * Supports both hex (e.g., "0x1") and CAIP-2 format (e.g., "eip155:1", "solana:...") | ||
| * @returns The merged configuration for the specified chain | ||
| * @example | ||
| * ```ts | ||
| * // Both resolve to the same config (normalized to 0x1) | ||
| * const chainConfig = useSelector((state) => | ||
| * selectSmartTransactionsFeatureFlagsForChain(state, '0x1') | ||
| * ); | ||
| * const sameConfig = useSelector((state) => | ||
| * selectSmartTransactionsFeatureFlagsForChain(state, 'eip155:1') | ||
| * ); | ||
| * | ||
| * // Non-EVM uses exact match | ||
| * const solanaConfig = useSelector((state) => | ||
| * selectSmartTransactionsFeatureFlagsForChain(state, 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp') | ||
| * ); | ||
| * | ||
| * if (chainConfig.extensionActive) { | ||
| * // Smart transactions are enabled | ||
| * } | ||
| * ``` | ||
| */ | ||
| export const selectSmartTransactionsFeatureFlagsForChain = createSelector([ | ||
| selectSmartTransactionsFeatureFlags, | ||
| (_state, chainId) => chainId, | ||
| ], (featureFlags, chainId) => getSmartTransactionsFeatureFlagsForChain(featureFlags, chainId)); | ||
| //# sourceMappingURL=selectors.mjs.map |
| {"version":3,"file":"selectors.mjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,IAAI,eAAe,EAAE,iBAAiB;AAE7D,OAAO,EACL,oCAAoC,EACpC,wCAAwC,EACzC,yCAAqC;AAgBtC;;GAEG;AACH,MAAM,cAAc,GAClB,eAAe,CAAC,SAAS,EAAsC,CAAC;AAElE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAAG,cAAc,CAC/D,CAAC,CAAC,KAAK,EAAE,EAAE,WAAC,OAAA,MAAA,KAAK,CAAC,kBAAkB,0CAAE,yBAAyB,CAAA,EAAA,CAAC,EAChE,CAAC,eAAe,EAAuC,EAAE,CACvD,oCAAoC,CAAC,eAAe,CAAC,CACxD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,CAAC,MAAM,2CAA2C,GAAG,cAAc,CACvE;IACE,mCAAmC;IACnC,CAAC,MAA0C,EAAE,OAA0B,EAAE,EAAE,CACzE,OAAO;CACV,EACD,CAAC,YAAY,EAAE,OAAO,EAAkC,EAAE,CACxD,wCAAwC,CAAC,YAAY,EAAE,OAAO,CAAC,CAClE,CAAC","sourcesContent":["import type { CaipChainId, Hex } from '@metamask/utils';\nimport { createSelector as createSelector_ } from 'reselect';\n\nimport {\n processSmartTransactionsFeatureFlags,\n getSmartTransactionsFeatureFlagsForChain,\n} from './featureFlags/feature-flags';\nimport type {\n SmartTransactionsFeatureFlagsConfig,\n SmartTransactionsNetworkConfig,\n} from './types';\n\n/**\n * The state shape expected by the smart transactions feature flag selectors.\n * This represents the relevant portion of the remote feature flag controller state.\n */\nexport type SmartTransactionsFeatureFlagsState = {\n remoteFeatureFlags?: {\n smartTransactionsNetworks?: unknown;\n };\n};\n\n/**\n * Creates a typed selector for smart transactions feature flags\n */\nconst createSelector =\n createSelector_.withTypes<SmartTransactionsFeatureFlagsState>();\n\n/**\n * Selects and validates the smart transactions feature flags from state.\n * Returns the validated configuration or defaults if invalid.\n * If you need to get the feature flags for a specific chain, use `selectSmartTransactionsFeatureFlagsForChain`.\n *\n * @param state - The state containing remoteFeatureFlags.smartTransactionsNetworks\n * @returns The validated smart transactions feature flags configuration\n * @example\n * ```ts\n * // In a React component\n * const featureFlags = useSelector(selectSmartTransactionsFeatureFlags);\n *\n * // Or with reselect composition\n * const selectIsExtensionActive = createSelector(\n * selectSmartTransactionsFeatureFlags,\n * (flags) => flags.default?.extensionActive ?? false\n * );\n * ```\n */\nexport const selectSmartTransactionsFeatureFlags = createSelector(\n [(state) => state.remoteFeatureFlags?.smartTransactionsNetworks],\n (rawFeatureFlags): SmartTransactionsFeatureFlagsConfig =>\n processSmartTransactionsFeatureFlags(rawFeatureFlags),\n);\n\n/**\n * Selects the merged feature flags configuration for a specific chain.\n * Chain-specific configuration takes precedence over default configuration.\n *\n * For EVM chains, the chain ID is normalized to hex format before lookup.\n * This means both '0x1' and 'eip155:1' will resolve to the same configuration.\n * Non-EVM chains (e.g., Solana, Bitcoin) use exact match.\n *\n * @param _state - The state containing remoteFeatureFlags.smartTransactionsNetworks\n * @param chainId - The chain ID to get configuration for.\n * Supports both hex (e.g., \"0x1\") and CAIP-2 format (e.g., \"eip155:1\", \"solana:...\")\n * @returns The merged configuration for the specified chain\n * @example\n * ```ts\n * // Both resolve to the same config (normalized to 0x1)\n * const chainConfig = useSelector((state) =>\n * selectSmartTransactionsFeatureFlagsForChain(state, '0x1')\n * );\n * const sameConfig = useSelector((state) =>\n * selectSmartTransactionsFeatureFlagsForChain(state, 'eip155:1')\n * );\n *\n * // Non-EVM uses exact match\n * const solanaConfig = useSelector((state) =>\n * selectSmartTransactionsFeatureFlagsForChain(state, 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp')\n * );\n *\n * if (chainConfig.extensionActive) {\n * // Smart transactions are enabled\n * }\n * ```\n */\nexport const selectSmartTransactionsFeatureFlagsForChain = createSelector(\n [\n selectSmartTransactionsFeatureFlags,\n (_state: SmartTransactionsFeatureFlagsState, chainId: Hex | CaipChainId) =>\n chainId,\n ],\n (featureFlags, chainId): SmartTransactionsNetworkConfig =>\n getSmartTransactionsFeatureFlagsForChain(featureFlags, chainId),\n);\n"]} |
+13
-1
@@ -10,2 +10,13 @@ # Changelog | ||
| ## [22.0.0] | ||
| ### Changed | ||
| - **BREAKING**: The controller now reads feature flags directly from `RemoteFeatureFlagController` via the messenger instead of using the `getFeatureFlags` callback ([#550](https://github.com/MetaMask/smart-transactions-controller/pull/550)) | ||
| - Clients must configure the following as allowed actions in the controller messenger: | ||
| - `RemoteFeatureFlagController:getState` | ||
| - `ErrorReportingService:captureException` (for reporting validation errors to Sentry) | ||
| - Clients must configure `RemoteFeatureFlagController:stateChange` as an allowed event | ||
| - The `getFeatureFlags` constructor option is now deprecated and ignored | ||
| ## [21.1.0] | ||
@@ -685,3 +696,4 @@ | ||
| [Unreleased]: https://github.com/MetaMask/smart-transactions-controller/compare/v21.1.0...HEAD | ||
| [Unreleased]: https://github.com/MetaMask/smart-transactions-controller/compare/v22.0.0...HEAD | ||
| [22.0.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v21.1.0...v22.0.0 | ||
| [21.1.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v21.0.0...v21.1.0 | ||
@@ -688,0 +700,0 @@ [21.0.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v20.1.0...v21.0.0 |
+21
-1
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.SmartTransactionsTraceName = exports.MetaMetricsEventCategory = exports.MetaMetricsEventName = exports.SENTINEL_API_BASE_URL_MAP = exports.API_BASE_URL = void 0; | ||
| exports.DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS = exports.SmartTransactionsTraceName = exports.MetaMetricsEventCategory = exports.MetaMetricsEventName = exports.SENTINEL_API_BASE_URL_MAP = exports.API_BASE_URL = void 0; | ||
| exports.API_BASE_URL = 'https://transaction.api.cx.metamask.io'; | ||
@@ -34,2 +34,22 @@ // The map with types applied | ||
| })(SmartTransactionsTraceName = exports.SmartTransactionsTraceName || (exports.SmartTransactionsTraceName = {})); | ||
| /** | ||
| * Default feature flags configuration for smart transactions. | ||
| * Used as a fallback when remote feature flags are unavailable or invalid. | ||
| * This is voluntarily defensive because it is applied to any network without valid configuration. | ||
| */ | ||
| exports.DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS = { | ||
| default: { | ||
| extensionActive: false, | ||
| mobileActive: false, | ||
| mobileActiveIOS: false, | ||
| mobileActiveAndroid: false, | ||
| expectedDeadline: 45, | ||
| maxDeadline: 150, | ||
| extensionReturnTxHashAsap: false, | ||
| extensionReturnTxHashAsapBatch: false, | ||
| mobileReturnTxHashAsap: false, | ||
| extensionSkipSmartTransactionStatusPage: false, | ||
| batchStatusPollingInterval: 1000, | ||
| }, | ||
| }; | ||
| //# sourceMappingURL=constants.cjs.map |
+20
-0
@@ -22,3 +22,23 @@ export declare const API_BASE_URL = "https://transaction.api.cx.metamask.io"; | ||
| } | ||
| /** | ||
| * Default feature flags configuration for smart transactions. | ||
| * Used as a fallback when remote feature flags are unavailable or invalid. | ||
| * This is voluntarily defensive because it is applied to any network without valid configuration. | ||
| */ | ||
| export declare const DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS: { | ||
| readonly default: { | ||
| readonly extensionActive: false; | ||
| readonly mobileActive: false; | ||
| readonly mobileActiveIOS: false; | ||
| readonly mobileActiveAndroid: false; | ||
| readonly expectedDeadline: 45; | ||
| readonly maxDeadline: 150; | ||
| readonly extensionReturnTxHashAsap: false; | ||
| readonly extensionReturnTxHashAsapBatch: false; | ||
| readonly mobileReturnTxHashAsap: false; | ||
| readonly extensionSkipSmartTransactionStatusPage: false; | ||
| readonly batchStatusPollingInterval: 1000; | ||
| }; | ||
| }; | ||
| export {}; | ||
| //# sourceMappingURL=constants.d.cts.map |
+20
-0
@@ -22,3 +22,23 @@ export declare const API_BASE_URL = "https://transaction.api.cx.metamask.io"; | ||
| } | ||
| /** | ||
| * Default feature flags configuration for smart transactions. | ||
| * Used as a fallback when remote feature flags are unavailable or invalid. | ||
| * This is voluntarily defensive because it is applied to any network without valid configuration. | ||
| */ | ||
| export declare const DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS: { | ||
| readonly default: { | ||
| readonly extensionActive: false; | ||
| readonly mobileActive: false; | ||
| readonly mobileActiveIOS: false; | ||
| readonly mobileActiveAndroid: false; | ||
| readonly expectedDeadline: 45; | ||
| readonly maxDeadline: 150; | ||
| readonly extensionReturnTxHashAsap: false; | ||
| readonly extensionReturnTxHashAsapBatch: false; | ||
| readonly mobileReturnTxHashAsap: false; | ||
| readonly extensionSkipSmartTransactionStatusPage: false; | ||
| readonly batchStatusPollingInterval: 1000; | ||
| }; | ||
| }; | ||
| export {}; | ||
| //# sourceMappingURL=constants.d.mts.map |
+20
-0
@@ -31,2 +31,22 @@ export const API_BASE_URL = 'https://transaction.api.cx.metamask.io'; | ||
| })(SmartTransactionsTraceName = SmartTransactionsTraceName || (SmartTransactionsTraceName = {})); | ||
| /** | ||
| * Default feature flags configuration for smart transactions. | ||
| * Used as a fallback when remote feature flags are unavailable or invalid. | ||
| * This is voluntarily defensive because it is applied to any network without valid configuration. | ||
| */ | ||
| export const DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS = { | ||
| default: { | ||
| extensionActive: false, | ||
| mobileActive: false, | ||
| mobileActiveIOS: false, | ||
| mobileActiveAndroid: false, | ||
| expectedDeadline: 45, | ||
| maxDeadline: 150, | ||
| extensionReturnTxHashAsap: false, | ||
| extensionReturnTxHashAsapBatch: false, | ||
| mobileReturnTxHashAsap: false, | ||
| extensionSkipSmartTransactionStatusPage: false, | ||
| batchStatusPollingInterval: 1000, | ||
| }, | ||
| }; | ||
| //# sourceMappingURL=constants.mjs.map |
+5
-1
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.getSmartTransactionMetricsSensitiveProperties = exports.getSmartTransactionMetricsProperties = exports.MetaMetricsEventCategory = exports.MetaMetricsEventName = exports.ClientId = exports.SmartTransactionStatuses = exports.SmartTransactionCancellationReason = exports.SmartTransactionMinedTx = exports.SmartTransactionsController = void 0; | ||
| exports.selectSmartTransactionsFeatureFlagsForChain = exports.selectSmartTransactionsFeatureFlags = exports.getSmartTransactionMetricsSensitiveProperties = exports.getSmartTransactionMetricsProperties = exports.MetaMetricsEventCategory = exports.MetaMetricsEventName = exports.ClientId = exports.SmartTransactionStatuses = exports.SmartTransactionCancellationReason = exports.SmartTransactionMinedTx = exports.SmartTransactionsController = void 0; | ||
| var SmartTransactionsController_1 = require("./SmartTransactionsController.cjs"); | ||
@@ -17,2 +17,6 @@ Object.defineProperty(exports, "SmartTransactionsController", { enumerable: true, get: function () { return SmartTransactionsController_1.SmartTransactionsController; } }); | ||
| Object.defineProperty(exports, "getSmartTransactionMetricsSensitiveProperties", { enumerable: true, get: function () { return utils_1.getSmartTransactionMetricsSensitiveProperties; } }); | ||
| // Feature flag selectors | ||
| var selectors_1 = require("./selectors.cjs"); | ||
| Object.defineProperty(exports, "selectSmartTransactionsFeatureFlags", { enumerable: true, get: function () { return selectors_1.selectSmartTransactionsFeatureFlags; } }); | ||
| Object.defineProperty(exports, "selectSmartTransactionsFeatureFlagsForChain", { enumerable: true, get: function () { return selectors_1.selectSmartTransactionsFeatureFlagsForChain; } }); | ||
| //# sourceMappingURL=index.cjs.map |
+2
-1
| export { SmartTransactionsController } from "./SmartTransactionsController.cjs"; | ||
| export type { SmartTransactionsControllerMessenger, SmartTransactionsControllerState, SmartTransactionsControllerGetStateAction, SmartTransactionsControllerActions, SmartTransactionsControllerStateChangeEvent, SmartTransactionsControllerSmartTransactionEvent, SmartTransactionsControllerSmartTransactionConfirmationDoneEvent, SmartTransactionsControllerEvents, } from "./SmartTransactionsController.cjs"; | ||
| export { type Fee, type Fees, type IndividualTxFees, type FeatureFlags, type SmartTransaction, SmartTransactionMinedTx, SmartTransactionCancellationReason, SmartTransactionStatuses, ClientId, } from "./types.cjs"; | ||
| export { type Fee, type Fees, type IndividualTxFees, type FeatureFlags, type SmartTransaction, type SmartTransactionsNetworkConfig, type SmartTransactionsFeatureFlagsConfig, SmartTransactionMinedTx, SmartTransactionCancellationReason, SmartTransactionStatuses, ClientId, } from "./types.cjs"; | ||
| export { MetaMetricsEventName, MetaMetricsEventCategory } from "./constants.cjs"; | ||
| export { getSmartTransactionMetricsProperties, getSmartTransactionMetricsSensitiveProperties, } from "./utils.cjs"; | ||
| export { selectSmartTransactionsFeatureFlags, selectSmartTransactionsFeatureFlagsForChain, type SmartTransactionsFeatureFlagsState, } from "./selectors.cjs"; | ||
| //# sourceMappingURL=index.d.cts.map |
+2
-1
| export { SmartTransactionsController } from "./SmartTransactionsController.mjs"; | ||
| export type { SmartTransactionsControllerMessenger, SmartTransactionsControllerState, SmartTransactionsControllerGetStateAction, SmartTransactionsControllerActions, SmartTransactionsControllerStateChangeEvent, SmartTransactionsControllerSmartTransactionEvent, SmartTransactionsControllerSmartTransactionConfirmationDoneEvent, SmartTransactionsControllerEvents, } from "./SmartTransactionsController.mjs"; | ||
| export { type Fee, type Fees, type IndividualTxFees, type FeatureFlags, type SmartTransaction, SmartTransactionMinedTx, SmartTransactionCancellationReason, SmartTransactionStatuses, ClientId, } from "./types.mjs"; | ||
| export { type Fee, type Fees, type IndividualTxFees, type FeatureFlags, type SmartTransaction, type SmartTransactionsNetworkConfig, type SmartTransactionsFeatureFlagsConfig, SmartTransactionMinedTx, SmartTransactionCancellationReason, SmartTransactionStatuses, ClientId, } from "./types.mjs"; | ||
| export { MetaMetricsEventName, MetaMetricsEventCategory } from "./constants.mjs"; | ||
| export { getSmartTransactionMetricsProperties, getSmartTransactionMetricsSensitiveProperties, } from "./utils.mjs"; | ||
| export { selectSmartTransactionsFeatureFlags, selectSmartTransactionsFeatureFlagsForChain, type SmartTransactionsFeatureFlagsState, } from "./selectors.mjs"; | ||
| //# sourceMappingURL=index.d.mts.map |
+2
-0
@@ -5,2 +5,4 @@ export { SmartTransactionsController } from "./SmartTransactionsController.mjs"; | ||
| export { getSmartTransactionMetricsProperties, getSmartTransactionMetricsSensitiveProperties } from "./utils.mjs"; | ||
| // Feature flag selectors | ||
| export { selectSmartTransactionsFeatureFlags, selectSmartTransactionsFeatureFlagsForChain } from "./selectors.mjs"; | ||
| //# sourceMappingURL=index.mjs.map |
@@ -16,3 +16,3 @@ "use strict"; | ||
| }; | ||
| var _SmartTransactionsController_instances, _SmartTransactionsController_interval, _SmartTransactionsController_clientId, _SmartTransactionsController_chainId, _SmartTransactionsController_supportedChainIds, _SmartTransactionsController_ethQuery, _SmartTransactionsController_trackMetaMetricsEvent, _SmartTransactionsController_getMetaMetricsProps, _SmartTransactionsController_getFeatureFlags, _SmartTransactionsController_trace, _SmartTransactionsController_fetch, _SmartTransactionsController_updateSmartTransaction, _SmartTransactionsController_addMetaMetricsPropsToNewSmartTransaction, _SmartTransactionsController_createOrUpdateSmartTransaction, _SmartTransactionsController_confirmSmartTransaction, _SmartTransactionsController_addNonceToTransaction, _SmartTransactionsController_getChainId, _SmartTransactionsController_getChainIds, _SmartTransactionsController_getNetworkClientId, _SmartTransactionsController_getEthQuery, _SmartTransactionsController_getCurrentSmartTransactions, _SmartTransactionsController_wipeSmartTransactionsPerChainId; | ||
| var _SmartTransactionsController_instances, _SmartTransactionsController_interval, _SmartTransactionsController_clientId, _SmartTransactionsController_chainId, _SmartTransactionsController_supportedChainIds, _SmartTransactionsController_ethQuery, _SmartTransactionsController_trackMetaMetricsEvent, _SmartTransactionsController_getMetaMetricsProps, _SmartTransactionsController_trace, _SmartTransactionsController_validateAndReportFeatureFlags, _SmartTransactionsController_fetch, _SmartTransactionsController_updateSmartTransaction, _SmartTransactionsController_addMetaMetricsPropsToNewSmartTransaction, _SmartTransactionsController_createOrUpdateSmartTransaction, _SmartTransactionsController_confirmSmartTransaction, _SmartTransactionsController_addNonceToTransaction, _SmartTransactionsController_getChainId, _SmartTransactionsController_getChainIds, _SmartTransactionsController_getNetworkClientId, _SmartTransactionsController_getEthQuery, _SmartTransactionsController_getCurrentSmartTransactions, _SmartTransactionsController_wipeSmartTransactionsPerChainId; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -27,2 +27,4 @@ exports.SmartTransactionsController = exports.getDefaultSmartTransactionsControllerState = exports.DEFAULT_INTERVAL = void 0; | ||
| const constants_1 = require("./constants.cjs"); | ||
| const feature_flags_1 = require("./featureFlags/feature-flags.cjs"); | ||
| const validators_1 = require("./featureFlags/validators.cjs"); | ||
| const types_1 = require("./types.cjs"); | ||
@@ -81,3 +83,3 @@ const utils_1 = require("./utils.cjs"); | ||
| class SmartTransactionsController extends (0, polling_controller_1.StaticIntervalPollingController)() { | ||
| constructor({ interval = exports.DEFAULT_INTERVAL, clientId, chainId: InitialChainId = controller_utils_1.ChainId.mainnet, supportedChainIds = [controller_utils_1.ChainId.mainnet, controller_utils_1.ChainId.sepolia], trackMetaMetricsEvent, state = {}, messenger, getMetaMetricsProps, getFeatureFlags, trace, }) { | ||
| constructor({ interval = exports.DEFAULT_INTERVAL, clientId, chainId: InitialChainId = controller_utils_1.ChainId.mainnet, supportedChainIds = [controller_utils_1.ChainId.mainnet, controller_utils_1.ChainId.sepolia], trackMetaMetricsEvent, state = {}, messenger, getMetaMetricsProps, trace, }) { | ||
| super({ | ||
@@ -97,3 +99,2 @@ name: controllerName, | ||
| _SmartTransactionsController_getMetaMetricsProps.set(this, void 0); | ||
| _SmartTransactionsController_getFeatureFlags.set(this, void 0); | ||
| _SmartTransactionsController_trace.set(this, void 0); | ||
@@ -108,3 +109,2 @@ __classPrivateFieldSet(this, _SmartTransactionsController_interval, interval, "f"); | ||
| __classPrivateFieldSet(this, _SmartTransactionsController_getMetaMetricsProps, getMetaMetricsProps, "f"); | ||
| __classPrivateFieldSet(this, _SmartTransactionsController_getFeatureFlags, getFeatureFlags, "f"); | ||
| __classPrivateFieldSet(this, _SmartTransactionsController_trace, trace !== null && trace !== void 0 ? trace : ((_request, fn) => fn === null || fn === void 0 ? void 0 : fn()), "f"); | ||
@@ -120,2 +120,6 @@ this.initializeSmartTransactionsForChainId(); | ||
| this.messenger.subscribe(`${controllerName}:stateChange`, (currentState) => this.checkPoll(currentState)); | ||
| // Validate feature flags on changes | ||
| this.messenger.subscribe('RemoteFeatureFlagController:stateChange', () => { | ||
| __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_validateAndReportFeatureFlags).call(this); | ||
| }); | ||
| } | ||
@@ -496,3 +500,12 @@ async _executePoll({ chainIds, }) { | ||
| exports.SmartTransactionsController = SmartTransactionsController; | ||
| _SmartTransactionsController_interval = new WeakMap(), _SmartTransactionsController_clientId = new WeakMap(), _SmartTransactionsController_chainId = new WeakMap(), _SmartTransactionsController_supportedChainIds = new WeakMap(), _SmartTransactionsController_ethQuery = new WeakMap(), _SmartTransactionsController_trackMetaMetricsEvent = new WeakMap(), _SmartTransactionsController_getMetaMetricsProps = new WeakMap(), _SmartTransactionsController_getFeatureFlags = new WeakMap(), _SmartTransactionsController_trace = new WeakMap(), _SmartTransactionsController_instances = new WeakSet(), _SmartTransactionsController_fetch = | ||
| _SmartTransactionsController_interval = new WeakMap(), _SmartTransactionsController_clientId = new WeakMap(), _SmartTransactionsController_chainId = new WeakMap(), _SmartTransactionsController_supportedChainIds = new WeakMap(), _SmartTransactionsController_ethQuery = new WeakMap(), _SmartTransactionsController_trackMetaMetricsEvent = new WeakMap(), _SmartTransactionsController_getMetaMetricsProps = new WeakMap(), _SmartTransactionsController_trace = new WeakMap(), _SmartTransactionsController_instances = new WeakSet(), _SmartTransactionsController_validateAndReportFeatureFlags = function _SmartTransactionsController_validateAndReportFeatureFlags() { | ||
| var _a; | ||
| const remoteFeatureFlagControllerState = this.messenger.call('RemoteFeatureFlagController:getState'); | ||
| const rawFlags = (_a = remoteFeatureFlagControllerState === null || remoteFeatureFlagControllerState === void 0 ? void 0 : remoteFeatureFlagControllerState.remoteFeatureFlags) === null || _a === void 0 ? void 0 : _a.smartTransactionsNetworks; | ||
| const { errors } = (0, validators_1.validateSmartTransactionsFeatureFlags)(rawFlags); | ||
| // Report each validation error to Sentry | ||
| for (const error of errors) { | ||
| this.messenger.call('ErrorReportingService:captureException', new Error(`[SmartTransactionsController] Feature flag validation failed: ${error.message}. Please check the SmartTransactionNetworks feature flag in Remote Config. Smart transactions are disabled for this network. Default disabled config: ${JSON.stringify(constants_1.DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS.default)}`)); | ||
| } | ||
| }, _SmartTransactionsController_fetch = | ||
| /* istanbul ignore next */ | ||
@@ -569,6 +582,7 @@ async function _SmartTransactionsController_fetch(request, options) { | ||
| this.messenger.publish(`SmartTransactionsController:smartTransaction`, nextSmartTransaction); | ||
| const featureFlags = (0, feature_flags_1.getSmartTransactionsFeatureFlagsForChain)((0, feature_flags_1.getSmartTransactionsFeatureFlags)(this.messenger), chainId); | ||
| if ((0, utils_1.shouldMarkRegularTransactionsAsFailed)({ | ||
| smartTransaction: nextSmartTransaction, | ||
| clientId: __classPrivateFieldGet(this, _SmartTransactionsController_clientId, "f"), | ||
| getFeatureFlags: __classPrivateFieldGet(this, _SmartTransactionsController_getFeatureFlags, "f"), | ||
| featureFlags, | ||
| })) { | ||
@@ -575,0 +589,0 @@ (0, utils_1.markRegularTransactionsAsFailed)({ |
| /// <reference types="node" /> | ||
| import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller"; | ||
| import { type TraceCallback } from "@metamask/controller-utils"; | ||
| import type { ErrorReportingServiceCaptureExceptionAction } from "@metamask/error-reporting-service"; | ||
| import type { Messenger } from "@metamask/messenger"; | ||
| import type { NetworkClientId, NetworkControllerGetNetworkClientByIdAction, NetworkControllerGetStateAction, NetworkControllerStateChangeEvent } from "@metamask/network-controller"; | ||
| import type { RemoteFeatureFlagControllerGetStateAction, RemoteFeatureFlagControllerStateChangeEvent } from "@metamask/remote-feature-flag-controller"; | ||
| import type { TransactionControllerGetNonceLockAction, TransactionControllerGetTransactionsAction, TransactionControllerUpdateTransactionAction, TransactionMeta, TransactionParams } from "@metamask/transaction-controller"; | ||
| import type { Hex } from "@metamask/utils"; | ||
| import { MetaMetricsEventCategory, MetaMetricsEventName } from "./constants.cjs"; | ||
| import type { Fees, Hex, IndividualTxFees, SignedCanceledTransaction, SignedTransaction, SmartTransaction, SmartTransactionsStatus, UnsignedTransaction, MetaMetricsProps, FeatureFlags, ClientId } from "./types.cjs"; | ||
| import type { Fees, IndividualTxFees, SignedCanceledTransaction, SignedTransaction, SmartTransaction, SmartTransactionsStatus, UnsignedTransaction, MetaMetricsProps, FeatureFlags, ClientId } from "./types.cjs"; | ||
| import { SmartTransactionStatuses } from "./types.cjs"; | ||
@@ -42,3 +45,3 @@ import { getSmartTransactionMetricsProperties, getSmartTransactionMetricsSensitiveProperties } from "./utils.cjs"; | ||
| export declare type SmartTransactionsControllerActions = SmartTransactionsControllerGetStateAction; | ||
| declare type AllowedActions = NetworkControllerGetNetworkClientByIdAction | NetworkControllerGetStateAction | TransactionControllerGetNonceLockAction | TransactionControllerGetTransactionsAction | TransactionControllerUpdateTransactionAction; | ||
| declare type AllowedActions = NetworkControllerGetNetworkClientByIdAction | NetworkControllerGetStateAction | RemoteFeatureFlagControllerGetStateAction | TransactionControllerGetNonceLockAction | TransactionControllerGetTransactionsAction | TransactionControllerUpdateTransactionAction | ErrorReportingServiceCaptureExceptionAction; | ||
| export declare type SmartTransactionsControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SmartTransactionsControllerState>; | ||
@@ -57,3 +60,3 @@ export declare type SmartTransactionsControllerSmartTransactionEvent = { | ||
| export declare type SmartTransactionsControllerEvents = SmartTransactionsControllerStateChangeEvent | SmartTransactionsControllerSmartTransactionEvent | SmartTransactionsControllerSmartTransactionConfirmationDoneEvent; | ||
| declare type AllowedEvents = NetworkControllerStateChangeEvent; | ||
| declare type AllowedEvents = NetworkControllerStateChangeEvent | RemoteFeatureFlagControllerStateChangeEvent; | ||
| /** | ||
@@ -79,3 +82,8 @@ * The messenger of the {@link SmartTransactionsController}. | ||
| getMetaMetricsProps: () => Promise<MetaMetricsProps>; | ||
| getFeatureFlags: () => FeatureFlags; | ||
| /** | ||
| * @deprecated This option is ignored. Feature flags are now read directly | ||
| * from RemoteFeatureFlagController via the messenger. This option will be | ||
| * removed in a future version. | ||
| */ | ||
| getFeatureFlags?: () => FeatureFlags; | ||
| trace?: TraceCallback; | ||
@@ -104,3 +112,3 @@ }; | ||
| timeoutHandle?: NodeJS.Timeout; | ||
| constructor({ interval, clientId, chainId: InitialChainId, supportedChainIds, trackMetaMetricsEvent, state, messenger, getMetaMetricsProps, getFeatureFlags, trace, }: SmartTransactionsControllerOptions); | ||
| constructor({ interval, clientId, chainId: InitialChainId, supportedChainIds, trackMetaMetricsEvent, state, messenger, getMetaMetricsProps, trace, }: SmartTransactionsControllerOptions); | ||
| _executePoll({ chainIds, }: SmartTransactionsControllerPollingInput): Promise<void>; | ||
@@ -107,0 +115,0 @@ checkPoll({ smartTransactionsState: { smartTransactions }, }: SmartTransactionsControllerState): void; |
| /// <reference types="node" /> | ||
| import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller"; | ||
| import { type TraceCallback } from "@metamask/controller-utils"; | ||
| import type { ErrorReportingServiceCaptureExceptionAction } from "@metamask/error-reporting-service"; | ||
| import type { Messenger } from "@metamask/messenger"; | ||
| import type { NetworkClientId, NetworkControllerGetNetworkClientByIdAction, NetworkControllerGetStateAction, NetworkControllerStateChangeEvent } from "@metamask/network-controller"; | ||
| import type { RemoteFeatureFlagControllerGetStateAction, RemoteFeatureFlagControllerStateChangeEvent } from "@metamask/remote-feature-flag-controller"; | ||
| import type { TransactionControllerGetNonceLockAction, TransactionControllerGetTransactionsAction, TransactionControllerUpdateTransactionAction, TransactionMeta, TransactionParams } from "@metamask/transaction-controller"; | ||
| import type { Hex } from "@metamask/utils"; | ||
| import { MetaMetricsEventCategory, MetaMetricsEventName } from "./constants.mjs"; | ||
| import type { Fees, Hex, IndividualTxFees, SignedCanceledTransaction, SignedTransaction, SmartTransaction, SmartTransactionsStatus, UnsignedTransaction, MetaMetricsProps, FeatureFlags, ClientId } from "./types.mjs"; | ||
| import type { Fees, IndividualTxFees, SignedCanceledTransaction, SignedTransaction, SmartTransaction, SmartTransactionsStatus, UnsignedTransaction, MetaMetricsProps, FeatureFlags, ClientId } from "./types.mjs"; | ||
| import { SmartTransactionStatuses } from "./types.mjs"; | ||
@@ -42,3 +45,3 @@ import { getSmartTransactionMetricsProperties, getSmartTransactionMetricsSensitiveProperties } from "./utils.mjs"; | ||
| export declare type SmartTransactionsControllerActions = SmartTransactionsControllerGetStateAction; | ||
| declare type AllowedActions = NetworkControllerGetNetworkClientByIdAction | NetworkControllerGetStateAction | TransactionControllerGetNonceLockAction | TransactionControllerGetTransactionsAction | TransactionControllerUpdateTransactionAction; | ||
| declare type AllowedActions = NetworkControllerGetNetworkClientByIdAction | NetworkControllerGetStateAction | RemoteFeatureFlagControllerGetStateAction | TransactionControllerGetNonceLockAction | TransactionControllerGetTransactionsAction | TransactionControllerUpdateTransactionAction | ErrorReportingServiceCaptureExceptionAction; | ||
| export declare type SmartTransactionsControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SmartTransactionsControllerState>; | ||
@@ -57,3 +60,3 @@ export declare type SmartTransactionsControllerSmartTransactionEvent = { | ||
| export declare type SmartTransactionsControllerEvents = SmartTransactionsControllerStateChangeEvent | SmartTransactionsControllerSmartTransactionEvent | SmartTransactionsControllerSmartTransactionConfirmationDoneEvent; | ||
| declare type AllowedEvents = NetworkControllerStateChangeEvent; | ||
| declare type AllowedEvents = NetworkControllerStateChangeEvent | RemoteFeatureFlagControllerStateChangeEvent; | ||
| /** | ||
@@ -79,3 +82,8 @@ * The messenger of the {@link SmartTransactionsController}. | ||
| getMetaMetricsProps: () => Promise<MetaMetricsProps>; | ||
| getFeatureFlags: () => FeatureFlags; | ||
| /** | ||
| * @deprecated This option is ignored. Feature flags are now read directly | ||
| * from RemoteFeatureFlagController via the messenger. This option will be | ||
| * removed in a future version. | ||
| */ | ||
| getFeatureFlags?: () => FeatureFlags; | ||
| trace?: TraceCallback; | ||
@@ -104,3 +112,3 @@ }; | ||
| timeoutHandle?: NodeJS.Timeout; | ||
| constructor({ interval, clientId, chainId: InitialChainId, supportedChainIds, trackMetaMetricsEvent, state, messenger, getMetaMetricsProps, getFeatureFlags, trace, }: SmartTransactionsControllerOptions); | ||
| constructor({ interval, clientId, chainId: InitialChainId, supportedChainIds, trackMetaMetricsEvent, state, messenger, getMetaMetricsProps, trace, }: SmartTransactionsControllerOptions); | ||
| _executePoll({ chainIds, }: SmartTransactionsControllerPollingInput): Promise<void>; | ||
@@ -107,0 +115,0 @@ checkPoll({ smartTransactionsState: { smartTransactions }, }: SmartTransactionsControllerState): void; |
@@ -12,3 +12,3 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
| }; | ||
| var _SmartTransactionsController_instances, _SmartTransactionsController_interval, _SmartTransactionsController_clientId, _SmartTransactionsController_chainId, _SmartTransactionsController_supportedChainIds, _SmartTransactionsController_ethQuery, _SmartTransactionsController_trackMetaMetricsEvent, _SmartTransactionsController_getMetaMetricsProps, _SmartTransactionsController_getFeatureFlags, _SmartTransactionsController_trace, _SmartTransactionsController_fetch, _SmartTransactionsController_updateSmartTransaction, _SmartTransactionsController_addMetaMetricsPropsToNewSmartTransaction, _SmartTransactionsController_createOrUpdateSmartTransaction, _SmartTransactionsController_confirmSmartTransaction, _SmartTransactionsController_addNonceToTransaction, _SmartTransactionsController_getChainId, _SmartTransactionsController_getChainIds, _SmartTransactionsController_getNetworkClientId, _SmartTransactionsController_getEthQuery, _SmartTransactionsController_getCurrentSmartTransactions, _SmartTransactionsController_wipeSmartTransactionsPerChainId; | ||
| var _SmartTransactionsController_instances, _SmartTransactionsController_interval, _SmartTransactionsController_clientId, _SmartTransactionsController_chainId, _SmartTransactionsController_supportedChainIds, _SmartTransactionsController_ethQuery, _SmartTransactionsController_trackMetaMetricsEvent, _SmartTransactionsController_getMetaMetricsProps, _SmartTransactionsController_trace, _SmartTransactionsController_validateAndReportFeatureFlags, _SmartTransactionsController_fetch, _SmartTransactionsController_updateSmartTransaction, _SmartTransactionsController_addMetaMetricsPropsToNewSmartTransaction, _SmartTransactionsController_createOrUpdateSmartTransaction, _SmartTransactionsController_confirmSmartTransaction, _SmartTransactionsController_addNonceToTransaction, _SmartTransactionsController_getChainId, _SmartTransactionsController_getChainIds, _SmartTransactionsController_getNetworkClientId, _SmartTransactionsController_getEthQuery, _SmartTransactionsController_getCurrentSmartTransactions, _SmartTransactionsController_wipeSmartTransactionsPerChainId; | ||
| function $importDefault(module) { | ||
@@ -28,3 +28,5 @@ if (module === null || module === void 0 ? void 0 : module.__esModule) { | ||
| const cloneDeep = $importDefault($cloneDeep); | ||
| import { MetaMetricsEventCategory, MetaMetricsEventName, SmartTransactionsTraceName } from "./constants.mjs"; | ||
| import { DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS, MetaMetricsEventCategory, MetaMetricsEventName, SmartTransactionsTraceName } from "./constants.mjs"; | ||
| import { getSmartTransactionsFeatureFlags, getSmartTransactionsFeatureFlagsForChain } from "./featureFlags/feature-flags.mjs"; | ||
| import { validateSmartTransactionsFeatureFlags } from "./featureFlags/validators.mjs"; | ||
| import { APIType, SmartTransactionStatuses } from "./types.mjs"; | ||
@@ -82,3 +84,3 @@ import { calculateStatus, getAPIRequestURL, handleFetch, incrementNonceInHex, isSmartTransactionCancellable, isSmartTransactionPending, getTxHash, getSmartTransactionMetricsProperties, getSmartTransactionMetricsSensitiveProperties, shouldMarkRegularTransactionsAsFailed, markRegularTransactionsAsFailed } from "./utils.mjs"; | ||
| export class SmartTransactionsController extends StaticIntervalPollingController() { | ||
| constructor({ interval = DEFAULT_INTERVAL, clientId, chainId: InitialChainId = ChainId.mainnet, supportedChainIds = [ChainId.mainnet, ChainId.sepolia], trackMetaMetricsEvent, state = {}, messenger, getMetaMetricsProps, getFeatureFlags, trace, }) { | ||
| constructor({ interval = DEFAULT_INTERVAL, clientId, chainId: InitialChainId = ChainId.mainnet, supportedChainIds = [ChainId.mainnet, ChainId.sepolia], trackMetaMetricsEvent, state = {}, messenger, getMetaMetricsProps, trace, }) { | ||
| super({ | ||
@@ -98,3 +100,2 @@ name: controllerName, | ||
| _SmartTransactionsController_getMetaMetricsProps.set(this, void 0); | ||
| _SmartTransactionsController_getFeatureFlags.set(this, void 0); | ||
| _SmartTransactionsController_trace.set(this, void 0); | ||
@@ -109,3 +110,2 @@ __classPrivateFieldSet(this, _SmartTransactionsController_interval, interval, "f"); | ||
| __classPrivateFieldSet(this, _SmartTransactionsController_getMetaMetricsProps, getMetaMetricsProps, "f"); | ||
| __classPrivateFieldSet(this, _SmartTransactionsController_getFeatureFlags, getFeatureFlags, "f"); | ||
| __classPrivateFieldSet(this, _SmartTransactionsController_trace, trace !== null && trace !== void 0 ? trace : ((_request, fn) => fn === null || fn === void 0 ? void 0 : fn()), "f"); | ||
@@ -121,2 +121,6 @@ this.initializeSmartTransactionsForChainId(); | ||
| this.messenger.subscribe(`${controllerName}:stateChange`, (currentState) => this.checkPoll(currentState)); | ||
| // Validate feature flags on changes | ||
| this.messenger.subscribe('RemoteFeatureFlagController:stateChange', () => { | ||
| __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_validateAndReportFeatureFlags).call(this); | ||
| }); | ||
| } | ||
@@ -496,3 +500,12 @@ async _executePoll({ chainIds, }) { | ||
| } | ||
| _SmartTransactionsController_interval = new WeakMap(), _SmartTransactionsController_clientId = new WeakMap(), _SmartTransactionsController_chainId = new WeakMap(), _SmartTransactionsController_supportedChainIds = new WeakMap(), _SmartTransactionsController_ethQuery = new WeakMap(), _SmartTransactionsController_trackMetaMetricsEvent = new WeakMap(), _SmartTransactionsController_getMetaMetricsProps = new WeakMap(), _SmartTransactionsController_getFeatureFlags = new WeakMap(), _SmartTransactionsController_trace = new WeakMap(), _SmartTransactionsController_instances = new WeakSet(), _SmartTransactionsController_fetch = | ||
| _SmartTransactionsController_interval = new WeakMap(), _SmartTransactionsController_clientId = new WeakMap(), _SmartTransactionsController_chainId = new WeakMap(), _SmartTransactionsController_supportedChainIds = new WeakMap(), _SmartTransactionsController_ethQuery = new WeakMap(), _SmartTransactionsController_trackMetaMetricsEvent = new WeakMap(), _SmartTransactionsController_getMetaMetricsProps = new WeakMap(), _SmartTransactionsController_trace = new WeakMap(), _SmartTransactionsController_instances = new WeakSet(), _SmartTransactionsController_validateAndReportFeatureFlags = function _SmartTransactionsController_validateAndReportFeatureFlags() { | ||
| var _a; | ||
| const remoteFeatureFlagControllerState = this.messenger.call('RemoteFeatureFlagController:getState'); | ||
| const rawFlags = (_a = remoteFeatureFlagControllerState === null || remoteFeatureFlagControllerState === void 0 ? void 0 : remoteFeatureFlagControllerState.remoteFeatureFlags) === null || _a === void 0 ? void 0 : _a.smartTransactionsNetworks; | ||
| const { errors } = validateSmartTransactionsFeatureFlags(rawFlags); | ||
| // Report each validation error to Sentry | ||
| for (const error of errors) { | ||
| this.messenger.call('ErrorReportingService:captureException', new Error(`[SmartTransactionsController] Feature flag validation failed: ${error.message}. Please check the SmartTransactionNetworks feature flag in Remote Config. Smart transactions are disabled for this network. Default disabled config: ${JSON.stringify(DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS.default)}`)); | ||
| } | ||
| }, _SmartTransactionsController_fetch = | ||
| /* istanbul ignore next */ | ||
@@ -569,6 +582,7 @@ async function _SmartTransactionsController_fetch(request, options) { | ||
| this.messenger.publish(`SmartTransactionsController:smartTransaction`, nextSmartTransaction); | ||
| const featureFlags = getSmartTransactionsFeatureFlagsForChain(getSmartTransactionsFeatureFlags(this.messenger), chainId); | ||
| if (shouldMarkRegularTransactionsAsFailed({ | ||
| smartTransaction: nextSmartTransaction, | ||
| clientId: __classPrivateFieldGet(this, _SmartTransactionsController_clientId, "f"), | ||
| getFeatureFlags: __classPrivateFieldGet(this, _SmartTransactionsController_getFeatureFlags, "f"), | ||
| featureFlags, | ||
| })) { | ||
@@ -575,0 +589,0 @@ markRegularTransactionsAsFailed({ |
+24
-1
| import type { NetworkClientId } from "@metamask/network-controller"; | ||
| import type { CaipChainId, Hex } from "@metamask/utils"; | ||
| import type { SmartTransactionsNetworkConfig } from "./featureFlags/index.cjs"; | ||
| /** API */ | ||
@@ -106,3 +108,2 @@ export declare enum APIType { | ||
| export declare type SignedCanceledTransaction = any; | ||
| export declare type Hex = `0x${string}`; | ||
| export declare type MetaMetricsProps = { | ||
@@ -119,2 +120,24 @@ accountHardwareType?: string; | ||
| }; | ||
| /** | ||
| * Configuration for smart transactions on a specific network. | ||
| * These flags control feature availability and behavior per chain. | ||
| * | ||
| * This type is inferred from the SmartTransactionsNetworkConfigSchema. | ||
| * To add a new field, update the schema in `src/featureFlags/validators.ts`. | ||
| */ | ||
| export type { SmartTransactionsNetworkConfig }; | ||
| /** | ||
| * Feature flags configuration for smart transactions across all networks. | ||
| * Contains a default configuration and optional chain-specific overrides. | ||
| */ | ||
| export declare type SmartTransactionsFeatureFlagsConfig = { | ||
| /** Default configuration applied to all chains unless overridden */ | ||
| default?: SmartTransactionsNetworkConfig; | ||
| } & { | ||
| /** | ||
| * Chain-specific configuration overrides, keyed by chain ID. | ||
| * Supports both hex (e.g., "0x1") and CAIP-2 format (e.g., "eip155:1", "solana:...") | ||
| */ | ||
| [chainId: Hex | CaipChainId]: SmartTransactionsNetworkConfig | undefined; | ||
| }; | ||
| //# sourceMappingURL=types.d.cts.map |
+24
-1
| import type { NetworkClientId } from "@metamask/network-controller"; | ||
| import type { CaipChainId, Hex } from "@metamask/utils"; | ||
| import type { SmartTransactionsNetworkConfig } from "./featureFlags/index.mjs"; | ||
| /** API */ | ||
@@ -106,3 +108,2 @@ export declare enum APIType { | ||
| export declare type SignedCanceledTransaction = any; | ||
| export declare type Hex = `0x${string}`; | ||
| export declare type MetaMetricsProps = { | ||
@@ -119,2 +120,24 @@ accountHardwareType?: string; | ||
| }; | ||
| /** | ||
| * Configuration for smart transactions on a specific network. | ||
| * These flags control feature availability and behavior per chain. | ||
| * | ||
| * This type is inferred from the SmartTransactionsNetworkConfigSchema. | ||
| * To add a new field, update the schema in `src/featureFlags/validators.ts`. | ||
| */ | ||
| export type { SmartTransactionsNetworkConfig }; | ||
| /** | ||
| * Feature flags configuration for smart transactions across all networks. | ||
| * Contains a default configuration and optional chain-specific overrides. | ||
| */ | ||
| export declare type SmartTransactionsFeatureFlagsConfig = { | ||
| /** Default configuration applied to all chains unless overridden */ | ||
| default?: SmartTransactionsNetworkConfig; | ||
| } & { | ||
| /** | ||
| * Chain-specific configuration overrides, keyed by chain ID. | ||
| * Supports both hex (e.g., "0x1") and CAIP-2 format (e.g., "eip155:1", "solana:...") | ||
| */ | ||
| [chainId: Hex | CaipChainId]: SmartTransactionsNetworkConfig | undefined; | ||
| }; | ||
| //# sourceMappingURL=types.d.mts.map |
+5
-7
@@ -196,10 +196,9 @@ "use strict"; | ||
| exports.getSmartTransactionMetricsSensitiveProperties = getSmartTransactionMetricsSensitiveProperties; | ||
| const getReturnTxHashAsap = (clientId, smartTransactionsFeatureFlags) => { | ||
| const getReturnTxHashAsap = (clientId, featureFlags) => { | ||
| return clientId === types_1.ClientId.Extension | ||
| ? smartTransactionsFeatureFlags === null || smartTransactionsFeatureFlags === void 0 ? void 0 : smartTransactionsFeatureFlags.extensionReturnTxHashAsap | ||
| : smartTransactionsFeatureFlags === null || smartTransactionsFeatureFlags === void 0 ? void 0 : smartTransactionsFeatureFlags.mobileReturnTxHashAsap; | ||
| ? featureFlags.extensionReturnTxHashAsap | ||
| : featureFlags.mobileReturnTxHashAsap; | ||
| }; | ||
| exports.getReturnTxHashAsap = getReturnTxHashAsap; | ||
| const shouldMarkRegularTransactionsAsFailed = ({ smartTransaction, clientId, getFeatureFlags, }) => { | ||
| var _a; | ||
| const shouldMarkRegularTransactionsAsFailed = ({ smartTransaction, clientId, featureFlags, }) => { | ||
| const { status, transactionId } = smartTransaction; | ||
@@ -216,4 +215,3 @@ const failureStatuses = [ | ||
| } | ||
| const { smartTransactions: smartTransactionsFeatureFlags } = (_a = getFeatureFlags()) !== null && _a !== void 0 ? _a : {}; | ||
| const returnTxHashAsapEnabled = (0, exports.getReturnTxHashAsap)(clientId, smartTransactionsFeatureFlags); | ||
| const returnTxHashAsapEnabled = (0, exports.getReturnTxHashAsap)(clientId, featureFlags); | ||
| return Boolean(returnTxHashAsapEnabled && transactionId); | ||
@@ -220,0 +218,0 @@ }; |
+4
-4
| import type { TransactionControllerGetTransactionsAction, TransactionControllerUpdateTransactionAction } from "@metamask/transaction-controller"; | ||
| import type { SmartTransaction, SmartTransactionsStatus, FeatureFlags } from "./types.cjs"; | ||
| import type { SmartTransaction, SmartTransactionsStatus, SmartTransactionsNetworkConfig } from "./types.cjs"; | ||
| import { APIType, SmartTransactionStatuses, ClientId } from "./types.cjs"; | ||
@@ -55,7 +55,7 @@ export declare function isSmartTransactionPending(smartTransaction: SmartTransaction): boolean; | ||
| }; | ||
| export declare const getReturnTxHashAsap: (clientId: ClientId, smartTransactionsFeatureFlags: FeatureFlags['smartTransactions']) => boolean | undefined; | ||
| export declare const shouldMarkRegularTransactionsAsFailed: ({ smartTransaction, clientId, getFeatureFlags, }: { | ||
| export declare const getReturnTxHashAsap: (clientId: ClientId, featureFlags: SmartTransactionsNetworkConfig) => boolean | undefined; | ||
| export declare const shouldMarkRegularTransactionsAsFailed: ({ smartTransaction, clientId, featureFlags, }: { | ||
| smartTransaction: SmartTransaction; | ||
| clientId: ClientId; | ||
| getFeatureFlags: () => FeatureFlags; | ||
| featureFlags: SmartTransactionsNetworkConfig; | ||
| }) => boolean; | ||
@@ -62,0 +62,0 @@ export declare const markRegularTransactionsAsFailed: ({ smartTransaction, getRegularTransactions, updateTransaction, }: { |
+4
-4
| import type { TransactionControllerGetTransactionsAction, TransactionControllerUpdateTransactionAction } from "@metamask/transaction-controller"; | ||
| import type { SmartTransaction, SmartTransactionsStatus, FeatureFlags } from "./types.mjs"; | ||
| import type { SmartTransaction, SmartTransactionsStatus, SmartTransactionsNetworkConfig } from "./types.mjs"; | ||
| import { APIType, SmartTransactionStatuses, ClientId } from "./types.mjs"; | ||
@@ -55,7 +55,7 @@ export declare function isSmartTransactionPending(smartTransaction: SmartTransaction): boolean; | ||
| }; | ||
| export declare const getReturnTxHashAsap: (clientId: ClientId, smartTransactionsFeatureFlags: FeatureFlags['smartTransactions']) => boolean | undefined; | ||
| export declare const shouldMarkRegularTransactionsAsFailed: ({ smartTransaction, clientId, getFeatureFlags, }: { | ||
| export declare const getReturnTxHashAsap: (clientId: ClientId, featureFlags: SmartTransactionsNetworkConfig) => boolean | undefined; | ||
| export declare const shouldMarkRegularTransactionsAsFailed: ({ smartTransaction, clientId, featureFlags, }: { | ||
| smartTransaction: SmartTransaction; | ||
| clientId: ClientId; | ||
| getFeatureFlags: () => FeatureFlags; | ||
| featureFlags: SmartTransactionsNetworkConfig; | ||
| }) => boolean; | ||
@@ -62,0 +62,0 @@ export declare const markRegularTransactionsAsFailed: ({ smartTransaction, getRegularTransactions, updateTransaction, }: { |
+5
-7
@@ -185,9 +185,8 @@ function $importDefault(module) { | ||
| }; | ||
| export const getReturnTxHashAsap = (clientId, smartTransactionsFeatureFlags) => { | ||
| export const getReturnTxHashAsap = (clientId, featureFlags) => { | ||
| return clientId === ClientId.Extension | ||
| ? smartTransactionsFeatureFlags === null || smartTransactionsFeatureFlags === void 0 ? void 0 : smartTransactionsFeatureFlags.extensionReturnTxHashAsap | ||
| : smartTransactionsFeatureFlags === null || smartTransactionsFeatureFlags === void 0 ? void 0 : smartTransactionsFeatureFlags.mobileReturnTxHashAsap; | ||
| ? featureFlags.extensionReturnTxHashAsap | ||
| : featureFlags.mobileReturnTxHashAsap; | ||
| }; | ||
| export const shouldMarkRegularTransactionsAsFailed = ({ smartTransaction, clientId, getFeatureFlags, }) => { | ||
| var _a; | ||
| export const shouldMarkRegularTransactionsAsFailed = ({ smartTransaction, clientId, featureFlags, }) => { | ||
| const { status, transactionId } = smartTransaction; | ||
@@ -204,4 +203,3 @@ const failureStatuses = [ | ||
| } | ||
| const { smartTransactions: smartTransactionsFeatureFlags } = (_a = getFeatureFlags()) !== null && _a !== void 0 ? _a : {}; | ||
| const returnTxHashAsapEnabled = getReturnTxHashAsap(clientId, smartTransactionsFeatureFlags); | ||
| const returnTxHashAsapEnabled = getReturnTxHashAsap(clientId, featureFlags); | ||
| return Boolean(returnTxHashAsapEnabled && transactionId); | ||
@@ -208,0 +206,0 @@ }; |
+9
-5
| { | ||
| "name": "@metamask/smart-transactions-controller", | ||
| "version": "21.1.0", | ||
| "version": "22.0.0", | ||
| "description": "Improves success rates for swaps by trialing transactions privately and finding minimum fees", | ||
@@ -54,5 +54,8 @@ "repository": { | ||
| "@metamask/polling-controller": "^15.0.0", | ||
| "@metamask/superstruct": "^3.1.0", | ||
| "@metamask/utils": "^11.0.0", | ||
| "bignumber.js": "^9.0.1", | ||
| "fast-json-patch": "^3.1.0", | ||
| "lodash": "^4.17.21" | ||
| "lodash": "^4.17.21", | ||
| "reselect": "^5.1.1" | ||
| }, | ||
@@ -64,2 +67,3 @@ "devDependencies": { | ||
| "@metamask/auto-changelog": "^3.1.0", | ||
| "@metamask/error-reporting-service": "^3.0.0", | ||
| "@metamask/eslint-config": "^12.2.0", | ||
@@ -72,2 +76,3 @@ "@metamask/eslint-config-jest": "^12.1.0", | ||
| "@metamask/network-controller": "^25.0.0", | ||
| "@metamask/remote-feature-flag-controller": "^2.0.0", | ||
| "@metamask/transaction-controller": "^61.0.0", | ||
@@ -99,3 +104,5 @@ "@ts-bridge/cli": "^0.6.3", | ||
| "peerDependencies": { | ||
| "@metamask/error-reporting-service": "^3.0.0", | ||
| "@metamask/network-controller": "^25.0.0", | ||
| "@metamask/remote-feature-flag-controller": "^2.0.0", | ||
| "@metamask/transaction-controller": "^61.0.0" | ||
@@ -115,5 +122,2 @@ }, | ||
| "optional": true | ||
| }, | ||
| "@metamask/remote-feature-flag-controller": { | ||
| "optional": true | ||
| } | ||
@@ -120,0 +124,0 @@ }, |
+47
-0
@@ -28,2 +28,49 @@ # `@metamask/smart-transactions-controller` | ||
| ### Feature Flags | ||
| Smart transactions feature flags are managed via `RemoteFeatureFlagController` (LaunchDarkly). The configuration uses a `default` remote object for global settings and chain-specific overrides keyed by hex chain ID. | ||
| The flag in LaunchDarkly is named `smartTransactionsNetworks`. | ||
| #### Adding a New Flag | ||
| 1. **Add the field to the schema** in `src/utils/validators.ts`: | ||
| ```typescript | ||
| export const SmartTransactionsNetworkConfigSchema = type({ | ||
| // ... existing fields | ||
| myNewFlag: optional(boolean()), | ||
| }); | ||
| ``` | ||
| The `SmartTransactionsNetworkConfig` type is automatically inferred from this schema. | ||
| 2. **Add default value** in `src/constants.ts` under `DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS`: | ||
| These values should be defensive. They are applied when the remote config is invalid or does not exist for a network. | ||
| It disables smart transaction. | ||
| ```typescript | ||
| export const DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS = { | ||
| default: { | ||
| // ... existing defaults | ||
| myNewFlag: false, | ||
| }, | ||
| }; | ||
| ``` | ||
| 3. **Use in clients** via the exported selectors: | ||
| ```typescript | ||
| import { selectSmartTransactionsFeatureFlagsForChain } from '@metamask/smart-transactions-controller'; | ||
| const chainConfig = selectSmartTransactionsFeatureFlagsForChain( | ||
| state, | ||
| '0x1', | ||
| ); | ||
| if (chainConfig.myNewFlag) { | ||
| // Feature is enabled | ||
| } | ||
| ``` | ||
| ### Release & Publishing | ||
@@ -30,0 +77,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
550012
36.42%76
72.73%2688
34.53%151
45.19%22
29.41%37
5.71%17
13.33%+ Added
+ Added
+ Added