Skip to content

Commit

Permalink
fix last price
Browse files Browse the repository at this point in the history
  • Loading branch information
brightiron committed Sep 19, 2024
1 parent 91735e5 commit 66e8378
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions src/views/Range/RangeChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
YAxis,
} from "recharts";
import { NameType } from "recharts/types/component/DefaultTooltipContent";
import { formatCurrency, parseBigNumber, trim } from "src/helpers";
import { formatCurrency, parseBigNumber } from "src/helpers";
import { RANGEv2 as OlympusRange } from "src/typechain/Range";
import { OperatorMovingAverage, OperatorTargetPrice, PriceHistory } from "src/views/Range/hooks";

Expand Down Expand Up @@ -54,31 +54,18 @@ const RangeChart = (props: {
const { data: targetPrice } = OperatorTargetPrice();
const { data: movingAverage } = OperatorMovingAverage();

const formattedWallHigh = trim(parseBigNumber(rangeData.high.wall.price, 18), 2);
const formattedWallLow = trim(parseBigNumber(rangeData.low.wall.price, 18), 2);
const formattedCushionHigh = trim(parseBigNumber(rangeData.high.cushion.price, 18), 2);
const formattedCushionLow = trim(parseBigNumber(rangeData.low.cushion.price, 18), 2);
const chartData = priceData.map(item => {
const chartData = priceData.map((item, index) => {
const isFirstItem = index === 0;

return {
price: parseFloat(item.snapshot.ohmPrice),
timestamp: item.snapshot.timestamp,
timestamp: isFirstItem ? "now" : item.snapshot.timestamp,
uv: [item.snapshot.highWallPrice, item.snapshot.highCushionPrice],
lv: [item.snapshot.lowWallPrice, item.snapshot.lowCushionPrice],
ma: parseFloat(item.snapshot.ohmMovingAveragePrice),
};
});

/* We load an object at the front of the chartData array
* with no price data to shift the chart line left and add an extra element with current market price
*/
chartData.unshift({
price: currentPrice,
timestamp: "now",
uv: [formattedWallHigh, formattedCushionHigh],
lv: [formattedWallLow, formattedCushionLow],
ma: targetPrice,
});

const CustomReferenceDot = (props: {
cx: string | number | undefined;
cy: string | number | undefined;
Expand Down Expand Up @@ -238,15 +225,15 @@ const RangeChart = (props: {

<ReferenceDot
x={"now"}
y={chartData.length > 1 ? chartData[1].price : 0}
y={chartData.length > 1 ? chartData[0].price : 0}
shape={CustomReferenceDot}
fill={theme.colors.gray[10]}
>
<Label
className={classes.currentPrice}
position={(isSquishyBid && bidPriceDelta < 0) || (isSquishyAsk && askPriceDelta < 0) ? "bottom" : "top"}
>
{formatCurrency(chartData.length > 1 ? chartData[1].price : 0, 2, reserveSymbol)}
{formatCurrency(chartData.length > 1 ? chartData[0].price : 0, 2, reserveSymbol)}
</Label>
</ReferenceDot>
<ReferenceDot x={"now"} y={askPrice} shape={CustomReferenceDot} fill="#F8CC82">
Expand Down

0 comments on commit 66e8378

Please sign in to comment.