@@ -19,11 +19,19 @@ const fetchQuotes = jest.fn();
1919const setSwapQuotes = jest . fn ( ) ;
2020const getNetworkConfigurationByNetworkClientId = jest . fn ( ) ;
2121
22- const createMiddleware = ( ) => {
22+ const createMiddleware = (
23+ args : {
24+ // eslint-disable-next-line @typescript-eslint/naming-convention
25+ dappSwapMetricsFlag ?: { enabled : boolean ; bridge_quote_fees : number } ;
26+ } = { } ,
27+ ) => {
2328 const middlewareFunction = createDappSwapMiddleware ( {
2429 fetchQuotes,
2530 setSwapQuotes,
2631 getNetworkConfigurationByNetworkClientId,
32+ // eslint-disable-next-line @typescript-eslint/naming-convention
33+ dappSwapMetricsFlag : { enabled : true , bridge_quote_fees : 250 } ,
34+ ...args ,
2735 } ) ;
2836 return { middlewareFunction } ;
2937} ;
@@ -50,6 +58,42 @@ describe('DappSwapMiddleware', () => {
5058 await flushPromises ( ) ;
5159 } ) ;
5260
61+ it ( 'does not fetch quotes if dapp swap is not enabled' , async ( ) => {
62+ fetchQuotes . mockReturnValueOnce ( mockBridgeQuotes ) ;
63+ const { middlewareFunction } = createMiddleware ( {
64+ // eslint-disable-next-line @typescript-eslint/naming-convention
65+ dappSwapMetricsFlag : { enabled : false , bridge_quote_fees : 250 } ,
66+ } ) ;
67+
68+ const req = {
69+ ...REQUEST_MOCK ,
70+ method : 'eth_sendTransaction' ,
71+ origin : 'https://metamask.github.io' ,
72+ securityAlertResponse : {
73+ securityAlertId : '123' ,
74+ } ,
75+ params : [
76+ {
77+ data : '0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000068f0dd1b0000000000000000000000000000000000000000000000000000000000000003100604000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000044000000000000000000000000000000000000000000000000000000000000004c000000000000000000000000000000000000000000000000000000000000003c0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000003070b0e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000005af3107a4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000001f4000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e58310000000000000000000000007ffc3dbf3b2b50ff3a1d5523bc24bb5043837b1400000000000000000000000000000000000000000000000000000000000000190000000000000000000000000000000000000000000000000000000000000060000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831000000000000000000000000178239802520a9c99dcbd791f81326b70298d62900000000000000000000000000000000000000000000000000000000000601470c' ,
78+ from : '0x12312312312312' ,
79+ chainId : '1' ,
80+ calls : [ ] ,
81+ } ,
82+ ] ,
83+ networkClientId : 'networkClientId' ,
84+ } ;
85+
86+ await middlewareFunction (
87+ req as unknown as DappSwapMiddlewareRequest < ( string | { to : string } ) [ ] > ,
88+ { ...JsonRpcResponseStruct . TYPE } ,
89+ ( ) => undefined ,
90+ ) ;
91+
92+ await flushPromises ( ) ;
93+
94+ expect ( fetchQuotes ) . not . toHaveBeenCalled ( ) ;
95+ } ) ;
96+
5397 it ( 'for correct origin, fetches quotes and sets swap quotes' , async ( ) => {
5498 fetchQuotes . mockReturnValueOnce ( mockBridgeQuotes ) ;
5599 getNetworkConfigurationByNetworkClientId . mockReturnValueOnce ( {
@@ -67,7 +111,7 @@ describe('DappSwapMiddleware', () => {
67111 } ,
68112 params : [
69113 {
70- data : '0x123123123' ,
114+ data : '0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000068f0dd1b0000000000000000000000000000000000000000000000000000000000000003100604000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000044000000000000000000000000000000000000000000000000000000000000004c000000000000000000000000000000000000000000000000000000000000003c0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000003070b0e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000005af3107a4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000001f4000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e58310000000000000000000000007ffc3dbf3b2b50ff3a1d5523bc24bb5043837b1400000000000000000000000000000000000000000000000000000000000000190000000000000000000000000000000000000000000000000000000000000060000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831000000000000000000000000178239802520a9c99dcbd791f81326b70298d62900000000000000000000000000000000000000000000000000000000000601470c' ,
71115 from : '0x12312312312312' ,
72116 calls : [ ] ,
73117 } ,
@@ -84,8 +128,15 @@ describe('DappSwapMiddleware', () => {
84128 await flushPromises ( ) ;
85129
86130 expect ( fetchQuotes ) . toHaveBeenCalledWith ( {
87- walletAddress : '0x12312312312312' ,
131+ destChainId : '0x1' ,
132+ destTokenAddress : '0xaf88d065e77c8cc2239327c5edb3a432268e5831' ,
88133 fee : 250 ,
134+ gasIncluded : false ,
135+ gasIncluded7702 : false ,
136+ srcChainId : '0x1' ,
137+ srcTokenAddress : '0x0000000000000000000000000000000000000000' ,
138+ srcTokenAmount : '0x5af3107a4000' ,
139+ walletAddress : '0x12312312312312' ,
89140 } ) ;
90141 } ) ;
91142} ) ;
0 commit comments