-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: rfq dexes grouping * auto group dex by tag * fix: search * chore: env to prod
- Loading branch information
Showing
6 changed files
with
140 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { useEffect, useMemo, useRef } from 'react' | ||
|
||
import Checkbox from 'components/CheckBox' | ||
import { useActiveWeb3React } from 'hooks' | ||
import { useAllDexes, useExcludeDexes } from 'state/customizeDexes/hooks' | ||
|
||
import { ImageWrapper, Source, SourceName } from './styles' | ||
|
||
export const LiquiditySourceGroup = ({ | ||
tag, | ||
debouncedSearchText, | ||
}: { | ||
tag: { id: number; name: string } | ||
debouncedSearchText: string | ||
}) => { | ||
const { chainId } = useActiveWeb3React() | ||
const dexes = useAllDexes(chainId) | ||
|
||
const dexByTag = useMemo(() => dexes.filter(item => item.tags?.some(t => t.id === tag.id)), [dexes, tag.id]) | ||
|
||
const [excludeDexes, setExcludeDexes] = useExcludeDexes(chainId) | ||
|
||
const handleToggleDex = (id: string) => { | ||
const isExclude = excludeDexes.find(item => item === id) | ||
if (isExclude) { | ||
setExcludeDexes(excludeDexes.filter(item => item !== id)) | ||
} else { | ||
setExcludeDexes([...excludeDexes, id]) | ||
} | ||
} | ||
|
||
const groupRef = useRef<HTMLInputElement>(null) | ||
|
||
useEffect(() => { | ||
const selectedDexes = dexByTag?.filter(item => !excludeDexes.includes(item.id)) || [] | ||
|
||
if (!groupRef.current) return | ||
|
||
if (selectedDexes.length === dexByTag?.length) { | ||
groupRef.current.checked = true | ||
groupRef.current.indeterminate = false | ||
} else if (!selectedDexes.length) { | ||
groupRef.current.checked = false | ||
groupRef.current.indeterminate = false | ||
} else if (selectedDexes.length < (dexByTag?.length || 0)) { | ||
groupRef.current.checked = false | ||
groupRef.current.indeterminate = true | ||
} | ||
}, [excludeDexes, dexByTag]) | ||
|
||
const filteredDexes = dexByTag.filter(item => item.name.toLowerCase().includes(debouncedSearchText)) | ||
|
||
if (!filteredDexes.length) return null | ||
|
||
return ( | ||
<> | ||
<Source> | ||
<Checkbox | ||
ref={groupRef} | ||
checked={!dexByTag.map(i => i.id).every(item => excludeDexes.includes(item))} | ||
onChange={e => { | ||
if (e.target.checked) { | ||
setExcludeDexes(excludeDexes.filter(item => !dexByTag.map(d => d.id).includes(item))) | ||
} else { | ||
const newData = [ | ||
...excludeDexes.filter(item => dexByTag.map(d => d.id).includes(item)), | ||
...dexByTag.map(item => item.id), | ||
] | ||
setExcludeDexes(newData) | ||
} | ||
}} | ||
/> | ||
<SourceName>{tag.name}</SourceName> | ||
</Source> | ||
|
||
{filteredDexes.map(({ name, logoURL, id }) => { | ||
return ( | ||
<Source key={name} style={{ padding: '12px 48px' }}> | ||
<Checkbox checked={!excludeDexes.includes(id)} onChange={() => handleToggleDex(id)} /> | ||
|
||
<ImageWrapper> | ||
<img src={logoURL} alt="" /> | ||
</ImageWrapper> | ||
|
||
<SourceName>{name}</SourceName> | ||
</Source> | ||
) | ||
})} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import styled from 'styled-components' | ||
|
||
export const Source = styled.div` | ||
width: 100%; | ||
height: 32px; | ||
display: flex; | ||
align-items: center; | ||
column-gap: 16px; | ||
padding: 12px; | ||
` | ||
|
||
export const ImageWrapper = styled.div` | ||
width: 32px; | ||
height: 32px; | ||
display: flex; | ||
align-items: center; | ||
img { | ||
width: 100%; | ||
height: auto; | ||
} | ||
` | ||
|
||
export const SourceName = styled.span` | ||
font-size: 14px; | ||
font-weight: 400; | ||
line-height: 20px; | ||
color: ${({ theme }) => theme.text}; | ||
` |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters