@@ -27,7 +27,6 @@ describe('useNetworkSwitchSelectedTokenAddress', () => {
2727
2828 beforeEach ( ( ) => {
2929 vi . clearAllMocks ( ) ;
30-
3130 mockedUseIsSwapTransfer . mockReturnValue ( false ) ;
3231 mockedUseSelectedToken . mockReturnValue ( [
3332 {
@@ -50,10 +49,10 @@ describe('useNetworkSwitchSelectedTokenAddress', () => {
5049 } ) ;
5150 } ) ;
5251
53- it ( 'returns undefined (keeps the current token) when the resolved destination token is the same logical token ' , ( ) => {
54- // Ethereum (PYUSD) to ArbitrumOne (PYUSD OFT)
55- // Different addresses but same "logical" token
56- // Returns undefined to keep the current token
52+ it ( 'returns the resolved destination token address when the source token changes across a network switch ' , ( ) => {
53+ // Ethereum -> Arbitrum One:
54+ // the selected source token is L1 PYUSD, but after switching networks
55+ // the new source token must become the resolved Arbitrum-side token.
5756 mockedUseSelectedToken . mockReturnValue ( [
5857 {
5958 type : TokenType . ERC20 ,
@@ -76,14 +75,70 @@ describe('useNetworkSwitchSelectedTokenAddress', () => {
7675 listIds : new Set ( [ '1' ] ) ,
7776 } ) ;
7877
78+ const { result } = renderHook ( useNetworkSwitchSelectedTokenAddress ) ;
79+ expect ( result . current ) . toBe ( CommonAddress . ArbitrumOne . PYUSDOFT ) ;
80+ } ) ;
81+
82+ it ( 'returns the L1 PYUSD address when switching away from Arbitrum One PYUSD OFT' , ( ) => {
83+ // Arbitrum One -> Ethereum:
84+ // the current source token is Arbitrum PYUSD OFT, and after switching
85+ // networks the new source token must become Ethereum PYUSD.
86+ mockedUseSelectedToken . mockReturnValue ( [
87+ {
88+ type : TokenType . ERC20 ,
89+ address : CommonAddress . ArbitrumOne . PYUSDOFT ,
90+ importLookupAddress : CommonAddress . Ethereum . PYUSD ,
91+ name : 'PYUSD OFT' ,
92+ symbol : 'PYUSD' ,
93+ decimals : 6 ,
94+ listIds : new Set ( [ '1' ] ) ,
95+ } ,
96+ vi . fn ( ) ,
97+ ] ) ;
98+ mockedUseDestinationToken . mockReturnValue ( {
99+ type : TokenType . ERC20 ,
100+ address : CommonAddress . Ethereum . PYUSD ,
101+ importLookupAddress : CommonAddress . Ethereum . PYUSD ,
102+ name : 'PYUSD' ,
103+ symbol : 'PYUSD' ,
104+ decimals : 6 ,
105+ listIds : new Set ( [ '1' ] ) ,
106+ } ) ;
107+
108+ const { result } = renderHook ( useNetworkSwitchSelectedTokenAddress ) ;
109+ expect ( result . current ) . toBe ( CommonAddress . Ethereum . PYUSD ) ;
110+ } ) ;
111+
112+ it ( 'returns undefined when the resolved destination token keeps the same address' , ( ) => {
113+ // If switching networks would keep the exact same token address,
114+ // the hook should leave query state untouched.
115+ mockedUseSelectedToken . mockReturnValue ( [
116+ {
117+ type : TokenType . ERC20 ,
118+ address : CommonAddress . Ethereum . WETH ,
119+ name : 'Wrapped Ether' ,
120+ symbol : 'WETH' ,
121+ decimals : 18 ,
122+ listIds : new Set ( [ '1' ] ) ,
123+ } ,
124+ vi . fn ( ) ,
125+ ] ) ;
126+ mockedUseDestinationToken . mockReturnValue ( {
127+ type : TokenType . ERC20 ,
128+ address : CommonAddress . Ethereum . WETH ,
129+ name : 'Wrapped Ether' ,
130+ symbol : 'WETH' ,
131+ decimals : 18 ,
132+ listIds : new Set ( [ '1' ] ) ,
133+ } ) ;
134+
79135 const { result } = renderHook ( useNetworkSwitchSelectedTokenAddress ) ;
80136 expect ( result . current ) . toBeUndefined ( ) ;
81137 } ) ;
82138
83139 it ( 'returns the resolved destination token address for swaps' , ( ) => {
84- // LiFi swap from Ethereum (PYUSD) to ArbitrumOne (PYUSD OFT)
85- // Different addresses but same "logical" token
86- // Returns the destination token (PYUSD OFT)
140+ // In swap mode, the selected token should always follow the resolved
141+ // destination token instead of trying to preserve the current source token.
87142 mockedUseIsSwapTransfer . mockReturnValue ( true ) ;
88143 mockedUseDestinationToken . mockReturnValue ( {
89144 type : TokenType . ERC20 ,
@@ -100,8 +155,8 @@ describe('useNetworkSwitchSelectedTokenAddress', () => {
100155 } ) ;
101156
102157 it ( 'returns null for native swaps without a destination token' , ( ) => {
103- // LiFi swaps to native currency
104- // Returns null to clear the selected token
158+ // For swaps that resolve to the native asset, there is no ERC20 token
159+ // address to keep selected, so the hook clears the token query param.
105160 mockedUseIsSwapTransfer . mockReturnValue ( true ) ;
106161 mockedUseDestinationToken . mockReturnValue ( null ) ;
107162
0 commit comments