@edgex-web/components 0.1.0-beta.13 → 0.1.0-beta.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js
CHANGED
|
@@ -100,5 +100,5 @@ React keys must be passed directly to JSX without using spread:
|
|
|
100
100
|
* @license qrcode.react
|
|
101
101
|
* Copyright (c) Paul O'Shannessy
|
|
102
102
|
* SPDX-License-Identifier: ISC
|
|
103
|
-
*/var Uc={L:dt.QrCode.Ecc.LOW,M:dt.QrCode.Ecc.MEDIUM,Q:dt.QrCode.Ecc.QUARTILE,H:dt.QrCode.Ecc.HIGH},Ei=128,Ci="L",Si="#FFFFFF",$i="#000000",Oi=!1,Ti=1,zc=4,Hc=0,Gc=.1;function Ni(e,t=0){const n=[];return e.forEach(function(r,o){let s=null;r.forEach(function(c,a){if(!c&&s!==null){n.push(`M${s+t} ${o+t}h${a-s}v1H${s+t}z`),s=null;return}if(a===r.length-1){if(!c)return;s===null?n.push(`M${a+t},${o+t} h1v1H${a+t}z`):n.push(`M${s+t},${o+t} h${a+1-s}v1H${s+t}z`);return}c&&s===null&&(s=a)})}),n.join("")}function Ai(e,t){return e.slice().map((n,r)=>r<t.y||r>=t.y+t.h?n:n.map((o,s)=>s<t.x||s>=t.x+t.w?o:!1))}function Yc(e,t,n,r){if(r==null)return null;const o=e.length+n*2,s=Math.floor(t*Gc),c=o/t,a=(r.width||s)*c,i=(r.height||s)*c,l=r.x==null?e.length/2-a/2:r.x*c,u=r.y==null?e.length/2-i/2:r.y*c,p=r.opacity==null?1:r.opacity;let m=null;if(r.excavate){let h=Math.floor(l),g=Math.floor(u),b=Math.ceil(a+l-h),w=Math.ceil(i+u-g);m={x:h,y:g,w:b,h:w}}const d=r.crossOrigin;return{x:l,y:u,h:i,w:a,excavation:m,opacity:p,crossOrigin:d}}function Kc(e,t){return t!=null?Math.max(Math.floor(t),0):e?zc:Hc}function Mi({value:e,level:t,minVersion:n,includeMargin:r,marginSize:o,imageSettings:s,size:c,boostLevel:a}){let i=f.useMemo(()=>{const h=(Array.isArray(e)?e:[e]).reduce((g,b)=>(g.push(...dt.QrSegment.makeSegments(b)),g),[]);return dt.QrCode.encodeSegments(h,Uc[t],n,void 0,void 0,a)},[e,t,n,a]);const{cells:l,margin:u,numCells:p,calculatedImageSettings:m}=f.useMemo(()=>{let d=i.getModules();const h=Kc(r,o),g=d.length+h*2,b=Yc(d,c,h,s);return{cells:d,margin:h,numCells:g,calculatedImageSettings:b}},[i,c,s,r,o]);return{qrcode:i,margin:u,cells:l,numCells:p,calculatedImageSettings:m}}var Qc=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),qc=f.forwardRef(function(t,n){const r=t,{value:o,size:s=Ei,level:c=Ci,bgColor:a=Si,fgColor:i=$i,includeMargin:l=Oi,minVersion:u=Ti,boostLevel:p,marginSize:m,imageSettings:d}=r,g=nr(r,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:b}=g,w=nr(g,["style"]),E=d==null?void 0:d.src,x=f.useRef(null),C=f.useRef(null),S=f.useCallback(I=>{x.current=I,typeof n=="function"?n(I):n&&(n.current=I)},[n]),[M,F]=f.useState(!1),{margin:W,cells:V,numCells:A,calculatedImageSettings:O}=Mi({value:o,level:c,minVersion:u,boostLevel:p,includeMargin:l,marginSize:m,imageSettings:d,size:s});f.useEffect(()=>{if(x.current!=null){const I=x.current,B=I.getContext("2d");if(!B)return;let z=V;const U=C.current,T=O!=null&&U!==null&&U.complete&&U.naturalHeight!==0&&U.naturalWidth!==0;T&&O.excavation!=null&&(z=Ai(V,O.excavation));const _=window.devicePixelRatio||1;I.height=I.width=s*_;const N=s/A*_;B.scale(N,N),B.fillStyle=a,B.fillRect(0,0,A,A),B.fillStyle=i,Qc?B.fill(new Path2D(Ni(z,W))):V.forEach(function(H,G){H.forEach(function(q,pe){q&&B.fillRect(pe+W,G+W,1,1)})}),O&&(B.globalAlpha=O.opacity),T&&B.drawImage(U,O.x+W,O.y+W,O.w,O.h)}}),f.useEffect(()=>{F(!1)},[E]);const j=tr({height:s,width:s},b);let D=null;return E!=null&&(D=f.createElement("img",{src:E,key:E,style:{display:"none"},onLoad:()=>{F(!0)},ref:C,crossOrigin:O==null?void 0:O.crossOrigin})),f.createElement(f.Fragment,null,f.createElement("canvas",tr({style:j,height:s,width:s,ref:S,role:"img"},w)),D)});qc.displayName="QRCodeCanvas";var Pi=f.forwardRef(function(t,n){const r=t,{value:o,size:s=Ei,level:c=Ci,bgColor:a=Si,fgColor:i=$i,includeMargin:l=Oi,minVersion:u=Ti,boostLevel:p,title:m,marginSize:d,imageSettings:h}=r,g=nr(r,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:b,cells:w,numCells:E,calculatedImageSettings:x}=Mi({value:o,level:c,minVersion:u,boostLevel:p,includeMargin:l,marginSize:d,imageSettings:h,size:s});let C=w,S=null;h!=null&&x!=null&&(x.excavation!=null&&(C=Ai(w,x.excavation)),S=f.createElement("image",{href:h.src,height:x.h,width:x.w,x:x.x+b,y:x.y+b,preserveAspectRatio:"none",opacity:x.opacity,crossOrigin:x.crossOrigin}));const M=Ni(C,b);return f.createElement("svg",tr({height:s,width:s,viewBox:`0 0 ${E} ${E}`,ref:n,role:"img"},g),!!m&&f.createElement("title",null,m),f.createElement("path",{fill:a,d:`M0,0 h${E}v${E}H0z`,shapeRendering:"crispEdges"}),f.createElement("path",{fill:i,d:M,shapeRendering:"crispEdges"}),S)});Pi.displayName="QRCodeSVG";const Xc=(e,t)=>Number(e)>Number(t),Ne=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"},rr=(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 i=o[0]+"."+o[1].substring(0,6);return rr(i,t)}const s=parseFloat(e),c=parseFloat(t);if(!isNaN(s)&&!isNaN(c)&&s>c)return{isValid:!0,formattedValue:Ne(t),errorType:"auto_adjusted_to_max"};let a=e;return!isNaN(s)&&!e.endsWith(".")&&e.includes(".")&&(a=e.replace(/\.?0+$/,""),a.includes(".")||(a=a)),{isValid:!0,formattedValue:a}},Jc=(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)},Li={ETHEREUM:1,SEPOLIA:11155111},Zc=[Li.ETHEREUM,Li.SEPOLIA],ef=e=>{if(e.chainId!==void 0){const t=typeof e.chainId=="string"?parseInt(e.chainId,10):e.chainId;return!Zc.includes(t)}return!0},tf=[{chainId:1,chain:"Ethereum",chainIconUrl:"https://static.edgex.exchange/icons/logo/ethereum.svg",allowDeposit:!0,blockTime:12,txConfirm:12},{chainId:42161,chain:"Arbitrum",chainIconUrl:"https://static.edgex.exchange/icons/logo/arbitrum.svg",allowDeposit:!0,blockTime:1,txConfirm:1}],or={wallet:"mpc",ethAddress:"0x1234567890123456789012345678901234567890",accountId:"123",l2Key:"0x123"},ir={address:"0x1234567890123456789012345678901234567890"},sr={multiChain:{minDeposit:10}},nf=({walletAdapter:e,curSelectToken:t,currentActiveChain:n,metadata:r})=>{var s;const o=f.useMemo(()=>ef(n||{}),[n]);return y.jsxs(y.Fragment,{children:[y.jsx("div",{className:"flex justify-center mt-4 mb-3",children:y.jsx("div",{className:"bg-white rounded-lg",children:y.jsx(Pi,{value:(e==null?void 0:e.getDisplayAddress())||"",size:120,level:"L",bgColor:"#ffffff",fgColor:"#000000",marginSize:0})})}),y.jsxs("div",{className:"flex items-center justify-between bg-fill-input-primary rounded-lg py-2 px-3 mb-3",children:[y.jsx("span",{className:"flex-1 text-text-primary text-sm font-medium break-all mr-3",children:e==null?void 0:e.getDisplayAddress()}),y.jsx("div",{onClick:()=>{navigator.clipboard.writeText((e==null?void 0:e.getDisplayAddress())||"")},style:{cursor:"pointer"},children:y.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[y.jsx("rect",{x:"2.08496",y:"4.02295",width:"9.89893",height:"9.89893",rx:"2",stroke:"#F9F9F9"}),y.jsx("path",{d:"M5.85547 2.07861H11.415C12.7957 2.07861 13.915 3.1979 13.915 4.57861V10.0786",stroke:"#F9F9F9",strokeLinecap:"round"})]})})]}),y.jsxs("div",{className:"flex items-start",children:[y.jsx("div",{className:"w-5",children:y.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:y.jsx("path",{d:"M8.00016 14.6667C11.6821 14.6667 14.6668 11.6819 14.6668 8C14.6668 4.31809 11.6821 1.33333 8.00016 1.33333C4.31826 1.33333 1.3335 4.31809 1.3335 8C1.3335 11.6819 4.31826 14.6667 8.00016 14.6667Z",fill:"#FF8F34",stroke:"#FF8F34",strokeWidth:"1.33333",strokeLinejoin:"round"})})}),y.jsxs("div",{className:"flex-1",children:[y.jsxs("p",{className:"text-xs text-functional-orange-1",children:["Only ",t," (",n==null?void 0:n.chain,") is supported for deposits to this address."]}),y.jsx("div",{className:"pt-2 h-[1px] border-b border-dashed border-line-divider-secondary"})]})]}),o&&y.jsxs(y.Fragment,{children:[y.jsx("div",{className:"flex items-start pl-5 pt-2 text-functional-orange-1 text-xs",children:"When the deposit amount exceeds 250,000, there may be a delay in arrival. It is recommended to use the Ethereum network for deposits."}),y.jsx("div",{className:"pt-4 h-[1px] border-b border-dashed border-line-divider-secondary"})]}),y.jsxs("div",{className:"text-sm",children:[y.jsxs("div",{className:"flex justify-between items-center h-[18px] mt-4",children:[y.jsx("span",{className:"text-text-tertiary",children:"Arrival Time"}),y.jsxs("span",{className:"text-text-primary font-medium text-right underline decoration-dotted underline-offset-1",children:["≈"," ",Math.ceil(((n==null?void 0:n.blockTime)||12)*((n==null?void 0:n.txConfirm)||12)/60)," ","minutes"]})]}),y.jsxs("div",{className:"flex justify-between items-center h-[18px] mt-2",children:[y.jsx("span",{className:"text-text-tertiary",children:"Minimum Deposit Amount"}),y.jsxs("span",{className:"text-text-primary font-medium text-right",children:[((s=r==null?void 0:r.multiChain)==null?void 0:s.minDeposit)||10," ",t]})]}),y.jsxs("div",{className:"flex justify-between items-center h-[18px] mt-2",children:[y.jsx("span",{className:"text-text-tertiary",children:"Maximum Deposit Amount"}),y.jsxs("span",{className:"text-text-primary font-medium text-right",children:["250,000 ",t]})]})]})]})},rf=({chains:e,defaultChainId:t,defaultTokenAddress:n,walletAdapter:r,metadata:o,onDeposit:s,onClose:c})=>{var d;const[a,i]=f.useState(()=>{var h;return!e||e.length===0?1:t||((h=e[0])==null?void 0:h.chainId)||1}),[l,u]=f.useState(()=>{var w;if(!e||e.length===0)return"";const h=t||((w=e[0])==null?void 0:w.chainId),g=e.find(E=>E.chainId===h);if(!g||!g.tokenList||g.tokenList.length===0)return"";const b=g.tokenList.find(E=>E.tokenAddress===n)||g.tokenList[0];return(b==null?void 0:b.token)||""}),p=e&&e.length>0?e.find(h=>h.chainId===a)||e[0]:null,m=(d=p==null?void 0:p.tokenList)==null?void 0:d.find(h=>h.token===l);return!e||e.length===0?y.jsx("div",{className:"text-center py-8",children:y.jsx("p",{className:"text-gray-400",children:"No chains available"})}):p?y.jsxs(y.Fragment,{children:[y.jsx(er,{currentActiveChain:p,chainList:e,onChainChange:i,curSelectToken:l,onTokenChange:u,walletType:"mpc"}),y.jsx(nf,{walletAdapter:r,curSelectToken:l,currentActiveChain:p,metadata:o}),y.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:()=>{s&&s({amount:"",chainId:a,tokenAddress:(m==null?void 0:m.tokenAddress)||"",tokenSymbol:l}),c()},children:"Deposit"})]}):y.jsx("div",{className:"text-center py-8",children:y.jsx("p",{className:"text-gray-400",children:"Loading..."})})},of=({depositAmount:e,curSelectToken:t,curSelectTokenData:n,approved:r,currentActiveChain:o,currentEquity:s,amount:c,decimals:a,tokenBalance:i,platformBalance:l="0",onDepositAmountChange:u,onApprove:p})=>{const m=h=>{const g=h.target.value,w=rr(g,i||"0");if(w.isValid)u(w.formattedValue),w.errorType;else return w.errorType==="exceed_balance",void 0},d=()=>{const h=parseFloat(i||"0"),g=parseFloat(e||"0");if(g>0){const b=h-g,w=Ne(Math.max(0,b).toString());return`${Ne(i||"0")} → ${w} ${t}`}return`${Ne(i||"0")} ${t}`};return y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"bg-fill-input-primary rounded-lg px-3 py-3 my-4",children:[y.jsxs("div",{className:"flex justify-between items-center h-[18px] mb-3",children:[y.jsx("input",{type:"text",placeholder:"Amount",value:e,onChange:m,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"}),y.jsx("button",{onClick:()=>{u(i||"0")},className:"text-theme-normal text-xs font-medium cursor-pointer hover:opacity-80 transition-opacity h-full flex items-center",children:"MAX"})]}),y.jsx("div",{className:"h-[1px] bg-line-divider-secondary mb-2"}),y.jsxs("div",{className:"flex justify-between items-center",children:[y.jsx("span",{className:"text-text-tertiary text-xs leading-[14px]",children:"Available"}),y.jsx("span",{className:"text-text-primary text-xs leading-[14px]",children:d()})]})]}),!r&&Xc(e||"0",0)&&y.jsxs("div",{className:"flex justify-center flex-col items-center",children:[y.jsxs("h3",{className:"text-text-primary text-sm leading-4 font-medium",children:["Enable ",t," on ",o==null?void 0:o.chain]}),y.jsxs("p",{className:"text-text-secondary text-xs leading-3 mt-4",children:["You must enable ",t," first before you can deposit on"," ",o==null?void 0:o.chain,"."]}),y.jsxs("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",onClick:p,children:["Enable ",t]})]}),y.jsx("div",{className:"border-t border-line-divider-secondary border-dashed py-4",children:y.jsxs("div",{className:"flex justify-between items-center",children:[y.jsx("span",{className:"text-sm leading-[18px] text-text-tertiary",children:"总资产"}),y.jsx("span",{className:"text-sm leading-[18px] text-text-primary font-medium",children:e?`${Ne(l)} → ${Ne((parseFloat(l)+parseFloat(e)).toString())} ${t}`:`${Ne(l)} ${t}`})]})})]})},sf=({token:e,account:t,chainId:n,contractAddress:r,wagmiHooks:o,onResult:s})=>{var i,l;const c=(i=o==null?void 0:o.useBalance)==null?void 0:i.call(o,{address:t,token:e.tokenAddress,chainId:n,query:{enabled:!!t&&!!n&&!!e.tokenAddress&&!!(o!=null&&o.useBalance)}}),a=(l=o==null?void 0:o.useReadContract)==null?void 0:l.call(o,{address:e.tokenAddress,abi:[{name:"allowance",type:"function",stateMutability:"view",inputs:[{name:"owner",type:"address"},{name:"spender",type:"address"}],outputs:[{name:"",type:"uint256"}]}],functionName:"allowance",args:[t,r],chainId:n,query:{enabled:!!t&&!!n&&!!e.tokenAddress&&!!r&&!!(o!=null&&o.useReadContract)}});return f.useEffect(()=>{s(e.tokenAddress,{balance:c,allowance:a})},[c,a,e.tokenAddress,s]),null},Fi=({account:e,chainId:t,contractAddress:n,tokens:r=[],wagmiHooks:o})=>{var h;const s=f.useMemo(()=>r.filter(g=>g.tokenAddress&&g.tokenAddress!=="0x0000000000000000000000000000000000000000"),[r]),[c,a]=f.useState({}),i=f.useCallback((g,b)=>{a(w=>({...w,[g]:b}))},[]),l=(h=o==null?void 0:o.useBalance)==null?void 0:h.call(o,{address:e,chainId:t,query:{enabled:!!e&&!!t&&!!(o!=null&&o.useBalance)}}),u=f.useMemo(()=>s.map(g=>f.createElement(sf,{key:g.tokenAddress,token:g,account:e,chainId:t,contractAddress:n,wagmiHooks:o,onResult:i})),[s,e,t,n,o,i]),p=f.useMemo(()=>{if(!(o!=null&&o.useBalance))return{balanceList:[],allowanceList:[],baseTokenBalance:{value:BigInt(0),formatted:"0",decimals:18,symbol:"ETH"},combinedData:{}};const g=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"},b=s.map(x=>{const C=c[x.tokenAddress],S=C==null?void 0:C.balance,M=S==null?void 0:S.data;return{address:x.tokenAddress,value:(M==null?void 0:M.value)||BigInt(0),formatted:(M==null?void 0:M.formatted)||"0",decimals:(M==null?void 0:M.decimals)||x.decimals}}).filter(x=>x.address),w=s.map(x=>{const C=c[x.tokenAddress],S=C==null?void 0:C.allowance,M=S==null?void 0:S.data,F=BigInt(M?M.toString():0);return{address:x.tokenAddress,value:F,formatted:(F/BigInt(10)**BigInt(x.decimals)).toString(),decimals:x.decimals}}).filter(x=>x.address),E=b.reduce((x,C)=>{const S=w.find(M=>M.address===C.address);return{...x,[C.address]:{balance:C,allowance:S||{address:C.address,value:BigInt(0),formatted:"0",decimals:C.decimals}}}},{});return{balanceList:b,allowanceList:w,baseTokenBalance:g,combinedData:E}},[l,c,s,o==null?void 0:o.useBalance]),m=f.useCallback(async()=>p,[p]),d=f.useMemo(()=>{const g=(l==null?void 0:l.isLoading)||!1,b=Object.values(c).some(w=>{var E,x;return((E=w.balance)==null?void 0:E.isLoading)||((x=w.allowance)==null?void 0:x.isLoading)});return g||b},[l==null?void 0:l.isLoading,c]);return{multicallRun:m,multicallResult:p,validErcTokens:s,isLoading:d,queryComponents:u}},lf=({chains:e,defaultChainId:t,defaultTokenAddress:n,defaultAmount:r="",walletAdapter:o,metadata:s,currentEquity:c,platformBalance:a="0",wagmiHooks:i,approved:l,onApproved:u,onDeposit:p,onClose:m,onChainChange:d,onTokenChange:h})=>{var _;const[g,b]=f.useState(()=>{var N;return!e||e.length===0?1:t||((N=e[0])==null?void 0:N.chainId)||1}),[w,E]=f.useState(()=>{var q;if(!e||e.length===0)return"";const N=t||((q=e[0])==null?void 0:q.chainId),H=e.find(pe=>pe.chainId===N);if(!H||!H.tokenList||H.tokenList.length===0)return"";const G=H.tokenList.find(pe=>pe.tokenAddress===n)||H.tokenList[0];return(G==null?void 0:G.token)||""}),[x,C]=f.useState(r),S=f.useCallback(N=>{b(N),d==null||d(N)},[d]),M=f.useCallback(N=>{E(N),h==null||h(N)},[h]),F=f.useRef(!0),W=f.useRef(w),V=f.useRef(g);f.useEffect(()=>{if(F.current){F.current=!1,W.current=w,V.current=g;return}(W.current!==w||V.current!==g)&&(C(""),W.current=w,V.current=g)},[w,g]);const A=e&&e.length>0?e.find(N=>N.chainId===g)||e[0]:null,O=(_=A==null?void 0:A.tokenList)==null?void 0:_.find(N=>N.token===w),j=o==null?void 0:o.getDisplayAddress(),{multicallResult:D,queryComponents:I}=Fi({account:j,chainId:g,contractAddress:void 0,tokens:(A==null?void 0:A.tokenList)||[],wagmiHooks:i}),B=f.useMemo(()=>{var H;if(!O)return;if(!O.tokenAddress||O.tokenAddress.toLowerCase()==="0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee")return D.baseTokenBalance.formatted;const N=D.combinedData[O.tokenAddress];return((H=N==null?void 0:N.balance)==null?void 0:H.formatted)||"0"},[O,D]),z=l??!1,U=f.useMemo(()=>{const N=parseFloat(x||"0"),H=10,G=B||"0",q=Jc(x,G,z);return!x||N===0?{text:"Confirm Deposit",disabled:!0}:z?N>parseFloat(G)?{text:"Insufficient Balance",disabled:!0}:N<H?{text:`Min Deposit ${H} ${w}`,disabled:!0}:{text:"Confirm Deposit",disabled:!q}:{text:"Confirm Deposit",disabled:!0}},[x,w,B,z]),T=f.useCallback(async()=>{p&&p({amount:x,chainId:g,tokenAddress:(O==null?void 0:O.tokenAddress)||"",tokenSymbol:w})},[p,x,g,O==null?void 0:O.tokenAddress,w]);return!(i!=null&&i.useBalance)||!(i!=null&&i.useReadContract)||!(i!=null&&i.useAccount)?y.jsxs("div",{className:"p-6 text-center",children:[y.jsx("p",{className:"text-red-500",children:"缺少必要的 wagmi hooks"}),y.jsx("p",{className:"text-sm text-gray-500 mt-2",children:"请确保传入了 useBalance, useReadContract, useAccount"})]}):!e||e.length===0?y.jsx("div",{className:"text-center py-8",children:y.jsx("p",{className:"text-gray-400",children:"No chains available"})}):A?y.jsxs(y.Fragment,{children:[I,y.jsx(er,{currentActiveChain:A,chainList:e,onChainChange:S,curSelectToken:w,onTokenChange:M,walletType:"evm"}),y.jsx(of,{depositAmount:x,curSelectToken:w,curSelectTokenData:{balance:O==null?void 0:O.balance,allowance:O==null?void 0:O.allowance},approved:z,currentActiveChain:A,currentEquity:c||0,amount:x,decimals:(O==null?void 0:O.decimals)||6,tokenBalance:B,platformBalance:a,onDepositAmountChange:C,onApprove:async()=>{u&&await u()}}),y.jsx("button",{className:`w-full h-[38px] text-sm rounded-xl font-medium transition-colors ${U.disabled?"bg-text-disabled text-text-secondary cursor-not-allowed":"bg-fill-btn-primary text-text-on-sec-btn"}`,onClick:T,disabled:U.disabled,children:U.text})]}):y.jsx("div",{className:"text-center py-8",children:y.jsx("p",{className:"text-gray-400",children:"Loading..."})})},Ii=({isOpen:e,onClose:t,config:n,currentActiveAccount:r=or,smartWallet:o=ir,chains:s,defaultChainId:c,defaultTokenAddress:a,defaultAmount:i="",metadata:l=sr,currentEquity:u=5e3,platformBalance:p="0",wagmiHooks:m,approved:d,onApproved:h,onDeposit:g,onChainChange:b,onTokenChange:w})=>{const E=f.useMemo(()=>{var C;return r?yr(r,o,!1,(C=s[0])==null?void 0:C.chainId,"0","0"):null},[r,o,s]),x=(E==null?void 0:E.getWalletType())==="mpc";return e?de.createPortal(y.jsx("div",{className:"fixed top-0 left-0 right-0 bottom-0 z-[999] w-screen h-screen",style:{zIndex:999},children:y.jsx("div",{className:"fixed top-0 left-0 right-0 bottom-0 z-50 flex items-center justify-center",style:{background:"rgba(0, 0, 0, 0.6)"},onClick:()=>{t()},"aria-hidden":"true",children:y.jsxs("div",{className:"relative w-[420px] max-h-[85vh] bg-fill-page-secondary overflow-auto rounded-lg p-6 shadow-xl",onClick:C=>{C.stopPropagation()},children:[y.jsxs("div",{className:"flex items-center justify-between mb-4",children:[y.jsx("h2",{className:"text-lg font-semibold text-white",children:"Deposit"}),y.jsx("button",{className:"text-gray-400 hover:text-gray-200 transition-colors",onClick:t,"aria-label":"Close",children:y.jsx(br,{className:"h-4 w-4"})})]}),x?y.jsx(rf,{chains:s,defaultChainId:c,defaultTokenAddress:a,defaultAmount:i,walletAdapter:E,metadata:l,currentEquity:u,onDeposit:g,onClose:t}):y.jsx(lf,{chains:s,defaultChainId:c,defaultTokenAddress:a,defaultAmount:i,walletAdapter:E,metadata:l,currentEquity:u,platformBalance:p,wagmiHooks:m,approved:d,onApproved:h,onDeposit:g,onClose:t,onChainChange:b,onTokenChange:w})]})})}),document.body):null};let je=null;const af={symbol:"USDT"},ji=f.forwardRef((e,t)=>{const[n,r]=f.useState(!1),[o,s]=f.useState({chains:[]}),c=f.useCallback(u=>{s(u),r(!0)},[]),a=f.useCallback(u=>{s(p=>({...p,...u}))},[]),i=f.useCallback(()=>{r(!1),o.onClose&&o.onClose()},[o.onClose]),l=f.useCallback(()=>n,[n]);return f.useImperativeHandle(t,()=>({openDeposit:c,closeDeposit:i,updateDepositOptions:a,isOpen:l}),[c,i,a,l]),f.useEffect(()=>(je={openDeposit:c,closeDeposit:i,updateDepositOptions:a,isOpen:l},()=>{je=null}),[c,i,a,l]),y.jsx(Ii,{isOpen:n,onClose:i,config:o.config||af,currentActiveAccount:o.currentActiveAccount||or,smartWallet:o.smartWallet||ir,chains:o.chains||tf,defaultChainId:o.defaultChainId,defaultTokenAddress:o.defaultTokenAddress,defaultAmount:o.defaultAmount,metadata:o.metadata||sr,currentEquity:o.currentEquity??5e3,platformBalance:o.platformBalance||"0",wagmiHooks:o.wagmiHooks,approved:o.approved,onApproved:o.onApproved,onDeposit:o.onDeposit,onChainChange:o.onChainChange,onTokenChange:o.onTokenChange})});ji.displayName="DepositManager";const Di=e=>{if(!je){console.error("DepositManager not initialized. Make sure to render <DepositManager /> in your app.");return}je.openDeposit(e||{chains:[]})},_i=()=>{if(!je){console.error("DepositManager not initialized. Make sure to render <DepositManager /> in your app.");return}je.closeDeposit()},ki=e=>{je&&je.updateDepositOptions(e)},uf=()=>je?je.isOpen():!1,cf=()=>({openDeposit:Di,closeDeposit:_i,updateDepositOptions:ki,isOpen:uf});f.createContext(null);const ff=Object.values({MAINNET:1,SEPOLIA:11155111}),lr=e=>ff.includes(e),df=({withdrawAmount:e,curSelectToken:t,currentActiveChain:n,platformBalance:r="0",walletType:o="evm",receiverAddress:s="",onWithdrawAmountChange:c,onReceiverAddressChange:a})=>{const i=p=>{const m=p.target.value,h=rr(m,r||"0");if(h.isValid)c(h.formattedValue),h.errorType;else return h.errorType==="exceed_balance",void 0},l=()=>{c(r)},u=()=>{const p=parseFloat(r||"0"),m=parseFloat(e||"0");if(m>0){const d=p-m,h=Ne(Math.max(0,d).toString());return`${Ne(r||"0")} → ${h} ${t}`}return`${Ne(r||"0")} ${t}`};return y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"bg-fill-input-primary rounded-lg px-3 py-3 my-4",children:[y.jsxs("div",{className:"flex justify-between items-center h-[18px] mb-3",children:[y.jsx("input",{type:"text",placeholder:"Amount",value:e,onChange:i,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"}),y.jsx("button",{onClick:l,className:"text-theme-normal text-xs font-medium cursor-pointer hover:opacity-80 transition-opacity h-full flex items-center",children:"MAX"})]}),y.jsx("div",{className:"h-[1px] bg-line-divider-secondary mb-2"}),y.jsxs("div",{className:"flex justify-between items-center",children:[y.jsx("span",{className:"text-text-tertiary text-xs leading-[14px]",children:"Available"}),y.jsx("span",{className:"text-text-primary text-xs leading-[14px]",children:u()})]})]}),o==="mpc"&&!lr(n==null?void 0:n.chainId)&&y.jsx("div",{className:"bg-fill-input-primary rounded-lg my-4 h-9 flex items-center px-3",children:y.jsx("input",{type:"text",placeholder:"Receiver Address",value:s,onChange:p=>a==null?void 0:a(p.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"})}),y.jsx("div",{className:"bg-fill-page-secondary rounded-lg mb-4",children:y.jsx("p",{className:"text-text-tertiary text-xs leading-[18px]",children:"Cross-chain withdrawals require verification at L2 (via ZK proofs) and the withdrawal process may take up to 2 hours. Sufficient funds in the corresponding chain's asset pool are required to process cross-chain withdrawals. Gas fees will also be incurred. edgeX will charge a fee to cover this."})}),y.jsxs("div",{className:"py-4 border-t border-line-divider-secondary border-dashed",children:[y.jsxs("div",{className:"flex items-center justify-between",children:[y.jsx("span",{className:"text-text-tertiary text-xs",children:"Speed"}),y.jsxs("div",{className:"flex items-center space-x-1",children:[y.jsx("span",{className:"text-theme-normal",children:"⚡"}),y.jsx("span",{className:"text-theme-normal",children:"⚡"}),y.jsx("span",{className:"text-theme-normal",children:"⚡"})]})]}),y.jsxs("div",{className:"flex items-center justify-between mt-2 h-[18px]",children:[y.jsx("span",{className:"text-text-tertiary text-sm leading-4",children:"Amount to receive"}),y.jsxs("span",{className:"text-text-primary text-sm leading-4 font-medium",children:[Ne(e)," ",t]})]})]})]})},pf=({chains:e,defaultChainId:t,defaultTokenAddress:n,defaultAmount:r="",walletAdapter:o,metadata:s,currentEquity:c,platformBalance:a="0",wagmiHooks:i,onWithdraw:l,onClose:u,onChainChange:p,onTokenChange:m})=>{var _;const[d,h]=f.useState(()=>{var N;return!e||e.length===0?1:t||((N=e[0])==null?void 0:N.chainId)||1}),[g,b]=f.useState(()=>{var q;if(!e||e.length===0)return"";const N=t||((q=e[0])==null?void 0:q.chainId),H=e.find(pe=>pe.chainId===N);if(!H||!H.tokenList||H.tokenList.length===0)return"";const G=H.tokenList.find(pe=>pe.tokenAddress===n)||H.tokenList[0];return(G==null?void 0:G.token)||""}),[w,E]=f.useState(r),[x,C]=f.useState(""),S=(o==null?void 0:o.getWalletType())||"evm",M=f.useCallback(N=>{h(N),p==null||p(N)},[p]),F=f.useCallback(N=>{b(N),m==null||m(N)},[m]),W=f.useRef(!0),V=f.useRef(g),A=f.useRef(d);f.useEffect(()=>{if(W.current){W.current=!1,V.current=g,A.current=d;return}(V.current!==g||A.current!==d)&&(E(""),V.current=g,A.current=d)},[g,d]);const O=e&&e.length>0?e.find(N=>N.chainId===d)||e[0]:null,j=(_=O==null?void 0:O.tokenList)==null?void 0:_.find(N=>N.token===g),D=o==null?void 0:o.getDisplayAddress(),{multicallResult:I,queryComponents:B}=Fi({account:D,chainId:d,contractAddress:void 0,tokens:(O==null?void 0:O.tokenList)||[],wagmiHooks:i}),z=f.useMemo(()=>{var H;if(!j)return;if(!j.tokenAddress||j.tokenAddress.toLowerCase()==="0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee")return I.baseTokenBalance.formatted;const N=I.combinedData[j.tokenAddress];return((H=N==null?void 0:N.balance)==null?void 0:H.formatted)||"0"},[j,I]),U=f.useMemo(()=>{const N=parseFloat(w||"0"),H=1,G=parseFloat(a||"0");return!w||N===0?{text:"Confirm Withdraw",disabled:!0}:S==="mpc"&&!lr(d)&&!x.trim()?{text:"Enter Receiver Address",disabled:!0}:N>G?{text:"Insufficient Balance",disabled:!0}:N<H?{text:`Min Withdraw ${H} ${g}`,disabled:!0}:{text:"Confirm Withdraw",disabled:!1}},[w,g,a,S,x]),T=f.useCallback(async()=>{if(l){const N={amount:w,chainId:d,tokenAddress:(j==null?void 0:j.tokenAddress)||"",tokenSymbol:g};S==="mpc"&&!lr(d)&&(N.receiverAddress=x),l(N)}},[l,w,d,j==null?void 0:j.tokenAddress,g,S,x]);return!(i!=null&&i.useBalance)||!(i!=null&&i.useReadContract)||!(i!=null&&i.useAccount)?y.jsxs("div",{className:"p-6 text-center",children:[y.jsx("p",{className:"text-red-500",children:"缺少必要的 wagmi hooks"}),y.jsx("p",{className:"text-sm text-gray-500 mt-2",children:"请确保传入了 useBalance, useReadContract, useAccount"})]}):!e||e.length===0?y.jsx("div",{className:"text-center py-8",children:y.jsx("p",{className:"text-gray-400",children:"No chains available"})}):O?y.jsxs(y.Fragment,{children:[B,y.jsx(er,{currentActiveChain:O,chainList:e,onChainChange:M,curSelectToken:g,onTokenChange:F,walletType:"evm"}),y.jsx(df,{withdrawAmount:w,curSelectToken:g,curSelectTokenData:{balance:j==null?void 0:j.balance,allowance:j==null?void 0:j.allowance},currentActiveChain:O,currentEquity:c||0,amount:w,decimals:(j==null?void 0:j.decimals)||6,tokenBalance:z,platformBalance:a,walletType:S,receiverAddress:x,onWithdrawAmountChange:E,onReceiverAddressChange:C}),y.jsx("button",{className:`w-full h-[38px] text-sm rounded-xl font-medium transition-colors ${U.disabled?"bg-text-disabled text-text-secondary cursor-not-allowed":"bg-fill-btn-primary text-text-on-sec-btn"}`,onClick:T,disabled:U.disabled,children:U.text})]}):y.jsx("div",{className:"text-center py-8",children:y.jsx("p",{className:"text-gray-400",children:"Loading..."})})},Ri=({isOpen:e,onClose:t,config:n,currentActiveAccount:r=or,smartWallet:o=ir,chains:s,defaultChainId:c,defaultTokenAddress:a,defaultAmount:i="",metadata:l=sr,currentEquity:u=5e3,platformBalance:p="0",wagmiHooks:m,onWithdraw:d,onChainChange:h,onTokenChange:g})=>{const b=f.useMemo(()=>{var w;return r?yr(r,o,!1,(w=s[0])==null?void 0:w.chainId,"0","0"):null},[r,o,s]);return e?de.createPortal(y.jsx("div",{className:"fixed top-0 left-0 right-0 bottom-0 w-screen h-screen",style:{zIndex:49},children:y.jsx("div",{className:"fixed top-0 left-0 right-0 bottom-0 z-49 flex items-center justify-center",style:{background:"rgba(0, 0, 0, 0.6)"},onClick:()=>{t()},"aria-hidden":"true",children:y.jsxs("div",{className:"relative w-[420px] max-h-[85vh] bg-fill-page-secondary overflow-auto rounded-lg p-6 shadow-xl",onClick:w=>{w.stopPropagation()},children:[y.jsxs("div",{className:"flex items-center justify-between mb-4",children:[y.jsx("h2",{className:"text-lg font-semibold text-white",children:"Withdraw"}),y.jsx("button",{className:"text-gray-400 hover:text-gray-200 transition-colors",onClick:t,"aria-label":"Close",children:y.jsx(br,{className:"h-4 w-4"})})]}),y.jsx(pf,{chains:s,defaultChainId:c,defaultTokenAddress:a,defaultAmount:i,walletAdapter:b,metadata:l,currentEquity:u,platformBalance:p,wagmiHooks:m,onWithdraw:d,onClose:t,onChainChange:h,onTokenChange:g})]})})}),document.body):null},mf=[],hf={};let De=null;const Wi=f.forwardRef((e,t)=>{const[n,r]=f.useState(!1),[o,s]=f.useState({chains:[]}),c=f.useCallback(u=>{s(u||{chains:[]}),r(!0)},[]),a=f.useCallback(u=>{s(p=>({...p,...u}))},[]),i=f.useCallback(()=>{r(!1),o.onClose&&o.onClose()},[o.onClose]),l=f.useCallback(()=>n,[n]);return f.useImperativeHandle(t,()=>({openWithdraw:c,closeWithdraw:i,updateWithdrawOptions:a,isOpen:l}),[c,i,a,l]),f.useEffect(()=>(De={openWithdraw:c,closeWithdraw:i,updateWithdrawOptions:a,isOpen:l},()=>{De=null}),[c,i,a,l]),y.jsx(Ri,{isOpen:n,onClose:i,config:o.config||{symbol:"USDT"},currentActiveAccount:o.currentActiveAccount,smartWallet:o.smartWallet,chains:o.chains||mf,defaultChainId:o.defaultChainId,defaultTokenAddress:o.defaultTokenAddress,defaultAmount:o.defaultAmount,metadata:o.metadata||hf,currentEquity:o.currentEquity??5e3,platformBalance:o.platformBalance||"0",wagmiHooks:o.wagmiHooks,onWithdraw:o.onWithdraw,onChainChange:o.onChainChange,onTokenChange:o.onTokenChange})});Wi.displayName="WithdrawManager";const Bi=e=>{if(!De){console.error("WithdrawManager not initialized. Make sure to render <WithdrawManager /> in your app.");return}De.openWithdraw(e||{chains:[]})},Vi=()=>{if(!De){console.error("WithdrawManager not initialized. Make sure to render <WithdrawManager /> in your app.");return}De.closeWithdraw()},Ui=e=>{if(!De){console.error("WithdrawManager not initialized. Make sure to render <WithdrawManager /> in your app.");return}De.updateWithdrawOptions(e)},gf=()=>De?De.isOpen():!1,vf=()=>({openWithdraw:Bi,closeWithdraw:Vi,updateWithdrawOptions:Ui,isOpen:gf});Z.ComponentProvider=us,Z.Deposit=Ii,Z.DepositManager=ji,Z.Withdraw=Ri,Z.WithdrawManager=Wi,Z.closeDeposit=_i,Z.closeWithdraw=Vi,Z.openDeposit=Di,Z.openWithdraw=Bi,Z.updateDepositOptions=ki,Z.updateWithdrawOptions=Ui,Z.useDeposit=cs,Z.useDepositManager=cf,Z.useWithdraw=fs,Z.useWithdrawManager=vf,Object.defineProperty(Z,Symbol.toStringTag,{value:"Module"})});
|
|
103
|
+
*/var Uc={L:dt.QrCode.Ecc.LOW,M:dt.QrCode.Ecc.MEDIUM,Q:dt.QrCode.Ecc.QUARTILE,H:dt.QrCode.Ecc.HIGH},Ei=128,Ci="L",Si="#FFFFFF",$i="#000000",Oi=!1,Ti=1,zc=4,Hc=0,Gc=.1;function Ni(e,t=0){const n=[];return e.forEach(function(r,o){let s=null;r.forEach(function(c,a){if(!c&&s!==null){n.push(`M${s+t} ${o+t}h${a-s}v1H${s+t}z`),s=null;return}if(a===r.length-1){if(!c)return;s===null?n.push(`M${a+t},${o+t} h1v1H${a+t}z`):n.push(`M${s+t},${o+t} h${a+1-s}v1H${s+t}z`);return}c&&s===null&&(s=a)})}),n.join("")}function Ai(e,t){return e.slice().map((n,r)=>r<t.y||r>=t.y+t.h?n:n.map((o,s)=>s<t.x||s>=t.x+t.w?o:!1))}function Yc(e,t,n,r){if(r==null)return null;const o=e.length+n*2,s=Math.floor(t*Gc),c=o/t,a=(r.width||s)*c,i=(r.height||s)*c,l=r.x==null?e.length/2-a/2:r.x*c,u=r.y==null?e.length/2-i/2:r.y*c,p=r.opacity==null?1:r.opacity;let m=null;if(r.excavate){let h=Math.floor(l),g=Math.floor(u),b=Math.ceil(a+l-h),w=Math.ceil(i+u-g);m={x:h,y:g,w:b,h:w}}const d=r.crossOrigin;return{x:l,y:u,h:i,w:a,excavation:m,opacity:p,crossOrigin:d}}function Kc(e,t){return t!=null?Math.max(Math.floor(t),0):e?zc:Hc}function Mi({value:e,level:t,minVersion:n,includeMargin:r,marginSize:o,imageSettings:s,size:c,boostLevel:a}){let i=f.useMemo(()=>{const h=(Array.isArray(e)?e:[e]).reduce((g,b)=>(g.push(...dt.QrSegment.makeSegments(b)),g),[]);return dt.QrCode.encodeSegments(h,Uc[t],n,void 0,void 0,a)},[e,t,n,a]);const{cells:l,margin:u,numCells:p,calculatedImageSettings:m}=f.useMemo(()=>{let d=i.getModules();const h=Kc(r,o),g=d.length+h*2,b=Yc(d,c,h,s);return{cells:d,margin:h,numCells:g,calculatedImageSettings:b}},[i,c,s,r,o]);return{qrcode:i,margin:u,cells:l,numCells:p,calculatedImageSettings:m}}var Qc=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),qc=f.forwardRef(function(t,n){const r=t,{value:o,size:s=Ei,level:c=Ci,bgColor:a=Si,fgColor:i=$i,includeMargin:l=Oi,minVersion:u=Ti,boostLevel:p,marginSize:m,imageSettings:d}=r,g=nr(r,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:b}=g,w=nr(g,["style"]),E=d==null?void 0:d.src,x=f.useRef(null),C=f.useRef(null),S=f.useCallback(I=>{x.current=I,typeof n=="function"?n(I):n&&(n.current=I)},[n]),[M,F]=f.useState(!1),{margin:W,cells:V,numCells:A,calculatedImageSettings:O}=Mi({value:o,level:c,minVersion:u,boostLevel:p,includeMargin:l,marginSize:m,imageSettings:d,size:s});f.useEffect(()=>{if(x.current!=null){const I=x.current,B=I.getContext("2d");if(!B)return;let z=V;const U=C.current,T=O!=null&&U!==null&&U.complete&&U.naturalHeight!==0&&U.naturalWidth!==0;T&&O.excavation!=null&&(z=Ai(V,O.excavation));const _=window.devicePixelRatio||1;I.height=I.width=s*_;const N=s/A*_;B.scale(N,N),B.fillStyle=a,B.fillRect(0,0,A,A),B.fillStyle=i,Qc?B.fill(new Path2D(Ni(z,W))):V.forEach(function(H,G){H.forEach(function(q,pe){q&&B.fillRect(pe+W,G+W,1,1)})}),O&&(B.globalAlpha=O.opacity),T&&B.drawImage(U,O.x+W,O.y+W,O.w,O.h)}}),f.useEffect(()=>{F(!1)},[E]);const j=tr({height:s,width:s},b);let D=null;return E!=null&&(D=f.createElement("img",{src:E,key:E,style:{display:"none"},onLoad:()=>{F(!0)},ref:C,crossOrigin:O==null?void 0:O.crossOrigin})),f.createElement(f.Fragment,null,f.createElement("canvas",tr({style:j,height:s,width:s,ref:S,role:"img"},w)),D)});qc.displayName="QRCodeCanvas";var Pi=f.forwardRef(function(t,n){const r=t,{value:o,size:s=Ei,level:c=Ci,bgColor:a=Si,fgColor:i=$i,includeMargin:l=Oi,minVersion:u=Ti,boostLevel:p,title:m,marginSize:d,imageSettings:h}=r,g=nr(r,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:b,cells:w,numCells:E,calculatedImageSettings:x}=Mi({value:o,level:c,minVersion:u,boostLevel:p,includeMargin:l,marginSize:d,imageSettings:h,size:s});let C=w,S=null;h!=null&&x!=null&&(x.excavation!=null&&(C=Ai(w,x.excavation)),S=f.createElement("image",{href:h.src,height:x.h,width:x.w,x:x.x+b,y:x.y+b,preserveAspectRatio:"none",opacity:x.opacity,crossOrigin:x.crossOrigin}));const M=Ni(C,b);return f.createElement("svg",tr({height:s,width:s,viewBox:`0 0 ${E} ${E}`,ref:n,role:"img"},g),!!m&&f.createElement("title",null,m),f.createElement("path",{fill:a,d:`M0,0 h${E}v${E}H0z`,shapeRendering:"crispEdges"}),f.createElement("path",{fill:i,d:M,shapeRendering:"crispEdges"}),S)});Pi.displayName="QRCodeSVG";const Xc=(e,t)=>Number(e)>Number(t),Ne=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"},rr=(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 i=o[0]+"."+o[1].substring(0,6);return rr(i,t)}const s=parseFloat(e),c=parseFloat(t);if(!isNaN(s)&&!isNaN(c)&&s>c)return{isValid:!0,formattedValue:Ne(t),errorType:"auto_adjusted_to_max"};let a=e;return!isNaN(s)&&!e.endsWith(".")&&e.includes(".")&&(a=e.replace(/\.?0+$/,""),a.includes(".")||(a=a)),{isValid:!0,formattedValue:a}},Jc=(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)},Li={ETHEREUM:1,SEPOLIA:11155111},Zc=[Li.ETHEREUM,Li.SEPOLIA],ef=e=>{if(e.chainId!==void 0){const t=typeof e.chainId=="string"?parseInt(e.chainId,10):e.chainId;return!Zc.includes(t)}return!0},tf=[{chainId:1,chain:"Ethereum",chainIconUrl:"https://static.edgex.exchange/icons/logo/ethereum.svg",allowDeposit:!0,blockTime:12,txConfirm:12},{chainId:42161,chain:"Arbitrum",chainIconUrl:"https://static.edgex.exchange/icons/logo/arbitrum.svg",allowDeposit:!0,blockTime:1,txConfirm:1}],or={wallet:"mpc",ethAddress:"0x1234567890123456789012345678901234567890",accountId:"123",l2Key:"0x123"},ir={address:"0x1234567890123456789012345678901234567890"},sr={multiChain:{minDeposit:10}},nf=({walletAdapter:e,curSelectToken:t,currentActiveChain:n,metadata:r})=>{var s;const o=f.useMemo(()=>ef(n||{}),[n]);return y.jsxs(y.Fragment,{children:[y.jsx("div",{className:"flex justify-center mt-4 mb-3",children:y.jsx("div",{className:"bg-white rounded-lg",children:y.jsx(Pi,{value:(e==null?void 0:e.getDisplayAddress())||"",size:120,level:"L",bgColor:"#ffffff",fgColor:"#000000",marginSize:0})})}),y.jsxs("div",{className:"flex items-center justify-between bg-fill-input-primary rounded-lg py-2 px-3 mb-3",children:[y.jsx("span",{className:"flex-1 text-text-primary text-sm font-medium break-all mr-3",children:e==null?void 0:e.getDisplayAddress()}),y.jsx("div",{onClick:()=>{navigator.clipboard.writeText((e==null?void 0:e.getDisplayAddress())||"")},style:{cursor:"pointer"},children:y.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[y.jsx("rect",{x:"2.08496",y:"4.02295",width:"9.89893",height:"9.89893",rx:"2",stroke:"#F9F9F9"}),y.jsx("path",{d:"M5.85547 2.07861H11.415C12.7957 2.07861 13.915 3.1979 13.915 4.57861V10.0786",stroke:"#F9F9F9",strokeLinecap:"round"})]})})]}),y.jsxs("div",{className:"flex items-start",children:[y.jsx("div",{className:"w-5",children:y.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:y.jsx("path",{d:"M8.00016 14.6667C11.6821 14.6667 14.6668 11.6819 14.6668 8C14.6668 4.31809 11.6821 1.33333 8.00016 1.33333C4.31826 1.33333 1.3335 4.31809 1.3335 8C1.3335 11.6819 4.31826 14.6667 8.00016 14.6667Z",fill:"#FF8F34",stroke:"#FF8F34",strokeWidth:"1.33333",strokeLinejoin:"round"})})}),y.jsxs("div",{className:"flex-1",children:[y.jsxs("p",{className:"text-xs text-functional-orange-1",children:["Only ",t," (",n==null?void 0:n.chain,") is supported for deposits to this address."]}),y.jsx("div",{className:"pt-2 h-[1px] border-b border-dashed border-line-divider-secondary"})]})]}),o&&y.jsxs(y.Fragment,{children:[y.jsx("div",{className:"flex items-start pl-5 pt-2 text-functional-orange-1 text-xs",children:"When the deposit amount exceeds 250,000, there may be a delay in arrival. It is recommended to use the Ethereum network for deposits."}),y.jsx("div",{className:"pt-4 h-[1px] border-b border-dashed border-line-divider-secondary"})]}),y.jsxs("div",{className:"text-sm",children:[y.jsxs("div",{className:"flex justify-between items-center h-[18px] mt-4",children:[y.jsx("span",{className:"text-text-tertiary",children:"Arrival Time"}),y.jsxs("span",{className:"text-text-primary font-medium text-right underline decoration-dotted underline-offset-1",children:["≈"," ",Math.ceil(((n==null?void 0:n.blockTime)||12)*((n==null?void 0:n.txConfirm)||12)/60)," ","minutes"]})]}),y.jsxs("div",{className:"flex justify-between items-center h-[18px] mt-2",children:[y.jsx("span",{className:"text-text-tertiary",children:"Minimum Deposit Amount"}),y.jsxs("span",{className:"text-text-primary font-medium text-right",children:[((s=r==null?void 0:r.multiChain)==null?void 0:s.minDeposit)||10," ",t]})]}),y.jsxs("div",{className:"flex justify-between items-center h-[18px] mt-2",children:[y.jsx("span",{className:"text-text-tertiary",children:"Maximum Deposit Amount"}),y.jsxs("span",{className:"text-text-primary font-medium text-right",children:["250,000 ",t]})]})]})]})},rf=({chains:e,defaultChainId:t,defaultTokenAddress:n,walletAdapter:r,metadata:o,onDeposit:s,onClose:c})=>{var d;const[a,i]=f.useState(()=>{var h;return!e||e.length===0?1:t||((h=e[0])==null?void 0:h.chainId)||1}),[l,u]=f.useState(()=>{var w;if(!e||e.length===0)return"";const h=t||((w=e[0])==null?void 0:w.chainId),g=e.find(E=>E.chainId===h);if(!g||!g.tokenList||g.tokenList.length===0)return"";const b=g.tokenList.find(E=>E.tokenAddress===n)||g.tokenList[0];return(b==null?void 0:b.token)||""}),p=e&&e.length>0?e.find(h=>h.chainId===a)||e[0]:null,m=(d=p==null?void 0:p.tokenList)==null?void 0:d.find(h=>h.token===l);return!e||e.length===0?y.jsx("div",{className:"text-center py-8",children:y.jsx("p",{className:"text-gray-400",children:"No chains available"})}):p?y.jsxs(y.Fragment,{children:[y.jsx(er,{currentActiveChain:p,chainList:e,onChainChange:i,curSelectToken:l,onTokenChange:u,walletType:"mpc"}),y.jsx(nf,{walletAdapter:r,curSelectToken:l,currentActiveChain:p,metadata:o}),y.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:()=>{s&&s({amount:"",chainId:a,tokenAddress:(m==null?void 0:m.tokenAddress)||"",tokenSymbol:l}),c()},children:"Deposit"})]}):y.jsx("div",{className:"text-center py-8",children:y.jsx("p",{className:"text-gray-400",children:"Loading..."})})},of=({depositAmount:e,curSelectToken:t,curSelectTokenData:n,approved:r,currentActiveChain:o,currentEquity:s,amount:c,decimals:a,tokenBalance:i,platformBalance:l="0",onDepositAmountChange:u,onApprove:p})=>{const m=h=>{const g=h.target.value,w=rr(g,i||"0");if(w.isValid)u(w.formattedValue),w.errorType;else return w.errorType==="exceed_balance",void 0},d=()=>{const h=parseFloat(i||"0"),g=parseFloat(e||"0");if(g>0){const b=h-g,w=Ne(Math.max(0,b).toString());return`${Ne(i||"0")} → ${w} ${t}`}return`${Ne(i||"0")} ${t}`};return y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"bg-fill-input-primary rounded-lg px-3 py-3 my-4",children:[y.jsxs("div",{className:"flex justify-between items-center h-[18px] mb-3",children:[y.jsx("input",{type:"text",placeholder:"Amount",value:e,onChange:m,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"}),y.jsx("button",{onClick:()=>{u(i||"0")},className:"text-theme-normal text-xs font-medium cursor-pointer hover:opacity-80 transition-opacity h-full flex items-center",children:"MAX"})]}),y.jsx("div",{className:"h-[1px] bg-line-divider-secondary mb-2"}),y.jsxs("div",{className:"flex justify-between items-center",children:[y.jsx("span",{className:"text-text-tertiary text-xs leading-[14px]",children:"Available"}),y.jsx("span",{className:"text-text-primary text-xs leading-[14px]",children:d()})]})]}),!r&&Xc(e||"0",0)&&y.jsxs("div",{className:"flex justify-center flex-col items-center",children:[y.jsxs("h3",{className:"text-text-primary text-sm leading-4 font-medium",children:["Enable ",t," on ",o==null?void 0:o.chain]}),y.jsxs("p",{className:"text-text-secondary text-xs leading-3 mt-4",children:["You must enable ",t," first before you can deposit on"," ",o==null?void 0:o.chain,"."]}),y.jsxs("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",onClick:p,children:["Enable ",t]})]}),y.jsx("div",{className:"border-t border-line-divider-secondary border-dashed py-4",children:y.jsxs("div",{className:"flex justify-between items-center",children:[y.jsx("span",{className:"text-sm leading-[18px] text-text-tertiary",children:"总资产"}),y.jsx("span",{className:"text-sm leading-[18px] text-text-primary font-medium",children:e?`${Ne(l)} → ${Ne((parseFloat(l)+parseFloat(e)).toString())} ${t}`:`${Ne(l)} ${t}`})]})})]})},sf=({token:e,account:t,chainId:n,contractAddress:r,wagmiHooks:o,onResult:s})=>{var i,l;const c=(i=o==null?void 0:o.useBalance)==null?void 0:i.call(o,{address:t,token:e.tokenAddress,chainId:n,query:{enabled:!!t&&!!n&&!!e.tokenAddress&&!!(o!=null&&o.useBalance)}}),a=(l=o==null?void 0:o.useReadContract)==null?void 0:l.call(o,{address:e.tokenAddress,abi:[{name:"allowance",type:"function",stateMutability:"view",inputs:[{name:"owner",type:"address"},{name:"spender",type:"address"}],outputs:[{name:"",type:"uint256"}]}],functionName:"allowance",args:[t,r],chainId:n,query:{enabled:!!t&&!!n&&!!e.tokenAddress&&!!r&&!!(o!=null&&o.useReadContract)}});return f.useEffect(()=>{s(e.tokenAddress,{balance:c,allowance:a})},[c,a,e.tokenAddress,s]),null},Fi=({account:e,chainId:t,contractAddress:n,tokens:r=[],wagmiHooks:o})=>{var h;const s=f.useMemo(()=>r.filter(g=>g.tokenAddress&&g.tokenAddress!=="0x0000000000000000000000000000000000000000"),[r]),[c,a]=f.useState({}),i=f.useCallback((g,b)=>{a(w=>({...w,[g]:b}))},[]),l=(h=o==null?void 0:o.useBalance)==null?void 0:h.call(o,{address:e,chainId:t,query:{enabled:!!e&&!!t&&!!(o!=null&&o.useBalance)}}),u=f.useMemo(()=>s.map(g=>f.createElement(sf,{key:g.tokenAddress,token:g,account:e,chainId:t,contractAddress:n,wagmiHooks:o,onResult:i})),[s,e,t,n,o,i]),p=f.useMemo(()=>{if(!(o!=null&&o.useBalance))return{balanceList:[],allowanceList:[],baseTokenBalance:{value:BigInt(0),formatted:"0",decimals:18,symbol:"ETH"},combinedData:{}};const g=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"},b=s.map(x=>{const C=c[x.tokenAddress],S=C==null?void 0:C.balance,M=S==null?void 0:S.data;return{address:x.tokenAddress,value:(M==null?void 0:M.value)||BigInt(0),formatted:(M==null?void 0:M.formatted)||"0",decimals:(M==null?void 0:M.decimals)||x.decimals}}).filter(x=>x.address),w=s.map(x=>{const C=c[x.tokenAddress],S=C==null?void 0:C.allowance,M=S==null?void 0:S.data,F=BigInt(M?M.toString():0);return{address:x.tokenAddress,value:F,formatted:(F/BigInt(10)**BigInt(x.decimals)).toString(),decimals:x.decimals}}).filter(x=>x.address),E=b.reduce((x,C)=>{const S=w.find(M=>M.address===C.address);return{...x,[C.address]:{balance:C,allowance:S||{address:C.address,value:BigInt(0),formatted:"0",decimals:C.decimals}}}},{});return{balanceList:b,allowanceList:w,baseTokenBalance:g,combinedData:E}},[l,c,s,o==null?void 0:o.useBalance]),m=f.useCallback(async()=>p,[p]),d=f.useMemo(()=>{const g=(l==null?void 0:l.isLoading)||!1,b=Object.values(c).some(w=>{var E,x;return((E=w.balance)==null?void 0:E.isLoading)||((x=w.allowance)==null?void 0:x.isLoading)});return g||b},[l==null?void 0:l.isLoading,c]);return{multicallRun:m,multicallResult:p,validErcTokens:s,isLoading:d,queryComponents:u}},lf=({chains:e,defaultChainId:t,defaultTokenAddress:n,defaultAmount:r="",walletAdapter:o,metadata:s,currentEquity:c,platformBalance:a="0",wagmiHooks:i,approved:l,onApproved:u,onDeposit:p,onClose:m,onChainChange:d,onTokenChange:h})=>{var _;const[g,b]=f.useState(()=>{var N;return!e||e.length===0?1:t||((N=e[0])==null?void 0:N.chainId)||1}),[w,E]=f.useState(()=>{var q;if(!e||e.length===0)return"";const N=t||((q=e[0])==null?void 0:q.chainId),H=e.find(pe=>pe.chainId===N);if(!H||!H.tokenList||H.tokenList.length===0)return"";const G=H.tokenList.find(pe=>pe.tokenAddress===n)||H.tokenList[0];return(G==null?void 0:G.token)||""}),[x,C]=f.useState(r),S=f.useCallback(N=>{b(N),d==null||d(N)},[d]),M=f.useCallback(N=>{E(N),h==null||h(N)},[h]),F=f.useRef(!0),W=f.useRef(w),V=f.useRef(g);f.useEffect(()=>{if(F.current){F.current=!1,W.current=w,V.current=g;return}(W.current!==w||V.current!==g)&&(C(""),W.current=w,V.current=g)},[w,g]);const A=e&&e.length>0?e.find(N=>N.chainId===g)||e[0]:null,O=(_=A==null?void 0:A.tokenList)==null?void 0:_.find(N=>N.token===w),j=o==null?void 0:o.getDisplayAddress(),{multicallResult:D,queryComponents:I}=Fi({account:j,chainId:g,contractAddress:void 0,tokens:(A==null?void 0:A.tokenList)||[],wagmiHooks:i}),B=f.useMemo(()=>{var H;if(!O)return;if(!O.tokenAddress||O.tokenAddress.toLowerCase()==="0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee")return D.baseTokenBalance.formatted;const N=D.combinedData[O.tokenAddress];return((H=N==null?void 0:N.balance)==null?void 0:H.formatted)||"0"},[O,D]),z=l??!1,U=f.useMemo(()=>{const N=parseFloat(x||"0"),H=10,G=B||"0",q=Jc(x,G,z);return!x||N===0?{text:"Confirm Deposit",disabled:!0}:z?N>parseFloat(G)?{text:"Insufficient Balance",disabled:!0}:N<H?{text:`Min Deposit ${H} ${w}`,disabled:!0}:{text:"Confirm Deposit",disabled:!q}:{text:"Confirm Deposit",disabled:!0}},[x,w,B,z]),T=f.useCallback(async()=>{p&&p({amount:x,chainId:g,tokenAddress:(O==null?void 0:O.tokenAddress)||"",tokenSymbol:w})},[p,x,g,O==null?void 0:O.tokenAddress,w]);return!(i!=null&&i.useBalance)||!(i!=null&&i.useReadContract)||!(i!=null&&i.useAccount)?y.jsxs("div",{className:"p-6 text-center",children:[y.jsx("p",{className:"text-red-500",children:"缺少必要的 wagmi hooks"}),y.jsx("p",{className:"text-sm text-gray-500 mt-2",children:"请确保传入了 useBalance, useReadContract, useAccount"})]}):!e||e.length===0?y.jsx("div",{className:"text-center py-8",children:y.jsx("p",{className:"text-gray-400",children:"No chains available"})}):A?y.jsxs(y.Fragment,{children:[I,y.jsx(er,{currentActiveChain:A,chainList:e,onChainChange:S,curSelectToken:w,onTokenChange:M,walletType:"evm"}),y.jsx(of,{depositAmount:x,curSelectToken:w,curSelectTokenData:{balance:O==null?void 0:O.balance,allowance:O==null?void 0:O.allowance},approved:z,currentActiveChain:A,currentEquity:c||0,amount:x,decimals:(O==null?void 0:O.decimals)||6,tokenBalance:B,platformBalance:a,onDepositAmountChange:C,onApprove:async()=>{u&&await u()}}),y.jsx("button",{className:`w-full h-[38px] text-sm rounded-xl font-medium transition-colors ${U.disabled?"bg-text-disabled text-text-secondary cursor-not-allowed":"bg-fill-btn-primary text-text-on-sec-btn"}`,onClick:T,disabled:U.disabled,children:U.text})]}):y.jsx("div",{className:"text-center py-8",children:y.jsx("p",{className:"text-gray-400",children:"Loading..."})})},Ii=({isOpen:e,onClose:t,config:n,currentActiveAccount:r=or,smartWallet:o=ir,chains:s,defaultChainId:c,defaultTokenAddress:a,defaultAmount:i="",metadata:l=sr,currentEquity:u=5e3,platformBalance:p="0",wagmiHooks:m,approved:d,onApproved:h,onDeposit:g,onChainChange:b,onTokenChange:w})=>{const E=f.useMemo(()=>{var C;return r?yr(r,o,!1,(C=s[0])==null?void 0:C.chainId,"0","0"):null},[r,o,s]),x=(E==null?void 0:E.getWalletType())==="mpc";return e?de.createPortal(y.jsx("div",{className:"fixed top-0 left-0 right-0 bottom-0 z-[999] w-screen h-screen",style:{zIndex:999},children:y.jsx("div",{className:"fixed top-0 left-0 right-0 bottom-0 z-50 flex items-center justify-center",style:{background:"rgba(0, 0, 0, 0.6)"},onClick:()=>{t()},"aria-hidden":"true",children:y.jsxs("div",{className:"relative w-[420px] max-h-[85vh] bg-fill-page-secondary overflow-auto rounded-lg p-6 shadow-xl",onClick:C=>{C.stopPropagation()},children:[y.jsxs("div",{className:"flex items-center justify-between mb-4",children:[y.jsx("h2",{className:"text-lg font-semibold text-white",children:"Deposit"}),y.jsx("button",{className:"text-gray-400 hover:text-gray-200 transition-colors",onClick:t,"aria-label":"Close",children:y.jsx(br,{className:"h-4 w-4"})})]}),x?y.jsx(rf,{chains:s,defaultChainId:c,defaultTokenAddress:a,defaultAmount:i,walletAdapter:E,metadata:l,currentEquity:u,onDeposit:g,onClose:t}):y.jsx(lf,{chains:s,defaultChainId:c,defaultTokenAddress:a,defaultAmount:i,walletAdapter:E,metadata:l,currentEquity:u,platformBalance:p,wagmiHooks:m,approved:d,onApproved:h,onDeposit:g,onClose:t,onChainChange:b,onTokenChange:w})]})})}),document.body):null};let je=null;const af={symbol:"USDT"},ji=f.forwardRef((e,t)=>{const[n,r]=f.useState(!1),[o,s]=f.useState({chains:[]}),c=f.useCallback(u=>{s(u),r(!0)},[]),a=f.useCallback(u=>{s(p=>({...p,...u}))},[]),i=f.useCallback(()=>{r(!1),o.onClose&&o.onClose()},[o.onClose]),l=f.useCallback(()=>n,[n]);return f.useImperativeHandle(t,()=>({openDeposit:c,closeDeposit:i,updateDepositOptions:a,isOpen:l}),[c,i,a,l]),f.useEffect(()=>(je={openDeposit:c,closeDeposit:i,updateDepositOptions:a,isOpen:l},()=>{je=null}),[c,i,a,l]),y.jsx(Ii,{isOpen:n,onClose:i,config:o.config||af,currentActiveAccount:o.currentActiveAccount||or,smartWallet:o.smartWallet||ir,chains:o.chains||tf,defaultChainId:o.defaultChainId,defaultTokenAddress:o.defaultTokenAddress,defaultAmount:o.defaultAmount,metadata:o.metadata||sr,currentEquity:o.currentEquity??5e3,platformBalance:o.platformBalance||"0",wagmiHooks:o.wagmiHooks,approved:o.approved,onApproved:o.onApproved,onDeposit:o.onDeposit,onChainChange:o.onChainChange,onTokenChange:o.onTokenChange})});ji.displayName="DepositManager";const Di=e=>{if(!je){console.error("DepositManager not initialized. Make sure to render <DepositManager /> in your app.");return}je.openDeposit(e||{chains:[]})},_i=()=>{if(!je){console.error("DepositManager not initialized. Make sure to render <DepositManager /> in your app.");return}je.closeDeposit()},ki=e=>{je&&je.updateDepositOptions(e)},uf=()=>je?je.isOpen():!1,cf=()=>({openDeposit:Di,closeDeposit:_i,updateDepositOptions:ki,isOpen:uf});f.createContext(null);const ff=Object.values({MAINNET:1,SEPOLIA:11155111}),lr=e=>ff.includes(+e),df=({withdrawAmount:e,curSelectToken:t,currentActiveChain:n,platformBalance:r="0",walletType:o="evm",receiverAddress:s="",onWithdrawAmountChange:c,onReceiverAddressChange:a})=>{const i=p=>{const m=p.target.value,h=rr(m,r||"0");if(h.isValid)c(h.formattedValue),h.errorType;else return h.errorType==="exceed_balance",void 0},l=()=>{c(r)},u=()=>{const p=parseFloat(r||"0"),m=parseFloat(e||"0");if(m>0){const d=p-m,h=Ne(Math.max(0,d).toString());return`${Ne(r||"0")} → ${h} ${t}`}return`${Ne(r||"0")} ${t}`};return y.jsxs(y.Fragment,{children:[y.jsxs("div",{className:"bg-fill-input-primary rounded-lg px-3 py-3 my-4",children:[y.jsxs("div",{className:"flex justify-between items-center h-[18px] mb-3",children:[y.jsx("input",{type:"text",placeholder:"Amount",value:e,onChange:i,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"}),y.jsx("button",{onClick:l,className:"text-theme-normal text-xs font-medium cursor-pointer hover:opacity-80 transition-opacity h-full flex items-center",children:"MAX"})]}),y.jsx("div",{className:"h-[1px] bg-line-divider-secondary mb-2"}),y.jsxs("div",{className:"flex justify-between items-center",children:[y.jsx("span",{className:"text-text-tertiary text-xs leading-[14px]",children:"Available"}),y.jsx("span",{className:"text-text-primary text-xs leading-[14px]",children:u()})]})]}),o==="mpc"&&!lr(n==null?void 0:n.chainId)&&y.jsx("div",{className:"bg-fill-input-primary rounded-lg my-4 h-9 flex items-center px-3",children:y.jsx("input",{type:"text",placeholder:"Receiver Address",value:s,onChange:p=>a==null?void 0:a(p.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"})}),y.jsx("div",{className:"bg-fill-page-secondary rounded-lg mb-4",children:y.jsx("p",{className:"text-text-tertiary text-xs leading-[18px]",children:"Cross-chain withdrawals require verification at L2 (via ZK proofs) and the withdrawal process may take up to 2 hours. Sufficient funds in the corresponding chain's asset pool are required to process cross-chain withdrawals. Gas fees will also be incurred. edgeX will charge a fee to cover this."})}),y.jsxs("div",{className:"py-4 border-t border-line-divider-secondary border-dashed",children:[y.jsxs("div",{className:"flex items-center justify-between",children:[y.jsx("span",{className:"text-text-tertiary text-xs",children:"Speed"}),y.jsxs("div",{className:"flex items-center space-x-1",children:[y.jsx("span",{className:"text-theme-normal",children:"⚡"}),y.jsx("span",{className:"text-theme-normal",children:"⚡"}),y.jsx("span",{className:"text-theme-normal",children:"⚡"})]})]}),y.jsxs("div",{className:"flex items-center justify-between mt-2 h-[18px]",children:[y.jsx("span",{className:"text-text-tertiary text-sm leading-4",children:"Amount to receive"}),y.jsxs("span",{className:"text-text-primary text-sm leading-4 font-medium",children:[Ne(e)," ",t]})]})]})]})},pf=({chains:e,defaultChainId:t,defaultTokenAddress:n,defaultAmount:r="",walletAdapter:o,metadata:s,currentEquity:c,platformBalance:a="0",wagmiHooks:i,onWithdraw:l,onClose:u,onChainChange:p,onTokenChange:m})=>{var _;const[d,h]=f.useState(()=>{var N;return!e||e.length===0?1:t||((N=e[0])==null?void 0:N.chainId)||1}),[g,b]=f.useState(()=>{var q;if(!e||e.length===0)return"";const N=t||((q=e[0])==null?void 0:q.chainId),H=e.find(pe=>pe.chainId===N);if(!H||!H.tokenList||H.tokenList.length===0)return"";const G=H.tokenList.find(pe=>pe.tokenAddress===n)||H.tokenList[0];return(G==null?void 0:G.token)||""}),[w,E]=f.useState(r),[x,C]=f.useState(""),S=(o==null?void 0:o.getWalletType())||"evm",M=f.useCallback(N=>{h(N),p==null||p(N)},[p]),F=f.useCallback(N=>{b(N),m==null||m(N)},[m]),W=f.useRef(!0),V=f.useRef(g),A=f.useRef(d);f.useEffect(()=>{if(W.current){W.current=!1,V.current=g,A.current=d;return}(V.current!==g||A.current!==d)&&(E(""),V.current=g,A.current=d)},[g,d]);const O=e&&e.length>0?e.find(N=>N.chainId===d)||e[0]:null,j=(_=O==null?void 0:O.tokenList)==null?void 0:_.find(N=>N.token===g),D=o==null?void 0:o.getDisplayAddress(),{multicallResult:I,queryComponents:B}=Fi({account:D,chainId:d,contractAddress:void 0,tokens:(O==null?void 0:O.tokenList)||[],wagmiHooks:i}),z=f.useMemo(()=>{var H;if(!j)return;if(!j.tokenAddress||j.tokenAddress.toLowerCase()==="0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee")return I.baseTokenBalance.formatted;const N=I.combinedData[j.tokenAddress];return((H=N==null?void 0:N.balance)==null?void 0:H.formatted)||"0"},[j,I]),U=f.useMemo(()=>{const N=parseFloat(w||"0"),H=1,G=parseFloat(a||"0");return!w||N===0?{text:"Confirm Withdraw",disabled:!0}:S==="mpc"&&!lr(d)&&!x.trim()?{text:"Enter Receiver Address",disabled:!0}:N>G?{text:"Insufficient Balance",disabled:!0}:N<H?{text:`Min Withdraw ${H} ${g}`,disabled:!0}:{text:"Confirm Withdraw",disabled:!1}},[w,g,a,S,x]),T=f.useCallback(async()=>{if(l){const N={amount:w,chainId:d,tokenAddress:(j==null?void 0:j.tokenAddress)||"",tokenSymbol:g};S==="mpc"&&!lr(d)&&(N.receiverAddress=x),l(N)}},[l,w,d,j==null?void 0:j.tokenAddress,g,S,x]);return!(i!=null&&i.useBalance)||!(i!=null&&i.useReadContract)||!(i!=null&&i.useAccount)?y.jsxs("div",{className:"p-6 text-center",children:[y.jsx("p",{className:"text-red-500",children:"缺少必要的 wagmi hooks"}),y.jsx("p",{className:"text-sm text-gray-500 mt-2",children:"请确保传入了 useBalance, useReadContract, useAccount"})]}):!e||e.length===0?y.jsx("div",{className:"text-center py-8",children:y.jsx("p",{className:"text-gray-400",children:"No chains available"})}):O?y.jsxs(y.Fragment,{children:[B,y.jsx(er,{currentActiveChain:O,chainList:e,onChainChange:M,curSelectToken:g,onTokenChange:F,walletType:"evm"}),y.jsx(df,{withdrawAmount:w,curSelectToken:g,curSelectTokenData:{balance:j==null?void 0:j.balance,allowance:j==null?void 0:j.allowance},currentActiveChain:O,currentEquity:c||0,amount:w,decimals:(j==null?void 0:j.decimals)||6,tokenBalance:z,platformBalance:a,walletType:S,receiverAddress:x,onWithdrawAmountChange:E,onReceiverAddressChange:C}),y.jsx("button",{className:`w-full h-[38px] text-sm rounded-xl font-medium transition-colors ${U.disabled?"bg-text-disabled text-text-secondary cursor-not-allowed":"bg-fill-btn-primary text-text-on-sec-btn"}`,onClick:T,disabled:U.disabled,children:U.text})]}):y.jsx("div",{className:"text-center py-8",children:y.jsx("p",{className:"text-gray-400",children:"Loading..."})})},Ri=({isOpen:e,onClose:t,config:n,currentActiveAccount:r=or,smartWallet:o=ir,chains:s,defaultChainId:c,defaultTokenAddress:a,defaultAmount:i="",metadata:l=sr,currentEquity:u=5e3,platformBalance:p="0",wagmiHooks:m,onWithdraw:d,onChainChange:h,onTokenChange:g})=>{const b=f.useMemo(()=>{var w;return r?yr(r,o,!1,(w=s[0])==null?void 0:w.chainId,"0","0"):null},[r,o,s]);return e?de.createPortal(y.jsx("div",{className:"fixed top-0 left-0 right-0 bottom-0 w-screen h-screen",style:{zIndex:49},children:y.jsx("div",{className:"fixed top-0 left-0 right-0 bottom-0 z-49 flex items-center justify-center",style:{background:"rgba(0, 0, 0, 0.6)"},onClick:()=>{t()},"aria-hidden":"true",children:y.jsxs("div",{className:"relative w-[420px] max-h-[85vh] bg-fill-page-secondary overflow-auto rounded-lg p-6 shadow-xl",onClick:w=>{w.stopPropagation()},children:[y.jsxs("div",{className:"flex items-center justify-between mb-4",children:[y.jsx("h2",{className:"text-lg font-semibold text-white",children:"Withdraw"}),y.jsx("button",{className:"text-gray-400 hover:text-gray-200 transition-colors",onClick:t,"aria-label":"Close",children:y.jsx(br,{className:"h-4 w-4"})})]}),y.jsx(pf,{chains:s,defaultChainId:c,defaultTokenAddress:a,defaultAmount:i,walletAdapter:b,metadata:l,currentEquity:u,platformBalance:p,wagmiHooks:m,onWithdraw:d,onClose:t,onChainChange:h,onTokenChange:g})]})})}),document.body):null},mf=[],hf={};let De=null;const Wi=f.forwardRef((e,t)=>{const[n,r]=f.useState(!1),[o,s]=f.useState({chains:[]}),c=f.useCallback(u=>{s(u||{chains:[]}),r(!0)},[]),a=f.useCallback(u=>{s(p=>({...p,...u}))},[]),i=f.useCallback(()=>{r(!1),o.onClose&&o.onClose()},[o.onClose]),l=f.useCallback(()=>n,[n]);return f.useImperativeHandle(t,()=>({openWithdraw:c,closeWithdraw:i,updateWithdrawOptions:a,isOpen:l}),[c,i,a,l]),f.useEffect(()=>(De={openWithdraw:c,closeWithdraw:i,updateWithdrawOptions:a,isOpen:l},()=>{De=null}),[c,i,a,l]),y.jsx(Ri,{isOpen:n,onClose:i,config:o.config||{symbol:"USDT"},currentActiveAccount:o.currentActiveAccount,smartWallet:o.smartWallet,chains:o.chains||mf,defaultChainId:o.defaultChainId,defaultTokenAddress:o.defaultTokenAddress,defaultAmount:o.defaultAmount,metadata:o.metadata||hf,currentEquity:o.currentEquity??5e3,platformBalance:o.platformBalance||"0",wagmiHooks:o.wagmiHooks,onWithdraw:o.onWithdraw,onChainChange:o.onChainChange,onTokenChange:o.onTokenChange})});Wi.displayName="WithdrawManager";const Bi=e=>{if(!De){console.error("WithdrawManager not initialized. Make sure to render <WithdrawManager /> in your app.");return}De.openWithdraw(e||{chains:[]})},Vi=()=>{if(!De){console.error("WithdrawManager not initialized. Make sure to render <WithdrawManager /> in your app.");return}De.closeWithdraw()},Ui=e=>{if(!De){console.error("WithdrawManager not initialized. Make sure to render <WithdrawManager /> in your app.");return}De.updateWithdrawOptions(e)},gf=()=>De?De.isOpen():!1,vf=()=>({openWithdraw:Bi,closeWithdraw:Vi,updateWithdrawOptions:Ui,isOpen:gf});Z.ComponentProvider=us,Z.Deposit=Ii,Z.DepositManager=ji,Z.Withdraw=Ri,Z.WithdrawManager=Wi,Z.closeDeposit=_i,Z.closeWithdraw=Vi,Z.openDeposit=Di,Z.openWithdraw=Bi,Z.updateDepositOptions=ki,Z.updateWithdrawOptions=Ui,Z.useDeposit=cs,Z.useDepositManager=cf,Z.useWithdraw=fs,Z.useWithdrawManager=vf,Object.defineProperty(Z,Symbol.toStringTag,{value:"Module"})});
|
|
104
104
|
//# sourceMappingURL=index.umd.js.map
|