From 73f12fa7b08e22ff0172f7cd6f80d2250c4230fa Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Mon, 14 Oct 2024 16:50:48 +0700 Subject: [PATCH 1/2] fix image and search pool --- src/components/Pagination/usePagination.ts | 5 ++- .../Pool-V3/components/PoolList/index.tsx | 3 +- src/pages/UniversalSwap/helpers.ts | 42 ++++++++++++++++++- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/components/Pagination/usePagination.ts b/src/components/Pagination/usePagination.ts index 63ad80fc1..00ae5a7cf 100644 --- a/src/components/Pagination/usePagination.ts +++ b/src/components/Pagination/usePagination.ts @@ -2,11 +2,12 @@ import { useState } from 'react'; export const LIMIT_PAGE = 10; -const usePagination = ({ data }) => { +const usePagination = ({ data, search }) => { const [limit, _setLimit] = useState(LIMIT_PAGE); const [page, setPage] = useState(1); const totalPages = Math.ceil(data.length / limit); - const indexOfLastItem = page * limit; + let indexOfLastItem = page * limit; + if (search) indexOfLastItem = 1 * limit; const indexOfFirstItem = indexOfLastItem - limit; const handleNext = () => { diff --git a/src/pages/Pool-V3/components/PoolList/index.tsx b/src/pages/Pool-V3/components/PoolList/index.tsx index 289b6ad28..8deb5d36f 100644 --- a/src/pages/Pool-V3/components/PoolList/index.tsx +++ b/src/pages/Pool-V3/components/PoolList/index.tsx @@ -227,7 +227,8 @@ const PoolList = ({ search, filterType }: { search: string; filterType: POOL_TYP }); const { setPage, page, handleNext, handlePrev, totalPages, indexOfLastItem, indexOfFirstItem } = usePagination({ - data: filteredPool + data: filteredPool, + search }); useOnClickOutside(sortRef, () => { diff --git a/src/pages/UniversalSwap/helpers.ts b/src/pages/UniversalSwap/helpers.ts index df2e09cf1..f95cfdf11 100644 --- a/src/pages/UniversalSwap/helpers.ts +++ b/src/pages/UniversalSwap/helpers.ts @@ -23,7 +23,7 @@ import { } from '@oraichain/oraidex-universal-swap'; import { isMobile } from '@walletconnect/browser-utils'; import { swapFromTokens, swapToTokens, tokenMap } from 'config/bridgeTokens'; -import { flattenTokensWithIcon, oraichainTokensWithIcon } from 'config/chainInfos'; +import { flattenTokensWithIcon, oraichainTokensWithIcon, tokensWithIcon } from 'config/chainInfos'; import { PAIRS_CHART } from 'config/pools'; import { networks } from 'helper'; import { generateError } from 'libs/utils'; @@ -32,6 +32,7 @@ import { TIMER } from 'pages/CoHarvest/constants'; import { formatDate, formatTimeWithPeriod } from 'pages/CoHarvest/helpers'; import { endOfMonth, endOfWeek } from 'pages/Pools/helpers'; import { FILTER_TIME_CHART, PairToken } from 'reducer/type'; +import { assets } from 'chain-registry'; export enum SwapDirection { From, @@ -524,3 +525,42 @@ export const getPathInfo = (path, chainIcons, assets) => { return { NetworkFromIcon, NetworkToIcon, pathChainId }; }; + +export const getTokenIconWithChainRegistry = (baseDenom: string) => { + if (!baseDenom) return undefined; + + const supportedChains = new Set([ + 'osmosis', + 'cosmoshub', + 'injective', + 'noble', + 'celestia', + 'oraichain', + 'neutaro', + 'binancesmartchain', + 'bitcoin', + 'ethereum', + 'tron', + 'ton' + ]); + + const baseDenomUpper = baseDenom.toUpperCase(); + + const assetList = assets.flatMap(({ chain_name, assets }) => (supportedChains.has(chain_name) ? assets : [])); + + const isMatchingAsset = (asset) => { + const [token, tokenCw20] = asset.base.split(':'); + const tokenAddressMatch = asset?.address?.toUpperCase() === baseDenomUpper; + const denomMatch = (tokenCw20 || token).toUpperCase() === baseDenomUpper; + + return denomMatch || tokenAddressMatch; + }; + + return assetList.find(isMatchingAsset); +}; + +export const getTokenIconWithCommon = (baseDenom: string) => { + return flattenTokensWithIcon.find((token) => + [token?.contractAddress, token.denom].filter(Boolean).includes(baseDenom) + ); +}; From 9047aad0c6303d3b27bb486dd3802fb5b9fbc0e7 Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Mon, 14 Oct 2024 16:55:28 +0700 Subject: [PATCH 2/2] fix image and search pool --- src/components/Pagination/usePagination.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Pagination/usePagination.ts b/src/components/Pagination/usePagination.ts index 00ae5a7cf..570271ca8 100644 --- a/src/components/Pagination/usePagination.ts +++ b/src/components/Pagination/usePagination.ts @@ -7,7 +7,7 @@ const usePagination = ({ data, search }) => { const [page, setPage] = useState(1); const totalPages = Math.ceil(data.length / limit); let indexOfLastItem = page * limit; - if (search) indexOfLastItem = 1 * limit; + if (search) indexOfLastItem = limit; const indexOfFirstItem = indexOfLastItem - limit; const handleNext = () => {