From 68244b31f7ee5660b0acdf294fe5536dab3842e7 Mon Sep 17 00:00:00 2001 From: DMY <147dmy@gmail.com> Date: Wed, 4 Dec 2024 18:22:59 +0800 Subject: [PATCH 1/2] fix: cant open swap list after clearing chain --- src/ui/component/TokenSelect/index.tsx | 34 +++++++++++++------ src/ui/views/Bridge/Component/BridgeToken.tsx | 1 + src/ui/views/Swap/Component/Main.tsx | 2 ++ 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/ui/component/TokenSelect/index.tsx b/src/ui/component/TokenSelect/index.tsx index 9d9785e9eda..4e0177ffd11 100644 --- a/src/ui/component/TokenSelect/index.tsx +++ b/src/ui/component/TokenSelect/index.tsx @@ -10,7 +10,7 @@ import { ReactComponent as SvgIconArrowDownTriangle } from '@/ui/assets/swap/arr import { useTokens } from '@/ui/utils/portfolio/token'; import { useRabbySelector } from '@/ui/store'; import { uniqBy } from 'lodash'; -import { SWAP_SUPPORT_CHAINS } from '@/constant'; +import { CHAINS_ENUM } from '@/constant'; import useSearchToken from '@/ui/hooks/useSearchToken'; import useSortToken from '@/ui/hooks/useSortTokens'; import { useAsync } from 'react-use'; @@ -52,14 +52,14 @@ const Text = styled.span` ${ellipsis()} `; -export interface TokenSelectProps { +interface CommonProps { token?: TokenItem; onChange?(amount: string): void; onTokenChange(token: TokenItem): void; - chainId?: string; + // chainId?: string; useSwapTokenList?: boolean; excludeTokens?: TokenItem['id'][]; - type?: ComponentProps['type']; + // type?: ComponentProps['type']; placeholder?: string; hideChainIcon?: boolean; value?: string; @@ -75,8 +75,21 @@ export interface TokenSelectProps { | React.ReactNode; disabledTips?: React.ReactNode; drawerHeight?: string | number; + supportChains?: CHAINS_ENUM[]; +} + +interface BridgeFromProps extends CommonProps { + type: 'bridgeFrom'; + chainId?: string; } +interface OtherProps extends CommonProps { + type: Exclude['type'], 'bridgeFrom'>; + chainId: string; +} + +type TokenSelectProps = BridgeFromProps | OtherProps; + const defaultExcludeTokens = []; const TokenSelect = ({ @@ -94,6 +107,7 @@ const TokenSelect = ({ useSwapTokenList = false, disabledTips = 'Not supported', drawerHeight, + supportChains, }: TokenSelectProps) => { const [queryConds, setQueryConds] = useState({ keyword: '', @@ -229,7 +243,7 @@ const TokenSelect = ({ {typeof tokenRender === 'function' ? tokenRender?.({ token, openTokenModal: handleSelectToken }) : tokenRender} - {queryConds.chainServerId && ( + {type === 'bridgeFrom' && !queryConds.chainServerId ? null : ( )} @@ -293,7 +307,7 @@ const TokenSelect = ({ /> )} - {queryConds.chainServerId && ( + {type === 'bridgeFrom' && !queryConds.chainServerId ? null : ( )} diff --git a/src/ui/views/Bridge/Component/BridgeToken.tsx b/src/ui/views/Bridge/Component/BridgeToken.tsx index f009a7d0114..1416b7ad91a 100644 --- a/src/ui/views/Bridge/Component/BridgeToken.tsx +++ b/src/ui/views/Bridge/Component/BridgeToken.tsx @@ -201,6 +201,7 @@ export const BridgeToken = ({ placeholder={t('page.swap.search-by-name-address')} disabledTips={t('page.bridge.insufficient-balance')} tokenRender={(p) => } + supportChains={supportedChains} /> )} diff --git a/src/ui/views/Swap/Component/Main.tsx b/src/ui/views/Swap/Component/Main.tsx index 2f7f247728d..93928ed8f34 100644 --- a/src/ui/views/Swap/Component/Main.tsx +++ b/src/ui/views/Swap/Component/Main.tsx @@ -526,6 +526,7 @@ export const Main = () => { placeholder={t('page.swap.search-by-name-address')} excludeTokens={receiveToken?.id ? [receiveToken?.id] : undefined} tokenRender={(p) => } + supportChains={SWAP_SUPPORT_CHAINS} /> { placeholder={t('page.swap.search-by-name-address')} excludeTokens={payToken?.id ? [payToken?.id] : undefined} tokenRender={(p) => } + supportChains={SWAP_SUPPORT_CHAINS} useSwapTokenList /> From fac8d34dd88ee484759754eaad3f91d5e2459791 Mon Sep 17 00:00:00 2001 From: DMY <147dmy@gmail.com> Date: Wed, 4 Dec 2024 18:24:47 +0800 Subject: [PATCH 2/2] clear --- src/ui/component/TokenSelect/index.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ui/component/TokenSelect/index.tsx b/src/ui/component/TokenSelect/index.tsx index 4e0177ffd11..e973954a964 100644 --- a/src/ui/component/TokenSelect/index.tsx +++ b/src/ui/component/TokenSelect/index.tsx @@ -56,10 +56,8 @@ interface CommonProps { token?: TokenItem; onChange?(amount: string): void; onTokenChange(token: TokenItem): void; - // chainId?: string; useSwapTokenList?: boolean; excludeTokens?: TokenItem['id'][]; - // type?: ComponentProps['type']; placeholder?: string; hideChainIcon?: boolean; value?: string;