11import useThrottle from 'hooks/useThrottle'
22import { Dex } from 'state/customizeDexes'
33
4+ const findDexById = ( exchangeId : string , allDexes ?: Dex [ ] ) : Dex | undefined => {
5+ if ( ! allDexes ) return undefined
6+ return allDexes . find (
7+ dex =>
8+ dex . id === exchangeId ||
9+ ( ( exchangeId === 'kyberswap' || exchangeId === 'kyberswap-static' ) && dex . id === 'kyberswapv1' ) , // Mapping for kyberswap classic dex
10+ )
11+ }
12+
413export const getDexInfoByPool = ( exchange : string , allDexes ?: Dex [ ] ) => {
514 if ( exchange === '1inch' ) {
615 return { name : '1inch' , logoURL : 'https://s2.coinmarketcap.com/static/img/coins/64x64/8104.png' }
@@ -14,11 +23,31 @@ export const getDexInfoByPool = (exchange: string, allDexes?: Dex[]) => {
1423 return { name : '0x' , logoURL : 'https://s2.coinmarketcap.com/static/img/coins/64x64/1896.png' }
1524 }
1625
17- return allDexes ?. find (
18- dex =>
19- dex . id === exchange ||
20- ( ( exchange === 'kyberswap' || exchange === 'kyberswap-static' ) && dex . id === 'kyberswapv1' ) , // Mapping for kyberswap classic dex
21- )
26+ // Try to find in allDexes first
27+ const foundDex = findDexById ( exchange , allDexes )
28+ if ( foundDex ) {
29+ return foundDex
30+ }
31+
32+ // If not found, check if exchange contains '/' (format 'exchange/exchange')
33+ if ( exchange . includes ( '/' ) ) {
34+ const parts = exchange . split ( '/' )
35+ if ( parts . length === 2 ) {
36+ const [ firstPart , secondPart ] = parts
37+ const firstDex = findDexById ( firstPart , allDexes )
38+ const secondDex = findDexById ( secondPart , allDexes )
39+
40+ // If both parts are found as dexes, return 'name/name' format
41+ if ( firstDex && secondDex ) {
42+ return { name : `${ firstDex . name } /${ secondDex . name } ` , logoURL : '' }
43+ }
44+ }
45+
46+ // If one or neither is found, return original exchange with empty logoURL
47+ return { name : exchange , logoURL : '' }
48+ }
49+
50+ return undefined
2251}
2352
2453export const getSwapPercent = ( percent ?: number , routeNumber = 0 ) : string | null => {
0 commit comments