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