Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement your position rewarded idication #347

Open
wants to merge 35 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
61cb4ec
Implement your position rewarded idication
kuba80-02 Jan 4, 2025
501e531
Fix
kuba80-02 Jan 4, 2025
890a31d
Fix
kuba80-02 Jan 4, 2025
d2f851b
Recalculate estimation on hover
kuba80-02 Jan 5, 2025
6831a06
Fix est point calculation
kuba80-02 Jan 5, 2025
2906308
Remove useless print APR
kuba80-02 Jan 5, 2025
1bf8933
Fix unused
kuba80-02 Jan 5, 2025
0ad1133
Added comas formating
kuba80-02 Jan 5, 2025
c96b9c6
Bug fixes and add inactive indicator
kuba80-02 Jan 5, 2025
2f39662
Fix
kuba80-02 Jan 5, 2025
d8faf56
Test
kuba80-02 Jan 5, 2025
2edb100
Test
kuba80-02 Jan 5, 2025
fd9572c
Fix
kuba80-02 Jan 5, 2025
c0ad651
Fix RWD
kuba80-02 Jan 5, 2025
3330b18
Fix popover position
kuba80-02 Jan 5, 2025
964d1e2
Change tooltip
kuba80-02 Jan 5, 2025
0f33179
Update tooltip text
kuba80-02 Jan 5, 2025
23a995a
Update texts
kuba80-02 Jan 5, 2025
45a22b9
Update text
kuba80-02 Jan 5, 2025
09b56b2
Merge branch 'dev' of https://github.com/invariant-labs/webapp-eclips…
kuba80-02 Jan 6, 2025
7604159
Fix bug with entering position
kuba80-02 Jan 6, 2025
8e926cc
Merge branch 'dev' of https://github.com/invariant-labs/webapp-eclips…
kuba80-02 Jan 7, 2025
525ad4d
Redesign mobile card
kuba80-02 Jan 7, 2025
28b23ac
Fix
kuba80-02 Jan 7, 2025
8231556
Fix
kuba80-02 Jan 7, 2025
68d3228
Merge branch 'dev' of https://github.com/invariant-labs/webapp-eclips…
kuba80-02 Jan 8, 2025
9ae6c6a
Fixed tooltip
kuba80-02 Jan 8, 2025
eed7569
Fix
kuba80-02 Jan 8, 2025
4aca897
Fix
kuba80-02 Jan 8, 2025
0710893
Add hover
kuba80-02 Jan 8, 2025
fc29fca
Fix
kuba80-02 Jan 8, 2025
d071e9f
Click outside
kuba80-02 Jan 8, 2025
c408715
add class
kuba80-02 Jan 8, 2025
2b4ca7a
Add tooltip inactive 2 reasons
kuba80-02 Jan 8, 2025
7a90769
Add dev info
kuba80-02 Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions src/components/Modals/PromotedPoolPopover/PromotedPoolPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { BN } from '@coral-xyz/anchor'
import useStyles from './style'
import { Popover, Typography } from '@mui/material'
import { formatNumberWithCommas, printBN } from '@utils/utils'
import { LEADERBOARD_DECIMAL } from '@pages/LeaderboardPage/config'

export interface IPromotedPoolPopover {
open: boolean
anchorEl: HTMLElement | null
onClose: () => void
apr: number
apy: number
apr?: BN
apy?: number
estPoints?: BN
points: BN
}

