Skip to content

Commit

Permalink
Merge pull request #996 from oraichain/fix/img-chainregistry
Browse files Browse the repository at this point in the history
fix image and search pool
  • Loading branch information
haunv3 authored Oct 22, 2024
2 parents 2ccfb1e + 9047aad commit ad00fbd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/components/Pagination/usePagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = limit;
const indexOfFirstItem = indexOfLastItem - limit;

const handleNext = () => {
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Pool-V3/components/PoolList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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, () => {
Expand Down
42 changes: 41 additions & 1 deletion src/pages/UniversalSwap/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand Down Expand Up @@ -509,3 +510,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)
);
};

0 comments on commit ad00fbd

Please sign in to comment.