Skip to content
Merged
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
10 changes: 0 additions & 10 deletions eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -650,21 +650,11 @@
"count": 1
}
},
"packages/bridge-controller/src/utils/metrics/constants.ts": {
"@typescript-eslint/naming-convention": {
"count": 2
}
},
"packages/bridge-controller/src/utils/metrics/properties.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 5
}
},
"packages/bridge-controller/src/utils/metrics/types.ts": {
"@typescript-eslint/naming-convention": {
"count": 83
}
},
"packages/bridge-controller/src/utils/quote-fees.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 1
Expand Down
1 change: 1 addition & 0 deletions packages/bridge-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Add `HYPEREVM` network support ([#7787](https://github.com/MetaMask/core/pull/7787))
- Add `HYPEREVM` into constants `ALLOWED_BRIDGE_CHAIN_IDS`, `SWAPS_TOKEN_OBJECT` and `NETWORK_TO_NAME_MAP`
- Add `PollingStatusUpdated` to `UnifiedSwapBridgeEventName` enum and `PollingStatus` enum with `MaxPollingReached` and `ManuallyRestarted` values ([#7825](https://github.com/MetaMask/core/pull/7825))

### Changed

Expand Down
1 change: 1 addition & 0 deletions packages/bridge-controller/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export { BridgeController } from './bridge-controller';
export {
UnifiedSwapBridgeEventName,
UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY,
PollingStatus,
} from './utils/metrics/constants';

export type {
Expand Down
7 changes: 7 additions & 0 deletions packages/bridge-controller/src/utils/metrics/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/naming-convention */
export const UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY = 'Unified SwapBridge';

/**
Expand All @@ -20,6 +21,12 @@ export enum UnifiedSwapBridgeEventName {
AssetDetailTooltipClicked = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Asset Detail Tooltip Clicked`,
QuotesValidationFailed = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Quotes Failed Validation`,
StatusValidationFailed = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Status Failed Validation`,
PollingStatusUpdated = `${UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY} Polling Status Updated`,
}

export enum PollingStatus {
MaxPollingReached = 'max_polling_reached',
ManuallyRestarted = 'manually_restarted',
}

export enum AbortReason {
Expand Down
17 changes: 17 additions & 0 deletions packages/bridge-controller/src/utils/metrics/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type { CaipAssetType, CaipChainId } from '@metamask/utils';

import type {
UnifiedSwapBridgeEventName,
MetaMetricsSwapsEventSource,
MetricsActionType,
MetricsSwapType,
PollingStatus,
} from './constants';
import type { SortOrder, StatusTypes } from '../../types';

Expand Down Expand Up @@ -212,6 +214,20 @@ export type RequiredEventContextFromClient = {
[UnifiedSwapBridgeEventName.StatusValidationFailed]: {
failures: string[];
};
[UnifiedSwapBridgeEventName.PollingStatusUpdated]: TradeData &
Pick<QuoteFetchData, 'price_impact'> &
Omit<RequestMetadata, 'security_warnings'> &
Pick<
RequestParams,
| 'token_symbol_source'
| 'token_symbol_destination'
| 'chain_id_source'
| 'chain_id_destination'
> & {
action_type: MetricsActionType;
polling_status: PollingStatus;
retry_attempts: number;
};
};

/**
Expand Down Expand Up @@ -268,6 +284,7 @@ export type EventPropertiesFromControllerState = {
[UnifiedSwapBridgeEventName.StatusValidationFailed]: RequestParams & {
refresh_count: number;
};
[UnifiedSwapBridgeEventName.PollingStatusUpdated]: null;
};

/**
Expand Down
4 changes: 4 additions & 0 deletions packages/bridge-status-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `Unified SwapBridge Polling Status Updated` metrics event with `status` property (`max_polling_reached` or `manually_restarted`), emitted when polling stops due to max attempts or is manually restarted ([#7825](https://github.com/MetaMask/core/pull/7825))

### Changed

- Bump `@metamask/transaction-controller` from `^62.11.0` to `^62.12.0` ([#7775](https://github.com/MetaMask/core/pull/7775))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
isBitcoinTrade,
isTronTrade,
AbortReason,
PollingStatus,
} from '@metamask/bridge-controller';
import type { TraceCallback } from '@metamask/controller-utils';
import { toHex } from '@metamask/controller-utils';
Expand Down Expand Up @@ -379,6 +380,9 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid

const historyItem = this.state.txHistory[targetTxMetaId];

// Capture attempts count before resetting for metrics
const previousAttempts = historyItem.attempts?.counter ?? 0;

// Reset the attempts counter
this.update((state) => {
if (targetTxMetaId) {
Expand All @@ -400,6 +404,38 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
if (!existingPollingToken) {
// Restart polling
this.#startPollingForTxId(targetTxMetaId);

// Track polling manually restarted event
if (!historyItem.featureId) {
const selectedAccount = this.messenger.call(
'AccountsController:getAccountByAddress',
historyItem.account,
);
const requestParams = getRequestParamFromHistory(historyItem);
const requestMetadata = getRequestMetadataFromHistory(
historyItem,
selectedAccount,
);
const { security_warnings: _, ...metadataWithoutWarnings } =
requestMetadata;

this.#trackUnifiedSwapBridgeEvent(
UnifiedSwapBridgeEventName.PollingStatusUpdated,
targetTxMetaId,
{
...getTradeDataFromHistory(historyItem),
...getPriceImpactFromQuote(historyItem.quote),
...metadataWithoutWarnings,
chain_id_source: requestParams.chain_id_source,
chain_id_destination: requestParams.chain_id_destination,
token_symbol_source: requestParams.token_symbol_source,
token_symbol_destination: requestParams.token_symbol_destination,
action_type: MetricsActionType.SWAPBRIDGE_V1,
polling_status: PollingStatus.ManuallyRestarted,
retry_attempts: previousAttempts,
},
);
}
}
}
};
Expand Down Expand Up @@ -665,6 +701,39 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
if (newAttempts.counter >= MAX_ATTEMPTS && pollingToken) {
this.stopPollingByPollingToken(pollingToken);
delete this.#pollingTokensByTxMetaId[bridgeTxMetaId];

// Track max polling reached event
const historyItem = this.state.txHistory[bridgeTxMetaId];
if (historyItem && !historyItem.featureId) {
const selectedAccount = this.messenger.call(
'AccountsController:getAccountByAddress',
historyItem.account,
);
const requestParams = getRequestParamFromHistory(historyItem);
const requestMetadata = getRequestMetadataFromHistory(
historyItem,
selectedAccount,
);
const { security_warnings: _, ...metadataWithoutWarnings } =
requestMetadata;

this.#trackUnifiedSwapBridgeEvent(
UnifiedSwapBridgeEventName.PollingStatusUpdated,
bridgeTxMetaId,
{
...getTradeDataFromHistory(historyItem),
...getPriceImpactFromQuote(historyItem.quote),
...metadataWithoutWarnings,
chain_id_source: requestParams.chain_id_source,
chain_id_destination: requestParams.chain_id_destination,
token_symbol_source: requestParams.token_symbol_source,
token_symbol_destination: requestParams.token_symbol_destination,
action_type: MetricsActionType.SWAPBRIDGE_V1,
polling_status: PollingStatus.MaxPollingReached,
retry_attempts: newAttempts.counter,
},
);
}
}

// Update the attempts counter
Expand Down Expand Up @@ -1915,7 +1984,8 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
| typeof UnifiedSwapBridgeEventName.Submitted
| typeof UnifiedSwapBridgeEventName.Failed
| typeof UnifiedSwapBridgeEventName.Completed
| typeof UnifiedSwapBridgeEventName.StatusValidationFailed,
| typeof UnifiedSwapBridgeEventName.StatusValidationFailed
| typeof UnifiedSwapBridgeEventName.PollingStatusUpdated,
>(
eventName: EventName,
txMetaId?: string,
Expand Down