Skip to content

Commit

Permalink
Merge pull request #4557 from tncoskun/liquidity-threshould-changed-t…
Browse files Browse the repository at this point in the history
…o-pool-price

Liquidity threshould changed to pool price
  • Loading branch information
benwolski authored Dec 27, 2024
2 parents 564a679 + b367e7c commit 6e76216
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 88 deletions.
17 changes: 9 additions & 8 deletions src/pages/platformAmbient/Chart/Axes/yAxis/YaxisCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { createRectLabel } from './YaxisUtils';

interface yAxisIF {
scaleData: scaleData | undefined;
market: number;
chartPoolPrice: number;
liqMode: string;
liqTransitionPointforCurve: number;
liqTransitionPointforDepth: number;
Expand Down Expand Up @@ -84,7 +84,7 @@ function YAxisCanvas(props: yAxisIF) {
liqMode,
lineSellColor,
lineBuyColor,
market,
chartPoolPrice,
liqTransitionPointforCurve,
liqTransitionPointforDepth,
isAmbientOrAdvanced,
Expand Down Expand Up @@ -240,11 +240,11 @@ function YAxisCanvas(props: yAxisIF) {
const sameLocationLimit = () => {
if (scaleData) {
const resultData =
scaleData?.yScale(limit) - scaleData?.yScale(market);
scaleData?.yScale(limit) - scaleData?.yScale(chartPoolPrice);
const resultLocationData = resultData < 0 ? -20 : 20;
const isSameLocation = Math.abs(resultData) < 20;
const sameLocationData =
scaleData?.yScale(market) + resultLocationData;
scaleData?.yScale(chartPoolPrice) + resultLocationData;
return {
isSameLocation: isSameLocation,
sameLocationData: sameLocationData,
Expand Down Expand Up @@ -397,12 +397,13 @@ function YAxisCanvas(props: yAxisIF) {
}
});

if (market) {
const { tick, tickSubString } = prepareTickLabel(market);
if (chartPoolPrice) {
const { tick, tickSubString } =
prepareTickLabel(chartPoolPrice);

createRectLabel(
context,
yScale(market),
yScale(chartPoolPrice),
X,
'white',
'black',
Expand Down Expand Up @@ -872,7 +873,7 @@ function YAxisCanvas(props: yAxisIF) {
renderSubchartCrCanvas();
}
}, [
market,
chartPoolPrice,
diffHashSig(crosshairData),
limit,
isLineDrag,
Expand Down
36 changes: 21 additions & 15 deletions src/pages/platformAmbient/Chart/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,6 @@ export default function Chart(props: propsIF) {

const [limit, setLimit] = useState<number>(0);

const [market, setMarket] = useState<number>(0);

const [boundaries, setBoundaries] = useState<boolean>();
const [isShapeEdited, setIsShapeEdited] = useState<boolean>();

Expand Down Expand Up @@ -720,7 +718,6 @@ export default function Chart(props: propsIF) {
: lastCandleData.priceCloseDecimalCorrected;
}

setMarket(poolPrice);
return poolPrice;
}, [
lastCandleData,
Expand Down Expand Up @@ -4110,7 +4107,7 @@ export default function Chart(props: propsIF) {
.on('draw', () => {
setCanvasResolution(canvas);
ctx.setLineDash([5, 3]);
marketLine([market]);
marketLine([chartPoolPrice]);
})
.on('measure', (event: CustomEvent) => {
scaleData?.xScale.range([0, event.detail.width]);
Expand All @@ -4120,7 +4117,7 @@ export default function Chart(props: propsIF) {
});
}
renderCanvasArray([d3CanvasMarketLine]);
}, [market, marketLine]);
}, [chartPoolPrice, marketLine]);

useEffect(() => {
const noGoZoneBoundaries = noGoZone(
Expand Down Expand Up @@ -4257,7 +4254,7 @@ export default function Chart(props: propsIF) {
}

function changeScaleLimit(isTriggeredByZoom: boolean) {
if (scaleData && market && rescale) {
if (scaleData && chartPoolPrice && rescale) {
const { minYBoundary, maxYBoundary } =
getYAxisBoundary(isTriggeredByZoom);

Expand All @@ -4267,14 +4264,14 @@ export default function Chart(props: propsIF) {
minYBoundary,
value,
minTickForLimit,
market,
chartPoolPrice,
);

const high = Math.max(
maxYBoundary,
value,
maxTickForLimit,
market,
chartPoolPrice,
);

const bufferForLimit = Math.abs((low - high) / 6);
Expand All @@ -4297,7 +4294,7 @@ export default function Chart(props: propsIF) {
const min = minPrice;
const max = maxPrice;

if (!market) {
if (!chartPoolPrice) {
scaleData.yScale.domain(
scaleData.priceRange(visibleCandleData),
);
Expand All @@ -4308,17 +4305,27 @@ export default function Chart(props: propsIF) {

if (
maxYBoundary !== undefined &&
market &&
chartPoolPrice &&
minYBoundary !== undefined
) {
if (simpleRangeWidth !== 100 || advancedMode) {
if (minPrice && maxPrice) {
ranges[0] = { name: 'Min', value: minPrice };
ranges[1] = { name: 'Max', value: maxPrice };

const low = Math.min(min, max, minYBoundary, market);
const low = Math.min(
min,
max,
minYBoundary,
chartPoolPrice,
);

const high = Math.max(min, max, maxYBoundary, market);
const high = Math.max(
min,
max,
maxYBoundary,
chartPoolPrice,
);

const bufferForRange = Math.abs((low - high) / 6);

Expand Down Expand Up @@ -4415,7 +4422,7 @@ export default function Chart(props: propsIF) {
}, [
location.pathname.includes('pool') ||
location.pathname.includes('reposition'),
market,
chartPoolPrice,
isLineDrag,
minPrice,
maxPrice,
Expand Down Expand Up @@ -5704,7 +5711,7 @@ export default function Chart(props: propsIF) {

const yAxisCanvasProps = {
scaleData,
market,
chartPoolPrice,
liqMode,
liqTransitionPointforCurve: liquidityData
? liquidityData?.liqTransitionPointforCurve
Expand Down Expand Up @@ -5936,7 +5943,6 @@ export default function Chart(props: propsIF) {
mainCanvasBoundingClientRect={
mainCanvasBoundingClientRect
}
chartPoolPrice={chartPoolPrice}
chartThemeColors={chartThemeColors}
render={render}
colorChangeTrigger={colorChangeTrigger}
Expand Down
Loading

0 comments on commit 6e76216

Please sign in to comment.