@dodoex/widgets 3.0.2-zetachain.12 → 3.0.2-zetachain.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,971 +0,0 @@
1
- import styled from '@emotion/styled';
2
- import { merge } from 'lodash';
3
- import { useMemo, useRef } from 'react';
4
- import { l as labelPadding, g as chartT, m as colorRgb } from './helper-CMiEdcFd.js';
5
- import { Line, Text, Stage, Layer, Rect, Circle, Label, Tag } from 'react-konva';
6
- import { j as jsxRuntimeExports, f as formatShortNumber } from './index-bUI_7SKV.js';
7
- import BigNumber from 'bignumber.js';
8
- import { solveQuadraticFunctionForTarget, PMMState, PMMHelper } from '@dodoex/api';
9
- import '@lingui/core';
10
- import '@lingui/react';
11
- import '@dodoex/components';
12
- import '@web3-react/core';
13
- import 'axios';
14
- import '@ethersproject/bignumber';
15
- import 'zustand';
16
- import '@dodoex/dodo-contract-request';
17
- import '@tanstack/react-query';
18
- import 'pino';
19
- import 'events';
20
- import 'node-fetch';
21
- import '@web3-react/eip1193';
22
- import '@web3-react/walletconnect-v2';
23
- import '@web3-react/metamask';
24
- import '@web3-react/types';
25
- import '@ethersproject/contracts';
26
- import 'identicon.js';
27
- import 'react-dom';
28
- import 'dayjs';
29
- import 'react-transition-group';
30
- import '@dodoex/contract-request';
31
- import 'recharts';
32
- import 'react-window';
33
- import 'jsbi';
34
- import 'tiny-invariant';
35
- import '@ethersproject/units';
36
- import '@uniswap/sdk-core';
37
- import '@uniswap/v2-sdk';
38
- import 'react-infinite-scroller';
39
- import 'd3';
40
- import 'rmc-date-picker';
41
-
42
- const Container = styled.div`
43
- height: 100%;
44
- position: relative;
45
- `;
46
- const TipWrapper = styled.div`
47
- text-align: center;
48
- margin-top: 17.1px;
49
- margin-bottom: 88.41px;
50
- color: #606066;
51
- font-size: 12px;
52
- line-height: 17px;
53
- font-weight: 400;
54
- `;
55
-
56
- // The space reserved at the top
57
- const topEmptyHeight = 36;
58
- function computePointYByHeight({
59
- maxHeight,
60
- gridAreaHeight,
61
- value
62
- }) {
63
- const height = new BigNumber(gridAreaHeight).minus(topEmptyHeight);
64
- const onePXY = height.div(maxHeight);
65
- const y = height.minus(value.multipliedBy(onePXY)).plus(topEmptyHeight);
66
- return y.toNumber();
67
- }
68
- /**
69
- * Obtain the closest data point from the data point collection through the coordinate point x and a series of point data subsets from the point to the center line.
70
- */
71
- function getStatAreaPointByX({
72
- targetPrice,
73
- areaPoints,
74
- isLeft
75
- }) {
76
- for (let index = 0; index < areaPoints.length; index++) {
77
- const point = areaPoints[index];
78
- const nextPoint = index < areaPoints.length - 1 ? areaPoints[index + 1] : null;
79
- if (!nextPoint) {
80
- return {
81
- targetAreaStatPoint: point,
82
- targetAreaStatPoints: areaPoints
83
- };
84
- }
85
- if (isLeft) {
86
- if (targetPrice.lte(point.middlePrice) && targetPrice.gte(nextPoint.middlePrice)) {
87
- return {
88
- targetAreaStatPoint: point,
89
- targetAreaStatPoints: areaPoints.slice(0, index + 1)
90
- };
91
- }
92
- } else if (targetPrice.gte(point.middlePrice) && targetPrice.lte(nextPoint.middlePrice)) {
93
- return {
94
- targetAreaStatPoint: point,
95
- targetAreaStatPoints: areaPoints.slice(0, index + 1)
96
- };
97
- }
98
- }
99
- return {
100
- targetAreaStatPoint: null,
101
- targetAreaStatPoints: []
102
- };
103
- }
104
- /**
105
- * Given a pixel's x-coordinate, width, logarithm of the minimum value of the abscissa, and logarithm of the maximum value of the abscissa, calculate the logarithmic coordinate corresponding to the point
106
- */
107
- function computeTargetPrice({
108
- x,
109
- width,
110
- minXLN10,
111
- maxXLN10
112
- }) {
113
- const xLN10 = new BigNumber(x).div(width).multipliedBy(maxXLN10.minus(minXLN10));
114
- const power = xLN10.plus(minXLN10);
115
- return new BigNumber(10 ** power.toNumber());
116
- }
117
- /**
118
- * Given the logarithm of a coordinate, the width, the logarithm of the minimum value of the abscissa, and the logarithm of the maximum value of the abscissa, calculate the x coordinate corresponding to the point
119
- */
120
- function computeTargetX({
121
- width,
122
- targetLN10,
123
- minXLN10,
124
- maxXLN10
125
- }) {
126
- return targetLN10.minus(minXLN10).div(maxXLN10.minus(minXLN10)).multipliedBy(width).toNumber();
127
- }
128
- /**
129
- * Calculate logarithm
130
- */
131
- function computeTargetLN({
132
- target
133
- }) {
134
- return new BigNumber(Math.log10(target.toNumber()));
135
- }
136
-
137
- function useGridLine({
138
- gridAreaHeight,
139
- gridAreaWidth,
140
- horizontalLineCount,
141
- verticalLineCount,
142
- color = '#2A2A2D'
143
- }) {
144
- return useMemo(() => {
145
- const horizontalGridLines = [];
146
- const horizontalGridPerBlockHeight = gridAreaHeight / (horizontalLineCount + 1);
147
- const verticalGridLines = [];
148
- const verticalGridPerBlockHeight = gridAreaWidth / (verticalLineCount + 1);
149
- for (let index = 0; index < horizontalLineCount; index++) {
150
- const y = horizontalGridPerBlockHeight * (index + 1);
151
- horizontalGridLines.push([0, y, gridAreaWidth, y]);
152
- }
153
- for (let index = 0; index < verticalLineCount; index++) {
154
- const x = verticalGridPerBlockHeight * (index + 1);
155
- verticalGridLines.push([x, 0, x, gridAreaHeight]);
156
- }
157
- return /*#__PURE__*/jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, {
158
- children: [horizontalGridLines.map((points, index) => /*#__PURE__*/jsxRuntimeExports.jsx(Line, {
159
- points: points,
160
- stroke: color,
161
- strokeWidth: 1,
162
- lineCap: "round",
163
- lineJoin: "round",
164
- tension: 1,
165
- listening: false
166
- }, index)), verticalGridLines.map((points, index) => /*#__PURE__*/jsxRuntimeExports.jsx(Line, {
167
- points: points,
168
- stroke: color,
169
- strokeWidth: 1,
170
- lineCap: "round",
171
- lineJoin: "round",
172
- tension: 1,
173
- listening: false
174
- }, index))]
175
- });
176
- }, [gridAreaHeight, gridAreaWidth, horizontalLineCount, verticalLineCount, color]);
177
- }
178
-
179
- function useHorizontalLabel({
180
- minXLN10,
181
- maxXLN10,
182
- labelCount,
183
- gridAreaHeight,
184
- gridAreaWidth,
185
- color = '#606066'
186
- }) {
187
- return useMemo(() => {
188
- const labelWidth = gridAreaWidth / (labelCount + 1);
189
- const labelTextList = [];
190
- const labelLines = [];
191
- for (let index = 0; index < labelCount; index++) {
192
- const x = labelWidth / 2 + labelWidth * index;
193
- labelTextList.push({
194
- x,
195
- y: gridAreaHeight + 10.08 + 1,
196
- text: formatShortNumber(computeTargetPrice({
197
- x: labelWidth * (index + 1),
198
- width: gridAreaWidth,
199
- minXLN10,
200
- maxXLN10
201
- }))
202
- });
203
- const lineX = labelWidth * (index + 1);
204
- labelLines.push([lineX, gridAreaHeight + 1, lineX, gridAreaHeight + 4 + 1]);
205
- }
206
- return /*#__PURE__*/jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, {
207
- children: [labelTextList.map((labelText, index) => /*#__PURE__*/jsxRuntimeExports.jsx(Text, {
208
- x: labelText.x,
209
- y: labelText.y,
210
- text: labelText.text,
211
- fontSize: 14,
212
- fontFamily: "Manrope",
213
- fill: color,
214
- width: labelWidth,
215
- padding: 0,
216
- align: "center",
217
- verticalAlign: "bottom",
218
- listening: false
219
- }, index)), labelLines.map((points, index) => /*#__PURE__*/jsxRuntimeExports.jsx(Line, {
220
- points: points,
221
- stroke: color,
222
- strokeWidth: 1,
223
- lineCap: "butt",
224
- lineJoin: "miter",
225
- tension: 1,
226
- listening: false
227
- }, index))]
228
- });
229
- }, [minXLN10, maxXLN10, gridAreaHeight, gridAreaWidth, labelCount]);
230
- }
231
-
232
- function useLiquidityLine({
233
- leftStatAreaPoints,
234
- rightStatAreaPoints,
235
- minXLN10,
236
- maxXLN10,
237
- maxLeftHeight,
238
- maxRightHeight,
239
- gridAreaWidth,
240
- gridAreaHeight,
241
- colorMap
242
- }) {
243
- const leftLine = useMemo(() => {
244
- if (leftStatAreaPoints.length < 1) {
245
- return /*#__PURE__*/jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {});
246
- }
247
- const points = [];
248
- let minPointY = gridAreaHeight;
249
- for (const statPoint of leftStatAreaPoints) {
250
- const {
251
- middlePrice,
252
- rectangleHeight
253
- } = statPoint;
254
- const targetLN10 = computeTargetLN({
255
- target: middlePrice
256
- });
257
- const x = computeTargetX({
258
- minXLN10,
259
- maxXLN10,
260
- width: gridAreaWidth,
261
- targetLN10
262
- });
263
- const y = computePointYByHeight({
264
- maxHeight: maxLeftHeight,
265
- gridAreaHeight,
266
- value: rectangleHeight
267
- });
268
- points.push(x, y);
269
- if (y < minPointY) {
270
- minPointY = y;
271
- }
272
- }
273
- // Gradient color points: from center to left
274
- const linearGradientPoints = points.slice();
275
- const [rightEndPointX, rightEndPointY] = linearGradientPoints;
276
- const leftStartPointY = linearGradientPoints[linearGradientPoints.length - 1];
277
- const leftStartPointX = linearGradientPoints[linearGradientPoints.length - 2];
278
- linearGradientPoints.push(leftStartPointX, leftStartPointY);
279
- linearGradientPoints.push(leftStartPointX, gridAreaHeight);
280
- linearGradientPoints.push(rightEndPointX, gridAreaHeight);
281
- linearGradientPoints.push(rightEndPointX, rightEndPointY);
282
- return /*#__PURE__*/jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, {
283
- children: [/*#__PURE__*/jsxRuntimeExports.jsx(Line, {
284
- points: linearGradientPoints,
285
- closed: true,
286
- listening: false,
287
- lineCap: "round",
288
- lineJoin: "round",
289
- fillLinearGradientStartPoint: {
290
- x: 0,
291
- y: gridAreaHeight
292
- },
293
- fillLinearGradientEndPoint: {
294
- x: 0,
295
- y: minPointY
296
- },
297
- fillLinearGradientColorStops: colorMap.leftBg
298
- }), /*#__PURE__*/jsxRuntimeExports.jsx(Line, {
299
- points: points,
300
- stroke: colorMap.leftLine,
301
- strokeWidth: 2,
302
- lineCap: "round",
303
- lineJoin: "round",
304
- listening: false
305
- })]
306
- });
307
- }, [leftStatAreaPoints, gridAreaWidth, minXLN10, maxXLN10, gridAreaHeight, maxLeftHeight]);
308
- const rightLine = useMemo(() => {
309
- if (rightStatAreaPoints.length < 1) {
310
- return /*#__PURE__*/jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {});
311
- }
312
- const points = [];
313
- let minPointY = gridAreaHeight;
314
- for (const statPoint of rightStatAreaPoints) {
315
- const {
316
- middlePrice,
317
- rectangleHeight
318
- } = statPoint;
319
- const targetLN10 = computeTargetLN({
320
- target: middlePrice
321
- });
322
- const x = computeTargetX({
323
- minXLN10,
324
- maxXLN10,
325
- width: gridAreaWidth,
326
- targetLN10
327
- });
328
- const y = computePointYByHeight({
329
- maxHeight: maxRightHeight,
330
- gridAreaHeight,
331
- value: rectangleHeight
332
- });
333
- points.push(x, y);
334
- if (y < minPointY) {
335
- minPointY = y;
336
- }
337
- }
338
- // Gradient colored dots
339
- const linearGradientPoints = points.slice();
340
- const [firstPointX] = linearGradientPoints;
341
- linearGradientPoints.unshift(firstPointX, gridAreaHeight);
342
- linearGradientPoints.unshift(gridAreaWidth, gridAreaHeight);
343
- return /*#__PURE__*/jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, {
344
- children: [/*#__PURE__*/jsxRuntimeExports.jsx(Line, {
345
- points: linearGradientPoints,
346
- closed: true,
347
- listening: false,
348
- lineCap: "round",
349
- lineJoin: "round",
350
- fillLinearGradientStartPoint: {
351
- x: 0,
352
- y: gridAreaHeight
353
- },
354
- fillLinearGradientEndPoint: {
355
- x: 0,
356
- y: minPointY
357
- },
358
- fillLinearGradientColorStops: colorMap.rightBg
359
- }), /*#__PURE__*/jsxRuntimeExports.jsx(Line, {
360
- points: points,
361
- stroke: colorMap.rightLine,
362
- strokeWidth: 2,
363
- lineCap: "round",
364
- lineJoin: "round",
365
- listening: false
366
- })]
367
- });
368
- }, [rightStatAreaPoints, gridAreaWidth, minXLN10, maxXLN10, gridAreaHeight, maxRightHeight]);
369
- return {
370
- leftLine,
371
- rightLine
372
- };
373
- }
374
-
375
- function useMiddleLine({
376
- gridAreaHeight,
377
- gridAreaWidth,
378
- color = '#606066'
379
- }) {
380
- return useMemo(() => {
381
- const topPointX = gridAreaWidth / 2;
382
- return /*#__PURE__*/jsxRuntimeExports.jsx(Line, {
383
- points: [topPointX, 0, topPointX, gridAreaHeight - 1],
384
- stroke: color,
385
- strokeWidth: 1,
386
- lineCap: "round",
387
- lineJoin: "round",
388
- tension: 1,
389
- listening: false
390
- });
391
- }, [gridAreaHeight, gridAreaWidth, color]);
392
- }
393
-
394
- function usePoints({
395
- params
396
- }) {
397
- return useMemo(() => {
398
- const b = new BigNumber(params.b);
399
- const q = new BigNumber(params.q);
400
- let b0 = new BigNumber(params.b0);
401
- const q0 = new BigNumber(params.q0);
402
- const i = new BigNumber(params.i);
403
- const K = new BigNumber(params.k);
404
- const {
405
- R
406
- } = params;
407
- // When created, b0 is equal to b, and a b0 needs to be calculated.
408
- if (R === 1 && b0.eq(b)) {
409
- b0 = solveQuadraticFunctionForTarget(b, q.minus(q0), new BigNumber(1).div(i), K);
410
- }
411
- const pmmState = new PMMState({
412
- i,
413
- K,
414
- B: b,
415
- Q: q,
416
- B0: b0,
417
- Q0: q0,
418
- R,
419
- mtFeeRate: new BigNumber(0),
420
- lpFeeRate: new BigNumber(0)
421
- });
422
- const pmm = new PMMHelper();
423
- const B = new BigNumber(pmmState.B);
424
- // const Q = new BigNumber(pmmState.Q);
425
- // A collection of data points, mapped into points on the graph through equal width and height proportions
426
- const leftStatPoints = [];
427
- const rightStatPoints = [];
428
- let maxLeftHeight = new BigNumber(0);
429
- let maxRightHeight = new BigNumber(0);
430
- const midPrice = pmm.GetMidPrice(pmmState);
431
- const portion = q.gt(0) ? b.div(q) : new BigNumber(1);
432
- // console.log('v2 midPrice', midPrice.toString(), portion.toString());
433
- for (let index = 0; index <= 250; index++) {
434
- let giveAmount = B.multipliedBy(index / 100).multipliedBy(midPrice.multipliedBy(portion).multipliedBy(4));
435
- // let giveAmount = B.multipliedBy(index / 100).multipliedBy(4);
436
- // let giveAmount = B.multipliedBy(index / 100);
437
- if (index === 0) {
438
- giveAmount = B.multipliedBy(1 / 100000000000);
439
- }
440
- // sellBase needs to pass in the number of quotes and gets the number of bases
441
- const getAmount = pmm === null || pmm === void 0 ? void 0 : pmm.QuerySellBase(giveAmount, pmmState);
442
- // console.log('v2 QuerySellBase', giveAmount.toString(), getAmount.toString());
443
- if (!getAmount.isNaN() && getAmount.gt(0)) {
444
- // Price on the left
445
- const price = getAmount.div(giveAmount);
446
- leftStatPoints.push({
447
- giveAmount,
448
- getAmount,
449
- price
450
- });
451
- continue;
452
- }
453
- leftStatPoints.push({
454
- giveAmount,
455
- getAmount: new BigNumber(0),
456
- price: new BigNumber(0)
457
- });
458
- }
459
- for (let index = 0; index <= 250; index++) {
460
- let giveAmount = B.multipliedBy(index / 100).multipliedBy(midPrice.multipliedBy(4));
461
- // let giveAmount = B.multipliedBy(index / 100);
462
- if (index === 0) {
463
- giveAmount = B.multipliedBy(1 / 100000000000);
464
- }
465
- // sellQuote needs to pass in the number of bases and get the number of quotes
466
- const getAmount = pmm === null || pmm === void 0 ? void 0 : pmm.QuerySellQuote(giveAmount, pmmState);
467
- // console.log('v2 QuerySellQuote', giveAmount.toString(), getAmount.toString());
468
- if (!getAmount.isNaN() && getAmount.gt(0)) {
469
- // Price on the right
470
- const price = giveAmount.dividedBy(getAmount);
471
- rightStatPoints.push({
472
- giveAmount,
473
- getAmount,
474
- price
475
- });
476
- continue;
477
- }
478
- rightStatPoints.push({
479
- giveAmount,
480
- getAmount: new BigNumber(0),
481
- price: new BigNumber(0)
482
- });
483
- }
484
- if (leftStatPoints.length < 2 && rightStatPoints.length < 2) {
485
- return {
486
- leftStatAreaPoints: [],
487
- rightStatAreaPoints: [],
488
- maxLeftHeight: new BigNumber(10).multipliedBy(1.2),
489
- maxRightHeight: new BigNumber(10).multipliedBy(1.2),
490
- middlePriceLN10: new BigNumber(0),
491
- minXLN10: new BigNumber(-1),
492
- maxXLN10: new BigNumber(1)
493
- };
494
- }
495
- // The data points are divided into two groups on the left and right, and the width and height corresponding to the area are calculated.
496
- const leftStatAreaPoints = [];
497
- for (let index = 1; index < leftStatPoints.length; index++) {
498
- const statPoint = leftStatPoints[index];
499
- const {
500
- giveAmount,
501
- getAmount,
502
- price
503
- } = statPoint;
504
- const lastStatPoint = leftStatPoints[index - 1];
505
- if (!price.isNaN() && price.gt(0) && lastStatPoint) {
506
- const priceChange = price.minus(lastStatPoint.price).abs();
507
- const giveAmountChange = giveAmount.minus(lastStatPoint.giveAmount).abs();
508
- const getAmountChange = getAmount.minus(lastStatPoint.getAmount).abs();
509
- const leftRectangleHeight = getAmountChange.multipliedBy(giveAmountChange);
510
- if (index === 1) {
511
- leftStatAreaPoints.push({
512
- area: getAmount,
513
- price,
514
- middlePrice: price.plus(priceChange.div(1.1)),
515
- rectangleHeight: leftRectangleHeight.plus(leftRectangleHeight.multipliedBy(0.03))
516
- });
517
- }
518
- leftStatAreaPoints.push({
519
- area: getAmount,
520
- price,
521
- middlePrice: price.plus(priceChange.div(2)),
522
- rectangleHeight: leftRectangleHeight
523
- });
524
- maxLeftHeight = BigNumber.max(leftRectangleHeight, maxLeftHeight);
525
- }
526
- }
527
- const rightStatAreaPoints = [];
528
- for (let index = 1; index < rightStatPoints.length; index++) {
529
- const statPoint = rightStatPoints[index];
530
- const {
531
- giveAmount,
532
- getAmount,
533
- price
534
- } = statPoint;
535
- const lastStatPoint = rightStatPoints[index - 1];
536
- const lastPrice = lastStatPoint.price;
537
- const lastGiveAmount = lastStatPoint.giveAmount;
538
- const lastGetAmount = lastStatPoint.getAmount;
539
- if (!price.isNaN() && price.gt(0) && lastStatPoint) {
540
- const priceChange = price.minus(lastPrice).abs();
541
- const giveAmountChange = giveAmount.minus(lastGiveAmount).abs();
542
- const getAmountChange = getAmount.minus(lastGetAmount).abs();
543
- const rightRectangleHeight = getAmountChange.multipliedBy(giveAmountChange);
544
- if (index === 1) {
545
- rightStatAreaPoints.push({
546
- area: getAmount,
547
- price,
548
- middlePrice: price.minus(priceChange.div(1.1)),
549
- rectangleHeight: rightRectangleHeight.plus(rightRectangleHeight.multipliedBy(0.03))
550
- });
551
- }
552
- rightStatAreaPoints.push({
553
- area: getAmount,
554
- price,
555
- middlePrice: price.minus(priceChange.div(2)),
556
- rectangleHeight: rightRectangleHeight
557
- });
558
- maxRightHeight = BigNumber.max(rightRectangleHeight, maxRightHeight);
559
- }
560
- }
561
- // Intuitively, the data points on the left are distributed from the middle to the left, and the data points on the right are distributed from the middle to the right.
562
- // Left starting point
563
- const leftStartStatPoint = leftStatPoints.length > 0 ? leftStatPoints[leftStatPoints.length - 1] : rightStatPoints[0];
564
- // midpoint
565
- const middleStatPoint = rightStatPoints.length > 0 ? rightStatPoints[0] : leftStatPoints[0];
566
- // Right end point
567
- const rightEndStatPoint = rightStatPoints.length > 0 ? rightStatPoints[rightStatPoints.length - 1] : leftStatPoints[0];
568
- const minX = leftStartStatPoint.price;
569
- const maxX = rightEndStatPoint.price;
570
- const middlePrice = middleStatPoint.price;
571
- const middlePriceLN10 = new BigNumber(Math.log10(middlePrice.toNumber()));
572
- // Center the graphic
573
- let minXLN10 = minX.gt(0) ? new BigNumber(Math.log10(minX.toNumber())) : new BigNumber(-Math.log10(maxX.toNumber()));
574
- let maxXLN10 = maxX.gt(0) ? new BigNumber(Math.log10(maxX.toNumber())) : new BigNumber(-Math.log10(minX.toNumber()));
575
- const rangeLN10 = BigNumber.max(middlePriceLN10.minus(minXLN10).abs(), maxXLN10.minus(middlePriceLN10).abs());
576
- minXLN10 = middlePriceLN10.minus(rangeLN10);
577
- maxXLN10 = middlePriceLN10.plus(rangeLN10);
578
- // console.log('v2 price', {
579
- // // middlePrice: middlePrice.toString(),
580
- // minX: minX.toString(),
581
- // // maxX: maxX.toString(),
582
- // middlePriceLN10: middlePriceLN10.toString(),
583
- // minXLN10: minXLN10.toString(),
584
- // maxXLN10: maxXLN10.toString(),
585
- // });
586
- return {
587
- leftStatAreaPoints,
588
- rightStatAreaPoints,
589
- maxLeftHeight: maxLeftHeight.multipliedBy(1.2),
590
- maxRightHeight: maxRightHeight.multipliedBy(1.2),
591
- minXLN10,
592
- maxXLN10,
593
- middlePriceLN10
594
- };
595
- }, [params]);
596
- }
597
-
598
- const bgColor = 'rgba(38, 39, 41, 0.3)';
599
- function LiquidityChartKonva({
600
- width,
601
- height,
602
- params,
603
- baseTokenSymbol,
604
- quoteTokenSymbol,
605
- colorMap
606
- }) {
607
- const {
608
- maxLeftHeight,
609
- maxRightHeight,
610
- leftStatAreaPoints,
611
- rightStatAreaPoints,
612
- minXLN10,
613
- maxXLN10
614
- } = usePoints({
615
- params
616
- });
617
- const xAxisLabelHeight = 30.13;
618
- const gridAreaHeight = height - xAxisLabelHeight;
619
- const horizontalLineCount = 9;
620
- // The number of vertical grid lines or the number of horizontal axis scales
621
- const verticalLineCount = 7;
622
- const tooltipRef = useRef(null);
623
- const colorMapRes = merge({
624
- grid: '#2A2A2D',
625
- midPriceLine: '#313335',
626
- leftBg: [0, bgColor, 1, '#31645d'],
627
- leftLine: '#55f6db',
628
- leftColor: '',
629
- rightBg: [0, bgColor, 1, '#67303d'],
630
- rightLine: '#ff4f73',
631
- rightColor: '',
632
- tooltipBg: '#121212',
633
- tooltipColor: undefined,
634
- textColor: '#606066'
635
- }, colorMap);
636
- const handleMouseover = evt => {
637
- var _a;
638
- const {
639
- current: tooltip
640
- } = tooltipRef;
641
- const node = evt.target;
642
- if (node && tooltip) {
643
- // update tooltip
644
- const mousePos = (_a = node.getStage()) === null || _a === void 0 ? void 0 : _a.getPointerPosition();
645
- if (mousePos) {
646
- const {
647
- x
648
- } = mousePos;
649
- const middleX = width / 2;
650
- if (Math.abs(x - middleX) <= 2) {
651
- return;
652
- }
653
- if (x <= 2 || width - x <= 2) {
654
- return;
655
- }
656
- const targetPrice = computeTargetPrice({
657
- x,
658
- width,
659
- minXLN10,
660
- maxXLN10
661
- });
662
- let targetAreaStatPoint = null;
663
- let targetAreaStatPoints = [];
664
- const isLeft = x < middleX;
665
- if (isLeft) {
666
- const result = getStatAreaPointByX({
667
- areaPoints: leftStatAreaPoints,
668
- targetPrice,
669
- isLeft
670
- });
671
- targetAreaStatPoint = result.targetAreaStatPoint;
672
- targetAreaStatPoints = result.targetAreaStatPoints;
673
- } else {
674
- const result = getStatAreaPointByX({
675
- areaPoints: rightStatAreaPoints,
676
- targetPrice,
677
- isLeft
678
- });
679
- targetAreaStatPoint = result.targetAreaStatPoint;
680
- targetAreaStatPoints = result.targetAreaStatPoints;
681
- }
682
- if (targetAreaStatPoint) {
683
- const targetLN10 = computeTargetLN({
684
- target: targetAreaStatPoint.middlePrice
685
- });
686
- const targetAreaPointX = computeTargetX({
687
- minXLN10,
688
- maxXLN10,
689
- width,
690
- targetLN10
691
- });
692
- const targetAreaPointY = computePointYByHeight({
693
- maxHeight: isLeft ? maxLeftHeight : maxRightHeight,
694
- gridAreaHeight,
695
- value: targetAreaStatPoint.rectangleHeight
696
- });
697
- const tooltipLabel = tooltip.findOne('#tooltip');
698
- const toolTipVertLine = tooltip.findOne('#toolTipVertLine');
699
- const joinCircle = tooltip.findOne('#joinCircle');
700
- const tooltipText = tooltip.findOne('#tooltip-Text');
701
- const tooltipTag = tooltip.findOne('#tooltip-tag');
702
- const priceTextLabel = tooltip.findOne('#priceTextLabel');
703
- const priceTextLabelText = priceTextLabel === null || priceTextLabel === void 0 ? void 0 : priceTextLabel.findOne('#priceTextLabel-text');
704
- const area = tooltip.findOne('#area');
705
- tooltipLabel === null || tooltipLabel === void 0 ? void 0 : tooltipLabel.position({
706
- x: targetAreaPointX,
707
- y: targetAreaPointY - 5 - 6
708
- });
709
- tooltipText === null || tooltipText === void 0 ? void 0 : tooltipText.fill(colorMapRes.tooltipColor || (isLeft ? '#00FAD9' : '#FF5072'));
710
- tooltipText === null || tooltipText === void 0 ? void 0 : tooltipText.text(isLeft ? chartT('pool.chart.liquidity-chart-buy', {
711
- amount: formatShortNumber(targetAreaStatPoint.area),
712
- symbol: baseTokenSymbol,
713
- price: formatShortNumber(targetAreaStatPoint.price)
714
- }) : chartT('pool.chart.liquidity-chart-sell', {
715
- amount: formatShortNumber(targetAreaStatPoint.area),
716
- symbol: quoteTokenSymbol,
717
- price: formatShortNumber(targetAreaStatPoint.price)
718
- }));
719
- if (tooltipLabel && tooltipTag) {
720
- if (tooltipLabel.width() / 2 > x) {
721
- tooltipTag.pointerDirection('left');
722
- tooltipTag.pointerHeight(15);
723
- tooltipTag.pointerWidth(8);
724
- tooltipLabel.offsetX(-(5 + 6));
725
- tooltipLabel.offsetY(-(5 + 6));
726
- } else if (tooltipLabel.width() / 2 + x > width) {
727
- tooltipTag.pointerDirection('right');
728
- tooltipTag.pointerHeight(15);
729
- tooltipTag.pointerWidth(8);
730
- tooltipLabel.offsetX(5 + 6);
731
- tooltipLabel.offsetY(-(5 + 6));
732
- } else {
733
- // @ts-ignore
734
- tooltipTag.pointerDirection('down');
735
- tooltipTag.pointerHeight(8);
736
- tooltipTag.pointerWidth(15);
737
- tooltipLabel.offsetX(0);
738
- tooltipLabel.offsetY(0);
739
- }
740
- }
741
- toolTipVertLine === null || toolTipVertLine === void 0 ? void 0 : toolTipVertLine.points([targetAreaPointX, gridAreaHeight, targetAreaPointX, targetAreaPointY]);
742
- toolTipVertLine === null || toolTipVertLine === void 0 ? void 0 : toolTipVertLine.stroke(isLeft ? '#55f6db' : '#ff4f73');
743
- let joinFill = isLeft ? 'rgb(86, 246, 218)' : '#FF5072';
744
- let joinStroke = isLeft ? 'rgba(86, 246, 218, 0.3)' : 'rgba(255, 80, 114, 0.3)';
745
- if (colorMapRes.leftLine && colorMapRes.rightLine) {
746
- joinFill = isLeft ? colorMapRes.leftLine : colorMapRes.rightLine;
747
- joinStroke = isLeft ? `rgba(${colorRgb(colorMapRes.leftLine)}, 0.4)` : `rgba(${colorRgb(colorMapRes.rightLine)}, 0.4)`;
748
- }
749
- if (joinCircle) {
750
- joinCircle.x(targetAreaPointX);
751
- joinCircle.y(targetAreaPointY);
752
- joinCircle.fill(joinFill);
753
- joinCircle.stroke(joinStroke);
754
- }
755
- if (priceTextLabel) {
756
- priceTextLabel.x(targetAreaPointX);
757
- priceTextLabel.y(gridAreaHeight + 8.08 + 1);
758
- priceTextLabel.offsetX(priceTextLabel.width() / 2);
759
- if (priceTextLabel.x() - priceTextLabel.width() / 2 < 0) {
760
- priceTextLabel.x(priceTextLabel.width() / 2);
761
- } else if (priceTextLabel.x() + priceTextLabel.width() / 2 > width) {
762
- priceTextLabel.x(width - priceTextLabel.width() / 2);
763
- } else {
764
- priceTextLabel.x(x);
765
- }
766
- }
767
- if (priceTextLabelText) {
768
- priceTextLabelText.fill(colorMapRes.tooltipColor || (isLeft ? '#00FAD9' : '#FF5072'));
769
- priceTextLabelText.text(formatShortNumber(targetAreaStatPoint.price));
770
- }
771
- // Gradient colored dots
772
- const points = [];
773
- for (const statPoint of targetAreaStatPoints) {
774
- const {
775
- middlePrice,
776
- rectangleHeight
777
- } = statPoint;
778
- const targetLN10Gradient = computeTargetLN({
779
- target: middlePrice
780
- });
781
- const xGradient = computeTargetX({
782
- minXLN10,
783
- maxXLN10,
784
- width,
785
- targetLN10: targetLN10Gradient
786
- });
787
- const y = computePointYByHeight({
788
- maxHeight: isLeft ? maxLeftHeight : maxRightHeight,
789
- gridAreaHeight,
790
- value: rectangleHeight
791
- });
792
- points.push(xGradient, y + 1);
793
- }
794
- const linearGradientPoints = points.slice();
795
- const [firstPointX, firstPointY] = linearGradientPoints;
796
- if (isLeft) {
797
- linearGradientPoints.push(targetAreaPointX, targetAreaPointY);
798
- linearGradientPoints.push(targetAreaPointX, gridAreaHeight);
799
- linearGradientPoints.push(firstPointX, gridAreaHeight);
800
- linearGradientPoints.push(firstPointX, firstPointY);
801
- } else {
802
- linearGradientPoints.unshift(firstPointX, gridAreaHeight);
803
- linearGradientPoints.unshift(targetAreaPointX, gridAreaHeight);
804
- linearGradientPoints.unshift(targetAreaPointX, targetAreaPointY);
805
- }
806
- if (area) {
807
- area.points(linearGradientPoints);
808
- area.fill(isLeft ? colorMapRes.leftLine || '#2c5b56' : colorMapRes.rightLine || '#7b3a48');
809
- }
810
- tooltip.show();
811
- }
812
- }
813
- }
814
- };
815
- const handleMouseOut = () => {
816
- const {
817
- current: tooltip
818
- } = tooltipRef;
819
- if (tooltip) {
820
- tooltip.hide();
821
- }
822
- };
823
- const gridLine = useGridLine({
824
- gridAreaHeight,
825
- gridAreaWidth: width,
826
- horizontalLineCount,
827
- verticalLineCount,
828
- color: colorMapRes.grid
829
- });
830
- const horizontalLabel = useHorizontalLabel({
831
- gridAreaHeight,
832
- gridAreaWidth: width,
833
- labelCount: verticalLineCount,
834
- minXLN10,
835
- maxXLN10,
836
- color: colorMapRes.textColor
837
- });
838
- const middleLine = useMiddleLine({
839
- gridAreaHeight,
840
- gridAreaWidth: width,
841
- color: colorMapRes.midPriceLine
842
- });
843
- const {
844
- leftLine,
845
- rightLine
846
- } = useLiquidityLine({
847
- leftStatAreaPoints,
848
- rightStatAreaPoints,
849
- minXLN10,
850
- maxXLN10,
851
- maxLeftHeight,
852
- maxRightHeight,
853
- gridAreaWidth: width,
854
- gridAreaHeight,
855
- colorMap: colorMapRes
856
- });
857
- return /*#__PURE__*/jsxRuntimeExports.jsxs(Stage, {
858
- width: width,
859
- height: height,
860
- onMouseMove: handleMouseover,
861
- onMouseOver: handleMouseover,
862
- onMouseEnter: handleMouseover,
863
- onMouseOut: handleMouseOut,
864
- children: [/*#__PURE__*/jsxRuntimeExports.jsxs(Layer, {
865
- children: [/*#__PURE__*/jsxRuntimeExports.jsx(Rect, {
866
- x: 0,
867
- y: 0,
868
- width: width,
869
- height: gridAreaHeight,
870
- stroke: colorMapRes.grid,
871
- strokeWidth: 1
872
- }), gridLine, horizontalLabel, leftLine, rightLine, middleLine]
873
- }), /*#__PURE__*/jsxRuntimeExports.jsxs(Layer, {
874
- ref: tooltipRef,
875
- visible: false,
876
- children: [/*#__PURE__*/jsxRuntimeExports.jsx(Line, {
877
- points: [],
878
- closed: true,
879
- listening: false,
880
- lineCap: "round",
881
- lineJoin: "round",
882
- id: "area"
883
- }), /*#__PURE__*/jsxRuntimeExports.jsx(Line, {
884
- points: [],
885
- strokeWidth: 1,
886
- stroke: "#ff4f73",
887
- lineJoin: "round",
888
- lineCap: "round",
889
- dash: [4, 6],
890
- id: "toolTipVertLine"
891
- }), /*#__PURE__*/jsxRuntimeExports.jsx(Circle, {
892
- x: 0,
893
- y: 0,
894
- radius: 5,
895
- fill: "#FF5072",
896
- stroke: "rgba(255, 80, 114, 0.3)",
897
- strokeWidth: 12,
898
- id: "joinCircle"
899
- }), /*#__PURE__*/jsxRuntimeExports.jsxs(Label, {
900
- listening: false,
901
- x: 0,
902
- y: 0,
903
- id: "priceTextLabel",
904
- children: [/*#__PURE__*/jsxRuntimeExports.jsx(Tag, {
905
- fill: colorMapRes.tooltipBg,
906
- id: "priceTextLabel-tag"
907
- }), /*#__PURE__*/jsxRuntimeExports.jsx(Text, {
908
- text: "-",
909
- fontSize: 14,
910
- fontFamily: "Manrope",
911
- padding: 2,
912
- fill: "#FF5072",
913
- id: "priceTextLabel-text"
914
- })]
915
- }), /*#__PURE__*/jsxRuntimeExports.jsxs(Label, {
916
- listening: false,
917
- id: "tooltip",
918
- children: [/*#__PURE__*/jsxRuntimeExports.jsx(Tag, {
919
- fill: colorMapRes.tooltipBg,
920
- pointerDirection: "down",
921
- pointerWidth: 15,
922
- pointerHeight: 8,
923
- cornerRadius: 8,
924
- lineJoin: "round",
925
- id: "tooltip-tag"
926
- }), /*#__PURE__*/jsxRuntimeExports.jsx(Text, {
927
- text: "",
928
- fontFamily: "Manrope",
929
- fontSize: 12,
930
- lineHeight: 17 / 12
931
- // width={210}
932
- ,
933
- padding: labelPadding,
934
- fill: "#FF5072",
935
- id: "tooltip-Text"
936
- })]
937
- })]
938
- })]
939
- });
940
- }
941
-
942
- const LiquidityChart = ({
943
- width = 834,
944
- height = 462,
945
- baseTokenSymbol,
946
- quoteTokenSymbol,
947
- pmmModel,
948
- pmmParams,
949
- midPrice,
950
- notShowTipText,
951
- colorMap
952
- }) => {
953
- return /*#__PURE__*/jsxRuntimeExports.jsxs(Container, {
954
- children: [pmmParams !== undefined && midPrice !== undefined && pmmModel !== undefined && midPrice !== undefined && /*#__PURE__*/jsxRuntimeExports.jsx(LiquidityChartKonva, {
955
- width: width,
956
- height: height,
957
- params: pmmParams,
958
- midPrice: midPrice,
959
- pmmModel: pmmModel,
960
- baseTokenSymbol: baseTokenSymbol,
961
- quoteTokenSymbol: quoteTokenSymbol,
962
- colorMap: colorMap
963
- }), !notShowTipText ? /*#__PURE__*/jsxRuntimeExports.jsxs(TipWrapper, {
964
- children: ["*\xA0", chartT('pool.chart.liquidity-chart-tip', {
965
- baseTokenSymbol
966
- })]
967
- }) : '']
968
- });
969
- };
970
-
971
- export { LiquidityChart as default };