From 9c3b7de03814c64194736f51f1f801d9b6886de9 Mon Sep 17 00:00:00 2001 From: vuonghuuhung Date: Tue, 14 Jan 2025 18:30:16 +0700 Subject: [PATCH] refactor: improve token search logic and clean up console log --- src/pages/Balance/index.tsx | 17 +++++++++++------ .../components/OverviewPool/OverviewPool.tsx | 2 -- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/pages/Balance/index.tsx b/src/pages/Balance/index.tsx index e4d7f12bc..167acd098 100644 --- a/src/pages/Balance/index.tsx +++ b/src/pages/Balance/index.tsx @@ -205,12 +205,16 @@ const Balance: React.FC = () => { useGetFeeConfig(); useEffect(() => { - if (!searchTokenAddress) return setTokens([otherChainTokenCommon, oraichainTokensCommon]); - (async () => { try { + if (!searchTokenAddress) return setTokens([otherChainTokenCommon, oraichainTokensCommon]); + const foundTokens = [otherChainTokenCommon, oraichainTokensCommon].map((childTokens) => - childTokens.filter((t) => t.name.includes(searchTokenAddress.toUpperCase())) + childTokens.filter((t) => + [t.name.toUpperCase(), t.contractAddress?.toUpperCase(), t.denom?.toUpperCase()].includes( + searchTokenAddress.toUpperCase() + ) + ) ); if (foundTokens.every((t) => t.length === 0)) { @@ -647,9 +651,10 @@ const Balance: React.FC = () => { let newToToken = to; if (toNetworkChainId && (!toToken || toToken?.chainId !== toNetworkChainId)) { - newToToken = [...otherChainTokens, ...oraichainTokens].find( - (flat) => flat.chainId === toNetworkChainId && flat.coinGeckoId === from.coinGeckoId - ); + newToToken = [...otherChainTokenCommon, ...oraichainTokensCommon].find((flat) => { + return flat.chainId === toNetworkChainId && flat.coinGeckoId === from.coinGeckoId; + }); + assert(newToToken, 'Cannot find newToToken token that matches from token to bridge!'); } diff --git a/src/pages/Pools/components/OverviewPool/OverviewPool.tsx b/src/pages/Pools/components/OverviewPool/OverviewPool.tsx index 332ac3935..77c439b73 100644 --- a/src/pages/Pools/components/OverviewPool/OverviewPool.tsx +++ b/src/pages/Pools/components/OverviewPool/OverviewPool.tsx @@ -19,8 +19,6 @@ import styles from './OverviewPool.module.scss'; export const OverviewPool = ({ poolDetailData }: { poolDetailData: PoolDetail }) => { const theme = useTheme(); - console.log(poolDetailData); - const { pairAmountInfoData } = useGetPairInfo(poolDetailData); const { token1, token2 } = poolDetailData;