Skip to content

Commit

Permalink
change earning 24h & 7d fee
Browse files Browse the repository at this point in the history
  • Loading branch information
tienkane committed Dec 30, 2024
1 parent 79b3b3a commit fc0104d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export const APP_PATHS = {
EARN: '/earns',
EARN_POOLS: '/earns/pools',
EARN_POSITIONS: '/earns/positions',
EARN_POSITION_DETAIL: '/earns/position/:id',
EARN_POSITION_DETAIL: '/earns/position/:chainId/:id',
} as const

export const TERM_FILES_PATH = {
Expand Down
32 changes: 4 additions & 28 deletions src/pages/Earns/PositionDetail/LeftSection.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { t } from '@lingui/macro'
import { useMemo } from 'react'
import { Flex, Text } from 'rebass'
import { usePositionEarningStatisticsQuery } from 'services/zapEarn'

import HelpIcon from 'assets/svg/help-circle.svg'
import InfoHelper from 'components/InfoHelper'
Expand All @@ -16,28 +14,6 @@ import { InfoLeftColumn, InfoRight, InfoSection, InfoSectionFirstFormat, Vertica
const LeftSection = ({ position }: { position: ParsedPosition }) => {
const theme = useTheme()

const { data: positionEarningStatistics } = usePositionEarningStatisticsQuery(
{
tokenAddress: position.tokenAddress,
tokenId: position.id,
chainId: position.chainId,
},
{ skip: !position, pollingInterval: 15_000 },
)

const earning = useMemo(() => {
if (!positionEarningStatistics || !positionEarningStatistics.length) return {}

const reversedPositionEarningStatistics = [...positionEarningStatistics].reverse()
const earning24h = reversedPositionEarningStatistics[0].earningByDay
const earning7d = reversedPositionEarningStatistics.slice(0, 7).reduce((a, b) => a + b.earningByDay, 0)

return {
earning24h,
earning7d,
}
}, [positionEarningStatistics])

return (
<InfoLeftColumn>
<InfoSectionFirstFormat>
Expand Down Expand Up @@ -96,8 +72,8 @@ const LeftSection = ({ position }: { position: ParsedPosition }) => {
1 {t`day`}
</Text>
<Text>
{earning.earning24h || earning.earning24h === 0
? formatDisplayNumber(earning.earning24h, { significantDigits: 4, style: 'currency' })
{position.earning24h || position.earning24h === 0
? formatDisplayNumber(position.earning24h, { significantDigits: 4, style: 'currency' })
: '--'}
</Text>
</Flex>
Expand All @@ -107,8 +83,8 @@ const LeftSection = ({ position }: { position: ParsedPosition }) => {
7 {t`days`}
</Text>
<Text>
{earning.earning7d || earning.earning7d === 0
? formatDisplayNumber(earning.earning7d, { significantDigits: 4, style: 'currency' })
{position.earning7d || position.earning7d === 0
? formatDisplayNumber(position.earning7d, { significantDigits: 4, style: 'currency' })
: '--'}
</Text>
</Flex>
Expand Down
8 changes: 6 additions & 2 deletions src/pages/Earns/PositionDetail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,19 @@ export interface ParsedPosition {
token1UnclaimedAmount: number
token0UnclaimedValue: number
token1UnclaimedValue: number
earning24h: number
earning7d: number
totalEarnedFee: number
}

const PositionDetail = () => {
const firstLoading = useRef(false)

const { account } = useActiveWeb3React()
const { id } = useParams()
const { id, chainId } = useParams()
const { liquidityWidget, handleOpenZapInWidget, handleOpenZapOut } = useLiquidityWidget()
const { data: userPosition, isLoading } = useUserPositionsQuery(
{ addresses: account || '', positionId: id },
{ addresses: account || '', positionId: id, chainIds: chainId },
{ skip: !account, pollingInterval: 15_000 },
)

Expand Down Expand Up @@ -91,6 +93,8 @@ const PositionDetail = () => {
token1UnclaimedAmount: position.feePending[1]?.quotes.usd.value / position.feePending[1]?.quotes.usd.price,
token0UnclaimedValue: position.feePending[0]?.quotes.usd.value,
token1UnclaimedValue: position.feePending[1]?.quotes.usd.value,
earning24h: position.earning24h,
earning7d: position.earning7d,
totalEarnedFee:
position.feePending.reduce((a, b) => a + b.quotes.usd.value, 0) +
position.feesClaimed.reduce((a, b) => a + b.quotes.usd.value, 0),
Expand Down
9 changes: 8 additions & 1 deletion src/pages/Earns/UserPositions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,14 @@ const MyPositions = () => {
return (
<PositionRow
key={positionId}
onClick={() => navigate({ pathname: APP_PATHS.EARN_POSITION_DETAIL.replace(':id', id) })}
onClick={() =>
navigate({
pathname: APP_PATHS.EARN_POSITION_DETAIL.replace(':chainId', poolChainId.toString()).replace(
':id',
id,
),
})
}
>
<PositionOverview>
<Flex alignItems={'center'} sx={{ gap: 2 }}>
Expand Down
12 changes: 1 addition & 11 deletions src/services/zapEarn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export interface EarnPosition {
totalWithdrawValue: number
yesterdayEarning: number
earning24h: number
earning7d: number
status: PositionStatus
avgConvertPrice: number
isConvertedFromToken0: boolean
Expand Down Expand Up @@ -265,16 +266,6 @@ const zapEarnServiceApi = createApi({
}
}) => response.data.positions,
}),
positionEarningStatistics: builder.query<
Array<PositionEarning>,
{ tokenAddress: string; tokenId: string; chainId: string | number }
>({
query: params => ({
url: `/v1/userPositions/positionEarningStatistic`,
params,
}),
transformResponse: (response: { data: Array<PositionEarning> }) => response.data,
}),
addFavorite: builder.mutation<void, AddRemoveFavoriteParams>({
query: body => ({
method: 'POST',
Expand All @@ -297,7 +288,6 @@ export const {
useSupportedProtocolsQuery,
usePoolsExplorerQuery,
useUserPositionsQuery,
usePositionEarningStatisticsQuery,
useAddFavoriteMutation,
useRemoveFavoriteMutation,
} = zapEarnServiceApi
Expand Down

0 comments on commit fc0104d

Please sign in to comment.