Skip to content

Commit

Permalink
Merge pull request #812 from invariant-labs/plot-refactor
Browse files Browse the repository at this point in the history
fix positioning of plot markers and add last global buy and sell pric…
  • Loading branch information
zielvna authored Dec 17, 2024
2 parents 0af0e55 + e3efbcf commit a02cdf2
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/components/NewPosition/RangeSelector/RangeSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,10 @@ export const RangeSelector: React.FC<IRangeSelector> = ({
<Grid container flexDirection='column'>
<Typography className={classes.currentPrice}>Current price</Typography>
<Typography className={classes.globalPrice}>Global price</Typography>
<Typography className={classes.buySellPrice}>Buy/sell price</Typography>
<Typography className={classes.lastGlobalBuyPrice}>Last global buy price</Typography>
<Typography className={classes.lastGlobalSellPrice}>
Last global sell price
</Typography>
</Grid>
</Grid>
</Grid>
Expand Down
15 changes: 15 additions & 0 deletions src/components/NewPosition/RangeSelector/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ const useStyles = makeStyles()(theme => {
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'flex-end',
cursor: 'default'
},
activeLiquidityIcon: {
Expand Down Expand Up @@ -241,6 +242,20 @@ const useStyles = makeStyles()(theme => {
...typography.caption2,
textAlign: 'right',
marginLeft: 4
},
lastGlobalBuyPrice: {
display: 'inline-block',
color: colors.invariant.plotGreen,
...typography.caption2,
textAlign: 'right',
marginLeft: 4
},
lastGlobalSellPrice: {
display: 'inline-block',
color: colors.invariant.plotRed,
...typography.caption2,
textAlign: 'right',
marginLeft: 4
}
}
})
Expand Down
2 changes: 2 additions & 0 deletions src/components/PositionDetails/PositionDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ const PositionDetails: React.FC<IProps> = ({
}
}
globalPrice={globalPrice}
tokenAPriceData={xToY ? tokenXPriceData : tokenYPriceData}
tokenBPriceData={xToY ? tokenYPriceData : tokenXPriceData}
/>
</Grid>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,17 @@ export const Primary: Story = {
decimal: 12
},
xToY: true,
hasTicksError: false
hasTicksError: false,
tokenAPriceData: {
price: 100000,
buyPrice: 105000,
sellPrice: 95000
},
tokenBPriceData: {
price: 4000,
buyPrice: 4100,
sellPrice: 3900
}
},
render: args => {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
calcPriceByTickIndex,
calcTicksAmountInRange,
numberToString,
spacingMultiplicityGte
spacingMultiplicityGte,
TokenPriceData
} from '@utils/utils'
import { PlotTickData } from '@store/reducers/positions'
import React, { useEffect, useState } from 'react'
Expand Down Expand Up @@ -35,6 +36,8 @@ export interface ISinglePositionPlot {
min: number
max: number
}
tokenAPriceData: TokenPriceData | undefined
tokenBPriceData: TokenPriceData | undefined
}

