@spicenet-io/spiceflow-ui 2.5.6 → 2.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -20,7 +20,7 @@ import{jsxs as i,jsx as e,Fragment as Qt}from"react/jsx-runtime";import Ft,{useS
20
20
  transform: translateX(100%);
21
21
  }
22
22
  }
23
- `})]})},ys={WALLET_DISCONNECTED:"Wallet is not connected.",WALLET_REJECTED:"Transaction was rejected.",SIGNATURE_FAILED:"Signature failed. Please try again.",CONCURRENT_EXECUTION:"A transaction is already in progress.",ABORT:"Transaction was cancelled.",NO_VENUE_FOR_CHAIN:"No swap venue available for this chain.",NO_LIQUIDITY:"No liquidity available for this swap pair.",VENUE_API_ERROR:"Swap service error. Please try again.",ROUTE_TOKEN_NOT_FOUND:"Token not found in the registry.",ROUTE_UNSUPPORTED_INPUT:"This input token is not supported.",ROUTE_STRATEGY_ERROR:"No viable route found for this swap.",INVALID_PARAMS:"Invalid parameters. Please check your inputs.",RELAYER_ERROR:"Relayer error. Please try again.",RELAYER_EXECUTE_ERROR:"Transaction execution failed. Please try again.",RELAYER_STATUS_ERROR:"Failed to check transaction status.",ON_CHAIN_REVERT:"Transaction reverted on-chain. Please verify your inputs.",POLLING_EXHAUSTED:"Transaction status check timed out. It may still complete.",POLLING_CONSECUTIVE_FAILURES:"Lost connection to transaction status. It may still complete.",ALL_ATTEMPTS_FAILED:"All attempts failed. Please try again."},xs=[{test:t=>t.includes("user rejected")||t.includes("user denied")||t.includes("user cancelled")||t.includes("rejected the request")||t.includes("action_rejected"),message:"Transaction was rejected."},{test:t=>t.includes("4001"),message:"Transaction was rejected."},{test:t=>t.includes("insufficient funds")||t.includes("insufficient balance"),message:"Insufficient funds for this transaction."},{test:t=>t.includes("internal json-rpc error")||t.includes("internal error")||t.includes("an internal error was received"),message:"RPC Network error. Try switching your RPC endpoint or try again."},{test:t=>t.includes("network error")||t.includes("failed to fetch")||t.includes("econnrefused")||t.includes("timeout"),message:"Network connection error. Please check your connection."},{test:t=>t.includes("does not match the target chain")||t.includes("current chain of the wallet"),message:"Wrong network detected. Please switch to the correct network and try again."},{test:t=>t.includes("nonce too low")||t.includes("nonce has already been used"),message:"Transaction conflict. Please try again."},{test:t=>t.includes("cannot estimate gas")||t.includes("gas required exceeds"),message:"Unable to estimate gas. The transaction may fail \u2014 please verify your inputs."},{test:t=>t.includes("execution reverted")||t.includes("transaction reverted"),message:"Transaction would fail on-chain. Please verify your inputs and try again."}],Ot=(t,n="Something went wrong. Please try again.")=>{if(Xn(t)){const s=ys[t.code];if(s)return s}const o=qo(t).toLowerCase();for(const{test:s,message:a}of xs)if(s(o))return a;return n},bs=t=>{if(Xn(t))return t.code==="WALLET_REJECTED";const n=qo(t).toLowerCase();return n.includes("user rejected")||n.includes("user denied")||n.includes("user cancelled")||n.includes("rejected the request")||n.includes("action_rejected")||n.includes("4001")};function qo(t){if(!t)return"";if(typeof t=="string")return t;const n=t,o=n.message||n.reason||"",s=n.details||"";return`${o} ${s}`.trim()}var Go="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAA6lBMVEXc3NzX/v/1hRvZ2dnd3dzb29va7fpMaXHa1tPc3N35/v/c3Nzc3NzCrp/c3Nza2tp1PRbLsJzlr33uhSj0kTHcnWnUva7jdhuNX0B6Qhrsk0LOxMCFVDJ+RyGhfGTkeiGYVSHjdx3lij7khDPEsaPfoW/jgjLQuKXmgzB2PRb2hRvldhvjdRv4hhvpeRtwORb/ihryghvabhnsehrUaRjLXxXtfRt7PxXwexricRbRYhURFBeSTBe0XBrEZxmDRxiiVRrlgCbfzMAvLCmrWBgbMEh9UjBbOBe2pJi9byekk4nkgDHkgDJLNB7jlKArAAAAKXRSTlMzJv0TNSYsADUxKBwK/QUZ/URTx650/vqJ5YpMosxj3ezwkqa6/q3KrihQ98kAAAAJcEhZcwAACxMAAAsTAQCanBgAAATxSURBVHjapVeJcuI4EJXBdiRuw4JzDAFyzeIT22BsNgTIJNnM7Pz/90xLsmV5ChJm6SqqZOR+7teXWujsgLSqdU0jBCFCNK1ebR16D+39t1HXiKqqGDHBsCRavXEsQKutIVWln0aZ0BX8o7VbRwC06gS+LHQLIWAJqbc+A6iC+h7t3BCVVD8EaGgqOqSemaFqjcMA8PkP1RnEb0bIAPXD1peNqO8H0NQj1LkR2j6Ao/XLCOh/6JcQkOD/B/oUoV4GqGb6+HNdnCFUZYBG9nmsE/whBsZE5y9g0pAAcgcQQ1V0fAgDNnRFNQiW3cAA2lwfI3wxvunqyl4z4OOK3r0ZX2CUIbRzgFZOoHY9nW7NXt9QdFTGgCddMfq9cDudXteyLdLKAPII4NqXZcffzIPJQx8zDCFgev9hksw3fmf5pYalSCDJAGAw7Uz9zkuU2CNKRQiYPrIT76Xjwws5B/BjiwG0hQHAgIr/GHpeYvb+EtIzI88LH32+fy1MaDMAKOGCAUdYPnmmE82ERI7pPS25fsEB0UCgs4ZwVO08AwB5sT0zrmQSm7b94mff7yzPa8LBDQAQSSwo5DRsKxO7MF+mwNyIBAPwjHEhIQCNgOsHwnwmF4aeWwAcUEMO97DgABAvkUv13WgrqXeWQ7moGqiqFtkivJjTCADBDWTzZR9SE6pIquOSF6msGYdgPS0BSD4EJ6CikUB+DKcd2QkRB4hkF3SmQyyqHioKaViicF4AQEp7DqfgRJDCSwFxLlPQ5GMAAHJ9n4bRyQEcGkZ/HwColwBYHH3fXz6uHc+xnZgCxLDwnPXj0mcgUhRpOZSblTEE9c32ybMi27ELAHiILO9puwGIoXG48YEJ43UYzGYumG/LADbQcGezIFyPjRr+7aCREfTezLUqFtMB4QB87cSw4c56uqyPSz4A/S6UDuikqzkTmwLYfL1K4aFiVbolBCKHEWHlclahyRvMF4vFarWgOm5KV4vFnIbEqswuFUmD5oF0olAGFZ7+88VqvV05FMBZbderxZwXRqXEgSaSfCTp3cDiAIETvr2+riP64K1fX99ClhMA4AIH+YAqFVPGgGnFu+9v44Quk/Hb913suXyjzAGKSS7nnAEtgBg6WeAxLIjrLM56A+NQKueioVAGruW67OdWrCCwYqoS01XgZmLJHGhDkVqa3oXeSyUESaktvBrBJ5WU/sd3IxFI3tKKpkrwCDIQcjCkUfPAnIAJ+NSjcQ1tuuuNMCk11TORCVh5SEyWdXP2dmzxpk4TEzDnbMtM/lakligfLADQj3gOOysASNPd5l+QzS5NAWCVbUV9RTBol442cIIxsVnlwPthurtv/sOkeb9LQ2oS25qIcs6PNtmNvch0HBOKN/15P3h+5wDvz4P7/1IocNhzop7swvLxTjMpMm0viSa9m6/Pg+cf35j8gOXXm94kSjzbjIo8Esd7cbxCIBNzdNs3dAXdDQbN9ybIe3MwuEOKbvRvR2YigigNGNKMh28vu0ihswGp9ZuDJpNBs0+HFjjuUffyFpcnvfKQhbgym06wcnXHAe6umNWYjSlKkcXlMa8YpIrEIldMCMHyrLNvzDs0aBImxwyap4+6pw/bp4/71A/opAvH6Vee0y9dn1z70OfXvuziudcMSKdjLp786quecPWVL99Zfqt/ePkuX/8Jv/43Dl3/fwH9bPJ09nq7MQAAAABJRU5ErkJggg==",bo="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAQlBMVEVMaXGGl/+Elf+HmP+Hmf+Hl/+Gl/+Flv+Glv+Gl/+Gl/+Gl/////+On/+Akv/4+f/v8f/i5v+9x//S2P+tuP+erP+W3PvUAAAAC3RSTlMArBlx7Isy/vvOXbb4wDYAAAAJcEhZcwAACxMAAAsTAQCanBgAAALuSURBVHjarVfbtqsgDOxu0UBpkOv//+pJRC0i2HZ58uTeqzOEyYXkduvY/Tn8KSEBpFB/w3O8/WTjoCSS6dn4S6rha477QxFGS0nHM56ckJL/ox73b+CDQAQJujKiQxTDR4qH4LN109gP8Ti/uyI46K4BUagTLZ4Cz+CZAsWzhx/oeP3RyImhjf/7ePzmxF8Hr7+zNsP3eL7GkWH4Bc8MlQ7P3/DMsIvFKHRLPzBsTWVBizIfVNMBg9H7mLQxTRdUkb9tfJxebNZjywuJW1bf2xcw4WXtzDF5bVqXuJ9HwETHNnPYeHRii0THgcwQyBxTBDQ9Fx7dEBr0TOCDYyeS6aigsFsCQIFgBh9YiVgxQA7EqM9KiCiS95nh5WsGPZ4k8ZZFRqfoY4shy9i8AaExxRgTMgcApuSODPMdRtn02wc7Z9HkPMsPa1ZVOsiRygga4udfZ5vTKKx/7GIBVFJHCUy0r705DNu3LQ9kEQ6NxMTXwWzhUTD7xlJr2MLvrZCBVazy2OD0iaC4BGh1k4cSLOSbbIuujKW4wT76aYefrGswuBJSEoBeUnaFk7nQcKEIJZRXMPsfM95O3p3KKAoRa/cJTh0pHKMybSqyiO8wMsG0wzODi7UK9u0Ah7FIJAj1+UyQcl4Gqi2uax+L/siJVKQyi+j251sbMoHTZrUqlctiojDGRX27WpivYNtdi4upKme0c/gXBmdzY7ZoOi/cWDeU7MJy+oKn3hzbT9/cFKt6pmKe9udnCoTeG103VW7EjrGZJMOD863GNzfVQ0EDP6aJUH61wBRHGZa23npYDDpuh8EnpPBRS6UUQOg9r8enzaDdmhmsPkH/da3bokkr/i0dwMmYU7lg0pRrwiVzNrW+n/dKhVzVVIbGnE9Jj86IA8glk87h+xGnGrJyzXwYNvdD1uUx7/qgeX3UvT5sXx/3ry8c11ee60vX9bXvvXjWfsC3i+d79YV19+WPH1bf/7B8Lxy8/isBINTp+v8Ph4CTcAywkiYAAAAASUVORK5CYII=",Cs="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAPFBMVEVMaXGZhueZh+eYhuWXheWYh+eYhuaXheCYhuaah+j//fmhjvOSf+Sdi+q8sOzNxO/m4fT08fapmuja0/Jb/wGxAAAACnRSTlMArEz/IYtsA87sGIEBYwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAmJJREFUeNqtV4uSgyAMRIECGhTk///1otTKG3s2Mzdz03aXbEJIQkhuYv9jIx+komhKDnxk4v1F1wT+SoxcUj3PWu8Ex39U8lH4bzt4QthL6tlDA8OP5Iv1vMADGFc5+uRQnDWdEES81EwbNquXqDuBx8va6ZcXktUYBOkc/3GixsBvwA8neFGGGO7hdyeGAsMXeM/wBJ8ziLv6LwYeisD4f4lHhiAXmH9FvzYV3AchOw6At9gFKW4KANDbsttGoSyCKd1Ab4uxkzezhBQaRfQygHB3oj2FhjwT9QgifErM6jiOrQgAXe2UmcuiIKSuHG+mki2XCH0kYqzgF1vETyYszLFaxLBMNdsgDGNFAazRoUcwrDMlDYz28RS0newGcCRlDa8TK4YgxuORGj9x8NYVEsxjKQSp/pNAw5YRcJI/JP5nYeqxjAxeIfCeRQQDyWOos/y5xR2V4NIgYhRJVkjgpralBPcvQH4PsBxIX0DjJqKRdgYLtsYPUyqh60CsACXEQew7ECvAICZp7DqwQEIQXaR+CkzaoeKr3FewQdqg4mIy36VgLyZWz4G96N5vs8sKj0UPSlJGy4fAbWX88SgGQYgJVjDXi7JaaxYo9Oj4UQ0lrHCGdN25ceiEfNoZSfIomjhcKN26DarT0q4gaiyfe2C9u9hWNUBvRghbG+yd1AZNFFrjmu+ucXMF2j60OObE7f0m+mrv/5qQkimpO+IU8fKXQ9bDMe/5oPl81P3BsP183EeGu3GoLBw/WHnuLF20sXQ9X/ueL57PV99w+Z7P5Vvj8j3fXr7j9X/f/5Vsrv9/K3NM7mGXOq0AAAAASUVORK5CYII=";const $t=ho(1)?.logo??"";ho(42161)?.logo;const Nn=fo.find(t=>t.symbol==="USDC")?.logo??"";fo.find(t=>t.symbol==="WBTC")?.logo;const zt=Object.fromEntries([...$r(),..._r()].map(t=>[t.id,t.logo])),so={metamask:Go,metaMask:Go,rabby:bo,phantom:Cs},ws=Object.fromEntries(fo.map(t=>[t.symbol,t.logo])),_t=({symbol:t,logoURI:n,size:o=20,theme:s})=>{const a=s||Sn("dark"),[l,r]=B(!1),c={width:`${o}px`,height:`${o}px`,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:`${o*.4}px`,fontWeight:a.typography.fontWeight.bold,flexShrink:0,overflow:"hidden",backgroundColor:"#ffffff"},d=t.toUpperCase(),u=n||ws[d];if(u&&!l)return e("img",{src:u,alt:t,style:{...c,objectFit:"cover"},onError:()=>r(!0)});const p=vs(t);return e("div",{style:{...c,...p.style},children:p.icon})},vs=t=>{const n=t.toUpperCase(),o={ETH:{bg:"#627EEA",text:"#FFFFFF",icon:"\u039E"},BTC:{bg:"#F7931A",text:"#FFFFFF",icon:"\u20BF"},USDC:{bg:"#2775CA",text:"#FFFFFF"},USDT:{bg:"#26A17B",text:"#FFFFFF"},DAI:{bg:"#F5AC37",text:"#FFFFFF"},WETH:{bg:"#627EEA",text:"#FFFFFF",icon:"\u039E"},WBTC:{bg:"#F09242",text:"#FFFFFF",icon:"\u20BF"},CBTC:{bg:"#F7931A",text:"#FFFFFF",icon:"\u20BF"},USD:{bg:"#26A17B",text:"#FFFFFF",icon:"$"},MATIC:{bg:"#8247E5",text:"#FFFFFF"},AVAX:{bg:"#E84142",text:"#FFFFFF"},SOL:{bg:"#9945FF",text:"#FFFFFF"},DOT:{bg:"#E6007A",text:"#FFFFFF"},ADA:{bg:"#0033AD",text:"#FFFFFF"},LINK:{bg:"#375BD2",text:"#FFFFFF"},UNI:{bg:"#FF007A",text:"#FFFFFF"},AAVE:{bg:"#B6509E",text:"#FFFFFF"},CRV:{bg:"#40E0D0",text:"#000000"}}[n];if(o)return{style:{backgroundColor:o.bg,color:o.text},icon:o.icon||n.charAt(0)};const s=n.split("").reduce((c,d)=>d.charCodeAt(0)+((c<<5)-c),0),a=Math.abs(s)%360,l=`hsl(${a}, 60%, 50%)`,r=a>180?"#FFFFFF":"#000000";return{style:{backgroundColor:l,color:r},icon:n.charAt(0)}};var Co="data:image/svg+xml,%3csvg width='15' height='15' viewBox='0 0 15 15' fill='none' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M7.5 7.49993V10.4999M7.5 4.96868V4.96784M14.25 7.5C14.25 11.2279 11.2279 14.25 7.5 14.25C3.77208 14.25 0.75 11.2279 0.75 7.5C0.75 3.77208 3.77208 0.75 7.5 0.75C11.2279 0.75 14.25 3.77208 14.25 7.5Z' stroke='%23ED6969' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3e%3c/svg%3e";const ks=({isOpen:t,onClose:n,onComplete:o,title:s="Testnet Airdrop",description:a="Request testnet tokens for your wallet. A small gas fee is required to process the airdrop.",chainId:l,airdropTag:r="default",walletAddress:c,airdropTokens:d,getChainConfig:u,getSupportedTokens:p})=>{const f=Sn("light"),{primaryColor:m}=je(),[g,h]=B(null),[C,y]=B(null),{chain:S}=Yt(),{data:U}=qn(),{switchChainAsync:b}=Bn(),x=Ce(()=>p(l),[l,p]),M=Ce(()=>x.filter(A=>!rt(A.address)),[x]),{data:z,refetch:T}=jo({contracts:M.map(A=>({address:A.address,abi:At,functionName:"balanceOf",args:[c],chainId:l})),blockTag:"pending"}),I=ie(()=>{T();const A=setTimeout(T,2e3),E=setTimeout(T,4e3);return()=>{clearTimeout(A),clearTimeout(E)}},[T]);$(()=>t?I():void 0,[t,I]),$(()=>{let A;const E=()=>{A?.(),A=I()};return window.addEventListener("airdrop-complete",E),()=>{A?.(),window.removeEventListener("airdrop-complete",E)}},[I]);const F=Ce(()=>{const A=[];return M.forEach((E,O)=>{if(!d.some(se=>se.toUpperCase()===E.symbol.toUpperCase()))return;const V=z?.[O],P=V?.status==="success"?V.result:BigInt(0),X=Number(P)/Math.pow(10,E.decimals);A.push({address:E.address,symbol:E.symbol,name:E.name,decimals:E.decimals,balance:P,balanceFormatted:X})}),A},[M,z,d]),w=u(l),W="0x11126A138f34532D250CCf35531E5A2f398ce7d4",Z=ie(async A=>{if(!c||!l){y({message:"Wallet not connected",type:"error"});return}if(!U){y({message:"Wallet client not available",type:"error"});return}h(A.address);try{S?.id!==l&&await b({chainId:l});const E=ct(l),O=await E.getGasPrice(),V=BigInt(21e3)*O*BigInt(110)/BigInt(100),P=await U.sendTransaction({to:W,value:V});await E.waitForTransactionReceipt({hash:P,timeout:6e4,pollingInterval:2e3,confirmations:1});const X=await qe.requestAirdrop({chainId:l,tokenId:A.symbol==="WBTC"?"mWBTC":A.symbol,wallet:c,tag:r});if(X.success){const se=w?.blockExplorer;y({message:`Successfully airdropped ${A.symbol}!`,type:"success",linkText:X.txHash?"View Transaction":void 0,linkUrl:X.txHash&&se?`${se}/tx/${X.txHash}`:void 0}),window.dispatchEvent(new CustomEvent("airdrop-complete",{detail:{token:A.symbol,txHash:X.txHash}})),o&&o()}else y({message:X.errorMessage||"Airdrop failed",type:"error"})}catch(E){y({message:Ot(E,"Airdrop request failed"),type:"error"})}finally{h(null)}},[c,l,U,S,b,r,w,o]),D=ie(()=>{window.dispatchEvent(new CustomEvent("airdrop-skipped"))},[n]);return i(Dt,{isOpen:t,onClose:n,title:s,subtitle:i("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:Co,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})]}),theme:f,maxWidth:"420px",children:[i("div",{style:{padding:"0 24px 32px 24px"},children:[e("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:F.length===0?e("p",{style:{textAlign:"center",color:"#6b7280",fontSize:"14px",padding:"20px 0"},children:"No airdrop tokens available for this chain."}):F.map(A=>{const E=g===A.address,O=E||g!==null;return i("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",borderRadius:"12px",border:"1px solid #e5e7eb",backgroundColor:"white",transition:"all 150ms ease"},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[e(_t,{symbol:A.symbol,size:36,theme:f}),i("div",{children:[e("div",{style:{fontSize:"16px",fontWeight:600,color:"#111827"},children:A.symbol}),i("div",{style:{fontSize:"12px",color:"#6b7280",fontFamily:'"IBM Plex Mono", monospace'},children:["Balance:"," ",A.balanceFormatted?.toFixed(4)??"0.0000"]})]})]}),e(Ge,{variant:"outline",size:"sm",onClick:()=>Z(A),disabled:O,loading:E,theme:f,styles:{button:{backgroundColor:m}},children:"Get Airdrop"})]},A.address)})}),e(Ge,{variant:"outline",fullWidth:!0,onClick:D,disabled:g!==null,theme:f,styles:{button:{backgroundColor:m}},style:{marginTop:"20px"},children:"NEXT"})]}),C&&e(xo,{message:C.message,type:C.type,linkText:C.linkText,linkUrl:C.linkUrl,onClose:()=>y(null)})]})},wo=15,vo=({checkStepStatus:t,pollingInterval:n=4e3,retryStep:o,maxRetries:s=3})=>{const[a,l]=B(null),r=Fe(null),c=Fe(!1),d=Fe(!1),u=Fe(null),p=Fe({}),f=Fe(0),m=Fe(0),g=ie(()=>{r.current&&(clearInterval(r.current),r.current=null)},[]),h=ie(()=>{u.current=null,l(null),p.current={},f.current=0,m.current=0,g()},[g]),C=ie((y,S)=>{g(),c.current=!1,d.current=!1,p.current={},f.current=0,m.current=0;const U={intentId:y,steps:S.map(x=>({...x,status:"pending"})),overallStatus:"processing"};u.current=U,l(U);const b=async()=>{if(c.current||d.current)return;d.current=!0,m.current+=1;const x=m.current;try{const M=u.current;if(!M)return;const z=M.steps.map(w=>({...w}));let T=!0,I=!1;for(let w=0;w<z.length;w++){const W=z[w];if(W.status!=="success"){if((W.stepId===0||w>0&&z[w-1].status==="success")&&(W.status==="pending"||W.status==="processing"))try{const Z=await t(y,W.stepId);if(f.current=0,Z.data.status==="success")z[w]={...W,status:"success",transactionHash:Z.data.transactionHash},w+1<z.length&&z[w+1].status==="pending"&&(z[w+1]={...z[w+1],status:"processing"});else if(Z.data.status==="executing"||Z.data.status==="created")z[w]={...W,status:"processing"};else if(Z.data.status==="reverted"){const D=p.current[W.stepId]||0;if(o&&D<s){p.current[W.stepId]=D+1;try{await o(y,W.stepId)}catch(A){console.error(`[useStatus] Retry failed for step ${W.stepId}:`,A)}z[w]={...W,status:"processing"}}else z[w]={...W,status:"failed",transactionHash:Z.data.transactionHash},I=!0}else z[w]={...W,status:"processing"}}catch(Z){f.current+=1,console.error(`[useStatus] Poll #${x}: Error checking step ${W.stepId} (consecutive errors: ${f.current}/${wo}):`,Z),f.current>=wo&&(console.error(`[useStatus] Too many consecutive polling errors (${wo}). Marking step ${W.stepId} as failed.`),z[w]={...W,status:"failed"},I=!0)}z[w].status!=="success"&&(T=!1)}}const F={...M,steps:z,overallStatus:I?"failed":T?"success":"processing"};u.current=F,l(F),(T||I)&&(c.current=!0,g())}finally{d.current=!1}};b(),r.current=setInterval(b,n)},[t,n,g,o,s]);return $(()=>()=>{g()},[g]),{intentStatus:a,startStatusPolling:C,stopStatusPolling:g,clearStatus:h}},Fn=({address:t,supportedChains:n,enabled:o=!0,refetchInterval:s})=>{const a=It(xt)?.apiUrl||Zr,[l,r]=B([]),[c,d]=B(!1),[u,p]=B(null),[f,m]=B(!1),g=Fe(!1),h=Fe(!1),C=n?JSON.stringify([...n].sort()):"",y=ie(async(b=!1)=>{if(!t||!o){r([]),m(!1),g.current=!1;return}if(!h.current){h.current=!0,!g.current&&!b&&d(!0),p(null);try{const x=await fetch(`${a}/spicedeposit/${t}`);if(!x.ok)throw new Error(`Failed to fetch balance: ${x.status}`);const M=await x.json();if(M.success&&M.data?.tokens&&Array.isArray(M.data.tokens)){const z=new Map;M.data.tokens.forEach(I=>{const F=I.chainId,w=I.tokenAddress,W=I.amount;if(n&&!n.includes(F))return;const Z=BigInt(W||"0");if(Z>BigInt(0)){const D=Ke(F),A=rt(w),E=A?Kt:w.toLowerCase();let O=18,V="TOKEN",P=w.slice(0,6)+"..."+w.slice(-4),X;if(A)O=D?.nativeCurrency?.decimals||18,V=D?.nativeCurrency?.symbol||"ETH",P=D?.nativeCurrency?.name||"Native Token";else{const R=D?.supportedTokens?.find(H=>H.address.toLowerCase()===w.toLowerCase());R&&(O=R.decimals,V=R.symbol,P=R.name,X=R.logo)}const se=parseFloat((Number(Z)/Math.pow(10,O)).toFixed(6));if(se>0){const R=`${E}-${F}`,H=z.get(R);if(H){const q=H.balance+Z,me=parseFloat((Number(q)/Math.pow(10,O)).toFixed(6));z.set(R,{...H,balance:q,balanceFormatted:me})}else z.set(R,{address:E,symbol:V,name:P,decimals:O,chainId:F,balance:Z,balanceFormatted:se,balanceUsd:0,isNative:A,logoURI:X})}}});const T=Array.from(z.values());r(T),m(T.length>0),g.current=!0}else r([]),m(!1)}catch(x){const M=x instanceof Error?x.message:"Failed to fetch balance";p(M),console.error("Error fetching Spice assets:",x),g.current||(r([]),m(!1))}finally{d(!1),h.current=!1}}},[t,o,C,a]);$(()=>{o&&t&&(g.current=!1,y(!1))},[t,o,C]),$(()=>{if(!o||!t||!s)return;const b=setInterval(()=>{y(!0)},s);return()=>clearInterval(b)},[t,o,s,C]);const S=ie(b=>l.filter(x=>x.chainId===b),[l]),U=ie(async()=>{await y(!0)},[y]);return{assets:l,loading:c,error:u,hasBalance:f,refetch:U,getAssetsByChain:S}},ao=(t,n=4)=>!isFinite(t)||t===0?"0":t<1e-4?"< 0.0001":t.toFixed(n),Mn=t=>isFinite(t)?new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(t):"$0.00",Is=(t,n=6,o=4)=>t.length<=n+o?t:`${t.slice(0,n)}...${t.slice(-o)}`,Jo=t=>{const n=t.replace(/[^0-9.]/g,""),o=n.split(".");return o.length>2?o[0]+"."+o.slice(1).join(""):n},Ss=async t=>{try{return await navigator.clipboard.writeText(t),!0}catch(n){return console.error("Failed to copy to clipboard:",n),!1}},Pn=({chainId:t,name:n,size:o=16})=>{const s=t&&(zt[t]||ho(t)?.logo)||"";return s?e("img",{src:s,alt:n||`Chain ${t}`,style:{width:`${o}px`,height:`${o}px`,borderRadius:"50%",objectFit:"cover",flexShrink:0}}):null},As=({selectedAsset:t,assets:n,onAssetSelect:o,showDropdown:s,onToggleDropdown:a,disabled:l=!1,theme:r})=>{const c=r||Sn("dark"),d=Fe(null),u=Fe(null),p=Fe(null),[f,m]=B(null);$(()=>{if(s&&u.current){const I=()=>{if(u.current){const F=u.current.getBoundingClientRect();m({top:F.bottom+6,right:window.innerWidth-F.right})}};return I(),window.addEventListener("scroll",I,!0),window.addEventListener("resize",I),()=>{window.removeEventListener("scroll",I,!0),window.removeEventListener("resize",I)}}else m(null)},[s]),$(()=>{const I=F=>{d.current&&!d.current.contains(F.target)&&p.current&&!p.current.contains(F.target)&&s&&a()};return s&&document.addEventListener("mousedown",I),()=>{document.removeEventListener("mousedown",I)}},[s,a]);const[g,h]=B(!1),C={backgroundColor:"transparent",border:`1px solid ${c.mode==="light"?"#aaaaaa":c.colors.border}`,borderRadius:"6px",color:c.colors.text,cursor:l?"not-allowed":"pointer",padding:"8px 12px 8px 8px",width:"100%",display:"flex",flexDirection:"column",gap:"4px",opacity:l?.6:1,transition:"all 0.15s ease",transform:g?"scale(0.98)":"scale(1)"},y={display:"flex",justifyContent:"space-between",alignItems:"center"},S={display:"flex",alignItems:"center",gap:"4px",paddingTop:"4px",borderTop:`1px solid ${c.colors.border}`},U=()=>f?{position:"fixed",top:`${f.top}px`,right:`${f.right}px`,backgroundColor:c.colors.secondary,border:`1px solid ${c.colors.border}`,borderRadius:c.borderRadius.md,boxShadow:c.shadows.lg,zIndex:100,width:"200px",maxHeight:"300px",overflow:"auto"}:{},b={backgroundColor:"transparent",border:"none",color:c.colors.text,cursor:"pointer",padding:c.spacing.sm,width:"100%",display:"flex",alignItems:"center",gap:c.spacing.sm,transition:`background-color ${c.animation.normal}`,":hover":{backgroundColor:c.colors.surfaceHover}},x={display:"flex",flexDirection:"column",alignItems:"flex-start",flex:1},M={fontSize:c.typography.fontSize.sm,fontWeight:c.typography.fontWeight.medium},z={fontSize:c.typography.fontSize.xs,color:c.colors.textMuted},T={transition:`transform ${c.animation.normal}`,transform:s?"rotate(180deg)":"rotate(0deg)"};return i(Qt,{children:[e("div",{style:{position:"relative"},ref:d,children:i("div",{ref:u,style:C,onClick:l?void 0:a,onMouseLeave:()=>{h(!1)},onMouseDown:()=>h(!0),onMouseUp:()=>h(!1),children:[i("div",{style:y,children:[e("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:t?.asset?i(Qt,{children:[e(_t,{symbol:t.asset.symbol,logoURI:t.asset.logoURI,theme:c,size:24}),e("span",{style:{fontSize:"16px",fontWeight:500,color:c.colors.text,lineHeight:"1.5"},children:t.asset.symbol})]}):e("span",{style:{fontSize:"14px",color:c.colors.textMuted},children:"Select"})}),e("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:c.colors.textMuted,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:T,children:e("path",{d:"M6 9l6 6 6-6"})})]}),t?.asset&&i("div",{style:S,children:[e(Pn,{chainId:t.asset.chainId,theme:c}),e("span",{style:{fontSize:"11px",color:c.colors.textMuted},children:vt(t.asset.chainId)})]})]})}),s&&f&&Zo(i("div",{ref:p,style:U(),children:[n.length===0&&e("div",{style:{padding:"10px 12px",color:c.colors.textMuted,fontSize:c.typography.fontSize.xs},children:"No assets available"}),n.map(I=>i("button",{style:b,onClick:()=>{o(I),a()},children:[e(_t,{symbol:I.symbol,logoURI:I.logoURI,theme:c},`${I.address}-${I.chainId}`),i("div",{style:x,children:[i("div",{style:{display:"flex",alignItems:"center",gap:c.spacing.xs},children:[e("span",{style:M,children:I.symbol}),e(Pn,{chainId:I.chainId,theme:c})]}),i("span",{style:z,children:[ao(I.balanceFormatted)," \u2022"," ",vt(I.chainId)]})]})]},`${I.address}-${I.chainId}`))]}),document.body)]})},Es=({assets:t,selectedAsset:n,onAssetSelect:o,onAmountChange:s,disabled:a=!1,loading:l=!1,label:r="Select Asset",showBalance:c=!0,showMaxButton:d=!0,placeholder:u="0.0",theme:p,styles:f,maxAmount:m,hideAmountInput:g=!1,displayAmount:h,dark:C})=>{const y=p||Sn("dark"),{primaryColor:S,dark:U,dk:b}=je(f,C),x=C??U,[M,z]=B(!1),[T,I]=B(null),[F,w]=B(null),[W,Z]=B(n?.amount||""),D=Fe(null),A=Fe("");$(()=>{const R=n?.asset?`${n.asset.chainId}-${n.asset.address}`:"";R!==A.current&&(Z(n?.amount||""),A.current=R)},[n?.asset?.chainId,n?.asset?.address,n?.amount]);const E=R=>{let H=R;H.startsWith(".")&&(H="0"+H);const q=Jo(H);if(!q){Z(q),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{s(q)},300);return}if(m&&parseFloat(q)>parseFloat(m)){Z(m),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{s(m)},300);return}if(n?.asset){const me=parseFloat(q),we=n.asset.balanceFormatted;if(!isNaN(me)&&me>we){const oe=(Math.floor(we*1e6)/1e6).toString();Z(oe),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{s(oe)},300);return}}Z(q),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{s(q)},300)},O=R=>{if(n?.asset){const H=n.asset.balanceFormatted*R/100;let q=Math.floor(H*1e6)/1e6;m&&q>parseFloat(m)&&(q=parseFloat(m));const me=q.toString();Z(me),D.current&&clearTimeout(D.current),s(me)}},V=n?.asset?.balanceFormatted??0,P=parseFloat(W)||0,X=V>0?P/V*100:0;$(()=>()=>{D.current&&clearTimeout(D.current)},[]);const se={backgroundColor:f?.assetSelector?.backgroundColor||f?.secondaryBackground||(x?b.cardBg:"#e9e9e9"),border:x?`0.5px solid ${b.cardBorder}`:"0.5px solid #A8A8A7",borderRadius:f?.assetSelector?.borderRadius||"6px",padding:f?.assetSelector?.padding||"16px",height:"auto",minHeight:g?void 0:"144px",display:"flex",flexDirection:"column",gap:"8px",position:"relative",opacity:a?.6:1};return l?e("div",{style:se,children:i("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[i("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e("div",{style:{backgroundColor:x?b.hoverBg:"#d1d5db",borderRadius:"4px",height:"16px",width:"60px"}}),e("div",{style:{backgroundColor:x?b.hoverBg:"#d1d5db",borderRadius:"4px",height:"40px",width:"150px"}})]}),i("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-end",gap:"8px"},children:[e("div",{style:{backgroundColor:x?b.hoverBg:"#d1d5db",borderRadius:"4px",height:"12px",width:"80px"}}),e("div",{style:{backgroundColor:x?b.hoverBg:"#d1d5db",borderRadius:"6px",height:"46px",width:"128px"}})]})]})}):i("div",{style:se,children:[i("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e("span",{style:{fontFamily:f?.fontFamily||y.typography.fontFamily,fontSize:"16px",fontWeight:500,color:x?b.textSecondary:"#7d7c7b",lineHeight:"24px"},children:r}),c&&n?.asset&&i("span",{style:{fontFamily:f?.fontFamily||y.typography.fontFamily,fontSize:"12px",fontWeight:500,color:x?b.textSecondary:"#71757a",lineHeight:"16px"},children:["Balance: ",ao(n.asset.balanceFormatted)]})]}),i("div",{style:{display:"flex",justifyContent:g&&!h?"flex-start":"space-between",alignItems:"center",flex:1},children:[!g&&e("input",{type:"text",value:W,onChange:R=>E(R.target.value),placeholder:u,disabled:a||!n?.asset,style:{fontFamily:f?.fontFamily||y.typography.fontFamily,fontSize:"40px",fontWeight:700,color:a?x?"rgba(255, 255, 255, 0.16)":"rgba(14, 13, 11, 0.16)":W?x?"#ffffff":"#0e0d0b":x?"#4a5568":"#d1d5db",lineHeight:"1.08",letterSpacing:"-1.2px",backgroundColor:"transparent",border:"none",outline:"none",padding:0,width:"100%",maxWidth:"200px"}}),e("div",{style:{width:"128px",position:"relative",flexShrink:0},children:e(As,{selectedAsset:n,assets:t,onAssetSelect:o,showDropdown:M,onToggleDropdown:()=>z(!M),disabled:a,theme:y})}),g&&h&&e("span",{style:{fontFamily:f?.fontFamily||y.typography.fontFamily,fontSize:"40px",fontWeight:700,color:x?"#ffffff":"#0e0d0b",lineHeight:"1.08",letterSpacing:"-1.2px",textAlign:"right",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h})]}),!g&&e("div",{style:{display:"flex",justifyContent:"flex-end",alignItems:"center",gap:"10px",height:"14px"},children:[0,25,50,75,100].map((R,H)=>{const q=Math.abs(X-R)<1,me=H===4,we=R/100,oe=T===R,ae=F===R;return e("button",{onClick:()=>O(R),onMouseEnter:()=>I(R),onMouseLeave:()=>{I(null),w(null)},onMouseDown:()=>w(R),onMouseUp:()=>w(null),disabled:a||!n?.asset,title:`${R}%`,style:{width:"14px",height:"14px",padding:0,border:"none",backgroundColor:"transparent",cursor:a||!n?.asset?"not-allowed":"pointer",opacity:q?1:oe?.8:.5,transform:ae?"scale(0.85)":oe?"scale(1.15)":"scale(1)",transition:"all 0.15s ease"},children:i("svg",{width:"14",height:"14",viewBox:"0 0 14 14",children:[e("circle",{cx:"7",cy:"7",r:"6.84375",fill:me?S:"none",stroke:me?S:x?"#4a5568":"#3C3E42",strokeWidth:"0.3125"}),!me&&we>0&&e("path",{d:`M 7 7 L 7 0.15625 A 6.84375 6.84375 0 ${we>.5?1:0} 1 ${7+6.84375*Math.sin(we*2*Math.PI)} ${7-6.84375*Math.cos(we*2*Math.PI)} Z`,fill:x?b.textSecondary:"#3C3E42"})]})},R)})})]})},Rn=Es,Bs=()=>{const[t,n]=B(!1);let o=null,s=null;try{o=no()}catch(p){s=p instanceof Error?p.message:String(p)}if($(()=>{n(!0)},[]),s)return{isReady:!1,isAuthenticated:!1,isConnected:!1,provider:"dynamic",actions:{signAuthorization:async()=>{throw new Error("Dynamic context not available")},signMessage:async()=>{throw new Error("Dynamic context not available")},getEthereumProvider:async()=>{throw new Error("Dynamic context not available")}}};const{user:a,primaryWallet:l,connectedWallets:r}=o||{},c=oo({connectedWallets:r,primaryWallet:l})||l,d=!!a,u=c?.address;return{isReady:t&&!!o,isAuthenticated:d,isConnected:d&&!!u,address:u,provider:"dynamic",actions:{signAuthorization:async p=>{if(!c)throw new Error("Dynamic embedded wallet not available");const{isEthereumWallet:f}=await import("@dynamic-labs/ethereum");if(!f(c))throw new Error("Embedded wallet is not an Ethereum wallet");const m=c.connector,g={address:c.address,chainId:p.chainId,contractAddress:p.contractAddress,nonce:p.nonce},h={address:p.contractAddress,chainId:p.chainId,nonce:p.nonce},C=typeof m?.getWaasWalletClient=="function"?await m.getWaasWalletClient():null;if(C&&typeof C.signRawMessage=="function"){const{hashAuthorization:y}=await import("viem/experimental"),{parseSignature:S}=await import("viem"),U={address:p.contractAddress,chainId:p.chainId,nonce:p.nonce},b=m.getSignedSessionId,x=typeof b=="function"?await b.call(m):void 0,M=m.getAuthToken,z=typeof M=="function"?M.call(m):void 0,T=await C.signRawMessage({accountAddress:c.address,authToken:z,context:{eip7702Auth:U},message:y(U).slice(2),signedSessionId:x}),I=S(T);return{address:g.contractAddress,chainId:g.chainId,contractAddress:g.contractAddress,nonce:BigInt(g.nonce),r:I.r,s:I.s,yParity:Number(I.yParity)}}if(typeof m?.signAuthorization=="function"){typeof m.switchNetwork=="function"&&await m.switchNetwork({networkChainId:p.chainId});const y=await m.signAuthorization(h);return ps(y,g)}throw new Error("Dynamic embedded wallet does not support EIP-7702 authorization. Ensure @dynamic-labs packages are v4.15+.")},signMessage:async p=>{if(!c)throw new Error("Dynamic embedded wallet not available");const{isEthereumWallet:f}=await import("@dynamic-labs/ethereum");if(!f(c))throw new Error("Embedded wallet is not an Ethereum wallet");const m=typeof p=="object"&&"raw"in p?{raw:p.raw}:p,g=await c.getWalletClient();if(!g)throw new Error("Dynamic wallet client not available");return{signature:await g.signMessage({message:m,account:c.address})}},getEthereumProvider:async()=>{if(!c)throw new Error("Dynamic embedded wallet not available");const{isEthereumWallet:p}=await import("@dynamic-labs/ethereum");if(!p(c))throw new Error("Embedded wallet is not an Ethereum wallet");return Xo(c)}}}},en=()=>{const t=It(xt),n=t?.mode||"7702";let o=null,s=null;try{o=go(),{user:s}=to()}catch{o=null}const a=o?.wallets?.find(d=>d.connectorType==="embedded")?.address,l=s?.wallet?.address;let r=null;try{r=no()}catch{r=null}const c=(oo(r)||r?.primaryWallet)?.address;if(!(!t||n!=="7702"))return t.provider==="privy"?a??l:t.provider==="dynamic"?c:a??l??c},Fs=()=>{const t=It(xt)?.mode,{isConnected:n,address:o}=Yt();let s=null,a=null,l=null,r=null,c=null;try{s=to(),a=ls(),l=ds(),r=go()}catch(m){c=m instanceof Error?m.message:String(m)}if(c)return t==="ondemand"&&n&&o?{isReady:!0,isAuthenticated:!0,isConnected:!0,address:o,provider:"privy",actions:{signAuthorization:async()=>{throw new Error("Not available in ondemand mode")},signMessage:async()=>{throw new Error("Not available in ondemand mode")},getEthereumProvider:async()=>{throw new Error("Not available in ondemand mode")}}}:{isReady:!1,isAuthenticated:!1,isConnected:!1,provider:null,actions:{signAuthorization:async()=>{throw new Error("Privy not available")},signMessage:async()=>{throw new Error("Privy not available")},getEthereumProvider:async()=>{throw new Error("Privy not available")}}};const{ready:d=!1,authenticated:u=!1}=s||{},p=en(),f=r?.wallets?.find(m=>m.connectorType==="embedded");return{isReady:t==="ondemand"?!0:d,isAuthenticated:t==="ondemand"?!0:u,isConnected:t==="ondemand"&&n&&!!o||d&&u&&!!p,address:t==="ondemand"&&!p&&n?o:p,provider:"privy",actions:{signAuthorization:async m=>{if(!a)throw new Error("Privy sign authorization not available");try{const g=await a.signAuthorization({contractAddress:m.contractAddress,chainId:m.chainId,nonce:m.nonce},{address:p});return delete g.v,g}catch(g){const h=g?.message||String(g);throw h.includes("not configured")||h.includes("chain")?new Error(`Chain ${m.chainId} is not configured in PrivyProvider. Add this chain to your Privy dashboard or supportedChainIds.`):g}},signMessage:async m=>{if(typeof m=="object"&&"raw"in m){if(!f)throw new Error("Embedded wallet not available for raw signing");const g=await f.getEthereumProvider();return{signature:await zn({account:f.address,transport:Un(g)}).signMessage({account:f.address,message:{raw:m.raw}})}}if(!l)throw new Error("Privy sign message not available");return{signature:(await l.signMessage({message:m})).signature}},getEthereumProvider:async()=>{if(!f)throw new Error("Embedded wallet not available");return f.getEthereumProvider()}}}},tn=()=>{const t=It(xt)?.provider,n=Fs(),o=Bs();return t==="privy"?n:t==="dynamic"?o:{isReady:!1,isAuthenticated:!1,isConnected:!1,provider:null,actions:{signAuthorization:async()=>{throw new Error("No wallet provider available")},signMessage:async()=>{throw new Error("No wallet provider available")},getEthereumProvider:async()=>{throw new Error("No wallet provider available")}}}};async function ko(t,n=3,o=1e3){let s;for(let a=0;a<=n;a++)try{return await t()}catch(l){s=l instanceof Error?l:new Error(String(l)),a<n&&(console.warn(`[withRetry] Attempt ${a+1}/${n} failed: ${s.message}. Retrying in ${o}ms...`),await new Promise(r=>setTimeout(r,o)))}throw s}const $o=({isSuccess:t,type:n,chainName:o,explorerUrl:s,txHash:a,dark:l=!1,successBg:r="#d1fae5",successBorder:c="#6ee7b7",successText:d="#065f46",errorBg:u="#fee2e2",errorBorder:p="#fca5a5",errorText:f="#dc2626",textSecondary:m="#6b7280"})=>i("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px",borderRadius:"8px",backgroundColor:t?r:u,border:t?`1px solid ${c}`:`1px solid ${p}`},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[e("div",{style:{width:"28px",height:"28px",borderRadius:"50%",backgroundColor:t?"#10b981":"#ef4444",display:"flex",alignItems:"center",justifyContent:"center"},children:t?e("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:e("path",{d:"M11.6667 3.5L5.25 9.91667L2.33333 7",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}):e("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:e("path",{d:"M10.5 3.5L3.5 10.5M3.5 3.5L10.5 10.5",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),i("div",{children:[e("p",{style:{margin:0,fontSize:"14px",fontWeight:600,fontFamily:'"IBM Plex Mono", monospace',letterSpacing:"0.5px",color:t?d:f},children:t?`${n.toUpperCase()} CONFIRMED`:`${n.toUpperCase()} FAILED`}),i("p",{style:{margin:"2px 0 0 0",fontSize:"12px",color:m},children:["on ",o]})]})]}),s&&a&&i("a",{href:`${s}/tx/${a}`,target:"_blank",rel:"noopener noreferrer",style:{display:"flex",alignItems:"center",gap:"4px",fontSize:"13px",color:m,textDecoration:"none",whiteSpace:"nowrap"},children:["View on explorer",i("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:[e("path",{d:"M9 6.5V9.5C9 9.76522 8.89464 10.0196 8.70711 10.2071C8.51957 10.3946 8.26522 10.5 8 10.5H2.5C2.23478 10.5 1.98043 10.3946 1.79289 10.2071C1.60536 10.0196 1.5 9.76522 1.5 9.5V4C1.5 3.73478 1.60536 3.48043 1.79289 3.29289C1.98043 3.10536 2.23478 3 2.5 3H5.5",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),e("path",{d:"M7.5 1.5H10.5V4.5",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),e("path",{d:"M5 7L10.5 1.5",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"})]})]})]}),Ln=({isOpen:t,onClose:n,onComplete:o,closeOnComplete:s=!1,type:a,results:l,chainName:r="Network",explorerUrl:c,theme:d,styles:u,dark:p,intentStatus:f,onRetry:m,onNewTx:g,onRetryTx:h,asOverlay:C=!1,isProcessing:y=!1})=>{const S=d||Sn("light"),{primaryColor:U,dark:b,dk:x}=je(u,p),[M,z]=B(!1),T=b?x.cardBg:"#ffffff",I=b?"0 4px 20px rgba(0, 0, 0, 0.4)":"0 4px 20px rgba(0, 0, 0, 0.1)",F=b?"0 -4px 8px -2px rgba(0, 0, 0, 0.4)":"0 -4px 8px -2px rgba(0, 0, 0, 0.15)",w=b?x.textSecondary:"#6b7280",W=b?x.textPrimary:"#374151",Z=b?x.inputBg:"#f9fafb",D=b?x.inputBorder:"#e5e7eb",A=b?x.inputBg:"#f3f4f6",E=b?x.inputBorder:"#e5e7eb",[O,V]=B(!0),[P,X]=B(null),[se,R]=B(null);$(()=>{!t&&!f&&z(!1)},[t,f]);const H=()=>{z(!0),setTimeout(()=>{window.dispatchEvent(new CustomEvent("tx-complete",{detail:{type:a,results:l}})),window.dispatchEvent(new CustomEvent("spiceflow:action",{detail:{type:a,status:"success",results:l}})),o?.(),s&&n()},300)},q=()=>{V(!O)};if(f){const{steps:oe,overallStatus:ae}=f,de=ae==="processing",Me=ae==="success",ye=ae==="failed",We=oe.filter(L=>L.transactionHash)[0],ce=oe.length>1?oe.map(L=>L.chainName).filter(Boolean).join(" and "):r!=="Network"?r:oe[0]?.chainName||r,Ve=c||(We?Cn(We.chainId,We.transactionHash||"").replace(/\/tx\/.*$/,""):void 0),De=i(Qt,{children:[i("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"16px"},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"8px",cursor:"pointer"},onClick:q,children:[i("span",{style:{fontSize:"13px",fontWeight:500,color:w,fontFamily:u?.fontFamily||S.typography.fontFamily},children:[de?`Processing ${a.charAt(0).toUpperCase()+a.slice(1)}`:`${a.charAt(0).toUpperCase()+a.slice(1)} results`," "]}),e("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",style:{transform:O?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.3s ease"},children:e("path",{d:"M4 6L8 10L12 6",stroke:w,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})]}),!de&&e("button",{onClick:n,onMouseEnter:()=>X("close"),onMouseLeave:()=>{X(null),R(null)},onMouseDown:()=>R("close"),onMouseUp:()=>R(null),style:{background:se==="close"?b?x.hoverBg:"#f3f4f6":P==="close"?b?x.inputBg:"#f9fafb":"none",border:"none",borderRadius:"4px",cursor:"pointer",padding:"4px",display:"flex",alignItems:"center",justifyContent:"center",color:P==="close"||se==="close"?W:w,transform:se==="close"?"scale(0.9)":P==="close"?"scale(1.1)":"scale(1)",transition:"all 0.15s ease"},children:e("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:e("path",{d:"M12 4L4 12M4 4L12 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),e("div",{style:{marginBottom:"16px"},children:de?i("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"20px 16px",borderRadius:"8px",backgroundColor:A,border:`1px solid ${E}`,gap:"12px"},children:[e(An,{size:24,borderWidth:3,color:U}),i("div",{children:[e("p",{style:{margin:0,fontSize:"14px",fontWeight:600,fontFamily:'"IBM Plex Mono", monospace',letterSpacing:"0.5px",color:W},children:"PROCESSING TRANSACTION"}),i("p",{style:{margin:"2px 0 0 0",fontSize:"12px",color:w},children:["on ",ce]})]})]}):e($o,{isSuccess:Me,type:a,chainName:ce,explorerUrl:Ve,txHash:We?.transactionHash,dark:b,...b?{successBg:x.successBg,successBorder:x.successBorder,successText:x.successText,errorBg:x.errorBg,errorBorder:x.errorBorder,errorText:x.errorText}:{},textSecondary:w})}),e("div",{style:{overflow:"hidden",maxHeight:O?"300px":"0px",opacity:O?1:0,transition:"max-height 0.3s ease, opacity 0.3s ease",marginBottom:O?"16px":"0"},children:e("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:oe.map((L,Se)=>{const Ee=L.transactionHash?Cn(L.chainId,L.transactionHash):null;return i("div",{style:{padding:"10px 12px",borderRadius:"6px",backgroundColor:Z,border:`1px solid ${D}`,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e("span",{style:{fontSize:"13px",color:W},children:L.chainName?`On ${L.chainName}`:L.description||`Step ${Se+1}`}),i("span",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"12px",color:L.status==="success"?"#10b981":L.status==="failed"?"#ef4444":w,fontWeight:500},children:[Ee&&e("a",{href:Ee,target:"_blank",rel:"noopener noreferrer",style:{color:b?x.infoText:"#2563eb",textDecoration:"none"},onClick:te=>te.stopPropagation(),children:"View"}),L.status==="success"?"\u2713":L.status==="failed"?"\u2717":"\u25CB"]})]},Se)})})}),!de&&i("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[ye&&m&&e(Ge,{variant:"outline",fullWidth:!0,onClick:m,theme:S,styles:{button:{backgroundColor:U}},children:"TRY AGAIN"}),g&&i(Ge,{variant:"outline",fullWidth:!0,onClick:g,theme:S,styles:{button:{backgroundColor:U}},children:["NEW ",a.toUpperCase()," \u2192"]})]})]});return C?i("div",{style:{position:"absolute",bottom:0,left:0,right:0,zIndex:10,animation:M?"slideDown 0.3s ease-in forwards":"slideUp 0.3s ease-out forwards",pointerEvents:"auto"},children:[e("div",{style:{backgroundColor:T,borderRadius:"12px 12px 0 0",width:"100%",padding:"18px 24px 24px",boxShadow:F},children:De}),e("style",{children:`
23
+ `})]})},ys={WALLET_DISCONNECTED:"Wallet is not connected.",WALLET_REJECTED:"Transaction was rejected.",SIGNATURE_FAILED:"Signature failed. Please try again.",CONCURRENT_EXECUTION:"A transaction is already in progress.",ABORT:"Transaction was cancelled.",NO_VENUE_FOR_CHAIN:"No swap venue available for this chain.",NO_LIQUIDITY:"No liquidity available for this swap pair.",VENUE_API_ERROR:"Swap service error. Please try again.",ROUTE_TOKEN_NOT_FOUND:"Token not found in the registry.",ROUTE_UNSUPPORTED_INPUT:"This input token is not supported.",ROUTE_STRATEGY_ERROR:"No viable route found for this swap.",INVALID_PARAMS:"Invalid parameters. Please check your inputs.",RELAYER_ERROR:"Relayer error. Please try again.",RELAYER_EXECUTE_ERROR:"Transaction execution failed. Please try again.",RELAYER_STATUS_ERROR:"Failed to check transaction status.",ON_CHAIN_REVERT:"Transaction reverted on-chain. Please verify your inputs.",POLLING_EXHAUSTED:"Transaction status check timed out. It may still complete.",POLLING_CONSECUTIVE_FAILURES:"Lost connection to transaction status. It may still complete.",ALL_ATTEMPTS_FAILED:"All attempts failed. Please try again."},xs=[{test:t=>t.includes("user rejected")||t.includes("user denied")||t.includes("user cancelled")||t.includes("rejected the request")||t.includes("action_rejected"),message:"Transaction was rejected."},{test:t=>t.includes("4001"),message:"Transaction was rejected."},{test:t=>t.includes("insufficient funds")||t.includes("insufficient balance"),message:"Insufficient funds for this transaction."},{test:t=>t.includes("internal json-rpc error")||t.includes("internal error")||t.includes("an internal error was received"),message:"RPC Network error. Try switching your RPC endpoint or try again."},{test:t=>t.includes("network error")||t.includes("failed to fetch")||t.includes("econnrefused")||t.includes("timeout"),message:"Network connection error. Please check your connection."},{test:t=>t.includes("does not match the target chain")||t.includes("current chain of the wallet"),message:"Wrong network detected. Please switch to the correct network and try again."},{test:t=>t.includes("nonce too low")||t.includes("nonce has already been used"),message:"Transaction conflict. Please try again."},{test:t=>t.includes("cannot estimate gas")||t.includes("gas required exceeds"),message:"Unable to estimate gas. The transaction may fail \u2014 please verify your inputs."},{test:t=>t.includes("execution reverted")||t.includes("transaction reverted"),message:"Transaction would fail on-chain. Please verify your inputs and try again."}],Ot=(t,n="Something went wrong. Please try again.")=>{if(Xn(t)){const s=ys[t.code];if(s)return s}const o=qo(t).toLowerCase();for(const{test:s,message:a}of xs)if(s(o))return a;return n},bs=t=>{if(Xn(t))return t.code==="WALLET_REJECTED";const n=qo(t).toLowerCase();return n.includes("user rejected")||n.includes("user denied")||n.includes("user cancelled")||n.includes("rejected the request")||n.includes("action_rejected")||n.includes("4001")};function qo(t){if(!t)return"";if(typeof t=="string")return t;const n=t,o=n.message||n.reason||"",s=n.details||"";return`${o} ${s}`.trim()}var Go="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAA6lBMVEXc3NzX/v/1hRvZ2dnd3dzb29va7fpMaXHa1tPc3N35/v/c3Nzc3NzCrp/c3Nza2tp1PRbLsJzlr33uhSj0kTHcnWnUva7jdhuNX0B6Qhrsk0LOxMCFVDJ+RyGhfGTkeiGYVSHjdx3lij7khDPEsaPfoW/jgjLQuKXmgzB2PRb2hRvldhvjdRv4hhvpeRtwORb/ihryghvabhnsehrUaRjLXxXtfRt7PxXwexricRbRYhURFBeSTBe0XBrEZxmDRxiiVRrlgCbfzMAvLCmrWBgbMEh9UjBbOBe2pJi9byekk4nkgDHkgDJLNB7jlKArAAAAKXRSTlMzJv0TNSYsADUxKBwK/QUZ/URTx650/vqJ5YpMosxj3ezwkqa6/q3KrihQ98kAAAAJcEhZcwAACxMAAAsTAQCanBgAAATxSURBVHjapVeJcuI4EJXBdiRuw4JzDAFyzeIT22BsNgTIJNnM7Pz/90xLsmV5ChJm6SqqZOR+7teXWujsgLSqdU0jBCFCNK1ebR16D+39t1HXiKqqGDHBsCRavXEsQKutIVWln0aZ0BX8o7VbRwC06gS+LHQLIWAJqbc+A6iC+h7t3BCVVD8EaGgqOqSemaFqjcMA8PkP1RnEb0bIAPXD1peNqO8H0NQj1LkR2j6Ao/XLCOh/6JcQkOD/B/oUoV4GqGb6+HNdnCFUZYBG9nmsE/whBsZE5y9g0pAAcgcQQ1V0fAgDNnRFNQiW3cAA2lwfI3wxvunqyl4z4OOK3r0ZX2CUIbRzgFZOoHY9nW7NXt9QdFTGgCddMfq9cDudXteyLdLKAPII4NqXZcffzIPJQx8zDCFgev9hksw3fmf5pYalSCDJAGAw7Uz9zkuU2CNKRQiYPrIT76Xjwws5B/BjiwG0hQHAgIr/GHpeYvb+EtIzI88LH32+fy1MaDMAKOGCAUdYPnmmE82ERI7pPS25fsEB0UCgs4ZwVO08AwB5sT0zrmQSm7b94mff7yzPa8LBDQAQSSwo5DRsKxO7MF+mwNyIBAPwjHEhIQCNgOsHwnwmF4aeWwAcUEMO97DgABAvkUv13WgrqXeWQ7moGqiqFtkivJjTCADBDWTzZR9SE6pIquOSF6msGYdgPS0BSD4EJ6CikUB+DKcd2QkRB4hkF3SmQyyqHioKaViicF4AQEp7DqfgRJDCSwFxLlPQ5GMAAHJ9n4bRyQEcGkZ/HwColwBYHH3fXz6uHc+xnZgCxLDwnPXj0mcgUhRpOZSblTEE9c32ybMi27ELAHiILO9puwGIoXG48YEJ43UYzGYumG/LADbQcGezIFyPjRr+7aCREfTezLUqFtMB4QB87cSw4c56uqyPSz4A/S6UDuikqzkTmwLYfL1K4aFiVbolBCKHEWHlclahyRvMF4vFarWgOm5KV4vFnIbEqswuFUmD5oF0olAGFZ7+88VqvV05FMBZbderxZwXRqXEgSaSfCTp3cDiAIETvr2+riP64K1fX99ClhMA4AIH+YAqFVPGgGnFu+9v44Quk/Hb913suXyjzAGKSS7nnAEtgBg6WeAxLIjrLM56A+NQKueioVAGruW67OdWrCCwYqoS01XgZmLJHGhDkVqa3oXeSyUESaktvBrBJ5WU/sd3IxFI3tKKpkrwCDIQcjCkUfPAnIAJ+NSjcQ1tuuuNMCk11TORCVh5SEyWdXP2dmzxpk4TEzDnbMtM/lakligfLADQj3gOOysASNPd5l+QzS5NAWCVbUV9RTBol442cIIxsVnlwPthurtv/sOkeb9LQ2oS25qIcs6PNtmNvch0HBOKN/15P3h+5wDvz4P7/1IocNhzop7swvLxTjMpMm0viSa9m6/Pg+cf35j8gOXXm94kSjzbjIo8Esd7cbxCIBNzdNs3dAXdDQbN9ybIe3MwuEOKbvRvR2YigigNGNKMh28vu0ihswGp9ZuDJpNBs0+HFjjuUffyFpcnvfKQhbgym06wcnXHAe6umNWYjSlKkcXlMa8YpIrEIldMCMHyrLNvzDs0aBImxwyap4+6pw/bp4/71A/opAvH6Vee0y9dn1z70OfXvuziudcMSKdjLp786quecPWVL99Zfqt/ePkuX/8Jv/43Dl3/fwH9bPJ09nq7MQAAAABJRU5ErkJggg==",bo="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAQlBMVEVMaXGGl/+Elf+HmP+Hmf+Hl/+Gl/+Flv+Glv+Gl/+Gl/+Gl/////+On/+Akv/4+f/v8f/i5v+9x//S2P+tuP+erP+W3PvUAAAAC3RSTlMArBlx7Isy/vvOXbb4wDYAAAAJcEhZcwAACxMAAAsTAQCanBgAAALuSURBVHjarVfbtqsgDOxu0UBpkOv//+pJRC0i2HZ58uTeqzOEyYXkduvY/Tn8KSEBpFB/w3O8/WTjoCSS6dn4S6rha477QxFGS0nHM56ckJL/ox73b+CDQAQJujKiQxTDR4qH4LN109gP8Ti/uyI46K4BUagTLZ4Cz+CZAsWzhx/oeP3RyImhjf/7ePzmxF8Hr7+zNsP3eL7GkWH4Bc8MlQ7P3/DMsIvFKHRLPzBsTWVBizIfVNMBg9H7mLQxTRdUkb9tfJxebNZjywuJW1bf2xcw4WXtzDF5bVqXuJ9HwETHNnPYeHRii0THgcwQyBxTBDQ9Fx7dEBr0TOCDYyeS6aigsFsCQIFgBh9YiVgxQA7EqM9KiCiS95nh5WsGPZ4k8ZZFRqfoY4shy9i8AaExxRgTMgcApuSODPMdRtn02wc7Z9HkPMsPa1ZVOsiRygga4udfZ5vTKKx/7GIBVFJHCUy0r705DNu3LQ9kEQ6NxMTXwWzhUTD7xlJr2MLvrZCBVazy2OD0iaC4BGh1k4cSLOSbbIuujKW4wT76aYefrGswuBJSEoBeUnaFk7nQcKEIJZRXMPsfM95O3p3KKAoRa/cJTh0pHKMybSqyiO8wMsG0wzODi7UK9u0Ah7FIJAj1+UyQcl4Gqi2uax+L/siJVKQyi+j251sbMoHTZrUqlctiojDGRX27WpivYNtdi4upKme0c/gXBmdzY7ZoOi/cWDeU7MJy+oKn3hzbT9/cFKt6pmKe9udnCoTeG103VW7EjrGZJMOD863GNzfVQ0EDP6aJUH61wBRHGZa23npYDDpuh8EnpPBRS6UUQOg9r8enzaDdmhmsPkH/da3bokkr/i0dwMmYU7lg0pRrwiVzNrW+n/dKhVzVVIbGnE9Jj86IA8glk87h+xGnGrJyzXwYNvdD1uUx7/qgeX3UvT5sXx/3ry8c11ee60vX9bXvvXjWfsC3i+d79YV19+WPH1bf/7B8Lxy8/isBINTp+v8Ph4CTcAywkiYAAAAASUVORK5CYII=",Cs="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAPFBMVEVMaXGZhueZh+eYhuWXheWYh+eYhuaXheCYhuaah+j//fmhjvOSf+Sdi+q8sOzNxO/m4fT08fapmuja0/Jb/wGxAAAACnRSTlMArEz/IYtsA87sGIEBYwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAmJJREFUeNqtV4uSgyAMRIECGhTk///1otTKG3s2Mzdz03aXbEJIQkhuYv9jIx+komhKDnxk4v1F1wT+SoxcUj3PWu8Ex39U8lH4bzt4QthL6tlDA8OP5Iv1vMADGFc5+uRQnDWdEES81EwbNquXqDuBx8va6ZcXktUYBOkc/3GixsBvwA8neFGGGO7hdyeGAsMXeM/wBJ8ziLv6LwYeisD4f4lHhiAXmH9FvzYV3AchOw6At9gFKW4KANDbsttGoSyCKd1Ab4uxkzezhBQaRfQygHB3oj2FhjwT9QgifErM6jiOrQgAXe2UmcuiIKSuHG+mki2XCH0kYqzgF1vETyYszLFaxLBMNdsgDGNFAazRoUcwrDMlDYz28RS0newGcCRlDa8TK4YgxuORGj9x8NYVEsxjKQSp/pNAw5YRcJI/JP5nYeqxjAxeIfCeRQQDyWOos/y5xR2V4NIgYhRJVkjgpralBPcvQH4PsBxIX0DjJqKRdgYLtsYPUyqh60CsACXEQew7ECvAICZp7DqwQEIQXaR+CkzaoeKr3FewQdqg4mIy36VgLyZWz4G96N5vs8sKj0UPSlJGy4fAbWX88SgGQYgJVjDXi7JaaxYo9Oj4UQ0lrHCGdN25ceiEfNoZSfIomjhcKN26DarT0q4gaiyfe2C9u9hWNUBvRghbG+yd1AZNFFrjmu+ucXMF2j60OObE7f0m+mrv/5qQkimpO+IU8fKXQ9bDMe/5oPl81P3BsP183EeGu3GoLBw/WHnuLF20sXQ9X/ueL57PV99w+Z7P5Vvj8j3fXr7j9X/f/5Vsrv9/K3NM7mGXOq0AAAAASUVORK5CYII=";const $t=ho(1)?.logo??"";ho(42161)?.logo;const Nn=fo.find(t=>t.symbol==="USDC")?.logo??"";fo.find(t=>t.symbol==="WBTC")?.logo;const zt=Object.fromEntries([...$r(),..._r()].map(t=>[t.id,t.logo])),so={metamask:Go,metaMask:Go,rabby:bo,phantom:Cs},ws=Object.fromEntries(fo.map(t=>[t.symbol,t.logo])),_t=({symbol:t,logoURI:n,size:o=20,theme:s})=>{const a=s||Sn("dark"),[l,r]=B(!1),c={width:`${o}px`,height:`${o}px`,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",fontSize:`${o*.4}px`,fontWeight:a.typography.fontWeight.bold,flexShrink:0,overflow:"hidden",backgroundColor:"#ffffff"},d=t.toUpperCase(),u=n||ws[d];if(u&&!l)return e("img",{src:u,alt:t,style:{...c,objectFit:"cover"},onError:()=>r(!0)});const p=vs(t);return e("div",{style:{...c,...p.style},children:p.icon})},vs=t=>{const n=t.toUpperCase(),o={ETH:{bg:"#627EEA",text:"#FFFFFF",icon:"\u039E"},BTC:{bg:"#F7931A",text:"#FFFFFF",icon:"\u20BF"},USDC:{bg:"#2775CA",text:"#FFFFFF"},USDT:{bg:"#26A17B",text:"#FFFFFF"},DAI:{bg:"#F5AC37",text:"#FFFFFF"},WETH:{bg:"#627EEA",text:"#FFFFFF",icon:"\u039E"},WBTC:{bg:"#F09242",text:"#FFFFFF",icon:"\u20BF"},CBTC:{bg:"#F7931A",text:"#FFFFFF",icon:"\u20BF"},USD:{bg:"#26A17B",text:"#FFFFFF",icon:"$"},MATIC:{bg:"#8247E5",text:"#FFFFFF"},AVAX:{bg:"#E84142",text:"#FFFFFF"},SOL:{bg:"#9945FF",text:"#FFFFFF"},DOT:{bg:"#E6007A",text:"#FFFFFF"},ADA:{bg:"#0033AD",text:"#FFFFFF"},LINK:{bg:"#375BD2",text:"#FFFFFF"},UNI:{bg:"#FF007A",text:"#FFFFFF"},AAVE:{bg:"#B6509E",text:"#FFFFFF"},CRV:{bg:"#40E0D0",text:"#000000"}}[n];if(o)return{style:{backgroundColor:o.bg,color:o.text},icon:o.icon||n.charAt(0)};const s=n.split("").reduce((c,d)=>d.charCodeAt(0)+((c<<5)-c),0),a=Math.abs(s)%360,l=`hsl(${a}, 60%, 50%)`,r=a>180?"#FFFFFF":"#000000";return{style:{backgroundColor:l,color:r},icon:n.charAt(0)}};var Co="data:image/svg+xml,%3csvg width='15' height='15' viewBox='0 0 15 15' fill='none' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M7.5 7.49993V10.4999M7.5 4.96868V4.96784M14.25 7.5C14.25 11.2279 11.2279 14.25 7.5 14.25C3.77208 14.25 0.75 11.2279 0.75 7.5C0.75 3.77208 3.77208 0.75 7.5 0.75C11.2279 0.75 14.25 3.77208 14.25 7.5Z' stroke='%23ED6969' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3e%3c/svg%3e";const ks=({isOpen:t,onClose:n,onComplete:o,title:s="Testnet Airdrop",description:a="Request testnet tokens for your wallet. A small gas fee is required to process the airdrop.",chainId:l,airdropTag:r="default",walletAddress:c,airdropTokens:d,getChainConfig:u,getSupportedTokens:p})=>{const f=Sn("light"),{primaryColor:m}=je(),[g,h]=B(null),[C,y]=B(null),{chain:S}=Yt(),{data:U}=qn(),{switchChainAsync:b}=Bn(),x=Ce(()=>p(l),[l,p]),M=Ce(()=>x.filter(A=>!rt(A.address)),[x]),{data:z,refetch:T}=jo({contracts:M.map(A=>({address:A.address,abi:At,functionName:"balanceOf",args:[c],chainId:l})),blockTag:"pending"}),I=ie(()=>{T();const A=setTimeout(T,2e3),E=setTimeout(T,4e3);return()=>{clearTimeout(A),clearTimeout(E)}},[T]);$(()=>t?I():void 0,[t,I]),$(()=>{let A;const E=()=>{A?.(),A=I()};return window.addEventListener("airdrop-complete",E),()=>{A?.(),window.removeEventListener("airdrop-complete",E)}},[I]);const F=Ce(()=>{const A=[];return M.forEach((E,O)=>{if(!d.some(se=>se.toUpperCase()===E.symbol.toUpperCase()))return;const V=z?.[O],P=V?.status==="success"?V.result:BigInt(0),X=Number(P)/Math.pow(10,E.decimals);A.push({address:E.address,symbol:E.symbol,name:E.name,decimals:E.decimals,balance:P,balanceFormatted:X})}),A},[M,z,d]),w=u(l),W="0x11126A138f34532D250CCf35531E5A2f398ce7d4",Z=ie(async A=>{if(!c||!l){y({message:"Wallet not connected",type:"error"});return}if(!U){y({message:"Wallet client not available",type:"error"});return}h(A.address);try{S?.id!==l&&await b({chainId:l});const E=ct(l),O=await E.getGasPrice(),V=BigInt(21e3)*O*BigInt(110)/BigInt(100),P=await U.sendTransaction({to:W,value:V});await E.waitForTransactionReceipt({hash:P,timeout:6e4,pollingInterval:2e3,confirmations:1});const X=await qe.requestAirdrop({chainId:l,tokenId:A.symbol==="WBTC"?"mWBTC":A.symbol,wallet:c,tag:r});if(X.success){const se=w?.blockExplorer;y({message:`Successfully airdropped ${A.symbol}!`,type:"success",linkText:X.txHash?"View Transaction":void 0,linkUrl:X.txHash&&se?`${se}/tx/${X.txHash}`:void 0}),window.dispatchEvent(new CustomEvent("airdrop-complete",{detail:{token:A.symbol,txHash:X.txHash}})),o&&o()}else y({message:X.errorMessage||"Airdrop failed",type:"error"})}catch(E){y({message:Ot(E,"Airdrop request failed"),type:"error"})}finally{h(null)}},[c,l,U,S,b,r,w,o]),D=ie(()=>{window.dispatchEvent(new CustomEvent("airdrop-skipped"))},[n]);return i(Dt,{isOpen:t,onClose:n,title:s,subtitle:i("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:Co,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})]}),theme:f,maxWidth:"420px",children:[i("div",{style:{padding:"0 24px 32px 24px"},children:[e("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:F.length===0?e("p",{style:{textAlign:"center",color:"#6b7280",fontSize:"14px",padding:"20px 0"},children:"No airdrop tokens available for this chain."}):F.map(A=>{const E=g===A.address,O=E||g!==null;return i("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",borderRadius:"12px",border:"1px solid #e5e7eb",backgroundColor:"white",transition:"all 150ms ease"},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[e(_t,{symbol:A.symbol,size:36,theme:f}),i("div",{children:[e("div",{style:{fontSize:"16px",fontWeight:600,color:"#111827"},children:A.symbol}),i("div",{style:{fontSize:"12px",color:"#6b7280",fontFamily:'"IBM Plex Mono", monospace'},children:["Balance:"," ",A.balanceFormatted?.toFixed(4)??"0.0000"]})]})]}),e(Ge,{variant:"outline",size:"sm",onClick:()=>Z(A),disabled:O,loading:E,theme:f,styles:{button:{backgroundColor:m}},children:"Get Airdrop"})]},A.address)})}),e(Ge,{variant:"outline",fullWidth:!0,onClick:D,disabled:g!==null,theme:f,styles:{button:{backgroundColor:m}},style:{marginTop:"20px"},children:"NEXT"})]}),C&&e(xo,{message:C.message,type:C.type,linkText:C.linkText,linkUrl:C.linkUrl,onClose:()=>y(null)})]})},wo=15,vo=({checkStepStatus:t,pollingInterval:n=4e3,retryStep:o,maxRetries:s=3})=>{const[a,l]=B(null),r=Fe(null),c=Fe(!1),d=Fe(!1),u=Fe(null),p=Fe({}),f=Fe(0),m=Fe(0),g=ie(()=>{r.current&&(clearInterval(r.current),r.current=null)},[]),h=ie(()=>{u.current=null,l(null),p.current={},f.current=0,m.current=0,g()},[g]),C=ie((y,S)=>{g(),c.current=!1,d.current=!1,p.current={},f.current=0,m.current=0;const U={intentId:y,steps:S.map(x=>({...x,status:"pending"})),overallStatus:"processing"};u.current=U,l(U);const b=async()=>{if(c.current||d.current)return;d.current=!0,m.current+=1;const x=m.current;try{const M=u.current;if(!M)return;const z=M.steps.map(w=>({...w}));let T=!0,I=!1;for(let w=0;w<z.length;w++){const W=z[w];if(W.status!=="success"){if((W.stepId===0||w>0&&z[w-1].status==="success")&&(W.status==="pending"||W.status==="processing"))try{const Z=await t(y,W.stepId);if(f.current=0,Z.data.status==="success")z[w]={...W,status:"success",transactionHash:Z.data.transactionHash},w+1<z.length&&z[w+1].status==="pending"&&(z[w+1]={...z[w+1],status:"processing"});else if(Z.data.status==="executing"||Z.data.status==="created")z[w]={...W,status:"processing"};else if(Z.data.status==="reverted"){const D=p.current[W.stepId]||0;if(o&&D<s){p.current[W.stepId]=D+1;try{await o(y,W.stepId)}catch(A){console.error(`[useStatus] Retry failed for step ${W.stepId}:`,A)}z[w]={...W,status:"processing"}}else z[w]={...W,status:"failed",transactionHash:Z.data.transactionHash},I=!0}else z[w]={...W,status:"processing"}}catch(Z){f.current+=1,console.error(`[useStatus] Poll #${x}: Error checking step ${W.stepId} (consecutive errors: ${f.current}/${wo}):`,Z),f.current>=wo&&(console.error(`[useStatus] Too many consecutive polling errors (${wo}). Marking step ${W.stepId} as failed.`),z[w]={...W,status:"failed"},I=!0)}z[w].status!=="success"&&(T=!1)}}const F={...M,steps:z,overallStatus:I?"failed":T?"success":"processing"};u.current=F,l(F),(T||I)&&(c.current=!0,g())}finally{d.current=!1}};b(),r.current=setInterval(b,n)},[t,n,g,o,s]);return $(()=>()=>{g()},[g]),{intentStatus:a,startStatusPolling:C,stopStatusPolling:g,clearStatus:h}},Fn=({address:t,supportedChains:n,enabled:o=!0,refetchInterval:s})=>{const a=It(xt)?.apiUrl||Zr,[l,r]=B([]),[c,d]=B(!1),[u,p]=B(null),[f,m]=B(!1),g=Fe(!1),h=Fe(!1),C=n?JSON.stringify([...n].sort()):"",y=ie(async(b=!1)=>{if(!t||!o){r([]),m(!1),g.current=!1;return}if(!h.current){h.current=!0,!g.current&&!b&&d(!0),p(null);try{const x=await fetch(`${a}/spicedeposit/${t}`);if(!x.ok)throw new Error(`Failed to fetch balance: ${x.status}`);const M=await x.json();if(M.success&&M.data?.tokens&&Array.isArray(M.data.tokens)){const z=new Map;M.data.tokens.forEach(I=>{const F=I.chainId,w=I.tokenAddress,W=I.amount;if(n&&!n.includes(F))return;const Z=BigInt(W||"0");if(Z>BigInt(0)){const D=Ke(F),A=rt(w),E=A?Kt:w.toLowerCase();let O=18,V="TOKEN",P=w.slice(0,6)+"..."+w.slice(-4),X;if(A)O=D?.nativeCurrency?.decimals||18,V=D?.nativeCurrency?.symbol||"ETH",P=D?.nativeCurrency?.name||"Native Token";else{const R=D?.supportedTokens?.find(H=>H.address.toLowerCase()===w.toLowerCase());R&&(O=R.decimals,V=R.symbol,P=R.name,X=R.logo)}const se=parseFloat((Number(Z)/Math.pow(10,O)).toFixed(6));if(se>0){const R=`${E}-${F}`,H=z.get(R);if(H){const q=H.balance+Z,me=parseFloat((Number(q)/Math.pow(10,O)).toFixed(6));z.set(R,{...H,balance:q,balanceFormatted:me})}else z.set(R,{address:E,symbol:V,name:P,decimals:O,chainId:F,balance:Z,balanceFormatted:se,balanceUsd:0,isNative:A,logoURI:X})}}});const T=Array.from(z.values());r(T),m(T.length>0),g.current=!0}else r([]),m(!1)}catch(x){const M=x instanceof Error?x.message:"Failed to fetch balance";p(M),console.error("Error fetching Spice assets:",x),g.current||(r([]),m(!1))}finally{d(!1),h.current=!1}}},[t,o,C,a]);$(()=>{o&&t&&(g.current=!1,y(!1))},[t,o,C]),$(()=>{if(!o||!t||!s)return;const b=setInterval(()=>{y(!0)},s);return()=>clearInterval(b)},[t,o,s,C]);const S=ie(b=>l.filter(x=>x.chainId===b),[l]),U=ie(async()=>{await y(!0)},[y]);return{assets:l,loading:c,error:u,hasBalance:f,refetch:U,getAssetsByChain:S}},ao=(t,n=4)=>!isFinite(t)||t===0?"0":t<1e-4?"< 0.0001":t.toFixed(n),Mn=t=>isFinite(t)?t>0&&t<.01?"<$0.01":new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(t):"$0.00",Is=(t,n=6,o=4)=>t.length<=n+o?t:`${t.slice(0,n)}...${t.slice(-o)}`,Jo=t=>{const n=t.replace(/[^0-9.]/g,""),o=n.split(".");return o.length>2?o[0]+"."+o.slice(1).join(""):n},Ss=async t=>{try{return await navigator.clipboard.writeText(t),!0}catch(n){return console.error("Failed to copy to clipboard:",n),!1}},Pn=({chainId:t,name:n,size:o=16})=>{const s=t&&(zt[t]||ho(t)?.logo)||"";return s?e("img",{src:s,alt:n||`Chain ${t}`,style:{width:`${o}px`,height:`${o}px`,borderRadius:"50%",objectFit:"cover",flexShrink:0}}):null},As=({selectedAsset:t,assets:n,onAssetSelect:o,showDropdown:s,onToggleDropdown:a,disabled:l=!1,theme:r})=>{const c=r||Sn("dark"),d=Fe(null),u=Fe(null),p=Fe(null),[f,m]=B(null);$(()=>{if(s&&u.current){const I=()=>{if(u.current){const F=u.current.getBoundingClientRect();m({top:F.bottom+6,right:window.innerWidth-F.right})}};return I(),window.addEventListener("scroll",I,!0),window.addEventListener("resize",I),()=>{window.removeEventListener("scroll",I,!0),window.removeEventListener("resize",I)}}else m(null)},[s]),$(()=>{const I=F=>{d.current&&!d.current.contains(F.target)&&p.current&&!p.current.contains(F.target)&&s&&a()};return s&&document.addEventListener("mousedown",I),()=>{document.removeEventListener("mousedown",I)}},[s,a]);const[g,h]=B(!1),C={backgroundColor:"transparent",border:`1px solid ${c.mode==="light"?"#aaaaaa":c.colors.border}`,borderRadius:"6px",color:c.colors.text,cursor:l?"not-allowed":"pointer",padding:"8px 12px 8px 8px",width:"100%",display:"flex",flexDirection:"column",gap:"4px",opacity:l?.6:1,transition:"all 0.15s ease",transform:g?"scale(0.98)":"scale(1)"},y={display:"flex",justifyContent:"space-between",alignItems:"center"},S={display:"flex",alignItems:"center",gap:"4px",paddingTop:"4px",borderTop:`1px solid ${c.colors.border}`},U=()=>f?{position:"fixed",top:`${f.top}px`,right:`${f.right}px`,backgroundColor:c.colors.secondary,border:`1px solid ${c.colors.border}`,borderRadius:c.borderRadius.md,boxShadow:c.shadows.lg,zIndex:100,width:"200px",maxHeight:"300px",overflow:"auto"}:{},b={backgroundColor:"transparent",border:"none",color:c.colors.text,cursor:"pointer",padding:c.spacing.sm,width:"100%",display:"flex",alignItems:"center",gap:c.spacing.sm,transition:`background-color ${c.animation.normal}`,":hover":{backgroundColor:c.colors.surfaceHover}},x={display:"flex",flexDirection:"column",alignItems:"flex-start",flex:1},M={fontSize:c.typography.fontSize.sm,fontWeight:c.typography.fontWeight.medium},z={fontSize:c.typography.fontSize.xs,color:c.colors.textMuted},T={transition:`transform ${c.animation.normal}`,transform:s?"rotate(180deg)":"rotate(0deg)"};return i(Qt,{children:[e("div",{style:{position:"relative"},ref:d,children:i("div",{ref:u,style:C,onClick:l?void 0:a,onMouseLeave:()=>{h(!1)},onMouseDown:()=>h(!0),onMouseUp:()=>h(!1),children:[i("div",{style:y,children:[e("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:t?.asset?i(Qt,{children:[e(_t,{symbol:t.asset.symbol,logoURI:t.asset.logoURI,theme:c,size:24}),e("span",{style:{fontSize:"16px",fontWeight:500,color:c.colors.text,lineHeight:"1.5"},children:t.asset.symbol})]}):e("span",{style:{fontSize:"14px",color:c.colors.textMuted},children:"Select"})}),e("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:c.colors.textMuted,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:T,children:e("path",{d:"M6 9l6 6 6-6"})})]}),t?.asset&&i("div",{style:S,children:[e(Pn,{chainId:t.asset.chainId,theme:c}),e("span",{style:{fontSize:"11px",color:c.colors.textMuted},children:vt(t.asset.chainId)})]})]})}),s&&f&&Zo(i("div",{ref:p,style:U(),children:[n.length===0&&e("div",{style:{padding:"10px 12px",color:c.colors.textMuted,fontSize:c.typography.fontSize.xs},children:"No assets available"}),n.map(I=>i("button",{style:b,onClick:()=>{o(I),a()},children:[e(_t,{symbol:I.symbol,logoURI:I.logoURI,theme:c},`${I.address}-${I.chainId}`),i("div",{style:x,children:[i("div",{style:{display:"flex",alignItems:"center",gap:c.spacing.xs},children:[e("span",{style:M,children:I.symbol}),e(Pn,{chainId:I.chainId,theme:c})]}),i("span",{style:z,children:[ao(I.balanceFormatted)," \u2022"," ",vt(I.chainId)]})]})]},`${I.address}-${I.chainId}`))]}),document.body)]})},Es=({assets:t,selectedAsset:n,onAssetSelect:o,onAmountChange:s,disabled:a=!1,loading:l=!1,label:r="Select Asset",showBalance:c=!0,showMaxButton:d=!0,placeholder:u="0.0",theme:p,styles:f,maxAmount:m,hideAmountInput:g=!1,displayAmount:h,dark:C})=>{const y=p||Sn("dark"),{primaryColor:S,dark:U,dk:b}=je(f,C),x=C??U,[M,z]=B(!1),[T,I]=B(null),[F,w]=B(null),[W,Z]=B(n?.amount||""),D=Fe(null),A=Fe("");$(()=>{const R=n?.asset?`${n.asset.chainId}-${n.asset.address}`:"";R!==A.current&&(Z(n?.amount||""),A.current=R)},[n?.asset?.chainId,n?.asset?.address,n?.amount]);const E=R=>{let H=R;H.startsWith(".")&&(H="0"+H);const q=Jo(H);if(!q){Z(q),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{s(q)},300);return}if(m&&parseFloat(q)>parseFloat(m)){Z(m),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{s(m)},300);return}if(n?.asset){const me=parseFloat(q),we=n.asset.balanceFormatted;if(!isNaN(me)&&me>we){const oe=(Math.floor(we*1e6)/1e6).toString();Z(oe),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{s(oe)},300);return}}Z(q),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{s(q)},300)},O=R=>{if(n?.asset){const H=n.asset.balanceFormatted*R/100;let q=Math.floor(H*1e6)/1e6;m&&q>parseFloat(m)&&(q=parseFloat(m));const me=q.toString();Z(me),D.current&&clearTimeout(D.current),s(me)}},V=n?.asset?.balanceFormatted??0,P=parseFloat(W)||0,X=V>0?P/V*100:0;$(()=>()=>{D.current&&clearTimeout(D.current)},[]);const se={backgroundColor:f?.assetSelector?.backgroundColor||f?.secondaryBackground||(x?b.cardBg:"#e9e9e9"),border:x?`0.5px solid ${b.cardBorder}`:"0.5px solid #A8A8A7",borderRadius:f?.assetSelector?.borderRadius||"6px",padding:f?.assetSelector?.padding||"16px",height:"auto",minHeight:g?void 0:"144px",display:"flex",flexDirection:"column",gap:"8px",position:"relative",opacity:a?.6:1};return l?e("div",{style:se,children:i("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[i("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e("div",{style:{backgroundColor:x?b.hoverBg:"#d1d5db",borderRadius:"4px",height:"16px",width:"60px"}}),e("div",{style:{backgroundColor:x?b.hoverBg:"#d1d5db",borderRadius:"4px",height:"40px",width:"150px"}})]}),i("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-end",gap:"8px"},children:[e("div",{style:{backgroundColor:x?b.hoverBg:"#d1d5db",borderRadius:"4px",height:"12px",width:"80px"}}),e("div",{style:{backgroundColor:x?b.hoverBg:"#d1d5db",borderRadius:"6px",height:"46px",width:"128px"}})]})]})}):i("div",{style:se,children:[i("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e("span",{style:{fontFamily:f?.fontFamily||y.typography.fontFamily,fontSize:"16px",fontWeight:500,color:x?b.textSecondary:"#7d7c7b",lineHeight:"24px"},children:r}),c&&n?.asset&&i("span",{style:{fontFamily:f?.fontFamily||y.typography.fontFamily,fontSize:"12px",fontWeight:500,color:x?b.textSecondary:"#71757a",lineHeight:"16px"},children:["Balance: ",ao(n.asset.balanceFormatted)]})]}),i("div",{style:{display:"flex",justifyContent:g&&!h?"flex-start":"space-between",alignItems:"center",flex:1},children:[!g&&e("input",{type:"text",value:W,onChange:R=>E(R.target.value),placeholder:u,disabled:a||!n?.asset,style:{fontFamily:f?.fontFamily||y.typography.fontFamily,fontSize:"40px",fontWeight:700,color:a?x?"rgba(255, 255, 255, 0.16)":"rgba(14, 13, 11, 0.16)":W?x?"#ffffff":"#0e0d0b":x?"#4a5568":"#d1d5db",lineHeight:"1.08",letterSpacing:"-1.2px",backgroundColor:"transparent",border:"none",outline:"none",padding:0,width:"100%",maxWidth:"200px"}}),e("div",{style:{width:"128px",position:"relative",flexShrink:0},children:e(As,{selectedAsset:n,assets:t,onAssetSelect:o,showDropdown:M,onToggleDropdown:()=>z(!M),disabled:a,theme:y})}),g&&h&&e("span",{style:{fontFamily:f?.fontFamily||y.typography.fontFamily,fontSize:"40px",fontWeight:700,color:x?"#ffffff":"#0e0d0b",lineHeight:"1.08",letterSpacing:"-1.2px",textAlign:"right",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h})]}),!g&&e("div",{style:{display:"flex",justifyContent:"flex-end",alignItems:"center",gap:"10px",height:"14px"},children:[0,25,50,75,100].map((R,H)=>{const q=Math.abs(X-R)<1,me=H===4,we=R/100,oe=T===R,ae=F===R;return e("button",{onClick:()=>O(R),onMouseEnter:()=>I(R),onMouseLeave:()=>{I(null),w(null)},onMouseDown:()=>w(R),onMouseUp:()=>w(null),disabled:a||!n?.asset,title:`${R}%`,style:{width:"14px",height:"14px",padding:0,border:"none",backgroundColor:"transparent",cursor:a||!n?.asset?"not-allowed":"pointer",opacity:q?1:oe?.8:.5,transform:ae?"scale(0.85)":oe?"scale(1.15)":"scale(1)",transition:"all 0.15s ease"},children:i("svg",{width:"14",height:"14",viewBox:"0 0 14 14",children:[e("circle",{cx:"7",cy:"7",r:"6.84375",fill:me?S:"none",stroke:me?S:x?"#4a5568":"#3C3E42",strokeWidth:"0.3125"}),!me&&we>0&&e("path",{d:`M 7 7 L 7 0.15625 A 6.84375 6.84375 0 ${we>.5?1:0} 1 ${7+6.84375*Math.sin(we*2*Math.PI)} ${7-6.84375*Math.cos(we*2*Math.PI)} Z`,fill:x?b.textSecondary:"#3C3E42"})]})},R)})})]})},Rn=Es,Bs=()=>{const[t,n]=B(!1);let o=null,s=null;try{o=no()}catch(p){s=p instanceof Error?p.message:String(p)}if($(()=>{n(!0)},[]),s)return{isReady:!1,isAuthenticated:!1,isConnected:!1,provider:"dynamic",actions:{signAuthorization:async()=>{throw new Error("Dynamic context not available")},signMessage:async()=>{throw new Error("Dynamic context not available")},getEthereumProvider:async()=>{throw new Error("Dynamic context not available")}}};const{user:a,primaryWallet:l,connectedWallets:r}=o||{},c=oo({connectedWallets:r,primaryWallet:l})||l,d=!!a,u=c?.address;return{isReady:t&&!!o,isAuthenticated:d,isConnected:d&&!!u,address:u,provider:"dynamic",actions:{signAuthorization:async p=>{if(!c)throw new Error("Dynamic embedded wallet not available");const{isEthereumWallet:f}=await import("@dynamic-labs/ethereum");if(!f(c))throw new Error("Embedded wallet is not an Ethereum wallet");const m=c.connector,g={address:c.address,chainId:p.chainId,contractAddress:p.contractAddress,nonce:p.nonce},h={address:p.contractAddress,chainId:p.chainId,nonce:p.nonce},C=typeof m?.getWaasWalletClient=="function"?await m.getWaasWalletClient():null;if(C&&typeof C.signRawMessage=="function"){const{hashAuthorization:y}=await import("viem/experimental"),{parseSignature:S}=await import("viem"),U={address:p.contractAddress,chainId:p.chainId,nonce:p.nonce},b=m.getSignedSessionId,x=typeof b=="function"?await b.call(m):void 0,M=m.getAuthToken,z=typeof M=="function"?M.call(m):void 0,T=await C.signRawMessage({accountAddress:c.address,authToken:z,context:{eip7702Auth:U},message:y(U).slice(2),signedSessionId:x}),I=S(T);return{address:g.contractAddress,chainId:g.chainId,contractAddress:g.contractAddress,nonce:BigInt(g.nonce),r:I.r,s:I.s,yParity:Number(I.yParity)}}if(typeof m?.signAuthorization=="function"){typeof m.switchNetwork=="function"&&await m.switchNetwork({networkChainId:p.chainId});const y=await m.signAuthorization(h);return ps(y,g)}throw new Error("Dynamic embedded wallet does not support EIP-7702 authorization. Ensure @dynamic-labs packages are v4.15+.")},signMessage:async p=>{if(!c)throw new Error("Dynamic embedded wallet not available");const{isEthereumWallet:f}=await import("@dynamic-labs/ethereum");if(!f(c))throw new Error("Embedded wallet is not an Ethereum wallet");const m=typeof p=="object"&&"raw"in p?{raw:p.raw}:p,g=await c.getWalletClient();if(!g)throw new Error("Dynamic wallet client not available");return{signature:await g.signMessage({message:m,account:c.address})}},getEthereumProvider:async()=>{if(!c)throw new Error("Dynamic embedded wallet not available");const{isEthereumWallet:p}=await import("@dynamic-labs/ethereum");if(!p(c))throw new Error("Embedded wallet is not an Ethereum wallet");return Xo(c)}}}},en=()=>{const t=It(xt),n=t?.mode||"7702";let o=null,s=null;try{o=go(),{user:s}=to()}catch{o=null}const a=o?.wallets?.find(d=>d.connectorType==="embedded")?.address,l=s?.wallet?.address;let r=null;try{r=no()}catch{r=null}const c=(oo(r)||r?.primaryWallet)?.address;if(!(!t||n!=="7702"))return t.provider==="privy"?a??l:t.provider==="dynamic"?c:a??l??c},Fs=()=>{const t=It(xt)?.mode,{isConnected:n,address:o}=Yt();let s=null,a=null,l=null,r=null,c=null;try{s=to(),a=ls(),l=ds(),r=go()}catch(m){c=m instanceof Error?m.message:String(m)}if(c)return t==="ondemand"&&n&&o?{isReady:!0,isAuthenticated:!0,isConnected:!0,address:o,provider:"privy",actions:{signAuthorization:async()=>{throw new Error("Not available in ondemand mode")},signMessage:async()=>{throw new Error("Not available in ondemand mode")},getEthereumProvider:async()=>{throw new Error("Not available in ondemand mode")}}}:{isReady:!1,isAuthenticated:!1,isConnected:!1,provider:null,actions:{signAuthorization:async()=>{throw new Error("Privy not available")},signMessage:async()=>{throw new Error("Privy not available")},getEthereumProvider:async()=>{throw new Error("Privy not available")}}};const{ready:d=!1,authenticated:u=!1}=s||{},p=en(),f=r?.wallets?.find(m=>m.connectorType==="embedded");return{isReady:t==="ondemand"?!0:d,isAuthenticated:t==="ondemand"?!0:u,isConnected:t==="ondemand"&&n&&!!o||d&&u&&!!p,address:t==="ondemand"&&!p&&n?o:p,provider:"privy",actions:{signAuthorization:async m=>{if(!a)throw new Error("Privy sign authorization not available");try{const g=await a.signAuthorization({contractAddress:m.contractAddress,chainId:m.chainId,nonce:m.nonce},{address:p});return delete g.v,g}catch(g){const h=g?.message||String(g);throw h.includes("not configured")||h.includes("chain")?new Error(`Chain ${m.chainId} is not configured in PrivyProvider. Add this chain to your Privy dashboard or supportedChainIds.`):g}},signMessage:async m=>{if(typeof m=="object"&&"raw"in m){if(!f)throw new Error("Embedded wallet not available for raw signing");const g=await f.getEthereumProvider();return{signature:await zn({account:f.address,transport:Un(g)}).signMessage({account:f.address,message:{raw:m.raw}})}}if(!l)throw new Error("Privy sign message not available");return{signature:(await l.signMessage({message:m})).signature}},getEthereumProvider:async()=>{if(!f)throw new Error("Embedded wallet not available");return f.getEthereumProvider()}}}},tn=()=>{const t=It(xt)?.provider,n=Fs(),o=Bs();return t==="privy"?n:t==="dynamic"?o:{isReady:!1,isAuthenticated:!1,isConnected:!1,provider:null,actions:{signAuthorization:async()=>{throw new Error("No wallet provider available")},signMessage:async()=>{throw new Error("No wallet provider available")},getEthereumProvider:async()=>{throw new Error("No wallet provider available")}}}};async function ko(t,n=3,o=1e3){let s;for(let a=0;a<=n;a++)try{return await t()}catch(l){s=l instanceof Error?l:new Error(String(l)),a<n&&(console.warn(`[withRetry] Attempt ${a+1}/${n} failed: ${s.message}. Retrying in ${o}ms...`),await new Promise(r=>setTimeout(r,o)))}throw s}const $o=({isSuccess:t,type:n,chainName:o,explorerUrl:s,txHash:a,dark:l=!1,successBg:r="#d1fae5",successBorder:c="#6ee7b7",successText:d="#065f46",errorBg:u="#fee2e2",errorBorder:p="#fca5a5",errorText:f="#dc2626",textSecondary:m="#6b7280"})=>i("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px",borderRadius:"8px",backgroundColor:t?r:u,border:t?`1px solid ${c}`:`1px solid ${p}`},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[e("div",{style:{width:"28px",height:"28px",borderRadius:"50%",backgroundColor:t?"#10b981":"#ef4444",display:"flex",alignItems:"center",justifyContent:"center"},children:t?e("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:e("path",{d:"M11.6667 3.5L5.25 9.91667L2.33333 7",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}):e("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:e("path",{d:"M10.5 3.5L3.5 10.5M3.5 3.5L10.5 10.5",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),i("div",{children:[e("p",{style:{margin:0,fontSize:"14px",fontWeight:600,fontFamily:'"IBM Plex Mono", monospace',letterSpacing:"0.5px",color:t?d:f},children:t?`${n.toUpperCase()} CONFIRMED`:`${n.toUpperCase()} FAILED`}),i("p",{style:{margin:"2px 0 0 0",fontSize:"12px",color:m},children:["on ",o]})]})]}),s&&a&&i("a",{href:`${s}/tx/${a}`,target:"_blank",rel:"noopener noreferrer",style:{display:"flex",alignItems:"center",gap:"4px",fontSize:"13px",color:m,textDecoration:"none",whiteSpace:"nowrap"},children:["View on explorer",i("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:[e("path",{d:"M9 6.5V9.5C9 9.76522 8.89464 10.0196 8.70711 10.2071C8.51957 10.3946 8.26522 10.5 8 10.5H2.5C2.23478 10.5 1.98043 10.3946 1.79289 10.2071C1.60536 10.0196 1.5 9.76522 1.5 9.5V4C1.5 3.73478 1.60536 3.48043 1.79289 3.29289C1.98043 3.10536 2.23478 3 2.5 3H5.5",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),e("path",{d:"M7.5 1.5H10.5V4.5",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),e("path",{d:"M5 7L10.5 1.5",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"})]})]})]}),Ln=({isOpen:t,onClose:n,onComplete:o,closeOnComplete:s=!1,type:a,results:l,chainName:r="Network",explorerUrl:c,theme:d,styles:u,dark:p,intentStatus:f,onRetry:m,onNewTx:g,onRetryTx:h,asOverlay:C=!1,isProcessing:y=!1})=>{const S=d||Sn("light"),{primaryColor:U,dark:b,dk:x}=je(u,p),[M,z]=B(!1),T=b?x.cardBg:"#ffffff",I=b?"0 4px 20px rgba(0, 0, 0, 0.4)":"0 4px 20px rgba(0, 0, 0, 0.1)",F=b?"0 -4px 8px -2px rgba(0, 0, 0, 0.4)":"0 -4px 8px -2px rgba(0, 0, 0, 0.15)",w=b?x.textSecondary:"#6b7280",W=b?x.textPrimary:"#374151",Z=b?x.inputBg:"#f9fafb",D=b?x.inputBorder:"#e5e7eb",A=b?x.inputBg:"#f3f4f6",E=b?x.inputBorder:"#e5e7eb",[O,V]=B(!0),[P,X]=B(null),[se,R]=B(null);$(()=>{!t&&!f&&z(!1)},[t,f]);const H=()=>{z(!0),setTimeout(()=>{window.dispatchEvent(new CustomEvent("tx-complete",{detail:{type:a,results:l}})),window.dispatchEvent(new CustomEvent("spiceflow:action",{detail:{type:a,status:"success",results:l}})),o?.(),s&&n()},300)},q=()=>{V(!O)};if(f){const{steps:oe,overallStatus:ae}=f,de=ae==="processing",Me=ae==="success",ye=ae==="failed",We=oe.filter(L=>L.transactionHash)[0],ce=oe.length>1?oe.map(L=>L.chainName).filter(Boolean).join(" and "):r!=="Network"?r:oe[0]?.chainName||r,Ve=c||(We?Cn(We.chainId,We.transactionHash||"").replace(/\/tx\/.*$/,""):void 0),De=i(Qt,{children:[i("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"16px"},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"8px",cursor:"pointer"},onClick:q,children:[i("span",{style:{fontSize:"13px",fontWeight:500,color:w,fontFamily:u?.fontFamily||S.typography.fontFamily},children:[de?`Processing ${a.charAt(0).toUpperCase()+a.slice(1)}`:`${a.charAt(0).toUpperCase()+a.slice(1)} results`," "]}),e("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",style:{transform:O?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.3s ease"},children:e("path",{d:"M4 6L8 10L12 6",stroke:w,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})]}),!de&&e("button",{onClick:n,onMouseEnter:()=>X("close"),onMouseLeave:()=>{X(null),R(null)},onMouseDown:()=>R("close"),onMouseUp:()=>R(null),style:{background:se==="close"?b?x.hoverBg:"#f3f4f6":P==="close"?b?x.inputBg:"#f9fafb":"none",border:"none",borderRadius:"4px",cursor:"pointer",padding:"4px",display:"flex",alignItems:"center",justifyContent:"center",color:P==="close"||se==="close"?W:w,transform:se==="close"?"scale(0.9)":P==="close"?"scale(1.1)":"scale(1)",transition:"all 0.15s ease"},children:e("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:e("path",{d:"M12 4L4 12M4 4L12 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),e("div",{style:{marginBottom:"16px"},children:de?i("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"20px 16px",borderRadius:"8px",backgroundColor:A,border:`1px solid ${E}`,gap:"12px"},children:[e(An,{size:24,borderWidth:3,color:U}),i("div",{children:[e("p",{style:{margin:0,fontSize:"14px",fontWeight:600,fontFamily:'"IBM Plex Mono", monospace',letterSpacing:"0.5px",color:W},children:"PROCESSING TRANSACTION"}),i("p",{style:{margin:"2px 0 0 0",fontSize:"12px",color:w},children:["on ",ce]})]})]}):e($o,{isSuccess:Me,type:a,chainName:ce,explorerUrl:Ve,txHash:We?.transactionHash,dark:b,...b?{successBg:x.successBg,successBorder:x.successBorder,successText:x.successText,errorBg:x.errorBg,errorBorder:x.errorBorder,errorText:x.errorText}:{},textSecondary:w})}),e("div",{style:{overflow:"hidden",maxHeight:O?"300px":"0px",opacity:O?1:0,transition:"max-height 0.3s ease, opacity 0.3s ease",marginBottom:O?"16px":"0"},children:e("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:oe.map((L,Se)=>{const Ee=L.transactionHash?Cn(L.chainId,L.transactionHash):null;return i("div",{style:{padding:"10px 12px",borderRadius:"6px",backgroundColor:Z,border:`1px solid ${D}`,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e("span",{style:{fontSize:"13px",color:W},children:L.chainName?`On ${L.chainName}`:L.description||`Step ${Se+1}`}),i("span",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"12px",color:L.status==="success"?"#10b981":L.status==="failed"?"#ef4444":w,fontWeight:500},children:[Ee&&e("a",{href:Ee,target:"_blank",rel:"noopener noreferrer",style:{color:b?x.infoText:"#2563eb",textDecoration:"none"},onClick:te=>te.stopPropagation(),children:"View"}),L.status==="success"?"\u2713":L.status==="failed"?"\u2717":"\u25CB"]})]},Se)})})}),!de&&i("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[ye&&m&&e(Ge,{variant:"outline",fullWidth:!0,onClick:m,theme:S,styles:{button:{backgroundColor:U}},children:"TRY AGAIN"}),g&&i(Ge,{variant:"outline",fullWidth:!0,onClick:g,theme:S,styles:{button:{backgroundColor:U}},children:["NEW ",a.toUpperCase()," \u2192"]})]})]});return C?i("div",{style:{position:"absolute",bottom:0,left:0,right:0,zIndex:10,animation:M?"slideDown 0.3s ease-in forwards":"slideUp 0.3s ease-out forwards",pointerEvents:"auto"},children:[e("div",{style:{backgroundColor:T,borderRadius:"12px 12px 0 0",width:"100%",padding:"18px 24px 24px",boxShadow:F},children:De}),e("style",{children:`
24
24
  @keyframes slideUp {
25
25
  from { transform: translateY(100%); }
26
26
  to { transform: translateY(0); }
@@ -111,7 +111,7 @@ import{jsxs as i,jsx as e,Fragment as Qt}from"react/jsx-runtime";import Ft,{useS
111
111
  from { transform: rotate(0deg); }
112
112
  to { transform: rotate(360deg); }
113
113
  }
114
- `})]})},Ca=({color:t})=>i("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",style:{marginTop:"1px",flexShrink:0},children:[e("circle",{cx:"7",cy:"7",r:"6.5",stroke:t,strokeWidth:"1.2"}),e("path",{d:"M7 6v4",stroke:t,strokeWidth:"1.2",strokeLinecap:"round"}),e("circle",{cx:"7",cy:"4.5",r:"0.7",fill:t})]}),wa=({isOpen:t,onClose:n,lockBatches:o,lockTokenSymbol:s,lockTokenLogoURI:a,destinationInputHook:l,sourceAssetInputHook:r,lockDurationHook:c,lockChainId:d,durationOptions:u,votingPowerEstimate:p,sourceChains:f,sourceAssets:m=[],escrowAddress:g,includeWalletAssets:h=!1,destinationTokenAddress:C,onLockSuccess:y,onLockExecute:S,sourceToDestinationConversionRate:U,estimatedOutputAmount:b,onAddFunds:x,styles:M,dark:z=!1})=>{const{theme:T,dark:I,primaryColor:F,dk:w}=je(M,z),W=T.typography.fontFamily,Z=It(xt),D=(Z?.mode||"7702")!=="7702",A=I?w.cardBg:M?.assetSelector?.backgroundColor||M?.secondaryBackground||"#e9e9e9",E=I?`1px solid ${w.cardBorder}`:"0.5px solid #A8A8A7",O=I?"12px":"6px",V=I?w.textPrimary:"#111827",P=I?w.textSecondary:"#6b7280",X=Ce(()=>({...M,assetSelector:{...M?.assetSelector,backgroundColor:I?w.cardBg:M?.assetSelector?.backgroundColor,borderRadius:I?"12px":M?.assetSelector?.borderRadius},secondaryBackground:I?w.cardBg:M?.secondaryBackground}),[M,I]),se=Ce(()=>I?{...T,colors:{...T.colors,secondary:w.cardBg,surfaceHover:w.hoverBg,border:w.cardBorder,borderHover:w.inputBorder}}:T,[I,T]),[R,H]=B(null),[q,me]=B(0),we=c?.selectedDurationIdx??q,oe=c?.setSelectedDurationIdx??me,[ae,de]=B(!1),[Me,ye]=B(null),[We,ce]=B(!1),[Ve,De]=B(!1),[L,Se]=B(null);qn(),Bn();const{chain:Ee,address:te}=Yt();Vo();const ze=Fe(Ee);$(()=>{ze.current=Ee},[Ee]);const Pe=tn(),{isReady:Q,isAuthenticated:J,isConnected:v,address:k,provider:ee,actions:re}=Pe,{intentStatus:N,startStatusPolling:Y,clearStatus:le}=vo({checkStepStatus:(_,he)=>qe.checkStepStatus(_,he),retryStep:async(_,he)=>{const[tt,it]=_.split("/"),gt=parseInt(it||"0",10);await qe.executeStep(tt,gt,he,{action:"execute"})},maxRetries:3}),{assets:pe,refetch:ke}=Fn({address:k,supportedChains:f,enabled:v&&!D,refetchInterval:3e4}),pt=Ce(()=>{if(m.length===0)return pe;const _=new Set(m.map(he=>he.toLowerCase()));return pe.filter(he=>_.has(he.address.toLowerCase()))},[pe,m]),fe=en(),xe=D?te:fe,be=Ce(()=>{if(!h)return[];const _=new Set,he=[],tt=it=>{if(!it)return;const gt=it.toLowerCase();_.has(gt)||(_.add(gt),he.push(Et(it)))};if(C&&tt(C),D)for(const it of m)tt(it);return he},[h,D,C,m]),Xe=Ce(()=>be.map(_=>_.toLowerCase()).sort().join(","),[be]),kt=Ce(()=>JSON.stringify([...f||[]].sort()),[f]),[Ct,ut]=B([]),Ut=Fe(0),St=ie(async()=>{if(!h||!xe||be.length===0){Ut.current++,ut([]);return}const _=++Ut.current,he=Et(xe),tt=f&&f.length>0?f:[d],it=be.map(Te=>{const Ae=Te.toLowerCase();for(const lt of tt){const Ye=Ke(lt)?.supportedTokens?.find(Ze=>Ze.address.toLowerCase()===Ae);if(Ye)return{address:Te,chainId:lt,configToken:{decimals:Ye.decimals,symbol:Ye.symbol,name:Ye.name,logo:Ye.logo}}}return{address:Te,chainId:d}}),gt=new Map;for(const Te of it){const Ae=gt.get(Te.chainId)||[];Ae.push(Te),gt.set(Te.chainId,Ae)}const Ie=async(Te,Ae)=>{try{const lt=await vn(Te,{address:Ae.address,abi:bt,functionName:"balanceOf",args:[he]});let Ye,Ze,Be,He;if(Ae.configToken)Ye=Ae.configToken.decimals,Ze=Ae.configToken.symbol,Be=Ae.configToken.name,He=Ae.configToken.logo;else{const[Lt,j,G]=await Promise.all([vn(Te,{address:Ae.address,abi:bt,functionName:"decimals",args:[]}).catch(()=>18),vn(Te,{address:Ae.address,abi:bt,functionName:"symbol",args:[]}).catch(()=>"TOKEN"),vn(Te,{address:Ae.address,abi:bt,functionName:"name",args:[]}).catch(()=>"TOKEN")]);Ye=Number(Lt),Ze=j,Be=G}const $e=!!C&&Ae.address.toLowerCase()===C.toLowerCase()&&Ae.chainId===d;$e&&a&&(He=a),$e&&s&&!Ae.configToken&&(Ze==="TOKEN"&&(Ze=s),Be==="TOKEN"&&(Be=s));const Pt=parseFloat((Number(lt)/Math.pow(10,Ye)).toFixed(6));return{address:Ae.address,name:Be,symbol:Ze,decimals:Ye,balance:lt,balanceFormatted:Pt,balanceUsd:0,logoURI:He,isNative:!1,chainId:Ae.chainId}}catch{return null}},Re=await Promise.all(Array.from(gt.entries()).map(async([Te,Ae])=>{let lt;try{lt=ct(Te)}catch{return[]}const Ye=[],Ze=[];for(const He of Ae){const $e=Ye.length;Ye.push({address:He.address,abi:bt,functionName:"balanceOf",args:[he]}),He.configToken||Ye.push({address:He.address,abi:bt,functionName:"decimals",args:[]},{address:He.address,abi:bt,functionName:"symbol",args:[]},{address:He.address,abi:bt,functionName:"name",args:[]}),Ze.push({start:$e,item:He})}let Be=null;try{Be=await lt.multicall({contracts:Ye})}catch{Be=null}return Be?Ze.map(({start:He,item:$e})=>{const Pt=Be[He],Lt=Pt?.status==="success"?Pt.result:0n;let j,G,K,ne;if($e.configToken)j=$e.configToken.decimals,G=$e.configToken.symbol,K=$e.configToken.name,ne=$e.configToken.logo;else{const dt=Be[He+1],Ue=Be[He+2],nt=Be[He+3];j=dt?.status==="success"?Number(dt.result):18,G=Ue?.status==="success"?Ue.result:"TOKEN",K=nt?.status==="success"?nt.result:G}const Le=!!C&&$e.address.toLowerCase()===C.toLowerCase()&&$e.chainId===d;Le&&a&&(ne=a),Le&&s&&!$e.configToken&&(G==="TOKEN"&&(G=s),K==="TOKEN"&&(K=s));const wt=parseFloat((Number(Lt)/Math.pow(10,j)).toFixed(6));return{address:$e.address,name:K,symbol:G,decimals:j,balance:Lt,balanceFormatted:wt,balanceUsd:0,logoURI:ne,isNative:!1,chainId:$e.chainId}}):(await Promise.all(Ae.map(He=>Ie(lt,He)))).filter(He=>He!==null)}));_===Ut.current&&ut(Re.flat())},[h,xe,Xe,kt,d,C,a,s]);$(()=>{if(!h){ut([]);return}St();const _=setInterval(()=>{St()},15e3);return()=>clearInterval(_)},[St,h]);const st=ie(()=>{St()},[St]),Nt=Ce(()=>Ct.filter(_=>_.balance>0n),[Ct]),Zt=Ce(()=>{if(D)return Nt.map(he=>({...he,_source:"wallet"}));if(!h)return pt;const _=[];for(const he of Nt)_.push({...he,_source:"wallet"});for(const he of pt)_.push({...he,_source:"spice"});return _},[D,h,Nt,pt]),ue=Fe(null),ge=Fe(null);$(()=>{ge.current=R},[R]),$(()=>{t||(H(null),ye(null),de(!1),De(!1),Se(null),ce(!1),le())},[t,le]),$(()=>{l&&l.assetAmount!==(R?.amount||"")&&H(_=>_&&{..._,amount:l.assetAmount})},[l?.assetAmount]),$(()=>{r&&r.assetAmount!==(R?.amount||"")&&H(_=>_&&{..._,amount:r.assetAmount})},[r?.assetAmount]),$(()=>{if(N?.overallStatus==="success"&&N.intentId&&ue.current!==N.intentId&&k){const _=N.steps.find(he=>he.transactionHash);if(_?.transactionHash){ue.current=N.intentId;const he=ge.current;if(!he?.asset||!he.amount||he.asset._source==="wallet")return;const tt=_e(he.amount,he.asset.decimals);if(tt===0n)return;qe.submitSpiceDeposit({user:k,txHash:_.transactionHash,sender:k,tokenAddress:he.asset.address,chainId:he.asset.chainId??d,amount:tt.toString(),isDeposit:!1}).then(()=>ke()).catch(()=>{ue.current=null})}}},[N,k,d,ke]);const ve=parseFloat(R?.amount||"")||0,Je=Ce(()=>R?.asset?R.asset._source==="wallet"?R.asset.balanceFormatted??0:pt.find(_=>_.address.toLowerCase()===R.asset.address.toLowerCase()&&_.chainId===R.asset.chainId)?.balanceFormatted??0:0,[R?.asset,pt]),ht=ve>0&&ve>Je,et=c?.selectedDuration??u[we]??u[0],at=Ce(()=>!R?.asset||!C?!1:R.asset.address.toLowerCase()===C.toLowerCase()&&R.asset.chainId===d,[R?.asset,C,d]),Mt=Ce(()=>ve<=0?0:at?ve:!U||U<=0?0:ve/U,[ve,U,at]),nn=Ce(()=>Mt<=0?null:Mt.toLocaleString(void 0,{maximumFractionDigits:2}),[Mt]),on=p&&Mt>0&&et?p(Mt,et.months):void 0,hn=Ce(()=>ve<=0?"$0.00":at&&U?(ve*U).toLocaleString(void 0,{style:"currency",currency:"USD",maximumFractionDigits:2}):!U||U<=0?"$0.00":ve.toLocaleString(void 0,{style:"currency",currency:"USD",maximumFractionDigits:2}),[ve,U,at]),fn=Ce(()=>{if(!nn)return null;const _=parseFloat(nn.replace(/,/g,""));return at&&U?(_*U).toLocaleString(void 0,{maximumFractionDigits:2}):U?(_*U).toLocaleString(void 0,{maximumFractionDigits:2}):null},[nn,U,at]),kn=ie(_=>{H(he=>({asset:_,amount:he?.asset?.address===_.address&&he?.asset?.chainId===_.chainId&&he.amount||""})),ye(null),r?.setSelectedAsset&&r.setSelectedAsset({symbol:_.symbol,address:_.address,decimals:_.decimals,chainId:_.chainId})},[r?.setSelectedAsset]),qt=ie(_=>{H(he=>he&&{...he,amount:_}),ye(null),l&&l.setAssetAmount(_),r&&r.setAssetAmount(_)},[l,r]),Vt=ie(()=>{if(typeof o=="function"){if(!R?.asset||!R.amount)throw new Error("Select an asset and enter an amount");return o({asset:R.asset,amount:R.amount,amountWei:_e(R.amount,R.asset.decimals)})}return o},[o,R]),Gt=ie(async()=>{if(!v||!k)throw new Error("Please connect your wallet to continue");const _=Vt();if(_.length===0)throw new Error("No lock batches configured");if(!Q||!J)throw new Error(`Please authenticate with ${ee||"wallet provider"} to continue`);const he=[..._],tt=[...new Set(he.map(Be=>Be.chainId))],it=[];for(const Be of tt){const He=ct(Be),$e=En(Be),Pt=await Gn(k,He),Lt=await re.signAuthorization({contractAddress:$e,chainId:Be,nonce:Number(Pt)});it.push(Lt)}const gt=Jn(he),Ie=Math.floor(Date.now()/1e3)+60*10,Re=gt.map(Be=>Be.hash),Te=_n(eo([{type:"string"},{type:"uint256"},{type:"uint256"},{type:"bytes32[]"}],["ecdsa",0n,BigInt(Ie),Re])),Ae=await re.signMessage({raw:Te}),lt=typeof Ae=="string"?Ae:Ae.signature;if(!lt)throw new Error("Failed to sign intent authorization");const Ye={mode:"7702",signatureType:"ecdsa",signature:lt,nbf:0,exp:Ie,chainBatches:gt.map((Be,He)=>({hash:Be.hash,chainId:Be.chainId,tokenTransfers:he[He].tokenTransfers??[],calls:Be.calls}))},Ze=await qe.createAction({user:k,chainAuthorizations:it.map(Be=>({r:Be.r,s:Be.s,yParity:Be.yParity,address:Be.address,chainId:Number(Be.chainId),nonce:Number(Be.nonce)})),intents:[Ye]});if(Ze){const Be=Zn(he,vt),[He,$e]=Ze.intentIds[0].split("/"),Pt=parseInt($e||"0",10);Y(Ze.intentIds[0],Be);for(let Lt=0;Lt<he.length;Lt++)await ko(()=>qe.executeStep(He,Pt,Lt,{action:"execute"}))}},[Vt,Pe,Y]),rn=ie(async()=>{if(!R?.asset||!R.amount)throw new Error("Select an asset and enter an amount");if(!k||!fe)throw new Error("Embedded wallet not connected");const _=R.asset,he=_e(R.amount,_.decimals),tt=g||En(d),it=await re.getEthereumProvider();await it.request({method:"wallet_switchEthereumChain",params:[{chainId:`0x${d.toString(16)}`}]});const gt=Ke(d),Ie=zn({account:fe,transport:Un(it),chain:gt?.viemChain});let Re;if(_.isNative||rt(_.address))Re=await Ie.sendTransaction({to:tt,value:he,chain:gt?.viemChain});else{const Te=Wt({abi:bt,functionName:"transfer",args:[tt,he]});Re=await Ie.sendTransaction({to:_.address,data:Te,chain:gt?.viemChain})}if((await ct(d).waitForTransactionReceipt({hash:Re,timeout:12e4,pollingInterval:2e3,confirmations:1})).status!=="success")throw new Error("Transfer to escrow failed");await ko(()=>qe.submitSpiceDeposit({txHash:Re,sender:fe,tokenAddress:_.address,chainId:d,amount:he.toString(),user:fe,isDeposit:!0})),await ke(),st(),await Gt()},[R,k,fe,re,g,d,Gt,ke,st]),Bt=ie(async()=>{if(!R?.asset||!R.amount)throw new Error("Select an asset and enter an amount");if(!te)throw new Error("Please connect your wallet to continue");if(!S)throw new Error("onLockExecute callback is required for non-7702 mode");const _=Vt();if(_.length===0)throw new Error("No lock batches configured");const he=R.asset,tt=_e(R.amount,he.decimals),it=await S({asset:he,amount:R.amount,amountWei:tt,lockDurationMonths:et?.months??0,chainBatches:_});it&&y?.(it)},[R,te,S,Vt,et,y]);$(()=>{if(N?.overallStatus==="success"){const _=N.steps.find(he=>he.transactionHash);y?.(_?.transactionHash)}},[N?.overallStatus,y]);const sn=h&&R?.asset?._source==="wallet"&&R?.asset?.chainId===d,an=ie(async()=>{if(!R?.asset||ve<=0){ye("Select an asset and enter an amount");return}if(ht){ye("Insufficient balance. Add more assets.");return}if(de(!0),ye(null),D){try{await Bt()}catch(_){ye(Ot(_,"Transaction failed. Please try again."))}finally{de(!1)}return}ce(!0);try{sn&&!at?await rn():await Gt()}catch(_){ye(Ot(_,"Transaction failed. Please try again."))}finally{de(!1)}},[R,ve,ht,D,Bt,sn,at,rn,Gt]),gn=!!R?.asset&&ve>0&&!ht&&!ae,Jt=i("div",{style:{display:"flex",alignItems:"flex-start",gap:"6px"},children:[e(Ca,{color:P}),i("p",{style:{fontSize:"13px",color:P,margin:0,lineHeight:"1.5"},children:["Add ",s," by converting assets from your account"]})]});if(!t)return null;const mn={backgroundColor:A,border:E,borderRadius:O,padding:"16px",marginBottom:"16px"};return e(Dt,{isOpen:t,onClose:n,title:`Add ${s} to your account`,subtitle:Jt,styles:M,dark:I,footerLinkText:"Spicenet accounts \u2192",overlayContent:Ve?e("div",{}):void 0,children:i("div",{style:{padding:"0 24px 8px 24px",position:"relative"},children:[i("div",{style:{marginBottom:"12px"},children:[x&&e("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:"6px"},children:i("button",{onClick:x,style:{background:"none",border:"none",cursor:"pointer",padding:0,display:"flex",alignItems:"center",gap:"4px",color:F,fontSize:"12px",fontWeight:500,fontFamily:W,textDecoration:"underline",textUnderlineOffset:"2px"},children:["Add Funds",i("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:F,strokeWidth:"1.8",children:[e("circle",{cx:"6",cy:"6",r:"5"}),e("path",{d:"M6 4v4M4 6h4",strokeLinecap:"round"})]})]})}),e(Rn,{assets:Zt,selectedAsset:R??void 0,onAssetSelect:kn,onAmountChange:qt,label:"Amount",showBalance:!0,showMaxButton:!0,theme:se,styles:X}),e("div",{style:{marginTop:"6px",paddingLeft:"4px",fontSize:"13px",color:P,fontFamily:W},children:hn})]}),i("div",{style:mn,children:[i("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",paddingBottom:"16px",borderBottom:I?`1px solid ${w.cardBorder}`:"1px solid #e5e7eb"},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[a?e("img",{src:a,alt:s,style:{width:"32px",height:"32px",borderRadius:"50%",objectFit:"cover"}}):e("div",{style:{width:"32px",height:"32px",borderRadius:"50%",backgroundColor:I?w.inputBg:"#d1d5db",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"12px",fontWeight:700,color:V},children:s.slice(0,2)}),e("span",{style:{fontSize:"16px",fontWeight:600,color:V,fontFamily:W},children:s})]}),i("div",{style:{textAlign:"right"},children:[e("div",{style:{fontSize:"22px",fontWeight:700,color:V,fontFamily:W,lineHeight:1.1},children:nn??"0.00"}),i("div",{style:{fontSize:"12px",color:P,fontFamily:W,marginTop:"2px"},children:["~$",fn??"0.00"]})]})]}),i("div",{style:{paddingTop:"16px",paddingBottom:"16px",borderBottom:I?`1px solid ${w.cardBorder}`:"1px solid #e5e7eb"},children:[i("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},children:[e("span",{style:{fontSize:"15px",fontWeight:500,color:P,fontFamily:W},children:"Lock Duration"}),e("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:e("path",{d:"M4 6L8 10L12 6",stroke:P,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})]}),e(ga,{options:u,selectedIndex:we,onSelect:oe,primaryColor:F,dark:I,textPrimary:V,textSecondary:P})]}),i("div",{style:{paddingTop:"12px",display:"flex",flexDirection:"column",gap:"8px"},children:[e(ya,{durationMonths:et?.months,fontFamily:W,dark:I,textPrimary:V,textSecondary:P}),p&&e(xa,{votes:on,fontFamily:W,dark:I,textPrimary:V,textSecondary:P})]})]}),Me&&e("div",{style:{marginBottom:"12px",padding:"10px 14px",backgroundColor:I?"rgba(239,68,68,0.12)":"#fef2f2",border:`1px solid ${I?"rgba(239,68,68,0.3)":"#fecaca"}`,borderRadius:"6px"},children:e("p",{style:{color:"#ef4444",fontSize:"13px",margin:0,fontFamily:W},children:Me})}),e(Ge,{variant:"outline",fullWidth:!0,onClick:an,disabled:!gn,loading:ae,dark:I,styles:{button:{backgroundColor:F}},children:ae?sn&&!at?"DEPOSITING...":at?"LOCKING...":"CONVERTING...":sn&&!at?`DEPOSIT ${s}`:at?`LOCK ${s}`:`CONVERT TO ${s}`}),e(ba,{isOpen:Ve,data:L,isLocking:ae,lockError:Me,onContinue:an,onClose:()=>De(!1),primaryColor:F,fontFamily:W,dark:I}),N&&We&&e("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:10,backgroundColor:I?w.shell:"white",borderRadius:O,padding:"16px 0"},children:e(Ln,{type:"deposit",isOpen:!!N&&N.overallStatus!=="processing",isProcessing:ae||N?.overallStatus==="processing",closeOnComplete:!1,onRetryTx:()=>{le(),ce(!1),an()},onNewTx:()=>{le(),ce(!1),H(null),ue.current=null,ke(),st()},onClose:()=>{le(),ce(!1)},onComplete:()=>{le(),ce(!1),H(null),ue.current=null,ke(),st()},results:N?.overallStatus==="success"||N?.overallStatus==="failed"?N.steps.map(_=>({asset:{symbol:R?.asset?.symbol||s,address:R?.asset?.address||""},txHash:_.transactionHash||"",success:_.status==="success",amount:R?.amount})):void 0,chainName:vt(d),explorerUrl:Cn(d,"").replace(/\/tx\/.*$/,"")||void 0,theme:T,styles:M,dark:I})})]})})},vr=({variant:t,destinationSymbol:n,destinationLogoURI:o,destinationDecimals:s,primaryColor:a,fontFamily:l,textPrimary:r,textSecondary:c,cardBg:d,cardBorder:u,dk:p,dark:f,isQuoting:m,quoteError:g,estimatedOutput:h,paymentAmount:C,needsSwap:y,exactOutputSwap:S,adjustable:U=!1,maxAmount:b,onAmountChange:x})=>t==="supply"?e("div",{style:{backgroundColor:d,border:`1px solid ${u}`,borderRadius:"12px",padding:"14px 16px",marginBottom:"16px"},children:i("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[e(kr,{symbol:n,logoURI:o,primaryColor:a,size:28}),i("span",{style:{fontSize:"13px",fontWeight:500,color:c,fontFamily:l},children:["Estimated ",n]})]}),e("div",{style:{textAlign:"right"},children:m?e("span",{style:{fontSize:"14px",color:c,fontFamily:l},children:"Quoting..."}):g?e("span",{style:{fontSize:"13px",color:"#ef4444",fontFamily:l},children:"Quote failed"}):h?i("span",{style:{fontSize:"16px",fontWeight:600,color:r,fontFamily:l},children:["\u2248 ",h]}):e("span",{style:{fontSize:"14px",color:c,fontFamily:l},children:"\u2014"})})]})}):e(va,{destinationSymbol:n,destinationLogoURI:o,destinationDecimals:s,primaryColor:a,fontFamily:l,textPrimary:r,textSecondary:c,cardBg:d,cardBorder:u,dk:p,dark:f,paymentAmount:C||"0",needsSwap:y,exactOutputSwap:S,isQuoting:m,adjustable:U,maxAmount:b,onAmountChange:x}),kr=({symbol:t,logoURI:n,primaryColor:o,size:s})=>n?e("img",{src:n,alt:t,style:{width:s,height:s,borderRadius:"50%",objectFit:"cover"}}):e("div",{style:{width:s,height:s,borderRadius:"50%",backgroundColor:`${o}22`,display:"flex",alignItems:"center",justifyContent:"center",fontSize:s<30?"11px":"12px",fontWeight:700,color:o},children:t.slice(0,2)}),va=({destinationSymbol:t,destinationLogoURI:n,destinationDecimals:o,primaryColor:s,fontFamily:a,textPrimary:l,textSecondary:r,cardBg:c,cardBorder:d,dk:u,dark:p,paymentAmount:f,needsSwap:m,exactOutputSwap:g,isQuoting:h,adjustable:C,maxAmount:y,onAmountChange:S})=>{const U='"IBM Plex Mono", monospace',b=parseFloat(f||"0"),x=y?parseFloat(y):0,[M,z]=B(f||""),T=Fe(null),[I,F]=B(null),[w,W]=B(null);$(()=>{C||z(f||"")},[f,C]);const Z=E=>{let O=E;O.startsWith(".")&&(O="0"+O);const V=Jo(O);let P=V;y&&parseFloat(V)>parseFloat(y)&&(P=y),z(P),T.current&&clearTimeout(T.current),T.current=setTimeout(()=>S?.(P),300)},D=E=>{if(!x)return;if(E===100){z(y||x.toString()),T.current&&clearTimeout(T.current),S?.(y||x.toString());return}const O=10**o,V=(Math.floor(x*E/100*O)/O).toString();z(V),T.current&&clearTimeout(T.current),S?.(V)},A=x>0?parseFloat(M||"0")/x*100:0;return $(()=>()=>{T.current&&clearTimeout(T.current)},[]),i("div",{style:{backgroundColor:c,border:`1px solid ${d}`,borderRadius:p?"12px":"6px",padding:"16px",marginBottom:"16px"},children:[i("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[e(kr,{symbol:t,logoURI:n,primaryColor:s,size:32}),i("div",{children:[e("span",{style:{fontSize:"14px",fontWeight:600,color:l,fontFamily:a},children:"Payment"}),e("div",{style:{fontSize:"12px",color:r,fontFamily:a,marginTop:"2px"},children:t})]})]}),i("div",{style:{textAlign:"right"},children:[C?e("input",{type:"text",value:M,onChange:E=>Z(E.target.value),placeholder:"0.0",style:{fontSize:"20px",fontWeight:700,color:l,fontFamily:U,lineHeight:1.1,backgroundColor:"transparent",border:"none",outline:"none",padding:0,width:"120px",textAlign:"right"}}):e("div",{style:{fontSize:"20px",fontWeight:700,color:l,fontFamily:U,lineHeight:1.1},children:b>0?f:"0.00"}),e("div",{style:{fontSize:"12px",color:r,fontFamily:U,marginTop:"2px"},children:t}),C&&x>0&&e("div",{style:{display:"flex",justifyContent:"flex-end",alignItems:"center",gap:"10px",marginTop:"6px"},children:[0,25,50,75,100].map((E,O)=>{const V=Math.abs(A-E)<1,P=O===4,X=E/100,se=I===E,R=w===E;return e("button",{onClick:()=>D(E),onMouseEnter:()=>F(E),onMouseLeave:()=>{F(null),W(null)},onMouseDown:()=>W(E),onMouseUp:()=>W(null),title:`${E}%`,style:{width:"14px",height:"14px",padding:0,border:"none",backgroundColor:"transparent",cursor:"pointer",opacity:V?1:se?.8:.5,transform:R?"scale(0.85)":se?"scale(1.15)":"scale(1)",transition:"all 0.15s ease"},children:i("svg",{width:"14",height:"14",viewBox:"0 0 14 14",children:[e("circle",{cx:"7",cy:"7",r:"6.84375",fill:P?s:"none",stroke:P?s:p?"#4a5568":"#3C3E42",strokeWidth:"0.3125"}),!P&&X>0&&e("path",{d:`M 7 7 L 7 0.15625 A 6.84375 6.84375 0 ${X>.5?1:0} 1 ${7+6.84375*Math.sin(X*2*Math.PI)} ${7-6.84375*Math.cos(X*2*Math.PI)} Z`,fill:p?u?.textSecondary||"#9ca3af":"#3C3E42"})]})},E)})})]})]}),m&&g&&!h&&e("div",{style:{marginTop:"12px",paddingTop:"12px",borderTop:p?`1px solid ${u?.cardBorder||d}`:"1px solid #e5e7eb",display:"flex",justifyContent:"flex-end"},children:i("span",{style:{fontSize:"11px",color:r,fontFamily:a,opacity:.7},children:["via ",g.venue]})})]})};function Ir(t,n,o){const s=t.address.toLowerCase()===n,a=t.chainId===o,l=t._source==="wallet";return l&&s&&a?0:l&&a?1:!l&&s?2:!l&&a?3:4}function ka(t){const{address:n,destinationToken:o,supportedSourceAssets:s,sourceChains:a,enabled:l}=t,r=en(),{assets:c,refetch:d}=Fn({address:n,supportedChains:a,enabled:l,refetchInterval:3e4}),u=Ce(()=>{if(!s||s.length===0)return c;const g=s.map(h=>h.toLowerCase());return c.filter(h=>g.includes(h.address.toLowerCase()))},[c,s]),[p,f]=B(null);$(()=>{if(!o.address||!r||!l){f(null);return}let g=!1;const h=Et(o.address),C=Et(r),y=ct(o.chainId),S=async()=>{try{const b=await y.multicall({contracts:[{address:h,abi:At,functionName:"balanceOf",args:[C]},{address:h,abi:At,functionName:"decimals",args:[]},{address:h,abi:At,functionName:"symbol",args:[]},{address:h,abi:At,functionName:"name",args:[]}]});if(g)return;const x=b[0].status==="success"?b[0].result:0n,M=b[1].status==="success"?Number(b[1].result):o.decimals,z=b[2].status==="success"?b[2].result:o.symbol,T=b[3].status==="success"?b[3].result:o.symbol;x>0n?f({address:h,name:T,symbol:z,decimals:M,balance:x,balanceFormatted:parseFloat((Number(x)/Math.pow(10,M)).toFixed(6)),balanceUsd:0,logoURI:o.logoURI,isNative:!1,chainId:o.chainId}):f(null)}catch{g||f(null)}};S();const U=setInterval(S,15e3);return()=>{g=!0,clearInterval(U)}},[o.address,o.chainId,o.decimals,o.symbol,o.logoURI,r,l]);const m=ie(()=>{if(!o.address||!r)return;const g=ct(o.chainId),h=Et(o.address),C=Et(r);g.multicall({contracts:[{address:h,abi:At,functionName:"balanceOf",args:[C]},{address:h,abi:At,functionName:"decimals",args:[]}]}).then(y=>{const S=y[0].status==="success"?y[0].result:0n,U=y[1].status==="success"?Number(y[1].result):18;S>0n?f(b=>b?{...b,balance:S,balanceFormatted:parseFloat((Number(S)/Math.pow(10,U)).toFixed(6))}:null):f(null)}).catch(()=>{})},[o.address,o.chainId,r]);return{displayAssets:Ce(()=>{const g=[];p&&g.push({...p,_source:"wallet"});for(const C of u)g.push({...C,_source:"spice"});const h=o.address.toLowerCase();return g.sort((C,y)=>Ir(C,h,o.chainId)-Ir(y,h,o.chainId)),g},[p,u,o.address,o.chainId]),filteredSpiceAssets:u,embeddedWalletAddress:r,refreshSpiceAssets:d,refreshWalletAssets:m}}function jn(t){const n=new Set(Qo(t).map(o=>o.toLowerCase()));return n.add(t.toLowerCase()),n}const Ia=["USDC","USDT","WETH","WBTC"];function Mo(t,n){const o=Ke(n);if(!o)return;if(o.nativeCurrency.symbol.toUpperCase()===t.toUpperCase())return{address:Kt,symbol:o.nativeCurrency.symbol,decimals:o.nativeCurrency.decimals,chainId:n};const s=o.supportedTokens?.find(a=>a.symbol.toUpperCase()===t.toUpperCase());if(s)return{address:s.address.toLowerCase(),symbol:s.symbol,decimals:s.decimals,chainId:n}}function yn(t,n){const o=Ke(n);if(!o)return;const s=jn(t);if([...s].some(l=>rt(l)))return{address:Kt,symbol:o.nativeCurrency.symbol,decimals:o.nativeCurrency.decimals,chainId:n};const a=o.supportedTokens?.find(l=>s.has(l.address.toLowerCase()));if(a)return{address:a.address.toLowerCase(),symbol:a.symbol,decimals:a.decimals,chainId:n}}function Sr(t){const{sourceAsset:n,outputAsset:o,sourceChainId:s,destinationChainId:a,intermediaryCandidates:l=Ia}=t,r=jn(n.address);if(r.has(o.address.toLowerCase()))return{strategy:"direct",sourceAsset:n,outputAsset:o,sourceChainId:s,destinationChainId:a,summary:`${n.symbol} fronted directly`};if(yn(n.address,a))return{strategy:"direct",sourceAsset:n,outputAsset:o,sourceChainId:s,destinationChainId:a,summary:`${n.symbol} fronted on destination, swapped to ${o.symbol}`};if(yn(o.address,s))return{strategy:"source-swap",sourceAsset:n,outputAsset:o,sourceChainId:s,destinationChainId:a,summary:`${n.symbol} \u2192 ${o.symbol} on source chain, then fronted`};const c=jn(o.address);for(const d of l){const u=Mo(d,s);if(!u||r.has(u.address.toLowerCase())||c.has(u.address.toLowerCase()))continue;const p=Mo(d,a);if(!(!p||!jn(u.address).has(p.address.toLowerCase())))return{strategy:"intermediary",sourceAsset:n,outputAsset:o,intermediaryAsset:p,sourceChainId:s,destinationChainId:a,summary:`${n.symbol} \u2192 ${d} on source, fronted, then ${d} \u2192 ${o.symbol} on destination`}}throw new Oe("ROUTE_STRATEGY_ERROR",`No viable cross-chain route found from ${n.symbol} (chain ${s}) to ${o.symbol} (chain ${a}). No intermediary asset is available on both chains.`,{sourceAsset:n.symbol,outputAsset:o.symbol,sourceChainId:s,destinationChainId:a,candidatesChecked:l})}async function Ar(t){const{route:n,sourceAmount:o,userAddress:s,registry:a,actionCalls:l,slippage:r}=t;async function c(d,u,p,f){const m=a.getVenueForChain(d);if(!m)throw new Oe("NO_VENUE_FOR_CHAIN",`No liquidity venue configured for chain ${d}. Cannot resolve swap ${u} \u2192 ${p}.`,{chainId:d,tokenIn:u,tokenOut:p,amountIn:f.toString()});const g=await m.resolve({type:"swap",tokenIn:u,tokenOut:p,amountIn:f,maxSlippage:r},d,s);if(!g)throw new Oe("NO_LIQUIDITY",`${m.name} returned no quote for ${u} \u2192 ${p} on chain ${d}. No liquidity available for this pair.`,{venue:m.name,chainId:d,tokenIn:u,tokenOut:p,amountIn:f.toString()});return g}switch(n.strategy){case"direct":{const d=yn(n.sourceAsset.address,n.destinationChainId)||n.sourceAsset;if(jn(d.address).has(n.outputAsset.address.toLowerCase()))return{chainBatches:[{chainId:n.destinationChainId,calls:l}],solverFrontToken:d,solverFrontAmount:o,resolvedSwaps:{}};const u=await c(n.destinationChainId,d.address,n.outputAsset.address,o);return{chainBatches:[{chainId:n.destinationChainId,calls:[...u.calls,...l]}],solverFrontToken:d,solverFrontAmount:o,resolvedSwaps:{destinationSwap:u}}}case"source-swap":{const d=yn(n.outputAsset.address,n.sourceChainId);if(!d)throw new Oe("ROUTE_TOKEN_NOT_FOUND",`Output asset ${n.outputAsset.symbol} (${n.outputAsset.address}) not found on source chain ${n.sourceChainId}`,{token:n.outputAsset.symbol,address:n.outputAsset.address,chainId:n.sourceChainId,side:"source"});const u=yn(n.outputAsset.address,n.destinationChainId);if(!u)throw new Oe("ROUTE_TOKEN_NOT_FOUND",`Output asset ${n.outputAsset.symbol} (${n.outputAsset.address}) not found on destination chain ${n.destinationChainId}`,{token:n.outputAsset.symbol,address:n.outputAsset.address,chainId:n.destinationChainId,side:"destination"});const p=await c(n.sourceChainId,n.sourceAsset.address,d.address,o);return{chainBatches:[{chainId:n.sourceChainId,calls:p.calls},{chainId:n.destinationChainId,calls:l}],solverFrontToken:u,solverFrontAmount:p.amountOutMinimum,resolvedSwaps:{sourceSwap:p}}}case"intermediary":{if(!n.intermediaryAsset)throw new Oe("ROUTE_STRATEGY_ERROR","Intermediary strategy requires an intermediary asset but none was provided in the route plan.",{strategy:n.strategy});const d=yn(n.intermediaryAsset.address,n.sourceChainId);if(!d)throw new Oe("ROUTE_TOKEN_NOT_FOUND",`Intermediary ${n.intermediaryAsset.symbol} (${n.intermediaryAsset.address}) not found on source chain ${n.sourceChainId}`,{token:n.intermediaryAsset.symbol,address:n.intermediaryAsset.address,chainId:n.sourceChainId,side:"source"});const u=await c(n.sourceChainId,n.sourceAsset.address,d.address,o),p=await c(n.destinationChainId,n.intermediaryAsset.address,n.outputAsset.address,u.amountOutMinimum);return{chainBatches:[{chainId:n.sourceChainId,calls:u.calls},{chainId:n.destinationChainId,calls:[...p.calls,...l]}],solverFrontToken:n.intermediaryAsset,solverFrontAmount:u.amountOutMinimum,resolvedSwaps:{sourceSwap:u,destinationSwap:p}}}default:throw new Oe("ROUTE_STRATEGY_ERROR",`Unknown route strategy: ${n.strategy}`,{strategy:n.strategy})}}async function Er(t){const{tokenIn:n,tokenOut:o,amountIn:s,fee:a,chainId:l,config:r}=t;if(s<=0n)throw new Error("amountIn must be greater than 0");const c=(await ct(l).simulateContract({address:r.quoterV2,abi:ts,functionName:"quoteExactInputSingle",args:[{tokenIn:n,tokenOut:o,amountIn:s,fee:a,sqrtPriceLimitX96:0n}]})).result;if(c[0]<=0n)throw new Error("No liquidity found for this pair. The pool returned 0 output.");return{amountOut:c[0],sqrtPriceX96After:c[1],gasEstimate:c[3]}}async function Br(t){const n=t.feeTiers??[100,500,3e3,1e4],o=await Promise.allSettled(n.map(a=>Er({...t,fee:a})));let s=null;for(let a=0;a<o.length;a++){const l=o[a];l.status==="fulfilled"&&(!s||l.value.amountOut>s.amountOut)&&(s={...l.value,fee:n[a]})}if(!s)throw new Error("No liquidity found for this pair on any fee tier.");return s}const Sa=[{inputs:[{components:[{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"amount",type:"uint256"},{name:"fee",type:"uint24"},{name:"sqrtPriceLimitX96",type:"uint160"}],name:"params",type:"tuple"}],name:"quoteExactOutputSingle",outputs:[{name:"amountIn",type:"uint256"},{name:"sqrtPriceX96After",type:"uint160"},{name:"initializedTicksCrossed",type:"uint32"},{name:"gasEstimate",type:"uint256"}],stateMutability:"nonpayable",type:"function"}];async function Aa(t){const{tokenIn:n,tokenOut:o,amountOut:s,fee:a,chainId:l,config:r}=t;if(s<=0n)throw new Error("amountOut must be greater than 0");const c=(await ct(l).simulateContract({address:r.quoterV2,abi:Sa,functionName:"quoteExactOutputSingle",args:[{tokenIn:n,tokenOut:o,amount:s,fee:a,sqrtPriceLimitX96:0n}]})).result;if(c[0]<=0n)throw new Error("No liquidity found for this pair. The pool returned 0 input.");return{amountIn:c[0],sqrtPriceX96After:c[1],gasEstimate:c[3]}}async function Ea(t){const n=t.feeTiers??[100,500,3e3,1e4],o=await Promise.allSettled(n.map(a=>Aa({...t,fee:a})));let s=null;for(let a=0;a<o.length;a++){const l=o[a];l.status==="fulfilled"&&(!s||l.value.amountIn<s.amountIn)&&(s={...l.value,fee:n[a]})}if(!s)throw new Error("No liquidity found for this pair on any fee tier.");return s}function Fr(t){return t.type==="swap"}const Ro=.02,Ba=[1,8453,42161,10,137,43114,56],Fa="https://api.1inch.dev/swap/v6.0";function Mr(t,n){return os(t,n)}function Rr(t){const n=t?.baseUrl??Fa;return{name:"1inch",chainIds:t?.chainIds??Ba,resolve:async(o,s,a)=>{const l=o.maxSlippage??Ro,r=l*100,c=rt(o.tokenIn)?Yo:o.tokenIn,d=rt(o.tokenOut)?Yo:o.tokenOut,u=rt(o.tokenIn);try{const p=new URL(`${n}/${s}/swap`);p.searchParams.set("src",c),p.searchParams.set("dst",d),p.searchParams.set("amount",o.amountIn.toString()),p.searchParams.set("from",a),p.searchParams.set("slippage",r.toString()),p.searchParams.set("disableEstimate","true"),p.searchParams.set("allowPartialFill","false");const f={Accept:"application/json"};t?.apiKey&&(f.Authorization=`Bearer ${t.apiKey}`);const m=await fetch(p.toString(),{headers:f});if(!m.ok)throw new Oe("VENUE_API_ERROR",`[1inchVenue] API returned ${m.status} for ${o.tokenIn} \u2192 ${o.tokenOut} on chain ${s}`,{venue:"1inch",chainId:s,tokenIn:o.tokenIn,tokenOut:o.tokenOut,amountIn:o.amountIn.toString(),cause:`HTTP ${m.status}`});const g=await m.json();if(!g.dstAmount||!g.tx)return console.warn(`[1inchVenue] No route data for ${o.tokenIn} \u2192 ${o.tokenOut} on chain ${s}`),null;const h=BigInt(g.dstAmount);if(h<=0n)return console.warn(`[1inchVenue] Zero output for ${o.tokenIn} \u2192 ${o.tokenOut} on chain ${s}`),null;const C=Mr(h,l),y=[];return g.tx.to&&!u&&y.push({to:o.tokenIn,value:0n,data:Wt({abi:At,functionName:"approve",args:[g.tx.to,o.amountIn]})}),y.push({to:g.tx.to,value:BigInt(g.tx.value||"0"),data:g.tx.data}),{venue:"1inch",amountOut:h,amountOutMinimum:C,calls:y}}catch(p){if(p instanceof Oe)throw p;const f=p instanceof Error?p.message:String(p);throw new Oe("VENUE_API_ERROR",`[1inchVenue] Exception for ${o.tokenIn} \u2192 ${o.tokenOut} on chain ${s}: ${f}`,{venue:"1inch",chainId:s,tokenIn:o.tokenIn,tokenOut:o.tokenOut,amountIn:o.amountIn.toString(),cause:f})}}}}const Tr=[4114,5115],To={swapRouter:"0x565eD3D57fe40f78A46f348C220121AE093c3cF8",quoterV2:"0x428f20dd8926Eabe19653815Ed0BE7D6c36f8425"},Wr={swapRouter:"0x2626664c2603336E57B271c5C0b26F421741e481",quoterV2:"0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a",chainIds:[8453]};function Dr(t){return{name:"satsuma",chainIds:t.chainIds??Tr,resolve:async(n,o,s)=>{const a=n.maxSlippage??Ro,l=rt(n.tokenIn);let r;try{r=await Br({tokenIn:n.tokenIn,tokenOut:n.tokenOut,amountIn:n.amountIn,chainId:o,config:{swapRouter:t.swapRouter,quoterV2:t.quoterV2},feeTiers:t.feeTiers})}catch{return console.warn(`[SatsumaVenue] No viable fee tier for ${n.tokenIn} \u2192 ${n.tokenOut} on chain ${o}.`),null}const c=Mr(r.amountOut,a),d=[];return l||d.push({to:n.tokenIn,value:0n,data:Wt({abi:At,functionName:"approve",args:[t.swapRouter,n.amountIn]})}),d.push({to:t.swapRouter,value:l?n.amountIn:0n,data:Wt({abi:ns,functionName:"exactInputSingle",args:[{tokenIn:n.tokenIn,tokenOut:n.tokenOut,fee:r.fee,recipient:s,amountIn:n.amountIn,amountOutMinimum:c,sqrtPriceLimitX96:0n}]})}),{venue:"satsuma",amountOut:r.amountOut,amountOutMinimum:c,calls:d}}}}function zr(t){return{name:"satsuma",chainIds:t.chainIds??Tr,resolve:async(n,o,s)=>{const a=n.maxSlippage??Ro,l=rt(n.tokenIn);let r;try{r=await Ea({tokenIn:n.tokenIn,tokenOut:n.tokenOut,amountOut:n.amountOut,chainId:o,config:{swapRouter:t.swapRouter,quoterV2:t.quoterV2},feeTiers:t.feeTiers})}catch{return null}const c=BigInt(Math.round(a*1e4)),d=r.amountIn+r.amountIn*c/10000n,u=[];return u.push({to:t.swapRouter,value:l?d:0n,data:Wt({abi:Ma,functionName:"exactOutputSingle",args:[{tokenIn:n.tokenIn,tokenOut:n.tokenOut,fee:r.fee,recipient:s,amountOut:n.amountOut,amountInMaximum:d,sqrtPriceLimitX96:0n}]})}),{venue:"satsuma",amountIn:r.amountIn,amountInMax:d,amountOut:n.amountOut,calls:u}}}}const Ma=[{inputs:[{components:[{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"fee",type:"uint24"},{name:"recipient",type:"address"},{name:"amountOut",type:"uint256"},{name:"amountInMaximum",type:"uint256"},{name:"sqrtPriceLimitX96",type:"uint160"}],name:"params",type:"tuple"}],name:"exactOutputSingle",outputs:[{name:"amountIn",type:"uint256"}],stateMutability:"payable",type:"function"}];function Ur(t){const n=[];t?.customVenues&&n.push(...t.customVenues),t?.satsuma&&n.push(Dr(t.satsuma)),n.push(Rr(t?.oneInch));function o(a){return n.find(l=>l.chainIds.includes(a))}async function s(a,l,r){const c=[],d=[];for(const u of a){if(!Fr(u)){c.push(u);continue}const p=o(l);if(!p)throw new Oe("NO_VENUE_FOR_CHAIN",`No liquidity venue configured for chain ${l}. Cannot resolve swap ${u.tokenIn} \u2192 ${u.tokenOut}.`,{chainId:l,tokenIn:u.tokenIn,tokenOut:u.tokenOut,amountIn:u.amountIn.toString()});const f=await p.resolve(u,l,r);if(!f)throw new Oe("NO_LIQUIDITY",`${p.name} returned no quote for ${u.tokenIn} \u2192 ${u.tokenOut} on chain ${l}.`,{venue:p.name,chainId:l,tokenIn:u.tokenIn,tokenOut:u.tokenOut,amountIn:u.amountIn.toString()});c.push(...f.calls),d.push(f)}return{calls:c,resolvedSwaps:d}}return{resolveSwapIntents:s,getVenueForChain:o,venues:n}}function Ra(t){const n=t?.customVenues??[];async function o(s,a,l){const r=n.filter(d=>d.chainIds.includes(a));if(r.length===0)throw new Oe("NO_SWAP_ROUTE",`No exact-output venue supports chain ${a}`,{chainId:a,tokenIn:s.tokenIn,tokenOut:s.tokenOut});const c=(await Promise.allSettled(r.map(d=>d.resolve(s,a,l)))).filter(d=>d.status==="fulfilled").map(d=>d.value).filter(d=>d!==null);if(c.length===0)throw new Oe("NO_SWAP_ROUTE",`All aggregators failed for ${s.tokenIn} \u2192 ${s.tokenOut} on chain ${a}`,{chainId:a,tokenIn:s.tokenIn,tokenOut:s.tokenOut,amountOut:s.amountOut.toString()});return c.sort((d,u)=>d.amountIn<u.amountIn?-1:d.amountIn>u.amountIn?1:0),c[0]}return{getQuote:o,venues:n}}function Ta(t){const{direction:n,selectedAsset:o,destinationToken:s,chainId:a,recipient:l,paymentAmount:r}=t,[c,d]=B(!1),[u,p]=B(null),[f,m]=B(null),[g,h]=B(null),[C,y]=B(null),[S,U]=B(null),[b,x]=B(null),M=Fe(null),z=Ce(()=>Ur({satsuma:To}),[]),T=Ce(()=>Ra({customVenues:[zr(To),zr(Wr)]}),[]),I=Ce(()=>{if(!o?.asset)return null;if(o.asset.chainId===a)return o.asset.address;const D=yn(o.asset.address,a);return D?D.address:null},[o?.asset?.address,o?.asset?.chainId,a]),F=Ce(()=>o?.asset?o.asset.address.toLowerCase()===s.address.toLowerCase()&&o.asset.chainId===a?!0:rs(o.asset.address,s.address):!1,[o,s.address,a]),w=I?I.toLowerCase()===s.address.toLowerCase():!1,W=n==="output"&&parseFloat(r||"0")===0,Z=!!o?.asset&&!F&&!w&&!W;return $(()=>{M.current&&clearTimeout(M.current);const D=n==="input"?o?.amount:r,A=parseFloat(D||"0");if(!Z||A<=0||!o?.asset||!l||!I){m(null),h(null),y(null),U(null),x(null),p(null),d(!1);return}return d(!0),M.current=setTimeout(async()=>{try{if(n==="input"){const E=_e(o.amount,o.asset.decimals),O=z.getVenueForChain(a);if(!O)throw new Error("No swap venue for this chain");const V=await O.resolve({type:"swap",tokenIn:I,tokenOut:s.address,amountIn:E},a,l);if(!V)throw new Error("No liquidity for this pair");x(V.amountOut),y(V),U(null);const P=wn(V.amountOut,s.decimals),X=parseFloat(P);m(X<.01?X.toPrecision(4):X.toLocaleString(void 0,{maximumFractionDigits:6})),h(null),p(null)}else{const E=_e(r||"0",s.decimals),O=await T.getQuote({tokenIn:I,tokenOut:s.address,amountOut:E},a,l);U(O),y(null),x(null),h(parseFloat(wn(O.amountIn,o.asset.decimals)).toFixed(6)),m(null),p(null)}}catch(E){const O=E instanceof Error?E.message:"Failed to get quote";p(O),m(null),h(null),y(null),U(null),x(null)}finally{d(!1)}},500),()=>{M.current&&clearTimeout(M.current)}},[n,Z,o?.amount,o?.asset?.address,o?.asset?.decimals,r,I,a,s.address,s.decimals,l,z,T]),{isQuoting:c,quoteError:u,estimatedOutput:f,estimatedInput:g,resolvedSwap:C,exactOutputSwap:S,quoteAmountOut:b,resolvedTokenIn:I,isDirect:w,needsSwap:Z,selectedIsEquivalent:F}}const Wa=[0n,1n,30n],Da=new Set(["ABORT","CONCURRENT_EXECUTION","WALLET_DISCONNECTED","WALLET_REJECTED","NO_VENUE_FOR_CHAIN"]);function Nr(t,n){return n===0n?t:t*(1000n-n)/1000n}async function Pr(t,n){const{chainId:o,swapCalls:s,quoteAmountOut:a,buildActionCalls:l,tokenAddress:r,tokenTransferAmount:c,onProgress:d,signal:u,options:p,buffers:f=Wa}=n;for(let m=0;m<f.length;m++){const g=f[m],h=Nr(a,g),C=l(h),y=[{chainId:o,calls:[...s,...C]}];try{return await t(y,r,c,d,u,p)}catch(S){if(Xn(S)&&Da.has(S.code)||S.name==="AbortError"||u?.aborted||S.message?.includes("User rejected")||S.message?.includes("User denied")||S.code===4001||m>=f.length-1)throw S;const U=Number(f[m+1])/10;console.warn(`[SwapThenAction] Action attempt ${m+1} failed (buffer ${Number(g)/10}%), retrying with ${U}% buffer...`,S.message),d?.({step:"signing-delegation",message:`Adjusting action amount, retrying (${U}% buffer)...`})}}throw new Oe("ALL_ATTEMPTS_FAILED","All action attempts failed after exhausting buffer progression.",{attempts:f.length,chainId:o})}const Lr={idle:"","signing-delegation":"Signing delegation...","signing-intent":"Signing intent...",submitting:"Submitting transaction...",executing:"Executing on-chain...",success:"Transaction successful!",error:"Transaction failed"},Hr=["signing-delegation","signing-intent","submitting","executing"],za=({color:t})=>i("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",style:{marginTop:"1px",flexShrink:0},children:[e("circle",{cx:"7",cy:"7",r:"6.5",stroke:t,strokeWidth:"1.2"}),e("path",{d:"M7 6v4",stroke:t,strokeWidth:"1.2",strokeLinecap:"round"}),e("circle",{cx:"7",cy:"4.5",r:"0.7",fill:t})]}),jr=({isOpen:t,onClose:n,destinationToken:o,buildActionCalls:s,actionLabel:a,amountDirection:l="input",swapDescription:r,directDescription:c,supportedSourceAssets:d,sourceChains:u,paymentAmount:p,amountInputMode:f="fixed",minPaymentAmount:m,maxPaymentAmount:g,onAmountChange:h,styles:C,dark:y,title:S,subtitle:U,onAddFunds:b,onSuccess:x,onError:M})=>{const z=l==="output",{theme:T,dark:I,primaryColor:F,dk:w,palette:W}=je(C,y),Z=T.typography.fontFamily,D=C?.inputVariant?C.inputVariant==="dark":I,A=W.textPrimary,E=W.textSecondary,O=D?w.cardBg:"#f9fafb",V=D?w.cardBorder:"#e5e7eb",P=C?.button?.backgroundColor??F,X=C?.button?.color??"#0e0d0b",se=D?{...T,colors:{...T.colors,secondary:w.cardBg,surfaceHover:w.hoverBg,border:"#2d2d2d",borderHover:"#3a3a3a"}}:T,R=o.chainId,H=tn(),{address:q,isConnected:me,isReady:we,isAuthenticated:oe,provider:ae}=H,{executeGasless:de}=co(),{displayAssets:Me,filteredSpiceAssets:ye,embeddedWalletAddress:We,refreshSpiceAssets:ce,refreshWalletAssets:Ve}=ka({address:q,destinationToken:o,supportedSourceAssets:d,sourceChains:u,enabled:t&&!!q}),De=z?Me:ye,[L,Se]=B(null),[Ee,te]=B(p||""),[ze,Pe]=B(!1),[Q,J]=B(null),[v,k]=B("idle"),[ee,re]=B(""),[N,Y]=B(null),[le,pe]=B(!1),[ke,pt]=B(null),fe=Fe(L),xe=Fe(!1),be=Fe(null);$(()=>{fe.current=L},[L]);const Xe=f==="adjustable"?Ee:p||"0",kt=We||q,{isQuoting:Ct,quoteError:ut,estimatedOutput:Ut,resolvedSwap:St,exactOutputSwap:st,quoteAmountOut:Nt,resolvedTokenIn:Zt,isDirect:ue,needsSwap:ge,selectedIsEquivalent:ve}=Ta({direction:l,selectedAsset:L,destinationToken:o,chainId:R,recipient:kt,paymentAmount:Xe}),Je=z?parseFloat(Xe||"0"):parseFloat(L?.amount||"")||0,ht=Ce(()=>L?.asset?ye.find(Ie=>Ie.address.toLowerCase()===L.asset.address.toLowerCase())?.balanceFormatted??0:0,[L,ye]),et=Ce(()=>L?.asset?z?ve?Je>L.asset.balanceFormatted:st?parseFloat(wn(st.amountInMax,L.asset.decimals))>L.asset.balanceFormatted:!1:Je>ht:!1,[L,z,ve,Je,st,ht]);$(()=>{t||(Se(null),J(null),Pe(!1),k("idle"),re(""),Y(null),pe(!1),pt(null),xe.current=!1,f==="adjustable"&&te(p||""),be.current&&(be.current.abort(),be.current=null))},[t]);const at=ie(Ie=>{Se(Re=>({asset:Ie,amount:Re?.asset?.address===Ie.address&&Re?.asset?.chainId===Ie.chainId&&Re.amount||""})),J(null)},[]),Mt=ie(Ie=>{Se(Re=>Re&&{...Re,amount:Ie}),J(null)},[]),nn=ie(Ie=>{let Re=Ie;g&&parseFloat(Re)>parseFloat(g)&&(Re=g),te(Re),h?.(Re),J(null)},[g,h]),on=ie(Ie=>{k({building:"signing-delegation","signing-delegation":"signing-delegation","signing-intent":"signing-intent",submitting:"submitting",executing:"executing",success:"success",error:"error"}[Ie.step]||"executing"),re(Ie.message),Ie.txHash&&Y(Ie.txHash)},[]),hn=ie(()=>{const Ie=_e(Xe,o.decimals),Re={userAddress:We,chainId:R,destinationToken:o.address},Te=s(Ie,Re),Ae={chainId:R,calls:Te},lt=L?.asset?._source==="spice",Ye=(Ze,Be)=>({token:Ze,from:"solver",to:We,amount:Be});if(Ie===0n)return[Ae];if(ge&&st){let Ze=L.asset.address;if(L.asset.chainId!==R){const $e=Ko(L.asset.address)?.deployments.find(Pt=>Pt.chainId===R);$e&&(Ze=$e.address)}const Be=lt?[Ye(Ze,st.amountInMax)]:[],He={to:Ze,value:0n,data:Wt({abi:At,functionName:"approve",args:[st.calls[0]?.to,st.amountInMax]})};return[{chainId:R,calls:[He,...st.calls,...Te],tokenTransfers:[...Be,...Ae.tokenTransfers??[]]}]}if(lt){let Ze=o.address;if(L.asset.chainId!==R){const Be=Ko(L.asset.address)?.deployments.find(He=>He.chainId===R);Be&&(Ze=Be.address)}return[{...Ae,tokenTransfers:[Ye(Ze,Ie),...Ae.tokenTransfers??[]]}]}return[Ae]},[Xe,o,We,R,s,L,ge,st]),fn=ie(async()=>{if(!L?.asset||Je<=0){J("Select an asset and enter an amount");return}if(et){J("Insufficient balance");return}if(!We){J("Wallet not ready");return}Pe(!0),J(null),k("signing-delegation"),re("Building transaction..."),Y(null),xe.current=!1;const Ie=new AbortController;be.current=Ie;try{const Re={userAddress:We,chainId:R,destinationToken:o.address};if(ue){const Te=_e(L.amount,L.asset.decimals),Ae=s(Te,Re);await de([{chainId:R,calls:Ae}],Zt??L.asset.address,Te,on,Ie.signal)}else{if(!St||!Nt)throw new Error("Please wait for the swap quote");const Te=_e(L.amount,L.asset.decimals);await Pr(de,{chainId:R,swapCalls:St.calls,quoteAmountOut:Nt,buildActionCalls:Ae=>s(Ae,Re),tokenAddress:Zt,tokenTransferAmount:Te,onProgress:on,signal:Ie.signal})}k("success"),re("Transaction successful!")}catch(Re){const Te=Re instanceof Error?Re:new Error(String(Re));if(Te.name==="AbortError"||Ie.signal.aborted){k("idle");return}const Ae=Te.message||"Transaction failed";k("error"),re(Ae),J(Ae),M?.(Te)}finally{Pe(!1)}},[L,Je,et,We,ue,R,St,Nt,Zt,s,de,on,M]),kn=ie(async()=>{if(Je<0){J("Enter a valid payment amount");return}if(!L?.asset){J("Select a payment source");return}if(et){J("Insufficient balance");return}if(ge&&!st){J("Swap quote not available. Try a different asset.");return}if(!me||!q){J("Please connect your wallet to continue");return}if(!we||!oe){J(`Please authenticate with ${ae||"wallet provider"} to continue`);return}Pe(!0),J(null),pe(!0),pt({status:"processing"});try{const Ie=hn(),Re=Ie.some(Ye=>Ye.tokenTransfers?.length),Te=_e(Xe,o.decimals),Ae=L?.asset?.address||o.address,lt=await de(Ie,Ae,Te,Ye=>{Ye.txHash&&(pt(Ze=>({...Ze,txHash:Ye.txHash})),Y(Ye.txHash))},void 0,Re?{useCustomTransfers:!0}:void 0);pt(Ye=>({status:"success",txHash:Ye?.txHash||lt}))}catch(Ie){const Re=Ot(Ie,"Payment failed. Please try again.");J(Re),pt({status:"failed",error:Re}),M?.(Ie instanceof Error?Ie:new Error(Re))}finally{Pe(!1)}},[Je,L,et,ge,st,me,q,we,oe,ae,hn,Xe,o,de,M]);$(()=>{!z&&v==="success"&&N&&(ce(),x?.(N))},[z,v,N,ce,x]),$(()=>{if(!z||ke?.status!=="success"||xe.current||!q)return;xe.current=!0;const Ie=fe.current;!Ie?.asset||Ie.asset?._source==="wallet"||ce()},[z,ke?.status,q,ce]);const qt=Fe(x),Vt=Fe(M);$(()=>{qt.current=x},[x]),$(()=>{Vt.current=M},[M]),$(()=>{z&&(ke?.status==="success"&&qt.current?.(ke.txHash||""),ke?.status==="failed"&&Vt.current?.(new Error("Payment execution failed")))},[z,ke?.status]);const Gt=ie(()=>{pe(!1),pt(null),Se(null),xe.current=!1,ce(),Ve()},[ce,Ve]),rn=z?!!L?.asset&&Je>=0&&!et&&!ze&&(!ge||!!st):!!L?.asset&&Je>0&&!et&&!ze&&(ue||!!St&&!Ct),Bt=ue?c||`Your ${o.symbol} will be used directly.`:r||"Your assets will be swapped and used in a single atomic transaction.",sn=I?w.shell:"white",an=I?w.buttonBorder:"#0e0d0b",gn=(R?Ke(R):void 0)?.viemChain?.blockExplorers?.default?.url??"",Jt=Hr.indexOf(v),mn=ze?(Lr[v]||"EXECUTING...").toUpperCase():v==="success"?"DONE":et?"INSUFFICIENT BALANCE":a.toUpperCase(),_=Ce(()=>{if(ze)return"PAYING...";if(et&&L?.asset)return`INSUFFICIENT ${L.asset.symbol}`;const Ie=Je>0?` ${Xe} ${o.symbol}`:"";return ge?`SWAP & PAY${Ie}`:`PAY${Ie}`},[ze,et,L,Je,Xe,o.symbol,ge]),he=v==="success"?()=>{k("idle"),Se(null),Y(null),ce()}:fn,tt=v==="success"?!1:!rn;if(!t)return null;const it=z?S||`Pay ${o.symbol}`:a,gt=z?U:i("div",{style:{display:"flex",alignItems:"flex-start",gap:"6px"},children:[e(za,{color:E}),e("p",{style:{fontSize:"13px",color:E,margin:0,lineHeight:"1.5"},children:Bt})]});if(z){const Ie=ke&&(ke.status==="success"||ke.status==="failed")?[{asset:{symbol:L?.asset?.symbol||o.symbol,address:L?.asset?.address||""},amount:Xe,txHash:ke.txHash||"",success:ke.status==="success",error:ke.status==="failed"?ke.error:void 0}]:void 0;return e(Dt,{isOpen:t,onClose:n,title:it,subtitle:gt,styles:C,dark:I,footerLinkText:"Spicenet accounts \u2192",children:i("div",{style:{padding:"16px 24px 8px 24px",position:"relative"},children:[b&&e("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:"6px"},children:i("button",{onClick:b,style:{background:"none",border:"none",cursor:"pointer",padding:0,display:"flex",alignItems:"center",gap:"4px",color:F,fontSize:"12px",fontWeight:500,fontFamily:Z,textDecoration:"underline",textUnderlineOffset:"2px"},children:["Add Funds",i("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:F,strokeWidth:"1.8",children:[e("circle",{cx:"6",cy:"6",r:"5"}),e("path",{d:"M6 4v4M4 6h4",strokeLinecap:"round"})]})]})}),e("div",{style:{marginBottom:"12px"},children:e(Rn,{assets:De,selectedAsset:L??void 0,onAssetSelect:at,onAmountChange:()=>{},label:"Pay with",showBalance:!0,showMaxButton:!1,hideAmountInput:!0,displayAmount:L?.asset?ge?Ct?"...":st?`~${parseFloat(wn(st.amountIn,L.asset.decimals)).toFixed(6)}`:void 0:Xe??void 0:void 0,dark:I,theme:se,styles:C})}),e(vr,{variant:"pay",destinationSymbol:o.symbol,destinationLogoURI:o.logoURI,destinationDecimals:o.decimals,primaryColor:F,fontFamily:Z,textPrimary:A,textSecondary:E,cardBg:O,cardBorder:V,dk:w,dark:I,isQuoting:Ct,quoteError:ut,estimatedOutput:Ut,paymentAmount:Xe,needsSwap:ge,exactOutputSwap:st,adjustable:f==="adjustable",maxAmount:g,onAmountChange:nn}),Q&&e("div",{style:{marginBottom:"12px",padding:"10px 14px",backgroundColor:W.errorBg,border:`1px solid ${W.errorBorder}`,borderRadius:"6px"},children:e("p",{style:{color:W.errorText,fontSize:"13px",margin:0,fontFamily:Z},children:Q})}),e(Ge,{variant:"outline",fullWidth:!0,onClick:kn,disabled:!rn,loading:ze,dark:I,styles:{button:{backgroundColor:F}},children:_}),ke&&le&&e("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:10,backgroundColor:I?w.shell:"white",borderRadius:I?"12px":"6px",padding:"16px 0"},children:e(Ln,{type:"payment",isOpen:ke.status!=="processing",isProcessing:ze||ke.status==="processing",closeOnComplete:!1,chainName:vt(R),explorerUrl:Cn(R,"").replace(/\/tx\/.*$/,"")||void 0,onRetryTx:()=>{pe(!1),pt(null),kn()},onNewTx:Gt,onClose:()=>{pe(!1),pt(null)},onComplete:Gt,results:Ie,styles:C,dark:I})})]})})}return i(Dt,{isOpen:t,onClose:n,title:it,subtitle:gt,dark:I,styles:C,theme:T,children:[e("div",{style:{marginBottom:"16px"},children:e(Rn,{assets:De,selectedAsset:L||void 0,onAssetSelect:at,onAmountChange:Mt,disabled:ze||v==="success",showBalance:!0,showMaxButton:!0,label:"From Spice Balance",placeholder:"0.00",theme:se,styles:C,dark:D,maxAmount:ht>0?ht.toString():void 0})}),L?.asset&&!ue&&e(vr,{variant:"supply",destinationSymbol:o.symbol,destinationLogoURI:o.logoURI,destinationDecimals:o.decimals,primaryColor:F,fontFamily:Z,textPrimary:A,textSecondary:E,cardBg:O,cardBorder:V,dark:I,isQuoting:Ct,quoteError:ut,estimatedOutput:Ut}),v!=="idle"&&i("div",{style:{padding:"10px 14px",borderRadius:"10px",marginBottom:"16px",backgroundColor:v==="success"?W.successBg:v==="error"?W.errorBg:O,border:`1px solid ${v==="success"?W.successBorder:v==="error"?W.errorBorder:V}`},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[v==="success"?e("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:e("path",{d:"M5 13l4 4L19 7",stroke:W.successText,strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round"})}):v==="error"?e("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:e("path",{d:"M18 6L6 18M6 6l12 12",stroke:W.errorText,strokeWidth:"2.5",strokeLinecap:"round"})}):e(An,{size:14,color:F}),e("span",{style:{fontSize:"13px",fontWeight:500,color:v==="success"?W.successText:v==="error"?W.errorText:A,fontFamily:Z,flex:1},children:v==="success"?"Transaction successful!":v==="error"?ee||"Transaction failed":Lr[v]||ee}),v==="success"&&N&&e("a",{href:`${gn}/tx/${N}`,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:F,fontFamily:Z,textDecoration:"none",whiteSpace:"nowrap",flexShrink:0},children:"View tx \u2192"}),v==="error"&&e("button",{onClick:()=>{k("idle"),J(null),setTimeout(fn,50)},style:{background:"none",border:"none",fontSize:"12px",color:F,fontFamily:Z,cursor:"pointer",padding:0,whiteSpace:"nowrap",flexShrink:0},children:"Retry \u2192"})]}),Jt>=0&&v!=="success"&&v!=="error"&&e("div",{style:{marginTop:"8px",height:"3px",borderRadius:"2px",backgroundColor:`${E}22`,overflow:"hidden"},children:e("div",{style:{height:"100%",borderRadius:"2px",backgroundColor:F,width:`${(Jt+1)/Hr.length*100}%`,transition:"width 400ms ease"}})})]}),Q&&v==="idle"&&e("div",{style:{padding:"10px 14px",borderRadius:"10px",backgroundColor:W.errorBg,border:`1px solid ${W.errorBorder}`,marginBottom:"16px"},children:e("p",{style:{fontSize:"13px",color:W.errorText,margin:0,fontFamily:Z},children:Q})}),e(Ge,{variant:"outline",fullWidth:!0,disabled:tt,onClick:he,style:{height:"56px",backgroundColor:tt?`${P}66`:v==="success"?W.successBg:P,color:v==="success"?W.successText:X,border:`1px solid ${v==="success"?W.successBorder:an}`,fontSize:"14px",fontWeight:700,letterSpacing:"2px",fontFamily:'"IBM Plex Mono", monospace',boxShadow:tt?"none":`3px 3px 0px ${sn}, 4px 4px 0px ${an}`,cursor:tt?"not-allowed":"pointer",opacity:tt?.6:1},children:mn})]})},Ua=t=>e(jr,{isOpen:t.isOpen,onClose:t.onClose,amountDirection:"output",destinationToken:{address:t.paymentTokenAddress,symbol:t.paymentTokenSymbol,decimals:t.paymentTokenDecimals,chainId:t.paymentChainId,logoURI:t.paymentTokenLogoURI},buildActionCalls:t.buildActionCalls,actionLabel:t.ctaLabel||"PAY",paymentAmount:t.paymentAmount,amountInputMode:t.amountInputMode,minPaymentAmount:t.minPaymentAmount,maxPaymentAmount:t.maxPaymentAmount,onAmountChange:t.onAmountChange,sourceChains:t.sourceChains,title:t.title,subtitle:t.subtitle,onAddFunds:t.onAddFunds,styles:t.styles,dark:t.dark,onSuccess:t.onPaymentSuccess,onError:t.onPaymentError}),Na=({label:t="Export Wallet",style:n,className:o,onExport:s,onError:a})=>{const[l,r]=B(!1),[c,d]=B(!1),{primaryColor:u}=je(),p=It(xt),{isAuthenticated:f}=tn();let m=null;try{m=to()}catch{}let g=null,h=null;try{g=cs(),h=no()}catch{g=null,h=null}const C=oo(h),y=ie(async()=>{if(!f){a?.("User is not authenticated. Please log in first.");return}try{if(p?.provider==="dynamic"){if(!g||!C){a?.("Dynamic is not available. Ensure the app is wrapped in a DynamicContextProvider.");return}await g.initExportProcess(!1),s?.();return}if(!m){a?.("Privy is not available. Ensure the app is wrapped in a PrivyProvider.");return}await m.exportWallet(),s?.()}catch(b){const x=b instanceof Error?b.message:"Failed to export wallet";console.error("Export wallet error:",b),a?.(x)}},[C,g,f,a,s,m,p?.provider]),S=!f,U={padding:"10px 20px",borderRadius:"8px",fontFamily:'"IBM Plex Mono", monospace',fontSize:"14px",fontWeight:500,letterSpacing:"0.4px",textTransform:"uppercase",cursor:S?"not-allowed":"pointer",opacity:S?.5:1,border:"1px solid #0e0d0b",color:"#0e0d0b",backgroundColor:c?`${u}cc`:l?`${u}ee`:u,transition:"all 150ms ease",display:"inline-flex",alignItems:"center",justifyContent:"center",gap:"8px",...n};return i("button",{onClick:y,onMouseEnter:()=>r(!0),onMouseLeave:()=>{r(!1),d(!1)},onMouseDown:()=>d(!0),onMouseUp:()=>d(!1),disabled:S,className:o,style:U,children:[i("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e("polyline",{points:"17 8 12 3 7 8"}),e("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]}),t]})};function Or(t){const n=It(xt),o=en(),s=t?.enabled===!1?void 0:o,a=n?.network?{network:n.network,pollIntervalMs:t?.pollIntervalMs,chainIds:t?.chainIds??n.supportedChainIds}:void 0;return{...gr(s,a),embeddedWalletAddress:o}}const Pa=({appName:t,status:n,statusLabel:o,totalUsdValue:s,breakdownSubtitle:a,address:l,dk:r,dark:c=!1,showModeToggle:d,isEmbeddedMode:u=!0,onModeToggle:p})=>{const[f,m]=B(!1),g=async()=>{l&&await Ss(l)&&(m(!0),setTimeout(()=>m(!1),2e3))},h=n==="active",C=o||(h?"Active":"Inactive"),y=h?"#10b981":"#9ca3af";return i("div",{children:[i("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"4px"},children:[i("div",{style:{fontSize:"13px",fontWeight:600,color:c?r.textPrimary:"#111827"},children:[t," Account"]}),d?i("button",{onClick:p,style:{display:"flex",alignItems:"center",gap:"4px",padding:"2px 8px",borderRadius:"9999px",backgroundColor:c?r.hoverBg:"#f3f4f6",border:c?`1px solid ${r.cardBorder}`:"1px solid #e5e7eb",cursor:"pointer",fontSize:"11px",fontWeight:600,fontFamily:'"IBM Plex Mono", monospace',color:c?r.textSecondary:"#6b7280",transition:"all 150ms ease",letterSpacing:"0.02em"},children:[e("div",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:u?"#22c55e":"#f59e0b"}}),e("span",{children:u?"Embedded":"External"})]}):i("div",{style:{display:"flex",alignItems:"center",gap:"4px",padding:"2px 8px",borderRadius:"9999px",backgroundColor:c?r.hoverBg:h?"#ecfdf5":"#f3f4f6",border:c?`1px solid ${r.cardBorder}`:h?"1px solid #a7f3d0":"1px solid #e5e7eb"},children:[e("div",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:y}}),e("span",{style:{fontSize:"11px",fontWeight:500,color:c?r.textSecondary:h?"#065f46":"#6b7280"},children:C})]})]}),e("div",{style:{fontSize:"28px",fontWeight:700,color:c?r.textPrimary:"#111827",lineHeight:1.2,marginBottom:"2px"},children:Mn(s)}),a&&e("div",{style:{fontSize:"12px",color:c?r.textSecondary:"#6b7280",marginBottom:"8px"},children:a}),l&&i("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[e("span",{style:{fontSize:"12px",fontFamily:'"IBM Plex Mono", monospace',color:c?r.textSecondary:"#9ca3af"},children:Is(l)}),e("button",{onClick:g,style:{padding:"2px 6px",fontSize:"10px",fontWeight:500,backgroundColor:"transparent",color:c?r.textSecondary:"#9ca3af",border:"none",cursor:"pointer",borderRadius:"4px",transition:"all 150ms ease"},title:"Copy address",children:f?"Copied":"Copy"})]})]})},La=({pendingDeposits:t,onCompleteDeposit:n,dk:o,dark:s=!1})=>t.length===0?null:i("div",{children:[e("div",{style:{fontSize:"11px",fontWeight:600,letterSpacing:"1px",color:s?o.textSecondary:"#6b7280",marginBottom:"8px",textTransform:"uppercase"},children:"Pending Deposits"}),e("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:t.map((a,l)=>{const r=Ke(a.chainId)?.displayName||`Chain ${a.chainId}`;return i("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 12px",backgroundColor:s?o.warningBg:"#fffbeb",border:s?`1px solid ${o.warningBorder}`:"1px solid #fde68a",borderRadius:"8px"},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e("div",{style:{width:"24px",height:"24px",borderRadius:"50%",backgroundColor:s?o.hoverBg:"#fde68a",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"11px",fontWeight:600,color:s?o.warningText:"#92400e"},children:a.tokenSymbol.charAt(0)}),i("div",{children:[i("div",{style:{fontSize:"13px",fontWeight:500,color:s?o.textPrimary:"#111827"},children:[a.amount," ",a.tokenSymbol]}),i("div",{style:{fontSize:"11px",color:s?o.warningText:"#92400e"},children:["on ",r]})]})]}),e("button",{onClick:()=>n?.(a),style:{padding:"4px 12px",fontSize:"11px",fontWeight:600,backgroundColor:s?o.hoverBg:"#fef3c7",color:s?o.textPrimary:"#92400e",border:s?`1px solid ${o.warningBorder}`:"1px solid #fde68a",borderRadius:"9999px",cursor:"pointer",transition:"all 150ms ease"},children:"Complete"})]},`${a.tokenAddress}-${a.chainId}-${l}`)})})]}),Ha=({spiceAssets:t,loading:n,dk:o,dark:s=!1})=>{const a={fontSize:"11px",fontWeight:600,letterSpacing:"1px",color:s?o.textSecondary:"#6b7280",marginBottom:"8px",textTransform:"uppercase"},l={backgroundColor:s?o.cardBg:"#f9fafb",border:s?`1px solid ${o.cardBorder}`:"1px solid #e5e7eb",borderRadius:"8px"};return n?i("div",{children:[e("div",{style:a,children:"Idle Balances"}),[1,2].map(r=>e("div",{style:{...l,padding:"12px",marginBottom:"6px",height:"48px",animation:"pulse 1.5s ease-in-out infinite",opacity:.5}},r))]}):t.length===0?i("div",{children:[e("div",{style:a,children:"Idle Balances"}),e("div",{style:{...l,padding:"16px",textAlign:"center",fontSize:"13px",color:s?o.textSecondary:"#9ca3af"},children:"No assets yet. Deposit to get started."})]}):i("div",{children:[e("div",{style:a,children:"Idle Balances"}),e("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:t.map((r,c)=>{const d=Ke(r.chainId)?.displayName||`Chain ${r.chainId}`;return i("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 12px",...l},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[r.logoURI?e("img",{src:r.logoURI,alt:r.tokenSymbol,style:{width:"24px",height:"24px",borderRadius:"50%"}}):e("div",{style:{width:"24px",height:"24px",borderRadius:"50%",backgroundColor:s?o.hoverBg:"#e5e7eb",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"11px",fontWeight:600,color:s?o.textSecondary:"#6b7280"},children:r.tokenSymbol.charAt(0)}),i("div",{children:[e("div",{style:{fontSize:"13px",fontWeight:500,color:s?o.textPrimary:"#111827"},children:r.tokenSymbol}),e("div",{style:{fontSize:"11px",color:s?o.textSecondary:"#9ca3af"},children:d})]})]}),i("div",{style:{textAlign:"right"},children:[e("div",{style:{fontSize:"13px",fontWeight:500,color:s?o.textPrimary:"#111827"},children:ao(r.balanceFormatted)}),e("div",{style:{fontSize:"11px",color:s?o.textSecondary:"#9ca3af"},children:Mn(r.usdValue)})]})]},`${r.tokenAddress}-${r.chainId}-${c}`)})})]})},ja=({section:t,dk:n,dark:o=!1})=>{const s=a=>{switch(a){case"green":return"#10b981";case"red":return"#ef4444";default:return o?n.textPrimary:"#111827"}};return i("div",{children:[e("div",{style:{fontSize:"11px",fontWeight:600,letterSpacing:"1px",color:o?n.textSecondary:"#6b7280",marginBottom:"8px",textTransform:"uppercase"},children:t.title}),e("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:t.items.map((a,l)=>i("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 12px",backgroundColor:o?n.cardBg:"#f9fafb",border:o?`1px solid ${n.cardBorder}`:"1px solid #e5e7eb",borderRadius:"8px"},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[a.tokenLogoURI?e("img",{src:a.tokenLogoURI,alt:a.tokenSymbol,style:{width:"20px",height:"20px",borderRadius:"50%"}}):e("div",{style:{width:"20px",height:"20px",borderRadius:"50%",backgroundColor:o?n.hoverBg:"#e5e7eb",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",fontWeight:600,color:o?n.textSecondary:"#6b7280"},children:a.tokenSymbol.charAt(0)}),i("div",{children:[e("div",{style:{fontSize:"13px",fontWeight:500,color:o?n.textPrimary:"#111827"},children:a.tokenSymbol}),e("div",{style:{fontSize:"11px",color:o?n.textSecondary:"#6b7280"},children:a.label})]})]}),e("div",{style:{fontSize:"13px",fontWeight:600,color:s(a.valueColor)},children:a.displayValue})]},l))})]})},Oa=({onDepositClick:t,onWithdrawClick:n,depositDisabled:o=!1,withdrawDisabled:s=!1,primaryColor:a="#EA4B4B",dark:l=!1})=>i("div",{style:{display:"flex",gap:"8px"},children:[e(Ge,{variant:"outline",onClick:t,disabled:o,dark:l,styles:{button:{backgroundColor:a}},style:{flex:1,height:"44px",fontSize:"12px"},children:"Deposit"}),e(Ge,{variant:"outline",onClick:n,disabled:s,dark:l,styles:{button:{backgroundColor:a}},style:{flex:1,height:"44px",fontSize:"12px"},children:"Withdraw"})]}),Va=({appName:t,status:n,statusLabel:o,totalUsdValue:s,breakdownSubtitle:a,address:l,spiceAssets:r,spiceAssetsLoading:c,pendingDeposits:d,customSections:u,onDepositClick:p,onWithdrawClick:f,onCompleteDeposit:m,primaryColor:g,dk:h,dark:C=!1,showModeToggle:y,isEmbeddedMode:S,onModeToggle:U})=>{const[b,x]=B(!1);return i("div",{style:{display:"flex",flexDirection:"column",gap:"16px",padding:"16px",maxHeight:"calc(80vh - 32px)",overflowY:"auto"},children:[e(Pa,{appName:t,status:n,statusLabel:o,totalUsdValue:s,breakdownSubtitle:a,address:l,dk:h,dark:C,showModeToggle:y,isEmbeddedMode:S,onModeToggle:U}),e("div",{style:{height:"1px",backgroundColor:C?"#2d2d2d":"#e5e7eb"}}),i("div",{children:[i("button",{onClick:()=>x(!b),style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",padding:"8px 12px",backgroundColor:C?h.cardBg:"#f9fafb",border:C?`1px solid ${h.cardBorder}`:"1px solid #e5e7eb",borderRadius:"8px",cursor:"pointer",color:C?h.textSecondary:"#6b7280",fontSize:"12px",fontWeight:500},children:[e("span",{children:"How It Works"}),e("span",{style:{transform:b?"rotate(180deg)":"rotate(0deg)",transition:"transform 200ms ease",fontSize:"10px"},children:"\u25BE"})]}),b&&i("div",{style:{marginTop:"6px",padding:"10px 12px",backgroundColor:C?h.cardBg:"#f0fdf4",border:C?`1px solid ${h.cardBorder}`:"1px solid #bbf7d0",borderRadius:"8px",fontSize:"12px",lineHeight:1.5,color:C?h.textSecondary:"#374151"},children:["Fund your ",t," Account from any supported chain (10+ EVM chains). Once funded, transact gas-free and asset-abstracted on"," ",t,"."]})]}),e(La,{pendingDeposits:d,onCompleteDeposit:m,dk:h,dark:C}),e(Ha,{spiceAssets:r,loading:c,dk:h,dark:C}),u.map((M,z)=>e(ja,{section:M,dk:h,dark:C},z)),e(Oa,{onDepositClick:p,onWithdrawClick:f,primaryColor:g,dark:C})]})},Wo=380,Tn=8,Qa=({appName:t="Spice",status:n="active",statusLabel:o,customSections:s=[],extraAssets:a=[],tokenPrices:l={},breakdownLabels:r=[],supportedChains:c,styles:d,dark:u=!1,onDepositSuccess:p,onDepositClick:f,onWithdrawClick:m,onCompleteDeposit:g,showModeToggle:h=!1,defaultMode:C})=>{const y=It(xt),S=y?.mode!=="7702";$(()=>{C&&y?.setMode&&y.setMode(C==="non7702"?"ondemand":"7702")},[]);const[U,b]=B(!1),[x,M]=B(null),[z,T]=B({top:0,left:0,placement:"below"}),I=Fe(null),F=Fe(null),{address:w,isConnected:W}=tn(),Z=en(),{address:D}=Yt(),{dark:A,primaryColor:E,dk:O}=je(d,u),V=Ce(()=>c||$n("mainnet"),[c]),{assets:P,loading:X}=Fn({address:w,supportedChains:V,enabled:!!w&&!S,refetchInterval:3e4}),se=Ce(()=>[...S?[]:P.map(L=>{const Se=L.balanceUsd||0,Ee=Number(L.balance)/Math.pow(10,L.decimals),te=Se>0?Se:(l[L.symbol]||0)*Ee;return{tokenAddress:L.address,tokenSymbol:L.symbol,tokenDecimals:L.decimals,chainId:L.chainId,balance:L.balance.toString(),balanceFormatted:L.balanceFormatted,usdValue:te,logoURI:L.logoURI}}),...a].filter(L=>L.usdValue>=.01),[S,P,l,a]),R=Ce(()=>se.reduce((L,Se)=>L+Se.usdValue,0),[se]),{pendingDeposits:H}=Or({chainIds:V,enabled:!!w}),q=Ce(()=>s.reduce((L,Se)=>L+Se.totalValue,0),[s]),me=R+q,we=Ce(()=>{const L=[];R>0&&L.push(`${Mn(R)} idle`);for(const Se of s){const Ee=r.find(te=>te.sectionTitle===Se.title)?.label||Se.title.toLowerCase();L.push(`${Mn(Se.totalValue)} ${Ee}`)}return L.join(" \xB7 ")},[R,s,r]),oe=ie(L=>{g?g(L):M(L)},[g]),ae=ie(()=>{M(null)},[]),de=ie(()=>{M(null),p?.()},[p]),Me=ie(()=>{if(!I.current)return;const L=I.current.getBoundingClientRect(),Se=window.innerHeight-L.bottom-Tn,Ee=L.top-Tn,te=Se>=400||Se>=Ee?"below":"above",ze=Math.max(Tn,Math.min(L.right-Wo,window.innerWidth-Wo-Tn)),Pe=te==="below"?L.bottom+Tn:L.top-Tn;T({top:Pe,left:ze,placement:te})},[]);Yr(()=>{U&&Me()},[U,Me]),$(()=>{if(!U)return;const L=te=>{I.current&&!I.current.contains(te.target)&&F.current&&!F.current.contains(te.target)&&b(!1)},Se=te=>{te.key==="Escape"&&b(!1)},Ee=()=>Me();return document.addEventListener("mousedown",L),document.addEventListener("keydown",Se),window.addEventListener("scroll",Ee,{passive:!0}),window.addEventListener("resize",Me),()=>{document.removeEventListener("mousedown",L),document.removeEventListener("keydown",Se),window.removeEventListener("scroll",Ee),window.removeEventListener("resize",Me)}},[U,Me]);const ye=y?.mode==="7702",We=ye?Z||w:D||w,ce=ie(()=>{y?.setMode&&y.setMode(ye?"ondemand":"7702")},[y,ye]);if(typeof window>"u")return null;const Ve=i("button",{ref:I,onClick:()=>b(!U),style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"8px 14px",borderRadius:"9999px",backgroundColor:A?O.hoverBg:"#ffffff",border:A?`1px solid ${O.cardBorder}`:"1px solid #e5e7eb",cursor:"pointer",fontSize:"13px",fontWeight:500,fontFamily:'"Helvetica Neue", sans-serif',color:A?O.textPrimary:"#111827",transition:"all 150ms ease",boxShadow:A?"none":"0 1px 2px rgba(0,0,0,0.05)"},children:[e("span",{style:{width:"8px",height:"8px",borderRadius:"50%",backgroundColor:E,flexShrink:0}}),i("span",{children:[t," Account"]}),W&&i("span",{style:{color:A?O.textSecondary:"#6b7280"},children:["\xB7 ",Mn(me)]}),e("span",{style:{fontSize:"10px",color:A?O.textSecondary:"#9ca3af",transform:U?"rotate(180deg)":"rotate(0deg)",transition:"transform 200ms ease"},children:"\u25BE"})]}),De=U?gs.createPortal(i(Qt,{children:[e("div",{style:{position:"fixed",inset:0,backgroundColor:"rgba(0, 0, 0, 0.08)",zIndex:9998},onClick:()=>b(!1)}),e("div",{ref:F,style:{position:"fixed",top:z.placement==="below"?`${z.top}px`:"auto",bottom:z.placement==="above"?`${window.innerHeight-z.top}px`:"auto",left:`${z.left}px`,width:`${Wo}px`,maxHeight:"80vh",backgroundColor:A?O.shell:"#ffffff",border:A?`1px solid ${O.cardBorder}`:"1px solid #e5e7eb",borderRadius:"12px",boxShadow:A?"0 10px 40px rgba(0, 0, 0, 0.5)":"0 10px 40px rgba(0, 0, 0, 0.12)",zIndex:9999,overflow:"hidden",animation:"accountDisplayFadeIn 150ms ease-out"},children:e(Va,{appName:t,status:n,statusLabel:o,totalUsdValue:me,breakdownSubtitle:we,address:h?We:w,spiceAssets:se,spiceAssetsLoading:X,pendingDeposits:H,customSections:s,onDepositClick:f,onWithdrawClick:m,onCompleteDeposit:oe,primaryColor:E,dk:O,dark:A,showModeToggle:h,isEmbeddedMode:ye,onModeToggle:ce})}),e("style",{children:`
114
+ `})]})},Ca=({color:t})=>i("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",style:{marginTop:"1px",flexShrink:0},children:[e("circle",{cx:"7",cy:"7",r:"6.5",stroke:t,strokeWidth:"1.2"}),e("path",{d:"M7 6v4",stroke:t,strokeWidth:"1.2",strokeLinecap:"round"}),e("circle",{cx:"7",cy:"4.5",r:"0.7",fill:t})]}),wa=({isOpen:t,onClose:n,lockBatches:o,lockTokenSymbol:s,lockTokenLogoURI:a,destinationInputHook:l,sourceAssetInputHook:r,lockDurationHook:c,lockChainId:d,durationOptions:u,votingPowerEstimate:p,sourceChains:f,sourceAssets:m=[],escrowAddress:g,includeWalletAssets:h=!1,destinationTokenAddress:C,onLockSuccess:y,onLockExecute:S,sourceToDestinationConversionRate:U,estimatedOutputAmount:b,onAddFunds:x,styles:M,dark:z=!1})=>{const{theme:T,dark:I,primaryColor:F,dk:w}=je(M,z),W=T.typography.fontFamily,Z=It(xt),D=(Z?.mode||"7702")!=="7702",A=I?w.cardBg:M?.assetSelector?.backgroundColor||M?.secondaryBackground||"#e9e9e9",E=I?`1px solid ${w.cardBorder}`:"0.5px solid #A8A8A7",O=I?"12px":"6px",V=I?w.textPrimary:"#111827",P=I?w.textSecondary:"#6b7280",X=Ce(()=>({...M,assetSelector:{...M?.assetSelector,backgroundColor:I?w.cardBg:M?.assetSelector?.backgroundColor,borderRadius:I?"12px":M?.assetSelector?.borderRadius},secondaryBackground:I?w.cardBg:M?.secondaryBackground}),[M,I]),se=Ce(()=>I?{...T,colors:{...T.colors,secondary:w.cardBg,surfaceHover:w.hoverBg,border:w.cardBorder,borderHover:w.inputBorder}}:T,[I,T]),[R,H]=B(null),[q,me]=B(0),we=c?.selectedDurationIdx??q,oe=c?.setSelectedDurationIdx??me,[ae,de]=B(!1),[Me,ye]=B(null),[We,ce]=B(!1),[Ve,De]=B(!1),[L,Se]=B(null);qn(),Bn();const{chain:Ee,address:te}=Yt();Vo();const ze=Fe(Ee);$(()=>{ze.current=Ee},[Ee]);const Pe=tn(),{isReady:Q,isAuthenticated:J,isConnected:v,address:k,provider:ee,actions:re}=Pe,{intentStatus:N,startStatusPolling:Y,clearStatus:le}=vo({checkStepStatus:(_,he)=>qe.checkStepStatus(_,he),retryStep:async(_,he)=>{const[tt,it]=_.split("/"),gt=parseInt(it||"0",10);await qe.executeStep(tt,gt,he,{action:"execute"})},maxRetries:3}),{assets:pe,refetch:ke}=Fn({address:k,supportedChains:f,enabled:v&&!D,refetchInterval:3e4}),pt=Ce(()=>{if(m.length===0)return pe;const _=new Set(m.map(he=>he.toLowerCase()));return pe.filter(he=>_.has(he.address.toLowerCase()))},[pe,m]),fe=en(),xe=D?te:fe,be=Ce(()=>{if(!h)return[];const _=new Set,he=[],tt=it=>{if(!it)return;const gt=it.toLowerCase();_.has(gt)||(_.add(gt),he.push(Et(it)))};if(C&&tt(C),D)for(const it of m)tt(it);return he},[h,D,C,m]),Xe=Ce(()=>be.map(_=>_.toLowerCase()).sort().join(","),[be]),kt=Ce(()=>JSON.stringify([...f||[]].sort()),[f]),[Ct,ut]=B([]),Ut=Fe(0),St=ie(async()=>{if(!h||!xe||be.length===0){Ut.current++,ut([]);return}const _=++Ut.current,he=Et(xe),tt=f&&f.length>0?f:[d],it=be.map(Te=>{const Ae=Te.toLowerCase();for(const lt of tt){const Ye=Ke(lt)?.supportedTokens?.find(Ze=>Ze.address.toLowerCase()===Ae);if(Ye)return{address:Te,chainId:lt,configToken:{decimals:Ye.decimals,symbol:Ye.symbol,name:Ye.name,logo:Ye.logo}}}return{address:Te,chainId:d}}),gt=new Map;for(const Te of it){const Ae=gt.get(Te.chainId)||[];Ae.push(Te),gt.set(Te.chainId,Ae)}const Ie=async(Te,Ae)=>{try{const lt=await vn(Te,{address:Ae.address,abi:bt,functionName:"balanceOf",args:[he]});let Ye,Ze,Be,He;if(Ae.configToken)Ye=Ae.configToken.decimals,Ze=Ae.configToken.symbol,Be=Ae.configToken.name,He=Ae.configToken.logo;else{const[Lt,j,G]=await Promise.all([vn(Te,{address:Ae.address,abi:bt,functionName:"decimals",args:[]}).catch(()=>18),vn(Te,{address:Ae.address,abi:bt,functionName:"symbol",args:[]}).catch(()=>"TOKEN"),vn(Te,{address:Ae.address,abi:bt,functionName:"name",args:[]}).catch(()=>"TOKEN")]);Ye=Number(Lt),Ze=j,Be=G}const $e=!!C&&Ae.address.toLowerCase()===C.toLowerCase()&&Ae.chainId===d;$e&&a&&(He=a),$e&&s&&!Ae.configToken&&(Ze==="TOKEN"&&(Ze=s),Be==="TOKEN"&&(Be=s));const Pt=parseFloat((Number(lt)/Math.pow(10,Ye)).toFixed(6));return{address:Ae.address,name:Be,symbol:Ze,decimals:Ye,balance:lt,balanceFormatted:Pt,balanceUsd:0,logoURI:He,isNative:!1,chainId:Ae.chainId}}catch{return null}},Re=await Promise.all(Array.from(gt.entries()).map(async([Te,Ae])=>{let lt;try{lt=ct(Te)}catch{return[]}const Ye=[],Ze=[];for(const He of Ae){const $e=Ye.length;Ye.push({address:He.address,abi:bt,functionName:"balanceOf",args:[he]}),He.configToken||Ye.push({address:He.address,abi:bt,functionName:"decimals",args:[]},{address:He.address,abi:bt,functionName:"symbol",args:[]},{address:He.address,abi:bt,functionName:"name",args:[]}),Ze.push({start:$e,item:He})}let Be=null;try{Be=await lt.multicall({contracts:Ye})}catch{Be=null}return Be?Ze.map(({start:He,item:$e})=>{const Pt=Be[He],Lt=Pt?.status==="success"?Pt.result:0n;let j,G,K,ne;if($e.configToken)j=$e.configToken.decimals,G=$e.configToken.symbol,K=$e.configToken.name,ne=$e.configToken.logo;else{const dt=Be[He+1],Ue=Be[He+2],nt=Be[He+3];j=dt?.status==="success"?Number(dt.result):18,G=Ue?.status==="success"?Ue.result:"TOKEN",K=nt?.status==="success"?nt.result:G}const Le=!!C&&$e.address.toLowerCase()===C.toLowerCase()&&$e.chainId===d;Le&&a&&(ne=a),Le&&s&&!$e.configToken&&(G==="TOKEN"&&(G=s),K==="TOKEN"&&(K=s));const wt=parseFloat((Number(Lt)/Math.pow(10,j)).toFixed(6));return{address:$e.address,name:K,symbol:G,decimals:j,balance:Lt,balanceFormatted:wt,balanceUsd:0,logoURI:ne,isNative:!1,chainId:$e.chainId}}):(await Promise.all(Ae.map(He=>Ie(lt,He)))).filter(He=>He!==null)}));_===Ut.current&&ut(Re.flat())},[h,xe,Xe,kt,d,C,a,s]);$(()=>{if(!h){ut([]);return}St();const _=setInterval(()=>{St()},15e3);return()=>clearInterval(_)},[St,h]);const st=ie(()=>{St()},[St]),Nt=Ce(()=>Ct.filter(_=>_.balance>0n),[Ct]),Zt=Ce(()=>{if(D)return Nt.map(he=>({...he,_source:"wallet"}));if(!h)return pt;const _=[];for(const he of Nt)_.push({...he,_source:"wallet"});for(const he of pt)_.push({...he,_source:"spice"});return _},[D,h,Nt,pt]),ue=Fe(null),ge=Fe(null);$(()=>{ge.current=R},[R]),$(()=>{t||(H(null),ye(null),de(!1),De(!1),Se(null),ce(!1),le())},[t,le]),$(()=>{l&&l.assetAmount!==(R?.amount||"")&&H(_=>_&&{..._,amount:l.assetAmount})},[l?.assetAmount]),$(()=>{r&&r.assetAmount!==(R?.amount||"")&&H(_=>_&&{..._,amount:r.assetAmount})},[r?.assetAmount]),$(()=>{if(N?.overallStatus==="success"&&N.intentId&&ue.current!==N.intentId&&k){const _=N.steps.find(he=>he.transactionHash);if(_?.transactionHash){ue.current=N.intentId;const he=ge.current;if(!he?.asset||!he.amount||he.asset._source==="wallet")return;const tt=_e(he.amount,he.asset.decimals);if(tt===0n)return;qe.submitSpiceDeposit({user:k,txHash:_.transactionHash,sender:k,tokenAddress:he.asset.address,chainId:he.asset.chainId??d,amount:tt.toString(),isDeposit:!1}).then(()=>ke()).catch(()=>{ue.current=null})}}},[N,k,d,ke]);const ve=parseFloat(R?.amount||"")||0,Je=Ce(()=>R?.asset?R.asset._source==="wallet"?R.asset.balanceFormatted??0:pt.find(_=>_.address.toLowerCase()===R.asset.address.toLowerCase()&&_.chainId===R.asset.chainId)?.balanceFormatted??0:0,[R?.asset,pt]),ht=ve>0&&ve>Je,et=c?.selectedDuration??u[we]??u[0],at=Ce(()=>!R?.asset||!C?!1:R.asset.address.toLowerCase()===C.toLowerCase()&&R.asset.chainId===d,[R?.asset,C,d]),Mt=Ce(()=>ve<=0?0:at?ve:!U||U<=0?0:ve/U,[ve,U,at]),nn=Ce(()=>Mt<=0?null:Mt.toLocaleString(void 0,{maximumFractionDigits:2}),[Mt]),on=p&&Mt>0&&et?p(Mt,et.months):void 0,hn=Ce(()=>ve<=0?"$0.00":at&&U?(ve*U).toLocaleString(void 0,{style:"currency",currency:"USD",maximumFractionDigits:2}):!U||U<=0?"$0.00":ve.toLocaleString(void 0,{style:"currency",currency:"USD",maximumFractionDigits:2}),[ve,U,at]),fn=Ce(()=>{if(!nn)return null;const _=parseFloat(nn.replace(/,/g,""));return at&&U?(_*U).toLocaleString(void 0,{maximumFractionDigits:2}):U?(_*U).toLocaleString(void 0,{maximumFractionDigits:2}):null},[nn,U,at]),kn=ie(_=>{H(he=>({asset:_,amount:he?.asset?.address===_.address&&he?.asset?.chainId===_.chainId&&he.amount||""})),ye(null),r?.setSelectedAsset&&r.setSelectedAsset({symbol:_.symbol,address:_.address,decimals:_.decimals,chainId:_.chainId})},[r?.setSelectedAsset]),qt=ie(_=>{H(he=>he&&{...he,amount:_}),ye(null),l&&l.setAssetAmount(_),r&&r.setAssetAmount(_)},[l,r]),Vt=ie(()=>{if(typeof o=="function"){if(!R?.asset||!R.amount)throw new Error("Select an asset and enter an amount");return o({asset:R.asset,amount:R.amount,amountWei:_e(R.amount,R.asset.decimals)})}return o},[o,R]),Gt=ie(async()=>{if(!v||!k)throw new Error("Please connect your wallet to continue");const _=Vt();if(_.length===0)throw new Error("No lock batches configured");if(!Q||!J)throw new Error(`Please authenticate with ${ee||"wallet provider"} to continue`);const he=[..._],tt=[...new Set(he.map(Be=>Be.chainId))],it=[];for(const Be of tt){const He=ct(Be),$e=En(Be),Pt=await Gn(k,He),Lt=await re.signAuthorization({contractAddress:$e,chainId:Be,nonce:Number(Pt)});it.push(Lt)}const gt=Jn(he),Ie=Math.floor(Date.now()/1e3)+60*10,Re=gt.map(Be=>Be.hash),Te=_n(eo([{type:"string"},{type:"uint256"},{type:"uint256"},{type:"bytes32[]"}],["ecdsa",0n,BigInt(Ie),Re])),Ae=await re.signMessage({raw:Te}),lt=typeof Ae=="string"?Ae:Ae.signature;if(!lt)throw new Error("Failed to sign intent authorization");const Ye={mode:"7702",signatureType:"ecdsa",signature:lt,nbf:0,exp:Ie,chainBatches:gt.map((Be,He)=>({hash:Be.hash,chainId:Be.chainId,tokenTransfers:he[He].tokenTransfers??[],calls:Be.calls}))},Ze=await qe.createAction({user:k,chainAuthorizations:it.map(Be=>({r:Be.r,s:Be.s,yParity:Be.yParity,address:Be.address,chainId:Number(Be.chainId),nonce:Number(Be.nonce)})),intents:[Ye]});if(Ze){const Be=Zn(he,vt),[He,$e]=Ze.intentIds[0].split("/"),Pt=parseInt($e||"0",10);Y(Ze.intentIds[0],Be);for(let Lt=0;Lt<he.length;Lt++)await ko(()=>qe.executeStep(He,Pt,Lt,{action:"execute"}))}},[Vt,Pe,Y]),rn=ie(async()=>{if(!R?.asset||!R.amount)throw new Error("Select an asset and enter an amount");if(!k||!fe)throw new Error("Embedded wallet not connected");const _=R.asset,he=_e(R.amount,_.decimals),tt=g||En(d),it=await re.getEthereumProvider();await it.request({method:"wallet_switchEthereumChain",params:[{chainId:`0x${d.toString(16)}`}]});const gt=Ke(d),Ie=zn({account:fe,transport:Un(it),chain:gt?.viemChain});let Re;if(_.isNative||rt(_.address))Re=await Ie.sendTransaction({to:tt,value:he,chain:gt?.viemChain});else{const Te=Wt({abi:bt,functionName:"transfer",args:[tt,he]});Re=await Ie.sendTransaction({to:_.address,data:Te,chain:gt?.viemChain})}if((await ct(d).waitForTransactionReceipt({hash:Re,timeout:12e4,pollingInterval:2e3,confirmations:1})).status!=="success")throw new Error("Transfer to escrow failed");await ko(()=>qe.submitSpiceDeposit({txHash:Re,sender:fe,tokenAddress:_.address,chainId:d,amount:he.toString(),user:fe,isDeposit:!0})),await ke(),st(),await Gt()},[R,k,fe,re,g,d,Gt,ke,st]),Bt=ie(async()=>{if(!R?.asset||!R.amount)throw new Error("Select an asset and enter an amount");if(!te)throw new Error("Please connect your wallet to continue");if(!S)throw new Error("onLockExecute callback is required for non-7702 mode");const _=Vt();if(_.length===0)throw new Error("No lock batches configured");const he=R.asset,tt=_e(R.amount,he.decimals),it=await S({asset:he,amount:R.amount,amountWei:tt,lockDurationMonths:et?.months??0,chainBatches:_});it&&y?.(it)},[R,te,S,Vt,et,y]);$(()=>{if(N?.overallStatus==="success"){const _=N.steps.find(he=>he.transactionHash);y?.(_?.transactionHash)}},[N?.overallStatus,y]);const sn=h&&R?.asset?._source==="wallet"&&R?.asset?.chainId===d,an=ie(async()=>{if(!R?.asset||ve<=0){ye("Select an asset and enter an amount");return}if(ht){ye("Insufficient balance. Add more assets.");return}if(de(!0),ye(null),D){try{await Bt()}catch(_){ye(Ot(_,"Transaction failed. Please try again."))}finally{de(!1)}return}ce(!0);try{sn&&!at?await rn():await Gt()}catch(_){ye(Ot(_,"Transaction failed. Please try again."))}finally{de(!1)}},[R,ve,ht,D,Bt,sn,at,rn,Gt]),gn=!!R?.asset&&ve>0&&!ht&&!ae,Jt=i("div",{style:{display:"flex",alignItems:"flex-start",gap:"6px"},children:[e(Ca,{color:P}),i("p",{style:{fontSize:"13px",color:P,margin:0,lineHeight:"1.5"},children:["Add ",s," by converting assets from your account"]})]});if(!t)return null;const mn={backgroundColor:A,border:E,borderRadius:O,padding:"16px",marginBottom:"16px"};return e(Dt,{isOpen:t,onClose:n,title:`Add ${s} to your account`,subtitle:Jt,styles:M,dark:I,footerLinkText:"Spicenet accounts \u2192",overlayContent:Ve?e("div",{}):void 0,children:i("div",{style:{padding:"0 24px 8px 24px",position:"relative"},children:[i("div",{style:{marginBottom:"12px"},children:[x&&e("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:"6px"},children:i("button",{onClick:x,style:{background:"none",border:"none",cursor:"pointer",padding:0,display:"flex",alignItems:"center",gap:"4px",color:F,fontSize:"12px",fontWeight:500,fontFamily:W,textDecoration:"underline",textUnderlineOffset:"2px"},children:["Add Funds",i("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:F,strokeWidth:"1.8",children:[e("circle",{cx:"6",cy:"6",r:"5"}),e("path",{d:"M6 4v4M4 6h4",strokeLinecap:"round"})]})]})}),e(Rn,{assets:Zt,selectedAsset:R??void 0,onAssetSelect:kn,onAmountChange:qt,label:"Amount",showBalance:!0,showMaxButton:!0,theme:se,styles:X}),e("div",{style:{marginTop:"6px",paddingLeft:"4px",fontSize:"13px",color:P,fontFamily:W},children:hn})]}),i("div",{style:mn,children:[i("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",paddingBottom:"16px",borderBottom:I?`1px solid ${w.cardBorder}`:"1px solid #e5e7eb"},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[a?e("img",{src:a,alt:s,style:{width:"32px",height:"32px",borderRadius:"50%",objectFit:"cover"}}):e("div",{style:{width:"32px",height:"32px",borderRadius:"50%",backgroundColor:I?w.inputBg:"#d1d5db",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"12px",fontWeight:700,color:V},children:s.slice(0,2)}),e("span",{style:{fontSize:"16px",fontWeight:600,color:V,fontFamily:W},children:s})]}),i("div",{style:{textAlign:"right"},children:[e("div",{style:{fontSize:"22px",fontWeight:700,color:V,fontFamily:W,lineHeight:1.1},children:nn??"0.00"}),i("div",{style:{fontSize:"12px",color:P,fontFamily:W,marginTop:"2px"},children:["~$",fn??"0.00"]})]})]}),i("div",{style:{paddingTop:"16px",paddingBottom:"16px",borderBottom:I?`1px solid ${w.cardBorder}`:"1px solid #e5e7eb"},children:[i("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},children:[e("span",{style:{fontSize:"15px",fontWeight:500,color:P,fontFamily:W},children:"Lock Duration"}),e("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:e("path",{d:"M4 6L8 10L12 6",stroke:P,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})]}),e(ga,{options:u,selectedIndex:we,onSelect:oe,primaryColor:F,dark:I,textPrimary:V,textSecondary:P})]}),i("div",{style:{paddingTop:"12px",display:"flex",flexDirection:"column",gap:"8px"},children:[e(ya,{durationMonths:et?.months,fontFamily:W,dark:I,textPrimary:V,textSecondary:P}),p&&e(xa,{votes:on,fontFamily:W,dark:I,textPrimary:V,textSecondary:P})]})]}),Me&&e("div",{style:{marginBottom:"12px",padding:"10px 14px",backgroundColor:I?"rgba(239,68,68,0.12)":"#fef2f2",border:`1px solid ${I?"rgba(239,68,68,0.3)":"#fecaca"}`,borderRadius:"6px"},children:e("p",{style:{color:"#ef4444",fontSize:"13px",margin:0,fontFamily:W},children:Me})}),e(Ge,{variant:"outline",fullWidth:!0,onClick:an,disabled:!gn,loading:ae,dark:I,styles:{button:{backgroundColor:F}},children:ae?sn&&!at?"DEPOSITING...":at?"LOCKING...":"CONVERTING...":sn&&!at?`DEPOSIT ${s}`:at?`LOCK ${s}`:`CONVERT TO ${s}`}),e(ba,{isOpen:Ve,data:L,isLocking:ae,lockError:Me,onContinue:an,onClose:()=>De(!1),primaryColor:F,fontFamily:W,dark:I}),N&&We&&e("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:10,backgroundColor:I?w.shell:"white",borderRadius:O,padding:"16px 0"},children:e(Ln,{type:"deposit",isOpen:!!N&&N.overallStatus!=="processing",isProcessing:ae||N?.overallStatus==="processing",closeOnComplete:!1,onRetryTx:()=>{le(),ce(!1),an()},onNewTx:()=>{le(),ce(!1),H(null),ue.current=null,ke(),st()},onClose:()=>{le(),ce(!1)},onComplete:()=>{le(),ce(!1),H(null),ue.current=null,ke(),st()},results:N?.overallStatus==="success"||N?.overallStatus==="failed"?N.steps.map(_=>({asset:{symbol:R?.asset?.symbol||s,address:R?.asset?.address||""},txHash:_.transactionHash||"",success:_.status==="success",amount:R?.amount})):void 0,chainName:vt(d),explorerUrl:Cn(d,"").replace(/\/tx\/.*$/,"")||void 0,theme:T,styles:M,dark:I})})]})})},vr=({variant:t,destinationSymbol:n,destinationLogoURI:o,destinationDecimals:s,primaryColor:a,fontFamily:l,textPrimary:r,textSecondary:c,cardBg:d,cardBorder:u,dk:p,dark:f,isQuoting:m,quoteError:g,estimatedOutput:h,paymentAmount:C,needsSwap:y,exactOutputSwap:S,adjustable:U=!1,maxAmount:b,onAmountChange:x})=>t==="supply"?e("div",{style:{backgroundColor:d,border:`1px solid ${u}`,borderRadius:"12px",padding:"14px 16px",marginBottom:"16px"},children:i("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[e(kr,{symbol:n,logoURI:o,primaryColor:a,size:28}),i("span",{style:{fontSize:"13px",fontWeight:500,color:c,fontFamily:l},children:["Estimated ",n]})]}),e("div",{style:{textAlign:"right"},children:m?e("span",{style:{fontSize:"14px",color:c,fontFamily:l},children:"Quoting..."}):g?e("span",{style:{fontSize:"13px",color:"#ef4444",fontFamily:l},children:"Quote failed"}):h?i("span",{style:{fontSize:"16px",fontWeight:600,color:r,fontFamily:l},children:["\u2248 ",h]}):e("span",{style:{fontSize:"14px",color:c,fontFamily:l},children:"\u2014"})})]})}):e(va,{destinationSymbol:n,destinationLogoURI:o,destinationDecimals:s,primaryColor:a,fontFamily:l,textPrimary:r,textSecondary:c,cardBg:d,cardBorder:u,dk:p,dark:f,paymentAmount:C||"0",needsSwap:y,exactOutputSwap:S,isQuoting:m,adjustable:U,maxAmount:b,onAmountChange:x}),kr=({symbol:t,logoURI:n,primaryColor:o,size:s})=>n?e("img",{src:n,alt:t,style:{width:s,height:s,borderRadius:"50%",objectFit:"cover"}}):e("div",{style:{width:s,height:s,borderRadius:"50%",backgroundColor:`${o}22`,display:"flex",alignItems:"center",justifyContent:"center",fontSize:s<30?"11px":"12px",fontWeight:700,color:o},children:t.slice(0,2)}),va=({destinationSymbol:t,destinationLogoURI:n,destinationDecimals:o,primaryColor:s,fontFamily:a,textPrimary:l,textSecondary:r,cardBg:c,cardBorder:d,dk:u,dark:p,paymentAmount:f,needsSwap:m,exactOutputSwap:g,isQuoting:h,adjustable:C,maxAmount:y,onAmountChange:S})=>{const U='"IBM Plex Mono", monospace',b=parseFloat(f||"0"),x=y?parseFloat(y):0,[M,z]=B(f||""),T=Fe(null),[I,F]=B(null),[w,W]=B(null);$(()=>{C||z(f||"")},[f,C]);const Z=E=>{let O=E;O.startsWith(".")&&(O="0"+O);const V=Jo(O);let P=V;y&&parseFloat(V)>parseFloat(y)&&(P=y),z(P),T.current&&clearTimeout(T.current),T.current=setTimeout(()=>S?.(P),300)},D=E=>{if(!x)return;if(E===100){z(y||x.toString()),T.current&&clearTimeout(T.current),S?.(y||x.toString());return}const O=10**o,V=(Math.floor(x*E/100*O)/O).toString();z(V),T.current&&clearTimeout(T.current),S?.(V)},A=x>0?parseFloat(M||"0")/x*100:0;return $(()=>()=>{T.current&&clearTimeout(T.current)},[]),i("div",{style:{backgroundColor:c,border:`1px solid ${d}`,borderRadius:p?"12px":"6px",padding:"16px",marginBottom:"16px"},children:[i("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[e(kr,{symbol:t,logoURI:n,primaryColor:s,size:32}),i("div",{children:[e("span",{style:{fontSize:"14px",fontWeight:600,color:l,fontFamily:a},children:"Payment"}),e("div",{style:{fontSize:"12px",color:r,fontFamily:a,marginTop:"2px"},children:t})]})]}),i("div",{style:{textAlign:"right"},children:[C?e("input",{type:"text",value:M,onChange:E=>Z(E.target.value),placeholder:"0.0",style:{fontSize:"20px",fontWeight:700,color:l,fontFamily:U,lineHeight:1.1,backgroundColor:"transparent",border:"none",outline:"none",padding:0,width:"120px",textAlign:"right"}}):e("div",{style:{fontSize:"20px",fontWeight:700,color:l,fontFamily:U,lineHeight:1.1},children:b>0?f:"0.00"}),e("div",{style:{fontSize:"12px",color:r,fontFamily:U,marginTop:"2px"},children:t}),C&&x>0&&e("div",{style:{display:"flex",justifyContent:"flex-end",alignItems:"center",gap:"10px",marginTop:"6px"},children:[0,25,50,75,100].map((E,O)=>{const V=Math.abs(A-E)<1,P=O===4,X=E/100,se=I===E,R=w===E;return e("button",{onClick:()=>D(E),onMouseEnter:()=>F(E),onMouseLeave:()=>{F(null),W(null)},onMouseDown:()=>W(E),onMouseUp:()=>W(null),title:`${E}%`,style:{width:"14px",height:"14px",padding:0,border:"none",backgroundColor:"transparent",cursor:"pointer",opacity:V?1:se?.8:.5,transform:R?"scale(0.85)":se?"scale(1.15)":"scale(1)",transition:"all 0.15s ease"},children:i("svg",{width:"14",height:"14",viewBox:"0 0 14 14",children:[e("circle",{cx:"7",cy:"7",r:"6.84375",fill:P?s:"none",stroke:P?s:p?"#4a5568":"#3C3E42",strokeWidth:"0.3125"}),!P&&X>0&&e("path",{d:`M 7 7 L 7 0.15625 A 6.84375 6.84375 0 ${X>.5?1:0} 1 ${7+6.84375*Math.sin(X*2*Math.PI)} ${7-6.84375*Math.cos(X*2*Math.PI)} Z`,fill:p?u?.textSecondary||"#9ca3af":"#3C3E42"})]})},E)})})]})]}),m&&g&&!h&&e("div",{style:{marginTop:"12px",paddingTop:"12px",borderTop:p?`1px solid ${u?.cardBorder||d}`:"1px solid #e5e7eb",display:"flex",justifyContent:"flex-end"},children:i("span",{style:{fontSize:"11px",color:r,fontFamily:a,opacity:.7},children:["via ",g.venue]})})]})};function Ir(t,n,o){const s=t.address.toLowerCase()===n,a=t.chainId===o,l=t._source==="wallet";return l&&s&&a?0:l&&a?1:!l&&s?2:!l&&a?3:4}function ka(t){const{address:n,destinationToken:o,supportedSourceAssets:s,sourceChains:a,enabled:l}=t,r=en(),{assets:c,refetch:d}=Fn({address:n,supportedChains:a,enabled:l,refetchInterval:3e4}),u=Ce(()=>{if(!s||s.length===0)return c;const g=s.map(h=>h.toLowerCase());return c.filter(h=>g.includes(h.address.toLowerCase()))},[c,s]),[p,f]=B(null);$(()=>{if(!o.address||!r||!l){f(null);return}let g=!1;const h=Et(o.address),C=Et(r),y=ct(o.chainId),S=async()=>{try{const b=await y.multicall({contracts:[{address:h,abi:At,functionName:"balanceOf",args:[C]},{address:h,abi:At,functionName:"decimals",args:[]},{address:h,abi:At,functionName:"symbol",args:[]},{address:h,abi:At,functionName:"name",args:[]}]});if(g)return;const x=b[0].status==="success"?b[0].result:0n,M=b[1].status==="success"?Number(b[1].result):o.decimals,z=b[2].status==="success"?b[2].result:o.symbol,T=b[3].status==="success"?b[3].result:o.symbol;x>0n?f({address:h,name:T,symbol:z,decimals:M,balance:x,balanceFormatted:parseFloat((Number(x)/Math.pow(10,M)).toFixed(6)),balanceUsd:0,logoURI:o.logoURI,isNative:!1,chainId:o.chainId}):f(null)}catch{g||f(null)}};S();const U=setInterval(S,15e3);return()=>{g=!0,clearInterval(U)}},[o.address,o.chainId,o.decimals,o.symbol,o.logoURI,r,l]);const m=ie(()=>{if(!o.address||!r)return;const g=ct(o.chainId),h=Et(o.address),C=Et(r);g.multicall({contracts:[{address:h,abi:At,functionName:"balanceOf",args:[C]},{address:h,abi:At,functionName:"decimals",args:[]}]}).then(y=>{const S=y[0].status==="success"?y[0].result:0n,U=y[1].status==="success"?Number(y[1].result):18;S>0n?f(b=>b?{...b,balance:S,balanceFormatted:parseFloat((Number(S)/Math.pow(10,U)).toFixed(6))}:null):f(null)}).catch(()=>{})},[o.address,o.chainId,r]);return{displayAssets:Ce(()=>{const g=[];p&&g.push({...p,_source:"wallet"});for(const C of u)g.push({...C,_source:"spice"});const h=o.address.toLowerCase();return g.sort((C,y)=>Ir(C,h,o.chainId)-Ir(y,h,o.chainId)),g},[p,u,o.address,o.chainId]),filteredSpiceAssets:u,embeddedWalletAddress:r,refreshSpiceAssets:d,refreshWalletAssets:m}}function jn(t){const n=new Set(Qo(t).map(o=>o.toLowerCase()));return n.add(t.toLowerCase()),n}const Ia=["USDC","USDT","WETH","WBTC"];function Mo(t,n){const o=Ke(n);if(!o)return;if(o.nativeCurrency.symbol.toUpperCase()===t.toUpperCase())return{address:Kt,symbol:o.nativeCurrency.symbol,decimals:o.nativeCurrency.decimals,chainId:n};const s=o.supportedTokens?.find(a=>a.symbol.toUpperCase()===t.toUpperCase());if(s)return{address:s.address.toLowerCase(),symbol:s.symbol,decimals:s.decimals,chainId:n}}function yn(t,n){const o=Ke(n);if(!o)return;const s=jn(t);if([...s].some(l=>rt(l)))return{address:Kt,symbol:o.nativeCurrency.symbol,decimals:o.nativeCurrency.decimals,chainId:n};const a=o.supportedTokens?.find(l=>s.has(l.address.toLowerCase()));if(a)return{address:a.address.toLowerCase(),symbol:a.symbol,decimals:a.decimals,chainId:n}}function Sr(t){const{sourceAsset:n,outputAsset:o,sourceChainId:s,destinationChainId:a,intermediaryCandidates:l=Ia}=t,r=jn(n.address);if(r.has(o.address.toLowerCase()))return{strategy:"direct",sourceAsset:n,outputAsset:o,sourceChainId:s,destinationChainId:a,summary:`${n.symbol} fronted directly`};if(yn(n.address,a))return{strategy:"direct",sourceAsset:n,outputAsset:o,sourceChainId:s,destinationChainId:a,summary:`${n.symbol} fronted on destination, swapped to ${o.symbol}`};if(yn(o.address,s))return{strategy:"source-swap",sourceAsset:n,outputAsset:o,sourceChainId:s,destinationChainId:a,summary:`${n.symbol} \u2192 ${o.symbol} on source chain, then fronted`};const c=jn(o.address);for(const d of l){const u=Mo(d,s);if(!u||r.has(u.address.toLowerCase())||c.has(u.address.toLowerCase()))continue;const p=Mo(d,a);if(!(!p||!jn(u.address).has(p.address.toLowerCase())))return{strategy:"intermediary",sourceAsset:n,outputAsset:o,intermediaryAsset:p,sourceChainId:s,destinationChainId:a,summary:`${n.symbol} \u2192 ${d} on source, fronted, then ${d} \u2192 ${o.symbol} on destination`}}throw new Oe("ROUTE_STRATEGY_ERROR",`No viable cross-chain route found from ${n.symbol} (chain ${s}) to ${o.symbol} (chain ${a}). No intermediary asset is available on both chains.`,{sourceAsset:n.symbol,outputAsset:o.symbol,sourceChainId:s,destinationChainId:a,candidatesChecked:l})}async function Ar(t){const{route:n,sourceAmount:o,userAddress:s,registry:a,actionCalls:l,slippage:r}=t;async function c(d,u,p,f){const m=a.getVenueForChain(d);if(!m)throw new Oe("NO_VENUE_FOR_CHAIN",`No liquidity venue configured for chain ${d}. Cannot resolve swap ${u} \u2192 ${p}.`,{chainId:d,tokenIn:u,tokenOut:p,amountIn:f.toString()});const g=await m.resolve({type:"swap",tokenIn:u,tokenOut:p,amountIn:f,maxSlippage:r},d,s);if(!g)throw new Oe("NO_LIQUIDITY",`${m.name} returned no quote for ${u} \u2192 ${p} on chain ${d}. No liquidity available for this pair.`,{venue:m.name,chainId:d,tokenIn:u,tokenOut:p,amountIn:f.toString()});return g}switch(n.strategy){case"direct":{const d=yn(n.sourceAsset.address,n.destinationChainId)||n.sourceAsset;if(jn(d.address).has(n.outputAsset.address.toLowerCase()))return{chainBatches:[{chainId:n.destinationChainId,calls:l}],solverFrontToken:d,solverFrontAmount:o,resolvedSwaps:{}};const u=await c(n.destinationChainId,d.address,n.outputAsset.address,o);return{chainBatches:[{chainId:n.destinationChainId,calls:[...u.calls,...l]}],solverFrontToken:d,solverFrontAmount:o,resolvedSwaps:{destinationSwap:u}}}case"source-swap":{const d=yn(n.outputAsset.address,n.sourceChainId);if(!d)throw new Oe("ROUTE_TOKEN_NOT_FOUND",`Output asset ${n.outputAsset.symbol} (${n.outputAsset.address}) not found on source chain ${n.sourceChainId}`,{token:n.outputAsset.symbol,address:n.outputAsset.address,chainId:n.sourceChainId,side:"source"});const u=yn(n.outputAsset.address,n.destinationChainId);if(!u)throw new Oe("ROUTE_TOKEN_NOT_FOUND",`Output asset ${n.outputAsset.symbol} (${n.outputAsset.address}) not found on destination chain ${n.destinationChainId}`,{token:n.outputAsset.symbol,address:n.outputAsset.address,chainId:n.destinationChainId,side:"destination"});const p=await c(n.sourceChainId,n.sourceAsset.address,d.address,o);return{chainBatches:[{chainId:n.sourceChainId,calls:p.calls},{chainId:n.destinationChainId,calls:l}],solverFrontToken:u,solverFrontAmount:p.amountOutMinimum,resolvedSwaps:{sourceSwap:p}}}case"intermediary":{if(!n.intermediaryAsset)throw new Oe("ROUTE_STRATEGY_ERROR","Intermediary strategy requires an intermediary asset but none was provided in the route plan.",{strategy:n.strategy});const d=yn(n.intermediaryAsset.address,n.sourceChainId);if(!d)throw new Oe("ROUTE_TOKEN_NOT_FOUND",`Intermediary ${n.intermediaryAsset.symbol} (${n.intermediaryAsset.address}) not found on source chain ${n.sourceChainId}`,{token:n.intermediaryAsset.symbol,address:n.intermediaryAsset.address,chainId:n.sourceChainId,side:"source"});const u=await c(n.sourceChainId,n.sourceAsset.address,d.address,o),p=await c(n.destinationChainId,n.intermediaryAsset.address,n.outputAsset.address,u.amountOutMinimum);return{chainBatches:[{chainId:n.sourceChainId,calls:u.calls},{chainId:n.destinationChainId,calls:[...p.calls,...l]}],solverFrontToken:n.intermediaryAsset,solverFrontAmount:u.amountOutMinimum,resolvedSwaps:{sourceSwap:u,destinationSwap:p}}}default:throw new Oe("ROUTE_STRATEGY_ERROR",`Unknown route strategy: ${n.strategy}`,{strategy:n.strategy})}}async function Er(t){const{tokenIn:n,tokenOut:o,amountIn:s,fee:a,chainId:l,config:r}=t;if(s<=0n)throw new Error("amountIn must be greater than 0");const c=(await ct(l).simulateContract({address:r.quoterV2,abi:ts,functionName:"quoteExactInputSingle",args:[{tokenIn:n,tokenOut:o,amountIn:s,fee:a,sqrtPriceLimitX96:0n}]})).result;if(c[0]<=0n)throw new Error("No liquidity found for this pair. The pool returned 0 output.");return{amountOut:c[0],sqrtPriceX96After:c[1],gasEstimate:c[3]}}async function Br(t){const n=t.feeTiers??[100,500,3e3,1e4],o=await Promise.allSettled(n.map(a=>Er({...t,fee:a})));let s=null;for(let a=0;a<o.length;a++){const l=o[a];l.status==="fulfilled"&&(!s||l.value.amountOut>s.amountOut)&&(s={...l.value,fee:n[a]})}if(!s)throw new Error("No liquidity found for this pair on any fee tier.");return s}const Sa=[{inputs:[{components:[{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"amount",type:"uint256"},{name:"fee",type:"uint24"},{name:"sqrtPriceLimitX96",type:"uint160"}],name:"params",type:"tuple"}],name:"quoteExactOutputSingle",outputs:[{name:"amountIn",type:"uint256"},{name:"sqrtPriceX96After",type:"uint160"},{name:"initializedTicksCrossed",type:"uint32"},{name:"gasEstimate",type:"uint256"}],stateMutability:"nonpayable",type:"function"}];async function Aa(t){const{tokenIn:n,tokenOut:o,amountOut:s,fee:a,chainId:l,config:r}=t;if(s<=0n)throw new Error("amountOut must be greater than 0");const c=(await ct(l).simulateContract({address:r.quoterV2,abi:Sa,functionName:"quoteExactOutputSingle",args:[{tokenIn:n,tokenOut:o,amount:s,fee:a,sqrtPriceLimitX96:0n}]})).result;if(c[0]<=0n)throw new Error("No liquidity found for this pair. The pool returned 0 input.");return{amountIn:c[0],sqrtPriceX96After:c[1],gasEstimate:c[3]}}async function Ea(t){const n=t.feeTiers??[100,500,3e3,1e4],o=await Promise.allSettled(n.map(a=>Aa({...t,fee:a})));let s=null;for(let a=0;a<o.length;a++){const l=o[a];l.status==="fulfilled"&&(!s||l.value.amountIn<s.amountIn)&&(s={...l.value,fee:n[a]})}if(!s)throw new Error("No liquidity found for this pair on any fee tier.");return s}function Fr(t){return t.type==="swap"}const Ro=.02,Ba=[1,8453,42161,10,137,43114,56],Fa="https://api.1inch.dev/swap/v6.0";function Mr(t,n){return os(t,n)}function Rr(t){const n=t?.baseUrl??Fa;return{name:"1inch",chainIds:t?.chainIds??Ba,resolve:async(o,s,a)=>{const l=o.maxSlippage??Ro,r=l*100,c=rt(o.tokenIn)?Yo:o.tokenIn,d=rt(o.tokenOut)?Yo:o.tokenOut,u=rt(o.tokenIn);try{const p=new URL(`${n}/${s}/swap`);p.searchParams.set("src",c),p.searchParams.set("dst",d),p.searchParams.set("amount",o.amountIn.toString()),p.searchParams.set("from",a),p.searchParams.set("slippage",r.toString()),p.searchParams.set("disableEstimate","true"),p.searchParams.set("allowPartialFill","false");const f={Accept:"application/json"};t?.apiKey&&(f.Authorization=`Bearer ${t.apiKey}`);const m=await fetch(p.toString(),{headers:f});if(!m.ok)throw new Oe("VENUE_API_ERROR",`[1inchVenue] API returned ${m.status} for ${o.tokenIn} \u2192 ${o.tokenOut} on chain ${s}`,{venue:"1inch",chainId:s,tokenIn:o.tokenIn,tokenOut:o.tokenOut,amountIn:o.amountIn.toString(),cause:`HTTP ${m.status}`});const g=await m.json();if(!g.dstAmount||!g.tx)return console.warn(`[1inchVenue] No route data for ${o.tokenIn} \u2192 ${o.tokenOut} on chain ${s}`),null;const h=BigInt(g.dstAmount);if(h<=0n)return console.warn(`[1inchVenue] Zero output for ${o.tokenIn} \u2192 ${o.tokenOut} on chain ${s}`),null;const C=Mr(h,l),y=[];return g.tx.to&&!u&&y.push({to:o.tokenIn,value:0n,data:Wt({abi:At,functionName:"approve",args:[g.tx.to,o.amountIn]})}),y.push({to:g.tx.to,value:BigInt(g.tx.value||"0"),data:g.tx.data}),{venue:"1inch",amountOut:h,amountOutMinimum:C,calls:y}}catch(p){if(p instanceof Oe)throw p;const f=p instanceof Error?p.message:String(p);throw new Oe("VENUE_API_ERROR",`[1inchVenue] Exception for ${o.tokenIn} \u2192 ${o.tokenOut} on chain ${s}: ${f}`,{venue:"1inch",chainId:s,tokenIn:o.tokenIn,tokenOut:o.tokenOut,amountIn:o.amountIn.toString(),cause:f})}}}}const Tr=[4114,5115],To={swapRouter:"0x565eD3D57fe40f78A46f348C220121AE093c3cF8",quoterV2:"0x428f20dd8926Eabe19653815Ed0BE7D6c36f8425"},Wr={swapRouter:"0x2626664c2603336E57B271c5C0b26F421741e481",quoterV2:"0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a",chainIds:[8453]};function Dr(t){return{name:"satsuma",chainIds:t.chainIds??Tr,resolve:async(n,o,s)=>{const a=n.maxSlippage??Ro,l=rt(n.tokenIn);let r;try{r=await Br({tokenIn:n.tokenIn,tokenOut:n.tokenOut,amountIn:n.amountIn,chainId:o,config:{swapRouter:t.swapRouter,quoterV2:t.quoterV2},feeTiers:t.feeTiers})}catch{return console.warn(`[SatsumaVenue] No viable fee tier for ${n.tokenIn} \u2192 ${n.tokenOut} on chain ${o}.`),null}const c=Mr(r.amountOut,a),d=[];return l||d.push({to:n.tokenIn,value:0n,data:Wt({abi:At,functionName:"approve",args:[t.swapRouter,n.amountIn]})}),d.push({to:t.swapRouter,value:l?n.amountIn:0n,data:Wt({abi:ns,functionName:"exactInputSingle",args:[{tokenIn:n.tokenIn,tokenOut:n.tokenOut,fee:r.fee,recipient:s,amountIn:n.amountIn,amountOutMinimum:c,sqrtPriceLimitX96:0n}]})}),{venue:"satsuma",amountOut:r.amountOut,amountOutMinimum:c,calls:d}}}}function zr(t){return{name:"satsuma",chainIds:t.chainIds??Tr,resolve:async(n,o,s)=>{const a=n.maxSlippage??Ro,l=rt(n.tokenIn);let r;try{r=await Ea({tokenIn:n.tokenIn,tokenOut:n.tokenOut,amountOut:n.amountOut,chainId:o,config:{swapRouter:t.swapRouter,quoterV2:t.quoterV2},feeTiers:t.feeTiers})}catch{return null}const c=BigInt(Math.round(a*1e4)),d=r.amountIn+r.amountIn*c/10000n,u=[];return u.push({to:t.swapRouter,value:l?d:0n,data:Wt({abi:Ma,functionName:"exactOutputSingle",args:[{tokenIn:n.tokenIn,tokenOut:n.tokenOut,fee:r.fee,recipient:s,amountOut:n.amountOut,amountInMaximum:d,sqrtPriceLimitX96:0n}]})}),{venue:"satsuma",amountIn:r.amountIn,amountInMax:d,amountOut:n.amountOut,calls:u}}}}const Ma=[{inputs:[{components:[{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"fee",type:"uint24"},{name:"recipient",type:"address"},{name:"amountOut",type:"uint256"},{name:"amountInMaximum",type:"uint256"},{name:"sqrtPriceLimitX96",type:"uint160"}],name:"params",type:"tuple"}],name:"exactOutputSingle",outputs:[{name:"amountIn",type:"uint256"}],stateMutability:"payable",type:"function"}];function Ur(t){const n=[];t?.customVenues&&n.push(...t.customVenues),t?.satsuma&&n.push(Dr(t.satsuma)),n.push(Rr(t?.oneInch));function o(a){return n.find(l=>l.chainIds.includes(a))}async function s(a,l,r){const c=[],d=[];for(const u of a){if(!Fr(u)){c.push(u);continue}const p=o(l);if(!p)throw new Oe("NO_VENUE_FOR_CHAIN",`No liquidity venue configured for chain ${l}. Cannot resolve swap ${u.tokenIn} \u2192 ${u.tokenOut}.`,{chainId:l,tokenIn:u.tokenIn,tokenOut:u.tokenOut,amountIn:u.amountIn.toString()});const f=await p.resolve(u,l,r);if(!f)throw new Oe("NO_LIQUIDITY",`${p.name} returned no quote for ${u.tokenIn} \u2192 ${u.tokenOut} on chain ${l}.`,{venue:p.name,chainId:l,tokenIn:u.tokenIn,tokenOut:u.tokenOut,amountIn:u.amountIn.toString()});c.push(...f.calls),d.push(f)}return{calls:c,resolvedSwaps:d}}return{resolveSwapIntents:s,getVenueForChain:o,venues:n}}function Ra(t){const n=t?.customVenues??[];async function o(s,a,l){const r=n.filter(d=>d.chainIds.includes(a));if(r.length===0)throw new Oe("NO_SWAP_ROUTE",`No exact-output venue supports chain ${a}`,{chainId:a,tokenIn:s.tokenIn,tokenOut:s.tokenOut});const c=(await Promise.allSettled(r.map(d=>d.resolve(s,a,l)))).filter(d=>d.status==="fulfilled").map(d=>d.value).filter(d=>d!==null);if(c.length===0)throw new Oe("NO_SWAP_ROUTE",`All aggregators failed for ${s.tokenIn} \u2192 ${s.tokenOut} on chain ${a}`,{chainId:a,tokenIn:s.tokenIn,tokenOut:s.tokenOut,amountOut:s.amountOut.toString()});return c.sort((d,u)=>d.amountIn<u.amountIn?-1:d.amountIn>u.amountIn?1:0),c[0]}return{getQuote:o,venues:n}}function Ta(t){const{direction:n,selectedAsset:o,destinationToken:s,chainId:a,recipient:l,paymentAmount:r}=t,[c,d]=B(!1),[u,p]=B(null),[f,m]=B(null),[g,h]=B(null),[C,y]=B(null),[S,U]=B(null),[b,x]=B(null),M=Fe(null),z=Ce(()=>Ur({satsuma:To}),[]),T=Ce(()=>Ra({customVenues:[zr(To),zr(Wr)]}),[]),I=Ce(()=>{if(!o?.asset)return null;if(o.asset.chainId===a)return o.asset.address;const D=yn(o.asset.address,a);return D?D.address:null},[o?.asset?.address,o?.asset?.chainId,a]),F=Ce(()=>o?.asset?o.asset.address.toLowerCase()===s.address.toLowerCase()&&o.asset.chainId===a?!0:rs(o.asset.address,s.address):!1,[o,s.address,a]),w=I?I.toLowerCase()===s.address.toLowerCase():!1,W=n==="output"&&parseFloat(r||"0")===0,Z=!!o?.asset&&!F&&!w&&!W;return $(()=>{M.current&&clearTimeout(M.current);const D=n==="input"?o?.amount:r,A=parseFloat(D||"0");if(!Z||A<=0||!o?.asset||!l||!I){m(null),h(null),y(null),U(null),x(null),p(null),d(!1);return}return d(!0),M.current=setTimeout(async()=>{try{if(n==="input"){const E=_e(o.amount,o.asset.decimals),O=z.getVenueForChain(a);if(!O)throw new Error("No swap venue for this chain");const V=await O.resolve({type:"swap",tokenIn:I,tokenOut:s.address,amountIn:E},a,l);if(!V)throw new Error("No liquidity for this pair");x(V.amountOut),y(V),U(null);const P=wn(V.amountOut,s.decimals),X=parseFloat(P);m(X<.01?X.toPrecision(4):X.toLocaleString(void 0,{maximumFractionDigits:6})),h(null),p(null)}else{const E=_e(r||"0",s.decimals),O=await T.getQuote({tokenIn:I,tokenOut:s.address,amountOut:E},a,l);U(O),y(null),x(null),h(parseFloat(wn(O.amountIn,o.asset.decimals)).toFixed(6)),m(null),p(null)}}catch(E){const O=E instanceof Error?E.message:"Failed to get quote";p(O),m(null),h(null),y(null),U(null),x(null)}finally{d(!1)}},500),()=>{M.current&&clearTimeout(M.current)}},[n,Z,o?.amount,o?.asset?.address,o?.asset?.decimals,r,I,a,s.address,s.decimals,l,z,T]),{isQuoting:c,quoteError:u,estimatedOutput:f,estimatedInput:g,resolvedSwap:C,exactOutputSwap:S,quoteAmountOut:b,resolvedTokenIn:I,isDirect:w,needsSwap:Z,selectedIsEquivalent:F}}const Wa=[0n,1n,30n],Da=new Set(["ABORT","CONCURRENT_EXECUTION","WALLET_DISCONNECTED","WALLET_REJECTED","NO_VENUE_FOR_CHAIN"]);function Nr(t,n){return n===0n?t:t*(1000n-n)/1000n}async function Pr(t,n){const{chainId:o,swapCalls:s,quoteAmountOut:a,buildActionCalls:l,tokenAddress:r,tokenTransferAmount:c,onProgress:d,signal:u,options:p,buffers:f=Wa}=n;for(let m=0;m<f.length;m++){const g=f[m],h=Nr(a,g),C=l(h),y=[{chainId:o,calls:[...s,...C]}];try{return await t(y,r,c,d,u,p)}catch(S){if(Xn(S)&&Da.has(S.code)||S.name==="AbortError"||u?.aborted||S.message?.includes("User rejected")||S.message?.includes("User denied")||S.code===4001||m>=f.length-1)throw S;const U=Number(f[m+1])/10;console.warn(`[SwapThenAction] Action attempt ${m+1} failed (buffer ${Number(g)/10}%), retrying with ${U}% buffer...`,S.message),d?.({step:"signing-delegation",message:`Adjusting action amount, retrying (${U}% buffer)...`})}}throw new Oe("ALL_ATTEMPTS_FAILED","All action attempts failed after exhausting buffer progression.",{attempts:f.length,chainId:o})}const Lr={idle:"","signing-delegation":"Signing delegation...","signing-intent":"Signing intent...",submitting:"Submitting transaction...",executing:"Executing on-chain...",success:"Transaction successful!",error:"Transaction failed"},Hr=["signing-delegation","signing-intent","submitting","executing"],za=({color:t})=>i("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",style:{marginTop:"1px",flexShrink:0},children:[e("circle",{cx:"7",cy:"7",r:"6.5",stroke:t,strokeWidth:"1.2"}),e("path",{d:"M7 6v4",stroke:t,strokeWidth:"1.2",strokeLinecap:"round"}),e("circle",{cx:"7",cy:"4.5",r:"0.7",fill:t})]}),jr=({isOpen:t,onClose:n,destinationToken:o,buildActionCalls:s,actionLabel:a,amountDirection:l="input",swapDescription:r,directDescription:c,supportedSourceAssets:d,sourceChains:u,paymentAmount:p,amountInputMode:f="fixed",minPaymentAmount:m,maxPaymentAmount:g,onAmountChange:h,styles:C,dark:y,title:S,subtitle:U,onAddFunds:b,onSuccess:x,onError:M})=>{const z=l==="output",{theme:T,dark:I,primaryColor:F,dk:w,palette:W}=je(C,y),Z=T.typography.fontFamily,D=C?.inputVariant?C.inputVariant==="dark":I,A=W.textPrimary,E=W.textSecondary,O=D?w.cardBg:"#f9fafb",V=D?w.cardBorder:"#e5e7eb",P=C?.button?.backgroundColor??F,X=C?.button?.color??"#0e0d0b",se=D?{...T,colors:{...T.colors,secondary:w.cardBg,surfaceHover:w.hoverBg,border:"#2d2d2d",borderHover:"#3a3a3a"}}:T,R=o.chainId,H=tn(),{address:q,isConnected:me,isReady:we,isAuthenticated:oe,provider:ae}=H,{executeGasless:de}=co(),{displayAssets:Me,filteredSpiceAssets:ye,embeddedWalletAddress:We,refreshSpiceAssets:ce,refreshWalletAssets:Ve}=ka({address:q,destinationToken:o,supportedSourceAssets:d,sourceChains:u,enabled:t&&!!q}),De=z?Me:ye,[L,Se]=B(null),[Ee,te]=B(p||""),[ze,Pe]=B(!1),[Q,J]=B(null),[v,k]=B("idle"),[ee,re]=B(""),[N,Y]=B(null),[le,pe]=B(!1),[ke,pt]=B(null),fe=Fe(L),xe=Fe(!1),be=Fe(null);$(()=>{fe.current=L},[L]);const Xe=f==="adjustable"?Ee:p||"0",kt=We||q,{isQuoting:Ct,quoteError:ut,estimatedOutput:Ut,resolvedSwap:St,exactOutputSwap:st,quoteAmountOut:Nt,resolvedTokenIn:Zt,isDirect:ue,needsSwap:ge,selectedIsEquivalent:ve}=Ta({direction:l,selectedAsset:L,destinationToken:o,chainId:R,recipient:kt,paymentAmount:Xe}),Je=z?parseFloat(Xe||"0"):parseFloat(L?.amount||"")||0,ht=Ce(()=>L?.asset?ye.find(Ie=>Ie.address.toLowerCase()===L.asset.address.toLowerCase())?.balanceFormatted??0:0,[L,ye]),et=Ce(()=>L?.asset?z?ve?Je>L.asset.balanceFormatted:st?parseFloat(wn(st.amountInMax,L.asset.decimals))>L.asset.balanceFormatted:!1:Je>ht:!1,[L,z,ve,Je,st,ht]);$(()=>{t||(Se(null),J(null),Pe(!1),k("idle"),re(""),Y(null),pe(!1),pt(null),xe.current=!1,f==="adjustable"&&te(p||""),be.current&&(be.current.abort(),be.current=null))},[t]);const at=ie(Ie=>{Se(Re=>({asset:Ie,amount:Re?.asset?.address===Ie.address&&Re?.asset?.chainId===Ie.chainId&&Re.amount||""})),J(null)},[]),Mt=ie(Ie=>{Se(Re=>Re&&{...Re,amount:Ie}),J(null)},[]),nn=ie(Ie=>{let Re=Ie;g&&parseFloat(Re)>parseFloat(g)&&(Re=g),te(Re),h?.(Re),J(null)},[g,h]),on=ie(Ie=>{k({building:"signing-delegation","signing-delegation":"signing-delegation","signing-intent":"signing-intent",submitting:"submitting",executing:"executing",success:"success",error:"error"}[Ie.step]||"executing"),re(Ie.message),Ie.txHash&&Y(Ie.txHash)},[]),hn=ie(()=>{const Ie=_e(Xe,o.decimals),Re={userAddress:We,chainId:R,destinationToken:o.address},Te=s(Ie,Re),Ae={chainId:R,calls:Te},lt=L?.asset?._source==="spice",Ye=(Ze,Be)=>({token:Ze,from:"solver",to:We,amount:Be});if(Ie===0n)return[Ae];if(ge&&st){let Ze=L.asset.address;if(L.asset.chainId!==R){const $e=Ko(L.asset.address)?.deployments.find(Pt=>Pt.chainId===R);$e&&(Ze=$e.address)}const Be=lt?[Ye(Ze,st.amountInMax)]:[],He={to:Ze,value:0n,data:Wt({abi:At,functionName:"approve",args:[st.calls[0]?.to,st.amountInMax]})};return[{chainId:R,calls:[He,...st.calls,...Te],tokenTransfers:[...Be,...Ae.tokenTransfers??[]]}]}if(lt){let Ze=o.address;if(L.asset.chainId!==R){const Be=Ko(L.asset.address)?.deployments.find(He=>He.chainId===R);Be&&(Ze=Be.address)}return[{...Ae,tokenTransfers:[Ye(Ze,Ie),...Ae.tokenTransfers??[]]}]}return[Ae]},[Xe,o,We,R,s,L,ge,st]),fn=ie(async()=>{if(!L?.asset||Je<=0){J("Select an asset and enter an amount");return}if(et){J("Insufficient balance");return}if(!We){J("Wallet not ready");return}Pe(!0),J(null),k("signing-delegation"),re("Building transaction..."),Y(null),xe.current=!1;const Ie=new AbortController;be.current=Ie;try{const Re={userAddress:We,chainId:R,destinationToken:o.address};if(ue){const Te=_e(L.amount,L.asset.decimals),Ae=s(Te,Re);await de([{chainId:R,calls:Ae}],Zt??L.asset.address,Te,on,Ie.signal)}else{if(!St||!Nt)throw new Error("Please wait for the swap quote");const Te=_e(L.amount,L.asset.decimals);await Pr(de,{chainId:R,swapCalls:St.calls,quoteAmountOut:Nt,buildActionCalls:Ae=>s(Ae,Re),tokenAddress:Zt,tokenTransferAmount:Te,onProgress:on,signal:Ie.signal})}k("success"),re("Transaction successful!")}catch(Re){const Te=Re instanceof Error?Re:new Error(String(Re));if(Te.name==="AbortError"||Ie.signal.aborted){k("idle");return}const Ae=Te.message||"Transaction failed";k("error"),re(Ae),J(Ae),M?.(Te)}finally{Pe(!1)}},[L,Je,et,We,ue,R,St,Nt,Zt,s,de,on,M]),kn=ie(async()=>{if(Je<0){J("Enter a valid payment amount");return}if(!L?.asset){J("Select a payment source");return}if(et){J("Insufficient balance");return}if(ge&&!st){J("Swap quote not available. Try a different asset.");return}if(!me||!q){J("Please connect your wallet to continue");return}if(!we||!oe){J(`Please authenticate with ${ae||"wallet provider"} to continue`);return}Pe(!0),J(null),pe(!0),pt({status:"processing"});try{const Ie=hn(),Re=Ie.some(Ye=>Ye.tokenTransfers?.length),Te=_e(Xe,o.decimals),Ae=L?.asset?.address||o.address,lt=await de(Ie,Ae,Te,Ye=>{Ye.txHash&&(pt(Ze=>({...Ze,txHash:Ye.txHash})),Y(Ye.txHash))},void 0,Re?{useCustomTransfers:!0}:void 0);pt(Ye=>({status:"success",txHash:Ye?.txHash||lt}))}catch(Ie){const Re=Ot(Ie,"Payment failed. Please try again.");J(Re),pt({status:"failed",error:Re}),M?.(Ie instanceof Error?Ie:new Error(Re))}finally{Pe(!1)}},[Je,L,et,ge,st,me,q,we,oe,ae,hn,Xe,o,de,M]);$(()=>{!z&&v==="success"&&N&&(ce(),x?.(N))},[z,v,N,ce,x]),$(()=>{if(!z||ke?.status!=="success"||xe.current||!q)return;xe.current=!0;const Ie=fe.current;!Ie?.asset||Ie.asset?._source==="wallet"||ce()},[z,ke?.status,q,ce]);const qt=Fe(x),Vt=Fe(M);$(()=>{qt.current=x},[x]),$(()=>{Vt.current=M},[M]),$(()=>{z&&(ke?.status==="success"&&qt.current?.(ke.txHash||""),ke?.status==="failed"&&Vt.current?.(new Error("Payment execution failed")))},[z,ke?.status]);const Gt=ie(()=>{pe(!1),pt(null),Se(null),xe.current=!1,ce(),Ve()},[ce,Ve]),rn=z?!!L?.asset&&Je>=0&&!et&&!ze&&(!ge||!!st):!!L?.asset&&Je>0&&!et&&!ze&&(ue||!!St&&!Ct),Bt=ue?c||`Your ${o.symbol} will be used directly.`:r||"Your assets will be swapped and used in a single atomic transaction.",sn=I?w.shell:"white",an=I?w.buttonBorder:"#0e0d0b",gn=(R?Ke(R):void 0)?.viemChain?.blockExplorers?.default?.url??"",Jt=Hr.indexOf(v),mn=ze?(Lr[v]||"EXECUTING...").toUpperCase():v==="success"?"DONE":et?"INSUFFICIENT BALANCE":a.toUpperCase(),_=Ce(()=>{if(ze)return"PAYING...";if(et&&L?.asset)return`INSUFFICIENT ${L.asset.symbol}`;const Ie=Je>0?` ${Xe} ${o.symbol}`:"";return ge?`SWAP & PAY${Ie}`:`PAY${Ie}`},[ze,et,L,Je,Xe,o.symbol,ge]),he=v==="success"?()=>{k("idle"),Se(null),Y(null),ce()}:fn,tt=v==="success"?!1:!rn;if(!t)return null;const it=z?S||`Pay ${o.symbol}`:a,gt=z?U:i("div",{style:{display:"flex",alignItems:"flex-start",gap:"6px"},children:[e(za,{color:E}),e("p",{style:{fontSize:"13px",color:E,margin:0,lineHeight:"1.5"},children:Bt})]});if(z){const Ie=ke&&(ke.status==="success"||ke.status==="failed")?[{asset:{symbol:L?.asset?.symbol||o.symbol,address:L?.asset?.address||""},amount:Xe,txHash:ke.txHash||"",success:ke.status==="success",error:ke.status==="failed"?ke.error:void 0}]:void 0;return e(Dt,{isOpen:t,onClose:n,title:it,subtitle:gt,styles:C,dark:I,footerLinkText:"Spicenet accounts \u2192",children:i("div",{style:{padding:"16px 24px 8px 24px",position:"relative"},children:[b&&e("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:"6px"},children:i("button",{onClick:b,style:{background:"none",border:"none",cursor:"pointer",padding:0,display:"flex",alignItems:"center",gap:"4px",color:F,fontSize:"12px",fontWeight:500,fontFamily:Z,textDecoration:"underline",textUnderlineOffset:"2px"},children:["Add Funds",i("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:F,strokeWidth:"1.8",children:[e("circle",{cx:"6",cy:"6",r:"5"}),e("path",{d:"M6 4v4M4 6h4",strokeLinecap:"round"})]})]})}),e("div",{style:{marginBottom:"12px"},children:e(Rn,{assets:De,selectedAsset:L??void 0,onAssetSelect:at,onAmountChange:()=>{},label:"Pay with",showBalance:!0,showMaxButton:!1,hideAmountInput:!0,displayAmount:L?.asset?ge?Ct?"...":st?`~${parseFloat(wn(st.amountIn,L.asset.decimals)).toFixed(6)}`:void 0:Xe??void 0:void 0,dark:I,theme:se,styles:C})}),e(vr,{variant:"pay",destinationSymbol:o.symbol,destinationLogoURI:o.logoURI,destinationDecimals:o.decimals,primaryColor:F,fontFamily:Z,textPrimary:A,textSecondary:E,cardBg:O,cardBorder:V,dk:w,dark:I,isQuoting:Ct,quoteError:ut,estimatedOutput:Ut,paymentAmount:Xe,needsSwap:ge,exactOutputSwap:st,adjustable:f==="adjustable",maxAmount:g,onAmountChange:nn}),Q&&e("div",{style:{marginBottom:"12px",padding:"10px 14px",backgroundColor:W.errorBg,border:`1px solid ${W.errorBorder}`,borderRadius:"6px"},children:e("p",{style:{color:W.errorText,fontSize:"13px",margin:0,fontFamily:Z},children:Q})}),e(Ge,{variant:"outline",fullWidth:!0,onClick:kn,disabled:!rn,loading:ze,dark:I,styles:{button:{backgroundColor:F}},children:_}),ke&&le&&e("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:10,backgroundColor:I?w.shell:"white",borderRadius:I?"12px":"6px",padding:"16px 0"},children:e(Ln,{type:"payment",isOpen:ke.status!=="processing",isProcessing:ze||ke.status==="processing",closeOnComplete:!1,chainName:vt(R),explorerUrl:Cn(R,"").replace(/\/tx\/.*$/,"")||void 0,onRetryTx:()=>{pe(!1),pt(null),kn()},onNewTx:Gt,onClose:()=>{pe(!1),pt(null)},onComplete:Gt,results:Ie,styles:C,dark:I})})]})})}return i(Dt,{isOpen:t,onClose:n,title:it,subtitle:gt,dark:I,styles:C,theme:T,children:[e("div",{style:{marginBottom:"16px"},children:e(Rn,{assets:De,selectedAsset:L||void 0,onAssetSelect:at,onAmountChange:Mt,disabled:ze||v==="success",showBalance:!0,showMaxButton:!0,label:"From Spice Balance",placeholder:"0.00",theme:se,styles:C,dark:D,maxAmount:ht>0?ht.toString():void 0})}),L?.asset&&!ue&&e(vr,{variant:"supply",destinationSymbol:o.symbol,destinationLogoURI:o.logoURI,destinationDecimals:o.decimals,primaryColor:F,fontFamily:Z,textPrimary:A,textSecondary:E,cardBg:O,cardBorder:V,dark:I,isQuoting:Ct,quoteError:ut,estimatedOutput:Ut}),v!=="idle"&&i("div",{style:{padding:"10px 14px",borderRadius:"10px",marginBottom:"16px",backgroundColor:v==="success"?W.successBg:v==="error"?W.errorBg:O,border:`1px solid ${v==="success"?W.successBorder:v==="error"?W.errorBorder:V}`},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[v==="success"?e("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:e("path",{d:"M5 13l4 4L19 7",stroke:W.successText,strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round"})}):v==="error"?e("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:e("path",{d:"M18 6L6 18M6 6l12 12",stroke:W.errorText,strokeWidth:"2.5",strokeLinecap:"round"})}):e(An,{size:14,color:F}),e("span",{style:{fontSize:"13px",fontWeight:500,color:v==="success"?W.successText:v==="error"?W.errorText:A,fontFamily:Z,flex:1},children:v==="success"?"Transaction successful!":v==="error"?ee||"Transaction failed":Lr[v]||ee}),v==="success"&&N&&e("a",{href:`${gn}/tx/${N}`,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:F,fontFamily:Z,textDecoration:"none",whiteSpace:"nowrap",flexShrink:0},children:"View tx \u2192"}),v==="error"&&e("button",{onClick:()=>{k("idle"),J(null),setTimeout(fn,50)},style:{background:"none",border:"none",fontSize:"12px",color:F,fontFamily:Z,cursor:"pointer",padding:0,whiteSpace:"nowrap",flexShrink:0},children:"Retry \u2192"})]}),Jt>=0&&v!=="success"&&v!=="error"&&e("div",{style:{marginTop:"8px",height:"3px",borderRadius:"2px",backgroundColor:`${E}22`,overflow:"hidden"},children:e("div",{style:{height:"100%",borderRadius:"2px",backgroundColor:F,width:`${(Jt+1)/Hr.length*100}%`,transition:"width 400ms ease"}})})]}),Q&&v==="idle"&&e("div",{style:{padding:"10px 14px",borderRadius:"10px",backgroundColor:W.errorBg,border:`1px solid ${W.errorBorder}`,marginBottom:"16px"},children:e("p",{style:{fontSize:"13px",color:W.errorText,margin:0,fontFamily:Z},children:Q})}),e(Ge,{variant:"outline",fullWidth:!0,disabled:tt,onClick:he,style:{height:"56px",backgroundColor:tt?`${P}66`:v==="success"?W.successBg:P,color:v==="success"?W.successText:X,border:`1px solid ${v==="success"?W.successBorder:an}`,fontSize:"14px",fontWeight:700,letterSpacing:"2px",fontFamily:'"IBM Plex Mono", monospace',boxShadow:tt?"none":`3px 3px 0px ${sn}, 4px 4px 0px ${an}`,cursor:tt?"not-allowed":"pointer",opacity:tt?.6:1},children:mn})]})},Ua=t=>e(jr,{isOpen:t.isOpen,onClose:t.onClose,amountDirection:"output",destinationToken:{address:t.paymentTokenAddress,symbol:t.paymentTokenSymbol,decimals:t.paymentTokenDecimals,chainId:t.paymentChainId,logoURI:t.paymentTokenLogoURI},buildActionCalls:t.buildActionCalls,actionLabel:t.ctaLabel||"PAY",paymentAmount:t.paymentAmount,amountInputMode:t.amountInputMode,minPaymentAmount:t.minPaymentAmount,maxPaymentAmount:t.maxPaymentAmount,onAmountChange:t.onAmountChange,sourceChains:t.sourceChains,title:t.title,subtitle:t.subtitle,onAddFunds:t.onAddFunds,styles:t.styles,dark:t.dark,onSuccess:t.onPaymentSuccess,onError:t.onPaymentError}),Na=({label:t="Export Wallet",style:n,className:o,onExport:s,onError:a})=>{const[l,r]=B(!1),[c,d]=B(!1),{primaryColor:u}=je(),p=It(xt),{isAuthenticated:f}=tn();let m=null;try{m=to()}catch{}let g=null,h=null;try{g=cs(),h=no()}catch{g=null,h=null}const C=oo(h),y=ie(async()=>{if(!f){a?.("User is not authenticated. Please log in first.");return}try{if(p?.provider==="dynamic"){if(!g||!C){a?.("Dynamic is not available. Ensure the app is wrapped in a DynamicContextProvider.");return}await g.initExportProcess(!1),s?.();return}if(!m){a?.("Privy is not available. Ensure the app is wrapped in a PrivyProvider.");return}await m.exportWallet(),s?.()}catch(b){const x=b instanceof Error?b.message:"Failed to export wallet";console.error("Export wallet error:",b),a?.(x)}},[C,g,f,a,s,m,p?.provider]),S=!f,U={padding:"10px 20px",borderRadius:"8px",fontFamily:'"IBM Plex Mono", monospace',fontSize:"14px",fontWeight:500,letterSpacing:"0.4px",textTransform:"uppercase",cursor:S?"not-allowed":"pointer",opacity:S?.5:1,border:"1px solid #0e0d0b",color:"#0e0d0b",backgroundColor:c?`${u}cc`:l?`${u}ee`:u,transition:"all 150ms ease",display:"inline-flex",alignItems:"center",justifyContent:"center",gap:"8px",...n};return i("button",{onClick:y,onMouseEnter:()=>r(!0),onMouseLeave:()=>{r(!1),d(!1)},onMouseDown:()=>d(!0),onMouseUp:()=>d(!1),disabled:S,className:o,style:U,children:[i("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e("polyline",{points:"17 8 12 3 7 8"}),e("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]}),t]})};function Or(t){const n=It(xt),o=en(),s=t?.enabled===!1?void 0:o,a=n?.network?{network:n.network,pollIntervalMs:t?.pollIntervalMs,chainIds:t?.chainIds??n.supportedChainIds}:void 0;return{...gr(s,a),embeddedWalletAddress:o}}const Pa=({appName:t,status:n,statusLabel:o,totalUsdValue:s,breakdownSubtitle:a,address:l,dk:r,dark:c=!1,showModeToggle:d,isEmbeddedMode:u=!0,onModeToggle:p})=>{const[f,m]=B(!1),g=async()=>{l&&await Ss(l)&&(m(!0),setTimeout(()=>m(!1),2e3))},h=n==="active",C=o||(h?"Active":"Inactive"),y=h?"#10b981":"#9ca3af";return i("div",{children:[i("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"4px"},children:[i("div",{style:{fontSize:"13px",fontWeight:600,color:c?r.textPrimary:"#111827"},children:[t," Account"]}),d?i("button",{onClick:p,style:{display:"flex",alignItems:"center",gap:"4px",padding:"2px 8px",borderRadius:"9999px",backgroundColor:c?r.hoverBg:"#f3f4f6",border:c?`1px solid ${r.cardBorder}`:"1px solid #e5e7eb",cursor:"pointer",fontSize:"11px",fontWeight:600,fontFamily:'"IBM Plex Mono", monospace',color:c?r.textSecondary:"#6b7280",transition:"all 150ms ease",letterSpacing:"0.02em"},children:[e("div",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:u?"#22c55e":"#f59e0b"}}),e("span",{children:u?"Embedded":"External"})]}):i("div",{style:{display:"flex",alignItems:"center",gap:"4px",padding:"2px 8px",borderRadius:"9999px",backgroundColor:c?r.hoverBg:h?"#ecfdf5":"#f3f4f6",border:c?`1px solid ${r.cardBorder}`:h?"1px solid #a7f3d0":"1px solid #e5e7eb"},children:[e("div",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:y}}),e("span",{style:{fontSize:"11px",fontWeight:500,color:c?r.textSecondary:h?"#065f46":"#6b7280"},children:C})]})]}),e("div",{style:{fontSize:"28px",fontWeight:700,color:c?r.textPrimary:"#111827",lineHeight:1.2,marginBottom:"2px"},children:Mn(s)}),a&&e("div",{style:{fontSize:"12px",color:c?r.textSecondary:"#6b7280",marginBottom:"8px"},children:a}),l&&i("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[e("span",{style:{fontSize:"12px",fontFamily:'"IBM Plex Mono", monospace',color:c?r.textSecondary:"#9ca3af"},children:Is(l)}),e("button",{onClick:g,style:{padding:"2px 6px",fontSize:"10px",fontWeight:500,backgroundColor:"transparent",color:c?r.textSecondary:"#9ca3af",border:"none",cursor:"pointer",borderRadius:"4px",transition:"all 150ms ease"},title:"Copy address",children:f?"Copied":"Copy"})]})]})},La=({pendingDeposits:t,onCompleteDeposit:n,dk:o,dark:s=!1})=>t.length===0?null:i("div",{children:[e("div",{style:{fontSize:"11px",fontWeight:600,letterSpacing:"1px",color:s?o.textSecondary:"#6b7280",marginBottom:"8px",textTransform:"uppercase"},children:"Pending Deposits"}),e("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:t.map((a,l)=>{const r=Ke(a.chainId)?.displayName||`Chain ${a.chainId}`;return i("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 12px",backgroundColor:s?o.warningBg:"#fffbeb",border:s?`1px solid ${o.warningBorder}`:"1px solid #fde68a",borderRadius:"8px"},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e("div",{style:{width:"24px",height:"24px",borderRadius:"50%",backgroundColor:s?o.hoverBg:"#fde68a",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"11px",fontWeight:600,color:s?o.warningText:"#92400e"},children:a.tokenSymbol.charAt(0)}),i("div",{children:[i("div",{style:{fontSize:"13px",fontWeight:500,color:s?o.textPrimary:"#111827"},children:[a.amount," ",a.tokenSymbol]}),i("div",{style:{fontSize:"11px",color:s?o.warningText:"#92400e"},children:["on ",r]})]})]}),e("button",{onClick:()=>n?.(a),style:{padding:"4px 12px",fontSize:"11px",fontWeight:600,backgroundColor:s?o.hoverBg:"#fef3c7",color:s?o.textPrimary:"#92400e",border:s?`1px solid ${o.warningBorder}`:"1px solid #fde68a",borderRadius:"9999px",cursor:"pointer",transition:"all 150ms ease"},children:"Complete"})]},`${a.tokenAddress}-${a.chainId}-${l}`)})})]}),Ha=({spiceAssets:t,loading:n,dk:o,dark:s=!1})=>{const a={fontSize:"11px",fontWeight:600,letterSpacing:"1px",color:s?o.textSecondary:"#6b7280",marginBottom:"8px",textTransform:"uppercase"},l={backgroundColor:s?o.cardBg:"#f9fafb",border:s?`1px solid ${o.cardBorder}`:"1px solid #e5e7eb",borderRadius:"8px"};return n?i("div",{children:[e("div",{style:a,children:"Idle Balances"}),[1,2].map(r=>e("div",{style:{...l,padding:"12px",marginBottom:"6px",height:"48px",animation:"pulse 1.5s ease-in-out infinite",opacity:.5}},r))]}):t.length===0?i("div",{children:[e("div",{style:a,children:"Idle Balances"}),e("div",{style:{...l,padding:"16px",textAlign:"center",fontSize:"13px",color:s?o.textSecondary:"#9ca3af"},children:"No assets yet. Deposit to get started."})]}):i("div",{children:[e("div",{style:a,children:"Idle Balances"}),e("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:t.map((r,c)=>{const d=Ke(r.chainId)?.displayName||`Chain ${r.chainId}`;return i("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 12px",...l},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[r.logoURI?e("img",{src:r.logoURI,alt:r.tokenSymbol,style:{width:"24px",height:"24px",borderRadius:"50%"}}):e("div",{style:{width:"24px",height:"24px",borderRadius:"50%",backgroundColor:s?o.hoverBg:"#e5e7eb",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"11px",fontWeight:600,color:s?o.textSecondary:"#6b7280"},children:r.tokenSymbol.charAt(0)}),i("div",{children:[e("div",{style:{fontSize:"13px",fontWeight:500,color:s?o.textPrimary:"#111827"},children:r.tokenSymbol}),e("div",{style:{fontSize:"11px",color:s?o.textSecondary:"#9ca3af"},children:d})]})]}),i("div",{style:{textAlign:"right"},children:[e("div",{style:{fontSize:"13px",fontWeight:500,color:s?o.textPrimary:"#111827"},children:ao(r.balanceFormatted)}),e("div",{style:{fontSize:"11px",color:s?o.textSecondary:"#9ca3af"},children:Mn(r.usdValue)})]})]},`${r.tokenAddress}-${r.chainId}-${c}`)})})]})},ja=({section:t,dk:n,dark:o=!1})=>{const s=a=>{switch(a){case"green":return"#10b981";case"red":return"#ef4444";default:return o?n.textPrimary:"#111827"}};return i("div",{children:[e("div",{style:{fontSize:"11px",fontWeight:600,letterSpacing:"1px",color:o?n.textSecondary:"#6b7280",marginBottom:"8px",textTransform:"uppercase"},children:t.title}),e("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:t.items.map((a,l)=>i("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 12px",backgroundColor:o?n.cardBg:"#f9fafb",border:o?`1px solid ${n.cardBorder}`:"1px solid #e5e7eb",borderRadius:"8px"},children:[i("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[a.tokenLogoURI?e("img",{src:a.tokenLogoURI,alt:a.tokenSymbol,style:{width:"20px",height:"20px",borderRadius:"50%"}}):e("div",{style:{width:"20px",height:"20px",borderRadius:"50%",backgroundColor:o?n.hoverBg:"#e5e7eb",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",fontWeight:600,color:o?n.textSecondary:"#6b7280"},children:a.tokenSymbol.charAt(0)}),i("div",{children:[e("div",{style:{fontSize:"13px",fontWeight:500,color:o?n.textPrimary:"#111827"},children:a.tokenSymbol}),e("div",{style:{fontSize:"11px",color:o?n.textSecondary:"#6b7280"},children:a.label})]})]}),e("div",{style:{fontSize:"13px",fontWeight:600,color:s(a.valueColor)},children:a.displayValue})]},l))})]})},Oa=({onDepositClick:t,onWithdrawClick:n,depositDisabled:o=!1,withdrawDisabled:s=!1,primaryColor:a="#EA4B4B",dark:l=!1})=>i("div",{style:{display:"flex",gap:"8px"},children:[e(Ge,{variant:"outline",onClick:t,disabled:o,dark:l,styles:{button:{backgroundColor:a}},style:{flex:1,height:"44px",fontSize:"12px"},children:"Deposit"}),e(Ge,{variant:"outline",onClick:n,disabled:s,dark:l,styles:{button:{backgroundColor:a}},style:{flex:1,height:"44px",fontSize:"12px"},children:"Withdraw"})]}),Va=({appName:t,status:n,statusLabel:o,totalUsdValue:s,breakdownSubtitle:a,address:l,spiceAssets:r,spiceAssetsLoading:c,pendingDeposits:d,customSections:u,onDepositClick:p,onWithdrawClick:f,onCompleteDeposit:m,primaryColor:g,dk:h,dark:C=!1,showModeToggle:y,isEmbeddedMode:S,onModeToggle:U})=>{const[b,x]=B(!1);return i("div",{style:{display:"flex",flexDirection:"column",gap:"16px",padding:"16px",maxHeight:"calc(80vh - 32px)",overflowY:"auto"},children:[e(Pa,{appName:t,status:n,statusLabel:o,totalUsdValue:s,breakdownSubtitle:a,address:l,dk:h,dark:C,showModeToggle:y,isEmbeddedMode:S,onModeToggle:U}),e("div",{style:{height:"1px",backgroundColor:C?"#2d2d2d":"#e5e7eb"}}),i("div",{children:[i("button",{onClick:()=>x(!b),style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",padding:"8px 12px",backgroundColor:C?h.cardBg:"#f9fafb",border:C?`1px solid ${h.cardBorder}`:"1px solid #e5e7eb",borderRadius:"8px",cursor:"pointer",color:C?h.textSecondary:"#6b7280",fontSize:"12px",fontWeight:500},children:[e("span",{children:"How It Works"}),e("span",{style:{transform:b?"rotate(180deg)":"rotate(0deg)",transition:"transform 200ms ease",fontSize:"10px"},children:"\u25BE"})]}),b&&i("div",{style:{marginTop:"6px",padding:"10px 12px",backgroundColor:C?h.cardBg:"#f0fdf4",border:C?`1px solid ${h.cardBorder}`:"1px solid #bbf7d0",borderRadius:"8px",fontSize:"12px",lineHeight:1.5,color:C?h.textSecondary:"#374151"},children:["Fund your ",t," Account from any supported chain (10+ EVM chains). Once funded, transact gas-free and asset-abstracted on"," ",t,"."]})]}),e(La,{pendingDeposits:d,onCompleteDeposit:m,dk:h,dark:C}),e(Ha,{spiceAssets:r,loading:c,dk:h,dark:C}),u.map((M,z)=>e(ja,{section:M,dk:h,dark:C},z)),e(Oa,{onDepositClick:p,onWithdrawClick:f,primaryColor:g,dark:C})]})},Wo=380,Tn=8,Qa=({appName:t="Spice",status:n="active",statusLabel:o,customSections:s=[],extraAssets:a=[],tokenPrices:l={},breakdownLabels:r=[],supportedChains:c,styles:d,dark:u=!1,onDepositSuccess:p,onDepositClick:f,onWithdrawClick:m,onCompleteDeposit:g,showModeToggle:h=!1,defaultMode:C})=>{const y=It(xt),S=y?.mode!=="7702";$(()=>{C&&y?.setMode&&y.setMode(C==="non7702"?"ondemand":"7702")},[]);const[U,b]=B(!1),[x,M]=B(null),[z,T]=B({top:0,left:0,placement:"below"}),I=Fe(null),F=Fe(null),{address:w,isConnected:W}=tn(),Z=en(),{address:D}=Yt(),{dark:A,primaryColor:E,dk:O}=je(d,u),V=Ce(()=>c||$n("mainnet"),[c]),{assets:P,loading:X}=Fn({address:w,supportedChains:V,enabled:!!w&&!S,refetchInterval:3e4}),se=Ce(()=>[...S?[]:P.map(L=>{const Se=L.balanceUsd||0,Ee=Number(L.balance)/Math.pow(10,L.decimals),te=Se>0?Se:(l[L.symbol]||0)*Ee;return{tokenAddress:L.address,tokenSymbol:L.symbol,tokenDecimals:L.decimals,chainId:L.chainId,balance:L.balance.toString(),balanceFormatted:L.balanceFormatted,usdValue:te,logoURI:L.logoURI}}),...a].filter(L=>L.balanceFormatted>0),[S,P,l,a]),R=Ce(()=>se.reduce((L,Se)=>L+Se.usdValue,0),[se]),{pendingDeposits:H}=Or({chainIds:V,enabled:!!w}),q=Ce(()=>s.reduce((L,Se)=>L+Se.totalValue,0),[s]),me=R+q,we=Ce(()=>{const L=[];R>0&&L.push(`${Mn(R)} idle`);for(const Se of s){const Ee=r.find(te=>te.sectionTitle===Se.title)?.label||Se.title.toLowerCase();L.push(`${Mn(Se.totalValue)} ${Ee}`)}return L.join(" \xB7 ")},[R,s,r]),oe=ie(L=>{g?g(L):M(L)},[g]),ae=ie(()=>{M(null)},[]),de=ie(()=>{M(null),p?.()},[p]),Me=ie(()=>{if(!I.current)return;const L=I.current.getBoundingClientRect(),Se=window.innerHeight-L.bottom-Tn,Ee=L.top-Tn,te=Se>=400||Se>=Ee?"below":"above",ze=Math.max(Tn,Math.min(L.right-Wo,window.innerWidth-Wo-Tn)),Pe=te==="below"?L.bottom+Tn:L.top-Tn;T({top:Pe,left:ze,placement:te})},[]);Yr(()=>{U&&Me()},[U,Me]),$(()=>{if(!U)return;const L=te=>{I.current&&!I.current.contains(te.target)&&F.current&&!F.current.contains(te.target)&&b(!1)},Se=te=>{te.key==="Escape"&&b(!1)},Ee=()=>Me();return document.addEventListener("mousedown",L),document.addEventListener("keydown",Se),window.addEventListener("scroll",Ee,{passive:!0}),window.addEventListener("resize",Me),()=>{document.removeEventListener("mousedown",L),document.removeEventListener("keydown",Se),window.removeEventListener("scroll",Ee),window.removeEventListener("resize",Me)}},[U,Me]);const ye=y?.mode==="7702",We=ye?Z||w:D||w,ce=ie(()=>{y?.setMode&&y.setMode(ye?"ondemand":"7702")},[y,ye]);if(typeof window>"u")return null;const Ve=i("button",{ref:I,onClick:()=>b(!U),style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"8px 14px",borderRadius:"9999px",backgroundColor:A?O.hoverBg:"#ffffff",border:A?`1px solid ${O.cardBorder}`:"1px solid #e5e7eb",cursor:"pointer",fontSize:"13px",fontWeight:500,fontFamily:'"Helvetica Neue", sans-serif',color:A?O.textPrimary:"#111827",transition:"all 150ms ease",boxShadow:A?"none":"0 1px 2px rgba(0,0,0,0.05)"},children:[e("span",{style:{width:"8px",height:"8px",borderRadius:"50%",backgroundColor:E,flexShrink:0}}),i("span",{children:[t," Account"]}),W&&i("span",{style:{color:A?O.textSecondary:"#6b7280"},children:["\xB7 ",Mn(me)]}),e("span",{style:{fontSize:"10px",color:A?O.textSecondary:"#9ca3af",transform:U?"rotate(180deg)":"rotate(0deg)",transition:"transform 200ms ease"},children:"\u25BE"})]}),De=U?gs.createPortal(i(Qt,{children:[e("div",{style:{position:"fixed",inset:0,backgroundColor:"rgba(0, 0, 0, 0.08)",zIndex:9998},onClick:()=>b(!1)}),e("div",{ref:F,style:{position:"fixed",top:z.placement==="below"?`${z.top}px`:"auto",bottom:z.placement==="above"?`${window.innerHeight-z.top}px`:"auto",left:`${z.left}px`,width:`${Wo}px`,maxHeight:"80vh",backgroundColor:A?O.shell:"#ffffff",border:A?`1px solid ${O.cardBorder}`:"1px solid #e5e7eb",borderRadius:"12px",boxShadow:A?"0 10px 40px rgba(0, 0, 0, 0.5)":"0 10px 40px rgba(0, 0, 0, 0.12)",zIndex:9999,overflow:"hidden",animation:"accountDisplayFadeIn 150ms ease-out"},children:e(Va,{appName:t,status:n,statusLabel:o,totalUsdValue:me,breakdownSubtitle:we,address:h?We:w,spiceAssets:se,spiceAssetsLoading:X,pendingDeposits:H,customSections:s,onDepositClick:f,onWithdrawClick:m,onCompleteDeposit:oe,primaryColor:E,dk:O,dark:A,showModeToggle:h,isEmbeddedMode:ye,onModeToggle:ce})}),e("style",{children:`
115
115
  @keyframes accountDisplayFadeIn {
116
116
  from { opacity: 0; transform: translateY(-4px); }
117
117
  to { opacity: 1; transform: translateY(0); }