Skip to content

Commit

Permalink
fix: farms is reset
Browse files Browse the repository at this point in the history
  • Loading branch information
viet-nv committed Sep 20, 2023
1 parent c667c4a commit abdae69
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/pages/Pools/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -370,6 +371,7 @@ const Pools = () => {
)}
</PoolsPageWrapper>
<SwitchLocaleLink />
<ElasticFarmV2Updater interval={false} />
</>
)
}
Expand Down
6 changes: 5 additions & 1 deletion src/pages/ProAmmPools/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 0 additions & 2 deletions src/pages/ProAmmPools/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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`}
/>
<FarmUpdater interval={false} />
<ElasticFarmV2Updater interval={false} />
</PageWrapper>
)
}
8 changes: 5 additions & 3 deletions src/state/farms/elasticv2/updater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit abdae69

Please sign in to comment.