Skip to content

add prices values #992

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

Draft
wants to merge 1 commit into
base: new-position-details
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
66 changes: 61 additions & 5 deletions src/components/NewPosition/RangeSelector/RangeSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useRef } from 'react'
import React, { useState, useEffect, useRef, useMemo } from 'react'
import PriceRangePlot, { TickPlotPositionData } from '@common/PriceRangePlot/PriceRangePlot'
import RangeInput from '@components/Inputs/RangeInput/RangeInput'
import { PlotTickData } from '@store/reducers/positions'
Expand All @@ -21,6 +21,7 @@ import { getMaxTick, getMinTick } from '@invariant-labs/sdk/lib/utils'
import { Button, Grid, Typography } from '@mui/material'
import icons from '@static/icons'
import { TooltipGradient } from '@common/TooltipHover/TooltipGradient'
import { colors } from '@static/theme'

export interface IRangeSelector {
updatePath: (concIndex: number) => void
Expand Down Expand Up @@ -423,16 +424,71 @@ export const RangeSelector: React.FC<IRangeSelector> = ({
autoZoomHandler(leftRange, rightRange, true)
}, [tokenASymbol, tokenBSymbol])

const buyPercentageDifference = useMemo(() => {
if (
tokenAPriceData?.buyPrice === undefined ||
globalPrice === undefined ||
tokenBPriceData?.price === undefined
) {
return
}
return ((tokenAPriceData.buyPrice / tokenBPriceData?.price - globalPrice) / globalPrice) * 100
}, [tokenAPriceData?.buyPrice, globalPrice, tokenBPriceData?.price])

const sellPercentageDifference = useMemo(() => {
if (
tokenAPriceData?.sellPrice === undefined ||
globalPrice === undefined ||
tokenBPriceData?.price === undefined
) {
return
}
return ((tokenAPriceData.sellPrice / tokenBPriceData?.price - globalPrice) / globalPrice) * 100
}, [tokenAPriceData?.sellPrice, globalPrice, tokenBPriceData?.price])

return (
<Grid container className={classes.wrapper}>
<Grid className={classes.topInnerWrapper}>
<Grid className={classes.headerContainer} container>
<Grid>
<Typography className={classes.header}>Price range</Typography>
{poolIndex !== null && (
<Typography className={classes.currentPrice}>
{formatNumberWithoutSuffix(midPrice.x)} {tokenBSymbol} per {tokenASymbol}
</Typography>
<>
<div className={classes.priceBlock}>
<Typography className={classes.currentPrice}>
{formatNumberWithoutSuffix(midPrice.x)} {tokenASymbol}/{tokenBSymbol}
</Typography>
</div>
<div className={classes.priceBlock}>
{globalPrice && (
<Typography
className={classes.currentPrice}
style={{ color: colors.invariant.blue }}>
{formatNumberWithoutSuffix(globalPrice)} {tokenASymbol}/{tokenBSymbol}
</Typography>
)}
</div>
<div className={classes.priceBlock}>
{buyPercentageDifference && (
<Typography
className={classes.currentPrice}
style={{ color: colors.invariant.plotGreen }}>
{buyPercentageDifference < 0 ? '-' : '+'}
{formatNumberWithoutSuffix(Math.abs(buyPercentageDifference))}%
</Typography>
)}
</div>
<div className={classes.priceBlock}>
{sellPercentageDifference && (
<Typography
className={classes.currentPrice}
style={{ color: colors.invariant.plotRed }}>
{sellPercentageDifference < 0 ? '-' : '+'}{' '}
{formatNumberWithoutSuffix(Math.abs(sellPercentageDifference))}%
</Typography>
)}
</div>
</>
)}
</Grid>
<Grid className={classes.activeLiquidityContainer} container>
Expand Down Expand Up @@ -468,7 +524,7 @@ export const RangeSelector: React.FC<IRangeSelector> = ({
Active liquidity <span className={classes.activeLiquidityIcon}>i</span>
</Typography>
</TooltipGradient>
<Grid container flexDirection='column'>
<Grid container flexDirection='column' mt={'3px'}>
<Typography className={classes.currentPrice}>Current price</Typography>
<Typography className={classes.globalPrice}>Global price</Typography>
<Typography className={classes.lastGlobalBuyPrice}>Last global buy price</Typography>
Expand Down
5 changes: 5 additions & 0 deletions src/components/NewPosition/RangeSelector/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ const useStyles = makeStyles()(theme => {
minWidth: 82,
textAlign: 'center'
}
},
priceBlock: {
height: 17,
margin: 0,
textAlign: 'left'
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import {
calcPriceByTickIndex,
calcTicksAmountInRange,
calculateConcentration,
formatNumberWithoutSuffix,
formatNumberWithSuffix,
numberToString,
spacingMultiplicityGte,
TokenPriceData,
truncateString
} from '@utils/utils'
import { PlotTickData } from '@store/reducers/positions'
import React, { useEffect, useState } from 'react'
import React, { useEffect, useMemo, useState } from 'react'

import useStyles from './style'
import { getMinTick } from '@invariant-labs/sdk/lib/utils'
Expand Down Expand Up @@ -159,10 +160,72 @@ const SinglePositionPlot: React.FC<ISinglePositionPlot> = ({
const maxPercentage = (max / currentPrice - 1) * 100
const concentration = calculateConcentration(leftRange.index, rightRange.index)

const buyPercentageDifference = useMemo(() => {
if (
tokenAPriceData?.buyPrice === undefined ||
globalPrice === undefined ||
tokenBPriceData?.price === undefined
) {
return
}
return ((tokenAPriceData.buyPrice / tokenBPriceData?.price - globalPrice) / globalPrice) * 100
}, [tokenAPriceData?.buyPrice, globalPrice, tokenBPriceData?.price])

const sellPercentageDifference = useMemo(() => {
if (
tokenAPriceData?.sellPrice === undefined ||
globalPrice === undefined ||
tokenBPriceData?.price === undefined
) {
return
}
return ((tokenAPriceData.sellPrice / tokenBPriceData?.price - globalPrice) / globalPrice) * 100
}, [tokenAPriceData?.sellPrice, globalPrice, tokenBPriceData?.price])

return (
<Box className={classes.container}>
<Box className={classes.headerContainer}>
<Typography className={classes.header}>Price range</Typography>
<Grid>
<Typography className={classes.header}>Price range</Typography>
{
<>
<div className={classes.priceBlock}>
<Typography className={classes.currentPrice}>
{formatNumberWithoutSuffix(midPrice.x)} {tokenX.name}/{tokenY.name}
</Typography>
</div>
<div className={classes.priceBlock}>
{globalPrice && (
<Typography
className={classes.currentPrice}
style={{ color: colors.invariant.blue }}>
{formatNumberWithoutSuffix(globalPrice)} {tokenX.name}/{tokenY.name}
</Typography>
)}
</div>
<div className={classes.priceBlock}>
{buyPercentageDifference && (
<Typography
className={classes.currentPrice}
style={{ color: colors.invariant.plotGreen }}>
{buyPercentageDifference < 0 ? '-' : '+'}
{formatNumberWithoutSuffix(Math.abs(buyPercentageDifference))}%
</Typography>
)}
</div>
<div className={classes.priceBlock}>
{sellPercentageDifference && (
<Typography
className={classes.currentPrice}
style={{ color: colors.invariant.plotRed }}>
{sellPercentageDifference < 0 ? '-' : '+'}{' '}
{formatNumberWithoutSuffix(Math.abs(sellPercentageDifference))}%
</Typography>
)}
</div>
</>
}
</Grid>
<Grid>
<RangeIndicator inRange={min <= currentPrice && currentPrice <= max} />
<Grid gap={'2px'} mt={1} display='flex' flexDirection='column' alignItems='flex-end'>
Expand Down
9 changes: 8 additions & 1 deletion src/components/PositionDetails/SinglePositionPlot/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export const useStyles = makeStyles()((theme: Theme) => ({
},
header: {
...typography.heading4,
color: colors.white.main
color: colors.white.main,
marginBottom: 28
},
plot: {
width: '100%',
Expand Down Expand Up @@ -114,6 +115,7 @@ export const useStyles = makeStyles()((theme: Theme) => ({
marginLeft: 16
},
currentPrice: {
display: 'inline-block',
color: colors.invariant.yellow,
...typography.caption2,
textAlign: 'right'
Expand Down Expand Up @@ -162,6 +164,11 @@ export const useStyles = makeStyles()((theme: Theme) => ({
...typography.caption2,
textAlign: 'right',
marginLeft: 4
},
priceBlock: {
height: 17,
margin: 0,
textAlign: 'left'
}
}))

Expand Down