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

Merged
merged 45 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 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
67c9313
remove comment
kuba80-02 Jan 8, 2025
21c7db9
Fix bug with entering position on closing popover
kuba80-02 Jan 8, 2025
84baac1
Remove useless prevent default
kuba80-02 Jan 8, 2025
dba53c5
Fix label when points per day is zero
kuba80-02 Jan 9, 2025
de51ae7
Fix
kuba80-02 Jan 9, 2025
c9f0aa7
Fix
kuba80-02 Jan 9, 2025
a711fb7
Fix desktop filcker
kuba80-02 Jan 9, 2025
4b0a699
Fixes
kuba80-02 Jan 9, 2025
0c2c01f
Fixes
kuba80-02 Jan 9, 2025
00559f1
Fix display in yourprogress
kuba80-02 Jan 9, 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
135 changes: 111 additions & 24 deletions src/components/Modals/PromotedPoolPopover/PromotedPoolPopover.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,101 @@
import { BN } from '@coral-xyz/anchor'
import useStyles from './style'
import { Popover, Typography } from '@mui/material'
import { formatNumberWithCommas, printBN } from '@utils/utils'
import { formatNumberWithCommas, printBN, removeAdditionalDecimals } from '@utils/utils'
import { LEADERBOARD_DECIMAL } from '@pages/LeaderboardPage/config'
import { useRef, useCallback, useEffect } from 'react'

export interface IPromotedPoolPopover {
open: boolean
anchorEl: HTMLElement | null
onClose: () => void
apr: number
apy: number
isActive?: boolean
apr?: BN
apy?: number
estPoints?: BN
points: BN
headerText?: string | React.ReactNode
pointsLabel?: string | React.ReactNode
showEstPointsFirst?: boolean
}

export const PromotedPoolPopover = ({
open,
onClose,
anchorEl,
isActive,
apr,
apy,
points
estPoints,
points,
headerText = 'The pool distributes points:',
pointsLabel = 'Points per 24H',
showEstPointsFirst = false
}: IPromotedPoolPopover) => {
const { classes } = useStyles()
const timeoutRef = useRef<NodeJS.Timeout>()

const handleMouseEnter = useCallback(() => {
if (timeoutRef.current) {
clearTimeout(timeoutRef.current)
}
}, [])

const isLessThanMinimal = (value: BN) => {
const minimalValue = new BN(1).mul(new BN(10).pow(new BN(LEADERBOARD_DECIMAL - 2)))
return value.lt(minimalValue)
}

const handleMouseLeave = useCallback(() => {
timeoutRef.current = setTimeout(() => {
onClose()
}, 100)
}, [onClose])

useEffect(() => {
return () => {
if (timeoutRef.current) {
clearTimeout(timeoutRef.current)
}
}
}, [])

if (!anchorEl) return null

const TotalPointsSection = (
<div className={classes.insideBox}>
<Typography
className={classes.greyText}
dangerouslySetInnerHTML={
typeof pointsLabel === 'string' ? { __html: pointsLabel } : undefined
}>
{typeof pointsLabel !== 'string' ? pointsLabel : null}
</Typography>
<Typography className={classes.whiteText}>
{formatNumberWithCommas(printBN(points, 0))}
</Typography>
</div>
)
const EstPointsSection = estPoints ? (
<div className={classes.insideBox}>
<Typography className={classes.greyText}>Points earned by this position per 24H:</Typography>
<Typography className={classes.whiteText}>
{isLessThanMinimal(estPoints) && isActive
? '<0.01'
: removeAdditionalDecimals(
formatNumberWithCommas(printBN(estPoints, LEADERBOARD_DECIMAL)),
2
)}
</Typography>
</div>
) : null

return (
<Popover
onClick={e => e.stopPropagation()}
open={open}
anchorEl={anchorEl}
className='promoted-pool-popover'
classes={{
paper: classes.paper,
root: classes.popover
Expand All @@ -40,7 +108,8 @@ export const PromotedPoolPopover = ({
disableRestoreFocus
slotProps={{
paper: {
onMouseLeave: onClose
onMouseEnter: handleMouseEnter,
onMouseLeave: handleMouseLeave
}
}}
transformOrigin={{
Expand All @@ -50,25 +119,43 @@ export const PromotedPoolPopover = ({
marginThreshold={16}>
<div className={classes.root}>
<div className={classes.container}>
<Typography className={classes.greyText}>This pool distributes points: </Typography>
<div className={classes.insideBox}>
<Typography className={classes.greyText}>Points per 24H</Typography>
<Typography className={classes.whiteText}>
{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>
{/* Content remains the same */}
<Typography
className={classes.greyText}
dangerouslySetInnerHTML={
typeof headerText === 'string' ? { __html: headerText } : undefined
}>
{typeof headerText !== 'string' ? headerText : null}
</Typography>

{showEstPointsFirst ? (
<>
{EstPointsSection}
{TotalPointsSection}
</>
) : (
<>
{TotalPointsSection}
{EstPointsSection}
</>
)}

{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>
</Typography>
</div>
</>
) : null}
</div>
</div>
</Popover>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Modals/PromotedPoolPopover/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const useStyles = makeStyles()(() => {
},
root: {
background: colors.invariant.component,
width: 217,
width: 'fit-content',
height: 'fit-content',
borderRadius: 14,
paddingTop: 16,
Expand Down
54 changes: 51 additions & 3 deletions src/components/PositionsList/PositionItem/PositionItem.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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'
import { PositionItemDesktop } from './variants/PositionItemDesktop'

const meta = {
title: 'Components/PositionItem',
component: PositionItem
} satisfies Meta<typeof PositionItem>
component: PositionItemDesktop
} satisfies Meta<typeof PositionItemDesktop>

export default meta
type Story = StoryObj<typeof meta>
Expand All @@ -23,7 +25,53 @@ export const Primary: Story = {
max: 149.6,
fee: 0.05,
valueX: 10000.45,
position: {
bump: 0,
feeGrowthInsideX: new BN(0),
feeGrowthInsideY: new BN(0),
id: 0,
lastSlot: new BN(0),
lowerTickIndex: new BN(0),
owner: Keypair.generate().publicKey,
pool: Keypair.generate().publicKey,
secondsPerLiquidityInside: new BN(0),
tokensOwedX: new BN(0),
tokensOwedY: new BN(0),
upperTickIndex: new BN(0),
liquidity: new BN(0)
},
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
Loading
Loading