const SinglePositionPlot: React.FC<ISinglePositionPlot> = ({
Expand All @@ -53,7 +56,9 @@ const SinglePositionPlot: React.FC<ISinglePositionPlot> = ({
xToY,
hasTicksError,
reloadHandler,
volumeRange
volumeRange,
tokenAPriceData,
tokenBPriceData
}) => {
const { classes } = useStyles()

Expand Down Expand Up @@ -185,8 +190,10 @@ const SinglePositionPlot: React.FC<ISinglePositionPlot> = ({
</Typography>
</Tooltip>
<Grid container flexDirection='column'>
<Typography className={classes.currentPrice}>Current price ━━━</Typography>
<Typography className={classes.globalPrice}>Global price ━━━</Typography>
<Typography className={classes.currentPrice}>Current price</Typography>
<Typography className={classes.globalPrice}>Global price</Typography>
<Typography className={classes.lastGlobalBuyPrice}>Last global buy price</Typography>
<Typography className={classes.lastGlobalSellPrice}>Last global sell price</Typography>
</Grid>
</Grid>
</Grid>
Expand All @@ -212,6 +219,8 @@ const SinglePositionPlot: React.FC<ISinglePositionPlot> = ({
reloadHandler={reloadHandler}
volumeRange={volumeRange}
globalPrice={globalPrice}
tokenAPriceData={tokenAPriceData}
tokenBPriceData={tokenBPriceData}
/>
</Grid>
<Grid className={classes.minMaxInfo}>
Expand Down
15 changes: 15 additions & 0 deletions src/components/PositionDetails/SinglePositionPlot/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const useStyles = makeStyles()((theme: Theme) => ({
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'flex-end',
cursor: 'default'
},
activeLiquidityIcon: {
Expand Down Expand Up @@ -151,6 +152,20 @@ export const useStyles = makeStyles()((theme: Theme) => ({
...typography.caption2,
textAlign: 'right',
marginLeft: 4
},
lastGlobalBuyPrice: {
display: 'inline-block',
color: colors.invariant.plotGreen,
...typography.caption2,
textAlign: 'right',
marginLeft: 4
},
lastGlobalSellPrice: {
display: 'inline-block',
color: colors.invariant.plotRed,
...typography.caption2,
textAlign: 'right',
marginLeft: 4
}
}))

Expand Down
8 changes: 4 additions & 4 deletions src/components/PriceRangePlot/PriceRangePlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export const PriceRangePlot: React.FC<IPriceRangePlot> = ({
const unitLen = innerWidth / (plotMax - plotMin)
return (
<svg
x={(tokenAPriceData.buyPrice / tokenBPriceData.price - plotMin) * unitLen}
x={(tokenAPriceData.buyPrice / tokenBPriceData.price - plotMin) * unitLen - 20}
y={0}
width={60}
height={innerHeight}>
Expand All @@ -337,7 +337,7 @@ export const PriceRangePlot: React.FC<IPriceRangePlot> = ({
</filter>
</defs>
<rect x={14} y={20} width='16' height={innerHeight} filter='url(#shadow)' opacity='0.3' />
<rect x={19} y={20} width='3' height={innerHeight} fill={colors.white.main} />
<rect x={19} y={20} width='3' height={innerHeight} fill={colors.invariant.plotGreen} />
</svg>
)
}
Expand All @@ -350,7 +350,7 @@ export const PriceRangePlot: React.FC<IPriceRangePlot> = ({
const unitLen = innerWidth / (plotMax - plotMin)
return (
<svg
x={(tokenAPriceData.sellPrice / tokenBPriceData.price - plotMin) * unitLen}
x={(tokenAPriceData.sellPrice / tokenBPriceData.price - plotMin) * unitLen - 20}
y={0}
width={60}
height={innerHeight}>
Expand All @@ -360,7 +360,7 @@ export const PriceRangePlot: React.FC<IPriceRangePlot> = ({
</filter>
</defs>
<rect x={14} y={20} width='16' height={innerHeight} filter='url(#shadow)' opacity='0.3' />
<rect x={19} y={20} width='3' height={innerHeight} fill={colors.white.main} />
<rect x={19} y={20} width='3' height={innerHeight} fill={colors.invariant.plotRed} />
</svg>
)
}
Expand Down
4 changes: 3 additions & 1 deletion src/static/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ export const colors = {
yellow: '#EFD063',
blue: '#43BBFF',
transparentBcg: 'rgba(1, 5, 20, 0.25)',
bodyBackground: '#141b2d'
bodyBackground: '#141b2d',
plotGreen: '#9DD46D',
plotRed: '#FB555F'
}
}

Expand Down
18 changes: 16 additions & 2 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,10 @@ interface RawJupApiResponse {
id: string
price: string
extraInfo?: {
lastSwappedPrice: {
lastJupiterSellPrice: string
lastJupiterBuyPrice: string
}
quotedPrice: {
buyPrice: string
sellPrice: string
Expand All @@ -974,6 +978,8 @@ export interface TokenPriceData {
price: number
buyPrice: number
sellPrice: number
lastBuyPrice?: number
lastSellPrice?: number
}

export const getCoingeckoPricesData = async (
Expand Down Expand Up @@ -1032,7 +1038,9 @@ export const getJupPricesData = async (ids: string[]): Promise<Record<string, To
acc[id] = {
price: Number(price),
buyPrice: Number(extraInfo?.quotedPrice.buyPrice ?? 0),
sellPrice: Number(extraInfo?.quotedPrice.sellPrice ?? 0)
sellPrice: Number(extraInfo?.quotedPrice.sellPrice ?? 0),
lastBuyPrice: Number(extraInfo?.lastSwappedPrice.lastJupiterBuyPrice ?? 0),
lastSellPrice: Number(extraInfo?.lastSwappedPrice.lastJupiterSellPrice ?? 0)
}
return acc
}, {})
Expand Down Expand Up @@ -1334,7 +1342,13 @@ export const getJupTokenPrice = async (id: string): Promise<TokenPriceData> => {
return {
price: Number(response.data.data[id].price),
buyPrice: Number(response.data.data[id].extraInfo?.quotedPrice.buyPrice ?? 0),
sellPrice: Number(response.data.data[id].extraInfo?.quotedPrice.sellPrice ?? 0)
sellPrice: Number(response.data.data[id].extraInfo?.quotedPrice.sellPrice ?? 0),
lastBuyPrice: Number(
response.data.data[id].extraInfo?.lastSwappedPrice.lastJupiterBuyPrice ?? 0
),
lastSellPrice: Number(
response.data.data[id].extraInfo?.lastSwappedPrice.lastJupiterSellPrice ?? 0
)
}
} catch (error) {
return {
Expand Down

0 comments on commit a02cdf2

Please sign in to comment.