@aori/mega-swap-widget 0.1.2 → 0.1.4
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/README.md +31 -0
- package/dist/AssetSelectionMenu-KOJBN3OR.js +2 -0
- package/dist/AssetSelectionMenu-M7HHUUWM.cjs +2 -0
- package/dist/ChainSelectionMenu-EJANKMWU.cjs +2 -0
- package/dist/ChainSelectionMenu-YCFDREZO.js +2 -0
- package/dist/SwapFormHorizontal-6YSJJM2S.cjs +2 -0
- package/dist/SwapFormHorizontal-E32W3PHA.js +2 -0
- package/dist/SwapFormSplit-6Y2B4VU3.cjs +2 -0
- package/dist/SwapFormSplit-M4YIQNAW.js +2 -0
- package/dist/WidgetWalletPanel-LKFDBFYR.cjs +2 -0
- package/dist/WidgetWalletPanel-T5L5224H.js +2 -0
- package/dist/WidgetWalletTradeHistory-PZLWJ2IK.js +2 -0
- package/dist/WidgetWalletTradeHistory-SDYMU4HL.cjs +2 -0
- package/dist/chunk-3RAZPKY5.js +2 -0
- package/dist/chunk-4CM44UII.cjs +2 -0
- package/dist/chunk-52HJQZWW.cjs +2 -0
- package/dist/chunk-5WTODHGO.cjs +2 -0
- package/dist/chunk-7QJJOVSV.js +2 -0
- package/dist/chunk-BJYKILHS.cjs +2 -0
- package/dist/chunk-EXGKQSDI.cjs +2 -0
- package/dist/chunk-GDIG4JLQ.cjs +2 -0
- package/dist/chunk-JVRQLJXZ.js +2 -0
- package/dist/chunk-SBQ3EQ2U.js +2 -0
- package/dist/chunk-SE6JOLEM.cjs +27 -0
- package/dist/chunk-TCAVGM6Y.cjs +2 -0
- package/dist/chunk-VI4ISTPB.js +2 -0
- package/dist/chunk-ZA7N764R.js +2 -0
- package/dist/chunk-ZFVYFTDI.js +2 -0
- package/dist/chunk-ZKDVXDQF.cjs +2 -0
- package/dist/chunk-ZWGBVGLP.js +2 -0
- package/dist/chunk-ZWNDO5OZ.js +27 -0
- package/dist/index.cjs +2 -2
- package/dist/index.css +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -2
- package/package.json +1 -1
- package/dist/AssetSelectionMenu-4E576X3D.cjs +0 -2
- package/dist/AssetSelectionMenu-ZFY7XFRX.js +0 -2
- package/dist/ChainSelectionMenu-SKXLHK3S.js +0 -2
- package/dist/ChainSelectionMenu-VU3SIBVL.cjs +0 -2
- package/dist/SwapFormHorizontal-GI4X7ISS.js +0 -2
- package/dist/SwapFormHorizontal-V557YBX2.cjs +0 -2
- package/dist/SwapFormSplit-52RBMJIO.js +0 -2
- package/dist/SwapFormSplit-PQCS3BPT.cjs +0 -2
- package/dist/WidgetWalletPanel-XYV3YL4I.js +0 -2
- package/dist/WidgetWalletPanel-YBMN5KZH.cjs +0 -2
- package/dist/chunk-4BQRVCQR.js +0 -2
- package/dist/chunk-4LJJMEOG.js +0 -2
- package/dist/chunk-726CI6GC.js +0 -2
- package/dist/chunk-DUIRZSBV.cjs +0 -2
- package/dist/chunk-EW2OR6CJ.js +0 -27
- package/dist/chunk-FDQKBTWP.js +0 -2
- package/dist/chunk-HTWUZKYO.cjs +0 -2
- package/dist/chunk-LXEKOQAG.cjs +0 -27
- package/dist/chunk-MCT3UZTP.cjs +0 -2
- package/dist/chunk-UZWGYG2S.cjs +0 -2
- package/dist/chunk-XYF2YBR3.js +0 -2
- package/dist/chunk-XZRXVBSB.cjs +0 -2
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } async function _asyncOptionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }"use client";
|
|
2
|
+
var _chunkKH57FLSTcjs = require('./chunk-KH57FLST.cjs');var _chunkBJYKILHScjs = require('./chunk-BJYKILHS.cjs');var _chunkTCAVGM6Ycjs = require('./chunk-TCAVGM6Y.cjs');var _chunkSE6JOLEMcjs = require('./chunk-SE6JOLEM.cjs');var _chunk34N36GUDcjs = require('./chunk-34N36GUD.cjs');var _chunkT3I3AJXVcjs = require('./chunk-T3I3AJXV.cjs');var _reactquery = require('@tanstack/react-query');var _react = require('react');function Sr(e){if(e.length===0)return 5e3;let l=Math.max(...e.map(r=>_nullishCoalesce(_optionalChain([_chunkSE6JOLEMcjs.c.call(void 0, r), 'optionalAccess', _2 => _2.blockTimeMs]), () => (2e3))));return Math.min(5e3,Math.max(1e3,l*2+1e3))}var Tr=()=>{let{address:e}=_chunk34N36GUDcjs.a.call(void 0, ),t=_chunkTCAVGM6Ycjs.c.call(void 0, ),s=_reactquery.useQueryClient.call(void 0, ),c=_react.useRef.call(void 0, null),l=_react.useRef.call(void 0, !0),r=_react.useCallback.call(void 0, a=>{if(!e)return;let h=[...new Set(a.tokens.map(p=>p.asset.chainId))],y=Sr(h);c.current&&(clearTimeout(c.current),c.current=null),c.current=setTimeout(async()=>{if(c.current=null,!!l.current)try{let p=a.tokens.map(w=>({chainId:w.asset.chainId,tokenAddress:w.asset.address})),o=await _chunkSE6JOLEMcjs.H.call(void 0, e,p);if(o.balances.length===0)return;if(a.tokens.length>=2){let w=a.tokens[0].asset,d=a.tokens[1].asset,f=_chunkSE6JOLEMcjs.I.swap(e,w.chainId,w.address,d.chainId,d.address);s.setQueryData(f,o)}let n=_chunkSE6JOLEMcjs.I.bulk(e,t),b=s.getQueryData(n);if(b){let w=b.balances.map(d=>_nullishCoalesce(o.balances.find(g=>g.chainId===d.chainId&&g.token.toLowerCase()===d.token.toLowerCase()), () => (d)));for(let d of o.balances)w.some(f=>f.chainId===d.chainId&&f.token.toLowerCase()===d.token.toLowerCase())||w.push(d);for(let d of a.tokens)if(!o.balances.some(g=>g.chainId===d.asset.chainId&&g.token.toLowerCase()===d.asset.address.toLowerCase())){let g=w.findIndex(i=>i.chainId===d.asset.chainId&&i.token.toLowerCase()===d.asset.address.toLowerCase());g!==-1&&(w[g]={...w[g],balance:"0",shiftedBalance:"0"})}s.setQueryData(n,{balances:w})}}catch (e2){}},y)},[e,t,s]);return _react.useEffect.call(void 0, ()=>(l.current=!0,()=>{l.current=!1,c.current&&(clearTimeout(c.current),c.current=null)}),[]),{triggerBalanceUpdate:r}},st=class extends EventTarget{emit(t){this.dispatchEvent(new CustomEvent("balance-update",{detail:t}))}},ot=new st,Ee= exports.b =()=>e=>ot.emit(e),ts= exports.c =()=>{let{triggerBalanceUpdate:e}=Tr();_react.useEffect.call(void 0, ()=>{let t=s=>{e(s.detail)};return ot.addEventListener("balance-update",t),()=>ot.removeEventListener("balance-update",t)},[e])};var _viem = require('viem');var _jsxruntime = require('react/jsx-runtime');var $t=_react.createContext.call(void 0, void 0),Pt=1e4,Ir=3e4,Or=1e3,Pr=2;function $r(e){return _nullishCoalesce(e.find(s=>_optionalChain([s, 'access', _3 => _3.routeSteps, 'optionalAccess', _4 => _4[0], 'optionalAccess', _5 => _5.type])==="AORI_V1"), () => (e[0]))}var ls=({children:e,recipient:t})=>{let{address:s}=_chunk34N36GUDcjs.a.call(void 0, ),c=t||s,[l,r]=_react.useState.call(void 0, "idle"),[a,h]=_react.useState.call(void 0, "idle"),[y,p]=_react.useState.call(void 0, null),[o,n]=_react.useState.call(void 0, null),[b,w]=_react.useState.call(void 0, !1),[d,f]=_react.useState.call(void 0, !1),[g,i]=_react.useState.call(void 0, !1),m=_react.useRef.call(void 0, null),v=_react.useRef.call(void 0, null),u=_react.useRef.call(void 0, null),T=_react.useRef.call(void 0, null),P=_react.useRef.call(void 0, null),C=_react.useRef.call(void 0, 0),$=_react.useRef.call(void 0, 0),L=_react.useRef.call(void 0, 0),N=_react.useRef.call(void 0, !1),E=_react.useRef.call(void 0, new Map),I=_react.useCallback.call(void 0, ()=>{u.current&&clearTimeout(u.current),T.current&&clearTimeout(T.current),P.current&&clearTimeout(P.current),u.current=null,T.current=null,P.current=null},[]),U=_react.useCallback.call(void 0, ()=>{I(),m.current=null,C.current=0,r(()=>N.current?"fresh":"idle")},[I]),B=_react.useCallback.call(void 0, ()=>{U(),v.current=null,p(null),n(null),w(!1),f(!1),i(!1),E.current.clear(),r("idle"),h("idle")},[U]),oe=_react.useCallback.call(void 0, x=>{if(!x)return;T.current&&clearTimeout(T.current);let S=Math.max(0,x+Ir-Date.now());T.current=setTimeout(()=>{r(O=>O==="idle"?"idle":"stale")},S)},[]),H=_react.useCallback.call(void 0, async(x,S)=>{let{inputToken:O,outputToken:A,inputAmount:q,setOutputAmount:Z}=x;if(!O||!A||!q||parseFloat(q)<=0||Date.now()-($.current||0)<Pt-10)return;let Be=++C.current;try{if(!_optionalChain([O, 'optionalAccess', _6 => _6.decimals])||!_optionalChain([A, 'optionalAccess', _7 => _7.decimals]))return;let z=_chunkSE6JOLEMcjs.A.call(void 0, O.chainId)||_optionalChain([_chunkSE6JOLEMcjs.c.call(void 0, O.chainId), 'optionalAccess', _8 => _8.key])||"",ie=_chunkSE6JOLEMcjs.A.call(void 0, A.chainId)||_optionalChain([_chunkSE6JOLEMcjs.c.call(void 0, A.chainId), 'optionalAccess', _9 => _9.key])||"";if(!z||!ie)throw new Error("Unknown chain");let ee=_viem.parseUnits.call(void 0, q.toString(),O.decimals).toString(),Ce={srcChainKey:z,dstChainKey:ie,srcTokenAddress:_chunkSE6JOLEMcjs.v.call(void 0, O.address),dstTokenAddress:_chunkSE6JOLEMcjs.v.call(void 0, A.address),amount:ee,srcWalletAddress:s||"0x0000000000000000000000000000000000000000",dstWalletAddress:c||s||"0x0000000000000000000000000000000000000000",options:{amountType:"EXACT_SRC_AMOUNT",feeTolerance:{type:"PERCENT",amount:2}}};$.current=Date.now();let te=await fetch(`${_chunkSE6JOLEMcjs.k.call(void 0, )}/quotes`,{method:"POST",headers:_chunkSE6JOLEMcjs.m.call(void 0, ),body:JSON.stringify(Ce),signal:AbortSignal.timeout(15e3)});if(!te.ok){let Se=await _asyncOptionalChain([(await te.json().catch(()=>({}))), 'optionalAccess', async _10 => _10.message])||te.statusText;throw Object.assign(new Error(Se),{status:te.status})}let me=await te.json();if(Be!==C.current||m.current!==S)return;let $e=_nullishCoalesce(me.quotes, () => ([])),ae=$r($e);if(!ae)throw Object.assign(new Error("No quotes returned"),{emptyQuotes:!0});let Je=Number(_viem.formatUnits.call(void 0, _chunkSE6JOLEMcjs.q.call(void 0, ae.dstAmount),A.decimals));typeof Z=="function"&&Z(Je),ae._receivedAt=Date.now(),p(ae),n(null),w(!1),r("fresh"),oe(ae._receivedAt),S&&E.current.delete(S)}catch(z){if(Be!==C.current||m.current!==S)return;let ie=_optionalChain([z, 'optionalAccess', _11 => _11.status]),ee=z instanceof Error?z.message:"",Ce=!!_optionalChain([z, 'optionalAccess', _12 => _12.emptyQuotes]);if((ie===400||Ce||ee.includes("Quote request failed"))&&S){let me=(E.current.get(S)||0)+1;if(E.current.set(S,me),me>=Pr){f(!0),I(),m.current=null;return}}if(ee.toLowerCase().includes("order cap exceeded")){i(!0),I(),m.current=null;return}if(ee.toLowerCase().includes("insufficient executor balance")){w(!0),I(),m.current=null;return}n(z instanceof Error?z.message:"Unknown error")}},[s,c,oe,I]),W=_react.useCallback.call(void 0, (x,S)=>{I(),v.current=x,$.current=0,E.current.delete(S),w(!1),f(!1),i(!1),n(null),r("polling");let O=async()=>{m.current===S&&(await H(x,S),m.current===S&&(u.current=setTimeout(O,Pt)))};O()},[I,H]),R=_react.useCallback.call(void 0, x=>{if(!_optionalChain([x, 'optionalAccess', _13 => _13.inputToken])||!_optionalChain([x, 'optionalAccess', _14 => _14.outputToken])||!_optionalChain([x, 'optionalAccess', _15 => _15.inputAmount])||parseFloat(x.inputAmount)<=0){U();return}let S=v.current;if(S&&_optionalChain([S, 'access', _16 => _16.inputToken, 'optionalAccess', _17 => _17.address])===_optionalChain([x, 'access', _18 => _18.inputToken, 'optionalAccess', _19 => _19.address])&&_optionalChain([S, 'access', _20 => _20.inputToken, 'optionalAccess', _21 => _21.chainId])===_optionalChain([x, 'access', _22 => _22.inputToken, 'optionalAccess', _23 => _23.chainId])&&_optionalChain([S, 'access', _24 => _24.outputToken, 'optionalAccess', _25 => _25.address])===_optionalChain([x, 'access', _26 => _26.outputToken, 'optionalAccess', _27 => _27.address])&&_optionalChain([S, 'access', _28 => _28.outputToken, 'optionalAccess', _29 => _29.chainId])===_optionalChain([x, 'access', _30 => _30.outputToken, 'optionalAccess', _31 => _31.chainId])&&S.inputAmount===x.inputAmount&&m.current)return;let A=Date.now();if(A-L.current<100)return;L.current=A;let q=`${Date.now()}-${Math.random().toString(36).slice(2)}`;m.current=q,W(x,q)},[W,U]),V=_react.useCallback.call(void 0, ({amount:x,inputToken:S,outputToken:O,setOutputAmount:A})=>{A(null),P.current&&clearTimeout(P.current),!x||x===0?(h("idle"),U(),p(null),n(null),w(!1),f(!1),i(!1)):(h("typing"),U(),p(null),w(!1),f(!1),i(!1),n(null),P.current=setTimeout(()=>{h("settled"),S&&O&&x>0&&R({inputToken:S,outputToken:O,inputAmount:x.toString(),setOutputAmount:A})},Or))},[U,R]),F=_react.useCallback.call(void 0, ()=>{let x=v.current;if(!x)return;p(null);let S=`${Date.now()}-${Math.random().toString(36).slice(2)}`;m.current=S,r("refreshing"),typeof x.setOutputAmount=="function"&&x.setOutputAmount(null),W(x,S)},[W]);_react.useEffect.call(void 0, ()=>{N.current=!!y},[y]),_react.useEffect.call(void 0, ()=>()=>I(),[I]);let X=_react.useMemo.call(void 0, ()=>({status:l,inputState:a,rfqQuote:y,error:o,liquidityError:b,routingError:d,sizeCapError:g,ensureForParams:R,stop:U,refresh:F,clear:B,handleInputChange:V}),[l,a,y,o,b,d,g,R,U,F,B,V]);return _jsxruntime.jsx.call(void 0, $t.Provider,{value:X,children:e})},Ve= exports.e =()=>{let e=_react.useContext.call(void 0, $t);if(e===void 0)throw new Error("useRfq must be used within an RfqProvider");return e};var Wr=_react.createContext.call(void 0, {openConnectModal:()=>{}}),ms= exports.g =()=>_react.useContext.call(void 0, Wr);var Lr=20,Br=({side:e,asset:t,otherAsset:s,isPlacingOrder:c,isWrappingPair:l,isUnwrappingPair:r})=>{let{baseAmount:a,quoteAmount:h,setBaseAmount:y,setQuoteAmount:p}=_chunkBJYKILHScjs.f.call(void 0, ),{amountInputVariant:o,hideAmountInputSymbol:n,widgetType:b}=_chunkTCAVGM6Ycjs.b.call(void 0, ),w=b==="compact",[d,f]=e==="base"?[y,p]:[p,y],g=!t||e==="quote"||c,i=w?32:o==="default"?64:32,[m,v]=_react.useState.call(void 0, i),[u,T]=_react.useState.call(void 0, ""),P=_react.useRef.call(void 0, null),C=_react.useRef.call(void 0, null),$=_react.useRef.call(void 0, null),L=_react.useRef.call(void 0, null),N="USD",E=e==="base"?a:h,[I,U]=_react.useState.call(void 0, !1),B=_react.useCallback.call(void 0, ()=>{if(o!=="default"){v(i);return}if(!P.current||!C.current||!$.current)return;let W=P.current.offsetWidth,R=20,V=i;for(;V>20&&(C.current.style.fontSize=`${V}px`,$.current.style.fontSize=`${V}px`,!(C.current.offsetWidth+$.current.offsetWidth+R<=W));)V-=1;v(V)},[o,i]),oe=_react.useCallback.call(void 0, W=>{W.key==="."&&u.includes(".")&&W.preventDefault()},[u]),H=_react.useCallback.call(void 0, W=>{let R=W.target.value;if(R==="."&&(R="0."),!/^\d*\.?\d*$/.test(R)||(R.match(/\./g)||[]).length>1)return;if(R.length>1&&R[0]==="0"&&R[1]!=="."&&(R=R.replace(/^0+/,"")||"0"),_optionalChain([t, 'optionalAccess', _32 => _32.decimals])!==void 0&&R.includes(".")){let[,F]=R.split(".");if(F&&F.length>t.decimals)return}if(R.length>Lr)return;T(R);let V=parseFloat(R);R!==u&&(R===""||R==="0."||R.endsWith(".")?(d(null),e==="base"&&f(null)):!Number.isNaN(V)&&V>=0&&d(V),e==="base"&&p(null),(r||l)&&p(V||0))},[u,d,e,p,_optionalChain([t, 'optionalAccess', _33 => _33.decimals]),f,r,l]);return _react.useEffect.call(void 0, ()=>{let W=F=>{if(F===null)return"";let X=_optionalChain([t, 'optionalAccess', _34 => _34.decimals]);if(X===void 0)return"";let x=F.toString();if(/e/i.test(x)&&(x=Number(F).toLocaleString("en-US",{useGrouping:!1,maximumFractionDigits:X})),x.includes(".")){let[S,O]=x.split("."),A=O.slice(0,X);return A?`${S}.${A}`:S}return x};if(E===null){u==="0."||u!==""&&u.endsWith(".")||T("");return}if(!g&&(u.endsWith(".")||u.match(/\.\d*0$/)||u==="0"||u==="0.")&&u!=="")return;let V=parseFloat(u)||0;(u===""||Math.abs(V-E)>1e-10)&&T(W(E))},[E,_optionalChain([t, 'optionalAccess', _35 => _35.decimals]),u,g]),_react.useEffect.call(void 0, ()=>{B()},[u,B]),_react.useEffect.call(void 0, ()=>{U(!0)},[]),_react.useEffect.call(void 0, ()=>{I&&B()},[I,B]),_react.useEffect.call(void 0, ()=>{C.current&&L.current&&(L.current.style.width=`${C.current.offsetWidth}px`)},[u]),_react.useEffect.call(void 0, ()=>{if(!I)return;let W=new ResizeObserver(()=>{I&&B()});return P.current&&W.observe(P.current),()=>W.disconnect()},[I,B]),_jsxruntime.jsx.call(void 0, "div",{ref:P,style:{fontSize:`${m}px`,transition:"font-size 0.05s ease-in-out"},className:`mt-2 box-border flex ${w?o==="normal"?"h-12 my-1":"h-10 my-0.5":o==="normal"?"h-12 my-1":"h-20 my-1"} w-full flex-row items-center ${g?"cursor-default":"cursor-text"}`,onClick:()=>_optionalChain([L, 'access', _36 => _36.current, 'optionalAccess', _37 => _37.focus, 'call', _38 => _38()]),children:_jsxruntime.jsxs.call(void 0, "div",{className:"relative flex w-full items-center",children:[_jsxruntime.jsx.call(void 0, "label",{htmlFor:`${e}Amount`,className:"sr-only",children:e==="base"?"Input token amount":"Output token amount"}),_jsxruntime.jsx.call(void 0, "input",{ref:L,type:"text",inputMode:"decimal",placeholder:"0",autoComplete:"off",id:`${e}Amount`,value:u,onWheel:W=>W.target.blur(),onKeyDown:oe,onChange:H,style:{transition:"width 0.15s ease-in-out",color:"var(--widget-foreground)",WebkitTextFillColor:"var(--widget-foreground)",opacity:g?.4:1},className:"flex min-w-[45px] whitespace-nowrap bg-transparent placeholder:opacity-50",disabled:g}),_jsxruntime.jsx.call(void 0, "span",{style:{transition:"width 0.15s ease-in-out"},ref:C,className:"pointer-events-none absolute flex whitespace-nowrap invisible",children:u||0}),!n&&o!=="normal"&&_jsxruntime.jsx.call(void 0, "span",{ref:$,className:"ml-2 font-light uppercase",style:{color:"var(--widget-foreground)",opacity:.5,fontSize:`${m}px`},children:_optionalChain([t, 'optionalAccess', _39 => _39.symbol])?t.symbol.length>6?`${t.symbol.slice(0,6)}...`:t.symbol:N}),(n||o==="normal")&&_jsxruntime.jsx.call(void 0, "span",{ref:$,className:"hidden"})]})})},ys= exports.h =Br;var Vr=({toggle:e,side:t,asset:s,isPlacingOrder:c,hideDropdown:l})=>{let{baseBalance:r,quoteBalance:a}=_chunkBJYKILHScjs.f.call(void 0, ),{tokenDisplay:h,tokenBadgeOrientation:y,widgetType:p}=_chunkTCAVGM6Ycjs.b.call(void 0, ),o=p==="compact",n=o?"h-10":"h-12",b=o?"h-10 w-10":"h-12 w-12",w=t==="base"?r.formatted?(()=>{let f=parseFloat(r.formatted);return f>=1e8?_chunkSE6JOLEMcjs.o.call(void 0, f):f.toFixed(3)})():void 0:a.formatted?(()=>{let f=parseFloat(a.formatted);return f>=1e8?_chunkSE6JOLEMcjs.o.call(void 0, f):f.toFixed(3)})():void 0,d={role:"button",tabIndex:c?-1:0,"aria-disabled":c,"aria-label":`Select ${t==="base"?"input":"output"} token${s?`: ${s.symbol}`:""}`,onClick:c?void 0:e,onKeyDown:c?void 0:f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),e())}};return h==="pill"?_jsxruntime.jsx.call(void 0, "div",{...d,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-full cursor-pointer transition-colors ${y==="right"?"ml-auto":""}`,style:{border:"1px solid var(--widget-border)",backgroundColor:"var(--widget-secondary)",color:"var(--widget-secondary-foreground)"},children:s?_jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment,{children:[_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.M,{chain:s.chainId,size:"xs"}),_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.N,{className:"rounded-full",asset:s,size:"xxs",noChain:!0}),_jsxruntime.jsx.call(void 0, "span",{className:"text-xs font-medium uppercase",children:s.symbol}),!l&&_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.T,{className:"w-1.5 opacity-60",style:{color:"var(--widget-secondary-foreground)"}})]}):_jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment,{children:[_jsxruntime.jsx.call(void 0, "span",{className:"text-xs opacity-70",children:"Select"}),!l&&_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.T,{className:"w-1.5 opacity-60",style:{color:"var(--widget-secondary-foreground)"}})]})}):h==="ghost"?_jsxruntime.jsxs.call(void 0, "div",{...d,className:"inline-flex items-center gap-1.5 cursor-pointer transition-opacity hover:opacity-70 py-1",style:{color:"var(--widget-foreground)"},children:[s?_jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment,{children:[_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.M,{chain:s.chainId,size:"xs"}),_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.N,{className:"rounded-full",asset:s,size:"xxs",noChain:!0}),_jsxruntime.jsx.call(void 0, "span",{className:"text-sm font-medium uppercase",children:s.symbol})]}):_jsxruntime.jsx.call(void 0, "span",{className:"text-sm",style:{color:"var(--widget-muted-foreground)"},children:"Select token"}),!l&&_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.T,{className:"w-1.5 opacity-50"})]}):_jsxruntime.jsx.call(void 0, "div",{...d,className:`relative ${n} w-full cursor-pointer text-xl duration-100 ease-linear`,style:{border:"1px solid var(--widget-border)",backgroundColor:"var(--widget-secondary)",borderTopLeftRadius:"9999px",borderBottomLeftRadius:"9999px",borderTopRightRadius:"var(--widget-radius)",borderBottomRightRadius:"var(--widget-radius)"},children:_jsxruntime.jsx.call(void 0, "div",{className:"relative flex h-full w-full flex-row items-center",children:s?_jsxruntime.jsxs.call(void 0, "div",{className:"relative flex h-full w-full flex-row items-center",children:[_jsxruntime.jsx.call(void 0, "div",{className:`${b} pl-px flex items-center justify-center`,children:_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.N,{className:"rounded-full",asset:s,size:"md"})}),_jsxruntime.jsxs.call(void 0, "div",{className:"flex h-full w-full flex-row items-center justify-between pl-1.5 pr-7",children:[_jsxruntime.jsxs.call(void 0, "div",{className:"flex h-full flex-col justify-center",children:[_jsxruntime.jsx.call(void 0, "p",{className:"text-sm font-medium uppercase",style:{color:"var(--widget-secondary-foreground)"},children:s.symbol}),_jsxruntime.jsxs.call(void 0, "span",{className:"text-2xs font-mono",style:{color:"var(--widget-secondary-foreground)",opacity:.6},children:[_optionalChain([s, 'access', _40 => _40.address, 'optionalAccess', _41 => _41.slice, 'call', _42 => _42(0,6)]),"...",_optionalChain([s, 'access', _43 => _43.address, 'optionalAccess', _44 => _44.slice, 'call', _45 => _45(-4)])]})]}),w!==void 0&&_jsxruntime.jsxs.call(void 0, "div",{className:"flex flex-col text-right",children:[_jsxruntime.jsx.call(void 0, "p",{className:"text-2xs",style:{color:"var(--widget-secondary-foreground)",opacity:.5},children:"Balance"}),_jsxruntime.jsx.call(void 0, "span",{className:"font-mono text-xs tabular-nums",style:{color:"var(--widget-secondary-foreground)"},children:w})]})]}),!l&&_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.T,{className:"absolute right-3 top-1/2 w-1.5 translate-y-[-50%]",style:{color:"var(--widget-secondary-foreground)",opacity:.6}})]}):_jsxruntime.jsx.call(void 0, "div",{className:"flex h-full w-full items-center justify-center",children:_jsxruntime.jsx.call(void 0, "span",{className:"text-sm",style:{color:"var(--widget-secondary-foreground)",opacity:.7},children:"Select token"})})})})},Rs= exports.i =Vr;var Mt=_chunkT3I3AJXVcjs.b.call(void 0, _chunkKH57FLSTcjs.a.call(void 0, ),1);var Fr=()=>{let[e,t]=_react.useState.call(void 0, null),[s,c]=_react.useState.call(void 0, ""),l=_chunkSE6JOLEMcjs.x.call(void 0, s,1e3),[r,a]=_react.useState.call(void 0, !1),[h,y]=_react.useState.call(void 0, "");_react.useEffect.call(void 0, ()=>{_chunkBJYKILHScjs.c.getState().setRecipient(e)},[e]),_react.useEffect.call(void 0, ()=>{c(e||"")},[e]);let p=n=>{let b=n.target.value;r&&(a(!1),y(""),t(null)),c(b),b===""&&t(null)};_react.useEffect.call(void 0, ()=>{l===""||!l?(a(!1),y(""),t(null)):_chunkSE6JOLEMcjs.w.call(void 0, l)?(a(!1),y(""),t(l)):(a(!0),y("Invalid wallet address..."),t(null),c(""))},[l]),_react.useEffect.call(void 0, ()=>{if(r){let n=setTimeout(()=>{t(null),c(""),a(!1),y("")},2e3);return()=>clearTimeout(n)}},[r]);let o=()=>{t(null),c(""),a(!1),y("")};return _jsxruntime.jsx.call(void 0, "div",{className:"w-full",children:_jsxruntime.jsxs.call(void 0, "div",{className:"relative flex flex-row items-center",children:[_jsxruntime.jsx.call(void 0, "input",{type:"password",style:{display:"none"},"aria-hidden":"true",tabIndex:-1}),_jsxruntime.jsx.call(void 0, "label",{htmlFor:"recipient-address",className:"sr-only",children:"Recipient wallet address"}),_jsxruntime.jsx.call(void 0, "div",{className:"absolute left-3 flex h-6 w-6 items-end justify-center overflow-hidden rounded-full",style:{backgroundColor:"var(--widget-secondary)"},children:e&&!r?_jsxruntime.jsx.call(void 0, "img",{className:"h-full w-full rounded-full object-cover",src:(0,Mt.makeGradient)(e),alt:"Recipient avatar"}):_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.S,{className:"h-5 w-5",style:{color:r?"var(--widget-destructive)":"var(--widget-muted-foreground)"}})}),_jsxruntime.jsx.call(void 0, "div",{className:"absolute left-12 top-1.5 -translate-y-1 text-xs font-medium opacity-60",style:{color:r?"var(--widget-destructive)":"var(--widget-muted-foreground)"},"aria-hidden":"true",children:"To:"}),_jsxruntime.jsx.call(void 0, "input",{id:"recipient-address",className:"mono block h-10 w-full items-center pl-12 pt-4 pr-8 text-xs",style:{backgroundColor:r?"color-mix(in srgb, var(--widget-destructive) 10%, transparent)":"transparent",color:r?"var(--widget-destructive)":"var(--widget-foreground)",outline:"none",opacity:r?.9:1},placeholder:r?h:"Enter recipient address...",value:s,onChange:p,spellCheck:!1,"aria-invalid":r,"aria-describedby":r?"recipient-error":void 0}),r&&_jsxruntime.jsx.call(void 0, "span",{id:"recipient-error",className:"sr-only",children:h}),e&&!r&&_jsxruntime.jsxs.call(void 0, "button",{type:"button",className:"absolute right-2 top-1/2 -translate-y-1/2 cursor-pointer flex items-center justify-center h-4 w-4 rounded-full transition-colors hover:[color:var(--widget-destructive)]",style:{color:"var(--widget-muted-foreground)"},onClick:o,"aria-label":"Clear recipient",children:[_jsxruntime.jsx.call(void 0, "svg",{className:"h-2.5 w-2.5",viewBox:"0 -0.5 21 21",fill:"none",children:_jsxruntime.jsx.call(void 0, "g",{fill:"currentColor",fillRule:"evenodd",children:_jsxruntime.jsx.call(void 0, "polygon",{points:"375.0183 90 384 98.554 382.48065 100 373.5 91.446 364.5183 100 363 98.554 371.98065 90 363 81.446 364.5183 80 373.5 88.554 382.48065 80 384 81.446",transform:"translate(-363 -80)"})})}),_jsxruntime.jsx.call(void 0, "span",{className:"sr-only",children:"Clear recipient"})]})]})})},Ps= exports.j =Fr;var qr=["SUCCEEDED","FAILED","COMPLETED","CANCELLED"];async function Dt(e,t,s={}){let{onStatusChange:c,onComplete:l,onError:r,interval:a=4e3,timeout:h=3e5,txHash:y,signal:p}=s,o=null,n=Date.now(),b=0,w=8,d=null,f=y?`?txHash=${y}`:"";return new Promise((g,i)=>{let m=async()=>{try{if(_optionalChain([p, 'optionalAccess', _46 => _46.aborted])){d&&clearTimeout(d),i(new DOMException("Polling aborted","AbortError"));return}if(Date.now()-n>h){d&&clearTimeout(d);let P=new Error("Order status polling timed out");_optionalChain([r, 'optionalCall', _47 => _47(P)]),i(P);return}let v=await fetch(`${t}/status/${e}${f}`,{headers:_chunkSE6JOLEMcjs.m.call(void 0, ),signal:p});if(v.status===404){d=setTimeout(m,a);return}if(!v.ok)throw new Error(`Failed to fetch order status: ${await v.text()}`);let u=await v.json();if(!u||typeof u!="object"||!u.status)throw new Error(`Invalid status response format: ${JSON.stringify(u)}`);b=0;let T=u.status.toUpperCase();if(T!==o&&(o=T,_optionalChain([c, 'optionalCall', _48 => _48(u)])),qr.includes(T)){d&&clearTimeout(d),_optionalChain([l, 'optionalCall', _49 => _49(u)]),g(u);return}d=setTimeout(m,a)}catch(v){if(v instanceof Error&&v.name==="AbortError"){d&&clearTimeout(d),i(v);return}if(++b>=w){d&&clearTimeout(d);let u=v instanceof Error?v:new Error(String(v));_optionalChain([r, 'optionalCall', _50 => _50(u)]),i(u);return}d=setTimeout(m,a)}};m()})}function Wt(e){let t=e.toUpperCase();return t==="SUCCEEDED"||t==="COMPLETED"?"completed":t==="FAILED"?"failed":t==="CANCELLED"?"cancelled":t==="PROCESSING"?"received":"pending"}var Lt=e=>{let t=_react.useRef.call(void 0, new Map),s=_react.useRef.call(void 0, new Map),c=_react.useRef.call(void 0, new Map),l=_react.useRef.call(void 0, 0),r=_react.useCallback.call(void 0, ()=>++l.current,[]),{address:a}=_chunk34N36GUDcjs.a.call(void 0, ),h=Ee(),y=_react.useCallback.call(void 0, (n,b)=>{if(t.current.get(n))return;b&&s.current.set(n,b),t.current.set(n,!0);let w=l.current,d=new AbortController;c.current.set(n,d);let f=_optionalChain([b, 'optionalAccess', _51 => _51.baseToken, 'optionalAccess', _52 => _52.chainId])===1;Dt(n,_chunkSE6JOLEMcjs.k.call(void 0, ),{interval:f?1e3:500,timeout:3e5,signal:d.signal,onStatusChange:g=>{if(!_optionalChain([g, 'optionalAccess', _53 => _53.status]))return;let i=Wt(g.status);if(_optionalChain([e, 'optionalCall', _54 => _54(n,i)]),i==="completed"&&a){let m=s.current.get(n);if(m&&(m.baseToken||m.quoteToken)){let v=[];m.baseToken&&v.push({asset:m.baseToken,userAddress:a}),m.quoteToken&&v.push({asset:m.quoteToken,userAddress:a}),h({type:"swap",tokens:v})}}["completed","failed","cancelled"].includes(i)&&(t.current.delete(n),s.current.delete(n)),w!==l.current&&(t.current.delete(n),s.current.delete(n))},onComplete:g=>{_optionalChain([g, 'optionalAccess', _55 => _55.status])&&_optionalChain([e, 'optionalCall', _56 => _56(n,Wt(g.status))]),t.current.delete(n),s.current.delete(n)},onError:()=>{t.current.delete(n),s.current.delete(n)}}).catch(g=>{g instanceof Error&&g.name==="AbortError"||(t.current.delete(n),s.current.delete(n),c.current.delete(n))})},[a,h,e]),p=_react.useCallback.call(void 0, n=>{let b=c.current.get(n);b&&(b.abort(),c.current.delete(n)),r(),t.current.delete(n),s.current.delete(n)},[r]),o=_react.useCallback.call(void 0, ()=>{for(let n of c.current.values())n.abort();c.current.clear(),r(),t.current.clear(),s.current.clear()},[r]);return _react.useEffect.call(void 0, ()=>()=>o(),[o]),{startPolling:y,stopPolling:p,stopAllPolling:o,isPolling:n=>t.current.has(n)}};var Gr=_react.createContext.call(void 0, {registerTransaction:()=>{},enabled:!1}),Bt= exports.m =()=>_react.useContext.call(void 0, Gr);var _actions = require('viem/actions');function Vt(e){return e instanceof Error?e.name==="UserRejectedRequestError"||e.message.includes("User rejected")||e.message.includes("rejected")||e.message.includes("denied")||e.message.includes("cancelled")||e.message.includes("canceled"):!1}async function _t(e){if(_optionalChain([e, 'access', _57 => _57.chain, 'optionalAccess', _58 => _58.id]))return e.chain.id;let t=_optionalChain([e, 'access', _59 => _59.getChainId, 'optionalCall', _60 => _60()]);return t!=null?await t:null}var Hr=async(e,t)=>{try{if(await _t(e)===t)return!0;if(e.request)await e.request({method:"wallet_switchEthereumChain",params:[{chainId:`0x${t.toString(16)}`}]});else if(e.switchChain)await e.switchChain({id:t});else if(e.send)await e.send("wallet_switchEthereumChain",[{chainId:`0x${t.toString(16)}`}]);else throw new Error("Wallet doesn't support chain switching");return await _t(e)===t}catch(s){throw Vt(s)?new Error("User rejected the chain switch request"):new Error(`Please switch your wallet to the required network (Chain ID: ${t})`)}},Ft= exports.o =async e=>{let{quote:t,signatureStep:s,userAddress:c,walletClient:l}=e;if(!l)throw new Error("Wallet client not available");if(s.type!=="SIGNATURE"||!_optionalChain([s, 'access', _61 => _61.signature, 'optionalAccess', _62 => _62.typedData]))throw new Error("Invalid signature step");try{let r=s.signature.typedData,a={...r.message};for(let o of["inputAmount","outputAmount","startTime","endTime"])a[o]!=null&&(a[o]=BigInt(a[o]));let h=r.domain;if(h.chainId!=null){let o=Number(h.chainId);await Hr(l,o)}let y=await _actions.signTypedData.call(void 0, l,{account:c,domain:h,types:r.types,primaryType:r.primaryType,message:a}),p=await fetch(`${_chunkSE6JOLEMcjs.k.call(void 0, )}/submit-signature`,{method:"POST",headers:_chunkSE6JOLEMcjs.m.call(void 0, ),body:JSON.stringify({quoteId:t.id,signatures:[y]})});if(!p.ok){let o=await p.json().catch(()=>({}));throw new Error(_optionalChain([o, 'optionalAccess', _63 => _63.message])||`Submit failed: ${p.status}`)}return{quoteId:t.id,signature:y}}catch(r){throw Vt(r)?new Error("User rejected the signing request"):r instanceof Error&&r.message.includes("chain")?new Error("Chain switching failed. Please manually switch to the correct network."):r}};var qt="vt_submitted_quotes";var lt=()=>{try{let e=localStorage.getItem(qt);return e?JSON.parse(e):[]}catch (e3){return[]}},Qt=e=>{try{localStorage.setItem(qt,JSON.stringify(e))}catch (e4){}},Xr= exports.p =e=>{let t=Date.now(),s=typeof e=="string"?new Date(e).getTime():e>9999999999?e:e*1e3;return t<s+3e4},Yr=e=>lt().some(t=>t.quoteId===e),jt= exports.q =(e,t)=>Yr(e)?{canSubmit:!1,reason:"Order already submitted"}:Xr(t)?{canSubmit:!0}:{canSubmit:!1,reason:"Quote has expired"},zt= exports.r =(e,t)=>{let s=typeof t=="string"?new Date(t).getTime():t,c=lt();c.push({quoteId:e,submittedAt:Date.now(),createdAt:s}),Qt(c)},Gt= exports.s =()=>{let e=lt(),t=Date.now(),s=300*1e3,c=e.filter(l=>t-l.submittedAt<s);c.length!==e.length&&Qt(c)};var _core = require('@wagmi/core');var _abis = require('abitype/abis');var _wagmi = require('wagmi');function Kt(){let e=_wagmi.useConfig.call(void 0, );return _reactquery.useMutation.call(void 0, {mutationFn:async({chainId:t,accountAddress:s,amountRaw:c,writeContractAsync:l})=>{let r=_chunkSE6JOLEMcjs.c.call(void 0, t);if(!r)throw new Error(`No wrapping contract for chain ${t}`);let a=r.wrappedAsset.address,h=await l({abi:_abis.wethAbi,functionName:"withdraw",address:a,account:s,args:[c],chainId:t});if((await _core.waitForTransactionReceipt.call(void 0, e,{hash:h,chainId:t,confirmations:1,pollingInterval:4e3})).status!=="success")throw new Error("Unwrap transaction did not get successful receipt");return{success:!0,hash:h}}})}function Ht(){let e=_wagmi.useConfig.call(void 0, );return _reactquery.useMutation.call(void 0, {mutationFn:async({chainId:t,accountAddress:s,amountRaw:c,writeContractAsync:l})=>{let r=_chunkSE6JOLEMcjs.c.call(void 0, t);if(!r)throw new Error(`No wrapping contract for chain ${t}`);let a=r.wrappedAsset.address,h=await l({abi:_abis.wethAbi,functionName:"deposit",address:a,account:s,value:c,chainId:t});if((await _core.waitForTransactionReceipt.call(void 0, e,{hash:h,chainId:t,confirmations:1,pollingInterval:4e3})).status!=="success")throw new Error("Wrap transaction did not get successful receipt");return{success:!0,hash:h}}})}function Yt(){let{registerTransaction:e,enabled:t}=Bt(),s=_react.useRef.call(void 0, new Set),c=_react.useCallback.call(void 0, (r,a)=>{!t||s.current.has(r)||(s.current.add(r),e(r,a))},[t,e]),l=_react.useCallback.call(void 0, (r,a)=>{!t||s.current.has(r)||(s.current.add(r),e(r,a))},[t,e]);return{trackOrderTransaction:c,trackNativeTransaction:l,txTrackingEnabled:t}}var pn=15e3,Ge="chain",mn=({needsChainSwitch:e,requiredChain:t,reviewState:s,goToNextStep:c,cancel:l})=>{let r=_chunkSE6JOLEMcjs.r.call(void 0, Ge,s),[a,h]=_react.useState.call(void 0, "pending"),y=_react.useRef.call(void 0, !1),p=_react.useRef.call(void 0, !1),o=_react.useRef.call(void 0, null),n=_wagmi.useChainId.call(void 0, ),{switchChainAsync:b}=_wagmi.useSwitchChain.call(void 0, ),{status:w,isReconnecting:d}=_wagmi.useAccount.call(void 0, ),f=_react.useCallback.call(void 0, ()=>{o.current&&(clearTimeout(o.current),o.current=null)},[]),g=_react.useCallback.call(void 0, async()=>{if(!(y.current||p.current||w!=="connected"||d)){y.current=!0,p.current=!0,h("pending"),o.current=setTimeout(()=>{y.current&&(h("error"),y.current=!1)},pn);try{await b({chainId:t.chainId}),f(),h("success"),c(Ge,s)}catch (e5){f(),h("error")}finally{y.current=!1}}},[b,w,d,t.chainId,c,s,f]);_react.useEffect.call(void 0, ()=>{y.current||p.current||s===Ge&&a==="pending"&&w==="connected"&&!d&&(e&&n!==t.chainId?g():(h("success"),c(Ge,s)))},[s,a,e,n,t.chainId,w,d,g,c]),_react.useEffect.call(void 0, ()=>()=>f(),[f]);let i=()=>{a==="error"&&(p.current=!1,h("pending"))},m=!r&&a==="error",v=!r&&(a==="pending"||a==="error"),u=m?"var(--widget-status-failed)":"var(--widget-status-pending)";return _jsxruntime.jsxs.call(void 0, "div",{className:"flex w-full flex-row justify-between space-x-3",children:[_jsxruntime.jsx.call(void 0, "button",{type:"button",className:`inline-flex h-12 w-full items-center justify-center text-sm font-medium transition duration-150 ${m?"cursor-pointer":"cursor-not-allowed"}`,style:{backgroundColor:`color-mix(in srgb, ${u} 12%, transparent)`,border:`1px solid color-mix(in srgb, ${u} 20%, transparent)`,color:u,borderRadius:"var(--widget-radius)"},onClick:m?i:void 0,children:_jsxruntime.jsxs.call(void 0, "div",{className:"flex h-10 w-full flex-row items-center space-x-3 px-4",children:[_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.M,{chain:t.chainId,size:"xs"}),_jsxruntime.jsx.call(void 0, "p",{className:"whitespace-nowrap",children:m?"Retry Switch":`Switch to ${t.name}`}),_jsxruntime.jsx.call(void 0, "div",{className:"flex flex-1 border-t",style:{borderColor:"var(--widget-border)"}}),_jsxruntime.jsxs.call(void 0, "div",{className:"flex h-6 w-3 items-center justify-center rounded-full",children:[!r&&a==="pending"&&_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.U,{size:"5"}),(r||a==="success")&&_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.O,{className:"h-8 w-8"}),m&&_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.R,{className:"h-[12px] w-[12px]"})]})]})}),v&&_jsxruntime.jsx.call(void 0, "button",{type:"button",className:"inline-flex h-12 items-center justify-center px-8 text-sm font-medium transition duration-150 cursor-pointer",style:{backgroundColor:"color-mix(in srgb, var(--widget-status-failed) 12%, transparent)",border:"1px solid color-mix(in srgb, var(--widget-status-failed) 20%, transparent)",color:"var(--widget-status-failed)",borderRadius:"var(--widget-radius)"},onClick:l,children:"Cancel"})]})},er=mn;var fn=({startTime:e,onExpired:t})=>{let[s,c]=_react.useState.call(void 0, 30),[l,r]=_react.useState.call(void 0, !1),a=_react.useRef.call(void 0, !1),h=_react.useRef.call(void 0, t);h.current=t,_react.useEffect.call(void 0, ()=>{a.current=!1},[e]),_react.useEffect.call(void 0, ()=>{let p=()=>{let n=Date.now(),w=(e>9999999999?e:e*1e3)+30*1e3,d=Math.max(0,w-n),f=Math.floor(d/1e3);if(f<=0){c(0),a.current||(a.current=!0,r(!0),h.current());return}c(f),r(!1)};if(l)return;p();let o=setInterval(p,1e3);return()=>clearInterval(o)},[e,l]);let y=p=>{let o=Math.floor(p/60),n=p%60;return`${o.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`};return l?null:_jsxruntime.jsx.call(void 0, "span",{className:"text-xs font-mono",children:y(s)})},sr=fn;function Sn(e){return e.name==="UserRejectedRequestError"||e.message.includes("User rejected")||e.message.includes("rejected")||e.message.includes("denied")||e.message.includes("cancelled")||e.message.includes("canceled")}var be="signingOrder";async function Tn(e,t,s,c,l){let r=_optionalChain([e, 'access', _64 => _64.transaction, 'optionalAccess', _65 => _65.encoded]),a=_nullishCoalesce(_optionalChain([r, 'optionalAccess', _66 => _66.to]), () => (e.to)),h=_nullishCoalesce(_optionalChain([r, 'optionalAccess', _67 => _67.data]), () => (e.data)),y=_nullishCoalesce(_optionalChain([r, 'optionalAccess', _68 => _68.value]), () => (e.value));if(!a)throw new Error('Transaction step missing "to" address');let p=_optionalChain([r, 'optionalAccess', _69 => _69.chainId]),o=e.chainKey||l,n=p||(o?_chunkSE6JOLEMcjs.z.call(void 0, o):void 0);if(!n)throw new Error(`Unknown chain: ${o}`);let b=_chunkSE6JOLEMcjs.h.call(void 0, )[n],w=await s({account:t,chain:b,to:a,data:h||"0x",value:BigInt(y||"0")});return await _core.waitForTransactionReceipt.call(void 0, c,{hash:w,chainId:n}),w}var Rn=({base:e,baseAmount:t,quote:s,quoteAmount:c,userAddress:l,reviewState:r,goToNextStep:a,cancel:h,isWrappingPair:y,isUnwrappingPair:p,restartSigningFlow:o,onSwapInitiated:n,onOrderSubmitted:b,onSwapComplete:w,startPolling:d,trackNativeTransaction:f})=>{let g=_chunkSE6JOLEMcjs.r.call(void 0, be,r),[i,m]=_react.useState.call(void 0, "idle"),v=_react.useRef.call(void 0, !1),u=_react.useRef.call(void 0, null),T=_wagmi.useConfig.call(void 0, ),{isReconnecting:P}=_wagmi.useAccount.call(void 0, ),{rfqQuote:C,stop:$,refresh:L}=Ve(),{data:N}=_wagmi.useWalletClient.call(void 0, {chainId:e.chainId}),{switchChain:E}=_wagmi.useSwitchChain.call(void 0, ),{sendTransactionAsync:I}=_wagmi.useSendTransaction.call(void 0, ),U=_nullishCoalesce(_optionalChain([C, 'optionalAccess', _70 => _70._receivedAt]), () => (0)),B=_react.useCallback.call(void 0, ()=>U?Date.now()>=U+30*1e3:!1,[U]),oe=_react.useCallback.call(void 0, async()=>{if(v.current||!["idle","error"].includes(i))return;if(!_optionalChain([C, 'optionalAccess', _71 => _71.id])||!_optionalChain([C, 'optionalAccess', _72 => _72._receivedAt])){m("error");return}if(!jt(C.id,C._receivedAt).canSubmit){m("stale");return}v.current=!0;try{if(!N)throw new Error("Wallet client not available");Gt();let S=_nullishCoalesce(C.userSteps, () => ([])),O;for(let A of S)if(A.type==="TRANSACTION"){m("submitting");let q=A.chainKey||C.srcChainKey,Z=q?_chunkSE6JOLEMcjs.z.call(void 0, q):void 0;Z&&_optionalChain([N, 'access', _73 => _73.chain, 'optionalAccess', _74 => _74.id])!==Z&&(await E({chainId:Z}),await new Promise(Le=>setTimeout(Le,800))),O=await Tn(A,l,I,T,C.srcChainKey),f(O,A.description||`Tx on ${q}`)}else A.type==="SIGNATURE"&&(m("signing"),await Ft({quote:C,signatureStep:A,userAddress:l,walletClient:N}));zt(C.id,C._receivedAt),_optionalChain([b, 'optionalCall', _75 => _75(C.id)]),d(C.id,{baseToken:e,quoteToken:s}),_optionalChain([n, 'optionalCall', _76 => _76()]),$(),m("success"),a(be,r),_optionalChain([w, 'optionalCall', _77 => _77(C.id)])}catch(S){S instanceof Error&&Sn(S)?(u.current=null,m("idle")):m("error")}finally{v.current=!1}},[i,C,N,e,s,l,$,d,a,r,w,E,I,n,b,f,T]);_react.useEffect.call(void 0, ()=>{if(r===be&&$(),g&&i!=="success"){m("success"),a(be,r);return}if(i==="success"){a(be,r);return}if(r===be&&i==="idle"&&!_optionalChain([C, 'optionalAccess', _78 => _78.id])){m("refreshingQuote"),L();return}if(r===be&&i==="idle"&&N&&!v.current&&!P){let x=_optionalChain([C, 'optionalAccess', _79 => _79.id])||null;x&&u.current!==x&&(u.current=x,oe())}},[g,r,i,N,P,oe,a,_optionalChain([C, 'optionalAccess', _80 => _80.id]),L,$]),_react.useEffect.call(void 0, ()=>{i==="refreshingQuote"&&_optionalChain([C, 'optionalAccess', _81 => _81.id])&&m("idle")},[i,_optionalChain([C, 'optionalAccess', _82 => _82.id])]),_react.useEffect.call(void 0, ()=>{r!==be&&(u.current=null)},[r]),_react.useEffect.call(void 0, ()=>{let x=setInterval(()=>{B()&&!v.current&&i!=="submitting"&&i!=="success"&&m("stale")},1e3);return()=>clearInterval(x)},[B,i]);let H=()=>{i==="error"&&!v.current&&(u.current=null,m("idle"))},W=_react.useCallback.call(void 0, ()=>{u.current=null,m("refreshingQuote"),L()},[L]),R=_react.useCallback.call(void 0, ()=>{o?o(!0):h()},[o,h]),V=()=>i==="error"?"Retry swap":i==="signing"?"Sign Swap Order":i==="submitting"?"Submitting...":i==="refreshingQuote"?"Refreshing Quote...":i==="stale"?"Quote Stale":"Sign & Submit",F=!g&&(i==="error"||i==="stale"),X=F?"var(--widget-status-failed)":"var(--widget-status-pending)";return _jsxruntime.jsxs.call(void 0, "div",{className:"flex w-full flex-row justify-between space-x-3",children:[_jsxruntime.jsx.call(void 0, "button",{type:"button",className:`inline-flex h-12 w-full items-center justify-center text-sm font-medium transition duration-150 ${F?"cursor-pointer":"cursor-not-allowed"}`,style:{backgroundColor:`color-mix(in srgb, ${X} 12%, transparent)`,border:`1px solid color-mix(in srgb, ${X} 20%, transparent)`,color:X,borderRadius:"var(--widget-radius)"},onClick:!g&&i==="error"?H:i==="stale"?R:void 0,children:_jsxruntime.jsxs.call(void 0, "div",{className:"flex h-10 w-full flex-row items-center space-x-3 px-4",children:[_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.N,{asset:e,size:"xs",noChain:!0}),_jsxruntime.jsx.call(void 0, "p",{className:"whitespace-nowrap",children:V()}),_jsxruntime.jsx.call(void 0, "div",{className:"flex flex-1 border-t",style:{borderColor:"var(--widget-border)"}}),U>0&&i!=="success"&&i!=="error"&&i!=="stale"&&_jsxruntime.jsx.call(void 0, sr,{startTime:U,onExpired:()=>m("stale")}),_jsxruntime.jsxs.call(void 0, "div",{className:"flex h-6 w-3 items-center justify-center rounded-full",children:[!g&&(i==="idle"||i==="signing"||i==="submitting"||i==="refreshingQuote")&&_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.U,{size:"5"}),(g||i==="success")&&_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.O,{className:"h-8 w-8"}),!g&&(i==="error"||i==="stale")&&_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.R,{className:"h-[12px] w-[12px]"})]})]})}),!g&&i==="error"&&_jsxruntime.jsx.call(void 0, "button",{type:"button",className:"inline-flex h-12 items-center justify-center px-8 text-sm font-medium transition duration-150 cursor-pointer",style:{backgroundColor:"color-mix(in srgb, var(--widget-status-failed) 12%, transparent)",border:"1px solid color-mix(in srgb, var(--widget-status-failed) 20%, transparent)",color:"var(--widget-status-failed)",borderRadius:"var(--widget-radius)"},onClick:h,children:"Cancel"})]})},ir=Rn;var kn="trackingTx",ar={pending:{icon:_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.U,{size:"5"}),buttonText:"Trade Pending",showNewSwap:!1,statusVar:"var(--widget-status-pending)",clickable:!1},received:{icon:_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.U,{size:"5"}),buttonText:"Trade Received",showNewSwap:!1,statusVar:"var(--widget-status-received)",clickable:!1},completed:{icon:_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.O,{}),buttonText:"Continue Swapping",showNewSwap:!0,statusVar:"var(--widget-status-completed)",clickable:!0},failed:{icon:_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.X,{}),buttonText:"Retry Swap",showNewSwap:!0,statusVar:"var(--widget-status-failed)",clickable:!0},cancelled:{icon:_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.X,{}),buttonText:"Continue Swapping",showNewSwap:!0,statusVar:"var(--widget-status-failed)",clickable:!0}},Nn=({orderHash:e,base:t,quote:s,baseAmount:c,quoteAmount:l,reviewState:r,onNewSwap:a,onRetry:h,status:y})=>{let p=_chunkSE6JOLEMcjs.r.call(void 0, kn,r),o=ar[y]||ar.pending;_react.useEffect.call(void 0, ()=>{if(y==="completed"){let w=setTimeout(a,5e3);return()=>clearTimeout(w)}},[y,a]);let n=()=>{y==="failed"?h():o.showNewSwap&&a()},b=o.statusVar;return _jsxruntime.jsx.call(void 0, "div",{className:"flex flex-row justify-between space-x-3 w-full",children:_jsxruntime.jsx.call(void 0, "button",{type:"button",className:`inline-flex h-12 w-full items-center justify-center text-sm font-medium transition duration-150 ${o.clickable?"cursor-pointer":"cursor-not-allowed"}`,style:{backgroundColor:`color-mix(in srgb, ${b} 12%, transparent)`,border:`1px solid color-mix(in srgb, ${b} 20%, transparent)`,color:b,borderRadius:"var(--widget-radius)"},onClick:o.showNewSwap?n:void 0,children:_jsxruntime.jsxs.call(void 0, "div",{className:"flex h-10 w-full flex-row items-center space-x-3 px-4",children:[_jsxruntime.jsx.call(void 0, "div",{className:"flex h-6 w-6 items-center justify-center rounded-full",children:o.icon}),_jsxruntime.jsx.call(void 0, "p",{className:"whitespace-nowrap",children:o.buttonText}),_jsxruntime.jsx.call(void 0, "div",{className:"flex flex-1 border-t",style:{borderColor:"var(--widget-border)"}}),o.showNewSwap&&_jsxruntime.jsx.call(void 0, "div",{className:"flex h-6 w-6 items-center justify-center",children:_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.W,{})})]})})})},cr=Nn;var Un=15e3,Xe="unwrapping",Mn=({needsToUnwrap:e,amount:t,chainId:s,token:c,reviewState:l,setReviewState:r,goToNextStep:a,cancel:h,delayedClose:y})=>{let p=_chunkSE6JOLEMcjs.r.call(void 0, Xe,l),[o,n]=_react.useState.call(void 0, "idle"),b=Kt(),{writeContractAsync:w}=_wagmi.useWriteContract.call(void 0, ),{address:d}=_chunk34N36GUDcjs.a.call(void 0, ),f=Ee(),g=_react.useRef.call(void 0, !1),i=_react.useRef.call(void 0, !1),m=_react.useRef.call(void 0, null),{status:v}=_wagmi.useAccount.call(void 0, ),u=_react.useCallback.call(void 0, ()=>{m.current&&(clearTimeout(m.current),m.current=null)},[]),T=_react.useCallback.call(void 0, async()=>{if(!(g.current||i.current||!d||v!=="connected")){g.current=!0,i.current=!0,n("pending"),m.current=setTimeout(()=>{g.current&&(n("error"),g.current=!1)},Un);try{let N=_chunkSE6JOLEMcjs.c.call(void 0, s);if(!N)throw new Error(`No config for chain ${s}`);let E=_nullishCoalesce(N.wrappedAsset.decimals, () => (N.nativeAsset.decimals)),I=_viem.parseUnits.call(void 0, t.toString(),E);await b.mutateAsync({chainId:s,accountAddress:d,amountRaw:I,writeContractAsync:w});let U={symbol:N.nativeAsset.symbol,name:N.nativeAsset.name,address:_chunkSE6JOLEMcjs.a,decimals:N.nativeAsset.decimals,chainId:s},B={symbol:N.wrappedAsset.symbol,name:N.wrappedAsset.name,address:N.wrappedAsset.address,decimals:N.wrappedAsset.decimals,chainId:s};f({type:"unwrap",tokens:[{asset:U,userAddress:d},{asset:B,userAddress:d}]}),u(),n("success"),a(Xe,l),await y()}catch (e6){u(),n("error")}finally{g.current=!1}}},[d,v,s,t,b,w,f,a,l,y,u]);_react.useEffect.call(void 0, ()=>{g.current||i.current||l===Xe&&o==="idle"&&v==="connected"&&(e?T():(n("success"),a(Xe,l)))},[l,o,e,v,T,a]),_react.useEffect.call(void 0, ()=>()=>u(),[u]);let P=()=>{o==="error"&&(i.current=!1,n("idle"))},C=!p&&o==="error",$=!p&&(o==="pending"||o==="idle"||o==="error"),L=C?"var(--widget-status-failed)":"var(--widget-status-pending)";return _jsxruntime.jsxs.call(void 0, "div",{className:"flex w-full flex-row justify-between space-x-3",children:[_jsxruntime.jsx.call(void 0, "button",{type:"button",className:`inline-flex h-12 w-full items-center justify-center text-sm font-medium transition duration-150 ${C?"cursor-pointer":"cursor-not-allowed"}`,style:{backgroundColor:`color-mix(in srgb, ${L} 12%, transparent)`,border:`1px solid color-mix(in srgb, ${L} 20%, transparent)`,color:L,borderRadius:"var(--widget-radius)"},onClick:C?P:void 0,children:_jsxruntime.jsxs.call(void 0, "div",{className:"flex h-10 w-full flex-row items-center space-x-3 px-4",children:[_jsxruntime.jsx.call(void 0, "p",{className:"whitespace-nowrap",children:C?"Retry Unwrap":c?`Unwrap ${c.symbol}`:"Unwrap Native Token"}),_jsxruntime.jsx.call(void 0, "div",{className:"flex flex-1 border-t",style:{borderColor:"var(--widget-border)"}}),_jsxruntime.jsxs.call(void 0, "div",{className:"flex h-6 w-3 items-center justify-center rounded-full",children:[!p&&(o==="pending"||o==="idle")&&_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.U,{size:"5"}),(p||o==="success")&&_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.O,{className:"h-8 w-8"}),C&&_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.R,{className:"h-[12px] w-[12px]"})]})]})}),$&&_jsxruntime.jsx.call(void 0, "button",{type:"button",className:"inline-flex h-12 items-center justify-center px-8 text-sm font-medium transition duration-150 cursor-pointer",style:{backgroundColor:"color-mix(in srgb, var(--widget-status-failed) 12%, transparent)",border:"1px solid color-mix(in srgb, var(--widget-status-failed) 20%, transparent)",color:"var(--widget-status-failed)",borderRadius:"var(--widget-radius)"},onClick:h,children:"Cancel"})]})},dr=Mn;var _n=15e3,Ye="wrapping",Vn=({needsToWrap:e,amount:t,chainId:s,token:c,reviewState:l,setReviewState:r,goToNextStep:a,cancel:h,delayedClose:y,isWrappingPair:p})=>{let o=_chunkSE6JOLEMcjs.r.call(void 0, Ye,l),[n,b]=_react.useState.call(void 0, "idle"),w=Ht(),{writeContractAsync:d}=_wagmi.useWriteContract.call(void 0, ),{address:f}=_chunk34N36GUDcjs.a.call(void 0, ),g=Ee(),i=_react.useRef.call(void 0, !1),m=_react.useRef.call(void 0, !1),v=_react.useRef.call(void 0, null),{status:u}=_wagmi.useAccount.call(void 0, ),T=_react.useCallback.call(void 0, ()=>{v.current&&(clearTimeout(v.current),v.current=null)},[]),P=_react.useCallback.call(void 0, async()=>{if(!(i.current||m.current||!f||u!=="connected")){i.current=!0,m.current=!0,b("pending"),v.current=setTimeout(()=>{i.current&&(b("error"),i.current=!1)},_n);try{let E=_chunkSE6JOLEMcjs.c.call(void 0, s);if(!E)throw new Error(`No config for chain ${s}`);let I=_viem.parseUnits.call(void 0, t.toString(),E.nativeAsset.decimals);await w.mutateAsync({chainId:s,accountAddress:f,amountRaw:I,writeContractAsync:d});let U={symbol:E.nativeAsset.symbol,name:E.nativeAsset.name,address:_chunkSE6JOLEMcjs.a,decimals:E.nativeAsset.decimals,chainId:s},B={symbol:E.wrappedAsset.symbol,name:E.wrappedAsset.name,address:E.wrappedAsset.address,decimals:E.wrappedAsset.decimals,chainId:s};g({type:"wrap",tokens:[{asset:U,userAddress:f},{asset:B,userAddress:f}]}),T(),b("success"),a(Ye,l),p&&await y()}catch (e7){T(),b("error")}finally{i.current=!1}}},[f,u,s,t,w,d,g,a,l,y,p,T]);_react.useEffect.call(void 0, ()=>{i.current||m.current||l===Ye&&n==="idle"&&u==="connected"&&(e?P():(b("success"),a(Ye,l)))},[l,n,e,u,P,a]),_react.useEffect.call(void 0, ()=>()=>T(),[T]);let C=()=>{n==="error"&&(m.current=!1,b("idle"))},$=!o&&n==="error",L=!o&&(n==="pending"||n==="idle"||n==="error"),N=$?"var(--widget-status-failed)":"var(--widget-status-pending)";return _jsxruntime.jsxs.call(void 0, "div",{className:"flex w-full flex-row justify-between space-x-3",children:[_jsxruntime.jsx.call(void 0, "button",{type:"button",className:`inline-flex h-12 w-full items-center justify-center text-sm font-medium transition duration-150 ${$?"cursor-pointer":"cursor-not-allowed"}`,style:{backgroundColor:`color-mix(in srgb, ${N} 12%, transparent)`,border:`1px solid color-mix(in srgb, ${N} 20%, transparent)`,color:N,borderRadius:"var(--widget-radius)"},onClick:$?C:void 0,children:_jsxruntime.jsxs.call(void 0, "div",{className:"flex h-10 w-full flex-row items-center space-x-3 px-4",children:[_jsxruntime.jsx.call(void 0, "p",{className:"whitespace-nowrap",children:$?"Retry Wrap":c?`Wrap ${c.symbol}`:"Wrap Native Token"}),_jsxruntime.jsx.call(void 0, "div",{className:"flex flex-1 border-t",style:{borderColor:"var(--widget-border)"}}),_jsxruntime.jsxs.call(void 0, "div",{className:"flex h-6 w-3 items-center justify-center rounded-full",children:[!o&&(n==="pending"||n==="idle")&&_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.U,{size:"5"}),(o||n==="success")&&_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.O,{className:"h-8 w-8"}),$&&_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.R,{className:"h-[12px] w-[12px]"})]})]})}),L&&_jsxruntime.jsx.call(void 0, "button",{type:"button",className:"inline-flex h-12 items-center justify-center px-8 text-sm font-medium transition duration-150 cursor-pointer",style:{backgroundColor:"color-mix(in srgb, var(--widget-status-failed) 12%, transparent)",border:"1px solid color-mix(in srgb, var(--widget-status-failed) 20%, transparent)",color:"var(--widget-status-failed)",borderRadius:"var(--widget-radius)"},onClick:h,children:"Cancel"})]})},fr=Vn;var Si=({base:e,baseAmount:t,quote:s,quoteAmount:c,userAddress:l,isWrappingPair:r,isUnwrappingPair:a,isBaseGasToken:h,isQuoteGasToken:y,reviewActionProps:p,reviewState:o,setReviewState:n,trackedOrderHash:b,setTrackedOrderHash:w,txStatus:d,onSwapComplete:f,onSwapInitiated:g,onOrderSubmitted:i,onStaleQuoteRestart:m,setExitHandler:v,setRetryHandler:u})=>{let{rfqQuote:T,status:P,liquidityError:C,routingError:$,sizeCapError:L,stop:N,clear:E}=Ve(),{clearForm:I}=_chunkBJYKILHScjs.f.call(void 0, ),U=_wagmi.useChainId.call(void 0, ),{swapButtonVariant:B,widgetType:oe}=_chunkTCAVGM6Ycjs.b.call(void 0, ),H=oe==="compact",{trackOrderTransaction:W,trackNativeTransaction:R}=Yt(),{startPolling:V}=Lt((_,fe)=>{_chunkBJYKILHScjs.c.getState().setTxStatus(fe),fe==="completed"&&W(_,`Swap ${e.symbol} \u2192 ${s.symbol}`)}),[F,X]=_react.useState.call(void 0, !1),x=_react.useRef.call(void 0, !1),S=_react.useRef.call(void 0, null),O=r,A=a,q=!r&&!a,Z=U!==_optionalChain([e, 'optionalAccess', _83 => _83.chainId])&&(O||A||q),Le=_chunkSE6JOLEMcjs.c.call(void 0, e.chainId),Be={chainId:e.chainId,name:_nullishCoalesce(_optionalChain([Le, 'optionalAccess', _84 => _84.displayName]), () => (`Chain ${e.chainId}`))},z=_react.useCallback.call(void 0, (_,fe)=>{if(fe!==_)return;if(_==="chain"){if(O){n("wrapping");return}if(A){n("unwrapping");return}n("signingOrder");return}if(_==="signingOrder"){n("trackingTx");return}if(_==="wrapping"){if(!r){n("signingOrder");return}n("wrapSuccess");return}if(_==="unwrapping"){n("wrapSuccess");return}let yt=_chunkSE6JOLEMcjs.s.call(void 0, _);yt&&n(yt)},[n,r,O,A,q]),ie=_react.useCallback.call(void 0, ()=>Z?"chain":O?"wrapping":A?"unwrapping":q?"signingOrder":null,[Z,O,A,q]),ee=_react.useCallback.call(void 0, ()=>{n(null),I()},[I,n]),Ce=_react.useCallback.call(void 0, async()=>{n("wrapSuccess");for(let _=0;_<3;_++)await _chunkSE6JOLEMcjs.t.call(void 0, 700);ee()},[ee,n]),te=_react.useCallback.call(void 0, async()=>{E(),n("cancelled");for(let _=0;_<3;_++)await _chunkSE6JOLEMcjs.t.call(void 0, 500);ee()},[E,ee,n]),me=_react.useCallback.call(void 0, ()=>{b&&(_chunkBJYKILHScjs.c.getState().stopTracking(),n(null),w(null),I())},[b,n,w,I]),$e=_react.useCallback.call(void 0, ()=>{n(null),w(null),x.current=!0,_optionalChain([m, 'optionalCall', _85 => _85()])},[n,w,m]),ae=_react.useCallback.call(void 0, ()=>{p&&n(ie())},[ie,p,n]),Je=_react.useCallback.call(void 0, (_=!1)=>{_?(x.current=!0,n(null),_optionalChain([m, 'optionalCall', _86 => _86()])):(n(null),S.current=setTimeout(()=>{p&&(n(ie()),X(!1))},100))},[n,p,ie,m]);_react.useEffect.call(void 0, ()=>{o!==null&&N()},[o,N]),_react.useEffect.call(void 0, ()=>{o!==null&&F&&X(!1)},[o,F]),_react.useEffect.call(void 0, ()=>{_optionalChain([v, 'optionalCall', _87 => _87(me)])},[v,me]),_react.useEffect.call(void 0, ()=>{_optionalChain([u, 'optionalCall', _88 => _88($e)])},[u,$e]),_react.useEffect.call(void 0, ()=>()=>{S.current&&clearTimeout(S.current)},[]),_react.useEffect.call(void 0, ()=>{x.current&&P==="fresh"&&_optionalChain([T, 'optionalAccess', _89 => _89.id])&&(x.current=!1,n("signingOrder"))},[P,_optionalChain([T, 'optionalAccess', _90 => _90.id]),n]);let Ue=_=>{if(!_)return{backgroundColor:B==="default"?"var(--widget-muted)":"transparent",color:"var(--widget-muted-foreground)",border:B!=="default"?"1px solid var(--widget-border)":"none",borderRadius:"var(--widget-radius)"};switch(B){case"outline":return{backgroundColor:"transparent",color:"var(--widget-primary)",border:"1px solid var(--widget-primary)",borderRadius:"var(--widget-radius)"};case"ghost":return{backgroundColor:"transparent",color:"var(--widget-primary)",border:"none",borderRadius:"var(--widget-radius)"};default:return{backgroundColor:"var(--widget-primary)",color:"var(--widget-primary-foreground)",borderRadius:"var(--widget-radius)"}}},Se=`w-full ${H?"py-2":"py-3"} text-sm font-medium transition-colors cursor-pointer mt-1`;if(o===null&&!r&&!a){if(F)return _jsxruntime.jsx.call(void 0, "button",{className:Se,disabled:!0,style:{...Ue(!1),opacity:.6,cursor:"not-allowed"},children:"Getting fresh quote..."});let _=()=>C?"Insufficient Liquidity":$?"Route Not Available":L?"Size Cap Exceeded":!T&&P==="polling"?"Getting Quote...":T?"Swap":"Enter Amount",fe=!!p;return _jsxruntime.jsx.call(void 0, "button",{onClick:fe?ae:void 0,disabled:!fe,className:`${Se} disabled:opacity-40 disabled:cursor-not-allowed`,style:Ue(fe),children:_()})}return o===null&&a?_jsxruntime.jsx.call(void 0, "button",{onClick:p?ae:void 0,disabled:!p,className:`${Se} disabled:opacity-40 disabled:cursor-not-allowed`,style:Ue(!!p),children:"Unwrap"}):o===null&&r?_jsxruntime.jsx.call(void 0, "button",{onClick:p?ae:void 0,disabled:!p,className:`${Se} disabled:opacity-40 disabled:cursor-not-allowed`,style:Ue(!!p),children:"Wrap"}):o==="success"?_jsxruntime.jsx.call(void 0, "div",{className:"flex flex-col gap-2 w-full",children:_jsxruntime.jsx.call(void 0, "button",{className:`w-full ${H?"py-2":"py-3"} text-sm font-medium cursor-default`,style:{backgroundColor:"color-mix(in srgb, var(--widget-status-completed) 15%, transparent)",color:"var(--widget-status-completed)",border:"1px solid color-mix(in srgb, var(--widget-status-completed) 20%, transparent)",borderRadius:"var(--widget-radius)"},children:"Order Placed"})}):o==="wrapSuccess"?_jsxruntime.jsx.call(void 0, "div",{className:"flex flex-col gap-2 w-full",children:_jsxruntime.jsx.call(void 0, "button",{className:`w-full ${H?"py-2":"py-3"} text-sm font-medium cursor-default`,style:{backgroundColor:"color-mix(in srgb, var(--widget-status-completed) 15%, transparent)",color:"var(--widget-status-completed)",border:"1px solid color-mix(in srgb, var(--widget-status-completed) 20%, transparent)",borderRadius:"var(--widget-radius)"},children:r?"Wrapped Successfully":"Unwrapped Successfully"})}):o==="cancelled"?_jsxruntime.jsx.call(void 0, "div",{className:"flex flex-col gap-2 w-full",children:_jsxruntime.jsx.call(void 0, "button",{onClick:ee,className:`w-full ${H?"py-2":"py-3"} text-sm font-medium cursor-pointer`,style:{backgroundColor:"color-mix(in srgb, var(--widget-status-failed) 15%, transparent)",color:"var(--widget-status-failed)",border:"1px solid color-mix(in srgb, var(--widget-status-failed) 20%, transparent)",borderRadius:"var(--widget-radius)"},children:"Order Cancelled"})}):_jsxruntime.jsxs.call(void 0, "div",{className:"flex w-full",children:[o==="chain"&&Z&&_jsxruntime.jsx.call(void 0, er,{requiredChain:Be,needsChainSwitch:Z&&U!==e.chainId,reviewState:o,goToNextStep:z,cancel:te}),o==="wrapping"&&O&&_jsxruntime.jsx.call(void 0, fr,{needsToWrap:O,amount:t,chainId:e.chainId,token:e,reviewState:o,setReviewState:n,goToNextStep:z,cancel:te,delayedClose:Ce,isWrappingPair:r}),o==="unwrapping"&&A&&_jsxruntime.jsx.call(void 0, dr,{needsToUnwrap:A,amount:t,chainId:e.chainId,token:e,reviewState:o,setReviewState:n,goToNextStep:z,cancel:te,delayedClose:Ce}),o==="signingOrder"&&q&&_jsxruntime.jsx.call(void 0, ir,{base:e,baseAmount:t,quote:s,quoteAmount:c,userAddress:l,reviewState:o,goToNextStep:z,cancel:te,restartSigningFlow:Je,onSwapInitiated:g,onOrderSubmitted:i,isWrappingPair:r,isUnwrappingPair:a,onSwapComplete:f,startPolling:V,trackNativeTransaction:R}),o==="trackingTx"&&b&&_jsxruntime.jsx.call(void 0, cr,{orderHash:b,base:e,quote:s,baseAmount:t,quoteAmount:c,reviewState:o,status:d,onNewSwap:me,onRetry:$e}),o&&!["chain","wrapping","unwrapping","approval","signingOrder","trackingTx","success","wrapSuccess","cancelled"].includes(o)&&_jsxruntime.jsx.call(void 0, "button",{disabled:!0,className:`w-full ${H?"py-2":"py-3"} text-sm font-medium`,style:{backgroundColor:"var(--widget-muted)",color:"var(--widget-muted-foreground)",borderRadius:"var(--widget-radius)"},children:"Processing..."})]})};var _shallow = require('zustand/react/shallow');var br={pending:"var(--widget-status-pending)",received:"var(--widget-status-received)",completed:"var(--widget-status-completed)",failed:"var(--widget-status-failed)",cancelled:"var(--widget-status-failed)"},hr={pending:{title:"Trade Pending",subtitle:"Submitting to network"},received:{title:"Trade Received",subtitle:"Processing settlement"},completed:{title:"Trade Filled",subtitle:"Settlement complete"},failed:{title:"Trade Failed",subtitle:"Settlement unsuccessful"},cancelled:{title:"Trade Cancelled",subtitle:"Order was cancelled"}};function Gn(e){let t=_nullishCoalesce(br[e], () => (br.pending));return{textColor:t,bgColor:`color-mix(in srgb, ${t} 15%, transparent)`,borderColor:`color-mix(in srgb, ${t} 20%, transparent)`,cardBgColor:`color-mix(in srgb, ${t} 8%, transparent)`,cardBorderColor:`color-mix(in srgb, ${t} 15%, transparent)`,iconBgColor:`color-mix(in srgb, ${t} 12%, transparent)`,iconBorderColor:`color-mix(in srgb, ${t} 15%, transparent)`}}var Kn=({status:e})=>{switch(e){case"completed":return _jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.O,{});case"failed":case"cancelled":return _jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.X,{});default:return _jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.U,{size:"10"})}},Hn=({orderHash:e,base:t,quote:s,baseAmount:c,quoteAmount:l,status:r})=>{let[a,h]=_react.useState.call(void 0, !1),y=_react.useRef.call(void 0, null),p=_react.useRef.call(void 0, Date.now()),[o,n]=_react.useState.call(void 0, null),b=_react.useRef.call(void 0, null),{isRecipientInputOpen:w,recipient:d}=_chunkBJYKILHScjs.c.call(void 0, _shallow.useShallow.call(void 0, u=>({isRecipientInputOpen:u.isRecipientInputOpen,recipient:u.recipient})));_react.useEffect.call(void 0, ()=>{r==="received"&&(y.current=Date.now())},[r]),_react.useEffect.call(void 0, ()=>{if(r==="completed"&&!o){let u=y.current||p.current;n((Date.now()-u)/1e3)}},[r,o]),_react.useEffect.call(void 0, ()=>()=>{b.current&&clearTimeout(b.current)},[]);let f=_react.useCallback.call(void 0, ()=>{_optionalChain([navigator, 'access', _91 => _91.clipboard, 'optionalAccess', _92 => _92.writeText])&&navigator.clipboard.writeText(e).then(()=>{h(!0),b.current&&clearTimeout(b.current),b.current=setTimeout(()=>h(!1),2e3)}).catch(()=>{})},[e]),g=_nullishCoalesce(hr[r], () => (hr.pending)),i=Gn(r),m=_chunkSE6JOLEMcjs.o.call(void 0, c),v=_chunkSE6JOLEMcjs.o.call(void 0, l);return _jsxruntime.jsx.call(void 0, "div",{className:"relative w-full h-full overflow-hidden flex flex-col",style:{backgroundColor:i.bgColor,border:`1px var(--widget-border-style) ${i.borderColor}`,backdropFilter:"blur(8px)"},children:_jsxruntime.jsxs.call(void 0, "div",{className:"relative z-10 px-3 pt-5 pb-3 flex-1 flex flex-col",children:[_jsxruntime.jsx.call(void 0, "div",{className:"flex items-center justify-center mb-2",children:_jsxruntime.jsxs.call(void 0, "div",{className:"flex flex-col items-center gap-1 text-center",children:[_jsxruntime.jsx.call(void 0, "div",{className:"flex h-10 w-10 items-center justify-center rounded-full border",style:{backgroundColor:i.iconBgColor,borderColor:i.iconBorderColor},children:_jsxruntime.jsx.call(void 0, "div",{className:"h-7 w-7 flex items-center justify-center",children:_jsxruntime.jsx.call(void 0, Kn,{status:r})})}),_jsxruntime.jsxs.call(void 0, "div",{children:[_jsxruntime.jsx.call(void 0, "h3",{className:"text-xl font-bold",style:{color:i.textColor},children:g.title}),_jsxruntime.jsx.call(void 0, "p",{className:"text-2xs uppercase tracking-wider",style:{color:i.textColor,opacity:.6},children:g.subtitle})]})]})}),_jsxruntime.jsx.call(void 0, "div",{className:"flex-1 flex flex-col justify-center",children:_jsxruntime.jsxs.call(void 0, "div",{className:"space-y-1.5",children:[_jsxruntime.jsxs.call(void 0, "div",{className:"flex items-center justify-between backdrop-blur-sm p-2.5 border transition-all duration-300",style:{backgroundColor:i.cardBgColor,borderColor:i.cardBorderColor},children:[_jsxruntime.jsxs.call(void 0, "div",{className:"flex items-center gap-2.5",children:[_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.N,{asset:t,size:"sm"}),_jsxruntime.jsxs.call(void 0, "div",{children:[_jsxruntime.jsx.call(void 0, "div",{className:"text-sm font-bold",style:{color:i.textColor},children:t.symbol}),_jsxruntime.jsx.call(void 0, "div",{className:"text-2xs",style:{color:i.textColor,opacity:.5},children:t.name})]})]}),_jsxruntime.jsxs.call(void 0, "div",{className:"text-right",children:[_jsxruntime.jsx.call(void 0, "div",{className:"text-lg font-bold mono",style:{color:i.textColor},children:m}),t.price&&_jsxruntime.jsxs.call(void 0, "div",{className:"text-2xs mono",style:{color:i.textColor,opacity:.5},children:["$",(t.price*c).toFixed(2)]})]})]}),_jsxruntime.jsx.call(void 0, "div",{className:"flex justify-center pb-0.5 pt-1",children:_jsxruntime.jsx.call(void 0, "div",{className:"flex h-6 w-6 items-center justify-center rounded-full border",style:{backgroundColor:i.cardBgColor,borderColor:i.cardBorderColor},children:_jsxruntime.jsx.call(void 0, "span",{className:"text-base",style:{color:i.textColor},children:"\u2193"})})}),_jsxruntime.jsxs.call(void 0, "div",{className:"flex items-center justify-between backdrop-blur-sm p-2.5 border transition-all duration-300",style:{backgroundColor:i.cardBgColor,borderColor:i.cardBorderColor},children:[_jsxruntime.jsxs.call(void 0, "div",{className:"flex items-center gap-2.5",children:[_jsxruntime.jsx.call(void 0, _chunkSE6JOLEMcjs.N,{asset:s,size:"sm"}),_jsxruntime.jsxs.call(void 0, "div",{children:[_jsxruntime.jsx.call(void 0, "div",{className:"text-sm font-bold",style:{color:i.textColor},children:s.symbol}),_jsxruntime.jsx.call(void 0, "div",{className:"text-2xs",style:{color:i.textColor,opacity:.5},children:s.name})]})]}),_jsxruntime.jsxs.call(void 0, "div",{className:"text-right",children:[_jsxruntime.jsx.call(void 0, "div",{className:"text-lg font-bold mono",style:{color:i.textColor},children:v}),s.price&&_jsxruntime.jsxs.call(void 0, "div",{className:"text-2xs mono",style:{color:i.textColor,opacity:.5},children:["$",(s.price*l).toFixed(2)]})]})]}),w&&d&&_jsxruntime.jsxs.call(void 0, "div",{className:"mt-1.5",children:[_jsxruntime.jsx.call(void 0, "div",{className:"text-2xs mb-0.5 uppercase tracking-wider font-medium",style:{color:i.textColor,opacity:.5},children:"Recipient"}),_jsxruntime.jsx.call(void 0, "div",{className:"flex items-center backdrop-blur-sm p-2 border transition-all duration-300",style:{backgroundColor:i.cardBgColor,borderColor:i.cardBorderColor},children:_jsxruntime.jsxs.call(void 0, "div",{className:"flex items-center gap-2",children:[_jsxruntime.jsx.call(void 0, "div",{className:"flex h-5 w-5 items-center justify-center overflow-hidden rounded-full",style:{backgroundColor:i.iconBgColor},children:_jsxruntime.jsx.call(void 0, "span",{className:"text-2xs",children:"\u{1F464}"})}),_jsxruntime.jsxs.call(void 0, "div",{className:"flex flex-col",children:[_jsxruntime.jsx.call(void 0, "div",{className:"text-2xs",style:{color:i.textColor,opacity:.5},children:"To:"}),_jsxruntime.jsxs.call(void 0, "div",{className:"text-xs mono",style:{color:i.textColor},children:[d.slice(0,6),"...",d.slice(-4)]})]})]})})]})]})}),_jsxruntime.jsxs.call(void 0, "div",{className:"mt-3 pt-2.5 space-y-1.5",style:{borderTop:`1px solid ${i.cardBorderColor}`},children:[_jsxruntime.jsxs.call(void 0, "div",{role:"button",tabIndex:0,onClick:f,onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&(u.preventDefault(),f())},className:"flex items-center justify-between cursor-pointer group hover:opacity-80 transition-opacity",children:[_jsxruntime.jsx.call(void 0, "div",{className:"text-xs uppercase tracking-wider font-medium",style:{color:i.textColor,opacity:.5},children:a?"Copied!":r==="completed"||r==="failed"||r==="cancelled"?"Order Hash":r==="received"?"Received":"Pending"}),_jsxruntime.jsxs.call(void 0, "div",{className:"text-xs mono transition-colors",style:{color:i.textColor},children:[e.slice(0,6),"...",e.slice(-4)]})]}),r==="completed"&&o?_jsxruntime.jsxs.call(void 0, "div",{className:"flex items-center justify-between",children:[_jsxruntime.jsx.call(void 0, "div",{className:"text-xs uppercase tracking-wider font-medium",style:{color:i.textColor,opacity:.5},children:"Speed"}),_jsxruntime.jsxs.call(void 0, "div",{className:"text-base font-bold mono",style:{color:i.textColor},children:[o.toFixed(2),"s"]})]}):_jsxruntime.jsx.call(void 0, "div",{className:"h-5"})]})]})})},Oi= exports.w =Hn;exports.a = Tr; exports.b = Ee; exports.c = ts; exports.d = ls; exports.e = Ve; exports.f = Wr; exports.g = ms; exports.h = ys; exports.i = Rs; exports.j = Ps; exports.k = Dt; exports.l = Lt; exports.m = Bt; exports.n = Hr; exports.o = Ft; exports.p = Xr; exports.q = jt; exports.r = zt; exports.s = Gt; exports.t = Kt; exports.u = Ht; exports.v = Si; exports.w = Oi;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import{a as vr}from"./chunk-OPN7WCJR.js";import{c as he,f as Ne}from"./chunk-7QJJOVSV.js";import{b as Te,c as Nt}from"./chunk-VI4ISTPB.js";import{A as rt,H as Rt,I as nt,M as Me,N as ce,O as Y,R as ge,S as At,T as De,U as G,W as kt,X as We,a as _e,c as j,h as vt,k as Re,m as Ae,o as ke,q as xt,r as re,s as Ct,t as Ze,v as et,w as St,x as Tt,z as tt}from"./chunk-ZWNDO5OZ.js";import{a as ne}from"./chunk-46H44R7V.js";import{b as yr}from"./chunk-73CB2I7U.js";import{useQueryClient as xr}from"@tanstack/react-query";import{useCallback as Cr,useEffect as It,useRef as Et}from"react";function Sr(e){if(e.length===0)return 5e3;let l=Math.max(...e.map(r=>j(r)?.blockTimeMs??2e3));return Math.min(5e3,Math.max(1e3,l*2+1e3))}var Tr=()=>{let{address:e}=ne(),t=Nt(),s=xr(),c=Et(null),l=Et(!0),r=Cr(a=>{if(!e)return;let h=[...new Set(a.tokens.map(p=>p.asset.chainId))],y=Sr(h);c.current&&(clearTimeout(c.current),c.current=null),c.current=setTimeout(async()=>{if(c.current=null,!!l.current)try{let p=a.tokens.map(w=>({chainId:w.asset.chainId,tokenAddress:w.asset.address})),o=await Rt(e,p);if(o.balances.length===0)return;if(a.tokens.length>=2){let w=a.tokens[0].asset,d=a.tokens[1].asset,f=nt.swap(e,w.chainId,w.address,d.chainId,d.address);s.setQueryData(f,o)}let n=nt.bulk(e,t),b=s.getQueryData(n);if(b){let w=b.balances.map(d=>o.balances.find(g=>g.chainId===d.chainId&&g.token.toLowerCase()===d.token.toLowerCase())??d);for(let d of o.balances)w.some(f=>f.chainId===d.chainId&&f.token.toLowerCase()===d.token.toLowerCase())||w.push(d);for(let d of a.tokens)if(!o.balances.some(g=>g.chainId===d.asset.chainId&&g.token.toLowerCase()===d.asset.address.toLowerCase())){let g=w.findIndex(i=>i.chainId===d.asset.chainId&&i.token.toLowerCase()===d.asset.address.toLowerCase());g!==-1&&(w[g]={...w[g],balance:"0",shiftedBalance:"0"})}s.setQueryData(n,{balances:w})}}catch{}},y)},[e,t,s]);return It(()=>(l.current=!0,()=>{l.current=!1,c.current&&(clearTimeout(c.current),c.current=null)}),[]),{triggerBalanceUpdate:r}},st=class extends EventTarget{emit(t){this.dispatchEvent(new CustomEvent("balance-update",{detail:t}))}},ot=new st,Ee=()=>e=>ot.emit(e),ts=()=>{let{triggerBalanceUpdate:e}=Tr();It(()=>{let t=s=>{e(s.detail)};return ot.addEventListener("balance-update",t),()=>ot.removeEventListener("balance-update",t)},[e])};import{createContext as Rr,useCallback as le,useContext as Ar,useEffect as Ot,useMemo as kr,useRef as se,useState as ye}from"react";import{formatUnits as Nr,parseUnits as Er}from"viem";import{jsx as Ur}from"react/jsx-runtime";var $t=Rr(void 0),Pt=1e4,Ir=3e4,Or=1e3,Pr=2;function $r(e){return e.find(s=>s.routeSteps?.[0]?.type==="AORI_V1")??e[0]}var ls=({children:e,recipient:t})=>{let{address:s}=ne(),c=t||s,[l,r]=ye("idle"),[a,h]=ye("idle"),[y,p]=ye(null),[o,n]=ye(null),[b,w]=ye(!1),[d,f]=ye(!1),[g,i]=ye(!1),m=se(null),v=se(null),u=se(null),T=se(null),P=se(null),C=se(0),$=se(0),L=se(0),N=se(!1),E=se(new Map),I=le(()=>{u.current&&clearTimeout(u.current),T.current&&clearTimeout(T.current),P.current&&clearTimeout(P.current),u.current=null,T.current=null,P.current=null},[]),U=le(()=>{I(),m.current=null,C.current=0,r(()=>N.current?"fresh":"idle")},[I]),B=le(()=>{U(),v.current=null,p(null),n(null),w(!1),f(!1),i(!1),E.current.clear(),r("idle"),h("idle")},[U]),oe=le(x=>{if(!x)return;T.current&&clearTimeout(T.current);let S=Math.max(0,x+Ir-Date.now());T.current=setTimeout(()=>{r(O=>O==="idle"?"idle":"stale")},S)},[]),H=le(async(x,S)=>{let{inputToken:O,outputToken:A,inputAmount:q,setOutputAmount:Z}=x;if(!O||!A||!q||parseFloat(q)<=0||Date.now()-($.current||0)<Pt-10)return;let Be=++C.current;try{if(!O?.decimals||!A?.decimals)return;let z=rt(O.chainId)||j(O.chainId)?.key||"",ie=rt(A.chainId)||j(A.chainId)?.key||"";if(!z||!ie)throw new Error("Unknown chain");let ee=Er(q.toString(),O.decimals).toString(),Ce={srcChainKey:z,dstChainKey:ie,srcTokenAddress:et(O.address),dstTokenAddress:et(A.address),amount:ee,srcWalletAddress:s||"0x0000000000000000000000000000000000000000",dstWalletAddress:c||s||"0x0000000000000000000000000000000000000000",options:{amountType:"EXACT_SRC_AMOUNT",feeTolerance:{type:"PERCENT",amount:2}}};$.current=Date.now();let te=await fetch(`${Re()}/quotes`,{method:"POST",headers:Ae(),body:JSON.stringify(Ce),signal:AbortSignal.timeout(15e3)});if(!te.ok){let Se=(await te.json().catch(()=>({})))?.message||te.statusText;throw Object.assign(new Error(Se),{status:te.status})}let me=await te.json();if(Be!==C.current||m.current!==S)return;let $e=me.quotes??[],ae=$r($e);if(!ae)throw Object.assign(new Error("No quotes returned"),{emptyQuotes:!0});let Je=Number(Nr(xt(ae.dstAmount),A.decimals));typeof Z=="function"&&Z(Je),ae._receivedAt=Date.now(),p(ae),n(null),w(!1),r("fresh"),oe(ae._receivedAt),S&&E.current.delete(S)}catch(z){if(Be!==C.current||m.current!==S)return;let ie=z?.status,ee=z instanceof Error?z.message:"",Ce=!!z?.emptyQuotes;if((ie===400||Ce||ee.includes("Quote request failed"))&&S){let me=(E.current.get(S)||0)+1;if(E.current.set(S,me),me>=Pr){f(!0),I(),m.current=null;return}}if(ee.toLowerCase().includes("order cap exceeded")){i(!0),I(),m.current=null;return}if(ee.toLowerCase().includes("insufficient executor balance")){w(!0),I(),m.current=null;return}n(z instanceof Error?z.message:"Unknown error")}},[s,c,oe,I]),W=le((x,S)=>{I(),v.current=x,$.current=0,E.current.delete(S),w(!1),f(!1),i(!1),n(null),r("polling");let O=async()=>{m.current===S&&(await H(x,S),m.current===S&&(u.current=setTimeout(O,Pt)))};O()},[I,H]),R=le(x=>{if(!x?.inputToken||!x?.outputToken||!x?.inputAmount||parseFloat(x.inputAmount)<=0){U();return}let S=v.current;if(S&&S.inputToken?.address===x.inputToken?.address&&S.inputToken?.chainId===x.inputToken?.chainId&&S.outputToken?.address===x.outputToken?.address&&S.outputToken?.chainId===x.outputToken?.chainId&&S.inputAmount===x.inputAmount&&m.current)return;let A=Date.now();if(A-L.current<100)return;L.current=A;let q=`${Date.now()}-${Math.random().toString(36).slice(2)}`;m.current=q,W(x,q)},[W,U]),V=le(({amount:x,inputToken:S,outputToken:O,setOutputAmount:A})=>{A(null),P.current&&clearTimeout(P.current),!x||x===0?(h("idle"),U(),p(null),n(null),w(!1),f(!1),i(!1)):(h("typing"),U(),p(null),w(!1),f(!1),i(!1),n(null),P.current=setTimeout(()=>{h("settled"),S&&O&&x>0&&R({inputToken:S,outputToken:O,inputAmount:x.toString(),setOutputAmount:A})},Or))},[U,R]),F=le(()=>{let x=v.current;if(!x)return;p(null);let S=`${Date.now()}-${Math.random().toString(36).slice(2)}`;m.current=S,r("refreshing"),typeof x.setOutputAmount=="function"&&x.setOutputAmount(null),W(x,S)},[W]);Ot(()=>{N.current=!!y},[y]),Ot(()=>()=>I(),[I]);let X=kr(()=>({status:l,inputState:a,rfqQuote:y,error:o,liquidityError:b,routingError:d,sizeCapError:g,ensureForParams:R,stop:U,refresh:F,clear:B,handleInputChange:V}),[l,a,y,o,b,d,g,R,U,F,B,V]);return Ur($t.Provider,{value:X,children:e})},Ve=()=>{let e=Ar($t);if(e===void 0)throw new Error("useRfq must be used within an RfqProvider");return e};import{createContext as Mr,useContext as Dr}from"react";var Wr=Mr({openConnectModal:()=>{}}),ms=()=>Dr(Wr);import{useCallback as it,useEffect as Ie,useRef as Fe,useState as at}from"react";import{jsx as Oe,jsxs as _r}from"react/jsx-runtime";var Lr=20,Br=({side:e,asset:t,otherAsset:s,isPlacingOrder:c,isWrappingPair:l,isUnwrappingPair:r})=>{let{baseAmount:a,quoteAmount:h,setBaseAmount:y,setQuoteAmount:p}=Ne(),{amountInputVariant:o,hideAmountInputSymbol:n,widgetType:b}=Te(),w=b==="compact",[d,f]=e==="base"?[y,p]:[p,y],g=!t||e==="quote"||c,i=w?32:o==="default"?64:32,[m,v]=at(i),[u,T]=at(""),P=Fe(null),C=Fe(null),$=Fe(null),L=Fe(null),N="USD",E=e==="base"?a:h,[I,U]=at(!1),B=it(()=>{if(o!=="default"){v(i);return}if(!P.current||!C.current||!$.current)return;let W=P.current.offsetWidth,R=20,V=i;for(;V>20&&(C.current.style.fontSize=`${V}px`,$.current.style.fontSize=`${V}px`,!(C.current.offsetWidth+$.current.offsetWidth+R<=W));)V-=1;v(V)},[o,i]),oe=it(W=>{W.key==="."&&u.includes(".")&&W.preventDefault()},[u]),H=it(W=>{let R=W.target.value;if(R==="."&&(R="0."),!/^\d*\.?\d*$/.test(R)||(R.match(/\./g)||[]).length>1)return;if(R.length>1&&R[0]==="0"&&R[1]!=="."&&(R=R.replace(/^0+/,"")||"0"),t?.decimals!==void 0&&R.includes(".")){let[,F]=R.split(".");if(F&&F.length>t.decimals)return}if(R.length>Lr)return;T(R);let V=parseFloat(R);R!==u&&(R===""||R==="0."||R.endsWith(".")?(d(null),e==="base"&&f(null)):!Number.isNaN(V)&&V>=0&&d(V),e==="base"&&p(null),(r||l)&&p(V||0))},[u,d,e,p,t?.decimals,f,r,l]);return Ie(()=>{let W=F=>{if(F===null)return"";let X=t?.decimals;if(X===void 0)return"";let x=F.toString();if(/e/i.test(x)&&(x=Number(F).toLocaleString("en-US",{useGrouping:!1,maximumFractionDigits:X})),x.includes(".")){let[S,O]=x.split("."),A=O.slice(0,X);return A?`${S}.${A}`:S}return x};if(E===null){u==="0."||u!==""&&u.endsWith(".")||T("");return}if(!g&&(u.endsWith(".")||u.match(/\.\d*0$/)||u==="0"||u==="0.")&&u!=="")return;let V=parseFloat(u)||0;(u===""||Math.abs(V-E)>1e-10)&&T(W(E))},[E,t?.decimals,u,g]),Ie(()=>{B()},[u,B]),Ie(()=>{U(!0)},[]),Ie(()=>{I&&B()},[I,B]),Ie(()=>{C.current&&L.current&&(L.current.style.width=`${C.current.offsetWidth}px`)},[u]),Ie(()=>{if(!I)return;let W=new ResizeObserver(()=>{I&&B()});return P.current&&W.observe(P.current),()=>W.disconnect()},[I,B]),Oe("div",{ref:P,style:{fontSize:`${m}px`,transition:"font-size 0.05s ease-in-out"},className:`mt-2 box-border flex ${w?o==="normal"?"h-12 my-1":"h-10 my-0.5":o==="normal"?"h-12 my-1":"h-20 my-1"} w-full flex-row items-center ${g?"cursor-default":"cursor-text"}`,onClick:()=>L.current?.focus(),children:_r("div",{className:"relative flex w-full items-center",children:[Oe("label",{htmlFor:`${e}Amount`,className:"sr-only",children:e==="base"?"Input token amount":"Output token amount"}),Oe("input",{ref:L,type:"text",inputMode:"decimal",placeholder:"0",autoComplete:"off",id:`${e}Amount`,value:u,onWheel:W=>W.target.blur(),onKeyDown:oe,onChange:H,style:{transition:"width 0.15s ease-in-out",color:"var(--widget-foreground)",WebkitTextFillColor:"var(--widget-foreground)",opacity:g?.4:1},className:"flex min-w-[45px] whitespace-nowrap bg-transparent placeholder:opacity-50",disabled:g}),Oe("span",{style:{transition:"width 0.15s ease-in-out"},ref:C,className:"pointer-events-none absolute flex whitespace-nowrap invisible",children:u||0}),!n&&o!=="normal"&&Oe("span",{ref:$,className:"ml-2 font-light uppercase",style:{color:"var(--widget-foreground)",opacity:.5,fontSize:`${m}px`},children:t?.symbol?t.symbol.length>6?`${t.symbol.slice(0,6)}...`:t.symbol:N}),(n||o==="normal")&&Oe("span",{ref:$,className:"hidden"})]})})},ys=Br;import{Fragment as ct,jsx as D,jsxs as ue}from"react/jsx-runtime";var Vr=({toggle:e,side:t,asset:s,isPlacingOrder:c,hideDropdown:l})=>{let{baseBalance:r,quoteBalance:a}=Ne(),{tokenDisplay:h,tokenBadgeOrientation:y,widgetType:p}=Te(),o=p==="compact",n=o?"h-10":"h-12",b=o?"h-10 w-10":"h-12 w-12",w=t==="base"?r.formatted?(()=>{let f=parseFloat(r.formatted);return f>=1e8?ke(f):f.toFixed(3)})():void 0:a.formatted?(()=>{let f=parseFloat(a.formatted);return f>=1e8?ke(f):f.toFixed(3)})():void 0,d={role:"button",tabIndex:c?-1:0,"aria-disabled":c,"aria-label":`Select ${t==="base"?"input":"output"} token${s?`: ${s.symbol}`:""}`,onClick:c?void 0:e,onKeyDown:c?void 0:f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),e())}};return h==="pill"?D("div",{...d,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-full cursor-pointer transition-colors ${y==="right"?"ml-auto":""}`,style:{border:"1px solid var(--widget-border)",backgroundColor:"var(--widget-secondary)",color:"var(--widget-secondary-foreground)"},children:s?ue(ct,{children:[D(Me,{chain:s.chainId,size:"xs"}),D(ce,{className:"rounded-full",asset:s,size:"xxs",noChain:!0}),D("span",{className:"text-xs font-medium uppercase",children:s.symbol}),!l&&D(De,{className:"w-1.5 opacity-60",style:{color:"var(--widget-secondary-foreground)"}})]}):ue(ct,{children:[D("span",{className:"text-xs opacity-70",children:"Select"}),!l&&D(De,{className:"w-1.5 opacity-60",style:{color:"var(--widget-secondary-foreground)"}})]})}):h==="ghost"?ue("div",{...d,className:"inline-flex items-center gap-1.5 cursor-pointer transition-opacity hover:opacity-70 py-1",style:{color:"var(--widget-foreground)"},children:[s?ue(ct,{children:[D(Me,{chain:s.chainId,size:"xs"}),D(ce,{className:"rounded-full",asset:s,size:"xxs",noChain:!0}),D("span",{className:"text-sm font-medium uppercase",children:s.symbol})]}):D("span",{className:"text-sm",style:{color:"var(--widget-muted-foreground)"},children:"Select token"}),!l&&D(De,{className:"w-1.5 opacity-50"})]}):D("div",{...d,className:`relative ${n} w-full cursor-pointer text-xl duration-100 ease-linear`,style:{border:"1px solid var(--widget-border)",backgroundColor:"var(--widget-secondary)",borderTopLeftRadius:"9999px",borderBottomLeftRadius:"9999px",borderTopRightRadius:"var(--widget-radius)",borderBottomRightRadius:"var(--widget-radius)"},children:D("div",{className:"relative flex h-full w-full flex-row items-center",children:s?ue("div",{className:"relative flex h-full w-full flex-row items-center",children:[D("div",{className:`${b} pl-px flex items-center justify-center`,children:D(ce,{className:"rounded-full",asset:s,size:"md"})}),ue("div",{className:"flex h-full w-full flex-row items-center justify-between pl-1.5 pr-7",children:[ue("div",{className:"flex h-full flex-col justify-center",children:[D("p",{className:"text-sm font-medium uppercase",style:{color:"var(--widget-secondary-foreground)"},children:s.symbol}),ue("span",{className:"text-2xs font-mono",style:{color:"var(--widget-secondary-foreground)",opacity:.6},children:[s.address?.slice(0,6),"...",s.address?.slice(-4)]})]}),w!==void 0&&ue("div",{className:"flex flex-col text-right",children:[D("p",{className:"text-2xs",style:{color:"var(--widget-secondary-foreground)",opacity:.5},children:"Balance"}),D("span",{className:"font-mono text-xs tabular-nums",style:{color:"var(--widget-secondary-foreground)"},children:w})]})]}),!l&&D(De,{className:"absolute right-3 top-1/2 w-1.5 translate-y-[-50%]",style:{color:"var(--widget-secondary-foreground)",opacity:.6}})]}):D("div",{className:"flex h-full w-full items-center justify-center",children:D("span",{className:"text-sm",style:{color:"var(--widget-secondary-foreground)",opacity:.7},children:"Select token"})})})})},Rs=Vr;var Mt=yr(vr(),1);import{useState as qe,useEffect as Qe}from"react";import{jsx as K,jsxs as Ut}from"react/jsx-runtime";var Fr=()=>{let[e,t]=qe(null),[s,c]=qe(""),l=Tt(s,1e3),[r,a]=qe(!1),[h,y]=qe("");Qe(()=>{he.getState().setRecipient(e)},[e]),Qe(()=>{c(e||"")},[e]);let p=n=>{let b=n.target.value;r&&(a(!1),y(""),t(null)),c(b),b===""&&t(null)};Qe(()=>{l===""||!l?(a(!1),y(""),t(null)):St(l)?(a(!1),y(""),t(l)):(a(!0),y("Invalid wallet address..."),t(null),c(""))},[l]),Qe(()=>{if(r){let n=setTimeout(()=>{t(null),c(""),a(!1),y("")},2e3);return()=>clearTimeout(n)}},[r]);let o=()=>{t(null),c(""),a(!1),y("")};return K("div",{className:"w-full",children:Ut("div",{className:"relative flex flex-row items-center",children:[K("input",{type:"password",style:{display:"none"},"aria-hidden":"true",tabIndex:-1}),K("label",{htmlFor:"recipient-address",className:"sr-only",children:"Recipient wallet address"}),K("div",{className:"absolute left-3 flex h-6 w-6 items-end justify-center overflow-hidden rounded-full",style:{backgroundColor:"var(--widget-secondary)"},children:e&&!r?K("img",{className:"h-full w-full rounded-full object-cover",src:(0,Mt.makeGradient)(e),alt:"Recipient avatar"}):K(At,{className:"h-5 w-5",style:{color:r?"var(--widget-destructive)":"var(--widget-muted-foreground)"}})}),K("div",{className:"absolute left-12 top-1.5 -translate-y-1 text-xs font-medium opacity-60",style:{color:r?"var(--widget-destructive)":"var(--widget-muted-foreground)"},"aria-hidden":"true",children:"To:"}),K("input",{id:"recipient-address",className:"mono block h-10 w-full items-center pl-12 pt-4 pr-8 text-xs",style:{backgroundColor:r?"color-mix(in srgb, var(--widget-destructive) 10%, transparent)":"transparent",color:r?"var(--widget-destructive)":"var(--widget-foreground)",outline:"none",opacity:r?.9:1},placeholder:r?h:"Enter recipient address...",value:s,onChange:p,spellCheck:!1,"aria-invalid":r,"aria-describedby":r?"recipient-error":void 0}),r&&K("span",{id:"recipient-error",className:"sr-only",children:h}),e&&!r&&Ut("button",{type:"button",className:"absolute right-2 top-1/2 -translate-y-1/2 cursor-pointer flex items-center justify-center h-4 w-4 rounded-full transition-colors hover:[color:var(--widget-destructive)]",style:{color:"var(--widget-muted-foreground)"},onClick:o,"aria-label":"Clear recipient",children:[K("svg",{className:"h-2.5 w-2.5",viewBox:"0 -0.5 21 21",fill:"none",children:K("g",{fill:"currentColor",fillRule:"evenodd",children:K("polygon",{points:"375.0183 90 384 98.554 382.48065 100 373.5 91.446 364.5183 100 363 98.554 371.98065 90 363 81.446 364.5183 80 373.5 88.554 382.48065 80 384 81.446",transform:"translate(-363 -80)"})})}),K("span",{className:"sr-only",children:"Clear recipient"})]})]})})},Ps=Fr;var qr=["SUCCEEDED","FAILED","COMPLETED","CANCELLED"];async function Dt(e,t,s={}){let{onStatusChange:c,onComplete:l,onError:r,interval:a=4e3,timeout:h=3e5,txHash:y,signal:p}=s,o=null,n=Date.now(),b=0,w=8,d=null,f=y?`?txHash=${y}`:"";return new Promise((g,i)=>{let m=async()=>{try{if(p?.aborted){d&&clearTimeout(d),i(new DOMException("Polling aborted","AbortError"));return}if(Date.now()-n>h){d&&clearTimeout(d);let P=new Error("Order status polling timed out");r?.(P),i(P);return}let v=await fetch(`${t}/status/${e}${f}`,{headers:Ae(),signal:p});if(v.status===404){d=setTimeout(m,a);return}if(!v.ok)throw new Error(`Failed to fetch order status: ${await v.text()}`);let u=await v.json();if(!u||typeof u!="object"||!u.status)throw new Error(`Invalid status response format: ${JSON.stringify(u)}`);b=0;let T=u.status.toUpperCase();if(T!==o&&(o=T,c?.(u)),qr.includes(T)){d&&clearTimeout(d),l?.(u),g(u);return}d=setTimeout(m,a)}catch(v){if(v instanceof Error&&v.name==="AbortError"){d&&clearTimeout(d),i(v);return}if(++b>=w){d&&clearTimeout(d);let u=v instanceof Error?v:new Error(String(v));r?.(u),i(u);return}d=setTimeout(m,a)}};m()})}import{useCallback as je,useEffect as Qr,useRef as ze}from"react";function Wt(e){let t=e.toUpperCase();return t==="SUCCEEDED"||t==="COMPLETED"?"completed":t==="FAILED"?"failed":t==="CANCELLED"?"cancelled":t==="PROCESSING"?"received":"pending"}var Lt=e=>{let t=ze(new Map),s=ze(new Map),c=ze(new Map),l=ze(0),r=je(()=>++l.current,[]),{address:a}=ne(),h=Ee(),y=je((n,b)=>{if(t.current.get(n))return;b&&s.current.set(n,b),t.current.set(n,!0);let w=l.current,d=new AbortController;c.current.set(n,d);let f=b?.baseToken?.chainId===1;Dt(n,Re(),{interval:f?1e3:500,timeout:3e5,signal:d.signal,onStatusChange:g=>{if(!g?.status)return;let i=Wt(g.status);if(e?.(n,i),i==="completed"&&a){let m=s.current.get(n);if(m&&(m.baseToken||m.quoteToken)){let v=[];m.baseToken&&v.push({asset:m.baseToken,userAddress:a}),m.quoteToken&&v.push({asset:m.quoteToken,userAddress:a}),h({type:"swap",tokens:v})}}["completed","failed","cancelled"].includes(i)&&(t.current.delete(n),s.current.delete(n)),w!==l.current&&(t.current.delete(n),s.current.delete(n))},onComplete:g=>{g?.status&&e?.(n,Wt(g.status)),t.current.delete(n),s.current.delete(n)},onError:()=>{t.current.delete(n),s.current.delete(n)}}).catch(g=>{g instanceof Error&&g.name==="AbortError"||(t.current.delete(n),s.current.delete(n),c.current.delete(n))})},[a,h,e]),p=je(n=>{let b=c.current.get(n);b&&(b.abort(),c.current.delete(n)),r(),t.current.delete(n),s.current.delete(n)},[r]),o=je(()=>{for(let n of c.current.values())n.abort();c.current.clear(),r(),t.current.clear(),s.current.clear()},[r]);return Qr(()=>()=>o(),[o]),{startPolling:y,stopPolling:p,stopAllPolling:o,isPolling:n=>t.current.has(n)}};import{createContext as jr,useContext as zr}from"react";var Gr=jr({registerTransaction:()=>{},enabled:!1}),Bt=()=>zr(Gr);import{signTypedData as Kr}from"viem/actions";function Vt(e){return e instanceof Error?e.name==="UserRejectedRequestError"||e.message.includes("User rejected")||e.message.includes("rejected")||e.message.includes("denied")||e.message.includes("cancelled")||e.message.includes("canceled"):!1}async function _t(e){if(e.chain?.id)return e.chain.id;let t=e.getChainId?.();return t!=null?await t:null}var Hr=async(e,t)=>{try{if(await _t(e)===t)return!0;if(e.request)await e.request({method:"wallet_switchEthereumChain",params:[{chainId:`0x${t.toString(16)}`}]});else if(e.switchChain)await e.switchChain({id:t});else if(e.send)await e.send("wallet_switchEthereumChain",[{chainId:`0x${t.toString(16)}`}]);else throw new Error("Wallet doesn't support chain switching");return await _t(e)===t}catch(s){throw Vt(s)?new Error("User rejected the chain switch request"):new Error(`Please switch your wallet to the required network (Chain ID: ${t})`)}},Ft=async e=>{let{quote:t,signatureStep:s,userAddress:c,walletClient:l}=e;if(!l)throw new Error("Wallet client not available");if(s.type!=="SIGNATURE"||!s.signature?.typedData)throw new Error("Invalid signature step");try{let r=s.signature.typedData,a={...r.message};for(let o of["inputAmount","outputAmount","startTime","endTime"])a[o]!=null&&(a[o]=BigInt(a[o]));let h=r.domain;if(h.chainId!=null){let o=Number(h.chainId);await Hr(l,o)}let y=await Kr(l,{account:c,domain:h,types:r.types,primaryType:r.primaryType,message:a}),p=await fetch(`${Re()}/submit-signature`,{method:"POST",headers:Ae(),body:JSON.stringify({quoteId:t.id,signatures:[y]})});if(!p.ok){let o=await p.json().catch(()=>({}));throw new Error(o?.message||`Submit failed: ${p.status}`)}return{quoteId:t.id,signature:y}}catch(r){throw Vt(r)?new Error("User rejected the signing request"):r instanceof Error&&r.message.includes("chain")?new Error("Chain switching failed. Please manually switch to the correct network."):r}};var qt="vt_submitted_quotes";var lt=()=>{try{let e=localStorage.getItem(qt);return e?JSON.parse(e):[]}catch{return[]}},Qt=e=>{try{localStorage.setItem(qt,JSON.stringify(e))}catch{}},Xr=e=>{let t=Date.now(),s=typeof e=="string"?new Date(e).getTime():e>9999999999?e:e*1e3;return t<s+3e4},Yr=e=>lt().some(t=>t.quoteId===e),jt=(e,t)=>Yr(e)?{canSubmit:!1,reason:"Order already submitted"}:Xr(t)?{canSubmit:!0}:{canSubmit:!1,reason:"Quote has expired"},zt=(e,t)=>{let s=typeof t=="string"?new Date(t).getTime():t,c=lt();c.push({quoteId:e,submittedAt:Date.now(),createdAt:s}),Qt(c)},Gt=()=>{let e=lt(),t=Date.now(),s=300*1e3,c=e.filter(l=>t-l.submittedAt<s);c.length!==e.length&&Qt(c)};import{useMutation as Jr}from"@tanstack/react-query";import{waitForTransactionReceipt as Zr}from"@wagmi/core";import{wethAbi as en}from"abitype/abis";import{useConfig as tn}from"wagmi";function Kt(){let e=tn();return Jr({mutationFn:async({chainId:t,accountAddress:s,amountRaw:c,writeContractAsync:l})=>{let r=j(t);if(!r)throw new Error(`No wrapping contract for chain ${t}`);let a=r.wrappedAsset.address,h=await l({abi:en,functionName:"withdraw",address:a,account:s,args:[c],chainId:t});if((await Zr(e,{hash:h,chainId:t,confirmations:1,pollingInterval:4e3})).status!=="success")throw new Error("Unwrap transaction did not get successful receipt");return{success:!0,hash:h}}})}import{useMutation as rn}from"@tanstack/react-query";import{waitForTransactionReceipt as nn}from"@wagmi/core";import{wethAbi as sn}from"abitype/abis";import{useConfig as on}from"wagmi";function Ht(){let e=on();return rn({mutationFn:async({chainId:t,accountAddress:s,amountRaw:c,writeContractAsync:l})=>{let r=j(t);if(!r)throw new Error(`No wrapping contract for chain ${t}`);let a=r.wrappedAsset.address,h=await l({abi:sn,functionName:"deposit",address:a,account:s,value:c,chainId:t});if((await nn(e,{hash:h,chainId:t,confirmations:1,pollingInterval:4e3})).status!=="success")throw new Error("Wrap transaction did not get successful receipt");return{success:!0,hash:h}}})}import{useCallback as pe,useEffect as Pe,useRef as gr,useState as Fn}from"react";import{useChainId as qn}from"wagmi";import{useCallback as Xt,useRef as an}from"react";function Yt(){let{registerTransaction:e,enabled:t}=Bt(),s=an(new Set),c=Xt((r,a)=>{!t||s.current.has(r)||(s.current.add(r),e(r,a))},[t,e]),l=Xt((r,a)=>{!t||s.current.has(r)||(s.current.add(r),e(r,a))},[t,e]);return{trackOrderTransaction:c,trackNativeTransaction:l,txTrackingEnabled:t}}import{useEffect as Jt,useState as cn,useCallback as Zt,useRef as ut}from"react";import{useAccount as ln,useChainId as un,useSwitchChain as dn}from"wagmi";import{jsx as we,jsxs as dt}from"react/jsx-runtime";var pn=15e3,Ge="chain",mn=({needsChainSwitch:e,requiredChain:t,reviewState:s,goToNextStep:c,cancel:l})=>{let r=re(Ge,s),[a,h]=cn("pending"),y=ut(!1),p=ut(!1),o=ut(null),n=un(),{switchChainAsync:b}=dn(),{status:w,isReconnecting:d}=ln(),f=Zt(()=>{o.current&&(clearTimeout(o.current),o.current=null)},[]),g=Zt(async()=>{if(!(y.current||p.current||w!=="connected"||d)){y.current=!0,p.current=!0,h("pending"),o.current=setTimeout(()=>{y.current&&(h("error"),y.current=!1)},pn);try{await b({chainId:t.chainId}),f(),h("success"),c(Ge,s)}catch{f(),h("error")}finally{y.current=!1}}},[b,w,d,t.chainId,c,s,f]);Jt(()=>{y.current||p.current||s===Ge&&a==="pending"&&w==="connected"&&!d&&(e&&n!==t.chainId?g():(h("success"),c(Ge,s)))},[s,a,e,n,t.chainId,w,d,g,c]),Jt(()=>()=>f(),[f]);let i=()=>{a==="error"&&(p.current=!1,h("pending"))},m=!r&&a==="error",v=!r&&(a==="pending"||a==="error"),u=m?"var(--widget-status-failed)":"var(--widget-status-pending)";return dt("div",{className:"flex w-full flex-row justify-between space-x-3",children:[we("button",{type:"button",className:`inline-flex h-12 w-full items-center justify-center text-sm font-medium transition duration-150 ${m?"cursor-pointer":"cursor-not-allowed"}`,style:{backgroundColor:`color-mix(in srgb, ${u} 12%, transparent)`,border:`1px solid color-mix(in srgb, ${u} 20%, transparent)`,color:u,borderRadius:"var(--widget-radius)"},onClick:m?i:void 0,children:dt("div",{className:"flex h-10 w-full flex-row items-center space-x-3 px-4",children:[we(Me,{chain:t.chainId,size:"xs"}),we("p",{className:"whitespace-nowrap",children:m?"Retry Switch":`Switch to ${t.name}`}),we("div",{className:"flex flex-1 border-t",style:{borderColor:"var(--widget-border)"}}),dt("div",{className:"flex h-6 w-3 items-center justify-center rounded-full",children:[!r&&a==="pending"&&we(G,{size:"5"}),(r||a==="success")&&we(Y,{className:"h-8 w-8"}),m&&we(ge,{className:"h-[12px] w-[12px]"})]})]})}),v&&we("button",{type:"button",className:"inline-flex h-12 items-center justify-center px-8 text-sm font-medium transition duration-150 cursor-pointer",style:{backgroundColor:"color-mix(in srgb, var(--widget-status-failed) 12%, transparent)",border:"1px solid color-mix(in srgb, var(--widget-status-failed) 20%, transparent)",color:"var(--widget-status-failed)",borderRadius:"var(--widget-radius)"},onClick:l,children:"Cancel"})]})},er=mn;import{waitForTransactionReceipt as wn}from"@wagmi/core";import{useCallback as Ke,useEffect as He,useState as bn,useRef as or}from"react";import{useAccount as hn,useConfig as yn,useSendTransaction as vn,useSwitchChain as xn,useWalletClient as Cn}from"wagmi";import{useEffect as tr,useRef as rr,useState as nr}from"react";import{jsx as gn}from"react/jsx-runtime";var fn=({startTime:e,onExpired:t})=>{let[s,c]=nr(30),[l,r]=nr(!1),a=rr(!1),h=rr(t);h.current=t,tr(()=>{a.current=!1},[e]),tr(()=>{let p=()=>{let n=Date.now(),w=(e>9999999999?e:e*1e3)+30*1e3,d=Math.max(0,w-n),f=Math.floor(d/1e3);if(f<=0){c(0),a.current||(a.current=!0,r(!0),h.current());return}c(f),r(!1)};if(l)return;p();let o=setInterval(p,1e3);return()=>clearInterval(o)},[e,l]);let y=p=>{let o=Math.floor(p/60),n=p%60;return`${o.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`};return l?null:gn("span",{className:"text-xs font-mono",children:y(s)})},sr=fn;import{jsx as de,jsxs as pt}from"react/jsx-runtime";function Sn(e){return e.name==="UserRejectedRequestError"||e.message.includes("User rejected")||e.message.includes("rejected")||e.message.includes("denied")||e.message.includes("cancelled")||e.message.includes("canceled")}var be="signingOrder";async function Tn(e,t,s,c,l){let r=e.transaction?.encoded,a=r?.to??e.to,h=r?.data??e.data,y=r?.value??e.value;if(!a)throw new Error('Transaction step missing "to" address');let p=r?.chainId,o=e.chainKey||l,n=p||(o?tt(o):void 0);if(!n)throw new Error(`Unknown chain: ${o}`);let b=vt()[n],w=await s({account:t,chain:b,to:a,data:h||"0x",value:BigInt(y||"0")});return await wn(c,{hash:w,chainId:n}),w}var Rn=({base:e,baseAmount:t,quote:s,quoteAmount:c,userAddress:l,reviewState:r,goToNextStep:a,cancel:h,isWrappingPair:y,isUnwrappingPair:p,restartSigningFlow:o,onSwapInitiated:n,onOrderSubmitted:b,onSwapComplete:w,startPolling:d,trackNativeTransaction:f})=>{let g=re(be,r),[i,m]=bn("idle"),v=or(!1),u=or(null),T=yn(),{isReconnecting:P}=hn(),{rfqQuote:C,stop:$,refresh:L}=Ve(),{data:N}=Cn({chainId:e.chainId}),{switchChain:E}=xn(),{sendTransactionAsync:I}=vn(),U=C?._receivedAt??0,B=Ke(()=>U?Date.now()>=U+30*1e3:!1,[U]),oe=Ke(async()=>{if(v.current||!["idle","error"].includes(i))return;if(!C?.id||!C?._receivedAt){m("error");return}if(!jt(C.id,C._receivedAt).canSubmit){m("stale");return}v.current=!0;try{if(!N)throw new Error("Wallet client not available");Gt();let S=C.userSteps??[],O;for(let A of S)if(A.type==="TRANSACTION"){m("submitting");let q=A.chainKey||C.srcChainKey,Z=q?tt(q):void 0;Z&&N.chain?.id!==Z&&(await E({chainId:Z}),await new Promise(Le=>setTimeout(Le,800))),O=await Tn(A,l,I,T,C.srcChainKey),f(O,A.description||`Tx on ${q}`)}else A.type==="SIGNATURE"&&(m("signing"),await Ft({quote:C,signatureStep:A,userAddress:l,walletClient:N}));zt(C.id,C._receivedAt),b?.(C.id),d(C.id,{baseToken:e,quoteToken:s}),n?.(),$(),m("success"),a(be,r),w?.(C.id)}catch(S){S instanceof Error&&Sn(S)?(u.current=null,m("idle")):m("error")}finally{v.current=!1}},[i,C,N,e,s,l,$,d,a,r,w,E,I,n,b,f,T]);He(()=>{if(r===be&&$(),g&&i!=="success"){m("success"),a(be,r);return}if(i==="success"){a(be,r);return}if(r===be&&i==="idle"&&!C?.id){m("refreshingQuote"),L();return}if(r===be&&i==="idle"&&N&&!v.current&&!P){let x=C?.id||null;x&&u.current!==x&&(u.current=x,oe())}},[g,r,i,N,P,oe,a,C?.id,L,$]),He(()=>{i==="refreshingQuote"&&C?.id&&m("idle")},[i,C?.id]),He(()=>{r!==be&&(u.current=null)},[r]),He(()=>{let x=setInterval(()=>{B()&&!v.current&&i!=="submitting"&&i!=="success"&&m("stale")},1e3);return()=>clearInterval(x)},[B,i]);let H=()=>{i==="error"&&!v.current&&(u.current=null,m("idle"))},W=Ke(()=>{u.current=null,m("refreshingQuote"),L()},[L]),R=Ke(()=>{o?o(!0):h()},[o,h]),V=()=>i==="error"?"Retry swap":i==="signing"?"Sign Swap Order":i==="submitting"?"Submitting...":i==="refreshingQuote"?"Refreshing Quote...":i==="stale"?"Quote Stale":"Sign & Submit",F=!g&&(i==="error"||i==="stale"),X=F?"var(--widget-status-failed)":"var(--widget-status-pending)";return pt("div",{className:"flex w-full flex-row justify-between space-x-3",children:[de("button",{type:"button",className:`inline-flex h-12 w-full items-center justify-center text-sm font-medium transition duration-150 ${F?"cursor-pointer":"cursor-not-allowed"}`,style:{backgroundColor:`color-mix(in srgb, ${X} 12%, transparent)`,border:`1px solid color-mix(in srgb, ${X} 20%, transparent)`,color:X,borderRadius:"var(--widget-radius)"},onClick:!g&&i==="error"?H:i==="stale"?R:void 0,children:pt("div",{className:"flex h-10 w-full flex-row items-center space-x-3 px-4",children:[de(ce,{asset:e,size:"xs",noChain:!0}),de("p",{className:"whitespace-nowrap",children:V()}),de("div",{className:"flex flex-1 border-t",style:{borderColor:"var(--widget-border)"}}),U>0&&i!=="success"&&i!=="error"&&i!=="stale"&&de(sr,{startTime:U,onExpired:()=>m("stale")}),pt("div",{className:"flex h-6 w-3 items-center justify-center rounded-full",children:[!g&&(i==="idle"||i==="signing"||i==="submitting"||i==="refreshingQuote")&&de(G,{size:"5"}),(g||i==="success")&&de(Y,{className:"h-8 w-8"}),!g&&(i==="error"||i==="stale")&&de(ge,{className:"h-[12px] w-[12px]"})]})]})}),!g&&i==="error"&&de("button",{type:"button",className:"inline-flex h-12 items-center justify-center px-8 text-sm font-medium transition duration-150 cursor-pointer",style:{backgroundColor:"color-mix(in srgb, var(--widget-status-failed) 12%, transparent)",border:"1px solid color-mix(in srgb, var(--widget-status-failed) 20%, transparent)",color:"var(--widget-status-failed)",borderRadius:"var(--widget-radius)"},onClick:h,children:"Cancel"})]})},ir=Rn;import{useEffect as An}from"react";import{jsx as J,jsxs as En}from"react/jsx-runtime";var kn="trackingTx",ar={pending:{icon:J(G,{size:"5"}),buttonText:"Trade Pending",showNewSwap:!1,statusVar:"var(--widget-status-pending)",clickable:!1},received:{icon:J(G,{size:"5"}),buttonText:"Trade Received",showNewSwap:!1,statusVar:"var(--widget-status-received)",clickable:!1},completed:{icon:J(Y,{}),buttonText:"Continue Swapping",showNewSwap:!0,statusVar:"var(--widget-status-completed)",clickable:!0},failed:{icon:J(We,{}),buttonText:"Retry Swap",showNewSwap:!0,statusVar:"var(--widget-status-failed)",clickable:!0},cancelled:{icon:J(We,{}),buttonText:"Continue Swapping",showNewSwap:!0,statusVar:"var(--widget-status-failed)",clickable:!0}},Nn=({orderHash:e,base:t,quote:s,baseAmount:c,quoteAmount:l,reviewState:r,onNewSwap:a,onRetry:h,status:y})=>{let p=re(kn,r),o=ar[y]||ar.pending;An(()=>{if(y==="completed"){let w=setTimeout(a,5e3);return()=>clearTimeout(w)}},[y,a]);let n=()=>{y==="failed"?h():o.showNewSwap&&a()},b=o.statusVar;return J("div",{className:"flex flex-row justify-between space-x-3 w-full",children:J("button",{type:"button",className:`inline-flex h-12 w-full items-center justify-center text-sm font-medium transition duration-150 ${o.clickable?"cursor-pointer":"cursor-not-allowed"}`,style:{backgroundColor:`color-mix(in srgb, ${b} 12%, transparent)`,border:`1px solid color-mix(in srgb, ${b} 20%, transparent)`,color:b,borderRadius:"var(--widget-radius)"},onClick:o.showNewSwap?n:void 0,children:En("div",{className:"flex h-10 w-full flex-row items-center space-x-3 px-4",children:[J("div",{className:"flex h-6 w-6 items-center justify-center rounded-full",children:o.icon}),J("p",{className:"whitespace-nowrap",children:o.buttonText}),J("div",{className:"flex flex-1 border-t",style:{borderColor:"var(--widget-border)"}}),o.showNewSwap&&J("div",{className:"flex h-6 w-6 items-center justify-center",children:J(kt,{})})]})})})},cr=Nn;import{useCallback as lr,useEffect as ur,useState as In,useRef as mt}from"react";import{parseUnits as On}from"viem";import{useAccount as Pn,useWriteContract as $n}from"wagmi";import{jsx as ve,jsxs as ft}from"react/jsx-runtime";var Un=15e3,Xe="unwrapping",Mn=({needsToUnwrap:e,amount:t,chainId:s,token:c,reviewState:l,setReviewState:r,goToNextStep:a,cancel:h,delayedClose:y})=>{let p=re(Xe,l),[o,n]=In("idle"),b=Kt(),{writeContractAsync:w}=$n(),{address:d}=ne(),f=Ee(),g=mt(!1),i=mt(!1),m=mt(null),{status:v}=Pn(),u=lr(()=>{m.current&&(clearTimeout(m.current),m.current=null)},[]),T=lr(async()=>{if(!(g.current||i.current||!d||v!=="connected")){g.current=!0,i.current=!0,n("pending"),m.current=setTimeout(()=>{g.current&&(n("error"),g.current=!1)},Un);try{let N=j(s);if(!N)throw new Error(`No config for chain ${s}`);let E=N.wrappedAsset.decimals??N.nativeAsset.decimals,I=On(t.toString(),E);await b.mutateAsync({chainId:s,accountAddress:d,amountRaw:I,writeContractAsync:w});let U={symbol:N.nativeAsset.symbol,name:N.nativeAsset.name,address:_e,decimals:N.nativeAsset.decimals,chainId:s},B={symbol:N.wrappedAsset.symbol,name:N.wrappedAsset.name,address:N.wrappedAsset.address,decimals:N.wrappedAsset.decimals,chainId:s};f({type:"unwrap",tokens:[{asset:U,userAddress:d},{asset:B,userAddress:d}]}),u(),n("success"),a(Xe,l),await y()}catch{u(),n("error")}finally{g.current=!1}}},[d,v,s,t,b,w,f,a,l,y,u]);ur(()=>{g.current||i.current||l===Xe&&o==="idle"&&v==="connected"&&(e?T():(n("success"),a(Xe,l)))},[l,o,e,v,T,a]),ur(()=>()=>u(),[u]);let P=()=>{o==="error"&&(i.current=!1,n("idle"))},C=!p&&o==="error",$=!p&&(o==="pending"||o==="idle"||o==="error"),L=C?"var(--widget-status-failed)":"var(--widget-status-pending)";return ft("div",{className:"flex w-full flex-row justify-between space-x-3",children:[ve("button",{type:"button",className:`inline-flex h-12 w-full items-center justify-center text-sm font-medium transition duration-150 ${C?"cursor-pointer":"cursor-not-allowed"}`,style:{backgroundColor:`color-mix(in srgb, ${L} 12%, transparent)`,border:`1px solid color-mix(in srgb, ${L} 20%, transparent)`,color:L,borderRadius:"var(--widget-radius)"},onClick:C?P:void 0,children:ft("div",{className:"flex h-10 w-full flex-row items-center space-x-3 px-4",children:[ve("p",{className:"whitespace-nowrap",children:C?"Retry Unwrap":c?`Unwrap ${c.symbol}`:"Unwrap Native Token"}),ve("div",{className:"flex flex-1 border-t",style:{borderColor:"var(--widget-border)"}}),ft("div",{className:"flex h-6 w-3 items-center justify-center rounded-full",children:[!p&&(o==="pending"||o==="idle")&&ve(G,{size:"5"}),(p||o==="success")&&ve(Y,{className:"h-8 w-8"}),C&&ve(ge,{className:"h-[12px] w-[12px]"})]})]})}),$&&ve("button",{type:"button",className:"inline-flex h-12 items-center justify-center px-8 text-sm font-medium transition duration-150 cursor-pointer",style:{backgroundColor:"color-mix(in srgb, var(--widget-status-failed) 12%, transparent)",border:"1px solid color-mix(in srgb, var(--widget-status-failed) 20%, transparent)",color:"var(--widget-status-failed)",borderRadius:"var(--widget-radius)"},onClick:h,children:"Cancel"})]})},dr=Mn;import{useCallback as pr,useEffect as mr,useState as Dn,useRef as gt}from"react";import{parseUnits as Wn}from"viem";import{useAccount as Ln,useWriteContract as Bn}from"wagmi";import{jsx as xe,jsxs as wt}from"react/jsx-runtime";var _n=15e3,Ye="wrapping",Vn=({needsToWrap:e,amount:t,chainId:s,token:c,reviewState:l,setReviewState:r,goToNextStep:a,cancel:h,delayedClose:y,isWrappingPair:p})=>{let o=re(Ye,l),[n,b]=Dn("idle"),w=Ht(),{writeContractAsync:d}=Bn(),{address:f}=ne(),g=Ee(),i=gt(!1),m=gt(!1),v=gt(null),{status:u}=Ln(),T=pr(()=>{v.current&&(clearTimeout(v.current),v.current=null)},[]),P=pr(async()=>{if(!(i.current||m.current||!f||u!=="connected")){i.current=!0,m.current=!0,b("pending"),v.current=setTimeout(()=>{i.current&&(b("error"),i.current=!1)},_n);try{let E=j(s);if(!E)throw new Error(`No config for chain ${s}`);let I=Wn(t.toString(),E.nativeAsset.decimals);await w.mutateAsync({chainId:s,accountAddress:f,amountRaw:I,writeContractAsync:d});let U={symbol:E.nativeAsset.symbol,name:E.nativeAsset.name,address:_e,decimals:E.nativeAsset.decimals,chainId:s},B={symbol:E.wrappedAsset.symbol,name:E.wrappedAsset.name,address:E.wrappedAsset.address,decimals:E.wrappedAsset.decimals,chainId:s};g({type:"wrap",tokens:[{asset:U,userAddress:f},{asset:B,userAddress:f}]}),T(),b("success"),a(Ye,l),p&&await y()}catch{T(),b("error")}finally{i.current=!1}}},[f,u,s,t,w,d,g,a,l,y,p,T]);mr(()=>{i.current||m.current||l===Ye&&n==="idle"&&u==="connected"&&(e?P():(b("success"),a(Ye,l)))},[l,n,e,u,P,a]),mr(()=>()=>T(),[T]);let C=()=>{n==="error"&&(m.current=!1,b("idle"))},$=!o&&n==="error",L=!o&&(n==="pending"||n==="idle"||n==="error"),N=$?"var(--widget-status-failed)":"var(--widget-status-pending)";return wt("div",{className:"flex w-full flex-row justify-between space-x-3",children:[xe("button",{type:"button",className:`inline-flex h-12 w-full items-center justify-center text-sm font-medium transition duration-150 ${$?"cursor-pointer":"cursor-not-allowed"}`,style:{backgroundColor:`color-mix(in srgb, ${N} 12%, transparent)`,border:`1px solid color-mix(in srgb, ${N} 20%, transparent)`,color:N,borderRadius:"var(--widget-radius)"},onClick:$?C:void 0,children:wt("div",{className:"flex h-10 w-full flex-row items-center space-x-3 px-4",children:[xe("p",{className:"whitespace-nowrap",children:$?"Retry Wrap":c?`Wrap ${c.symbol}`:"Wrap Native Token"}),xe("div",{className:"flex flex-1 border-t",style:{borderColor:"var(--widget-border)"}}),wt("div",{className:"flex h-6 w-3 items-center justify-center rounded-full",children:[!o&&(n==="pending"||n==="idle")&&xe(G,{size:"5"}),(o||n==="success")&&xe(Y,{className:"h-8 w-8"}),$&&xe(ge,{className:"h-[12px] w-[12px]"})]})]})}),L&&xe("button",{type:"button",className:"inline-flex h-12 items-center justify-center px-8 text-sm font-medium transition duration-150 cursor-pointer",style:{backgroundColor:"color-mix(in srgb, var(--widget-status-failed) 12%, transparent)",border:"1px solid color-mix(in srgb, var(--widget-status-failed) 20%, transparent)",color:"var(--widget-status-failed)",borderRadius:"var(--widget-radius)"},onClick:h,children:"Cancel"})]})},fr=Vn;import{jsx as Q,jsxs as Qn}from"react/jsx-runtime";var Si=({base:e,baseAmount:t,quote:s,quoteAmount:c,userAddress:l,isWrappingPair:r,isUnwrappingPair:a,isBaseGasToken:h,isQuoteGasToken:y,reviewActionProps:p,reviewState:o,setReviewState:n,trackedOrderHash:b,setTrackedOrderHash:w,txStatus:d,onSwapComplete:f,onSwapInitiated:g,onOrderSubmitted:i,onStaleQuoteRestart:m,setExitHandler:v,setRetryHandler:u})=>{let{rfqQuote:T,status:P,liquidityError:C,routingError:$,sizeCapError:L,stop:N,clear:E}=Ve(),{clearForm:I}=Ne(),U=qn(),{swapButtonVariant:B,widgetType:oe}=Te(),H=oe==="compact",{trackOrderTransaction:W,trackNativeTransaction:R}=Yt(),{startPolling:V}=Lt((_,fe)=>{he.getState().setTxStatus(fe),fe==="completed"&&W(_,`Swap ${e.symbol} \u2192 ${s.symbol}`)}),[F,X]=Fn(!1),x=gr(!1),S=gr(null),O=r,A=a,q=!r&&!a,Z=U!==e?.chainId&&(O||A||q),Le=j(e.chainId),Be={chainId:e.chainId,name:Le?.displayName??`Chain ${e.chainId}`},z=pe((_,fe)=>{if(fe!==_)return;if(_==="chain"){if(O){n("wrapping");return}if(A){n("unwrapping");return}n("signingOrder");return}if(_==="signingOrder"){n("trackingTx");return}if(_==="wrapping"){if(!r){n("signingOrder");return}n("wrapSuccess");return}if(_==="unwrapping"){n("wrapSuccess");return}let yt=Ct(_);yt&&n(yt)},[n,r,O,A,q]),ie=pe(()=>Z?"chain":O?"wrapping":A?"unwrapping":q?"signingOrder":null,[Z,O,A,q]),ee=pe(()=>{n(null),I()},[I,n]),Ce=pe(async()=>{n("wrapSuccess");for(let _=0;_<3;_++)await Ze(700);ee()},[ee,n]),te=pe(async()=>{E(),n("cancelled");for(let _=0;_<3;_++)await Ze(500);ee()},[E,ee,n]),me=pe(()=>{b&&(he.getState().stopTracking(),n(null),w(null),I())},[b,n,w,I]),$e=pe(()=>{n(null),w(null),x.current=!0,m?.()},[n,w,m]),ae=pe(()=>{p&&n(ie())},[ie,p,n]),Je=pe((_=!1)=>{_?(x.current=!0,n(null),m?.()):(n(null),S.current=setTimeout(()=>{p&&(n(ie()),X(!1))},100))},[n,p,ie,m]);Pe(()=>{o!==null&&N()},[o,N]),Pe(()=>{o!==null&&F&&X(!1)},[o,F]),Pe(()=>{v?.(me)},[v,me]),Pe(()=>{u?.($e)},[u,$e]),Pe(()=>()=>{S.current&&clearTimeout(S.current)},[]),Pe(()=>{x.current&&P==="fresh"&&T?.id&&(x.current=!1,n("signingOrder"))},[P,T?.id,n]);let Ue=_=>{if(!_)return{backgroundColor:B==="default"?"var(--widget-muted)":"transparent",color:"var(--widget-muted-foreground)",border:B!=="default"?"1px solid var(--widget-border)":"none",borderRadius:"var(--widget-radius)"};switch(B){case"outline":return{backgroundColor:"transparent",color:"var(--widget-primary)",border:"1px solid var(--widget-primary)",borderRadius:"var(--widget-radius)"};case"ghost":return{backgroundColor:"transparent",color:"var(--widget-primary)",border:"none",borderRadius:"var(--widget-radius)"};default:return{backgroundColor:"var(--widget-primary)",color:"var(--widget-primary-foreground)",borderRadius:"var(--widget-radius)"}}},Se=`w-full ${H?"py-2":"py-3"} text-sm font-medium transition-colors cursor-pointer mt-1`;if(o===null&&!r&&!a){if(F)return Q("button",{className:Se,disabled:!0,style:{...Ue(!1),opacity:.6,cursor:"not-allowed"},children:"Getting fresh quote..."});let _=()=>C?"Insufficient Liquidity":$?"Route Not Available":L?"Size Cap Exceeded":!T&&P==="polling"?"Getting Quote...":T?"Swap":"Enter Amount",fe=!!p;return Q("button",{onClick:fe?ae:void 0,disabled:!fe,className:`${Se} disabled:opacity-40 disabled:cursor-not-allowed`,style:Ue(fe),children:_()})}return o===null&&a?Q("button",{onClick:p?ae:void 0,disabled:!p,className:`${Se} disabled:opacity-40 disabled:cursor-not-allowed`,style:Ue(!!p),children:"Unwrap"}):o===null&&r?Q("button",{onClick:p?ae:void 0,disabled:!p,className:`${Se} disabled:opacity-40 disabled:cursor-not-allowed`,style:Ue(!!p),children:"Wrap"}):o==="success"?Q("div",{className:"flex flex-col gap-2 w-full",children:Q("button",{className:`w-full ${H?"py-2":"py-3"} text-sm font-medium cursor-default`,style:{backgroundColor:"color-mix(in srgb, var(--widget-status-completed) 15%, transparent)",color:"var(--widget-status-completed)",border:"1px solid color-mix(in srgb, var(--widget-status-completed) 20%, transparent)",borderRadius:"var(--widget-radius)"},children:"Order Placed"})}):o==="wrapSuccess"?Q("div",{className:"flex flex-col gap-2 w-full",children:Q("button",{className:`w-full ${H?"py-2":"py-3"} text-sm font-medium cursor-default`,style:{backgroundColor:"color-mix(in srgb, var(--widget-status-completed) 15%, transparent)",color:"var(--widget-status-completed)",border:"1px solid color-mix(in srgb, var(--widget-status-completed) 20%, transparent)",borderRadius:"var(--widget-radius)"},children:r?"Wrapped Successfully":"Unwrapped Successfully"})}):o==="cancelled"?Q("div",{className:"flex flex-col gap-2 w-full",children:Q("button",{onClick:ee,className:`w-full ${H?"py-2":"py-3"} text-sm font-medium cursor-pointer`,style:{backgroundColor:"color-mix(in srgb, var(--widget-status-failed) 15%, transparent)",color:"var(--widget-status-failed)",border:"1px solid color-mix(in srgb, var(--widget-status-failed) 20%, transparent)",borderRadius:"var(--widget-radius)"},children:"Order Cancelled"})}):Qn("div",{className:"flex w-full",children:[o==="chain"&&Z&&Q(er,{requiredChain:Be,needsChainSwitch:Z&&U!==e.chainId,reviewState:o,goToNextStep:z,cancel:te}),o==="wrapping"&&O&&Q(fr,{needsToWrap:O,amount:t,chainId:e.chainId,token:e,reviewState:o,setReviewState:n,goToNextStep:z,cancel:te,delayedClose:Ce,isWrappingPair:r}),o==="unwrapping"&&A&&Q(dr,{needsToUnwrap:A,amount:t,chainId:e.chainId,token:e,reviewState:o,setReviewState:n,goToNextStep:z,cancel:te,delayedClose:Ce}),o==="signingOrder"&&q&&Q(ir,{base:e,baseAmount:t,quote:s,quoteAmount:c,userAddress:l,reviewState:o,goToNextStep:z,cancel:te,restartSigningFlow:Je,onSwapInitiated:g,onOrderSubmitted:i,isWrappingPair:r,isUnwrappingPair:a,onSwapComplete:f,startPolling:V,trackNativeTransaction:R}),o==="trackingTx"&&b&&Q(cr,{orderHash:b,base:e,quote:s,baseAmount:t,quoteAmount:c,reviewState:o,status:d,onNewSwap:me,onRetry:$e}),o&&!["chain","wrapping","unwrapping","approval","signingOrder","trackingTx","success","wrapSuccess","cancelled"].includes(o)&&Q("button",{disabled:!0,className:`w-full ${H?"py-2":"py-3"} text-sm font-medium`,style:{backgroundColor:"var(--widget-muted)",color:"var(--widget-muted-foreground)",borderRadius:"var(--widget-radius)"},children:"Processing..."})]})};import{useState as wr,useCallback as jn,useRef as bt,useEffect as ht}from"react";import{useShallow as zn}from"zustand/react/shallow";import{jsx as k,jsxs as M}from"react/jsx-runtime";var br={pending:"var(--widget-status-pending)",received:"var(--widget-status-received)",completed:"var(--widget-status-completed)",failed:"var(--widget-status-failed)",cancelled:"var(--widget-status-failed)"},hr={pending:{title:"Trade Pending",subtitle:"Submitting to network"},received:{title:"Trade Received",subtitle:"Processing settlement"},completed:{title:"Trade Filled",subtitle:"Settlement complete"},failed:{title:"Trade Failed",subtitle:"Settlement unsuccessful"},cancelled:{title:"Trade Cancelled",subtitle:"Order was cancelled"}};function Gn(e){let t=br[e]??br.pending;return{textColor:t,bgColor:`color-mix(in srgb, ${t} 15%, transparent)`,borderColor:`color-mix(in srgb, ${t} 20%, transparent)`,cardBgColor:`color-mix(in srgb, ${t} 8%, transparent)`,cardBorderColor:`color-mix(in srgb, ${t} 15%, transparent)`,iconBgColor:`color-mix(in srgb, ${t} 12%, transparent)`,iconBorderColor:`color-mix(in srgb, ${t} 15%, transparent)`}}var Kn=({status:e})=>{switch(e){case"completed":return k(Y,{});case"failed":case"cancelled":return k(We,{});default:return k(G,{size:"10"})}},Hn=({orderHash:e,base:t,quote:s,baseAmount:c,quoteAmount:l,status:r})=>{let[a,h]=wr(!1),y=bt(null),p=bt(Date.now()),[o,n]=wr(null),b=bt(null),{isRecipientInputOpen:w,recipient:d}=he(zn(u=>({isRecipientInputOpen:u.isRecipientInputOpen,recipient:u.recipient})));ht(()=>{r==="received"&&(y.current=Date.now())},[r]),ht(()=>{if(r==="completed"&&!o){let u=y.current||p.current;n((Date.now()-u)/1e3)}},[r,o]),ht(()=>()=>{b.current&&clearTimeout(b.current)},[]);let f=jn(()=>{navigator.clipboard?.writeText&&navigator.clipboard.writeText(e).then(()=>{h(!0),b.current&&clearTimeout(b.current),b.current=setTimeout(()=>h(!1),2e3)}).catch(()=>{})},[e]),g=hr[r]??hr.pending,i=Gn(r),m=ke(c),v=ke(l);return k("div",{className:"relative w-full h-full overflow-hidden flex flex-col",style:{backgroundColor:i.bgColor,border:`1px var(--widget-border-style) ${i.borderColor}`,backdropFilter:"blur(8px)"},children:M("div",{className:"relative z-10 px-3 pt-5 pb-3 flex-1 flex flex-col",children:[k("div",{className:"flex items-center justify-center mb-2",children:M("div",{className:"flex flex-col items-center gap-1 text-center",children:[k("div",{className:"flex h-10 w-10 items-center justify-center rounded-full border",style:{backgroundColor:i.iconBgColor,borderColor:i.iconBorderColor},children:k("div",{className:"h-7 w-7 flex items-center justify-center",children:k(Kn,{status:r})})}),M("div",{children:[k("h3",{className:"text-xl font-bold",style:{color:i.textColor},children:g.title}),k("p",{className:"text-2xs uppercase tracking-wider",style:{color:i.textColor,opacity:.6},children:g.subtitle})]})]})}),k("div",{className:"flex-1 flex flex-col justify-center",children:M("div",{className:"space-y-1.5",children:[M("div",{className:"flex items-center justify-between backdrop-blur-sm p-2.5 border transition-all duration-300",style:{backgroundColor:i.cardBgColor,borderColor:i.cardBorderColor},children:[M("div",{className:"flex items-center gap-2.5",children:[k(ce,{asset:t,size:"sm"}),M("div",{children:[k("div",{className:"text-sm font-bold",style:{color:i.textColor},children:t.symbol}),k("div",{className:"text-2xs",style:{color:i.textColor,opacity:.5},children:t.name})]})]}),M("div",{className:"text-right",children:[k("div",{className:"text-lg font-bold mono",style:{color:i.textColor},children:m}),t.price&&M("div",{className:"text-2xs mono",style:{color:i.textColor,opacity:.5},children:["$",(t.price*c).toFixed(2)]})]})]}),k("div",{className:"flex justify-center pb-0.5 pt-1",children:k("div",{className:"flex h-6 w-6 items-center justify-center rounded-full border",style:{backgroundColor:i.cardBgColor,borderColor:i.cardBorderColor},children:k("span",{className:"text-base",style:{color:i.textColor},children:"\u2193"})})}),M("div",{className:"flex items-center justify-between backdrop-blur-sm p-2.5 border transition-all duration-300",style:{backgroundColor:i.cardBgColor,borderColor:i.cardBorderColor},children:[M("div",{className:"flex items-center gap-2.5",children:[k(ce,{asset:s,size:"sm"}),M("div",{children:[k("div",{className:"text-sm font-bold",style:{color:i.textColor},children:s.symbol}),k("div",{className:"text-2xs",style:{color:i.textColor,opacity:.5},children:s.name})]})]}),M("div",{className:"text-right",children:[k("div",{className:"text-lg font-bold mono",style:{color:i.textColor},children:v}),s.price&&M("div",{className:"text-2xs mono",style:{color:i.textColor,opacity:.5},children:["$",(s.price*l).toFixed(2)]})]})]}),w&&d&&M("div",{className:"mt-1.5",children:[k("div",{className:"text-2xs mb-0.5 uppercase tracking-wider font-medium",style:{color:i.textColor,opacity:.5},children:"Recipient"}),k("div",{className:"flex items-center backdrop-blur-sm p-2 border transition-all duration-300",style:{backgroundColor:i.cardBgColor,borderColor:i.cardBorderColor},children:M("div",{className:"flex items-center gap-2",children:[k("div",{className:"flex h-5 w-5 items-center justify-center overflow-hidden rounded-full",style:{backgroundColor:i.iconBgColor},children:k("span",{className:"text-2xs",children:"\u{1F464}"})}),M("div",{className:"flex flex-col",children:[k("div",{className:"text-2xs",style:{color:i.textColor,opacity:.5},children:"To:"}),M("div",{className:"text-xs mono",style:{color:i.textColor},children:[d.slice(0,6),"...",d.slice(-4)]})]})]})})]})]})}),M("div",{className:"mt-3 pt-2.5 space-y-1.5",style:{borderTop:`1px solid ${i.cardBorderColor}`},children:[M("div",{role:"button",tabIndex:0,onClick:f,onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&(u.preventDefault(),f())},className:"flex items-center justify-between cursor-pointer group hover:opacity-80 transition-opacity",children:[k("div",{className:"text-xs uppercase tracking-wider font-medium",style:{color:i.textColor,opacity:.5},children:a?"Copied!":r==="completed"||r==="failed"||r==="cancelled"?"Order Hash":r==="received"?"Received":"Pending"}),M("div",{className:"text-xs mono transition-colors",style:{color:i.textColor},children:[e.slice(0,6),"...",e.slice(-4)]})]}),r==="completed"&&o?M("div",{className:"flex items-center justify-between",children:[k("div",{className:"text-xs uppercase tracking-wider font-medium",style:{color:i.textColor,opacity:.5},children:"Speed"}),M("div",{className:"text-base font-bold mono",style:{color:i.textColor},children:[o.toFixed(2),"s"]})]}):k("div",{className:"h-5"})]})]})})},Oi=Hn;export{Tr as a,Ee as b,ts as c,ls as d,Ve as e,Wr as f,ms as g,ys as h,Rs as i,Ps as j,Dt as k,Lt as l,Bt as m,Hr as n,Ft as o,Xr as p,jt as q,zt as r,Gt as s,Kt as t,Ht as u,Si as v,Oi as w};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import{c as s}from"./chunk-7QJJOVSV.js";import{b as p}from"./chunk-VI4ISTPB.js";import{useMemo as f}from"react";function m(){let{supportedInputTokens:t,supportedOutputTokens:n,supportedInputChains:o,supportedOutputChains:u}=p(),e=s(i=>i.isInverted);return f(()=>({effectiveInputTokens:e?n:t,effectiveOutputTokens:e?t:n,effectiveInputChains:e?u:o,effectiveOutputChains:e?o:u}),[e,t,n,o,u])}export{m as a};
|