|
7 | 7 | import { OnchainItemSectionName } from 'uniswap/src/components/lists/OnchainItemList/types' |
8 | 8 | import { useTokenSectionsForSwap } from 'uniswap/src/components/TokenSelector/lists/TokenSelectorSwapList' |
9 | 9 | import { TokenSelectorVariation } from 'uniswap/src/components/TokenSelector/types' |
| 10 | +import { AssetType, TradeableAsset } from 'uniswap/src/entities/assets' |
10 | 11 | import { UniverseChainId } from 'uniswap/src/features/chains/types' |
11 | 12 | import { renderHook } from 'uniswap/src/test/test-utils' |
12 | 13 |
|
@@ -61,11 +62,15 @@ const tokenOption = { |
61 | 62 | currencyInfo: { currencyId: 'token-currency-id' }, |
62 | 63 | } as TokenOption |
63 | 64 |
|
64 | | -function renderSwapSections(variation: TokenSelectorVariation): ReturnType<typeof useTokenSectionsForSwap> { |
| 65 | +function renderSwapSections( |
| 66 | + variation: TokenSelectorVariation, |
| 67 | + options?: { chainFilter?: UniverseChainId | null; oppositeSelectedToken?: TradeableAsset }, |
| 68 | +): ReturnType<typeof useTokenSectionsForSwap> { |
65 | 69 | const { result } = renderHook(() => |
66 | 70 | useTokenSectionsForSwap({ |
67 | 71 | addresses: { evmAddress: undefined, svmAddress: undefined }, |
68 | | - chainFilter: null, |
| 72 | + chainFilter: options?.chainFilter ?? null, |
| 73 | + oppositeSelectedToken: options?.oppositeSelectedToken, |
69 | 74 | variation, |
70 | 75 | }), |
71 | 76 | ) |
@@ -118,6 +123,36 @@ describe('useTokenSectionsForSwap Stocks section', () => { |
118 | 123 | expect(hasStocksSection(data)).toBe(false) |
119 | 124 | }) |
120 | 125 |
|
| 126 | + it('filters stocks by the input token chain when the chain filter is All Chains', () => { |
| 127 | + const inputToken: TradeableAsset = { |
| 128 | + address: '0x0000000000000000000000000000000000000001', |
| 129 | + chainId: UniverseChainId.Unichain, |
| 130 | + type: AssetType.Currency, |
| 131 | + } |
| 132 | + renderSwapSections(TokenSelectorVariation.SwapOutput, { oppositeSelectedToken: inputToken }) |
| 133 | + expect(mockUseRwaTokenOptions).toHaveBeenCalledWith( |
| 134 | + expect.objectContaining({ chainFilter: UniverseChainId.Unichain }), |
| 135 | + ) |
| 136 | + }) |
| 137 | + |
| 138 | + it('filters stocks by the selected chain even when an input token is on another chain', () => { |
| 139 | + const inputToken: TradeableAsset = { |
| 140 | + address: '0x0000000000000000000000000000000000000001', |
| 141 | + chainId: UniverseChainId.Unichain, |
| 142 | + type: AssetType.Currency, |
| 143 | + } |
| 144 | + renderSwapSections(TokenSelectorVariation.SwapOutput, { |
| 145 | + chainFilter: UniverseChainId.Base, |
| 146 | + oppositeSelectedToken: inputToken, |
| 147 | + }) |
| 148 | + expect(mockUseRwaTokenOptions).toHaveBeenCalledWith(expect.objectContaining({ chainFilter: UniverseChainId.Base })) |
| 149 | + }) |
| 150 | + |
| 151 | + it('does not filter stocks when there is no chain filter and no input token', () => { |
| 152 | + renderSwapSections(TokenSelectorVariation.SwapOutput) |
| 153 | + expect(mockUseRwaTokenOptions).toHaveBeenCalledWith(expect.objectContaining({ chainFilter: null })) |
| 154 | + }) |
| 155 | + |
121 | 156 | it('orders Stocks between Suggested and Bridging when both neighbors are present', () => { |
122 | 157 | mockUseCommonTokensOptionsWithFallback.mockReturnValue({ |
123 | 158 | data: [tokenOption], |
|
0 commit comments