Skip to content

Commit

Permalink
feat: handle claim reward
Browse files Browse the repository at this point in the history
  • Loading branch information
viet-nv committed Nov 22, 2023
1 parent 84e58f8 commit 8be97fa
Show file tree
Hide file tree
Showing 8 changed files with 468 additions and 20 deletions.
16 changes: 11 additions & 5 deletions src/pages/OmniFarms/components/FarmList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Trans } from '@lingui/macro'
import { useMemo } from 'react'
import Skeleton from 'react-loading-skeleton'
import { Text } from 'rebass'
import { useGetFarmsQuery } from 'services/knprotocol'
import { NormalizedFarm, useGetFarmsQuery } from 'services/knprotocol'
import styled from 'styled-components'

import Pagination from 'components/Pagination'
Expand All @@ -29,14 +29,14 @@ const Row = styled(HeaderWrapper)(({ theme }) => ({
height: '70px',
}))

export default function FarmList() {
export default function FarmList({ onHarvest }: { onHarvest: (farm: NormalizedFarm) => void }) {
const theme = useTheme()
const { account } = useActiveWeb3React()
const [{ chainIds, ...filters }, setFarmFilters] = useFarmFilters()

const params = useMemo(() => ({ ...filters, account }), [filters, account])

const { data, isLoading, isFetching } = useGetFarmsQuery(params, {
const { data, isLoading } = useGetFarmsQuery(params, {
pollingInterval: 10_000,
})

Expand All @@ -58,7 +58,7 @@ export default function FarmList() {
<FarmTable>
<FarmTableHeader />

{isLoading || isFetching ? (
{isLoading ? (
[...Array(10).keys()].map(i => (
<Row key={i}>
{skeleton('80%', 'left')}
Expand All @@ -72,7 +72,13 @@ export default function FarmList() {
))
) : data?.farmPools.length ? (
data?.farmPools.map(farm => {
return <FarmTableRow farm={farm} key={`${farm.chain.name}_${farm.protocol}_${farm.id}`} />
return (
<FarmTableRow
farm={farm}
key={`${farm.chain.name}_${farm.protocol}_${farm.id}`}
onHarvest={() => onHarvest(farm)}
/>
)
})
) : (
<Text padding="3rem" display="flex" alignItems="center" justifyContent="center" color={theme.subText}>
Expand Down
8 changes: 4 additions & 4 deletions src/pages/OmniFarms/components/FarmTableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const Row = styled(HeaderWrapper)(({ theme }) => ({
borderBottom: `1px solid ${theme.border}`,
}))

const getFeeOrAMPTag = (pool: NormalizedFarm) => {
export const getFeeOrAMPTag = (pool: NormalizedFarm) => {
if (pool.protocol === ProtocolType.Classic && 'amp' in pool.pool) {
return `AMP ${pool.pool.amp}`
}
Expand All @@ -45,7 +45,7 @@ const getFeeOrAMPTag = (pool: NormalizedFarm) => {
return ''
}

export default function FarmTableRow({ farm }: { farm: NormalizedFarm }) {
export default function FarmTableRow({ farm, onHarvest }: { farm: NormalizedFarm; onHarvest: () => void }) {
const { account } = useActiveWeb3React()
const [showStake, setShowStake] = useState(false)
const [showUnStake, setShowUnStake] = useState(false)
Expand Down Expand Up @@ -80,7 +80,7 @@ export default function FarmTableRow({ farm }: { farm: NormalizedFarm }) {
item =>
item.joinedPositions?.length ||
!!item.depositedPosition ||
!!item.farmV2DepositedPositions?.some(dp => dp.pendingRewards.some(rw => rw !== '0')),
!!item.farmV2DepositedPositions?.some(dp => dp.pendingRewards?.some(rw => rw !== '0')),
)

const hasRewards = farm.rewardAmounts.some(rw => rw.toExact() !== '0')
Expand Down Expand Up @@ -212,7 +212,7 @@ export default function FarmTableRow({ farm }: { farm: NormalizedFarm }) {
colorScheme={ButtonColorScheme.APR}
disabled={!hasRewards}
onClick={() => {
// handleHarvest()
onHarvest()
mixpanel.track('ElasticFarmV2 - Harvest Clicked', mixpanelPayload)
}}
>
Expand Down
Loading

0 comments on commit 8be97fa

Please sign in to comment.