@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.
- package/dist/helper-D5WuMQeC.cjs +1 -0
- package/dist/helper-DBpkATiS.js +1 -0
- package/dist/index-8oDXDMeV.js +12 -0
- package/dist/index-BOZ8b_SW.js +31 -0
- package/dist/index-DFE7Pd1Q.js +78 -0
- package/dist/index-Dpn4Koa2.cjs +31 -0
- package/dist/index-avbL_P0k.cjs +78 -0
- package/dist/index-xUlJTfVL.cjs +12 -0
- package/dist/index.cjs +1 -91
- package/dist/index.js +1 -37
- package/dist/types/hooks/ConnectWallet/useWalletInfo.d.ts +1 -3
- package/package.json +7 -7
- package/dist/helper-BnoyRpeK.cjs +0 -561
- package/dist/helper-BnoyRpeK.cjs.map +0 -1
- package/dist/helper-CMiEdcFd.js +0 -545
- package/dist/index-B-5Qs8z3.cjs +0 -1212
- package/dist/index-B-5Qs8z3.cjs.map +0 -1
- package/dist/index-COcquHWW.cjs +0 -974
- package/dist/index-COcquHWW.cjs.map +0 -1
- package/dist/index-CwQNn_Bp.js +0 -1209
- package/dist/index-De8Sa6Av.cjs +0 -96076
- package/dist/index-De8Sa6Av.cjs.map +0 -1
- package/dist/index-bUI_7SKV.js +0 -96014
- package/dist/index-s8jAQFVo.js +0 -971
- package/dist/index.cjs.map +0 -1
package/dist/index-CwQNn_Bp.js
DELETED
|
@@ -1,1209 +0,0 @@
|
|
|
1
|
-
import BigNumber from 'bignumber.js';
|
|
2
|
-
import { merge, throttle, debounce } from 'lodash';
|
|
3
|
-
import React__default, { useEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
-
import styled from '@emotion/styled';
|
|
5
|
-
import { css } from '@emotion/react';
|
|
6
|
-
import { Stage, Layer, Rect, Line, Text, Circle, Label, Tag } from 'react-konva';
|
|
7
|
-
import { c as computeXPortion, e as evalPoint, a as computeBaseVert, b as computeBaseMinByDistance, d as computeZoomMultiplesWhenZoom, f as computeBaseAfterZoom, u as updateTooltip, g as chartT, h as chartOffsetYBCToolTip, l as labelPadding, i as baseZoomMultiples, j as beforePriceImpactEffect, k as computeTargetXByTargetPrice } from './helper-CMiEdcFd.js';
|
|
8
|
-
import { f as formatShortNumber, j as jsxRuntimeExports, a as formatPercentageNumber, b as fixedInputStringToFormattedNumber } from './index-bUI_7SKV.js';
|
|
9
|
-
import { solveQuadraticFunctionForTarget, PMMModel } from '@dodoex/api';
|
|
10
|
-
import '@lingui/core';
|
|
11
|
-
import '@lingui/react';
|
|
12
|
-
import '@dodoex/components';
|
|
13
|
-
import '@web3-react/core';
|
|
14
|
-
import 'axios';
|
|
15
|
-
import '@ethersproject/bignumber';
|
|
16
|
-
import 'zustand';
|
|
17
|
-
import '@dodoex/dodo-contract-request';
|
|
18
|
-
import '@tanstack/react-query';
|
|
19
|
-
import 'pino';
|
|
20
|
-
import 'events';
|
|
21
|
-
import 'node-fetch';
|
|
22
|
-
import '@web3-react/eip1193';
|
|
23
|
-
import '@web3-react/walletconnect-v2';
|
|
24
|
-
import '@web3-react/metamask';
|
|
25
|
-
import '@web3-react/types';
|
|
26
|
-
import '@ethersproject/contracts';
|
|
27
|
-
import 'identicon.js';
|
|
28
|
-
import 'react-dom';
|
|
29
|
-
import 'dayjs';
|
|
30
|
-
import 'react-transition-group';
|
|
31
|
-
import '@dodoex/contract-request';
|
|
32
|
-
import 'recharts';
|
|
33
|
-
import 'react-window';
|
|
34
|
-
import 'jsbi';
|
|
35
|
-
import 'tiny-invariant';
|
|
36
|
-
import '@ethersproject/units';
|
|
37
|
-
import '@uniswap/sdk-core';
|
|
38
|
-
import '@uniswap/v2-sdk';
|
|
39
|
-
import 'react-infinite-scroller';
|
|
40
|
-
import 'd3';
|
|
41
|
-
import 'rmc-date-picker';
|
|
42
|
-
|
|
43
|
-
var DefaultContext = {
|
|
44
|
-
color: undefined,
|
|
45
|
-
size: undefined,
|
|
46
|
-
className: undefined,
|
|
47
|
-
style: undefined,
|
|
48
|
-
attr: undefined
|
|
49
|
-
};
|
|
50
|
-
var IconContext = React__default.createContext && /*#__PURE__*/React__default.createContext(DefaultContext);
|
|
51
|
-
|
|
52
|
-
var _excluded = ["attr", "size", "title"];
|
|
53
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
54
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
55
|
-
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
56
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
57
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
58
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
59
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
60
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
61
|
-
function Tree2Element(tree) {
|
|
62
|
-
return tree && tree.map((node, i) => /*#__PURE__*/React__default.createElement(node.tag, _objectSpread({
|
|
63
|
-
key: i
|
|
64
|
-
}, node.attr), Tree2Element(node.child)));
|
|
65
|
-
}
|
|
66
|
-
function GenIcon(data) {
|
|
67
|
-
// eslint-disable-next-line react/display-name
|
|
68
|
-
return props => /*#__PURE__*/React__default.createElement(IconBase, _extends({
|
|
69
|
-
attr: _objectSpread({}, data.attr)
|
|
70
|
-
}, props), Tree2Element(data.child));
|
|
71
|
-
}
|
|
72
|
-
function IconBase(props) {
|
|
73
|
-
var elem = conf => {
|
|
74
|
-
var {
|
|
75
|
-
attr,
|
|
76
|
-
size,
|
|
77
|
-
title
|
|
78
|
-
} = props,
|
|
79
|
-
svgProps = _objectWithoutProperties(props, _excluded);
|
|
80
|
-
var computedSize = size || conf.size || "1em";
|
|
81
|
-
var className;
|
|
82
|
-
if (conf.className) className = conf.className;
|
|
83
|
-
if (props.className) className = (className ? className + " " : "") + props.className;
|
|
84
|
-
return /*#__PURE__*/React__default.createElement("svg", _extends({
|
|
85
|
-
stroke: "currentColor",
|
|
86
|
-
fill: "currentColor",
|
|
87
|
-
strokeWidth: "0"
|
|
88
|
-
}, conf.attr, attr, svgProps, {
|
|
89
|
-
className: className,
|
|
90
|
-
style: _objectSpread(_objectSpread({
|
|
91
|
-
color: props.color || conf.color
|
|
92
|
-
}, conf.style), props.style),
|
|
93
|
-
height: computedSize,
|
|
94
|
-
width: computedSize,
|
|
95
|
-
xmlns: "http://www.w3.org/2000/svg"
|
|
96
|
-
}), title && /*#__PURE__*/React__default.createElement("title", null, title), props.children);
|
|
97
|
-
};
|
|
98
|
-
return IconContext !== undefined ? /*#__PURE__*/React__default.createElement(IconContext.Consumer, null, conf => elem(conf)) : elem(DefaultContext);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// THIS FILE IS AUTO GENERATED
|
|
102
|
-
function BiChevronLeft (props) {
|
|
103
|
-
return GenIcon({"tag":"svg","attr":{"viewBox":"0 0 24 24"},"child":[{"tag":"path","attr":{"d":"M13.293 6.293 7.586 12l5.707 5.707 1.414-1.414L10.414 12l4.293-4.293z"},"child":[]}]})(props);
|
|
104
|
-
}function BiChevronRight (props) {
|
|
105
|
-
return GenIcon({"tag":"svg","attr":{"viewBox":"0 0 24 24"},"child":[{"tag":"path","attr":{"d":"M10.707 17.707 16.414 12l-5.707-5.707-1.414 1.414L13.586 12l-4.293 4.293z"},"child":[]}]})(props);
|
|
106
|
-
}function BiMinus (props) {
|
|
107
|
-
return GenIcon({"tag":"svg","attr":{"viewBox":"0 0 24 24"},"child":[{"tag":"path","attr":{"d":"M5 11h14v2H5z"},"child":[]}]})(props);
|
|
108
|
-
}function BiPlus (props) {
|
|
109
|
-
return GenIcon({"tag":"svg","attr":{"viewBox":"0 0 24 24"},"child":[{"tag":"path","attr":{"d":"M19 11h-6V5h-2v6H5v2h6v6h2v-6h6z"},"child":[]}]})(props);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const Input = styled.input`
|
|
113
|
-
margin: 4px 10px 4px 6px;
|
|
114
|
-
border-radius: 10px;
|
|
115
|
-
border: 1px solid #373739;
|
|
116
|
-
padding: 4px 9px;
|
|
117
|
-
background-color: #1a1a1b;
|
|
118
|
-
color: #ffffff;
|
|
119
|
-
font-size: 14px;
|
|
120
|
-
font-weight: 400;
|
|
121
|
-
line-height: 20px;
|
|
122
|
-
outline: none;
|
|
123
|
-
width: 96px;
|
|
124
|
-
&:focus {
|
|
125
|
-
border-color: #fff;
|
|
126
|
-
|
|
127
|
-
${({
|
|
128
|
-
error
|
|
129
|
-
}) => error && css`
|
|
130
|
-
border-color: red;
|
|
131
|
-
`}
|
|
132
|
-
}
|
|
133
|
-
`;
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* 防止鼠标在图上滚动滚轮时页面上下滑动
|
|
137
|
-
* @param param0
|
|
138
|
-
*/
|
|
139
|
-
const usePreventWheel = ({
|
|
140
|
-
id
|
|
141
|
-
}) => {
|
|
142
|
-
useEffect(() => {
|
|
143
|
-
function handleWheelEvt(event) {
|
|
144
|
-
event.preventDefault();
|
|
145
|
-
}
|
|
146
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support
|
|
147
|
-
let passiveSupported = false;
|
|
148
|
-
try {
|
|
149
|
-
const options = {
|
|
150
|
-
get passive() {
|
|
151
|
-
// This function will be called when the browser
|
|
152
|
-
// attempts to access the passive property.
|
|
153
|
-
passiveSupported = true;
|
|
154
|
-
return false;
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
158
|
-
window.addEventListener('test', () => {}, options);
|
|
159
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
160
|
-
window.removeEventListener('test', () => {});
|
|
161
|
-
} catch (err) {
|
|
162
|
-
passiveSupported = false;
|
|
163
|
-
}
|
|
164
|
-
const container = document.getElementById(id);
|
|
165
|
-
// https://github.com/inuyaksa/jquery.nicescroll/issues/799
|
|
166
|
-
const options = passiveSupported ? {
|
|
167
|
-
passive: false
|
|
168
|
-
} : false;
|
|
169
|
-
container === null || container === void 0 ? void 0 : container.addEventListener('wheel', handleWheelEvt, options);
|
|
170
|
-
return () => {
|
|
171
|
-
container === null || container === void 0 ? void 0 : container.removeEventListener('wheel', handleWheelEvt);
|
|
172
|
-
};
|
|
173
|
-
}, [id]);
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
function useDepthLinePoints({
|
|
177
|
-
chartHeight,
|
|
178
|
-
chartWidth,
|
|
179
|
-
midPrice,
|
|
180
|
-
xPoints,
|
|
181
|
-
pmmModel,
|
|
182
|
-
baseMinAndZoomMultiples,
|
|
183
|
-
buyYPortion,
|
|
184
|
-
sellYPortion
|
|
185
|
-
}) {
|
|
186
|
-
return useMemo(() => {
|
|
187
|
-
const quoteLinePoints = [];
|
|
188
|
-
const baseLinePoints = [];
|
|
189
|
-
const midPriceLinePoints = [];
|
|
190
|
-
const {
|
|
191
|
-
baseMin,
|
|
192
|
-
zoomMultiples
|
|
193
|
-
} = baseMinAndZoomMultiples;
|
|
194
|
-
const xPortion = computeXPortion(chartWidth, zoomMultiples);
|
|
195
|
-
// 1 -> 10 -> 100 index increases from 0 to 2
|
|
196
|
-
// If the minimum value on the left is not midPrice/10, the existing calculation method is to calculate the maximum value based on the minimum value and multiply by 10^2
|
|
197
|
-
const multiplesNum = zoomMultiples * 2;
|
|
198
|
-
const step = new BigNumber(multiplesNum).div(xPoints);
|
|
199
|
-
// The position of the middle price
|
|
200
|
-
let midPriceN = new BigNumber(Math.log(midPrice.div(baseMin).toNumber()) / Math.log(10));
|
|
201
|
-
midPriceN = BigNumber.minimum(multiplesNum, midPriceN);
|
|
202
|
-
midPriceN = BigNumber.maximum(0, midPriceN);
|
|
203
|
-
for (let i = new BigNumber(0); i.lte(midPriceN);) {
|
|
204
|
-
const price = baseMin.multipliedBy(10 ** i.toNumber());
|
|
205
|
-
const result = evalPoint({
|
|
206
|
-
val: price,
|
|
207
|
-
model: pmmModel,
|
|
208
|
-
midPrice
|
|
209
|
-
});
|
|
210
|
-
if (!result.vert.isNaN()) {
|
|
211
|
-
const x = i.div(xPortion).toNumber();
|
|
212
|
-
const y = chartHeight - result.vert.div(buyYPortion).toNumber();
|
|
213
|
-
quoteLinePoints.push(x, y);
|
|
214
|
-
}
|
|
215
|
-
i = i.plus(step);
|
|
216
|
-
}
|
|
217
|
-
for (let i = midPriceN; i.lte(multiplesNum);) {
|
|
218
|
-
const price = baseMin.multipliedBy(10 ** i.toNumber());
|
|
219
|
-
const result = evalPoint({
|
|
220
|
-
val: price,
|
|
221
|
-
model: pmmModel,
|
|
222
|
-
midPrice
|
|
223
|
-
});
|
|
224
|
-
if (!result.vert.isNaN()) {
|
|
225
|
-
const x = i.div(xPortion).toNumber();
|
|
226
|
-
const y = chartHeight - result.vert.div(sellYPortion).toNumber();
|
|
227
|
-
baseLinePoints.push(x, y);
|
|
228
|
-
}
|
|
229
|
-
i = i.plus(step);
|
|
230
|
-
}
|
|
231
|
-
const midPriceX = midPriceN.div(xPortion).toNumber();
|
|
232
|
-
const [, firstY] = quoteLinePoints;
|
|
233
|
-
// k === 0 means selling coins at a constant price. The curve is two horizontal lines and requires special processing.
|
|
234
|
-
const isZeroK = pmmModel.k.eq(0);
|
|
235
|
-
if (isZeroK) {
|
|
236
|
-
quoteLinePoints.push(midPriceX, firstY || chartHeight);
|
|
237
|
-
}
|
|
238
|
-
quoteLinePoints.push(midPriceX, chartHeight);
|
|
239
|
-
midPriceLinePoints.push(midPriceX, chartHeight, midPriceX, 0);
|
|
240
|
-
const maxResult = evalPoint({
|
|
241
|
-
val: baseMin.multipliedBy(10 ** multiplesNum),
|
|
242
|
-
model: pmmModel,
|
|
243
|
-
midPrice
|
|
244
|
-
});
|
|
245
|
-
let maxHeightY = chartHeight;
|
|
246
|
-
const maxHeightX = new BigNumber(multiplesNum).div(xPortion).toNumber();
|
|
247
|
-
if (!maxResult.vert.isNaN()) {
|
|
248
|
-
maxHeightY = chartHeight - maxResult.vert.div(sellYPortion).toNumber();
|
|
249
|
-
}
|
|
250
|
-
if (isZeroK && baseLinePoints.length >= 2) {
|
|
251
|
-
baseLinePoints.unshift(midPriceX, maxHeightY);
|
|
252
|
-
baseLinePoints.unshift(midPriceX, chartHeight);
|
|
253
|
-
}
|
|
254
|
-
baseLinePoints.push(maxHeightX, maxHeightY);
|
|
255
|
-
// The left side has been dragged to the left side of baseMin
|
|
256
|
-
if (midPriceN.lte(0)) {
|
|
257
|
-
baseLinePoints.unshift(0, chartHeight);
|
|
258
|
-
}
|
|
259
|
-
return {
|
|
260
|
-
quoteLinePoints,
|
|
261
|
-
quoteLineAreaPoints: [0, chartHeight, 0, firstY, ...quoteLinePoints],
|
|
262
|
-
quoteLineAreaLinearGradientEndPointY: firstY,
|
|
263
|
-
baseLinePoints,
|
|
264
|
-
baseLineAreaPoints: [...baseLinePoints, maxHeightX, chartHeight],
|
|
265
|
-
baseLineAreaLinearGradientEndPointY: maxHeightY,
|
|
266
|
-
midPriceLinePoints
|
|
267
|
-
};
|
|
268
|
-
}, [baseMinAndZoomMultiples, chartWidth, xPoints, midPrice, pmmModel, chartHeight, buyYPortion, sellYPortion]);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
function useGridLinePoints({
|
|
272
|
-
chartHeight,
|
|
273
|
-
chartWidth,
|
|
274
|
-
horizontalLineCount,
|
|
275
|
-
verticalLineCount
|
|
276
|
-
}) {
|
|
277
|
-
return useMemo(() => {
|
|
278
|
-
const horizontalGridLines = [];
|
|
279
|
-
const horizontalGridPerBlockHeight = chartHeight / (horizontalLineCount + 1);
|
|
280
|
-
const verticalGridLines = [];
|
|
281
|
-
const verticalGridPerBlockWidth = chartWidth / verticalLineCount;
|
|
282
|
-
for (let index = 0; index < horizontalLineCount; index++) {
|
|
283
|
-
const y = horizontalGridPerBlockHeight * (index + 1);
|
|
284
|
-
horizontalGridLines.push([0, y, chartWidth, y]);
|
|
285
|
-
}
|
|
286
|
-
for (let index = 0; index < verticalLineCount; index++) {
|
|
287
|
-
const x = verticalGridPerBlockWidth * index + verticalGridPerBlockWidth / 2;
|
|
288
|
-
verticalGridLines.push([x, 0, x, chartHeight]);
|
|
289
|
-
}
|
|
290
|
-
return {
|
|
291
|
-
horizontalGridLines,
|
|
292
|
-
verticalGridLines
|
|
293
|
-
};
|
|
294
|
-
}, [chartHeight, chartWidth, horizontalLineCount, verticalLineCount]);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
function useHorizontalLabelPoints({
|
|
298
|
-
chartHeight,
|
|
299
|
-
chartWidth,
|
|
300
|
-
xAxisPoints,
|
|
301
|
-
oneXPx,
|
|
302
|
-
baseMinAndZoomMultiples
|
|
303
|
-
}) {
|
|
304
|
-
return useMemo(() => {
|
|
305
|
-
const xPortion = computeXPortion(chartWidth, baseMinAndZoomMultiples.zoomMultiples);
|
|
306
|
-
const horizontalLabelTickPoints = [];
|
|
307
|
-
const horizontalLabelTextPoints = [];
|
|
308
|
-
for (let i = 0; i < xAxisPoints; i++) {
|
|
309
|
-
horizontalLabelTickPoints.push([i * oneXPx + oneXPx / 2, chartHeight, i * oneXPx + oneXPx / 2, chartHeight + 4]);
|
|
310
|
-
const power = xPortion.multipliedBy(i).multipliedBy(oneXPx).plus(xPortion.multipliedBy(oneXPx / 2)).toNumber();
|
|
311
|
-
const axisNum = baseMinAndZoomMultiples.baseMin.multipliedBy(10 ** power);
|
|
312
|
-
const x = i * oneXPx;
|
|
313
|
-
const y = chartHeight + 2 + 4;
|
|
314
|
-
const text = formatShortNumber(axisNum);
|
|
315
|
-
horizontalLabelTextPoints.push({
|
|
316
|
-
x,
|
|
317
|
-
y,
|
|
318
|
-
text
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
return {
|
|
322
|
-
horizontalLabelTickPoints,
|
|
323
|
-
horizontalLabelTextPoints
|
|
324
|
-
};
|
|
325
|
-
}, [baseMinAndZoomMultiples.baseMin, baseMinAndZoomMultiples.zoomMultiples, chartHeight, chartWidth, oneXPx, xAxisPoints]);
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
const bgColor = 'rgba(38, 39, 41, 0.3)';
|
|
329
|
-
// toolTip the height of the arrow
|
|
330
|
-
const toolTipPointerHeight = 8;
|
|
331
|
-
const toolTipPointerWidth = 15;
|
|
332
|
-
const xAxisHight = 18;
|
|
333
|
-
const xPoints = 50;
|
|
334
|
-
/** The number of horizontal axis scales or the number of vertical grid lines */
|
|
335
|
-
const xAxisPoints = 7;
|
|
336
|
-
// Number of horizontal grid lines
|
|
337
|
-
const horizontalLineCount = 9;
|
|
338
|
-
function DepthChartKonva({
|
|
339
|
-
width,
|
|
340
|
-
height,
|
|
341
|
-
midPrice,
|
|
342
|
-
pmmModel,
|
|
343
|
-
params,
|
|
344
|
-
baseTokenSymbol,
|
|
345
|
-
quoteTokenSymbol,
|
|
346
|
-
baseMinAndZoomMultiples,
|
|
347
|
-
colorMap,
|
|
348
|
-
setBaseMinAndZoomMultiples
|
|
349
|
-
}) {
|
|
350
|
-
const colorMapRes = merge({
|
|
351
|
-
grid: '#2A2A2D',
|
|
352
|
-
midPriceLine: '#313335',
|
|
353
|
-
leftBg: [0, bgColor, 1, '#31645d'],
|
|
354
|
-
leftLine: '#55f6db',
|
|
355
|
-
leftColor: '',
|
|
356
|
-
rightBg: [0, bgColor, 1, '#67303d'],
|
|
357
|
-
rightLine: '#ff4f73',
|
|
358
|
-
rightColor: '',
|
|
359
|
-
tooltipBg: '#121212',
|
|
360
|
-
tooltipColor: undefined
|
|
361
|
-
}, colorMap);
|
|
362
|
-
const chartWidth = width;
|
|
363
|
-
const chartHeight = height - xAxisHight;
|
|
364
|
-
const oneXPx = chartWidth / xAxisPoints;
|
|
365
|
-
const {
|
|
366
|
-
buyBaseVert,
|
|
367
|
-
sellBaseVert
|
|
368
|
-
} = computeBaseVert({
|
|
369
|
-
midPrice,
|
|
370
|
-
q: params.q,
|
|
371
|
-
q0: params.q0,
|
|
372
|
-
pmmModel
|
|
373
|
-
});
|
|
374
|
-
const buyYPortion = buyBaseVert.div(chartHeight);
|
|
375
|
-
const sellYPortion = sellBaseVert.div(chartHeight);
|
|
376
|
-
const tooltipRef = useRef(null);
|
|
377
|
-
const stageRef = useRef(null);
|
|
378
|
-
const {
|
|
379
|
-
current: tooltip
|
|
380
|
-
} = tooltipRef;
|
|
381
|
-
const dragStartXRef = useRef(0);
|
|
382
|
-
const pointerXRef = useRef();
|
|
383
|
-
const {
|
|
384
|
-
horizontalGridLines,
|
|
385
|
-
verticalGridLines
|
|
386
|
-
} = useGridLinePoints({
|
|
387
|
-
chartHeight,
|
|
388
|
-
chartWidth,
|
|
389
|
-
horizontalLineCount,
|
|
390
|
-
verticalLineCount: xAxisPoints
|
|
391
|
-
});
|
|
392
|
-
const {
|
|
393
|
-
horizontalLabelTickPoints,
|
|
394
|
-
horizontalLabelTextPoints
|
|
395
|
-
} = useHorizontalLabelPoints({
|
|
396
|
-
chartHeight,
|
|
397
|
-
chartWidth,
|
|
398
|
-
xAxisPoints,
|
|
399
|
-
oneXPx,
|
|
400
|
-
baseMinAndZoomMultiples
|
|
401
|
-
});
|
|
402
|
-
const {
|
|
403
|
-
quoteLinePoints,
|
|
404
|
-
quoteLineAreaPoints,
|
|
405
|
-
quoteLineAreaLinearGradientEndPointY,
|
|
406
|
-
baseLinePoints,
|
|
407
|
-
baseLineAreaPoints,
|
|
408
|
-
baseLineAreaLinearGradientEndPointY,
|
|
409
|
-
midPriceLinePoints
|
|
410
|
-
} = useDepthLinePoints({
|
|
411
|
-
chartHeight,
|
|
412
|
-
chartWidth,
|
|
413
|
-
midPrice,
|
|
414
|
-
xPoints,
|
|
415
|
-
pmmModel,
|
|
416
|
-
baseMinAndZoomMultiples,
|
|
417
|
-
buyYPortion,
|
|
418
|
-
sellYPortion
|
|
419
|
-
});
|
|
420
|
-
const handleMouseover = evt => {
|
|
421
|
-
var _a;
|
|
422
|
-
const node = evt.target;
|
|
423
|
-
if (node && tooltip) {
|
|
424
|
-
// update tooltip
|
|
425
|
-
const mousePos = (_a = node.getStage()) === null || _a === void 0 ? void 0 : _a.getPointerPosition();
|
|
426
|
-
if (mousePos) {
|
|
427
|
-
const {
|
|
428
|
-
x
|
|
429
|
-
} = mousePos;
|
|
430
|
-
if (x > chartWidth) {
|
|
431
|
-
tooltip.hide();
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
|
-
updateTooltip({
|
|
435
|
-
x,
|
|
436
|
-
tooltip,
|
|
437
|
-
buyBaseVert,
|
|
438
|
-
sellBaseVert,
|
|
439
|
-
chartWidth,
|
|
440
|
-
chartHeight,
|
|
441
|
-
midPrice,
|
|
442
|
-
pmmModel,
|
|
443
|
-
baseTokenSymbol,
|
|
444
|
-
quoteTokenSymbol,
|
|
445
|
-
baseMinAndZoomMultiples,
|
|
446
|
-
t: chartT,
|
|
447
|
-
isHover: true,
|
|
448
|
-
color: colorMapRes.tooltipColor,
|
|
449
|
-
leftColor: colorMapRes.leftLine,
|
|
450
|
-
rightColor: colorMapRes.rightLine
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
};
|
|
455
|
-
const handleMouseOut = () => {
|
|
456
|
-
if (tooltip) {
|
|
457
|
-
tooltip.hide();
|
|
458
|
-
}
|
|
459
|
-
};
|
|
460
|
-
const updateWhenDrag = useMemo(() => throttle(evt => {
|
|
461
|
-
const {
|
|
462
|
-
target
|
|
463
|
-
} = evt;
|
|
464
|
-
const stage = target.getStage();
|
|
465
|
-
if (stage) {
|
|
466
|
-
stage.container().style.cursor = 'grabbing';
|
|
467
|
-
const mousePos = stage === null || stage === void 0 ? void 0 : stage.getPointerPosition();
|
|
468
|
-
if (mousePos) {
|
|
469
|
-
const dragDistance = mousePos.x - dragStartXRef.current;
|
|
470
|
-
dragStartXRef.current = mousePos.x;
|
|
471
|
-
pointerXRef.current = mousePos.x;
|
|
472
|
-
setBaseMinAndZoomMultiples(prev => {
|
|
473
|
-
if (prev.baseMin === undefined) {
|
|
474
|
-
return prev;
|
|
475
|
-
}
|
|
476
|
-
return {
|
|
477
|
-
baseMin: computeBaseMinByDistance({
|
|
478
|
-
dragDistance,
|
|
479
|
-
prevBaseMin: prev.baseMin,
|
|
480
|
-
chartWidth,
|
|
481
|
-
zoomMultiples: prev.zoomMultiples
|
|
482
|
-
}),
|
|
483
|
-
zoomMultiples: prev.zoomMultiples,
|
|
484
|
-
targetMarginPriceX: 0
|
|
485
|
-
};
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
}, 100), [chartWidth, setBaseMinAndZoomMultiples]);
|
|
490
|
-
const updateWhenWheel = useMemo(() => throttle(event => {
|
|
491
|
-
// eslint-disable-next-line no-param-reassign
|
|
492
|
-
event.cancelBubble = true;
|
|
493
|
-
event.evt.preventDefault();
|
|
494
|
-
// scroll up
|
|
495
|
-
const isScrollUp = event.evt.deltaY < 0;
|
|
496
|
-
setBaseMinAndZoomMultiples(prev => {
|
|
497
|
-
const newZoomMultiples = computeZoomMultiplesWhenZoom({
|
|
498
|
-
zoomIn: isScrollUp,
|
|
499
|
-
prevZoomMultiples: prev.zoomMultiples
|
|
500
|
-
});
|
|
501
|
-
return {
|
|
502
|
-
baseMin: computeBaseAfterZoom({
|
|
503
|
-
midPrice,
|
|
504
|
-
zoomMultiples: newZoomMultiples
|
|
505
|
-
}),
|
|
506
|
-
zoomMultiples: newZoomMultiples,
|
|
507
|
-
targetMarginPriceX: prev.targetMarginPriceX
|
|
508
|
-
};
|
|
509
|
-
});
|
|
510
|
-
}, 100), [midPrice, setBaseMinAndZoomMultiples]);
|
|
511
|
-
useEffect(() => {
|
|
512
|
-
if (baseMinAndZoomMultiples.targetMarginPriceX > 0 && tooltip !== null) {
|
|
513
|
-
updateTooltip({
|
|
514
|
-
x: baseMinAndZoomMultiples.targetMarginPriceX,
|
|
515
|
-
tooltip,
|
|
516
|
-
buyBaseVert,
|
|
517
|
-
sellBaseVert,
|
|
518
|
-
chartWidth,
|
|
519
|
-
chartHeight,
|
|
520
|
-
midPrice,
|
|
521
|
-
pmmModel,
|
|
522
|
-
baseTokenSymbol,
|
|
523
|
-
quoteTokenSymbol,
|
|
524
|
-
baseMinAndZoomMultiples,
|
|
525
|
-
t: chartT,
|
|
526
|
-
color: colorMapRes.tooltipColor,
|
|
527
|
-
leftColor: colorMapRes.leftLine,
|
|
528
|
-
rightColor: colorMapRes.rightLine
|
|
529
|
-
});
|
|
530
|
-
return;
|
|
531
|
-
}
|
|
532
|
-
if (pointerXRef.current !== undefined && tooltip !== null) {
|
|
533
|
-
updateTooltip({
|
|
534
|
-
x: pointerXRef.current,
|
|
535
|
-
tooltip,
|
|
536
|
-
buyBaseVert,
|
|
537
|
-
sellBaseVert,
|
|
538
|
-
chartWidth,
|
|
539
|
-
chartHeight,
|
|
540
|
-
midPrice,
|
|
541
|
-
pmmModel,
|
|
542
|
-
baseTokenSymbol,
|
|
543
|
-
quoteTokenSymbol,
|
|
544
|
-
baseMinAndZoomMultiples,
|
|
545
|
-
t: chartT,
|
|
546
|
-
isHover: true,
|
|
547
|
-
color: colorMapRes.tooltipColor,
|
|
548
|
-
leftColor: colorMapRes.leftLine,
|
|
549
|
-
rightColor: colorMapRes.rightLine
|
|
550
|
-
});
|
|
551
|
-
}
|
|
552
|
-
}, [baseMinAndZoomMultiples, baseTokenSymbol, buyBaseVert, chartHeight, chartWidth, colorMapRes.leftLine, colorMapRes.rightLine, colorMapRes.tooltipColor, midPrice, pmmModel, quoteTokenSymbol, sellBaseVert, tooltip]);
|
|
553
|
-
return /*#__PURE__*/jsxRuntimeExports.jsxs(Stage, {
|
|
554
|
-
ref: stageRef,
|
|
555
|
-
width: width,
|
|
556
|
-
offsetY: -chartOffsetYBCToolTip,
|
|
557
|
-
height: height + chartOffsetYBCToolTip,
|
|
558
|
-
draggable: true,
|
|
559
|
-
dragBoundFunc: function () {
|
|
560
|
-
return {
|
|
561
|
-
x: this.absolutePosition().x,
|
|
562
|
-
y: this.absolutePosition().y
|
|
563
|
-
};
|
|
564
|
-
},
|
|
565
|
-
onMouseMove: handleMouseover,
|
|
566
|
-
onMouseOver: handleMouseover,
|
|
567
|
-
onMouseOut: handleMouseOut,
|
|
568
|
-
onDragStart: function (evt) {
|
|
569
|
-
const {
|
|
570
|
-
target
|
|
571
|
-
} = evt;
|
|
572
|
-
const stage = target.getStage();
|
|
573
|
-
if (stage) {
|
|
574
|
-
const mousePos = stage.getPointerPosition();
|
|
575
|
-
if (mousePos) {
|
|
576
|
-
dragStartXRef.current = mousePos.x;
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
},
|
|
580
|
-
onDragMove: updateWhenDrag,
|
|
581
|
-
onDragEnd: evt => {
|
|
582
|
-
const {
|
|
583
|
-
target
|
|
584
|
-
} = evt;
|
|
585
|
-
const stage = target.getStage();
|
|
586
|
-
if (stage) {
|
|
587
|
-
stage.container().style.cursor = 'pointer';
|
|
588
|
-
}
|
|
589
|
-
},
|
|
590
|
-
onWheel: updateWhenWheel,
|
|
591
|
-
children: [/*#__PURE__*/jsxRuntimeExports.jsxs(Layer, {
|
|
592
|
-
children: [/*#__PURE__*/jsxRuntimeExports.jsx(Rect, {
|
|
593
|
-
x: 0,
|
|
594
|
-
y: 0,
|
|
595
|
-
width: width,
|
|
596
|
-
height: chartHeight,
|
|
597
|
-
stroke: colorMapRes.grid,
|
|
598
|
-
strokeWidth: 1
|
|
599
|
-
}), horizontalGridLines.map((points, index) => /*#__PURE__*/jsxRuntimeExports.jsx(Line, {
|
|
600
|
-
points: points,
|
|
601
|
-
stroke: colorMapRes.grid,
|
|
602
|
-
strokeWidth: 1,
|
|
603
|
-
lineCap: "round",
|
|
604
|
-
lineJoin: "round",
|
|
605
|
-
listening: false
|
|
606
|
-
}, index)), verticalGridLines.map((points, index) => /*#__PURE__*/jsxRuntimeExports.jsx(Line, {
|
|
607
|
-
points: points,
|
|
608
|
-
stroke: colorMapRes.grid,
|
|
609
|
-
strokeWidth: 1,
|
|
610
|
-
lineCap: "round",
|
|
611
|
-
lineJoin: "round",
|
|
612
|
-
listening: false
|
|
613
|
-
}, index)), horizontalLabelTickPoints.map((tickPoints, index) => /*#__PURE__*/jsxRuntimeExports.jsx(Line, {
|
|
614
|
-
points: tickPoints,
|
|
615
|
-
stroke: "#9d9d9d",
|
|
616
|
-
strokeWidth: 1,
|
|
617
|
-
lineCap: "round",
|
|
618
|
-
lineJoin: "round",
|
|
619
|
-
listening: false
|
|
620
|
-
}, index)), horizontalLabelTextPoints.map((textPoint, index) => /*#__PURE__*/jsxRuntimeExports.jsx(Text, {
|
|
621
|
-
x: textPoint.x,
|
|
622
|
-
y: textPoint.y,
|
|
623
|
-
text: textPoint.text,
|
|
624
|
-
fontFamily: "Manrope",
|
|
625
|
-
fontSize: 12,
|
|
626
|
-
fill: "#9d9d9d",
|
|
627
|
-
width: oneXPx,
|
|
628
|
-
padding: 0,
|
|
629
|
-
align: "center",
|
|
630
|
-
verticalAlign: "bottom",
|
|
631
|
-
listening: false
|
|
632
|
-
}, index)), /*#__PURE__*/jsxRuntimeExports.jsx(Line, {
|
|
633
|
-
points: quoteLineAreaPoints,
|
|
634
|
-
closed: true,
|
|
635
|
-
listening: false,
|
|
636
|
-
lineCap: "round",
|
|
637
|
-
lineJoin: "round",
|
|
638
|
-
fillLinearGradientStartPoint: {
|
|
639
|
-
x: 0,
|
|
640
|
-
y: chartHeight
|
|
641
|
-
},
|
|
642
|
-
fillLinearGradientEndPoint: {
|
|
643
|
-
x: 0,
|
|
644
|
-
y: quoteLineAreaLinearGradientEndPointY
|
|
645
|
-
},
|
|
646
|
-
fillLinearGradientColorStops: colorMapRes.leftBg
|
|
647
|
-
}), /*#__PURE__*/jsxRuntimeExports.jsx(Line, {
|
|
648
|
-
points: quoteLinePoints,
|
|
649
|
-
stroke: colorMapRes.leftLine,
|
|
650
|
-
strokeWidth: 2,
|
|
651
|
-
lineCap: "round",
|
|
652
|
-
lineJoin: "round",
|
|
653
|
-
listening: false
|
|
654
|
-
}), /*#__PURE__*/jsxRuntimeExports.jsx(Line, {
|
|
655
|
-
points: baseLineAreaPoints,
|
|
656
|
-
closed: true,
|
|
657
|
-
listening: false,
|
|
658
|
-
lineCap: "round",
|
|
659
|
-
lineJoin: "round",
|
|
660
|
-
fillLinearGradientStartPoint: {
|
|
661
|
-
x: chartWidth,
|
|
662
|
-
y: chartHeight
|
|
663
|
-
},
|
|
664
|
-
fillLinearGradientEndPoint: {
|
|
665
|
-
x: chartWidth,
|
|
666
|
-
y: baseLineAreaLinearGradientEndPointY
|
|
667
|
-
},
|
|
668
|
-
fillLinearGradientColorStops: colorMapRes.rightBg
|
|
669
|
-
}), /*#__PURE__*/jsxRuntimeExports.jsx(Line, {
|
|
670
|
-
points: baseLinePoints,
|
|
671
|
-
stroke: colorMapRes.rightLine,
|
|
672
|
-
strokeWidth: 2,
|
|
673
|
-
lineCap: "round",
|
|
674
|
-
lineJoin: "round",
|
|
675
|
-
listening: false
|
|
676
|
-
}), /*#__PURE__*/jsxRuntimeExports.jsx(Line, {
|
|
677
|
-
points: midPriceLinePoints,
|
|
678
|
-
stroke: colorMapRes.midPriceLine,
|
|
679
|
-
strokeWidth: 2,
|
|
680
|
-
lineCap: "round",
|
|
681
|
-
lineJoin: "round",
|
|
682
|
-
listening: false
|
|
683
|
-
})]
|
|
684
|
-
}), /*#__PURE__*/jsxRuntimeExports.jsxs(Layer, {
|
|
685
|
-
ref: tooltipRef,
|
|
686
|
-
visible: false,
|
|
687
|
-
listening: false,
|
|
688
|
-
children: [/*#__PURE__*/jsxRuntimeExports.jsx(Line, {
|
|
689
|
-
points: [],
|
|
690
|
-
stroke: "#ff4f73",
|
|
691
|
-
strokeWidth: 1,
|
|
692
|
-
lineCap: "round",
|
|
693
|
-
lineJoin: "round",
|
|
694
|
-
dash: [4, 6],
|
|
695
|
-
id: "toolTipVertLine"
|
|
696
|
-
}), /*#__PURE__*/jsxRuntimeExports.jsx(Line, {
|
|
697
|
-
points: [],
|
|
698
|
-
stroke: "ff4f73",
|
|
699
|
-
strokeWidth: 1,
|
|
700
|
-
lineCap: "round",
|
|
701
|
-
lineJoin: "round",
|
|
702
|
-
dash: [4, 6],
|
|
703
|
-
id: "toolTipHoriLine"
|
|
704
|
-
}), /*#__PURE__*/jsxRuntimeExports.jsx(Circle, {
|
|
705
|
-
x: 0,
|
|
706
|
-
y: 0,
|
|
707
|
-
radius: 5,
|
|
708
|
-
fill: "#FF5072",
|
|
709
|
-
stroke: "rgba(255, 80, 114, 0.3)",
|
|
710
|
-
strokeWidth: 12,
|
|
711
|
-
id: "joinCircle"
|
|
712
|
-
}), /*#__PURE__*/jsxRuntimeExports.jsxs(Label, {
|
|
713
|
-
x: 0,
|
|
714
|
-
y: 0,
|
|
715
|
-
id: "priceTextLabel",
|
|
716
|
-
children: [/*#__PURE__*/jsxRuntimeExports.jsx(Tag, {
|
|
717
|
-
fill: colorMapRes.tooltipBg,
|
|
718
|
-
id: "priceTextLabel-tag"
|
|
719
|
-
}), /*#__PURE__*/jsxRuntimeExports.jsx(Text, {
|
|
720
|
-
text: "",
|
|
721
|
-
fontSize: 12,
|
|
722
|
-
fontFamily: "Manrope",
|
|
723
|
-
padding: 4,
|
|
724
|
-
fill: "#FF5072",
|
|
725
|
-
id: "priceTextLabel-text"
|
|
726
|
-
})]
|
|
727
|
-
}), /*#__PURE__*/jsxRuntimeExports.jsxs(Label, {
|
|
728
|
-
x: 0,
|
|
729
|
-
y: 0,
|
|
730
|
-
id: "slippageTextLabel",
|
|
731
|
-
children: [/*#__PURE__*/jsxRuntimeExports.jsx(Tag, {
|
|
732
|
-
fill: colorMapRes.tooltipBg,
|
|
733
|
-
id: "slippageTextLabel-tag"
|
|
734
|
-
}), /*#__PURE__*/jsxRuntimeExports.jsx(Text, {
|
|
735
|
-
text: "",
|
|
736
|
-
fontSize: 12,
|
|
737
|
-
fontFamily: "Manrope",
|
|
738
|
-
padding: 4,
|
|
739
|
-
fill: "#FF5072",
|
|
740
|
-
id: "slippageTextLabel-text"
|
|
741
|
-
})]
|
|
742
|
-
}), /*#__PURE__*/jsxRuntimeExports.jsxs(Label, {
|
|
743
|
-
x: 0,
|
|
744
|
-
y: 0,
|
|
745
|
-
id: "toolTip",
|
|
746
|
-
children: [/*#__PURE__*/jsxRuntimeExports.jsx(Tag, {
|
|
747
|
-
fill: colorMapRes.tooltipBg,
|
|
748
|
-
pointerDirection: "down",
|
|
749
|
-
pointerWidth: toolTipPointerWidth,
|
|
750
|
-
pointerHeight: toolTipPointerHeight,
|
|
751
|
-
cornerRadius: toolTipPointerHeight,
|
|
752
|
-
lineJoin: "round",
|
|
753
|
-
id: "toolTip-tag"
|
|
754
|
-
}), /*#__PURE__*/jsxRuntimeExports.jsx(Text, {
|
|
755
|
-
text: "-",
|
|
756
|
-
fontSize: 12,
|
|
757
|
-
lineHeight: 17 / 12,
|
|
758
|
-
padding: labelPadding,
|
|
759
|
-
fontFamily: "Manrope",
|
|
760
|
-
fill: "#FFFFFF",
|
|
761
|
-
id: "toolTip-text"
|
|
762
|
-
})]
|
|
763
|
-
})]
|
|
764
|
-
})]
|
|
765
|
-
});
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
const BaseButton = styled.button`
|
|
769
|
-
margin: 0;
|
|
770
|
-
border: none;
|
|
771
|
-
padding: 0;
|
|
772
|
-
background: none;
|
|
773
|
-
|
|
774
|
-
&:focus {
|
|
775
|
-
outline: none;
|
|
776
|
-
}
|
|
777
|
-
&:active {
|
|
778
|
-
outline: none;
|
|
779
|
-
}
|
|
780
|
-
`;
|
|
781
|
-
|
|
782
|
-
const Container = styled.div`
|
|
783
|
-
height: 100%;
|
|
784
|
-
`;
|
|
785
|
-
const AmountInputContainer = styled.div`
|
|
786
|
-
display: flex;
|
|
787
|
-
align-items: center;
|
|
788
|
-
`;
|
|
789
|
-
const InputSectionWrapper = styled.div`
|
|
790
|
-
border: 1px solid ${({
|
|
791
|
-
borderColor
|
|
792
|
-
}) => borderColor || '#2a2a2d'};
|
|
793
|
-
flex: 1 0 50%;
|
|
794
|
-
|
|
795
|
-
display: flex;
|
|
796
|
-
align-items: center;
|
|
797
|
-
justify-content: center;
|
|
798
|
-
font-size: 12px;
|
|
799
|
-
font-weight: 400;
|
|
800
|
-
line-height: 17px;
|
|
801
|
-
color: #606066;
|
|
802
|
-
|
|
803
|
-
& + & {
|
|
804
|
-
border-left: none;
|
|
805
|
-
}
|
|
806
|
-
`;
|
|
807
|
-
const PriceImpactWrapper = styled.span`
|
|
808
|
-
color: #85858d;
|
|
809
|
-
`;
|
|
810
|
-
const OptButtonGroup = styled.div`
|
|
811
|
-
margin-top: 20px;
|
|
812
|
-
display: flex;
|
|
813
|
-
justify-content: center;
|
|
814
|
-
margin-bottom: 9px;
|
|
815
|
-
`;
|
|
816
|
-
const OptButton = styled(BaseButton)`
|
|
817
|
-
border-radius: 13px;
|
|
818
|
-
background-color: #373739;
|
|
819
|
-
width: 24px;
|
|
820
|
-
height: 24px;
|
|
821
|
-
font-size: 18px;
|
|
822
|
-
color: #85858d;
|
|
823
|
-
line-height: 0;
|
|
824
|
-
& + & {
|
|
825
|
-
margin-left: 10px;
|
|
826
|
-
}
|
|
827
|
-
&:first-child,
|
|
828
|
-
&:last-child {
|
|
829
|
-
font-size: 20px;
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
&:hover {
|
|
833
|
-
color: #fff;
|
|
834
|
-
}
|
|
835
|
-
`;
|
|
836
|
-
|
|
837
|
-
/**
|
|
838
|
-
* Calculate marginPrice for buying or selling target baseToken
|
|
839
|
-
* @param param0
|
|
840
|
-
* @returns
|
|
841
|
-
*/
|
|
842
|
-
function computeMarginPrice({
|
|
843
|
-
params,
|
|
844
|
-
target,
|
|
845
|
-
isBuy = true
|
|
846
|
-
}) {
|
|
847
|
-
const b = new BigNumber(params.b);
|
|
848
|
-
const q = new BigNumber(params.q);
|
|
849
|
-
let b0 = new BigNumber(params.b0);
|
|
850
|
-
const q0 = new BigNumber(params.q0);
|
|
851
|
-
const i = new BigNumber(params.i);
|
|
852
|
-
const k = new BigNumber(params.k);
|
|
853
|
-
const {
|
|
854
|
-
R
|
|
855
|
-
} = params;
|
|
856
|
-
// When created, b0 is equal to b, and a b0 needs to be calculated.
|
|
857
|
-
if (R === 1 && b0.eq(b)) {
|
|
858
|
-
b0 = solveQuadraticFunctionForTarget(b, q.minus(q0), new BigNumber(1).div(i), k);
|
|
859
|
-
}
|
|
860
|
-
const newB = isBuy ? b.plus(target) : b.minus(target);
|
|
861
|
-
if (newB.lt(b0) || b.eq(b0)) {
|
|
862
|
-
// b < b0: The shortage of baseToken corresponds to the user buying baseToken. At this time, the quoteToken in the pool is higher than the regression target; the price curve is directly used to calculate the marginal price.
|
|
863
|
-
let r = b0.multipliedBy(b0).div(newB).div(newB);
|
|
864
|
-
r = new BigNumber(1).minus(k).plus(k.multipliedBy(r));
|
|
865
|
-
return i.multipliedBy(r);
|
|
866
|
-
}
|
|
867
|
-
// There is a shortage of quoteToken, which corresponds to the user selling baseToken, causing the number of quoteTokens in the pool to be lower than the return target at this time; the parameter target is the number of baseTokens sold by the user, and it is necessary to calculate the number of quoteTokens obtained after selling based on this value, that is, the user How many quoteTokens are obtained; then put this value into the price curve equation to calculate the marginal price.
|
|
868
|
-
const pmm = new PMMModel();
|
|
869
|
-
pmm.RStatus = R;
|
|
870
|
-
pmm.B = b;
|
|
871
|
-
pmm.B0 = b0;
|
|
872
|
-
pmm.Q = q;
|
|
873
|
-
pmm.Q0 = q0;
|
|
874
|
-
pmm.i = i;
|
|
875
|
-
pmm.k = k;
|
|
876
|
-
pmm.mtFeeRate = new BigNumber(0);
|
|
877
|
-
pmm.lpFeeRate = new BigNumber(0);
|
|
878
|
-
let getAmount = new BigNumber(0);
|
|
879
|
-
if (isBuy) {
|
|
880
|
-
getAmount = pmm.querySellBase(target);
|
|
881
|
-
} else {
|
|
882
|
-
getAmount = pmm.queryBuyBase(target);
|
|
883
|
-
}
|
|
884
|
-
const deltaQ = isBuy ? q.minus(getAmount) : q.plus(getAmount);
|
|
885
|
-
let r = q0.multipliedBy(q0).div(deltaQ).div(deltaQ);
|
|
886
|
-
r = new BigNumber(1).minus(k).plus(k.multipliedBy(r));
|
|
887
|
-
return i.div(r);
|
|
888
|
-
}
|
|
889
|
-
/**
|
|
890
|
-
* Calculate the margin price for selling target baseTokens
|
|
891
|
-
*/
|
|
892
|
-
function computeSellMarginPrice({
|
|
893
|
-
params,
|
|
894
|
-
target
|
|
895
|
-
}) {
|
|
896
|
-
return computeMarginPrice({
|
|
897
|
-
params,
|
|
898
|
-
target,
|
|
899
|
-
isBuy: false
|
|
900
|
-
});
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
const DepthChart = ({
|
|
904
|
-
chartId,
|
|
905
|
-
width = 834,
|
|
906
|
-
height = 460,
|
|
907
|
-
baseTokenSymbol,
|
|
908
|
-
quoteTokenSymbol,
|
|
909
|
-
pmmModel,
|
|
910
|
-
pmmParams,
|
|
911
|
-
midPrice = new BigNumber(0),
|
|
912
|
-
colorMap,
|
|
913
|
-
notShowAmountInput
|
|
914
|
-
}) => {
|
|
915
|
-
usePreventWheel({
|
|
916
|
-
id: chartId
|
|
917
|
-
});
|
|
918
|
-
const [buyAmount, setBuyAmount] = useState('');
|
|
919
|
-
const [sellAmount, setSellAmount] = useState('');
|
|
920
|
-
const [buyImpact, setBuyImpact] = useState('-');
|
|
921
|
-
const [sellImpact, setSellImpact] = useState('-');
|
|
922
|
-
// 横轴起点和缩放比例同时变化,变化也会引起价格冲击点变化
|
|
923
|
-
const [baseMinAndZoomMultiples, setBaseMinAndZoomMultiples] = useState({
|
|
924
|
-
baseMin: new BigNumber(0),
|
|
925
|
-
zoomMultiples: baseZoomMultiples,
|
|
926
|
-
targetMarginPriceX: 0
|
|
927
|
-
});
|
|
928
|
-
useEffect(() => {
|
|
929
|
-
if (midPrice !== undefined) {
|
|
930
|
-
setBaseMinAndZoomMultiples(prev => {
|
|
931
|
-
return {
|
|
932
|
-
baseMin: computeBaseAfterZoom({
|
|
933
|
-
midPrice,
|
|
934
|
-
zoomMultiples: prev.zoomMultiples
|
|
935
|
-
}),
|
|
936
|
-
zoomMultiples: prev.zoomMultiples,
|
|
937
|
-
targetMarginPriceX: prev.targetMarginPriceX
|
|
938
|
-
};
|
|
939
|
-
});
|
|
940
|
-
}
|
|
941
|
-
}, [midPrice]);
|
|
942
|
-
const amountOnChange = useMemo(() => debounce(({
|
|
943
|
-
type,
|
|
944
|
-
amount
|
|
945
|
-
}) => {
|
|
946
|
-
if (amount === '' && midPrice) {
|
|
947
|
-
setBaseMinAndZoomMultiples({
|
|
948
|
-
baseMin: computeBaseAfterZoom({
|
|
949
|
-
midPrice,
|
|
950
|
-
zoomMultiples: baseZoomMultiples
|
|
951
|
-
}),
|
|
952
|
-
zoomMultiples: baseZoomMultiples,
|
|
953
|
-
targetMarginPriceX: 0
|
|
954
|
-
});
|
|
955
|
-
if (type === 'buy') {
|
|
956
|
-
setBuyImpact('-');
|
|
957
|
-
} else {
|
|
958
|
-
setSellImpact('-');
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
const amountB = new BigNumber(amount);
|
|
962
|
-
if (amountB.lte(0) || amountB.isNaN() || !(pmmParams === null || pmmParams === void 0 ? void 0 : pmmParams.b) || amountB.gte(pmmParams.b) || !midPrice) {
|
|
963
|
-
return;
|
|
964
|
-
}
|
|
965
|
-
if (type === 'buy') {
|
|
966
|
-
const marginPrice = computeMarginPrice({
|
|
967
|
-
params: pmmParams,
|
|
968
|
-
target: amountB
|
|
969
|
-
});
|
|
970
|
-
setBaseMinAndZoomMultiples(prev => {
|
|
971
|
-
const impactResult = beforePriceImpactEffect({
|
|
972
|
-
currentBaseMinAndZoomMultiples: prev,
|
|
973
|
-
targetPrice: marginPrice,
|
|
974
|
-
midPrice,
|
|
975
|
-
width
|
|
976
|
-
});
|
|
977
|
-
if (impactResult.isSkip) {
|
|
978
|
-
return {
|
|
979
|
-
baseMin: prev.baseMin,
|
|
980
|
-
zoomMultiples: prev.zoomMultiples,
|
|
981
|
-
targetMarginPriceX: impactResult.targetX
|
|
982
|
-
};
|
|
983
|
-
}
|
|
984
|
-
if (impactResult.targetX > 0) {
|
|
985
|
-
return {
|
|
986
|
-
baseMin: impactResult.baseMin,
|
|
987
|
-
zoomMultiples: impactResult.zoomMultiples,
|
|
988
|
-
targetMarginPriceX: impactResult.targetX
|
|
989
|
-
};
|
|
990
|
-
}
|
|
991
|
-
const result = computeTargetXByTargetPrice({
|
|
992
|
-
midPrice,
|
|
993
|
-
width,
|
|
994
|
-
type,
|
|
995
|
-
targetPrice: marginPrice
|
|
996
|
-
});
|
|
997
|
-
const newZoomMultiples = result.zoomMultiples.dp(6).toNumber();
|
|
998
|
-
return {
|
|
999
|
-
baseMin: computeBaseAfterZoom({
|
|
1000
|
-
midPrice,
|
|
1001
|
-
zoomMultiples: newZoomMultiples
|
|
1002
|
-
}),
|
|
1003
|
-
zoomMultiples: newZoomMultiples,
|
|
1004
|
-
targetMarginPriceX: result.targetX
|
|
1005
|
-
};
|
|
1006
|
-
});
|
|
1007
|
-
// console.log(
|
|
1008
|
-
// 'v2 marginPrice',
|
|
1009
|
-
// amountB.toFixed(6),
|
|
1010
|
-
// marginPrice.toFixed(6),
|
|
1011
|
-
// result.targetX,
|
|
1012
|
-
// result.zoomMultiples.toFixed(6),
|
|
1013
|
-
// );
|
|
1014
|
-
setBuyImpact(`${formatPercentageNumber({
|
|
1015
|
-
input: marginPrice.minus(midPrice).div(midPrice)
|
|
1016
|
-
})}`);
|
|
1017
|
-
} else {
|
|
1018
|
-
const marginPrice = computeSellMarginPrice({
|
|
1019
|
-
params: pmmParams,
|
|
1020
|
-
target: amountB
|
|
1021
|
-
});
|
|
1022
|
-
setBaseMinAndZoomMultiples(prev => {
|
|
1023
|
-
const impactResult = beforePriceImpactEffect({
|
|
1024
|
-
currentBaseMinAndZoomMultiples: prev,
|
|
1025
|
-
targetPrice: marginPrice,
|
|
1026
|
-
midPrice,
|
|
1027
|
-
width
|
|
1028
|
-
});
|
|
1029
|
-
if (impactResult.isSkip) {
|
|
1030
|
-
return {
|
|
1031
|
-
baseMin: prev.baseMin,
|
|
1032
|
-
zoomMultiples: prev.zoomMultiples,
|
|
1033
|
-
targetMarginPriceX: impactResult.targetX
|
|
1034
|
-
};
|
|
1035
|
-
}
|
|
1036
|
-
if (impactResult.targetX > 0) {
|
|
1037
|
-
return {
|
|
1038
|
-
baseMin: impactResult.baseMin,
|
|
1039
|
-
zoomMultiples: impactResult.zoomMultiples,
|
|
1040
|
-
targetMarginPriceX: impactResult.targetX
|
|
1041
|
-
};
|
|
1042
|
-
}
|
|
1043
|
-
const result = computeTargetXByTargetPrice({
|
|
1044
|
-
midPrice,
|
|
1045
|
-
width,
|
|
1046
|
-
type,
|
|
1047
|
-
targetPrice: marginPrice
|
|
1048
|
-
});
|
|
1049
|
-
const newZoomMultiples = result.zoomMultiples.dp(6).toNumber();
|
|
1050
|
-
return {
|
|
1051
|
-
baseMin: computeBaseAfterZoom({
|
|
1052
|
-
midPrice,
|
|
1053
|
-
zoomMultiples: newZoomMultiples
|
|
1054
|
-
}),
|
|
1055
|
-
zoomMultiples: newZoomMultiples,
|
|
1056
|
-
targetMarginPriceX: result.targetX
|
|
1057
|
-
};
|
|
1058
|
-
});
|
|
1059
|
-
setSellImpact(`+${formatPercentageNumber({
|
|
1060
|
-
input: marginPrice.minus(midPrice).div(midPrice)
|
|
1061
|
-
})}`);
|
|
1062
|
-
}
|
|
1063
|
-
}, 300), [pmmParams, midPrice, width]);
|
|
1064
|
-
useEffect(() => {
|
|
1065
|
-
if (buyAmount !== undefined) {
|
|
1066
|
-
amountOnChange({
|
|
1067
|
-
type: 'buy',
|
|
1068
|
-
amount: buyAmount
|
|
1069
|
-
});
|
|
1070
|
-
}
|
|
1071
|
-
}, [amountOnChange, buyAmount]);
|
|
1072
|
-
useEffect(() => {
|
|
1073
|
-
if (sellAmount !== undefined) {
|
|
1074
|
-
amountOnChange({
|
|
1075
|
-
type: 'sell',
|
|
1076
|
-
amount: sellAmount
|
|
1077
|
-
});
|
|
1078
|
-
}
|
|
1079
|
-
}, [amountOnChange, sellAmount]);
|
|
1080
|
-
const handleDragButtonMouseDown = moveLeft => {
|
|
1081
|
-
let dragDistance = 0;
|
|
1082
|
-
if (moveLeft) {
|
|
1083
|
-
dragDistance = -(width * 0.1);
|
|
1084
|
-
} else {
|
|
1085
|
-
dragDistance = width * 0.1;
|
|
1086
|
-
}
|
|
1087
|
-
setBaseMinAndZoomMultiples(prev => {
|
|
1088
|
-
if (prev.baseMin === undefined) {
|
|
1089
|
-
return prev;
|
|
1090
|
-
}
|
|
1091
|
-
return {
|
|
1092
|
-
baseMin: computeBaseMinByDistance({
|
|
1093
|
-
dragDistance,
|
|
1094
|
-
prevBaseMin: prev.baseMin,
|
|
1095
|
-
chartWidth: width,
|
|
1096
|
-
zoomMultiples: prev.zoomMultiples
|
|
1097
|
-
}),
|
|
1098
|
-
zoomMultiples: prev.zoomMultiples,
|
|
1099
|
-
targetMarginPriceX: prev.targetMarginPriceX
|
|
1100
|
-
};
|
|
1101
|
-
});
|
|
1102
|
-
};
|
|
1103
|
-
const handleZoomButtonMouseDown = zoomIn => {
|
|
1104
|
-
setBaseMinAndZoomMultiples(prev => {
|
|
1105
|
-
const newZoomMultiples = computeZoomMultiplesWhenZoom({
|
|
1106
|
-
zoomIn: zoomIn !== null && zoomIn !== void 0 ? zoomIn : false,
|
|
1107
|
-
prevZoomMultiples: prev.zoomMultiples
|
|
1108
|
-
});
|
|
1109
|
-
return {
|
|
1110
|
-
baseMin: computeBaseAfterZoom({
|
|
1111
|
-
midPrice,
|
|
1112
|
-
zoomMultiples: newZoomMultiples
|
|
1113
|
-
}),
|
|
1114
|
-
zoomMultiples: newZoomMultiples,
|
|
1115
|
-
targetMarginPriceX: prev.targetMarginPriceX
|
|
1116
|
-
};
|
|
1117
|
-
});
|
|
1118
|
-
};
|
|
1119
|
-
const buyInputError = useMemo(() => {
|
|
1120
|
-
if (buyAmount === '') {
|
|
1121
|
-
return false;
|
|
1122
|
-
}
|
|
1123
|
-
const amountB = new BigNumber(buyAmount);
|
|
1124
|
-
if (amountB.lte(0) || amountB.isNaN() || !(pmmParams === null || pmmParams === void 0 ? void 0 : pmmParams.b) || amountB.gte(pmmParams.b)) {
|
|
1125
|
-
return true;
|
|
1126
|
-
}
|
|
1127
|
-
return false;
|
|
1128
|
-
}, [buyAmount, pmmParams]);
|
|
1129
|
-
const sellInputError = useMemo(() => {
|
|
1130
|
-
if (sellAmount === '') {
|
|
1131
|
-
return false;
|
|
1132
|
-
}
|
|
1133
|
-
const amountB = new BigNumber(sellAmount);
|
|
1134
|
-
if (amountB.lte(0) || amountB.isNaN() || !(pmmParams === null || pmmParams === void 0 ? void 0 : pmmParams.b) || amountB.gte(pmmParams.b)) {
|
|
1135
|
-
return true;
|
|
1136
|
-
}
|
|
1137
|
-
return false;
|
|
1138
|
-
}, [sellAmount, pmmParams]);
|
|
1139
|
-
return /*#__PURE__*/jsxRuntimeExports.jsxs(Container, {
|
|
1140
|
-
id: chartId,
|
|
1141
|
-
children: [!notShowAmountInput ? /*#__PURE__*/jsxRuntimeExports.jsxs(AmountInputContainer, {
|
|
1142
|
-
children: [/*#__PURE__*/jsxRuntimeExports.jsxs(InputSectionWrapper, {
|
|
1143
|
-
borderColor: colorMap && colorMap.grid,
|
|
1144
|
-
children: [chartT('pool.chart.buy-amount', {
|
|
1145
|
-
symbol: baseTokenSymbol
|
|
1146
|
-
}), /*#__PURE__*/jsxRuntimeExports.jsx(Input, {
|
|
1147
|
-
value: buyAmount,
|
|
1148
|
-
error: buyInputError,
|
|
1149
|
-
onChange: evt => {
|
|
1150
|
-
const amount = fixedInputStringToFormattedNumber(evt.target.value, 2);
|
|
1151
|
-
if (amount !== null) {
|
|
1152
|
-
setBuyAmount(amount);
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
|
-
}), /*#__PURE__*/jsxRuntimeExports.jsx(PriceImpactWrapper, {
|
|
1156
|
-
children: chartT('pool.chart.price-impact', {
|
|
1157
|
-
amount: buyImpact
|
|
1158
|
-
})
|
|
1159
|
-
})]
|
|
1160
|
-
}), /*#__PURE__*/jsxRuntimeExports.jsxs(InputSectionWrapper, {
|
|
1161
|
-
borderColor: colorMap && colorMap.grid,
|
|
1162
|
-
children: [chartT('pool.chart.sell-amount', {
|
|
1163
|
-
symbol: baseTokenSymbol
|
|
1164
|
-
}), /*#__PURE__*/jsxRuntimeExports.jsx(Input, {
|
|
1165
|
-
value: sellAmount,
|
|
1166
|
-
error: sellInputError,
|
|
1167
|
-
onChange: evt => {
|
|
1168
|
-
const amount = fixedInputStringToFormattedNumber(evt.target.value, 2);
|
|
1169
|
-
if (amount !== null) {
|
|
1170
|
-
setSellAmount(amount);
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
}), /*#__PURE__*/jsxRuntimeExports.jsx(PriceImpactWrapper, {
|
|
1174
|
-
children: chartT('pool.chart.price-impact', {
|
|
1175
|
-
amount: sellImpact
|
|
1176
|
-
})
|
|
1177
|
-
})]
|
|
1178
|
-
})]
|
|
1179
|
-
}) : '', pmmParams !== undefined && midPrice !== undefined && pmmModel !== undefined && baseMinAndZoomMultiples.baseMin !== undefined && midPrice !== undefined && /*#__PURE__*/jsxRuntimeExports.jsx(DepthChartKonva, {
|
|
1180
|
-
width: width,
|
|
1181
|
-
height: height,
|
|
1182
|
-
params: pmmParams,
|
|
1183
|
-
midPrice: midPrice,
|
|
1184
|
-
pmmModel: pmmModel,
|
|
1185
|
-
baseTokenSymbol: baseTokenSymbol,
|
|
1186
|
-
quoteTokenSymbol: quoteTokenSymbol,
|
|
1187
|
-
baseMinAndZoomMultiples: baseMinAndZoomMultiples,
|
|
1188
|
-
colorMap: colorMap,
|
|
1189
|
-
setBaseMinAndZoomMultiples: setBaseMinAndZoomMultiples
|
|
1190
|
-
}), /*#__PURE__*/jsxRuntimeExports.jsxs(OptButtonGroup, {
|
|
1191
|
-
className: "operate-btn-wrapper",
|
|
1192
|
-
children: [/*#__PURE__*/jsxRuntimeExports.jsx(OptButton, {
|
|
1193
|
-
onClick: () => handleDragButtonMouseDown(true),
|
|
1194
|
-
children: /*#__PURE__*/jsxRuntimeExports.jsx(BiChevronLeft, {})
|
|
1195
|
-
}), /*#__PURE__*/jsxRuntimeExports.jsx(OptButton, {
|
|
1196
|
-
onClick: () => handleZoomButtonMouseDown(false),
|
|
1197
|
-
children: /*#__PURE__*/jsxRuntimeExports.jsx(BiMinus, {})
|
|
1198
|
-
}), /*#__PURE__*/jsxRuntimeExports.jsx(OptButton, {
|
|
1199
|
-
onClick: () => handleZoomButtonMouseDown(true),
|
|
1200
|
-
children: /*#__PURE__*/jsxRuntimeExports.jsx(BiPlus, {})
|
|
1201
|
-
}), /*#__PURE__*/jsxRuntimeExports.jsx(OptButton, {
|
|
1202
|
-
onClick: () => handleDragButtonMouseDown(false),
|
|
1203
|
-
children: /*#__PURE__*/jsxRuntimeExports.jsx(BiChevronRight, {})
|
|
1204
|
-
})]
|
|
1205
|
-
})]
|
|
1206
|
-
});
|
|
1207
|
-
};
|
|
1208
|
-
|
|
1209
|
-
export { DepthChart as default };
|