@orderly.network/ui-order-entry 2.0.1-alpha.1 → 2.0.1-alpha.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.
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
13
13
 
14
14
  var Me__default = /*#__PURE__*/_interopDefault(Me);
15
15
 
16
- var ve=Me.createContext({}),Z=()=>Me.useContext(ve),ie=e=>{let{type:t,values:r}=e,[n,o]=hooks.useLocalStorage("TP/SL_Mode","Offset%"),a=Me.useMemo(()=>!r.PnL||!e.values.trigger_price?null:jsxRuntime.jsxs(ui.Flex,{children:[jsxRuntime.jsx("span",{className:"oui-text-xs oui-text-base-contrast-54",children:`Est.${n==="PnL"?"ROI":"PNL"}:`}),n==="PnL"?jsxRuntime.jsx(ui.Text.numeral,{rule:"percentages",className:ui.cn("oui-text-xs oui-ml-1",t==="TP"?"oui-text-trade-profit":"oui-text-trade-loss"),children:r.ROI}):jsxRuntime.jsx(ui.Text.numeral,{rule:"price",className:ui.cn("oui-text-xs oui-ml-1",t==="TP"?"oui-text-trade-profit":"oui-text-trade-loss"),children:r.PnL})]}),[n,e.values.PnL,e.values.trigger_price]);return jsxRuntime.jsx(ve.Provider,{value:{mode:n,setMode:o,tipsEle:a},children:e.children})};var Le=e=>{let{type:t,values:r,quote_dp:n}=e,{mode:o,setMode:a,tipsEle:d}=Z(),[c,l]=Me.useState(!1),x=Me.useMemo(()=>{switch(o){case"Offset":return `${t.toLowerCase()}_offset`;case"Offset%":return `${t.toLowerCase()}_offset_percentage`;default:return `${t.toLowerCase()}_pnl`}},[o]),F=Me.useMemo(()=>r[o],[r,o]),O=Me.useMemo(()=>[{label:"PnL",value:"PnL",testId:"PnL_menu_item"},{label:"Offset",value:"Offset",testId:"Offset_mneu_item"},{label:"Offset%",value:"Offset%",testId:"Offset%_menu_item"}],[]),y=Me.useRef("");return {mode:o,modes:O,formatter:p=>{let{dp:M=2}=p;return {onRenderBefore:(s,V)=>(s=`${s}`,t==="SL"&&o==="PnL"&&(s=s.startsWith("-")?s:"-"+s),s===""||s==="-"?"":o==="Offset%"?`${new utils.Decimal(s.replace(new RegExp(y.current.replace(".","\\.")+"$"),"")).mul(100).todp(2,4).toString()}${y.current}`:(o==="Offset"&&(s=utils.todpIfNeed(s,M)),`${s}`)),onSendBefore:s=>{if(/^\-?0{2,}$/.test(s))return "0";if(o==="Offset%"){if(s!==""){s=utils.todpIfNeed(s,2);let V=s.match(/\.0{0,2}$/);V?y.current=V[0]:y.current="",s=new utils.Decimal(s).div(100).toString(),s=`${s}${y.current}`;}}else s=utils.todpIfNeed(s,M);return s===""||s==="-"?"":s}}},onModeChange:p=>{a(p);},onFocus:()=>{l(!0);},onBlur:()=>{l(!1);},value:F,onValueChange:p=>{e.onChange(x,p);},quote_dp:n,tips:c?d:void 0}};var Ee=e=>{let{mode:t,modes:r,onModeChange:n,onValueChange:o,quote:a,quote_dp:d,value:c,type:l,tips:x,onFocus:F,onBlur:O}=e,[y,P]=Me.useState(t);Me.useEffect(()=>{P(t),I(t==="Offset%"?"%":a);},[t]);let[k,I]=Me.useState(t==="Offset%"?"%":a);Me.useEffect(()=>{P(c?"":t);},[c]);let q=Me.useMemo(()=>`${l.toLowerCase()}_${t.toLowerCase()}`,[]);return jsxRuntime.jsx(ui.Input.tooltip,{prefix:y,size:"md",placeholder:k,id:q,align:"right",value:c,tooltip:x,tooltipProps:{content:{side:e.type==="TP"?"top":"bottom"}},"data-testid":e.testId,autoComplete:"off",onValueChange:o,formatters:[e.formatter({dp:d,mode:t,type:l}),ui.inputFormatter.currencyFormatter],classNames:{root:l==="TP"?"oui-text-trade-profit":"oui-text-trade-loss",additional:"oui-text-base-contrast-54",input:"oui-text-inherit"},onFocus:()=>{P(""),I(""),F();},onBlur:()=>{P(c?"":t),I(t==="Offset%"?"%":a),O();},suffix:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[t==="Offset%"&&!!c&&jsxRuntime.jsx(ui.Text,{size:"2xs",color:"inherit",className:"oui-ml-[2px]",children:"%"}),jsxRuntime.jsx(dt,{mode:t,modes:r,onModeChange:p=>n(p.value)})]})})},dt=e=>jsxRuntime.jsx(ui.SimpleDropdownMenu,{currentValue:e.mode,menu:e.modes,align:"end",size:"xs",className:"oui-min-w-[80px]",onCloseAutoFocus:t=>t.preventDefault(),onSelect:t=>e.onModeChange(t),children:jsxRuntime.jsx("button",{className:"oui-p-2",children:jsxRuntime.jsx(ui.CaretDownIcon,{size:12,color:"white"})})});var Se=e=>{let{testId:t,quote:r,...n}=e,o=Le(n);return jsxRuntime.jsx(Ee,{...o,testId:t,quote:r,type:e.type})};var $=Me.createContext({}),Ne=$.Provider;var Re=e=>{let t=Me__default.default.useRef(null);return Me.useEffect(()=>{e.orderType!==types.OrderType.LIMIT&&e.orderType!==types.OrderType.MARKET&&e.onSwitchChanged(!1);},[e.orderType]),e.orderType!==types.OrderType.LIMIT&&e.orderType!==types.OrderType.MARKET||e.isReduceOnly?null:jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs(ui.Flex,{itemAlign:"center",gapX:1,children:[jsxRuntime.jsx(ui.Switch,{id:"order_entry_tpsl",className:"oui-h-[14px]",checked:e.switchState,disabled:e.orderType!==types.OrderType.LIMIT&&e.orderType!==types.OrderType.MARKET||e.isReduceOnly,onCheckedChange:r=>{e.onSwitchChanged(r);}}),jsxRuntime.jsx("label",{htmlFor:"order_entry_tpsl",className:"oui-text-xs",children:"TP/SL"}),jsxRuntime.jsx(ui.ExclamationFillIcon,{color:"white",size:14,opacity:1,className:"oui-text-white/[.36] hover:oui-text-white/80 oui-cursor-pointer",onClick:()=>{ui.modal.dialog({title:"Tips",size:"xs",content:jsxRuntime.jsx(ui.Text,{intensity:54,children:"TP/SL applies to the entire position. For partial TP/SL, set it in open positions."})});}})]}),jsxRuntime.jsx("div",{className:ui.cn("oui-max-h-0 oui-overflow-hidden oui-transition-all",e.switchState&&"oui-max-h-[100px]"),onTransitionEnd:()=>{t.current?.style.setProperty("opacity",e.switchState?"1":"0");},children:jsxRuntime.jsx(ke,{ref:t,onChange:e.onChange,values:e.values,errors:e.errors,quote_dp:e.quote_dp})})]})},ke=Me__default.default.forwardRef((e,t)=>jsxRuntime.jsxs("div",{ref:t,className:"oui-transition-all oui-pt-2 oui-pb-2 oui-px-[1px] oui-space-y-1",children:[jsxRuntime.jsx(ie,{values:e.values.tp,type:"TP",children:jsxRuntime.jsx(Fe,{type:"TP",error:e.errors?e.errors.tp_trigger_price?.message:"",onChange:e.onChange,values:e.values.tp,quote_dp:e.quote_dp})}),jsxRuntime.jsx(ie,{values:e.values.sl,type:"SL",children:jsxRuntime.jsx(Fe,{type:"SL",error:e.errors?e.errors.sl_trigger_price?.message:"",onChange:e.onChange,values:e.values.sl,quote_dp:e.quote_dp})})]}));ke.displayName="TPSLInputForm";var Lt=e=>{let {errorMsgVisible:t}=Me.useContext($),{tipsEle:r}=Z(),[n,o]=Me.useState(`${e.type} Price`),[a,d]=Me.useState("USDC"),[c,l]=Me.useState(!1),x=Me.useMemo(()=>e.error&&t?e.error:c?r:null,[e.error,t,c,r]);e.type==="SL"?"sl_trigger_price":"tp_trigger_price";return Me.useEffect(()=>{o(e.values.trigger_price?e.type:`${e.type} Price`);},[e.values.trigger_price]),jsxRuntime.jsx(ui.Input.tooltip,{prefix:n,size:"md",placeholder:a,align:"right",onFocus:()=>{o(e.type),d(""),l(!0);},onBlur:()=>{o(e.values.trigger_price?e.type:`${e.type} Price`),d("USDC"),l(!1);},tooltip:x,tooltipProps:{content:{side:e.type==="TP"?"top":"bottom"}},color:e.error?"danger":void 0,autoComplete:"off",value:e.values.trigger_price,classNames:{additional:"oui-text-base-contrast-54",root:"oui-pr-2 md:oui-pr-3",prefix:"oui-pr-1 md:oui-pr-2"},onValueChange:e.onChange,formatters:[ui.inputFormatter.numberFormatter,ui.inputFormatter.dpFormatter(e.quote_dp??2),ui.inputFormatter.currencyFormatter]})},Fe=e=>{let t=e.type==="SL"?"sl_trigger_price":"tp_trigger_price";return jsxRuntime.jsxs(ui.Grid,{cols:2,gapX:1,children:[jsxRuntime.jsx(Lt,{type:e.type,error:e.error,values:e.values??"",onChange:r=>{e.onChange(t,r);},quote_dp:e.quote_dp}),jsxRuntime.jsx(Se,{onChange:e.onChange,quote:"USDC",quote_dp:e.quote_dp,type:e.type,values:{PnL:e.values.PnL,Offset:e.values.Offset,"Offset%":e.values["Offset%"],ROI:e.values.ROI}})]})};var me=e=>{let{baseDP:t,quoteDP:r,order:n,onConfirm:o,onCancel:a}=e,{side:d,order_type:c,symbol:l}=n,[x,F]=hooks.useLocalStorage("orderly_order_confirm",!0);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(ui.Flex,{justify:"between",children:[jsxRuntime.jsx(ui.Text.formatted,{rule:"symbol",showIcon:!0,children:n.symbol}),jsxRuntime.jsxs(ui.Flex,{justify:"end",gapX:1,children:[jsxRuntime.jsx(Mt,{type:n.order_type}),d===types.OrderSide.BUY?jsxRuntime.jsx(ui.Badge,{color:"buy",size:"sm",children:"Buy"}):jsxRuntime.jsx(ui.Badge,{color:"sell",size:"sm",children:"Sell"})]})]}),jsxRuntime.jsx(ui.Divider,{className:"oui-my-4"}),jsxRuntime.jsxs("div",{className:ui.textVariants({size:"sm",intensity:54,className:"oui-space-y-1"}),children:[jsxRuntime.jsxs(ui.Flex,{justify:"between",children:[jsxRuntime.jsx(ui.Text,{children:"Qty."}),jsxRuntime.jsx(ui.Text.numeral,{rule:"price",dp:t,padding:!1,className:"oui-text-base-contrast",children:n.order_quantity})]}),n.trigger_price?jsxRuntime.jsxs(ui.Flex,{justify:"between",children:[jsxRuntime.jsx(ui.Text,{children:"Trigger"}),jsxRuntime.jsx(ui.Text.numeral,{unit:"USDC",rule:"price",className:"oui-text-base-contrast",unitClassName:"oui-text-base-contrast-36 oui-ml-1",dp:r,padding:!1,children:n.trigger_price})]}):null,jsxRuntime.jsxs(ui.Flex,{justify:"between",children:[jsxRuntime.jsx(ui.Text,{children:"Price"}),n.order_type===types.OrderType.MARKET||n.order_type===types.OrderType.STOP_MARKET?jsxRuntime.jsx(ui.Text,{intensity:80,children:"Market"}):jsxRuntime.jsx(ui.Text.numeral,{unit:"USDC",rule:"price",className:"oui-text-base-contrast",unitClassName:"oui-text-base-contrast-36 oui-ml-1",dp:r,padding:!1,children:n.order_price})]}),jsxRuntime.jsxs(ui.Flex,{justify:"between",children:[jsxRuntime.jsx(ui.Text,{children:"Est. Total"}),jsxRuntime.jsx(ui.Text.numeral,{unit:"USDC",rule:"price",dp:r,padding:!1,className:"oui-text-base-contrast",unitClassName:"oui-text-base-contrast-36 oui-ml-1",children:n.total})]})]}),n.tp_trigger_price||n.sl_trigger_price?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ui.Divider,{className:"oui-my-4"}),jsxRuntime.jsxs("div",{className:ui.textVariants({size:"sm",intensity:54,className:"oui-space-y-1"}),children:[n.tp_trigger_price&&jsxRuntime.jsxs(ui.Flex,{justify:"between",children:[jsxRuntime.jsx(ui.Text,{children:"TP Price"}),jsxRuntime.jsx(ui.Text.numeral,{unit:"USDC",rule:"price",coloring:!0,dp:r,padding:!1,unitClassName:"oui-text-base-contrast-36 oui-ml-1",children:n.tp_trigger_price})]}),n.sl_trigger_price&&jsxRuntime.jsxs(ui.Flex,{justify:"between",children:[jsxRuntime.jsx(ui.Text,{children:"SL Price"}),jsxRuntime.jsx(ui.Text.numeral,{unit:"USDC",rule:"price",coloring:!0,className:"oui-text-trade-loss",unitClassName:"oui-text-base-contrast-36 oui-ml-1",dp:r,padding:!1,children:n.sl_trigger_price})]})]})]}):null,jsxRuntime.jsxs(ui.Flex,{gapX:1,pt:8,pb:3,children:[jsxRuntime.jsx(ui.Checkbox,{id:"orderConfirm",color:"white",onCheckedChange:O=>{F(!O);}}),jsxRuntime.jsx("label",{htmlFor:"orderConfirm",className:ui.textVariants({size:"xs",intensity:54}),children:"Disable order confirmation"})]}),jsxRuntime.jsxs(ui.Grid,{cols:2,gapX:3,children:[jsxRuntime.jsx(ui.Button,{color:"secondary",size:"md",onClick:()=>a(),children:"Cancel"}),jsxRuntime.jsx(ui.Button,{size:"md",onClick:()=>o(),children:"Confirm"})]})]})};me.displayName="OrderConfirmDialog";var Mt=e=>{let t=Me.useMemo(()=>{switch(e.type){case types.OrderType.LIMIT:return "Limit";case types.OrderType.MARKET:return "Market";case types.OrderType.STOP_LIMIT:return "Stop Limit";case types.OrderType.STOP_MARKET:return "Stop Market";default:return ""}},[e.type]);return jsxRuntime.jsx(ui.Badge,{color:"neutral",size:"sm",children:t})},wt=e=>{let{close:t,resolve:r,reject:n,...o}=e;return jsxRuntime.jsx(me,{...o,onCancel:t,onConfirm:()=>{r(),t();}})},fe="orderConfirm";ui.registerSimpleDialog(fe,wt,{size:"sm",title:"Order confirm"});var Be=e=>{let{pinned:t,orderTypeExtra:r}=e,n=o=>a=>{e.onValueChange&&e.onValueChange("order_type_ext",a?o:"");};return Me.useEffect(()=>{e.onValueChange?.("visible_quantity",e.hidden?0:1);},[e.hidden]),jsxRuntime.jsxs("div",{className:"oui-text-base-contrast-54",children:[jsxRuntime.jsxs(ui.Flex,{gapX:3,justify:t?"start":"between",mb:3,width:t?"unset":"100%",children:[jsxRuntime.jsxs(ui.Flex,{itemAlign:"center",children:[jsxRuntime.jsx(ui.Checkbox,{id:"toggle_order_post_only",className:"oui-peer",color:"white",variant:"radio",disabled:!e.showExtra,checked:r===types.OrderType.POST_ONLY,onCheckedChange:n(types.OrderType.POST_ONLY)}),jsxRuntime.jsx("label",{htmlFor:"toggle_order_post_only",className:"oui-text-2xs oui-ml-1 peer-data-[disabled]:oui-text-base-contrast-20",children:"Post only"})]}),jsxRuntime.jsxs(ui.Flex,{itemAlign:"center",children:[jsxRuntime.jsx(ui.Checkbox,{id:"toggle_order_iov",color:"white",className:"oui-peer",variant:"radio",checked:r===types.OrderType.IOC,onCheckedChange:n(types.OrderType.IOC),disabled:!e.showExtra}),jsxRuntime.jsx("label",{htmlFor:"toggle_order_iov",className:"oui-text-2xs oui-ml-1 peer-data-[disabled]:oui-text-base-contrast-20",children:"IOC"})]}),jsxRuntime.jsxs(ui.Flex,{itemAlign:"center",children:[jsxRuntime.jsx(ui.Checkbox,{id:"toggle_order_fok",color:"white",variant:"radio",className:"oui-peer",checked:r===types.OrderType.FOK,onCheckedChange:n(types.OrderType.FOK),disabled:!e.showExtra}),jsxRuntime.jsx("label",{htmlFor:"toggle_order_fok",className:"oui-text-2xs oui-ml-1 peer-data-[disabled]:oui-text-base-contrast-20",children:"FOK"})]})]}),jsxRuntime.jsxs(ui.Flex,{gapX:6,children:[jsxRuntime.jsxs(ui.Flex,{children:[jsxRuntime.jsx(ui.Checkbox,{id:"toggle_order_confirm",color:"white",checked:e.needConfirm,onCheckedChange:o=>{e.setNeedConfirm(!!o);}}),jsxRuntime.jsx("label",{htmlFor:"toggle_order_confirm",className:"oui-text-2xs oui-ml-1",children:"Order confirm"})]}),jsxRuntime.jsxs(ui.Flex,{children:[jsxRuntime.jsx(ui.Checkbox,{id:"toggle_order_hidden",color:"white",checked:e.hidden,onCheckedChange:o=>{e.setHidden(o);}}),jsxRuntime.jsx("label",{htmlFor:"toggle_order_hidden",className:"oui-text-2xs oui-ml-1",children:"Hidden"})]})]}),!t&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ui.Divider,{className:"oui-my-3"}),jsxRuntime.jsxs(ui.Flex,{children:[jsxRuntime.jsx(ui.Switch,{id:"toggle_order_keep_visible",onCheckedChange:o=>{e.setPinned(o);}}),jsxRuntime.jsx("label",{htmlFor:"toggle_order_keep_visible",className:"oui-text-2xs oui-ml-1",children:"Keep visible"})]})]})]})};var ze=()=>({});var ee=e=>{let t=ze();return jsxRuntime.jsx(Be,{...t,...e})};var ye=e=>{let{side:t,formattedOrder:r,setOrderValue:n,symbolInfo:o,maxQty:a,freeCollateral:d,helper:c,submit:l,metaState:x,refs:F}=e,{errors:O,validated:y}=x,[P,k]=Me.useState(!1),[I,q]=hooks.useLocalStorage("orderly_order_confirm",!0),[p,M]=hooks.useLocalStorage("orderly-order-additional-pinned",!0),[s,V]=hooks.useLocalStorage("orderly-order-hidden",!1),oe=Me.useMemo(()=>t===types.OrderSide.BUY?"Buy / Long":"Sell / Short",[t]);Me.useEffect(()=>{y&&k(!0);},[y]),Me.useEffect(()=>{let m=A=>{A.target.closest("#order-entry-submit-button")||k(X=>X&&!1);};return P?document.addEventListener("click",m):document.removeEventListener("click",m),()=>{document.removeEventListener("click",m);}},[P]);let ne=()=>{c.validate().then(m=>I?ui.modal.show(fe,{order:r,quote:o.quote,base:o.base,quoteDP:o.quote_dp,baseDP:o.base_dp}):!0,m=>{k(!0);}).then(()=>l().then(()=>{n("order_quantity","");})).catch(m=>{m instanceof types.SDKError&&ui.toast.error(`Error:${m.message}`);});};return jsxRuntime.jsx(Ne,{value:{errorMsgVisible:P},children:jsxRuntime.jsxs("div",{className:"oui-space-y-2 xl:oui-space-y-3 oui-text-base-contrast-54",ref:e.containerRef,children:[jsxRuntime.jsxs(ui.Flex,{gapX:2,className:"oui-flex-col lg:oui-flex-row oui-gap-y-3",children:[jsxRuntime.jsxs("div",{className:"oui-grid oui-grid-cols-2 oui-w-full oui-flex-1 oui-gap-x-2 lg:oui-flex lg:oui-gap-x-[6px]",children:[jsxRuntime.jsx(ui.Button,{onClick:()=>{e.setOrderValue("side",types.OrderSide.BUY);},size:"md",fullWidth:!0,"data-type":types.OrderSide.BUY,className:ui.cn(t===types.OrderSide.BUY&&e.canTrade?"oui-bg-success-darken hover:oui-bg-success-darken/80 active:oui-bg-success-darken/80":"oui-bg-base-7 hover:oui-bg-base-6 active:oui-bg-base-6 oui-text-base-contrast-36"),children:"Buy"}),jsxRuntime.jsx(ui.Button,{onClick:()=>{e.setOrderValue("side",types.OrderSide.SELL);},"data-type":types.OrderSide.SELL,fullWidth:!0,size:"md",className:ui.cn(t===types.OrderSide.SELL&&e.canTrade?"oui-bg-danger-darken hover:oui-bg-danger-darken/80 active:oui-bg-danger-darken/80":"oui-bg-base-7 hover:oui-bg-base-6 active:oui-bg-base-6 oui-text-base-contrast-36"),children:"Sell"})]}),jsxRuntime.jsx("div",{className:"oui-w-full lg:oui-flex-1",children:jsxRuntime.jsx(sr,{type:r.order_type,side:t,canTrade:e.canTrade,onChange:m=>{n("order_type",m);}})})]}),jsxRuntime.jsxs(ui.Flex,{justify:"between",children:[jsxRuntime.jsx(ui.Text,{size:"2xs",children:"Available"}),jsxRuntime.jsx(ui.Text.numeral,{unit:o.quote,size:"2xs",className:"oui-text-base-contrast-80",unitClassName:"oui-ml-1 oui-text-base-contrast-54",dp:2,padding:!1,children:e.canTrade?d:0})]}),jsxRuntime.jsx(nr,{type:e.type,symbolInfo:o,values:{quantity:r.order_quantity,price:r.order_price,trigger_price:r.trigger_price,total:r.total},errors:y?O:null,onChange:(m,A)=>{e.setOrderValue(m,A);},refs:e.refs,onBlur:e.onBlur,onFocus:e.onFocus}),jsxRuntime.jsx(ar,{canTrade:e.canTrade,maxQty:a,currentQtyPercentage:e.currentQtyPercentage,value:r.order_quantity?Number(r.order_quantity):0,tick:o.base_tick,dp:o.base_dp,setMaxQty:e.setMaxQty,onValueChange:m=>{n("order_quantity",m);},side:e.side}),jsxRuntime.jsx(uiConnector.AuthGuard,{buttonProps:{fullWidth:!0},children:jsxRuntime.jsx(ui.ThrottledButton,{fullWidth:!0,id:"order-entry-submit-button","data-type":types.OrderSide.BUY,className:ui.cn(t===types.OrderSide.BUY?"orderly-order-entry-submit-button-buy oui-bg-success-darken hover:oui-bg-success-darken/80 active:oui-bg-success-darken/80":"orderly-order-entry-submit-button-sell oui-bg-danger-darken hover:oui-bg-danger-darken/80 active:oui-bg-danger-darken/80"),onClick:()=>{ne();},loading:e.isMutating,children:oe})}),jsxRuntime.jsx(lr,{canTrade:e.canTrade,quote:o.quote,estLiqPrice:e.estLiqPrice,estLeverage:e.estLeverage,currentLeverage:e.currentLeverage}),jsxRuntime.jsx(ui.Divider,{className:"oui-w-full"}),jsxRuntime.jsx(Re,{quote_dp:e.symbolInfo.quote_dp,switchState:e.tpslSwitch,onSwitchChanged:e.setTpslSwitch,orderType:r.order_type,errors:y?O:null,isReduceOnly:r.reduce_only,values:{tp:{trigger_price:r.tp_trigger_price??"",PnL:r.tp_pnl??"",Offset:r.tp_offset??"","Offset%":r.tp_offset_percentage??"",ROI:r.tp_ROI??""},sl:{trigger_price:r.sl_trigger_price??"",PnL:r.sl_pnl??"",Offset:r.sl_offset??"","Offset%":r.sl_offset_percentage??"",ROI:r.sl_ROI??""}},onChange:(m,A)=>{e.setOrderValue(m,A);}}),jsxRuntime.jsxs(ui.Flex,{justify:"between",itemAlign:"center",className:"!oui-mt-[0px] xl:!oui-mt-3",children:[jsxRuntime.jsxs(ui.Flex,{itemAlign:"center",gapX:1,children:[jsxRuntime.jsx(ui.Switch,{className:"oui-h-[14px]",id:"reduceOnly",checked:e.formattedOrder.reduce_only,onCheckedChange:m=>{e.setOrderValue("reduce_only",m),m&&e.setOrderValue("order_type_ext","");}}),jsxRuntime.jsx("label",{htmlFor:"reduceOnly",className:"oui-text-xs",children:"Reduce only"})]}),!p&&jsxRuntime.jsx(ur,{pinned:p,setPinned:M,needConfirm:I,setNeedConfirm:q,onValueChange:n,orderTypeExtra:r.order_type_ext,showExtra:r.order_type===types.OrderType.LIMIT&&!e.tpslSwitch,hidden:s,setHidden:V})]}),p&&jsxRuntime.jsxs(ui.Box,{p:2,r:"md",intensity:700,position:"relative",children:[jsxRuntime.jsx(ee,{pinned:p,setPinned:M,needConfirm:I,setNeedConfirm:q,onValueChange:n,orderTypeExtra:r.order_type_ext,showExtra:r.order_type===types.OrderType.LIMIT&&!e.tpslSwitch,hidden:s,setHidden:V}),jsxRuntime.jsx(or,{onClick:()=>{M(!1);},className:"oui-absolute oui-top-2 oui-right-2 oui-group"})]})]})})},Qe="M10.007 1.302a.74.74 0 0 0-.486.214c-1.033.989-1.349 1.815-.972 2.948-.88.675-1.437.84-2.536.84-1.503 0-2.484.182-3.152.85v.02a1.583 1.583 0 0 0 0 2.248l1.867 1.882-3.181 3.18c-.26.26-.28.696-.02.956.261.26.699.26.959 0l3.193-3.194 1.87 1.861a1.585 1.585 0 0 0 2.25 0h.02c.668-.667.854-1.523.854-3.144 0-1.03.212-1.758.852-2.523 1.233.361 1.95.015 2.961-.995a.68.68 0 0 0 .188-.48c0-.234-.06-.593-.209-1.04a5.34 5.34 0 0 0-1.312-2.103 5.35 5.35 0 0 0-2.104-1.312c-.448-.15-.808-.208-1.042-.208",or=e=>{let[t,r]=Me.useState(Qe);return jsxRuntime.jsx("button",{...e,children:jsxRuntime.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",onMouseEnter:()=>{r('M10.008 1.302a.74.74 0 0 0-.486.214c-1.033.989-1.349 1.815-.972 2.948-.88.675-1.437.84-2.536.84-1.503 0-2.484.182-3.152.85v.02a1.583 1.583 0 0 0 0 2.248l1.867 1.882-3.181 3.18c-.26.26-.28.696-.02.956.261.26.699.26.959 0l3.193-3.194 1.87 1.861a1.585 1.585 0 0 0 2.25 0h.02c.668-.667.854-1.523.854-3.144 0-1.03.212-1.758.853-2.523 1.232.361 1.95.015 2.96-.995a.68.68 0 0 0 .188-.48c0-.234-.06-.593-.209-1.04a5.34 5.34 0 0 0-1.312-2.103A5.35 5.35 0 0 0 11.05 1.51c-.448-.15-.808-.208-1.042-.208m.258 1.37c.708.131 1.421.6 1.93 1.107.507.508.94 1.13 1.119 1.945-.636.61-1.026.658-1.662.323a.67.67 0 0 0-.779.117c-1.214 1.213-1.533 2.314-1.533 3.8 0 1.292-.076 1.773-.48 2.206-.113.123-.27.104-.374 0L3.799 7.486a.24.24 0 0 1-.017-.34c.239-.29.769-.515 2.226-.514 1.742.001 2.668-.448 3.812-1.52a.67.67 0 0 0 .125-.77c-.343-.686-.29-1.047.321-1.67"');},onMouseLeave:()=>{r(Qe);},children:jsxRuntime.jsx("path",{d:t,fill:"#608CFF"})})})},nr=e=>{let{type:t,symbolInfo:r,errors:n,values:o,onFocus:a,onBlur:d}=e,c=l=>n&&n[l]?n[l].message:"";return jsxRuntime.jsxs("div",{className:"oui-space-y-1",children:[t===types.OrderType.STOP_LIMIT||t===types.OrderType.STOP_MARKET?jsxRuntime.jsx("div",{className:"oui-group",children:jsxRuntime.jsx(W,{label:"Trigger",suffix:r.quote,error:c("trigger_price"),id:"trigger",ref:e.refs.triggerPriceInputRef,value:o.trigger_price,onChange:l=>{e.onChange("trigger_price",l);},formatters:[ui.inputFormatter.dpFormatter(r.quote_dp)],onFocus:a(1),onBlur:d(1)})}):null,t===types.OrderType.LIMIT||t===types.OrderType.STOP_LIMIT?jsxRuntime.jsx("div",{className:"oui-group",children:jsxRuntime.jsx(W,{label:"Price",suffix:r.quote,id:"price",value:o.price,error:c("order_price"),ref:e.refs.priceInputRef,onChange:l=>{e.onChange("order_price",l);},formatters:[ui.inputFormatter.dpFormatter(r.quote_dp)],onFocus:a(0),onBlur:d(0)})}):null,jsxRuntime.jsxs(ui.Grid,{cols:2,className:"oui-space-x-1 oui-group",children:[jsxRuntime.jsx(W,{label:"Qty",suffix:r.base,id:"order_quantity_input",name:"order_quantity_input",className:"!oui-rounded-br !oui-rounded-tr",value:o.quantity,error:c("order_quantity"),onChange:l=>{e.onChange("order_quantity",l);},formatters:[ui.inputFormatter.dpFormatter(r.base_dp)],onFocus:a(2),onBlur:d(2)}),jsxRuntime.jsx(W,{label:"Total\u2248",suffix:r.quote,id:"total",className:"!oui-rounded-bl !oui-rounded-tl",value:o.total,error:c("total"),onChange:l=>{e.onChange("total",l);},onFocus:a(3),onBlur:d(3),formatters:[ui.inputFormatter.dpFormatter(r.quote_dp)]})]})]})},W=Me.forwardRef((e,t)=>{let{errorMsgVisible:r}=Me.useContext($),[n,o]=Me.useState("0");return jsxRuntime.jsx(ui.Input.tooltip,{ref:t,tooltip:r?e.error:void 0,autoComplete:"off",autoFocus:e.autoFocus,size:"lg",placeholder:n,id:e.id,name:e.name,color:e.error?"danger":void 0,prefix:jsxRuntime.jsx(ir,{id:e.id,children:e.label}),suffix:e.suffix,value:e.value||"",onValueChange:e.onChange,onFocus:a=>{o(""),e.onFocus?.(a);},onBlur:a=>{o("0"),e.onBlur?.(a);},formatters:[...e.formatters??[],ui.inputFormatter.numberFormatter,ui.inputFormatter.currencyFormatter],classNames:{root:ui.cn("orderly-order-entry oui-relative oui-pt-8 oui-h-[54px] oui-px-2 oui-py-1 oui-pr-2 oui-border oui-border-solid oui-border-line oui-rounded group-first:oui-rounded-t-xl group-last:oui-rounded-b-xl",e.className),input:"oui-mt-5 oui-mb-1 oui-h-5",prefix:"oui-absolute oui-left-2 oui-top-[7px] oui-text-base-contrast-36",suffix:"oui-absolute oui-right-0 oui-top-0 oui-text-base-contrast-36 oui-text-2xs oui-justify-start oui-py-2"}})});W.displayName="CustomInput";var ir=e=>jsxRuntime.jsx("label",{htmlFor:e.id,className:"oui-absolute oui-left-2 oui-top-[7px] oui-text-base-contrast-36 oui-text-2xs",children:e.children}),ar=e=>{let{canTrade:t}=e,r=Me.useMemo(()=>t?e.side===types.OrderSide.BUY?"buy":"sell":void 0,[e.side,t]),n=Me.useMemo(()=>e.side===types.OrderSide.BUY?"Max buy":"Max sell",[e.side]);return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx(ui.Slider.single,{disabled:e.maxQty===0||!t,value:e.value,color:r,markCount:4,showTip:!0,max:e.maxQty,step:e.tick,onValueChange:e.onValueChange}),jsxRuntime.jsxs(ui.Flex,{justify:"between",className:"oui-pt-1 xl:oui-pt-2",children:[jsxRuntime.jsx(ui.Text.numeral,{rule:"percentages",size:"2xs",color:r,dp:2,padding:!1,children:t?e.currentQtyPercentage:0}),jsxRuntime.jsxs(ui.Flex,{children:[jsxRuntime.jsx("button",{className:ui.textVariants({size:"2xs",className:"oui-mr-1"}),onClick:()=>e.setMaxQty(),children:n}),jsxRuntime.jsx(ui.Text.numeral,{size:"2xs",color:r,dp:e.dp,padding:!1,children:t?e.maxQty:0})]})]})]})},sr=e=>{let t=[{label:"Limit order",value:types.OrderType.LIMIT},{label:"Market order",value:types.OrderType.MARKET},{label:"Stop limit",value:types.OrderType.STOP_LIMIT},{label:"Stop market",value:types.OrderType.STOP_MARKET}];return jsxRuntime.jsx(ui.Select.options,{currentValue:e.type,value:e.type,options:t,onValueChange:e.onChange,contentProps:{className:"oui-bg-base-8 oui-w-full"},valueFormatter:(r,n)=>{let o=t.find(a=>a.value===r);return o?jsxRuntime.jsx(ui.Text,{size:"xs",color:e.canTrade?e.side===types.OrderSide.BUY?"buy":"sell":void 0,children:o?.label.replace(" order","")}):jsxRuntime.jsx(ui.Text,{size:"xs",children:n.placeholder})},size:"md"})};function lr(e){let{canTrade:t}=e;return jsxRuntime.jsxs("div",{className:"oui-space-y-[2px] xl:oui-space-y-1",children:[jsxRuntime.jsxs(ui.Flex,{justify:"between",children:[jsxRuntime.jsx(ui.Text,{size:"2xs",children:"Est. Liq. price"}),jsxRuntime.jsx(ui.Text.numeral,{unit:e.quote,size:"2xs",className:"oui-text-base-contrast-80",unitClassName:"oui-ml-1 oui-text-base-contrast-36",children:t?e.estLiqPrice??"--":"--"})]}),jsxRuntime.jsxs(ui.Flex,{justify:"between",children:[jsxRuntime.jsx(ui.Text,{size:"2xs",children:"Account leverage"}),jsxRuntime.jsxs(ui.Flex,{gapX:1,className:ui.textVariants({size:"2xs",intensity:80}),children:[jsxRuntime.jsx(ui.Text.numeral,{unit:t?"x":void 0,children:t?e.currentLeverage??"--":"--"}),e.estLeverage&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsxRuntime.jsx("path",{d:"M2.505 4.997c0-.23.186-.416.416-.416H6.07L4.833 3.332l.586-.585 1.964 1.95a.42.42 0 0 1 .122.3.42.42 0 0 1-.122.3l-1.964 1.95-.586-.585L6.07 5.413H2.921a.416.416 0 0 1-.416-.416",fill:"#fff",fillOpacity:".54"})}),jsxRuntime.jsx("span",{children:`${e.estLeverage}x`})]})]})]})]})}function ur(e){let[t,r]=Me.useState(!1);return jsxRuntime.jsxs(ui.PopoverRoot,{open:t,onOpenChange:r,children:[jsxRuntime.jsx(ui.PopoverTrigger,{asChild:!0,children:jsxRuntime.jsx("button",{onClick:()=>{r(!0);},children:jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",className:"oui-fill-white/[.36] hover:oui-fill-white/80",children:jsxRuntime.jsx("path",{d:"M3.332 2.665a.667.667 0 0 0-.667.667v1.333c0 .368.299.667.667.667h1.333a.667.667 0 0 0 .667-.667V3.332a.667.667 0 0 0-.667-.667zm4 0a.667.667 0 0 0-.667.667v1.333c0 .368.299.667.667.667h1.333a.667.667 0 0 0 .667-.667V3.332a.667.667 0 0 0-.667-.667zm4 0a.667.667 0 0 0-.667.667v1.333c0 .368.299.667.667.667h1.333a.667.667 0 0 0 .667-.667V3.332a.667.667 0 0 0-.667-.667zm-8 4a.667.667 0 0 0-.667.667v1.333c0 .368.299.667.667.667h1.333a.667.667 0 0 0 .667-.667V7.332a.667.667 0 0 0-.667-.667zm4 0a.667.667 0 0 0-.667.667v1.333c0 .368.299.667.667.667h1.333a.667.667 0 0 0 .667-.667V7.332a.667.667 0 0 0-.667-.667zm4 0a.667.667 0 0 0-.667.667v1.333c0 .368.299.667.667.667h1.333a.667.667 0 0 0 .667-.667V7.332a.667.667 0 0 0-.667-.667zm-8 4a.667.667 0 0 0-.667.667v1.333c0 .368.299.667.667.667h1.333a.667.667 0 0 0 .667-.667v-1.333a.667.667 0 0 0-.667-.667zm4 0a.667.667 0 0 0-.667.667v1.333c0 .368.299.667.667.667h1.333a.667.667 0 0 0 .667-.667v-1.333a.667.667 0 0 0-.667-.667zm4 0a.667.667 0 0 0-.667.667v1.333c0 .368.299.667.667.667h1.333a.667.667 0 0 0 .667-.667v-1.333a.667.667 0 0 0-.667-.667z"})})})}),jsxRuntime.jsx(ui.PopoverContent,{side:"top",align:"end",className:"oui-w-[230px]",children:jsxRuntime.jsx(ee,{...e})})]})}var He=e=>{let[t,r]=hooks.useLocalStorage("orderly-order-entry-order-type",types.OrderType.LIMIT),[n,o]=hooks.useLocalStorage("orderly-order-entry-order-side",types.OrderSide.BUY),{formattedOrder:a,setValue:d,setValues:c,symbolInfo:l,...x}=hooks.useOrderEntry(e.symbol,{initialOrder:{symbol:e.symbol,order_type:t,side:n}}),[F,O]=hooks.useLocalStorage("orderly-order-entry-tp_sl-switch",!1),{state:y}=hooks.useAccount(),{wrongNetwork:P}=reactApp.useAppContext(),k=Me.useMemo(()=>y.status===types.AccountStatusEnum.EnableTrading&&!P,[y.status,P]),{currentLeverage:I}=hooks.useMarginRatio(),q=hooks.useEventEmitter(),p=Me.useRef(4),M=Me.useRef(null),s=Me.useRef(null),V=Me.useMemo(()=>Number(a.order_quantity)>=Number(x.maxQty)?1:ui.convertValueToPercentage(Number(a.order_quantity??0),0,x.maxQty)/100,[a.order_quantity,x.maxQty]),oe=()=>{if(l.base_tick<1)return;let f=hooks.utils.formatNumber(a?.order_quantity,new utils.Decimal(l?.base_tick||"0").toNumber());d("order_quantity",f,{shouldUpdateLastChangedField:!1});},ne=f=>v=>{p.current=f;},m=f=>v=>{setTimeout(()=>{p.current===f&&(p.current=4);},300),(f===2||f===3)&&oe();};Me.useEffect(()=>{let f=v=>{if(p.current===1)(a.order_type===types.OrderType.STOP_LIMIT||a.order_type===types.OrderType.STOP_MARKET)&&(d("trigger_price",utils.removeTrailingZeros(v[0])),H(M.current));else if(a.order_type===types.OrderType.STOP_LIMIT||a.order_type===types.OrderType.LIMIT)d("order_price",utils.removeTrailingZeros(v[0])),H(s.current);else {let z;a.order_type===types.OrderType.STOP_MARKET?z=types.OrderType.STOP_LIMIT:a.order_type===types.OrderType.MARKET&&(z=types.OrderType.LIMIT),typeof z<"u"&&d("order_type",z),d("order_price",utils.removeTrailingZeros(v[0])),H(s.current);}function H(z){setTimeout(()=>{z?.focus();},0);}};return q.on("orderbook:item:click",f),()=>{q.off("orderbook:item:click",f);}},[a.order_type,a.order_quantity,l]);let A=()=>{c({tp_trigger_price:"",sl_trigger_price:""});},he=()=>{c({order_type_ext:void 0});},X=()=>{d("order_quantity",x.maxQty);},$e=(f,v,H)=>{d(f,v,H),f==="order_type"&&r(v),f==="side"&&o(v),(f==="reduce_only"&&v||f==="order_type"&&(v===types.OrderType.STOP_LIMIT||v===types.OrderType.STOP_MARKET))&&A();},Ye=f=>{O(f),f?he():A();};return {...x,currentQtyPercentage:V,side:a.side,type:a.order_type,setOrderValue:$e,currentLeverage:I,formattedOrder:a,tpslSwitch:F,setTpslSwitch:Ye,setMaxQty:X,symbolInfo:l,onFocus:ne,onBlur:m,refs:{triggerPriceInputRef:M,priceInputRef:s},canTrade:k}};var Pr=e=>{let t=He(e);return jsxRuntime.jsx(ye,{...t,containerRef:e.containerRef})};
16
+ var ve=Me.createContext({}),Z=()=>Me.useContext(ve),ie=e=>{let{type:t,values:r}=e,[n,o]=hooks.useLocalStorage("TP/SL_Mode","Offset%"),a=Me.useMemo(()=>!r.PnL||!e.values.trigger_price?null:jsxRuntime.jsxs(ui.Flex,{children:[jsxRuntime.jsx("span",{className:"oui-text-xs oui-text-base-contrast-54",children:`Est.${n==="PnL"?"ROI":"PNL"}:`}),n==="PnL"?jsxRuntime.jsx(ui.Text.numeral,{rule:"percentages",className:ui.cn("oui-text-xs oui-ml-1",t==="TP"?"oui-text-trade-profit":"oui-text-trade-loss"),children:r.ROI}):jsxRuntime.jsx(ui.Text.numeral,{rule:"price",className:ui.cn("oui-text-xs oui-ml-1",t==="TP"?"oui-text-trade-profit":"oui-text-trade-loss"),children:r.PnL})]}),[n,e.values.PnL,e.values.trigger_price]);return jsxRuntime.jsx(ve.Provider,{value:{mode:n,setMode:o,tipsEle:a},children:e.children})};var Le=e=>{let{type:t,values:r,quote_dp:n}=e,{mode:o,setMode:a,tipsEle:c}=Z(),[m,l]=Me.useState(!1),x=Me.useMemo(()=>{switch(o){case"Offset":return `${t.toLowerCase()}_offset`;case"Offset%":return `${t.toLowerCase()}_offset_percentage`;default:return `${t.toLowerCase()}_pnl`}},[o]),F=Me.useMemo(()=>r[o],[r,o]),O=Me.useMemo(()=>[{label:"PnL",value:"PnL",testId:"PnL_menu_item"},{label:"Offset",value:"Offset",testId:"Offset_mneu_item"},{label:"Offset%",value:"Offset%",testId:"Offset%_menu_item"}],[]),y=Me.useRef("");return {mode:o,modes:O,formatter:p=>{let{dp:M=2}=p;return {onRenderBefore:(s,V)=>(s=`${s}`,t==="SL"&&o==="PnL"&&(s=s.startsWith("-")?s:"-"+s),s===""||s==="-"?"":o==="Offset%"?`${new utils.Decimal(s.replace(new RegExp(y.current.replace(".","\\.")+"$"),"")).mul(100).todp(2,4).toString()}${y.current}`:(o==="Offset"&&(s=utils.todpIfNeed(s,M)),`${s}`)),onSendBefore:s=>{if(/^\-?0{2,}$/.test(s))return "0";if(o==="Offset%"){if(s!==""){s=utils.todpIfNeed(s,2);let V=s.match(/\.0{0,2}$/);V?y.current=V[0]:y.current="",s=new utils.Decimal(s).div(100).toString(),s=`${s}${y.current}`;}}else s=utils.todpIfNeed(s,M);return s===""||s==="-"?"":s}}},onModeChange:p=>{a(p);},onFocus:()=>{l(!0);},onBlur:()=>{l(!1);},value:F,onValueChange:p=>{e.onChange(x,p);},quote_dp:n,tips:m?c:void 0}};var Ee=e=>{let{mode:t,modes:r,onModeChange:n,onValueChange:o,quote:a,quote_dp:c,value:m,type:l,tips:x,onFocus:F,onBlur:O}=e,[y,P]=Me.useState(t);Me.useEffect(()=>{P(t),I(t==="Offset%"?"%":a);},[t]);let[k,I]=Me.useState(t==="Offset%"?"%":a);Me.useEffect(()=>{P(m?"":t);},[m]);let q=Me.useMemo(()=>`${l.toLowerCase()}_${t.toLowerCase()}`,[]);return jsxRuntime.jsx(ui.Input.tooltip,{prefix:y,size:"md",placeholder:k,id:q,align:"right",value:m,tooltip:x,tooltipProps:{content:{side:e.type==="TP"?"top":"bottom"}},"data-testid":e.testId,autoComplete:"off",onValueChange:o,formatters:[e.formatter({dp:c,mode:t,type:l}),ui.inputFormatter.currencyFormatter],classNames:{root:l==="TP"?"oui-text-trade-profit":"oui-text-trade-loss",additional:"oui-text-base-contrast-54",input:"oui-text-inherit"},onFocus:()=>{P(""),I(""),F();},onBlur:()=>{P(m?"":t),I(t==="Offset%"?"%":a),O();},suffix:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[t==="Offset%"&&!!m&&jsxRuntime.jsx(ui.Text,{size:"2xs",color:"inherit",className:"oui-ml-[2px]",children:"%"}),jsxRuntime.jsx(ct,{mode:t,modes:r,onModeChange:p=>n(p.value)})]})})},ct=e=>jsxRuntime.jsx(ui.SimpleDropdownMenu,{currentValue:e.mode,menu:e.modes,align:"end",size:"xs",className:"oui-min-w-[80px]",onCloseAutoFocus:t=>t.preventDefault(),onSelect:t=>e.onModeChange(t),children:jsxRuntime.jsx("button",{className:"oui-p-2",children:jsxRuntime.jsx(ui.CaretDownIcon,{size:12,color:"white"})})});var Se=e=>{let{testId:t,quote:r,...n}=e,o=Le(n);return jsxRuntime.jsx(Ee,{...o,testId:t,quote:r,type:e.type})};var $=Me.createContext({}),Ne=$.Provider;var Re=e=>{let t=Me__default.default.useRef(null);return Me.useEffect(()=>{e.orderType!==types.OrderType.LIMIT&&e.orderType!==types.OrderType.MARKET&&e.onSwitchChanged(!1);},[e.orderType]),e.orderType!==types.OrderType.LIMIT&&e.orderType!==types.OrderType.MARKET||e.isReduceOnly?null:jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs(ui.Flex,{itemAlign:"center",gapX:1,children:[jsxRuntime.jsx(ui.Switch,{id:"order_entry_tpsl",className:"oui-h-[14px]",checked:e.switchState,disabled:e.orderType!==types.OrderType.LIMIT&&e.orderType!==types.OrderType.MARKET||e.isReduceOnly,onCheckedChange:r=>{e.onSwitchChanged(r);}}),jsxRuntime.jsx("label",{htmlFor:"order_entry_tpsl",className:"oui-text-xs",children:"TP/SL"}),jsxRuntime.jsx(ui.ExclamationFillIcon,{color:"white",size:14,opacity:1,className:"oui-text-white/[.36] hover:oui-text-white/80 oui-cursor-pointer",onClick:()=>{ui.modal.dialog({title:"Tips",size:"xs",content:jsxRuntime.jsx(ui.Text,{intensity:54,children:"TP/SL applies to the entire position. For partial TP/SL, set it in open positions."})});}})]}),jsxRuntime.jsx("div",{className:ui.cn("oui-max-h-0 oui-overflow-hidden oui-transition-all",e.switchState&&"oui-max-h-[100px]"),onTransitionEnd:()=>{t.current?.style.setProperty("opacity",e.switchState?"1":"0");},children:jsxRuntime.jsx(ke,{ref:t,onChange:e.onChange,values:e.values,errors:e.errors,quote_dp:e.quote_dp})})]})},ke=Me__default.default.forwardRef((e,t)=>jsxRuntime.jsxs("div",{ref:t,className:"oui-transition-all oui-pt-2 oui-pb-2 oui-px-[1px] oui-space-y-1",children:[jsxRuntime.jsx(ie,{values:e.values.tp,type:"TP",children:jsxRuntime.jsx(Fe,{type:"TP",error:e.errors?e.errors.tp_trigger_price?.message:"",onChange:e.onChange,values:e.values.tp,quote_dp:e.quote_dp})}),jsxRuntime.jsx(ie,{values:e.values.sl,type:"SL",children:jsxRuntime.jsx(Fe,{type:"SL",error:e.errors?e.errors.sl_trigger_price?.message:"",onChange:e.onChange,values:e.values.sl,quote_dp:e.quote_dp})})]}));ke.displayName="TPSLInputForm";var Ot=e=>{let {errorMsgVisible:t}=Me.useContext($),{tipsEle:r}=Z(),[n,o]=Me.useState(`${e.type} Price`),[a,c]=Me.useState("USDC"),[m,l]=Me.useState(!1),x=Me.useMemo(()=>e.error&&t?e.error:m?r:null,[e.error,t,m,r]);e.type==="SL"?"sl_trigger_price":"tp_trigger_price";return Me.useEffect(()=>{o(e.values.trigger_price?e.type:`${e.type} Price`);},[e.values.trigger_price]),jsxRuntime.jsx(ui.Input.tooltip,{prefix:n,size:"md",placeholder:a,align:"right",onFocus:()=>{o(e.type),c(""),l(!0);},onBlur:()=>{o(e.values.trigger_price?e.type:`${e.type} Price`),c("USDC"),l(!1);},tooltip:x,tooltipProps:{content:{side:e.type==="TP"?"top":"bottom"}},color:e.error?"danger":void 0,autoComplete:"off",value:e.values.trigger_price,classNames:{additional:"oui-text-base-contrast-54",root:"oui-pr-2 md:oui-pr-3",prefix:"oui-pr-1 md:oui-pr-2"},onValueChange:e.onChange,formatters:[ui.inputFormatter.numberFormatter,ui.inputFormatter.dpFormatter(e.quote_dp??2),ui.inputFormatter.currencyFormatter]})},Fe=e=>{let t=e.type==="SL"?"sl_trigger_price":"tp_trigger_price";return jsxRuntime.jsxs(ui.Grid,{cols:2,gapX:1,children:[jsxRuntime.jsx(Ot,{type:e.type,error:e.error,values:e.values??"",onChange:r=>{e.onChange(t,r);},quote_dp:e.quote_dp}),jsxRuntime.jsx(Se,{onChange:e.onChange,quote:"USDC",quote_dp:e.quote_dp,type:e.type,values:{PnL:e.values.PnL,Offset:e.values.Offset,"Offset%":e.values["Offset%"],ROI:e.values.ROI}})]})};var me=e=>{let{baseDP:t,quoteDP:r,order:n,onConfirm:o,onCancel:a}=e,{side:c,order_type:m,symbol:l}=n,[x,F]=hooks.useLocalStorage("orderly_order_confirm",!0);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(ui.Flex,{justify:"between",children:[jsxRuntime.jsx(ui.Text.formatted,{rule:"symbol",showIcon:!0,children:n.symbol}),jsxRuntime.jsxs(ui.Flex,{justify:"end",gapX:1,children:[jsxRuntime.jsx(wt,{type:n.order_type}),c===types.OrderSide.BUY?jsxRuntime.jsx(ui.Badge,{color:"buy",size:"sm",children:"Buy"}):jsxRuntime.jsx(ui.Badge,{color:"sell",size:"sm",children:"Sell"})]})]}),jsxRuntime.jsx(ui.Divider,{className:"oui-my-4"}),jsxRuntime.jsxs("div",{className:ui.textVariants({size:"sm",intensity:54,className:"oui-space-y-1"}),children:[jsxRuntime.jsxs(ui.Flex,{justify:"between",children:[jsxRuntime.jsx(ui.Text,{children:"Qty."}),jsxRuntime.jsx(ui.Text.numeral,{rule:"price",dp:t,padding:!1,className:"oui-text-base-contrast",children:n.order_quantity})]}),n.trigger_price?jsxRuntime.jsxs(ui.Flex,{justify:"between",children:[jsxRuntime.jsx(ui.Text,{children:"Trigger"}),jsxRuntime.jsx(ui.Text.numeral,{unit:"USDC",rule:"price",className:"oui-text-base-contrast",unitClassName:"oui-text-base-contrast-36 oui-ml-1",dp:r,padding:!1,children:n.trigger_price})]}):null,jsxRuntime.jsxs(ui.Flex,{justify:"between",children:[jsxRuntime.jsx(ui.Text,{children:"Price"}),n.order_type===types.OrderType.MARKET||n.order_type===types.OrderType.STOP_MARKET?jsxRuntime.jsx(ui.Text,{intensity:80,children:"Market"}):jsxRuntime.jsx(ui.Text.numeral,{unit:"USDC",rule:"price",className:"oui-text-base-contrast",unitClassName:"oui-text-base-contrast-36 oui-ml-1",dp:r,padding:!1,children:n.order_price})]}),jsxRuntime.jsxs(ui.Flex,{justify:"between",children:[jsxRuntime.jsx(ui.Text,{children:"Notional"}),jsxRuntime.jsx(ui.Text.numeral,{unit:"USDC",rule:"price",dp:r,padding:!1,className:"oui-text-base-contrast",unitClassName:"oui-text-base-contrast-36 oui-ml-1",children:n.total})]})]}),n.tp_trigger_price||n.sl_trigger_price?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ui.Divider,{className:"oui-my-4"}),jsxRuntime.jsxs("div",{className:ui.textVariants({size:"sm",intensity:54,className:"oui-space-y-1"}),children:[n.tp_trigger_price&&jsxRuntime.jsxs(ui.Flex,{justify:"between",children:[jsxRuntime.jsx(ui.Text,{children:"TP Price"}),jsxRuntime.jsx(ui.Text.numeral,{unit:"USDC",rule:"price",coloring:!0,dp:r,padding:!1,unitClassName:"oui-text-base-contrast-36 oui-ml-1",children:n.tp_trigger_price})]}),n.sl_trigger_price&&jsxRuntime.jsxs(ui.Flex,{justify:"between",children:[jsxRuntime.jsx(ui.Text,{children:"SL Price"}),jsxRuntime.jsx(ui.Text.numeral,{unit:"USDC",rule:"price",coloring:!0,className:"oui-text-trade-loss",unitClassName:"oui-text-base-contrast-36 oui-ml-1",dp:r,padding:!1,children:n.sl_trigger_price})]})]})]}):null,jsxRuntime.jsxs(ui.Flex,{gapX:1,pt:8,pb:3,children:[jsxRuntime.jsx(ui.Checkbox,{id:"orderConfirm",color:"white",onCheckedChange:O=>{F(!O);}}),jsxRuntime.jsx("label",{htmlFor:"orderConfirm",className:ui.textVariants({size:"xs",intensity:54}),children:"Disable order confirmation"})]}),jsxRuntime.jsxs(ui.Grid,{cols:2,gapX:3,children:[jsxRuntime.jsx(ui.Button,{color:"secondary",size:"md",onClick:()=>a(),children:"Cancel"}),jsxRuntime.jsx(ui.Button,{size:"md",onClick:()=>o(),children:"Confirm"})]})]})};me.displayName="OrderConfirmDialog";var wt=e=>{let t=Me.useMemo(()=>{switch(e.type){case types.OrderType.LIMIT:return "Limit";case types.OrderType.MARKET:return "Market";case types.OrderType.STOP_LIMIT:return "Stop Limit";case types.OrderType.STOP_MARKET:return "Stop Market";default:return ""}},[e.type]);return jsxRuntime.jsx(ui.Badge,{color:"neutral",size:"sm",children:t})},Rt=e=>{let{close:t,resolve:r,reject:n,...o}=e;return jsxRuntime.jsx(me,{...o,onCancel:t,onConfirm:()=>{r(),t();}})},fe="orderConfirm";ui.registerSimpleDialog(fe,Rt,{size:"sm",title:"Order confirm"});var Be=e=>{let{pinned:t,orderTypeExtra:r}=e,n=o=>a=>{e.onValueChange&&e.onValueChange("order_type_ext",a?o:"");};return Me.useEffect(()=>{e.onValueChange?.("visible_quantity",e.hidden?0:1);},[e.hidden]),jsxRuntime.jsxs("div",{className:"oui-text-base-contrast-54",children:[jsxRuntime.jsxs(ui.Flex,{justify:t?"start":"between",mb:3,width:t?"unset":"100%",className:"oui-gap-x-2 md:oui-gap-x-3",children:[jsxRuntime.jsxs(ui.Flex,{itemAlign:"center",children:[jsxRuntime.jsx(ui.Checkbox,{id:"toggle_order_post_only",className:"oui-peer",color:"white",variant:"radio",disabled:!e.showExtra,checked:r===types.OrderType.POST_ONLY,onCheckedChange:n(types.OrderType.POST_ONLY)}),jsxRuntime.jsx("label",{htmlFor:"toggle_order_post_only",className:"oui-text-2xs oui-ml-1 peer-data-[disabled]:oui-text-base-contrast-20",children:"Post only"})]}),jsxRuntime.jsxs(ui.Flex,{itemAlign:"center",children:[jsxRuntime.jsx(ui.Checkbox,{id:"toggle_order_iov",color:"white",className:"oui-peer",variant:"radio",checked:r===types.OrderType.IOC,onCheckedChange:n(types.OrderType.IOC),disabled:!e.showExtra}),jsxRuntime.jsx("label",{htmlFor:"toggle_order_iov",className:"oui-text-2xs oui-ml-1 peer-data-[disabled]:oui-text-base-contrast-20",children:"IOC"})]}),jsxRuntime.jsxs(ui.Flex,{itemAlign:"center",children:[jsxRuntime.jsx(ui.Checkbox,{id:"toggle_order_fok",color:"white",variant:"radio",className:"oui-peer",checked:r===types.OrderType.FOK,onCheckedChange:n(types.OrderType.FOK),disabled:!e.showExtra}),jsxRuntime.jsx("label",{htmlFor:"toggle_order_fok",className:"oui-text-2xs oui-ml-1 peer-data-[disabled]:oui-text-base-contrast-20",children:"FOK"})]})]}),jsxRuntime.jsxs(ui.Flex,{gapX:6,children:[jsxRuntime.jsxs(ui.Flex,{children:[jsxRuntime.jsx(ui.Checkbox,{id:"toggle_order_confirm",color:"white",checked:e.needConfirm,onCheckedChange:o=>{e.setNeedConfirm(!!o);}}),jsxRuntime.jsx("label",{htmlFor:"toggle_order_confirm",className:"oui-text-2xs oui-ml-1",children:"Order confirm"})]}),jsxRuntime.jsxs(ui.Flex,{children:[jsxRuntime.jsx(ui.Checkbox,{id:"toggle_order_hidden",color:"white",checked:e.hidden,onCheckedChange:o=>{e.setHidden(o);}}),jsxRuntime.jsx("label",{htmlFor:"toggle_order_hidden",className:"oui-text-2xs oui-ml-1",children:"Hidden"})]})]}),!t&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ui.Divider,{className:"oui-my-3"}),jsxRuntime.jsxs(ui.Flex,{children:[jsxRuntime.jsx(ui.Switch,{id:"toggle_order_keep_visible",onCheckedChange:o=>{e.setPinned(o);}}),jsxRuntime.jsx("label",{htmlFor:"toggle_order_keep_visible",className:"oui-text-2xs oui-ml-1",children:"Keep visible"})]})]})]})};var ze=()=>({});var ee=e=>{let t=ze();return jsxRuntime.jsx(Be,{...t,...e})};var ye=e=>{let{side:t,formattedOrder:r,setOrderValue:n,symbolInfo:o,maxQty:a,freeCollateral:c,helper:m,submit:l,metaState:x,refs:F}=e,{errors:O,validated:y}=x,[P,k]=Me.useState(!1),[I,q]=hooks.useLocalStorage("orderly_order_confirm",!0),[p,M]=hooks.useLocalStorage("orderly-order-additional-pinned",!0),[s,V]=hooks.useLocalStorage("orderly-order-hidden",!1),oe=Me.useMemo(()=>t===types.OrderSide.BUY?"Buy / Long":"Sell / Short",[t]);Me.useEffect(()=>{y&&k(!0);},[y]),Me.useEffect(()=>{let d=A=>{A.target.closest("#order-entry-submit-button")||k(X=>X&&!1);};return P?document.addEventListener("click",d):document.removeEventListener("click",d),()=>{document.removeEventListener("click",d);}},[P]);let ne=()=>{m.validate().then(d=>I?ui.modal.show(fe,{order:r,quote:o.quote,base:o.base,quoteDP:o.quote_dp,baseDP:o.base_dp}):!0,d=>{k(!0);}).then(()=>l().then(d=>{d.success?n("order_quantity",""):ui.toast.error(d.message);})).catch(d=>{d instanceof types.SDKError&&ui.toast.error(`Error:${d.message}`);});};return jsxRuntime.jsx(Ne,{value:{errorMsgVisible:P},children:jsxRuntime.jsxs("div",{className:"oui-space-y-2 xl:oui-space-y-3 oui-text-base-contrast-54",ref:e.containerRef,children:[jsxRuntime.jsxs(ui.Flex,{gapX:2,className:"oui-flex-col lg:oui-flex-row oui-gap-y-3",children:[jsxRuntime.jsxs("div",{className:"oui-grid oui-grid-cols-2 oui-w-full oui-flex-1 oui-gap-x-2 lg:oui-flex lg:oui-gap-x-[6px]",children:[jsxRuntime.jsx(ui.Button,{onClick:()=>{e.setOrderValue("side",types.OrderSide.BUY);},size:"md",fullWidth:!0,"data-type":types.OrderSide.BUY,className:ui.cn(t===types.OrderSide.BUY&&e.canTrade?"oui-bg-success-darken hover:oui-bg-success-darken/80 active:oui-bg-success-darken/80":"oui-bg-base-7 hover:oui-bg-base-6 active:oui-bg-base-6 oui-text-base-contrast-36"),children:"Buy"}),jsxRuntime.jsx(ui.Button,{onClick:()=>{e.setOrderValue("side",types.OrderSide.SELL);},"data-type":types.OrderSide.SELL,fullWidth:!0,size:"md",className:ui.cn(t===types.OrderSide.SELL&&e.canTrade?"oui-bg-danger-darken hover:oui-bg-danger-darken/80 active:oui-bg-danger-darken/80":"oui-bg-base-7 hover:oui-bg-base-6 active:oui-bg-base-6 oui-text-base-contrast-36"),children:"Sell"})]}),jsxRuntime.jsx("div",{className:"oui-w-full lg:oui-flex-1",children:jsxRuntime.jsx(sr,{type:r.order_type,side:t,canTrade:e.canTrade,onChange:d=>{n("order_type",d);}})})]}),jsxRuntime.jsxs(ui.Flex,{justify:"between",children:[jsxRuntime.jsx(ui.Text,{size:"2xs",children:"Available"}),jsxRuntime.jsx(ui.Text.numeral,{unit:o.quote,size:"2xs",className:"oui-text-base-contrast-80",unitClassName:"oui-ml-1 oui-text-base-contrast-54",dp:2,padding:!1,children:e.canTrade?c:0})]}),jsxRuntime.jsx(nr,{type:e.type,symbolInfo:o,values:{quantity:r.order_quantity,price:r.order_price,trigger_price:r.trigger_price,total:r.total},errors:y?O:null,onChange:(d,A)=>{e.setOrderValue(d,A);},refs:e.refs,onBlur:e.onBlur,onFocus:e.onFocus}),jsxRuntime.jsx(ar,{canTrade:e.canTrade,maxQty:a,currentQtyPercentage:e.currentQtyPercentage,value:r.order_quantity?Number(r.order_quantity):0,tick:o.base_tick,dp:o.base_dp,setMaxQty:e.setMaxQty,onValueChange:d=>{n("order_quantity",d);},side:e.side}),jsxRuntime.jsx(uiConnector.AuthGuard,{buttonProps:{fullWidth:!0},children:jsxRuntime.jsx(ui.ThrottledButton,{fullWidth:!0,id:"order-entry-submit-button","data-type":types.OrderSide.BUY,className:ui.cn(t===types.OrderSide.BUY?"orderly-order-entry-submit-button-buy oui-bg-success-darken hover:oui-bg-success-darken/80 active:oui-bg-success-darken/80":"orderly-order-entry-submit-button-sell oui-bg-danger-darken hover:oui-bg-danger-darken/80 active:oui-bg-danger-darken/80"),onClick:()=>{ne();},loading:e.isMutating,children:oe})}),jsxRuntime.jsx(lr,{canTrade:e.canTrade,quote:o.quote,estLiqPrice:e.estLiqPrice,estLeverage:e.estLeverage,currentLeverage:e.currentLeverage}),jsxRuntime.jsx(ui.Divider,{className:"oui-w-full"}),jsxRuntime.jsx(Re,{quote_dp:e.symbolInfo.quote_dp,switchState:e.tpslSwitch,onSwitchChanged:e.setTpslSwitch,orderType:r.order_type,errors:y?O:null,isReduceOnly:r.reduce_only,values:{tp:{trigger_price:r.tp_trigger_price??"",PnL:r.tp_pnl??"",Offset:r.tp_offset??"","Offset%":r.tp_offset_percentage??"",ROI:r.tp_ROI??""},sl:{trigger_price:r.sl_trigger_price??"",PnL:r.sl_pnl??"",Offset:r.sl_offset??"","Offset%":r.sl_offset_percentage??"",ROI:r.sl_ROI??""}},onChange:(d,A)=>{e.setOrderValue(d,A);}}),jsxRuntime.jsxs(ui.Flex,{justify:"between",itemAlign:"center",className:"!oui-mt-[0px] xl:!oui-mt-3",children:[jsxRuntime.jsxs(ui.Flex,{itemAlign:"center",gapX:1,children:[jsxRuntime.jsx(ui.Switch,{className:"oui-h-[14px]",id:"reduceOnly",checked:e.formattedOrder.reduce_only,onCheckedChange:d=>{e.setOrderValue("reduce_only",d),d&&e.setOrderValue("order_type_ext","");}}),jsxRuntime.jsx("label",{htmlFor:"reduceOnly",className:"oui-text-xs",children:"Reduce only"})]}),!p&&jsxRuntime.jsx(ur,{pinned:p,setPinned:M,needConfirm:I,setNeedConfirm:q,onValueChange:n,orderTypeExtra:r.order_type_ext,showExtra:r.order_type===types.OrderType.LIMIT&&!e.tpslSwitch,hidden:s,setHidden:V})]}),p&&jsxRuntime.jsxs(ui.Box,{p:2,r:"md",intensity:700,position:"relative",children:[jsxRuntime.jsx(ee,{pinned:p,setPinned:M,needConfirm:I,setNeedConfirm:q,onValueChange:n,orderTypeExtra:r.order_type_ext,showExtra:r.order_type===types.OrderType.LIMIT&&!e.tpslSwitch,hidden:s,setHidden:V}),jsxRuntime.jsx(or,{onClick:()=>{M(!1);},className:"oui-absolute oui-top-2 oui-right-2 oui-group"})]})]})})},Ge="M10.007 1.302a.74.74 0 0 0-.486.214c-1.033.989-1.349 1.815-.972 2.948-.88.675-1.437.84-2.536.84-1.503 0-2.484.182-3.152.85v.02a1.583 1.583 0 0 0 0 2.248l1.867 1.882-3.181 3.18c-.26.26-.28.696-.02.956.261.26.699.26.959 0l3.193-3.194 1.87 1.861a1.585 1.585 0 0 0 2.25 0h.02c.668-.667.854-1.523.854-3.144 0-1.03.212-1.758.852-2.523 1.233.361 1.95.015 2.961-.995a.68.68 0 0 0 .188-.48c0-.234-.06-.593-.209-1.04a5.34 5.34 0 0 0-1.312-2.103 5.35 5.35 0 0 0-2.104-1.312c-.448-.15-.808-.208-1.042-.208",or=e=>{let[t,r]=Me.useState(Ge);return jsxRuntime.jsx("button",{...e,children:jsxRuntime.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",onMouseEnter:()=>{r('M10.008 1.302a.74.74 0 0 0-.486.214c-1.033.989-1.349 1.815-.972 2.948-.88.675-1.437.84-2.536.84-1.503 0-2.484.182-3.152.85v.02a1.583 1.583 0 0 0 0 2.248l1.867 1.882-3.181 3.18c-.26.26-.28.696-.02.956.261.26.699.26.959 0l3.193-3.194 1.87 1.861a1.585 1.585 0 0 0 2.25 0h.02c.668-.667.854-1.523.854-3.144 0-1.03.212-1.758.853-2.523 1.232.361 1.95.015 2.96-.995a.68.68 0 0 0 .188-.48c0-.234-.06-.593-.209-1.04a5.34 5.34 0 0 0-1.312-2.103A5.35 5.35 0 0 0 11.05 1.51c-.448-.15-.808-.208-1.042-.208m.258 1.37c.708.131 1.421.6 1.93 1.107.507.508.94 1.13 1.119 1.945-.636.61-1.026.658-1.662.323a.67.67 0 0 0-.779.117c-1.214 1.213-1.533 2.314-1.533 3.8 0 1.292-.076 1.773-.48 2.206-.113.123-.27.104-.374 0L3.799 7.486a.24.24 0 0 1-.017-.34c.239-.29.769-.515 2.226-.514 1.742.001 2.668-.448 3.812-1.52a.67.67 0 0 0 .125-.77c-.343-.686-.29-1.047.321-1.67"');},onMouseLeave:()=>{r(Ge);},children:jsxRuntime.jsx("path",{d:t,fill:"#608CFF"})})})},nr=e=>{let{type:t,symbolInfo:r,errors:n,values:o,onFocus:a,onBlur:c}=e,m=l=>n&&n[l]?n[l].message:"";return jsxRuntime.jsxs("div",{className:"oui-space-y-1",children:[t===types.OrderType.STOP_LIMIT||t===types.OrderType.STOP_MARKET?jsxRuntime.jsx("div",{className:"oui-group",children:jsxRuntime.jsx(W,{label:"Trigger",suffix:r.quote,error:m("trigger_price"),id:"trigger",ref:e.refs.triggerPriceInputRef,value:o.trigger_price,onChange:l=>{e.onChange("trigger_price",l);},formatters:[ui.inputFormatter.dpFormatter(r.quote_dp)],onFocus:a(1),onBlur:c(1)})}):null,t===types.OrderType.LIMIT||t===types.OrderType.STOP_LIMIT?jsxRuntime.jsx("div",{className:"oui-group",children:jsxRuntime.jsx(W,{label:"Price",suffix:r.quote,id:"price",value:o.price,error:m("order_price"),ref:e.refs.priceInputRef,onChange:l=>{e.onChange("order_price",l);},formatters:[ui.inputFormatter.dpFormatter(r.quote_dp)],onFocus:a(0),onBlur:c(0)})}):null,jsxRuntime.jsxs(ui.Grid,{cols:2,className:"oui-space-x-1 oui-group",children:[jsxRuntime.jsx(W,{label:"Qty",suffix:r.base,id:"order_quantity_input",name:"order_quantity_input",className:"!oui-rounded-br !oui-rounded-tr",value:o.quantity,error:m("order_quantity"),onChange:l=>{e.onChange("order_quantity",l);},formatters:[ui.inputFormatter.dpFormatter(r.base_dp)],onFocus:a(2),onBlur:c(2)}),jsxRuntime.jsx(W,{label:"Total\u2248",suffix:r.quote,id:"total",className:"!oui-rounded-bl !oui-rounded-tl",value:o.total,error:m("total"),onChange:l=>{e.onChange("total",l);},onFocus:a(3),onBlur:c(3),formatters:[ui.inputFormatter.dpFormatter(r.quote_dp)]})]})]})},W=Me.forwardRef((e,t)=>{let{errorMsgVisible:r}=Me.useContext($),[n,o]=Me.useState("0");return jsxRuntime.jsx(ui.Input.tooltip,{ref:t,tooltip:r?e.error:void 0,autoComplete:"off",autoFocus:e.autoFocus,size:"lg",placeholder:n,id:e.id,name:e.name,color:e.error?"danger":void 0,prefix:jsxRuntime.jsx(ir,{id:e.id,children:e.label}),suffix:e.suffix,value:e.value||"",onValueChange:e.onChange,onFocus:a=>{o(""),e.onFocus?.(a);},onBlur:a=>{o("0"),e.onBlur?.(a);},formatters:[...e.formatters??[],ui.inputFormatter.numberFormatter,ui.inputFormatter.currencyFormatter],classNames:{root:ui.cn("orderly-order-entry oui-relative oui-pt-8 oui-h-[54px] oui-px-2 oui-py-1 oui-pr-2 oui-border oui-border-solid oui-border-line oui-rounded group-first:oui-rounded-t-xl group-last:oui-rounded-b-xl",e.className),input:"oui-mt-5 oui-mb-1 oui-h-5",prefix:"oui-absolute oui-left-2 oui-top-[7px] oui-text-base-contrast-36",suffix:"oui-absolute oui-right-0 oui-top-0 oui-text-base-contrast-36 oui-text-2xs oui-justify-start oui-py-2"}})});W.displayName="CustomInput";var ir=e=>jsxRuntime.jsx("label",{htmlFor:e.id,className:"oui-absolute oui-left-2 oui-top-[7px] oui-text-base-contrast-36 oui-text-2xs",children:e.children}),ar=e=>{let{canTrade:t}=e,r=Me.useMemo(()=>t?e.side===types.OrderSide.BUY?"buy":"sell":void 0,[e.side,t]),n=Me.useMemo(()=>e.side===types.OrderSide.BUY?"Max buy":"Max sell",[e.side]);return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx(ui.Slider.single,{disabled:e.maxQty===0||!t,value:e.value,color:r,markCount:4,showTip:!0,max:e.maxQty,step:e.tick,onValueChange:e.onValueChange}),jsxRuntime.jsxs(ui.Flex,{justify:"between",className:"oui-pt-1 xl:oui-pt-2",children:[jsxRuntime.jsx(ui.Text.numeral,{rule:"percentages",size:"2xs",color:r,dp:2,padding:!1,children:t?e.currentQtyPercentage:0}),jsxRuntime.jsxs(ui.Flex,{children:[jsxRuntime.jsx("button",{className:ui.textVariants({size:"2xs",className:"oui-mr-1"}),onClick:()=>e.setMaxQty(),children:n}),jsxRuntime.jsx(ui.Text.numeral,{size:"2xs",color:r,dp:e.dp,padding:!1,children:t?e.maxQty:0})]})]})]})},sr=e=>{let t=[{label:"Limit order",value:types.OrderType.LIMIT},{label:"Market order",value:types.OrderType.MARKET},{label:"Stop limit",value:types.OrderType.STOP_LIMIT},{label:"Stop market",value:types.OrderType.STOP_MARKET}];return jsxRuntime.jsx(ui.Select.options,{currentValue:e.type,value:e.type,options:t,onValueChange:e.onChange,contentProps:{className:"oui-bg-base-8 oui-w-full"},valueFormatter:(r,n)=>{let o=t.find(a=>a.value===r);return o?jsxRuntime.jsx(ui.Text,{size:"xs",color:e.canTrade?e.side===types.OrderSide.BUY?"buy":"sell":void 0,children:o?.label.replace(" order","")}):jsxRuntime.jsx(ui.Text,{size:"xs",children:n.placeholder})},size:"md"})};function lr(e){let{canTrade:t}=e;return jsxRuntime.jsxs("div",{className:"oui-space-y-[2px] xl:oui-space-y-1",children:[jsxRuntime.jsxs(ui.Flex,{justify:"between",children:[jsxRuntime.jsx(ui.Text,{size:"2xs",children:"Est. Liq. price"}),jsxRuntime.jsx(ui.Text.numeral,{unit:e.quote,size:"2xs",className:"oui-text-base-contrast-80",unitClassName:"oui-ml-1 oui-text-base-contrast-36",children:t?e.estLiqPrice??"--":"--"})]}),jsxRuntime.jsxs(ui.Flex,{justify:"between",children:[jsxRuntime.jsx(ui.Text,{size:"2xs",children:"Account leverage"}),jsxRuntime.jsxs(ui.Flex,{gapX:1,className:ui.textVariants({size:"2xs",intensity:80}),children:[jsxRuntime.jsx(ui.Text.numeral,{unit:t?"x":void 0,children:t?e.currentLeverage??"--":"--"}),e.estLeverage&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsxRuntime.jsx("path",{d:"M2.505 4.997c0-.23.186-.416.416-.416H6.07L4.833 3.332l.586-.585 1.964 1.95a.42.42 0 0 1 .122.3.42.42 0 0 1-.122.3l-1.964 1.95-.586-.585L6.07 5.413H2.921a.416.416 0 0 1-.416-.416",fill:"#fff",fillOpacity:".54"})}),jsxRuntime.jsx("span",{children:`${e.estLeverage}x`})]})]})]})]})}function ur(e){let[t,r]=Me.useState(!1);return jsxRuntime.jsxs(ui.PopoverRoot,{open:t,onOpenChange:r,children:[jsxRuntime.jsx(ui.PopoverTrigger,{asChild:!0,children:jsxRuntime.jsx("button",{onClick:()=>{r(!0);},children:jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",className:"oui-fill-white/[.36] hover:oui-fill-white/80",children:jsxRuntime.jsx("path",{d:"M3.332 2.665a.667.667 0 0 0-.667.667v1.333c0 .368.299.667.667.667h1.333a.667.667 0 0 0 .667-.667V3.332a.667.667 0 0 0-.667-.667zm4 0a.667.667 0 0 0-.667.667v1.333c0 .368.299.667.667.667h1.333a.667.667 0 0 0 .667-.667V3.332a.667.667 0 0 0-.667-.667zm4 0a.667.667 0 0 0-.667.667v1.333c0 .368.299.667.667.667h1.333a.667.667 0 0 0 .667-.667V3.332a.667.667 0 0 0-.667-.667zm-8 4a.667.667 0 0 0-.667.667v1.333c0 .368.299.667.667.667h1.333a.667.667 0 0 0 .667-.667V7.332a.667.667 0 0 0-.667-.667zm4 0a.667.667 0 0 0-.667.667v1.333c0 .368.299.667.667.667h1.333a.667.667 0 0 0 .667-.667V7.332a.667.667 0 0 0-.667-.667zm4 0a.667.667 0 0 0-.667.667v1.333c0 .368.299.667.667.667h1.333a.667.667 0 0 0 .667-.667V7.332a.667.667 0 0 0-.667-.667zm-8 4a.667.667 0 0 0-.667.667v1.333c0 .368.299.667.667.667h1.333a.667.667 0 0 0 .667-.667v-1.333a.667.667 0 0 0-.667-.667zm4 0a.667.667 0 0 0-.667.667v1.333c0 .368.299.667.667.667h1.333a.667.667 0 0 0 .667-.667v-1.333a.667.667 0 0 0-.667-.667zm4 0a.667.667 0 0 0-.667.667v1.333c0 .368.299.667.667.667h1.333a.667.667 0 0 0 .667-.667v-1.333a.667.667 0 0 0-.667-.667z"})})})}),jsxRuntime.jsx(ui.PopoverContent,{side:"top",align:"end",className:"oui-w-[230px]",children:jsxRuntime.jsx(ee,{...e})})]})}var $e=e=>{let[t,r]=hooks.useLocalStorage("orderly-order-entry-order-type",types.OrderType.LIMIT),[n,o]=hooks.useLocalStorage("orderly-order-entry-order-side",types.OrderSide.BUY),{formattedOrder:a,setValue:c,setValues:m,symbolInfo:l,...x}=hooks.useOrderEntry(e.symbol,{initialOrder:{symbol:e.symbol,order_type:t,side:n}}),[F,O]=hooks.useLocalStorage("orderly-order-entry-tp_sl-switch",!1),{state:y}=hooks.useAccount(),{wrongNetwork:P}=reactApp.useAppContext(),k=Me.useMemo(()=>y.status===types.AccountStatusEnum.EnableTrading&&!P,[y.status,P]),{currentLeverage:I}=hooks.useMarginRatio(),q=hooks.useEventEmitter(),p=Me.useRef(4),M=Me.useRef(null),s=Me.useRef(null),V=Me.useMemo(()=>Number(a.order_quantity)>=Number(x.maxQty)?1:ui.convertValueToPercentage(Number(a.order_quantity??0),0,x.maxQty)/100,[a.order_quantity,x.maxQty]),oe=()=>{if(l.base_tick<1)return;let f=hooks.utils.formatNumber(a?.order_quantity,new utils.Decimal(l?.base_tick||"0").toNumber());c("order_quantity",f,{shouldUpdateLastChangedField:!1});},ne=f=>v=>{p.current=f;},d=f=>v=>{setTimeout(()=>{p.current===f&&(p.current=4);},300),(f===2||f===3)&&oe();};Me.useEffect(()=>{let f=v=>{if(p.current===1)(a.order_type===types.OrderType.STOP_LIMIT||a.order_type===types.OrderType.STOP_MARKET)&&(c("trigger_price",utils.removeTrailingZeros(v[0])),H(M.current));else if(a.order_type===types.OrderType.STOP_LIMIT||a.order_type===types.OrderType.LIMIT)c("order_price",utils.removeTrailingZeros(v[0])),H(s.current);else {let z;a.order_type===types.OrderType.STOP_MARKET?z=types.OrderType.STOP_LIMIT:a.order_type===types.OrderType.MARKET&&(z=types.OrderType.LIMIT),typeof z<"u"&&c("order_type",z),c("order_price",utils.removeTrailingZeros(v[0])),H(s.current);}function H(z){setTimeout(()=>{z?.focus();},0);}};return q.on("orderbook:item:click",f),()=>{q.off("orderbook:item:click",f);}},[a.order_type,a.order_quantity,l]);let A=()=>{m({tp_trigger_price:"",sl_trigger_price:""});},he=()=>{m({order_type_ext:void 0});},X=()=>{c("order_quantity",x.maxQty);},Ye=(f,v,H)=>{c(f,v,H),f==="order_type"&&r(v),f==="side"&&o(v),(f==="reduce_only"&&v||f==="order_type"&&(v===types.OrderType.STOP_LIMIT||v===types.OrderType.STOP_MARKET))&&A();},We=f=>{O(f),f?he():A();};return {...x,currentQtyPercentage:V,side:a.side,type:a.order_type,setOrderValue:Ye,currentLeverage:I,formattedOrder:a,tpslSwitch:F,setTpslSwitch:We,setMaxQty:X,symbolInfo:l,onFocus:ne,onBlur:d,refs:{triggerPriceInputRef:M,priceInputRef:s},canTrade:k}};var Pr=e=>{let t=$e(e);return jsxRuntime.jsx(ye,{...t,containerRef:e.containerRef})};
17
17
 
18
18
  exports.AdditionalInfoWidget = ee;
19
19
  exports.OrderConfirmDialog = me;