From 4da9405df62cee10d0167315138f38e401da4255 Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Fri, 7 Feb 2025 11:00:38 +0700 Subject: [PATCH] fix crash pool --- src/pages/Pool-V3/components/PoolList/index.tsx | 12 ++++++------ src/pages/Pools/helpers.ts | 8 ++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/pages/Pool-V3/components/PoolList/index.tsx b/src/pages/Pool-V3/components/PoolList/index.tsx index f8c7fb5ae..9c372bbbe 100644 --- a/src/pages/Pool-V3/components/PoolList/index.tsx +++ b/src/pages/Pool-V3/components/PoolList/index.tsx @@ -32,6 +32,7 @@ import CreateNewPosition from '../CreateNewPosition'; import styles from './index.module.scss'; import PoolItemDataMobile from './PoolItemDataMobile'; import PoolItemTData from './PoolItemTData'; +import { isScientificFormat } from 'pages/Pools/helpers'; export enum PoolColumnHeader { POOL_NAME = 'Pool name', @@ -156,17 +157,16 @@ const PoolList = ({ search, filterType }: { search: string; filterType: POOL_TYP const showVolume = type === POOL_TYPE.V3 ? volumeV3 : toDisplay(volumeV2 || 0); let showApr = aprInfo?.[poolKey] || aprInfo?.[liquidityAddr] || {}; - if (type === POOL_TYPE.V2) { showApr = { ...showApr, apr: { - min: (showApr['apr']?.['min'] || 0), - max: (showApr['apr']?.['max'] || 0) + min: isScientificFormat(showApr['apr']?.['min']), + max: isScientificFormat(showApr['apr']?.['max']) }, swapFee: { - min: (showApr['swapFee']?.['min'] || 0), - max: (showApr['swapFee']?.['max'] || 0) + min: isScientificFormat(showApr['swapFee']?.['min']), + max: isScientificFormat(showApr['swapFee']?.['max']) } }; } @@ -194,7 +194,7 @@ const PoolList = ({ search, filterType }: { search: string; filterType: POOL_TYP return new BigDecimal(CoefficientBySort[sortOrder]).mul(a.showVolume - b.showVolume).toNumber(); case PoolColumnHeader.APR: return new BigDecimal(CoefficientBySort[sortOrder]) - .mul((a?.showApr.apr.max || 0) - (b?.showApr.apr.max || 0)) + .mul((a?.showApr.apr?.max || 0) - (b?.showApr.apr?.max || 0)) .toNumber(); default: diff --git a/src/pages/Pools/helpers.ts b/src/pages/Pools/helpers.ts index 8cf5e96f5..cc44f5f7c 100644 --- a/src/pages/Pools/helpers.ts +++ b/src/pages/Pools/helpers.ts @@ -337,3 +337,11 @@ export const listFactoryV1Pools: FACTORY_V1_POOL[] = [ ] } ]; + +export const isScientificFormat = (value) => { + // "6e-7" is in scientific format? true + // "-1.5e3" is in scientific format? true + // "0.001" is in scientific format? false + const regex = /^\d+e[+-]?\d+$/; + return !value || regex.test(value) ? 0 : value; +};