From fdaf8deb9742a029a5fa876378fc1117c9240e8b Mon Sep 17 00:00:00 2001 From: 0xoscario <33234035+0xoscario@users.noreply.github.com> Date: Thu, 27 Feb 2025 07:32:02 -0800 Subject: [PATCH] Remove Farming toggle and add All tab --- src/constants/index.ts | 13 +- src/hooks/v3/useV3Positions.ts | 5 + .../PoolsPage/v3/MyDefiedgePoolsV3/index.tsx | 16 +- .../PoolsPage/v3/MyGammaPoolsV3/index.tsx | 42 ++-- src/pages/PoolsPage/v3/MyICHIPools/index.tsx | 28 +-- .../PoolsPage/v3/MyLiquidityPoolsV3/index.tsx | 184 ++++++++++++------ .../PoolsPage/v3/MyLiquidityPoolsV4/index.tsx | 1 - .../PoolsPage/v3/MyQuickswapPoolsV3/index.tsx | 71 +++---- .../PoolsPage/v3/MySteerPoolsV3/index.tsx | 28 +-- .../PoolsPage/v3/MyUnipilotPoolsV3/index.tsx | 42 ++-- 10 files changed, 272 insertions(+), 158 deletions(-) diff --git a/src/constants/index.ts b/src/constants/index.ts index 3e7ea17fa..bab4d7105 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -301,12 +301,13 @@ export const GlobalConst = { otherLP: '4', }, poolsFilter: { - quickswap: '0', - unipilot: '1', - gamma: '2', - steer: '3', - defiedge: '4', - ichi: '5', + all: '0', + quickswap: '1', + unipilot: '2', + gamma: '3', + steer: '4', + defiedge: '5', + ichi: '6', }, }, analyticChart: { diff --git a/src/hooks/v3/useV3Positions.ts b/src/hooks/v3/useV3Positions.ts index 8e729d7f4..afd66b1c2 100644 --- a/src/hooks/v3/useV3Positions.ts +++ b/src/hooks/v3/useV3Positions.ts @@ -47,6 +47,7 @@ interface UseV3PositionsResults { loading: boolean; positions: PositionPool[] | undefined; count?: number; + includeCloseCount?: number; } export function useV3PositionsFromTokenIds( @@ -253,6 +254,9 @@ export function useV3Positions( (hideFarmingPosition ? 0 : transferredTokenIds.length + oldTransferredTokenIds.length); + const totalCount = + (algebraPositions ?? []).concat(isV4 ? [] : uniV3Positions ?? []).length + + (transferredTokenIds.length + oldTransferredTokenIds.length); return { loading: @@ -263,6 +267,7 @@ export function useV3Positions( _positionsOnFarmerLoading, positions: combinedPositions, count, + includeCloseCount: totalCount, }; } diff --git a/src/pages/PoolsPage/v3/MyDefiedgePoolsV3/index.tsx b/src/pages/PoolsPage/v3/MyDefiedgePoolsV3/index.tsx index 8595a1de9..ff2c8406a 100644 --- a/src/pages/PoolsPage/v3/MyDefiedgePoolsV3/index.tsx +++ b/src/pages/PoolsPage/v3/MyDefiedgePoolsV3/index.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect } from 'react'; import { Box, Button } from '@material-ui/core'; import { useActiveWeb3React } from 'hooks'; import Loader from 'components/Loader'; @@ -7,7 +7,13 @@ import DefiedgeLPList from './DefiedgeLPList'; import { useDefiedgePositions } from 'hooks/v3/useV3Positions'; import { useWeb3Modal } from '@web3modal/ethers5/react'; -export default function MyDefiedgePoolsV3() { +export default function MyDefiedgePoolsV3({ + isForAll, + setIsLoading, +}: { + isForAll?: boolean; + setIsLoading?: (loading: boolean) => void; +}) { const { t } = useTranslation(); const { chainId, account } = useActiveWeb3React(); @@ -17,9 +23,13 @@ export default function MyDefiedgePoolsV3() { const { positions, loading } = useDefiedgePositions(account, chainId); + useEffect(() => { + !!setIsLoading && setIsLoading(loading); + }, [setIsLoading, loading]); + return ( - {loading ? ( + {!!account && isForAll && loading ? ( diff --git a/src/pages/PoolsPage/v3/MyGammaPoolsV3/index.tsx b/src/pages/PoolsPage/v3/MyGammaPoolsV3/index.tsx index b3c1bfc89..0b8cc6a1b 100644 --- a/src/pages/PoolsPage/v3/MyGammaPoolsV3/index.tsx +++ b/src/pages/PoolsPage/v3/MyGammaPoolsV3/index.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect } from 'react'; import { Box, Button } from '@material-ui/core'; import { useActiveWeb3React } from 'hooks'; import Loader from 'components/Loader'; @@ -15,7 +15,13 @@ import { formatUnits, Interface } from 'ethers/lib/utils'; import { useGammaData } from 'hooks/v3/useGammaData'; import { useWeb3Modal } from '@web3modal/ethers5/react'; -export default function MyGammaPoolsV3() { +export default function MyGammaPoolsV3({ + isForAll, + setIsLoading, +}: { + isForAll?: boolean; + setIsLoading?: (loading: boolean) => void; +}) { const { t } = useTranslation(); const { chainId, account } = useActiveWeb3React(); @@ -109,6 +115,10 @@ export default function MyGammaPoolsV3() { lpTotalSupplyLoading || dataLoading; + useEffect(() => { + !!setIsLoading && setIsLoading(loading); + }, [setIsLoading, loading]); + const gammaPositions = lpsWithStakedAmount .map((lp, ind) => { const totalAmountsCalldata = lpTotalAmounts[ind]; @@ -165,25 +175,27 @@ export default function MyGammaPoolsV3() { .filter((item) => item.lpAmount > 0); return ( - - {loading ? ( + <> + {!!account && !isForAll && loading ? ( ) : gammaPositions.length > 0 ? ( ) : ( - -

{t('noLiquidityPositions')}.

- {showConnectAWallet && ( - - - - )} -
+ !isForAll && ( + +

{t('noLiquidityPositions')}.

+ {showConnectAWallet && ( + + + + )} +
+ ) )} -
+ ); } diff --git a/src/pages/PoolsPage/v3/MyICHIPools/index.tsx b/src/pages/PoolsPage/v3/MyICHIPools/index.tsx index cb585b979..b09b43392 100644 --- a/src/pages/PoolsPage/v3/MyICHIPools/index.tsx +++ b/src/pages/PoolsPage/v3/MyICHIPools/index.tsx @@ -6,7 +6,7 @@ import ICHILPItem from './ICHILPItem'; import { useICHIPositions } from 'hooks/v3/useV3Positions'; import { useWeb3Modal } from '@web3modal/ethers5/react'; -export default function MyICHIPools() { +export default function MyICHIPools({ isForAll }: { isForAll?: boolean }) { const { t } = useTranslation(); const { account } = useActiveWeb3React(); @@ -17,7 +17,7 @@ export default function MyICHIPools() { const { positions } = useICHIPositions(); return ( - + <> {positions && positions.length > 0 ? ( <> {positions.map((position, index) => ( @@ -25,17 +25,19 @@ export default function MyICHIPools() { ))} ) : ( - -

{t('noLiquidityPositions')}.

- {showConnectAWallet && ( - - - - )} -
+ !isForAll && ( + +

{t('noLiquidityPositions')}.

+ {showConnectAWallet && ( + + + + )} +
+ ) )} -
+ ); } diff --git a/src/pages/PoolsPage/v3/MyLiquidityPoolsV3/index.tsx b/src/pages/PoolsPage/v3/MyLiquidityPoolsV3/index.tsx index b05b79107..f4140dc7a 100644 --- a/src/pages/PoolsPage/v3/MyLiquidityPoolsV3/index.tsx +++ b/src/pages/PoolsPage/v3/MyLiquidityPoolsV3/index.tsx @@ -24,12 +24,10 @@ import MyUnipilotPoolsV3 from '../MyUnipilotPoolsV3'; import MyDefiedgePoolsV3 from '../MyDefiedgePoolsV3'; import MySteerPoolsV3 from '../MySteerPoolsV3'; import MyICHIPools from '../MyICHIPools'; -import { useIsV4 } from 'state/application/hooks'; export default function MyLiquidityPoolsV3() { const { t } = useTranslation(); const { chainId, account } = useActiveWeb3React(); - const { isV4 } = useIsV4(); const history = useHistory(); const { pairs: allV2PairsWithLiquidity } = useV2LiquidityPools( @@ -43,9 +41,11 @@ export default function MyLiquidityPoolsV3() { userHideQuickClosedPositions, setUserHideQuickClosedPositions, ] = useState(true); - const [hideQuickFarmingPositions, setHideQuickFarmingPositions] = useState( - false, - ); + + const [quickswapPoolsLoading, setQuickswapPoolsLoading] = useState(false); + const [unipilogPoolsLoading, setUnipilogPoolsLoading] = useState(false); + const [gammaPoolsLoading, setGammaPoolsLoading] = useState(false); + const [defiedgePoolsLoading, setDefiedgePoolsLoading] = useState(false); const filters = [ { @@ -53,54 +53,82 @@ export default function MyLiquidityPoolsV3() { method: setUserHideQuickClosedPositions, checkValue: userHideQuickClosedPositions, }, - { - title: t('farming'), - method: setHideQuickFarmingPositions, - checkValue: hideQuickFarmingPositions, - }, ]; - const { count: quickPoolsCount } = useV3Positions( - account, - userHideQuickClosedPositions, - hideQuickFarmingPositions, - isV4, - ); const { - loading: gammaPoolsLoading, + count: quickPoolsCount, + includeCloseCount: quickPoolsTotalCount, + loading: quickswapCountLoading, + } = useV3Positions(account, userHideQuickClosedPositions); + const { + loading: gammaPoolsCountLoading, count: gammaPoolsCount, } = useGammaPositionsCount(account, chainId); const { - loading: uniPilotPositionsLoading, + loading: uniPilotPositionsCountLoading, count: unipilotPositionsCount, } = useUnipilotPositionsCount(account, chainId); const { - loading: defiedgeStrategiesLoading, + loading: defiedgeStrategiesCountLoading, count: defiedgeStrategiesCount, } = useDefiedgePositions(account, chainId); const { - loading: steerPoolsLoading, + loading: steerPoolsCountLoading, count: steerPoolsCount, } = useV3SteerPositionsCount(); - const { loading: ichiLoading, count: ichiCount } = useICHIPositionsCount(); + const { + loading: ichiCountLoading, + count: ichiCount, + } = useICHIPositionsCount(); + + const counterLoading = + quickswapCountLoading || + gammaPoolsCountLoading || + uniPilotPositionsCountLoading || + steerPoolsCountLoading || + ichiCountLoading || + defiedgeStrategiesCountLoading; - const loading = - gammaPoolsLoading && - uniPilotPositionsLoading && - steerPoolsLoading && - ichiLoading && - defiedgeStrategiesLoading; + const poolLoading = + quickswapPoolsLoading || + unipilogPoolsLoading || + gammaPoolsLoading || + defiedgePoolsLoading; const [poolFilter, setPoolFilter] = useState( - GlobalConst.utils.poolsFilter.quickswap, + GlobalConst.utils.poolsFilter.all, ); const myPoolsFilter = useMemo(() => { const filters: any[] = []; + // all tab + filters.push({ + id: GlobalConst.utils.poolsFilter.all, + text: ( + + All + + {(quickPoolsTotalCount ?? 0) + + unipilotPositionsCount + + gammaPoolsCount + + defiedgeStrategiesCount + + steerPoolsCount + + ichiCount} + + + ), + }); filters.push({ id: GlobalConst.utils.poolsFilter.quickswap, text: ( @@ -228,6 +256,7 @@ export default function MyLiquidityPoolsV3() { defiedgeStrategiesCount, steerPoolsCount, ichiCount, + quickPoolsTotalCount, ]); return ( @@ -257,7 +286,7 @@ export default function MyLiquidityPoolsV3() {
)} - {loading ? ( + {!!account && counterLoading ? ( @@ -272,40 +301,79 @@ export default function MyLiquidityPoolsV3() { /> - {poolFilter === GlobalConst.utils.poolsFilter.quickswap && ( + {((!!account && counterLoading) || (account && poolLoading)) && ( + + + + )} + {!counterLoading && ( <> - {account && ( - - - {filters.map((item, key) => ( - - + {poolFilter === GlobalConst.utils.poolsFilter.all && ( + <> + {(quickPoolsCount ?? 0) > 0 && ( + + )} + {unipilotPositionsCount > 0 && ( + + )} + {gammaPoolsCount > 0 && ( + + )} + {defiedgeStrategiesCount > 0 && ( + + )} + {steerPoolsCount > 0 && } + {ichiCount > 0 && } + + )} + {poolFilter === GlobalConst.utils.poolsFilter.quickswap && ( + <> + {account && ( + + + {filters.map((item, key) => ( + + + + ))} - ))} - - + + )} + + + )} + {poolFilter === GlobalConst.utils.poolsFilter.unipilot && ( + + )} + {poolFilter === GlobalConst.utils.poolsFilter.gamma && ( + + )} + {poolFilter === GlobalConst.utils.poolsFilter.defiedge && ( + + )} + {poolFilter === GlobalConst.utils.poolsFilter.steer && ( + + )} + {poolFilter === GlobalConst.utils.poolsFilter.ichi && ( + )} - )} - {poolFilter === GlobalConst.utils.poolsFilter.unipilot && ( - - )} - {poolFilter === GlobalConst.utils.poolsFilter.gamma && ( - - )} - {poolFilter === GlobalConst.utils.poolsFilter.defiedge && ( - - )} - {poolFilter === GlobalConst.utils.poolsFilter.steer && ( - - )} - {poolFilter === GlobalConst.utils.poolsFilter.ichi && ( - - )} )} diff --git a/src/pages/PoolsPage/v3/MyLiquidityPoolsV4/index.tsx b/src/pages/PoolsPage/v3/MyLiquidityPoolsV4/index.tsx index 0fea35a73..7e7ea0076 100644 --- a/src/pages/PoolsPage/v3/MyLiquidityPoolsV4/index.tsx +++ b/src/pages/PoolsPage/v3/MyLiquidityPoolsV4/index.tsx @@ -129,7 +129,6 @@ export default function MyLiquidityPoolsV4() { )} diff --git a/src/pages/PoolsPage/v3/MyQuickswapPoolsV3/index.tsx b/src/pages/PoolsPage/v3/MyQuickswapPoolsV3/index.tsx index c8b064f10..b5a4bde5a 100644 --- a/src/pages/PoolsPage/v3/MyQuickswapPoolsV3/index.tsx +++ b/src/pages/PoolsPage/v3/MyQuickswapPoolsV3/index.tsx @@ -1,4 +1,4 @@ -import React, { useMemo } from 'react'; +import React, { useMemo, useEffect } from 'react'; import { Box, Button } from '@material-ui/core'; import { useV3Positions } from 'hooks/v3/useV3Positions'; import { useActiveWeb3React } from 'hooks'; @@ -10,16 +10,17 @@ import { useWeb3Modal } from '@web3modal/ethers5/react'; import { useIsV4 } from 'state/application/hooks'; const MyQuickswapPoolsV3: React.FC<{ - hideFarmingPositions: boolean; userHideClosedPositions: boolean; -}> = ({ hideFarmingPositions, userHideClosedPositions }) => { + isForAll?: boolean; + setIsLoading?: (loading: boolean) => void; +}> = ({ userHideClosedPositions, isForAll, setIsLoading }) => { const { t } = useTranslation(); const { account } = useActiveWeb3React(); const { isV4 } = useIsV4(); const { positions, loading: positionsLoading } = useV3Positions( account, - userHideClosedPositions, - hideFarmingPositions, + !isForAll && userHideClosedPositions, + false, isV4, ); @@ -44,16 +45,16 @@ const MyQuickswapPoolsV3: React.FC<{ const filteredPositions = useMemo( () => [ - ...(hideFarmingPositions || !farmingPositions ? [] : farmingPositions), + ...(!farmingPositions ? [] : farmingPositions), ...inRangeWithOutFarmingPositions, - ...(userHideClosedPositions ? [] : closedPositions), + ...(!isForAll && userHideClosedPositions ? [] : closedPositions), ], [ - hideFarmingPositions, farmingPositions, inRangeWithOutFarmingPositions, userHideClosedPositions, closedPositions, + isForAll, ], ); @@ -63,35 +64,37 @@ const MyQuickswapPoolsV3: React.FC<{ const showConnectAWallet = Boolean(!account); + useEffect(() => { + !!setIsLoading && setIsLoading(positionsLoading); + }, [setIsLoading, positionsLoading]); + const { open } = useWeb3Modal(); return ( - - - {positionsLoading ? ( - - - - ) : filteredPositions && filteredPositions.length > 0 ? ( - - Number(+posA.tokenId < +posB.tokenId), - )} - newestPosition={newestPosition} - /> - ) : ( - -

{t('noLiquidityPositions')}.

- {showConnectAWallet && ( - - - - )} -
- )} -
+ + {!!account && !isForAll && positionsLoading ? ( + + + + ) : filteredPositions && filteredPositions.length > 0 ? ( + + Number(+posA.tokenId < +posB.tokenId), + )} + newestPosition={newestPosition} + /> + ) : ( + + {!isForAll &&

{t('noLiquidityPositions')}.

} + {showConnectAWallet && ( + + + + )} +
+ )}
); }; diff --git a/src/pages/PoolsPage/v3/MySteerPoolsV3/index.tsx b/src/pages/PoolsPage/v3/MySteerPoolsV3/index.tsx index 3e93bc8c8..31f41ea11 100644 --- a/src/pages/PoolsPage/v3/MySteerPoolsV3/index.tsx +++ b/src/pages/PoolsPage/v3/MySteerPoolsV3/index.tsx @@ -6,7 +6,7 @@ import SteerLPItem from './SteerLPItem'; import { useV3SteerPositions } from 'hooks/v3/useV3Positions'; import { useWeb3Modal } from '@web3modal/ethers5/react'; -export default function MySteerPoolsV3() { +export default function MySteerPoolsV3({ isForAll }: { isForAll?: boolean }) { const { t } = useTranslation(); const { account } = useActiveWeb3React(); @@ -17,7 +17,7 @@ export default function MySteerPoolsV3() { const steerPositions = useV3SteerPositions(); return ( - + <> {steerPositions && steerPositions.length > 0 ? ( {steerPositions.map((position, index) => ( @@ -25,17 +25,19 @@ export default function MySteerPoolsV3() { ))} ) : ( - -

{t('noLiquidityPositions')}.

- {showConnectAWallet && ( - - - - )} -
+ !isForAll && ( + +

{t('noLiquidityPositions')}.

+ {showConnectAWallet && ( + + + + )} +
+ ) )} -
+ ); } diff --git a/src/pages/PoolsPage/v3/MyUnipilotPoolsV3/index.tsx b/src/pages/PoolsPage/v3/MyUnipilotPoolsV3/index.tsx index e9f43d587..4b6b26795 100644 --- a/src/pages/PoolsPage/v3/MyUnipilotPoolsV3/index.tsx +++ b/src/pages/PoolsPage/v3/MyUnipilotPoolsV3/index.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect } from 'react'; import { Box, Button } from '@material-ui/core'; import { useActiveWeb3React } from 'hooks'; import Loader from 'components/Loader'; @@ -10,7 +10,13 @@ import { } from 'hooks/v3/useV3Positions'; import { useWeb3Modal } from '@web3modal/ethers5/react'; -export default function MyUnipilotPoolsV3() { +export default function MyUnipilotPoolsV3({ + isForAll, + setIsLoading, +}: { + isForAll?: boolean; + setIsLoading?: (loading: boolean) => void; +}) { const { t } = useTranslation(); const { chainId, account } = useActiveWeb3React(); @@ -23,9 +29,13 @@ export default function MyUnipilotPoolsV3() { unipilotPositions, } = useUnipilotPositions(account, chainId); + useEffect(() => { + !!setIsLoading && setIsLoading(uniPilotPositionsLoading); + }, [setIsLoading, uniPilotPositionsLoading]); + return ( - - {uniPilotPositionsLoading ? ( + <> + {!!account && !isForAll && uniPilotPositionsLoading ? ( @@ -38,17 +48,19 @@ export default function MyUnipilotPoolsV3() { )} ) : ( - -

{t('noLiquidityPositions')}.

- {showConnectAWallet && ( - - - - )} -
+ !isForAll && ( + +

{t('noLiquidityPositions')}.

+ {showConnectAWallet && ( + + + + )} +
+ ) )} -
+ ); }