From 5b4449bcddc4bd966d974241f32cc4baec14b1d8 Mon Sep 17 00:00:00 2001 From: maro Date: Tue, 10 Jan 2023 00:25:33 +0900 Subject: [PATCH] chore: remove `isLp` from select asset form --- src/components/SelectAssetForm/index.tsx | 328 ++++++++--------------- src/pages/Trade/Swap/index.tsx | 5 +- 2 files changed, 111 insertions(+), 222 deletions(-) diff --git a/src/components/SelectAssetForm/index.tsx b/src/components/SelectAssetForm/index.tsx index f05b9a43..73607f21 100644 --- a/src/components/SelectAssetForm/index.tsx +++ b/src/components/SelectAssetForm/index.tsx @@ -1,4 +1,4 @@ -import { Col, Hidden, Row } from "react-grid-system"; +import { Col, Row } from "react-grid-system"; import styled from "@emotion/styled"; import { css, useTheme } from "@emotion/react"; import React, { useDeferredValue, useMemo, useState } from "react"; @@ -19,7 +19,6 @@ import Input from "components/Input"; import Hr from "components/Hr"; import TabButton from "components/TabButton"; import useAssets from "hooks/useAssets"; -import usePairs from "hooks/usePair"; import iconBookmark from "assets/icons/icon-bookmark-default.svg"; import iconBookmarkSelected from "assets/icons/icon-bookmark-selected.svg"; import useBookmark from "hooks/useBookmark"; @@ -42,7 +41,7 @@ interface SelectAssetFormProps { goBackOnSelect?: boolean; onSelect?(address: string): void; - addressList?: { address: string; isLP?: boolean }[]; + addressList?: string[]; } const Wrapper = styled.div` @@ -165,7 +164,6 @@ function SelectAssetForm(props: SelectAssetFormProps) { const [searchKeyword, setSearchKeyword] = useState(""); const deferredSearchKeyword = useDeferredValue(searchKeyword); const { getAsset, verifiedAssets } = useAssets(); - const { findPairByLpAddress } = usePairs(); const { bookmarks, toggleBookmark } = useBookmark(); const network = useNetwork(); const [tabIdx, setTabIdx] = useState(0); @@ -197,235 +195,130 @@ function SelectAssetForm(props: SelectAssetFormProps) { const items = ( isBookmark - ? bookmarks?.map((b) => ({ address: b, isLP: false })) + ? addressList?.filter((address) => bookmarks?.includes(address)) : addressList - )?.map(({ address, isLP }) => { - if (!isLP) { - const asset = getAsset(address); - const isVerified = - !!verifiedAssets?.[address] || - isNativeTokenAddress(network.name, address); - return ( - - item - ?.toLowerCase() - .includes(deferredSearchKeyword.toLowerCase()), - ) < 0 - } - onClick={() => { - if (handleSelect) { - handleSelect(address); - } - if (goBackOnSelect && onGoBack) { - onGoBack(); - } - }} - > - { - e.stopPropagation(); - toggleBookmark(address); - }} - /> - - - - {isVerified && ( - -
- - )} - - - - - {asset?.symbol} - - - {asset?.name} - - {ellipsisCenter(address, 6)} - - - - - - {formatNumber( - cutDecimal( - amountToValue(asset?.balance || 0, asset?.decimals) || 0, - 3, - ), - )} - - - ); - } - - const pair = findPairByLpAddress(address); - const assets = pair?.asset_addresses.map((item) => getAsset(item)) || []; - + )?.map((address) => { + const asset = getAsset(address); + const isVerified = + !!verifiedAssets?.[address] || + isNativeTokenAddress(network.name, address); return ( - asset?.address - ?.toLowerCase() - .includes(deferredSearchKeyword.toLowerCase()) || - asset?.symbol - ?.toLowerCase() - .includes(deferredSearchKeyword.toLowerCase()) || - asset?.name - ?.toLowerCase() - .includes(deferredSearchKeyword.toLowerCase()), - ) < 0) + [asset?.name, asset?.address, asset?.symbol].findIndex((item) => + item?.toLowerCase().includes(deferredSearchKeyword.toLowerCase()), + ) < 0 } + onClick={() => { + if (handleSelect) { + handleSelect(address); + } + if (goBackOnSelect && onGoBack) { + onGoBack(); + } + }} > -
{ + e.stopPropagation(); + toggleBookmark(address); + }} + /> + - div:last-child { - display: none; - } + vertical-align: middle; `} > - {assets.map((asset) => ( - - - + {isVerified && ( + +
- - - - {asset?.name} - - - - - -  -  - - - - - ))} - - - - - {ellipsisCenter(address, 10)} - - - -
+
+ )} +
+ + + + {asset?.symbol} + + + {asset?.name} + + {ellipsisCenter(address, 6)} + + + +
+ + {formatNumber( + cutDecimal( + amountToValue(asset?.balance || 0, asset?.decimals) || 0, + 3, + ), + )} + ); }); @@ -452,7 +345,6 @@ function SelectAssetForm(props: SelectAssetFormProps) { }, [ bookmarks, deferredSearchKeyword, - findPairByLpAddress, getAsset, goBackOnSelect, handleSelect, diff --git a/src/pages/Trade/Swap/index.tsx b/src/pages/Trade/Swap/index.tsx index 72595319..a1c741f6 100644 --- a/src/pages/Trade/Swap/index.tsx +++ b/src/pages/Trade/Swap/index.tsx @@ -410,10 +410,7 @@ function SwapPage() { > ({ - address, - isLP: false, - }))} + addressList={availableAssetAddresses.addresses} hasBackButton selectedAssetAddress={ selectAsset1Modal.isOpen