@@ -17,6 +17,7 @@ import {
1717 FeatureId ,
1818 getQuotesReceivedProperties ,
1919 UnifiedSwapBridgeEventName ,
20+ MetaMetricsSwapsEventSource ,
2021} from '@metamask/bridge-controller' ;
2122import { Messenger , MOCK_ANY_NAMESPACE } from '@metamask/messenger' ;
2223import type {
@@ -56,6 +57,7 @@ import type {
5657} from './types' ;
5758import * as bridgeStatusUtils from './utils/bridge-status' ;
5859import * as historyUtils from './utils/history' ;
60+ import * as metricsUtils from './utils/metrics' ;
5961import * as transactionUtils from './utils/transaction' ;
6062
6163type AllBridgeStatusControllerActions =
@@ -332,6 +334,7 @@ const getMockStartPollingForBridgeTxStatusArgs = ({
332334 initialDestAssetBalance : undefined ,
333335 targetContractAddress : '0x23981fC34e69eeDFE2BD9a0a9fCb0719Fe09DbFC' ,
334336 isStxEnabled,
337+ location : MetaMetricsSwapsEventSource . MainView ,
335338} ) ;
336339
337340const MockTxHistory = {
@@ -432,7 +435,7 @@ const MockTxHistory = {
432435 completionTime : undefined ,
433436 attempts,
434437 featureId,
435- location : undefined ,
438+ location : MetaMetricsSwapsEventSource . MainView ,
436439 } ,
437440 } ) ,
438441 getUnknown : ( {
@@ -547,7 +550,7 @@ const MockTxHistory = {
547550 isStxEnabled : true ,
548551 hasApprovalTx : false ,
549552 attempts : undefined ,
550- location : undefined ,
553+ location : MetaMetricsSwapsEventSource . MainView ,
551554 } ,
552555 } ) ,
553556} ;
@@ -5054,6 +5057,81 @@ describe('BridgeStatusController', () => {
50545057 expect ( messengerCallSpy . mock . lastCall ) . toMatchSnapshot ( ) ;
50555058 } ) ;
50565059
5060+ it ( 'should use txMeta properties if history item does not exist' , ( ) => {
5061+ const messengerCallSpy = jest . spyOn ( mockBridgeStatusMessenger , 'call' ) ;
5062+
5063+ const transactionMeta = {
5064+ error : { name : 'Error' , message : 'tx-error' } ,
5065+ chainId : CHAIN_IDS . ARBITRUM ,
5066+ networkClientId : 'eth-id' ,
5067+ time : Date . now ( ) ,
5068+ txParams : { } as unknown as TransactionParams ,
5069+ type : TransactionType . bridge ,
5070+ status : TransactionStatus . failed ,
5071+ id : 'bridgeTxMetaId1' ,
5072+ } ;
5073+ const getEVMTxPropertiesFromTransactionMetaSpy = jest
5074+ . spyOn ( metricsUtils , 'getEVMTxPropertiesFromTransactionMeta' )
5075+ . mockImplementationOnce ( ( ) => {
5076+ bridgeStatusController . wipeBridgeStatus ( {
5077+ address : 'otherAccount' ,
5078+ ignoreNetwork : true ,
5079+ } ) ;
5080+ return metricsUtils . getEVMTxPropertiesFromTransactionMeta (
5081+ transactionMeta ,
5082+ ) ;
5083+ } ) ;
5084+ mockMessenger . publish (
5085+ 'TransactionController:transactionStatusUpdated' ,
5086+ {
5087+ transactionMeta,
5088+ } ,
5089+ ) ;
5090+
5091+ expect ( getEVMTxPropertiesFromTransactionMetaSpy ) . toHaveBeenCalledTimes (
5092+ 2 ,
5093+ ) ;
5094+ expect ( bridgeStatusController . state . txHistory ) . toStrictEqual ( { } ) ;
5095+ expect ( messengerCallSpy . mock . lastCall ) . toMatchInlineSnapshot ( `
5096+ [
5097+ "BridgeController:trackUnifiedSwapBridgeEvent",
5098+ "Unified SwapBridge Failed",
5099+ {
5100+ "account_hardware_type": null,
5101+ "action_type": "swapbridge-v1",
5102+ "actual_time_minutes": 0,
5103+ "chain_id_destination": "eip155:42161",
5104+ "chain_id_source": "eip155:42161",
5105+ "custom_slippage": false,
5106+ "error_message": "Transaction failed. tx-error",
5107+ "gas_included": false,
5108+ "gas_included_7702": false,
5109+ "is_hardware_wallet": false,
5110+ "location": "Main View",
5111+ "price_impact": 0,
5112+ "provider": "",
5113+ "quote_vs_execution_ratio": 0,
5114+ "quoted_time_minutes": 0,
5115+ "quoted_vs_used_gas_ratio": 0,
5116+ "security_warnings": [],
5117+ "source_transaction": "FAILED",
5118+ "stx_enabled": false,
5119+ "swap_type": "crosschain",
5120+ "token_address_destination": "eip155:42161/slip44:60",
5121+ "token_address_source": "eip155:42161/slip44:60",
5122+ "token_security_type_destination": null,
5123+ "token_symbol_destination": "",
5124+ "token_symbol_source": "",
5125+ "usd_actual_gas": 0,
5126+ "usd_actual_return": 0,
5127+ "usd_amount_source": 0,
5128+ "usd_quoted_gas": 0,
5129+ "usd_quoted_return": 0,
5130+ },
5131+ ]
5132+ ` ) ;
5133+ } ) ;
5134+
50575135 it ( 'should include ab_tests and active_ab_tests from history in tracked event properties' , ( ) => {
50585136 const abTestsTxMetaId = 'bridgeTxMetaIdAbTests' ;
50595137 mockMessenger . call (
0 commit comments