Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: filter for verified/unverified tokens #118

Merged
merged 1 commit into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 86 additions & 4 deletions src/forms/SwapTokens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Loading from "components/Loading"
import { SwapTokenAsset } from "./useSwapSelectToken"
import { VariableSizeList, ListChildComponentProps } from "react-window"
import { isNativeToken } from "libs/utils"
import styled from "styled-components"
import styled, { css } from "styled-components"

const cx = classNames.bind(styles)

Expand Down Expand Up @@ -50,6 +50,48 @@ const NoPairs = styled.div`
}
`

const ToggleWrapper = styled.div`
width: 100%;
height: auto;
position: relative;
padding: 3px 6px 3px 3px;
border-radius: 14.5px;
background-color: #e2e7ff;

display: flex;
justify-content: space-between;
align-items: center;
`

const ToggleItem = styled.button<{ selected?: boolean }>`
flex: 1;
width: 100%;
height: auto;
padding: 3px;
border-radius: 11.5px;
cursor: pointer;
font-size: 12px;
font-weight: bold;
font-stretch: normal;
font-style: normal;
line-height: normal;
letter-spacing: normal;
text-align: center;
color: #4460e6;
line-height: 17px;

${({ selected }) =>
selected &&
css`
background-color: #0222ba;
color: #ffffff;
`}
`

ToggleItem.defaultProps = {
type: "button",
}

const SwapTokens = ({
selected,
onSelect: handleSelect,
Expand All @@ -64,26 +106,48 @@ const SwapTokens = ({
const [searchKeyword, setSearchKeyword] = useState("")
const [listHeight, setListHeight] = useState(250)

const [verified, setVerified] = useState(true)

const filteredAssetList = useMemo(
() =>
assetList?.filter(({ contract_addr: contractAddr }) => {
let symbol = ""
if (type === Type.WITHDRAW) {
const tokenInfoList = lpTokenInfos.get(contractAddr)

if (
(!tokenInfoList?.[0].verified || !tokenInfoList?.[1].verified) &&
verified
) {
return false
}

if (
tokenInfoList?.[0].verified &&
tokenInfoList?.[1].verified &&
!verified
) {
return false
}

symbol = tokenInfoList
? tokenInfoList[0].symbol + "-" + tokenInfoList[1].symbol
: ""
} else {
const tokenInfo = tokenInfos.get(contractAddr)
symbol = tokenInfo ? tokenInfo.symbol : ""

if (tokenInfo?.verified !== verified) {
return false
}
}

return (
symbol.toLowerCase().indexOf(searchKeyword.toLowerCase()) >= 0 ||
contractAddr.toLowerCase().indexOf(searchKeyword.toLowerCase()) >= 0
)
}),
[assetList, searchKeyword, type]
[assetList, searchKeyword, type, verified]
)
const assetElements = useMemo(() => {
return filteredAssetList?.map((asset) => {
Expand Down Expand Up @@ -131,11 +195,11 @@ const SwapTokens = ({
return () => {
window.removeEventListener("resize", handleWindowResize)
}
}, [])
}, [filteredAssetList])

return (
<div className={styles.component}>
<section className={styles.search}>
<section className={styles.search} style={{ marginBottom: 20 }}>
<input
id="search"
name="search"
Expand All @@ -146,6 +210,24 @@ const SwapTokens = ({
/>
</section>

<div
style={{
marginBottom: 20,
display: "flex",
justifyContent: "center",
alignItems: "center",
}}
>
<ToggleWrapper style={{ maxWidth: 178 }}>
<ToggleItem selected={verified} onClick={() => setVerified(true)}>
verified
</ToggleItem>
<ToggleItem selected={!verified} onClick={() => setVerified(false)}>
unverified
</ToggleItem>
</ToggleWrapper>
</div>

<ul ref={listRef} className={classNames(styles.list)}>
{assetElements && !isPairsLoading ? (
<>
Expand Down
5 changes: 3 additions & 2 deletions src/rest/useAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ const useAPI = () => {
let lastPair: (NativeInfo | AssetInfo)[] | null = null

try {
const url = `${service}/pairs`
const res: PairsResult = (await axios.get(url)).data
const res: PairsResult = (
await axios.get(`${service}/pairs`, { params: { unverified: "true" } })
).data

if (res?.pairs?.length) {
res.pairs.forEach((pair) => {
Expand Down