@spicenet-io/spiceflow-ui 3.3.53 → 3.3.54

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
@@ -100,7 +100,7 @@ import{jsxs as g,jsx as a,Fragment as fn}from"react/jsx-runtime";import hn,{useS
100
100
  from { transform: rotate(0deg); }
101
101
  to { transform: rotate(360deg); }
102
102
  }
103
- `})]})},uc="0xa9059cbb";function pc(e){const t=new Map;for(const n of e){if(n.amount<=0n)continue;const o=Ne(n.token),s=Ne(n.to),r=`${o.toLowerCase()}:${s.toLowerCase()}`,i=t.get(r);i?i.amount+=n.amount:t.set(r,{token:o,to:s,amount:n.amount})}return[...t.values()]}function fc(e,t){return`0x${t}${e.slice(4)}`}function hc(e,t,n){if(!Array.isArray(e))return 0n;const o=`evm:${t}:${n.slice(2).toLowerCase()}`;let s=0n;for(const r of e){if(!r||typeof r!="object")continue;const i=r,c=i.chainTokens;if((Array.isArray(c)?c.filter(d=>typeof d=="string"):c&&typeof c=="object"?Object.keys(c):[]).some(d=>d.toLowerCase()===o))try{s+=BigInt(i.balanceAvailable??"0")}catch{}}return s}async function oa(e,t,n,o){const s=await fetch(`${e}/wallets/${t}/balance`,{cache:"no-store"});if(!s.ok)throw new Error(`Failed to fetch spice balance: ${s.status}`);const r=await s.json();return hc(r?.balances,n,o)}async function mc({apiBaseUrl:e,user:t,chainId:n,tokenAddress:o,prevBalance:s,timeoutMs:r=3e4,pollIntervalMs:i=1500}){const c=Date.now()+r;for(await new Promise(d=>setTimeout(d,800));Date.now()<c;){try{if(await oa(e,t,n,o)>s)return}catch(d){console.warn("[SpiceLockModal] spice balance poll failed:",d?.message)}await new Promise(d=>setTimeout(d,i))}console.warn("[SpiceLockModal] Spicenet indexer did not reflect deposit within timeout; proceeding with intent")}function Ls(e,t){return zs(e,t)}function zs(e,t,n){const o=gc(t,e),s=Math.floor(Date.now()/1e3)+60*10,r=Rn(o);return{user:e,...n?{chainAuthorizations:n}:{},intents:[{mode:"7702",signatureType:"ecdsa",signature:"0x00",nbf:0,exp:s,chainBatches:r.map((i,c)=>({hash:i.hash,chainId:i.chainId,tokenTransfers:o[c].domain==="spicenet"?[]:o[c].tokenTransfers??[],calls:i.calls}))}]}}function gc(e,t){return e.map(n=>{if(n.domain==="spicenet"||n.calls.length===0)return n;const o=new Set((n.tokenTransfers??[]).filter(r=>(r.from==="escrow"||r.from==="solver")&&Ne(r.to).toLowerCase()===t.toLowerCase()).map(r=>Ne(r.token).toLowerCase()));if(o.size===0)return n;let s=0;for(const r of n.calls){if(!r.data?.startsWith(uc))break;try{const i=Co({abi:Ze,data:r.data});if(i.functionName!=="transfer")break;const[c]=i.args;if(c.toLowerCase()===t.toLowerCase()||!o.has(Ne(r.to).toLowerCase()))break;s+=1}catch{break}}return s===0?n:{...n,calls:n.calls.slice(s)}})}function rn(e,t,n,o){if(e.some(l=>l.domain==="spicenet"))return e;const s=n?.intents.flatMap(l=>l.batches),r=l=>l.from==="escrow",i=e.map(l=>{const p=s?.find(w=>w.chainId===l.chainId);if(!p)return l;const u=vn(p),h=u.totalFee;if(h<=0n)return l;const m=(l.tokenTransfers??[]).find(w=>r(w)&&Ne(w.to).toLowerCase()===t.toLowerCase()&&!Ue(Ne(w.token)));if(!m)return l;const f=Ne(m.token);let y=!1;const C=(l.tokenTransfers??[]).map(w=>y||!r(w)||Ne(w.to).toLowerCase()!==t.toLowerCase()||Ne(w.token).toLowerCase()!==f.toLowerCase()?w:(y=!0,{...w,amount:o?.payoutAlreadyGross?BigInt(w.amount):BigInt(w.amount)+h}));if(!y)return l;const v=[];u.spicenetFee>0n&&v.push({to:f,value:0n,data:xt({abi:Ze,functionName:"transfer",args:[xo,u.spicenetFee]})});const b=u.gasFee+u.bridgeFee;return b>0n&&v.push({to:f,value:0n,data:xt({abi:Ze,functionName:"transfer",args:[Tn,b]})}),{...l,tokenTransfers:C,calls:[...v,...l.calls]}}),c=i.flatMap(l=>(l.tokenTransfers??[]).filter(r).map(p=>{const u=Ne(p.token),h=Ne(p.to),m=[{token:u,to:h,amount:BigInt(p.amount)}];return{chainId:l.chainId,transfers:pc(m)}}));if(c.length===0)return e;const d=BigInt(Math.floor(Date.now()/1e3))+3600n;return[{chainId:_a,domain:"spicenet",tokenTransfers:[],calls:c.map((l,p)=>{const u=bo(wo([{type:"address"},{type:"address"},{type:"uint256"},{type:"uint256"},{type:"uint256"}],[t,l.transfers[0].token,l.transfers.reduce((m,f)=>m+f.amount,0n),BigInt(l.chainId),BigInt(Date.now()+p)])),h=fc(u,"77");return{to:"0x0000000000000000000000000000000000000000",value:0n,data:xt({abi:rs,functionName:"createWithdrawalRequest",args:[{chainId:`evm:${l.chainId}`,idempotenceKey:h,nbf:0n,exp:d,metadata:"{}",transfers:l.transfers.map(m=>({token:m.token.toLowerCase(),to:m.to,amount:m.amount}))}]})}})},...i]}function Os(e,t){return t?e.some(n=>(n.tokenTransfers??[]).some(o=>o.from==="escrow"&&BigInt(o.amount)>=t.grossAmount)):!1}function Hs(e){const t=e.selectedAsset?.asset,n=e.selectedAsset?.amount;if(!(!t||!n))return Ke(n,t.decimals)}function qn(e,t){const n=e.selectedAsset?.asset;if(!n||!e.selectedAsset?.amount)throw new Error("Select an asset and enter an amount");const o=Ke(e.selectedAsset.amount,n.decimals),s=t?.grossAmount??o;return e.resolveLockBatches({amount:e.selectedAsset.amount,amountWei:o,grossAmount:rt(s,n.decimals),grossAmountWei:s})}async function js(e,t,n){const o=[...new Set(n.filter(r=>r.domain!=="spicenet").map(r=>r.chainId))],s=[];for(const r of o){const i=pt(r),c=mo(r),d=await ss(t,i),l=await e.actions.signAuthorization({contractAddress:c,chainId:r,nonce:Number(d)});s.push(l)}return s}async function sa(e,t,n){const o=e.isSemi7702&&e.providerEmbeddedAddress||e.address;if(!e.isConnected||!o)throw new Error("Please connect your wallet to continue");if(t.length===0)throw new Error("No lock batches configured");if(!e.ready||!e.authenticated)throw new Error(`Please authenticate with ${e.provider||"wallet provider"} to continue`);const s=n??await js(e,o,t),r=Rn(t),i=Math.floor(Date.now()/1e3)+60*10,c=r.map(m=>m.hash),d=bo(wo([{type:"string"},{type:"uint256"},{type:"uint256"},{type:"bytes32[]"}],["ecdsa",0n,BigInt(i),c])),l=await e.actions.signMessage({raw:d}),p=typeof l=="string"?l:l.signature;if(!p)throw new Error("Failed to sign intent authorization");const u={mode:"7702",signatureType:"ecdsa",signature:p,nbf:0,exp:i,chainBatches:r.map((m,f)=>{const y=t[f],C=y.domain==="spicenet";return{hash:m.hash,chainId:m.chainId,tokenTransfers:C?[]:y.tokenTransfers??[],calls:m.calls}})},h=await nt.createAction({user:o,chainAuthorizations:s.map(m=>({r:m.r,s:m.s,yParity:m.yParity,address:m.address,chainId:Number(m.chainId),nonce:Number(m.nonce)})),intents:[u]});if(h){const m=es(t,nn),[f,y]=h.intentIds[0].split("/"),C=parseInt(y||"0",10),v=h.intentIds[0];e.startStatusPolling(h.intentIds[0],m),await Lr({actionId:f,intentIndex:C,intentId:v,totalSteps:t.length,isSpicenetStep:b=>t[b]?.domain==="spicenet",maxExecuteAttemptsForStep:b=>t[b]?.domain==="spicenet"?6:3,maxPolls:180})}}async function ra(e){let t=qn(e);if(t.length===0)throw new Error("No lock batches configured");const n=e.isSemi7702&&e.providerEmbeddedAddress||e.address;if(!e.isConnected||!n)throw new Error("Please connect your wallet to continue");const o=await js(e,n,t);let s=rn([...t],n),r;for(let i=0;i<4;i+=1){const c=await nt.estimateActionFees(zs(n,s,o.map(u=>({r:u.r,s:u.s,yParity:u.yParity,address:u.address,chainId:Number(u.chainId),nonce:Number(u.nonce)})))),d=Fo(c,{symbol:e.selectedAsset?.asset.symbol??"",decimals:e.selectedAsset?.asset.decimals??18,actionAmount:Hs(e)});if(!d)break;const l={grossAmount:d.grossAmount,netAmount:d.netAmount,feeAmount:d.totalFee??0n},p=r?.grossAmount===l.grossAmount&&r?.netAmount===l.netAmount&&r?.feeAmount===l.feeAmount;if(r=l,t=qn(e,r),s=rn([...t],n,c,{payoutAlreadyGross:Os(t,r)}),p)break}await sa(e,s,o)}async function yc(e){if(!e.selectedAsset?.asset||!e.selectedAsset.amount)throw new Error("Select an asset and enter an amount");if(!e.address||!e.embeddedWalletAddress)throw new Error("Embedded wallet not connected");const t=e.selectedAsset.asset,n=Ke(e.selectedAsset.amount,t.decimals),o=e.escrowAddress||mo(e.lockChainId),s=nt.getBaseUrl(),r=It(t.address);let i=0n;try{i=await oa(s,e.embeddedWalletAddress,e.lockChainId,r)}catch(u){console.warn("[SpiceLockModal] could not snapshot spice balance pre-deposit:",u?.message)}const c=await e.actions.getEthereumProvider();await Hn(c,e.lockChainId);const d=Be(e.lockChainId),l=Dn({account:e.embeddedWalletAddress,transport:Nn(c),chain:d?.viemChain});let p;if(t.isNative||Ue(t.address))p=await l.sendTransaction({to:o,value:n,chain:d?.viemChain});else{const u=xt({abi:Ze,functionName:"transfer",args:[o,n]});p=await l.sendTransaction({to:t.address,data:u,chain:d?.viemChain})}if((await pt(e.lockChainId).waitForTransactionReceipt({hash:p,timeout:12e4,pollingInterval:2e3,confirmations:1})).status!=="success")throw new Error("Transfer to escrow failed");await mc({apiBaseUrl:s,user:e.embeddedWalletAddress,chainId:e.lockChainId,tokenAddress:r,prevBalance:i}),await e.refreshSpiceAssets(),e.refreshWalletAssets(),await ra(e)}async function xc(e){if(!e.selectedAsset?.asset||!e.selectedAsset.amount)throw new Error("Select an asset and enter an amount");if(!e.externalWalletAddress||!e.externalWallet)throw new Error("Please connect your external wallet to continue");const t=e.embeddedWalletAddress||e.providerEmbeddedAddress;if(!t)throw new Error("Embedded wallet not available \u2014 sign in to create one before locking");if(e.onLockExecute){const S=e.resolveLockBatches();if(S.length===0)throw new Error("No lock batches configured");const A=e.selectedAsset.asset,B=Ke(e.selectedAsset.amount,A.decimals),F=await e.onLockExecute({asset:A,amount:e.selectedAsset.amount,amountWei:B,lockDurationMonths:e.selectedDuration?.months??0,chainBatches:S});F&&e.onLockSuccess?.(F);return}const n=e.resolveLockBatches();if(n.length===0)throw new Error("No lock batches configured");const o=e.selectedAsset.asset,s=Ke(e.selectedAsset.amount,o.decimals),r=o.chainId,i=e.escrowAddress||wn(r),c=It(o.address),d=o.isNative||Ue(c),l=n.some(S=>S.tokenTransfers?.some(A=>A.from==="escrow")),p=S=>({chainId:r,calls:d?[{to:i,value:S,data:"0x"}]:[{to:c,value:0n,data:xt({abi:Ze,functionName:"transfer",args:[i,S]})}]}),u=(S,A,B)=>{const F=p(S);if(!l)return[F,...A];const k=rn([...A],t,B,{payoutAlreadyGross:Os(A,y)});return[F,...k]};let h=qn(e),m=u(s,h);const f=await js(e,t,m);let y;if(l)for(let S=0;S<4;S+=1){const A=await nt.estimateActionFees(zs(t,m,f.map(E=>({r:E.r,s:E.s,yParity:E.yParity,address:E.address,chainId:Number(E.chainId),nonce:Number(E.nonce)})))),B=Fo(A,{symbol:o.symbol,decimals:o.decimals,actionAmount:s});if(!B)break;const F={grossAmount:B.grossAmount,netAmount:B.netAmount,feeAmount:B.totalFee??0n},k=y?.grossAmount===F.grossAmount&&y?.netAmount===F.netAmount&&y?.feeAmount===F.feeAmount;if(y=F,h=qn(e,y),m=u(F.grossAmount,h,A),k)break}const C=y?.grossAmount??s,v=await e.externalWallet.getEthereumProvider();let b=null;try{const S=await v.request({method:"eth_chainId"});b=parseInt(S,16)}catch{b=null}b!==r&&await Hn(v,r);const w=Be(r),I=Dn({account:e.externalWalletAddress,chain:w?.viemChain,transport:Nn(v)}),x=d?await I.sendTransaction({to:t,value:C,chain:w?.viemChain}):await I.sendTransaction({to:c,data:xt({abi:Ze,functionName:"transfer",args:[t,C]}),chain:w?.viemChain});if((await pt(r).waitForTransactionReceipt({hash:x,timeout:12e4,pollingInterval:2e3,confirmations:1})).status!=="success")throw new Error("Transfer to embedded wallet failed");await sa(e,m,f)}async function bc(e){if(!e.selectedAsset?.asset||!e.selectedAsset.amount||!e.requiresRelayerFeeEstimate)return null;if(e.isSemi7702){const i=e.embeddedWalletAddress||e.providerEmbeddedAddress;if(!i)throw new Error("Embedded wallet not available \u2014 sign in to create one before locking");let c=qn(e);if(c.length===0)throw new Error("No lock batches configured");const d=e.selectedAsset.asset,l=Ke(e.selectedAsset.amount,d.decimals),p=d.chainId,u=e.escrowAddress||wn(p),h=It(d.address),m=d.isNative||Ue(h),f=c.some(I=>I.tokenTransfers?.some(x=>x.from==="escrow")),y=I=>({chainId:p,calls:m?[{to:u,value:I,data:"0x"}]:[{to:h,value:0n,data:xt({abi:Ze,functionName:"transfer",args:[u,I]})}]}),C=(I,x,S)=>{const A=y(I);if(!f)return[A,...x];const B=rn([...x],i,S,{payoutAlreadyGross:x.some(F=>(F.tokenTransfers??[]).some(k=>k.from==="escrow"&&BigInt(k.amount)>=I))});return[A,...B]};let v=C(l,c),b=null,w;for(let I=0;I<4;I+=1){const x=await nt.estimateActionFees(Ls(i,v)),S=Fo(x,{symbol:d.symbol,decimals:d.decimals,actionAmount:l});if(!S)return b;const A={grossAmount:S.grossAmount,netAmount:S.netAmount,feeAmount:S.totalFee??0n},B=w?.grossAmount===A.grossAmount&&w?.netAmount===A.netAmount&&w?.feeAmount===A.feeAmount;if(b=S,w=A,c=qn(e,A),v=C(A.grossAmount,c,x),B)break}return b}const t=e.address;if(!e.isConnected||!t)throw new Error("Please connect your wallet to continue");let n=qn(e);if(n.length===0)throw new Error("No lock batches configured");let o=rn([...n],t),s=null;for(let i=0;i<4;i+=1){const c=await nt.estimateActionFees(Ls(t,o)),d=Fo(c,{symbol:e.selectedAsset.asset.symbol,decimals:e.selectedAsset.asset.decimals,actionAmount:Hs(e)});if(!d)return null;const l={grossAmount:d.grossAmount},p=s?.grossAmount===d.grossAmount&&s?.netAmount===d.netAmount&&s?.totalFee===d.totalFee;if(s=d,n=qn(e,l),o=rn([...n],t,c,{payoutAlreadyGross:Os(n,l)}),p)break}if(s)return s;const r=await nt.estimateActionFees(Ls(t,o));return Fo(r,{symbol:e.selectedAsset.asset.symbol,decimals:e.selectedAsset.asset.decimals,actionAmount:Hs(e)})}async function wc(e){if(!e.selectedAsset?.asset||!e.selectedAsset.amount)throw new Error("Select an asset and enter an amount");if(!e.externalWalletAddress||!e.externalWallet)throw new Error("Please connect your external wallet to continue");const t=e.resolveLockBatches();if(t.length===0)throw new Error("No lock batches configured");const n=t.find(l=>l.chainId===e.lockChainId)||t[0];if(!n)throw new Error("No lock batch for lock chain");const o=await e.externalWallet.getEthereumProvider();let s=null;try{const l=await o.request({method:"eth_chainId"});s=parseInt(l,16)}catch{s=null}s!==e.lockChainId&&await Hn(o,e.lockChainId);const r=Be(e.lockChainId),i=Dn({account:e.externalWalletAddress,chain:r?.viemChain,transport:Nn(o)}),c=pt(e.lockChainId);let d;for(const l of n.calls){const p=await i.sendTransaction({to:l.to,data:l.data,value:l.value,chain:r?.viemChain});if((await c.waitForTransactionReceipt({hash:p,timeout:12e4,pollingInterval:2e3,confirmations:1})).status!=="success")throw new Error("Lock transaction failed");d=p}d&&e.onLockSuccess?.(d)}async function Cc(e){if(!e.selectedAsset?.asset||e.parsedAmount<=0){e.ui.setError("Select an asset and enter an amount");return}if(e.isInsufficientBalance){e.ui.setError("Insufficient balance. Add more assets.");return}e.ui.setIsExecuting(!0),e.ui.setError(null);const t=n=>{console.error("[SpiceLockModal] lock failed:",n);const o=bn(n,""),s=typeof n?.shortMessage=="string"?n.shortMessage:typeof n?.message=="string"?n.message:"";e.ui.setError(o||s||"Transaction failed. Please try again.")};if(e.isSemi7702){if(e.isSourceDestToken){try{await wc(e)}catch(n){t(n)}finally{e.ui.setIsExecuting(!1)}return}e.ui.setShowStatusPanel(!0);try{await xc(e)}catch(n){t(n)}finally{e.ui.setIsExecuting(!1)}return}e.ui.setShowStatusPanel(!0);try{e.isDirectDeposit&&!e.isSourceDestToken?await yc(e):await ra(e)}catch(n){t(n)}finally{e.ui.setIsExecuting(!1)}}const aa=({isOpen:e,onClose:t,closeOnBackdropClick:n=!1,lockBatches:o,lockTokenSymbol:s,lockTokenLogoURI:r,destinationInputHook:i,sourceAssetInputHook:c,lockDurationHook:d,lockChainId:l,durationOptions:p,votingPowerEstimate:u,escrowAddress:h,includeWalletAssets:m=!1,destinationTokenAddress:f,onLockSuccess:y,onLockExecute:C,sourceToDestinationConversionRate:v,estimatedOutputAmount:b,onAddFunds:w,buildSpicenetBatch:I,styles:x,dark:S=!1})=>{const{theme:A,dark:B,primaryColor:F,dk:k}=ut(x,S),E=A.typography.fontFamily,M=Gt(Lt),T=M?.mode||"7702",O=!!M?.isWhitelistGateActive,N=T!=="7702",U=re(()=>M?.supportedChainIds??[],[M?.supportedChainIds]),V=re(()=>{if(O)return[];const G=M?.allowedTokens;if(!G||G.length===0)return[];const ue=new Set(G.map(Ye=>Ye.toLowerCase())),We=[],De=new Set;for(const Ye of U){const Ft=Be(Ye);for(const pn of Ft?.supportedTokens??[]){if(!ue.has(pn.symbol.toLowerCase()))continue;const q=`${Ye}:${pn.address.toLowerCase()}`;De.has(q)||(De.add(q),We.push(Ne(pn.address)))}}return We},[M?.allowedTokens,U,O]),D=B?k.cardBg:x?.assetSelector?.backgroundColor||x?.secondaryBackground||"#e9e9e9",Q=B?`1px solid ${k.cardBorder}`:"0.5px solid #A8A8A7",P=B?"12px":"6px",j=B?k.textPrimary:"#111827",L=B?k.textSecondary:"#6b7280",Z=re(()=>({...x,assetSelector:{...x?.assetSelector,backgroundColor:B?k.cardBg:x?.assetSelector?.backgroundColor,borderRadius:B?"12px":x?.assetSelector?.borderRadius},secondaryBackground:B?k.cardBg:x?.secondaryBackground}),[x,B]),ge=re(()=>B?{...A,colors:{...A.colors,secondary:k.cardBg,surfaceHover:k.hoverBg,border:k.cardBorder,borderHover:k.inputBorder}}:A,[B,A]),[W,_]=R(null),[fe,be]=R(0),Me=d?.selectedDurationIdx??fe,he=d?.setSelectedDurationIdx??be,[xe,H]=R(!1),[se,K]=R(null),[le,ye]=R(null),[Ee,ee]=R(!1),[z,ae]=R(!1),[we,Le]=R(null),[wt,at]=R(!1),it=ie(0),[Re,oe]=R(!1),[je,Y]=R(null);er(),ts();const{chain:ke,address:St}=go();Za();const Rt=ie(ke);X(()=>{Rt.current=ke},[ke]);const lt=Fn(),{isReady:an,isAuthenticated:Xt,isConnected:Nt,address:Ie,provider:Jt,actions:In}=lt,{externalWallet:An,embeddedAddress:Ut,externalAddress:ln}=no(),{intentStatus:ct,startStatusPolling:jt,clearStatus:_e}=gr({checkStepStatus:(G,ue)=>nt.checkStepStatus(G,ue),retryStep:async(G,ue)=>{const[We,De]=G.split("/"),Ye=parseInt(De||"0",10);await nt.executeStep(We,Ye,ue,{action:"execute"})},maxRetries:3}),{assets:ft,refetch:ht}=Eo({address:Ie,supportedChains:U,enabled:e&&Nt&&!N&&!O,refetchInterval:3e4}),Bt=re(()=>{if(O)return[];if(V.length===0)return ft;const G=new Set(V.map(ue=>ue.toLowerCase()));return ft.filter(ue=>G.has(ue.address.toLowerCase()))},[ft,V,O]),Kt=Bn(),me=ln||St,bt=N?me:Kt,Ct=re(()=>{if(!m)return[];if(O)return f?[Ne(f)]:[];const G=new Set,ue=[],We=De=>{if(!De)return;const Ye=De.toLowerCase();G.has(Ye)||(G.add(Ye),ue.push(Ne(De)))};if(f&&We(f),N)for(const De of V)We(De);return ue},[m,N,f,V,O]),Qt=re(()=>Ct.map(G=>G.toLowerCase()).sort().join(","),[Ct]),Ce=re(()=>JSON.stringify([...U||[]].sort()),[U]),[$t,mt]=R([]),Tt=ie(0),Vt=ie(async()=>{}),mn=ce(async()=>{if(!m||!bt||Ct.length===0){Tt.current++,mt([]);return}const G=++Tt.current,ue=Ne(bt),We=U&&U.length>0?U:[l],De=Ct.map($=>{const de=$.toLowerCase();if(f&&Se($,f)){const J=Be(l)?.supportedTokens?.find(Fe=>Se(Fe.address,de));return{address:$,chainId:l,configToken:J?{decimals:J.decimals,symbol:J.symbol,name:J.name,logo:J.logo}:void 0}}for(const J of We){const Fe=Be(J)?.supportedTokens?.find(He=>Se(He.address,de));if(Fe)return{address:$,chainId:J,configToken:{decimals:Fe.decimals,symbol:Fe.symbol,name:Fe.name,logo:Fe.logo}}}return{address:$,chainId:l}}),Ye=new Map;for(const $ of De){const de=Ye.get($.chainId)||[];de.push($),Ye.set($.chainId,de)}const Ft=async($,de)=>{try{const J=await kn($,{address:de.address,abi:Ze,functionName:"balanceOf",args:[ue]});let Fe,He,yt,tt;if(de.configToken)Fe=de.configToken.decimals,He=de.configToken.symbol,yt=de.configToken.name,tt=de.configToken.logo;else{const[Wt,en,tn]=await Promise.all([kn($,{address:de.address,abi:Ze,functionName:"decimals",args:[]}).catch(()=>18),kn($,{address:de.address,abi:Ze,functionName:"symbol",args:[]}).catch(()=>"TOKEN"),kn($,{address:de.address,abi:Ze,functionName:"name",args:[]}).catch(()=>"TOKEN")]);Fe=Number(Wt),He=en,yt=tn}const kt=!!f&&Se(de.address,f)&&de.chainId===l;kt&&r&&(tt=r),kt&&s&&!de.configToken&&(He==="TOKEN"&&(He=s),yt==="TOKEN"&&(yt=s));const Zt=parseFloat((Number(J)/Math.pow(10,Fe)).toFixed(6));return{address:de.address,name:yt,symbol:He,decimals:Fe,balance:J,balanceFormatted:Zt,balanceUsd:0,logoURI:tt,isNative:!1,chainId:de.chainId}}catch{return null}},pn=await Promise.all(Array.from(Ye.entries()).map(async([$,de])=>{let J;try{J=pt($)}catch{return[]}const Fe=[],He=[];for(const tt of de){const kt=Fe.length;Fe.push({address:tt.address,abi:Ze,functionName:"balanceOf",args:[ue]}),tt.configToken||Fe.push({address:tt.address,abi:Ze,functionName:"decimals",args:[]},{address:tt.address,abi:Ze,functionName:"symbol",args:[]},{address:tt.address,abi:Ze,functionName:"name",args:[]}),He.push({start:kt,item:tt})}let yt=null;try{yt=await J.multicall({contracts:Fe})}catch{yt=null}return yt?He.map(({start:tt,item:kt})=>{const Zt=yt[tt],Wt=Zt?.status==="success"?Zt.result:0n;let en,tn,Sn,Kn;if(kt.configToken)en=kt.configToken.decimals,tn=kt.configToken.symbol,Sn=kt.configToken.name,Kn=kt.configToken.logo;else{const pe=yt[tt+1],Pe=yt[tt+2],Pt=yt[tt+3];en=pe?.status==="success"?Number(pe.result):18,tn=Pe?.status==="success"?Pe.result:"TOKEN",Sn=Pt?.status==="success"?Pt.result:tn}const Yn=!!f&&Se(kt.address,f)&&kt.chainId===l;Yn&&r&&(Kn=r),Yn&&s&&!kt.configToken&&(tn==="TOKEN"&&(tn=s),Sn==="TOKEN"&&(Sn=s));const ve=parseFloat((Number(Wt)/Math.pow(10,en)).toFixed(6));return{address:kt.address,name:Sn,symbol:tn,decimals:en,balance:Wt,balanceFormatted:ve,balanceUsd:0,logoURI:Kn,isNative:!1,chainId:kt.chainId}}):(await Promise.all(de.map(tt=>Ft(J,tt)))).filter(tt=>tt!==null)}));if(G!==Tt.current)return;const q=pn.flat();mt(q)},[m,bt,Qt,Ce,l,f,r,s]);X(()=>{Vt.current=mn},[mn]),X(()=>{if(!e||!m){mt([]);return}Vt.current();const G=setInterval(()=>{Vt.current()},15e3);return()=>clearInterval(G)},[m,e,bt,Qt,Ce,l,f]);const cn=ce(()=>{mn()},[mn]),dt=re(()=>$t.filter(G=>G.balance>0n),[$t]),gn=re(()=>{if(N)return dt.map(ue=>({...ue,_source:"wallet"}));if(!m)return Bt;const G=[];for(const ue of dt)G.push({...ue,_source:"wallet"});for(const ue of Bt)G.push({...ue,_source:"spice"});return G},[N,m,dt,Bt]),ze=re(()=>O?f?gn.filter(G=>Se(G.address,f)&&G.chainId===l):[]:gn,[gn,O,f,l]),Et=ie(null),qt=ie(null);X(()=>{qt.current=W},[W]),X(()=>{!O||!W?.asset||f&&Se(W.asset.address,f)&&W.asset.chainId===l||_(null)},[O,W?.asset,f,l]),X(()=>{e||(_(null),K(null),ye(null),ee(!1),ae(!1),Le(null),H(!1),oe(!1),Y(null),at(!1),_e())},[e,_e]),X(()=>{i&&i.assetAmount!==(W?.amount||"")&&_(G=>G&&{...G,amount:i.assetAmount})},[i?.assetAmount]),X(()=>{c&&c.assetAmount!==(W?.amount||"")&&_(G=>G&&{...G,amount:c.assetAmount})},[c?.assetAmount]),X(()=>{if(!N&&ct?.overallStatus==="success"&&ct.intentId&&Et.current!==ct.intentId&&Ie&&ct.steps.find(G=>G.transactionHash)?.transactionHash){Et.current=ct.intentId;const G=qt.current;if(!G?.asset||!G.amount||G.asset._source==="wallet"||Ke(G.amount,G.asset.decimals)===0n)return;ht()}},[ct,Ie,l,ht,N]);const Ge=parseFloat(W?.amount||"")||0,ot=re(()=>W?.asset?W.asset._source==="wallet"?W.asset.balanceFormatted??0:Bt.find(G=>Se(G.address,W.asset.address)&&G.chainId===W.asset.chainId)?.balanceFormatted??0:0,[W?.asset,Bt]),Yt=Ge>0&&(we?parseFloat(rt(we.grossAmount,we.decimals))>ot:Ge>ot),vt=d?.selectedDuration??p[Me]??p[0],Oe=re(()=>!W?.asset||!f?!1:Se(W.asset.address,f)&&W.asset.chainId===l,[W?.asset,f,l]),Xe=re(()=>Ge<=0?0:Oe?Ge:!v||v<=0?0:Ge/v,[Ge,v,Oe]),Mt=re(()=>Xe<=0?null:Xe.toLocaleString(void 0,{maximumFractionDigits:2}),[Xe]),gt=u&&Xe>0&&vt?u(Xe,vt.months):void 0,dn=re(()=>Ge<=0?"$0.00":Oe&&v?(Ge*v).toLocaleString(void 0,{style:"currency",currency:"USD",maximumFractionDigits:2}):!v||v<=0?"$0.00":Ge.toLocaleString(void 0,{style:"currency",currency:"USD",maximumFractionDigits:2}),[Ge,v,Oe]),Qe=re(()=>{if(!Mt)return null;const G=parseFloat(Mt.replace(/,/g,""));return Oe&&v?(G*v).toLocaleString(void 0,{maximumFractionDigits:2}):v?(G*v).toLocaleString(void 0,{maximumFractionDigits:2}):null},[Mt,v,Oe]),yn=ce(G=>{_(ue=>({asset:G,amount:ue?.asset?.address===G.address&&ue?.asset?.chainId===G.chainId&&ue.amount||""})),K(null),ye(null),ae(!1),Le(null),c?.setSelectedAsset&&c.setSelectedAsset({symbol:G.symbol,address:G.address,decimals:G.decimals,chainId:G.chainId})},[c?.setSelectedAsset]),un=ce(G=>{_(ue=>ue&&{...ue,amount:G}),K(null),ye(null),ae(!1),Le(null),i&&i.setAssetAmount(G),c&&c.setAssetAmount(G)},[i,c]),_t=ce(G=>{if(typeof o=="function"){if(!W?.asset||!W.amount)throw new Error("Select an asset and enter an amount");return o({asset:W.asset,amount:G?.amount??W.amount,amountWei:G?.amountWei??Ke(W.amount,W.asset.decimals),grossAmount:G?.grossAmount,grossAmountWei:G?.grossAmountWei,feeAdjusted:!!G})}return o},[o,W]),te=ie(null),ne=re(()=>!W?.asset||Ge<=0?!1:N?!Oe&&!C:!0,[W,Ge,N,Oe,C]),Ae=ce(()=>bc(te.current),[]);X(()=>{if(!e||xe)return;if(!W?.asset||Ge<=0){ye(null),ee(!1),ae(!1),Le(null);return}if(!ne){ye(null),ee(!1),ae(!0),Le(null);return}let G=!1;const ue=async()=>{const Ye=++it.current;ye(null),ae(!1),ee(!0);try{const Ft=await Ae();if(G||it.current!==Ye)return;ye(null),ae(!0),Le(Ft)}catch(Ft){if(G||it.current!==Ye)return;ye(bn(Ft,"Unable to calculate fees for this lock.")),ae(!1)}finally{!G&&it.current===Ye&&ee(!1)}},We=window.setTimeout(()=>{ue()},250),De=window.setInterval(()=>{ue()},1e4);return()=>{G=!0,clearTimeout(We),window.clearInterval(De),ee(!1),ae(!1)}},[e,xe,W,Ge,ne,Ae]),X(()=>{if(ct?.overallStatus==="success"){const G=ct.steps.find(ue=>ue.transactionHash);y?.(G?.transactionHash)}},[ct?.overallStatus,y]);const Je=m&&W?.asset?._source==="wallet"&&W?.asset?.chainId===l,st=ce(()=>Cc(te.current),[]),et=!!W?.asset&&Ge>0&&!Yt&&!xe&&(!ne||z&&!Ee&&!le),$e=se||le,Ve=g("div",{style:{display:"flex",alignItems:"flex-start",gap:"6px"},children:[a(ks,{color:L}),g("p",{style:{fontSize:"13px",color:L,margin:0,lineHeight:"1.5"},children:["Add ",s," by converting assets from your account"]})]});if(te.current={selectedAsset:W,parsedAmount:Ge,selectedDuration:vt,isInsufficientBalance:Yt,isSemi7702:N,isSourceDestToken:Oe,isDirectDeposit:Je,requiresRelayerFeeEstimate:ne,address:Ie,embeddedWalletAddress:Kt,providerEmbeddedAddress:Ut,externalWallet:An,externalWalletAddress:me,isConnected:Nt,ready:an,authenticated:Xt,provider:Jt,actions:In,lockChainId:l,escrowAddress:h,onLockExecute:C,onLockSuccess:y,buildSpicenetBatch:I,resolveLockBatches:_t,startStatusPolling:jt,refreshSpiceAssets:ht,refreshWalletAssets:cn,ui:{setError:K,setIsExecuting:H,setShowStatusPanel:at}},!e)return null;const qe={backgroundColor:D,border:Q,borderRadius:P,padding:"16px",marginBottom:"16px"};return a(Pn,{isOpen:e,onClose:t,title:`Add ${s} to your account`,subtitle:Ve,styles:x,dark:B,footerLinkText:"Spicenet accounts \u2192",overlayContent:Re?a("div",{}):void 0,closeOnBackdropClick:n,children:g("div",{style:{padding:"0 24px 8px 24px",position:"relative"},children:[g("div",{style:{marginBottom:"12px"},children:[w&&a("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:"6px"},children:a(vs,{onClick:w,color:F,fontFamily:E})}),a("div",{style:{marginTop:"10px",fontSize:"13px",color:L,fontFamily:E},children:a(Ao,{assets:ze,selectedAsset:W??void 0,onAssetSelect:yn,onAmountChange:un,label:"Amount",showBalance:!0,showMaxButton:!0,theme:ge,styles:Z})}),a("div",{style:{marginTop:"6px",paddingLeft:"4px",fontSize:"13px",color:L,fontFamily:E},children:dn})]}),g("div",{style:qe,children:[g("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",paddingBottom:"16px",borderBottom:B?`1px solid ${k.cardBorder}`:"1px solid #e5e7eb"},children:[g("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[r?a("img",{src:r,alt:s,style:{width:"32px",height:"32px",borderRadius:"50%",objectFit:"cover"}}):a("div",{style:{width:"32px",height:"32px",borderRadius:"50%",backgroundColor:B?k.inputBg:"#d1d5db",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"12px",fontWeight:700,color:j},children:s.slice(0,2)}),a("span",{style:{fontSize:"16px",fontWeight:600,color:j,fontFamily:E},children:s})]}),g("div",{style:{textAlign:"right"},children:[a("div",{style:{fontSize:"22px",fontWeight:700,color:j,fontFamily:E,lineHeight:1.1},children:Mt??"0.00"}),g("div",{style:{fontSize:"12px",color:L,fontFamily:E,marginTop:"2px"},children:["~$",Qe??"0.00"]})]})]}),g("div",{style:{paddingTop:"16px",paddingBottom:"16px",borderBottom:B?`1px solid ${k.cardBorder}`:"1px solid #e5e7eb"},children:[g("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},children:[a("span",{style:{fontSize:"15px",fontWeight:500,color:L,fontFamily:E},children:"Lock Duration"}),a(Un,{color:L})]}),a(ac,{options:p,selectedIndex:Me,onSelect:he,primaryColor:F,dark:B,textPrimary:j,textSecondary:L})]}),g("div",{style:{paddingTop:"12px",display:"flex",flexDirection:"column",gap:"8px"},children:[a(lc,{durationMonths:vt?.months,fontFamily:E,dark:B,textPrimary:j,textSecondary:L}),u&&a(cc,{votes:gt,fontFamily:E,dark:B,textPrimary:j,textSecondary:L})]})]}),ne&&a(Uo,{fontFamily:E,textPrimary:j,textSecondary:L,cardBg:D,cardBorder:Q,resolvedDark:B,darkCardBorder:k.cardBorder,primaryColor:F,feePreview:we,isLoading:Ee,errorText:le}),$e&&a(io,{variant:"error",palette:k,fontFamily:E,style:{marginBottom:"12px"},children:$e}),a(At,{variant:"outline",fullWidth:!0,onClick:st,disabled:!et,loading:xe,dark:B,styles:{...x,button:{...x?.button,backgroundColor:F}},children:xe?Je&&!Oe?"DEPOSITING...":Oe?"LOCKING...":"CONVERTING...":Ee&&ne?"CALCULATING FEES...":Je&&!Oe?`DEPOSIT ${s}`:Oe?`LOCK ${s}`:`CONVERT TO ${s}`}),a(dc,{isOpen:Re,data:je,isLocking:xe,lockError:$e,onContinue:st,onClose:()=>oe(!1),primaryColor:F,fontFamily:E,dark:B}),ct&&wt&&a("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:10,backgroundColor:B?"rgba(0, 0, 0, 0.45)":"rgba(255, 255, 255, 0.55)",backdropFilter:"blur(2px)",WebkitBackdropFilter:"blur(2px)",borderRadius:P},children:a(Fs,{type:"deposit",showStepBreakdown:!1,isOpen:!!ct&&ct.overallStatus!=="processing",isProcessing:xe||ct?.overallStatus==="processing",closeOnComplete:!1,onRetryTx:()=>{_e(),at(!1),st()},onNewTx:()=>{_e(),at(!1),_(null),Et.current=null,ht(),cn()},onClose:()=>{_e(),at(!1)},onComplete:()=>{_e(),at(!1),_(null),Et.current=null,ht(),cn()},results:ct?.overallStatus==="success"||ct?.overallStatus==="failed"?ct.steps.map(G=>({asset:{symbol:W?.asset?.symbol||s,address:W?.asset?.address||""},txHash:G.transactionHash||"",success:G.status==="success",amount:W?.amount})):void 0,chainName:nn(l),explorerUrl:to(l,"").replace(/\/tx\/.*$/,"")||void 0,theme:A,styles:x,dark:B})})]})})},kc="0xa9059cbb";function vc(e,t,n){return Ue(e)?{to:n,value:t,data:"0x"}:{to:e,value:0n,data:xt({abi:Ot,functionName:"transfer",args:[n,t]})}}function Qs(e,t,n,o){return t!=="user-transfer"||!n||e.length===0||e[0]?.to.toLowerCase()!==o.toLowerCase()||!e[0]?.data.startsWith(kc)?{feeCall:null,remainingCalls:e}:{feeCall:e[0],remainingCalls:e.slice(1)}}async function Go(e,t,n){if(!t)return[e];const o=await t(n);return o?[o,e]:[e]}function _n(e){return e.filter(t=>t.domain!=="spicenet")}function Xo(e){const t=(e.tokenTransfers??[]).filter(n=>n.from==="escrow").map(n=>({token:It(n.token),recipient:n.to,amount:BigInt(n.amount)})).filter(n=>n.amount>0n);return t.length>0?t:void 0}function uo(e,t,n){if(t===n)return e;if(t<n)return e*10n**BigInt(n-t);const o=10n**BigInt(t-n);return(e+o-1n)/o}async function Ic(e,t){const{currentPaymentAmount:n,destinationToken:o,embeddedWalletAddress:s,providerEmbeddedAddress:r,address:i,isNon7702:c,isPayMode:d,resolvedChainId:l,buildActionCalls:p,feeExecutionMode:u,buildSpicenetBatch:h,selectedAsset:m,needsSwap:f,exactOutputSwap:y,resolvedTokenIn:C}=e,v=Ke(n,o.decimals),b=t?.actionAmountOverride??v,w=s||r||(c?void 0:i);if(!w)throw new Error("Embedded wallet address is not available. Please sign in and try again.");const I={userAddress:w,chainId:l,destinationToken:o.address,grossAmount:t?.fundingAmountOverride??v,netAmount:b,combinedFeeAmount:t?.actionContextOverride?.combinedFeeAmount,feeExecutionMode:u,feeBreakdown:t?.actionContextOverride?.feeBreakdown,...t?.actionContextOverride},x=p(b,I),S={chainId:l,calls:x},A=(!d&&!c?!0:m?.asset?._source==="spice")||c,B=(F,k)=>({token:F,from:c?"solver":"escrow",to:w,amount:k});if(v===0n)return[S];if(f&&y){const F=C??Mn(m.asset,l)??m.asset.address,k=t?.fundingAmountOverride??y.amountInMax,E=A?[B(F,k)]:[],M={to:F,value:0n,data:xt({abi:Ot,functionName:"approve",args:[y.calls[0]?.to,y.amountInMax]})},T={chainId:l,calls:[M,...y.calls,...x],tokenTransfers:[...E,...S.tokenTransfers??[]]};return A?Go(T,h,{userAddress:w,destinationChainId:l,deliveryToken:F,deliveryAmount:k,deliveryRecipient:w,deliveryTransfers:Xo(T),sourceAsset:m.asset}):[T]}if(A){const F=C??Mn(m.asset,l)??o.address,k=t?.fundingAmountOverride??v,E={...S,tokenTransfers:[B(F,k),...S.tokenTransfers??[]]};return Go(E,h,{userAddress:w,destinationChainId:l,deliveryToken:F,deliveryAmount:k,deliveryRecipient:w,deliveryTransfers:Xo(E),sourceAsset:m.asset})}return[S]}async function Ac(e,t){const{selectedAsset:n,embeddedWalletAddress:o,externalWalletAddress:s,resolvedChainId:r,destinationToken:i,buildActionCalls:c,feeExecutionMode:d,buildSpicenetBatch:l,isPayMode:p,isNon7702:u,needsSwap:h,resolvedSwap:m,quoteAmountOut:f,resolvedTokenIn:y}=e,C=m?.amountOutMinimum??f;if(!n?.asset||!o)return[];const v=u?s:o;if(!v)return[];const b=t?.fundingAmountOverride??t?.actionAmountOverride??Ke(n.amount,n.asset.decimals),w=t?.fundingAmountOverride??b,I=t?.sourceFundingAmountOverride??b,x=t?.deliveryAmountOverride??w,S=t?.withdrawalAmountOverride??x,A=t?.actionAmountOverride??b,B={userAddress:v,chainId:r,destinationToken:i.address,feeToken:d==="user-transfer"&&h&&y?y:i.address,grossAmount:w,netAmount:A,combinedFeeAmount:t?.actionContextOverride?.combinedFeeAmount,feeExecutionMode:d,feeBreakdown:t?.actionContextOverride?.feeBreakdown,...t?.actionContextOverride},F=c(A,B),k=n.asset?._source==="wallet";if(!p&&u&&k&&n.asset.chainId===r){if(h){if(!y)throw new Error("Swap input token could not be resolved");if(!m||C===null)throw new Error("Swap quote not available yet")}if(h&&m&&C){const Q=c(t?.actionAmountOverride??C,{...B,netAmount:t?.actionAmountOverride??C}),{feeCall:P,remainingCalls:j}=Qs(Q,d,h,B.feeToken);return[{chainId:r,calls:[...P?[P]:[],...m.calls,...j]}]}return[{chainId:r,calls:F}]}if(!p&&!u&&k){if(n.asset.chainId===r){if(h){if(!y)throw new Error("Swap input token could not be resolved");if(!m||C===null)throw new Error("Swap quote not available yet")}if(h&&m&&C){const Q=c(t?.actionAmountOverride??C,{...B,netAmount:t?.actionAmountOverride??C}),{feeCall:P,remainingCalls:j}=Qs(Q,d,h,B.feeToken);return[{chainId:r,calls:[...P?[P]:[],...m.calls,...j]}]}return[{chainId:r,calls:F}]}throw new Error("Cross-chain wallet supplies require external wallet mode")}const E=!p&&!u?n.asset?._source!=="wallet":n.asset?._source==="spice",M=u&&k;if(!(E||M))return[{chainId:r,calls:F}];const T=M&&n.asset.chainId!==r?{chainId:n.asset.chainId,calls:[vc(It(n.asset.address),I,wn(n.asset.chainId))]}:null,O=(Q,P)=>({token:Q,from:M?"solver":"escrow",to:o,amount:P}),N=(Q,P)=>M?[{token:Q,from:"escrow",to:ei,amount:P}]:[];if(h){if(!y)throw new Error("Swap input token could not be resolved");if(!m||C===null)throw new Error("Swap quote not available yet")}if(h&&m&&C&&y){const Q=c(t?.actionAmountOverride??C,{...B,netAmount:t?.actionAmountOverride??C}),{feeCall:P,remainingCalls:j}=Qs(Q,d,h,B.feeToken),L={chainId:r,calls:[...P?[P]:[],...m.calls,...j],tokenTransfers:[...N(y,S),O(y,x)]},Z=await Go(L,l,{userAddress:o,destinationChainId:r,deliveryToken:y,deliveryAmount:x,withdrawalAmount:S,deliveryRecipient:o,deliveryTransfers:Xo(L),sourceAsset:n.asset});return T?[T,...Z]:Z}const U=y??Mn(n.asset,r)??i.address,V={chainId:r,calls:F,tokenTransfers:[...N(U,S),O(U,x)]},D=await Go(V,l,{userAddress:o,destinationChainId:r,deliveryToken:U,deliveryAmount:x,withdrawalAmount:S,deliveryRecipient:o,deliveryTransfers:Xo(V),sourceAsset:n.asset});return T?[T,...D]:D}async function Sc(e,t,n,o,s){let r=e;for(let i=0;i<4;i++){const c=await t(r),d=await o(c,n,r,s),l=Nl(d);if(l===null||l>=e)return r;const p=r-l,u=e+p;if(u<=r)return r;r=u}return r}function Ec(e,t,n,o){if(e<=0n)return 0n;const s=e-t;if(s<=0n)return 0n;const r=o+n;return r<=0n?s:s*o/r}function Fc(e,t){const n=rt(e,t);return n.includes(".")?n.replace(/\.?0+$/,"")||"0":n}async function Bc(e){const{asset:t,isPayMode:n,isNon7702:o,needsSwap:s,isQuoting:r,embeddedWalletAddress:i,buildSupplyChainBatches:c,estimateGasless:d,executionTokenAddress:l,feeExecutionMode:p}=e;if(n||o||s||r||!i||t.balance<=0n)return null;const u=i,h=await c({fundingAmountOverride:t.balance,actionAmountOverride:t.balance});if(h.length===0)return null;const m=h.some(w=>w.tokenTransfers?.length),f=await d(h,l,t.balance,m?{userOverride:u,useCustomTransfers:!0,feeExecutionMode:p}:p?{userOverride:u,feeExecutionMode:p}:{userOverride:u}),y=Qn(f,{chainId:t.chainId,tokenAddress:t.address,symbol:t.symbol,decimals:t.decimals}),C=y?uo(y.gasFee,y.decimals,t.decimals):0n,v=y?uo(y.spicenetFee,y.decimals,t.decimals):0n,b=Ec(t.balance,C,v,t.balance);return b>0n?Fc(b,t.decimals):null}async function Tc(e){const{selectedAsset:t,isPayMode:n,parsedAmount:o,needsSwap:s,exactOutputSwap:r,isNon7702:i,isSourceDestToken:c,currentPaymentAmount:d,destinationToken:l,feeExecutionMode:p,resolvedTokenIn:u,embeddedWalletAddress:h,providerEmbeddedAddress:m,resolvedChainId:f,isConnected:y,address:C,ready:v,authenticated:b,isDirect:w,resolvedSwap:I,isQuoting:x,executionTokenAddress:S,buildPayChainBatches:A,buildSupplyChainBatches:B,estimateGasless:F,estimateRequiredGrossFunding:k}=e;if(!t?.asset)return null;if(n){if(o<=0||s&&!r||i&&c)return null;const D=Ke(d,l.decimals),Q=u||Mn(t.asset,f)||t.asset.address||l.address,P={chainId:f,tokenAddress:Q,symbol:Dt(Q,f)?.symbol??t.asset.symbol,decimals:Dt(Q,f)?.decimals??t.asset.decimals};if(i){const _=h||m;if(!_)return null;const fe=_,be=s?r?.amountInMax??0n:D;if(be===0n)return null;const Me=await k(be,H=>A({fundingAmountOverride:H}).then(se=>rn(_n(se),fe)),Q,{userOverride:_,useCustomTransfers:!0}),he=rn(_n(await A({fundingAmountOverride:Me})),fe),xe=await F(he,Q,Me,{userOverride:_,useCustomTransfers:!0,feeExecutionMode:p});return Qn(xe,P)}if(!y||!C||!v||!b)return null;const j=h||m||C,L=s?r?.amountInMax??0n:D;if(L===0n)return null;const Z=await k(L,_=>A({fundingAmountOverride:_}).then(fe=>rn(_n(fe),j)),Q,{useCustomTransfers:!0});let ge=rn(_n(await A({fundingAmountOverride:Z})),j);const W=await F(ge,Q,Z,{useCustomTransfers:!0,feeExecutionMode:p});return Qn(W,P)}if(o<=0||!h)return null;const E=h||m;if(!(!n&&!i&&t.asset?._source==="wallet"&&t.asset.chainId!==f)&&!w&&!I&&!x||x)return null;const M=Ke(t.amount,t.asset.decimals),T=await B();if(T.length===0)return null;const O=i&&t.asset?._source==="wallet"&&t.asset.chainId===f,N={chainId:f,tokenAddress:S,symbol:Dt(S,f)?.symbol??l.symbol,decimals:Dt(S,f)?.decimals??l.decimals};if(O){const D=await nt.estimateBatchGas({user:E,outputToken:S,stepIndex:0,chainBatches:T}),Q=Vo(M,10n),P=Q+D.gasFee;return{...N,grossAmount:M+P,netAmount:M,totalFee:P,gasFee:D.gasFee,spicenetFee:Q,bridgeFee:0n,gasQuoteSource:D.gasQuoteSource}}const U=T.some(D=>D.tokenTransfers?.length),V=await F(T,S,M,U?{userOverride:E,useCustomTransfers:!0,feeExecutionMode:p}:p?{userOverride:E,feeExecutionMode:p}:{userOverride:E});return Qn(V,N)}const Mc=10n;function ia(e,t){const n=e.selectedAsset?.asset;if(!n||n?._source!=="wallet")return;const o=Mn(n,e.resolvedChainId);if(!o||!Se(o,e.executionTokenAddress))return;const s=Dt(e.executionTokenAddress,e.resolvedChainId),r=uo(t,s?.decimals??e.destinationToken.decimals,n.decimals);if(r<=n.balance)return;const i=rt(r,n.decimals),c=rt(n.balance,n.decimals);throw new Error(`Insufficient ${n.symbol} for amount plus fees. Required ${i} ${n.symbol}; available ${c} ${n.symbol}.`)}function la(e){const t=Dt(e.executionTokenAddress,e.resolvedChainId);return{chainId:e.resolvedChainId,tokenAddress:e.executionTokenAddress,symbol:t?.symbol??e.destinationToken.symbol,decimals:t?.decimals??e.destinationToken.decimals}}function ca(e,t,n){const o=Qn(e,la(t));if(!o)return;const s=Vo(n,Mc),r=o.bridgeFee??0n,i=s+o.gasFee+r;return{grossAmount:n+i,netAmount:n,combinedFeeAmount:i,feeExecutionMode:"user-transfer",feeBreakdown:{spicenetFee:s,gasFee:o.gasFee,bridgeFee:r}}}function po(e,t,n){if(e===t)return!0;const o=e>t?e:t;return o===0n?!1:(e>t?e-t:t-e)*10000n<=o*n}function da(e,t,n){let o=0n,s=0n;const r=n.toLowerCase();for(const i of e)if(i.chainId===t){for(const c of i.calls??[])if(c.to.toLowerCase()===r)try{const d=Co({abi:Ot,data:c.data});if(d.functionName!=="transfer")continue;const l=d.args[0].toLowerCase(),p=d.args[1];l===xo.toLowerCase()?o+=p:l===Tn.toLowerCase()&&(s+=p)}catch{continue}}return{spicenetFee:o,gasFee:s}}function Rc(e,t,n){const o=t.feeExecutionMode==="user-transfer"&&t.needsSwap&&t.resolvedTokenIn?t.resolvedTokenIn:t.executionTokenAddress,s=da(e,t.resolvedChainId,o);return s.spicenetFee===0n&&n.feeBreakdown.spicenetFee>0n||s.gasFee===0n&&n.feeBreakdown.gasFee>0n?!1:po(s.spicenetFee,n.feeBreakdown.spicenetFee,100n)&&po(s.gasFee,n.feeBreakdown.gasFee,100n)}function Dc(e,t){return e?po(e.grossAmount,t.grossAmount,100n)&&po(e.feeBreakdown.spicenetFee,t.feeBreakdown.spicenetFee,100n)&&po(e.feeBreakdown.gasFee,t.feeBreakdown.gasFee,100n)&&po(e.feeBreakdown.bridgeFee,t.feeBreakdown.bridgeFee,100n):!1}async function Nc(e){if(!e.selectedAsset?.asset||e.parsedAmount<=0){e.ui.setError("Select an asset and enter an amount");return}if(e.isInsufficientBalance){e.ui.setError("Insufficient balance");return}if(e.isNon7702){if(!e.externalWalletAddress){e.ui.setError("Please connect your external wallet to continue");return}e.ui.setIsExecuting(!0),e.ui.setError(null),e.ui.setTxHash(null);try{if(e.isSourceDestToken){e.ui.setStep("executing"),e.ui.setStatusMsg("Submitting transaction...");const n=await ua(e);e.ui.setTxHash(n??null)}else{e.ui.setStep("signing-delegation"),e.ui.setStatusMsg("Building transaction..."),e.refs.spiceDepositSubmittedRef.current=!1;const n=new AbortController;e.refs.abortControllerRef.current=n,await Wc(e,n.signal)}e.ui.setStep("success"),e.ui.setStatusMsg(e.isSourceDestToken?"Transaction confirmed":"Deposit confirmed")}catch(n){const o=n instanceof Error?n:new Error(String(n));if(o.name==="AbortError"||e.refs.abortControllerRef.current?.signal.aborted){e.ui.setStep("idle");return}const s=o.message||"Transaction failed";e.ui.setStep("error"),e.ui.setStatusMsg(s),e.ui.setError(s),e.onError?.(o)}finally{e.ui.setIsExecuting(!1)}return}if(!e.embeddedWalletAddress){e.ui.setError("Wallet not ready");return}e.ui.setIsExecuting(!0),e.ui.setError(null),e.ui.setStep("signing-delegation"),e.ui.setStatusMsg("Building transaction..."),e.ui.setTxHash(null),e.refs.spiceDepositSubmittedRef.current=!1;const t=new AbortController;e.refs.abortControllerRef.current=t;try{const n=Ke(e.selectedAsset.amount,e.selectedAsset.asset.decimals),o=n;let s=await e.gasless.buildSupplyChainBatches();const r=e.selectedAsset.asset?._source==="wallet",i=e.embeddedWalletAddress||e.providerEmbeddedAddress;if(e.buildSpicenetBatch&&!e.isPayMode&&!e.isNon7702&&!r&&!s.some(m=>Do(m.chainId)))throw new Error("Spice-funded supplies must include a Spicenet funding batch before the destination chain batch.");const c=s.some(m=>m.tokenTransfers?.length)?{userOverride:i,useCustomTransfers:!0,feeExecutionMode:e.feeExecutionMode}:e.feeExecutionMode?{userOverride:i,feeExecutionMode:e.feeExecutionMode}:{userOverride:i};let d=n;const l=e.feeExecutionMode==="user-transfer"&&e.needsSwap&&!e.exactOutputSwap,p=e.feeExecutionMode==="user-transfer"&&!l?o:void 0;let u;for(let m=0;m<4;m+=1){const f=await e.gasless.estimateGasless(s,e.executionTokenAddress,d,c),y=Qn(f,la(e));u=e.feeExecutionMode==="user-transfer"&&y?ca(f,e,o):void 0;const C=u?.grossAmount??y?.grossAmount??d;if(C===d){d=C;break}d=C,s=await e.gasless.buildSupplyChainBatches({fundingAmountOverride:d,actionAmountOverride:p,actionContextOverride:u})}e.feeExecutionMode==="user-transfer"&&(ia(e,d),s=await e.gasless.buildSupplyChainBatches({fundingAmountOverride:d,actionAmountOverride:p,actionContextOverride:u}));let h=u;await e.gasless.executeGasless(s,e.executionTokenAddress,d,e.gasless.onProgress,t.signal,e.feeExecutionMode==="user-transfer"?{...c,skipUserFundingPreflight:!0,adjustBatchesForEstimate:({feeEstimate:m,chainBatches:f})=>{const y=ca(m,e,o);if(!y)return null;const C=e.feeExecutionMode==="user-transfer"&&e.needsSwap&&e.resolvedTokenIn?e.resolvedTokenIn:e.executionTokenAddress;da(f,e.resolvedChainId,C);const v=Dc(h,y),b=Rc(f,e,y);return v||b?null:(h=y,e.gasless.buildSupplyChainBatches({fundingAmountOverride:y.grossAmount,actionAmountOverride:p,actionContextOverride:y}))}}:c),e.ui.setStep("success"),e.ui.setStatusMsg("Deposit confirmed")}catch(n){const o=n instanceof Error?n:new Error(String(n));if(o.name==="AbortError"||t.signal.aborted){e.ui.setStep("idle");return}const s=o.message||"Transaction failed";e.ui.setStep("error"),e.ui.setStatusMsg(s),e.ui.setError(s),e.onError?.(o)}finally{e.ui.setIsExecuting(!1)}}async function Wc(e,t){if(!e.selectedAsset?.asset)throw new Error("Select a payment source");if(!e.externalWalletAddress||!e.externalWallet)throw new Error("Please connect your external wallet to continue");const n=e.embeddedWalletAddress||e.providerEmbeddedAddress;if(!n)throw new Error("Embedded wallet not available \u2014 sign in to create one before supplying");const o=e.selectedAsset.asset,s=Ke(e.selectedAsset.amount,o.decimals),r=s,i=o?._source==="wallet"&&o.chainId===e.resolvedChainId;let c=await e.gasless.buildSupplyChainBatches();const d={userOverride:n,useCustomTransfers:!0,feeExecutionMode:e.feeExecutionMode};let l=s;const p=e.feeExecutionMode==="user-transfer"&&e.needsSwap&&!e.exactOutputSwap,u=e.feeExecutionMode==="user-transfer"&&!p?r:void 0;let h;if(i){const B=await nt.estimateBatchGas({user:n,outputToken:e.executionTokenAddress,stepIndex:0,chainBatches:c}),F=Vo(s,10n),k=F+B.gasFee;l=s+k,e.feeExecutionMode==="user-transfer"&&(h={grossAmount:l,netAmount:r,combinedFeeAmount:k,feeExecutionMode:e.feeExecutionMode,feeBreakdown:{spicenetFee:F,gasFee:B.gasFee,bridgeFee:0n}})}else{const B=await e.gasless.estimateGasless(c,e.executionTokenAddress,0n,d),F=Qn(B,{chainId:e.resolvedChainId,tokenAddress:e.executionTokenAddress,symbol:Dt(e.executionTokenAddress,e.resolvedChainId)?.symbol??e.destinationToken.symbol,decimals:Dt(e.executionTokenAddress,e.resolvedChainId)?.decimals??e.destinationToken.decimals});F&&(l=F.grossAmount>s?F.grossAmount:s,e.feeExecutionMode==="user-transfer"&&(h={grossAmount:l,netAmount:r,combinedFeeAmount:F.totalFee,feeExecutionMode:e.feeExecutionMode,feeBreakdown:{spicenetFee:F.spicenetFee,gasFee:F.gasFee,bridgeFee:F.bridgeFee??0n}}))}const m=Dt(e.executionTokenAddress,e.resolvedChainId),f=i?l:uo(l,m?.decimals??e.destinationToken.decimals,o.decimals);ia(e,l),c=await e.gasless.buildSupplyChainBatches({fundingAmountOverride:l,sourceFundingAmountOverride:f,withdrawalAmountOverride:l,actionAmountOverride:u,actionContextOverride:h});const y=o.chainId,C=n,v=await e.externalWallet.getEthereumProvider();let b=null;try{const B=await v.request({method:"eth_chainId"});b=parseInt(B,16)}catch{b=null}b!==y&&(e.ui.setStatusMsg("Switching source network..."),await Hn(v,y));const w=Be(y),I=Dn({account:e.externalWalletAddress,chain:w?.viemChain,transport:Nn(v)}),x=It(o.address),S=o.isNative||Ue(x);e.ui.setStatusMsg("Funding embedded wallet...");const A=S?await I.sendTransaction({to:C,value:f,chain:w?.viemChain}):await I.sendTransaction({to:x,data:xt({abi:Ot,functionName:"transfer",args:[C,f]}),chain:w?.viemChain});if((await pt(y).waitForTransactionReceipt({hash:A,timeout:12e4,pollingInterval:2e3,confirmations:1})).status!=="success")throw new Error("Embedded wallet funding failed");e.ui.setStatusMsg("Signing supply intent..."),await e.gasless.executeGasless(c,e.executionTokenAddress,0n,e.gasless.onProgress,t,d)}async function ua(e){if(!e.selectedAsset?.asset)throw new Error("Select a payment source");if(!e.externalWalletAddress||!e.externalWallet)throw new Error("Please connect your external wallet to continue");const t=Ke(e.isPayMode?e.currentPaymentAmount:e.selectedAsset.amount,e.destinationToken.decimals),n={userAddress:e.externalWalletAddress,chainId:e.resolvedChainId,destinationToken:e.destinationToken.address},o=e.buildActionCalls(t,n);if(o.length===0)throw new Error("No action calls configured");const s=await e.externalWallet.getEthereumProvider();let r=null;try{const p=await s.request({method:"eth_chainId"});r=parseInt(p,16)}catch{r=null}r!==e.resolvedChainId&&await Hn(s,e.resolvedChainId);const i=Be(e.resolvedChainId),c=Dn({account:e.externalWalletAddress,chain:i?.viemChain,transport:Nn(s)}),d=pt(e.resolvedChainId);let l;for(const p of o){const u=await c.sendTransaction({to:p.to,data:p.data,value:p.value,chain:i?.viemChain});if((await d.waitForTransactionReceipt({hash:u,timeout:12e4,pollingInterval:2e3,confirmations:1})).status!=="success")throw new Error("Transaction failed");l=u}return l}async function Pc(e){if(!e.selectedAsset?.asset)throw new Error("Select a payment source");if(!e.externalWalletAddress||!e.externalWallet)throw new Error("Please connect your external wallet to continue");const t=e.embeddedWalletAddress||e.providerEmbeddedAddress;if(!t)throw new Error("Embedded wallet not available \u2014 sign in to create one before paying");const n=e.selectedAsset.asset,o=n.chainId,s=Ke(e.currentPaymentAmount,e.destinationToken.decimals),r=e.selectedIsEquivalent?s:e.exactOutputSwap?e.exactOutputSwap.amountInMax:0n;if(r===0n)throw new Error("Quote not available yet");const i=e.resolvedTokenIn||e.selectedAsset.asset.address,c={userOverride:t,useCustomTransfers:!0},d=await e.gasless.estimateRequiredGrossFunding(r,b=>e.gasless.buildPayChainBatches({fundingAmountOverride:b}),i,c),l=wn(o),p=await e.externalWallet.getEthereumProvider();let u=null;try{const b=await p.request({method:"eth_chainId"});u=parseInt(b,16)}catch{u=null}u!==o&&await Hn(p,o);const h=Be(o),m=Dn({account:e.externalWalletAddress,chain:h?.viemChain,transport:Nn(p)}),f=It(n.address),y=n.isNative||Ue(f)?await m.sendTransaction({to:l,value:d,chain:h?.viemChain}):await m.sendTransaction({to:f,data:xt({abi:Ot,functionName:"transfer",args:[l,d]}),chain:h?.viemChain});if((await pt(o).waitForTransactionReceipt({hash:y,timeout:12e4,pollingInterval:2e3,confirmations:1})).status!=="success")throw new Error("Escrow deposit failed");const C=await e.gasless.buildPayChainBatches({fundingAmountOverride:d}),v=C.some(b=>b.tokenTransfers?.length);return await e.gasless.executeGasless(C,i,d,b=>{b.txHash&&(e.ui.setPaymentResult(w=>({...w??{status:"processing"},txHash:b.txHash})),e.ui.setTxHash(b.txHash))},void 0,v?c:{userOverride:t})}async function Uc(e){if(e.parsedAmount<0){e.ui.setError("Enter a valid payment amount");return}if(!e.selectedAsset?.asset){e.ui.setError("Select a payment source");return}if(e.isInsufficientBalance){e.ui.setError("Insufficient balance");return}if(e.parsedAmount>0&&e.needsSwap&&!e.exactOutputSwap){e.ui.setError("Swap quote not available. Try a different asset.");return}if(e.isNon7702){if(!e.externalWalletAddress){e.ui.setError("Please connect your external wallet to continue");return}e.ui.setIsExecuting(!0),e.ui.setError(null),e.ui.setShowStatusPanel(!0),e.ui.setPaymentResult({status:"processing"});try{let t;if(e.isSourceDestToken||e.parsedAmount===0)t=await ua(e);else if(e.onPayExecute&&e.selectedAsset?.asset){const n=e.selectedAsset.asset,o=Ke(e.currentPaymentAmount,e.destinationToken.decimals),s=e.selectedIsEquivalent?o:e.exactOutputSwap?e.exactOutputSwap.amountInMax:0n;if(s===0n)throw new Error("Quote not available yet");const r=e.embeddedWalletAddress||e.providerEmbeddedAddress;if(!r)throw new Error("Embedded wallet not available \u2014 sign in to create one before paying");const i=e.resolvedTokenIn||n.address,c=await e.gasless.estimateRequiredGrossFunding(s,p=>e.gasless.buildPayChainBatches({fundingAmountOverride:p}),i,{userOverride:r,useCustomTransfers:!0}),d=await e.gasless.buildPayChainBatches({fundingAmountOverride:c}),l=await e.onPayExecute({asset:n,amount:e.currentPaymentAmount,amountWei:o,destinationToken:e.destinationToken,chainBatches:d,requiredNetFunding:s,grossFundingAmount:c,selectedIsEquivalent:e.selectedIsEquivalent,resolvedTokenIn:i,exactOutputSwapAmountInMax:e.exactOutputSwap?.amountInMax});l&&(e.ui.setTxHash(l),e.ui.setPaymentResult(p=>({...p??{status:"processing"},txHash:l}))),t=l||void 0}else t=await Pc(e);e.ui.setPaymentResult(n=>({status:"success",txHash:n?.txHash||t||""}))}catch(t){const n=bn(t,"Payment failed. Please try again.");e.ui.setError(n),e.ui.setPaymentResult({status:"failed",error:n}),e.onError?.(t instanceof Error?t:new Error(n))}finally{e.ui.setIsExecuting(!1)}return}if(!e.isConnected||!e.address){e.ui.setError("Please connect your wallet to continue");return}if(!e.ready||!e.authenticated){e.ui.setError(`Please authenticate with ${e.provider||"wallet provider"} to continue`);return}e.ui.setIsExecuting(!0),e.ui.setError(null),e.ui.setShowStatusPanel(!0),e.ui.setPaymentResult({status:"processing"});try{const t=Ke(e.currentPaymentAmount,e.destinationToken.decimals),n=e.resolvedTokenIn||e.selectedAsset?.asset?.address||e.destinationToken.address,o=e.needsSwap?e.exactOutputSwap?.amountInMax??0n:t,s={useCustomTransfers:!0,feeExecutionMode:e.feeExecutionMode},r=e.embeddedWalletAddress||e.providerEmbeddedAddress||e.address,i=await e.gasless.estimateRequiredGrossFunding(o,m=>e.gasless.buildPayChainBatches({fundingAmountOverride:m}).then(f=>rn(_n(f),r)),n,s);let c=i,d=rn(_n(await e.gasless.buildPayChainBatches({fundingAmountOverride:i})),r);const l=await e.gasless.estimateGasless(d,n,i,s),p=Qn(l,{chainId:e.resolvedChainId,tokenAddress:n,symbol:Dt(n,e.resolvedChainId)?.symbol??e.selectedAsset.asset.symbol,decimals:Dt(n,e.resolvedChainId)?.decimals??e.selectedAsset.asset.decimals})?.grossAmount??i;p!==i&&(c=p),d=rn(_n(await e.gasless.buildPayChainBatches({fundingAmountOverride:c})),r,l,{payoutAlreadyGross:!0});const u=d.some(m=>m.tokenTransfers?.length),h=await e.gasless.executeGasless(d,n,u?c:0n,m=>{m.txHash&&(e.ui.setPaymentResult(f=>({...f,txHash:m.txHash})),e.ui.setTxHash(m.txHash))},void 0,s);e.ui.setPaymentResult(m=>({status:"success",txHash:m?.txHash||h}))}catch(t){const n=bn(t,"Payment failed. Please try again.");e.ui.setError(n),e.ui.setPaymentResult({status:"failed",error:n}),e.onError?.(t instanceof Error?t:new Error(n))}finally{e.ui.setIsExecuting(!1)}}const pa=({variant:e,destinationSymbol:t,destinationLogoURI:n,destinationDecimals:o,primaryColor:s,fontFamily:r,textPrimary:i,textSecondary:c,cardBg:d,cardBorder:l,dk:p,dark:u,isQuoting:h,quoteError:m,estimatedOutput:f,paymentAmount:y,needsSwap:C,exactOutputSwap:v,adjustable:b=!1,maxAmount:w,onAmountChange:I})=>e==="supply"?g("div",{style:{backgroundColor:d,border:`1px solid ${l}`,borderRadius:u?"8px":"7px",padding:"14px 16px 12px 16px",marginBottom:"16px",minHeight:"112px",display:"flex",flexDirection:"column",justifyContent:"space-between"},children:[g("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"12px"},children:[g("div",{style:{minWidth:0},children:[a("span",{style:{fontFamily:r,fontSize:"17px",fontWeight:500,color:u?"#a7abb2":"#7D7C7B",lineHeight:"24px"},children:"Used in TX"}),a("div",{style:{fontSize:"12px",fontWeight:500,color:c,fontFamily:r,marginTop:"10px"},children:"Net amount after swap and fees"})]}),g("div",{style:{textAlign:"right",minWidth:0,display:"inline-flex",alignItems:"center",gap:"8px",border:`1px solid ${l}`,borderRadius:"8px",padding:"8px 10px",minHeight:"42px"},children:[a(fa,{symbol:t,logoURI:n,primaryColor:s,size:24}),a("span",{style:{fontSize:"16px",fontWeight:500,color:u?"#f3f4f6":"#3C3E42",lineHeight:"1.3",fontFamily:r,letterSpacing:0},children:t})]})]}),a("div",{style:{textAlign:"right",minWidth:0},children:h?a("span",{style:{fontSize:"18px",color:c,fontFamily:r},children:"Quoting..."}):m?a("span",{style:{fontSize:"13px",color:u?"#f87171":"#dc2626",fontFamily:r},children:"Quote failed"}):f?a(Jn,{value:f,title:f,fontFamily:r,color:i,lineHeight:"0.95",textAlign:"right",maxFontSize:32,minFontSize:18}):a("span",{style:{fontSize:"20px",color:c,fontFamily:r},children:"\u2014"})})]}):a(Lc,{destinationSymbol:t,destinationLogoURI:n,destinationDecimals:o,primaryColor:s,fontFamily:r,textPrimary:i,textSecondary:c,cardBg:d,cardBorder:l,dk:p,dark:u,paymentAmount:y||"0",needsSwap:C,exactOutputSwap:v,isQuoting:h,adjustable:b,maxAmount:w,onAmountChange:I}),fa=({symbol:e,logoURI:t,primaryColor:n,size:o})=>t?a("img",{src:t,alt:e,style:{width:o,height:o,borderRadius:"50%",objectFit:"cover"}}):a("div",{style:{width:o,height:o,borderRadius:"50%",backgroundColor:`${n}22`,display:"flex",alignItems:"center",justifyContent:"center",fontSize:o<30?"11px":"12px",fontWeight:700,color:n},children:e.slice(0,2)}),Lc=({destinationSymbol:e,destinationLogoURI:t,destinationDecimals:n,primaryColor:o,fontFamily:s,textPrimary:r,textSecondary:i,cardBg:c,cardBorder:d,dk:l,dark:p,paymentAmount:u,needsSwap:h,exactOutputSwap:m,isQuoting:f,adjustable:y,maxAmount:C,onAmountChange:v})=>{const b='"IBM Plex Mono", monospace',w=parseFloat(u||"0"),I=C?parseFloat(C):0,[x,S]=R(u||""),A=ie(null),[B,F]=R(null),[k,E]=R(null);X(()=>{y||S(u||"")},[u,y]);const M=N=>{let U=N;U.startsWith(".")&&(U="0"+U);const V=so(U);let D=V;C&&parseFloat(V)>parseFloat(C)&&(D=C),S(D),A.current&&clearTimeout(A.current),A.current=setTimeout(()=>v?.(D),300)},T=N=>{if(!I)return;if(N===100){S(C||I.toString()),A.current&&clearTimeout(A.current),v?.(C||I.toString());return}const U=10**n,V=Math.floor(I*N/100*U)/U,D=ro(V,n);S(D),A.current&&clearTimeout(A.current),v?.(D)},O=I>0?parseFloat(x||"0")/I*100:0;return X(()=>()=>{A.current&&clearTimeout(A.current)},[]),g("div",{style:{backgroundColor:c,border:`1px solid ${d}`,borderRadius:p?"12px":"6px",padding:"16px",marginBottom:"16px"},children:[g("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[g("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[a(fa,{symbol:e,logoURI:t,primaryColor:o,size:32}),g("div",{children:[a("span",{style:{fontSize:"14px",fontWeight:600,color:r,fontFamily:s},children:"Payment"}),a("div",{style:{fontSize:"12px",color:i,fontFamily:s,marginTop:"2px"},children:e})]})]}),g("div",{style:{textAlign:"right"},children:[y?a(Jn,{element:"input",ariaLabel:`${e} amount`,dataSpiceflowFocus:!0,value:x,onChange:N=>M(N.target.value),placeholder:"0.0",fontFamily:b,color:r,lineHeight:1.1,textAlign:"right",maxFontSize:20,minFontSize:12,style:{width:"120px"}}):a(Jn,{element:"div",value:w>0?u:"0.00",title:w>0?u:"0.00",fontFamily:b,color:r,lineHeight:1.1,textAlign:"right",maxFontSize:20,minFontSize:12}),a("div",{style:{fontSize:"12px",color:i,fontFamily:b,marginTop:"2px"},children:e}),y&&I>0&&a("div",{style:{display:"flex",justifyContent:"flex-end",alignItems:"center",gap:"10px",marginTop:"6px"},children:[0,25,50,75,100].map((N,U)=>{const V=Math.abs(O-N)<1,D=U===4,Q=N/100,P=B===N,j=k===N;return a("button",{onClick:()=>T(N),onMouseEnter:()=>F(N),onMouseLeave:()=>{F(null),E(null)},onMouseDown:()=>E(N),onMouseUp:()=>E(null),title:`${N}%`,style:{width:"14px",height:"14px",padding:0,border:"none",backgroundColor:"transparent",cursor:"pointer",opacity:V?1:P?.8:.5,transform:j?"scale(0.85)":P?"scale(1.15)":"scale(1)",transition:sn.interactive},children:g("svg",{width:"14",height:"14",viewBox:"0 0 14 14",children:[a("circle",{cx:"7",cy:"7",r:"6.84375",fill:D?o:"none",stroke:D?o:p?"#4a5568":"#3C3E42",strokeWidth:"0.3125"}),!D&&Q>0&&a("path",{d:`M 7 7 L 7 0.15625 A 6.84375 6.84375 0 ${Q>.5?1:0} 1 ${7+6.84375*Math.sin(Q*2*Math.PI)} ${7-6.84375*Math.cos(Q*2*Math.PI)} Z`,fill:p?l?.textSecondary||"#9ca3af":"#3C3E42"})]})},N)})})]})]}),h&&m&&!f&&a("div",{style:{marginTop:"12px",paddingTop:"12px",borderTop:p?`1px solid ${l?.cardBorder||d}`:"1px solid #e5e7eb",display:"flex",justifyContent:"flex-end"},children:g("span",{style:{fontSize:"11px",color:i,fontFamily:s,opacity:.7},children:["via ",m.venue]})})]})};function ha(e,t,n){const o=Se(e.address,t),s=e.chainId===n,r=e._source==="wallet";return r&&o&&s?0:r&&s?1:!r&&o?2:!r&&s?3:4}function zc(e,t){return!t||t.length===0||t.some(n=>Se(n,e.address))?!0:Object.keys(e.chainTokens??{}).some(n=>{const o=co(n);return o?t.some(s=>Se(s,o.address)):!1})}function Oc(e){const{destinationToken:t,supportedSourceAssets:n,sourceChains:o,enabled:s}=e,r=(Gt(Lt)?.mode||"7702")!=="7702",i=Bn(),{externalAddress:c,embeddedAddress:d}=no(),l=i||d,{assets:p,refetch:u}=Eo({address:l,supportedChains:o,enabled:s&&!r&&!!l,refetchInterval:3e4}),h=re(()=>r?[]:p.filter(A=>zc(A,n)),[p,n,r]),m=r?c:i,f=re(()=>{const A=new Set,B=[],F=k=>{if(!k)return;const E=k.toLowerCase();A.has(E)||(A.add(E),B.push(Ne(k)))};if(F(t.address),r&&n)for(const k of n)F(k);return B},[r,t.address,n]),y=re(()=>f.map(A=>A.toLowerCase()).sort().join(","),[f]),C=re(()=>JSON.stringify([...o||[]].sort()),[o]),[v,b]=R([]),w=ie(0),I=ie(async()=>{}),x=ce(async()=>{if(!s||!m||f.length===0){w.current++,b([]);return}const A=++w.current,B=Ne(m),F=r?o&&o.length>0?o:[t.chainId]:[t.chainId],k=[];for(const O of f){const N=O.toLowerCase();if(N===zt)continue;if(N===t.address.toLowerCase()){const V=Be(t.chainId)?.supportedTokens?.find(D=>Se(D.address,N));k.push({address:O,chainId:t.chainId,configToken:V?{decimals:V.decimals,symbol:V.symbol,name:V.name,logo:V.logo}:void 0});continue}let U=!1;for(const V of F){const D=Be(V)?.supportedTokens?.find(Q=>Se(Q.address,N));if(D){k.push({address:O,chainId:V,configToken:{decimals:D.decimals,symbol:D.symbol,name:D.name,logo:D.logo}}),U=!0;break}}U||k.push({address:O,chainId:t.chainId})}const E=new Map;for(const O of k){const N=E.get(O.chainId)||[];N.push(O),E.set(O.chainId,N)}const M=async(O,N)=>{try{const U=await kn(O,{address:N.address,abi:Ot,functionName:"balanceOf",args:[B]});let V,D,Q,P;if(N.configToken)V=N.configToken.decimals,D=N.configToken.symbol,Q=N.configToken.name,P=N.configToken.logo;else{const[Z,ge,W]=await Promise.all([kn(O,{address:N.address,abi:Ot,functionName:"decimals"}).catch(()=>18),kn(O,{address:N.address,abi:Ot,functionName:"symbol"}).catch(()=>"TOKEN"),kn(O,{address:N.address,abi:Ot,functionName:"name"}).catch(()=>"TOKEN")]);V=Number(Z),D=ge,Q=W}const j=Se(N.address,t.address)&&N.chainId===t.chainId;j&&t.logoURI&&(P=t.logoURI),j&&!N.configToken&&D==="TOKEN"&&(D=t.symbol,Q=t.symbol);const L=parseFloat((Number(U)/Math.pow(10,V)).toFixed(6));return{address:N.address,name:Q,symbol:D,decimals:V,balance:U,balanceFormatted:L,balanceUsd:0,logoURI:P,isNative:!1,chainId:N.chainId}}catch{return null}},T=await Promise.all(Array.from(E.entries()).map(async([O,N])=>{let U;try{U=pt(O)}catch{return[]}const V=[],D=[];for(const P of N){const j=V.length;V.push({address:P.address,abi:Ot,functionName:"balanceOf",args:[B]}),P.configToken||V.push({address:P.address,abi:Ot,functionName:"decimals"},{address:P.address,abi:Ot,functionName:"symbol"},{address:P.address,abi:Ot,functionName:"name"}),D.push({start:j,item:P})}let Q=null;try{Q=await U.multicall({contracts:V})}catch{Q=null}return Q?D.map(({start:P,item:j})=>{const L=Q[P],Z=L?.status==="success"?L.result:0n;let ge,W,_,fe;if(j.configToken)ge=j.configToken.decimals,W=j.configToken.symbol,_=j.configToken.name,fe=j.configToken.logo;else{const he=Q[P+1],xe=Q[P+2],H=Q[P+3];ge=he?.status==="success"?Number(he.result):18,W=xe?.status==="success"?xe.result:"TOKEN",_=H?.status==="success"?H.result:W}const be=Se(j.address,t.address)&&j.chainId===t.chainId;be&&t.logoURI&&(fe=t.logoURI),be&&!j.configToken&&W==="TOKEN"&&(W=t.symbol,_=t.symbol);const Me=parseFloat((Number(Z)/Math.pow(10,ge)).toFixed(6));return{address:j.address,name:_,symbol:W,decimals:ge,balance:Z,balanceFormatted:Me,balanceUsd:0,logoURI:fe,isNative:!1,chainId:j.chainId}}):(await Promise.all(N.map(P=>M(U,P)))).filter(P=>P!==null)}));A===w.current&&b(T.flat())},[s,r,m,y,C,t.address,t.chainId,t.symbol,t.logoURI]);X(()=>{I.current=x},[x]),X(()=>{if(!s){b([]);return}I.current();const A=setInterval(()=>{I.current()},15e3);return()=>clearInterval(A)},[s,r,m,y,C,t.address,t.chainId]);const S=ce(()=>{x()},[x]);return{displayAssets:re(()=>{const A=[],B=v.filter(k=>k.balance>0n);for(const k of B)A.push({...k,_source:"wallet"});for(const k of h)A.push({...k,_source:"spice"});const F=t.address.toLowerCase();return A.sort((k,E)=>ha(k,F,t.chainId)-ha(E,F,t.chainId)),A},[v,h,t.address,t.chainId]),filteredSpiceAssets:h,walletAssets:v,embeddedWalletAddress:l,externalAddress:c,isNon7702:r,refreshSpiceAssets:u,refreshWalletAssets:S}}async function ma(e){const{tokenIn:t,tokenOut:n,amountIn:o,fee:s,chainId:r,config:i}=e;if(o<=0n)throw new Error("amountIn must be greater than 0");const c=(await pt(r).simulateContract({address:i.quoterV2,abi:ti,functionName:"quoteExactInputSingle",args:[{tokenIn:t,tokenOut:n,amountIn:o,fee:s,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 ga(e){const t=e.feeTiers??[100,500,3e3,1e4],n=await Promise.allSettled(t.map(s=>ma({...e,fee:s})));let o=null;for(let s=0;s<n.length;s++){const r=n[s];r.status==="fulfilled"&&(!o||r.value.amountOut>o.amountOut)&&(o={...r.value,fee:t[s]})}if(!o)throw new Error("No liquidity found for this pair on any fee tier.");return o}const Hc=[{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 jc(e){const{tokenIn:t,tokenOut:n,amountOut:o,fee:s,chainId:r,config:i}=e;if(o<=0n)throw new Error("amountOut must be greater than 0");const c=(await pt(r).simulateContract({address:i.quoterV2,abi:Hc,functionName:"quoteExactOutputSingle",args:[{tokenIn:t,tokenOut:n,amount:o,fee:s,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 Qc(e){const t=e.feeTiers??[100,500,3e3,1e4],n=await Promise.allSettled(t.map(s=>jc({...e,fee:s})));let o=null;for(let s=0;s<n.length;s++){const r=n[s];r.status==="fulfilled"&&(!o||r.value.amountIn<o.amountIn)&&(o={...r.value,fee:t[s]})}if(!o)throw new Error("No liquidity found for this pair on any fee tier.");return o}function ya(e){return e.type==="swap"}const Vs=.02,Vc=[1,8453,42161,10,137,43114,56],qc="https://api.1inch.dev/swap/v6.0";function xa(e,t){return oi(e,t)}function ba(e){const t=e?.baseUrl??qc;return{name:"1inch",chainIds:e?.chainIds??Vc,resolve:async(n,o,s)=>{const r=n.maxSlippage??Vs,i=r*100,c=Ue(n.tokenIn)?or:n.tokenIn,d=Ue(n.tokenOut)?or:n.tokenOut,l=Ue(n.tokenIn);try{const p=new URL(`${t}/${o}/swap`);p.searchParams.set("src",c),p.searchParams.set("dst",d),p.searchParams.set("amount",n.amountIn.toString()),p.searchParams.set("from",s),p.searchParams.set("slippage",i.toString()),p.searchParams.set("disableEstimate","true"),p.searchParams.set("allowPartialFill","false");const u={Accept:"application/json"};e?.apiKey&&(u.Authorization=`Bearer ${e.apiKey}`);const h=await fetch(p.toString(),{headers:u});if(!h.ok)throw new Te("VENUE_API_ERROR",`[1inchVenue] API returned ${h.status} for ${n.tokenIn} \u2192 ${n.tokenOut} on chain ${o}`,{venue:"1inch",chainId:o,tokenIn:n.tokenIn,tokenOut:n.tokenOut,amountIn:n.amountIn.toString(),cause:`HTTP ${h.status}`});const m=await h.json();if(!m.dstAmount||!m.tx)return console.warn(`[1inchVenue] No route data for ${n.tokenIn} \u2192 ${n.tokenOut} on chain ${o}`),null;const f=BigInt(m.dstAmount);if(f<=0n)return console.warn(`[1inchVenue] Zero output for ${n.tokenIn} \u2192 ${n.tokenOut} on chain ${o}`),null;const y=xa(f,r),C=[];return m.tx.to&&!l&&C.push({to:n.tokenIn,value:0n,data:xt({abi:Ot,functionName:"approve",args:[m.tx.to,n.amountIn]})}),C.push({to:m.tx.to,value:BigInt(m.tx.value||"0"),data:m.tx.data}),{venue:"1inch",amountOut:f,amountOutMinimum:y,calls:C}}catch(p){if(p instanceof Te)throw p;const u=p instanceof Error?p.message:String(p);throw new Te("VENUE_API_ERROR",`[1inchVenue] Exception for ${n.tokenIn} \u2192 ${n.tokenOut} on chain ${o}: ${u}`,{venue:"1inch",chainId:o,tokenIn:n.tokenIn,tokenOut:n.tokenOut,amountIn:n.amountIn.toString(),cause:u})}}}}const wa=[4114,5115],qs={swapRouter:"0x565eD3D57fe40f78A46f348C220121AE093c3cF8",quoterV2:"0x428f20dd8926Eabe19653815Ed0BE7D6c36f8425",feeTiers:[3e3]},Ca={swapRouter:"0x2626664c2603336E57B271c5C0b26F421741e481",quoterV2:"0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a",chainIds:[8453],feeTiers:[3e3]};function ka(e){return{name:"satsuma",chainIds:e.chainIds??wa,resolve:async(t,n,o)=>{const s=t.maxSlippage??Vs,r=Ue(t.tokenIn);let i;try{i=await ga({tokenIn:t.tokenIn,tokenOut:t.tokenOut,amountIn:t.amountIn,chainId:n,config:{swapRouter:e.swapRouter,quoterV2:e.quoterV2},feeTiers:e.feeTiers})}catch{return console.warn(`[SatsumaVenue] No viable fee tier for ${t.tokenIn} \u2192 ${t.tokenOut} on chain ${n}.`),null}const c=xa(i.amountOut,s),d=[];return r||d.push({to:t.tokenIn,value:0n,data:xt({abi:Ot,functionName:"approve",args:[e.swapRouter,t.amountIn]})}),d.push({to:e.swapRouter,value:r?t.amountIn:0n,data:xt({abi:ni,functionName:"exactInputSingle",args:[{tokenIn:t.tokenIn,tokenOut:t.tokenOut,fee:i.fee,recipient:o,amountIn:t.amountIn,amountOutMinimum:c,sqrtPriceLimitX96:0n}]})}),{venue:"satsuma",amountOut:i.amountOut,amountOutMinimum:c,calls:d}}}}function va(e){return{name:"satsuma",chainIds:e.chainIds??wa,resolve:async(t,n,o)=>{const s=t.maxSlippage??Vs,r=Ue(t.tokenIn);let i;try{i=await Qc({tokenIn:t.tokenIn,tokenOut:t.tokenOut,amountOut:t.amountOut,chainId:n,config:{swapRouter:e.swapRouter,quoterV2:e.quoterV2},feeTiers:e.feeTiers})}catch{return null}const c=BigInt(Math.round(s*1e4)),d=i.amountIn+i.amountIn*c/10000n,l=[];return l.push({to:e.swapRouter,value:r?d:0n,data:xt({abi:Kc,functionName:"exactOutputSingle",args:[{tokenIn:t.tokenIn,tokenOut:t.tokenOut,fee:i.fee,recipient:o,amountOut:t.amountOut,amountInMaximum:d,sqrtPriceLimitX96:0n}]})}),{venue:"satsuma",amountIn:i.amountIn,amountInMax:d,amountOut:t.amountOut,calls:l}}}}const Kc=[{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 Ia(e){const t=[];e?.customVenues&&t.push(...e.customVenues),e?.satsuma&&t.push(ka(e.satsuma)),t.push(ba(e?.oneInch));function n(s){return t.find(r=>r.chainIds.includes(s))}async function o(s,r,i){const c=[],d=[];for(const l of s){if(!ya(l)){c.push(l);continue}const p=n(r);if(!p)throw new Te("NO_VENUE_FOR_CHAIN",`No liquidity venue configured for chain ${r}. Cannot resolve swap ${l.tokenIn} \u2192 ${l.tokenOut}.`,{chainId:r,tokenIn:l.tokenIn,tokenOut:l.tokenOut,amountIn:l.amountIn.toString()});const u=await p.resolve(l,r,i);if(!u)throw new Te("NO_LIQUIDITY",`${p.name} returned no quote for ${l.tokenIn} \u2192 ${l.tokenOut} on chain ${r}.`,{venue:p.name,chainId:r,tokenIn:l.tokenIn,tokenOut:l.tokenOut,amountIn:l.amountIn.toString()});c.push(...u.calls),d.push(u)}return{calls:c,resolvedSwaps:d}}return{resolveSwapIntents:o,getVenueForChain:n,venues:t}}function Yc(e){const t=e?.customVenues??[];async function n(o,s,r){const i=t.filter(d=>d.chainIds.includes(s));if(i.length===0)throw new Te("NO_SWAP_ROUTE",`No exact-output venue supports chain ${s}`,{chainId:s,tokenIn:o.tokenIn,tokenOut:o.tokenOut});const c=(await Promise.allSettled(i.map(d=>d.resolve(o,s,r)))).filter(d=>d.status==="fulfilled").map(d=>d.value).filter(d=>d!==null);if(c.length===0)throw new Te("NO_SWAP_ROUTE",`All aggregators failed for ${o.tokenIn} \u2192 ${o.tokenOut} on chain ${s}`,{chainId:s,tokenIn:o.tokenIn,tokenOut:o.tokenOut,amountOut:o.amountOut.toString()});return c.sort((d,l)=>d.amountIn<l.amountIn?-1:d.amountIn>l.amountIn?1:0),c[0]}return{getQuote:n,venues:t}}const Zc=Ia({satsuma:qs});function Gc(e){const{direction:t,selectedAsset:n,destinationToken:o,chainId:s,recipient:r,paymentAmount:i}=e,[c,d]=R(!1),[l,p]=R(null),[u,h]=R(null),[m,f]=R(null),[y,C]=R(null),[v,b]=R(null),[w,I]=R(null),[x,S]=R(null),[A,B]=R(null),F=ie(null),k=ie(null),E=ie(0),M=ie(new Map),T=re(()=>Zc,[]),O=re(()=>Yc({customVenues:[va(qs),va(Ca)]}),[]),N=re(()=>{if(!n?.asset)return null;const W=Mn(n.asset,s);if(W)return W;const _=zn(n.asset.address,s,n.asset.chainId);return _?_.address:null},[n?.asset,s]),U=re(()=>n?.asset?Ho(n.asset,s):[],[n?.asset,s]),V=re(()=>U.map(W=>W.toLowerCase()).join(","),[U]);X(()=>{let W=!1;if(k.current&&(clearTimeout(k.current),k.current=null),!n?.asset||U.length<=1){B(null);return}return k.current=setTimeout(async()=>{const _=t==="input"?n.amount:i||"0";let fe=0n;try{fe=t==="input"?Ke(_,n.asset.decimals):0n}catch{fe=0n}try{const be=await Wr(n.asset,s,{requiredAmount:fe});W||B(be)}catch{W||B(null)}},400),()=>{W=!0,k.current&&(clearTimeout(k.current),k.current=null)}},[n?.asset,n?.amount,s,U.length,V,t,i]);const D=re(()=>A??N,[A,N]),Q=re(()=>!n?.asset||!D?[]:[D,...U.filter(W=>W.toLowerCase()!==D.toLowerCase())],[n?.asset,D,U]),P=re(()=>!n?.asset||!So(n.asset.address,n.asset.chainId,o.address,o.chainId)||!D?!1:Se(D,o.address),[n,o.address,o.chainId,D]),j=D?Se(D,o.address):!1,L=t==="output"&&parseFloat(i||"0")===0,Z=!!n?.asset&&!P&&!j&&!L,ge=Z?x??D:D;return X(()=>{F.current&&clearTimeout(F.current);const W=t==="input"?n?.amount:i,_=parseFloat(W||"0");if(!Z||!Number.isFinite(_)||_<=0||!n?.asset||!r||Q.length===0){E.current++,h(null),f(null),C(null),b(null),I(null),S(null),p(null),d(!1);return}const fe=n.asset.decimals;let be;try{be=t==="input"?Ke(n.amount,fe):Ke(i||"0",o.decimals)}catch{E.current++,p("Invalid amount"),d(!1);return}const Me=++E.current,he=()=>Me!==E.current;d(!0);const xe=t==="output"?150:400;return F.current=setTimeout(async()=>{try{if(t==="input"){const H=T.getVenueForChain(s);if(!H)throw new Error("No swap venue for this chain");let se=null,K=null;for(const ye of Q){const Ee=`${t}:${s}:${ye.toLowerCase()}:${o.address.toLowerCase()}:${be.toString()}`,ee=M.current.get(Ee);if(ee&&ee.expiresAt>Date.now()&&ee.resolvedSwap){se=ee.resolvedSwap,K=ye;break}const z=await H.resolve({type:"swap",tokenIn:ye,tokenOut:o.address,amountIn:be},s,r);if(he())return;if(z){M.current.set(Ee,{expiresAt:Date.now()+3e4,direction:t,resolvedSwap:z}),se=z,K=ye;break}}if(!se||!K)throw new Error("No liquidity for this pair");S(K),I(se.amountOut),C(se),b(null);const le=parseFloat(rt(se.amountOut,o.decimals));h(le<.01?le.toPrecision(4):le.toLocaleString(void 0,{maximumFractionDigits:6})),f(null),p(null)}else{let H=null,se=null;for(const K of Q){const le=`${t}:${s}:${K.toLowerCase()}:${o.address.toLowerCase()}:${be.toString()}`,ye=M.current.get(le);if(ye&&ye.expiresAt>Date.now()&&ye.exactOutputSwap){H=ye.exactOutputSwap,se=K;break}try{const Ee=await O.getQuote({tokenIn:K,tokenOut:o.address,amountOut:be},s,r);if(he())return;M.current.set(le,{expiresAt:Date.now()+3e4,direction:t,exactOutputSwap:Ee}),H=Ee,se=K;break}catch{if(he())return}}if(!H||!se)throw new Error("No liquidity for this pair");S(se),b(H),C(null),I(null),f(parseFloat(rt(H.amountIn,fe)).toFixed(6)),h(null),p(null)}}catch(H){if(he())return;const se=H instanceof Error?H.message:"Failed to get quote";p(se),h(null),f(null),C(null),b(null),I(null),S(null)}finally{he()||d(!1)}},xe),()=>{F.current&&clearTimeout(F.current)}},[t,Z,n?.amount,n?.asset?.address,n?.asset?.decimals,i,Q,s,o.address,o.decimals,r,T,O]),{isQuoting:c,quoteError:l,estimatedOutput:u,estimatedInput:m,resolvedSwap:y,exactOutputSwap:v,quoteAmountOut:w,resolvedTokenIn:ge,isDirect:j,needsSwap:Z,selectedIsEquivalent:P}}const Aa={idle:"","signing-delegation":"Signing delegation...","signing-intent":"Signing intent...",submitting:"Submitting transaction...",executing:"Executing on-chain...",success:"Deposit confirmed",error:"Transaction failed"},Sa=["signing-delegation","signing-intent","submitting","executing"],Ea=({isOpen:e,onClose:t,closeOnBackdropClick:n=!1,destinationToken:o,sourceChains:s,supportedSourceAssets:r,buildActionCalls:i,feeExecutionMode:c="user-transfer",buildSpicenetBatch:d,onPayExecute:l,actionLabel:p,amountDirection:u="input",swapDescription:h,directDescription:m,paymentAmount:f,amountInputMode:y="fixed",minPaymentAmount:C,maxPaymentAmount:v,onAmountChange:b,styles:w,dark:I,title:x,subtitle:S,onAddFunds:A,onSuccess:B,onError:F})=>{const k=u==="output",{theme:E,dark:M,primaryColor:T,dk:O,palette:N,fontFamily:U,monoFont:V,inputDark:D,cardBg:Q,cardBorder:P,textPrimary:j,textSecondary:L,subtitleText:Z}=ut(w,I),ge=D?{...E,colors:{...E.colors,secondary:O.cardBg,surfaceHover:O.hoverBg,border:"#2d2d2d",borderHover:"#3a3a3a"}}:E,W=o.chainId,_=Gt(Lt),fe=(_?.mode||"7702")!=="7702",be=!!_?.isWhitelistGateActive,Me=re(()=>s??_?.supportedChainIds??[],[s,_?.supportedChainIds]),he=re(()=>{if(be)return[];if(r)return r;const pe=_?.allowedTokens;if(!pe||pe.length===0)return;const Pe=new Set(pe.map(xn=>xn.toLowerCase())),Pt=[],En=new Set;for(const xn of Me){const fo=Be(xn);for(const Zn of fo?.supportedTokens??[]){if(!Pe.has(Zn.symbol.toLowerCase()))continue;const ho=Zn.address.toLowerCase();En.has(ho)||(En.add(ho),Pt.push(Zn.address))}}return Pt},[r,_?.allowedTokens,Me,be]),xe=Fn(),{address:H,isConnected:se,isReady:K,isAuthenticated:le,provider:ye}=xe,{executeGasless:Ee,estimateGasless:ee}=Zo(),{externalWallet:z,externalAddress:ae,embeddedAddress:we}=no(),Le=Bn()||we,{displayAssets:wt,filteredSpiceAssets:at,embeddedWalletAddress:it,refreshSpiceAssets:Re,refreshWalletAssets:oe}=Oc({destinationToken:o,supportedSourceAssets:he,sourceChains:Me,enabled:e&&(fe?!!ae:!!Le)}),je=be||k||fe?wt:at,[Y,ke]=R(null),[St,Rt]=R(f||""),[lt,an]=R(!1),[Xt,Nt]=R(null),[Ie,Jt]=R("idle"),[In,An]=R(""),[Ut,ln]=R(null),[ct,jt]=R(!1),[_e,ft]=R(null),[ht,Bt]=R(null),[Kt,me]=R(!1),[bt,Ct]=R(!1),[Qt,Ce]=R(null),$t=ie(Y),mt=ie(!1),Tt=ie(null),Vt=ie(0),mn=ie(null),cn=ie(null);X(()=>{$t.current=Y},[Y]);const dt=y==="adjustable"?St:f||"0",gn=it||we||H,{isQuoting:ze,quoteError:Et,estimatedOutput:qt,resolvedSwap:Ge,exactOutputSwap:ot,quoteAmountOut:Yt,resolvedTokenIn:vt,isDirect:Oe,needsSwap:Xe,selectedIsEquivalent:Mt}=Gc({direction:u,selectedAsset:Y,destinationToken:o,chainId:W,recipient:gn,paymentAmount:dt}),gt=k?parseFloat(dt||"0"):parseFloat(Y?.amount||"")||0,dn=Y?.asset?._source==="wallet",Qe=!!Y?.asset&&dn&&Y.asset.chainId!==W,yn=re(()=>Y?.asset?at.find(pe=>Se(pe.address,Y.asset.address))?.balanceFormatted??0:0,[Y,at]),un=dn?Y?.asset.balanceFormatted??0:yn,_t=re(()=>{if(!Y?.asset)return!1;if(k)return ht?uo(ht.grossAmount,ht.decimals,Y.asset.decimals)>Y.asset.balance:Mt||Oe?gt>Y.asset.balanceFormatted:ot?parseFloat(rt(ot.amountInMax,Y.asset.decimals))>Y.asset.balanceFormatted:!1;if(ht){const pe=uo(ht.grossAmount,ht.decimals,Y.asset.decimals);return dn?pe>Y.asset.balance:parseFloat(rt(pe,Y.asset.decimals))>un}return gt>un},[Y,k,ht,Mt,gt,ot,un,dn,Oe]);X(()=>{e||(ke(null),Nt(null),an(!1),Jt("idle"),An(""),ln(null),jt(!1),ft(null),Bt(null),me(!1),Ct(!1),Ce(null),mt.current=!1,y==="adjustable"&&Rt(f||""),Tt.current&&(Tt.current.abort(),Tt.current=null))},[e]);const te=ce(pe=>{ke(Pe=>({asset:pe,amount:Pe?.asset?.address===pe.address&&Pe?.asset?.chainId===pe.chainId&&Pe.amount||""})),Nt(null),Ce(null),Ct(!1)},[]),ne=ce(pe=>{ke(Pe=>Pe&&{...Pe,amount:pe}),Nt(null),Ce(null),Ct(!1)},[]),Ae=ce(pe=>{let Pe=pe;v&&parseFloat(Pe)>parseFloat(v)&&(Pe=v),Rt(Pe),b?.(Pe),Nt(null),Ce(null),Ct(!1)},[v,b]);ce(pe=>{if(mt.current||!H)return;const Pe=$t.current;!Pe?.asset||!Pe.amount||Pe.asset?._source==="wallet"||Ke(k?dt:Pe.amount,Pe.asset.decimals)===0n||(mt.current=!0,Re())},[H,W,Re,k,dt]);const Je=ce(pe=>{Jt({building:"signing-delegation","signing-delegation":"signing-delegation","signing-intent":"signing-intent",submitting:"submitting",executing:"executing",success:"success",error:"error"}[pe.step]||"executing"),An(pe.message),pe.txHash&&ln(pe.txHash)},[]),st=re(()=>({currentPaymentAmount:dt,destinationToken:o,embeddedWalletAddress:it,providerEmbeddedAddress:we,externalWalletAddress:ae,address:H,isNon7702:fe,isPayMode:k,resolvedChainId:W,buildActionCalls:i,feeExecutionMode:c,buildSpicenetBatch:d,selectedAsset:Y,needsSwap:Xe,resolvedSwap:Ge,exactOutputSwap:ot,quoteAmountOut:Yt,resolvedTokenIn:vt}),[dt,o,it,we,ae,H,fe,k,W,i,c,d,Y,Xe,Ge,ot,Yt,vt]),et=ce(pe=>Ic(st,pe),[st]),$e=ce(pe=>Ac(st,pe),[st]),Ve=ce((pe,Pe,Pt,En)=>Sc(pe,Pe,Pt,ee,En),[ee]),qe=re(()=>Y?.asset?Xe&&vt?vt:Y.asset.chainId===W?Y.asset.address:vt??Mn(Y.asset,W)??o.address:o.address,[Y,o.address,Xe,W,vt]),G=ce(()=>Nc(cn.current),[]),ue=re(()=>Y?.asset?Se(Y.asset.address,o.address)&&Y.asset.chainId===o.chainId:!1,[Y,o.address,o.chainId]),We=fe&&ue,De=We&&gt>0&&!!Y?.asset,Ye=Xt,Ft=re(()=>!(!Y?.asset||gt<=0),[Y,gt,De]),pn=re(()=>!e||lt||Ie!=="idle"||!Ft||De||!Y?.asset?null:[k?"pay":"supply",u,Y.asset.address.toLowerCase(),Y.asset.chainId,Y.amount,dt,o.address.toLowerCase(),o.chainId,W,vt?.toLowerCase()??"",Xe?"swap":"direct",Oe?"direct-token":"routed-token",fe?"non7702":"7702",ue?"source-dest":"cross-chain",ze?"quoting":"quoted",ot?.amountIn?.toString()??"",ot?.amountInMax?.toString()??"",ot?.venue??"",Ge?.amountOut?.toString()??"",Yt?.toString()??"",it??"",we??"",H??""].join("|"),[e,lt,Ie,Ft,De,Y,k,u,dt,o,W,vt,Xe,Oe,fe,ue,ze,ot,Ge,Yt,it,we,H]),q=ce(()=>Tc({selectedAsset:Y,isPayMode:k,parsedAmount:gt,needsSwap:Xe,exactOutputSwap:ot,isNon7702:fe,isSourceDestToken:ue,currentPaymentAmount:dt,destinationToken:o,feeExecutionMode:c,resolvedTokenIn:vt,embeddedWalletAddress:it,providerEmbeddedAddress:we,resolvedChainId:W,isConnected:se,address:H,ready:K,authenticated:le,isDirect:Oe,resolvedSwap:Ge,isQuoting:ze,executionTokenAddress:qe,buildPayChainBatches:et,buildSupplyChainBatches:$e,estimateGasless:ee,estimateRequiredGrossFunding:Ve}),[Y,k,gt,Xe,ot,fe,ue,dt,o,c,vt,it,we,Ve,et,ee,W,se,H,K,le,Oe,Ge,ze,$e,qe]);X(()=>{mn.current=q},[q]);const $=ce(pe=>Bc({asset:pe,isPayMode:k,isNon7702:fe,needsSwap:Xe,isQuoting:ze,embeddedWalletAddress:it,buildSupplyChainBatches:$e,estimateGasless:ee,executionTokenAddress:qe,feeExecutionMode:c}),[k,fe,Xe,ze,it,$e,ee,qe,c]);X(()=>{if(!e){me(!1),Ct(!1),Ce(null),Bt(null);return}if(lt||Ie!=="idle"){Vt.current+=1,me(!1);return}if(!Ft){Bt(null),me(!1),Ct(!1),Ce(null);return}if(De){Bt(null),me(!1),Ct(!0),Ce(null);return}if(ze){Vt.current+=1,me(!1),Ct(!1);return}if(!pn)return;let pe=!1;const Pe=async()=>{const En=++Vt.current;Ce(null),me(!0);try{const xn=await mn.current?.();if(pe||Vt.current!==En)return;xn?(Bt(xn),Ct(!0)):(Bt(null),Ct(!1)),Ce(null)}catch(xn){if(pe||Vt.current!==En)return;const fo=bn(xn,"Unable to calculate fees for this action.");Bt(null),Ct(!1),Ce(fo)}finally{!pe&&Vt.current===En&&me(!1)}},Pt=window.setTimeout(()=>{Pe()},250);return()=>{pe=!0,clearTimeout(Pt),me(!1)}},[e,lt,Ie,Ft,De,ze,pn]);const de=ce(()=>Uc(cn.current),[]);X(()=>{!k&&Ie==="success"&&Ut&&(Re(),B?.(Ut))},[k,Ie,Ut,Re,B]),X(()=>{if(!k||_e?.status!=="success"||mt.current||!H)return;mt.current=!0;const pe=$t.current;!pe?.asset||pe.asset?._source==="wallet"||Re()},[k,_e?.status,H,Re]);const J=ie(B),Fe=ie(F);X(()=>{J.current=B},[B]),X(()=>{Fe.current=F},[F]),X(()=>{e&&(Re(),oe())},[e,Re,oe]),X(()=>{k&&(_e?.status==="success"&&J.current?.(_e.txHash||""),_e?.status==="failed"&&Fe.current?.(new Error("Payment execution failed")))},[k,_e?.status]);const He=ce(()=>{jt(!1),ft(null),ke(null),mt.current=!1,Re(),oe()},[Re,oe]);cn.current={selectedAsset:Y,parsedAmount:gt,currentPaymentAmount:dt,isInsufficientBalance:_t,isPayMode:k,isNon7702:fe,isSourceDestToken:ue,needsSwap:Xe,exactOutputSwap:ot,selectedIsEquivalent:Mt,resolvedTokenIn:vt,embeddedWalletAddress:it,providerEmbeddedAddress:we,externalWallet:z,externalWalletAddress:ae,address:H,isConnected:se,ready:K,authenticated:le,provider:ye,resolvedChainId:W,executionTokenAddress:qe,destinationToken:o,buildActionCalls:i,feeExecutionMode:c,buildSpicenetBatch:d,onPayExecute:l,onError:F,gasless:{estimateGasless:ee,executeGasless:Ee,buildPayChainBatches:et,buildSupplyChainBatches:$e,estimateRequiredGrossFunding:Ve,onProgress:Je},ui:{setError:Nt,setStep:Jt,setStatusMsg:An,setTxHash:ln,setIsExecuting:an,setShowStatusPanel:jt,setPaymentResult:ft},refs:{spiceDepositSubmittedRef:mt,abortControllerRef:Tt}};const yt=k&&gt===0,tt=k?!!Y?.asset&&gt>=0&&!_t&&!lt&&(yt||De||bt)&&!Qt&&(yt||!Xe||!!ot):!!Y?.asset&&gt>0&&!_t&&!lt&&(We||bt)&&!Qt&&(Qe||Oe||!!Ge&&!ze),kt=Oe?m||`Your ${o.symbol} will be used directly.`:h||"Your assets will be swapped and used in a single atomic transaction.",Zt=(W?Be(W):void 0)?.viemChain?.blockExplorers?.default?.url??"",Wt=Sa.indexOf(Ie),en=lt?(Aa[Ie]||"EXECUTING...").toUpperCase():Ie==="success"?"DONE":_t?"INSUFFICIENT BALANCE":p.toUpperCase(),tn=re(()=>{if(lt)return"PAYING...";if(_t&&Y?.asset)return`INSUFFICIENT ${Y.asset.symbol}`;if(p)return p.toUpperCase();const pe=gt>0?` ${dt} ${o.symbol}`:"";return Xe?`SWAP & PAY${pe}`:`PAY${pe}`},[lt,_t,Y,p,gt,dt,o.symbol,Xe]),Sn=Ie==="success"?()=>{Jt("idle"),ke(null),ln(null),Re()}:G,Kn=Ie==="success"?!1:!tt;if(!e)return null;const Yn=k?x||`Pay ${o.symbol}`:p,ve=k?S:g("div",{style:{display:"flex",alignItems:"flex-start",gap:"3px"},children:[a("span",{style:{marginTop:"3px",flexShrink:0},children:a(ks,{color:Z})}),a("p",{style:{fontSize:"12px",color:Z,margin:0,lineHeight:"1.4",fontFamily:U},children:kt})]});if(k){const pe=_e&&(_e.status==="success"||_e.status==="failed")?[{asset:{symbol:Y?.asset?.symbol||o.symbol,address:Y?.asset?.address||""},amount:dt,txHash:_e.txHash||"",success:_e.status==="success",error:_e.status==="failed"?_e.error:void 0}]:void 0;return a(Pn,{isOpen:e,onClose:t,title:Yn,subtitle:ve,styles:w,dark:M,footerLinkText:"Spicenet accounts \u2192",closeOnBackdropClick:n,children:g("div",{style:{padding:"16px 24px 8px 24px",position:"relative"},children:[A&&a("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:"6px"},children:a(vs,{onClick:A,color:T,fontFamily:U})}),a("div",{style:{marginBottom:"12px"},children:a(Ao,{assets:je,selectedAsset:Y??void 0,onAssetSelect:te,onAmountChange:()=>{},label:"Pay with",showBalance:!0,showMaxButton:!1,hideAmountInput:!0,displayAmount:Y?.asset?Xe?ze?"...":ot?`~${parseFloat(rt(ot.amountIn,Y.asset.decimals)).toFixed(6)}`:void 0:dt??void 0:void 0,dark:M,theme:ge,styles:w})}),a(pa,{variant:"pay",destinationSymbol:o.symbol,destinationLogoURI:o.logoURI,destinationDecimals:o.decimals,primaryColor:T,fontFamily:U,textPrimary:j,textSecondary:L,cardBg:Q,cardBorder:P,dk:O,dark:M,isQuoting:ze,quoteError:Et,estimatedOutput:qt,paymentAmount:dt,needsSwap:Xe,exactOutputSwap:ot,adjustable:y==="adjustable",maxAmount:v,onAmountChange:Ae}),Ft&&a(Uo,{fontFamily:U,textPrimary:j,textSecondary:L,cardBg:Q,cardBorder:P,resolvedDark:M,darkCardBorder:O.cardBorder,primaryColor:T,feePreview:ht,isLoading:Kt,errorText:Qt,directExecutionFeeNote:De}),Ye&&a(io,{variant:"error",palette:N,fontFamily:U,style:{marginBottom:"12px"},children:Ye}),a(At,{variant:"outline",fullWidth:!0,onClick:de,disabled:!tt,loading:lt,dark:M,styles:{...w,button:{...w?.button,backgroundColor:T}},children:tn}),_e&&ct&&a("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:10,backgroundColor:M?O.shell:"white",borderRadius:M?"12px":"6px",padding:"16px 0"},children:a(Fs,{type:"payment",isOpen:_e.status!=="processing",isProcessing:lt||_e.status==="processing",closeOnComplete:!1,chainName:nn(W),explorerUrl:to(W,"").replace(/\/tx\/.*$/,"")||void 0,onRetryTx:()=>{jt(!1),ft(null),de()},onNewTx:He,onClose:()=>{jt(!1),ft(null)},onComplete:He,results:pe,styles:w,dark:M})})]})})}return a(Pn,{isOpen:e,onClose:t,title:Yn,subtitle:ve,dark:M,styles:w,theme:E,closeOnBackdropClick:n,children:g("div",{style:{padding:"24px 24px 5px 24px",position:"relative"},children:[a("div",{style:{marginBottom:"16px"},children:a(Ao,{assets:je,selectedAsset:Y||void 0,onAssetSelect:te,onAmountChange:ne,disabled:lt||Ie==="success",showBalance:!0,showMaxButton:!0,label:"From Wallet",placeholder:"0.00",theme:ge,styles:w,dark:D,resolveMaxAmount:$,maxAmount:un>0?ro(un,Y?.asset.decimals??o.decimals):void 0})}),Y?.asset&&!Oe&&a(pa,{variant:"supply",destinationSymbol:o.symbol,destinationLogoURI:o.logoURI,destinationDecimals:o.decimals,primaryColor:T,fontFamily:U,textPrimary:j,textSecondary:L,cardBg:Q,cardBorder:P,dark:M,isQuoting:ze,quoteError:Et,estimatedOutput:qt}),Ft&&a(Uo,{fontFamily:U,textPrimary:j,textSecondary:L,cardBg:Q,cardBorder:P,resolvedDark:M,darkCardBorder:O.cardBorder,primaryColor:T,feePreview:ht,isLoading:Kt,errorText:Qt,directExecutionFeeNote:De}),Ie!=="idle"&&g("div",{style:{padding:"10px 14px",borderRadius:"7px",marginBottom:"16px",backgroundColor:Ie==="success"?Q:Ie==="error"?N.errorBg:Q,border:`1px solid ${Ie==="success"?P:Ie==="error"?N.errorBorder:P}`},children:[g("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[Ie==="success"?a("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:a("path",{d:"M5 13l4 4L19 7",stroke:N.successText,strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round"})}):Ie==="error"?a("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:a("path",{d:"M18 6L6 18M6 6l12 12",stroke:N.errorText,strokeWidth:"2.5",strokeLinecap:"round"})}):a(On,{size:14,color:T}),a("span",{style:{fontSize:"13px",fontWeight:500,color:Ie==="success"?j:Ie==="error"?N.errorText:j,fontFamily:U,flex:1},children:Ie==="success"?"Deposit confirmed":Ie==="error"?In||"Transaction failed":Aa[Ie]||In}),Ie==="success"&&Ut&&a("a",{href:`${Zt}/tx/${Ut}`,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:T,fontFamily:U,textDecoration:"none",whiteSpace:"nowrap",flexShrink:0},children:"View tx \u2192"}),Ie==="error"&&a("button",{onClick:()=>{Jt("idle"),Nt(null),setTimeout(G,50)},style:{background:"none",border:"none",fontSize:"12px",color:T,fontFamily:U,cursor:"pointer",padding:0,whiteSpace:"nowrap",flexShrink:0},children:"Retry \u2192"})]}),Wt>=0&&Ie!=="success"&&Ie!=="error"&&a("div",{style:{marginTop:"8px",height:"3px",borderRadius:"2px",backgroundColor:`${L}22`,overflow:"hidden"},children:a("div",{style:{height:"100%",width:"100%",borderRadius:"2px",backgroundColor:T,transformOrigin:"left center",transform:`scaleX(${(Wt+1)/Sa.length})`,transition:"transform 400ms ease"}})})]}),Xt&&Ie==="idle"&&a(io,{variant:"error",palette:N,fontFamily:U,style:{marginBottom:"16px"},children:Xt}),a(At,{variant:"outline",fullWidth:!0,disabled:Kn,onClick:Sn,theme:E,dark:M,styles:{...w,button:{...w?.button,backgroundColor:T}},style:{fontSize:"20px",fontWeight:600,letterSpacing:"1.5px",fontFamily:V},children:en})]})})},Xc=e=>a(Ea,{isOpen:e.isOpen,onClose:e.onClose,closeOnBackdropClick:e.closeOnBackdropClick,amountDirection:"output",destinationToken:{address:e.paymentTokenAddress,symbol:e.paymentTokenSymbol,decimals:e.paymentTokenDecimals,chainId:e.paymentChainId,logoURI:e.paymentTokenLogoURI},buildActionCalls:e.buildActionCalls,buildSpicenetBatch:e.buildSpicenetBatch,actionLabel:e.ctaLabel||"PAY",paymentAmount:e.paymentAmount,amountInputMode:e.amountInputMode,minPaymentAmount:e.minPaymentAmount,maxPaymentAmount:e.maxPaymentAmount,onAmountChange:e.onAmountChange,title:e.title,subtitle:e.subtitle,onAddFunds:e.onAddFunds,styles:e.styles,dark:e.dark,onSuccess:e.onPaymentSuccess,onError:e.onPaymentError}),Jc=({label:e="Export Wallet",style:t,className:n,onExport:o,onError:s})=>{const[r,i]=R(!1),[c,d]=R(!1),{primaryColor:l}=ut(),p=Gt(Lt),{isAuthenticated:u}=Fn();let h=null;try{h=ai()}catch{}let m=null,f=null;try{m=li(),f=ci()}catch{m=null,f=null}const y=Qa(f),C=ce(async()=>{if(!u){s?.("User is not authenticated. Please log in first.");return}try{if(p?.provider==="dynamic"){if(!m||!y){s?.("Dynamic is not available. Ensure the app is wrapped in a DynamicContextProvider.");return}await m.initExportProcess(!1),o?.();return}if(!h){s?.("Privy is not available. Ensure the app is wrapped in a PrivyProvider.");return}await h.exportWallet(),o?.()}catch(w){const I=w instanceof Error?w.message:"Failed to export wallet";console.error("Export wallet error:",w),s?.(I)}},[y,m,u,s,o,h,p?.provider]),v=!u,b={padding:"10px 20px",borderRadius:"8px",fontFamily:'"IBM Plex Mono", monospace',fontSize:"14px",fontWeight:500,letterSpacing:"0.4px",textTransform:"uppercase",cursor:v?"not-allowed":"pointer",opacity:v?.5:1,border:"1px solid #0e0d0b",color:"#0e0d0b",backgroundColor:c?`${l}cc`:r?`${l}ee`:l,transition:"background-color 150ms ease, transform 150ms ease",display:"inline-flex",alignItems:"center",justifyContent:"center",gap:"8px",...t};return g("button",{onClick:C,onMouseEnter:()=>i(!0),onMouseLeave:()=>{i(!1),d(!1)},onMouseDown:()=>d(!0),onMouseUp:()=>d(!1),disabled:v,className:n,style:b,children:[g("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[a("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),a("polyline",{points:"17 8 12 3 7 8"}),a("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]}),e]})};function Fa(e){const t=Gt(Lt),n=Bn(),o=e?.enabled===!1?void 0:n,s=t?.network?{network:t.network,pollIntervalMs:e?.pollIntervalMs,chainIds:e?.chainIds??t.supportedChainIds,discoverWalletBalances:e?.discoverWalletBalances}:void 0;return{...Ar(o,s),embeddedWalletAddress:n}}var $c="data:image/svg+xml,%3csvg width='11' height='11' viewBox='0 0 24 24' fill='none' stroke='black' stroke-opacity='0.5' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' xmlns='http://www.w3.org/2000/svg'%3e%3cpolyline points='17 1 21 5 17 9' /%3e%3cpath d='M3 11V9a4 4 0 0 1 4-4h14' /%3e%3cpolyline points='7 23 3 19 7 15' /%3e%3cpath d='M21 13v2a4 4 0 0 1-4 4H3' /%3e%3c/svg%3e";const _c=({appName:e,status:t,statusLabel:n,totalUsdValue:o,breakdownSubtitle:s,address:r,dk:i,dark:c=!1,showModeToggle:d,isEmbeddedMode:l=!0,onModeToggle:p})=>{const[u,h]=R(!1),m=async()=>{r&&await wi(r)&&(h(!0),setTimeout(()=>h(!1),2e3))},f=t==="active",y=n||(f?"Active":"Inactive"),C=f?"#10b981":"#9ca3af",v=g("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:[g("div",{children:[a("strong",{children:"Embedded:"})," Deposit assets into ",e," account and use them here."]}),g("div",{children:[a("strong",{children:"External:"})," Use assets from your connected wallet here."]})]});return g("div",{children:[g("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"4px"},children:[g("div",{style:{fontSize:"13px",fontWeight:600,color:i.textPrimary},children:[e," Account"]}),d?g("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[g("button",{onClick:p,style:{display:"flex",alignItems:"center",gap:"4px",padding:"2px 8px",borderRadius:"9999px",backgroundColor:c?i.hoverBg:"#f3f4f6",border:c?`1px solid ${i.cardBorder}`:"1px solid #e5e7eb",cursor:"pointer",fontSize:"11px",fontWeight:600,fontFamily:'"IBM Plex Mono", monospace',color:i.textSecondary,transition:"background-color 150ms ease, border-color 150ms ease, color 150ms ease",letterSpacing:"0.02em"},children:[a("div",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:l?"#22c55e":"#f59e0b"}}),a("span",{children:l?"Embedded":"External"}),a("img",{src:$c,alt:"","aria-hidden":"true",style:{width:"11px",height:"11px",display:"block",...c?{filter:"invert(0.65)"}:{}}})]}),a(yr,{content:v,label:"Account mode info",textColor:c?i.textPrimary:"#f9fafb",backgroundColor:c?i.cardBg:"#111827",borderColor:c?i.cardBorder:"rgba(255,255,255,0.08)",accentColor:c?i.textSecondary:"#6b7280",children:a("img",{src:Ss,alt:"","aria-hidden":"true",style:{width:"12px",height:"12px",display:"block",...c?{filter:"invert(0.65)"}:{}}})})]}):g("div",{style:{display:"flex",alignItems:"center",gap:"4px",padding:"2px 8px",borderRadius:"9999px",backgroundColor:c?i.hoverBg:f?"#ecfdf5":"#f3f4f6",border:c?`1px solid ${i.cardBorder}`:f?"1px solid #a7f3d0":"1px solid #e5e7eb"},children:[a("div",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:C}}),a("span",{style:{fontSize:"11px",fontWeight:500,color:c?i.textSecondary:f?"#065f46":"#6b7280"},children:y})]})]}),a("div",{style:{fontSize:"28px",fontWeight:700,color:i.textPrimary,lineHeight:1.2,marginBottom:"2px"},children:oo(o)}),s&&a("div",{style:{fontSize:"12px",color:i.textSecondary,marginBottom:"8px"},children:s}),r&&g("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[a("span",{style:{fontSize:"12px",fontFamily:'"IBM Plex Mono", monospace',color:c?i.textSecondary:"#9ca3af"},children:bi(r)}),a("button",{onClick:m,style:{padding:"2px 6px",fontSize:"10px",fontWeight:500,backgroundColor:"transparent",color:c?i.textSecondary:"#9ca3af",border:"none",cursor:"pointer",borderRadius:"4px",transition:"background-color 150ms ease, color 150ms ease"},title:"Copy address",children:u?"Copied":"Copy"})]})]})},ed=({pendingDeposits:e,onCompleteDeposit:t,dk:n,dark:o=!1})=>e.length===0?null:g("div",{children:[a("div",{style:{fontSize:"11px",fontWeight:600,letterSpacing:"1px",color:n.textSecondary,marginBottom:"8px",textTransform:"uppercase"},children:"Pending Deposits"}),a("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:e.map((s,r)=>{const i=Be(s.chainId)?.displayName||`Chain ${s.chainId}`;return g("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 12px",backgroundColor:o?n.warningBg:"#fffbeb",border:o?`1px solid ${n.warningBorder}`:"1px solid #fde68a",borderRadius:"8px"},children:[g("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[a("div",{style:{width:"24px",height:"24px",borderRadius:"50%",backgroundColor:o?n.hoverBg:"#fde68a",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"11px",fontWeight:600,color:n.warningText},children:s.tokenSymbol.charAt(0)}),g("div",{children:[g("div",{style:{fontSize:"13px",fontWeight:500,color:n.textPrimary},children:[s.amount," ",s.tokenSymbol]}),g("div",{style:{fontSize:"11px",color:n.warningText},children:["on ",i]})]})]}),a("button",{onClick:()=>t?.(s),style:{padding:"4px 12px",fontSize:"11px",fontWeight:600,backgroundColor:o?n.hoverBg:"#fef3c7",color:o?n.textPrimary:"#92400e",border:o?`1px solid ${n.warningBorder}`:"1px solid #fde68a",borderRadius:"9999px",cursor:"pointer",transition:"background-color 150ms ease, border-color 150ms ease, color 150ms ease"},children:"Complete"})]},`${s.tokenAddress}-${s.chainId}-${r}`)})})]}),td=({spiceAssets:e,loading:t,dk:n,dark:o=!1})=>{const s={fontSize:"11px",fontWeight:600,letterSpacing:"1px",color:n.textSecondary,marginBottom:"8px",textTransform:"uppercase"},r={backgroundColor:n.cardBg,border:o?`1px solid ${n.cardBorder}`:"1px solid #e5e7eb",borderRadius:"8px"};return t?g("div",{children:[a("div",{style:s,children:"Idle Balances"}),[1,2].map(i=>a("div",{style:{...r,padding:"12px",marginBottom:"6px",height:"48px",animation:"pulse 1.5s ease-in-out infinite",opacity:.5}},i))]}):e.length===0?g("div",{children:[a("div",{style:s,children:"Idle Balances"}),a("div",{style:{...r,padding:"16px",textAlign:"center",fontSize:"13px",color:o?n.textSecondary:"#9ca3af"},children:"No assets yet. Deposit to get started."})]}):g("div",{children:[a("div",{style:s,children:"Idle Balances"}),a("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:e.map((i,c)=>{const d=Be(i.chainId),l=i.chainDisplayName||d?.displayName||`Chain ${i.chainId}`,p=i.tokenDisplaySymbol||i.tokenDisplayName||i.tokenSymbol;return g("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 12px",...r},children:[g("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[i.logoURI?a("img",{src:i.logoURI,alt:i.tokenSymbol,style:{width:"24px",height:"24px",borderRadius:"50%"}}):a("div",{style:{width:"24px",height:"24px",borderRadius:"50%",backgroundColor:o?n.hoverBg:"#e5e7eb",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"11px",fontWeight:600,color:n.textSecondary},children:p.charAt(0)}),g("div",{children:[a("div",{style:{fontSize:"13px",fontWeight:500,color:n.textPrimary},children:p}),a("div",{style:{fontSize:"11px",color:o?n.textSecondary:"#9ca3af"},children:l})]})]}),g("div",{style:{textAlign:"right"},children:[a("div",{style:{fontSize:"13px",fontWeight:500,color:n.textPrimary},children:jn(i.balanceFormatted)}),a("div",{style:{fontSize:"11px",color:o?n.textSecondary:"#9ca3af"},children:oo(i.usdValue)})]})]},`${i.tokenAddress}-${i.chainId}-${c}`)})})]})},nd=({section:e,dk:t,dark:n=!1})=>{const o=s=>{switch(s){case"green":return"#10b981";case"red":return"#ef4444";default:return t.textPrimary}};return g("div",{children:[a("div",{style:{fontSize:"11px",fontWeight:600,letterSpacing:"1px",color:t.textSecondary,marginBottom:"8px",textTransform:"uppercase"},children:e.title}),a("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:e.items.map((s,r)=>g("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 12px",backgroundColor:t.cardBg,border:n?`1px solid ${t.cardBorder}`:"1px solid #e5e7eb",borderRadius:"8px"},children:[g("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[s.tokenLogoURI?a("img",{src:s.tokenLogoURI,alt:s.tokenSymbol,style:{width:"20px",height:"20px",borderRadius:"50%"}}):a("div",{style:{width:"20px",height:"20px",borderRadius:"50%",backgroundColor:n?t.hoverBg:"#e5e7eb",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",fontWeight:600,color:t.textSecondary},children:s.tokenSymbol.charAt(0)}),g("div",{children:[a("div",{style:{fontSize:"13px",fontWeight:500,color:t.textPrimary},children:s.tokenSymbol}),a("div",{style:{fontSize:"11px",color:t.textSecondary},children:s.label})]})]}),a("div",{style:{fontSize:"13px",fontWeight:600,color:o(s.valueColor)},children:s.displayValue})]},r))})]})},od=({onDepositClick:e,onWithdrawClick:t,depositDisabled:n=!1,withdrawDisabled:o=!1,primaryColor:s="#EA4B4B",dark:r=!1})=>!e&&!t?null:g("div",{style:{display:"flex",gap:"8px"},children:[e&&a(At,{variant:"outline",onClick:e,disabled:n,dark:r,styles:{button:{backgroundColor:s}},style:{flex:1,height:"44px",fontSize:"12px"},children:"Deposit"}),t&&a(At,{variant:"outline",onClick:t,disabled:o,dark:r,styles:{button:{backgroundColor:s}},style:{flex:1,height:"44px",fontSize:"12px"},children:"Withdraw"})]}),sd=({appName:e,status:t,statusLabel:n,totalUsdValue:o,breakdownSubtitle:s,address:r,spiceAssets:i,spiceAssetsLoading:c,pendingDeposits:d,customSections:l,onDepositClick:p,onWithdrawClick:u,onCompleteDeposit:h,primaryColor:m,dk:f,dark:y=!1,showModeToggle:C,isEmbeddedMode:v,onModeToggle:b,showConnectExternalCta:w,onConnectExternalWallet:I,connectExternalError:x,showHowItWorks:S=!0})=>{const[A,B]=R(!1);return g("div",{style:{display:"flex",flexDirection:"column",gap:"16px",padding:"16px",maxHeight:"calc(80vh - 32px)",overflowY:"auto"},children:[a(_c,{appName:e,status:t,statusLabel:n,totalUsdValue:o,breakdownSubtitle:s,address:r,dk:f,dark:y,showModeToggle:C,isEmbeddedMode:v,onModeToggle:b}),w&&g("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:[a("button",{onClick:I,style:{width:"100%",padding:"10px 14px",borderRadius:"8px",backgroundColor:m||"#EA4B4B",color:"#ffffff",border:"none",cursor:"pointer",fontSize:"13px",fontWeight:600,fontFamily:'"Helvetica Neue", sans-serif',transition:"opacity 150ms ease"},children:"Connect External Wallet"}),x&&a("span",{style:{fontSize:"11px",color:y?f.errorText:"#b91c1c",lineHeight:1.4},children:x})]}),a("div",{style:{height:"1px",backgroundColor:y?"#2d2d2d":"#e5e7eb"}}),a(od,{onDepositClick:p,onWithdrawClick:u,primaryColor:m,dark:y}),S&&g("div",{children:[g("button",{onClick:()=>B(!A),style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",padding:"8px 12px",backgroundColor:f.cardBg,border:y?`1px solid ${f.cardBorder}`:"1px solid #e5e7eb",borderRadius:"8px",cursor:"pointer",color:f.textSecondary,fontSize:"12px",fontWeight:500},children:[a("span",{children:"How It Works"}),a("span",{style:{transform:A?"rotate(180deg)":"rotate(0deg)",transition:"transform 200ms ease",fontSize:"10px"},children:"\u25BE"})]}),A&&g("div",{style:{marginTop:"6px",padding:"10px 12px",backgroundColor:y?f.cardBg:"#f0fdf4",border:y?`1px solid ${f.cardBorder}`:"1px solid #bbf7d0",borderRadius:"8px",fontSize:"12px",lineHeight:1.5,color:y?f.textSecondary:"#374151"},children:["Fund your ",e," Account from any supported chain. Once funded, transact gas-free and asset-abstracted on ",e,"."]})]}),a(ed,{pendingDeposits:d,onCompleteDeposit:h,dk:f,dark:y}),a(td,{spiceAssets:i,loading:c,dk:f,dark:y}),l.map((F,k)=>a(nd,{section:F,dk:f,dark:y},k))]})},Ks=380,eo=8;function Ba(e){return e?.trim().replace(/^spice/i,"").replace(/[^a-z0-9]/gi,"").toUpperCase()||void 0}function rd(e,t){const n=new Map;Object.entries(t).forEach(([s,r])=>{if(!Number.isFinite(r)||r<=0)return;n.set(s,r),n.set(s.toUpperCase(),r);const i=Ba(s);i&&n.set(i,r)});const o=[e.symbol,e.displaySymbol,e.receiptTokenName,e.name,e.displayName];for(const s of o){if(!s)continue;const r=n.get(s)??n.get(s.toUpperCase());if(r!==void 0)return r;const i=Ba(s);if(!i)continue;const c=n.get(i);if(c!==void 0)return c}return 0}const ad=({appName:e="Spice",status:t="active",statusLabel:n,customSections:o=[],extraAssets:s=[],tokenPrices:r={},breakdownLabels:i=[],styles:c,dark:d=!1,onDepositSuccess:l,onDepositClick:p,onWithdrawClick:u,onCompleteDeposit:h,showModeToggle:m=!1,defaultMode:f})=>{const y=Gt(Lt),C=y?.mode!=="7702",v=!!y?.isWhitelistGateActive,b=ie(!1);X(()=>{if(!b.current){if(Va()){b.current=!0;return}f&&y?.setMode&&(y.setMode(f==="non7702"?"ondemand":"7702"),b.current=!0)}},[y,f]);const[w,I]=R(!1),[x,S]=R(null),[A,B]=R({top:0,bottom:0,left:0,placement:"below"}),F=ie(null),k=ie(null),{address:E,isConnected:M}=Fn(),T=Bn(),{externalAddress:O,embeddedAddress:N}=no(),{dark:U,primaryColor:V,dk:D}=ut(c,d),Q=C&&!O,P=!C||Q,j=P?T||N:E,L=re(()=>y?.supportedChainIds??Ro("mainnet"),[y?.supportedChainIds]),{assets:Z,loading:ge}=Eo({address:j,supportedChains:L,enabled:!!j&&P,refetchInterval:3e4}),W=re(()=>{const oe=P?Z.map(Y=>{const ke=Y.balanceUsd||0,St=Number.isFinite(Y.balanceFormatted)?Y.balanceFormatted:0,Rt=ke>0?ke:rd(Y,r)*St;return{tokenAddress:Y.address,tokenSymbol:Y.symbol,tokenDisplaySymbol:ys(Y),tokenDisplayName:Si(Y),tokenDecimals:Y.decimals,chainId:Y.chainId,chainDisplayName:xs(Y),balance:Y.balance.toString(),balanceFormatted:Y.balanceFormatted,usdValue:Rt,logoURI:Y.logoURI}}):[],je=Q?[]:s;return[...oe,...je].filter(Y=>Y.balanceFormatted>0)},[P,Q,Z,r,s]),_=re(()=>W.reduce((oe,je)=>oe+je.usdValue,0),[W]),{pendingDeposits:fe}=Fa({chainIds:L,enabled:!!E,discoverWalletBalances:!1}),be=re(()=>o.reduce((oe,je)=>oe+je.totalValue,0),[o]),Me=_+be,he=re(()=>{const oe=[];_>0&&oe.push(`${oo(_)} idle`);for(const je of o){const Y=i.find(ke=>ke.sectionTitle===je.title)?.label||je.title.toLowerCase();oe.push(`${oo(je.totalValue)} ${Y}`)}return oe.join(" \xB7 ")},[_,o,i]),xe=ce(oe=>{h?h(oe):S(oe)},[h]),H=ce(()=>{S(null)},[]),se=ce(()=>{S(null),l?.()},[l]),K=ce(()=>{if(!F.current)return;const oe=F.current.getBoundingClientRect(),je=window.innerHeight-oe.bottom-eo,Y=oe.top-eo,ke=je>=400||je>=Y?"below":"above",St=Math.max(eo,Math.min(oe.right-Ks,window.innerWidth-Ks-eo)),Rt=ke==="below"?oe.bottom+eo:oe.top-eo,lt=ke==="above"?window.innerHeight-Rt:0;B({top:Rt,bottom:lt,left:St,placement:ke})},[]);Gs(()=>{w&&K()},[w,K]),X(()=>{if(!w)return;const oe=ke=>{F.current&&!F.current.contains(ke.target)&&k.current&&!k.current.contains(ke.target)&&I(!1)},je=ke=>{ke.key==="Escape"&&I(!1)},Y=()=>K();return document.addEventListener("mousedown",oe),document.addEventListener("keydown",je),window.addEventListener("scroll",Y,{passive:!0}),window.addEventListener("resize",K),()=>{document.removeEventListener("mousedown",oe),document.removeEventListener("keydown",je),window.removeEventListener("scroll",Y),window.removeEventListener("resize",K)}},[w,K]);const le=P?T||N||E:O||E,ye=ce(()=>{y?.setMode&&y.setMode(P?"ondemand":"7702")},[y,P]),[Ee,ee]=R(null);let z=null;try{z=sr({onSuccess:()=>ee(null),onError:oe=>ee(bn(oe,"Failed to connect wallet."))}).connectWallet}catch{z=null}const ae=ce(()=>{z&&(I(!1),ee(null),z({walletChainType:"ethereum-only"}))},[z]),we=!O&&!!z,Le=ce(()=>{I(!1),p?.()},[p]),wt=ce(()=>{I(!1),u?.()},[u]),at=ce(oe=>{I(!1),xe(oe)},[xe]);if(typeof window>"u")return null;const it=g("button",{ref:F,onClick:()=>I(!w),style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"8px 14px",borderRadius:"9999px",backgroundColor:U?D.hoverBg:"#ffffff",border:U?`1px solid ${D.cardBorder}`:"1px solid #e5e7eb",cursor:"pointer",fontSize:"13px",fontWeight:500,fontFamily:'"Helvetica Neue", sans-serif',color:U?D.textPrimary:"#111827",transition:"background-color 150ms ease, border-color 150ms ease, box-shadow 150ms ease",boxShadow:U?"none":"0 1px 2px rgba(0,0,0,0.05)"},children:[a("span",{style:{width:"8px",height:"8px",borderRadius:"50%",backgroundColor:V,flexShrink:0}}),g("span",{children:[e," Account"]}),M&&g("span",{style:{color:U?D.textSecondary:"#6b7280"},children:["\xB7 ",oo(Me)]}),a("span",{style:{fontSize:"10px",color:U?D.textSecondary:"#9ca3af",transform:w?"rotate(180deg)":"rotate(0deg)",transition:"transform 200ms ease"},children:"\u25BE"})]}),Re=w?rr.createPortal(g(fn,{children:[a("div",{style:{position:"fixed",inset:0,backgroundColor:"rgba(0, 0, 0, 0.08)",zIndex:Xn.popover},onClick:()=>I(!1)}),a("div",{ref:k,style:{position:"fixed",top:A.placement==="below"?`${A.top}px`:"auto",bottom:A.placement==="above"?`${A.bottom}px`:"auto",left:`${A.left}px`,width:`${Ks}px`,maxWidth:`calc(100vw - ${eo*2}px)`,maxHeight:"80vh",backgroundColor:U?D.shell:"#ffffff",border:U?`1px solid ${D.cardBorder}`:"1px solid #e5e7eb",borderRadius:"12px",boxShadow:U?"0 10px 40px rgba(0, 0, 0, 0.5)":"0 10px 40px rgba(0, 0, 0, 0.12)",zIndex:Xn.popover+1,overflow:"hidden",animation:`accountDisplayFadeIn 200ms ${Ht.out}`},children:a(sd,{appName:e,status:t,statusLabel:n,totalUsdValue:Me,breakdownSubtitle:he,address:P?le:E,spiceAssets:W,spiceAssetsLoading:ge,pendingDeposits:fe,customSections:o,onDepositClick:p?Le:void 0,onWithdrawClick:u?wt:void 0,onCompleteDeposit:at,primaryColor:V,dk:D,dark:U,showModeToggle:m,isEmbeddedMode:P,onModeToggle:ye,showConnectExternalCta:we,onConnectExternalWallet:ae,connectExternalError:Ee,showHowItWorks:!v})}),a("style",{children:`
103
+ `})]})},uc="0xa9059cbb";function pc(e){const t=new Map;for(const n of e){if(n.amount<=0n)continue;const o=Ne(n.token),s=Ne(n.to),r=`${o.toLowerCase()}:${s.toLowerCase()}`,i=t.get(r);i?i.amount+=n.amount:t.set(r,{token:o,to:s,amount:n.amount})}return[...t.values()]}function fc(e,t){return`0x${t}${e.slice(4)}`}function hc(e,t,n){if(!Array.isArray(e))return 0n;const o=`evm:${t}:${n.slice(2).toLowerCase()}`;let s=0n;for(const r of e){if(!r||typeof r!="object")continue;const i=r,c=i.chainTokens;if((Array.isArray(c)?c.filter(d=>typeof d=="string"):c&&typeof c=="object"?Object.keys(c):[]).some(d=>d.toLowerCase()===o))try{s+=BigInt(i.balanceAvailable??"0")}catch{}}return s}async function oa(e,t,n,o){const s=await fetch(`${e}/wallets/${t}/balance`,{cache:"no-store"});if(!s.ok)throw new Error(`Failed to fetch spice balance: ${s.status}`);const r=await s.json();return hc(r?.balances,n,o)}async function mc({apiBaseUrl:e,user:t,chainId:n,tokenAddress:o,prevBalance:s,timeoutMs:r=3e4,pollIntervalMs:i=1500}){const c=Date.now()+r;for(await new Promise(d=>setTimeout(d,800));Date.now()<c;){try{if(await oa(e,t,n,o)>s)return}catch(d){console.warn("[SpiceLockModal] spice balance poll failed:",d?.message)}await new Promise(d=>setTimeout(d,i))}console.warn("[SpiceLockModal] Spicenet indexer did not reflect deposit within timeout; proceeding with intent")}function Ls(e,t){return zs(e,t)}function zs(e,t,n){const o=gc(t,e),s=Math.floor(Date.now()/1e3)+60*10,r=Rn(o);return{user:e,...n?{chainAuthorizations:n}:{},intents:[{mode:"7702",signatureType:"ecdsa",signature:"0x00",nbf:0,exp:s,chainBatches:r.map((i,c)=>({hash:i.hash,chainId:i.chainId,tokenTransfers:o[c].domain==="spicenet"?[]:o[c].tokenTransfers??[],calls:i.calls}))}]}}function gc(e,t){return e.map(n=>{if(n.domain==="spicenet"||n.calls.length===0)return n;const o=new Set((n.tokenTransfers??[]).filter(r=>(r.from==="escrow"||r.from==="solver")&&Ne(r.to).toLowerCase()===t.toLowerCase()).map(r=>Ne(r.token).toLowerCase()));if(o.size===0)return n;let s=0;for(const r of n.calls){if(!r.data?.startsWith(uc))break;try{const i=Co({abi:Ze,data:r.data});if(i.functionName!=="transfer")break;const[c]=i.args;if(c.toLowerCase()===t.toLowerCase()||!o.has(Ne(r.to).toLowerCase()))break;s+=1}catch{break}}return s===0?n:{...n,calls:n.calls.slice(s)}})}function rn(e,t,n,o){if(e.some(l=>l.domain==="spicenet"))return e;const s=n?.intents.flatMap(l=>l.batches),r=l=>l.from==="escrow",i=e.map(l=>{const p=s?.find(w=>w.chainId===l.chainId);if(!p)return l;const u=vn(p),h=u.totalFee;if(h<=0n)return l;const m=(l.tokenTransfers??[]).find(w=>r(w)&&Ne(w.to).toLowerCase()===t.toLowerCase()&&!Ue(Ne(w.token)));if(!m)return l;const f=Ne(m.token);let y=!1;const C=(l.tokenTransfers??[]).map(w=>y||!r(w)||Ne(w.to).toLowerCase()!==t.toLowerCase()||Ne(w.token).toLowerCase()!==f.toLowerCase()?w:(y=!0,{...w,amount:o?.payoutAlreadyGross?BigInt(w.amount):BigInt(w.amount)+h}));if(!y)return l;const v=[];u.spicenetFee>0n&&v.push({to:f,value:0n,data:xt({abi:Ze,functionName:"transfer",args:[xo,u.spicenetFee]})});const b=u.gasFee+u.bridgeFee;return b>0n&&v.push({to:f,value:0n,data:xt({abi:Ze,functionName:"transfer",args:[Tn,b]})}),{...l,tokenTransfers:C,calls:[...v,...l.calls]}}),c=i.flatMap(l=>(l.tokenTransfers??[]).filter(r).map(p=>{const u=Ne(p.token),h=Ne(p.to),m=[{token:u,to:h,amount:BigInt(p.amount)}];return{chainId:l.chainId,transfers:pc(m)}}));if(c.length===0)return e;const d=BigInt(Math.floor(Date.now()/1e3))+3600n;return[{chainId:_a,domain:"spicenet",tokenTransfers:[],calls:c.map((l,p)=>{const u=bo(wo([{type:"address"},{type:"address"},{type:"uint256"},{type:"uint256"},{type:"uint256"}],[t,l.transfers[0].token,l.transfers.reduce((m,f)=>m+f.amount,0n),BigInt(l.chainId),BigInt(Date.now()+p)])),h=fc(u,"77");return{to:"0x0000000000000000000000000000000000000000",value:0n,data:xt({abi:rs,functionName:"createWithdrawalRequest",args:[{chainId:`evm:${l.chainId}`,idempotenceKey:h,nbf:0n,exp:d,metadata:"{}",transfers:l.transfers.map(m=>({token:m.token.toLowerCase(),to:m.to,amount:m.amount}))}]})}})},...i]}function Os(e,t){return t?e.some(n=>(n.tokenTransfers??[]).some(o=>o.from==="escrow"&&BigInt(o.amount)>=t.grossAmount)):!1}function Hs(e){const t=e.selectedAsset?.asset,n=e.selectedAsset?.amount;if(!(!t||!n))return Ke(n,t.decimals)}function qn(e,t){const n=e.selectedAsset?.asset;if(!n||!e.selectedAsset?.amount)throw new Error("Select an asset and enter an amount");const o=Ke(e.selectedAsset.amount,n.decimals),s=t?.grossAmount??o;return e.resolveLockBatches({amount:e.selectedAsset.amount,amountWei:o,grossAmount:rt(s,n.decimals),grossAmountWei:s})}async function js(e,t,n){const o=[...new Set(n.filter(r=>r.domain!=="spicenet").map(r=>r.chainId))],s=[];for(const r of o){const i=pt(r),c=mo(r),d=await ss(t,i),l=await e.actions.signAuthorization({contractAddress:c,chainId:r,nonce:Number(d)});s.push(l)}return s}async function sa(e,t,n){const o=e.isSemi7702&&e.providerEmbeddedAddress||e.address;if(!e.isConnected||!o)throw new Error("Please connect your wallet to continue");if(t.length===0)throw new Error("No lock batches configured");if(!e.ready||!e.authenticated)throw new Error(`Please authenticate with ${e.provider||"wallet provider"} to continue`);const s=n??await js(e,o,t),r=Rn(t),i=Math.floor(Date.now()/1e3)+60*10,c=r.map(m=>m.hash),d=bo(wo([{type:"string"},{type:"uint256"},{type:"uint256"},{type:"bytes32[]"}],["ecdsa",0n,BigInt(i),c])),l=await e.actions.signMessage({raw:d}),p=typeof l=="string"?l:l.signature;if(!p)throw new Error("Failed to sign intent authorization");const u={mode:"7702",signatureType:"ecdsa",signature:p,nbf:0,exp:i,chainBatches:r.map((m,f)=>{const y=t[f],C=y.domain==="spicenet";return{hash:m.hash,chainId:m.chainId,tokenTransfers:C?[]:y.tokenTransfers??[],calls:m.calls}})},h=await nt.createAction({user:o,chainAuthorizations:s.map(m=>({r:m.r,s:m.s,yParity:m.yParity,address:m.address,chainId:Number(m.chainId),nonce:Number(m.nonce)})),intents:[u]});if(h){const m=es(t,nn),[f,y]=h.intentIds[0].split("/"),C=parseInt(y||"0",10),v=h.intentIds[0];e.startStatusPolling(h.intentIds[0],m),await Lr({actionId:f,intentIndex:C,intentId:v,totalSteps:t.length,isSpicenetStep:b=>t[b]?.domain==="spicenet",maxExecuteAttemptsForStep:b=>t[b]?.domain==="spicenet"?6:3,maxPolls:180})}}async function ra(e){let t=qn(e);if(t.length===0)throw new Error("No lock batches configured");const n=e.isSemi7702&&e.providerEmbeddedAddress||e.address;if(!e.isConnected||!n)throw new Error("Please connect your wallet to continue");const o=await js(e,n,t);let s=rn([...t],n),r;for(let i=0;i<4;i+=1){const c=await nt.estimateActionFees(zs(n,s,o.map(u=>({r:u.r,s:u.s,yParity:u.yParity,address:u.address,chainId:Number(u.chainId),nonce:Number(u.nonce)})))),d=Fo(c,{symbol:e.selectedAsset?.asset.symbol??"",decimals:e.selectedAsset?.asset.decimals??18,actionAmount:Hs(e)});if(!d)break;const l={grossAmount:d.grossAmount,netAmount:d.netAmount,feeAmount:d.totalFee??0n},p=r?.grossAmount===l.grossAmount&&r?.netAmount===l.netAmount&&r?.feeAmount===l.feeAmount;if(r=l,t=qn(e,r),s=rn([...t],n,c,{payoutAlreadyGross:Os(t,r)}),p)break}await sa(e,s,o)}async function yc(e){if(!e.selectedAsset?.asset||!e.selectedAsset.amount)throw new Error("Select an asset and enter an amount");if(!e.address||!e.embeddedWalletAddress)throw new Error("Embedded wallet not connected");const t=e.selectedAsset.asset,n=Ke(e.selectedAsset.amount,t.decimals),o=e.escrowAddress||mo(e.lockChainId),s=nt.getBaseUrl(),r=It(t.address);let i=0n;try{i=await oa(s,e.embeddedWalletAddress,e.lockChainId,r)}catch(u){console.warn("[SpiceLockModal] could not snapshot spice balance pre-deposit:",u?.message)}const c=await e.actions.getEthereumProvider();await Hn(c,e.lockChainId);const d=Be(e.lockChainId),l=Dn({account:e.embeddedWalletAddress,transport:Nn(c),chain:d?.viemChain});let p;if(t.isNative||Ue(t.address))p=await l.sendTransaction({to:o,value:n,chain:d?.viemChain});else{const u=xt({abi:Ze,functionName:"transfer",args:[o,n]});p=await l.sendTransaction({to:t.address,data:u,chain:d?.viemChain})}if((await pt(e.lockChainId).waitForTransactionReceipt({hash:p,timeout:12e4,pollingInterval:2e3,confirmations:1})).status!=="success")throw new Error("Transfer to escrow failed");await mc({apiBaseUrl:s,user:e.embeddedWalletAddress,chainId:e.lockChainId,tokenAddress:r,prevBalance:i}),await e.refreshSpiceAssets(),e.refreshWalletAssets(),await ra(e)}async function xc(e){if(!e.selectedAsset?.asset||!e.selectedAsset.amount)throw new Error("Select an asset and enter an amount");if(!e.externalWalletAddress||!e.externalWallet)throw new Error("Please connect your external wallet to continue");const t=e.embeddedWalletAddress||e.providerEmbeddedAddress;if(!t)throw new Error("Embedded wallet not available \u2014 sign in to create one before locking");if(e.onLockExecute){const S=e.resolveLockBatches();if(S.length===0)throw new Error("No lock batches configured");const A=e.selectedAsset.asset,B=Ke(e.selectedAsset.amount,A.decimals),F=await e.onLockExecute({asset:A,amount:e.selectedAsset.amount,amountWei:B,lockDurationMonths:e.selectedDuration?.months??0,chainBatches:S});F&&e.onLockSuccess?.(F);return}const n=e.resolveLockBatches();if(n.length===0)throw new Error("No lock batches configured");const o=e.selectedAsset.asset,s=Ke(e.selectedAsset.amount,o.decimals),r=o.chainId,i=e.escrowAddress||wn(r),c=It(o.address),d=o.isNative||Ue(c),l=n.some(S=>S.tokenTransfers?.some(A=>A.from==="escrow")),p=S=>({chainId:r,calls:d?[{to:i,value:S,data:"0x"}]:[{to:c,value:0n,data:xt({abi:Ze,functionName:"transfer",args:[i,S]})}]}),u=(S,A,B)=>{const F=p(S);if(!l)return[F,...A];const k=rn([...A],t,B,{payoutAlreadyGross:Os(A,y)});return[F,...k]};let h=qn(e),m=u(s,h);const f=await js(e,t,m);let y;if(l)for(let S=0;S<4;S+=1){const A=await nt.estimateActionFees(zs(t,m,f.map(E=>({r:E.r,s:E.s,yParity:E.yParity,address:E.address,chainId:Number(E.chainId),nonce:Number(E.nonce)})))),B=Fo(A,{symbol:o.symbol,decimals:o.decimals,actionAmount:s});if(!B)break;const F={grossAmount:B.grossAmount,netAmount:B.netAmount,feeAmount:B.totalFee??0n},k=y?.grossAmount===F.grossAmount&&y?.netAmount===F.netAmount&&y?.feeAmount===F.feeAmount;if(y=F,h=qn(e,y),m=u(F.grossAmount,h,A),k)break}const C=y?.grossAmount??s,v=await e.externalWallet.getEthereumProvider();let b=null;try{const S=await v.request({method:"eth_chainId"});b=parseInt(S,16)}catch{b=null}b!==r&&await Hn(v,r);const w=Be(r),I=Dn({account:e.externalWalletAddress,chain:w?.viemChain,transport:Nn(v)}),x=d?await I.sendTransaction({to:t,value:C,chain:w?.viemChain}):await I.sendTransaction({to:c,data:xt({abi:Ze,functionName:"transfer",args:[t,C]}),chain:w?.viemChain});if((await pt(r).waitForTransactionReceipt({hash:x,timeout:12e4,pollingInterval:2e3,confirmations:1})).status!=="success")throw new Error("Transfer to embedded wallet failed");await sa(e,m,f)}async function bc(e){if(!e.selectedAsset?.asset||!e.selectedAsset.amount||!e.requiresRelayerFeeEstimate)return null;if(e.isSemi7702){const i=e.embeddedWalletAddress||e.providerEmbeddedAddress;if(!i)throw new Error("Embedded wallet not available \u2014 sign in to create one before locking");let c=qn(e);if(c.length===0)throw new Error("No lock batches configured");const d=e.selectedAsset.asset,l=Ke(e.selectedAsset.amount,d.decimals),p=d.chainId,u=e.escrowAddress||wn(p),h=It(d.address),m=d.isNative||Ue(h),f=c.some(I=>I.tokenTransfers?.some(x=>x.from==="escrow")),y=I=>({chainId:p,calls:m?[{to:u,value:I,data:"0x"}]:[{to:h,value:0n,data:xt({abi:Ze,functionName:"transfer",args:[u,I]})}]}),C=(I,x,S)=>{const A=y(I);if(!f)return[A,...x];const B=rn([...x],i,S,{payoutAlreadyGross:x.some(F=>(F.tokenTransfers??[]).some(k=>k.from==="escrow"&&BigInt(k.amount)>=I))});return[A,...B]};let v=C(l,c),b=null,w;for(let I=0;I<4;I+=1){const x=await nt.estimateActionFees(Ls(i,v)),S=Fo(x,{symbol:d.symbol,decimals:d.decimals,actionAmount:l});if(!S)return b;const A={grossAmount:S.grossAmount,netAmount:S.netAmount,feeAmount:S.totalFee??0n},B=w?.grossAmount===A.grossAmount&&w?.netAmount===A.netAmount&&w?.feeAmount===A.feeAmount;if(b=S,w=A,c=qn(e,A),v=C(A.grossAmount,c,x),B)break}return b}const t=e.address;if(!e.isConnected||!t)throw new Error("Please connect your wallet to continue");let n=qn(e);if(n.length===0)throw new Error("No lock batches configured");let o=rn([...n],t),s=null;for(let i=0;i<4;i+=1){const c=await nt.estimateActionFees(Ls(t,o)),d=Fo(c,{symbol:e.selectedAsset.asset.symbol,decimals:e.selectedAsset.asset.decimals,actionAmount:Hs(e)});if(!d)return null;const l={grossAmount:d.grossAmount},p=s?.grossAmount===d.grossAmount&&s?.netAmount===d.netAmount&&s?.totalFee===d.totalFee;if(s=d,n=qn(e,l),o=rn([...n],t,c,{payoutAlreadyGross:Os(n,l)}),p)break}if(s)return s;const r=await nt.estimateActionFees(Ls(t,o));return Fo(r,{symbol:e.selectedAsset.asset.symbol,decimals:e.selectedAsset.asset.decimals,actionAmount:Hs(e)})}async function wc(e){if(!e.selectedAsset?.asset||!e.selectedAsset.amount)throw new Error("Select an asset and enter an amount");if(!e.externalWalletAddress||!e.externalWallet)throw new Error("Please connect your external wallet to continue");const t=e.resolveLockBatches();if(t.length===0)throw new Error("No lock batches configured");const n=t.find(l=>l.chainId===e.lockChainId)||t[0];if(!n)throw new Error("No lock batch for lock chain");const o=await e.externalWallet.getEthereumProvider();let s=null;try{const l=await o.request({method:"eth_chainId"});s=parseInt(l,16)}catch{s=null}s!==e.lockChainId&&await Hn(o,e.lockChainId);const r=Be(e.lockChainId),i=Dn({account:e.externalWalletAddress,chain:r?.viemChain,transport:Nn(o)}),c=pt(e.lockChainId);let d;for(const l of n.calls){const p=await i.sendTransaction({to:l.to,data:l.data,value:l.value,chain:r?.viemChain});if((await c.waitForTransactionReceipt({hash:p,timeout:12e4,pollingInterval:2e3,confirmations:1})).status!=="success")throw new Error("Lock transaction failed");d=p}d&&e.onLockSuccess?.(d)}async function Cc(e){if(!e.selectedAsset?.asset||e.parsedAmount<=0){e.ui.setError("Select an asset and enter an amount");return}if(e.isInsufficientBalance){e.ui.setError("Insufficient balance. Add more assets.");return}e.ui.setIsExecuting(!0),e.ui.setError(null);const t=n=>{console.error("[SpiceLockModal] lock failed:",n);const o=bn(n,""),s=typeof n?.shortMessage=="string"?n.shortMessage:typeof n?.message=="string"?n.message:"";e.ui.setError(o||s||"Transaction failed. Please try again.")};if(e.isSemi7702){if(e.isSourceDestToken){try{await wc(e)}catch(n){t(n)}finally{e.ui.setIsExecuting(!1)}return}e.ui.setShowStatusPanel(!0);try{await xc(e)}catch(n){t(n)}finally{e.ui.setIsExecuting(!1)}return}e.ui.setShowStatusPanel(!0);try{e.isDirectDeposit&&!e.isSourceDestToken?await yc(e):await ra(e)}catch(n){t(n)}finally{e.ui.setIsExecuting(!1)}}const aa=({isOpen:e,onClose:t,closeOnBackdropClick:n=!1,lockBatches:o,lockTokenSymbol:s,lockTokenLogoURI:r,destinationInputHook:i,sourceAssetInputHook:c,lockDurationHook:d,lockChainId:l,durationOptions:p,votingPowerEstimate:u,escrowAddress:h,includeWalletAssets:m=!1,destinationTokenAddress:f,onLockSuccess:y,onLockExecute:C,sourceToDestinationConversionRate:v,estimatedOutputAmount:b,onAddFunds:w,buildSpicenetBatch:I,styles:x,dark:S=!1})=>{const{theme:A,dark:B,primaryColor:F,dk:k}=ut(x,S),E=A.typography.fontFamily,M=Gt(Lt),T=M?.mode||"7702",O=!!M?.isWhitelistGateActive,N=T!=="7702",U=re(()=>M?.supportedChainIds??[],[M?.supportedChainIds]),V=re(()=>{if(O)return[];const G=M?.allowedTokens;if(!G||G.length===0)return[];const ue=new Set(G.map(Ye=>Ye.toLowerCase())),We=[],De=new Set;for(const Ye of U){const Ft=Be(Ye);for(const pn of Ft?.supportedTokens??[]){if(!ue.has(pn.symbol.toLowerCase()))continue;const q=`${Ye}:${pn.address.toLowerCase()}`;De.has(q)||(De.add(q),We.push(Ne(pn.address)))}}return We},[M?.allowedTokens,U,O]),D=B?k.cardBg:x?.assetSelector?.backgroundColor||x?.secondaryBackground||"#e9e9e9",Q=B?`1px solid ${k.cardBorder}`:"0.5px solid #A8A8A7",P=B?"12px":"6px",j=B?k.textPrimary:"#111827",L=B?k.textSecondary:"#6b7280",Z=re(()=>({...x,assetSelector:{...x?.assetSelector,backgroundColor:B?k.cardBg:x?.assetSelector?.backgroundColor,borderRadius:B?"12px":x?.assetSelector?.borderRadius},secondaryBackground:B?k.cardBg:x?.secondaryBackground}),[x,B]),ge=re(()=>B?{...A,colors:{...A.colors,secondary:k.cardBg,surfaceHover:k.hoverBg,border:k.cardBorder,borderHover:k.inputBorder}}:A,[B,A]),[W,_]=R(null),[fe,be]=R(0),Me=d?.selectedDurationIdx??fe,he=d?.setSelectedDurationIdx??be,[xe,H]=R(!1),[se,K]=R(null),[le,ye]=R(null),[Ee,ee]=R(!1),[z,ae]=R(!1),[we,Le]=R(null),[wt,at]=R(!1),it=ie(0),[Re,oe]=R(!1),[je,Y]=R(null);er(),ts();const{chain:ke,address:St}=go();Za();const Rt=ie(ke);X(()=>{Rt.current=ke},[ke]);const lt=Fn(),{isReady:an,isAuthenticated:Xt,isConnected:Nt,address:Ie,provider:Jt,actions:In}=lt,{externalWallet:An,embeddedAddress:Ut,externalAddress:ln}=no(),{intentStatus:ct,startStatusPolling:jt,clearStatus:_e}=gr({checkStepStatus:(G,ue)=>nt.checkStepStatus(G,ue),retryStep:async(G,ue)=>{const[We,De]=G.split("/"),Ye=parseInt(De||"0",10);await nt.executeStep(We,Ye,ue,{action:"execute"})},maxRetries:3}),{assets:ft,refetch:ht}=Eo({address:Ie,supportedChains:U,enabled:e&&Nt&&!N&&!O,refetchInterval:3e4}),Bt=re(()=>{if(O)return[];if(V.length===0)return ft;const G=new Set(V.map(ue=>ue.toLowerCase()));return ft.filter(ue=>G.has(ue.address.toLowerCase()))},[ft,V,O]),Kt=Bn(),me=ln||St,bt=N?me:Kt,Ct=re(()=>{if(!m)return[];if(O)return f?[Ne(f)]:[];const G=new Set,ue=[],We=De=>{if(!De)return;const Ye=De.toLowerCase();G.has(Ye)||(G.add(Ye),ue.push(Ne(De)))};if(f&&We(f),N)for(const De of V)We(De);return ue},[m,N,f,V,O]),Qt=re(()=>Ct.map(G=>G.toLowerCase()).sort().join(","),[Ct]),Ce=re(()=>JSON.stringify([...U||[]].sort()),[U]),[$t,mt]=R([]),Tt=ie(0),Vt=ie(async()=>{}),mn=ce(async()=>{if(!m||!bt||Ct.length===0){Tt.current++,mt([]);return}const G=++Tt.current,ue=Ne(bt),We=U&&U.length>0?U:[l],De=Ct.map($=>{const de=$.toLowerCase();if(f&&Se($,f)){const J=Be(l)?.supportedTokens?.find(Fe=>Se(Fe.address,de));return{address:$,chainId:l,configToken:J?{decimals:J.decimals,symbol:J.symbol,name:J.name,logo:J.logo}:void 0}}for(const J of We){const Fe=Be(J)?.supportedTokens?.find(He=>Se(He.address,de));if(Fe)return{address:$,chainId:J,configToken:{decimals:Fe.decimals,symbol:Fe.symbol,name:Fe.name,logo:Fe.logo}}}return{address:$,chainId:l}}),Ye=new Map;for(const $ of De){const de=Ye.get($.chainId)||[];de.push($),Ye.set($.chainId,de)}const Ft=async($,de)=>{try{const J=await kn($,{address:de.address,abi:Ze,functionName:"balanceOf",args:[ue]});let Fe,He,yt,tt;if(de.configToken)Fe=de.configToken.decimals,He=de.configToken.symbol,yt=de.configToken.name,tt=de.configToken.logo;else{const[Wt,en,tn]=await Promise.all([kn($,{address:de.address,abi:Ze,functionName:"decimals",args:[]}).catch(()=>18),kn($,{address:de.address,abi:Ze,functionName:"symbol",args:[]}).catch(()=>"TOKEN"),kn($,{address:de.address,abi:Ze,functionName:"name",args:[]}).catch(()=>"TOKEN")]);Fe=Number(Wt),He=en,yt=tn}const kt=!!f&&Se(de.address,f)&&de.chainId===l;kt&&r&&(tt=r),kt&&s&&!de.configToken&&(He==="TOKEN"&&(He=s),yt==="TOKEN"&&(yt=s));const Zt=parseFloat((Number(J)/Math.pow(10,Fe)).toFixed(6));return{address:de.address,name:yt,symbol:He,decimals:Fe,balance:J,balanceFormatted:Zt,balanceUsd:0,logoURI:tt,isNative:!1,chainId:de.chainId}}catch{return null}},pn=await Promise.all(Array.from(Ye.entries()).map(async([$,de])=>{let J;try{J=pt($)}catch{return[]}const Fe=[],He=[];for(const tt of de){const kt=Fe.length;Fe.push({address:tt.address,abi:Ze,functionName:"balanceOf",args:[ue]}),tt.configToken||Fe.push({address:tt.address,abi:Ze,functionName:"decimals",args:[]},{address:tt.address,abi:Ze,functionName:"symbol",args:[]},{address:tt.address,abi:Ze,functionName:"name",args:[]}),He.push({start:kt,item:tt})}let yt=null;try{yt=await J.multicall({contracts:Fe})}catch{yt=null}return yt?He.map(({start:tt,item:kt})=>{const Zt=yt[tt],Wt=Zt?.status==="success"?Zt.result:0n;let en,tn,Sn,Kn;if(kt.configToken)en=kt.configToken.decimals,tn=kt.configToken.symbol,Sn=kt.configToken.name,Kn=kt.configToken.logo;else{const pe=yt[tt+1],Pe=yt[tt+2],Pt=yt[tt+3];en=pe?.status==="success"?Number(pe.result):18,tn=Pe?.status==="success"?Pe.result:"TOKEN",Sn=Pt?.status==="success"?Pt.result:tn}const Yn=!!f&&Se(kt.address,f)&&kt.chainId===l;Yn&&r&&(Kn=r),Yn&&s&&!kt.configToken&&(tn==="TOKEN"&&(tn=s),Sn==="TOKEN"&&(Sn=s));const ve=parseFloat((Number(Wt)/Math.pow(10,en)).toFixed(6));return{address:kt.address,name:Sn,symbol:tn,decimals:en,balance:Wt,balanceFormatted:ve,balanceUsd:0,logoURI:Kn,isNative:!1,chainId:kt.chainId}}):(await Promise.all(de.map(tt=>Ft(J,tt)))).filter(tt=>tt!==null)}));if(G!==Tt.current)return;const q=pn.flat();mt(q)},[m,bt,Qt,Ce,l,f,r,s]);X(()=>{Vt.current=mn},[mn]),X(()=>{if(!e||!m){mt([]);return}Vt.current();const G=setInterval(()=>{Vt.current()},15e3);return()=>clearInterval(G)},[m,e,bt,Qt,Ce,l,f]);const cn=ce(()=>{mn()},[mn]),dt=re(()=>$t.filter(G=>G.balance>0n),[$t]),gn=re(()=>{if(N)return dt.map(ue=>({...ue,_source:"wallet"}));if(!m)return Bt;const G=[];for(const ue of dt)G.push({...ue,_source:"wallet"});for(const ue of Bt)G.push({...ue,_source:"spice"});return G},[N,m,dt,Bt]),ze=re(()=>O?f?gn.filter(G=>Se(G.address,f)&&G.chainId===l):[]:gn,[gn,O,f,l]),Et=ie(null),qt=ie(null);X(()=>{qt.current=W},[W]),X(()=>{!O||!W?.asset||f&&Se(W.asset.address,f)&&W.asset.chainId===l||_(null)},[O,W?.asset,f,l]),X(()=>{e||(_(null),K(null),ye(null),ee(!1),ae(!1),Le(null),H(!1),oe(!1),Y(null),at(!1),_e())},[e,_e]),X(()=>{i&&i.assetAmount!==(W?.amount||"")&&_(G=>G&&{...G,amount:i.assetAmount})},[i?.assetAmount]),X(()=>{c&&c.assetAmount!==(W?.amount||"")&&_(G=>G&&{...G,amount:c.assetAmount})},[c?.assetAmount]),X(()=>{if(!N&&ct?.overallStatus==="success"&&ct.intentId&&Et.current!==ct.intentId&&Ie&&ct.steps.find(G=>G.transactionHash)?.transactionHash){Et.current=ct.intentId;const G=qt.current;if(!G?.asset||!G.amount||G.asset._source==="wallet"||Ke(G.amount,G.asset.decimals)===0n)return;ht()}},[ct,Ie,l,ht,N]);const Ge=parseFloat(W?.amount||"")||0,ot=re(()=>W?.asset?W.asset._source==="wallet"?W.asset.balanceFormatted??0:Bt.find(G=>Se(G.address,W.asset.address)&&G.chainId===W.asset.chainId)?.balanceFormatted??0:0,[W?.asset,Bt]),Yt=Ge>0&&(we?parseFloat(rt(we.grossAmount,we.decimals))>ot:Ge>ot),vt=d?.selectedDuration??p[Me]??p[0],Oe=re(()=>!W?.asset||!f?!1:Se(W.asset.address,f)&&W.asset.chainId===l,[W?.asset,f,l]),Xe=re(()=>Ge<=0?0:Oe?Ge:!v||v<=0?0:Ge/v,[Ge,v,Oe]),Mt=re(()=>Xe<=0?null:Xe.toLocaleString(void 0,{maximumFractionDigits:2}),[Xe]),gt=u&&Xe>0&&vt?u(Xe,vt.months):void 0,dn=re(()=>Ge<=0?"$0.00":Oe&&v?(Ge*v).toLocaleString(void 0,{style:"currency",currency:"USD",maximumFractionDigits:2}):!v||v<=0?"$0.00":Ge.toLocaleString(void 0,{style:"currency",currency:"USD",maximumFractionDigits:2}),[Ge,v,Oe]),Qe=re(()=>{if(!Mt)return null;const G=parseFloat(Mt.replace(/,/g,""));return Oe&&v?(G*v).toLocaleString(void 0,{maximumFractionDigits:2}):v?(G*v).toLocaleString(void 0,{maximumFractionDigits:2}):null},[Mt,v,Oe]),yn=ce(G=>{_(ue=>({asset:G,amount:ue?.asset?.address===G.address&&ue?.asset?.chainId===G.chainId&&ue.amount||""})),K(null),ye(null),ae(!1),Le(null),c?.setSelectedAsset&&c.setSelectedAsset({symbol:G.symbol,address:G.address,decimals:G.decimals,chainId:G.chainId})},[c?.setSelectedAsset]),un=ce(G=>{_(ue=>ue&&{...ue,amount:G}),K(null),ye(null),ae(!1),Le(null),i&&i.setAssetAmount(G),c&&c.setAssetAmount(G)},[i,c]),_t=ce(G=>{if(typeof o=="function"){if(!W?.asset||!W.amount)throw new Error("Select an asset and enter an amount");return o({asset:W.asset,amount:G?.amount??W.amount,amountWei:G?.amountWei??Ke(W.amount,W.asset.decimals),grossAmount:G?.grossAmount,grossAmountWei:G?.grossAmountWei,feeAdjusted:!!G})}return o},[o,W]),te=ie(null),ne=re(()=>!W?.asset||Ge<=0?!1:N?!Oe&&!C:!0,[W,Ge,N,Oe,C]),Ae=ce(()=>bc(te.current),[]);X(()=>{if(!e||xe)return;if(!W?.asset||Ge<=0){ye(null),ee(!1),ae(!1),Le(null);return}if(!ne){ye(null),ee(!1),ae(!0),Le(null);return}let G=!1;const ue=async()=>{const Ye=++it.current;ye(null),ae(!1),ee(!0);try{const Ft=await Ae();if(G||it.current!==Ye)return;ye(null),ae(!0),Le(Ft)}catch(Ft){if(G||it.current!==Ye)return;ye(bn(Ft,"Unable to calculate fees for this lock.")),ae(!1)}finally{!G&&it.current===Ye&&ee(!1)}},We=window.setTimeout(()=>{ue()},250),De=window.setInterval(()=>{ue()},1e4);return()=>{G=!0,clearTimeout(We),window.clearInterval(De),ee(!1),ae(!1)}},[e,xe,W,Ge,ne,Ae]),X(()=>{if(ct?.overallStatus==="success"){const G=ct.steps.find(ue=>ue.transactionHash);y?.(G?.transactionHash)}},[ct?.overallStatus,y]);const Je=m&&W?.asset?._source==="wallet"&&W?.asset?.chainId===l,st=ce(()=>Cc(te.current),[]),et=!!W?.asset&&Ge>0&&!Yt&&!xe&&(!ne||z&&!Ee&&!le),$e=se||le,Ve=g("div",{style:{display:"flex",alignItems:"flex-start",gap:"6px"},children:[a(ks,{color:L}),g("p",{style:{fontSize:"13px",color:L,margin:0,lineHeight:"1.5"},children:["Add ",s," by converting assets from your account"]})]});if(te.current={selectedAsset:W,parsedAmount:Ge,selectedDuration:vt,isInsufficientBalance:Yt,isSemi7702:N,isSourceDestToken:Oe,isDirectDeposit:Je,requiresRelayerFeeEstimate:ne,address:Ie,embeddedWalletAddress:Kt,providerEmbeddedAddress:Ut,externalWallet:An,externalWalletAddress:me,isConnected:Nt,ready:an,authenticated:Xt,provider:Jt,actions:In,lockChainId:l,escrowAddress:h,onLockExecute:C,onLockSuccess:y,buildSpicenetBatch:I,resolveLockBatches:_t,startStatusPolling:jt,refreshSpiceAssets:ht,refreshWalletAssets:cn,ui:{setError:K,setIsExecuting:H,setShowStatusPanel:at}},!e)return null;const qe={backgroundColor:D,border:Q,borderRadius:P,padding:"16px",marginBottom:"16px"};return a(Pn,{isOpen:e,onClose:t,title:`Add ${s} to your account`,subtitle:Ve,styles:x,dark:B,footerLinkText:"Spicenet accounts \u2192",overlayContent:Re?a("div",{}):void 0,closeOnBackdropClick:n,children:g("div",{style:{padding:"0 24px 8px 24px",position:"relative"},children:[g("div",{style:{marginBottom:"12px"},children:[w&&a("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:"6px"},children:a(vs,{onClick:w,color:F,fontFamily:E})}),a("div",{style:{marginTop:"10px",fontSize:"13px",color:L,fontFamily:E},children:a(Ao,{assets:ze,selectedAsset:W??void 0,onAssetSelect:yn,onAmountChange:un,label:"Amount",showBalance:!0,showMaxButton:!0,theme:ge,styles:Z})}),a("div",{style:{marginTop:"6px",paddingLeft:"4px",fontSize:"13px",color:L,fontFamily:E},children:dn})]}),g("div",{style:qe,children:[g("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",paddingBottom:"16px",borderBottom:B?`1px solid ${k.cardBorder}`:"1px solid #e5e7eb"},children:[g("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[r?a("img",{src:r,alt:s,style:{width:"32px",height:"32px",borderRadius:"50%",objectFit:"cover"}}):a("div",{style:{width:"32px",height:"32px",borderRadius:"50%",backgroundColor:B?k.inputBg:"#d1d5db",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"12px",fontWeight:700,color:j},children:s.slice(0,2)}),a("span",{style:{fontSize:"16px",fontWeight:600,color:j,fontFamily:E},children:s})]}),g("div",{style:{textAlign:"right"},children:[a("div",{style:{fontSize:"22px",fontWeight:700,color:j,fontFamily:E,lineHeight:1.1},children:Mt??"0.00"}),g("div",{style:{fontSize:"12px",color:L,fontFamily:E,marginTop:"2px"},children:["~$",Qe??"0.00"]})]})]}),g("div",{style:{paddingTop:"16px",paddingBottom:"16px",borderBottom:B?`1px solid ${k.cardBorder}`:"1px solid #e5e7eb"},children:[g("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},children:[a("span",{style:{fontSize:"15px",fontWeight:500,color:L,fontFamily:E},children:"Lock Duration"}),a(Un,{color:L})]}),a(ac,{options:p,selectedIndex:Me,onSelect:he,primaryColor:F,dark:B,textPrimary:j,textSecondary:L})]}),g("div",{style:{paddingTop:"12px",display:"flex",flexDirection:"column",gap:"8px"},children:[a(lc,{durationMonths:vt?.months,fontFamily:E,dark:B,textPrimary:j,textSecondary:L}),u&&a(cc,{votes:gt,fontFamily:E,dark:B,textPrimary:j,textSecondary:L})]})]}),ne&&a(Uo,{fontFamily:E,textPrimary:j,textSecondary:L,cardBg:D,cardBorder:Q,resolvedDark:B,darkCardBorder:k.cardBorder,primaryColor:F,feePreview:we,isLoading:Ee,errorText:le}),$e&&a(io,{variant:"error",palette:k,fontFamily:E,style:{marginBottom:"12px"},children:$e}),a(At,{variant:"outline",fullWidth:!0,onClick:st,disabled:!et,loading:xe,dark:B,styles:{...x,button:{...x?.button,backgroundColor:F}},children:xe?Je&&!Oe?"DEPOSITING...":Oe?"LOCKING...":"CONVERTING...":Ee&&ne?"CALCULATING FEES...":Je&&!Oe?`DEPOSIT ${s}`:Oe?`LOCK ${s}`:`CONVERT TO ${s}`}),a(dc,{isOpen:Re,data:je,isLocking:xe,lockError:$e,onContinue:st,onClose:()=>oe(!1),primaryColor:F,fontFamily:E,dark:B}),ct&&wt&&a("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:10,backgroundColor:B?"rgba(0, 0, 0, 0.45)":"rgba(255, 255, 255, 0.55)",backdropFilter:"blur(2px)",WebkitBackdropFilter:"blur(2px)",borderRadius:P},children:a(Fs,{type:"deposit",showStepBreakdown:!1,isOpen:!!ct&&ct.overallStatus!=="processing",isProcessing:xe||ct?.overallStatus==="processing",closeOnComplete:!1,onRetryTx:()=>{_e(),at(!1),st()},onNewTx:()=>{_e(),at(!1),_(null),Et.current=null,ht(),cn()},onClose:()=>{_e(),at(!1)},onComplete:()=>{_e(),at(!1),_(null),Et.current=null,ht(),cn()},results:ct?.overallStatus==="success"||ct?.overallStatus==="failed"?ct.steps.map(G=>({asset:{symbol:W?.asset?.symbol||s,address:W?.asset?.address||""},txHash:G.transactionHash||"",success:G.status==="success",amount:W?.amount})):void 0,chainName:nn(l),explorerUrl:to(l,"").replace(/\/tx\/.*$/,"")||void 0,theme:A,styles:x,dark:B})})]})})},kc="0xa9059cbb";function vc(e,t,n){return Ue(e)?{to:n,value:t,data:"0x"}:{to:e,value:0n,data:xt({abi:Ot,functionName:"transfer",args:[n,t]})}}function Qs(e,t,n,o){return t!=="user-transfer"||!n||e.length===0||e[0]?.to.toLowerCase()!==o.toLowerCase()||!e[0]?.data.startsWith(kc)?{feeCall:null,remainingCalls:e}:{feeCall:e[0],remainingCalls:e.slice(1)}}async function Go(e,t,n){if(!t)return[e];const o=await t(n);return o?[o,e]:[e]}function _n(e){return e.filter(t=>t.domain!=="spicenet")}function Xo(e){const t=(e.tokenTransfers??[]).filter(n=>n.from==="escrow").map(n=>({token:It(n.token),recipient:n.to,amount:BigInt(n.amount)})).filter(n=>n.amount>0n);return t.length>0?t:void 0}function uo(e,t,n){if(t===n)return e;if(t<n)return e*10n**BigInt(n-t);const o=10n**BigInt(t-n);return(e+o-1n)/o}async function Ic(e,t){const{currentPaymentAmount:n,destinationToken:o,embeddedWalletAddress:s,providerEmbeddedAddress:r,address:i,isNon7702:c,isPayMode:d,resolvedChainId:l,buildActionCalls:p,feeExecutionMode:u,buildSpicenetBatch:h,selectedAsset:m,needsSwap:f,exactOutputSwap:y,resolvedTokenIn:C}=e,v=Ke(n,o.decimals),b=t?.actionAmountOverride??v,w=s||r||(c?void 0:i);if(!w)throw new Error("Embedded wallet address is not available. Please sign in and try again.");const I={userAddress:w,chainId:l,destinationToken:o.address,grossAmount:t?.fundingAmountOverride??v,netAmount:b,combinedFeeAmount:t?.actionContextOverride?.combinedFeeAmount,feeExecutionMode:u,feeBreakdown:t?.actionContextOverride?.feeBreakdown,...t?.actionContextOverride},x=p(b,I),S={chainId:l,calls:x},A=(!d&&!c?!0:m?.asset?._source==="spice")||c,B=(F,k)=>({token:F,from:c?"solver":"escrow",to:w,amount:k});if(v===0n)return[S];if(f&&y){const F=C??Mn(m.asset,l)??m.asset.address,k=t?.fundingAmountOverride??y.amountInMax,E=A?[B(F,k)]:[],M={to:F,value:0n,data:xt({abi:Ot,functionName:"approve",args:[y.calls[0]?.to,y.amountInMax]})},T={chainId:l,calls:[M,...y.calls,...x],tokenTransfers:[...E,...S.tokenTransfers??[]]};return A?Go(T,h,{userAddress:w,destinationChainId:l,deliveryToken:F,deliveryAmount:k,deliveryRecipient:w,deliveryTransfers:Xo(T),sourceAsset:m.asset}):[T]}if(A){const F=C??Mn(m.asset,l)??o.address,k=t?.fundingAmountOverride??v,E={...S,tokenTransfers:[B(F,k),...S.tokenTransfers??[]]};return Go(E,h,{userAddress:w,destinationChainId:l,deliveryToken:F,deliveryAmount:k,deliveryRecipient:w,deliveryTransfers:Xo(E),sourceAsset:m.asset})}return[S]}async function Ac(e,t){const{selectedAsset:n,embeddedWalletAddress:o,externalWalletAddress:s,resolvedChainId:r,destinationToken:i,buildActionCalls:c,feeExecutionMode:d,buildSpicenetBatch:l,isPayMode:p,isNon7702:u,needsSwap:h,resolvedSwap:m,quoteAmountOut:f,resolvedTokenIn:y}=e,C=m?.amountOutMinimum??f;if(!n?.asset||!o)return[];const v=u?s:o;if(!v)return[];const b=t?.fundingAmountOverride??t?.actionAmountOverride??Ke(n.amount,n.asset.decimals),w=t?.fundingAmountOverride??b,I=t?.sourceFundingAmountOverride??b,x=t?.deliveryAmountOverride??w,S=t?.withdrawalAmountOverride??x,A=t?.actionAmountOverride??b,B={userAddress:v,chainId:r,destinationToken:i.address,feeToken:d==="user-transfer"&&h&&y?y:i.address,grossAmount:w,netAmount:A,combinedFeeAmount:t?.actionContextOverride?.combinedFeeAmount,feeExecutionMode:d,feeBreakdown:t?.actionContextOverride?.feeBreakdown,...t?.actionContextOverride},F=c(A,B),k=n.asset?._source==="wallet";if(!p&&u&&k&&n.asset.chainId===r){if(h){if(!y)throw new Error("Swap input token could not be resolved");if(!m||C===null)throw new Error("Swap quote not available yet")}if(h&&m&&C){const Q=c(t?.actionAmountOverride??C,{...B,netAmount:t?.actionAmountOverride??C}),{feeCall:P,remainingCalls:j}=Qs(Q,d,h,B.feeToken);return[{chainId:r,calls:[...P?[P]:[],...m.calls,...j]}]}return[{chainId:r,calls:F}]}if(!p&&!u&&k){if(n.asset.chainId===r){if(h){if(!y)throw new Error("Swap input token could not be resolved");if(!m||C===null)throw new Error("Swap quote not available yet")}if(h&&m&&C){const Q=c(t?.actionAmountOverride??C,{...B,netAmount:t?.actionAmountOverride??C}),{feeCall:P,remainingCalls:j}=Qs(Q,d,h,B.feeToken);return[{chainId:r,calls:[...P?[P]:[],...m.calls,...j]}]}return[{chainId:r,calls:F}]}throw new Error("Cross-chain wallet supplies require external wallet mode")}const E=!p&&!u?n.asset?._source!=="wallet":n.asset?._source==="spice",M=u&&k;if(!(E||M))return[{chainId:r,calls:F}];const T=M&&n.asset.chainId!==r?{chainId:n.asset.chainId,calls:[vc(It(n.asset.address),I,wn(n.asset.chainId))]}:null,O=(Q,P)=>({token:Q,from:M?"solver":"escrow",to:o,amount:P}),N=(Q,P)=>M?[{token:Q,from:"escrow",to:ei,amount:P}]:[];if(h){if(!y)throw new Error("Swap input token could not be resolved");if(!m||C===null)throw new Error("Swap quote not available yet")}if(h&&m&&C&&y){const Q=c(t?.actionAmountOverride??C,{...B,netAmount:t?.actionAmountOverride??C}),{feeCall:P,remainingCalls:j}=Qs(Q,d,h,B.feeToken),L={chainId:r,calls:[...P?[P]:[],...m.calls,...j],tokenTransfers:[...N(y,S),O(y,x)]},Z=await Go(L,l,{userAddress:o,destinationChainId:r,deliveryToken:y,deliveryAmount:x,withdrawalAmount:S,deliveryRecipient:o,deliveryTransfers:Xo(L),sourceAsset:n.asset});return T?[T,...Z]:Z}const U=y??Mn(n.asset,r)??i.address,V={chainId:r,calls:F,tokenTransfers:[...N(U,S),O(U,x)]},D=await Go(V,l,{userAddress:o,destinationChainId:r,deliveryToken:U,deliveryAmount:x,withdrawalAmount:S,deliveryRecipient:o,deliveryTransfers:Xo(V),sourceAsset:n.asset});return T?[T,...D]:D}async function Sc(e,t,n,o,s){let r=e;for(let i=0;i<4;i++){const c=await t(r),d=await o(c,n,r,s),l=Nl(d);if(l===null||l>=e)return r;const p=r-l,u=e+p;if(u<=r)return r;r=u}return r}function Ec(e,t,n,o){if(e<=0n)return 0n;const s=e-t;if(s<=0n)return 0n;const r=o+n;return r<=0n?s:s*o/r}function Fc(e,t){const n=rt(e,t);return n.includes(".")?n.replace(/\.?0+$/,"")||"0":n}async function Bc(e){const{asset:t,isPayMode:n,isNon7702:o,needsSwap:s,isQuoting:r,embeddedWalletAddress:i,buildSupplyChainBatches:c,estimateGasless:d,executionTokenAddress:l,feeExecutionMode:p}=e;if(n||o||s||r||!i||t.balance<=0n)return null;const u=i,h=await c({fundingAmountOverride:t.balance,actionAmountOverride:t.balance});if(h.length===0)return null;const m=h.some(w=>w.tokenTransfers?.length),f=await d(h,l,t.balance,m?{userOverride:u,useCustomTransfers:!0,feeExecutionMode:p}:p?{userOverride:u,feeExecutionMode:p}:{userOverride:u}),y=Qn(f,{chainId:t.chainId,tokenAddress:t.address,symbol:t.symbol,decimals:t.decimals}),C=y?uo(y.gasFee,y.decimals,t.decimals):0n,v=y?uo(y.spicenetFee,y.decimals,t.decimals):0n,b=Ec(t.balance,C,v,t.balance);return b>0n?Fc(b,t.decimals):null}async function Tc(e){const{selectedAsset:t,isPayMode:n,parsedAmount:o,needsSwap:s,exactOutputSwap:r,isNon7702:i,isSourceDestToken:c,currentPaymentAmount:d,destinationToken:l,feeExecutionMode:p,resolvedTokenIn:u,embeddedWalletAddress:h,providerEmbeddedAddress:m,resolvedChainId:f,isConnected:y,address:C,ready:v,authenticated:b,isDirect:w,resolvedSwap:I,isQuoting:x,executionTokenAddress:S,buildPayChainBatches:A,buildSupplyChainBatches:B,estimateGasless:F,estimateRequiredGrossFunding:k}=e;if(!t?.asset)return null;if(n){if(o<=0||s&&!r||i&&c)return null;const D=Ke(d,l.decimals),Q=u||Mn(t.asset,f)||t.asset.address||l.address,P={chainId:f,tokenAddress:Q,symbol:Dt(Q,f)?.symbol??t.asset.symbol,decimals:Dt(Q,f)?.decimals??t.asset.decimals};if(i){const _=h||m;if(!_)return null;const fe=_,be=s?r?.amountInMax??0n:D;if(be===0n)return null;const Me=await k(be,H=>A({fundingAmountOverride:H}).then(se=>rn(_n(se),fe)),Q,{userOverride:_,useCustomTransfers:!0}),he=rn(_n(await A({fundingAmountOverride:Me})),fe),xe=await F(he,Q,Me,{userOverride:_,useCustomTransfers:!0,feeExecutionMode:p});return Qn(xe,P)}if(!y||!C||!v||!b)return null;const j=h||m||C,L=s?r?.amountInMax??0n:D;if(L===0n)return null;const Z=await k(L,_=>A({fundingAmountOverride:_}).then(fe=>rn(_n(fe),j)),Q,{useCustomTransfers:!0});let ge=rn(_n(await A({fundingAmountOverride:Z})),j);const W=await F(ge,Q,Z,{useCustomTransfers:!0,feeExecutionMode:p});return Qn(W,P)}if(o<=0||!h)return null;const E=h||m;if(!(!n&&!i&&t.asset?._source==="wallet"&&t.asset.chainId!==f)&&!w&&!I&&!x||x)return null;const M=Ke(t.amount,t.asset.decimals),T=await B();if(T.length===0)return null;const O=i&&t.asset?._source==="wallet"&&t.asset.chainId===f,N={chainId:f,tokenAddress:S,symbol:Dt(S,f)?.symbol??l.symbol,decimals:Dt(S,f)?.decimals??l.decimals};if(O){const D=await nt.estimateBatchGas({user:E,outputToken:S,stepIndex:0,chainBatches:T}),Q=Vo(M,10n),P=Q+D.gasFee;return{...N,grossAmount:M+P,netAmount:M,totalFee:P,gasFee:D.gasFee,spicenetFee:Q,bridgeFee:0n,gasQuoteSource:D.gasQuoteSource}}const U=T.some(D=>D.tokenTransfers?.length),V=await F(T,S,M,U?{userOverride:E,useCustomTransfers:!0,feeExecutionMode:p}:p?{userOverride:E,feeExecutionMode:p}:{userOverride:E});return Qn(V,N)}const Mc=10n;function ia(e,t){const n=e.selectedAsset?.asset;if(!n||n?._source!=="wallet")return;const o=Mn(n,e.resolvedChainId);if(!o||!Se(o,e.executionTokenAddress))return;const s=Dt(e.executionTokenAddress,e.resolvedChainId),r=uo(t,s?.decimals??e.destinationToken.decimals,n.decimals);if(r<=n.balance)return;const i=rt(r,n.decimals),c=rt(n.balance,n.decimals);throw new Error(`Insufficient ${n.symbol} for amount plus fees. Required ${i} ${n.symbol}; available ${c} ${n.symbol}.`)}function la(e){const t=Dt(e.executionTokenAddress,e.resolvedChainId);return{chainId:e.resolvedChainId,tokenAddress:e.executionTokenAddress,symbol:t?.symbol??e.destinationToken.symbol,decimals:t?.decimals??e.destinationToken.decimals}}function ca(e,t,n){const o=Qn(e,la(t));if(!o)return;const s=Vo(n,Mc),r=o.bridgeFee??0n,i=s+o.gasFee+r;return{grossAmount:n+i,netAmount:n,combinedFeeAmount:i,feeExecutionMode:"user-transfer",feeBreakdown:{spicenetFee:s,gasFee:o.gasFee,bridgeFee:r}}}function po(e,t,n){if(e===t)return!0;const o=e>t?e:t;return o===0n?!1:(e>t?e-t:t-e)*10000n<=o*n}function da(e,t,n){let o=0n,s=0n;const r=n.toLowerCase();for(const i of e)if(i.chainId===t){for(const c of i.calls??[])if(c.to.toLowerCase()===r)try{const d=Co({abi:Ot,data:c.data});if(d.functionName!=="transfer")continue;const l=d.args[0].toLowerCase(),p=d.args[1];l===xo.toLowerCase()?o+=p:l===Tn.toLowerCase()&&(s+=p)}catch{continue}}return{spicenetFee:o,gasFee:s}}function Rc(e,t,n){const o=t.feeExecutionMode==="user-transfer"&&t.needsSwap&&t.resolvedTokenIn?t.resolvedTokenIn:t.executionTokenAddress,s=da(e,t.resolvedChainId,o);return s.spicenetFee===0n&&n.feeBreakdown.spicenetFee>0n||s.gasFee===0n&&n.feeBreakdown.gasFee>0n?!1:po(s.spicenetFee,n.feeBreakdown.spicenetFee,100n)&&po(s.gasFee,n.feeBreakdown.gasFee,100n)}function Dc(e,t){return e?po(e.grossAmount,t.grossAmount,100n)&&po(e.feeBreakdown.spicenetFee,t.feeBreakdown.spicenetFee,100n)&&po(e.feeBreakdown.gasFee,t.feeBreakdown.gasFee,100n)&&po(e.feeBreakdown.bridgeFee,t.feeBreakdown.bridgeFee,100n):!1}async function Nc(e){if(!e.selectedAsset?.asset||e.parsedAmount<=0){e.ui.setError("Select an asset and enter an amount");return}if(e.isInsufficientBalance){e.ui.setError("Insufficient balance");return}if(e.isNon7702){if(!e.externalWalletAddress){e.ui.setError("Please connect your external wallet to continue");return}e.ui.setIsExecuting(!0),e.ui.setError(null),e.ui.setTxHash(null);try{if(e.isSourceDestToken){e.ui.setStep("executing"),e.ui.setStatusMsg("Submitting transaction...");const n=await ua(e);e.ui.setTxHash(n??null)}else{e.ui.setStep("signing-delegation"),e.ui.setStatusMsg("Building transaction..."),e.refs.spiceDepositSubmittedRef.current=!1;const n=new AbortController;e.refs.abortControllerRef.current=n,await Wc(e,n.signal)}e.ui.setStep("success"),e.ui.setStatusMsg(e.isSourceDestToken?"Transaction confirmed":"Deposit confirmed")}catch(n){const o=n instanceof Error?n:new Error(String(n));if(o.name==="AbortError"||e.refs.abortControllerRef.current?.signal.aborted){e.ui.setStep("idle");return}const s=o.message||"Transaction failed";e.ui.setStep("error"),e.ui.setStatusMsg(s),e.ui.setError(s),e.onError?.(o)}finally{e.ui.setIsExecuting(!1)}return}if(!e.embeddedWalletAddress){e.ui.setError("Wallet not ready");return}e.ui.setIsExecuting(!0),e.ui.setError(null),e.ui.setStep("signing-delegation"),e.ui.setStatusMsg("Building transaction..."),e.ui.setTxHash(null),e.refs.spiceDepositSubmittedRef.current=!1;const t=new AbortController;e.refs.abortControllerRef.current=t;try{const n=Ke(e.selectedAsset.amount,e.selectedAsset.asset.decimals),o=n;let s=await e.gasless.buildSupplyChainBatches();const r=e.selectedAsset.asset?._source==="wallet",i=e.embeddedWalletAddress||e.providerEmbeddedAddress;if(e.buildSpicenetBatch&&!e.isPayMode&&!e.isNon7702&&!r&&!s.some(m=>Do(m.chainId)))throw new Error("Spice-funded supplies must include a Spicenet funding batch before the destination chain batch.");const c=s.some(m=>m.tokenTransfers?.length)?{userOverride:i,useCustomTransfers:!0,feeExecutionMode:e.feeExecutionMode}:e.feeExecutionMode?{userOverride:i,feeExecutionMode:e.feeExecutionMode}:{userOverride:i};let d=n;const l=e.feeExecutionMode==="user-transfer"&&e.needsSwap&&!e.exactOutputSwap,p=e.feeExecutionMode==="user-transfer"&&!l?o:void 0;let u;for(let m=0;m<4;m+=1){const f=await e.gasless.estimateGasless(s,e.executionTokenAddress,d,c),y=Qn(f,la(e));u=e.feeExecutionMode==="user-transfer"&&y?ca(f,e,o):void 0;const C=u?.grossAmount??y?.grossAmount??d;if(C===d){d=C;break}d=C,s=await e.gasless.buildSupplyChainBatches({fundingAmountOverride:d,actionAmountOverride:p,actionContextOverride:u})}e.feeExecutionMode==="user-transfer"&&(ia(e,d),s=await e.gasless.buildSupplyChainBatches({fundingAmountOverride:d,actionAmountOverride:p,actionContextOverride:u}));let h=u;await e.gasless.executeGasless(s,e.executionTokenAddress,d,e.gasless.onProgress,t.signal,e.feeExecutionMode==="user-transfer"?{...c,skipUserFundingPreflight:!0,adjustBatchesForEstimate:({feeEstimate:m,chainBatches:f})=>{const y=ca(m,e,o);if(!y)return null;const C=e.feeExecutionMode==="user-transfer"&&e.needsSwap&&e.resolvedTokenIn?e.resolvedTokenIn:e.executionTokenAddress;da(f,e.resolvedChainId,C);const v=Dc(h,y),b=Rc(f,e,y);return v||b?null:(h=y,e.gasless.buildSupplyChainBatches({fundingAmountOverride:y.grossAmount,actionAmountOverride:p,actionContextOverride:y}))}}:c),e.ui.setStep("success"),e.ui.setStatusMsg("Deposit confirmed")}catch(n){const o=n instanceof Error?n:new Error(String(n));if(o.name==="AbortError"||t.signal.aborted){e.ui.setStep("idle");return}const s=o.message||"Transaction failed";e.ui.setStep("error"),e.ui.setStatusMsg(s),e.ui.setError(s),e.onError?.(o)}finally{e.ui.setIsExecuting(!1)}}async function Wc(e,t){if(!e.selectedAsset?.asset)throw new Error("Select a payment source");if(!e.externalWalletAddress||!e.externalWallet)throw new Error("Please connect your external wallet to continue");const n=e.embeddedWalletAddress||e.providerEmbeddedAddress;if(!n)throw new Error("Embedded wallet not available \u2014 sign in to create one before supplying");const o=e.selectedAsset.asset,s=Ke(e.selectedAsset.amount,o.decimals),r=s,i=o?._source==="wallet"&&o.chainId===e.resolvedChainId;let c=await e.gasless.buildSupplyChainBatches();const d={userOverride:n,useCustomTransfers:!0,feeExecutionMode:e.feeExecutionMode};let l=s;const p=e.feeExecutionMode==="user-transfer"&&e.needsSwap&&!e.exactOutputSwap,u=e.feeExecutionMode==="user-transfer"&&!p?r:void 0;let h;if(i){const B=await nt.estimateBatchGas({user:n,outputToken:e.executionTokenAddress,stepIndex:0,chainBatches:c}),F=Vo(s,10n),k=F+B.gasFee;l=s+k,e.feeExecutionMode==="user-transfer"&&(h={grossAmount:l,netAmount:r,combinedFeeAmount:k,feeExecutionMode:e.feeExecutionMode,feeBreakdown:{spicenetFee:F,gasFee:B.gasFee,bridgeFee:0n}})}else{const B=await e.gasless.estimateGasless(c,e.executionTokenAddress,0n,d),F=Qn(B,{chainId:e.resolvedChainId,tokenAddress:e.executionTokenAddress,symbol:Dt(e.executionTokenAddress,e.resolvedChainId)?.symbol??e.destinationToken.symbol,decimals:Dt(e.executionTokenAddress,e.resolvedChainId)?.decimals??e.destinationToken.decimals});F&&(l=F.grossAmount>s?F.grossAmount:s,e.feeExecutionMode==="user-transfer"&&(h={grossAmount:l,netAmount:r,combinedFeeAmount:F.totalFee,feeExecutionMode:e.feeExecutionMode,feeBreakdown:{spicenetFee:F.spicenetFee,gasFee:F.gasFee,bridgeFee:F.bridgeFee??0n}}))}const m=Dt(e.executionTokenAddress,e.resolvedChainId),f=i?l:uo(l,m?.decimals??e.destinationToken.decimals,o.decimals);ia(e,l),c=await e.gasless.buildSupplyChainBatches({fundingAmountOverride:l,sourceFundingAmountOverride:f,withdrawalAmountOverride:l,actionAmountOverride:u,actionContextOverride:h});const y=o.chainId,C=n,v=await e.externalWallet.getEthereumProvider();let b=null;try{const B=await v.request({method:"eth_chainId"});b=parseInt(B,16)}catch{b=null}b!==y&&(e.ui.setStatusMsg("Switching source network..."),await Hn(v,y));const w=Be(y),I=Dn({account:e.externalWalletAddress,chain:w?.viemChain,transport:Nn(v)}),x=It(o.address),S=o.isNative||Ue(x);e.ui.setStatusMsg("Funding embedded wallet...");const A=S?await I.sendTransaction({to:C,value:f,chain:w?.viemChain}):await I.sendTransaction({to:x,data:xt({abi:Ot,functionName:"transfer",args:[C,f]}),chain:w?.viemChain});if((await pt(y).waitForTransactionReceipt({hash:A,timeout:12e4,pollingInterval:2e3,confirmations:1})).status!=="success")throw new Error("Embedded wallet funding failed");e.ui.setStatusMsg("Signing supply intent..."),await e.gasless.executeGasless(c,e.executionTokenAddress,0n,e.gasless.onProgress,t,d)}async function ua(e){if(!e.selectedAsset?.asset)throw new Error("Select a payment source");if(!e.externalWalletAddress||!e.externalWallet)throw new Error("Please connect your external wallet to continue");const t=Ke(e.isPayMode?e.currentPaymentAmount:e.selectedAsset.amount,e.destinationToken.decimals),n={userAddress:e.externalWalletAddress,chainId:e.resolvedChainId,destinationToken:e.destinationToken.address},o=e.buildActionCalls(t,n);if(o.length===0)throw new Error("No action calls configured");const s=await e.externalWallet.getEthereumProvider();let r=null;try{const p=await s.request({method:"eth_chainId"});r=parseInt(p,16)}catch{r=null}r!==e.resolvedChainId&&await Hn(s,e.resolvedChainId);const i=Be(e.resolvedChainId),c=Dn({account:e.externalWalletAddress,chain:i?.viemChain,transport:Nn(s)}),d=pt(e.resolvedChainId);let l;for(const p of o){const u=await c.sendTransaction({to:p.to,data:p.data,value:p.value,chain:i?.viemChain});if((await d.waitForTransactionReceipt({hash:u,timeout:12e4,pollingInterval:2e3,confirmations:1})).status!=="success")throw new Error("Transaction failed");l=u}return l}async function Pc(e){if(!e.selectedAsset?.asset)throw new Error("Select a payment source");if(!e.externalWalletAddress||!e.externalWallet)throw new Error("Please connect your external wallet to continue");const t=e.embeddedWalletAddress||e.providerEmbeddedAddress;if(!t)throw new Error("Embedded wallet not available \u2014 sign in to create one before paying");const n=e.selectedAsset.asset,o=n.chainId,s=Ke(e.currentPaymentAmount,e.destinationToken.decimals),r=e.selectedIsEquivalent?s:e.exactOutputSwap?e.exactOutputSwap.amountInMax:0n;if(r===0n)throw new Error("Quote not available yet");const i=e.resolvedTokenIn||e.selectedAsset.asset.address,c={userOverride:t,useCustomTransfers:!0},d=await e.gasless.estimateRequiredGrossFunding(r,b=>e.gasless.buildPayChainBatches({fundingAmountOverride:b}),i,c),l=wn(o),p=await e.externalWallet.getEthereumProvider();let u=null;try{const b=await p.request({method:"eth_chainId"});u=parseInt(b,16)}catch{u=null}u!==o&&await Hn(p,o);const h=Be(o),m=Dn({account:e.externalWalletAddress,chain:h?.viemChain,transport:Nn(p)}),f=It(n.address),y=n.isNative||Ue(f)?await m.sendTransaction({to:l,value:d,chain:h?.viemChain}):await m.sendTransaction({to:f,data:xt({abi:Ot,functionName:"transfer",args:[l,d]}),chain:h?.viemChain});if((await pt(o).waitForTransactionReceipt({hash:y,timeout:12e4,pollingInterval:2e3,confirmations:1})).status!=="success")throw new Error("Escrow deposit failed");const C=await e.gasless.buildPayChainBatches({fundingAmountOverride:d}),v=C.some(b=>b.tokenTransfers?.length);return await e.gasless.executeGasless(C,i,d,b=>{b.txHash&&(e.ui.setPaymentResult(w=>({...w??{status:"processing"},txHash:b.txHash})),e.ui.setTxHash(b.txHash))},void 0,v?c:{userOverride:t})}async function Uc(e){if(e.parsedAmount<0){e.ui.setError("Enter a valid payment amount");return}if(!e.selectedAsset?.asset){e.ui.setError("Select a payment source");return}if(e.isInsufficientBalance){e.ui.setError("Insufficient balance");return}if(e.parsedAmount>0&&e.needsSwap&&!e.exactOutputSwap){e.ui.setError("Swap quote not available. Try a different asset.");return}if(e.isNon7702){if(!e.externalWalletAddress){e.ui.setError("Please connect your external wallet to continue");return}e.ui.setIsExecuting(!0),e.ui.setError(null),e.ui.setShowStatusPanel(!0),e.ui.setPaymentResult({status:"processing"});try{let t;if(e.isSourceDestToken||e.parsedAmount===0)t=await ua(e);else if(e.onPayExecute&&e.selectedAsset?.asset){const n=e.selectedAsset.asset,o=Ke(e.currentPaymentAmount,e.destinationToken.decimals),s=e.selectedIsEquivalent?o:e.exactOutputSwap?e.exactOutputSwap.amountInMax:0n;if(s===0n)throw new Error("Quote not available yet");const r=e.embeddedWalletAddress||e.providerEmbeddedAddress;if(!r)throw new Error("Embedded wallet not available \u2014 sign in to create one before paying");const i=e.resolvedTokenIn||n.address,c=await e.gasless.estimateRequiredGrossFunding(s,p=>e.gasless.buildPayChainBatches({fundingAmountOverride:p}),i,{userOverride:r,useCustomTransfers:!0}),d=await e.gasless.buildPayChainBatches({fundingAmountOverride:c}),l=await e.onPayExecute({asset:n,amount:e.currentPaymentAmount,amountWei:o,destinationToken:e.destinationToken,chainBatches:d,requiredNetFunding:s,grossFundingAmount:c,selectedIsEquivalent:e.selectedIsEquivalent,resolvedTokenIn:i,exactOutputSwapAmountInMax:e.exactOutputSwap?.amountInMax});l&&(e.ui.setTxHash(l),e.ui.setPaymentResult(p=>({...p??{status:"processing"},txHash:l}))),t=l||void 0}else t=await Pc(e);e.ui.setPaymentResult(n=>({status:"success",txHash:n?.txHash||t||""}))}catch(t){const n=bn(t,"Payment failed. Please try again.");e.ui.setError(n),e.ui.setPaymentResult({status:"failed",error:n}),e.onError?.(t instanceof Error?t:new Error(n))}finally{e.ui.setIsExecuting(!1)}return}if(!e.isConnected||!e.address){e.ui.setError("Please connect your wallet to continue");return}if(!e.ready||!e.authenticated){e.ui.setError(`Please authenticate with ${e.provider||"wallet provider"} to continue`);return}e.ui.setIsExecuting(!0),e.ui.setError(null),e.ui.setShowStatusPanel(!0),e.ui.setPaymentResult({status:"processing"});try{const t=Ke(e.currentPaymentAmount,e.destinationToken.decimals),n=e.resolvedTokenIn||e.selectedAsset?.asset?.address||e.destinationToken.address,o=e.needsSwap?e.exactOutputSwap?.amountInMax??0n:t,s={useCustomTransfers:!0,feeExecutionMode:e.feeExecutionMode},r=e.embeddedWalletAddress||e.providerEmbeddedAddress||e.address,i=await e.gasless.estimateRequiredGrossFunding(o,m=>e.gasless.buildPayChainBatches({fundingAmountOverride:m}).then(f=>rn(_n(f),r)),n,s);let c=i,d=rn(_n(await e.gasless.buildPayChainBatches({fundingAmountOverride:i})),r);const l=await e.gasless.estimateGasless(d,n,i,s),p=Qn(l,{chainId:e.resolvedChainId,tokenAddress:n,symbol:Dt(n,e.resolvedChainId)?.symbol??e.selectedAsset.asset.symbol,decimals:Dt(n,e.resolvedChainId)?.decimals??e.selectedAsset.asset.decimals})?.grossAmount??i;p!==i&&(c=p),d=rn(_n(await e.gasless.buildPayChainBatches({fundingAmountOverride:c})),r,l,{payoutAlreadyGross:!0});const u=d.some(m=>m.tokenTransfers?.length),h=await e.gasless.executeGasless(d,n,u?c:0n,m=>{m.txHash&&(e.ui.setPaymentResult(f=>({...f,txHash:m.txHash})),e.ui.setTxHash(m.txHash))},void 0,s);e.ui.setPaymentResult(m=>({status:"success",txHash:m?.txHash||h}))}catch(t){const n=bn(t,"Payment failed. Please try again.");e.ui.setError(n),e.ui.setPaymentResult({status:"failed",error:n}),e.onError?.(t instanceof Error?t:new Error(n))}finally{e.ui.setIsExecuting(!1)}}const pa=({variant:e,destinationSymbol:t,destinationLogoURI:n,destinationDecimals:o,primaryColor:s,fontFamily:r,textPrimary:i,textSecondary:c,cardBg:d,cardBorder:l,dk:p,dark:u,isQuoting:h,quoteError:m,estimatedOutput:f,paymentAmount:y,needsSwap:C,exactOutputSwap:v,adjustable:b=!1,maxAmount:w,onAmountChange:I})=>e==="supply"?g("div",{style:{backgroundColor:d,border:`1px solid ${l}`,borderRadius:u?"8px":"7px",padding:"14px 16px 12px 16px",marginBottom:"16px",minHeight:"112px",display:"flex",flexDirection:"column",justifyContent:"space-between"},children:[g("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"12px"},children:[g("div",{style:{minWidth:0},children:[a("span",{style:{fontFamily:r,fontSize:"17px",fontWeight:500,color:u?"#a7abb2":"#7D7C7B",lineHeight:"24px"},children:"Used in TX"}),a("div",{style:{fontSize:"12px",fontWeight:500,color:c,fontFamily:r,marginTop:"10px"},children:"Net amount after swap and fees"})]}),g("div",{style:{textAlign:"right",minWidth:0,display:"inline-flex",alignItems:"center",gap:"8px",border:`1px solid ${l}`,borderRadius:"8px",padding:"8px 10px",minHeight:"42px"},children:[a(fa,{symbol:t,logoURI:n,primaryColor:s,size:24}),a("span",{style:{fontSize:"16px",fontWeight:500,color:u?"#f3f4f6":"#3C3E42",lineHeight:"1.3",fontFamily:r,letterSpacing:0},children:t})]})]}),a("div",{style:{textAlign:"right",minWidth:0},children:h?a("span",{style:{fontSize:"18px",color:c,fontFamily:r},children:"Quoting..."}):m?a("span",{style:{fontSize:"13px",color:u?"#f87171":"#dc2626",fontFamily:r},children:"Quote failed"}):f?a(Jn,{value:f,title:f,fontFamily:r,color:i,lineHeight:"0.95",textAlign:"right",maxFontSize:32,minFontSize:18}):a("span",{style:{fontSize:"20px",color:c,fontFamily:r},children:"\u2014"})})]}):a(Lc,{destinationSymbol:t,destinationLogoURI:n,destinationDecimals:o,primaryColor:s,fontFamily:r,textPrimary:i,textSecondary:c,cardBg:d,cardBorder:l,dk:p,dark:u,paymentAmount:y||"0",needsSwap:C,exactOutputSwap:v,isQuoting:h,adjustable:b,maxAmount:w,onAmountChange:I}),fa=({symbol:e,logoURI:t,primaryColor:n,size:o})=>t?a("img",{src:t,alt:e,style:{width:o,height:o,borderRadius:"50%",objectFit:"cover"}}):a("div",{style:{width:o,height:o,borderRadius:"50%",backgroundColor:`${n}22`,display:"flex",alignItems:"center",justifyContent:"center",fontSize:o<30?"11px":"12px",fontWeight:700,color:n},children:e.slice(0,2)}),Lc=({destinationSymbol:e,destinationLogoURI:t,destinationDecimals:n,primaryColor:o,fontFamily:s,textPrimary:r,textSecondary:i,cardBg:c,cardBorder:d,dk:l,dark:p,paymentAmount:u,needsSwap:h,exactOutputSwap:m,isQuoting:f,adjustable:y,maxAmount:C,onAmountChange:v})=>{const b='"IBM Plex Mono", monospace',w=parseFloat(u||"0"),I=C?parseFloat(C):0,[x,S]=R(u||""),A=ie(null),[B,F]=R(null),[k,E]=R(null);X(()=>{y||S(u||"")},[u,y]);const M=N=>{let U=N;U.startsWith(".")&&(U="0"+U);const V=so(U);let D=V;C&&parseFloat(V)>parseFloat(C)&&(D=C),S(D),A.current&&clearTimeout(A.current),A.current=setTimeout(()=>v?.(D),300)},T=N=>{if(!I)return;if(N===100){S(C||I.toString()),A.current&&clearTimeout(A.current),v?.(C||I.toString());return}const U=10**n,V=Math.floor(I*N/100*U)/U,D=ro(V,n);S(D),A.current&&clearTimeout(A.current),v?.(D)},O=I>0?parseFloat(x||"0")/I*100:0;return X(()=>()=>{A.current&&clearTimeout(A.current)},[]),g("div",{style:{backgroundColor:c,border:`1px solid ${d}`,borderRadius:p?"12px":"6px",padding:"16px",marginBottom:"16px"},children:[g("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[g("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[a(fa,{symbol:e,logoURI:t,primaryColor:o,size:32}),g("div",{children:[a("span",{style:{fontSize:"14px",fontWeight:600,color:r,fontFamily:s},children:"Payment"}),a("div",{style:{fontSize:"12px",color:i,fontFamily:s,marginTop:"2px"},children:e})]})]}),g("div",{style:{textAlign:"right"},children:[y?a(Jn,{element:"input",ariaLabel:`${e} amount`,dataSpiceflowFocus:!0,value:x,onChange:N=>M(N.target.value),placeholder:"0.0",fontFamily:b,color:r,lineHeight:1.1,textAlign:"right",maxFontSize:20,minFontSize:12,style:{width:"120px"}}):a(Jn,{element:"div",value:w>0?u:"0.00",title:w>0?u:"0.00",fontFamily:b,color:r,lineHeight:1.1,textAlign:"right",maxFontSize:20,minFontSize:12}),a("div",{style:{fontSize:"12px",color:i,fontFamily:b,marginTop:"2px"},children:e}),y&&I>0&&a("div",{style:{display:"flex",justifyContent:"flex-end",alignItems:"center",gap:"10px",marginTop:"6px"},children:[0,25,50,75,100].map((N,U)=>{const V=Math.abs(O-N)<1,D=U===4,Q=N/100,P=B===N,j=k===N;return a("button",{onClick:()=>T(N),onMouseEnter:()=>F(N),onMouseLeave:()=>{F(null),E(null)},onMouseDown:()=>E(N),onMouseUp:()=>E(null),title:`${N}%`,style:{width:"14px",height:"14px",padding:0,border:"none",backgroundColor:"transparent",cursor:"pointer",opacity:V?1:P?.8:.5,transform:j?"scale(0.85)":P?"scale(1.15)":"scale(1)",transition:sn.interactive},children:g("svg",{width:"14",height:"14",viewBox:"0 0 14 14",children:[a("circle",{cx:"7",cy:"7",r:"6.84375",fill:D?o:"none",stroke:D?o:p?"#4a5568":"#3C3E42",strokeWidth:"0.3125"}),!D&&Q>0&&a("path",{d:`M 7 7 L 7 0.15625 A 6.84375 6.84375 0 ${Q>.5?1:0} 1 ${7+6.84375*Math.sin(Q*2*Math.PI)} ${7-6.84375*Math.cos(Q*2*Math.PI)} Z`,fill:p?l?.textSecondary||"#9ca3af":"#3C3E42"})]})},N)})})]})]}),h&&m&&!f&&a("div",{style:{marginTop:"12px",paddingTop:"12px",borderTop:p?`1px solid ${l?.cardBorder||d}`:"1px solid #e5e7eb",display:"flex",justifyContent:"flex-end"},children:g("span",{style:{fontSize:"11px",color:i,fontFamily:s,opacity:.7},children:["via ",m.venue]})})]})};function ha(e,t,n){const o=Se(e.address,t),s=e.chainId===n,r=e._source==="wallet";return r&&o&&s?0:r&&s?1:!r&&o?2:!r&&s?3:4}function zc(e,t){return!t||t.length===0||t.some(n=>Se(n,e.address))?!0:Object.keys(e.chainTokens??{}).some(n=>{const o=co(n);return o?t.some(s=>Se(s,o.address)):!1})}function Oc(e){const{destinationToken:t,supportedSourceAssets:n,sourceChains:o,enabled:s}=e,r=(Gt(Lt)?.mode||"7702")!=="7702",i=Bn(),{externalAddress:c,embeddedAddress:d}=no(),l=i||d,{assets:p,refetch:u}=Eo({address:l,supportedChains:o,enabled:s&&!r&&!!l,refetchInterval:3e4}),h=re(()=>r?[]:p.filter(A=>zc(A,n)),[p,n,r]),m=r?c:i,f=re(()=>{const A=new Set,B=[],F=k=>{if(!k)return;const E=k.toLowerCase();A.has(E)||(A.add(E),B.push(Ne(k)))};if(F(t.address),r&&n)for(const k of n)F(k);return B},[r,t.address,n]),y=re(()=>f.map(A=>A.toLowerCase()).sort().join(","),[f]),C=re(()=>JSON.stringify([...o||[]].sort()),[o]),[v,b]=R([]),w=ie(0),I=ie(async()=>{}),x=ce(async()=>{if(!s||!m||f.length===0){w.current++,b([]);return}const A=++w.current,B=Ne(m),F=r?o&&o.length>0?o:[t.chainId]:[t.chainId],k=[];for(const O of f){const N=O.toLowerCase();if(N===zt)continue;if(N===t.address.toLowerCase()){const V=Be(t.chainId)?.supportedTokens?.find(D=>Se(D.address,N));k.push({address:O,chainId:t.chainId,configToken:V?{decimals:V.decimals,symbol:V.symbol,name:V.name,logo:V.logo}:void 0});continue}let U=!1;for(const V of F){const D=Be(V)?.supportedTokens?.find(Q=>Se(Q.address,N));if(D){k.push({address:O,chainId:V,configToken:{decimals:D.decimals,symbol:D.symbol,name:D.name,logo:D.logo}}),U=!0;break}}U||k.push({address:O,chainId:t.chainId})}const E=new Map;for(const O of k){const N=E.get(O.chainId)||[];N.push(O),E.set(O.chainId,N)}const M=async(O,N)=>{try{const U=await kn(O,{address:N.address,abi:Ot,functionName:"balanceOf",args:[B]});let V,D,Q,P;if(N.configToken)V=N.configToken.decimals,D=N.configToken.symbol,Q=N.configToken.name,P=N.configToken.logo;else{const[Z,ge,W]=await Promise.all([kn(O,{address:N.address,abi:Ot,functionName:"decimals"}).catch(()=>18),kn(O,{address:N.address,abi:Ot,functionName:"symbol"}).catch(()=>"TOKEN"),kn(O,{address:N.address,abi:Ot,functionName:"name"}).catch(()=>"TOKEN")]);V=Number(Z),D=ge,Q=W}const j=Se(N.address,t.address)&&N.chainId===t.chainId;j&&t.logoURI&&(P=t.logoURI),j&&!N.configToken&&D==="TOKEN"&&(D=t.symbol,Q=t.symbol);const L=parseFloat((Number(U)/Math.pow(10,V)).toFixed(6));return{address:N.address,name:Q,symbol:D,decimals:V,balance:U,balanceFormatted:L,balanceUsd:0,logoURI:P,isNative:!1,chainId:N.chainId}}catch{return null}},T=await Promise.all(Array.from(E.entries()).map(async([O,N])=>{let U;try{U=pt(O)}catch{return[]}const V=[],D=[];for(const P of N){const j=V.length;V.push({address:P.address,abi:Ot,functionName:"balanceOf",args:[B]}),P.configToken||V.push({address:P.address,abi:Ot,functionName:"decimals"},{address:P.address,abi:Ot,functionName:"symbol"},{address:P.address,abi:Ot,functionName:"name"}),D.push({start:j,item:P})}let Q=null;try{Q=await U.multicall({contracts:V})}catch{Q=null}return Q?D.map(({start:P,item:j})=>{const L=Q[P],Z=L?.status==="success"?L.result:0n;let ge,W,_,fe;if(j.configToken)ge=j.configToken.decimals,W=j.configToken.symbol,_=j.configToken.name,fe=j.configToken.logo;else{const he=Q[P+1],xe=Q[P+2],H=Q[P+3];ge=he?.status==="success"?Number(he.result):18,W=xe?.status==="success"?xe.result:"TOKEN",_=H?.status==="success"?H.result:W}const be=Se(j.address,t.address)&&j.chainId===t.chainId;be&&t.logoURI&&(fe=t.logoURI),be&&!j.configToken&&W==="TOKEN"&&(W=t.symbol,_=t.symbol);const Me=parseFloat((Number(Z)/Math.pow(10,ge)).toFixed(6));return{address:j.address,name:_,symbol:W,decimals:ge,balance:Z,balanceFormatted:Me,balanceUsd:0,logoURI:fe,isNative:!1,chainId:j.chainId}}):(await Promise.all(N.map(P=>M(U,P)))).filter(P=>P!==null)}));A===w.current&&b(T.flat())},[s,r,m,y,C,t.address,t.chainId,t.symbol,t.logoURI]);X(()=>{I.current=x},[x]),X(()=>{if(!s){b([]);return}I.current();const A=setInterval(()=>{I.current()},15e3);return()=>clearInterval(A)},[s,r,m,y,C,t.address,t.chainId]);const S=ce(()=>{x()},[x]);return{displayAssets:re(()=>{const A=[],B=v.filter(k=>k.balance>0n);for(const k of B)A.push({...k,_source:"wallet"});for(const k of h)A.push({...k,_source:"spice"});const F=t.address.toLowerCase();return A.sort((k,E)=>ha(k,F,t.chainId)-ha(E,F,t.chainId)),A},[v,h,t.address,t.chainId]),filteredSpiceAssets:h,walletAssets:v,embeddedWalletAddress:l,externalAddress:c,isNon7702:r,refreshSpiceAssets:u,refreshWalletAssets:S}}async function ma(e){const{tokenIn:t,tokenOut:n,amountIn:o,fee:s,chainId:r,config:i}=e;if(o<=0n)throw new Error("amountIn must be greater than 0");const c=(await pt(r).simulateContract({address:i.quoterV2,abi:ti,functionName:"quoteExactInputSingle",args:[{tokenIn:t,tokenOut:n,amountIn:o,fee:s,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 ga(e){const t=e.feeTiers??[100,500,3e3,1e4],n=await Promise.allSettled(t.map(s=>ma({...e,fee:s})));let o=null;for(let s=0;s<n.length;s++){const r=n[s];r.status==="fulfilled"&&(!o||r.value.amountOut>o.amountOut)&&(o={...r.value,fee:t[s]})}if(!o)throw new Error("No liquidity found for this pair on any fee tier.");return o}const Hc=[{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 jc(e){const{tokenIn:t,tokenOut:n,amountOut:o,fee:s,chainId:r,config:i}=e;if(o<=0n)throw new Error("amountOut must be greater than 0");const c=(await pt(r).simulateContract({address:i.quoterV2,abi:Hc,functionName:"quoteExactOutputSingle",args:[{tokenIn:t,tokenOut:n,amount:o,fee:s,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 Qc(e){const t=e.feeTiers??[100,500,3e3,1e4],n=await Promise.allSettled(t.map(s=>jc({...e,fee:s})));let o=null;for(let s=0;s<n.length;s++){const r=n[s];r.status==="fulfilled"&&(!o||r.value.amountIn<o.amountIn)&&(o={...r.value,fee:t[s]})}if(!o)throw new Error("No liquidity found for this pair on any fee tier.");return o}function ya(e){return e.type==="swap"}const Vs=.02,Vc=[1,8453,42161,10,137,43114,56],qc="https://api.1inch.dev/swap/v6.0";function xa(e,t){return oi(e,t)}function ba(e){const t=e?.baseUrl??qc;return{name:"1inch",chainIds:e?.chainIds??Vc,resolve:async(n,o,s)=>{const r=n.maxSlippage??Vs,i=r*100,c=Ue(n.tokenIn)?or:n.tokenIn,d=Ue(n.tokenOut)?or:n.tokenOut,l=Ue(n.tokenIn);try{const p=new URL(`${t}/${o}/swap`);p.searchParams.set("src",c),p.searchParams.set("dst",d),p.searchParams.set("amount",n.amountIn.toString()),p.searchParams.set("from",s),p.searchParams.set("slippage",i.toString()),p.searchParams.set("disableEstimate","true"),p.searchParams.set("allowPartialFill","false");const u={Accept:"application/json"};e?.apiKey&&(u.Authorization=`Bearer ${e.apiKey}`);const h=await fetch(p.toString(),{headers:u});if(!h.ok)throw new Te("VENUE_API_ERROR",`[1inchVenue] API returned ${h.status} for ${n.tokenIn} \u2192 ${n.tokenOut} on chain ${o}`,{venue:"1inch",chainId:o,tokenIn:n.tokenIn,tokenOut:n.tokenOut,amountIn:n.amountIn.toString(),cause:`HTTP ${h.status}`});const m=await h.json();if(!m.dstAmount||!m.tx)return console.warn(`[1inchVenue] No route data for ${n.tokenIn} \u2192 ${n.tokenOut} on chain ${o}`),null;const f=BigInt(m.dstAmount);if(f<=0n)return console.warn(`[1inchVenue] Zero output for ${n.tokenIn} \u2192 ${n.tokenOut} on chain ${o}`),null;const y=xa(f,r),C=[];return m.tx.to&&!l&&C.push({to:n.tokenIn,value:0n,data:xt({abi:Ot,functionName:"approve",args:[m.tx.to,n.amountIn]})}),C.push({to:m.tx.to,value:BigInt(m.tx.value||"0"),data:m.tx.data}),{venue:"1inch",amountOut:f,amountOutMinimum:y,calls:C}}catch(p){if(p instanceof Te)throw p;const u=p instanceof Error?p.message:String(p);throw new Te("VENUE_API_ERROR",`[1inchVenue] Exception for ${n.tokenIn} \u2192 ${n.tokenOut} on chain ${o}: ${u}`,{venue:"1inch",chainId:o,tokenIn:n.tokenIn,tokenOut:n.tokenOut,amountIn:n.amountIn.toString(),cause:u})}}}}const wa=[4114,5115],qs={swapRouter:"0x565eD3D57fe40f78A46f348C220121AE093c3cF8",quoterV2:"0x428f20dd8926Eabe19653815Ed0BE7D6c36f8425",feeTiers:[3e3]},Ca={swapRouter:"0x2626664c2603336E57B271c5C0b26F421741e481",quoterV2:"0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a",chainIds:[8453],feeTiers:[3e3]};function ka(e){return{name:"satsuma",chainIds:e.chainIds??wa,resolve:async(t,n,o)=>{const s=t.maxSlippage??Vs,r=Ue(t.tokenIn);let i;try{i=await ga({tokenIn:t.tokenIn,tokenOut:t.tokenOut,amountIn:t.amountIn,chainId:n,config:{swapRouter:e.swapRouter,quoterV2:e.quoterV2},feeTiers:e.feeTiers})}catch{return console.warn(`[SatsumaVenue] No viable fee tier for ${t.tokenIn} \u2192 ${t.tokenOut} on chain ${n}.`),null}const c=xa(i.amountOut,s),d=[];return r||d.push({to:t.tokenIn,value:0n,data:xt({abi:Ot,functionName:"approve",args:[e.swapRouter,t.amountIn]})}),d.push({to:e.swapRouter,value:r?t.amountIn:0n,data:xt({abi:ni,functionName:"exactInputSingle",args:[{tokenIn:t.tokenIn,tokenOut:t.tokenOut,fee:i.fee,recipient:o,amountIn:t.amountIn,amountOutMinimum:c,sqrtPriceLimitX96:0n}]})}),{venue:"satsuma",amountOut:i.amountOut,amountOutMinimum:c,calls:d}}}}function va(e){return{name:"satsuma",chainIds:e.chainIds??wa,resolve:async(t,n,o)=>{const s=t.maxSlippage??Vs,r=Ue(t.tokenIn);let i;try{i=await Qc({tokenIn:t.tokenIn,tokenOut:t.tokenOut,amountOut:t.amountOut,chainId:n,config:{swapRouter:e.swapRouter,quoterV2:e.quoterV2},feeTiers:e.feeTiers})}catch{return null}const c=BigInt(Math.round(s*1e4)),d=i.amountIn+i.amountIn*c/10000n,l=[];return l.push({to:e.swapRouter,value:r?d:0n,data:xt({abi:Kc,functionName:"exactOutputSingle",args:[{tokenIn:t.tokenIn,tokenOut:t.tokenOut,fee:i.fee,recipient:o,amountOut:t.amountOut,amountInMaximum:d,sqrtPriceLimitX96:0n}]})}),{venue:"satsuma",amountIn:i.amountIn,amountInMax:d,amountOut:t.amountOut,calls:l}}}}const Kc=[{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 Ia(e){const t=[];e?.customVenues&&t.push(...e.customVenues),e?.satsuma&&t.push(ka(e.satsuma)),t.push(ba(e?.oneInch));function n(s){return t.find(r=>r.chainIds.includes(s))}async function o(s,r,i){const c=[],d=[];for(const l of s){if(!ya(l)){c.push(l);continue}const p=n(r);if(!p)throw new Te("NO_VENUE_FOR_CHAIN",`No liquidity venue configured for chain ${r}. Cannot resolve swap ${l.tokenIn} \u2192 ${l.tokenOut}.`,{chainId:r,tokenIn:l.tokenIn,tokenOut:l.tokenOut,amountIn:l.amountIn.toString()});const u=await p.resolve(l,r,i);if(!u)throw new Te("NO_LIQUIDITY",`${p.name} returned no quote for ${l.tokenIn} \u2192 ${l.tokenOut} on chain ${r}.`,{venue:p.name,chainId:r,tokenIn:l.tokenIn,tokenOut:l.tokenOut,amountIn:l.amountIn.toString()});c.push(...u.calls),d.push(u)}return{calls:c,resolvedSwaps:d}}return{resolveSwapIntents:o,getVenueForChain:n,venues:t}}function Yc(e){const t=e?.customVenues??[];async function n(o,s,r){const i=t.filter(d=>d.chainIds.includes(s));if(i.length===0)throw new Te("NO_SWAP_ROUTE",`No exact-output venue supports chain ${s}`,{chainId:s,tokenIn:o.tokenIn,tokenOut:o.tokenOut});const c=(await Promise.allSettled(i.map(d=>d.resolve(o,s,r)))).filter(d=>d.status==="fulfilled").map(d=>d.value).filter(d=>d!==null);if(c.length===0)throw new Te("NO_SWAP_ROUTE",`All aggregators failed for ${o.tokenIn} \u2192 ${o.tokenOut} on chain ${s}`,{chainId:s,tokenIn:o.tokenIn,tokenOut:o.tokenOut,amountOut:o.amountOut.toString()});return c.sort((d,l)=>d.amountIn<l.amountIn?-1:d.amountIn>l.amountIn?1:0),c[0]}return{getQuote:n,venues:t}}const Zc=Ia({satsuma:qs});function Gc(e){const{direction:t,selectedAsset:n,destinationToken:o,chainId:s,recipient:r,paymentAmount:i}=e,[c,d]=R(!1),[l,p]=R(null),[u,h]=R(null),[m,f]=R(null),[y,C]=R(null),[v,b]=R(null),[w,I]=R(null),[x,S]=R(null),[A,B]=R(null),F=ie(null),k=ie(null),E=ie(0),M=ie(new Map),T=re(()=>Zc,[]),O=re(()=>Yc({customVenues:[va(qs),va(Ca)]}),[]),N=re(()=>{if(!n?.asset)return null;const W=Mn(n.asset,s);if(W)return W;const _=zn(n.asset.address,s,n.asset.chainId);return _?_.address:null},[n?.asset,s]),U=re(()=>n?.asset?Ho(n.asset,s):[],[n?.asset,s]),V=re(()=>U.map(W=>W.toLowerCase()).join(","),[U]);X(()=>{let W=!1;if(k.current&&(clearTimeout(k.current),k.current=null),!n?.asset||U.length<=1){B(null);return}return k.current=setTimeout(async()=>{const _=t==="input"?n.amount:i||"0";let fe=0n;try{fe=t==="input"?Ke(_,n.asset.decimals):0n}catch{fe=0n}try{const be=await Wr(n.asset,s,{requiredAmount:fe});W||B(be)}catch{W||B(null)}},400),()=>{W=!0,k.current&&(clearTimeout(k.current),k.current=null)}},[n?.asset,n?.amount,s,U.length,V,t,i]);const D=re(()=>A??N,[A,N]),Q=re(()=>!n?.asset||!D?[]:[D,...U.filter(W=>W.toLowerCase()!==D.toLowerCase())],[n?.asset,D,U]),P=re(()=>!n?.asset||!So(n.asset.address,n.asset.chainId,o.address,o.chainId)||!D?!1:Se(D,o.address),[n,o.address,o.chainId,D]),j=D?Se(D,o.address):!1,L=t==="output"&&parseFloat(i||"0")===0,Z=!!n?.asset&&!P&&!j&&!L,ge=Z?x??D:D;return X(()=>{F.current&&clearTimeout(F.current);const W=t==="input"?n?.amount:i,_=parseFloat(W||"0");if(!Z||!Number.isFinite(_)||_<=0||!n?.asset||!r||Q.length===0){E.current++,h(null),f(null),C(null),b(null),I(null),S(null),p(null),d(!1);return}const fe=n.asset.decimals;let be;try{be=t==="input"?Ke(n.amount,fe):Ke(i||"0",o.decimals)}catch{E.current++,p("Invalid amount"),d(!1);return}const Me=++E.current,he=()=>Me!==E.current;d(!0);const xe=t==="output"?150:400;return F.current=setTimeout(async()=>{try{if(t==="input"){const H=T.getVenueForChain(s);if(!H)throw new Error("No swap venue for this chain");let se=null,K=null;for(const ye of Q){const Ee=`${t}:${s}:${ye.toLowerCase()}:${o.address.toLowerCase()}:${be.toString()}`,ee=M.current.get(Ee);if(ee&&ee.expiresAt>Date.now()&&ee.resolvedSwap){se=ee.resolvedSwap,K=ye;break}const z=await H.resolve({type:"swap",tokenIn:ye,tokenOut:o.address,amountIn:be},s,r);if(he())return;if(z){M.current.set(Ee,{expiresAt:Date.now()+3e4,direction:t,resolvedSwap:z}),se=z,K=ye;break}}if(!se||!K)throw new Error("No liquidity for this pair");S(K),I(se.amountOut),C(se),b(null);const le=parseFloat(rt(se.amountOut,o.decimals));h(le<.01?le.toPrecision(4):le.toLocaleString(void 0,{maximumFractionDigits:6})),f(null),p(null)}else{let H=null,se=null;for(const K of Q){const le=`${t}:${s}:${K.toLowerCase()}:${o.address.toLowerCase()}:${be.toString()}`,ye=M.current.get(le);if(ye&&ye.expiresAt>Date.now()&&ye.exactOutputSwap){H=ye.exactOutputSwap,se=K;break}try{const Ee=await O.getQuote({tokenIn:K,tokenOut:o.address,amountOut:be},s,r);if(he())return;M.current.set(le,{expiresAt:Date.now()+3e4,direction:t,exactOutputSwap:Ee}),H=Ee,se=K;break}catch{if(he())return}}if(!H||!se)throw new Error("No liquidity for this pair");S(se),b(H),C(null),I(null),f(parseFloat(rt(H.amountIn,fe)).toFixed(6)),h(null),p(null)}}catch(H){if(he())return;const se=H instanceof Error?H.message:"Failed to get quote";p(se),h(null),f(null),C(null),b(null),I(null),S(null)}finally{he()||d(!1)}},xe),()=>{F.current&&clearTimeout(F.current)}},[t,Z,n?.amount,n?.asset?.address,n?.asset?.decimals,i,Q,s,o.address,o.decimals,r,T,O]),{isQuoting:c,quoteError:l,estimatedOutput:u,estimatedInput:m,resolvedSwap:y,exactOutputSwap:v,quoteAmountOut:w,resolvedTokenIn:ge,isDirect:j,needsSwap:Z,selectedIsEquivalent:P}}const Aa={idle:"","signing-delegation":"Signing delegation...","signing-intent":"Signing intent...",submitting:"Submitting transaction...",executing:"Executing on-chain...",success:"Deposit confirmed",error:"Transaction failed"},Sa=["signing-delegation","signing-intent","submitting","executing"],Ea=({isOpen:e,onClose:t,closeOnBackdropClick:n=!1,destinationToken:o,sourceChains:s,supportedSourceAssets:r,buildActionCalls:i,feeExecutionMode:c="user-transfer",buildSpicenetBatch:d,onPayExecute:l,actionLabel:p,amountDirection:u="input",swapDescription:h,directDescription:m,paymentAmount:f,amountInputMode:y="fixed",minPaymentAmount:C,maxPaymentAmount:v,onAmountChange:b,styles:w,dark:I,title:x,subtitle:S,onAddFunds:A,onSuccess:B,onError:F})=>{const k=u==="output",{theme:E,dark:M,primaryColor:T,dk:O,palette:N,fontFamily:U,monoFont:V,inputDark:D,cardBg:Q,cardBorder:P,textPrimary:j,textSecondary:L,subtitleText:Z}=ut(w,I),ge=D?{...E,colors:{...E.colors,secondary:O.cardBg,surfaceHover:O.hoverBg,border:"#2d2d2d",borderHover:"#3a3a3a"}}:E,W=o.chainId,_=Gt(Lt),fe=(_?.mode||"7702")!=="7702",be=!!_?.isWhitelistGateActive,Me=re(()=>s??_?.supportedChainIds??[],[s,_?.supportedChainIds]),he=re(()=>{if(be)return[];if(r)return r;const pe=_?.allowedTokens;if(!pe||pe.length===0)return;const Pe=new Set(pe.map(xn=>xn.toLowerCase())),Pt=[],En=new Set;for(const xn of Me){const fo=Be(xn);for(const Zn of fo?.supportedTokens??[]){if(!Pe.has(Zn.symbol.toLowerCase()))continue;const ho=Zn.address.toLowerCase();En.has(ho)||(En.add(ho),Pt.push(Zn.address))}}return Pt},[r,_?.allowedTokens,Me,be]),xe=Fn(),{address:H,isConnected:se,isReady:K,isAuthenticated:le,provider:ye}=xe,{executeGasless:Ee,estimateGasless:ee}=Zo(),{externalWallet:z,externalAddress:ae,embeddedAddress:we}=no(),Le=Bn()||we,{displayAssets:wt,filteredSpiceAssets:at,embeddedWalletAddress:it,refreshSpiceAssets:Re,refreshWalletAssets:oe}=Oc({destinationToken:o,supportedSourceAssets:he,sourceChains:Me,enabled:e&&(fe?!!ae:!!Le)}),je=be||k||fe?wt:at,[Y,ke]=R(null),[St,Rt]=R(f||""),[lt,an]=R(!1),[Xt,Nt]=R(null),[Ie,Jt]=R("idle"),[In,An]=R(""),[Ut,ln]=R(null),[ct,jt]=R(!1),[_e,ft]=R(null),[ht,Bt]=R(null),[Kt,me]=R(!1),[bt,Ct]=R(!1),[Qt,Ce]=R(null),$t=ie(Y),mt=ie(!1),Tt=ie(null),Vt=ie(0),mn=ie(null),cn=ie(null);X(()=>{$t.current=Y},[Y]);const dt=y==="adjustable"?St:f||"0",gn=it||we||H,{isQuoting:ze,quoteError:Et,estimatedOutput:qt,resolvedSwap:Ge,exactOutputSwap:ot,quoteAmountOut:Yt,resolvedTokenIn:vt,isDirect:Oe,needsSwap:Xe,selectedIsEquivalent:Mt}=Gc({direction:u,selectedAsset:Y,destinationToken:o,chainId:W,recipient:gn,paymentAmount:dt}),gt=k?parseFloat(dt||"0"):parseFloat(Y?.amount||"")||0,dn=Y?.asset?._source==="wallet",Qe=!!Y?.asset&&dn&&Y.asset.chainId!==W,yn=re(()=>Y?.asset?at.find(pe=>Se(pe.address,Y.asset.address))?.balanceFormatted??0:0,[Y,at]),un=dn?Y?.asset.balanceFormatted??0:yn,_t=re(()=>{if(!Y?.asset)return!1;if(k)return ht?uo(ht.grossAmount,ht.decimals,Y.asset.decimals)>Y.asset.balance:Mt||Oe?gt>Y.asset.balanceFormatted:ot?parseFloat(rt(ot.amountInMax,Y.asset.decimals))>Y.asset.balanceFormatted:!1;if(ht){const pe=uo(ht.grossAmount,ht.decimals,Y.asset.decimals);return dn?pe>Y.asset.balance:parseFloat(rt(pe,Y.asset.decimals))>un}return gt>un},[Y,k,ht,Mt,gt,ot,un,dn,Oe]);X(()=>{e||(ke(null),Nt(null),an(!1),Jt("idle"),An(""),ln(null),jt(!1),ft(null),Bt(null),me(!1),Ct(!1),Ce(null),mt.current=!1,y==="adjustable"&&Rt(f||""),Tt.current&&(Tt.current.abort(),Tt.current=null))},[e]);const te=ce(pe=>{ke(Pe=>({asset:pe,amount:Pe?.asset?.address===pe.address&&Pe?.asset?.chainId===pe.chainId&&Pe.amount||""})),Nt(null),Ce(null),Ct(!1)},[]),ne=ce(pe=>{ke(Pe=>Pe&&{...Pe,amount:pe}),Nt(null),Ce(null),Ct(!1)},[]),Ae=ce(pe=>{let Pe=pe;v&&parseFloat(Pe)>parseFloat(v)&&(Pe=v),Rt(Pe),b?.(Pe),Nt(null),Ce(null),Ct(!1)},[v,b]);ce(pe=>{if(mt.current||!H)return;const Pe=$t.current;!Pe?.asset||!Pe.amount||Pe.asset?._source==="wallet"||Ke(k?dt:Pe.amount,Pe.asset.decimals)===0n||(mt.current=!0,Re())},[H,W,Re,k,dt]);const Je=ce(pe=>{Jt({building:"signing-delegation","signing-delegation":"signing-delegation","signing-intent":"signing-intent",submitting:"submitting",executing:"executing",success:"success",error:"error"}[pe.step]||"executing"),An(pe.message),pe.txHash&&ln(pe.txHash)},[]),st=re(()=>({currentPaymentAmount:dt,destinationToken:o,embeddedWalletAddress:it,providerEmbeddedAddress:we,externalWalletAddress:ae,address:H,isNon7702:fe,isPayMode:k,resolvedChainId:W,buildActionCalls:i,feeExecutionMode:c,buildSpicenetBatch:d,selectedAsset:Y,needsSwap:Xe,resolvedSwap:Ge,exactOutputSwap:ot,quoteAmountOut:Yt,resolvedTokenIn:vt}),[dt,o,it,we,ae,H,fe,k,W,i,c,d,Y,Xe,Ge,ot,Yt,vt]),et=ce(pe=>Ic(st,pe),[st]),$e=ce(pe=>Ac(st,pe),[st]),Ve=ce((pe,Pe,Pt,En)=>Sc(pe,Pe,Pt,ee,En),[ee]),qe=re(()=>Y?.asset?Xe&&vt?vt:Y.asset.chainId===W?Y.asset.address:vt??Mn(Y.asset,W)??o.address:o.address,[Y,o.address,Xe,W,vt]),G=ce(()=>Nc(cn.current),[]),ue=re(()=>Y?.asset?Se(Y.asset.address,o.address)&&Y.asset.chainId===o.chainId:!1,[Y,o.address,o.chainId]),We=fe&&ue,De=We&&gt>0&&!!Y?.asset,Ye=Xt,Ft=re(()=>!(!Y?.asset||gt<=0),[Y,gt,De]),pn=re(()=>!e||lt||Ie!=="idle"||!Ft||De||!Y?.asset?null:[k?"pay":"supply",u,Y.asset.address.toLowerCase(),Y.asset.chainId,Y.amount,dt,o.address.toLowerCase(),o.chainId,W,vt?.toLowerCase()??"",Xe?"swap":"direct",Oe?"direct-token":"routed-token",fe?"non7702":"7702",ue?"source-dest":"cross-chain",ze?"quoting":"quoted",ot?.amountIn?.toString()??"",ot?.amountInMax?.toString()??"",ot?.venue??"",Ge?.amountOut?.toString()??"",Yt?.toString()??"",it??"",we??"",H??""].join("|"),[e,lt,Ie,Ft,De,Y,k,u,dt,o,W,vt,Xe,Oe,fe,ue,ze,ot,Ge,Yt,it,we,H]),q=ce(()=>Tc({selectedAsset:Y,isPayMode:k,parsedAmount:gt,needsSwap:Xe,exactOutputSwap:ot,isNon7702:fe,isSourceDestToken:ue,currentPaymentAmount:dt,destinationToken:o,feeExecutionMode:c,resolvedTokenIn:vt,embeddedWalletAddress:it,providerEmbeddedAddress:we,resolvedChainId:W,isConnected:se,address:H,ready:K,authenticated:le,isDirect:Oe,resolvedSwap:Ge,isQuoting:ze,executionTokenAddress:qe,buildPayChainBatches:et,buildSupplyChainBatches:$e,estimateGasless:ee,estimateRequiredGrossFunding:Ve}),[Y,k,gt,Xe,ot,fe,ue,dt,o,c,vt,it,we,Ve,et,ee,W,se,H,K,le,Oe,Ge,ze,$e,qe]);X(()=>{mn.current=q},[q]);const $=ce(pe=>Bc({asset:pe,isPayMode:k,isNon7702:fe,needsSwap:Xe,isQuoting:ze,embeddedWalletAddress:it,buildSupplyChainBatches:$e,estimateGasless:ee,executionTokenAddress:qe,feeExecutionMode:c}),[k,fe,Xe,ze,it,$e,ee,qe,c]);X(()=>{if(!e){me(!1),Ct(!1),Ce(null),Bt(null);return}if(lt||Ie!=="idle"){Vt.current+=1,me(!1);return}if(!Ft){Bt(null),me(!1),Ct(!1),Ce(null);return}if(De){Bt(null),me(!1),Ct(!0),Ce(null);return}if(ze){Vt.current+=1,me(!1),Ct(!1);return}if(!pn)return;let pe=!1;const Pe=async()=>{const En=++Vt.current;Ce(null),me(!0);try{const xn=await mn.current?.();if(pe||Vt.current!==En)return;xn?(Bt(xn),Ct(!0)):(Bt(null),Ct(!1)),Ce(null)}catch(xn){if(pe||Vt.current!==En)return;const fo=bn(xn,"Unable to calculate fees for this action.");Bt(null),Ct(!1),Ce(fo)}finally{!pe&&Vt.current===En&&me(!1)}},Pt=window.setTimeout(()=>{Pe()},250);return()=>{pe=!0,clearTimeout(Pt),me(!1)}},[e,lt,Ie,Ft,De,ze,pn]);const de=ce(()=>Uc(cn.current),[]);X(()=>{!k&&Ie==="success"&&Ut&&(Re(),B?.(Ut))},[k,Ie,Ut,Re,B]),X(()=>{if(!k||_e?.status!=="success"||mt.current||!H)return;mt.current=!0;const pe=$t.current;!pe?.asset||pe.asset?._source==="wallet"||Re()},[k,_e?.status,H,Re]);const J=ie(B),Fe=ie(F);X(()=>{J.current=B},[B]),X(()=>{Fe.current=F},[F]),X(()=>{e&&(Re(),oe())},[e,Re,oe]),X(()=>{k&&(_e?.status==="success"&&J.current?.(_e.txHash||""),_e?.status==="failed"&&Fe.current?.(new Error("Payment execution failed")))},[k,_e?.status]);const He=ce(()=>{jt(!1),ft(null),ke(null),mt.current=!1,Re(),oe()},[Re,oe]);cn.current={selectedAsset:Y,parsedAmount:gt,currentPaymentAmount:dt,isInsufficientBalance:_t,isPayMode:k,isNon7702:fe,isSourceDestToken:ue,needsSwap:Xe,exactOutputSwap:ot,selectedIsEquivalent:Mt,resolvedTokenIn:vt,embeddedWalletAddress:it,providerEmbeddedAddress:we,externalWallet:z,externalWalletAddress:ae,address:H,isConnected:se,ready:K,authenticated:le,provider:ye,resolvedChainId:W,executionTokenAddress:qe,destinationToken:o,buildActionCalls:i,feeExecutionMode:c,buildSpicenetBatch:d,onPayExecute:l,onError:F,gasless:{estimateGasless:ee,executeGasless:Ee,buildPayChainBatches:et,buildSupplyChainBatches:$e,estimateRequiredGrossFunding:Ve,onProgress:Je},ui:{setError:Nt,setStep:Jt,setStatusMsg:An,setTxHash:ln,setIsExecuting:an,setShowStatusPanel:jt,setPaymentResult:ft},refs:{spiceDepositSubmittedRef:mt,abortControllerRef:Tt}};const yt=k&&gt===0,tt=k?!!Y?.asset&&gt>=0&&!_t&&!lt&&(yt||De||bt)&&!Qt&&(yt||!Xe||!!ot):!!Y?.asset&&gt>0&&!_t&&!lt&&(We||bt)&&!Qt&&(Qe||Oe||!!Ge&&!ze),kt=Oe?m||`Your ${o.symbol} will be used directly.`:h||"Your assets will be swapped and used in a single atomic transaction.",Zt=(W?Be(W):void 0)?.viemChain?.blockExplorers?.default?.url??"",Wt=Sa.indexOf(Ie),en=lt?(Aa[Ie]||"EXECUTING...").toUpperCase():Ie==="success"?"DONE":_t?"INSUFFICIENT BALANCE":p.toUpperCase(),tn=re(()=>{if(lt)return"PAYING...";if(_t&&Y?.asset)return`INSUFFICIENT ${Y.asset.symbol}`;if(p)return p.toUpperCase();const pe=gt>0?` ${dt} ${o.symbol}`:"";return Xe?`SWAP & PAY${pe}`:`PAY${pe}`},[lt,_t,Y,p,gt,dt,o.symbol,Xe]),Sn=Ie==="success"?()=>{Jt("idle"),ke(null),ln(null),Re()}:G,Kn=Ie==="success"?!1:!tt;if(!e)return null;const Yn=k?x||`Pay ${o.symbol}`:p,ve=k?S:g("div",{style:{display:"flex",alignItems:"flex-start",gap:"3px"},children:[a("span",{style:{marginTop:"3px",flexShrink:0},children:a(ks,{color:Z})}),a("p",{style:{fontSize:"12px",color:Z,margin:0,lineHeight:"1.4",fontFamily:U},children:kt})]});if(k){const pe=_e&&(_e.status==="success"||_e.status==="failed")?[{asset:{symbol:Y?.asset?.symbol||o.symbol,address:Y?.asset?.address||""},amount:dt,txHash:_e.txHash||"",success:_e.status==="success",error:_e.status==="failed"?_e.error:void 0}]:void 0;return a(Pn,{isOpen:e,onClose:t,title:Yn,subtitle:ve,styles:w,dark:M,footerLinkText:"Spicenet accounts \u2192",closeOnBackdropClick:n,children:g("div",{style:{padding:"16px 24px 8px 24px",position:"relative"},children:[A&&a("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:"6px"},children:a(vs,{onClick:A,color:T,fontFamily:U})}),a("div",{style:{marginBottom:"12px"},children:a(Ao,{assets:je,selectedAsset:Y??void 0,onAssetSelect:te,onAmountChange:()=>{},label:"Pay with",showBalance:!0,showMaxButton:!1,hideAmountInput:!0,displayAmount:Y?.asset?Xe?ze?"...":ot?`~${parseFloat(rt(ot.amountIn,Y.asset.decimals)).toFixed(6)}`:void 0:dt??void 0:void 0,dark:M,theme:ge,styles:w})}),a(pa,{variant:"pay",destinationSymbol:o.symbol,destinationLogoURI:o.logoURI,destinationDecimals:o.decimals,primaryColor:T,fontFamily:U,textPrimary:j,textSecondary:L,cardBg:Q,cardBorder:P,dk:O,dark:M,isQuoting:ze,quoteError:Et,estimatedOutput:qt,paymentAmount:dt,needsSwap:Xe,exactOutputSwap:ot,adjustable:y==="adjustable",maxAmount:v,onAmountChange:Ae}),Ft&&a(Uo,{fontFamily:U,textPrimary:j,textSecondary:L,cardBg:Q,cardBorder:P,resolvedDark:M,darkCardBorder:O.cardBorder,primaryColor:T,feePreview:ht,isLoading:Kt,errorText:Qt,directExecutionFeeNote:De}),Ye&&a(io,{variant:"error",palette:N,fontFamily:U,style:{marginBottom:"12px"},children:Ye}),a(At,{variant:"outline",fullWidth:!0,onClick:de,disabled:!tt,loading:lt,dark:M,styles:{...w,button:{...w?.button,backgroundColor:T}},children:tn}),_e&&ct&&a("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:10,backgroundColor:M?O.shell:"white",borderRadius:M?"12px":"6px",padding:"16px 0"},children:a(Fs,{type:"payment",isOpen:_e.status!=="processing",isProcessing:lt||_e.status==="processing",closeOnComplete:!1,chainName:nn(W),explorerUrl:to(W,"").replace(/\/tx\/.*$/,"")||void 0,onRetryTx:()=>{jt(!1),ft(null),de()},onNewTx:He,onClose:()=>{jt(!1),ft(null)},onComplete:He,results:pe,styles:w,dark:M})})]})})}return a(Pn,{isOpen:e,onClose:t,title:Yn,subtitle:ve,dark:M,styles:w,theme:E,closeOnBackdropClick:n,children:g("div",{style:{padding:"24px 24px 5px 24px",position:"relative"},children:[a("div",{style:{marginBottom:"16px"},children:a(Ao,{assets:je,selectedAsset:Y||void 0,onAssetSelect:te,onAmountChange:ne,disabled:lt||Ie==="success",showBalance:!0,showMaxButton:!0,label:"From Wallet",placeholder:"0.00",theme:ge,styles:w,dark:D,resolveMaxAmount:$,maxAmount:un>0?ro(un,Y?.asset.decimals??o.decimals):void 0})}),Y?.asset&&!Oe&&a(pa,{variant:"supply",destinationSymbol:o.symbol,destinationLogoURI:o.logoURI,destinationDecimals:o.decimals,primaryColor:T,fontFamily:U,textPrimary:j,textSecondary:L,cardBg:Q,cardBorder:P,dark:M,isQuoting:ze,quoteError:Et,estimatedOutput:qt}),Ft&&a(Uo,{fontFamily:U,textPrimary:j,textSecondary:L,cardBg:Q,cardBorder:P,resolvedDark:M,darkCardBorder:O.cardBorder,primaryColor:T,feePreview:ht,isLoading:Kt,errorText:Qt,directExecutionFeeNote:De}),Ie!=="idle"&&g("div",{style:{padding:"10px 14px",borderRadius:"7px",marginBottom:"16px",backgroundColor:Ie==="success"?Q:Ie==="error"?N.errorBg:Q,border:`1px solid ${Ie==="success"?P:Ie==="error"?N.errorBorder:P}`},children:[g("div",{style:{display:"flex",alignItems:"center",gap:"10px"},children:[Ie==="success"?a("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:a("path",{d:"M5 13l4 4L19 7",stroke:N.successText,strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round"})}):Ie==="error"?a("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:a("path",{d:"M18 6L6 18M6 6l12 12",stroke:N.errorText,strokeWidth:"2.5",strokeLinecap:"round"})}):a(On,{size:14,color:T}),a("span",{style:{fontSize:"13px",fontWeight:500,color:Ie==="success"?j:Ie==="error"?N.errorText:j,fontFamily:U,flex:1},children:Ie==="success"?"Deposit confirmed":Ie==="error"?In||"Transaction failed":Aa[Ie]||In}),Ie==="success"&&Ut&&a("a",{href:`${Zt}/tx/${Ut}`,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"12px",color:T,fontFamily:U,textDecoration:"none",whiteSpace:"nowrap",flexShrink:0},children:"View tx \u2192"}),Ie==="error"&&a("button",{onClick:()=>{Jt("idle"),Nt(null),setTimeout(G,50)},style:{background:"none",border:"none",fontSize:"12px",color:T,fontFamily:U,cursor:"pointer",padding:0,whiteSpace:"nowrap",flexShrink:0},children:"Retry \u2192"})]}),Wt>=0&&Ie!=="success"&&Ie!=="error"&&a("div",{style:{marginTop:"8px",height:"3px",borderRadius:"2px",backgroundColor:`${L}22`,overflow:"hidden"},children:a("div",{style:{height:"100%",width:"100%",borderRadius:"2px",backgroundColor:T,transformOrigin:"left center",transform:`scaleX(${(Wt+1)/Sa.length})`,transition:"transform 400ms ease"}})})]}),Xt&&Ie==="idle"&&a(io,{variant:"error",palette:N,fontFamily:U,style:{marginBottom:"16px"},children:Xt}),a(At,{variant:"outline",fullWidth:!0,disabled:Kn,onClick:Sn,theme:E,dark:M,styles:{...w,button:{...w?.button,backgroundColor:T}},style:{fontSize:"20px",fontWeight:600,letterSpacing:"1.5px",fontFamily:V},children:en})]})})},Xc=e=>a(Ea,{isOpen:e.isOpen,onClose:e.onClose,closeOnBackdropClick:e.closeOnBackdropClick,amountDirection:"output",destinationToken:{address:e.paymentTokenAddress,symbol:e.paymentTokenSymbol,decimals:e.paymentTokenDecimals,chainId:e.paymentChainId,logoURI:e.paymentTokenLogoURI},buildActionCalls:e.buildActionCalls,buildSpicenetBatch:e.buildSpicenetBatch,actionLabel:e.ctaLabel||"PAY",paymentAmount:e.paymentAmount,amountInputMode:e.amountInputMode,minPaymentAmount:e.minPaymentAmount,maxPaymentAmount:e.maxPaymentAmount,onAmountChange:e.onAmountChange,title:e.title,subtitle:e.subtitle,onAddFunds:e.onAddFunds,styles:e.styles,dark:e.dark,onSuccess:e.onPaymentSuccess,onError:e.onPaymentError}),Jc=({label:e="Export Wallet",style:t,className:n,onExport:o,onError:s})=>{const[r,i]=R(!1),[c,d]=R(!1),{primaryColor:l}=ut(),p=Gt(Lt),{isAuthenticated:u}=Fn();let h=null;try{h=ai()}catch{}let m=null,f=null;try{m=li(),f=ci()}catch{m=null,f=null}const y=Qa(f),C=ce(async()=>{if(!u){s?.("User is not authenticated. Please log in first.");return}try{if(p?.provider==="dynamic"){if(!m||!y){s?.("Dynamic is not available. Ensure the app is wrapped in a DynamicContextProvider.");return}await m.initExportProcess(!1),o?.();return}if(!h){s?.("Privy is not available. Ensure the app is wrapped in a PrivyProvider.");return}await h.exportWallet(),o?.()}catch(w){const I=w instanceof Error?w.message:"Failed to export wallet";console.error("Export wallet error:",w),s?.(I)}},[y,m,u,s,o,h,p?.provider]),v=!u,b={padding:"10px 20px",borderRadius:"8px",fontFamily:'"IBM Plex Mono", monospace',fontSize:"14px",fontWeight:500,letterSpacing:"0.4px",textTransform:"uppercase",cursor:v?"not-allowed":"pointer",opacity:v?.5:1,border:"1px solid #0e0d0b",color:"#0e0d0b",backgroundColor:c?`${l}cc`:r?`${l}ee`:l,transition:"background-color 150ms ease, transform 150ms ease",display:"inline-flex",alignItems:"center",justifyContent:"center",gap:"8px",...t};return g("button",{onClick:C,onMouseEnter:()=>i(!0),onMouseLeave:()=>{i(!1),d(!1)},onMouseDown:()=>d(!0),onMouseUp:()=>d(!1),disabled:v,className:n,style:b,children:[g("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[a("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),a("polyline",{points:"17 8 12 3 7 8"}),a("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]}),e]})};function Fa(e){const t=Gt(Lt),n=Bn(),o=e?.enabled===!1?void 0:n,s=t?.network?{network:t.network,pollIntervalMs:e?.pollIntervalMs,chainIds:e?.chainIds??t.supportedChainIds,discoverWalletBalances:e?.discoverWalletBalances}:void 0;return{...Ar(o,s),embeddedWalletAddress:n}}var $c="data:image/svg+xml,%3csvg width='11' height='11' viewBox='0 0 24 24' fill='none' stroke='black' stroke-opacity='0.5' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' xmlns='http://www.w3.org/2000/svg'%3e%3cpolyline points='17 1 21 5 17 9' /%3e%3cpath d='M3 11V9a4 4 0 0 1 4-4h14' /%3e%3cpolyline points='7 23 3 19 7 15' /%3e%3cpath d='M21 13v2a4 4 0 0 1-4 4H3' /%3e%3c/svg%3e";const _c=({appName:e,status:t,statusLabel:n,totalUsdValue:o,breakdownSubtitle:s,address:r,dk:i,dark:c=!1,showModeToggle:d,isEmbeddedMode:l=!0,onModeToggle:p})=>{const[u,h]=R(!1),m=async()=>{r&&await wi(r)&&(h(!0),setTimeout(()=>h(!1),2e3))},f=t==="active",y=n||(f?"Active":"Inactive"),C=f?"#10b981":"#9ca3af",v=g("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:[g("div",{children:[a("strong",{children:"Embedded:"})," Deposit assets into ",e," account and use them here."]}),g("div",{children:[a("strong",{children:"External:"})," Use assets from your connected wallet here."]})]});return g("div",{children:[g("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"4px"},children:[g("div",{style:{fontSize:"13px",fontWeight:600,color:i.textPrimary},children:[e," Account"]}),d?g("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[g("button",{onClick:p,style:{display:"flex",alignItems:"center",gap:"4px",padding:"2px 8px",borderRadius:"9999px",backgroundColor:c?i.hoverBg:"#f3f4f6",border:c?`1px solid ${i.cardBorder}`:"1px solid #e5e7eb",cursor:"pointer",fontSize:"11px",fontWeight:600,fontFamily:'"IBM Plex Mono", monospace',color:i.textSecondary,transition:"background-color 150ms ease, border-color 150ms ease, color 150ms ease",letterSpacing:"0.02em"},children:[a("span",{children:l?"Embedded":"External"}),a("img",{src:$c,alt:"","aria-hidden":"true",style:{width:"11px",height:"11px",display:"block",...c?{filter:"invert(0.65)"}:{}}})]}),a(yr,{content:v,label:"Account mode info",textColor:c?i.textPrimary:"#f9fafb",backgroundColor:c?i.cardBg:"#111827",borderColor:c?i.cardBorder:"rgba(255,255,255,0.08)",accentColor:c?i.textSecondary:"#6b7280",children:a("img",{src:Ss,alt:"","aria-hidden":"true",style:{width:"12px",height:"12px",display:"block",...c?{filter:"invert(0.65)"}:{}}})})]}):g("div",{style:{display:"flex",alignItems:"center",gap:"4px",padding:"2px 8px",borderRadius:"9999px",backgroundColor:c?i.hoverBg:f?"#ecfdf5":"#f3f4f6",border:c?`1px solid ${i.cardBorder}`:f?"1px solid #a7f3d0":"1px solid #e5e7eb"},children:[a("div",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:C}}),a("span",{style:{fontSize:"11px",fontWeight:500,color:c?i.textSecondary:f?"#065f46":"#6b7280"},children:y})]})]}),a("div",{style:{fontSize:"28px",fontWeight:700,color:i.textPrimary,lineHeight:1.2,marginBottom:"2px"},children:oo(o)}),s&&a("div",{style:{fontSize:"12px",color:i.textSecondary,marginBottom:"8px"},children:s}),r&&g("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[a("span",{style:{fontSize:"12px",fontFamily:'"IBM Plex Mono", monospace',color:c?i.textSecondary:"#9ca3af"},children:bi(r)}),a("button",{onClick:m,style:{padding:"2px 6px",fontSize:"10px",fontWeight:500,backgroundColor:"transparent",color:c?i.textSecondary:"#9ca3af",border:"none",cursor:"pointer",borderRadius:"4px",transition:"background-color 150ms ease, color 150ms ease"},title:"Copy address",children:u?"Copied":"Copy"})]})]})},ed=({pendingDeposits:e,onCompleteDeposit:t,dk:n,dark:o=!1})=>e.length===0?null:g("div",{children:[a("div",{style:{fontSize:"11px",fontWeight:600,letterSpacing:"1px",color:n.textSecondary,marginBottom:"8px",textTransform:"uppercase"},children:"Pending Deposits"}),a("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:e.map((s,r)=>{const i=Be(s.chainId)?.displayName||`Chain ${s.chainId}`;return g("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 12px",backgroundColor:o?n.warningBg:"#fffbeb",border:o?`1px solid ${n.warningBorder}`:"1px solid #fde68a",borderRadius:"8px"},children:[g("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[a("div",{style:{width:"24px",height:"24px",borderRadius:"50%",backgroundColor:o?n.hoverBg:"#fde68a",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"11px",fontWeight:600,color:n.warningText},children:s.tokenSymbol.charAt(0)}),g("div",{children:[g("div",{style:{fontSize:"13px",fontWeight:500,color:n.textPrimary},children:[s.amount," ",s.tokenSymbol]}),g("div",{style:{fontSize:"11px",color:n.warningText},children:["on ",i]})]})]}),a("button",{onClick:()=>t?.(s),style:{padding:"4px 12px",fontSize:"11px",fontWeight:600,backgroundColor:o?n.hoverBg:"#fef3c7",color:o?n.textPrimary:"#92400e",border:o?`1px solid ${n.warningBorder}`:"1px solid #fde68a",borderRadius:"9999px",cursor:"pointer",transition:"background-color 150ms ease, border-color 150ms ease, color 150ms ease"},children:"Complete"})]},`${s.tokenAddress}-${s.chainId}-${r}`)})})]}),td=({spiceAssets:e,loading:t,dk:n,dark:o=!1})=>{const s={fontSize:"11px",fontWeight:600,letterSpacing:"1px",color:n.textSecondary,marginBottom:"8px",textTransform:"uppercase"},r={backgroundColor:n.cardBg,border:o?`1px solid ${n.cardBorder}`:"1px solid #e5e7eb",borderRadius:"8px"};return t?g("div",{children:[a("div",{style:s,children:"Idle Balances"}),[1,2].map(i=>a("div",{style:{...r,padding:"12px",marginBottom:"6px",height:"48px",animation:"pulse 1.5s ease-in-out infinite",opacity:.5}},i))]}):e.length===0?g("div",{children:[a("div",{style:s,children:"Idle Balances"}),a("div",{style:{...r,padding:"16px",textAlign:"center",fontSize:"13px",color:o?n.textSecondary:"#9ca3af"},children:"No assets yet. Deposit to get started."})]}):g("div",{children:[a("div",{style:s,children:"Idle Balances"}),a("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:e.map((i,c)=>{const d=Be(i.chainId),l=i.chainDisplayName||d?.displayName||`Chain ${i.chainId}`,p=i.tokenDisplaySymbol||i.tokenDisplayName||i.tokenSymbol;return g("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 12px",...r},children:[g("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[i.logoURI?a("img",{src:i.logoURI,alt:i.tokenSymbol,style:{width:"24px",height:"24px",borderRadius:"50%"}}):a("div",{style:{width:"24px",height:"24px",borderRadius:"50%",backgroundColor:o?n.hoverBg:"#e5e7eb",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"11px",fontWeight:600,color:n.textSecondary},children:p.charAt(0)}),g("div",{children:[a("div",{style:{fontSize:"13px",fontWeight:500,color:n.textPrimary},children:p}),a("div",{style:{fontSize:"11px",color:o?n.textSecondary:"#9ca3af"},children:l})]})]}),g("div",{style:{textAlign:"right"},children:[a("div",{style:{fontSize:"13px",fontWeight:500,color:n.textPrimary},children:jn(i.balanceFormatted)}),a("div",{style:{fontSize:"11px",color:o?n.textSecondary:"#9ca3af"},children:oo(i.usdValue)})]})]},`${i.tokenAddress}-${i.chainId}-${c}`)})})]})},nd=({section:e,dk:t,dark:n=!1})=>{const o=s=>{switch(s){case"green":return"#10b981";case"red":return"#ef4444";default:return t.textPrimary}};return g("div",{children:[a("div",{style:{fontSize:"11px",fontWeight:600,letterSpacing:"1px",color:t.textSecondary,marginBottom:"8px",textTransform:"uppercase"},children:e.title}),a("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:e.items.map((s,r)=>g("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 12px",backgroundColor:t.cardBg,border:n?`1px solid ${t.cardBorder}`:"1px solid #e5e7eb",borderRadius:"8px"},children:[g("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[s.tokenLogoURI?a("img",{src:s.tokenLogoURI,alt:s.tokenSymbol,style:{width:"20px",height:"20px",borderRadius:"50%"}}):a("div",{style:{width:"20px",height:"20px",borderRadius:"50%",backgroundColor:n?t.hoverBg:"#e5e7eb",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"10px",fontWeight:600,color:t.textSecondary},children:s.tokenSymbol.charAt(0)}),g("div",{children:[a("div",{style:{fontSize:"13px",fontWeight:500,color:t.textPrimary},children:s.tokenSymbol}),a("div",{style:{fontSize:"11px",color:t.textSecondary},children:s.label})]})]}),a("div",{style:{fontSize:"13px",fontWeight:600,color:o(s.valueColor)},children:s.displayValue})]},r))})]})},od=({onDepositClick:e,onWithdrawClick:t,depositDisabled:n=!1,withdrawDisabled:o=!1,primaryColor:s="#EA4B4B",dark:r=!1})=>!e&&!t?null:g("div",{style:{display:"flex",gap:"8px"},children:[e&&a(At,{variant:"outline",onClick:e,disabled:n,dark:r,styles:{button:{backgroundColor:s}},style:{flex:1,height:"44px",fontSize:"12px"},children:"Deposit"}),t&&a(At,{variant:"outline",onClick:t,disabled:o,dark:r,styles:{button:{backgroundColor:s}},style:{flex:1,height:"44px",fontSize:"12px"},children:"Withdraw"})]}),sd=({appName:e,status:t,statusLabel:n,totalUsdValue:o,breakdownSubtitle:s,address:r,spiceAssets:i,spiceAssetsLoading:c,pendingDeposits:d,customSections:l,onDepositClick:p,onWithdrawClick:u,onCompleteDeposit:h,primaryColor:m,dk:f,dark:y=!1,showModeToggle:C,isEmbeddedMode:v,onModeToggle:b,showConnectExternalCta:w,onConnectExternalWallet:I,connectExternalError:x,showHowItWorks:S=!0})=>{const[A,B]=R(!1);return g("div",{style:{display:"flex",flexDirection:"column",gap:"16px",padding:"16px",maxHeight:"calc(80vh - 32px)",overflowY:"auto"},children:[a(_c,{appName:e,status:t,statusLabel:n,totalUsdValue:o,breakdownSubtitle:s,address:r,dk:f,dark:y,showModeToggle:C,isEmbeddedMode:v,onModeToggle:b}),w&&g("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:[a("button",{onClick:I,style:{width:"100%",padding:"10px 14px",borderRadius:"8px",backgroundColor:m||"#EA4B4B",color:"#ffffff",border:"none",cursor:"pointer",fontSize:"13px",fontWeight:600,fontFamily:'"Helvetica Neue", sans-serif',transition:"opacity 150ms ease"},children:"Connect External Wallet"}),x&&a("span",{style:{fontSize:"11px",color:y?f.errorText:"#b91c1c",lineHeight:1.4},children:x})]}),a("div",{style:{height:"1px",backgroundColor:y?"#2d2d2d":"#e5e7eb"}}),a(od,{onDepositClick:p,onWithdrawClick:u,primaryColor:m,dark:y}),S&&g("div",{children:[g("button",{onClick:()=>B(!A),style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",padding:"8px 12px",backgroundColor:f.cardBg,border:y?`1px solid ${f.cardBorder}`:"1px solid #e5e7eb",borderRadius:"8px",cursor:"pointer",color:f.textSecondary,fontSize:"12px",fontWeight:500},children:[a("span",{children:"How It Works"}),a("span",{style:{transform:A?"rotate(180deg)":"rotate(0deg)",transition:"transform 200ms ease",fontSize:"10px"},children:"\u25BE"})]}),A&&g("div",{style:{marginTop:"6px",padding:"10px 12px",backgroundColor:y?f.cardBg:"#f0fdf4",border:y?`1px solid ${f.cardBorder}`:"1px solid #bbf7d0",borderRadius:"8px",fontSize:"12px",lineHeight:1.5,color:y?f.textSecondary:"#374151"},children:["Fund your ",e," Account from any supported chain. Once funded, transact gas-free and asset-abstracted on ",e,"."]})]}),a(ed,{pendingDeposits:d,onCompleteDeposit:h,dk:f,dark:y}),a(td,{spiceAssets:i,loading:c,dk:f,dark:y}),l.map((F,k)=>a(nd,{section:F,dk:f,dark:y},k))]})},Ks=380,eo=8;function Ba(e){return e?.trim().replace(/^spice/i,"").replace(/[^a-z0-9]/gi,"").toUpperCase()||void 0}function rd(e,t){const n=new Map;Object.entries(t).forEach(([s,r])=>{if(!Number.isFinite(r)||r<=0)return;n.set(s,r),n.set(s.toUpperCase(),r);const i=Ba(s);i&&n.set(i,r)});const o=[e.symbol,e.displaySymbol,e.receiptTokenName,e.name,e.displayName];for(const s of o){if(!s)continue;const r=n.get(s)??n.get(s.toUpperCase());if(r!==void 0)return r;const i=Ba(s);if(!i)continue;const c=n.get(i);if(c!==void 0)return c}return 0}const ad=({appName:e="Spice",status:t="active",statusLabel:n,customSections:o=[],extraAssets:s=[],tokenPrices:r={},breakdownLabels:i=[],styles:c,dark:d=!1,onDepositSuccess:l,onDepositClick:p,onWithdrawClick:u,onCompleteDeposit:h,showModeToggle:m=!1,defaultMode:f})=>{const y=Gt(Lt),C=y?.mode!=="7702",v=!!y?.isWhitelistGateActive,b=ie(!1);X(()=>{if(!b.current){if(Va()){b.current=!0;return}f&&y?.setMode&&(y.setMode(f==="non7702"?"ondemand":"7702"),b.current=!0)}},[y,f]);const[w,I]=R(!1),[x,S]=R(null),[A,B]=R({top:0,bottom:0,left:0,placement:"below"}),F=ie(null),k=ie(null),{address:E,isConnected:M}=Fn(),T=Bn(),{externalAddress:O,embeddedAddress:N}=no(),{dark:U,primaryColor:V,dk:D}=ut(c,d),Q=C&&!O,P=!C||Q,j=P?T||N:E,L=re(()=>y?.supportedChainIds??Ro("mainnet"),[y?.supportedChainIds]),{assets:Z,loading:ge}=Eo({address:j,supportedChains:L,enabled:!!j&&P,refetchInterval:3e4}),W=re(()=>{const oe=P?Z.map(Y=>{const ke=Y.balanceUsd||0,St=Number.isFinite(Y.balanceFormatted)?Y.balanceFormatted:0,Rt=ke>0?ke:rd(Y,r)*St;return{tokenAddress:Y.address,tokenSymbol:Y.symbol,tokenDisplaySymbol:ys(Y),tokenDisplayName:Si(Y),tokenDecimals:Y.decimals,chainId:Y.chainId,chainDisplayName:xs(Y),balance:Y.balance.toString(),balanceFormatted:Y.balanceFormatted,usdValue:Rt,logoURI:Y.logoURI}}):[],je=Q?[]:s;return[...oe,...je].filter(Y=>Y.balanceFormatted>0)},[P,Q,Z,r,s]),_=re(()=>W.reduce((oe,je)=>oe+je.usdValue,0),[W]),{pendingDeposits:fe}=Fa({chainIds:L,enabled:!!E,discoverWalletBalances:!0}),be=re(()=>o.reduce((oe,je)=>oe+je.totalValue,0),[o]),Me=_+be,he=re(()=>{const oe=[];_>0&&oe.push(`${oo(_)} idle`);for(const je of o){const Y=i.find(ke=>ke.sectionTitle===je.title)?.label||je.title.toLowerCase();oe.push(`${oo(je.totalValue)} ${Y}`)}return oe.join(" \xB7 ")},[_,o,i]),xe=ce(oe=>{h?h(oe):S(oe)},[h]),H=ce(()=>{S(null)},[]),se=ce(()=>{S(null),l?.()},[l]),K=ce(()=>{if(!F.current)return;const oe=F.current.getBoundingClientRect(),je=window.innerHeight-oe.bottom-eo,Y=oe.top-eo,ke=je>=400||je>=Y?"below":"above",St=Math.max(eo,Math.min(oe.right-Ks,window.innerWidth-Ks-eo)),Rt=ke==="below"?oe.bottom+eo:oe.top-eo,lt=ke==="above"?window.innerHeight-Rt:0;B({top:Rt,bottom:lt,left:St,placement:ke})},[]);Gs(()=>{w&&K()},[w,K]),X(()=>{if(!w)return;const oe=ke=>{F.current&&!F.current.contains(ke.target)&&k.current&&!k.current.contains(ke.target)&&I(!1)},je=ke=>{ke.key==="Escape"&&I(!1)},Y=()=>K();return document.addEventListener("mousedown",oe),document.addEventListener("keydown",je),window.addEventListener("scroll",Y,{passive:!0}),window.addEventListener("resize",K),()=>{document.removeEventListener("mousedown",oe),document.removeEventListener("keydown",je),window.removeEventListener("scroll",Y),window.removeEventListener("resize",K)}},[w,K]);const le=P?T||N||E:O||E,ye=ce(()=>{y?.setMode&&y.setMode(P?"ondemand":"7702")},[y,P]),[Ee,ee]=R(null);let z=null;try{z=sr({onSuccess:()=>ee(null),onError:oe=>ee(bn(oe,"Failed to connect wallet."))}).connectWallet}catch{z=null}const ae=ce(()=>{z&&(I(!1),ee(null),z({walletChainType:"ethereum-only"}))},[z]),we=!O&&!!z,Le=ce(()=>{I(!1),p?.()},[p]),wt=ce(()=>{I(!1),u?.()},[u]),at=ce(oe=>{I(!1),xe(oe)},[xe]);if(typeof window>"u")return null;const it=g("button",{ref:F,onClick:()=>I(!w),style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"8px 14px",borderRadius:"9999px",backgroundColor:U?D.hoverBg:"#ffffff",border:U?`1px solid ${D.cardBorder}`:"1px solid #e5e7eb",cursor:"pointer",fontSize:"13px",fontWeight:500,fontFamily:'"Helvetica Neue", sans-serif',color:U?D.textPrimary:"#111827",transition:"background-color 150ms ease, border-color 150ms ease, box-shadow 150ms ease",boxShadow:U?"none":"0 1px 2px rgba(0,0,0,0.05)"},children:[g("span",{children:[e," Account"]}),M&&g("span",{style:{color:U?D.textSecondary:"#6b7280"},children:["\xB7 ",oo(Me)]}),a("span",{style:{fontSize:"10px",color:U?D.textSecondary:"#9ca3af",transform:w?"rotate(180deg)":"rotate(0deg)",transition:"transform 200ms ease"},children:"\u25BE"})]}),Re=w?rr.createPortal(g(fn,{children:[a("div",{style:{position:"fixed",inset:0,backgroundColor:"rgba(0, 0, 0, 0.08)",zIndex:Xn.popover},onClick:()=>I(!1)}),a("div",{ref:k,style:{position:"fixed",top:A.placement==="below"?`${A.top}px`:"auto",bottom:A.placement==="above"?`${A.bottom}px`:"auto",left:`${A.left}px`,width:`${Ks}px`,maxWidth:`calc(100vw - ${eo*2}px)`,maxHeight:"80vh",backgroundColor:U?D.shell:"#ffffff",border:U?`1px solid ${D.cardBorder}`:"1px solid #e5e7eb",borderRadius:"12px",boxShadow:U?"0 10px 40px rgba(0, 0, 0, 0.5)":"0 10px 40px rgba(0, 0, 0, 0.12)",zIndex:Xn.popover+1,overflow:"hidden",animation:`accountDisplayFadeIn 200ms ${Ht.out}`},children:a(sd,{appName:e,status:t,statusLabel:n,totalUsdValue:Me,breakdownSubtitle:he,address:P?le:E,spiceAssets:W,spiceAssetsLoading:ge,pendingDeposits:fe,customSections:o,onDepositClick:p?Le:void 0,onWithdrawClick:u?wt:void 0,onCompleteDeposit:at,primaryColor:V,dk:D,dark:U,showModeToggle:m,isEmbeddedMode:P,onModeToggle:ye,showConnectExternalCta:we,onConnectExternalWallet:ae,connectExternalError:Ee,showHowItWorks:!v})}),a("style",{children:`
104
104
  @keyframes accountDisplayFadeIn {
105
105
  from { opacity: 0; transform: translateY(-4px); }
106
106
  to { opacity: 1; transform: translateY(0); }