@@ -12,7 +12,11 @@ import type {
1212 TransactionPayControllerMessenger ,
1313 TransactionPaySourceAmount ,
1414} from './types' ;
15- import { getStrategyOrder } from './utils/feature-flags' ;
15+ import type { TransactionPayRouteContext } from './utils/feature-flags' ;
16+ import {
17+ getStrategyOrder ,
18+ getStrategyOrderForRoute ,
19+ } from './utils/feature-flags' ;
1620import { updateQuotes } from './utils/quotes' ;
1721import { updateSourceAmounts } from './utils/source-amounts' ;
1822import { pollTransactionChanges } from './utils/transaction' ;
@@ -36,6 +40,7 @@ describe('TransactionPayController', () => {
3640 const updateQuotesMock = jest . mocked ( updateQuotes ) ;
3741 const pollTransactionChangesMock = jest . mocked ( pollTransactionChanges ) ;
3842 const getStrategyOrderMock = jest . mocked ( getStrategyOrder ) ;
43+ const getStrategyOrderForRouteMock = jest . mocked ( getStrategyOrderForRoute ) ;
3944 let messenger : TransactionPayControllerMessenger ;
4045
4146 /**
@@ -55,6 +60,9 @@ describe('TransactionPayController', () => {
5560
5661 messenger = getMessengerMock ( { skipRegister : true } ) . messenger ;
5762 getStrategyOrderMock . mockReturnValue ( [ TransactionPayStrategy . Relay ] ) ;
63+ getStrategyOrderForRouteMock . mockReturnValue ( [
64+ TransactionPayStrategy . Relay ,
65+ ] ) ;
5866 updateQuotesMock . mockResolvedValue ( true ) ;
5967 } ) ;
6068
@@ -324,6 +332,115 @@ describe('TransactionPayController', () => {
324332 ) . toBe ( TransactionPayStrategy . Bridge ) ;
325333 } ) ;
326334
335+ it ( 'uses route-based feature flag resolution when getStrategyRouteContext is provided' , async ( ) => {
336+ const getStrategyRouteContext = jest . fn ( ( ) => ( {
337+ chainId : '0xa4b1' as Hex ,
338+ tokenAddress : '0xabc' as Hex ,
339+ transactionType : 'perpsDeposit' ,
340+ } ) ) ;
341+
342+ getStrategyOrderForRouteMock . mockReturnValue ( [
343+ TransactionPayStrategy . Across ,
344+ ] ) ;
345+
346+ new TransactionPayController ( {
347+ getDelegationTransaction : jest . fn ( ) ,
348+ getStrategyRouteContext,
349+ messenger,
350+ } ) ;
351+
352+ expect (
353+ messenger . call (
354+ 'TransactionPayController:getStrategy' ,
355+ TRANSACTION_META_MOCK ,
356+ ) ,
357+ ) . toBe ( TransactionPayStrategy . Across ) ;
358+ expect ( getStrategyRouteContext ) . toHaveBeenCalledWith (
359+ TRANSACTION_META_MOCK ,
360+ ) ;
361+ expect ( getStrategyOrderForRouteMock ) . toHaveBeenCalledWith ( messenger , {
362+ chainId : '0xa4b1' ,
363+ tokenAddress : '0xabc' ,
364+ transactionType : 'perpsDeposit' ,
365+ } ) ;
366+ } ) ;
367+
368+ it ( 'falls back to default strategy order when route-based resolution returns no strategies' , async ( ) => {
369+ getStrategyOrderForRouteMock . mockReturnValue ( [ ] ) ;
370+ getStrategyOrderMock . mockReturnValue ( [ TransactionPayStrategy . Relay ] ) ;
371+
372+ new TransactionPayController ( {
373+ getDelegationTransaction : jest . fn ( ) ,
374+ getStrategyRouteContext : ( ) : TransactionPayRouteContext => ( {
375+ chainId : '0xa4b1' as Hex ,
376+ tokenAddress : '0xabc' as Hex ,
377+ transactionType : 'perpsDeposit' ,
378+ } ) ,
379+ messenger,
380+ } ) ;
381+
382+ expect (
383+ messenger . call (
384+ 'TransactionPayController:getStrategy' ,
385+ TRANSACTION_META_MOCK ,
386+ ) ,
387+ ) . toBe ( TransactionPayStrategy . Relay ) ;
388+ expect ( getStrategyOrderForRouteMock ) . toHaveBeenCalledWith ( messenger , {
389+ chainId : '0xa4b1' ,
390+ tokenAddress : '0xabc' ,
391+ transactionType : 'perpsDeposit' ,
392+ } ) ;
393+ expect ( getStrategyOrderMock ) . toHaveBeenCalledWith ( messenger ) ;
394+ } ) ;
395+
396+ it ( 'falls back to default strategy order for quote refresh when route-based resolution returns no strategies' , async ( ) => {
397+ getStrategyOrderForRouteMock . mockReturnValue ( [ ] ) ;
398+ getStrategyOrderMock . mockReturnValue ( [ TransactionPayStrategy . Relay ] ) ;
399+
400+ const controller = new TransactionPayController ( {
401+ getDelegationTransaction : jest . fn ( ) ,
402+ getStrategyRouteContext : ( ) : TransactionPayRouteContext => ( {
403+ chainId : '0xa4b1' as Hex ,
404+ tokenAddress : '0xabc' as Hex ,
405+ transactionType : 'perpsDeposit' ,
406+ } ) ,
407+ messenger,
408+ } ) ;
409+
410+ controller . setTransactionConfig ( TRANSACTION_ID_MOCK , ( config ) => {
411+ config . isPostQuote = true ;
412+ } ) ;
413+
414+ const { getStrategies } = updateQuotesMock . mock . calls [ 0 ] [ 0 ] ;
415+
416+ expect ( getStrategies ( TRANSACTION_META_MOCK ) ) . toStrictEqual ( [
417+ TransactionPayStrategy . Relay ,
418+ ] ) ;
419+ } ) ;
420+
421+ it ( 'prefers explicit getStrategies values over route-based feature flag resolution' , async ( ) => {
422+ new TransactionPayController ( {
423+ getDelegationTransaction : jest . fn ( ) ,
424+ getStrategies : ( ) : TransactionPayStrategy [ ] => [
425+ TransactionPayStrategy . Test ,
426+ ] ,
427+ getStrategyRouteContext : ( ) : TransactionPayRouteContext => ( {
428+ chainId : '0xa4b1' as Hex ,
429+ tokenAddress : '0xabc' as Hex ,
430+ transactionType : 'perpsDeposit' ,
431+ } ) ,
432+ messenger,
433+ } ) ;
434+
435+ expect (
436+ messenger . call (
437+ 'TransactionPayController:getStrategy' ,
438+ TRANSACTION_META_MOCK ,
439+ ) ,
440+ ) . toBe ( TransactionPayStrategy . Test ) ;
441+ expect ( getStrategyOrderForRouteMock ) . not . toHaveBeenCalled ( ) ;
442+ } ) ;
443+
327444 it ( 'returns default strategy order when no callbacks and no strategy order feature flag' , async ( ) => {
328445 getStrategyOrderMock . mockReturnValue ( [ TransactionPayStrategy . Relay ] ) ;
329446
0 commit comments