Skip to content

Commit

Permalink
add kyber pmm
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhoaidanh committed Sep 20, 2023
1 parent 2bc876b commit 55ef134
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 40 deletions.
10 changes: 6 additions & 4 deletions src/components/swapv2/LiquiditySourcesPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ const LiquiditySourceHeader = styled.div`
align-items: center;
`

export const isKyberSwapDex = (id: string) => id.includes('kyber')

const LiquiditySourcesPanel: React.FC<Props> = ({ onBack }) => {
const [searchText, setSearchText] = useState('')
const debouncedSearchText = useDebounce(searchText.toLowerCase(), 200).trim()
Expand Down Expand Up @@ -135,7 +137,7 @@ const LiquiditySourcesPanel: React.FC<Props> = ({ onBack }) => {
}, [excludeDexes, dexes])

const ksDexes = useMemo(
() => dexes.filter(item => item.id.includes('kyberswap')).sort((a, b) => a.sortId - b.sortId),
() => dexes.filter(item => isKyberSwapDex(item.id)).sort((a, b) => a.sortId - b.sortId),
[dexes],
)

Expand Down Expand Up @@ -210,10 +212,10 @@ const LiquiditySourcesPanel: React.FC<Props> = ({ onBack }) => {
checked={!ksDexes.map(i => i.id).every(item => excludeDexes.includes(item))}
onChange={e => {
if (e.target.checked) {
setExcludeDexes(excludeDexes.filter(item => !item.includes('kyberswap')))
setExcludeDexes(excludeDexes.filter(item => !isKyberSwapDex(item)))
} else {
const newData = [
...excludeDexes.filter(item => !item.includes('kyberswap')),
...excludeDexes.filter(item => !isKyberSwapDex(item)),
...ksDexes.map(item => item.id),
]
setExcludeDexes(newData)
Expand Down Expand Up @@ -244,7 +246,7 @@ const LiquiditySourcesPanel: React.FC<Props> = ({ onBack }) => {
</>
)}
{dexes
?.filter(item => !item.id.includes('kyberswap') && item.name.toLowerCase().includes(debouncedSearchText))
?.filter(item => !isKyberSwapDex(item.id) && item.name.toLowerCase().includes(debouncedSearchText))
.map(({ name, logoURL, id }) => (
<Source key={name}>
<Checkbox checked={!excludeDexes.includes(id)} onChange={() => handleToggleDex(id)} />
Expand Down
30 changes: 1 addition & 29 deletions src/constants/dexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,5 @@ export const KYBERSWAP_KS_DEXES_TO_UI_DEXES: { [key: string]: string | undefined
'kyberswap-static': 'kyberswapv1', // kyberswap classic new contract -> with static fee
'kyberswap-limit-order': 'kyberswap-limit-order',
'kyberswap-limit-order-v2': 'kyberswap-limit-order-v2',
}

export const KYBERSWAP_UI_DEXES: {
[key: string]: {
name: string
id: string
logoURL: string
}
} = {
'kyberswap-elastic': {
name: 'KyberSwap Elastic',
id: 'kyberswap-elastic',
logoURL: 'https://kyberswap.com/favicon.ico',
},
kyberswapv1: {
name: 'KyberSwap Classic',
id: 'kyberswapv1',
logoURL: 'https://kyberswap.com/favicon.ico',
},
'kyberswap-limit-order': {
name: 'KyberSwap Limit Order',
id: 'kyberswap-limit-order',
logoURL: 'https://kyberswap.com/favicon.ico',
},
'kyberswap-limit-order-v2': {
name: 'KyberSwap Limit Order V2',
id: 'kyberswap-limit-order-v2',
logoURL: 'https://kyberswap.com/favicon.ico',
},
'kyber-pmm': 'kyber-pmm',
}
20 changes: 13 additions & 7 deletions src/state/customizeDexes/updater.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useEffect, useMemo } from 'react'
import { useDispatch } from 'react-redux'

import { KYBERSWAP_KS_DEXES_TO_UI_DEXES, KYBERSWAP_UI_DEXES } from 'constants/dexes'
import { isKyberSwapDex } from 'components/swapv2/LiquiditySourcesPanel'
import { KYBERSWAP_KS_DEXES_TO_UI_DEXES } from 'constants/dexes'
import { useActiveWeb3React } from 'hooks'
import useLiquiditySources from 'hooks/useAggregatorStats'
import { AppDispatch } from 'state/index'
Expand All @@ -18,16 +19,21 @@ export default function Updater(): null {
// filterout kyberswap dexes, will hardcode
const normalizeDexes = useMemo(() => {
const dexesFormatted: Dex[] = dexes?.map(item => ({ ...item, id: item.dexId, sortId: item.id })) || []
const dexesOutsideKyberswap = dexesFormatted.filter(item => !item.id.includes('kyberswap'))
const dexesOutsideKyberswap = dexesFormatted.filter(item => !isKyberSwapDex(item.id))
const dexesKyberswap = uniqueArray(
dexesFormatted.filter(dex => KYBERSWAP_KS_DEXES_TO_UI_DEXES[dex.id]),
dex => KYBERSWAP_KS_DEXES_TO_UI_DEXES[dex.id],
)
const dexesUIKyberswap = dexesKyberswap.map(dex => ({
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
...KYBERSWAP_UI_DEXES[KYBERSWAP_KS_DEXES_TO_UI_DEXES[dex.id]!],
sortId: dex.sortId,
}))

const dexesUIKyberswap = dexesKyberswap.map(dex => {
return {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
id: KYBERSWAP_KS_DEXES_TO_UI_DEXES[dex.id]!,
name: dex.name,
logoURL: dex.logoURL || 'https://kyberswap.com/favicon.ico',
sortId: dex.sortId,
}
})

return [...dexesOutsideKyberswap, ...dexesUIKyberswap]
}, [dexes])
Expand Down

0 comments on commit 55ef134

Please sign in to comment.