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/bridge-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

- Support emitting Unified SwapBridge input currency mode on quote and input changed metrics ([#8909](https://github.com/MetaMask/core/pull/8909))
- Add optional `has_sufficient_gas_for_quote` property to `QuotesReceived` event and `getQuotesReceivedProperties` utility to allow clients to pass whether the user has sufficient gas to submit the quote ([#8895](https://github.com/MetaMask/core/pull/8895))

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ exports[`BridgeController BatchSell (multiple quote requests) SSE fetch quotes s
{
"action_type": "swapbridge-v1",
"input": "chain_source",
"input_currency_mode": "crypto",
"input_value": "eip155:10",
"location": "Main View",
},
Expand All @@ -76,6 +77,7 @@ exports[`BridgeController BatchSell (multiple quote requests) SSE fetch quotes s
{
"action_type": "swapbridge-v1",
"input": "chain_destination",
"input_currency_mode": "crypto",
"input_value": "eip155:137",
"location": "Main View",
},
Expand All @@ -85,6 +87,7 @@ exports[`BridgeController BatchSell (multiple quote requests) SSE fetch quotes s
{
"action_type": "swapbridge-v1",
"input": "token_destination",
"input_currency_mode": "crypto",
"input_value": "eip155:137/erc20:0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
"location": "Main View",
},
Expand All @@ -94,6 +97,7 @@ exports[`BridgeController BatchSell (multiple quote requests) SSE fetch quotes s
{
"action_type": "swapbridge-v1",
"input": "slippage",
"input_currency_mode": "crypto",
"input_value": 0.5,
"location": "Main View",
},
Expand All @@ -107,6 +111,7 @@ exports[`BridgeController BatchSell (multiple quote requests) SSE fetch quotes s
"chain_id_source": "eip155:10",
"custom_slippage": true,
"has_sufficient_funds": true,
"input_currency_mode": "crypto",
"is_hardware_wallet": false,
"location": "Main View",
"security_warnings": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ exports[`BridgeController SSE should replace all stale quotes after a refresh an
"chain_id_source": "eip155:1",
"custom_slippage": true,
"has_sufficient_funds": true,
"input_currency_mode": "crypto",
"is_hardware_wallet": false,
"location": "Main View",
"security_warnings": [],
Expand Down Expand Up @@ -100,6 +101,7 @@ exports[`BridgeController SSE should reset and refetch quotes after quote reques
"chain_id_source": "eip155:1",
"custom_slippage": true,
"has_sufficient_funds": false,
"input_currency_mode": "crypto",
"is_hardware_wallet": false,
"location": "Main View",
"security_warnings": [],
Expand Down Expand Up @@ -128,6 +130,7 @@ exports[`BridgeController SSE should reset quotes list if quote refresh fails 2`
"chain_id_source": "eip155:1",
"custom_slippage": true,
"has_sufficient_funds": true,
"input_currency_mode": "crypto",
"is_hardware_wallet": false,
"location": "Main View",
"security_warnings": [],
Expand Down Expand Up @@ -214,6 +217,7 @@ exports[`BridgeController SSE should rethrow error from server 3`] = `
{
"action_type": "swapbridge-v1",
"input": "chain_source",
"input_currency_mode": "crypto",
"input_value": "eip155:1",
"location": "Main View",
},
Expand All @@ -223,6 +227,7 @@ exports[`BridgeController SSE should rethrow error from server 3`] = `
{
"action_type": "swapbridge-v1",
"input": "chain_destination",
"input_currency_mode": "crypto",
"input_value": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"location": "Main View",
},
Expand All @@ -232,6 +237,7 @@ exports[`BridgeController SSE should rethrow error from server 3`] = `
{
"action_type": "swapbridge-v1",
"input": "token_destination",
"input_currency_mode": "crypto",
"input_value": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:123d1",
"location": "Main View",
},
Expand All @@ -241,6 +247,7 @@ exports[`BridgeController SSE should rethrow error from server 3`] = `
{
"action_type": "swapbridge-v1",
"input": "slippage",
"input_currency_mode": "crypto",
"input_value": 0.5,
"location": "Main View",
},
Expand All @@ -254,6 +261,7 @@ exports[`BridgeController SSE should rethrow error from server 3`] = `
"chain_id_source": "eip155:1",
"custom_slippage": true,
"has_sufficient_funds": true,
"input_currency_mode": "crypto",
"is_hardware_wallet": false,
"location": "Main View",
"security_warnings": [],
Expand Down Expand Up @@ -340,6 +348,7 @@ exports[`BridgeController SSE should trigger quote polling if request is valid 2
{
"action_type": "swapbridge-v1",
"input": "chain_source",
"input_currency_mode": "crypto",
"input_value": "eip155:1",
"location": "Main View",
},
Expand All @@ -349,6 +358,7 @@ exports[`BridgeController SSE should trigger quote polling if request is valid 2
{
"action_type": "swapbridge-v1",
"input": "chain_destination",
"input_currency_mode": "crypto",
"input_value": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"location": "Main View",
},
Expand All @@ -358,6 +368,7 @@ exports[`BridgeController SSE should trigger quote polling if request is valid 2
{
"action_type": "swapbridge-v1",
"input": "token_destination",
"input_currency_mode": "crypto",
"input_value": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:123d1",
"location": "Main View",
},
Expand All @@ -367,6 +378,7 @@ exports[`BridgeController SSE should trigger quote polling if request is valid 2
{
"action_type": "swapbridge-v1",
"input": "slippage",
"input_currency_mode": "crypto",
"input_value": 0.5,
"location": "Main View",
},
Expand All @@ -380,6 +392,7 @@ exports[`BridgeController SSE should trigger quote polling if request is valid 2
"chain_id_source": "eip155:1",
"custom_slippage": true,
"has_sufficient_funds": true,
"input_currency_mode": "crypto",
"is_hardware_wallet": false,
"location": "Main View",
"security_warnings": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ exports[`BridgeController trackUnifiedSwapBridgeEvent client-side calls should t
"gas_included_7702": false,
"has_gas_included_quote": false,
"initial_load_time_all_quotes": 0,
"input_currency_mode": "crypto",
"is_hardware_wallet": false,
"location": "Main View",
"price_impact": 0,
Expand Down Expand Up @@ -472,6 +473,7 @@ exports[`BridgeController updateBridgeQuoteRequestParams should only poll once i
{
"action_type": "swapbridge-v1",
"input": "chain_source",
"input_currency_mode": "crypto",
"input_value": "eip155:1",
"location": "Main View",
},
Expand All @@ -481,6 +483,7 @@ exports[`BridgeController updateBridgeQuoteRequestParams should only poll once i
{
"action_type": "swapbridge-v1",
"input": "chain_destination",
"input_currency_mode": "crypto",
"input_value": "eip155:10",
"location": "Main View",
},
Expand All @@ -490,6 +493,7 @@ exports[`BridgeController updateBridgeQuoteRequestParams should only poll once i
{
"action_type": "swapbridge-v1",
"input": "token_destination",
"input_currency_mode": "crypto",
"input_value": "eip155:10/erc20:0x123",
"location": "Main View",
},
Expand All @@ -499,6 +503,7 @@ exports[`BridgeController updateBridgeQuoteRequestParams should only poll once i
{
"action_type": "swapbridge-v1",
"input": "slippage",
"input_currency_mode": "crypto",
"input_value": 0.5,
"location": "Main View",
},
Expand All @@ -512,6 +517,7 @@ exports[`BridgeController updateBridgeQuoteRequestParams should only poll once i
"chain_id_source": "eip155:1",
"custom_slippage": true,
"has_sufficient_funds": false,
"input_currency_mode": "crypto",
"is_hardware_wallet": false,
"location": "Main View",
"security_warnings": [],
Expand Down Expand Up @@ -541,6 +547,7 @@ exports[`BridgeController updateBridgeQuoteRequestParams should only poll once i
"gas_included_7702": false,
"has_gas_included_quote": false,
"initial_load_time_all_quotes": 11000,
"input_currency_mode": "crypto",
"is_hardware_wallet": false,
"location": "Main View",
"price_impact": 0,
Expand Down Expand Up @@ -904,6 +911,7 @@ exports[`BridgeController updateBridgeQuoteRequestParams should trigger quote po
{
"action_type": "swapbridge-v1",
"input": "chain_source",
"input_currency_mode": "crypto",
"input_value": "eip155:1",
"location": "Main View",
},
Expand All @@ -913,6 +921,7 @@ exports[`BridgeController updateBridgeQuoteRequestParams should trigger quote po
{
"action_type": "swapbridge-v1",
"input": "chain_destination",
"input_currency_mode": "crypto",
"input_value": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"location": "Main View",
},
Expand All @@ -922,6 +931,7 @@ exports[`BridgeController updateBridgeQuoteRequestParams should trigger quote po
{
"action_type": "swapbridge-v1",
"input": "token_destination",
"input_currency_mode": "crypto",
"input_value": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:123d1",
"location": "Main View",
},
Expand All @@ -931,6 +941,7 @@ exports[`BridgeController updateBridgeQuoteRequestParams should trigger quote po
{
"action_type": "swapbridge-v1",
"input": "slippage",
"input_currency_mode": "crypto",
"input_value": 0.5,
"location": "Main View",
},
Expand All @@ -944,6 +955,7 @@ exports[`BridgeController updateBridgeQuoteRequestParams should trigger quote po
"chain_id_source": "eip155:1",
"custom_slippage": true,
"has_sufficient_funds": true,
"input_currency_mode": "crypto",
"is_hardware_wallet": false,
"location": "Main View",
"security_warnings": [],
Expand All @@ -968,6 +980,7 @@ exports[`BridgeController updateBridgeQuoteRequestParams should trigger quote po
"chain_id_source": "eip155:1",
"custom_slippage": true,
"has_sufficient_funds": true,
"input_currency_mode": "crypto",
"is_hardware_wallet": false,
"location": "Main View",
"security_warnings": [],
Expand All @@ -992,6 +1005,7 @@ exports[`BridgeController updateBridgeQuoteRequestParams should trigger quote po
"chain_id_source": "eip155:1",
"custom_slippage": true,
"has_sufficient_funds": true,
"input_currency_mode": "crypto",
"is_hardware_wallet": false,
"location": "Main View",
"security_warnings": [],
Expand Down Expand Up @@ -1041,6 +1055,7 @@ exports[`BridgeController updateBridgeQuoteRequestParams should trigger quote po
"chain_id_source": "eip155:1",
"custom_slippage": true,
"has_sufficient_funds": true,
"input_currency_mode": "crypto",
"is_hardware_wallet": false,
"location": "Main View",
"security_warnings": [],
Expand All @@ -1065,6 +1080,7 @@ exports[`BridgeController updateBridgeQuoteRequestParams should update the quote
{
"action_type": "swapbridge-v1",
"input": "chain_source",
"input_currency_mode": "crypto",
"input_value": "eip155:1",
"location": "Main View",
},
Expand All @@ -1074,6 +1090,7 @@ exports[`BridgeController updateBridgeQuoteRequestParams should update the quote
{
"action_type": "swapbridge-v1",
"input": "chain_destination",
"input_currency_mode": "crypto",
"input_value": "eip155:10",
"location": "Main View",
},
Expand All @@ -1083,6 +1100,7 @@ exports[`BridgeController updateBridgeQuoteRequestParams should update the quote
{
"action_type": "swapbridge-v1",
"input": "slippage",
"input_currency_mode": "crypto",
"input_value": 0.5,
"location": "Main View",
},
Expand Down
14 changes: 13 additions & 1 deletion packages/bridge-controller/src/bridge-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import {
AbortReason,
MetaMetricsSwapsEventSource,
MetricsActionType,
InputCurrencyMode,
UnifiedSwapBridgeEventName,
} from './utils/metrics/constants';
import {
Expand Down Expand Up @@ -356,7 +357,11 @@ export class BridgeController extends StaticIntervalPollingController<BridgePoll
if (quoteRequestIndex >= quoteRequestCount) {
return;
}
this.#trackInputChangedEvents(paramsToUpdate, quoteRequestIndex);
this.#trackInputChangedEvents(
paramsToUpdate,
context.input_currency_mode,
quoteRequestIndex,
);
this.resetState(AbortReason.QuoteRequestUpdated, quoteRequestIndex);
this.update((state) => {
// Update only the specified quote request and keep the rest of the quote requests unchanged
Expand Down Expand Up @@ -1160,6 +1165,9 @@ export class BridgeController extends StaticIntervalPollingController<BridgePoll
location: clientProps?.location ?? this.#location,
action_type: MetricsActionType.SWAPBRIDGE_V1,
};
const inputCurrencyMode =
(clientProps?.input_currency_mode as InputCurrencyMode | undefined) ??
InputCurrencyMode.CRYPTO;
const quoteRequest = this.state.quoteRequest[quoteRequestIndex];
switch (eventName) {
case UnifiedSwapBridgeEventName.ButtonClicked:
Expand Down Expand Up @@ -1198,6 +1206,7 @@ export class BridgeController extends StaticIntervalPollingController<BridgePoll
...this.#getQuoteFetchData(),
refresh_count: this.state.quotesRefreshCount,
...baseProperties,
input_currency_mode: inputCurrencyMode,
};
case UnifiedSwapBridgeEventName.QuotesRequested:
return {
Expand All @@ -1208,6 +1217,7 @@ export class BridgeController extends StaticIntervalPollingController<BridgePoll
...this.#getRequestMetadata(),
has_sufficient_funds: !quoteRequest.insufficientBal,
...baseProperties,
input_currency_mode: inputCurrencyMode,
};
case UnifiedSwapBridgeEventName.QuotesError:
return {
Expand Down Expand Up @@ -1270,6 +1280,7 @@ export class BridgeController extends StaticIntervalPollingController<BridgePoll

readonly #trackInputChangedEvents = (
paramsToUpdate: Partial<GenericQuoteRequest>,
inputCurrencyMode: InputCurrencyMode = InputCurrencyMode.CRYPTO,
quoteRequestIndex: number = 0,
) => {
Object.entries(paramsToUpdate).forEach(([key, value]) => {
Expand All @@ -1292,6 +1303,7 @@ export class BridgeController extends StaticIntervalPollingController<BridgePoll
{
input: inputKey,
input_value: inputValue,
input_currency_mode: inputCurrencyMode,
location: this.#location,
},
);
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 @@ -4,6 +4,7 @@ export {
UnifiedSwapBridgeEventName,
UNIFIED_SWAP_BRIDGE_EVENT_CATEGORY,
InputAmountPreset,
InputCurrencyMode,
MetaMetricsSwapsEventSource,
PollingStatus,
} from './utils/metrics/constants';
Expand Down
5 changes: 5 additions & 0 deletions packages/bridge-controller/src/utils/metrics/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ export enum MetaMetricsSwapsEventSource {
Rewards = 'Rewards',
}

export enum InputCurrencyMode {
FIAT = 'fiat',
CRYPTO = 'crypto',
}

export enum InputAmountPreset {
PERCENT_25 = '25%',
PERCENT_50 = '50%',
Expand Down
Loading
Loading