@dodoex/widgets 3.0.2-zetachain.10 → 3.0.2-zetachain.12
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.
- package/dist/helper-BnoyRpeK.cjs +561 -0
- package/dist/helper-BnoyRpeK.cjs.map +1 -0
- package/dist/helper-CMiEdcFd.js +545 -0
- package/dist/index-B-5Qs8z3.cjs +1212 -0
- package/dist/index-B-5Qs8z3.cjs.map +1 -0
- package/dist/index-COcquHWW.cjs +974 -0
- package/dist/index-COcquHWW.cjs.map +1 -0
- package/dist/index-CwQNn_Bp.js +1209 -0
- package/dist/index-De8Sa6Av.cjs +96076 -0
- package/dist/index-De8Sa6Av.cjs.map +1 -0
- package/dist/index-bUI_7SKV.js +96014 -0
- package/dist/index-s8jAQFVo.js +971 -0
- package/dist/index.cjs +91 -1
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +37 -1
- package/dist/types/hooks/ConnectWallet/useWalletInfo.d.ts +3 -1
- package/package.json +7 -17
- package/dist/helper-B-L9J5Wk.js +0 -1
- package/dist/helper-DB7pJRlV.cjs +0 -1
- package/dist/index-BGkMyf0r.cjs +0 -78
- package/dist/index-BYYZxbt3.js +0 -263
- package/dist/index-CbzpdArY.cjs +0 -263
- package/dist/index-CnswmG4u.cjs +0 -12
- package/dist/index-D54mvRoh.js +0 -78
- package/dist/index-D8Yofu94.js +0 -12
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
import { i18n } from '@lingui/core';
|
|
2
|
+
import BigNumber from 'bignumber.js';
|
|
3
|
+
import { f as formatShortNumber } from './index-bUI_7SKV.js';
|
|
4
|
+
|
|
5
|
+
// \{\{([A-Za-z]+)\}\} to ${params.$1}
|
|
6
|
+
function chartT(key, params) {
|
|
7
|
+
switch (key) {
|
|
8
|
+
case 'depth-chart.tips.buy':
|
|
9
|
+
return i18n._(
|
|
10
|
+
/*i18n*/
|
|
11
|
+
{
|
|
12
|
+
id: "q+Q952",
|
|
13
|
+
message: "Users pay {0} {1} and receive {2} {3}\\nPrice {4} ({5}%)",
|
|
14
|
+
values: {
|
|
15
|
+
0: params.amountText,
|
|
16
|
+
1: params.baseTokenSymbol,
|
|
17
|
+
2: params.oppositeAmountText,
|
|
18
|
+
3: params.quoteTokenSymbol,
|
|
19
|
+
4: params.priceText,
|
|
20
|
+
5: params.slippageText
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
case 'depth-chart.tips.mid-price':
|
|
24
|
+
return i18n._(
|
|
25
|
+
/*i18n*/
|
|
26
|
+
{
|
|
27
|
+
id: "cnbRVW",
|
|
28
|
+
message: "Initial Price {0} {1} = {2} {3}",
|
|
29
|
+
values: {
|
|
30
|
+
0: params.amountText,
|
|
31
|
+
1: params.baseTokenSymbol,
|
|
32
|
+
2: params.oppositeAmountText,
|
|
33
|
+
3: params.quoteTokenSymbol
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
case 'depth-chart.tips.sell':
|
|
37
|
+
return i18n._(
|
|
38
|
+
/*i18n*/
|
|
39
|
+
{
|
|
40
|
+
id: "q+Q952",
|
|
41
|
+
message: "Users pay {0} {1} and receive {2} {3}\\nPrice {4} ({5}%)",
|
|
42
|
+
values: {
|
|
43
|
+
0: params.oppositeAmountText,
|
|
44
|
+
1: params.quoteTokenSymbol,
|
|
45
|
+
2: params.amountText,
|
|
46
|
+
3: params.baseTokenSymbol,
|
|
47
|
+
4: params.priceText,
|
|
48
|
+
5: params.slippageText
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
case 'pool.chart.buy-amount':
|
|
52
|
+
return i18n._(
|
|
53
|
+
/*i18n*/
|
|
54
|
+
{
|
|
55
|
+
id: "TaScUS",
|
|
56
|
+
message: "Users sell {0} amount:",
|
|
57
|
+
values: {
|
|
58
|
+
0: params.symbol
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
case 'pool.chart.price-impact':
|
|
62
|
+
return i18n._(
|
|
63
|
+
/*i18n*/
|
|
64
|
+
{
|
|
65
|
+
id: "I0LXan",
|
|
66
|
+
message: "Price Impact: {0}",
|
|
67
|
+
values: {
|
|
68
|
+
0: params.amount
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
case 'pool.chart.sell-amount':
|
|
72
|
+
return i18n._(
|
|
73
|
+
/*i18n*/
|
|
74
|
+
{
|
|
75
|
+
id: "F2vX4t",
|
|
76
|
+
message: "Users buy {0} amount:",
|
|
77
|
+
values: {
|
|
78
|
+
0: params.symbol
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
case 'pool.create.disabled-token-amount':
|
|
82
|
+
return i18n._(
|
|
83
|
+
/*i18n*/
|
|
84
|
+
{
|
|
85
|
+
id: "5QDjef",
|
|
86
|
+
message: "The token amount is calculated by initial price."
|
|
87
|
+
});
|
|
88
|
+
case 'pool.create.set-pool.emulator.title':
|
|
89
|
+
return i18n._(
|
|
90
|
+
/*i18n*/
|
|
91
|
+
{
|
|
92
|
+
id: "FQfStS",
|
|
93
|
+
message: "Emulator"
|
|
94
|
+
});
|
|
95
|
+
case 'pool.create.set-pool.emulator.title.question':
|
|
96
|
+
return i18n._(
|
|
97
|
+
/*i18n*/
|
|
98
|
+
{
|
|
99
|
+
id: "9D2g7k",
|
|
100
|
+
message: "The liquidity of DODO is continuous, which is different from the discrete liquidity of UniV3. The ticks shown in the illustration are for demonstration purposes only."
|
|
101
|
+
});
|
|
102
|
+
// liquidity-chart
|
|
103
|
+
case 'pool.chart.liquidity-chart-tip':
|
|
104
|
+
return i18n._(
|
|
105
|
+
/*i18n*/
|
|
106
|
+
{
|
|
107
|
+
id: "YvXHDU",
|
|
108
|
+
message: "The area of the chart indicates the buy/sell volume of {0} that can be carried by the market when the current price changes to the hover price.",
|
|
109
|
+
values: {
|
|
110
|
+
0: params.baseTokenSymbol
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
case 'pool.chart.liquidity-chart-buy':
|
|
114
|
+
return i18n._(
|
|
115
|
+
/*i18n*/
|
|
116
|
+
{
|
|
117
|
+
id: "TvH4Ym",
|
|
118
|
+
message: "Bought {0} {1}, price in the pool decreased to {2}",
|
|
119
|
+
values: {
|
|
120
|
+
0: params.amount,
|
|
121
|
+
1: params.symbol,
|
|
122
|
+
2: params.price
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
case 'pool.chart.liquidity-chart-sell':
|
|
126
|
+
return i18n._(
|
|
127
|
+
/*i18n*/
|
|
128
|
+
{
|
|
129
|
+
id: "0O1wzf",
|
|
130
|
+
message: "Traders sold \u202A{0}\u202C {1}, price in the pool increased to {2}",
|
|
131
|
+
values: {
|
|
132
|
+
0: params.amount,
|
|
133
|
+
1: params.symbol,
|
|
134
|
+
2: params.price
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
default:
|
|
138
|
+
throw new Error(`Unknown key ${key}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const labelPadding = 12;
|
|
143
|
+
// The distance between toolTip and the top of the column
|
|
144
|
+
const toolTipMarginBottom = 6;
|
|
145
|
+
// Since toolTip exceeds part of the drawing area, additional padding is required
|
|
146
|
+
const chartOffsetYBCToolTip = labelPadding + toolTipMarginBottom;
|
|
147
|
+
|
|
148
|
+
function colorRgb(str) {
|
|
149
|
+
let sColor = str.toLowerCase();
|
|
150
|
+
// Regular expression for hexadecimal color values
|
|
151
|
+
const reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
|
|
152
|
+
// If it is a hexadecimal color
|
|
153
|
+
if (sColor && reg.test(sColor)) {
|
|
154
|
+
if (sColor.length === 4) {
|
|
155
|
+
let sColorNew = '#';
|
|
156
|
+
for (let i = 1; i < 4; i += 1) {
|
|
157
|
+
sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1));
|
|
158
|
+
}
|
|
159
|
+
sColor = sColorNew;
|
|
160
|
+
}
|
|
161
|
+
// Handle six-bit color values
|
|
162
|
+
const sColorChange = [];
|
|
163
|
+
for (let i = 1; i < 7; i += 2) {
|
|
164
|
+
sColorChange.push(parseInt(`0x${sColor.slice(i, i + 2)}`));
|
|
165
|
+
}
|
|
166
|
+
return sColorChange.join(',');
|
|
167
|
+
}
|
|
168
|
+
return sColor;
|
|
169
|
+
}
|
|
170
|
+
function evalPoint({
|
|
171
|
+
val,
|
|
172
|
+
model
|
|
173
|
+
}) {
|
|
174
|
+
let v = val;
|
|
175
|
+
if (val.isNaN()) {
|
|
176
|
+
return {
|
|
177
|
+
side: 'no-one',
|
|
178
|
+
vert: new BigNumber(0),
|
|
179
|
+
base: new BigNumber(0),
|
|
180
|
+
quote: new BigNumber(0)
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
// If Q0=0, the minimum value of the abscissa must be greater than or equal to i. If the abscissa input is less than i, the vertical axis value when the abscissa is i is returned.
|
|
184
|
+
// If B0=0, the maximum value of the abscissa must be less than or equal to i. If the abscissa input is greater than i, the vertical axis value when the abscissa is i is returned.
|
|
185
|
+
if (model.Q0.eq(0) && val.lt(model.i)) {
|
|
186
|
+
v = model.i;
|
|
187
|
+
}
|
|
188
|
+
if (model.B0.eq(0) && val.gt(model.i)) {
|
|
189
|
+
v = model.i;
|
|
190
|
+
}
|
|
191
|
+
const resp = model.getPriceDepth(v);
|
|
192
|
+
const base = resp.baseAmount;
|
|
193
|
+
const quote = resp.quoteAmount;
|
|
194
|
+
const {
|
|
195
|
+
isBuy
|
|
196
|
+
} = resp;
|
|
197
|
+
return {
|
|
198
|
+
side: isBuy ? 'ask' : 'bid',
|
|
199
|
+
// vert: isBuy ? base.multipliedBy(midPrice) : quote,
|
|
200
|
+
vert: isBuy ? base : quote,
|
|
201
|
+
base,
|
|
202
|
+
quote
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Returns two vertical coordinates, buyBaseVert on the left and sellBaseVert on the right.
|
|
207
|
+
* @param param0
|
|
208
|
+
*/
|
|
209
|
+
function computeBaseVert({
|
|
210
|
+
midPrice,
|
|
211
|
+
q,
|
|
212
|
+
q0,
|
|
213
|
+
pmmModel
|
|
214
|
+
}) {
|
|
215
|
+
let baseVert = BigNumber.maximum(q, q0, pmmModel.B.multipliedBy(midPrice));
|
|
216
|
+
// Special handling to avoid exceptions
|
|
217
|
+
if (baseVert.isNaN()) {
|
|
218
|
+
baseVert = new BigNumber(10);
|
|
219
|
+
}
|
|
220
|
+
if (baseVert.eq(0)) {
|
|
221
|
+
baseVert = new BigNumber(1);
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
buyBaseVert: baseVert.multipliedBy(1.2),
|
|
225
|
+
sellBaseVert: baseVert.div(midPrice).multipliedBy(1.2)
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* // 1000/800 The price represented by one pixel
|
|
230
|
+
// Maximum value on the right side of the middle price = middle price * 10 = middle price * 10^1
|
|
231
|
+
// Calculate the x-axis coordinate (price): middle price*10^(xPortion*x)+middle price; x is the number of equal parts that divide the right half into 50 parts
|
|
232
|
+
* @param chartWidth icon width
|
|
233
|
+
* @param zoomMultiples magnification factors
|
|
234
|
+
* @returns
|
|
235
|
+
*/
|
|
236
|
+
function computeXPortion(chartWidth, zoomMultiples = 1) {
|
|
237
|
+
return new BigNumber(zoomMultiples).div(chartWidth / 2);
|
|
238
|
+
}
|
|
239
|
+
function updateTooltip({
|
|
240
|
+
tooltip,
|
|
241
|
+
x,
|
|
242
|
+
chartWidth,
|
|
243
|
+
chartHeight,
|
|
244
|
+
buyBaseVert,
|
|
245
|
+
sellBaseVert,
|
|
246
|
+
pmmModel,
|
|
247
|
+
midPrice,
|
|
248
|
+
baseTokenSymbol,
|
|
249
|
+
quoteTokenSymbol,
|
|
250
|
+
t,
|
|
251
|
+
baseMinAndZoomMultiples,
|
|
252
|
+
isHover,
|
|
253
|
+
color,
|
|
254
|
+
leftColor,
|
|
255
|
+
rightColor
|
|
256
|
+
}) {
|
|
257
|
+
const {
|
|
258
|
+
zoomMultiples,
|
|
259
|
+
baseMin
|
|
260
|
+
} = baseMinAndZoomMultiples;
|
|
261
|
+
const xPortion = computeXPortion(chartWidth, zoomMultiples);
|
|
262
|
+
const buyYPortion = buyBaseVert.div(chartHeight);
|
|
263
|
+
const sellYPortion = sellBaseVert.div(chartHeight);
|
|
264
|
+
const multiplesNum = zoomMultiples * 2;
|
|
265
|
+
const price = baseMin.multipliedBy(10 ** xPortion.multipliedBy(x).toNumber());
|
|
266
|
+
let midPriceN = new BigNumber(Math.log(midPrice.div(baseMin).toNumber()) / Math.log(10));
|
|
267
|
+
midPriceN = BigNumber.minimum(multiplesNum, midPriceN);
|
|
268
|
+
midPriceN = BigNumber.maximum(0, midPriceN);
|
|
269
|
+
const xMidPrice = midPriceN.div(xPortion);
|
|
270
|
+
const result = evalPoint({
|
|
271
|
+
val: price,
|
|
272
|
+
model: pmmModel,
|
|
273
|
+
midPrice
|
|
274
|
+
});
|
|
275
|
+
if (result.vert.isNaN()) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const isQuote = price.lt(midPrice);
|
|
279
|
+
let yy = chartHeight - result.vert.div(buyYPortion).toNumber();
|
|
280
|
+
if (!isQuote) {
|
|
281
|
+
yy = chartHeight - result.vert.div(sellYPortion).toNumber();
|
|
282
|
+
}
|
|
283
|
+
const priceText = formatShortNumber(price);
|
|
284
|
+
const amountText = formatShortNumber(result.vert);
|
|
285
|
+
const slippageText = price.minus(midPrice).abs().div(midPrice).multipliedBy(100).toFixed(2);
|
|
286
|
+
const xMidPriceText = xMidPrice.toNumber();
|
|
287
|
+
const toolTipVertLine = tooltip.findOne('#toolTipVertLine');
|
|
288
|
+
const toolTipHoriLine = tooltip.findOne('#toolTipHoriLine');
|
|
289
|
+
const joinCircle = tooltip.findOne('#joinCircle');
|
|
290
|
+
const tooltipLabel = tooltip.findOne('#toolTip');
|
|
291
|
+
const priceTextLabel = tooltip.findOne('#priceTextLabel');
|
|
292
|
+
const slippageTextLabel = tooltip.findOne('#slippageTextLabel');
|
|
293
|
+
if (!tooltipLabel) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
tooltipLabel.x(x);
|
|
297
|
+
// yy + radius of intersection circle + border of intersection circle
|
|
298
|
+
tooltipLabel.y(yy - 5 - 6);
|
|
299
|
+
const toolTipText = tooltipLabel.getText();
|
|
300
|
+
const toolTipTag = tooltipLabel.getTag();
|
|
301
|
+
let oppositeAmountText = result.side === 'ask' ? formatShortNumber(result.quote) : formatShortNumber(result.base);
|
|
302
|
+
const isZeroK = pmmModel.k.lte(0);
|
|
303
|
+
if (isZeroK) {
|
|
304
|
+
oppositeAmountText = amountText;
|
|
305
|
+
}
|
|
306
|
+
const midPriceText = formatShortNumber(midPrice);
|
|
307
|
+
const tipTextParams = {
|
|
308
|
+
amountText,
|
|
309
|
+
baseTokenSymbol,
|
|
310
|
+
oppositeAmountText,
|
|
311
|
+
quoteTokenSymbol,
|
|
312
|
+
priceText: isZeroK ? midPriceText : priceText,
|
|
313
|
+
slippageText: `${isQuote ? '-' : '+'}${slippageText}`
|
|
314
|
+
};
|
|
315
|
+
if (xMidPrice.minus(4).lte(x) && xMidPrice.plus(2).gte(x) && isHover) {
|
|
316
|
+
// midPrice hover
|
|
317
|
+
toolTipText.text(t('depth-chart.tips.mid-price', {
|
|
318
|
+
amountText: 1,
|
|
319
|
+
baseTokenSymbol,
|
|
320
|
+
oppositeAmountText: midPriceText,
|
|
321
|
+
quoteTokenSymbol
|
|
322
|
+
}));
|
|
323
|
+
tooltipLabel.x(xMidPriceText);
|
|
324
|
+
tooltipLabel.y(chartHeight / 2);
|
|
325
|
+
toolTipVertLine === null || toolTipVertLine === void 0 ? void 0 : toolTipVertLine.hide();
|
|
326
|
+
toolTipHoriLine === null || toolTipHoriLine === void 0 ? void 0 : toolTipHoriLine.hide();
|
|
327
|
+
joinCircle === null || joinCircle === void 0 ? void 0 : joinCircle.hide();
|
|
328
|
+
priceTextLabel === null || priceTextLabel === void 0 ? void 0 : priceTextLabel.hide();
|
|
329
|
+
slippageTextLabel === null || slippageTextLabel === void 0 ? void 0 : slippageTextLabel.hide();
|
|
330
|
+
} else {
|
|
331
|
+
toolTipText.text(isQuote ? t('depth-chart.tips.buy', {
|
|
332
|
+
amountText: oppositeAmountText,
|
|
333
|
+
baseTokenSymbol,
|
|
334
|
+
oppositeAmountText: amountText,
|
|
335
|
+
quoteTokenSymbol,
|
|
336
|
+
priceText: isZeroK ? midPriceText : priceText,
|
|
337
|
+
slippageText: `${isQuote ? '-' : '+'}${slippageText}`
|
|
338
|
+
}) : t('depth-chart.tips.sell', tipTextParams));
|
|
339
|
+
const textColor = color || (isQuote ? '#55f6db' : '#ff4f73');
|
|
340
|
+
const lineColor = isQuote ? leftColor || '#55f6db' : rightColor || '#ff4f73';
|
|
341
|
+
toolTipText.fill(textColor);
|
|
342
|
+
if (tooltipLabel.width() / 2 > x) {
|
|
343
|
+
toolTipTag.pointerDirection('left');
|
|
344
|
+
toolTipTag.pointerHeight(15);
|
|
345
|
+
toolTipTag.pointerWidth(8);
|
|
346
|
+
tooltipLabel.offsetX(-(5 + 6));
|
|
347
|
+
tooltipLabel.offsetY(-(5 + 6));
|
|
348
|
+
} else if (tooltipLabel.width() / 2 + x > chartWidth) {
|
|
349
|
+
toolTipTag.pointerDirection('right');
|
|
350
|
+
toolTipTag.pointerHeight(15);
|
|
351
|
+
toolTipTag.pointerWidth(8);
|
|
352
|
+
tooltipLabel.offsetX(5 + 6);
|
|
353
|
+
tooltipLabel.offsetY(-(5 + 6));
|
|
354
|
+
} else {
|
|
355
|
+
// @ts-ignore
|
|
356
|
+
toolTipTag.pointerDirection('down');
|
|
357
|
+
toolTipTag.pointerHeight(8);
|
|
358
|
+
toolTipTag.pointerWidth(15);
|
|
359
|
+
tooltipLabel.offsetX(0);
|
|
360
|
+
tooltipLabel.offsetY(0);
|
|
361
|
+
}
|
|
362
|
+
toolTipVertLine === null || toolTipVertLine === void 0 ? void 0 : toolTipVertLine.points([x, chartHeight, x, yy]);
|
|
363
|
+
toolTipVertLine === null || toolTipVertLine === void 0 ? void 0 : toolTipVertLine.stroke(lineColor);
|
|
364
|
+
toolTipHoriLine === null || toolTipHoriLine === void 0 ? void 0 : toolTipHoriLine.points(isQuote ? [x, yy, xMidPriceText, yy] : [xMidPriceText, yy, x, yy]);
|
|
365
|
+
toolTipHoriLine === null || toolTipHoriLine === void 0 ? void 0 : toolTipHoriLine.stroke(lineColor);
|
|
366
|
+
joinCircle === null || joinCircle === void 0 ? void 0 : joinCircle.x(x);
|
|
367
|
+
joinCircle === null || joinCircle === void 0 ? void 0 : joinCircle.y(yy);
|
|
368
|
+
joinCircle === null || joinCircle === void 0 ? void 0 : joinCircle.fill(isQuote ? leftColor || 'rgb(86, 246, 218)' : rightColor || '#FF5072');
|
|
369
|
+
joinCircle === null || joinCircle === void 0 ? void 0 : joinCircle.stroke(
|
|
370
|
+
// eslint-disable-next-line no-nested-ternary
|
|
371
|
+
isQuote ? leftColor ? `rgba(${colorRgb(leftColor)}, 0.4)` : 'rgba(86, 246, 218, 0.3)' : rightColor ? `rgba(${colorRgb(rightColor)}, 0.4)` : 'rgba(255, 80, 114, 0.3)');
|
|
372
|
+
if (priceTextLabel) {
|
|
373
|
+
priceTextLabel.x(x);
|
|
374
|
+
priceTextLabel.y(chartHeight);
|
|
375
|
+
priceTextLabel.offsetX(priceTextLabel.width() / 2);
|
|
376
|
+
if (priceTextLabel.x() - priceTextLabel.width() / 2 < 0) {
|
|
377
|
+
priceTextLabel.x(priceTextLabel.width() / 2);
|
|
378
|
+
} else if (priceTextLabel.x() + priceTextLabel.width() / 2 > chartWidth) {
|
|
379
|
+
priceTextLabel.x(chartWidth - priceTextLabel.width() / 2);
|
|
380
|
+
} else {
|
|
381
|
+
priceTextLabel.x(x);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
const priceTextLabelText = priceTextLabel === null || priceTextLabel === void 0 ? void 0 : priceTextLabel.findOne('#priceTextLabel-text');
|
|
385
|
+
if (priceTextLabelText) {
|
|
386
|
+
priceTextLabelText.fill(textColor);
|
|
387
|
+
priceTextLabelText.text(priceText);
|
|
388
|
+
}
|
|
389
|
+
if (slippageTextLabel) {
|
|
390
|
+
slippageTextLabel.x(isQuote ? x + (xMidPriceText - x) / 2 : x - (x - xMidPriceText) / 2);
|
|
391
|
+
slippageTextLabel.y(yy);
|
|
392
|
+
slippageTextLabel.offsetY(slippageTextLabel.height() / 2);
|
|
393
|
+
slippageTextLabel.offsetX(slippageTextLabel.width() / 2);
|
|
394
|
+
}
|
|
395
|
+
const slippageTextLabelText = slippageTextLabel === null || slippageTextLabel === void 0 ? void 0 : slippageTextLabel.findOne('#slippageTextLabel-text');
|
|
396
|
+
if (slippageTextLabelText) {
|
|
397
|
+
slippageTextLabelText.fill(textColor);
|
|
398
|
+
slippageTextLabelText.text(`${isQuote ? '-' : '+'}${slippageText}%`);
|
|
399
|
+
}
|
|
400
|
+
toolTipVertLine === null || toolTipVertLine === void 0 ? void 0 : toolTipVertLine.show();
|
|
401
|
+
toolTipHoriLine === null || toolTipHoriLine === void 0 ? void 0 : toolTipHoriLine.show();
|
|
402
|
+
joinCircle === null || joinCircle === void 0 ? void 0 : joinCircle.show();
|
|
403
|
+
priceTextLabel === null || priceTextLabel === void 0 ? void 0 : priceTextLabel.show();
|
|
404
|
+
slippageTextLabel === null || slippageTextLabel === void 0 ? void 0 : slippageTextLabel.show();
|
|
405
|
+
}
|
|
406
|
+
tooltip.show();
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Calculate the minimum value on the left by pulling distance or button click
|
|
410
|
+
*/
|
|
411
|
+
function computeBaseMinByDistance({
|
|
412
|
+
dragDistance,
|
|
413
|
+
prevBaseMin,
|
|
414
|
+
chartWidth,
|
|
415
|
+
zoomMultiples
|
|
416
|
+
}) {
|
|
417
|
+
const xPortion = computeXPortion(chartWidth, zoomMultiples);
|
|
418
|
+
if (dragDistance > 0) {
|
|
419
|
+
return prevBaseMin.multipliedBy(10 ** 0 - xPortion.multipliedBy(dragDistance).toNumber());
|
|
420
|
+
}
|
|
421
|
+
return prevBaseMin.multipliedBy(10 ** xPortion.multipliedBy(new BigNumber(dragDistance).abs()).plus(0).toNumber());
|
|
422
|
+
}
|
|
423
|
+
const baseZoomMultiples = 1;
|
|
424
|
+
function computeZoomMultiplesWhenZoom({
|
|
425
|
+
prevZoomMultiples,
|
|
426
|
+
zoomIn
|
|
427
|
+
}) {
|
|
428
|
+
if (!zoomIn) {
|
|
429
|
+
if (prevZoomMultiples <= baseZoomMultiples * 0.1) {
|
|
430
|
+
return prevZoomMultiples;
|
|
431
|
+
}
|
|
432
|
+
// The reduction ratio cannot exceed 0.001
|
|
433
|
+
// if (prevZoomMultiples <= baseZoomMultiples * 0.1) {
|
|
434
|
+
// if (prevZoomMultiples <= baseZoomMultiples * 0.01) {
|
|
435
|
+
// if (prevZoomMultiples === baseZoomMultiples * 0.001) {
|
|
436
|
+
// return prevZoomMultiples;
|
|
437
|
+
// }
|
|
438
|
+
// return prevZoomMultiples - baseZoomMultiples * 0.001;
|
|
439
|
+
// }
|
|
440
|
+
// return prevZoomMultiples - baseZoomMultiples * 0.01;
|
|
441
|
+
// }
|
|
442
|
+
}
|
|
443
|
+
return zoomIn ? prevZoomMultiples + baseZoomMultiples * 0.1 : prevZoomMultiples - baseZoomMultiples * 0.1;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Given a price target corresponding to the abscissa, calculate the abscissa of the point
|
|
447
|
+
* The buying impact point is at the left 1/4 position
|
|
448
|
+
* The selling impact point is 3/4 on the right
|
|
449
|
+
*
|
|
450
|
+
* Returns a coordinate point, baseMin and zoomMultiples
|
|
451
|
+
*
|
|
452
|
+
* Take the initial state as the starting point, that is, midPrice * 10 ^ -1 as the starting point of the horizontal axis, and it is a left-right symmetrical state, that is, the logarithm of the horizontal axis is from -1 -> 0 -> 1
|
|
453
|
+
*
|
|
454
|
+
* type === 'sell'
|
|
455
|
+
* targetPrice = midPrice * 10 ^ n
|
|
456
|
+
* n = Math.log10(targetPrice / midPrice)
|
|
457
|
+
* n = maxN * (3 / 4)
|
|
458
|
+
*
|
|
459
|
+
* If the new price is within the existing range, the zoom factor will not be adjusted (the price impact will not change the shape of the graph after graph scaling or translation)
|
|
460
|
+
* If it is not within the current interval, check whether it is midPrice * 10 ^-1 and midPrice * 10^1. If you still do not adjust the zoom factor, hit the specified point directly, otherwise you need to adjust the zoom factor (avoid inputting extremely small values) The value cannot be scaled to the specified range, resulting in stuck)
|
|
461
|
+
*/
|
|
462
|
+
function computeTargetXByTargetPrice({
|
|
463
|
+
type,
|
|
464
|
+
targetPrice,
|
|
465
|
+
midPrice,
|
|
466
|
+
width
|
|
467
|
+
}) {
|
|
468
|
+
if (type === 'sell') {
|
|
469
|
+
const n = new BigNumber(Math.log10(targetPrice.div(midPrice).toNumber()));
|
|
470
|
+
const maxN = n.minus(0).div(3 / 4).abs();
|
|
471
|
+
const zoomMultiples = maxN;
|
|
472
|
+
return {
|
|
473
|
+
zoomMultiples,
|
|
474
|
+
targetX: width / 2 * (3 / 4) + width / 2
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
const n = new BigNumber(Math.log10(targetPrice.div(midPrice).toNumber()));
|
|
478
|
+
const maxN = new BigNumber(0).minus(n).div(3 / 4).abs();
|
|
479
|
+
const zoomMultiples = maxN;
|
|
480
|
+
return {
|
|
481
|
+
zoomMultiples,
|
|
482
|
+
targetX: width / 2 * (1 / 4)
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* If the new price is within the existing range, the zoom factor will not be adjusted (the price impact will not change the shape of the graph after graph scaling or translation)
|
|
487
|
+
* If it is not within the current interval, check whether it is midPrice * 10 ^-1 and midPrice * 10^1. If it is within the range, adjust the zoom factor to 1, and then impact to the specified point, otherwise you need to adjust the zoom factor ( Avoid entering extremely small values that may result in inability to scale to the specified range and cause stucks)
|
|
488
|
+
*
|
|
489
|
+
* Returns an abscissa and a flag indicating whether to skip
|
|
490
|
+
*/
|
|
491
|
+
function beforePriceImpactEffect({
|
|
492
|
+
currentBaseMinAndZoomMultiples,
|
|
493
|
+
targetPrice,
|
|
494
|
+
midPrice,
|
|
495
|
+
width
|
|
496
|
+
}) {
|
|
497
|
+
const {
|
|
498
|
+
baseMin,
|
|
499
|
+
zoomMultiples
|
|
500
|
+
} = currentBaseMinAndZoomMultiples;
|
|
501
|
+
const minN = new BigNumber(Math.log10(baseMin.div(midPrice).toNumber()));
|
|
502
|
+
const maxN = minN.plus(zoomMultiples * 2);
|
|
503
|
+
// price maximum
|
|
504
|
+
const baseMax = new BigNumber(midPrice.multipliedBy(10 ** maxN.toNumber()));
|
|
505
|
+
if (targetPrice.gte(baseMin) && targetPrice.lte(baseMax)) {
|
|
506
|
+
const n = new BigNumber(Math.log10(targetPrice.div(midPrice).toNumber()));
|
|
507
|
+
const targetX = n.minus(minN).div(zoomMultiples * 2).multipliedBy(width).toNumber();
|
|
508
|
+
return {
|
|
509
|
+
isSkip: true,
|
|
510
|
+
targetX,
|
|
511
|
+
baseMin: new BigNumber(0),
|
|
512
|
+
zoomMultiples: baseZoomMultiples
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
// 是否在 midPrice 范围内
|
|
516
|
+
const defaultBaseMin = new BigNumber(midPrice.multipliedBy(10 ** -baseZoomMultiples));
|
|
517
|
+
const defaultBaseMax = new BigNumber(midPrice.multipliedBy(10 ** baseZoomMultiples));
|
|
518
|
+
if (targetPrice.gte(defaultBaseMin) && targetPrice.lte(defaultBaseMax)) {
|
|
519
|
+
const n = new BigNumber(Math.log10(targetPrice.div(midPrice).toNumber()));
|
|
520
|
+
const targetX = n.minus(-baseZoomMultiples).div(baseZoomMultiples * 2).multipliedBy(width).toNumber();
|
|
521
|
+
return {
|
|
522
|
+
isSkip: false,
|
|
523
|
+
targetX,
|
|
524
|
+
baseMin: defaultBaseMin,
|
|
525
|
+
zoomMultiples: baseZoomMultiples
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
return {
|
|
529
|
+
isSkip: false,
|
|
530
|
+
targetX: -1,
|
|
531
|
+
baseMin: new BigNumber(0),
|
|
532
|
+
zoomMultiples: baseZoomMultiples
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Recalculate baseMin after the zoom factor changes
|
|
537
|
+
*/
|
|
538
|
+
function computeBaseAfterZoom({
|
|
539
|
+
midPrice,
|
|
540
|
+
zoomMultiples
|
|
541
|
+
}) {
|
|
542
|
+
return midPrice.multipliedBy(10 ** -zoomMultiples);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
export { computeBaseVert as a, computeBaseMinByDistance as b, computeXPortion as c, computeZoomMultiplesWhenZoom as d, evalPoint as e, computeBaseAfterZoom as f, chartT as g, chartOffsetYBCToolTip as h, baseZoomMultiples as i, beforePriceImpactEffect as j, computeTargetXByTargetPrice as k, labelPadding as l, colorRgb as m, updateTooltip as u };
|