Skip to content

Commit 9f30357

Browse files
authored
fix: show fallback route for previous route version and detect dex name for fallbackroute (#2961)
1 parent dbfb55b commit 9f30357

File tree

3 files changed

+39
-12
lines changed

3 files changed

+39
-12
lines changed

apps/kyberswap-interface/src/components/TradeRouting/TradeRouteV3.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,9 @@ const RouteNode = ({
586586
target="_blank"
587587
sx={{ gap: '4px', fontSize: '10px', color: theme.subText }}
588588
>
589-
<img src={dex?.logoURL} alt="" width="12px" height="12px" style={{ borderRadius: '50%' }} />
589+
{dex?.logoURL ? (
590+
<img src={dex.logoURL} alt="" width="12px" height="12px" style={{ borderRadius: '50%' }} />
591+
) : null}
590592
<Text flex={1} sx={{}}>
591593
{dex?.name || swap.exchange}
592594
</Text>

apps/kyberswap-interface/src/components/TradeRouting/helpers.ts

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import useThrottle from 'hooks/useThrottle'
22
import { 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+
413
export 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

2453
export const getSwapPercent = (percent?: number, routeNumber = 0): string | null => {

apps/kyberswap-interface/src/components/TradeRouting/index.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,8 @@ const RouteRow = ({ route, chainId, backgroundColor }: RouteRowProps) => {
103103
)
104104
})(
105105
<>
106-
{dex?.logoURL ? (
107-
<img src={dex?.logoURL} alt="" className="img--sm" />
108-
) : (
109-
<i className="img--sm" />
110-
)}
111-
{`${dex?.name || '--'}: ${pool.swapPercentage}%`}
106+
{dex?.logoURL ? <img src={dex.logoURL} alt="" className="img--sm" /> : null}
107+
{`${dex?.name || pool.exchange}: ${pool.swapPercentage}%`}
112108
</>,
113109
)
114110
return link

0 commit comments

Comments
 (0)