Expand All @@ -18,6 +20,7 @@ export const PromotedPoolPopover = ({
anchorEl,
apr,
apy,
estPoints,
points
}: IPromotedPoolPopover) => {
const { classes } = useStyles()
Expand Down Expand Up @@ -57,18 +60,30 @@ export const PromotedPoolPopover = ({
{formatNumberWithCommas(printBN(points, 0))}
</Typography>
</div>
<div className={classes.insideBox}>
<Typography className={classes.greyText}>
APY
<span className={classes.apr}>APR</span>
</Typography>{' '}
<Typography className={classes.whiteText}>
{`${apy > 1000 ? '>1000%' : apy === 0 ? '' : apy.toFixed(2) + '%'}`}
<span className={classes.apr}>
{`${apr > 1000 ? '>1000%' : apr === 0 ? '-' : apr.toFixed(2) + '%'}`}
</span>
</Typography>
</div>
{estPoints ? (
<div className={classes.insideBox}>
<Typography className={classes.greyText}>Your Points</Typography>
<Typography className={classes.whiteText}>{printBN(estPoints, 0)}</Typography>
</div>
) : null}

{apr && apy ? (
<>
<div className={classes.insideBox}>
<Typography className={classes.greyText}>
APY
<span className={classes.apr}>APR</span>
</Typography>{' '}
<Typography className={classes.whiteText}>
{`${apy > 1000 ? '>1000%' : apy === 0 ? '' : apy.toFixed(2) + '%'}`}
<span className={classes.apr}>
{`${apr > 1000 ? '>1000%' : apr === 0 ? '-' : apr.toFixed(2) + '%'}`}
</span>
{printBN(apr, LEADERBOARD_DECIMAL)}
</Typography>
</div>
</>
) : null}
</div>
</div>
</Popover>
Expand Down
34 changes: 34 additions & 0 deletions src/components/PositionsList/PositionItem/PositionItem.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { NetworkType } from '@store/consts/static'
import { PositionItem } from './PositionItem'

import type { Meta, StoryObj } from '@storybook/react'
import { Keypair } from '@solana/web3.js'
import { BN } from '@coral-xyz/anchor'

const meta = {
title: 'Components/PositionItem',
Expand All @@ -23,7 +25,39 @@ export const Primary: Story = {
max: 149.6,
fee: 0.05,
valueX: 10000.45,

valueY: 2137.4,
liquidity: new BN(0),
poolAddress: Keypair.generate().publicKey,

poolData: {
address: Keypair.generate().publicKey,
bump: 0,
currentTickIndex: 0,
fee: new BN(0),
feeGrowthGlobalX: new BN(0),
feeProtocolTokenX: new BN(0),
feeProtocolTokenY: new BN(0),
feeReceiver: Keypair.generate().publicKey,
lastTimestamp: new BN(0),
oracleAddress: Keypair.generate().publicKey,
oracleInitialized: true,
liquidity: new BN(0),
poolIndex: 0,
positionIterator: new BN(0),
protocolFee: new BN(0),
secondsPerLiquidityGlobal: new BN(0),
sqrtPrice: new BN(0),
startTimestamp: new BN(0),
tickmap: Keypair.generate().publicKey,
tickSpacing: 0,
tokenX: Keypair.generate().publicKey,
tokenY: Keypair.generate().publicKey,
tokenXReserve: Keypair.generate().publicKey,
tokenYReserve: Keypair.generate().publicKey,
feeGrowthGlobalY: new BN(0)
},

id: '0',
address: '',
tokenXLiq: 5000,
Expand Down
73 changes: 69 additions & 4 deletions src/components/PositionsList/PositionItem/PositionItem.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
import { Grid, Hidden, Tooltip, Typography, useMediaQuery } from '@mui/material'
import { Box, Grid, Hidden, Tooltip, Typography, useMediaQuery } from '@mui/material'
import SwapList from '@static/svg/swap-list.svg'
import { theme } from '@static/theme'
import { formatNumber } from '@utils/utils'
import classNames from 'classnames'
import { useMemo, useState } from 'react'
import { useMemo, useRef, useState } from 'react'
import { useStyles } from './style'
import { TooltipHover } from '@components/TooltipHover/TooltipHover'
import { initialXtoY, tickerToAddress } from '@utils/utils'
import { NetworkType } from '@store/consts/static'
import lockIcon from '@static/svg/lock.svg'
import unlockIcon from '@static/svg/unlock.svg'
import icons from '@static/icons'
import { PublicKey } from '@solana/web3.js'
import { useSelector } from 'react-redux'
import { leaderboardSelectors } from '@store/selectors/leaderboard'
import PromotedPoolPopover from '@components/Modals/PromotedPoolPopover/PromotedPoolPopover'
import { BN } from '@coral-xyz/anchor'
import { estimatePointsForLiquidity } from '@invariant-labs/points-sdk'
import { PoolStructure } from '@invariant-labs/sdk-eclipse/lib/market'
import { PoolWithAddressAndIndex } from '@store/selectors/positions'

export interface IPositionItem {
tokenXName: string
tokenYName: string
tokenXIcon: string
tokenYIcon: string
tokenXLiq: number
poolAddress: PublicKey
tokenYLiq: number
fee: number
min: number
Expand All @@ -30,18 +40,23 @@ export interface IPositionItem {
network: NetworkType
isFullRange: boolean
isLocked: boolean
poolData: PoolWithAddressAndIndex
liquidity: BN
}

export const PositionItem: React.FC<IPositionItem> = ({
tokenXName,
tokenYName,
tokenXIcon,
poolAddress,
tokenYIcon,
fee,
min,
max,
valueX,
valueY,
liquidity,
poolData,
isActive = false,
currentPrice,
tokenXLiq,
Expand All @@ -51,6 +66,18 @@ export const PositionItem: React.FC<IPositionItem> = ({
isLocked
}) => {
const { classes } = useStyles()
const airdropIconRef = useRef<any>(null)

const { promotedPools } = useSelector(leaderboardSelectors.config)
const [isPromotedPoolPopoverOpen, setIsPromotedPoolPopoverOpen] = useState(false)

const { isPromoted, pointsPerSecond } = useMemo(() => {
if (!poolAddress) return { isPromoted: false, pointsPerSecond: '00' }
const promotedPool = promotedPools.find(pool => pool.address === poolAddress.toString())

if (!promotedPool) return { isPromoted: false, pointsPerSecond: '00' }
return { isPromoted: true, pointsPerSecond: promotedPool.pointsPerSecond }
}, [promotedPools, poolAddress])

const isXs = useMediaQuery(theme.breakpoints.down('xs'))
const isDesktop = useMediaQuery(theme.breakpoints.up('lg'))
Expand Down Expand Up @@ -134,6 +161,15 @@ export const PositionItem: React.FC<IPositionItem> = ({
),
[valueX, valueY, tokenXName, classes, isXs, isDesktop, tokenYName, xToY]
)
const estimation = useMemo(() => {
const estOfPoints = estimatePointsForLiquidity(
new BN(liquidity, 'hex'),
poolData as PoolStructure,
new BN(pointsPerSecond, 'hex'),
false
) as BN
return estOfPoints
}, [liquidity, poolData, pointsPerSecond])

return (
<Grid
Expand Down Expand Up @@ -172,11 +208,40 @@ export const PositionItem: React.FC<IPositionItem> = ({
{xToY ? tokenXName : tokenYName} - {xToY ? tokenYName : tokenXName}
</Typography>
</Grid>

<Hidden mdUp>{feeFragment}</Hidden>
</Grid>

<Grid container item className={classes.mdInfo} direction='row'>
<Box sx={{ display: 'flex', alignItems: 'center' }}>
{isPromoted && (
<>
<div
ref={airdropIconRef}
className={classes.actionButton}
onPointerLeave={() => {
setIsPromotedPoolPopoverOpen(false)
}}
onPointerEnter={() => {
setIsPromotedPoolPopoverOpen(true)
}}>
<img
src={icons.airdropRainbow}
alt={'Airdrop'}
style={{ height: '32px', marginRight: '16px' }}
/>
</div>
<PromotedPoolPopover
anchorEl={airdropIconRef.current}
open={isPromotedPoolPopoverOpen}
onClose={() => {
setIsPromotedPoolPopoverOpen(false)
}}
estPoints={estimation}
points={new BN(pointsPerSecond, 'hex').muln(24).muln(60).muln(60)}
/>
</>
)}
<Hidden mdUp>{feeFragment}</Hidden>
</Box>
<Hidden mdDown>{feeFragment}</Hidden>
<Grid
container
Expand Down
20 changes: 20 additions & 0 deletions src/components/PositionsList/PositionItem/style.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ export const useStyles = makeStyles()((theme: Theme) => ({
width: 28
}
},
actionButton: {
background: 'none',
padding: 0,
margin: 0,
border: 'none',
display: 'inline-flex',
position: 'relative',
color: colors.invariant.black,
textTransform: 'none',

transition: 'filter 0.2s linear',

'&:hover': {
filter: 'brightness(1.2)',
cursor: 'pointer',
'@media (hover: none)': {
filter: 'none'
}
}
},
arrows: {
width: 36,
marginLeft: 4,
Expand Down
Loading
Loading