Skip to content

Commit

Permalink
Merge branch 'main' into inbox-watchlist
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhoaidanh authored Sep 26, 2023
2 parents ed6a628 + 8176628 commit e6646ef
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 50 deletions.
10 changes: 3 additions & 7 deletions src/pages/Farm/ElasticFarmCombination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,7 @@ export const ElasticFarmCombination: FC = () => {

{type === FARM_TAB.ENDED && tab !== VERSION.CLASSIC && (
<Text fontStyle="italic" fontSize={12} marginBottom="1rem" color={theme.subText}>
<Trans>
Your rewards may be automatically harvested a few days after the farm ends. Please check the{' '}
<StyledInternalLink to={`${APP_PATHS.FARMS}/${networkInfo.route}?type=vesting`}>Vesting</StyledInternalLink>{' '}
tab to see your rewards
</Trans>
<Trans>Your rewards may be automatically harvested a few days after the farm ends.</Trans>
</Text>
)}

Expand All @@ -117,11 +113,11 @@ export const ElasticFarmCombination: FC = () => {
<Text as="span" color={theme.warning}>
multiple phases
</Text>
. Once the current phase ends, you can harvest your rewards from the farm in the{' '}
If you haven’t harvested your rewards for ended farms, you still can access them via the{' '}
<StyledInternalLink to={`${APP_PATHS.FARMS}/${networkInfo.route}?type=${FARM_TAB.ENDED}`}>
Ended
</StyledInternalLink>{' '}
tab. To continue earning rewards in the new phase, you must restake your NFT position into the active farm
tab. To continue earning rewards in the new phase, you must retake your NFT position into the active farm
</Trans>
</Text>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export default function NewRangesNotiModal({ updatedFarms }: { updatedFarms: Ela
{hasIdleRange && hasNewRange ? (
<Trans>
One or more of the Elastic static farm ranges you were participating in have become idle and have new
farming ranges. You are still earning farming rewards from this idle farm range. However, to continue
earning more rewards, please stake your liquidity into the other ranges instead
farming ranges. You are still earning farming rewards from this idle farm range. However, to keep earning
fees, please stake your liquidity that is in-range position
</Trans>
) : hasNewRange ? (
<Trans>
Expand All @@ -92,8 +92,8 @@ export default function NewRangesNotiModal({ updatedFarms }: { updatedFarms: Ela
) : (
<Trans>
One or more of the Elastic static farm ranges you were participating in have become idle. You are still
earning farming rewards from this idle farm range. However, to continue earning more rewards, please stake
your liquidity into the other active ranges instead
earning farming rewards from this idle farm range. However, to keep earning fees, please stake your
liquidity that is in-range position{' '}
</Trans>
)}
</Text>
Expand Down
19 changes: 9 additions & 10 deletions src/state/farms/elastic/updaters/v1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,26 +151,24 @@ const FarmUpdaterV1: React.FC<CommonProps> = ({ interval }) => {
})

useEffect(() => {
if (!elasticFarm.farms && !elasticFarm.loading) {
dispatch(setLoading({ chainId, loading: true }))
const getFarm = (withLoading = false) => {
withLoading && dispatch(setLoading({ chainId, loading: true }))
try {
getElasticFarms()
} finally {
dispatch(setLoading({ chainId, loading: false }))
withLoading && dispatch(setLoading({ chainId, loading: false }))
}
}
}, [elasticFarm, getElasticFarms, dispatch, chainId])

useEffect(() => {
getFarm(true)
const i = interval
? setInterval(() => {
getElasticFarms()
getFarm()
}, 20_000)
: undefined
return () => {
i && clearInterval(i)
}
}, [interval, getElasticFarms])
}, [interval, chainId, getElasticFarms, dispatch])

useEffect(() => {
if (error && chainId) {
Expand All @@ -179,8 +177,9 @@ const FarmUpdaterV1: React.FC<CommonProps> = ({ interval }) => {
}
}, [error, dispatch, chainId])

const hasFarm = elasticFarm?.farms?.length
useEffect(() => {
if (data?.farms && chainId && !elasticFarm?.farms?.length) {
if (data?.farms && chainId && !hasFarm) {
// transform farm data
const formattedData: ElasticFarm[] = data.farms.map((farm: SubgraphFarm) => {
return {
Expand Down Expand Up @@ -268,7 +267,7 @@ const FarmUpdaterV1: React.FC<CommonProps> = ({ interval }) => {
})
dispatch(setFarms({ chainId, farms: formattedData }))
}
}, [data, dispatch, chainId, elasticFarm])
}, [data, dispatch, chainId, hasFarm])

return null
}
Expand Down
47 changes: 18 additions & 29 deletions src/state/farms/elasticv2/updater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FeeAmount, Pool, Position } from '@kyberswap/ks-sdk-elastic'
import { BigNumber } from 'ethers'
import { Interface } from 'ethers/lib/utils'
import { useEffect, useMemo, useRef } from 'react'
import { useLazyGetFarmV2Query } from 'services/knprotocol'
import knProtocolApi, { useLazyGetFarmV2Query } from 'services/knprotocol'

import FarmV2QuoterABI from 'constants/abis/farmv2Quoter.json'
import NFTPositionManagerABI from 'constants/abis/v2/ProAmmNFTPositionManager.json'
Expand All @@ -17,11 +17,11 @@ import { NativeCurrencies } from 'constants/tokens'
import { useActiveWeb3React } from 'hooks'
import { useContract, useMulticallContract } from 'hooks/useContract'
import { useKyberSwapConfig } from 'state/application/hooks'
import { useAppDispatch, useAppSelector } from 'state/hooks'
import { useAppDispatch } from 'state/hooks'
import { useTokenPricesWithLoading } from 'state/tokenPrices/hooks'
import { isAddressString } from 'utils'

import { defaultChainData, setFarms, setLoading, setUserFarmInfo } from '.'
import { setFarms, setLoading, setUserFarmInfo } from '.'
import { ElasticFarmV2, SubgraphFarmV2, SubgraphToken, UserFarmV2Info } from './types'

const positionManagerInterface = new Interface(NFTPositionManagerABI.abi)
Expand Down Expand Up @@ -106,7 +106,6 @@ const queryFarms = gql`
export default function ElasticFarmV2Updater({ interval = true }: { interval?: boolean }) {
const dispatch = useAppDispatch()
const { networkInfo, isEVM, chainId, account } = useActiveWeb3React()
const elasticFarm = useAppSelector(state => state.elasticFarmV2[chainId] || defaultChainData)
const { elasticClient, isEnableKNProtocol } = useKyberSwapConfig()

const multicallContract = useMulticallContract()
Expand All @@ -122,12 +121,10 @@ 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 || latestKnProtocolData.current?.data?.data || [],
farmV2S: knProtocolData?.data?.data || [],
}
} else return subgraphData
}, [isEnableKNProtocol, knProtocolData, subgraphData])
Expand All @@ -136,38 +133,30 @@ export default function ElasticFarmV2Updater({ interval = true }: { interval?: b
if (isEnableKNProtocol) return knProtocolError
return subgraphError
}, [isEnableKNProtocol, subgraphError, knProtocolError])
const isLoadingElasticFarm = useRef(elasticFarm.loading)
isLoadingElasticFarm.current = elasticFarm.loading

useEffect(() => {
if (isEVM && !elasticFarm?.farms && !isLoadingElasticFarm.current) {
dispatch(setLoading({ chainId, loading: true }))
if (isEnableKNProtocol) {
const getFarm = (chainId: number, withLoading = false) => {
if (withLoading) dispatch(setLoading({ chainId, loading: true }))
if (isEnableKNProtocol)
getElasticFarmV2FromKnProtocol(chainId).finally(() => {
dispatch(setLoading({ chainId, loading: false }))
})
} else
else {
getElasticFarmV2().finally(() => {
dispatch(setLoading({ chainId, loading: false }))
})
}
}
}, [
isEVM,
chainId,
dispatch,
getElasticFarmV2,
elasticFarm?.farms,
getElasticFarmV2FromKnProtocol,
isEnableKNProtocol,
])
Promise.resolve(dispatch(knProtocolApi.util.resetApiState())).then(() => {
dispatch(setFarms({ chainId, farms: [] }))
getFarm(chainId, true)
})
// for chain which is not enable kn protocol
setTimeout(() => {
dispatch(setLoading({ chainId, loading: false }))
}, 3000)

useEffect(() => {
const i = interval
? setInterval(() => {
if (isEnableKNProtocol) getElasticFarmV2FromKnProtocol(chainId)
else getElasticFarmV2()
}, 10_000)
: undefined
const i = interval ? setInterval(() => getFarm(chainId, false), 10_000) : undefined
return () => {
i && clearInterval(i)
}
Expand Down

0 comments on commit e6646ef

Please sign in to comment.