diff --git a/src/components/NewPosition/RangeSelector/RangeSelector.tsx b/src/components/NewPosition/RangeSelector/RangeSelector.tsx index 13fe35b1a..f77e26170 100644 --- a/src/components/NewPosition/RangeSelector/RangeSelector.tsx +++ b/src/components/NewPosition/RangeSelector/RangeSelector.tsx @@ -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' @@ -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 @@ -423,6 +424,28 @@ export const RangeSelector: React.FC = ({ 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 ( @@ -430,9 +453,42 @@ export const RangeSelector: React.FC = ({ Price range {poolIndex !== null && ( - - {formatNumberWithoutSuffix(midPrice.x)} {tokenBSymbol} per {tokenASymbol} - + <> +
+ + {formatNumberWithoutSuffix(midPrice.x)} {tokenASymbol}/{tokenBSymbol} + +
+
+ {globalPrice && ( + + {formatNumberWithoutSuffix(globalPrice)} {tokenASymbol}/{tokenBSymbol} + + )} +
+
+ {buyPercentageDifference && ( + + {buyPercentageDifference < 0 ? '-' : '+'} + {formatNumberWithoutSuffix(Math.abs(buyPercentageDifference))}% + + )} +
+
+ {sellPercentageDifference && ( + + {sellPercentageDifference < 0 ? '-' : '+'}{' '} + {formatNumberWithoutSuffix(Math.abs(sellPercentageDifference))}% + + )} +
+ )}
@@ -468,7 +524,7 @@ export const RangeSelector: React.FC = ({ Active liquidity i - + Current price Global price Last global buy price diff --git a/src/components/NewPosition/RangeSelector/style.ts b/src/components/NewPosition/RangeSelector/style.ts index d6aa07cb0..f1f7715a5 100644 --- a/src/components/NewPosition/RangeSelector/style.ts +++ b/src/components/NewPosition/RangeSelector/style.ts @@ -296,6 +296,11 @@ const useStyles = makeStyles()(theme => { minWidth: 82, textAlign: 'center' } + }, + priceBlock: { + height: 17, + margin: 0, + textAlign: 'left' } } }) diff --git a/src/components/PositionDetails/SinglePositionPlot/SinglePositionPlot.tsx b/src/components/PositionDetails/SinglePositionPlot/SinglePositionPlot.tsx index 482c1705a..aac14db3c 100644 --- a/src/components/PositionDetails/SinglePositionPlot/SinglePositionPlot.tsx +++ b/src/components/PositionDetails/SinglePositionPlot/SinglePositionPlot.tsx @@ -4,6 +4,7 @@ import { calcPriceByTickIndex, calcTicksAmountInRange, calculateConcentration, + formatNumberWithoutSuffix, formatNumberWithSuffix, numberToString, spacingMultiplicityGte, @@ -11,7 +12,7 @@ import { 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' @@ -159,10 +160,72 @@ const SinglePositionPlot: React.FC = ({ 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 ( - Price range + + Price range + { + <> +
+ + {formatNumberWithoutSuffix(midPrice.x)} {tokenX.name}/{tokenY.name} + +
+
+ {globalPrice && ( + + {formatNumberWithoutSuffix(globalPrice)} {tokenX.name}/{tokenY.name} + + )} +
+
+ {buyPercentageDifference && ( + + {buyPercentageDifference < 0 ? '-' : '+'} + {formatNumberWithoutSuffix(Math.abs(buyPercentageDifference))}% + + )} +
+
+ {sellPercentageDifference && ( + + {sellPercentageDifference < 0 ? '-' : '+'}{' '} + {formatNumberWithoutSuffix(Math.abs(sellPercentageDifference))}% + + )} +
+ + } +
diff --git a/src/components/PositionDetails/SinglePositionPlot/style.ts b/src/components/PositionDetails/SinglePositionPlot/style.ts index ece7c6ce1..1c63f86cf 100644 --- a/src/components/PositionDetails/SinglePositionPlot/style.ts +++ b/src/components/PositionDetails/SinglePositionPlot/style.ts @@ -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%', @@ -114,6 +115,7 @@ export const useStyles = makeStyles()((theme: Theme) => ({ marginLeft: 16 }, currentPrice: { + display: 'inline-block', color: colors.invariant.yellow, ...typography.caption2, textAlign: 'right' @@ -162,6 +164,11 @@ export const useStyles = makeStyles()((theme: Theme) => ({ ...typography.caption2, textAlign: 'right', marginLeft: 4 + }, + priceBlock: { + height: 17, + margin: 0, + textAlign: 'left' } }))