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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/transaction-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Add event-driven transaction polling via `AccountActivityService:transactionUpdated` ([#7822](https://github.com/MetaMask/core/pull/7822))
- Add optional `requiredAssets` to `TransactionMeta` ([#7820](https://github.com/MetaMask/core/pull/7820))

### Changed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import type { AccountsController } from '@metamask/accounts-controller';
import { toHex } from '@metamask/controller-utils';
import type {
Transaction as AccountActivityTransaction,
WebSocketConnectionInfo,
} from '@metamask/core-backend';
import { WebSocketState } from '@metamask/core-backend';
import type { Hex } from '@metamask/utils';
import { isCaipChainId, parseCaipChainId } from '@metamask/utils';
// This package purposefully relies on Node's EventEmitter module.
// eslint-disable-next-line import-x/no-nodejs-modules
import EventEmitter from 'events';
Expand All @@ -19,6 +17,7 @@ import {
getIncomingTransactionsPollingInterval,
isIncomingTransactionsUseWebsocketsEnabled,
} from '../utils/feature-flags';
import { caip2ToHex } from '../utils/utils';

export type IncomingTransactionOptions = {
/** Name of the client to include in requests. */
Expand Down Expand Up @@ -420,24 +419,6 @@ export class IncomingTransactionHelper {
return tags?.length ? tags : undefined;
}

/**
* Convert CAIP-2 chain ID to hex format.
*
* @param caip2ChainId - Chain ID in CAIP-2 format (e.g., 'eip155:1')
* @returns Hex chain ID (e.g., '0x1') or undefined if invalid format
*/
#caip2ToHex(caip2ChainId: string): Hex | undefined {
if (!isCaipChainId(caip2ChainId)) {
return undefined;
}
try {
const { reference } = parseCaipChainId(caip2ChainId);
return toHex(reference);
} catch {
return undefined;
}
}

#onNetworkStatusChanged(chainIds: string[], status: 'up' | 'down'): void {
if (!this.#useWebsockets) {
return;
Expand All @@ -446,7 +427,7 @@ export class IncomingTransactionHelper {
let hasChanges = false;

for (const caip2ChainId of chainIds) {
const hexChainId = this.#caip2ToHex(caip2ChainId);
const hexChainId = caip2ToHex(caip2ChainId);

if (!hexChainId || !SUPPORTED_CHAIN_IDS.includes(hexChainId)) {
log('Chain ID not recognized or not supported', {
Expand Down
Loading
Loading