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
11 changes: 11 additions & 0 deletions packages/bridge-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `AccountHardwareType` type and `getAccountHardwareType` function to the package exports ([#8503](https://github.com/MetaMask/core/pull/8503))
- `AccountHardwareType` is a union of `'Ledger' | 'Trezor' | 'QR Hardware' | 'Lattice' | null`
- `getAccountHardwareType` maps a keyring type string to the corresponding `AccountHardwareType` value

### Changed

- Add `account_hardware_type` field to `RequestMetadata` and all cross-chain swap analytics events ([#8503](https://github.com/MetaMask/core/pull/8503))
- `account_hardware_type` carries the specific hardware wallet brand (e.g. `'Ledger'`) or `null` for software wallets
- `is_hardware_wallet` is now derived from `account_hardware_type !== null`, keeping both fields in sync
- `EventPropertiesFromControllerState[PageViewed]` now includes `account_hardware_type`, `is_hardware_wallet`, `custom_slippage`, `slippage_limit`, and `swap_type` (previously only `RequestParams` fields were included)

- Bump `@metamask/transaction-controller` from `^64.2.0` to `^64.3.0` ([#8482](https://github.com/MetaMask/core/pull/8482))
- Bump `@metamask/keyring-api` from `^21.6.0` to `^23.0.1` ([#8464](https://github.com/MetaMask/core/pull/8464))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ exports[`BridgeController SSE should replace all stale quotes after a refresh an
[
"Unified SwapBridge Quotes Requested",
{
"account_hardware_type": null,
"action_type": "swapbridge-v1",
"chain_id_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"chain_id_source": "eip155:1",
Expand All @@ -89,6 +90,7 @@ exports[`BridgeController SSE should reset and refetch quotes after quote reques
[
"Unified SwapBridge Quotes Requested",
{
"account_hardware_type": null,
"action_type": "swapbridge-v1",
"chain_id_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"chain_id_source": "eip155:1",
Expand All @@ -115,6 +117,7 @@ exports[`BridgeController SSE should reset quotes list if quote refresh fails 2`
[
"Unified SwapBridge Quotes Requested",
{
"account_hardware_type": null,
"action_type": "swapbridge-v1",
"chain_id_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"chain_id_source": "eip155:1",
Expand All @@ -137,6 +140,7 @@ exports[`BridgeController SSE should reset quotes list if quote refresh fails 2`
[
"Unified SwapBridge Quotes Error",
{
"account_hardware_type": null,
"action_type": "swapbridge-v1",
"chain_id_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"chain_id_source": "eip155:1",
Expand Down Expand Up @@ -232,6 +236,7 @@ exports[`BridgeController SSE should rethrow error from server 3`] = `
[
"Unified SwapBridge Quotes Requested",
{
"account_hardware_type": null,
"action_type": "swapbridge-v1",
"chain_id_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"chain_id_source": "eip155:1",
Expand All @@ -254,6 +259,7 @@ exports[`BridgeController SSE should rethrow error from server 3`] = `
[
"Unified SwapBridge Quotes Error",
{
"account_hardware_type": null,
"action_type": "swapbridge-v1",
"chain_id_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"chain_id_source": "eip155:1",
Expand Down Expand Up @@ -349,6 +355,7 @@ exports[`BridgeController SSE should trigger quote polling if request is valid 2
[
"Unified SwapBridge Quotes Requested",
{
"account_hardware_type": null,
"action_type": "swapbridge-v1",
"chain_id_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"chain_id_source": "eip155:1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ exports[`BridgeController trackUnifiedSwapBridgeEvent bridge-status-controller c
[
"Unified SwapBridge Completed",
{
"account_hardware_type": null,
"action_type": "swapbridge-v1",
"actual_time_minutes": 10,
"approval_transaction": "PENDING",
Expand Down Expand Up @@ -98,6 +99,7 @@ exports[`BridgeController trackUnifiedSwapBridgeEvent bridge-status-controller c
[
"Unified SwapBridge Failed",
{
"account_hardware_type": null,
"action_type": "swapbridge-v1",
"actual_time_minutes": 10,
"allowance_reset_transaction": "PENDING",
Expand Down Expand Up @@ -140,6 +142,7 @@ exports[`BridgeController trackUnifiedSwapBridgeEvent bridge-status-controller c
[
"Unified SwapBridge Failed",
{
"account_hardware_type": null,
"action_type": "swapbridge-v1",
"chain_id_destination": "eip155:1",
"chain_id_source": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
Expand Down Expand Up @@ -195,6 +198,7 @@ exports[`BridgeController trackUnifiedSwapBridgeEvent bridge-status-controller c
[
"Unified SwapBridge Submitted",
{
"account_hardware_type": null,
"action_type": "swapbridge-v1",
"chain_id_destination": "eip155:1",
"chain_id_source": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
Expand Down Expand Up @@ -223,6 +227,7 @@ exports[`BridgeController trackUnifiedSwapBridgeEvent client-side calls should t
[
"Unified SwapBridge All Quotes Opened",
{
"account_hardware_type": null,
"action_type": "swapbridge-v1",
"can_submit": true,
"chain_id_destination": null,
Expand Down Expand Up @@ -253,6 +258,7 @@ exports[`BridgeController trackUnifiedSwapBridgeEvent client-side calls should t
[
"Unified SwapBridge All Quotes Sorted",
{
"account_hardware_type": null,
"action_type": "swapbridge-v1",
"best_quote_provider": "provider_bridge2",
"can_submit": true,
Expand Down Expand Up @@ -341,11 +347,15 @@ exports[`BridgeController trackUnifiedSwapBridgeEvent client-side calls should t
[
"Unified SwapBridge Page Viewed",
{
"abc": 1,
"account_hardware_type": null,
"action_type": "swapbridge-v1",
"chain_id_destination": null,
"chain_id_source": "eip155:1",
"custom_slippage": false,
"is_hardware_wallet": false,
"location": "Main View",
"slippage_limit": undefined,
"swap_type": "crosschain",
"token_address_destination": null,
"token_address_source": "eip155:1/slip44:60",
},
Expand All @@ -358,6 +368,7 @@ exports[`BridgeController trackUnifiedSwapBridgeEvent client-side calls should t
[
"Unified SwapBridge Quote Selected",
{
"account_hardware_type": null,
"action_type": "swapbridge-v1",
"best_quote_provider": "provider_bridge2",
"can_submit": false,
Expand Down Expand Up @@ -401,6 +412,7 @@ exports[`BridgeController trackUnifiedSwapBridgeEvent client-side calls should t
[
"Unified SwapBridge Quotes Received",
{
"account_hardware_type": null,
"action_type": "swapbridge-v1",
"best_quote_provider": "provider_bridge2",
"can_submit": true,
Expand Down Expand Up @@ -475,6 +487,7 @@ exports[`BridgeController updateBridgeQuoteRequestParams should only poll once i
[
"Unified SwapBridge Quotes Requested",
{
"account_hardware_type": null,
"action_type": "swapbridge-v1",
"chain_id_destination": "eip155:10",
"chain_id_source": "eip155:1",
Expand All @@ -497,6 +510,7 @@ exports[`BridgeController updateBridgeQuoteRequestParams should only poll once i
[
"Unified SwapBridge Quotes Received",
{
"account_hardware_type": null,
"action_type": "swapbridge-v1",
"best_quote_provider": "provider_bridge2",
"can_submit": true,
Expand Down Expand Up @@ -892,6 +906,7 @@ exports[`BridgeController updateBridgeQuoteRequestParams should trigger quote po
[
"Unified SwapBridge Quotes Requested",
{
"account_hardware_type": null,
"action_type": "swapbridge-v1",
"chain_id_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"chain_id_source": "eip155:1",
Expand All @@ -914,6 +929,7 @@ exports[`BridgeController updateBridgeQuoteRequestParams should trigger quote po
[
"Unified SwapBridge Quotes Requested",
{
"account_hardware_type": null,
"action_type": "swapbridge-v1",
"chain_id_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"chain_id_source": "eip155:1",
Expand All @@ -936,6 +952,7 @@ exports[`BridgeController updateBridgeQuoteRequestParams should trigger quote po
[
"Unified SwapBridge Quotes Requested",
{
"account_hardware_type": null,
"action_type": "swapbridge-v1",
"chain_id_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"chain_id_source": "eip155:1",
Expand All @@ -958,6 +975,7 @@ exports[`BridgeController updateBridgeQuoteRequestParams should trigger quote po
[
"Unified SwapBridge Quotes Error",
{
"account_hardware_type": null,
"action_type": "swapbridge-v1",
"chain_id_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"chain_id_source": "eip155:1",
Expand All @@ -981,6 +999,7 @@ exports[`BridgeController updateBridgeQuoteRequestParams should trigger quote po
[
"Unified SwapBridge Quotes Requested",
{
"account_hardware_type": null,
"action_type": "swapbridge-v1",
"chain_id_destination": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"chain_id_source": "eip155:1",
Expand Down
6 changes: 4 additions & 2 deletions packages/bridge-controller/src/bridge-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2895,8 +2895,7 @@ describe('BridgeController', function () {
rootMessenger.call(
'BridgeController:trackUnifiedSwapBridgeEvent',
UnifiedSwapBridgeEventName.PageViewed,
// @ts-expect-error Partial mock.
{ abc: 1 },
{},
);
expect(trackMetaMetricsFn).toHaveBeenCalledTimes(1);

Expand Down Expand Up @@ -3267,6 +3266,7 @@ describe('BridgeController', function () {
chain_id_destination: formatChainIdToCaip(1),
custom_slippage: false,
is_hardware_wallet: false,
account_hardware_type: null,
slippage_limit: 0.5,
usd_quoted_gas: 1,
gas_included: false,
Expand Down Expand Up @@ -3310,6 +3310,7 @@ describe('BridgeController', function () {
usd_amount_source: 100,
stx_enabled: false,
is_hardware_wallet: false,
account_hardware_type: null,
swap_type: MetricsSwapType.CROSSCHAIN,
provider: 'provider_bridge',
price_impact: 6,
Expand Down Expand Up @@ -3355,6 +3356,7 @@ describe('BridgeController', function () {
usd_amount_source: 100,
stx_enabled: false,
is_hardware_wallet: false,
account_hardware_type: null,
swap_type: MetricsSwapType.CROSSCHAIN,
chain_id_destination: formatChainIdToCaip(ChainId.SOLANA),
token_symbol_destination: 'USDC',
Expand Down
33 changes: 16 additions & 17 deletions packages/bridge-controller/src/bridge-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ import {
} from './utils/metrics/constants';
import {
formatProviderLabel,
getAccountHardwareType,
getRequestParams,
getSwapTypeFromQuote,
isCustomSlippage,
isHardwareWallet,
toInputChangedPropertyKey,
toInputChangedPropertyValue,
} from './utils/metrics/properties';
Expand Down Expand Up @@ -933,15 +933,21 @@ export class BridgeController extends StaticIntervalPollingController<BridgePoll

readonly #getRequestMetadata = (): Omit<
RequestMetadata,
| 'stx_enabled'
| 'usd_amount_source'
| 'security_warnings'
| 'is_hardware_wallet'
'stx_enabled' | 'usd_amount_source' | 'security_warnings'
> => {
const { walletAddress } = this.state.quoteRequest;
const accountHardwareType = getAccountHardwareType(
walletAddress
? this.#getMultichainSelectedAccount(walletAddress)
: undefined,
);

return {
slippage_limit: this.state.quoteRequest.slippage,
swap_type: getSwapTypeFromQuote(this.state.quoteRequest),
custom_slippage: isCustomSlippage(this.state.quoteRequest.slippage),
account_hardware_type: accountHardwareType,
is_hardware_wallet: accountHardwareType !== null,
};
};

Expand Down Expand Up @@ -979,9 +985,14 @@ export class BridgeController extends StaticIntervalPollingController<BridgePoll
};
switch (eventName) {
case UnifiedSwapBridgeEventName.ButtonClicked:
return {
...getRequestParams(this.state.quoteRequest),
...baseProperties,
};
case UnifiedSwapBridgeEventName.PageViewed:
return {
...getRequestParams(this.state.quoteRequest),
...this.#getRequestMetadata(),
...baseProperties,
};
case UnifiedSwapBridgeEventName.QuotesValidationFailed:
Expand All @@ -995,29 +1006,20 @@ export class BridgeController extends StaticIntervalPollingController<BridgePoll
...getRequestParams(this.state.quoteRequest),
...this.#getRequestMetadata(),
...this.#getQuoteFetchData(),
is_hardware_wallet: isHardwareWallet(
this.#getMultichainSelectedAccount(),
),
refresh_count: this.state.quotesRefreshCount,
...baseProperties,
};
case UnifiedSwapBridgeEventName.QuotesRequested:
return {
...getRequestParams(this.state.quoteRequest),
...this.#getRequestMetadata(),
is_hardware_wallet: isHardwareWallet(
this.#getMultichainSelectedAccount(),
),
has_sufficient_funds: !this.state.quoteRequest.insufficientBal,
...baseProperties,
};
case UnifiedSwapBridgeEventName.QuotesError:
return {
...getRequestParams(this.state.quoteRequest),
...this.#getRequestMetadata(),
is_hardware_wallet: isHardwareWallet(
this.#getMultichainSelectedAccount(),
),
error_message: this.state.quoteFetchError,
has_sufficient_funds: !this.state.quoteRequest.insufficientBal,
...baseProperties,
Expand All @@ -1029,9 +1031,6 @@ export class BridgeController extends StaticIntervalPollingController<BridgePoll
...getRequestParams(this.state.quoteRequest),
...this.#getRequestMetadata(),
...this.#getQuoteFetchData(),
is_hardware_wallet: isHardwareWallet(
this.#getMultichainSelectedAccount(),
),
...baseProperties,
};
case UnifiedSwapBridgeEventName.Failed: {
Expand Down
2 changes: 2 additions & 0 deletions packages/bridge-controller/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export {
} from './utils/metrics/constants';

export type {
AccountHardwareType,
RequiredEventContextFromClient,
CrossChainSwapsEventProperties,
TradeData,
Expand All @@ -20,6 +21,7 @@ export type {
} from './utils/metrics/types';

export {
getAccountHardwareType,
formatProviderLabel,
getRequestParams,
getSwapType,
Expand Down
Loading
Loading