From abdae697956f486af9480917c62d0effb42589c9 Mon Sep 17 00:00:00 2001 From: viet-nv Date: Wed, 20 Sep 2023 08:46:00 +0700 Subject: [PATCH] fix: farms is reset --- src/pages/Pools/index.tsx | 2 ++ src/pages/ProAmmPools/ListItem.tsx | 6 +++++- src/pages/ProAmmPools/index.tsx | 2 -- src/state/farms/elasticv2/updater.tsx | 8 +++++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/pages/Pools/index.tsx b/src/pages/Pools/index.tsx index 579f84aaf4..5d41df8e1c 100644 --- a/src/pages/Pools/index.tsx +++ b/src/pages/Pools/index.tsx @@ -33,6 +33,7 @@ import { Instruction } from 'pages/Pools/InstructionAndGlobalData' import ProAmmPoolList from 'pages/ProAmmPools' import { ApplicationModal } from 'state/application/actions' import { useOpenModal } from 'state/application/hooks' +import ElasticFarmV2Updater from 'state/farms/elasticv2/updater' import { Field } from 'state/pair/actions' import { MEDIA_WIDTHS } from 'theme' import { currencyId } from 'utils/currencyId' @@ -370,6 +371,7 @@ const Pools = () => { )} + ) } diff --git a/src/pages/ProAmmPools/ListItem.tsx b/src/pages/ProAmmPools/ListItem.tsx index fd0b5b4c1d..8345391988 100644 --- a/src/pages/ProAmmPools/ListItem.tsx +++ b/src/pages/ProAmmPools/ListItem.tsx @@ -128,7 +128,11 @@ export default function ProAmmPoolListItem({ pool, onShared, userPositions }: Li .find(farm => farm.poolAddress.toLowerCase() === pool.address.toLowerCase()) const isFarmV2 = !!farmV2 - const isFarmingPool = isFarmV1 || isFarmV2 + if (pool.address.toLowerCase() === '0x4db4ee18960c5cef92c2fc874daaa8e83f1608aa') { + console.log(farmV2, elasticFarmV2s) + } + + const isFarmingPool = isFarmV1 || isFarmV2 || !!pool.farmAPR const maxFarmV2Apr = Math.max(...(farmV2?.ranges.map(item => item.apr || 0) || []), 0) diff --git a/src/pages/ProAmmPools/index.tsx b/src/pages/ProAmmPools/index.tsx index 0284ba8d9c..236af8b042 100644 --- a/src/pages/ProAmmPools/index.tsx +++ b/src/pages/ProAmmPools/index.tsx @@ -19,7 +19,6 @@ import { ApplicationModal } from 'state/application/actions' import { useModalOpen, useOpenModal } from 'state/application/hooks' import { FarmUpdater, useElasticFarms } from 'state/farms/elastic/hooks' import { useElasticFarmsV2 } from 'state/farms/elasticv2/hooks' -import ElasticFarmV2Updater from 'state/farms/elasticv2/updater' import { Field } from 'state/mint/proamm/type' import { useTopPoolAddresses, useUserProMMPositions } from 'state/prommPools/hooks' import useGetElasticPools from 'state/prommPools/useGetElasticPools' @@ -472,7 +471,6 @@ export default function ProAmmPoolList({ title={sharedPoolId ? t`Share this pool with your friends!` : t`Share this list of pools with your friends`} /> - ) } diff --git a/src/state/farms/elasticv2/updater.tsx b/src/state/farms/elasticv2/updater.tsx index d9f9c169ac..3327c123b2 100644 --- a/src/state/farms/elasticv2/updater.tsx +++ b/src/state/farms/elasticv2/updater.tsx @@ -6,7 +6,7 @@ import { CurrencyAmount, Token, WETH } from '@kyberswap/ks-sdk-core' import { FeeAmount, Pool, Position } from '@kyberswap/ks-sdk-elastic' import { BigNumber } from 'ethers' import { Interface } from 'ethers/lib/utils' -import { useEffect, useMemo } from 'react' +import { useEffect, useMemo, useRef } from 'react' import { useLazyGetFarmV2Query } from 'services/knprotocol' import FarmV2QuoterABI from 'constants/abis/farmv2Quoter.json' @@ -123,10 +123,12 @@ export default function ElasticFarmV2Updater({ interval = true }: { interval?: b const [getElasticFarmV2FromKnProtocol, { data: knProtocolData, error: knProtocolError }] = useLazyGetFarmV2Query() + const latestKnProtocolData = useRef(knProtocolData) + const data = useMemo(() => { if (isEnableKNProtocol) { return { - farmV2S: knProtocolData?.data?.data || [], + farmV2S: knProtocolData?.data?.data || latestKnProtocolData.current?.data?.data || [], } } else return subgraphData }, [isEnableKNProtocol, knProtocolData, subgraphData]) @@ -173,7 +175,7 @@ export default function ElasticFarmV2Updater({ interval = true }: { interval?: b useEffect(() => { const getData = async () => { - if (data?.farmV2S && chainId) { + if (data?.farmV2S.length && chainId) { const tokens = [ ...new Set( data.farmV2S