From 85064bcb70e39c13a21127fb8e41571a94b0aae9 Mon Sep 17 00:00:00 2001 From: Thunnini Date: Thu, 19 Dec 2024 17:35:16 +0900 Subject: [PATCH] =?UTF-8?q?disabledChainInfos=EA=B0=80=20search=20text?= =?UTF-8?q?=EB=A5=BC=20=EB=B0=98=EC=98=81=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/hooks/use-get-search-chains.ts | 56 ++++++++++++++++--- 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/apps/extension/src/hooks/use-get-search-chains.ts b/apps/extension/src/hooks/use-get-search-chains.ts index 67964d280a..e414e1a7c8 100644 --- a/apps/extension/src/hooks/use-get-search-chains.ts +++ b/apps/extension/src/hooks/use-get-search-chains.ts @@ -75,15 +75,55 @@ export const useGetSearchChains = ({ (ChainInfo | ModularChainInfo)[] >([]); - const disabledChainInfos = useMemo( - () => - chainStore.chainInfosInListUI.filter( + const disabledChainInfosSearched = useMemo(() => { + return chainStore.chainInfosInListUI + .filter( (modularChainInfo) => !chainStore.isEnabledChain(modularChainInfo.chainId) - ), + ) + .filter((chainInfo) => { + const chainId = chainInfo.chainId.toLowerCase(); + const chainName = chainInfo.chainName.toLowerCase(); + const mainCurrencyDenom = + chainInfo.currencies[0].coinDenom.toLowerCase(); + const stakeCurrencyDenom = + chainInfo.stakeCurrency?.coinDenom.toLowerCase(); + const tokenDenom = chainStore.isEvmOnlyChain(chainInfo.chainId) + ? mainCurrencyDenom + : stakeCurrencyDenom || mainCurrencyDenom; + + // search text가 eth 또는 eth~ethereum일 경우 evm 체인은 모두 보여준다. + if (trimSearch.startsWith("eth")) { + const isEVM = !("bech32Config" in chainInfo); + + if (isEVM) { + return true; + } + } + + switch (filterOption) { + case "all": + return ( + chainName.includes(trimSearch) || + chainId.includes(trimSearch) || + tokenDenom.includes(trimSearch) + ); + case "chain": + return ( + chainName.includes(trimSearch) || chainId.includes(trimSearch) + ); + case "token": + return tokenDenom.includes(trimSearch); + case "chainNameAndToken": + return ( + chainName.includes(trimSearch) || tokenDenom.includes(trimSearch) + ); + default: + return false; + } + }); // eslint-disable-next-line react-hooks/exhaustive-deps - [chainStore.chainInfosInListUI] - ); + }, [chainStore.chainInfosInListUI, filterOption, trimSearch]); useEffect(() => { const disposer = autorun(() => { @@ -103,7 +143,7 @@ export const useGetSearchChains = ({ } const chains = queryChains.response.data.chains; - for (const disabledChainInfo of disabledChainInfos) { + for (const disabledChainInfo of disabledChainInfosSearched) { if ( !dupCheck.has( ChainIdHelper.parse(disabledChainInfo.chainId).identifier @@ -130,7 +170,7 @@ export const useGetSearchChains = ({ clearResultsOnEmptyQuery, initialChainInfos, queryChains, - disabledChainInfos, + disabledChainInfosSearched, ]); return {