@dodoex/widgets 3.14.1-react.1 → 3.14.1-react.2

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,12 +0,0 @@
1
- import t from"@emotion/styled";import{merge as e}from"lodash";import{useMemo as i,useRef as n}from"react";import{l as r,h as o,m as l}from"./helper-CQ8Clocj.js";import{Line as a,Text as s,Stage as d,Layer as g,Rect as m,Circle as u,Label as p,Tag as c}from"react-konva";import{j as h,f}from"./index-CWlMhnOc.js";import x from"bignumber.js";import{solveQuadraticFunctionForTarget as L,PMMState as w,PMMHelper as b}from"@dodoex/api";import"@lingui/core";import"@dodoex/components";import"@dodoex/dodo-contract-request";import"@lingui/react";import"identicon.js";import"zustand";import"@web3-react/core";import"@web3-react/eip1193";import"@web3-react/walletconnect-v2";import"@web3-react/metamask";import"@web3-react/types";import"@tanstack/react-query";import"@ethersproject/bignumber";import"react-dom";import"react-window";import"dayjs";import"react-transition-group";import"@dodoex/contract-request";import"axios";import"recharts";import"jsbi";import"tiny-invariant";import"@uniswap/sdk-core";import"@uniswap/v2-sdk";import"react-infinite-scroller";import"d3";import"rmc-date-picker";const A=t.div`
2
- height: 100%;
3
- position: relative;
4
- `,y=t.div`
5
- text-align: center;
6
- margin-top: 17.1px;
7
- margin-bottom: 88.41px;
8
- color: #606066;
9
- font-size: 12px;
10
- line-height: 17px;
11
- font-weight: 400;
12
- `;function N({maxHeight:t,gridAreaHeight:e,value:i}){const n=new x(e).minus(36),r=n.div(t);return n.minus(i.multipliedBy(r)).plus(36).toNumber()}function P({targetPrice:t,areaPoints:e,isLeft:i}){for(let n=0;n<e.length;n++){const r=e[n],o=n<e.length-1?e[n+1]:null;if(!o)return{targetAreaStatPoint:r,targetAreaStatPoints:e};if(i){if(t.lte(r.middlePrice)&&t.gte(o.middlePrice))return{targetAreaStatPoint:r,targetAreaStatPoints:e.slice(0,n+1)}}else if(t.gte(r.middlePrice)&&t.lte(o.middlePrice))return{targetAreaStatPoint:r,targetAreaStatPoints:e.slice(0,n+1)}}return{targetAreaStatPoint:null,targetAreaStatPoints:[]}}function v({x:t,width:e,minXLN10:i,maxXLN10:n}){const r=new x(t).div(e).multipliedBy(n.minus(i)).plus(i);return new x(10**r.toNumber())}function j({width:t,targetLN10:e,minXLN10:i,maxXLN10:n}){return e.minus(i).div(n.minus(i)).multipliedBy(t).toNumber()}function H({target:t}){return new x(Math.log10(t.toNumber()))}const S="rgba(38, 39, 41, 0.3)";function k({width:t,height:A,params:y,baseTokenSymbol:k,quoteTokenSymbol:X,colorMap:B}){const{maxLeftHeight:C,maxRightHeight:F,leftStatAreaPoints:M,rightStatAreaPoints:W,minXLN10:T,maxXLN10:q}=function({params:t}){return i(()=>{const e=new x(t.b),i=new x(t.q);let n=new x(t.b0);const r=new x(t.q0),o=new x(t.i),l=new x(t.k),{R:a}=t;1===a&&n.eq(e)&&(n=L(e,i.minus(r),new x(1).div(o),l));const s=new w({i:o,K:l,B:e,Q:i,B0:n,Q0:r,R:a,mtFeeRate:new x(0),lpFeeRate:new x(0)}),d=new b,g=new x(s.B),m=[],u=[];let p=new x(0),c=new x(0);const h=d.GetMidPrice(s),f=i.gt(0)?e.div(i):new x(1);for(let t=0;t<=250;t++){let e=g.multipliedBy(t/100).multipliedBy(h.multipliedBy(f).multipliedBy(4));0===t&&(e=g.multipliedBy(1e-11));const i=null==d?void 0:d.QuerySellBase(e,s);if(!i.isNaN()&&i.gt(0)){const t=i.div(e);m.push({giveAmount:e,getAmount:i,price:t});continue}m.push({giveAmount:e,getAmount:new x(0),price:new x(0)})}for(let t=0;t<=250;t++){let e=g.multipliedBy(t/100).multipliedBy(h.multipliedBy(4));0===t&&(e=g.multipliedBy(1e-11));const i=null==d?void 0:d.QuerySellQuote(e,s);if(!i.isNaN()&&i.gt(0)){const t=e.dividedBy(i);u.push({giveAmount:e,getAmount:i,price:t});continue}u.push({giveAmount:e,getAmount:new x(0),price:new x(0)})}if(m.length<2&&u.length<2)return{leftStatAreaPoints:[],rightStatAreaPoints:[],maxLeftHeight:new x(10).multipliedBy(1.2),maxRightHeight:new x(10).multipliedBy(1.2),middlePriceLN10:new x(0),minXLN10:new x(-1),maxXLN10:new x(1)};const A=[];for(let t=1;t<m.length;t++){const e=m[t],{giveAmount:i,getAmount:n,price:r}=e,o=m[t-1];if(!r.isNaN()&&r.gt(0)&&o){const e=r.minus(o.price).abs(),l=i.minus(o.giveAmount).abs(),a=n.minus(o.getAmount).abs().multipliedBy(l);1===t&&A.push({area:n,price:r,middlePrice:r.plus(e.div(1.1)),rectangleHeight:a.plus(a.multipliedBy(.03))}),A.push({area:n,price:r,middlePrice:r.plus(e.div(2)),rectangleHeight:a}),p=x.max(a,p)}}const y=[];for(let t=1;t<u.length;t++){const e=u[t],{giveAmount:i,getAmount:n,price:r}=e,o=u[t-1],l=o.price,a=o.giveAmount,s=o.getAmount;if(!r.isNaN()&&r.gt(0)&&o){const e=r.minus(l).abs(),o=i.minus(a).abs(),d=n.minus(s).abs().multipliedBy(o);1===t&&y.push({area:n,price:r,middlePrice:r.minus(e.div(1.1)),rectangleHeight:d.plus(d.multipliedBy(.03))}),y.push({area:n,price:r,middlePrice:r.minus(e.div(2)),rectangleHeight:d}),c=x.max(d,c)}}const N=m.length>0?m[m.length-1]:u[0],P=u.length>0?u[0]:m[0],v=u.length>0?u[u.length-1]:m[0],j=N.price,H=v.price,S=P.price,k=new x(Math.log10(S.toNumber()));let X=j.gt(0)?new x(Math.log10(j.toNumber())):new x(-Math.log10(H.toNumber())),B=H.gt(0)?new x(Math.log10(H.toNumber())):new x(-Math.log10(j.toNumber()));const C=x.max(k.minus(X).abs(),B.minus(k).abs());return X=k.minus(C),B=k.plus(C),{leftStatAreaPoints:A,rightStatAreaPoints:y,maxLeftHeight:p.multipliedBy(1.2),maxRightHeight:c.multipliedBy(1.2),minXLN10:X,maxXLN10:B,middlePriceLN10:k}},[t])}({params:y}),J=A-30.13,O=n(null),R=e({grid:"#2A2A2D",midPriceLine:"#313335",leftBg:[0,S,1,"#31645d"],leftLine:"#55f6db",leftColor:"",rightBg:[0,S,1,"#67303d"],rightLine:"#ff4f73",rightColor:"",tooltipBg:"#121212",tooltipColor:void 0,textColor:"#606066"},B),D=e=>{var i;const{current:n}=O,r=e.target;if(r&&n){const e=null===(i=r.getStage())||void 0===i?void 0:i.getPointerPosition();if(e){const{x:i}=e,r=t/2;if(Math.abs(i-r)<=2)return;if(i<=2||t-i<=2)return;const a=v({x:i,width:t,minXLN10:T,maxXLN10:q});let s=null,d=[];const g=i<r;if(g){const t=P({areaPoints:M,targetPrice:a,isLeft:g});s=t.targetAreaStatPoint,d=t.targetAreaStatPoints}else{const t=P({areaPoints:W,targetPrice:a,isLeft:g});s=t.targetAreaStatPoint,d=t.targetAreaStatPoints}if(s){const e=H({target:s.middlePrice}),r=j({minXLN10:T,maxXLN10:q,width:t,targetLN10:e}),a=N({maxHeight:g?C:F,gridAreaHeight:J,value:s.rectangleHeight}),m=n.findOne("#tooltip"),u=n.findOne("#toolTipVertLine"),p=n.findOne("#joinCircle"),c=n.findOne("#tooltip-Text"),h=n.findOne("#tooltip-tag"),x=n.findOne("#priceTextLabel"),L=null==x?void 0:x.findOne("#priceTextLabel-text"),w=n.findOne("#area");null==m||m.position({x:r,y:a-5-6}),null==c||c.fill(R.tooltipColor||(g?"#00FAD9":"#FF5072")),null==c||c.text(g?o("pool.chart.liquidity-chart-buy",{amount:f(s.area),symbol:k,price:f(s.price)}):o("pool.chart.liquidity-chart-sell",{amount:f(s.area),symbol:X,price:f(s.price)})),m&&h&&(m.width()/2>i?(h.pointerDirection("left"),h.pointerHeight(15),h.pointerWidth(8),m.offsetX(-11),m.offsetY(-11)):m.width()/2+i>t?(h.pointerDirection("right"),h.pointerHeight(15),h.pointerWidth(8),m.offsetX(11),m.offsetY(-11)):(h.pointerDirection("down"),h.pointerHeight(8),h.pointerWidth(15),m.offsetX(0),m.offsetY(0))),null==u||u.points([r,J,r,a]),null==u||u.stroke(g?"#55f6db":"#ff4f73");let b=g?"rgb(86, 246, 218)":"#FF5072",A=g?"rgba(86, 246, 218, 0.3)":"rgba(255, 80, 114, 0.3)";R.leftLine&&R.rightLine&&(b=g?R.leftLine:R.rightLine,A=g?`rgba(${l(R.leftLine)}, 0.4)`:`rgba(${l(R.rightLine)}, 0.4)`),p&&(p.x(r),p.y(a),p.fill(b),p.stroke(A)),x&&(x.x(r),x.y(J+8.08+1),x.offsetX(x.width()/2),x.x()-x.width()/2<0?x.x(x.width()/2):x.x()+x.width()/2>t?x.x(t-x.width()/2):x.x(i)),L&&(L.fill(R.tooltipColor||(g?"#00FAD9":"#FF5072")),L.text(f(s.price)));const y=[];for(const e of d){const{middlePrice:i,rectangleHeight:n}=e,r=H({target:i}),o=j({minXLN10:T,maxXLN10:q,width:t,targetLN10:r}),l=N({maxHeight:g?C:F,gridAreaHeight:J,value:n});y.push(o,l+1)}const P=y.slice(),[v,S]=P;g?(P.push(r,a),P.push(r,J),P.push(v,J),P.push(v,S)):(P.unshift(v,J),P.unshift(r,J),P.unshift(r,a)),w&&(w.points(P),w.fill(g?R.leftLine||"#2c5b56":R.rightLine||"#7b3a48")),n.show()}}}},z=function({gridAreaHeight:t,gridAreaWidth:e,horizontalLineCount:n,verticalLineCount:r,color:o="#2A2A2D"}){return i(()=>{const i=[],l=t/(n+1),s=[],d=e/(r+1);for(let t=0;t<n;t++){const n=l*(t+1);i.push([0,n,e,n])}for(let e=0;e<r;e++){const i=d*(e+1);s.push([i,0,i,t])}return h.jsxs(h.Fragment,{children:[i.map((t,e)=>h.jsx(a,{points:t,stroke:o,strokeWidth:1,lineCap:"round",lineJoin:"round",tension:1,listening:!1},e)),s.map((t,e)=>h.jsx(a,{points:t,stroke:o,strokeWidth:1,lineCap:"round",lineJoin:"round",tension:1,listening:!1},e))]})},[t,e,n,r,o])}({gridAreaHeight:J,gridAreaWidth:t,horizontalLineCount:9,verticalLineCount:7,color:R.grid}),G=function({minXLN10:t,maxXLN10:e,labelCount:n,gridAreaHeight:r,gridAreaWidth:o,color:l="#606066"}){return i(()=>{const i=o/(n+1),d=[],g=[];for(let l=0;l<n;l++){const n=i/2+i*l;d.push({x:n,y:r+10.08+1,text:f(v({x:i*(l+1),width:o,minXLN10:t,maxXLN10:e}))});const a=i*(l+1);g.push([a,r+1,a,r+4+1])}return h.jsxs(h.Fragment,{children:[d.map((t,e)=>h.jsx(s,{x:t.x,y:t.y,text:t.text,fontSize:14,fontFamily:"Manrope",fill:l,width:i,padding:0,align:"center",verticalAlign:"bottom",listening:!1},e)),g.map((t,e)=>h.jsx(a,{points:t,stroke:l,strokeWidth:1,lineCap:"butt",lineJoin:"miter",tension:1,listening:!1},e))]})},[t,e,r,o,n])}({gridAreaHeight:J,gridAreaWidth:t,labelCount:7,minXLN10:T,maxXLN10:q,color:R.textColor}),Q=function({gridAreaHeight:t,gridAreaWidth:e,color:n="#606066"}){return i(()=>{const i=e/2;return h.jsx(a,{points:[i,0,i,t-1],stroke:n,strokeWidth:1,lineCap:"round",lineJoin:"round",tension:1,listening:!1})},[t,e,n])}({gridAreaHeight:J,gridAreaWidth:t,color:R.midPriceLine}),{leftLine:E,rightLine:Y}=function({leftStatAreaPoints:t,rightStatAreaPoints:e,minXLN10:n,maxXLN10:r,maxLeftHeight:o,maxRightHeight:l,gridAreaWidth:s,gridAreaHeight:d,colorMap:g}){return{leftLine:i(()=>{if(t.length<1)return h.jsx(h.Fragment,{});const e=[];let i=d;for(const l of t){const{middlePrice:t,rectangleHeight:a}=l,g=H({target:t}),m=j({minXLN10:n,maxXLN10:r,width:s,targetLN10:g}),u=N({maxHeight:o,gridAreaHeight:d,value:a});e.push(m,u),u<i&&(i=u)}const l=e.slice(),[m,u]=l,p=l[l.length-1],c=l[l.length-2];return l.push(c,p),l.push(c,d),l.push(m,d),l.push(m,u),h.jsxs(h.Fragment,{children:[h.jsx(a,{points:l,closed:!0,listening:!1,lineCap:"round",lineJoin:"round",fillLinearGradientStartPoint:{x:0,y:d},fillLinearGradientEndPoint:{x:0,y:i},fillLinearGradientColorStops:g.leftBg}),h.jsx(a,{points:e,stroke:g.leftLine,strokeWidth:2,lineCap:"round",lineJoin:"round",listening:!1})]})},[t,s,n,r,d,o]),rightLine:i(()=>{if(e.length<1)return h.jsx(h.Fragment,{});const t=[];let i=d;for(const o of e){const{middlePrice:e,rectangleHeight:a}=o,g=H({target:e}),m=j({minXLN10:n,maxXLN10:r,width:s,targetLN10:g}),u=N({maxHeight:l,gridAreaHeight:d,value:a});t.push(m,u),u<i&&(i=u)}const o=t.slice(),[m]=o;return o.unshift(m,d),o.unshift(s,d),h.jsxs(h.Fragment,{children:[h.jsx(a,{points:o,closed:!0,listening:!1,lineCap:"round",lineJoin:"round",fillLinearGradientStartPoint:{x:0,y:d},fillLinearGradientEndPoint:{x:0,y:i},fillLinearGradientColorStops:g.rightBg}),h.jsx(a,{points:t,stroke:g.rightLine,strokeWidth:2,lineCap:"round",lineJoin:"round",listening:!1})]})},[e,s,n,r,d,l])}}({leftStatAreaPoints:M,rightStatAreaPoints:W,minXLN10:T,maxXLN10:q,maxLeftHeight:C,maxRightHeight:F,gridAreaWidth:t,gridAreaHeight:J,colorMap:R});return h.jsxs(d,{width:t,height:A,onMouseMove:D,onMouseOver:D,onMouseEnter:D,onMouseOut:()=>{const{current:t}=O;t&&t.hide()},children:[h.jsxs(g,{children:[h.jsx(m,{x:0,y:0,width:t,height:J,stroke:R.grid,strokeWidth:1}),z,G,E,Y,Q]}),h.jsxs(g,{ref:O,visible:!1,children:[h.jsx(a,{points:[],closed:!0,listening:!1,lineCap:"round",lineJoin:"round",id:"area"}),h.jsx(a,{points:[],strokeWidth:1,stroke:"#ff4f73",lineJoin:"round",lineCap:"round",dash:[4,6],id:"toolTipVertLine"}),h.jsx(u,{x:0,y:0,radius:5,fill:"#FF5072",stroke:"rgba(255, 80, 114, 0.3)",strokeWidth:12,id:"joinCircle"}),h.jsxs(p,{listening:!1,x:0,y:0,id:"priceTextLabel",children:[h.jsx(c,{fill:R.tooltipBg,id:"priceTextLabel-tag"}),h.jsx(s,{text:"-",fontSize:14,fontFamily:"Manrope",padding:2,fill:"#FF5072",id:"priceTextLabel-text"})]}),h.jsxs(p,{listening:!1,id:"tooltip",children:[h.jsx(c,{fill:R.tooltipBg,pointerDirection:"down",pointerWidth:15,pointerHeight:8,cornerRadius:8,lineJoin:"round",id:"tooltip-tag"}),h.jsx(s,{text:"",fontFamily:"Manrope",fontSize:12,lineHeight:17/12,padding:r,fill:"#FF5072",id:"tooltip-Text"})]})]})]})}const X=({width:t=834,height:e=462,baseTokenSymbol:i,quoteTokenSymbol:n,pmmModel:r,pmmParams:l,midPrice:a,notShowTipText:s,colorMap:d})=>h.jsxs(A,{children:[void 0!==l&&void 0!==a&&void 0!==r&&void 0!==a&&h.jsx(k,{width:t,height:e,params:l,midPrice:a,pmmModel:r,baseTokenSymbol:i,quoteTokenSymbol:n,colorMap:d}),s?"":h.jsxs(y,{children:["* ",o("pool.chart.liquidity-chart-tip",{baseTokenSymbol:i})]})]});export{X as default};
@@ -1,78 +0,0 @@
1
- import e from"bignumber.js";import{merge as t,throttle as i,debounce as o}from"lodash";import r,{useEffect as n,useMemo as l,useRef as s,useState as a}from"react";import d from"@emotion/styled";import{css as c}from"@emotion/react";import{Stage as u,Layer as p,Rect as m,Line as g,Text as h,Circle as b,Label as f,Tag as M}from"react-konva";import{c as x,e as v,a as y,b as P,d as w,f as j,u as z,l as L,g as k,h as B,i as C,j as S,k as N}from"./helper-CQ8Clocj.js";import{f as O,j as X,a as T,b as A}from"./index-CWlMhnOc.js";import{solveQuadraticFunctionForTarget as q,PMMModel as W}from"@dodoex/api";import"@lingui/core";import"@dodoex/components";import"@dodoex/dodo-contract-request";import"@lingui/react";import"identicon.js";import"zustand";import"@web3-react/core";import"@web3-react/eip1193";import"@web3-react/walletconnect-v2";import"@web3-react/metamask";import"@web3-react/types";import"@tanstack/react-query";import"@ethersproject/bignumber";import"react-dom";import"react-window";import"dayjs";import"react-transition-group";import"@dodoex/contract-request";import"axios";import"recharts";import"jsbi";import"tiny-invariant";import"@uniswap/sdk-core";import"@uniswap/v2-sdk";import"react-infinite-scroller";import"d3";import"rmc-date-picker";var E={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},F=r.createContext&&r.createContext(E),H=["attr","size","title"];function Z(e,t){if(null==e)return{};var i,o,r=function(e,t){if(null==e)return{};var i={};for(var o in e)if(Object.prototype.hasOwnProperty.call(e,o)){if(t.indexOf(o)>=0)continue;i[o]=e[o]}return i}(e,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);for(o=0;o<n.length;o++)i=n[o],t.indexOf(i)>=0||Object.prototype.propertyIsEnumerable.call(e,i)&&(r[i]=e[i])}return r}function G(){return G=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var o in i)Object.prototype.hasOwnProperty.call(i,o)&&(e[o]=i[o])}return e},G.apply(this,arguments)}function D(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),i.push.apply(i,o)}return i}function J(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?D(Object(i),!0).forEach(function(t){V(e,t,i[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):D(Object(i)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))})}return e}function V(e,t,i){var o;return(t="symbol"==typeof(o=function(e,t){if("object"!=typeof e||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var o=i.call(e,t);if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(t,"string"))?o:o+"")in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function Y(e){return e&&e.map((e,t)=>r.createElement(e.tag,J({key:t},e.attr),Y(e.child)))}function I(e){return t=>r.createElement(R,G({attr:J({},e.attr)},t),Y(e.child))}function R(e){var t=t=>{var i,{attr:o,size:n,title:l}=e,s=Z(e,H),a=n||t.size||"1em";return t.className&&(i=t.className),e.className&&(i=(i?i+" ":"")+e.className),r.createElement("svg",G({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},t.attr,o,s,{className:i,style:J(J({color:e.color||t.color},t.style),e.style),height:a,width:a,xmlns:"http://www.w3.org/2000/svg"}),l&&r.createElement("title",null,l),e.children)};return void 0!==F?r.createElement(F.Consumer,null,e=>t(e)):t(E)}function $(e){return I({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:[]}]})(e)}function Q(e){return I({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:[]}]})(e)}function K(e){return I({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{d:"M5 11h14v2H5z"},child:[]}]})(e)}function U(e){return I({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{d:"M19 11h-6V5h-2v6H5v2h6v6h2v-6h6z"},child:[]}]})(e)}const _=d.input`
2
- margin: 4px 10px 4px 6px;
3
- border-radius: 10px;
4
- border: 1px solid #373739;
5
- padding: 4px 9px;
6
- background-color: #1a1a1b;
7
- color: #ffffff;
8
- font-size: 14px;
9
- font-weight: 400;
10
- line-height: 20px;
11
- outline: none;
12
- width: 96px;
13
- &:focus {
14
- border-color: #fff;
15
-
16
- ${({error:e})=>e&&c`
17
- border-color: red;
18
- `}
19
- }
20
- `;const ee="rgba(38, 39, 41, 0.3)";function te({width:o,height:r,midPrice:a,pmmModel:d,params:c,baseTokenSymbol:C,quoteTokenSymbol:S,baseMinAndZoomMultiples:N,colorMap:T,setBaseMinAndZoomMultiples:A}){const q=t({grid:"#2A2A2D",midPriceLine:"#313335",leftBg:[0,ee,1,"#31645d"],leftLine:"#55f6db",leftColor:"",rightBg:[0,ee,1,"#67303d"],rightLine:"#ff4f73",rightColor:"",tooltipBg:"#121212",tooltipColor:void 0},T),W=o,E=r-18,F=W/7,{buyBaseVert:H,sellBaseVert:Z}=y({midPrice:a,q:c.q,q0:c.q0,pmmModel:d}),G=H.div(E),D=Z.div(E),J=s(null),V=s(null),{current:Y}=J,I=s(0),R=s(),{horizontalGridLines:$,verticalGridLines:Q}=function({chartHeight:e,chartWidth:t,horizontalLineCount:i,verticalLineCount:o}){return l(()=>{const r=[],n=e/(i+1),l=[],s=t/o;for(let e=0;e<i;e++){const i=n*(e+1);r.push([0,i,t,i])}for(let t=0;t<o;t++){const i=s*t+s/2;l.push([i,0,i,e])}return{horizontalGridLines:r,verticalGridLines:l}},[e,t,i,o])}({chartHeight:E,chartWidth:W,horizontalLineCount:9,verticalLineCount:7}),{horizontalLabelTickPoints:K,horizontalLabelTextPoints:U}=function({chartHeight:e,chartWidth:t,xAxisPoints:i,oneXPx:o,baseMinAndZoomMultiples:r}){return l(()=>{const n=x(t,r.zoomMultiples),l=[],s=[];for(let t=0;t<i;t++){l.push([t*o+o/2,e,t*o+o/2,e+4]);const i=n.multipliedBy(t).multipliedBy(o).plus(n.multipliedBy(o/2)).toNumber(),a=r.baseMin.multipliedBy(10**i),d=t*o,c=e+2+4,u=O(a);s.push({x:d,y:c,text:u})}return{horizontalLabelTickPoints:l,horizontalLabelTextPoints:s}},[r.baseMin,r.zoomMultiples,e,t,o,i])}({chartHeight:E,chartWidth:W,xAxisPoints:7,oneXPx:F,baseMinAndZoomMultiples:N}),{quoteLinePoints:_,quoteLineAreaPoints:te,quoteLineAreaLinearGradientEndPointY:ie,baseLinePoints:oe,baseLineAreaPoints:re,baseLineAreaLinearGradientEndPointY:ne,midPriceLinePoints:le}=function({chartHeight:t,chartWidth:i,midPrice:o,xPoints:r,pmmModel:n,baseMinAndZoomMultiples:s,buyYPortion:a,sellYPortion:d}){return l(()=>{const l=[],c=[],u=[],{baseMin:p,zoomMultiples:m}=s,g=x(i,m),h=2*m,b=new e(h).div(r);let f=new e(Math.log(o.div(p).toNumber())/Math.log(10));f=e.minimum(h,f),f=e.maximum(0,f);for(let i=new e(0);i.lte(f);){const e=p.multipliedBy(10**i.toNumber()),o=v({val:e,model:n});if(!o.vert.isNaN()){const e=i.div(g).toNumber(),r=t-o.vert.div(a).toNumber();l.push(e,r)}i=i.plus(b)}for(let e=f;e.lte(h);){const i=p.multipliedBy(10**e.toNumber()),o=v({val:i,model:n});if(!o.vert.isNaN()){const i=e.div(g).toNumber(),r=t-o.vert.div(d).toNumber();c.push(i,r)}e=e.plus(b)}const M=f.div(g).toNumber(),[,y]=l,P=n.k.eq(0);P&&l.push(M,y||t),l.push(M,t),u.push(M,t,M,0);const w=v({val:p.multipliedBy(10**h),model:n});let j=t;const z=new e(h).div(g).toNumber();return w.vert.isNaN()||(j=t-w.vert.div(d).toNumber()),P&&c.length>=2&&(c.unshift(M,j),c.unshift(M,t)),c.push(z,j),f.lte(0)&&c.unshift(0,t),{quoteLinePoints:l,quoteLineAreaPoints:[0,t,0,y,...l],quoteLineAreaLinearGradientEndPointY:y,baseLinePoints:c,baseLineAreaPoints:[...c,z,t],baseLineAreaLinearGradientEndPointY:j,midPriceLinePoints:u}},[s,i,r,o,n,t,a,d])}({chartHeight:E,chartWidth:W,midPrice:a,xPoints:50,pmmModel:d,baseMinAndZoomMultiples:N,buyYPortion:G,sellYPortion:D}),se=e=>{var t;const i=e.target;if(i&&Y){const e=null===(t=i.getStage())||void 0===t?void 0:t.getPointerPosition();if(e){const{x:t}=e;if(t>W)return void Y.hide();z({x:t,tooltip:Y,buyBaseVert:H,sellBaseVert:Z,chartWidth:W,chartHeight:E,midPrice:a,pmmModel:d,baseTokenSymbol:C,quoteTokenSymbol:S,baseMinAndZoomMultiples:N,t:B,isHover:!0,color:q.tooltipColor,leftColor:q.leftLine,rightColor:q.rightLine})}}},ae=l(()=>i(e=>{const{target:t}=e,i=t.getStage();if(i){i.container().style.cursor="grabbing";const e=null==i?void 0:i.getPointerPosition();if(e){const t=e.x-I.current;I.current=e.x,R.current=e.x,A(e=>void 0===e.baseMin?e:{baseMin:P({dragDistance:t,prevBaseMin:e.baseMin,chartWidth:W,zoomMultiples:e.zoomMultiples}),zoomMultiples:e.zoomMultiples,targetMarginPriceX:0})}}},100),[W,A]),de=l(()=>i(e=>{e.cancelBubble=!0,e.evt.preventDefault();const t=e.evt.deltaY<0;A(e=>{const i=w({zoomIn:t,prevZoomMultiples:e.zoomMultiples});return{baseMin:j({midPrice:a,zoomMultiples:i}),zoomMultiples:i,targetMarginPriceX:e.targetMarginPriceX}})},100),[a,A]);return n(()=>{N.targetMarginPriceX>0&&null!==Y?z({x:N.targetMarginPriceX,tooltip:Y,buyBaseVert:H,sellBaseVert:Z,chartWidth:W,chartHeight:E,midPrice:a,pmmModel:d,baseTokenSymbol:C,quoteTokenSymbol:S,baseMinAndZoomMultiples:N,t:B,color:q.tooltipColor,leftColor:q.leftLine,rightColor:q.rightLine}):void 0!==R.current&&null!==Y&&z({x:R.current,tooltip:Y,buyBaseVert:H,sellBaseVert:Z,chartWidth:W,chartHeight:E,midPrice:a,pmmModel:d,baseTokenSymbol:C,quoteTokenSymbol:S,baseMinAndZoomMultiples:N,t:B,isHover:!0,color:q.tooltipColor,leftColor:q.leftLine,rightColor:q.rightLine})},[N,C,H,E,W,q.leftLine,q.rightLine,q.tooltipColor,a,d,S,Z,Y]),X.jsxs(u,{ref:V,width:o,offsetY:-k,height:r+k,draggable:!0,dragBoundFunc:function(){return{x:this.absolutePosition().x,y:this.absolutePosition().y}},onMouseMove:se,onMouseOver:se,onMouseOut:()=>{Y&&Y.hide()},onDragStart:function(e){const{target:t}=e,i=t.getStage();if(i){const e=i.getPointerPosition();e&&(I.current=e.x)}},onDragMove:ae,onDragEnd:e=>{const{target:t}=e,i=t.getStage();i&&(i.container().style.cursor="pointer")},onWheel:de,children:[X.jsxs(p,{children:[X.jsx(m,{x:0,y:0,width:o,height:E,stroke:q.grid,strokeWidth:1}),$.map((e,t)=>X.jsx(g,{points:e,stroke:q.grid,strokeWidth:1,lineCap:"round",lineJoin:"round",listening:!1},t)),Q.map((e,t)=>X.jsx(g,{points:e,stroke:q.grid,strokeWidth:1,lineCap:"round",lineJoin:"round",listening:!1},t)),K.map((e,t)=>X.jsx(g,{points:e,stroke:"#9d9d9d",strokeWidth:1,lineCap:"round",lineJoin:"round",listening:!1},t)),U.map((e,t)=>X.jsx(h,{x:e.x,y:e.y,text:e.text,fontFamily:"Manrope",fontSize:12,fill:"#9d9d9d",width:F,padding:0,align:"center",verticalAlign:"bottom",listening:!1},t)),X.jsx(g,{points:te,closed:!0,listening:!1,lineCap:"round",lineJoin:"round",fillLinearGradientStartPoint:{x:0,y:E},fillLinearGradientEndPoint:{x:0,y:ie},fillLinearGradientColorStops:q.leftBg}),X.jsx(g,{points:_,stroke:q.leftLine,strokeWidth:2,lineCap:"round",lineJoin:"round",listening:!1}),X.jsx(g,{points:re,closed:!0,listening:!1,lineCap:"round",lineJoin:"round",fillLinearGradientStartPoint:{x:W,y:E},fillLinearGradientEndPoint:{x:W,y:ne},fillLinearGradientColorStops:q.rightBg}),X.jsx(g,{points:oe,stroke:q.rightLine,strokeWidth:2,lineCap:"round",lineJoin:"round",listening:!1}),X.jsx(g,{points:le,stroke:q.midPriceLine,strokeWidth:2,lineCap:"round",lineJoin:"round",listening:!1})]}),X.jsxs(p,{ref:J,visible:!1,listening:!1,children:[X.jsx(g,{points:[],stroke:"#ff4f73",strokeWidth:1,lineCap:"round",lineJoin:"round",dash:[4,6],id:"toolTipVertLine"}),X.jsx(g,{points:[],stroke:"ff4f73",strokeWidth:1,lineCap:"round",lineJoin:"round",dash:[4,6],id:"toolTipHoriLine"}),X.jsx(b,{x:0,y:0,radius:5,fill:"#FF5072",stroke:"rgba(255, 80, 114, 0.3)",strokeWidth:12,id:"joinCircle"}),X.jsxs(f,{x:0,y:0,id:"priceTextLabel",children:[X.jsx(M,{fill:q.tooltipBg,id:"priceTextLabel-tag"}),X.jsx(h,{text:"",fontSize:12,fontFamily:"Manrope",padding:4,fill:"#FF5072",id:"priceTextLabel-text"})]}),X.jsxs(f,{x:0,y:0,id:"slippageTextLabel",children:[X.jsx(M,{fill:q.tooltipBg,id:"slippageTextLabel-tag"}),X.jsx(h,{text:"",fontSize:12,fontFamily:"Manrope",padding:4,fill:"#FF5072",id:"slippageTextLabel-text"})]}),X.jsxs(f,{x:0,y:0,id:"toolTip",children:[X.jsx(M,{fill:q.tooltipBg,pointerDirection:"down",pointerWidth:15,pointerHeight:8,cornerRadius:8,lineJoin:"round",id:"toolTip-tag"}),X.jsx(h,{text:"-",fontSize:12,lineHeight:17/12,padding:L,fontFamily:"Manrope",fill:"#FFFFFF",id:"toolTip-text"})]})]})]})}const ie=d.button`
21
- margin: 0;
22
- border: none;
23
- padding: 0;
24
- background: none;
25
-
26
- &:focus {
27
- outline: none;
28
- }
29
- &:active {
30
- outline: none;
31
- }
32
- `,oe=d.div`
33
- height: 100%;
34
- `,re=d.div`
35
- display: flex;
36
- align-items: center;
37
- `,ne=d.div`
38
- border: 1px solid ${({borderColor:e})=>e||"#2a2a2d"};
39
- flex: 1 0 50%;
40
-
41
- display: flex;
42
- align-items: center;
43
- justify-content: center;
44
- font-size: 12px;
45
- font-weight: 400;
46
- line-height: 17px;
47
- color: #606066;
48
-
49
- & + & {
50
- border-left: none;
51
- }
52
- `,le=d.span`
53
- color: #85858d;
54
- `,se=d.div`
55
- margin-top: 20px;
56
- display: flex;
57
- justify-content: center;
58
- margin-bottom: 9px;
59
- `,ae=d(ie)`
60
- border-radius: 13px;
61
- background-color: #373739;
62
- width: 24px;
63
- height: 24px;
64
- font-size: 18px;
65
- color: #85858d;
66
- line-height: 0;
67
- & + & {
68
- margin-left: 10px;
69
- }
70
- &:first-child,
71
- &:last-child {
72
- font-size: 20px;
73
- }
74
-
75
- &:hover {
76
- color: #fff;
77
- }
78
- `;function de({params:t,target:i,isBuy:o=!0}){const r=new e(t.b),n=new e(t.q);let l=new e(t.b0);const s=new e(t.q0),a=new e(t.i),d=new e(t.k),{R:c}=t;1===c&&l.eq(r)&&(l=q(r,n.minus(s),new e(1).div(a),d));const u=o?r.plus(i):r.minus(i);if(u.lt(l)||r.eq(l)){let t=l.multipliedBy(l).div(u).div(u);return t=new e(1).minus(d).plus(d.multipliedBy(t)),a.multipliedBy(t)}const p=new W;p.RStatus=c,p.B=r,p.B0=l,p.Q=n,p.Q0=s,p.i=a,p.k=d,p.mtFeeRate=new e(0),p.lpFeeRate=new e(0);let m=new e(0);m=o?p.querySellBase(i):p.queryBuyBase(i);const g=o?n.minus(m):n.plus(m);let h=s.multipliedBy(s).div(g).div(g);return h=new e(1).minus(d).plus(d.multipliedBy(h)),a.div(h)}const ce=({chartId:t,width:i=834,height:r=460,baseTokenSymbol:s,quoteTokenSymbol:d,pmmModel:c,pmmParams:u,midPrice:p=new e(0),colorMap:m,notShowAmountInput:g})=>{(({id:e})=>{n(()=>{function t(e){e.preventDefault()}let i=!1;try{const e={get passive(){return i=!0,!1}};window.addEventListener("test",()=>{},e),window.removeEventListener("test",()=>{})}catch(e){i=!1}const o=document.getElementById(e),r=!!i&&{passive:!1};return null==o||o.addEventListener("wheel",t,r),()=>{null==o||o.removeEventListener("wheel",t)}},[e])})({id:t});const[h,b]=a(""),[f,M]=a(""),[x,v]=a("-"),[y,z]=a("-"),[L,k]=a({baseMin:new e(0),zoomMultiples:C,targetMarginPriceX:0});n(()=>{void 0!==p&&k(e=>({baseMin:j({midPrice:p,zoomMultiples:e.zoomMultiples}),zoomMultiples:e.zoomMultiples,targetMarginPriceX:e.targetMarginPriceX}))},[p]);const O=l(()=>o(({type:t,amount:o})=>{""===o&&p&&(k({baseMin:j({midPrice:p,zoomMultiples:C}),zoomMultiples:C,targetMarginPriceX:0}),"buy"===t?v("-"):z("-"));const r=new e(o);if(!r.lte(0)&&!r.isNaN()&&(null==u?void 0:u.b)&&!r.gte(u.b)&&p)if("buy"===t){const e=de({params:u,target:r});k(o=>{const r=S({currentBaseMinAndZoomMultiples:o,targetPrice:e,midPrice:p,width:i});if(r.isSkip)return{baseMin:o.baseMin,zoomMultiples:o.zoomMultiples,targetMarginPriceX:r.targetX};if(r.targetX>0)return{baseMin:r.baseMin,zoomMultiples:r.zoomMultiples,targetMarginPriceX:r.targetX};const n=N({midPrice:p,width:i,type:t,targetPrice:e}),l=n.zoomMultiples.dp(6).toNumber();return{baseMin:j({midPrice:p,zoomMultiples:l}),zoomMultiples:l,targetMarginPriceX:n.targetX}}),v(`${T({input:e.minus(p).div(p)})}`)}else{const e=function({params:e,target:t}){return de({params:e,target:t,isBuy:!1})}({params:u,target:r});k(o=>{const r=S({currentBaseMinAndZoomMultiples:o,targetPrice:e,midPrice:p,width:i});if(r.isSkip)return{baseMin:o.baseMin,zoomMultiples:o.zoomMultiples,targetMarginPriceX:r.targetX};if(r.targetX>0)return{baseMin:r.baseMin,zoomMultiples:r.zoomMultiples,targetMarginPriceX:r.targetX};const n=N({midPrice:p,width:i,type:t,targetPrice:e}),l=n.zoomMultiples.dp(6).toNumber();return{baseMin:j({midPrice:p,zoomMultiples:l}),zoomMultiples:l,targetMarginPriceX:n.targetX}}),z(`+${T({input:e.minus(p).div(p)})}`)}},300),[u,p,i]);n(()=>{void 0!==h&&O({type:"buy",amount:h})},[O,h]),n(()=>{void 0!==f&&O({type:"sell",amount:f})},[O,f]);const q=e=>{let t=0;t=e?-.1*i:.1*i,k(e=>void 0===e.baseMin?e:{baseMin:P({dragDistance:t,prevBaseMin:e.baseMin,chartWidth:i,zoomMultiples:e.zoomMultiples}),zoomMultiples:e.zoomMultiples,targetMarginPriceX:e.targetMarginPriceX})},W=e=>{k(t=>{const i=w({zoomIn:null!=e&&e,prevZoomMultiples:t.zoomMultiples});return{baseMin:j({midPrice:p,zoomMultiples:i}),zoomMultiples:i,targetMarginPriceX:t.targetMarginPriceX}})},E=l(()=>{if(""===h)return!1;const t=new e(h);return!(!t.lte(0)&&!t.isNaN()&&(null==u?void 0:u.b)&&!t.gte(u.b))},[h,u]),F=l(()=>{if(""===f)return!1;const t=new e(f);return!(!t.lte(0)&&!t.isNaN()&&(null==u?void 0:u.b)&&!t.gte(u.b))},[f,u]);return X.jsxs(oe,{id:t,children:[g?"":X.jsxs(re,{children:[X.jsxs(ne,{borderColor:m&&m.grid,children:[B("pool.chart.buy-amount",{symbol:s}),X.jsx(_,{value:h,error:E,onChange:e=>{const t=A(e.target.value,2);null!==t&&b(t)}}),X.jsx(le,{children:B("pool.chart.price-impact",{amount:x})})]}),X.jsxs(ne,{borderColor:m&&m.grid,children:[B("pool.chart.sell-amount",{symbol:s}),X.jsx(_,{value:f,error:F,onChange:e=>{const t=A(e.target.value,2);null!==t&&M(t)}}),X.jsx(le,{children:B("pool.chart.price-impact",{amount:y})})]})]}),void 0!==u&&void 0!==p&&void 0!==c&&void 0!==L.baseMin&&void 0!==p&&X.jsx(te,{width:i,height:r,params:u,midPrice:p,pmmModel:c,baseTokenSymbol:s,quoteTokenSymbol:d,baseMinAndZoomMultiples:L,colorMap:m,setBaseMinAndZoomMultiples:k}),X.jsxs(se,{className:"operate-btn-wrapper",children:[X.jsx(ae,{onClick:()=>q(!0),children:X.jsx($,{})}),X.jsx(ae,{onClick:()=>W(!1),children:X.jsx(K,{})}),X.jsx(ae,{onClick:()=>W(!0),children:X.jsx(U,{})}),X.jsx(ae,{onClick:()=>q(!1),children:X.jsx(Q,{})})]})]})};export{ce as default};