Skip to content

Commit f9952c7

Browse files
authored
feat: display uniswap reward (#2909)
* Display bonusApr in pool explorer Fix Update apr detail tooltip * Display bonusApr in zap-in widget * Display merkl reward Remove debug Check pool address Chore Update * Update share modal info * Update show reward in my positions Cont Cont * Only show on IN RANGE * Fix filter rewards by position tokenId * Chore * Cont * Chore * F x * Filter farming pool * Cont * Revert api * Cont * Cont
1 parent 1f8c2a2 commit f9952c7

File tree

25 files changed

+589
-50
lines changed

25 files changed

+589
-50
lines changed
Lines changed: 10 additions & 0 deletions
Loading

apps/kyberswap-interface/src/pages/Earns/PoolExplorer/DesktopTableRow.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { PoolQueryParams } from 'services/zapEarn'
66

77
import { ReactComponent as FarmingIcon } from 'assets/svg/kyber/kem.svg'
88
import { ReactComponent as FarmingLmIcon } from 'assets/svg/kyber/kemLm.svg'
9+
import { ReactComponent as UniBonusIcon } from 'assets/svg/kyber/uni_bonus.svg'
910
import Loader from 'components/Loader'
1011
import TokenLogo from 'components/TokenLogo'
1112
import { MouseoverTooltipDesktopOnly } from 'components/Tooltip'
@@ -23,7 +24,7 @@ export const kemFarming = (pool: ParsedEarnPool) => {
2324
const isFarmingLm = programs.includes(ProgramType.LM)
2425

2526
return isFarming ? (
26-
<AprDetailTooltip feeApr={pool.feeApr} egApr={pool.kemEGApr || 0} lmApr={pool.kemLMApr || 0}>
27+
<AprDetailTooltip feeApr={pool.feeApr || 0} egApr={pool.kemEGApr || 0} lmApr={pool.kemLMApr || 0}>
2728
{isFarmingLm ? (
2829
<FarmingLmIcon width={24} height={24} style={{ marginLeft: 4 }} />
2930
) : (
@@ -33,6 +34,16 @@ export const kemFarming = (pool: ParsedEarnPool) => {
3334
) : null
3435
}
3536

37+
export const uniReward = (pool: ParsedEarnPool) => {
38+
const hasReward = pool.bonusApr > 0
39+
40+
return hasReward ? (
41+
<AprDetailTooltip uniApr={pool.bonusApr}>
42+
<UniBonusIcon width={24} height={24} style={{ marginLeft: 4 }} />
43+
</AprDetailTooltip>
44+
) : null
45+
}
46+
3647
const DesktopTableRow = ({
3748
pool,
3849
filters,
@@ -87,7 +98,7 @@ const DesktopTableRow = ({
8798
<FeeTier>{formatDisplayNumber(pool.feeTier, { significantDigits: 4 })}%</FeeTier>
8899
</Flex>
89100
<Apr value={pool.apr}>
90-
{formatAprNumber(pool.apr)}% {kemFarming(pool)}
101+
{formatAprNumber(pool.apr)}% {kemFarming(pool)} {uniReward(pool)}
91102
</Apr>
92103
{isFarmingFiltered && (
93104
<Flex justifyContent="flex-end" onClick={e => handleOpenZapInWidget(e, true)}>

apps/kyberswap-interface/src/pages/Earns/PoolExplorer/MobileTableRow.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { PoolQueryParams } from 'services/zapEarn'
77
import CopyHelper from 'components/Copy'
88
import TokenLogo from 'components/TokenLogo'
99
import useTheme from 'hooks/useTheme'
10-
import { kemFarming } from 'pages/Earns/PoolExplorer/DesktopTableRow'
10+
import { kemFarming, uniReward } from 'pages/Earns/PoolExplorer/DesktopTableRow'
1111
import { FilterTag } from 'pages/Earns/PoolExplorer/Filter'
1212
import {
1313
Apr,
@@ -82,6 +82,7 @@ const MobileTableRow = ({
8282
<Flex alignItems="center" sx={{ gap: '2px' }}>
8383
<Apr value={pool.apr}>{formatAprNumber(pool.apr)}%</Apr>
8484
{kemFarming(pool)}
85+
{uniReward(pool)}
8586
</Flex>
8687
<Star
8788
size={16}

apps/kyberswap-interface/src/pages/Earns/PoolExplorer/TableContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const TableContent = ({
5757
dexLogo: dexInfo.logoURL,
5858
dexName: dexInfo.name,
5959
feeApr: pool.apr,
60-
apr: (pool.kemEGApr || 0) + (pool.kemLMApr || 0) + pool.apr,
60+
apr: pool.apr + (pool.kemEGApr || 0) + (pool.kemLMApr || 0) + (pool.bonusApr || 0),
6161
}
6262
})
6363
}, [poolData?.data?.pools, dexLookupMap])

apps/kyberswap-interface/src/pages/Earns/PositionDetail/RewardSection.tsx

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,25 @@ import { Flex, Text } from 'rebass'
66
import { useCycleConfigQuery } from 'services/kyberdata'
77

88
import { ReactComponent as FarmingIcon } from 'assets/svg/kyber/kem.svg'
9+
import { ReactComponent as UniBonusIcon } from 'assets/svg/kyber/uni_bonus.svg'
910
import InfoHelper from 'components/InfoHelper'
1011
import Loader from 'components/Loader'
1112
import TokenLogo from 'components/TokenLogo'
13+
import { MouseoverTooltip } from 'components/Tooltip'
1214
import { NETWORKS_INFO } from 'constants/networks'
1315
import useTheme from 'hooks/useTheme'
14-
import { NextDistribution, PositionAction, RewardDetailInfo, RewardsSection } from 'pages/Earns/PositionDetail/styles'
16+
import {
17+
NextDistribution,
18+
PositionAction,
19+
RewardDetailInfo,
20+
RewardLink,
21+
RewardsSection,
22+
} from 'pages/Earns/PositionDetail/styles'
1523
import { HorizontalDivider } from 'pages/Earns/UserPositions/styles'
1624
import PositionSkeleton from 'pages/Earns/components/PositionSkeleton'
1725
import RewardSyncing from 'pages/Earns/components/RewardSyncing'
1826
import useKemRewards from 'pages/Earns/hooks/useKemRewards'
27+
import useMerklRewards from 'pages/Earns/hooks/useMerklRewards'
1928
import { ParsedPosition, PositionStatus, TokenRewardInfo } from 'pages/Earns/types'
2029
import { checkEarlyPosition } from 'pages/Earns/utils/position'
2130
import { formatDisplayNumber } from 'utils/numbers'
@@ -50,6 +59,11 @@ const RewardSection = ({
5059
onOpenClaim: onOpenClaimRewards,
5160
claiming: rewardsClaiming,
5261
} = useKemRewards(refetchPositions)
62+
63+
const { rewardsByPosition } = useMerklRewards({ positions: position ? [position] : undefined })
64+
const merklRewards = position ? rewardsByPosition[position.id]?.rewards || [] : []
65+
const merklRewardsTotalUsd = position ? rewardsByPosition[position.id]?.totalUsdValue || 0 : 0
66+
5367
const rewardInfoThisPosition = !position ? undefined : rewardInfo?.nfts.find(item => item.nftId === position.tokenId)
5468

5569
const chain = position?.chain.id ? NETWORKS_INFO[position.chain.id as ChainId]?.route || '' : ''
@@ -83,6 +97,11 @@ const RewardSection = ({
8397
<Flex alignItems={'center'} justifyContent={'space-between'} sx={{ gap: '20px' }}>
8498
<Flex alignItems={'center'} sx={{ gap: 1 }}>
8599
<FarmingIcon width={20} height={20} />
100+
{merklRewards.length > 0 && (
101+
<MouseoverTooltip text={merklRewardTooltip(merklRewards, theme.text)} placement="top" width="160px">
102+
<UniBonusIcon width={20} height={20} />
103+
</MouseoverTooltip>
104+
)}
86105
<Text fontSize={14} color={theme.subText} lineHeight={'20PX'}>
87106
{t`Total Rewards`}
88107
</Text>
@@ -96,7 +115,7 @@ const RewardSection = ({
96115
) : (
97116
<Flex alignItems={'center'} sx={{ gap: 1 }}>
98117
<Text fontSize={20}>
99-
{formatDisplayNumber(rewardInfoThisPosition?.totalUsdValue || 0, {
118+
{formatDisplayNumber((rewardInfoThisPosition?.totalUsdValue || 0) + merklRewardsTotalUsd, {
100119
significantDigits: 4,
101120
style: 'currency',
102121
})}
@@ -105,6 +124,7 @@ const RewardSection = ({
105124
text={totalRewardTooltip({
106125
lmTokens: rewardInfoThisPosition?.lmTokens || [],
107126
egTokens: rewardInfoThisPosition?.egTokens || [],
127+
merklRewards,
108128
textColor: theme.text,
109129
})}
110130
placement="top"
@@ -315,17 +335,35 @@ export const inProgressRewardTooltip = ({
315335
)
316336
}
317337

338+
const merklRewardTooltip = (merklRewards: Array<TokenRewardInfo>, textColor: string) => (
339+
<Flex flexDirection={'column'} sx={{ gap: 1 }}>
340+
<Text lineHeight={'16px'} fontSize={12}>
341+
{t`Uniswap Bonus:`}
342+
</Text>
343+
{merklRewards.map(token => (
344+
<Flex alignItems={'center'} sx={{ gap: 1 }} flexWrap={'wrap'} key={token.address}>
345+
<TokenLogo src={token.logo} size={16} />
346+
<RewardLink href="https://app.uniswap.org/positions" target="_blank">
347+
<Text color={textColor}>{formatDisplayNumber(token.totalAmount, { significantDigits: 4 })}</Text>
348+
<Text color={textColor}>{token.symbol}</Text>
349+
</RewardLink>
350+
</Flex>
351+
))}
352+
</Flex>
353+
)
354+
318355
export const totalRewardTooltip = ({
319356
lmTokens,
320357
egTokens,
358+
merklRewards = [],
321359
textColor,
322360
}: {
323361
lmTokens: Array<TokenRewardInfo>
324362
egTokens: Array<TokenRewardInfo>
363+
merklRewards?: Array<TokenRewardInfo>
325364
textColor: string
326365
}) => (
327366
<Flex flexDirection={'column'} sx={{ gap: 1 }}>
328-
<HorizontalDivider />
329367
<Text lineHeight={'16px'} fontSize={12}>
330368
{t`LM Reward:`}
331369
{!lmTokens.length ? ' 0' : ''}
@@ -337,6 +375,8 @@ export const totalRewardTooltip = ({
337375
<Text color={textColor}>{token.symbol}</Text>
338376
</Flex>
339377
))}
378+
379+
<HorizontalDivider />
340380
<Text lineHeight={'16px'} fontSize={12}>
341381
{t`EG Sharing Reward:`}
342382
{!egTokens.length ? ' 0' : ''}
@@ -348,6 +388,13 @@ export const totalRewardTooltip = ({
348388
<Text color={textColor}>{token.symbol}</Text>
349389
</Flex>
350390
))}
391+
392+
{merklRewards.length > 0 && (
393+
<>
394+
<HorizontalDivider />
395+
{merklRewardTooltip(merklRewards, textColor)}
396+
</>
397+
)}
351398
</Flex>
352399
)
353400

apps/kyberswap-interface/src/pages/Earns/PositionDetail/index.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { ReactComponent as IconEarnNotFound } from 'assets/svg/earn/ic_earn_not_
1212
import { ReactComponent as IconUserEarnPosition } from 'assets/svg/earn/ic_user_earn_position.svg'
1313
import { ReactComponent as FarmingIcon } from 'assets/svg/kyber/kem.svg'
1414
import { ReactComponent as FarmingLmIcon } from 'assets/svg/kyber/kemLm.svg'
15+
import { ReactComponent as UniBonusIcon } from 'assets/svg/kyber/uni_bonus.svg'
1516
import { ReactComponent as RocketIcon } from 'assets/svg/rocket.svg'
1617
import { Loader2 } from 'components/Loader'
1718
import TokenLogo from 'components/TokenLogo'
@@ -360,7 +361,7 @@ const PositionDetail = () => {
360361
},
361362
position: {
362363
apr: {
363-
total: position.apr[aprInterval],
364+
total: position.apr[aprInterval] + position.bonusApr,
364365
eg: position.kemEGApr[aprInterval],
365366
lm: position.kemLMApr[aprInterval],
366367
},
@@ -384,9 +385,10 @@ const PositionDetail = () => {
384385
</Text>
385386
{position?.pool.isFarming && !isUnfinalized && (
386387
<AprDetailTooltip
387-
feeApr={position?.feeApr[aprInterval] || 0}
388-
egApr={position?.kemEGApr[aprInterval] || 0}
389-
lmApr={position?.kemLMApr[aprInterval] || 0}
388+
feeApr={position.feeApr[aprInterval] || 0}
389+
egApr={position.kemEGApr[aprInterval] || 0}
390+
lmApr={position.kemLMApr[aprInterval] || 0}
391+
uniApr={position.bonusApr}
390392
>
391393
<Info color={theme.subText} size={16} />
392394
</AprDetailTooltip>
@@ -407,12 +409,13 @@ const PositionDetail = () => {
407409
) : position?.pool.isFarming ? (
408410
<FarmingIcon width={20} height={20} />
409411
) : null}
412+
{position?.bonusApr ? <UniBonusIcon width={20} height={20} /> : null}
410413
<Text
411414
fontSize={20}
412415
marginRight={1}
413416
color={position?.apr && position.apr[aprInterval] > 0 ? theme.primary : theme.text}
414417
>
415-
{formatAprNumber(position?.apr[aprInterval] || 0)}%
418+
{formatAprNumber((position?.apr[aprInterval] || 0) + (position?.bonusApr || 0))}%
416419
</Text>
417420
{!initialLoading &&
418421
!isUnfinalized &&

apps/kyberswap-interface/src/pages/Earns/PositionDetail/styles.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { rgba } from 'polished'
2+
import { Link } from 'rebass'
23
import styled from 'styled-components'
34

45
import { ReactComponent as IconArrowLeftSvg } from 'assets/svg/ic_left_arrow.svg'
@@ -286,3 +287,9 @@ export const ShareButtonWrapper = styled.div`
286287
filter: brightness(1.05);
287288
}
288289
`
290+
291+
export const RewardLink = styled(Link)`
292+
display: flex;
293+
gap: 4px;
294+
border-bottom: 1px dashed ${({ theme }) => theme.text};
295+
`

0 commit comments

Comments
 (0)