@edgex-web/components 0.2.0-beta.20 → 0.2.0-beta.22
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/{ccip-JQR0a-Lg.mjs → ccip-C9dx9lVN.mjs} +2 -2
- package/dist/{ccip-JQR0a-Lg.mjs.map → ccip-C9dx9lVN.mjs.map} +1 -1
- package/dist/components/Deposit/src/components/mpc/index.d.ts.map +1 -1
- package/dist/{index-CF2ZlxOy.mjs → index-BRTnkVLg.mjs} +19 -13
- package/dist/{index-CF2ZlxOy.mjs.map → index-BRTnkVLg.mjs.map} +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as e, C as i, D as t, n, p as r, L as p, o as d, S as L, T as h, W as D, y as g, r as u, A as w, h as W, w as C, G as m, q as E, z as A, v as O, F as T, t as M, E as S, u as l, j as f, x as P, m as _, k as c, I as v } from "./index-
|
|
1
|
+
import { o as e, C as i, D as t, n, p as r, L as p, o as d, S as L, T as h, W as D, y as g, r as u, A as w, h as W, w as C, G as m, q as E, z as A, v as O, F as T, t as M, E as S, u as l, j as f, x as P, m as _, k as c, I as v } from "./index-BRTnkVLg.mjs";
|
|
2
2
|
import "react";
|
|
3
3
|
export {
|
|
4
4
|
e as ChromeLoader,
|
package/dist/index.umd.js
CHANGED
|
@@ -145,7 +145,7 @@ ${dg(d)}`),super(t.shortMessage,{cause:t,docsPath:r,metaMessages:[...t.metaMessa
|
|
|
145
145
|
${r?"opacity-50 cursor-not-allowed":"cursor-pointer hover:bg-fill-btn-secondary-hover"}
|
|
146
146
|
${u?"ring-1 ring-white":""}
|
|
147
147
|
`,children:[k.jsx("span",{className:"text-sm leading-[18px] font-medium",children:c("deposit.asset")}),k.jsxs("div",{className:"flex items-center space-x-2",children:[k.jsx("img",{src:t.iconUrl,alt:a(t),className:"w-4 h-4 rounded-full"}),k.jsx("span",{className:"text-sm text-white ml-1",children:a(t)}),k.jsxs("svg",{className:`w-3 h-3 ml-2 transition-transform duration-200 ${u?"rotate-180":""}`,xmlns:"http://www.w3.org/2000/svg",width:"10",height:"11",viewBox:"0 0 10 11",fill:"none",children:[k.jsx("g",{clipPath:"url(#clip0_asset_selector)",children:k.jsx("path",{d:"M5.32733 7.6716C5.13944 7.83432 4.86056 7.83432 4.67267 7.6716L1.68366 5.08304C1.33371 4.77997 1.54804 4.20508 2.01099 4.20508L7.98901 4.20508C8.45196 4.20508 8.66629 4.77998 8.31634 5.08304L5.32733 7.6716Z",fill:"#F9F9F9"})}),k.jsx("defs",{children:k.jsx("clipPath",{id:"clip0_asset_selector",children:k.jsx("rect",{width:"10",height:"10",fill:"white",transform:"translate(0 0.955078)"})})})]})]})]}),k.jsx(nu,{as:x.Fragment,enter:"transition ease-out duration-100",enterFrom:"transform opacity-0 scale-95",enterTo:"transform opacity-100 scale-100",leave:"transition ease-in duration-75",leaveFrom:"transform opacity-100 scale-100",leaveTo:"transform opacity-0 scale-95",children:k.jsx(mt.Options,{className:`
|
|
148
|
-
absolute z-50 mt-1 w-full max-h-
|
|
148
|
+
absolute z-50 mt-1 w-full max-h-[230px] overflow-y-auto rounded-lg
|
|
149
149
|
bg-fill-input-primary border border-line-divider-secondary shadow-lg
|
|
150
150
|
focus:outline-none
|
|
151
151
|
`,children:e.map(l=>k.jsx(mt.Option,{value:l,className:({active:f,selected:p})=>`relative cursor-pointer select-none py-3 px-3 ${p?"bg-fill-btn-secondary":f?"bg-fill-input-secondary":""}`,children:({selected:f,active:p})=>k.jsxs("div",{className:"flex items-center space-x-3",children:[k.jsx("img",{src:l.iconUrl,alt:a(l),className:"w-5 h-5 rounded-full"}),k.jsxs("div",{className:"flex flex-col",children:[k.jsx("span",{className:`text-sm font-medium ${f||p?"text-text-primary":"text-text-tertiary"}`,children:a(l)}),s===xn&&i==="perpetual"&&l.token==="USDC"&&k.jsx("p",{className:"mt-2 text-xs text-text-tertiary whitespace-pre-line",children:c("deposit.defaultSpotNotice")})]})]})},a(l)))})})]})})})},Eh=({currentActiveChain:e,chainList:t,onChainChange:n,curSelectToken:r,onTokenChange:o,walletType:s=xn,txType:i="deposit",accountType:c})=>{const a=x.useCallback(w=>i==="withdraw"?s===xn?w.allowAaWithdraw!==!1:w.allowWithdraw!==!1:s===xn?w.allowAaDeposit!==!1:w.allowDeposit!==!1,[i,s]),u=x.useMemo(()=>{const w=new Set,$=[];for(const E of t)if(a(E))for(const S of E.tokenList||[]){const N=S.symbol||S.token;!N||!(i!=="withdraw"||S.withdrawEnable===!0&&S.pullOff===!1)||w.has(N)||(w.add(N),$.push({token:N,symbol:N,iconUrl:S.iconUrl,decimals:S.decimals,tokenAddress:S.tokenAddress}))}return $},[t,a,i]),l=w=>{n(w.chainId)},f=w=>{const $=w.symbol||w.token;o($);const E=[];for(const S of t){if(!a(S))continue;(S.tokenList||[]).some(B=>(B.symbol||B.token)===$)&&E.push(S.chainId)}!E.includes(e.chainId)&&E[0]!==void 0&&n(E[0])},p=x.useMemo(()=>{var E,S;const w=r||((E=u[0])==null?void 0:E.symbol)||((S=u[0])==null?void 0:S.token);if(!w)return[];const $=[];for(const N of t){if(!a(N))continue;const B=(N.tokenList||[]).find(F=>(F.symbol||F.token)===w?i==="withdraw"?F.withdrawEnable===!0&&F.pullOff===!1:!0:!1);B&&$.push({...N,tokenList:[{token:B.token,symbol:B.symbol,iconUrl:B.iconUrl,decimals:B.decimals,tokenAddress:B.tokenAddress}]})}return $},[t,r,u,a,i]),d=x.useMemo(()=>p.find(w=>w.chainId===e.chainId)||p[0],[p,e.chainId]),h=x.useMemo(()=>u,[u]),m=x.useMemo(()=>{if(h.length!==0)return h.find(w=>w.token===r||w.symbol===r)||h[0]},[h,r]);return x.useEffect(()=>{if(h.length===0)return;if(!h.some($=>($.symbol||$.token)===r)){const $=h[0];o($.symbol||$.token)}},[h,r,o]),x.useEffect(()=>{if(p.length===0)return;p.some($=>$.chainId===e.chainId)||n(p[0].chainId)},[p,e.chainId,n]),k.jsxs("div",{className:"space-y-4",children:[h.length>0&&m&&k.jsx(s3,{tokens:h,selectedToken:m,onTokenChange:f,walletType:s,accountType:c}),k.jsx(o3,{chains:p,selectedChain:d,onChainChange:w=>{const $=t.find(E=>E.chainId===w.chainId);$&&l($)},walletType:s,className:"w-full"})]})},i3=({options:e})=>k.jsx(k.Fragment,{children:e.map(t=>k.jsx(mt.Option,{value:t.value,className:({active:n,selected:r})=>`relative cursor-pointer select-none py-3 px-3 ${r?"bg-fill-btn-secondary":n?"bg-fill-input-secondary":""}`,children:({selected:n,active:r})=>k.jsx("div",{className:"flex items-center justify-between",children:k.jsx("div",{className:"flex items-center space-x-3",children:k.jsx("div",{className:"flex flex-col",children:k.jsx("span",{className:`text-sm font-medium ${n||r?"text-text-primary":"text-text-tertiary"}`,children:t.label})})})})},t.value))}),Sh=({selectedAccount:e,onAccountChange:t,disabled:n=!1,className:r=""})=>{var f;const{t:o}=vt(),s=x.useMemo(()=>[{value:"spot",label:o("account.spot")},{value:"perpetual",label:o("account.perpetual")}],[o]),i=((f=s.find(p=>p.value===(e??"spot")))==null?void 0:f.label)||"",[c,a]=x.useState(e??"spot"),u=e??c,l=p=>{t==null||t(p),e||a(p)};return k.jsx("div",{className:`relative mb-4 ${r}`,children:k.jsx(mt,{value:u,onChange:l,disabled:n,children:({open:p})=>k.jsxs(k.Fragment,{children:[k.jsxs(mt.Button,{className:`
|
|
@@ -175,5 +175,5 @@ ${dg(d)}`),super(t.shortMessage,{cause:t,docsPath:r,metaMessages:[...t.metaMessa
|
|
|
175
175
|
${c}
|
|
176
176
|
${s}
|
|
177
177
|
`,children:[t,o&&k.jsx(am,{ref:f,placement:h.placement||n})]})})]})},Wo="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAIcSURBVHgBxZc/T8JAGMafA4mDEXFw0DiQmDi4CP5JHGFx0qizg8QvIHwCZHYAvwEm7mji5CJuJv7DxcWYYMLmIEYXY/R8j6tQaBvuaCm/pOlbSu99+rZ97zlgwDBowvNLCdrF6NJ50891OvNC+wrL3JShgZIAnl+JAj97FKXoMNLl7ySGnQDBHMtcVeFGAM8nKNlnlsI0eoIVuwlhzsmXqcwoURSFK1iVRCSdRDDn5PwC3cutingsJOK60nkiYE0unrdi8uFRIDwFBSJiTKOqzgKMl00teXgS2D0Fto+BiVkoIMYs8Xws4iiAkmeVn/n0oqyA2NQEQI4dytoKMEqfQt/haZmrQ4C8e7/4TtsI4JvwDbYDswCjvXr1yakQMXI2KxCD/8RMAtx2ux5gcjIzBAT8LH8bAQwYbwR8fUAb/vtuEsAr0OX5Eng8o30ZqN1BHzFLAkPGkb4AcdfnObigkbM5HdN3+Qb/ekGdrNu4CMyd8Ag6iElo/QBYzcpYByYsm8QkIFSADmI2nEkAc2sUL0ALHsxZBEjLxA+hSu22tb0+KV9Gd18027M2SybNQui+f53R6g/b+gDLVMi7YQsND+c5dTtzamlE0jiyJLwVYZhSqzO27YRSxFD8v1m4Q4xh74gdBUgRQm2QKsH0Ps82xEs9EndK3sgDlWGkW96naANqSzMSHSy4XprZi2kuTqN09VjrBH9AD4vTgfMHJt+rxIFF7EgAAAAASUVORK5CYII=",x4=({currentActiveChain:e,selectedToken:t,address:n,accountType:r,onDeposit:o,onCopy:s,onClose:i})=>{const{t:c}=vt(),a=r===p5,u=x.useMemo(()=>{if(!e)return!1;const h=Number(e.chainId);return!Number.isNaN(h)&&(h===42161||h===421614)},[e]),l=a,f=x.useMemo(()=>{var h;return(h=e==null?void 0:e.tokenList)==null?void 0:h.find(m=>m.token===t||m.symbol===t)},[e,t]),p=x.useMemo(()=>{const h=(t||"").toUpperCase();if(!l&&h==="USDC")return c("deposit.defaultSpotToPerpNotice",{coin:t,v:e==null?void 0:e.chain});const $=c(l?"deposit.crossChainDepositFeeTip":"deposit.depositAllTip",{coin:t,v:e==null?void 0:e.chain});return l&&(!u||h==="USDC")?String($).split(`
|
|
178
|
-
`)[0]:$},[c,t,e==null?void 0:e.chain,l,u]),d=(f==null?void 0:f.minDepositSize)||"10";return k.jsxs(k.Fragment,{children:[k.jsx("div",{className:"flex justify-center mt-4 mb-3",children:n&&k.jsx("div",{className:"bg-white rounded-lg",children:k.jsx(zh,{value:n,size:120,level:"L",bgColor:"#ffffff",fgColor:"#000000",marginSize:0})})}),n&&k.jsxs("div",{className:"flex items-center justify-between bg-fill-input-primary rounded-lg py-2 px-3 mb-3",children:[k.jsx("span",{className:"flex-1 text-text-primary text-sm font-medium break-all mr-3",children:n}),k.jsx(T3,{onCopy:()=>{s&&s(n)},text:n,children:k.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[k.jsx("rect",{x:"2.08496",y:"4.02295",width:"9.89893",height:"9.89893",rx:"2",stroke:"#F9F9F9"}),k.jsx("path",{d:"M5.85547 2.07861H11.415C12.7957 2.07861 13.915 3.1979 13.915 4.57861V10.0786",stroke:"#F9F9F9",strokeLinecap:"round"})]})},"copy")]}),k.jsxs("div",{className:"border-b border-dashed border-line-divider-secondary pb-4",children:[k.jsxs("div",{className:"flex items-start",children:[k.jsx("div",{className:"w-5",children:k.jsx("img",{src:Wo,className:"w-4 h-4",alt:"Warning"})}),k.jsx("div",{className:"flex-1",children:k.jsx("p",{className:"text-xs text-functional-orange-1",children:p})})]}),r===a0&&k.jsxs(k.Fragment,{children:[k.jsx("div",{className:"my-2 ml-5 h-[1px] border-b border-dashed border-line-divider-secondary"}),k.jsx("div",{className:"flex items-start pl-5 text-functional-orange-1 text-xs",children:c("deposit.addressUpdatedNotice")})]})]}),k.jsxs("div",{className:"text-sm",children:[k.jsxs("div",{className:"flex justify-between items-center h-[18px] mt-4",children:[k.jsx("span",{className:"text-text-tertiary",children:c("deposit.arrivalTime")}),k.jsx(Qn,{content:k.jsxs("div",{className:"grid flex-grow max-w-[300px] min-w-[80px] rounded-2xl flex-col gap-[10px]",children:[k.jsx("p",{children:c("deposit.arrivaltimeTooltip1",{v:(e==null?void 0:e.blockTime)*e.txConfirm/60,v1:e==null?void 0:e.txConfirm})}),k.jsx("p",{children:c("deposit.arrivaltimeTooltip2")})]}),placement:"top",children:k.jsx("span",{className:"text-text-primary font-medium text-right border-b-[2px] border-dashed border-line-divider-primary decoration-dashed",children:c("deposit.arrivalEstimated",{v:(e==null?void 0:e.blockTime)*e.txConfirm/60})})})]}),k.jsxs("div",{className:"flex justify-between items-center h-[18px] mt-1",children:[k.jsx("span",{className:"text-text-tertiary",children:c("deposit.minDeposit")}),k.jsxs("span",{className:"text-text-primary font-medium text-right",children:[d," ",t]})]}),r===a0&&k.jsxs("div",{className:"flex justify-between items-center h-[18px] mt-1",children:[k.jsx("span",{className:"text-text-tertiary",children:c("deposit.maxDeposit")}),k.jsxs("span",{className:"text-text-primary font-medium text-right",children:["200,000 ",t]})]})]}),k.jsx("button",{className:"w-full h-[38px] bg-fill-btn-primary rounded-xl text-sm font-medium text-text-on-sec-btn mt-4",onClick:()=>{o&&o({amount:"",chainId:e.chainId,tokenAddress:n,tokenSymbol:t}),i()},children:c("deposit.title")})]})},Vo=({size:e="xs",color:t,className:n="",label:r="Loading...",inline:o=!1})=>{const s=t?`loading-${t}`:"",i=o?"loading-inline":"";return k.jsx("span",{className:`loading loading-${e} loading-spinner ${s} ${i} ${n}`.trim(),"aria-label":r,role:"status","aria-live":"polite"})},E4=(e,t)=>Number(e)>Number(t),Mt=e=>{if(!e||e===""||isNaN(Number(e)))return"0.00";const t=Number(e);if(t===0)return"0.00";let n=t.toString();n.includes("e")&&(n=t.toFixed(20));const r=n.split("."),o=r[0];let s=r[1]||"";return s.length>6&&(s=s.substring(0,6)),s=s.replace(/0+$/,""),s?(s.length===1&&(s+="0"),o+"."+s):o+".00"},fi=(e,t="0")=>{if(/[^0-9.]/.test(e))return{isValid:!1,formattedValue:"",errorType:"invalid_char"};if(e===".")return{isValid:!0,formattedValue:"0."};if((e.match(/\./g)||[]).length>1)return{isValid:!1,formattedValue:"",errorType:"invalid_char"};if(!e||e==="")return{isValid:!0,formattedValue:""};const o=e.split(".");if(o.length===2&&o[1].length>6){const a=o[0]+"."+o[1].substring(0,6);return fi(a,t)}const s=parseFloat(e),i=parseFloat(t);return!isNaN(s)&&!isNaN(i)&&s>i?{isValid:!0,formattedValue:Mt(t),errorType:"auto_adjusted_to_max"}:{isValid:!0,formattedValue:e}},S4=(e,t,n)=>{const r=parseFloat(String(e)||"0"),o=parseFloat(String(t)||"0");if(o>0){const s=r-o,i=Mt(Math.max(0,s).toString());return k.jsxs("span",{className:"flex items-center gap-1",children:[Mt(e),k.jsx("span",{className:"text-sm font-edgex-harmony text-functional-green-1 leading-[18px] font-medium",children:"→"}),i," ",n]})}return`${Mt(e)} ${n}`},P4=(e,t,n)=>{if(!e||e===""||e==="0"||e==="0.00")return!1;const r=parseFloat(e),o=parseFloat(t);return!(isNaN(r)||isNaN(o)||r>o||!n)},$4=(e,t,n)=>{if(!xh(e,n))return!1;try{const r=new Ie(t||"0"),o=new Ie("200000");return r.isNaN()||o.isNaN()?!1:r.gte(o)}catch{return!1}},T4=(e,t,n,r)=>{let o=t||"0";if(!(r==="spot")&&xh(e,n))try{const i=new Ie(o),c=new Ie("200000");i.gt(c)&&(o="200000")}catch(i){console.warn("Error calculating max amount limit:",i)}try{const i=new Ie(o||"0");return console.log("bn:",i),console.log("bn:",i.isNaN()),i.isNaN()?o:i.decimalPlaces(6,Ie.ROUND_DOWN).toString()}catch{return o}},cm={chains:[],spotChains:[],currentActiveAccount:{wallet:"EVM",ethAddress:"",accountId:"",smartWalletAddress:""},defaultChainId:1,defaultAccountType:"perpetual",balances:{spot:{},perpetual:{}}};let Ye=null;const um=x.forwardRef((e,t)=>{const[n,r]=x.useState(!1),[o,s]=x.useState(!1),[i,c]=x.useState(cm),a=x.useCallback(h=>{c(h),r(!0)},[]),u=x.useCallback(h=>{c(m=>({...m,...h}))},[]),l=x.useCallback(()=>{r(!1),s(!1),i.onClose&&i.onClose()},[i.onClose]),f=x.useCallback(h=>{s(h)},[]),p=x.useCallback(()=>n,[n]),d=x.useCallback(()=>o,[o]);return x.useImperativeHandle(t,()=>({openDeposit:a,closeDeposit:l,updateDepositOptions:u,setDepositLoading:f,isOpen:p,isLoading:d}),[a,l,u,f,p,d]),x.useEffect(()=>(Ye={openDeposit:a,closeDeposit:l,updateDepositOptions:u,setDepositLoading:f,isOpen:p,isLoading:d},()=>{Ye=null}),[a,l,u,f,p,d]),n?k.jsx(mm,{isOpen:n,isLoading:o,onClose:l,currentActiveAccount:i.currentActiveAccount,chains:i.chains,spotChains:i.spotChains,defaultChainId:i.defaultChainId,defaultSymbol:i.defaultSymbol,defaultAccountType:i.defaultAccountType,balances:i.balances,wagmiHooks:i.wagmiHooks,onDeposit:i.onDeposit,onCopy:i.onCopy,onChainChange:h=>{var m;return(m=i.onChainChange)==null?void 0:m.call(i,h)},onTokenChange:h=>{var m;return(m=i.onTokenChange)==null?void 0:m.call(i,h)}}):null});um.displayName="DepositManager";const lm=e=>{if(!Ye){console.error("DepositManager not initialized. Make sure to render <DepositManager /> in your app.");return}Ye.openDeposit(e||cm)},fm=()=>{if(!Ye){console.error("DepositManager not initialized. Make sure to render <DepositManager /> in your app.");return}Ye.closeDeposit()},dm=e=>{Ye&&Ye.updateDepositOptions(e)},di=e=>{if(!Ye){console.error("DepositManager not initialized. Make sure to render <DepositManager /> in your app.");return}Ye.setDepositLoading(e)},A4=()=>Ye?Ye.isOpen():!1,pm=()=>Ye?Ye.isLoading():!1,O4=()=>({openDeposit:lm,closeDeposit:fm,updateDepositOptions:dm,setDepositLoading:di,isOpen:A4,isLoading:pm}),N4=e=>{const{t}=vt(),{isNetworkMismatch:n,depositAmount:r,approved:o,currentTokenBalance:s,selectedToken:i,showLayerZeroTip:c,minDeposit:a=10}=e;return x.useMemo(()=>{if(n)return{text:t("deposit.switchNetwork"),disabled:!0,isNetworkSwitch:!0};const u=parseFloat(r||"0"),l=a,f=P4(r,s||"0",o);return!r||u===0||!o?{text:t(c?"deposit.layerZeroDepositButton":"deposit.confirmDeposit"),disabled:!0,isNetworkSwitch:!1}:u<l?{text:t("deposit.minDepositParsed",{amount:l,token:i}),disabled:!0,isNetworkSwitch:!1}:{text:t(c?"deposit.layerZeroDepositButton":"deposit.confirmDeposit"),disabled:!f,isNetworkSwitch:!1}},[n,r,o,s,i,c,a,t])};function C4(e){const{account:t,accountChainId:n,targetChainId:r,tokenInfo:o,amount:s}=e,{useReadContract:i,useWriteContract:c,usePublicClient:a,useSwitchChain:u}=e.wagmiHooks,l=o==null?void 0:o.tokenAddress,f=(o==null?void 0:o.decimals)??18,p=o==null?void 0:o.contractAddress,d=!l||l.toLowerCase()==="0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",{switchChainAsync:h}=u(),{writeContractAsync:m}=c(),w=a(),$=i({address:l,abi:yr,functionName:"allowance",args:[mn(t||""),p],chainId:r,query:{enabled:!!(!d&&t&&r&&l&&p)}}),E=$!=null&&$.isSuccess?$.data:void 0,S=x.useMemo(()=>{if(d)return!0;if(!$.isSuccess||E===void 0||E===0n)return!1;try{const B=x6(String(Number(s||"0")||0),Number(f));return E>=B}catch{return!1}},[d,$.isSuccess,E,s,f]),N=x.useCallback(async()=>{try{if(r&&n&&+n!=+r&&await h({chainId:+r}),!m||!w||!l||!p)return;const F=mn(l),D=mn(p);if((E||0n)>0n){const v=await m({abi:yr,address:F,functionName:"approve",args:[D,0n]});await w.waitForTransactionReceipt({hash:v})}const g=await m({abi:yr,address:F,functionName:"approve",args:[D,ef]});await w.waitForTransactionReceipt({hash:g}),$!=null&&$.refetch&&await $.refetch()}catch(B){console.error("[useApprove] onApprove failed:",B)}},[r,n,l,p,E,$,m,w,h]);return{approve:S,onApprove:N}}const I4=({token:e,account:t,chainId:n,wagmiHooks:r,onResult:o})=>{var i;const s=(i=r==null?void 0:r.useBalance)==null?void 0:i.call(r,{address:t,token:e.tokenAddress,chainId:n,query:{enabled:!!t&&!!n&&!!e.tokenAddress&&!!(r!=null&&r.useBalance)}});return x.useEffect(()=>{o(mn(e.tokenAddress),{balance:s})},[s,e.tokenAddress,o]),null},M4=({account:e,chainId:t,contractAddress:n,tokens:r=[],wagmiHooks:o})=>{var E;const s=typeof t=="string"?Number.isFinite(Number(t))?Number(t):void 0:t,i=x.useMemo(()=>{const S="0x0000000000000000000000000000000000000000",N="0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";return r.filter(B=>{const F=B.tokenAddress;if(!F)return!1;const D=F.toLowerCase();return!(F===S||D===N)})},[r]),[c,a]=x.useState({}),u=x.useCallback((S,N)=>{a(B=>({...B,[S]:N}))},[]),l=(E=o==null?void 0:o.useBalance)==null?void 0:E.call(o,{address:e,chainId:s,query:{enabled:!!e&&!!s&&!!(o!=null&&o.useBalance)}}),[f,p]=x.useState(0),d=x.useMemo(()=>i.map(S=>x.createElement(I4,{key:`${S.tokenAddress}-${f}`,token:S,account:e,chainId:s,contractAddress:n,wagmiHooks:o,onResult:u})),[i,e,s,n,o,u,f]),h=x.useMemo(()=>{const S=l!=null&&l.data?{value:l.data.value,formatted:l.data.formatted,decimals:l.data.decimals,symbol:l.data.symbol}:{value:BigInt(0),formatted:"0",decimals:18,symbol:"ETH"},N=i.map(F=>{const D=c[mn(F.tokenAddress)],b=D==null?void 0:D.balance,g=b==null?void 0:b.data;return{address:mn(F.tokenAddress),value:(g==null?void 0:g.value)||BigInt(0),formatted:(g==null?void 0:g.formatted)||"0",decimals:(g==null?void 0:g.decimals)||F.decimals}}).filter(F=>F.address),B=N.reduce((F,D)=>({...F,[D.address]:{balance:D}}),{});return{balanceList:N,baseTokenBalance:S,combinedData:B}},[l,c,i]),m=x.useCallback(async()=>h,[h]),w=x.useMemo(()=>{const S=(l==null?void 0:l.isLoading)||!1,N=Object.values(c).some(B=>{var F;return(F=B.balance)==null?void 0:F.isLoading});return S||N},[l==null?void 0:l.isLoading,c]),$=x.useCallback(()=>p(S=>S+1),[]);return{multicallRun:m,multicallRefresh:$,multicallResult:h,validErcTokens:i,isLoading:w,queryComponents:d}},k4=({address:e,currentActiveChain:t,selectedToken:n,accountType:r,platformBalance:o,isLoading:s,wagmiHooks:i,onChainChange:c,onDeposit:a})=>{const{t:u}=vt(),l=i.useAccount(),f=t.tokenList.find(_=>_.token===n||_.symbol===n),p=t.chainId,[d,h]=x.useState("");x.useEffect(()=>{h("")},[n,t.chainId]);const{multicallResult:m,queryComponents:w}=M4({account:e,chainId:t.chainId,contractAddress:(f==null?void 0:f.contractAddress)||(t==null?void 0:t.contractAddress),tokens:(t==null?void 0:t.tokenList)||[],wagmiHooks:i}),$=x.useMemo(()=>{var W;if(!f)return"0";if(!f.tokenAddress||f.tokenAddress.toLowerCase()==="0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee")return m.baseTokenBalance.formatted;const _=m.combinedData[f.tokenAddress];return((W=_==null?void 0:_.balance)==null?void 0:W.formatted)||"0"},[f,m]),E="0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9",S="0xceeed84620e5eb9ab1d6dfc316867d2cda332e41",N=x.useMemo(()=>{var _,W;return s5({chain:u5,transport:c5(t.rpcUrl||((_=window==null?void 0:window.ENV)==null?void 0:_.CHAIN_RPC_URL_42161)||((W=window==null?void 0:window.ENV)==null?void 0:W.CHAIN_RPC_URL_421614))})},[t.rpcUrl]),B="1000000000000",{formatted:F}=l5({client:N,tokenAddress:E,holder:S,decimals:6,fallbackFormatted:B,pollingInterval:12e3}),[D,b]=x.useState(!1),{approve:g,onApprove:v}=C4({account:e,accountChainId:l.chainId,targetChainId:+t.chainId,tokenInfo:f,amount:d,wagmiHooks:i}),C=x.useCallback(async()=>{if(!D)try{b(!0),await v()}catch(_){console.error("Approve failed:",_)}finally{b(!1)}},[D,v]),O=x.useMemo(()=>+l.chainId!=+t.chainId,[l.chainId,t.chainId]),I=x.useCallback(async()=>{c&&c(p)},[c,p]);x.useEffect(()=>{O&&I()},[O,I]);const{showLayerZeroTip:M,layerZeroTipKey:y}=x.useMemo(()=>{const _=+t.chainId==42161||+t.chainId==421614,W=(n==null?void 0:n.toUpperCase())==="USDT",K=new Ie(d||"0"),G=new Ie("200000");let H=!1,Z;if(_&&W&&d)if(K.gte(G))H=!0,Z="deposit.layerZeroDepositTipGte200k";else{const J=F;if(typeof J=="string"&&J.length>0){const me=new Ie(J);!me.isNaN()&&K.gte(me)&&(H=!0,Z="deposit.layerZeroDepositTipExceedPool")}}return{showLayerZeroTip:H,layerZeroTipKey:Z}},[t.chainId,n,d,F]),A=x.useCallback(()=>T4(+t.chainId,$||"0",n,r),[$,t==null?void 0:t.chainId,n,r]),T=x.useMemo(()=>r!=="spot"&&$4(+t.chainId,d,n),[r,t==null?void 0:t.chainId,d,n]),P=x.useMemo(()=>"deposit.maxDepositSplitTip",[]),L=N4({isNetworkMismatch:O,depositAmount:d,approved:g,currentTokenBalance:$,selectedToken:n,showLayerZeroTip:M,minDeposit:f!=null&&f.minDepositSize?parseFloat(f.minDepositSize):10}),j=_=>{const W=_.target.value,K=A(),G=fi(W,K);if(G.isValid)h(G.formattedValue),G.errorType;else return G.errorType==="exceed_balance",void 0},z=x.useCallback(async()=>{di(!0);try{a&&a({amount:d,chainId:p,tokenAddress:(f==null?void 0:f.tokenAddress)||"",tokenSymbol:n,accountType:r})}catch(_){console.error("Deposit error:",_),di(!1)}},[a,d,p,f==null?void 0:f.tokenAddress,r,n]);return k.jsxs(k.Fragment,{children:[w,k.jsxs("div",{className:"bg-fill-input-primary rounded-lg px-3 py-3 my-4",children:[k.jsxs("div",{className:"flex justify-between items-center h-[18px] mb-3",children:[k.jsx("input",{type:"text",placeholder:u("deposit.amount"),value:d,onChange:j,className:"flex-1 bg-transparent text-text-primary text-sm font-medium placeholder-text-tertiary placeholder:font-normal focus:outline-none border-none p-0 h-full"}),k.jsx("button",{onClick:()=>{const _=A();h(_)},className:"text-theme-normal text-xs font-medium cursor-pointer hover:opacity-80 transition-opacity h-full flex items-center",children:u("deposit.max")})]}),k.jsx("div",{className:"h-[1px] bg-line-divider-secondary mb-2"}),k.jsxs("div",{className:"flex justify-between items-center",children:[k.jsx(Qn,{content:u("deposit.availableDesc"),children:k.jsx("span",{className:"text-text-tertiary text-xs leading-[14px] border-b border-dashed border-line-divider-primary",children:u("deposit.available")})}),k.jsx("span",{className:"text-text-primary text-xs leading-[14px]",children:S4($||"0",d,n)})]})]}),!g&&E4(d||"0",0)&&k.jsxs("div",{className:"flex justify-center flex-col items-center",children:[k.jsx("h3",{className:"text-text-primary text-sm leading-4 font-medium",children:u("deposit.enableSystemProWithToken",{token:n,network:t==null?void 0:t.chain})}),k.jsx("p",{className:"text-text-secondary text-xs leading-3 mt-4",children:u("deposit.enableTokenDesc",{token:n,network:t==null?void 0:t.chain})}),k.jsx("button",{className:"w-[180px] h-8 bg-fill-btn-primary hover:bg-fill-btn-primary-hover text-text-on-sec-btn rounded-xl text-sm font-medium transition-colors my-4 disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center",onClick:C,disabled:D,children:D?k.jsx(Vo,{size:"xs",inline:!0}):u("deposit.enableWithToken",{token:n})})]}),M&&k.jsxs(k.Fragment,{children:[k.jsxs("div",{className:"flex mb-4",children:[k.jsx("div",{className:"w-5",children:k.jsx("img",{src:Wo,className:"w-4 h-4",alt:"Warning"})}),k.jsx("div",{className:"flex-1 text-xs text-functional-orange-1",children:u(y||"deposit.layerZeroDepositTip")})]}),k.jsx("div",{className:"my-2 ml-5 h-[1px] border-b border-dashed border-line-divider-secondary"})]}),T&&k.jsxs("div",{className:"flex mb-4",children:[k.jsx("div",{className:"w-5",children:k.jsx("img",{src:Wo,className:"w-4 h-4",alt:"Warning"})}),k.jsx("div",{className:"flex-1 text-xs text-functional-orange-1",children:u(P)})]}),T&&k.jsx("div",{className:"my-2 ml-5 h-[1px] border-b border-dashed border-line-divider-secondary"}),k.jsxs("div",{className:"flex mb-4",children:[k.jsx("div",{className:"w-5",children:!(T||M)&&k.jsx("img",{src:Wo,className:"w-4 h-4",alt:"Warning"})}),k.jsx("div",{className:"flex-1 text-xs text-functional-orange-1 whitespace-pre-line",children:u("deposit.noPrivateKeyWalletWarning")})]}),k.jsxs("div",{className:"border-t border-line-divider-secondary border-dashed py-4",children:[k.jsxs("div",{className:"flex justify-between items-center h-[18px] leading-4",children:[k.jsx("span",{className:"text-sm text-text-tertiary",children:u("deposit.arrivalTime")}),k.jsx(Qn,{content:k.jsxs("div",{className:"grid flex-grow max-w-[300px] min-w-[80px] rounded-2xl flex-col gap-[10px]",children:[k.jsx("p",{children:u("deposit.arrivaltimeTooltip1",{v:(t==null?void 0:t.blockTime)*t.txConfirm/60,v1:t==null?void 0:t.txConfirm})}),k.jsx("p",{children:u("deposit.arrivaltimeTooltip2")})]}),placement:"top",children:k.jsx("span",{className:"text-text-primary font-medium text-right border-b-[2px] border-dashed border-line-divider-primary decoration-dashed text-sm",children:u("deposit.arrivalEstimated",{v:(t==null?void 0:t.blockTime)*t.txConfirm/60})})})]}),k.jsxs("div",{className:"flex justify-between items-center h-[18px] leading-4 mt-2",children:[k.jsx("span",{className:"text-sm text-text-tertiary",children:u("deposit.equity")}),k.jsx("span",{className:"text-sm text-text-primary font-medium",children:d?k.jsxs("span",{className:"flex items-center gap-1",children:[Mt(o),k.jsx("span",{className:"text-sm font-edgex-harmony text-functional-green-1 leading-[18px] font-medium",children:"→"}),Mt((parseFloat(o)+parseFloat(d)).toString())," ",n]}):`${Mt(o)} ${n}`})]})]}),k.jsxs("button",{className:`w-full h-[38px] text-sm rounded-xl font-medium transition-colors flex items-center justify-center gap-2 ${L.disabled||s?"bg-text-disabled text-text-secondary cursor-not-allowed":"bg-fill-btn-primary text-text-on-sec-btn"}`,onClick:z,disabled:L.disabled||s,children:[(s||O)&&k.jsx(Vo,{size:"xs"}),L.text]})]})},hm=e=>e.toLocaleUpperCase()===xn?xn:sc,Eu=e=>hm(e.wallet)===xn,B4=e=>hm(e.wallet)===sc,mm=({isOpen:e,isLoading:t=!1,onClose:n,currentActiveAccount:r,chains:o,spotChains:s=[],defaultChainId:i,defaultSymbol:c,defaultAccountType:a="perpetual",balances:u,wagmiHooks:l,onDeposit:f,onCopy:p,onChainChange:d,onTokenChange:h})=>{const{t:m}=vt(),[w,$]=x.useState(a),E=x.useCallback(T=>T==="spot"&&s&&s.length>0?s:o,[o,s]),S=E(a),[N,B]=x.useState(()=>{var T;return!S||S.length===0?1:i||((T=S[0])==null?void 0:T.chainId)||1}),F=x.useMemo(()=>E(w),[w,E]),D=F.find(T=>T.chainId===N)||F[0],[b,g]=x.useState(()=>{var _;if(!S||S.length===0)return"";const T=i||((_=S[0])==null?void 0:_.chainId),P=S.find(W=>W.chainId===T)||S[0],L=((P==null?void 0:P.tokenList)||[]).length>0?P:S.find(W=>(W.tokenList||[]).length>0),j=(L==null?void 0:L.tokenList)||[];if(c&&j.length>0){const W=c.toUpperCase(),K=j.find(G=>(G.token||G.symbol||"").toUpperCase()===W);if(K)return K.token||K.symbol||""}const z=j[0];return(z==null?void 0:z.token)||(z==null?void 0:z.symbol)||""}),v=x.useCallback(T=>{B(T),d==null||d(T)},[d]),C=x.useCallback(T=>{g(T),h==null||h(T)},[h]),O=x.useMemo(()=>{const T=(b||"").toLowerCase();if(!T)return"0";const P=w==="spot"?u==null?void 0:u.spot:u==null?void 0:u.perpetual,L=P==null?void 0:P[T];return typeof L=="string"&&L.length>0?L:"0"},[u,w,b]),[I,M]=x.useState(!1),y=T=>{T.target===T.currentTarget?M(!0):M(!1)},A=T=>{I&&T.target===T.currentTarget&&n(),M(!1)};return e?je.createPortal(k.jsx("div",{className:"fixed top-0 left-0 right-0 bottom-0 w-screen h-screen",style:{zIndex:98},children:k.jsx("div",{className:"fixed top-0 left-0 right-0 bottom-0 z-[99] flex items-center justify-center",style:{background:"rgba(0, 0, 0, 0.6)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)"},onMouseDown:y,onMouseUp:A,"aria-hidden":"true",children:k.jsxs("div",{className:"relative w-[420px] max-h-[85vh] bg-fill-page-secondary overflow-auto rounded-lg p-6 shadow-xl border-[2px] border-solid border-line-divider-secondary",onClick:T=>{T.stopPropagation()},children:[k.jsxs("div",{className:"flex items-center justify-between mb-4",children:[k.jsx("h2",{className:"text-lg font-semibold text-white",children:m("deposit.title")}),k.jsx("button",{className:"text-gray-400 hover:text-gray-200 transition-colors",onClick:n,"aria-label":"Close",children:k.jsx(l0,{className:"h-4 w-4"})})]}),k.jsx(Sh,{selectedAccount:w,onAccountChange:T=>{var H,Z;const P=T||"perpetual";$(P);const L=E(P);if(!L||L.length===0)return;const j=L.find(J=>J.chainId===N),z=j?j.chainId:L[0].chainId;B(z),d==null||d(z);const _=L.find(J=>J.chainId===z),W=(_==null?void 0:_.tokenList)||[],G=W.some(J=>(J.symbol||J.token)===b)?b:((H=W[0])==null?void 0:H.symbol)||((Z=W[0])==null?void 0:Z.token)||"";G&&(g(G),h==null||h(G))},className:"w-full"}),k.jsx(Eh,{currentActiveChain:D,chainList:F,onChainChange:v,curSelectToken:b,onTokenChange:C,walletType:Eu(r)?xn:sc,accountType:w}),Eu(r)&&k.jsx(x4,{address:r.smartWalletAddress,currentActiveChain:D,selectedToken:b,accountType:w,onDeposit:f,onCopy:p,onClose:n}),B4(r)&&k.jsx(k4,{address:r.ethAddress,currentActiveChain:D,selectedToken:b,accountType:w,platformBalance:O,isLoading:t,wagmiHooks:l,onChainChange:v,onDeposit:f,onClose:n})]})})}),document.body):null},L4=e=>{if(e==null||e==="")return 2;const t=String(e),n=t.indexOf(".");if(n===-1)return 0;const r=t.length-n-1;return r>0?r:2},F4=({withdrawAmount:e,curSelectToken:t,tokenInfo:n,currentActiveChain:r,platformBalance:o="0",fee:s="0.00",walletType:i="evm",receiverAddress:c="",accountType:a="perpetual",onWithdrawAmountChange:u,onReceiverAddressChange:l,onAmountChanged:f,showPoolBalanceInsufficientTip:p=!1})=>{const{t:d}=vt(),h=x.useMemo(()=>{const F=L4(n==null?void 0:n.showStepSize);if(a==="spot"||!ln(r==null?void 0:r.chainId)){const D=new Ie(e||"0").minus(s||"0").decimalPlaces(F,Ie.ROUND_DOWN);return D.isNegative()?"0.00":D.toString()}return e||"0"},[e,s,r==null?void 0:r.chainId,a,n==null?void 0:n.showStepSize]),m=x.useMemo(()=>o||"0",[o]),w=x.useMemo(()=>{const F=(n==null?void 0:n.feeRate)||(n==null?void 0:n.withdrawFeeRate)||(r==null?void 0:r.feeRate)||0;try{return new Ie(F||0).times(100).toString()}catch{return"0"}},[n==null?void 0:n.feeRate,n==null?void 0:n.withdrawFeeRate,r==null?void 0:r.feeRate]),$=x.useMemo(()=>w==="0",[w]),E=x.useMemo(()=>{const F=(t||"").toUpperCase();return F==="USDT"||F==="USDC"},[t]),S=F=>{const D=F.target.value,g=fi(D,m||"0");if(g.isValid)u(g.formattedValue),g.errorType;else return g.errorType==="exceed_balance",void 0;f==null||f(g.formattedValue)},N=()=>{const F=m||"0",b=fi(F,F).formattedValue;u(b),f==null||f(b)},B=()=>{const F=parseFloat(o||"0"),D=parseFloat(e||"0");if(D>0){const b=F-D,g=Mt(Math.max(0,b).toString());return k.jsxs("span",{className:"flex items-center gap-1",children:[Mt(o||"0"),k.jsx("span",{className:"text-sm font-edgex-harmony text-functional-green-1 leading-[18px] font-medium",children:"→"}),g," ",t]})}return`${Mt(o||"0")} ${t}`};return k.jsxs(k.Fragment,{children:[k.jsxs("div",{className:"bg-fill-input-primary rounded-lg px-3 py-3 my-4",children:[k.jsxs("div",{className:"flex justify-between items-center h-[18px] mb-3",children:[k.jsx("input",{type:"text",placeholder:d("deposit.amount"),value:e,onChange:S,className:"flex-1 bg-transparent text-text-primary text-sm font-medium placeholder-text-tertiary placeholder:font-normal focus:outline-none border-none p-0 h-full"}),k.jsx("button",{onClick:N,className:"text-theme-normal text-xs font-medium cursor-pointer hover:opacity-80 transition-opacity h-full flex items-center",children:d("deposit.max")})]}),k.jsx("div",{className:"h-[1px] bg-line-divider-secondary mb-2"}),k.jsxs("div",{className:"flex justify-between items-center",children:[k.jsx(Qn,{content:d("withdraw.availableDesc"),children:k.jsx("span",{className:"text-text-tertiary text-xs leading-[14px] border-b border-dashed border-line-divider-primary",children:d("deposit.available")})}),k.jsx("span",{className:"text-text-primary text-xs leading-[14px]",children:B()})]})]}),i==="mpc"&&(a==="spot"||!ln(r==null?void 0:r.chainId))?k.jsx("div",{className:"bg-fill-input-primary rounded-lg my-4 h-9 flex items-center px-3",children:k.jsx("input",{type:"text",placeholder:d("withdraw.receiverAddress"),value:c,onChange:F=>l==null?void 0:l(F.target.value),className:"flex-1 bg-transparent text-text-primary text-sm font-medium placeholder-text-tertiary placeholder:font-normal focus:outline-none border-none p-0 h-full"})}):null,k.jsx("div",{className:"bg-fill-page-secondary rounded-lg mb-4",children:ln(r==null?void 0:r.chainId)?k.jsxs(k.Fragment,{children:[k.jsx("p",{className:"text-text-tertiary text-xs leading-[18px]",children:d("withdraw.noticeDesc")}),k.jsx("a",{className:"block text-xs leading-[18px] mt-1 text-theme-normal",href:"https://edgex-1.gitbook.io/edgeX-documentation/getting-started/deposits-and-withdrawals/withdrawals",rel:"noreferrer",target:"_blank",children:d("withdraw.commonWithdraw")})]}):k.jsx("p",{className:"text-text-tertiary text-xs leading-[18px]",children:d("withdraw.crossChainTips")})}),p&&k.jsxs("div",{className:"flex mb-4",children:[k.jsx("div",{className:"w-5",children:k.jsx("img",{src:Wo,className:"w-4 h-4",alt:"Warning"})}),k.jsx("div",{className:"flex-1 text-xs text-functional-orange-1",children:d("withdraw.poolBalanceInsufficientTip")})]}),k.jsxs("div",{className:"py-4 border-t border-line-divider-secondary border-dashed",children:[k.jsxs("div",{className:"flex items-center justify-between h-[18px] leading-[18px]",children:[k.jsx(Qn,{content:k.jsxs("div",{children:[k.jsx("div",{children:d("withdraw.speedNote")}),k.jsxs("div",{className:"flex gap-1 items-center mt-1",children:[k.jsx(Uo,{selectedLevel:It.FAST,maxLevel:3}),k.jsx("span",{children:d("withdraw.speedNoteSpeed1")})]}),k.jsxs("div",{className:"flex gap-1 items-center mt-1",children:[k.jsx(Uo,{selectedLevel:It.Medium,maxLevel:3}),k.jsx("span",{children:d("withdraw.speedNoteSpeed2")})]}),k.jsxs("div",{className:"flex gap-1 items-center mt-1",children:[k.jsx(Uo,{selectedLevel:It.SLOW,maxLevel:3}),k.jsx("span",{children:d("withdraw.speedNoteSpeed3")})]})]}),children:k.jsx("span",{className:"text-text-tertiary text-sm leading-4 border-b border-dashed border-line-divider-primary",children:d("withdraw.speed")})}),k.jsx("div",{className:"flex items-center",children:k.jsx(Uo,{selectedLevel:ln(r==null?void 0:r.chainId)?It.SLOW:It.FAST,maxLevel:3})})]}),(a==="spot"||!ln(r==null?void 0:r.chainId))&&k.jsxs("div",{className:"flex items-center justify-between mt-2 h-[18px]",children:[$||!E?k.jsx("span",{className:"text-text-tertiary text-sm leading-4",children:$?d("withdraw.fee"):`${d("withdraw.fee")}/${d("withdraw.feeRate")}`}):k.jsx(Qn,{className:"w-[320px] font-normal flex items-center justify-center",content:k.jsx("span",{className:"flex items-center justify-center text-center",children:d("withdraw.feeCalculationTip")}),children:k.jsx("span",{className:"text-text-tertiary text-sm leading-4 border-b border-dashed border-line-divider-primary",children:`${d("withdraw.fee")}/${d("withdraw.feeRate")}`})}),k.jsxs("span",{className:"text-text-primary text-sm leading-4 font-medium",children:[s," ",t,!$&&` / ${w}%`]})]}),k.jsxs("div",{className:"flex items-center justify-between mt-2 h-[18px]",children:[k.jsx("span",{className:"text-text-tertiary text-sm leading-4",children:d(ln(r==null?void 0:r.chainId)?"withdraw.withdrawlAmount":"withdraw.amountToReceive")}),k.jsxs("span",{className:"text-text-primary text-sm leading-4 font-medium",children:[Mt(h)," ",t]})]})]})]})},D4=[];let Ke=null;const bm=x.forwardRef((e,t)=>{const[n,r]=x.useState(!1),[o,s]=x.useState(!1),[i,c]=x.useState({chains:[],currentActiveAccount:{wallet:"EVM",ethAddress:"",accountId:"",smartWalletAddress:""}}),a=x.useCallback(h=>{c(h||{chains:[],currentActiveAccount:{wallet:"EVM",ethAddress:"",accountId:"",smartWalletAddress:""}}),r(!0)},[]),u=x.useCallback(h=>{c(m=>({...m,...h}))},[]),l=x.useCallback(()=>{r(!1),s(!1),i.onClose&&i.onClose()},[i.onClose]),f=x.useCallback(h=>{s(h)},[]),p=x.useCallback(()=>n,[n]),d=x.useCallback(()=>o,[o]);return x.useImperativeHandle(t,()=>({openWithdraw:a,closeWithdraw:l,updateWithdrawOptions:u,setWithdrawLoading:f,isOpen:p,isLoading:d}),[a,l,u,f,p,d]),x.useEffect(()=>(Ke={openWithdraw:a,closeWithdraw:l,updateWithdrawOptions:u,setWithdrawLoading:f,isOpen:p,isLoading:d},()=>{Ke=null}),[a,l,u,f,p,d]),n?k.jsx(xm,{isOpen:n,isLoading:o,onClose:l,config:i.config||{symbol:"USDT"},currentActiveAccount:i.currentActiveAccount,chains:i.chains||D4,spotChains:i.spotChains,balances:i.balances,defaultChainId:i.defaultChainId,defaultSymbol:i.defaultSymbol,defaultAmount:i.defaultAmount,defaultAccountType:i.defaultAccountType,currentEquity:i.currentEquity??5e3,platformBalance:i.platformBalance||"0",fee:i.fee,wagmiHooks:i.wagmiHooks,onWithdraw:i.onWithdraw,onAccountChange:i.onAccountChange,onChainChange:i.onChainChange,onTokenChange:i.onTokenChange,onAmountChanged:i.onAmountChanged}):null});bm.displayName="WithdrawManager";const gm=e=>{if(!Ke){console.error("WithdrawManager not initialized. Make sure to render <WithdrawManager /> in your app.");return}Ke.openWithdraw(e||{chains:[],currentActiveAccount:{wallet:"EVM",ethAddress:"",accountId:"",smartWalletAddress:""}})},ym=()=>{if(!Ke){console.error("WithdrawManager not initialized. Make sure to render <WithdrawManager /> in your app.");return}Ke.closeWithdraw()},wm=e=>{if(!Ke){console.error("WithdrawManager not initialized. Make sure to render <WithdrawManager /> in your app.");return}Ke.updateWithdrawOptions(e)},pi=e=>{if(!Ke){console.error("WithdrawManager not initialized. Make sure to render <WithdrawManager /> in your app.");return}Ke.setWithdrawLoading(e)},R4=()=>Ke?Ke.isOpen():!1,vm=()=>Ke?Ke.isLoading():!1,j4=()=>({openWithdraw:gm,closeWithdraw:ym,updateWithdrawOptions:wm,setWithdrawLoading:pi,isOpen:R4,isLoading:vm}),_4=({walletType:e,chains:t,spotChains:n=[],defaultChainId:r,defaultSymbol:o,defaultAmount:s="",defaultAccountType:i="perpetual",currentEquity:c,platformBalance:a="0",balances:u,fee:l="0.00",isLoading:f=!1,onWithdraw:p,onClose:d,onChainChange:h,onTokenChange:m,onAmountChanged:w,onAccountChange:$})=>{var H;const{t:E}=vt(),[S,N]=x.useState(i),B=x.useCallback(Z=>Z==="spot"&&n&&n.length>0?n:t,[t,n]),F=x.useMemo(()=>B(S),[S,B]),D=x.useMemo(()=>{if(!F||F.length===0)return{chainId:1,tokenSymbol:""};const Z=de=>{const se=de||[];if(!se.length)return"";const ee="USDC".toUpperCase(),Nn=se.find(gt=>(gt.token||gt.symbol||"").toUpperCase()===ee)||se[0];return Nn.token||Nn.symbol||""};if(o){const de=o==null?void 0:o.toUpperCase();for(const se of F){const pe=se.tokenList||[];let ee;if(de&&(ee=pe.find(Se=>(Se.token||Se.symbol||"").toUpperCase()===de)),ee){const Se=ee.token||ee.symbol||o||"";return{chainId:se.chainId,tokenSymbol:Se}}}}if(r){const de=F.find(ee=>ee.chainId===r)||F[0],se=de.tokenList||[],pe=Z(se);return{chainId:de.chainId,tokenSymbol:pe}}const J="USDC",oe=de=>Array.isArray(de.tokenList)&&de.tokenList.some(se=>(se.token||se.symbol||"").toUpperCase()===J),me=F.find(oe)||F[0];if(!me)return{chainId:1,tokenSymbol:""};const ge=Z(me.tokenList);return{chainId:me.chainId,tokenSymbol:ge}},[F,r,o]),[b,g]=x.useState(()=>D.chainId),[v,C]=x.useState(()=>D.tokenSymbol),[O,I]=x.useState(s),[M,y]=x.useState(""),A=x.useCallback(Z=>{g(Z),h==null||h(Z)},[h]),T=x.useCallback(Z=>{C(Z),m==null||m(Z)},[m]),P=x.useRef(!0),L=x.useRef(v),j=x.useRef(b);x.useEffect(()=>{if(P.current){P.current=!1,L.current=v,j.current=b;return}(L.current!==v||j.current!==b)&&(I(""),L.current=v,j.current=b)},[v,b]);const z=F&&F.length>0?F.find(Z=>Z.chainId===b)||F[0]:null,_=(H=z==null?void 0:z.tokenList)==null?void 0:H.find(Z=>Z.token===v),W=x.useMemo(()=>{const Z=new Ie(O||"0"),J=new Ie(l||"0"),oe=ln(b);return _!=null&&_.minWithdrawSize&&Z.lt(_.minWithdrawSize)?{text:E("withdraw.minWithdrawParsed",{amount:_.minWithdrawSize,token:_.symbol||_.token}),disabled:!0}:!O||Z.isZero()||!oe&&Z.isLessThan(J)?{text:E("withdraw.confirmWithdraw"),disabled:!0}:e==="mpc"&&(!oe||S==="spot")&&!M.trim()?{text:E("withdraw.invalidReceiverAddress"),disabled:!0}:{text:E("withdraw.confirmWithdraw"),disabled:!1}},[E,b,O,e,M,l,S,_]),K=x.useMemo(()=>{const Z=(v||"").toLowerCase();if(!Z)return a||"0";const J=S==="spot"?u==null?void 0:u.spot:u==null?void 0:u.perpetual,oe=J==null?void 0:J[Z];return typeof oe=="string"&&oe.length>0?oe:a||"0"},[u,S,v,a]),G=x.useCallback(async()=>{pi(!0);try{if(p){const J={amount:new Ie(O||"0").toString(),chainId:b,tokenAddress:(_==null?void 0:_.tokenAddress)||"",coinId:(_==null?void 0:_.coinId)||"",tokenSymbol:v,accountType:S,selectedToken:_};e==="mpc"&&(!ln(b)||S==="spot")&&(J.receiverAddress=M),p(J)}}catch{pi(!1)}},[p,S,_,O,b,v,e,M]);return!F||F.length===0?k.jsx("div",{className:"text-center py-8",children:k.jsx("p",{className:"text-gray-400",children:"No chains available"})}):z?k.jsxs(k.Fragment,{children:[k.jsx(Sh,{selectedAccount:S,onAccountChange:Z=>{var Se,Nn;const J=Z||"perpetual";N(J),$==null||$(J);const oe=B(J);if(!oe||oe.length===0)return;const me=oe.find(gt=>gt.chainId===b),ge=me?me.chainId:oe[0].chainId;g(ge),h==null||h(ge);const de=oe.find(gt=>gt.chainId===ge),se=(de==null?void 0:de.tokenList)||[],ee=se.some(gt=>(gt.symbol||gt.token)===v)?v:((Se=se[0])==null?void 0:Se.symbol)||((Nn=se[0])==null?void 0:Nn.token)||"";ee&&(C(ee),m==null||m(ee))},className:"w-full"}),k.jsx(Eh,{currentActiveChain:z,chainList:F,onChainChange:A,curSelectToken:v,onTokenChange:T,walletType:"EVM",txType:"withdraw"}),k.jsx(F4,{withdrawAmount:O,curSelectToken:v,tokenInfo:_,curSelectTokenData:{balance:_==null?void 0:_.balance,allowance:_==null?void 0:_.allowance},currentActiveChain:z,currentEquity:c||0,decimals:(_==null?void 0:_.decimals)||6,platformBalance:K,fee:l,walletType:e,accountType:S,receiverAddress:M,onWithdrawAmountChange:I,onReceiverAddressChange:y,onAmountChanged:w}),k.jsxs("button",{className:`w-full h-[38px] text-sm rounded-xl font-medium transition-colors flex items-center justify-center gap-2 ${W.disabled||f?"bg-text-disabled text-text-secondary cursor-not-allowed":"bg-fill-btn-primary text-text-on-sec-btn"}`,onClick:G,disabled:W.disabled||f,children:[f&&k.jsx(Vo,{size:"xs"}),W.text]})]}):k.jsx("div",{className:"text-center py-8",children:k.jsx("p",{className:"text-gray-400",children:"Loading..."})})},xm=({isOpen:e,isLoading:t=!1,defaultAccountType:n="perpetual",onClose:r,config:o,currentActiveAccount:s,chains:i,spotChains:c=[],defaultChainId:a,defaultSymbol:u,defaultAmount:l="",currentEquity:f=5e3,platformBalance:p="0",balances:d,fee:h,wagmiHooks:m,onWithdraw:w,onChainChange:$,onTokenChange:E,onAmountChanged:S,onAccountChange:N})=>{const{t:B}=vt(),[F,D]=x.useState(!1),b=v=>{v.target===v.currentTarget?D(!0):D(!1)},g=v=>{F&&v.target===v.currentTarget&&r(),D(!1)};return e?je.createPortal(k.jsx("div",{className:"fixed top-0 left-0 right-0 bottom-0 w-screen h-screen",style:{zIndex:98},children:k.jsx("div",{className:"fixed top-0 left-0 right-0 bottom-0 z-[99] flex items-center justify-center",style:{background:"rgba(0, 0, 0, 0.6)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)"},onMouseDown:b,onMouseUp:g,"aria-hidden":"true",children:k.jsxs("div",{className:"relative w-[420px] max-h-[85vh] bg-fill-page-secondary overflow-auto rounded-lg p-6 shadow-xl",onClick:v=>{v.stopPropagation()},children:[k.jsxs("div",{className:"flex items-center justify-between mb-4",children:[k.jsx("h2",{className:"text-lg font-semibold text-white",children:B("withdraw.withdraw")}),k.jsx("button",{className:"text-gray-400 hover:text-gray-200 transition-colors",onClick:r,"aria-label":"Close",children:k.jsx(l0,{className:"h-4 w-4"})})]}),k.jsx(_4,{chains:i,spotChains:c,walletType:Eu(s)?"mpc":"evm",defaultChainId:a,defaultSymbol:u,defaultAmount:l,defaultAccountType:n,currentEquity:f,platformBalance:p,balances:d,fee:h,isLoading:t,wagmiHooks:m,onWithdraw:w,onClose:r,onChainChange:$,onTokenChange:E,onAmountChanged:S,onAccountChange:N})]})})}),document.body):null};re.ChromeLoader=Vo,re.ComponentProvider=Gm,re.DEFAULT_LOCALE=qo,re.Deposit=mm,re.DepositManager=um,re.LOCALE_NAMES=Hm,re.LoadingSpinner=Vo,re.SUPPORTED_LOCALES=bi,re.Tooltip=Qn,re.Withdraw=xm,re.WithdrawManager=bm,re.closeDeposit=fm,re.closeWithdraw=ym,re.formatThousands=Zm,re.isDepositLoading=pm,re.isWithdrawLoading=vm,re.openDeposit=lm,re.openWithdraw=gm,re.setDepositLoading=di,re.setWithdrawLoading=pi,re.updateDepositOptions=dm,re.updateWithdrawOptions=wm,re.useComponentConfig=Lu,re.useDeposit=f5,re.useDepositManager=O4,re.useTranslation=vt,re.useWithdraw=d5,re.useWithdrawManager=j4,Object.defineProperty(re,Symbol.toStringTag,{value:"Module"})});
|
|
178
|
+
`)[0]:$},[c,t,e==null?void 0:e.chain,l,u]),d=(f==null?void 0:f.minDepositSize)||"10";return k.jsxs(k.Fragment,{children:[k.jsx("div",{className:"flex justify-center mt-4 mb-3",children:n&&k.jsx("div",{className:"bg-white rounded-lg",children:k.jsx(zh,{value:n,size:120,level:"L",bgColor:"#ffffff",fgColor:"#000000",marginSize:0})})}),n&&k.jsxs("div",{className:"flex items-center justify-between bg-fill-input-primary rounded-lg py-2 px-3 mb-3",children:[k.jsx("span",{className:"flex-1 text-text-primary text-sm font-medium break-all mr-3",children:n}),k.jsx(T3,{onCopy:()=>{s&&s(n)},text:n,children:k.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[k.jsx("rect",{x:"2.08496",y:"4.02295",width:"9.89893",height:"9.89893",rx:"2",stroke:"#F9F9F9"}),k.jsx("path",{d:"M5.85547 2.07861H11.415C12.7957 2.07861 13.915 3.1979 13.915 4.57861V10.0786",stroke:"#F9F9F9",strokeLinecap:"round"})]})},"copy")]}),k.jsxs("div",{className:"border-b border-dashed border-line-divider-secondary pb-4",children:[k.jsxs("div",{className:"flex items-start",children:[k.jsx("div",{className:"w-5",children:k.jsx("img",{src:Wo,className:"w-4 h-4",alt:"Warning"})}),k.jsx("div",{className:"flex-1",children:k.jsx("p",{className:"text-xs text-functional-orange-1",children:p})})]}),r===a0&&k.jsxs(k.Fragment,{children:[k.jsx("div",{className:"my-2 ml-5 h-[1px] border-b border-dashed border-line-divider-secondary"}),k.jsx("div",{className:"flex items-start pl-5 text-functional-orange-1 text-xs",children:c("deposit.addressUpdatedNotice")})]})]}),k.jsxs("div",{className:"text-sm",children:[(a||t.toUpperCase()!=="USDC")&&k.jsxs("div",{className:"flex justify-between items-center h-[18px] mt-4",children:[k.jsx("span",{className:"text-text-tertiary",children:c("deposit.arrivalTime")}),k.jsx(Qn,{content:k.jsxs("div",{className:"grid flex-grow max-w-[300px] min-w-[80px] rounded-2xl flex-col gap-[10px]",children:[k.jsx("p",{children:c("deposit.arrivaltimeTooltip1",{v:(e==null?void 0:e.blockTime)*e.txConfirm/60,v1:e==null?void 0:e.txConfirm})}),k.jsx("p",{children:c("deposit.arrivaltimeTooltip2")})]}),placement:"top",children:k.jsx("span",{className:"text-text-primary font-medium text-right border-b-[2px] border-dashed border-line-divider-primary decoration-dashed",children:c("deposit.arrivalEstimated",{v:(e==null?void 0:e.blockTime)*e.txConfirm/60})})})]}),k.jsxs("div",{className:`flex justify-between items-center h-[18px] ${a||t.toUpperCase()!=="USDC"?"mt-1":"mt-4"}`,children:[k.jsx("span",{className:"text-text-tertiary",children:c("deposit.minDeposit")}),k.jsxs("span",{className:"text-text-primary font-medium text-right",children:[d," ",t]})]}),r===a0&&t.toUpperCase()!=="USDC"&&k.jsxs("div",{className:"flex justify-between items-center h-[18px] mt-1",children:[k.jsx("span",{className:"text-text-tertiary",children:c("deposit.maxDeposit")}),k.jsxs("span",{className:"text-text-primary font-medium text-right",children:["200,000 ",t]})]})]}),k.jsx("button",{className:"w-full h-[38px] bg-fill-btn-primary rounded-xl text-sm font-medium text-text-on-sec-btn mt-4",onClick:()=>{o&&o({amount:"",chainId:e.chainId,tokenAddress:n,tokenSymbol:t}),i()},children:c("deposit.title")})]})},Vo=({size:e="xs",color:t,className:n="",label:r="Loading...",inline:o=!1})=>{const s=t?`loading-${t}`:"",i=o?"loading-inline":"";return k.jsx("span",{className:`loading loading-${e} loading-spinner ${s} ${i} ${n}`.trim(),"aria-label":r,role:"status","aria-live":"polite"})},E4=(e,t)=>Number(e)>Number(t),Mt=e=>{if(!e||e===""||isNaN(Number(e)))return"0.00";const t=Number(e);if(t===0)return"0.00";let n=t.toString();n.includes("e")&&(n=t.toFixed(20));const r=n.split("."),o=r[0];let s=r[1]||"";return s.length>6&&(s=s.substring(0,6)),s=s.replace(/0+$/,""),s?(s.length===1&&(s+="0"),o+"."+s):o+".00"},fi=(e,t="0")=>{if(/[^0-9.]/.test(e))return{isValid:!1,formattedValue:"",errorType:"invalid_char"};if(e===".")return{isValid:!0,formattedValue:"0."};if((e.match(/\./g)||[]).length>1)return{isValid:!1,formattedValue:"",errorType:"invalid_char"};if(!e||e==="")return{isValid:!0,formattedValue:""};const o=e.split(".");if(o.length===2&&o[1].length>6){const a=o[0]+"."+o[1].substring(0,6);return fi(a,t)}const s=parseFloat(e),i=parseFloat(t);return!isNaN(s)&&!isNaN(i)&&s>i?{isValid:!0,formattedValue:Mt(t),errorType:"auto_adjusted_to_max"}:{isValid:!0,formattedValue:e}},S4=(e,t,n)=>{const r=parseFloat(String(e)||"0"),o=parseFloat(String(t)||"0");if(o>0){const s=r-o,i=Mt(Math.max(0,s).toString());return k.jsxs("span",{className:"flex items-center gap-1",children:[Mt(e),k.jsx("span",{className:"text-sm font-edgex-harmony text-functional-green-1 leading-[18px] font-medium",children:"→"}),i," ",n]})}return`${Mt(e)} ${n}`},P4=(e,t,n)=>{if(!e||e===""||e==="0"||e==="0.00")return!1;const r=parseFloat(e),o=parseFloat(t);return!(isNaN(r)||isNaN(o)||r>o||!n)},$4=(e,t,n)=>{if(!xh(e,n))return!1;try{const r=new Ie(t||"0"),o=new Ie("200000");return r.isNaN()||o.isNaN()?!1:r.gte(o)}catch{return!1}},T4=(e,t,n,r)=>{let o=t||"0";if(!(r==="spot")&&xh(e,n))try{const i=new Ie(o),c=new Ie("200000");i.gt(c)&&(o="200000")}catch(i){console.warn("Error calculating max amount limit:",i)}try{const i=new Ie(o||"0");return console.log("bn:",i),console.log("bn:",i.isNaN()),i.isNaN()?o:i.decimalPlaces(6,Ie.ROUND_DOWN).toString()}catch{return o}},cm={chains:[],spotChains:[],currentActiveAccount:{wallet:"EVM",ethAddress:"",accountId:"",smartWalletAddress:""},defaultChainId:1,defaultAccountType:"perpetual",balances:{spot:{},perpetual:{}}};let Ye=null;const um=x.forwardRef((e,t)=>{const[n,r]=x.useState(!1),[o,s]=x.useState(!1),[i,c]=x.useState(cm),a=x.useCallback(h=>{c(h),r(!0)},[]),u=x.useCallback(h=>{c(m=>({...m,...h}))},[]),l=x.useCallback(()=>{r(!1),s(!1),i.onClose&&i.onClose()},[i.onClose]),f=x.useCallback(h=>{s(h)},[]),p=x.useCallback(()=>n,[n]),d=x.useCallback(()=>o,[o]);return x.useImperativeHandle(t,()=>({openDeposit:a,closeDeposit:l,updateDepositOptions:u,setDepositLoading:f,isOpen:p,isLoading:d}),[a,l,u,f,p,d]),x.useEffect(()=>(Ye={openDeposit:a,closeDeposit:l,updateDepositOptions:u,setDepositLoading:f,isOpen:p,isLoading:d},()=>{Ye=null}),[a,l,u,f,p,d]),n?k.jsx(mm,{isOpen:n,isLoading:o,onClose:l,currentActiveAccount:i.currentActiveAccount,chains:i.chains,spotChains:i.spotChains,defaultChainId:i.defaultChainId,defaultSymbol:i.defaultSymbol,defaultAccountType:i.defaultAccountType,balances:i.balances,wagmiHooks:i.wagmiHooks,onDeposit:i.onDeposit,onCopy:i.onCopy,onChainChange:h=>{var m;return(m=i.onChainChange)==null?void 0:m.call(i,h)},onTokenChange:h=>{var m;return(m=i.onTokenChange)==null?void 0:m.call(i,h)}}):null});um.displayName="DepositManager";const lm=e=>{if(!Ye){console.error("DepositManager not initialized. Make sure to render <DepositManager /> in your app.");return}Ye.openDeposit(e||cm)},fm=()=>{if(!Ye){console.error("DepositManager not initialized. Make sure to render <DepositManager /> in your app.");return}Ye.closeDeposit()},dm=e=>{Ye&&Ye.updateDepositOptions(e)},di=e=>{if(!Ye){console.error("DepositManager not initialized. Make sure to render <DepositManager /> in your app.");return}Ye.setDepositLoading(e)},A4=()=>Ye?Ye.isOpen():!1,pm=()=>Ye?Ye.isLoading():!1,O4=()=>({openDeposit:lm,closeDeposit:fm,updateDepositOptions:dm,setDepositLoading:di,isOpen:A4,isLoading:pm}),N4=e=>{const{t}=vt(),{isNetworkMismatch:n,depositAmount:r,approved:o,currentTokenBalance:s,selectedToken:i,showLayerZeroTip:c,minDeposit:a=10}=e;return x.useMemo(()=>{if(n)return{text:t("deposit.switchNetwork"),disabled:!0,isNetworkSwitch:!0};const u=parseFloat(r||"0"),l=a,f=P4(r,s||"0",o);return!r||u===0||!o?{text:t(c?"deposit.layerZeroDepositButton":"deposit.confirmDeposit"),disabled:!0,isNetworkSwitch:!1}:u<l?{text:t("deposit.minDepositParsed",{amount:l,token:i}),disabled:!0,isNetworkSwitch:!1}:{text:t(c?"deposit.layerZeroDepositButton":"deposit.confirmDeposit"),disabled:!f,isNetworkSwitch:!1}},[n,r,o,s,i,c,a,t])};function C4(e){const{account:t,accountChainId:n,targetChainId:r,tokenInfo:o,amount:s}=e,{useReadContract:i,useWriteContract:c,usePublicClient:a,useSwitchChain:u}=e.wagmiHooks,l=o==null?void 0:o.tokenAddress,f=(o==null?void 0:o.decimals)??18,p=o==null?void 0:o.contractAddress,d=!l||l.toLowerCase()==="0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",{switchChainAsync:h}=u(),{writeContractAsync:m}=c(),w=a(),$=i({address:l,abi:yr,functionName:"allowance",args:[mn(t||""),p],chainId:r,query:{enabled:!!(!d&&t&&r&&l&&p)}}),E=$!=null&&$.isSuccess?$.data:void 0,S=x.useMemo(()=>{if(d)return!0;if(!$.isSuccess||E===void 0||E===0n)return!1;try{const B=x6(String(Number(s||"0")||0),Number(f));return E>=B}catch{return!1}},[d,$.isSuccess,E,s,f]),N=x.useCallback(async()=>{try{if(r&&n&&+n!=+r&&await h({chainId:+r}),!m||!w||!l||!p)return;const F=mn(l),D=mn(p);if((E||0n)>0n){const v=await m({abi:yr,address:F,functionName:"approve",args:[D,0n]});await w.waitForTransactionReceipt({hash:v})}const g=await m({abi:yr,address:F,functionName:"approve",args:[D,ef]});await w.waitForTransactionReceipt({hash:g}),$!=null&&$.refetch&&await $.refetch()}catch(B){console.error("[useApprove] onApprove failed:",B)}},[r,n,l,p,E,$,m,w,h]);return{approve:S,onApprove:N}}const I4=({token:e,account:t,chainId:n,wagmiHooks:r,onResult:o})=>{var i;const s=(i=r==null?void 0:r.useBalance)==null?void 0:i.call(r,{address:t,token:e.tokenAddress,chainId:n,query:{enabled:!!t&&!!n&&!!e.tokenAddress&&!!(r!=null&&r.useBalance)}});return x.useEffect(()=>{o(mn(e.tokenAddress),{balance:s})},[s,e.tokenAddress,o]),null},M4=({account:e,chainId:t,contractAddress:n,tokens:r=[],wagmiHooks:o})=>{var E;const s=typeof t=="string"?Number.isFinite(Number(t))?Number(t):void 0:t,i=x.useMemo(()=>{const S="0x0000000000000000000000000000000000000000",N="0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";return r.filter(B=>{const F=B.tokenAddress;if(!F)return!1;const D=F.toLowerCase();return!(F===S||D===N)})},[r]),[c,a]=x.useState({}),u=x.useCallback((S,N)=>{a(B=>({...B,[S]:N}))},[]),l=(E=o==null?void 0:o.useBalance)==null?void 0:E.call(o,{address:e,chainId:s,query:{enabled:!!e&&!!s&&!!(o!=null&&o.useBalance)}}),[f,p]=x.useState(0),d=x.useMemo(()=>i.map(S=>x.createElement(I4,{key:`${S.tokenAddress}-${f}`,token:S,account:e,chainId:s,contractAddress:n,wagmiHooks:o,onResult:u})),[i,e,s,n,o,u,f]),h=x.useMemo(()=>{const S=l!=null&&l.data?{value:l.data.value,formatted:l.data.formatted,decimals:l.data.decimals,symbol:l.data.symbol}:{value:BigInt(0),formatted:"0",decimals:18,symbol:"ETH"},N=i.map(F=>{const D=c[mn(F.tokenAddress)],b=D==null?void 0:D.balance,g=b==null?void 0:b.data;return{address:mn(F.tokenAddress),value:(g==null?void 0:g.value)||BigInt(0),formatted:(g==null?void 0:g.formatted)||"0",decimals:(g==null?void 0:g.decimals)||F.decimals}}).filter(F=>F.address),B=N.reduce((F,D)=>({...F,[D.address]:{balance:D}}),{});return{balanceList:N,baseTokenBalance:S,combinedData:B}},[l,c,i]),m=x.useCallback(async()=>h,[h]),w=x.useMemo(()=>{const S=(l==null?void 0:l.isLoading)||!1,N=Object.values(c).some(B=>{var F;return(F=B.balance)==null?void 0:F.isLoading});return S||N},[l==null?void 0:l.isLoading,c]),$=x.useCallback(()=>p(S=>S+1),[]);return{multicallRun:m,multicallRefresh:$,multicallResult:h,validErcTokens:i,isLoading:w,queryComponents:d}},k4=({address:e,currentActiveChain:t,selectedToken:n,accountType:r,platformBalance:o,isLoading:s,wagmiHooks:i,onChainChange:c,onDeposit:a})=>{const{t:u}=vt(),l=i.useAccount(),f=t.tokenList.find(_=>_.token===n||_.symbol===n),p=t.chainId,[d,h]=x.useState("");x.useEffect(()=>{h("")},[n,t.chainId]);const{multicallResult:m,queryComponents:w}=M4({account:e,chainId:t.chainId,contractAddress:(f==null?void 0:f.contractAddress)||(t==null?void 0:t.contractAddress),tokens:(t==null?void 0:t.tokenList)||[],wagmiHooks:i}),$=x.useMemo(()=>{var W;if(!f)return"0";if(!f.tokenAddress||f.tokenAddress.toLowerCase()==="0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee")return m.baseTokenBalance.formatted;const _=m.combinedData[f.tokenAddress];return((W=_==null?void 0:_.balance)==null?void 0:W.formatted)||"0"},[f,m]),E="0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9",S="0xceeed84620e5eb9ab1d6dfc316867d2cda332e41",N=x.useMemo(()=>{var _,W;return s5({chain:u5,transport:c5(t.rpcUrl||((_=window==null?void 0:window.ENV)==null?void 0:_.CHAIN_RPC_URL_42161)||((W=window==null?void 0:window.ENV)==null?void 0:W.CHAIN_RPC_URL_421614))})},[t.rpcUrl]),B="1000000000000",{formatted:F}=l5({client:N,tokenAddress:E,holder:S,decimals:6,fallbackFormatted:B,pollingInterval:12e3}),[D,b]=x.useState(!1),{approve:g,onApprove:v}=C4({account:e,accountChainId:l.chainId,targetChainId:+t.chainId,tokenInfo:f,amount:d,wagmiHooks:i}),C=x.useCallback(async()=>{if(!D)try{b(!0),await v()}catch(_){console.error("Approve failed:",_)}finally{b(!1)}},[D,v]),O=x.useMemo(()=>+l.chainId!=+t.chainId,[l.chainId,t.chainId]),I=x.useCallback(async()=>{c&&c(p)},[c,p]);x.useEffect(()=>{O&&I()},[O,I]);const{showLayerZeroTip:M,layerZeroTipKey:y}=x.useMemo(()=>{const _=+t.chainId==42161||+t.chainId==421614,W=(n==null?void 0:n.toUpperCase())==="USDT",K=new Ie(d||"0"),G=new Ie("200000");let H=!1,Z;if(_&&W&&d)if(K.gte(G))H=!0,Z="deposit.layerZeroDepositTipGte200k";else{const J=F;if(typeof J=="string"&&J.length>0){const me=new Ie(J);!me.isNaN()&&K.gte(me)&&(H=!0,Z="deposit.layerZeroDepositTipExceedPool")}}return{showLayerZeroTip:H,layerZeroTipKey:Z}},[t.chainId,n,d,F]),A=x.useCallback(()=>T4(+t.chainId,$||"0",n,r),[$,t==null?void 0:t.chainId,n,r]),T=x.useMemo(()=>r!=="spot"&&$4(+t.chainId,d,n),[r,t==null?void 0:t.chainId,d,n]),P=x.useMemo(()=>"deposit.maxDepositSplitTip",[]),L=N4({isNetworkMismatch:O,depositAmount:d,approved:g,currentTokenBalance:$,selectedToken:n,showLayerZeroTip:M,minDeposit:f!=null&&f.minDepositSize?parseFloat(f.minDepositSize):10}),j=_=>{const W=_.target.value,K=A(),G=fi(W,K);if(G.isValid)h(G.formattedValue),G.errorType;else return G.errorType==="exceed_balance",void 0},z=x.useCallback(async()=>{di(!0);try{a&&a({amount:d,chainId:p,tokenAddress:(f==null?void 0:f.tokenAddress)||"",tokenSymbol:n,accountType:r})}catch(_){console.error("Deposit error:",_),di(!1)}},[a,d,p,f==null?void 0:f.tokenAddress,r,n]);return k.jsxs(k.Fragment,{children:[w,k.jsxs("div",{className:"bg-fill-input-primary rounded-lg px-3 py-3 my-4",children:[k.jsxs("div",{className:"flex justify-between items-center h-[18px] mb-3",children:[k.jsx("input",{type:"text",placeholder:u("deposit.amount"),value:d,onChange:j,className:"flex-1 bg-transparent text-text-primary text-sm font-medium placeholder-text-tertiary placeholder:font-normal focus:outline-none border-none p-0 h-full"}),k.jsx("button",{onClick:()=>{const _=A();h(_)},className:"text-theme-normal text-xs font-medium cursor-pointer hover:opacity-80 transition-opacity h-full flex items-center",children:u("deposit.max")})]}),k.jsx("div",{className:"h-[1px] bg-line-divider-secondary mb-2"}),k.jsxs("div",{className:"flex justify-between items-center",children:[k.jsx(Qn,{content:u("deposit.availableDesc"),children:k.jsx("span",{className:"text-text-tertiary text-xs leading-[14px] border-b border-dashed border-line-divider-primary",children:u("deposit.available")})}),k.jsx("span",{className:"text-text-primary text-xs leading-[14px]",children:S4($||"0",d,n)})]})]}),!g&&E4(d||"0",0)&&k.jsxs("div",{className:"flex justify-center flex-col items-center",children:[k.jsx("h3",{className:"text-text-primary text-sm leading-4 font-medium",children:u("deposit.enableSystemProWithToken",{token:n,network:t==null?void 0:t.chain})}),k.jsx("p",{className:"text-text-secondary text-xs leading-3 mt-4",children:u("deposit.enableTokenDesc",{token:n,network:t==null?void 0:t.chain})}),k.jsx("button",{className:"w-[180px] h-8 bg-fill-btn-primary hover:bg-fill-btn-primary-hover text-text-on-sec-btn rounded-xl text-sm font-medium transition-colors my-4 disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center",onClick:C,disabled:D,children:D?k.jsx(Vo,{size:"xs",inline:!0}):u("deposit.enableWithToken",{token:n})})]}),M&&k.jsxs(k.Fragment,{children:[k.jsxs("div",{className:"flex mb-4",children:[k.jsx("div",{className:"w-5",children:k.jsx("img",{src:Wo,className:"w-4 h-4",alt:"Warning"})}),k.jsx("div",{className:"flex-1 text-xs text-functional-orange-1",children:u(y||"deposit.layerZeroDepositTip")})]}),k.jsx("div",{className:"my-2 ml-5 h-[1px] border-b border-dashed border-line-divider-secondary"})]}),T&&k.jsxs("div",{className:"flex mb-4",children:[k.jsx("div",{className:"w-5",children:k.jsx("img",{src:Wo,className:"w-4 h-4",alt:"Warning"})}),k.jsx("div",{className:"flex-1 text-xs text-functional-orange-1",children:u(P)})]}),T&&k.jsx("div",{className:"my-2 ml-5 h-[1px] border-b border-dashed border-line-divider-secondary"}),k.jsxs("div",{className:"flex mb-4",children:[k.jsx("div",{className:"w-5",children:!(T||M)&&k.jsx("img",{src:Wo,className:"w-4 h-4",alt:"Warning"})}),k.jsx("div",{className:"flex-1 text-xs text-functional-orange-1 whitespace-pre-line",children:u("deposit.noPrivateKeyWalletWarning")})]}),k.jsxs("div",{className:"border-t border-line-divider-secondary border-dashed py-4",children:[k.jsxs("div",{className:"flex justify-between items-center h-[18px] leading-4",children:[k.jsx("span",{className:"text-sm text-text-tertiary",children:u("deposit.arrivalTime")}),k.jsx(Qn,{content:k.jsxs("div",{className:"grid flex-grow max-w-[300px] min-w-[80px] rounded-2xl flex-col gap-[10px]",children:[k.jsx("p",{children:u("deposit.arrivaltimeTooltip1",{v:(t==null?void 0:t.blockTime)*t.txConfirm/60,v1:t==null?void 0:t.txConfirm})}),k.jsx("p",{children:u("deposit.arrivaltimeTooltip2")})]}),placement:"top",children:k.jsx("span",{className:"text-text-primary font-medium text-right border-b-[2px] border-dashed border-line-divider-primary decoration-dashed text-sm",children:u("deposit.arrivalEstimated",{v:(t==null?void 0:t.blockTime)*t.txConfirm/60})})})]}),k.jsxs("div",{className:"flex justify-between items-center h-[18px] leading-4 mt-2",children:[k.jsx("span",{className:"text-sm text-text-tertiary",children:u("deposit.equity")}),k.jsx("span",{className:"text-sm text-text-primary font-medium",children:d?k.jsxs("span",{className:"flex items-center gap-1",children:[Mt(o),k.jsx("span",{className:"text-sm font-edgex-harmony text-functional-green-1 leading-[18px] font-medium",children:"→"}),Mt((parseFloat(o)+parseFloat(d)).toString())," ",n]}):`${Mt(o)} ${n}`})]})]}),k.jsxs("button",{className:`w-full h-[38px] text-sm rounded-xl font-medium transition-colors flex items-center justify-center gap-2 ${L.disabled||s?"bg-text-disabled text-text-secondary cursor-not-allowed":"bg-fill-btn-primary text-text-on-sec-btn"}`,onClick:z,disabled:L.disabled||s,children:[(s||O)&&k.jsx(Vo,{size:"xs"}),L.text]})]})},hm=e=>e.toLocaleUpperCase()===xn?xn:sc,Eu=e=>hm(e.wallet)===xn,B4=e=>hm(e.wallet)===sc,mm=({isOpen:e,isLoading:t=!1,onClose:n,currentActiveAccount:r,chains:o,spotChains:s=[],defaultChainId:i,defaultSymbol:c,defaultAccountType:a="perpetual",balances:u,wagmiHooks:l,onDeposit:f,onCopy:p,onChainChange:d,onTokenChange:h})=>{const{t:m}=vt(),[w,$]=x.useState(a),E=x.useCallback(T=>T==="spot"&&s&&s.length>0?s:o,[o,s]),S=E(a),[N,B]=x.useState(()=>{var T;return!S||S.length===0?1:i||((T=S[0])==null?void 0:T.chainId)||1}),F=x.useMemo(()=>E(w),[w,E]),D=F.find(T=>T.chainId===N)||F[0],[b,g]=x.useState(()=>{var _;if(!S||S.length===0)return"";const T=i||((_=S[0])==null?void 0:_.chainId),P=S.find(W=>W.chainId===T)||S[0],L=((P==null?void 0:P.tokenList)||[]).length>0?P:S.find(W=>(W.tokenList||[]).length>0),j=(L==null?void 0:L.tokenList)||[];if(c&&j.length>0){const W=c.toUpperCase(),K=j.find(G=>(G.token||G.symbol||"").toUpperCase()===W);if(K)return K.token||K.symbol||""}const z=j[0];return(z==null?void 0:z.token)||(z==null?void 0:z.symbol)||""}),v=x.useCallback(T=>{B(T),d==null||d(T)},[d]),C=x.useCallback(T=>{g(T),h==null||h(T)},[h]),O=x.useMemo(()=>{const T=(b||"").toLowerCase();if(!T)return"0";const P=w==="spot"?u==null?void 0:u.spot:u==null?void 0:u.perpetual,L=P==null?void 0:P[T];return typeof L=="string"&&L.length>0?L:"0"},[u,w,b]),[I,M]=x.useState(!1),y=T=>{T.target===T.currentTarget?M(!0):M(!1)},A=T=>{I&&T.target===T.currentTarget&&n(),M(!1)};return e?je.createPortal(k.jsx("div",{className:"fixed top-0 left-0 right-0 bottom-0 w-screen h-screen",style:{zIndex:98},children:k.jsx("div",{className:"fixed top-0 left-0 right-0 bottom-0 z-[99] flex items-center justify-center",style:{background:"rgba(0, 0, 0, 0.6)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)"},onMouseDown:y,onMouseUp:A,"aria-hidden":"true",children:k.jsxs("div",{className:"relative w-[420px] max-h-[85vh] bg-fill-page-secondary overflow-auto rounded-lg p-6 shadow-xl border-[2px] border-solid border-line-divider-secondary",onClick:T=>{T.stopPropagation()},children:[k.jsxs("div",{className:"flex items-center justify-between mb-4",children:[k.jsx("h2",{className:"text-lg font-semibold text-white",children:m("deposit.title")}),k.jsx("button",{className:"text-gray-400 hover:text-gray-200 transition-colors",onClick:n,"aria-label":"Close",children:k.jsx(l0,{className:"h-4 w-4"})})]}),k.jsx(Sh,{selectedAccount:w,onAccountChange:T=>{var H,Z;const P=T||"perpetual";$(P);const L=E(P);if(!L||L.length===0)return;const j=L.find(J=>J.chainId===N),z=j?j.chainId:L[0].chainId;B(z),d==null||d(z);const _=L.find(J=>J.chainId===z),W=(_==null?void 0:_.tokenList)||[],G=W.some(J=>(J.symbol||J.token)===b)?b:((H=W[0])==null?void 0:H.symbol)||((Z=W[0])==null?void 0:Z.token)||"";G&&(g(G),h==null||h(G))},className:"w-full"}),k.jsx(Eh,{currentActiveChain:D,chainList:F,onChainChange:v,curSelectToken:b,onTokenChange:C,walletType:Eu(r)?xn:sc,accountType:w}),Eu(r)&&k.jsx(x4,{address:r.smartWalletAddress,currentActiveChain:D,selectedToken:b,accountType:w,onDeposit:f,onCopy:p,onClose:n}),B4(r)&&k.jsx(k4,{address:r.ethAddress,currentActiveChain:D,selectedToken:b,accountType:w,platformBalance:O,isLoading:t,wagmiHooks:l,onChainChange:v,onDeposit:f,onClose:n})]})})}),document.body):null},L4=e=>{if(e==null||e==="")return 2;const t=String(e),n=t.indexOf(".");if(n===-1)return 0;const r=t.length-n-1;return r>0?r:2},F4=({withdrawAmount:e,curSelectToken:t,tokenInfo:n,currentActiveChain:r,platformBalance:o="0",fee:s="0.00",walletType:i="evm",receiverAddress:c="",accountType:a="perpetual",onWithdrawAmountChange:u,onReceiverAddressChange:l,onAmountChanged:f,showPoolBalanceInsufficientTip:p=!1})=>{const{t:d}=vt(),h=x.useMemo(()=>{const F=L4(n==null?void 0:n.showStepSize);if(a==="spot"||!ln(r==null?void 0:r.chainId)){const D=new Ie(e||"0").minus(s||"0").decimalPlaces(F,Ie.ROUND_DOWN);return D.isNegative()?"0.00":D.toString()}return e||"0"},[e,s,r==null?void 0:r.chainId,a,n==null?void 0:n.showStepSize]),m=x.useMemo(()=>o||"0",[o]),w=x.useMemo(()=>{const F=(n==null?void 0:n.feeRate)||(n==null?void 0:n.withdrawFeeRate)||(r==null?void 0:r.feeRate)||0;try{return new Ie(F||0).times(100).toString()}catch{return"0"}},[n==null?void 0:n.feeRate,n==null?void 0:n.withdrawFeeRate,r==null?void 0:r.feeRate]),$=x.useMemo(()=>w==="0",[w]),E=x.useMemo(()=>{const F=(t||"").toUpperCase();return F==="USDT"||F==="USDC"},[t]),S=F=>{const D=F.target.value,g=fi(D,m||"0");if(g.isValid)u(g.formattedValue),g.errorType;else return g.errorType==="exceed_balance",void 0;f==null||f(g.formattedValue)},N=()=>{const F=m||"0",b=fi(F,F).formattedValue;u(b),f==null||f(b)},B=()=>{const F=parseFloat(o||"0"),D=parseFloat(e||"0");if(D>0){const b=F-D,g=Mt(Math.max(0,b).toString());return k.jsxs("span",{className:"flex items-center gap-1",children:[Mt(o||"0"),k.jsx("span",{className:"text-sm font-edgex-harmony text-functional-green-1 leading-[18px] font-medium",children:"→"}),g," ",t]})}return`${Mt(o||"0")} ${t}`};return k.jsxs(k.Fragment,{children:[k.jsxs("div",{className:"bg-fill-input-primary rounded-lg px-3 py-3 my-4",children:[k.jsxs("div",{className:"flex justify-between items-center h-[18px] mb-3",children:[k.jsx("input",{type:"text",placeholder:d("deposit.amount"),value:e,onChange:S,className:"flex-1 bg-transparent text-text-primary text-sm font-medium placeholder-text-tertiary placeholder:font-normal focus:outline-none border-none p-0 h-full"}),k.jsx("button",{onClick:N,className:"text-theme-normal text-xs font-medium cursor-pointer hover:opacity-80 transition-opacity h-full flex items-center",children:d("deposit.max")})]}),k.jsx("div",{className:"h-[1px] bg-line-divider-secondary mb-2"}),k.jsxs("div",{className:"flex justify-between items-center",children:[k.jsx(Qn,{content:d("withdraw.availableDesc"),children:k.jsx("span",{className:"text-text-tertiary text-xs leading-[14px] border-b border-dashed border-line-divider-primary",children:d("deposit.available")})}),k.jsx("span",{className:"text-text-primary text-xs leading-[14px]",children:B()})]})]}),i==="mpc"&&(a==="spot"||!ln(r==null?void 0:r.chainId))?k.jsx("div",{className:"bg-fill-input-primary rounded-lg my-4 h-9 flex items-center px-3",children:k.jsx("input",{type:"text",placeholder:d("withdraw.receiverAddress"),value:c,onChange:F=>l==null?void 0:l(F.target.value),className:"flex-1 bg-transparent text-text-primary text-sm font-medium placeholder-text-tertiary placeholder:font-normal focus:outline-none border-none p-0 h-full"})}):null,k.jsx("div",{className:"bg-fill-page-secondary rounded-lg mb-4",children:ln(r==null?void 0:r.chainId)?k.jsxs(k.Fragment,{children:[k.jsx("p",{className:"text-text-tertiary text-xs leading-[18px]",children:d("withdraw.noticeDesc")}),k.jsx("a",{className:"block text-xs leading-[18px] mt-1 text-theme-normal",href:"https://edgex-1.gitbook.io/edgeX-documentation/getting-started/deposits-and-withdrawals/withdrawals",rel:"noreferrer",target:"_blank",children:d("withdraw.commonWithdraw")})]}):k.jsx("p",{className:"text-text-tertiary text-xs leading-[18px]",children:d("withdraw.crossChainTips")})}),p&&k.jsxs("div",{className:"flex mb-4",children:[k.jsx("div",{className:"w-5",children:k.jsx("img",{src:Wo,className:"w-4 h-4",alt:"Warning"})}),k.jsx("div",{className:"flex-1 text-xs text-functional-orange-1",children:d("withdraw.poolBalanceInsufficientTip")})]}),k.jsxs("div",{className:"py-4 border-t border-line-divider-secondary border-dashed",children:[k.jsxs("div",{className:"flex items-center justify-between h-[18px] leading-[18px]",children:[k.jsx(Qn,{content:k.jsxs("div",{children:[k.jsx("div",{children:d("withdraw.speedNote")}),k.jsxs("div",{className:"flex gap-1 items-center mt-1",children:[k.jsx(Uo,{selectedLevel:It.FAST,maxLevel:3}),k.jsx("span",{children:d("withdraw.speedNoteSpeed1")})]}),k.jsxs("div",{className:"flex gap-1 items-center mt-1",children:[k.jsx(Uo,{selectedLevel:It.Medium,maxLevel:3}),k.jsx("span",{children:d("withdraw.speedNoteSpeed2")})]}),k.jsxs("div",{className:"flex gap-1 items-center mt-1",children:[k.jsx(Uo,{selectedLevel:It.SLOW,maxLevel:3}),k.jsx("span",{children:d("withdraw.speedNoteSpeed3")})]})]}),children:k.jsx("span",{className:"text-text-tertiary text-sm leading-4 border-b border-dashed border-line-divider-primary",children:d("withdraw.speed")})}),k.jsx("div",{className:"flex items-center",children:k.jsx(Uo,{selectedLevel:ln(r==null?void 0:r.chainId)?It.SLOW:It.FAST,maxLevel:3})})]}),(a==="spot"||!ln(r==null?void 0:r.chainId))&&k.jsxs("div",{className:"flex items-center justify-between mt-2 h-[18px]",children:[$||!E?k.jsx("span",{className:"text-text-tertiary text-sm leading-4",children:$?d("withdraw.fee"):`${d("withdraw.fee")}/${d("withdraw.feeRate")}`}):k.jsx(Qn,{className:"w-[320px] font-normal flex items-center justify-center",content:k.jsx("span",{className:"flex items-center justify-center text-center",children:d("withdraw.feeCalculationTip")}),children:k.jsx("span",{className:"text-text-tertiary text-sm leading-4 border-b border-dashed border-line-divider-primary",children:`${d("withdraw.fee")}/${d("withdraw.feeRate")}`})}),k.jsxs("span",{className:"text-text-primary text-sm leading-4 font-medium",children:[s," ",t,!$&&` / ${w}%`]})]}),k.jsxs("div",{className:"flex items-center justify-between mt-2 h-[18px]",children:[k.jsx("span",{className:"text-text-tertiary text-sm leading-4",children:d(ln(r==null?void 0:r.chainId)?"withdraw.withdrawlAmount":"withdraw.amountToReceive")}),k.jsxs("span",{className:"text-text-primary text-sm leading-4 font-medium",children:[Mt(h)," ",t]})]})]})]})},D4=[];let Ke=null;const bm=x.forwardRef((e,t)=>{const[n,r]=x.useState(!1),[o,s]=x.useState(!1),[i,c]=x.useState({chains:[],currentActiveAccount:{wallet:"EVM",ethAddress:"",accountId:"",smartWalletAddress:""}}),a=x.useCallback(h=>{c(h||{chains:[],currentActiveAccount:{wallet:"EVM",ethAddress:"",accountId:"",smartWalletAddress:""}}),r(!0)},[]),u=x.useCallback(h=>{c(m=>({...m,...h}))},[]),l=x.useCallback(()=>{r(!1),s(!1),i.onClose&&i.onClose()},[i.onClose]),f=x.useCallback(h=>{s(h)},[]),p=x.useCallback(()=>n,[n]),d=x.useCallback(()=>o,[o]);return x.useImperativeHandle(t,()=>({openWithdraw:a,closeWithdraw:l,updateWithdrawOptions:u,setWithdrawLoading:f,isOpen:p,isLoading:d}),[a,l,u,f,p,d]),x.useEffect(()=>(Ke={openWithdraw:a,closeWithdraw:l,updateWithdrawOptions:u,setWithdrawLoading:f,isOpen:p,isLoading:d},()=>{Ke=null}),[a,l,u,f,p,d]),n?k.jsx(xm,{isOpen:n,isLoading:o,onClose:l,config:i.config||{symbol:"USDT"},currentActiveAccount:i.currentActiveAccount,chains:i.chains||D4,spotChains:i.spotChains,balances:i.balances,defaultChainId:i.defaultChainId,defaultSymbol:i.defaultSymbol,defaultAmount:i.defaultAmount,defaultAccountType:i.defaultAccountType,currentEquity:i.currentEquity??5e3,platformBalance:i.platformBalance||"0",fee:i.fee,wagmiHooks:i.wagmiHooks,onWithdraw:i.onWithdraw,onAccountChange:i.onAccountChange,onChainChange:i.onChainChange,onTokenChange:i.onTokenChange,onAmountChanged:i.onAmountChanged}):null});bm.displayName="WithdrawManager";const gm=e=>{if(!Ke){console.error("WithdrawManager not initialized. Make sure to render <WithdrawManager /> in your app.");return}Ke.openWithdraw(e||{chains:[],currentActiveAccount:{wallet:"EVM",ethAddress:"",accountId:"",smartWalletAddress:""}})},ym=()=>{if(!Ke){console.error("WithdrawManager not initialized. Make sure to render <WithdrawManager /> in your app.");return}Ke.closeWithdraw()},wm=e=>{if(!Ke){console.error("WithdrawManager not initialized. Make sure to render <WithdrawManager /> in your app.");return}Ke.updateWithdrawOptions(e)},pi=e=>{if(!Ke){console.error("WithdrawManager not initialized. Make sure to render <WithdrawManager /> in your app.");return}Ke.setWithdrawLoading(e)},R4=()=>Ke?Ke.isOpen():!1,vm=()=>Ke?Ke.isLoading():!1,j4=()=>({openWithdraw:gm,closeWithdraw:ym,updateWithdrawOptions:wm,setWithdrawLoading:pi,isOpen:R4,isLoading:vm}),_4=({walletType:e,chains:t,spotChains:n=[],defaultChainId:r,defaultSymbol:o,defaultAmount:s="",defaultAccountType:i="perpetual",currentEquity:c,platformBalance:a="0",balances:u,fee:l="0.00",isLoading:f=!1,onWithdraw:p,onClose:d,onChainChange:h,onTokenChange:m,onAmountChanged:w,onAccountChange:$})=>{var H;const{t:E}=vt(),[S,N]=x.useState(i),B=x.useCallback(Z=>Z==="spot"&&n&&n.length>0?n:t,[t,n]),F=x.useMemo(()=>B(S),[S,B]),D=x.useMemo(()=>{if(!F||F.length===0)return{chainId:1,tokenSymbol:""};const Z=de=>{const se=de||[];if(!se.length)return"";const ee="USDC".toUpperCase(),Nn=se.find(gt=>(gt.token||gt.symbol||"").toUpperCase()===ee)||se[0];return Nn.token||Nn.symbol||""};if(o){const de=o==null?void 0:o.toUpperCase();for(const se of F){const pe=se.tokenList||[];let ee;if(de&&(ee=pe.find(Se=>(Se.token||Se.symbol||"").toUpperCase()===de)),ee){const Se=ee.token||ee.symbol||o||"";return{chainId:se.chainId,tokenSymbol:Se}}}}if(r){const de=F.find(ee=>ee.chainId===r)||F[0],se=de.tokenList||[],pe=Z(se);return{chainId:de.chainId,tokenSymbol:pe}}const J="USDC",oe=de=>Array.isArray(de.tokenList)&&de.tokenList.some(se=>(se.token||se.symbol||"").toUpperCase()===J),me=F.find(oe)||F[0];if(!me)return{chainId:1,tokenSymbol:""};const ge=Z(me.tokenList);return{chainId:me.chainId,tokenSymbol:ge}},[F,r,o]),[b,g]=x.useState(()=>D.chainId),[v,C]=x.useState(()=>D.tokenSymbol),[O,I]=x.useState(s),[M,y]=x.useState(""),A=x.useCallback(Z=>{g(Z),h==null||h(Z)},[h]),T=x.useCallback(Z=>{C(Z),m==null||m(Z)},[m]),P=x.useRef(!0),L=x.useRef(v),j=x.useRef(b);x.useEffect(()=>{if(P.current){P.current=!1,L.current=v,j.current=b;return}(L.current!==v||j.current!==b)&&(I(""),L.current=v,j.current=b)},[v,b]);const z=F&&F.length>0?F.find(Z=>Z.chainId===b)||F[0]:null,_=(H=z==null?void 0:z.tokenList)==null?void 0:H.find(Z=>Z.token===v),W=x.useMemo(()=>{const Z=new Ie(O||"0"),J=new Ie(l||"0"),oe=ln(b);return _!=null&&_.minWithdrawSize&&Z.lt(_.minWithdrawSize)?{text:E("withdraw.minWithdrawParsed",{amount:_.minWithdrawSize,token:_.symbol||_.token}),disabled:!0}:!O||Z.isZero()||!oe&&Z.isLessThan(J)?{text:E("withdraw.confirmWithdraw"),disabled:!0}:e==="mpc"&&(!oe||S==="spot")&&!M.trim()?{text:E("withdraw.invalidReceiverAddress"),disabled:!0}:{text:E("withdraw.confirmWithdraw"),disabled:!1}},[E,b,O,e,M,l,S,_]),K=x.useMemo(()=>{const Z=(v||"").toLowerCase();if(!Z)return a||"0";const J=S==="spot"?u==null?void 0:u.spot:u==null?void 0:u.perpetual,oe=J==null?void 0:J[Z];return typeof oe=="string"&&oe.length>0?oe:a||"0"},[u,S,v,a]),G=x.useCallback(async()=>{pi(!0);try{if(p){const J={amount:new Ie(O||"0").toString(),chainId:b,tokenAddress:(_==null?void 0:_.tokenAddress)||"",coinId:(_==null?void 0:_.coinId)||"",tokenSymbol:v,accountType:S,selectedToken:_};e==="mpc"&&(!ln(b)||S==="spot")&&(J.receiverAddress=M),p(J)}}catch{pi(!1)}},[p,S,_,O,b,v,e,M]);return!F||F.length===0?k.jsx("div",{className:"text-center py-8",children:k.jsx("p",{className:"text-gray-400",children:"No chains available"})}):z?k.jsxs(k.Fragment,{children:[k.jsx(Sh,{selectedAccount:S,onAccountChange:Z=>{var Se,Nn;const J=Z||"perpetual";N(J),$==null||$(J);const oe=B(J);if(!oe||oe.length===0)return;const me=oe.find(gt=>gt.chainId===b),ge=me?me.chainId:oe[0].chainId;g(ge),h==null||h(ge);const de=oe.find(gt=>gt.chainId===ge),se=(de==null?void 0:de.tokenList)||[],ee=se.some(gt=>(gt.symbol||gt.token)===v)?v:((Se=se[0])==null?void 0:Se.symbol)||((Nn=se[0])==null?void 0:Nn.token)||"";ee&&(C(ee),m==null||m(ee))},className:"w-full"}),k.jsx(Eh,{currentActiveChain:z,chainList:F,onChainChange:A,curSelectToken:v,onTokenChange:T,walletType:"EVM",txType:"withdraw"}),k.jsx(F4,{withdrawAmount:O,curSelectToken:v,tokenInfo:_,curSelectTokenData:{balance:_==null?void 0:_.balance,allowance:_==null?void 0:_.allowance},currentActiveChain:z,currentEquity:c||0,decimals:(_==null?void 0:_.decimals)||6,platformBalance:K,fee:l,walletType:e,accountType:S,receiverAddress:M,onWithdrawAmountChange:I,onReceiverAddressChange:y,onAmountChanged:w}),k.jsxs("button",{className:`w-full h-[38px] text-sm rounded-xl font-medium transition-colors flex items-center justify-center gap-2 ${W.disabled||f?"bg-text-disabled text-text-secondary cursor-not-allowed":"bg-fill-btn-primary text-text-on-sec-btn"}`,onClick:G,disabled:W.disabled||f,children:[f&&k.jsx(Vo,{size:"xs"}),W.text]})]}):k.jsx("div",{className:"text-center py-8",children:k.jsx("p",{className:"text-gray-400",children:"Loading..."})})},xm=({isOpen:e,isLoading:t=!1,defaultAccountType:n="perpetual",onClose:r,config:o,currentActiveAccount:s,chains:i,spotChains:c=[],defaultChainId:a,defaultSymbol:u,defaultAmount:l="",currentEquity:f=5e3,platformBalance:p="0",balances:d,fee:h,wagmiHooks:m,onWithdraw:w,onChainChange:$,onTokenChange:E,onAmountChanged:S,onAccountChange:N})=>{const{t:B}=vt(),[F,D]=x.useState(!1),b=v=>{v.target===v.currentTarget?D(!0):D(!1)},g=v=>{F&&v.target===v.currentTarget&&r(),D(!1)};return e?je.createPortal(k.jsx("div",{className:"fixed top-0 left-0 right-0 bottom-0 w-screen h-screen",style:{zIndex:98},children:k.jsx("div",{className:"fixed top-0 left-0 right-0 bottom-0 z-[99] flex items-center justify-center",style:{background:"rgba(0, 0, 0, 0.6)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)"},onMouseDown:b,onMouseUp:g,"aria-hidden":"true",children:k.jsxs("div",{className:"relative w-[420px] max-h-[85vh] bg-fill-page-secondary overflow-auto rounded-lg p-6 shadow-xl",onClick:v=>{v.stopPropagation()},children:[k.jsxs("div",{className:"flex items-center justify-between mb-4",children:[k.jsx("h2",{className:"text-lg font-semibold text-white",children:B("withdraw.withdraw")}),k.jsx("button",{className:"text-gray-400 hover:text-gray-200 transition-colors",onClick:r,"aria-label":"Close",children:k.jsx(l0,{className:"h-4 w-4"})})]}),k.jsx(_4,{chains:i,spotChains:c,walletType:Eu(s)?"mpc":"evm",defaultChainId:a,defaultSymbol:u,defaultAmount:l,defaultAccountType:n,currentEquity:f,platformBalance:p,balances:d,fee:h,isLoading:t,wagmiHooks:m,onWithdraw:w,onClose:r,onChainChange:$,onTokenChange:E,onAmountChanged:S,onAccountChange:N})]})})}),document.body):null};re.ChromeLoader=Vo,re.ComponentProvider=Gm,re.DEFAULT_LOCALE=qo,re.Deposit=mm,re.DepositManager=um,re.LOCALE_NAMES=Hm,re.LoadingSpinner=Vo,re.SUPPORTED_LOCALES=bi,re.Tooltip=Qn,re.Withdraw=xm,re.WithdrawManager=bm,re.closeDeposit=fm,re.closeWithdraw=ym,re.formatThousands=Zm,re.isDepositLoading=pm,re.isWithdrawLoading=vm,re.openDeposit=lm,re.openWithdraw=gm,re.setDepositLoading=di,re.setWithdrawLoading=pi,re.updateDepositOptions=dm,re.updateWithdrawOptions=wm,re.useComponentConfig=Lu,re.useDeposit=f5,re.useDepositManager=O4,re.useTranslation=vt,re.useWithdraw=d5,re.useWithdrawManager=j4,Object.defineProperty(re,Symbol.toStringTag,{value:"Module"})});
|
|
179
179
|
//# sourceMappingURL=index.umd.js.map
|