@spicenet-io/spiceflow-ui 1.11.3 → 1.11.5
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.cjs.js +2 -2
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
from { transform: rotate(0deg); }
|
|
45
45
|
to { transform: rotate(360deg); }
|
|
46
46
|
}
|
|
47
|
-
`}),!C&&l&&l.length>1&&e.jsx("div",{style:{overflow:"hidden",maxHeight:E?"200px":"0px",opacity:E?1:0,transition:"max-height 0.3s ease, opacity 0.3s ease",marginBottom:E?"16px":"0"},children:e.jsx("div",{style:{maxHeight:"180px",overflowY:"auto",display:"flex",flexDirection:"column",gap:"8px"},children:l.map(($,ee)=>e.jsxs("div",{style:{padding:"10px 12px",borderRadius:"6px",backgroundColor:"#f9fafb",border:"1px solid #e5e7eb",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontWeight:600,fontSize:"13px",color:"#111827",fontFamily:'"IBM Plex Mono", monospace'},children:$.asset.symbol}),$.amount&&e.jsx("span",{style:{fontSize:"12px",color:"#6b7280"},children:$.amount})]}),e.jsx("span",{style:{fontSize:"12px",color:$.success?"#10b981":"#ef4444",fontWeight:500},children:$.success?"\u2713":"\u2717"})]},ee))})}),!C&&!Z&&l&&e.jsx("div",{style:{padding:"12px",backgroundColor:"#fef2f2",border:"1px solid #fecaca",borderRadius:"8px",marginBottom:"16px"},children:e.jsx("p",{style:{fontSize:"13px",color:"#dc2626",margin:0,lineHeight:1.5},children:l.find($=>!$.success)?.error||`${s.charAt(0).toUpperCase()+s.slice(1)} failed. Please try again.`})}),!C&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[!Z&&k&&e.jsxs("button",{onClick:k,onMouseEnter:()=>f("retry-tx"),onMouseLeave:()=>{f(null),h(null)},onMouseDown:()=>h("retry-tx"),onMouseUp:()=>h(null),style:{width:"100%",height:"48px",padding:"14px 24px",borderRadius:"6px",backgroundColor:y==="retry-tx"?"#d43d3d":m==="retry-tx"?"#f05555":"#ea4b4b",border:"1px solid #0e0d0b",color:"#0e0d0b",fontFamily:'"IBM Plex Mono", monospace',fontWeight:500,fontSize:"16px",lineHeight:"156%",textTransform:"uppercase",cursor:"pointer",transition:"all 0.15s ease",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",transform:y==="retry-results"?"scale(0.98)":m==="retry-results"?"translateY(-2px)":"none",boxShadow:y==="retry-tx"?"1px 1px 0px black":m==="retry-tx"?"5px 5px 0px white, 6px 6px 0px black":"3px 3px 0px white, 4px 4px 0px black"},children:["TRY AGAIN
|
|
47
|
+
`}),!C&&l&&l.length>1&&e.jsx("div",{style:{overflow:"hidden",maxHeight:E?"200px":"0px",opacity:E?1:0,transition:"max-height 0.3s ease, opacity 0.3s ease",marginBottom:E?"16px":"0"},children:e.jsx("div",{style:{maxHeight:"180px",overflowY:"auto",display:"flex",flexDirection:"column",gap:"8px"},children:l.map(($,ee)=>e.jsxs("div",{style:{padding:"10px 12px",borderRadius:"6px",backgroundColor:"#f9fafb",border:"1px solid #e5e7eb",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontWeight:600,fontSize:"13px",color:"#111827",fontFamily:'"IBM Plex Mono", monospace'},children:$.asset.symbol}),$.amount&&e.jsx("span",{style:{fontSize:"12px",color:"#6b7280"},children:$.amount})]}),e.jsx("span",{style:{fontSize:"12px",color:$.success?"#10b981":"#ef4444",fontWeight:500},children:$.success?"\u2713":"\u2717"})]},ee))})}),!C&&!Z&&l&&e.jsx("div",{style:{padding:"12px",backgroundColor:"#fef2f2",border:"1px solid #fecaca",borderRadius:"8px",marginBottom:"16px"},children:e.jsx("p",{style:{fontSize:"13px",color:"#dc2626",margin:0,lineHeight:1.5},children:l.find($=>!$.success)?.error||`${s.charAt(0).toUpperCase()+s.slice(1)} failed. Please try again.`})}),!C&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[!Z&&k&&e.jsxs("button",{onClick:k,onMouseEnter:()=>f("retry-tx"),onMouseLeave:()=>{f(null),h(null)},onMouseDown:()=>h("retry-tx"),onMouseUp:()=>h(null),style:{width:"100%",height:"48px",padding:"14px 24px",borderRadius:"6px",backgroundColor:y==="retry-tx"?"#d43d3d":m==="retry-tx"?"#f05555":"#ea4b4b",border:"1px solid #0e0d0b",color:"#0e0d0b",fontFamily:'"IBM Plex Mono", monospace',fontWeight:500,fontSize:"16px",lineHeight:"156%",textTransform:"uppercase",cursor:"pointer",transition:"all 0.15s ease",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",transform:y==="retry-results"?"scale(0.98)":m==="retry-results"?"translateY(-2px)":"none",boxShadow:y==="retry-tx"?"1px 1px 0px black":m==="retry-tx"?"5px 5px 0px white, 6px 6px 0px black":"3px 3px 0px white, 4px 4px 0px black"},children:["TRY AGAIN ",s]}),Z&&e.jsx("button",{onClick:S,onMouseEnter:()=>f("continue-tx"),onMouseLeave:()=>{f(null),h(null)},onMouseDown:()=>h("continue-tx"),onMouseUp:()=>h(null),style:{width:"100%",height:"48px",padding:"14px 24px",borderRadius:"6px",backgroundColor:y==="continue-tx"?"#d43d3d":m==="continue-tx"?"#f05555":"#ea4b4b",border:"1px solid #0e0d0b",color:"#0e0d0b",fontFamily:'"IBM Plex Mono", monospace',fontWeight:500,fontSize:"16px",lineHeight:"156%",textTransform:"uppercase",cursor:"pointer",transition:"all 0.15s ease",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",transform:y==="continue-tx"?"scale(0.98)":m==="continue-tx"?"translateY(-2px)":"none",boxShadow:y==="continue-tx"?"1px 1px 0px black":m==="continue-results"?"5px 5px 0px white, 6px 6px 0px black":"3px 3px 0px white, 4px 4px 0px black"},children:"DONE"})]})]}),e.jsx("style",{children:`
|
|
48
48
|
@keyframes slideUp {
|
|
49
49
|
from {
|
|
50
50
|
transform: translateY(100%);
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
from { transform: rotate(0deg); }
|
|
67
67
|
to { transform: rotate(360deg); }
|
|
68
68
|
}
|
|
69
|
-
`})]}),G&&e.jsx(gs,{message:G.message,type:G.type,linkText:G.linkText,linkUrl:G.linkUrl,onClose:()=>U(null)})]})},bs=({withdrawBatches:t,externalWithdrawBatches:o,tokens:a,supportedTokens:n,theme:s="light",styles:l,className:c="",withdrawInputHook:i,defaultSelectedAsset:x,filterChains:g,withdrawMode:u="external",depositTokenAddress:d,onWithdrawModeChange:A,externalWalletAddress:k,embeddedWalletAddress:I,onWithdrawSuccess:C,onWithdrawError:p,onComplete:w,hideWithdrawModeSelector:v=!1,externalModeLabel:E="External Wallet",embeddedModeLabel:b="Embedded Wallet"})=>{const m=[{id:"external",label:E},{id:"embedded",label:b}],f=ce.createTheme(s),y={...f,typography:{...f.typography,fontFamily:l?.fontFamily||f.typography.fontFamily},colors:{...f.colors,primary:l?.primaryColor||f.colors.primary,primaryHover:l?.primaryColor?`${l.primaryColor}dd`:f.colors.primaryHover}},h=Mt(),{isReady:S,isAuthenticated:M,isConnected:Z,address:_,provider:$,actions:ee}=h,[W,T]=r.useState(()=>x?{asset:x,amount:""}:null),[K,F]=r.useState([]),[G,U]=r.useState(!1),[X,j]=r.useState(null),oe=r.useRef(!1),te=r.useRef(!1),se=I,ie=r.useMemo(()=>!a||a.length===0?[]:!n||n.length===0?a:a.filter(H=>n.some(re=>re.toLowerCase()===H.symbol.toLowerCase())),[a,n]),Y=ie?JSON.stringify(ie.map(H=>`${H.address}-${H.chainId}`).sort()):"",q=r.useCallback(async(H=!1)=>{if(!te.current){if(!ie||ie.length===0||!se){F([]),oe.current=!1;return}te.current=!0,!oe.current&&!H&&U(!0),j(null);try{const re=await Promise.all(ie.map(async ue=>{try{const ve=await Te(ue.chainId).readContract({address:ue.address,abi:de.erc20Abi,functionName:"balanceOf",args:[se]}),Xe=parseFloat(de.formatUnits(ve,ue.decimals));return{address:ue.address,symbol:ue.symbol,name:ue.name,decimals:ue.decimals,chainId:ue.chainId,balance:ve,balanceFormatted:Xe,balanceUsd:0,isNative:!1,logoURI:ue.logoURI}}catch(ve){return console.error(`Failed to fetch balance for ${ue.symbol}:`,ve),{address:ue.address,symbol:ue.symbol,name:ue.name,decimals:ue.decimals,chainId:ue.chainId,balance:BigInt(0),balanceFormatted:0,balanceUsd:0,isNative:!1,logoURI:ue.logoURI}}}));F(re),oe.current=!0}catch(re){console.error("Failed to fetch token balances:",re),j(re instanceof Error?re.message:"Failed to fetch token balances"),oe.current||F([])}finally{U(!1),te.current=!1}}},[Y,se]);r.useEffect(()=>{se&&ie.length>0&&(oe.current=!1,q(!1))},[Y,se]),r.useEffect(()=>{if(!ie.length||!se)return;const H=setInterval(()=>{q(!0)},3e4);return()=>clearInterval(H)},[Y,se]),K.some(H=>H.balanceFormatted>0);const[pe,ne]=r.useState(!1),[Fe,Se]=r.useState(null),[we,me]=r.useState(!1),[Ie,Ne]=r.useState(!1),[Qe,B]=r.useState(!1),[J,ye]=r.useState(u),[L,V]=r.useState(null),[O,ae]=r.useState(null),le=r.useRef(null),xe=r.useMemo(()=>J==="external"?k:I,[J,k,I]),R=r.useCallback(H=>{ye(H),A?.(H)},[A]),{intentStatus:Q,startStatusPolling:he,clearStatus:fe}=It({checkStepStatus:(H,re)=>ke.checkStepStatus(H,re)});r.useEffect(()=>{if(Q?.overallStatus==="success"&&Q.intentId&&le.current!==Q.intentId&&W&&_){const H=Q.steps.find(re=>re.transactionHash);if(H?.transactionHash)if(le.current=Q.intentId,J==="embedded"){const re=de.parseUnits(W.amount,W.asset.decimals),ue={user:_,txHash:H.transactionHash,sender:_,tokenAddress:d||W.asset.address,chainId:W.asset.chainId,amount:re.toString(),isDeposit:!0};console.log("[WithdrawWidget] Submitting spice deposit for embedded withdraw:",ue),ke.submitSpiceDeposit(ue).then(ve=>{console.log("[WithdrawWidget] Spice deposit submitted successfully:",ve),q()}).catch(ve=>{console.error("[WithdrawWidget] Spice deposit submission failed:",ve),le.current=null})}else q()}},[Q,_,J,W,d]),r.useEffect(()=>{i&&i.assetAmount!==W?.amount&&W&&T({...W,amount:i.assetAmount})},[i?.assetAmount,W]);const Ve=r.useCallback(()=>{Se(null)},[]),He=H=>{T({asset:H,amount:W?.amount||""}),Ve()},tt=r.useCallback(H=>{W&&(r.startTransition(()=>{T({...W,amount:H}),Ve()}),i&&i.setAssetAmount(H))},[W,i,Ve]),Ge=async()=>{if(!(!W||!_||t.length===0)){if(!xe){Se(`Please provide a ${J==="external"?"external":"embedded"} wallet address`);return}if(!S||!M){Se(`Please authenticate with ${$||"wallet provider"} to continue`);return}ne(!0),Se(null),B(!0);try{const H=J==="external"&&o?[...t,...o]:[...t],re=[...new Set(H.map(D=>D.chainId))],ue=[];for(const D of re){const z=Te(D),ge=pt(D),be=await Je.getAccountNonce(_,z),Ee=await ee.signAuthorization({contractAddress:ge,chainId:D,nonce:Number(be)});ue.push(Ee)}const ve=Je.hashChainBatches(H),Xe=Math.floor(Date.now()/1e3)+60*10,Tt=Je.getIntentHash(0n,BigInt(Xe),ve),ft=await ee.signMessage({raw:Tt}),Rt=typeof ft=="string"?ft:ft.signature;if(!Rt)throw new Error("Failed to sign intent authorization");const zt={from:"solver",to:_,token:"0x0000000000000000000000000000000000000000",amount:de.parseUnits("0.00001",18)},N={mode:"7702",signatureType:"ecdsa",signature:Rt,nbf:0,exp:Xe,chainBatches:ve.map((D,z)=>{const ge=H[z],be=ge?.tokenTransfers??[],Ee=ge?.calls&&ge.calls.length>0;return{hash:D.hash,chainId:D.chainId,tokenTransfers:Ee?[zt,...be]:be,calls:D.calls}})},P=await ke.createAction({user:_,chainAuthorizations:ue.map(D=>({...D,r:D.r,s:D.s,yParity:D.yParity,address:D.address,chainId:Number(D.chainId),nonce:Number(D.nonce)})),intents:[N]});if(P){const D=jt(H,Ee=>`Chain ${Ee}`),[z,ge]=P.intentIds[0].split("/"),be=parseInt(ge||"0",10);he(P.intentIds[0],D);for(let Ee=0;Ee<H.length;Ee++)await ke.executeStep(z,be,Ee,{action:"execute"});window.dispatchEvent(new CustomEvent("withdraw-completed"))}}catch(H){const re=H instanceof Error?H.message:"Withdraw failed";Se(re),p?.(re)}finally{ne(!1)}}},Oe=r.useMemo(()=>{let H=K;return g&&g.length>0&&(H=H.filter(re=>g.includes(re.chainId))),H},[K,g]),Ye=W&&W.amount&&parseFloat(W.amount)>0&&parseFloat(W.amount)<=W.asset.balanceFormatted&&Z&&!pe&&t.length>0&&!!xe,ot=X||Fe,it={backgroundColor:l?.container?.backgroundColor||l?.primaryBackground||y.colors.background,border:`1px solid ${l?.container?.borderColor||y.colors.border}`,borderRadius:l?.container?.borderRadius||y.borderRadius.lg,padding:l?.container?.padding||y.spacing.md,width:l?.container?.width||"100%",maxWidth:"28rem",minHeight:"200px",margin:"0 auto",color:y.colors.text,fontFamily:y.typography.fontFamily,boxShadow:l?.container?.boxShadow||(y.mode==="light"?"0 4px 6px -1px rgb(0 0 0 / 0.1)":"0 4px 6px -1px rgb(0 0 0 / 0.3)")},Ke=Q?e.jsx(Zt,{type:"withdraw",isOpen:!!Q&&Q.overallStatus!=="processing",isProcessing:pe||Q?.overallStatus==="processing",onRetryTx:()=>{fe(),B(!1),Ge()},onNewTx:()=>{fe(),B(!1),T(null),le.current=null,q()},onClose:()=>{fe(),B(!1)},onComplete:()=>{fe(),B(!1),T(null),le.current=null,q(),w?.()},results:Q?.overallStatus==="success"||Q?.overallStatus==="failed"?(()=>{if((o?[...t,...o]:t).length>1&&Q.steps.length>1){const H=Q.steps.find(re=>re.transactionHash);return[{asset:{symbol:W?.asset.symbol||"Token",address:W?.asset.address||""},txHash:H?.transactionHash||"",success:Q.steps.every(re=>re.status==="success"),amount:W?.amount}]}return Q.steps.map(H=>({asset:{symbol:W?.asset.symbol||"Token",address:W?.asset.address||""},txHash:H.transactionHash||"",success:H.status==="success",amount:W?.amount}))})():void 0,chainName:W?(()=>{const H=o?[...t,...o]:t,re=[...new Set(H.map(ue=>st(ue.chainId)))];return re.length>1?re.join(" and "):re[0]||"Network"})():"Network",explorerUrl:W?wt(t[t.length-1].chainId,"").replace(/\/tx\/.*$/,""):void 0,theme:y}):null;return e.jsxs("div",{style:{...it,position:"relative"},className:c,children:[Ke&&e.jsx("div",{style:{position:"absolute",top:0,left:"-25px",right:"-25px",bottom:"-16px"},children:e.jsx("div",{style:{position:"absolute",width:"100%",height:"100%",pointerEvents:"auto"},children:Ke})}),!v&&e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"6px",marginBottom:"10px"},children:e.jsx("label",{style:{fontSize:"12px",fontWeight:590,color:y.mode==="light"?"#374151":"#d1d5db"},children:"Withdraw To"})}),e.jsx("div",{style:{display:"flex",gap:"12px",flexWrap:"wrap"},children:m.map(H=>{const re=J===H.id,ue=H.id==="external"?k:I,ve=ue?`${ue.slice(0,6)}...${ue.slice(-4)}`:null;return e.jsxs("button",{onClick:()=>R(H.id),onMouseEnter:()=>V(H.id),onMouseLeave:()=>{V(null),ae(null)},onMouseDown:()=>ae(H.id),onMouseUp:()=>ae(null),style:{padding:"8px 12px",borderRadius:"8px",border:`1px solid ${re?"#EA4B4B7A":L===H.id?"#F4A5A5":y.mode==="light"?"#e5e7eb":"#374151"}`,backgroundColor:re?y.mode==="light"?"#FEF2F2":"#451a1a":O===H.id?y.mode==="light"?"#f5f5f5":"#2d2d2d":L===H.id?y.mode==="light"?"#fafafa":"#333333":y.mode==="light"?"white":"#1f1f1f",cursor:"pointer",display:"flex",flexDirection:"column",alignItems:"flex-start",gap:"4px",transition:"all 150ms ease",transform:O===H.id?"scale(0.96)":L===H.id?"translateY(-1px)":"none",boxShadow:re?"0 0 0 3px #FBDBDB":O===H.id?"0 1px 2px rgba(0, 0, 0, 0.05)":L===H.id?"0 4px 8px rgba(0, 0, 0, 0.1)":"none"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:510,color:y.mode==="light"?"#3C3E42":"#e5e7eb"},children:H.label}),ve&&e.jsx("span",{style:{fontSize:"10px",fontWeight:500,color:y.mode==="light"?"#939291":"#6b7280",fontFamily:'"IBM Plex Mono", monospace'},children:ve})]},H.id)})})]}),e.jsx("div",{style:{marginBottom:y.spacing.sm},children:e.jsx(xt,{assets:Oe,selectedAsset:W||void 0,onAssetSelect:He,onAmountChange:tt,loading:G,label:"Amount",showBalance:!0,showMaxButton:!0,theme:y,styles:l})}),ot&&e.jsx("div",{style:{backgroundColor:l?.errorMessage?.backgroundColor||(y.mode==="light"?"#fef2f2":`${l?.statusDisplay?.errorColor||y.colors.error}20`),border:`1px solid ${l?.errorMessage?.borderColor||(y.mode==="light"?"#fecaca":l?.statusDisplay?.errorColor||y.colors.error)}`,borderRadius:l?.errorMessage?.borderRadius||y.borderRadius.md,padding:l?.errorMessage?.padding||y.spacing.md,marginBottom:y.spacing.sm},children:e.jsx("p",{style:{color:l?.errorMessage?.color||l?.statusDisplay?.errorColor||y.colors.error,fontSize:l?.errorMessage?.fontSize||y.typography.fontSize.sm,fontWeight:l?.errorMessage?.fontWeight,fontFamily:l?.errorMessage?.fontFamily||y.typography.fontFamily,margin:0},children:ot})}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:y.spacing.sm},children:e.jsx(ce.Button,{variant:"outline",fullWidth:!0,onClick:Ge,onMouseEnter:()=>me(!0),onMouseLeave:()=>{me(!1),Ne(!1)},onMouseDown:()=>Ne(!0),onMouseUp:()=>Ne(!1),loading:pe,disabled:!Ye||!Z,theme:y,styles:l,style:{width:"100%",padding:"8px",backgroundColor:Ye?Ie?"#d43d3d":we?"#f05555":"#ea4b4b":"#d1d5db",color:Ye?"#0e0d0b":"#6b7280",border:"1px solid #0e0d0b",fontWeight:500,fontSize:"18px",fontFamily:'"IBM Plex Mono", monospace',lineHeight:"156%",textTransform:"uppercase",cursor:Ye?"pointer":"not-allowed",marginTop:"20px",display:"flex",alignItems:"center",justifyContent:"center",gap:"10px",transition:"all 150ms ease",transform:Ye?Ie?"scale(0.98)":we?"translateY(-2px)":"none":"none",boxShadow:Ie?"1px 1px 0px black":we&&Ye?"5px 5px 0px white, 6px 6px 0px black":"3px 3px 0px white, 4px 4px 0px black"},children:S?M?Z?pe?"Executing Withdraw...":W?W.amount?parseFloat(W.amount)>W.asset.balanceFormatted?"Insufficient Balance":t.length===0?"No Withdraw Batches":xe?"Execute Withdraw":`Set ${J==="external"?"External":"Embedded"} Wallet`:"Enter Amount":"Select Token":"Wallet Not Connected":"Authentication Required":"Loading..."})})]})},vo=({isOpen:t,onClose:o,title:a="Withdraw",maxWidth:n="480px",withdrawBatches:s,externalWithdrawBatches:l,tokens:c,supportedTokens:i,depositTokenAddress:x,theme:g="light",styles:u,className:d,withdrawInputHook:A,defaultSelectedAsset:k,filterChains:I,withdrawMode:C,onWithdrawModeChange:p,externalWalletAddress:w,embeddedWalletAddress:v,onWithdrawSuccess:E,onWithdrawError:b,onComplete:m,hideWithdrawModeSelector:f,externalModeLabel:y,embeddedModeLabel:h,subtitle:S})=>{const M=ce.createTheme(g),Z=_=>{E?.(_),o()};return e.jsx(rt,{isOpen:t,onClose:o,title:a,subtitle:S!==void 0?S:e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"5px",backgroundColor:"#f9fafb",border:"1px solid #ed6969",borderRadius:"8px",padding:"10px",margin:"0 0 0 0"},children:[e.jsx("img",{src:Qt,alt:"Info",style:{width:"14px",height:"14px",marginTop:"2px",flexShrink:0}}),e.jsx("p",{style:{fontSize:"13px",color:"#374151",margin:0,lineHeight:"1.5"},children:f?"Withdraw your vault tokens to your external wallet.":"Withdraw your vault tokens to your external or embedded wallet."})]}),styles:u,theme:M,maxWidth:n,children:e.jsx("div",{style:{padding:"0 24px 24px 24px"},children:e.jsx(bs,{withdrawBatches:s,externalWithdrawBatches:l,tokens:c,supportedTokens:i,depositTokenAddress:x,theme:g,styles:{...u,container:{...u?.container,boxShadow:"none",borderColor:"transparent",padding:"0",backgroundColor:"transparent"}},className:d,withdrawInputHook:A,defaultSelectedAsset:k,filterChains:I,withdrawMode:C,onWithdrawModeChange:p,hideWithdrawModeSelector:f,externalWalletAddress:w,embeddedWalletAddress:v,onWithdrawSuccess:Z,onWithdrawError:b,onComplete:m,externalModeLabel:y,embeddedModeLabel:h})})})};/**
|
|
69
|
+
`})]}),G&&e.jsx(gs,{message:G.message,type:G.type,linkText:G.linkText,linkUrl:G.linkUrl,onClose:()=>U(null)})]})},bs=({withdrawBatches:t,externalWithdrawBatches:o,tokens:a,supportedTokens:n,theme:s="light",styles:l,className:c="",withdrawInputHook:i,defaultSelectedAsset:x,filterChains:g,withdrawMode:u="external",depositTokenAddress:d,onWithdrawModeChange:A,externalWalletAddress:k,embeddedWalletAddress:I,onWithdrawSuccess:C,onWithdrawError:p,onComplete:w,hideWithdrawModeSelector:v=!1,externalModeLabel:E="External Wallet",embeddedModeLabel:b="Embedded Wallet"})=>{const m=[{id:"external",label:E},{id:"embedded",label:b}],f=ce.createTheme(s),y={...f,typography:{...f.typography,fontFamily:l?.fontFamily||f.typography.fontFamily},colors:{...f.colors,primary:l?.primaryColor||f.colors.primary,primaryHover:l?.primaryColor?`${l.primaryColor}dd`:f.colors.primaryHover}},h=Mt(),{isReady:S,isAuthenticated:M,isConnected:Z,address:_,provider:$,actions:ee}=h,[W,T]=r.useState(()=>x?{asset:x,amount:""}:null),[K,F]=r.useState([]),[G,U]=r.useState(!1),[X,j]=r.useState(null),oe=r.useRef(!1),te=r.useRef(!1),se=I,ie=r.useMemo(()=>!a||a.length===0?[]:!n||n.length===0?a:a.filter(H=>n.some(re=>re.toLowerCase()===H.symbol.toLowerCase())),[a,n]),Y=ie?JSON.stringify(ie.map(H=>`${H.address}-${H.chainId}`).sort()):"",q=r.useCallback(async(H=!1)=>{if(!te.current){if(!ie||ie.length===0||!se){F([]),oe.current=!1;return}te.current=!0,!oe.current&&!H&&U(!0),j(null);try{const re=await Promise.all(ie.map(async ue=>{try{const ve=await Te(ue.chainId).readContract({address:ue.address,abi:de.erc20Abi,functionName:"balanceOf",args:[se]}),Xe=parseFloat(de.formatUnits(ve,ue.decimals));return{address:ue.address,symbol:ue.symbol,name:ue.name,decimals:ue.decimals,chainId:ue.chainId,balance:ve,balanceFormatted:Xe,balanceUsd:0,isNative:!1,logoURI:ue.logoURI}}catch(ve){return console.error(`Failed to fetch balance for ${ue.symbol}:`,ve),{address:ue.address,symbol:ue.symbol,name:ue.name,decimals:ue.decimals,chainId:ue.chainId,balance:BigInt(0),balanceFormatted:0,balanceUsd:0,isNative:!1,logoURI:ue.logoURI}}}));F(re),oe.current=!0}catch(re){console.error("Failed to fetch token balances:",re),j(re instanceof Error?re.message:"Failed to fetch token balances"),oe.current||F([])}finally{U(!1),te.current=!1}}},[Y,se]);r.useEffect(()=>{se&&ie.length>0&&(oe.current=!1,q(!1))},[Y,se]),r.useEffect(()=>{if(!ie.length||!se)return;const H=setInterval(()=>{q(!0)},3e4);return()=>clearInterval(H)},[Y,se]),K.some(H=>H.balanceFormatted>0);const[pe,ne]=r.useState(!1),[Fe,Se]=r.useState(null),[we,me]=r.useState(!1),[Ie,Ne]=r.useState(!1),[Qe,B]=r.useState(!1),[J,ye]=r.useState(u),[L,V]=r.useState(null),[O,ae]=r.useState(null),le=r.useRef(null),xe=r.useMemo(()=>J==="external"?k:I,[J,k,I]),R=r.useCallback(H=>{ye(H),A?.(H)},[A]),{intentStatus:Q,startStatusPolling:he,clearStatus:fe}=It({checkStepStatus:(H,re)=>ke.checkStepStatus(H,re)});r.useEffect(()=>{if(Q?.overallStatus==="success"&&Q.intentId&&le.current!==Q.intentId&&W&&_){const H=Q.steps.find(re=>re.transactionHash);if(H?.transactionHash)if(le.current=Q.intentId,J==="embedded"){const re=de.parseUnits(W.amount,W.asset.decimals),ue={user:_,txHash:H.transactionHash,sender:_,tokenAddress:d||W.asset.address,chainId:W.asset.chainId,amount:re.toString(),isDeposit:!0};console.log("[WithdrawWidget] Submitting spice deposit for embedded withdraw:",ue),ke.submitSpiceDeposit(ue).then(ve=>{console.log("[WithdrawWidget] Spice deposit submitted successfully:",ve),q()}).catch(ve=>{console.error("[WithdrawWidget] Spice deposit submission failed:",ve),le.current=null})}else q()}},[Q,_,J,W,d]),r.useEffect(()=>{i&&i.assetAmount!==W?.amount&&W&&T({...W,amount:i.assetAmount})},[i?.assetAmount,W]);const Ve=r.useCallback(()=>{Se(null)},[]),He=H=>{T({asset:H,amount:W?.amount||""}),Ve()},tt=r.useCallback(H=>{W&&(r.startTransition(()=>{T({...W,amount:H}),Ve()}),i&&i.setAssetAmount(H))},[W,i,Ve]),Ge=async()=>{if(!(!W||!_||t.length===0)){if(!xe){Se(`Please provide a ${J==="external"?"external":"embedded"} wallet address`);return}if(!S||!M){Se(`Please authenticate with ${$||"wallet provider"} to continue`);return}ne(!0),Se(null),B(!0);try{const H=J==="external"&&o?[...t,...o]:[...t],re=[...new Set(H.map(D=>D.chainId))],ue=[];for(const D of re){const z=Te(D),ge=pt(D),be=await Je.getAccountNonce(_,z),Ee=await ee.signAuthorization({contractAddress:ge,chainId:D,nonce:Number(be)});ue.push(Ee)}const ve=Je.hashChainBatches(H),Xe=Math.floor(Date.now()/1e3)+60*10,Tt=Je.getIntentHash(0n,BigInt(Xe),ve),ft=await ee.signMessage({raw:Tt}),Rt=typeof ft=="string"?ft:ft.signature;if(!Rt)throw new Error("Failed to sign intent authorization");const zt={from:"solver",to:_,token:"0x0000000000000000000000000000000000000000",amount:de.parseUnits("0.00001",18)},N={mode:"7702",signatureType:"ecdsa",signature:Rt,nbf:0,exp:Xe,chainBatches:ve.map((D,z)=>{const ge=H[z],be=ge?.tokenTransfers??[],Ee=ge?.calls&&ge.calls.length>0;return{hash:D.hash,chainId:D.chainId,tokenTransfers:Ee?[zt,...be]:be,calls:D.calls}})},P=await ke.createAction({user:_,chainAuthorizations:ue.map(D=>({...D,r:D.r,s:D.s,yParity:D.yParity,address:D.address,chainId:Number(D.chainId),nonce:Number(D.nonce)})),intents:[N]});if(P){const D=jt(H,Ee=>`Chain ${Ee}`),[z,ge]=P.intentIds[0].split("/"),be=parseInt(ge||"0",10);he(P.intentIds[0],D);for(let Ee=0;Ee<H.length;Ee++)await ke.executeStep(z,be,Ee,{action:"execute"});window.dispatchEvent(new CustomEvent("withdraw-completed"))}}catch(H){const re=H instanceof Error?H.message:"Withdraw failed";Se(re),p?.(re)}finally{ne(!1)}}},Oe=r.useMemo(()=>{let H=K;return g&&g.length>0&&(H=H.filter(re=>g.includes(re.chainId))),H},[K,g]),Ye=W&&W.amount&&parseFloat(W.amount)>0&&parseFloat(W.amount)<=W.asset.balanceFormatted&&Z&&!pe&&t.length>0&&!!xe,ot=X||Fe,it={backgroundColor:l?.container?.backgroundColor||l?.primaryBackground||y.colors.background,border:`1px solid ${l?.container?.borderColor||y.colors.border}`,borderRadius:l?.container?.borderRadius||y.borderRadius.lg,padding:l?.container?.padding||y.spacing.md,width:l?.container?.width||"100%",maxWidth:"28rem",minHeight:"200px",margin:"0 auto",color:y.colors.text,fontFamily:y.typography.fontFamily,boxShadow:l?.container?.boxShadow||(y.mode==="light"?"0 4px 6px -1px rgb(0 0 0 / 0.1)":"0 4px 6px -1px rgb(0 0 0 / 0.3)")},Ke=Q?e.jsx(Zt,{type:"withdraw",isOpen:!!Q&&Q.overallStatus!=="processing",isProcessing:pe||Q?.overallStatus==="processing",onRetryTx:()=>{fe(),B(!1),Ge()},onNewTx:()=>{fe(),B(!1),T(null),le.current=null,q()},onClose:()=>{fe(),B(!1)},onComplete:()=>{fe(),B(!1),T(null),le.current=null,q(),w?.()},results:Q?.overallStatus==="success"||Q?.overallStatus==="failed"?(()=>{if((o?[...t,...o]:t).length>1&&Q.steps.length>1){const H=Q.steps.find(re=>re.transactionHash);return[{asset:{symbol:W?.asset.symbol||"Token",address:W?.asset.address||""},txHash:H?.transactionHash||"",success:Q.steps.every(re=>re.status==="success"),amount:W?.amount}]}return Q.steps.map(H=>({asset:{symbol:W?.asset.symbol||"Token",address:W?.asset.address||""},txHash:H.transactionHash||"",success:H.status==="success",amount:W?.amount}))})():void 0,chainName:W?(()=>{const H=o?[...t,...o]:t,re=[...new Set(H.map(ue=>st(ue.chainId)))];return re.length>1?re.join(" and "):re[0]||"Network"})():"Network",explorerUrl:W?wt(t[t.length-1].chainId,"").replace(/\/tx\/.*$/,""):void 0,theme:y}):null;return e.jsxs("div",{style:{...it,position:"relative"},className:c,children:[Ke&&e.jsx("div",{style:{position:"absolute",top:0,left:"-25px",right:"-25px",bottom:"-16px"},children:e.jsx("div",{style:{position:"absolute",width:"100%",height:"100%",pointerEvents:"auto"},children:Ke})}),!v&&e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"6px",marginBottom:"10px"},children:e.jsx("label",{style:{fontSize:"12px",fontWeight:590,color:y.mode==="light"?"#374151":"#d1d5db"},children:"Withdraw To"})}),e.jsx("div",{style:{display:"flex",gap:"12px",flexWrap:"wrap"},children:m.map(H=>{const re=J===H.id,ue=H.id==="external"?k:I,ve=ue?`${ue.slice(0,6)}...${ue.slice(-4)}`:null;return e.jsxs("button",{onClick:()=>R(H.id),onMouseEnter:()=>V(H.id),onMouseLeave:()=>{V(null),ae(null)},onMouseDown:()=>ae(H.id),onMouseUp:()=>ae(null),style:{padding:"8px 12px",borderRadius:"8px",border:`1px solid ${re?"#EA4B4B7A":L===H.id?"#F4A5A5":y.mode==="light"?"#e5e7eb":"#374151"}`,backgroundColor:re?y.mode==="light"?"#FEF2F2":"#451a1a":O===H.id?y.mode==="light"?"#f5f5f5":"#2d2d2d":L===H.id?y.mode==="light"?"#fafafa":"#333333":y.mode==="light"?"white":"#1f1f1f",cursor:"pointer",display:"flex",flexDirection:"column",alignItems:"flex-start",gap:"4px",transition:"all 150ms ease",transform:O===H.id?"scale(0.96)":L===H.id?"translateY(-1px)":"none",boxShadow:re?"0 0 0 3px #FBDBDB":O===H.id?"0 1px 2px rgba(0, 0, 0, 0.05)":L===H.id?"0 4px 8px rgba(0, 0, 0, 0.1)":"none"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:510,color:y.mode==="light"?"#3C3E42":"#e5e7eb"},children:H.label}),ve&&e.jsx("span",{style:{fontSize:"10px",fontWeight:500,color:y.mode==="light"?"#939291":"#6b7280",fontFamily:'"IBM Plex Mono", monospace'},children:ve})]},H.id)})})]}),e.jsx("div",{style:{marginBottom:y.spacing.sm},children:e.jsx(xt,{assets:Oe,selectedAsset:W||void 0,onAssetSelect:He,onAmountChange:tt,loading:G,label:"Amount",showBalance:!0,showMaxButton:!0,theme:y,styles:l})}),ot&&e.jsx("div",{style:{backgroundColor:l?.errorMessage?.backgroundColor||(y.mode==="light"?"#fef2f2":`${l?.statusDisplay?.errorColor||y.colors.error}20`),border:`1px solid ${l?.errorMessage?.borderColor||(y.mode==="light"?"#fecaca":l?.statusDisplay?.errorColor||y.colors.error)}`,borderRadius:l?.errorMessage?.borderRadius||y.borderRadius.md,padding:l?.errorMessage?.padding||y.spacing.md,marginBottom:y.spacing.sm},children:e.jsx("p",{style:{color:l?.errorMessage?.color||l?.statusDisplay?.errorColor||y.colors.error,fontSize:l?.errorMessage?.fontSize||y.typography.fontSize.sm,fontWeight:l?.errorMessage?.fontWeight,fontFamily:l?.errorMessage?.fontFamily||y.typography.fontFamily,margin:0},children:ot})}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:y.spacing.sm},children:e.jsx(ce.Button,{variant:"outline",fullWidth:!0,onClick:Ge,onMouseEnter:()=>me(!0),onMouseLeave:()=>{me(!1),Ne(!1)},onMouseDown:()=>Ne(!0),onMouseUp:()=>Ne(!1),loading:pe,disabled:!Ye||!Z,theme:y,styles:l,style:{width:"100%",padding:"8px",backgroundColor:Ye?Ie?"#d43d3d":we?"#f05555":"#ea4b4b":"#d1d5db",color:Ye?"#0e0d0b":"#6b7280",border:"1px solid #0e0d0b",fontWeight:500,fontSize:"18px",fontFamily:'"IBM Plex Mono", monospace',lineHeight:"156%",textTransform:"uppercase",cursor:Ye?"pointer":"not-allowed",marginTop:"20px",display:"flex",alignItems:"center",justifyContent:"center",gap:"10px",transition:"all 150ms ease",transform:Ye?Ie?"scale(0.98)":we?"translateY(-2px)":"none":"none",boxShadow:Ie?"1px 1px 0px black":we&&Ye?"5px 5px 0px white, 6px 6px 0px black":"3px 3px 0px white, 4px 4px 0px black"},children:S?M?Z?pe?"Executing Withdraw...":W?W.amount?parseFloat(W.amount)>W.asset.balanceFormatted?"Insufficient Balance":t.length===0?"No Withdraw Batches":xe?"Execute Withdraw":`Set ${J==="external"?"External":"Embedded"} Wallet`:"Enter Amount":"Select Token":"Wallet Not Connected":"Authentication Required":"Loading..."})})]})},vo=({isOpen:t,onClose:o,title:a="Withdraw",maxWidth:n="480px",withdrawBatches:s,externalWithdrawBatches:l,tokens:c,supportedTokens:i,depositTokenAddress:x,theme:g="light",styles:u,className:d,withdrawInputHook:A,defaultSelectedAsset:k,filterChains:I,withdrawMode:C,onWithdrawModeChange:p,externalWalletAddress:w,embeddedWalletAddress:v,onWithdrawSuccess:E,onWithdrawError:b,onComplete:m,hideWithdrawModeSelector:f,externalModeLabel:y,embeddedModeLabel:h,subtitle:S})=>{const M=ce.createTheme(g),Z=_=>{E?.(_),o()};return e.jsx(rt,{isOpen:t,onClose:o,title:a,subtitle:S!==void 0?S:e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"5px",backgroundColor:"#f9fafb",border:"1px solid #ed6969",borderRadius:"8px",padding:"10px",margin:"0 0 0 0"},children:[e.jsx("img",{src:Qt,alt:"Info",style:{width:"14px",height:"14px",marginTop:"2px",flexShrink:0}}),e.jsx("p",{style:{fontSize:"13px",color:"#374151",margin:0,lineHeight:"1.5"},children:C==="external"?"Withdraw your vault tokens to your external wallet.":"Withdraw your vault tokens to your cross-chain balance."})]}),styles:u,theme:M,maxWidth:n,children:e.jsx("div",{style:{padding:"0 24px 24px 24px"},children:e.jsx(bs,{withdrawBatches:s,externalWithdrawBatches:l,tokens:c,supportedTokens:i,depositTokenAddress:x,theme:g,styles:{...u,container:{...u?.container,boxShadow:"none",borderColor:"transparent",padding:"0",backgroundColor:"transparent"}},className:d,withdrawInputHook:A,defaultSelectedAsset:k,filterChains:I,withdrawMode:C,onWithdrawModeChange:p,hideWithdrawModeSelector:f,externalWalletAddress:w,embeddedWalletAddress:v,onWithdrawSuccess:Z,onWithdrawError:b,onComplete:m,externalModeLabel:y,embeddedModeLabel:h})})})};/**
|
|
70
70
|
* @license lucide-react v0.562.0 - ISC
|
|
71
71
|
*
|
|
72
72
|
* This source code is licensed under the ISC license.
|
package/dist/index.js
CHANGED
|
@@ -44,7 +44,7 @@ import{defineChain as xo,createPublicClient as bo,http as Co,isAddress as oo,get
|
|
|
44
44
|
from { transform: rotate(0deg); }
|
|
45
45
|
to { transform: rotate(360deg); }
|
|
46
46
|
}
|
|
47
|
-
`}),!A&&a&&a.length>1&&e("div",{style:{overflow:"hidden",maxHeight:E?"200px":"0px",opacity:E?1:0,transition:"max-height 0.3s ease, opacity 0.3s ease",marginBottom:E?"16px":"0"},children:e("div",{style:{maxHeight:"180px",overflowY:"auto",display:"flex",flexDirection:"column",gap:"8px"},children:a.map((_,oe)=>l("div",{style:{padding:"10px 12px",borderRadius:"6px",backgroundColor:"#f9fafb",border:"1px solid #e5e7eb",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[l("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e("span",{style:{fontWeight:600,fontSize:"13px",color:"#111827",fontFamily:'"IBM Plex Mono", monospace'},children:_.asset.symbol}),_.amount&&e("span",{style:{fontSize:"12px",color:"#6b7280"},children:_.amount})]}),e("span",{style:{fontSize:"12px",color:_.success?"#10b981":"#ef4444",fontWeight:500},children:_.success?"\u2713":"\u2717"})]},oe))})}),!A&&!G&&a&&e("div",{style:{padding:"12px",backgroundColor:"#fef2f2",border:"1px solid #fecaca",borderRadius:"8px",marginBottom:"16px"},children:e("p",{style:{fontSize:"13px",color:"#dc2626",margin:0,lineHeight:1.5},children:a.find(_=>!_.success)?.error||`${o.charAt(0).toUpperCase()+o.slice(1)} failed. Please try again.`})}),!A&&l("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[!G&&S&&l("button",{onClick:S,onMouseEnter:()=>m("retry-tx"),onMouseLeave:()=>{m(null),h(null)},onMouseDown:()=>h("retry-tx"),onMouseUp:()=>h(null),style:{width:"100%",height:"48px",padding:"14px 24px",borderRadius:"6px",backgroundColor:b==="retry-tx"?"#d43d3d":x==="retry-tx"?"#f05555":"#ea4b4b",border:"1px solid #0e0d0b",color:"#0e0d0b",fontFamily:'"IBM Plex Mono", monospace',fontWeight:500,fontSize:"16px",lineHeight:"156%",textTransform:"uppercase",cursor:"pointer",transition:"all 0.15s ease",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",transform:b==="retry-results"?"scale(0.98)":x==="retry-results"?"translateY(-2px)":"none",boxShadow:b==="retry-tx"?"1px 1px 0px black":x==="retry-tx"?"5px 5px 0px white, 6px 6px 0px black":"3px 3px 0px white, 4px 4px 0px black"},children:["TRY AGAIN
|
|
47
|
+
`}),!A&&a&&a.length>1&&e("div",{style:{overflow:"hidden",maxHeight:E?"200px":"0px",opacity:E?1:0,transition:"max-height 0.3s ease, opacity 0.3s ease",marginBottom:E?"16px":"0"},children:e("div",{style:{maxHeight:"180px",overflowY:"auto",display:"flex",flexDirection:"column",gap:"8px"},children:a.map((_,oe)=>l("div",{style:{padding:"10px 12px",borderRadius:"6px",backgroundColor:"#f9fafb",border:"1px solid #e5e7eb",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[l("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e("span",{style:{fontWeight:600,fontSize:"13px",color:"#111827",fontFamily:'"IBM Plex Mono", monospace'},children:_.asset.symbol}),_.amount&&e("span",{style:{fontSize:"12px",color:"#6b7280"},children:_.amount})]}),e("span",{style:{fontSize:"12px",color:_.success?"#10b981":"#ef4444",fontWeight:500},children:_.success?"\u2713":"\u2717"})]},oe))})}),!A&&!G&&a&&e("div",{style:{padding:"12px",backgroundColor:"#fef2f2",border:"1px solid #fecaca",borderRadius:"8px",marginBottom:"16px"},children:e("p",{style:{fontSize:"13px",color:"#dc2626",margin:0,lineHeight:1.5},children:a.find(_=>!_.success)?.error||`${o.charAt(0).toUpperCase()+o.slice(1)} failed. Please try again.`})}),!A&&l("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[!G&&S&&l("button",{onClick:S,onMouseEnter:()=>m("retry-tx"),onMouseLeave:()=>{m(null),h(null)},onMouseDown:()=>h("retry-tx"),onMouseUp:()=>h(null),style:{width:"100%",height:"48px",padding:"14px 24px",borderRadius:"6px",backgroundColor:b==="retry-tx"?"#d43d3d":x==="retry-tx"?"#f05555":"#ea4b4b",border:"1px solid #0e0d0b",color:"#0e0d0b",fontFamily:'"IBM Plex Mono", monospace',fontWeight:500,fontSize:"16px",lineHeight:"156%",textTransform:"uppercase",cursor:"pointer",transition:"all 0.15s ease",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",transform:b==="retry-results"?"scale(0.98)":x==="retry-results"?"translateY(-2px)":"none",boxShadow:b==="retry-tx"?"1px 1px 0px black":x==="retry-tx"?"5px 5px 0px white, 6px 6px 0px black":"3px 3px 0px white, 4px 4px 0px black"},children:["TRY AGAIN ",o]}),G&&e("button",{onClick:I,onMouseEnter:()=>m("continue-tx"),onMouseLeave:()=>{m(null),h(null)},onMouseDown:()=>h("continue-tx"),onMouseUp:()=>h(null),style:{width:"100%",height:"48px",padding:"14px 24px",borderRadius:"6px",backgroundColor:b==="continue-tx"?"#d43d3d":x==="continue-tx"?"#f05555":"#ea4b4b",border:"1px solid #0e0d0b",color:"#0e0d0b",fontFamily:'"IBM Plex Mono", monospace',fontWeight:500,fontSize:"16px",lineHeight:"156%",textTransform:"uppercase",cursor:"pointer",transition:"all 0.15s ease",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",transform:b==="continue-tx"?"scale(0.98)":x==="continue-tx"?"translateY(-2px)":"none",boxShadow:b==="continue-tx"?"1px 1px 0px black":x==="continue-results"?"5px 5px 0px white, 6px 6px 0px black":"3px 3px 0px white, 4px 4px 0px black"},children:"DONE"})]})]}),e("style",{children:`
|
|
48
48
|
@keyframes slideUp {
|
|
49
49
|
from {
|
|
50
50
|
transform: translateY(100%);
|
|
@@ -66,7 +66,7 @@ import{defineChain as xo,createPublicClient as bo,http as Co,isAddress as oo,get
|
|
|
66
66
|
from { transform: rotate(0deg); }
|
|
67
67
|
to { transform: rotate(360deg); }
|
|
68
68
|
}
|
|
69
|
-
`})]}),O&&e(No,{message:O.message,type:O.type,linkText:O.linkText,linkUrl:O.linkUrl,onClose:()=>z(null)})]})},Po=({withdrawBatches:t,externalWithdrawBatches:n,tokens:i,supportedTokens:r,theme:o="light",styles:a,className:c="",withdrawInputHook:s,defaultSelectedAsset:g,filterChains:f,withdrawMode:u="external",depositTokenAddress:d,onWithdrawModeChange:w,externalWalletAddress:S,embeddedWalletAddress:F,onWithdrawSuccess:A,onWithdrawError:p,onComplete:k,hideWithdrawModeSelector:B=!1,externalModeLabel:E="External Wallet",embeddedModeLabel:C="Embedded Wallet"})=>{const x=[{id:"external",label:E},{id:"embedded",label:C}],m=De(o),b={...m,typography:{...m.typography,fontFamily:a?.fontFamily||m.typography.fontFamily},colors:{...m.colors,primary:a?.primaryColor||m.colors.primary,primaryHover:a?.primaryColor?`${a.primaryColor}dd`:m.colors.primaryHover}},h=Gt(),{isReady:I,isAuthenticated:H,isConnected:G,address:te,provider:_,actions:oe}=h,[D,V]=y(()=>g?{asset:g,amount:""}:null),[X,v]=y([]),[O,z]=y(!1),[$,W]=y(null),se=Re(!1),re=Re(!1),ie=F,ce=Ae(()=>!i||i.length===0?[]:!r||r.length===0?i:i.filter(T=>r.some(le=>le.toLowerCase()===T.symbol.toLowerCase())),[i,r]),j=ce?JSON.stringify(ce.map(T=>`${T.address}-${T.chainId}`).sort()):"",P=ne(async(T=!1)=>{if(!re.current){if(!ce||ce.length===0||!ie){v([]),se.current=!1;return}re.current=!0,!se.current&&!T&&z(!0),W(null);try{const le=await Promise.all(ce.map(async he=>{try{const Be=await je(he.chainId).readContract({address:he.address,abi:Yt,functionName:"balanceOf",args:[ie]}),nt=parseFloat(fn(Be,he.decimals));return{address:he.address,symbol:he.symbol,name:he.name,decimals:he.decimals,chainId:he.chainId,balance:Be,balanceFormatted:nt,balanceUsd:0,isNative:!1,logoURI:he.logoURI}}catch(Be){return console.error(`Failed to fetch balance for ${he.symbol}:`,Be),{address:he.address,symbol:he.symbol,name:he.name,decimals:he.decimals,chainId:he.chainId,balance:BigInt(0),balanceFormatted:0,balanceUsd:0,isNative:!1,logoURI:he.logoURI}}}));v(le),se.current=!0}catch(le){console.error("Failed to fetch token balances:",le),W(le instanceof Error?le.message:"Failed to fetch token balances"),se.current||v([])}finally{z(!1),re.current=!1}}},[j,ie]);ee(()=>{ie&&ce.length>0&&(se.current=!1,P(!1))},[j,ie]),ee(()=>{if(!ce.length||!ie)return;const T=setInterval(()=>{P(!0)},3e4);return()=>clearInterval(T)},[j,ie]),X.some(T=>T.balanceFormatted>0);const[ue,ae]=y(!1),[ve,Ie]=y(null),[ke,xe]=y(!1),[Fe,Ze]=y(!1),[Ve,R]=y(!1),[Z,be]=y(u),[Q,Y]=y(null),[K,de]=y(null),pe=Re(null),fe=Ae(()=>Z==="external"?S:F,[Z,S,F]),L=ne(T=>{be(T),w?.(T)},[w]),{intentStatus:U,startStatusPolling:ge,clearStatus:ye}=Lt({checkStepStatus:(T,le)=>Se.checkStepStatus(T,le)});ee(()=>{if(U?.overallStatus==="success"&&U.intentId&&pe.current!==U.intentId&&D&&te){const T=U.steps.find(le=>le.transactionHash);if(T?.transactionHash)if(pe.current=U.intentId,Z==="embedded"){const le=Ke(D.amount,D.asset.decimals),he={user:te,txHash:T.transactionHash,sender:te,tokenAddress:d||D.asset.address,chainId:D.asset.chainId,amount:le.toString(),isDeposit:!0};console.log("[WithdrawWidget] Submitting spice deposit for embedded withdraw:",he),Se.submitSpiceDeposit(he).then(Be=>{console.log("[WithdrawWidget] Spice deposit submitted successfully:",Be),P()}).catch(Be=>{console.error("[WithdrawWidget] Spice deposit submission failed:",Be),pe.current=null})}else P()}},[U,te,Z,D,d]),ee(()=>{s&&s.assetAmount!==D?.amount&&D&&V({...D,amount:s.assetAmount})},[s?.assetAmount,D]);const Je=ne(()=>{Ie(null)},[]),Ne=T=>{V({asset:T,amount:D?.amount||""}),Je()},at=ne(T=>{D&&(Io(()=>{V({...D,amount:T}),Je()}),s&&s.setAssetAmount(T))},[D,s,Je]),et=async()=>{if(!(!D||!te||t.length===0)){if(!fe){Ie(`Please provide a ${Z==="external"?"external":"embedded"} wallet address`);return}if(!I||!H){Ie(`Please authenticate with ${_||"wallet provider"} to continue`);return}ae(!0),Ie(null),R(!0);try{const T=Z==="external"&&n?[...t,...n]:[...t],le=[...new Set(T.map(M=>M.chainId))],he=[];for(const M of le){const N=je(M),me=yt(M),Ce=await qt(te,N),Ee=await oe.signAuthorization({contractAddress:me,chainId:M,nonce:Number(Ce)});he.push(Ee)}const Be=jt(T),nt=Math.floor(Date.now()/1e3)+60*10,$t=Pt(0n,BigInt(nt),Be),wt=await oe.signMessage({raw:$t}),Vt=typeof wt=="string"?wt:wt.signature;if(!Vt)throw new Error("Failed to sign intent authorization");const _t={from:"solver",to:te,token:"0x0000000000000000000000000000000000000000",amount:Ke("0.00001",18)},q={mode:"7702",signatureType:"ecdsa",signature:Vt,nbf:0,exp:nt,chainBatches:Be.map((M,N)=>{const me=T[N],Ce=me?.tokenTransfers??[],Ee=me?.calls&&me.calls.length>0;return{hash:M.hash,chainId:M.chainId,tokenTransfers:Ee?[_t,...Ce]:Ce,calls:M.calls}})},J=await Se.createAction({user:te,chainAuthorizations:he.map(M=>({...M,r:M.r,s:M.s,yParity:M.yParity,address:M.address,chainId:Number(M.chainId),nonce:Number(M.nonce)})),intents:[q]});if(J){const M=Ut(T,Ee=>`Chain ${Ee}`),[N,me]=J.intentIds[0].split("/"),Ce=parseInt(me||"0",10);ge(J.intentIds[0],M);for(let Ee=0;Ee<T.length;Ee++)await Se.executeStep(N,Ce,Ee,{action:"execute"});window.dispatchEvent(new CustomEvent("withdraw-completed"))}}catch(T){const le=T instanceof Error?T.message:"Withdraw failed";Ie(le),p?.(le)}finally{ae(!1)}}},tt=Ae(()=>{let T=X;return f&&f.length>0&&(T=T.filter(le=>f.includes(le.chainId))),T},[X,f]),Ge=D&&D.amount&&parseFloat(D.amount)>0&&parseFloat(D.amount)<=D.asset.balanceFormatted&&G&&!ue&&t.length>0&&!!fe,dt=$||ve,gt={backgroundColor:a?.container?.backgroundColor||a?.primaryBackground||b.colors.background,border:`1px solid ${a?.container?.borderColor||b.colors.border}`,borderRadius:a?.container?.borderRadius||b.borderRadius.lg,padding:a?.container?.padding||b.spacing.md,width:a?.container?.width||"100%",maxWidth:"28rem",minHeight:"200px",margin:"0 auto",color:b.colors.text,fontFamily:b.typography.fontFamily,boxShadow:a?.container?.boxShadow||(b.mode==="light"?"0 4px 6px -1px rgb(0 0 0 / 0.1)":"0 4px 6px -1px rgb(0 0 0 / 0.3)")},ot=U?e(po,{type:"withdraw",isOpen:!!U&&U.overallStatus!=="processing",isProcessing:ue||U?.overallStatus==="processing",onRetryTx:()=>{ye(),R(!1),et()},onNewTx:()=>{ye(),R(!1),V(null),pe.current=null,P()},onClose:()=>{ye(),R(!1)},onComplete:()=>{ye(),R(!1),V(null),pe.current=null,P(),k?.()},results:U?.overallStatus==="success"||U?.overallStatus==="failed"?(()=>{if((n?[...t,...n]:t).length>1&&U.steps.length>1){const T=U.steps.find(le=>le.transactionHash);return[{asset:{symbol:D?.asset.symbol||"Token",address:D?.asset.address||""},txHash:T?.transactionHash||"",success:U.steps.every(le=>le.status==="success"),amount:D?.amount}]}return U.steps.map(T=>({asset:{symbol:D?.asset.symbol||"Token",address:D?.asset.address||""},txHash:T.transactionHash||"",success:T.status==="success",amount:D?.amount}))})():void 0,chainName:D?(()=>{const T=n?[...t,...n]:t,le=[...new Set(T.map(he=>lt(he.chainId)))];return le.length>1?le.join(" and "):le[0]||"Network"})():"Network",explorerUrl:D?Wt(t[t.length-1].chainId,"").replace(/\/tx\/.*$/,""):void 0,theme:b}):null;return l("div",{style:{...gt,position:"relative"},className:c,children:[ot&&e("div",{style:{position:"absolute",top:0,left:"-25px",right:"-25px",bottom:"-16px"},children:e("div",{style:{position:"absolute",width:"100%",height:"100%",pointerEvents:"auto"},children:ot})}),!B&&l("div",{style:{marginBottom:"16px"},children:[e("div",{style:{display:"flex",alignItems:"center",gap:"6px",marginBottom:"10px"},children:e("label",{style:{fontSize:"12px",fontWeight:590,color:b.mode==="light"?"#374151":"#d1d5db"},children:"Withdraw To"})}),e("div",{style:{display:"flex",gap:"12px",flexWrap:"wrap"},children:x.map(T=>{const le=Z===T.id,he=T.id==="external"?S:F,Be=he?`${he.slice(0,6)}...${he.slice(-4)}`:null;return l("button",{onClick:()=>L(T.id),onMouseEnter:()=>Y(T.id),onMouseLeave:()=>{Y(null),de(null)},onMouseDown:()=>de(T.id),onMouseUp:()=>de(null),style:{padding:"8px 12px",borderRadius:"8px",border:`1px solid ${le?"#EA4B4B7A":Q===T.id?"#F4A5A5":b.mode==="light"?"#e5e7eb":"#374151"}`,backgroundColor:le?b.mode==="light"?"#FEF2F2":"#451a1a":K===T.id?b.mode==="light"?"#f5f5f5":"#2d2d2d":Q===T.id?b.mode==="light"?"#fafafa":"#333333":b.mode==="light"?"white":"#1f1f1f",cursor:"pointer",display:"flex",flexDirection:"column",alignItems:"flex-start",gap:"4px",transition:"all 150ms ease",transform:K===T.id?"scale(0.96)":Q===T.id?"translateY(-1px)":"none",boxShadow:le?"0 0 0 3px #FBDBDB":K===T.id?"0 1px 2px rgba(0, 0, 0, 0.05)":Q===T.id?"0 4px 8px rgba(0, 0, 0, 0.1)":"none"},children:[e("span",{style:{fontSize:"14px",fontWeight:510,color:b.mode==="light"?"#3C3E42":"#e5e7eb"},children:T.label}),Be&&e("span",{style:{fontSize:"10px",fontWeight:500,color:b.mode==="light"?"#939291":"#6b7280",fontFamily:'"IBM Plex Mono", monospace'},children:Be})]},T.id)})})]}),e("div",{style:{marginBottom:b.spacing.sm},children:e(Ct,{assets:tt,selectedAsset:D||void 0,onAssetSelect:Ne,onAmountChange:at,loading:O,label:"Amount",showBalance:!0,showMaxButton:!0,theme:b,styles:a})}),dt&&e("div",{style:{backgroundColor:a?.errorMessage?.backgroundColor||(b.mode==="light"?"#fef2f2":`${a?.statusDisplay?.errorColor||b.colors.error}20`),border:`1px solid ${a?.errorMessage?.borderColor||(b.mode==="light"?"#fecaca":a?.statusDisplay?.errorColor||b.colors.error)}`,borderRadius:a?.errorMessage?.borderRadius||b.borderRadius.md,padding:a?.errorMessage?.padding||b.spacing.md,marginBottom:b.spacing.sm},children:e("p",{style:{color:a?.errorMessage?.color||a?.statusDisplay?.errorColor||b.colors.error,fontSize:a?.errorMessage?.fontSize||b.typography.fontSize.sm,fontWeight:a?.errorMessage?.fontWeight,fontFamily:a?.errorMessage?.fontFamily||b.typography.fontFamily,margin:0},children:dt})}),e("div",{style:{display:"flex",flexDirection:"column",gap:b.spacing.sm},children:e(Me,{variant:"outline",fullWidth:!0,onClick:et,onMouseEnter:()=>xe(!0),onMouseLeave:()=>{xe(!1),Ze(!1)},onMouseDown:()=>Ze(!0),onMouseUp:()=>Ze(!1),loading:ue,disabled:!Ge||!G,theme:b,styles:a,style:{width:"100%",padding:"8px",backgroundColor:Ge?Fe?"#d43d3d":ke?"#f05555":"#ea4b4b":"#d1d5db",color:Ge?"#0e0d0b":"#6b7280",border:"1px solid #0e0d0b",fontWeight:500,fontSize:"18px",fontFamily:'"IBM Plex Mono", monospace',lineHeight:"156%",textTransform:"uppercase",cursor:Ge?"pointer":"not-allowed",marginTop:"20px",display:"flex",alignItems:"center",justifyContent:"center",gap:"10px",transition:"all 150ms ease",transform:Ge?Fe?"scale(0.98)":ke?"translateY(-2px)":"none":"none",boxShadow:Fe?"1px 1px 0px black":ke&&Ge?"5px 5px 0px white, 6px 6px 0px black":"3px 3px 0px white, 4px 4px 0px black"},children:I?H?G?ue?"Executing Withdraw...":D?D.amount?parseFloat(D.amount)>D.asset.balanceFormatted?"Insufficient Balance":t.length===0?"No Withdraw Batches":fe?"Execute Withdraw":`Set ${Z==="external"?"External":"Embedded"} Wallet`:"Enter Amount":"Select Token":"Wallet Not Connected":"Authentication Required":"Loading..."})})]})},fr=({isOpen:t,onClose:n,title:i="Withdraw",maxWidth:r="480px",withdrawBatches:o,externalWithdrawBatches:a,tokens:c,supportedTokens:s,depositTokenAddress:g,theme:f="light",styles:u,className:d,withdrawInputHook:w,defaultSelectedAsset:S,filterChains:F,withdrawMode:A,onWithdrawModeChange:p,externalWalletAddress:k,embeddedWalletAddress:B,onWithdrawSuccess:E,onWithdrawError:C,onComplete:x,hideWithdrawModeSelector:m,externalModeLabel:b,embeddedModeLabel:h,subtitle:I})=>{const H=De(f),G=te=>{E?.(te),n()};return e(ut,{isOpen:t,onClose:n,title:i,subtitle:I!==void 0?I:l("div",{style:{display:"flex",alignItems:"flex-start",gap:"5px",backgroundColor:"#f9fafb",border:"1px solid #ed6969",borderRadius:"8px",padding:"10px",margin:"0 0 0 0"},children:[e("img",{src:Ot,alt:"Info",style:{width:"14px",height:"14px",marginTop:"2px",flexShrink:0}}),e("p",{style:{fontSize:"13px",color:"#374151",margin:0,lineHeight:"1.5"},children:m?"Withdraw your vault tokens to your external wallet.":"Withdraw your vault tokens to your external or embedded wallet."})]}),styles:u,theme:H,maxWidth:r,children:e("div",{style:{padding:"0 24px 24px 24px"},children:e(Po,{withdrawBatches:o,externalWithdrawBatches:a,tokens:c,supportedTokens:s,depositTokenAddress:g,theme:f,styles:{...u,container:{...u?.container,boxShadow:"none",borderColor:"transparent",padding:"0",backgroundColor:"transparent"}},className:d,withdrawInputHook:w,defaultSelectedAsset:S,filterChains:F,withdrawMode:A,onWithdrawModeChange:p,hideWithdrawModeSelector:m,externalWalletAddress:k,embeddedWalletAddress:B,onWithdrawSuccess:G,onWithdrawError:C,onComplete:x,externalModeLabel:b,embeddedModeLabel:h})})})};/**
|
|
69
|
+
`})]}),O&&e(No,{message:O.message,type:O.type,linkText:O.linkText,linkUrl:O.linkUrl,onClose:()=>z(null)})]})},Po=({withdrawBatches:t,externalWithdrawBatches:n,tokens:i,supportedTokens:r,theme:o="light",styles:a,className:c="",withdrawInputHook:s,defaultSelectedAsset:g,filterChains:f,withdrawMode:u="external",depositTokenAddress:d,onWithdrawModeChange:w,externalWalletAddress:S,embeddedWalletAddress:F,onWithdrawSuccess:A,onWithdrawError:p,onComplete:k,hideWithdrawModeSelector:B=!1,externalModeLabel:E="External Wallet",embeddedModeLabel:C="Embedded Wallet"})=>{const x=[{id:"external",label:E},{id:"embedded",label:C}],m=De(o),b={...m,typography:{...m.typography,fontFamily:a?.fontFamily||m.typography.fontFamily},colors:{...m.colors,primary:a?.primaryColor||m.colors.primary,primaryHover:a?.primaryColor?`${a.primaryColor}dd`:m.colors.primaryHover}},h=Gt(),{isReady:I,isAuthenticated:H,isConnected:G,address:te,provider:_,actions:oe}=h,[D,V]=y(()=>g?{asset:g,amount:""}:null),[X,v]=y([]),[O,z]=y(!1),[$,W]=y(null),se=Re(!1),re=Re(!1),ie=F,ce=Ae(()=>!i||i.length===0?[]:!r||r.length===0?i:i.filter(T=>r.some(le=>le.toLowerCase()===T.symbol.toLowerCase())),[i,r]),j=ce?JSON.stringify(ce.map(T=>`${T.address}-${T.chainId}`).sort()):"",P=ne(async(T=!1)=>{if(!re.current){if(!ce||ce.length===0||!ie){v([]),se.current=!1;return}re.current=!0,!se.current&&!T&&z(!0),W(null);try{const le=await Promise.all(ce.map(async he=>{try{const Be=await je(he.chainId).readContract({address:he.address,abi:Yt,functionName:"balanceOf",args:[ie]}),nt=parseFloat(fn(Be,he.decimals));return{address:he.address,symbol:he.symbol,name:he.name,decimals:he.decimals,chainId:he.chainId,balance:Be,balanceFormatted:nt,balanceUsd:0,isNative:!1,logoURI:he.logoURI}}catch(Be){return console.error(`Failed to fetch balance for ${he.symbol}:`,Be),{address:he.address,symbol:he.symbol,name:he.name,decimals:he.decimals,chainId:he.chainId,balance:BigInt(0),balanceFormatted:0,balanceUsd:0,isNative:!1,logoURI:he.logoURI}}}));v(le),se.current=!0}catch(le){console.error("Failed to fetch token balances:",le),W(le instanceof Error?le.message:"Failed to fetch token balances"),se.current||v([])}finally{z(!1),re.current=!1}}},[j,ie]);ee(()=>{ie&&ce.length>0&&(se.current=!1,P(!1))},[j,ie]),ee(()=>{if(!ce.length||!ie)return;const T=setInterval(()=>{P(!0)},3e4);return()=>clearInterval(T)},[j,ie]),X.some(T=>T.balanceFormatted>0);const[ue,ae]=y(!1),[ve,Ie]=y(null),[ke,xe]=y(!1),[Fe,Ze]=y(!1),[Ve,R]=y(!1),[Z,be]=y(u),[Q,Y]=y(null),[K,de]=y(null),pe=Re(null),fe=Ae(()=>Z==="external"?S:F,[Z,S,F]),L=ne(T=>{be(T),w?.(T)},[w]),{intentStatus:U,startStatusPolling:ge,clearStatus:ye}=Lt({checkStepStatus:(T,le)=>Se.checkStepStatus(T,le)});ee(()=>{if(U?.overallStatus==="success"&&U.intentId&&pe.current!==U.intentId&&D&&te){const T=U.steps.find(le=>le.transactionHash);if(T?.transactionHash)if(pe.current=U.intentId,Z==="embedded"){const le=Ke(D.amount,D.asset.decimals),he={user:te,txHash:T.transactionHash,sender:te,tokenAddress:d||D.asset.address,chainId:D.asset.chainId,amount:le.toString(),isDeposit:!0};console.log("[WithdrawWidget] Submitting spice deposit for embedded withdraw:",he),Se.submitSpiceDeposit(he).then(Be=>{console.log("[WithdrawWidget] Spice deposit submitted successfully:",Be),P()}).catch(Be=>{console.error("[WithdrawWidget] Spice deposit submission failed:",Be),pe.current=null})}else P()}},[U,te,Z,D,d]),ee(()=>{s&&s.assetAmount!==D?.amount&&D&&V({...D,amount:s.assetAmount})},[s?.assetAmount,D]);const Je=ne(()=>{Ie(null)},[]),Ne=T=>{V({asset:T,amount:D?.amount||""}),Je()},at=ne(T=>{D&&(Io(()=>{V({...D,amount:T}),Je()}),s&&s.setAssetAmount(T))},[D,s,Je]),et=async()=>{if(!(!D||!te||t.length===0)){if(!fe){Ie(`Please provide a ${Z==="external"?"external":"embedded"} wallet address`);return}if(!I||!H){Ie(`Please authenticate with ${_||"wallet provider"} to continue`);return}ae(!0),Ie(null),R(!0);try{const T=Z==="external"&&n?[...t,...n]:[...t],le=[...new Set(T.map(M=>M.chainId))],he=[];for(const M of le){const N=je(M),me=yt(M),Ce=await qt(te,N),Ee=await oe.signAuthorization({contractAddress:me,chainId:M,nonce:Number(Ce)});he.push(Ee)}const Be=jt(T),nt=Math.floor(Date.now()/1e3)+60*10,$t=Pt(0n,BigInt(nt),Be),wt=await oe.signMessage({raw:$t}),Vt=typeof wt=="string"?wt:wt.signature;if(!Vt)throw new Error("Failed to sign intent authorization");const _t={from:"solver",to:te,token:"0x0000000000000000000000000000000000000000",amount:Ke("0.00001",18)},q={mode:"7702",signatureType:"ecdsa",signature:Vt,nbf:0,exp:nt,chainBatches:Be.map((M,N)=>{const me=T[N],Ce=me?.tokenTransfers??[],Ee=me?.calls&&me.calls.length>0;return{hash:M.hash,chainId:M.chainId,tokenTransfers:Ee?[_t,...Ce]:Ce,calls:M.calls}})},J=await Se.createAction({user:te,chainAuthorizations:he.map(M=>({...M,r:M.r,s:M.s,yParity:M.yParity,address:M.address,chainId:Number(M.chainId),nonce:Number(M.nonce)})),intents:[q]});if(J){const M=Ut(T,Ee=>`Chain ${Ee}`),[N,me]=J.intentIds[0].split("/"),Ce=parseInt(me||"0",10);ge(J.intentIds[0],M);for(let Ee=0;Ee<T.length;Ee++)await Se.executeStep(N,Ce,Ee,{action:"execute"});window.dispatchEvent(new CustomEvent("withdraw-completed"))}}catch(T){const le=T instanceof Error?T.message:"Withdraw failed";Ie(le),p?.(le)}finally{ae(!1)}}},tt=Ae(()=>{let T=X;return f&&f.length>0&&(T=T.filter(le=>f.includes(le.chainId))),T},[X,f]),Ge=D&&D.amount&&parseFloat(D.amount)>0&&parseFloat(D.amount)<=D.asset.balanceFormatted&&G&&!ue&&t.length>0&&!!fe,dt=$||ve,gt={backgroundColor:a?.container?.backgroundColor||a?.primaryBackground||b.colors.background,border:`1px solid ${a?.container?.borderColor||b.colors.border}`,borderRadius:a?.container?.borderRadius||b.borderRadius.lg,padding:a?.container?.padding||b.spacing.md,width:a?.container?.width||"100%",maxWidth:"28rem",minHeight:"200px",margin:"0 auto",color:b.colors.text,fontFamily:b.typography.fontFamily,boxShadow:a?.container?.boxShadow||(b.mode==="light"?"0 4px 6px -1px rgb(0 0 0 / 0.1)":"0 4px 6px -1px rgb(0 0 0 / 0.3)")},ot=U?e(po,{type:"withdraw",isOpen:!!U&&U.overallStatus!=="processing",isProcessing:ue||U?.overallStatus==="processing",onRetryTx:()=>{ye(),R(!1),et()},onNewTx:()=>{ye(),R(!1),V(null),pe.current=null,P()},onClose:()=>{ye(),R(!1)},onComplete:()=>{ye(),R(!1),V(null),pe.current=null,P(),k?.()},results:U?.overallStatus==="success"||U?.overallStatus==="failed"?(()=>{if((n?[...t,...n]:t).length>1&&U.steps.length>1){const T=U.steps.find(le=>le.transactionHash);return[{asset:{symbol:D?.asset.symbol||"Token",address:D?.asset.address||""},txHash:T?.transactionHash||"",success:U.steps.every(le=>le.status==="success"),amount:D?.amount}]}return U.steps.map(T=>({asset:{symbol:D?.asset.symbol||"Token",address:D?.asset.address||""},txHash:T.transactionHash||"",success:T.status==="success",amount:D?.amount}))})():void 0,chainName:D?(()=>{const T=n?[...t,...n]:t,le=[...new Set(T.map(he=>lt(he.chainId)))];return le.length>1?le.join(" and "):le[0]||"Network"})():"Network",explorerUrl:D?Wt(t[t.length-1].chainId,"").replace(/\/tx\/.*$/,""):void 0,theme:b}):null;return l("div",{style:{...gt,position:"relative"},className:c,children:[ot&&e("div",{style:{position:"absolute",top:0,left:"-25px",right:"-25px",bottom:"-16px"},children:e("div",{style:{position:"absolute",width:"100%",height:"100%",pointerEvents:"auto"},children:ot})}),!B&&l("div",{style:{marginBottom:"16px"},children:[e("div",{style:{display:"flex",alignItems:"center",gap:"6px",marginBottom:"10px"},children:e("label",{style:{fontSize:"12px",fontWeight:590,color:b.mode==="light"?"#374151":"#d1d5db"},children:"Withdraw To"})}),e("div",{style:{display:"flex",gap:"12px",flexWrap:"wrap"},children:x.map(T=>{const le=Z===T.id,he=T.id==="external"?S:F,Be=he?`${he.slice(0,6)}...${he.slice(-4)}`:null;return l("button",{onClick:()=>L(T.id),onMouseEnter:()=>Y(T.id),onMouseLeave:()=>{Y(null),de(null)},onMouseDown:()=>de(T.id),onMouseUp:()=>de(null),style:{padding:"8px 12px",borderRadius:"8px",border:`1px solid ${le?"#EA4B4B7A":Q===T.id?"#F4A5A5":b.mode==="light"?"#e5e7eb":"#374151"}`,backgroundColor:le?b.mode==="light"?"#FEF2F2":"#451a1a":K===T.id?b.mode==="light"?"#f5f5f5":"#2d2d2d":Q===T.id?b.mode==="light"?"#fafafa":"#333333":b.mode==="light"?"white":"#1f1f1f",cursor:"pointer",display:"flex",flexDirection:"column",alignItems:"flex-start",gap:"4px",transition:"all 150ms ease",transform:K===T.id?"scale(0.96)":Q===T.id?"translateY(-1px)":"none",boxShadow:le?"0 0 0 3px #FBDBDB":K===T.id?"0 1px 2px rgba(0, 0, 0, 0.05)":Q===T.id?"0 4px 8px rgba(0, 0, 0, 0.1)":"none"},children:[e("span",{style:{fontSize:"14px",fontWeight:510,color:b.mode==="light"?"#3C3E42":"#e5e7eb"},children:T.label}),Be&&e("span",{style:{fontSize:"10px",fontWeight:500,color:b.mode==="light"?"#939291":"#6b7280",fontFamily:'"IBM Plex Mono", monospace'},children:Be})]},T.id)})})]}),e("div",{style:{marginBottom:b.spacing.sm},children:e(Ct,{assets:tt,selectedAsset:D||void 0,onAssetSelect:Ne,onAmountChange:at,loading:O,label:"Amount",showBalance:!0,showMaxButton:!0,theme:b,styles:a})}),dt&&e("div",{style:{backgroundColor:a?.errorMessage?.backgroundColor||(b.mode==="light"?"#fef2f2":`${a?.statusDisplay?.errorColor||b.colors.error}20`),border:`1px solid ${a?.errorMessage?.borderColor||(b.mode==="light"?"#fecaca":a?.statusDisplay?.errorColor||b.colors.error)}`,borderRadius:a?.errorMessage?.borderRadius||b.borderRadius.md,padding:a?.errorMessage?.padding||b.spacing.md,marginBottom:b.spacing.sm},children:e("p",{style:{color:a?.errorMessage?.color||a?.statusDisplay?.errorColor||b.colors.error,fontSize:a?.errorMessage?.fontSize||b.typography.fontSize.sm,fontWeight:a?.errorMessage?.fontWeight,fontFamily:a?.errorMessage?.fontFamily||b.typography.fontFamily,margin:0},children:dt})}),e("div",{style:{display:"flex",flexDirection:"column",gap:b.spacing.sm},children:e(Me,{variant:"outline",fullWidth:!0,onClick:et,onMouseEnter:()=>xe(!0),onMouseLeave:()=>{xe(!1),Ze(!1)},onMouseDown:()=>Ze(!0),onMouseUp:()=>Ze(!1),loading:ue,disabled:!Ge||!G,theme:b,styles:a,style:{width:"100%",padding:"8px",backgroundColor:Ge?Fe?"#d43d3d":ke?"#f05555":"#ea4b4b":"#d1d5db",color:Ge?"#0e0d0b":"#6b7280",border:"1px solid #0e0d0b",fontWeight:500,fontSize:"18px",fontFamily:'"IBM Plex Mono", monospace',lineHeight:"156%",textTransform:"uppercase",cursor:Ge?"pointer":"not-allowed",marginTop:"20px",display:"flex",alignItems:"center",justifyContent:"center",gap:"10px",transition:"all 150ms ease",transform:Ge?Fe?"scale(0.98)":ke?"translateY(-2px)":"none":"none",boxShadow:Fe?"1px 1px 0px black":ke&&Ge?"5px 5px 0px white, 6px 6px 0px black":"3px 3px 0px white, 4px 4px 0px black"},children:I?H?G?ue?"Executing Withdraw...":D?D.amount?parseFloat(D.amount)>D.asset.balanceFormatted?"Insufficient Balance":t.length===0?"No Withdraw Batches":fe?"Execute Withdraw":`Set ${Z==="external"?"External":"Embedded"} Wallet`:"Enter Amount":"Select Token":"Wallet Not Connected":"Authentication Required":"Loading..."})})]})},fr=({isOpen:t,onClose:n,title:i="Withdraw",maxWidth:r="480px",withdrawBatches:o,externalWithdrawBatches:a,tokens:c,supportedTokens:s,depositTokenAddress:g,theme:f="light",styles:u,className:d,withdrawInputHook:w,defaultSelectedAsset:S,filterChains:F,withdrawMode:A,onWithdrawModeChange:p,externalWalletAddress:k,embeddedWalletAddress:B,onWithdrawSuccess:E,onWithdrawError:C,onComplete:x,hideWithdrawModeSelector:m,externalModeLabel:b,embeddedModeLabel:h,subtitle:I})=>{const H=De(f),G=te=>{E?.(te),n()};return e(ut,{isOpen:t,onClose:n,title:i,subtitle:I!==void 0?I:l("div",{style:{display:"flex",alignItems:"flex-start",gap:"5px",backgroundColor:"#f9fafb",border:"1px solid #ed6969",borderRadius:"8px",padding:"10px",margin:"0 0 0 0"},children:[e("img",{src:Ot,alt:"Info",style:{width:"14px",height:"14px",marginTop:"2px",flexShrink:0}}),e("p",{style:{fontSize:"13px",color:"#374151",margin:0,lineHeight:"1.5"},children:A==="external"?"Withdraw your vault tokens to your external wallet.":"Withdraw your vault tokens to your cross-chain balance."})]}),styles:u,theme:H,maxWidth:r,children:e("div",{style:{padding:"0 24px 24px 24px"},children:e(Po,{withdrawBatches:o,externalWithdrawBatches:a,tokens:c,supportedTokens:s,depositTokenAddress:g,theme:f,styles:{...u,container:{...u?.container,boxShadow:"none",borderColor:"transparent",padding:"0",backgroundColor:"transparent"}},className:d,withdrawInputHook:w,defaultSelectedAsset:S,filterChains:F,withdrawMode:A,onWithdrawModeChange:p,hideWithdrawModeSelector:m,externalWalletAddress:k,embeddedWalletAddress:B,onWithdrawSuccess:G,onWithdrawError:C,onComplete:x,externalModeLabel:b,embeddedModeLabel:h})})})};/**
|
|
70
70
|
* @license lucide-react v0.562.0 - ISC
|
|
71
71
|
*
|
|
72
72
|
* This source code is licensed under the ISC license.
|