@xswap-link/sdk 0.10.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -88,7 +88,7 @@ nuik2Z3UwnCBNAiE2pBa3qQbD26+YBAnrbNmr4xK8wpDThAKwhdiuoIjum4saQg0VdFRVSxiR01e
|
|
|
88
88
|
EEYyDQde+0pTfR+Wmen0BJLu0r6ONsMwNA4n0jC0MEyNMBVG+JhcW37DNCMzk6fe0P6/6ZaOfwAl
|
|
89
89
|
LqsAAAAldEVYdGRhdGU6Y3JlYXRlADIwMjQtMDUtMjdUMTE6NTQ6MjkrMDA6MDCo6mafAAAAJXRF
|
|
90
90
|
WHRkYXRlOm1vZGlmeQAyMDI0LTA1LTI3VDExOjU0OjI5KzAwOjAw2bfeIwAAAABJRU5ErkJggg==`})});var j1=require("react"),so=()=>(0,j1.useMemo)(()=>({query:async(t,e,r=[])=>t?.provider?await t[e](...r):null,execute:async(t,e,r=[],n={})=>{try{if(t?.provider){let i=await t.estimateGas[e](...r,n);return n.gasLimit||(n.gasLimit=Math.floor(i.toNumber()*Hc)),await t[e](...r,n)}return null}catch(i){let a;try{a=t?.interface.parseError(i?.error?.data?.data)}catch{throw i?.error?.data?.message?new Error(i?.error?.data?.message):i}throw new Error(a?.name)}},executeCalldata:async(t,e)=>{try{let r=await t.estimateGas({...e});return await t.sendTransaction({...e,gasLimit:Math.floor(r.toNumber()*Hc)})}catch(r){throw r?.error?.data?.message?new Error(r?.error?.data?.message):r}}}),[]),hf=so;var G5=require("react");var Fs=require("react"),$1=({delayMs:t,instantExecution:e})=>{let r=(0,Fs.useRef)(null);return{debounce:(0,Fs.useCallback)(i=>{r.current&&(clearTimeout(r.current),r.current=null),e&&e(),r.current=setTimeout(i,t)},[t,e])}};var z5=require("react"),PC=new fe.utils.Interface(c1);var ep=Et(require("bignumber.js")),tp=require("notistack"),gt=require("react"),rp=require("wagmi"),Pn=require("react/jsx-runtime"),np=(0,gt.createContext)({}),ip="pending_transactions",xf=()=>Pt?{}:JSON.parse(localStorage.getItem(ip)||"{}"),mf=t=>{Pt||localStorage.setItem(ip,JSON.stringify(t))},ap=({children:t})=>{let{address:e}=(0,rp.useAccount)(),[r,n]=(0,gt.useState)([]),[i,a]=(0,gt.useState)(!1),{enqueueSnackbar:o,closeSnackbar:f}=(0,tp.useSnackbar)(),{debounce:d}=$1({delayMs:600});(0,gt.useEffect)(()=>{Pt||localStorage.removeItem("transactions-history")},[]);let p=(0,gt.useCallback)(async()=>{try{if(!e)return;let A=await Ms({walletAddress:e}),_=[];for(let M of A.history){if(!M.source)continue;let V;M.failed&&(V="REVERTED"),M.target?V="DONE":V="IN_PROGRESS";let F=new Date(M.source?.blockTime).getTime(),B=Cs;if(new ep.default(M.source.valueForInstantCcipRecieve||"0").gt(0))B=F+30*1e3;else{let J=F+ys?.[M.source.blockchainId]?.[M.source.targetBlockchainId];J&&(B=J)}_.push({messageId:M.messageId,hash:M.source.transactionHash,timestamp:F/1e3,sourceChainId:M.source.blockchainId,targetChainId:M.source.targetBlockchainId,amountWei:M.source.tokenAmount,tokenAddress:M.source.tokenAddress,tokenOutAddress:M.target?.tokenAddress||M.source.tokenOutAddress,tokenOutAmount:M.target?.tokenAmount||M.source.estimatedAmountOut,estimatedDeliveryTimestamp:B,status:V})}let I={};for(let M of _)I[M.hash]=M;let N=xf(),L={};for(let[M,V]of Object.entries(N)){if(M.toLowerCase().toLowerCase()!==e.toLowerCase())continue;let F=[];for(let B of V){if(!I[B.hash]){_.push(B),F.push(B);continue}I[B.hash]&&B.status==="DONE"&&I[B.hash]?.status==="IN_PROGRESS"&&(I[B.hash].status="DONE"),I[B.hash].status==="DONE"||I[B.hash].status}L[M.toLowerCase()]=F}mf(L),n(_.sort((M,V)=>V.timestamp-M.timestamp))}catch(A){console.error(A),o((0,Pn.jsx)(Yn,{message:{text:"Failed to fetch history!",variant:"error"}}),{persist:!1})}finally{a(!0)}},[e,Ms,o]);(0,gt.useEffect)(()=>{i||d(p);let A=setInterval(()=>{d(p)},6e4);return()=>clearInterval(A)},[e,p,Ms,d,i]);let h=(0,gt.useCallback)((A,_)=>{n(I=>{let N=I.filter(M=>M.hash!==A.hash),L=xf();return mf({...L,[_]:[A,...N]}),[A,...N]})},[]),w=(0,gt.useCallback)(A=>{o((0,Pn.jsx)(Yn,{message:{text:"Destination chain transaction mined successfully!",variant:"success",action:()=>(0,Pn.jsxs)("div",{className:"flex items-center flex-nowrap",children:[(0,Pn.jsx)(Ir,{type:"button",onClick:()=>{window.open(`${ua}${A}`)},children:"View"}),(0,Pn.jsx)("div",{className:"transaction-provider__close fill-white leading-[0px]",onClick:()=>f(A),children:(0,Pn.jsx)(lt,{})})]})}}),{persist:!1,key:A})},[o]),E=(0,gt.useCallback)((A,_)=>{n(I=>{let N=I.map(M=>M.hash===A.hash&&M.status!=="DONE"?A:M),L=xf();switch(mf({...L,[_]:[...N]}),A.status){case"DONE":{w(A.hash);break}case"REVERTED":break}return[...N]})},[w]);(0,gt.useEffect)(()=>{a(!1),n([])},[e]);let S=(0,gt.useMemo)(()=>({history:r,addTransactionToLocalHistory:h,updateTransactionInLocalHistory:E,historyLoadedOnce:i}),[r,h,E,i]);return(0,Pn.jsx)(np.Provider,{value:S,children:t})};function xa(){return(0,gt.useContext)(np)}var fp=Et(require("bignumber.js"));var Y=require("react"),dp=require("wagmi");var op=({supportedChains:t})=>{let e=t.find(r=>r.chainId===la)||t[0];if(!e)throw new Error("getDefaultSourceChain > couldn't find default source chain");return e},sp=({supportedChains:t})=>{let e=t.find(r=>r.chainId===ws)||t[0];if(!e)throw new Error("getDefaultDestinationChain > couldn't find default destination chain");return e},Ls=(t,e,r,n)=>{if(!t.tokens.some(f=>f.supported))return;let a=t.tokens.find(f=>f.address.toLowerCase()===e.toLowerCase()&&f.supported);if(a)return a;let o=t.tokens.find(f=>r?f.supported&&f.tokenId!==n:f.supported);if(o)return o},W5=({chain:t,bridgeTokensDictionary:e})=>{if(!t)return;let r=t.tokens.find(i=>i.tokenId==="XSWAP");if(r)return r;let n=Object.keys(e[t.chainId]||{})[0];return t.tokens.find(i=>i.address.toLowerCase()===n?.toLowerCase())},bf=t=>t.swapSupported,gf=({sourceChain:t,targetChain:e})=>{if(!t)throw new Error("isSwapTargetChainValid > sourceChain should be defined.");return e.swapSupported&&t.supportedDstForSwap?.includes(e.chainId)},yf=t=>!t||t.bridgeSupported,cp=({sourceChain:t,targetChain:e,sourceToken:r})=>{let n=!0,i=!0,a=!1;return t&&e&&(n=!!t.supportedDstForBridge?.includes(e.chainId)),r&&e&&(i=!!e.tokens.find(o=>o.tokenId===r.tokenId)),t&&e&&(a=t.chainId===e.chainId),i&&!a&&n},q5=({source:t,target:e,supportedChains:r})=>{let n=t.chain||op({supportedChains:r}),i=e.chain||sp({supportedChains:r}),a=t.token||Ls(n,Dc),o=e.token||Ls(i,Oc,n.chainId===i.chainId,a?.tokenId);if(!n||!i||!a||!o)return{source:{chain:void 0,token:void 0},target:{chain:void 0,token:void 0}};if(!bf(n)&&(n=op({supportedChains:r}),a=void 0,!bf(n)&&(console.error("[WRONG CONFIG] default swap source chain is invalid."),n=r.find(f=>bf(f)),!n)))throw new Error("mapToValidSwap > None of the chains supports swap. Couldn't set source chain.");if(!gf({sourceChain:n,targetChain:i})&&(i=sp({supportedChains:r}),o=void 0,!gf({sourceChain:n,targetChain:i})&&(console.error("[WRONG CONFIG] default swap target chain is invalid."),i=r.find(f=>gf({sourceChain:n,targetChain:f})),!i)))throw new Error("mapToValidSwap > None of the chains supports swap. Couldn't set target chain.");return a=n.tokens.find(f=>f.tokenId===a?.tokenId&&f.supported),o=i.tokens.find(f=>f.tokenId===o?.tokenId&&f.supported),a||(a=Ls(n,Dc)),(!o||a===o)&&(o=Ls(i,Oc,n.chainId===i.chainId,a?.tokenId)),{source:{chain:n,token:a},target:{chain:i,token:o}}},K5=({source:t,target:e,supportedChains:r,bridgeTokensDictionary:n})=>{let i=t.chain,a=e.chain,o=t.token,f=e.token;if(!yf(i)&&(i=void 0,o=void 0,!yf(i)&&(console.error("[WRONG CONFIG] default bridge source chain is invalid."),i=r.find(d=>yf(d)),!i)))throw new Error("mapToValidSwap > None of the chains supports bridge. Couldn't set source chain.");if(cp({sourceChain:i,targetChain:a,sourceToken:o})||(f=void 0,cp({sourceChain:i,targetChain:a,sourceToken:o})||(a=void 0)),o&&i&&(o=i.tokens.find(d=>d.tokenId===o?.tokenId&&d.supported),o&&(Object.keys(n[i.chainId]?.[o.address.toLowerCase()]||{}).length>0||(o=void 0))),f&&a&&(f=a.tokens.find(d=>d.tokenId===f?.tokenId&&d.supported)),!o){let d=W5({chain:i,bridgeTokensDictionary:n});d&&i&&a&&!!n[i.chainId]?.[d.address.toLowerCase()]?.[a.chainId]?o=d:o=void 0}if(o?.tokenId!==f?.tokenId&&(f=void 0),!f)if(o&&i&&a){let d=n[i.chainId]?.[o.address.toLowerCase()]?.[a.chainId];f=a.tokens.find(h=>h.address.toLowerCase()===d?.toLowerCase())}else f=void 0;return!f&&o&&(a=void 0),{source:{chain:i,token:o},target:{chain:a,token:f}}},Ds=({type:t,...e})=>t==="SWAP"?q5(e):K5(e);var pp=require("react/jsx-runtime"),Nt=()=>{throw new Error("Not implemented")},ct={bridgeUI:!1,integrationConfig:{},wagmiConfig:{},supportedChains:[],tab:"Swap",overlay:!1,error:"",feeToken:void 0,srcChain:void 0,srcChainTokensOptions:[],srcChainOtherTokensOptions:[],tokenPrices:{},dstChain:void 0,dstChainTokensOptions:[],dstChainOtherTokensOptions:[],srcToken:void 0,dstTokenLocked:!1,dstChainLocked:!1,srcTokenLocked:!1,srcChainLocked:!1,dstToken:void 0,srcValue:"",srcValueWei:"",srcValueUsd:null,dstValue:"",dstValueWei:"",dstValueUsd:null,dstValueMin:"",expressDelivery:!0,infiniteApproval:!0,slippage:"1.5",route:void 0,isAsyncDataLoaded:!1,srcTokenBalanceWei:"",srcTokenBalanceInfo:"-",isFetchingBalance:!1,isFetchingBalances:!1,isFetchingRoute:!1,isExpressDeliveryActive:!0,setTab:Nt,setError:Nt,setSrcChain:Nt,setDstChain:Nt,setSrcToken:Nt,setDstToken:Nt,setSrcValue:Nt,setExpressDelivery:Nt,setInfiniteApproval:Nt,setSlippage:Nt,setRoute:Nt,setSrcTokenBalanceWei:Nt,quoteRoute:Nt,refreshBalance:Nt,findTokenDataByAddressAndChain:Nt,bridgeTokensDictionary:null,onConnectWallet:Nt,hasOnConnectWalletCallback:!1,srcChainOptions:[],dstChainOptions:[]},lp=(0,Y.createContext)(ct),up=({children:t,integrationConfig:e,supportedChains:r,wagmiConfig:n,overlay:i})=>{let{address:a,chainId:o}=(0,dp.useAccount)(),[f,d]=(0,Y.useState)(!1),[p,h]=(0,Y.useState)(ct.tab),[w,E]=(0,Y.useState)(ct.error),[S,A]=(0,Y.useState)(ct.expressDelivery),[_,I]=(0,Y.useState)(ct.slippage),[N,L]=(0,Y.useState)(ct.infiniteApproval),[M,V]=(0,Y.useState)(ct.srcChain),[F,B]=(0,Y.useState)(ct.dstChain),[J,Q]=(0,Y.useState)(ct.feeToken),[G,ne]=(0,Y.useState)(ct.srcToken),[q,ae]=(0,Y.useState)(ct.dstToken),[T,s]=(0,Y.useState)(ct.tokenPrices),[l,g]=(0,Y.useState)({}),[v,C]=(0,Y.useState)([]),[b,y]=(0,Y.useState)(ct.srcValue),[m,c]=(0,Y.useState)(ct.srcTokenBalanceWei),[x,R]=(0,Y.useState)(ct.srcChainTokensOptions),[u,k]=(0,Y.useState)(ct.dstChainTokensOptions),[P,O]=(0,Y.useState)(ct.srcChainOtherTokensOptions),[z,$]=(0,Y.useState)(ct.dstChainOtherTokensOptions),[j,Z]=(0,Y.useState)([]),[Ye,ee]=(0,Y.useState)([]),[le,Br]=(0,Y.useState)(ct.isFetchingBalance),[He,Le]=(0,Y.useState)(ct.isFetchingBalances),[sn,De]=(0,Y.useState)(ct.isFetchingRoute),[Ce,nr]=(0,Y.useState)(ct.route),Se=(0,Y.useRef)(null),Oe=(0,Y.useRef)(crypto.randomUUID()),cn=(0,Y.useMemo)(()=>!!e?.srcTokenLocked,[e?.srcTokenLocked]),Ve=(0,Y.useMemo)(()=>!!e?.dstTokenLocked,[e?.dstTokenLocked]),Ge=(0,Y.useMemo)(()=>!!e?.dstChainLocked,[e?.dstChainLocked]),fn=(0,Y.useMemo)(()=>!!e?.srcChainLocked,[e?.srcChainLocked]),se=(0,Y.useMemo)(()=>!!e.bridge,[e.bridge]),ze=(0,Y.useMemo)(()=>!!(e.onConnectWallet||window.xPayOnConnectWallet),[e.onConnectWallet]),ir=(0,Y.useMemo)(()=>{let K=Pt?{}:JSON.parse(localStorage.getItem("custom-tokens")||"{}"),ce={};return r.forEach(oe=>{ce[oe.chainId]={},oe.tokens.forEach(te=>{ce[oe.chainId][te.address]=te})}),Vc(ce,K)},[r]),Me=(0,Y.useMemo)(()=>{let K={};return Object.entries(ir).forEach(([ce,oe])=>{K[ce]=Object.entries(oe).filter(([,te])=>te.supported).sort(([,te],[,be])=>be.priority-te.priority).map(([,te])=>({chainId:ce,...te}))}),K},[ir]),ue=(0,Y.useMemo)(()=>{if(!v||v.length===0)return null;let K={},ce=(oe,te,be,pe)=>{K[oe]||(K[oe]={}),K[oe][te]||(K[oe][te]={}),K[oe][te][be]=pe};for(let oe of v){let te=Object.entries(oe);if(te.length!==2)continue;let[be,pe]=te[0],[Ae,yt]=te[1];ce(be,pe,Ae,yt),ce(Ae,yt,be,pe)}return Object.keys(K).length>0?K:null},[v]),dn=(0,Y.useMemo)(()=>G&&M&&T&&T[M.chainId]&&T[M.chainId]?.[G.address]?(Number(b)*Number(T[M.chainId]?.[G.address])).toFixed(2):null,[T,G,b,M]),Ee=(0,Y.useMemo)(()=>As({amount:b,decimals:G?.decimals||18}),[G?.decimals,b]),ke=(0,Y.useMemo)(()=>mt({amount:Ce?.estAmountOut||"0",decimals:q?.decimals||18,precisionFractionalPlaces:Math.min(8,q?.decimals||18)}),[Ce]),ln=(0,Y.useMemo)(()=>As({amount:ke,decimals:q?.decimals||18}),[q?.decimals,ke]),We=(0,Y.useMemo)(()=>q&&F&&T&&T[F?.chainId]&&T[F?.chainId]?.[q.address]?(Number(ke)*Number(T[F?.chainId]?.[q.address])).toFixed(2):null,[T,q,ke,F]),qe=(0,Y.useMemo)(()=>mt({amount:Ce?.minAmountOut||"0",decimals:q?.decimals||18,precisionFractionalPlaces:Math.min(4,q?.decimals||18)}),[Ce]),Fr=(0,Y.useMemo)(()=>S&&!!Ce&&X.from(Ce.xSwapFees?.expressDeliveryFee||"0").gt("0"),[S,Ce]),Ke=(0,Y.useMemo)(()=>r.length>0&&v.length>0,[r,v]),Je=(0,Y.useMemo)(()=>{if(!G||!m||!a)return"";if(er(m).eq(0))return"0";let K=mt({amount:m,decimals:G.decimals,precisionFractionalPlaces:G.decimals});return new fp.default(K).lt("0.00001")?"<0.00001":mt({amount:m,decimals:G.decimals,precisionFractionalPlaces:5})},[G,m]),Qt=(0,Y.useCallback)(K=>{if(!K)return[];if(!se)return Me[K]||[];if(!Me[K]||!ue)return[];let ce=Object.keys(ue[K]||{});return Me[K].filter(oe=>ce.includes(oe.address))},[ue,se,Me]),Pe=(0,Y.useCallback)(async()=>{if(!M||!F||!G||!q||!Ee||er(Ee).eq(0)||se&&!ue){nr(void 0);return}let{source:K,target:ce}=Ds({source:{chain:M,token:G},target:{chain:F,token:q},type:se?"BRIDGE":"SWAP",supportedChains:r,bridgeTokensDictionary:ue||{}});if(!(K.chain?.chainId!==M?.chainId||ce.chain?.chainId!==F?.chainId||K.token?.address!==G?.address||ce.token?.address!==q?.address))try{E(""),De(!0),Se.current&&Se.current.abort(Uc),Se.current=new AbortController;let oe=await qc({integratorId:e.integratorId,fromChain:M.chainId,toChain:F.chainId,fromAddress:a||Wt[M.chainId]?.FeeCollector||"",toAddress:a||Wt[F.chainId]?.FeeCollector||"",fromToken:G.address,toToken:q.address,fromAmount:Ee,slippage:Number(_),customContractCalls:e.customContractCalls,paymentToken:vr.AddressZero,expressDelivery:S,infiniteApproval:N,integratorFee:e.integratorFee,integratorFeeReceiverAddress:e.integratorFeeReceiverAddress},Se.current.signal);nr(oe),Se.current=null}catch(oe){oe!==Uc&&(Se.current=null,console.error(oe),E("Could not find route!"),nr(void 0))}finally{Se.current||De(!1)}},[a,se,F,q,qc,Fr,_,M,G,Ee]),Ne=(0,Y.useCallback)(async()=>{if(!a||!M?.publicRpcUrls[0]||!G||!G?.address)return;let K=crypto.randomUUID();Oe.current=K,Br(!0);let ce=await f1(a,G.address,M?.publicRpcUrls[0]);K===Oe.current&&(c(As({amount:ce,decimals:G.decimals})),Br(!1))},[a,M,G]),un=(0,Y.useCallback)((K,ce)=>ir[ce]?.[K],[ir]),Xe=(0,Y.useCallback)(()=>{e.onConnectWallet?e.onConnectWallet():window.xPayOnConnectWallet&&window.xPayOnConnectWallet()},[e]);return(0,Y.useEffect)(()=>{if(r.length>0){let K=r.map(ce=>ce.chainId);v1({chainId:K}).then(ce=>{s(ce)})}},[r]),(0,Y.useEffect)(()=>{(async()=>{let K=await C1();C(K)})()},[]),(0,Y.useEffect)(()=>{Pe()},[Pe]),(0,Y.useEffect)(()=>{Ne()},[Ne]),(0,Y.useEffect)(()=>{a&&r.length>0&&(Le(!0),w1({walletAddress:a}).then(K=>{g(K),Le(!1)}))},[a,r.length]),(0,Y.useEffect)(()=>{Q(M?.tokens.find(({address:K})=>K.toLowerCase()===vr.AddressZero.toLowerCase()))},[M]),(0,Y.useEffect)(()=>{(async()=>{let K=F?.chainId===M?.chainId,ce=Qt(M?.chainId).filter(({symbol:de})=>K?de!==q?.symbol:!0);R(ce);let oe=Qt(F?.chainId).filter(({symbol:de})=>K?de!==G?.symbol:!0);k(oe);let te=[],be=r.filter(({chainId:de,web3Environment:xe,swapSupported:pt,bridgeSupported:Re})=>de!==M?.chainId&&xe==="mainnet"&&(se&&Re||!se&&pt));for(let{chainId:de}of be)te.push(...Qt(de).filter(({symbol:xe})=>de===F?.chainId?xe!==q?.symbol:!0));O(te);let pe=[],Ae=r.filter(({chainId:de,web3Environment:xe,swapSupported:pt,bridgeSupported:Re})=>de!==F?.chainId&&xe==="mainnet"&&(se&&Re&&M?.supportedDstForBridge?.includes(de)||!se&&pt&&M?.supportedDstForSwap?.includes(de)));for(let{chainId:de}of Ae)pe.push(...Qt(de).filter(({symbol:xe})=>de===M?.chainId?xe!==G?.symbol:!0));$(pe);let yt=de=>de.map(xe=>({...xe,balance:X.from(l[xe.chainId]?.[xe.address]||0)}));R(yt(ce)),k(yt(oe)),O(yt(te)),$(yt(pe))})()},[se,M,F,Qt,r,G?.symbol,q?.symbol,l]),(0,Y.useEffect)(()=>{let K=r.filter(({web3Environment:te,swapSupported:be,bridgeSupported:pe})=>te==="mainnet"&&(se&&pe||!se&&be)),ce=[];if(se&&F&&q&&ue){let te=K.filter(({chainId:be})=>{let pe=ue[be]||{};return Object.values(pe).some(Ae=>Ae[F.chainId])});ce=K.filter(be=>!te.some(pe=>pe.chainId===be.chainId)).map(be=>be.chainId)}let oe=new Set;if(M&&K.filter(te=>se?!M.supportedDstForBridge?.includes(te.chainId):!M.supportedDstForSwap?.includes(te.chainId)).forEach(te=>oe.add(te.chainId)),se&&M&&ue&&!G){let te=ue[M.chainId];te?K.filter(be=>!Object.values(te).some(pe=>pe[be.chainId])).forEach(be=>oe.add(be.chainId)):K.forEach(be=>oe.add(be.chainId))}if(se&&M&&ue&&G){let te=ue[M.chainId]?.[G.address];K.filter(be=>!te?.[be.chainId]).forEach(be=>oe.add(be.chainId))}Z(zc(K,ce)),ee(zc(K,[...oe]))},[r,se,M,G,F,q,ue]),(0,Y.useEffect)(()=>{if(!o||!f||e?.srcChainId)return;let K=r.find(({chainId:ce})=>ce===`${o}`);K&&V(K)},[o,f,r,e?.srcChainId]),(0,Y.useEffect)(()=>{f&&(ne(void 0),ae(void 0),V(void 0),B(void 0))},[se]),(0,Y.useEffect)(()=>{if(f||!r||r.length===0||!ue)return;let K=M||e?.srcChainId||(o?`${o}`:void 0)||(se?void 0:la),ce=r.find(({chainId:pt})=>pt===K),oe=F||e?.dstChainId||(se?void 0:ws),te=r.find(({chainId:pt})=>pt===oe),be,pe,Ae=Gc(e.srcTokenAddr,e?.srcChainId,r),yt=Gc(e.dstTokenAddr,e?.dstChainId,r);ce&&(pe=ce.tokens.find(({address:pt})=>pt.toLowerCase()===Ae?.toLowerCase())),te&&(be=te.tokens.find(({address:pt})=>pt.toLowerCase()===yt));let{source:de,target:xe}=Ds({source:{chain:ce,token:pe},target:{chain:te,token:be},type:se?"BRIDGE":"SWAP",supportedChains:r,bridgeTokensDictionary:ue});V(de.chain),B(xe.chain),ne(de.token),ae(xe.token),d(!0)},[e?.srcChainId,e?.srcTokenAddr,e?.dstChainId,e?.dstTokenAddr,r,se,o,f,ue]),(0,Y.useEffect)(()=>{if(!ue||r.length===0||!f)return;let{source:K,target:ce}=Ds({source:{chain:M,token:G},target:{chain:F,token:q},type:se?"BRIDGE":"SWAP",supportedChains:r,bridgeTokensDictionary:ue});K.chain?.chainId!==M?.chainId&&V(K.chain),ce.chain?.chainId!==F?.chainId&&B(ce.chain),(K.token?.address!==G?.address||K.token?.name!==G?.name)&&ne(K.token),(ce.token?.address!==q?.address||ce.token?.name!==q?.name)&&ae(ce.token)},[M,G,F,q,se,r,ue,f]),(0,Y.useEffect)(()=>{f&&(e.onDstChainChange?e.onDstChainChange(F?.chainId):window.xPayOnDstChainChange&&window.xPayOnDstChainChange(F?.chainId))},[e.onDstChainChange,F]),(0,Y.useEffect)(()=>{if(!f)return;let K=q?{address:q.address.toLowerCase(),symbol:q.tokenId}:void 0;e.onDstTokenChange?e.onDstTokenChange(K):window.xPayOnDstTokenChange&&window.xPayOnDstTokenChange(K)},[e.onDstTokenChange,q]),(0,Y.useEffect)(()=>{f&&(e.onSrcChainChange?e.onSrcChainChange(M?.chainId):window.xPayOnSrcChainChange&&window.xPayOnSrcChainChange(M?.chainId))},[e.onSrcChainChange,M]),(0,Y.useEffect)(()=>{if(!f)return;let K=G?{address:G.address.toLowerCase(),symbol:G.tokenId}:void 0;e.onSrcTokenChange?e.onSrcTokenChange(K):window.xPayOnSrcTokenChange&&window.xPayOnSrcTokenChange(K)},[e.onSrcTokenChange,G]),(0,pp.jsx)(lp.Provider,{value:{bridgeUI:se,integrationConfig:e,wagmiConfig:n,supportedChains:r,tab:p,setTab:h,overlay:i,error:w,setError:E,feeToken:J,srcChain:M,setSrcChain:V,srcChainTokensOptions:x,srcChainOtherTokensOptions:P,srcChainOptions:j,dstChainOptions:Ye,tokenPrices:T,dstChain:F,setDstChain:B,dstChainTokensOptions:u,dstChainOtherTokensOptions:z,srcToken:G,setSrcToken:ne,dstToken:q,setDstToken:ae,srcValue:b,setSrcValue:y,srcValueWei:Ee,srcValueUsd:dn,dstValue:ke,dstValueWei:ln,dstValueUsd:We,dstValueMin:qe,expressDelivery:S,setExpressDelivery:A,infiniteApproval:N,setInfiniteApproval:L,slippage:_,setSlippage:I,route:Ce,setRoute:nr,isAsyncDataLoaded:Ke,srcTokenBalanceWei:m,setSrcTokenBalanceWei:c,srcTokenBalanceInfo:Je,isFetchingRoute:sn,isFetchingBalance:le,isFetchingBalances:He,isExpressDeliveryActive:Fr,quoteRoute:Pe,refreshBalance:Ne,findTokenDataByAddressAndChain:un,srcTokenLocked:cn,srcChainLocked:fn,dstTokenLocked:Ve,dstChainLocked:Ge,bridgeTokensDictionary:ue,onConnectWallet:Xe,hasOnConnectWalletCallback:ze},children:t})},re=()=>(0,Y.useContext)(lp);var Nn=require("react"),bp=require("react/jsx-runtime"),hp=(0,Nn.createContext)({}),xp=({children:t})=>{let e=(0,Nn.useCallback)(async({executeTransaction:i,handlers:a})=>{try{let o=await i();if(!o)throw new Error("Transaction is undefined");a?.onConfirm?.(o);let f=await o.wait();a?.onSuccess?.(f)}catch(o){console.error(o),a?.onError?.(o)}},[]),r=(0,Nn.useCallback)(({executeTransaction:i,handlers:a,network:o="evm"})=>{let f=Date.now();return o==="evm"&&e({executeTransaction:i,handlers:a}),f},[e]),n=(0,Nn.useMemo)(()=>({enqueueTransaction:r}),[r]);return(0,bp.jsx)(hp.Provider,{value:n,children:t})};function mp(){return(0,Nn.useContext)(hp)}var ma=require("react"),wp=require("wagmi");var gp=require("react"),yp=require("wagmi");function J5(t){let{account:e,transport:r}=t;return new gs.Web3Provider(r,"any").getSigner(e.address)}async function vp({chainId:t}={}){let{data:e}=(0,yp.useConnectorClient)({chainId:t});return(0,gp.useMemo)(()=>e?J5(e):void 0,[e])}var X5=()=>{let[t,e]=(0,ma.useState)(),r=vp();(0,ma.useEffect)(()=>{r.then(a=>e(a))},[r]);let n=(0,wp.useAccount)();return{networks:{evm:(0,ma.useMemo)(()=>({networkName:"EVM",chainId:n.chainId?.toString()||la,address:n.address,signer:t,provider:t?.provider}),[n.address,n.chainId,t])}}},ba=X5;var Af=require("react");var Us=require("react");var ga=require("react/jsx-runtime"),Cp=()=>{let{isExpressDeliveryActive:t}=re();return(0,ga.jsxs)("div",{className:"flex items-center",children:[(0,ga.jsx)("div",{className:`w-4 h-4 mr-1 ${t?"fill-t_success_light":"fill-t_text_primary opacity-50"} `,children:(0,ga.jsx)(q1,{})}),(0,ga.jsx)("span",{className:`text-xs font-medium sm:text-sm ${t?"text-t_success_light":"opacity-50"}`,children:t?"Fast ~ 30sec ":"Normal ~ 30min"})]})};var ya=require("react/jsx-runtime"),Ap=({name:t,value:e})=>{let{isFetchingRoute:r}=re();return(0,ya.jsxs)("div",{className:"flex gap-x-1 justify-between text-xs font-medium",children:[(0,ya.jsx)("div",{className:"opacity-60",children:t}),(0,ya.jsx)("div",{children:r?(0,ya.jsx)(Pr,{className:"w-[60px] h-full"}):e})]})};var Os=require("react/jsx-runtime"),Tp=()=>{let{route:t,slippage:e,feeToken:r,dstToken:n,expressDelivery:i}=re(),a=[{name:"CCIP Fee: ",value:`${mt({amount:t?.xSwapFees.ccipFee||"0",decimals:r?.decimals||18,precisionFractionalPlaces:5})||0} ${r?.symbol||""}`},{name:"Native Fee: ",value:`${mt({amount:t?.xSwapFees.xSwapFee.nativeFee||"0",decimals:r?.decimals||18,precisionFractionalPlaces:5})||0} ${r?.symbol||""}`},...i?[{name:"Express delivery Fee: ",value:`${mt({amount:t?.xSwapFees.expressDeliveryFee||"0",decimals:r?.decimals||18,precisionFractionalPlaces:5})||0} ${r?.symbol||""}`}]:[],{name:"Slippage: ",value:`${e}%`},{name:"Min out: ",value:`${mt({amount:t?.minAmountOut||"0",decimals:n?.decimals||18,precisionFractionalPlaces:5})||0} ${n?.symbol||""}`}];return(0,Os.jsx)("div",{className:"border-t border-solid border-t_text_primary border-opacity-10 pt-3 mt-3",children:(0,Os.jsx)("div",{className:`flex flex-col gap-y-2 gap-x-10 sm:grid ${a.length===4?"sm:grid-rows-2":"sm:grid-rows-3"} sm:grid-flow-col`,children:a.map(({name:o,value:f})=>(0,Os.jsx)(Ap,{name:o,value:f},o))})})};var At=require("react/jsx-runtime"),Hs=()=>{let[t,e]=(0,Us.useState)(!1),{route:r,feeToken:n,isFetchingRoute:i,srcChain:a,dstChain:o}=re(),f=(0,Us.useMemo)(()=>{if(!r)return"0";let d=er(r.xSwapFees.ccipFee||"0").add(er(r.xSwapFees.xSwapFee.nativeFee||"0")).add(er(r.xSwapFees.expressDeliveryFee||"0")).toString();return mt({amount:d,decimals:n?.decimals||18,precisionFractionalPlaces:5})},[n?.decimals,r]);return(0,At.jsx)("div",{className:"flex flex-col x-border rounded-xl py-2 px-4 bg-t_bg_tertiary bg-opacity-5",children:(0,At.jsxs)("button",{"aria-label":`${t?"Collapse":"Expand"} fees panel`,type:"button",onClick:()=>e(d=>!d),children:[(0,At.jsxs)("div",{className:"flex justify-between",children:[(0,At.jsxs)("div",{className:"flex gap-2 items-center text-xs font-medium sm:text-sm fill-t_text_primary",children:[(0,At.jsx)(K1,{}),(0,At.jsx)("p",{className:"opacity-60",children:"Fee: "}),i?(0,At.jsx)(Pr,{className:"w-[100px] h-full"}):(0,At.jsx)("p",{children:`${f} ${n?.symbol||""}`})]}),(0,At.jsxs)("div",{className:"flex gap-2 items-center fill-t_text_primary",children:[r&&!i&&a?.chainId!==o?.chainId&&(0,At.jsx)(Cp,{}),t?(0,At.jsx)("div",{className:"w-4 h-2 rotate-180",children:(0,At.jsx)(Ei,{})}):(0,At.jsx)("div",{className:"w-4 h-2",children:(0,At.jsx)(Ei,{})})]})]}),t&&(0,At.jsx)(Tp,{})]})})};var co=require("react/jsx-runtime"),Sp=()=>(0,co.jsx)("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-14 p-1 border border-solid border-t_text_primary border-opacity-10 rounded-xl bg-t_bg_secondary",children:(0,co.jsx)("div",{className:"relative bg-gradient-to-r from-t_main_accent_light to-t_main_accent_dark w-8 h-8 rounded-xl",children:(0,co.jsx)("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 fill-white",children:(0,co.jsx)(Is,{})})})});var Q5=Et(require("viem/chains")),vf=require("viem/chains"),va=require("@wagmi/core"),wa=require("@wagmi/connectors"),Z5=(0,va.createStorage)({key:"xpay.wagmi.store",storage:Pt?void 0:localStorage}),Ep=t=>{let e=Y5(t),r=j5(e);return(0,va.createConfig)({chains:e,transports:r,connectors:[(0,wa.injected)(),(0,wa.coinbaseWallet)({appLogoUrl:"https://xswap.link/favicon.ico",appName:"XSwap"}),(0,wa.walletConnect)({projectId:"c392898b45ac587a280b5eb33e92aeb0",showQrModal:!0})],storage:Z5})},Y5=t=>{let e=[vf.mainnet];return e.push(...Object.values(Q5).filter(r=>r.id!==vf.mainnet.id&&t.some(({chainId:n})=>n===r.id.toString()))),e},j5=t=>{let e={};return t.forEach(r=>{e[r.id]=(0,va.http)()}),e};var fo=require("react"),kp=require("react-dom"),_p=require("react/jsx-runtime"),$5={TOP:"-translate-x-1/2 -translate-y-full",BOTTOM:"-translate-x-1/2",LEFT:"-translate-x-full -translate-y-1/2",RIGHT:"-translate-y-1/2"},Ca=({id:t,position:e,text:r,triggerRef:n})=>{let[i,a]=(0,fo.useState)({top:0,left:0}),[o,f]=(0,fo.useState)(!1);return(0,fo.useEffect)(()=>{let d=n.current,p=()=>{if(!d)return;let E=d.getBoundingClientRect();switch(e){case"TOP":{a({top:E.top,left:E.left+E.width/2});break}case"BOTTOM":{a({top:E.top+E.height,left:E.left+E.width/2});break}case"LEFT":{a({top:E.top+E.height/2,left:E.left});break}case"RIGHT":{a({top:E.top+E.height/2,left:E.left+E.width});break}}},h=()=>{p(),f(!0)},w=()=>{f(!1)};return d&&(d.addEventListener("mouseenter",h),d.addEventListener("mouseleave",w)),window.addEventListener("scroll",p,!0),window.addEventListener("resize",p,!0),()=>{d&&(d.removeEventListener("mouseenter",h),d.removeEventListener("mouseleave",w)),window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p,!0)}},[n,e]),(0,kp.createPortal)(o&&(0,_p.jsx)("div",{id:t,className:`fixed z-50 x-border rounded-xl shadow-lg py-2 px-4 bg-t_bg_primary text-sm text-t_text_primary text-opacity-50 max-w-80 ${$5[e]}`,style:{top:i.top,left:i.left},children:r}),Ci,t)};var Mp=require("react"),Rn=require("react/jsx-runtime"),Ip=({onCloseClick:t})=>{let e=(0,Mp.useRef)(null);return(0,Rn.jsxs)("div",{className:"flex justify-between items-center text-base font-medium",children:[(0,Rn.jsx)("div",{className:"text-t_text_primary",children:"Confirmation"}),(0,Rn.jsxs)("div",{className:"flex gap-4 items-center",children:[(0,Rn.jsx)(Ca,{text:"To sign the transaction open the wallet you have used to connect with XSwap.",position:"BOTTOM",triggerRef:e,id:"connect-wallet-to-sign-tx-tooltip"}),(0,Rn.jsx)(ki,{ref:e,className:"cursor-help fill-t_main_accent_light w-[18px] h-[18px]"}),(0,Rn.jsx)("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:t,children:(0,Rn.jsx)(lt,{})})]})]})};var wf=require("react"),ft=require("react/jsx-runtime"),Pp=()=>{let{txStatus:t,txNeedsApproval:e,txMsg:r}=rn(),n=(0,wf.useMemo)(()=>[{icon:a=>(0,ft.jsx)("div",{className:`${a}`,children:(0,ft.jsx)(sf,{})}),title:"sign approval transaction",state:t===1?"triggered":t>1?"completed":"none",show:r?t===1||t===2:e},{icon:a=>(0,ft.jsx)("div",{className:`${a}`,children:(0,ft.jsx)(ff,{})}),title:"confirming approval transaction...",state:t===2?"triggered":t>2?"completed":"none",show:r?t===1||t===2:e},{icon:a=>(0,ft.jsx)("div",{className:`${a}`,children:(0,ft.jsx)(sf,{})}),title:"sign transaction",state:t===3?"triggered":t>3?"completed":"none",show:r?t===3||t===4:!0},{icon:a=>(0,ft.jsx)("div",{className:`${a}`,children:(0,ft.jsx)(ff,{})}),title:"confirming transaction...",state:t===4?"triggered":t>4?"completed":"none",show:r?t===3||t===4:!0}],[r,e,t]),i=(0,wf.useMemo)(()=>n.filter(({show:a})=>a),[n]);return(0,ft.jsx)("div",{className:"flex flex-col gap-1",children:i.map(({icon:a,title:o,state:f},d)=>(0,ft.jsxs)("div",{className:"flex flex-col px-4 gap-1",children:[(0,ft.jsxs)("div",{className:"flex justify-between items-center",children:[(0,ft.jsxs)("div",{className:"flex items-center gap-2",children:[a(`${f==="triggered"?"fill-t_main_accent_light":"fill-t_text_primary opacity-50"}`),(0,ft.jsx)("div",{className:`${f!=="triggered"?"opacity-50":f==="triggered"&&"text-t_text_secondary"}`,children:o})]}),(0,ft.jsx)("div",{children:f==="completed"?(0,ft.jsx)("div",{className:"fill-t_success_dark",children:(0,ft.jsx)(Ps,{})}):f==="triggered"?(0,ft.jsx)("div",{className:"animate-spin-slow fill-t_main_accent_light",children:(0,ft.jsx)(J1,{})}):null})]}),d!==i.length-1&&(0,ft.jsx)("div",{className:"vertical-separator py-3 ml-2"})]},o))})};var lo=require("react"),br=require("react/jsx-runtime"),Cf=({type:t})=>{let{srcToken:e,srcChain:r,dstToken:n,dstChain:i,srcValue:a,srcValueUsd:o,dstValue:f,dstValueUsd:d}=re(),p=(0,lo.useMemo)(()=>t==="source"?e:n,[n,e,t]),h=(0,lo.useMemo)(()=>t==="source"?r:i,[i,r,t]),w=(0,lo.useMemo)(()=>t==="source"?a:f,[f,a,t]),E=(0,lo.useMemo)(()=>t==="source"?o:d,[d,o,t]);return(0,br.jsxs)("div",{className:"flex justify-between bg-gradient-to-r from-t_main_accent_light/20 to-t_main_accent_dark/20 p-5 rounded-xl",children:[(0,br.jsxs)("div",{className:"flex flex-col",children:[(0,br.jsx)("div",{className:"opacity-60 text-sm mb-2",children:`You ${t==="source"?"pay":"receive"}`}),(0,br.jsx)("div",{className:`${t==="destination"&&"text-t_text_secondary"}`,children:w}),(0,br.jsxs)("div",{className:"opacity-60",children:["$",E]})]}),(0,br.jsxs)("div",{className:"flex items-center gap-3",children:[(0,br.jsxs)("div",{className:"flex flex-col text-right",children:[(0,br.jsx)("div",{children:p?.symbol}),(0,br.jsx)("div",{className:"opacity-60",children:h?.displayName})]}),(0,br.jsx)($n,{token:p,className:"w-9 h-9",generatedLogoClassName:"w-9 h-9"})]})]})};var Ot=require("react/jsx-runtime"),Np=({onCloseClick:t})=>{let{supportedChains:e,srcChain:r,srcToken:n,dstChain:i,dstToken:a,srcValueWei:o,dstValueWei:f,route:d,refreshBalance:p}=re(),{txStatus:h,setTxStatus:w,txMsg:E,enqueueTransaction:S,setTxNeedsApproval:A}=rn(),{addTransactionToLocalHistory:_,updateTransactionInLocalHistory:I}=xa(),{networks:{evm:{signer:N}}}=ba(),L=so(),M=(0,Af.useCallback)(async F=>{if(!r||!i||!n||!a||!d)return;let B={hash:F.transactionHash,timestamp:Date.now()/1e3,sourceChainId:r.chainId,targetChainId:i.chainId,amountWei:o,tokenAddress:n.address,tokenOutAddress:a?.address,tokenOutAmount:f,estimatedDeliveryTimestamp:Number(d.xSwapFees.expressDeliveryFee||"0")>0?Date.now()/1e3*1e3+30*1e3:Date.now()/1e3*1e3+ys?.[r?.chainId]?.[i?.chainId]||Cs,status:"IN_PROGRESS"};if(r.chainId===i.chainId)B.estimatedDeliveryTimestamp=B.timestamp,B.status="DONE";else{let J="MessageSent(bytes32,uint64,address,bytes,address,uint256,uint256,address,uint256)",Q="MessageReceived(bytes32,uint64,address,bytes,address,uint256)",G="MessageSent(bytes32,uint64,address,address,address,address,uint256)",ne="MessageReceived(bytes32,uint64,address,bytes)",q=fe.getDefaultProvider(e.find(T=>T.ecosystem==="evm"&&T.chainId===i.chainId)?.publicRpcUrls[0]),ae=async(T,s,l)=>{let g=F.logs?.find(v=>v.topics[0]===fe.utils.id(s));if(g){let v=g?.topics[1];B.messageId=v;let C=new fe.Contract(Wt[i?.chainId]?.[T],T==="XSwapRouter"?o1:s1,q),b={address:Wt[i.chainId]?.[T],topics:[fe.utils.id(l),v]};(await C.queryFilter(b)).length>0?(B.status="DONE",I(B,F.from)):C.once(b,()=>{B.status="DONE",I(B,F.from)})}};await ae("XSwapRouter",J,Q),await ae("CustomXSwapRouter",G,ne)}_(B,F.from)},[_,I,r,i,n,a,o,f,e,d]),V=(0,Af.useCallback)(async()=>{if(n&&d){let F=()=>{S({executeTransaction:()=>{if(!(!d.transactions.swap||!N))return L.executeCalldata(N,d.transactions.swap)},txStatus:3,handlers:{onSuccess:B=>{w(5),p(),M(B),r?.chainId&&i?.chainId&&r?.chainId!==i?.chainId&&Rp(r?.chainId,B.transactionHash,a?.address,f)}}})};n.address!==vr.AddressZero&&d.transactions.approve?(A(!0),S({executeTransaction:()=>{if(!(!d.transactions.approve||!N))return L.executeCalldata(N,d.transactions.approve)},txStatus:1,handlers:{onSuccess:()=>F()}})):(A(!1),F())}},[n,d,S,N,L,w,p,M,r?.chainId,i?.chainId,a?.address,f,A]);return(0,Ot.jsxs)("div",{className:"flex flex-col text-t_text_primary gap-5",children:[(0,Ot.jsx)(Ip,{onCloseClick:t}),E?(0,Ot.jsx)("div",{children:E}):(0,Ot.jsxs)(Ot.Fragment,{children:[(0,Ot.jsxs)("div",{className:"relative flex flex-col gap-5 fill-white",children:[(0,Ot.jsx)(Cf,{type:"source"}),(0,Ot.jsx)(Sp,{}),(0,Ot.jsx)(Cf,{type:"destination"})]}),(0,Ot.jsx)(Hs,{})]}),h===0?(0,Ot.jsx)(Ir,{variant:"filled-squared",onClick:()=>{V()},type:"button",className:"text-white border-none h-14 text-sm font-bold w-full py-5 cursor-pointer bg-gradient-to-r from-t_main_accent_light to-t_main_accent_dark rounded-lg",children:"Sign and swap"}):(0,Ot.jsx)(Pp,{})]})};var _i=require("react/jsx-runtime"),Tf=({chain:t,token:e,value:r})=>(0,_i.jsxs)("div",{className:"flex items-center gap-2",children:[(0,_i.jsx)(ei,{chain:t,token:e,chainLogoClassName:"w-5",tokenLogoClassName:"w-9 h-9",generatedLogoClassName:"w-9 h-9 text-[16px]"}),(0,_i.jsxs)("div",{className:"flex flex-col w-min sm:w-auto",children:[(0,_i.jsx)("div",{children:`${r} ${e?.symbol}`}),(0,_i.jsx)("div",{className:"opacity-60",children:t?.displayName})]})]});var Ze=require("react/jsx-runtime"),Bp=({onCloseClick:t})=>{let{txError:e,txExplorerUrl:r,txMsg:n}=rn(),{isExpressDeliveryActive:i,srcChain:a,srcToken:o,dstChain:f,dstToken:d,srcValue:p,dstValue:h}=re();return(0,Ze.jsx)("div",{className:"flex flex-col gap-5 text-t_text_primary justify-center items-center",children:e?(0,Ze.jsxs)(Ze.Fragment,{children:[(0,Ze.jsx)("div",{className:"flex justify-end fill-t_text_primary cursor-pointer w-full",onClick:t,children:(0,Ze.jsx)(lt,{className:"w-3.5 h-3.5"})}),(0,Ze.jsx)(L1,{}),(0,Ze.jsx)("div",{className:"text-2xl font-bold",children:"Transaction failed"}),(0,Ze.jsx)("div",{className:"text-center",children:e})]}):(0,Ze.jsxs)(Ze.Fragment,{children:[(0,Ze.jsx)("div",{className:"flex justify-end fill-t_text_primary cursor-pointer w-full",onClick:t,children:(0,Ze.jsx)(lt,{className:"w-3.5 h-3.5"})}),(0,Ze.jsx)(W1,{}),(0,Ze.jsxs)("div",{className:"flex flex-col items-center",children:[(0,Ze.jsx)("div",{className:"text-2xl font-bold",children:"Transaction success!"}),!n&&a!==f&&(0,Ze.jsx)("div",{className:"text-sm font-normal opacity-60",children:`Approximated time of delivery: ${i?"30 sec":"30 min"}`})]}),!n&&(0,Ze.jsxs)("div",{className:"flex items-center gap-2",children:[(0,Ze.jsx)(Tf,{chain:a,token:o,value:p}),(0,Ze.jsx)("div",{className:"-rotate-90 flex justify-center w-8 fill-t_text_primary opacity-50",children:(0,Ze.jsx)(Is,{})}),(0,Ze.jsx)(Tf,{chain:f,token:d,value:h})]}),(0,Ze.jsxs)("a",{href:r,target:"_blank",rel:"noreferrer",className:"flex gap-4 items-center mb-2 fill-t_main_accent_light",children:[(0,Ze.jsx)("p",{className:"text-t_text_secondary underline",children:"View details on Explorer"}),(0,Ze.jsx)(U1,{})]})]})})};var Sf=require("react/jsx-runtime"),Fp=({onCloseClick:t})=>{let{txStatus:e,txError:r}=rn();return e===5||r?(0,Sf.jsx)(Bp,{onCloseClick:t}):(0,Sf.jsx)(Np,{onCloseClick:t})};var Lp=require("notistack"),Fe=require("react"),Dp=require("wagmi");var Tt=require("react/jsx-runtime"),Op=(0,Fe.createContext)({}),Up=({children:t})=>{let{chainId:e}=(0,Dp.useAccount)(),{enqueueTransaction:r}=mp(),{enqueueSnackbar:n,closeSnackbar:i}=(0,Lp.useSnackbar)(),[a,o]=(0,Fe.useState)("evm"),f=(0,Fe.useRef)(!1),[d,p]=(0,Fe.useState)(!1),[h,w]=(0,Fe.useState)(""),E=(0,Fe.useRef)(),[S,A]=(0,Fe.useState)(""),[_,I]=(0,Fe.useState)(""),[N,L]=(0,Fe.useState)(void 0),[M,V]=(0,Fe.useState)(!1),[F,B]=(0,Fe.useState)(!1),[J,Q]=(0,Fe.useState)(0),{supportedChains:G,setSrcValue:ne}=re(),q=y=>{E.current===y&&(f.current=!1,p(!1))};(0,Fe.useEffect)(()=>{if(!d&&(S&&(n((0,Tt.jsx)(Yn,{message:{text:S,variant:"error"}})),A("")),M&&h)){let y=h;n((0,Tt.jsx)(Yn,{message:{text:`Transaction ${d1(h)} is about to be mined!`,variant:"warning",action:()=>(0,Tt.jsxs)("div",{className:"flex items-center flex-nowrap",children:[(0,Tt.jsx)(Ir,{type:"button",onClick:()=>{window.open(`${G.find(m=>m.chainId===e?.toString()&&m.ecosystem===a)?.transactionExplorer}/${h}`||"")},children:"Check"}),(0,Tt.jsx)("div",{className:"fill-t_text_primary w-[14px] h-[14px] cursor-pointer p-[14px] leading-[0px]",onClick:()=>i(y),children:(0,Tt.jsx)(lt,{})})]}),animation:()=>(0,Tt.jsx)(nn,{className:"w-4 h-4"})}}),{persist:!0,key:y}),w("")}},[M,a,h,S,n,i,e,d,G]);let ae=(0,Fe.useCallback)((y,m,c)=>{let x=`${m}/${y}`;if(c){let u=c.events?.find(k=>k.event==="MessageSent")?.args?.messageId;return u?`${ua}${u}`:x}else return x},[]),T=(0,Fe.useCallback)((y,m,c=!0)=>{let x={...m};return x.onConfirm=R=>{E.current===y&&(m?.onConfirm&&m?.onConfirm(R),w(R?.hash||""),Q(u=>u+1))},x.onSuccess=R=>{if(i(R?.transactionHash),E.current===y){if(L(R),!f.current&&c){let u=`${h}-success`;n((0,Tt.jsx)(Yn,{message:{text:"Transaction mined successfully!",variant:"success",action:()=>(0,Tt.jsxs)("div",{className:"flex items-center flex-nowrap",children:[(0,Tt.jsx)(Ir,{type:"button",onClick:()=>{window.open(ae(h,G.find(k=>k.chainId===e?.toString()&&k.ecosystem===a)?.transactionExplorer||"",R))},children:"View"}),(0,Tt.jsx)("div",{className:"fill-t_text_primary w-[14px] h-[14px] cursor-pointer p-[14px] leading-[0px]",onClick:()=>i(u),children:(0,Tt.jsx)(lt,{})})]})}}),{persist:!1,key:u})}m?.onSuccess&&m?.onSuccess(R),A(""),V(!1)}},x.onError=R=>{E.current===y&&(A(l1(R)),m?.onError?.(R),V(!1))},x},[i,h,n,ae,G,e,a]),s=(0,Fe.useCallback)(({executeTransaction:y,txStatus:m,txMsg:c="",handlers:x,network:R="evm",showDefaultSuccessMessage:u=!0})=>{let k=Date.now(),P=x;return R==="evm"&&(P=T(k,x,u)),r({executeTransaction:y,txStatus:m,handlers:P,network:R}),E.current=k,f.current=!0,w(""),A(""),I(c),Q(m),L(void 0),V(!0),o(R),p(!0),k},[T,r]),l=(0,Fe.useMemo)(()=>ae(h,G.find(y=>y.chainId===e?.toString()&&y.ecosystem===a)?.transactionExplorer||"",N),[e,a,ae,G,h,N]),g=(0,Fe.useCallback)(y=>{p(y),f.current=y},[]),v=(0,Fe.useMemo)(()=>S?"error":J===5?"success":"neutral",[S,J]),C=(0,Fe.useMemo)(()=>({enqueueTransaction:s,closeTransactionModal:q,isTxModalOpen:d,setTxModalOpen:p,loading:M,txStatus:J,setTxStatus:Q,txExplorerUrl:l,txHash:h,txError:S,txMsg:_,setTxMsg:I,setTxError:A,txNeedsApproval:F,setTxNeedsApproval:B}),[s,d,M,J,l,h,S,_,F]),b=(0,Fe.useCallback)(()=>{A(""),ne(""),g(!1)},[A,ne,g]);return(0,Tt.jsxs)(Op.Provider,{value:C,children:[d&&(0,Tt.jsx)(Hp,{id:"tx_modal",className:"max-w-x_modal",type:v,onCloseClick:b,children:(0,Tt.jsx)(Fp,{onCloseClick:b})}),t]})};function rn(){return(0,Fe.useContext)(Op)}var Ef=require("react/jsx-runtime"),Aa=({className:t,children:e,onClose:r})=>{let{overlay:n}=re();return(0,Ef.jsx)("div",{className:`${n?"fixed bg-[rgba(0,0,0,0.8)]":"absolute"} top-0 left-0 right-0 bottom-0 flex items-center justify-center z-10 ${t||""}`,onMouseDown:i=>{i.target===i.currentTarget&&n&&(i.stopPropagation(),i.nativeEvent.stopImmediatePropagation(),i.preventDefault(),r())},children:(0,Ef.jsx)("div",{className:"flex flex-col bg-t_bg_primary rounded-3xl p-4 w-full min-w-[340px]",style:{height:n?"600px":"100%",maxWidth:"480px",maxHeight:"100%"},children:e})})};var Ta=require("react/jsx-runtime"),kf=()=>(0,Ta.jsxs)("div",{className:"flex justify-center items-center gap-2 my-3",children:[(0,Ta.jsx)("span",{className:"text-t_text_primary opacity-50",children:"Powered by"}),(0,Ta.jsx)("div",{className:"flex items-center gap-1 fill-t_chainlink_logo",children:(0,Ta.jsx)(P1,{})})]});var Sa=require("react"),Vp=require("react/jsx-runtime"),uo=(0,Sa.forwardRef)(({value:t,onChange:e,id:r,placeholder:n,regex:i,className:a,disabled:o},f)=>{let d=(0,Sa.useMemo)(()=>t.length<2?2:t.length,[t]),p=(0,Sa.useCallback)(h=>{h.target.value!=="."&&i.test(h.target.value)&&e(h.target.value.replace(/,/g,"."))},[e,i,r]);return(0,Vp.jsx)("input",{ref:f,id:r,type:"text",size:d,placeholder:n||"0",pattern:i.toString(),inputMode:"decimal",spellCheck:"false",autoComplete:"off",autoCorrect:"off",disabled:o,value:t,onChange:p,className:a})});uo.displayName="SafeInput";var Gp=require("react/jsx-runtime"),Pr=({className:t})=>(0,Gp.jsx)("div",{className:`bg-t_bg_tertiary bg-opacity-15 rounded animate-pulse ${t||""}`});var Ea=require("react/jsx-runtime"),nn=({className:t})=>(0,Ea.jsx)("div",{role:"status",className:t||"",children:(0,Ea.jsxs)("svg",{"aria-hidden":"true",className:`animate-spin fill-t_text_primary text-t_text_primary text-opacity-10 ${t||""}`,viewBox:"0 0 100 101",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,Ea.jsx)("path",{d:"M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z",fill:"currentColor"}),(0,Ea.jsx)("path",{d:"M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z",fill:"currentFill"})]})});var Sh=require("react");var qt=require("react/jsx-runtime"),zp=({onClose:t})=>{let{tab:e,setTab:r,overlay:n}=re();return(0,qt.jsx)("div",{className:"flex gap-5 items-center",children:e==="Swap"?(0,qt.jsxs)(qt.Fragment,{children:[(0,qt.jsx)("button",{type:"button",onClick:()=>r("Settings"),"aria-label":"Open settings",className:"fill-white",children:(0,qt.jsx)(G1,{})}),(0,qt.jsx)("button",{type:"button",onClick:()=>r("History"),"aria-label":"Open history",className:"fill-white",children:(0,qt.jsx)(O1,{})}),n&&(0,qt.jsx)("button",{type:"button",onClick:()=>t(),"aria-label":"Close",className:"fill-t_text_primary",children:(0,qt.jsx)(lt,{})})]}):(0,qt.jsx)("button",{type:"button",onClick:()=>{r("Swap")},"aria-label":"Switch to swap view",className:"fill-t_text_primary",children:(0,qt.jsx)(lt,{})})})};var po=require("react/jsx-runtime"),Wp=({onClose:t})=>{let{tab:e,bridgeUI:r}=re();return(0,po.jsxs)("div",{className:"flex justify-between mt-2 px-4",children:[(0,po.jsx)("div",{className:"text-xl font-sans-bold font-bold",children:e==="Swap"&&r?"Bridge":e}),(0,po.jsx)(zp,{onClose:t})]})};var qp=require("react"),Kp=require("react-virtuoso"),Mi=require("react/jsx-runtime"),Jp=()=>{let{history:t,historyLoadedOnce:e}=xa(),r=(0,qp.useMemo)(()=>!t||t.length===0?e?(0,Mi.jsx)("div",{className:"text-center py-4 text-[#9e9e9e]",children:"Your history is empty"}):(0,Mi.jsx)("div",{className:"flex justify-center w-full py-4 fill-t_text_primary",children:(0,Mi.jsx)(nn,{className:"w-8 h-8"})}):(0,Mi.jsx)(Kp.Virtuoso,{data:t,style:{height:"532px"},itemContent:(n,i)=>(0,Mi.jsx)(Xp,{transaction:i})}),[t,e]);return(0,Mi.jsx)("div",{className:"flex-1 overflow-hidden",children:r})};var ka=require("react/jsx-runtime"),ho=({checked:t,onClick:e})=>(0,ka.jsx)("div",{children:(0,ka.jsxs)("span",{className:"inline-flex w-14 h-9 p-3 relative align-middle box-border overflow-hidden cursor-pointer",onClick:e,children:[(0,ka.jsx)("span",{className:"h-full w-full rounded-lg bg-t_bg_tertiary bg-opacity-30"}),(0,ka.jsx)("span",{className:`transition-all w-5 h-5 rounded-full absolute translate-y-[-4px]
|
|
91
|
-
${t?"translate-x-[12px] bg-t_main_accent_light":"bg-t_bg_tertiary"} `})]})});ho.displayName="ToggleButton";var Qp=require("react"),an=require("react/jsx-runtime"),Zp=()=>{let t=(0,Qp.useRef)(null),{infiniteApproval:e,setInfiniteApproval:r}=re();return(0,an.jsxs)("div",{className:"flex flex-col gap-5 pt-5 border-t border-solid border-white border-opacity-10",children:[(0,an.jsx)("h1",{className:"text-sm font-medium text-left",children:"Approval"}),(0,an.jsx)("div",{className:"flex gap-2 items-center justify-between flex-wrap",children:(0,an.jsxs)("div",{className:"flex items-center",children:[(0,an.jsx)("h2",{className:"text-xs",children:"Infinite approval: "}),(0,an.jsx)(ho,{checked:e,onClick:()=>{r(n=>!n)}}),(0,an.jsx)(Ca,{text:"Enabling infinite approval allows to access your tokens without requiring repeated approvals for each transaction. This streamlines multiple transactions but may pose a security risk if the spender's address is compromised.",position:"BOTTOM",triggerRef:t,id:"infinite-approval-tooltip"}),(0,an.jsx)(ki,{ref:t,className:"cursor-help fill-t_main_accent_light w-[18px] h-[18px]"})]})})]})};var Yp=require("react"),gr=require("react/jsx-runtime"),jp=()=>{let t=(0,Yp.useRef)(null),{expressDelivery:e,setExpressDelivery:r}=re();return(0,gr.jsxs)("div",{className:"flex flex-col gap-5 pt-5 border-t border-solid border-t_text_primary border-opacity-10",children:[(0,gr.jsx)("h1",{className:"text-sm font-medium text-left",children:"Delivery"}),(0,gr.jsxs)("div",{className:"flex gap-2 items-center justify-between flex-wrap",children:[(0,gr.jsxs)("div",{className:"flex items-center",children:[(0,gr.jsx)("h2",{className:"text-xs",children:"Express delivery: "}),(0,gr.jsx)(ho,{checked:e,onClick:()=>{r(n=>!n)}}),(0,gr.jsx)(Ca,{text:"Express delivery is a special feature of XSwap that reduces transaction time across chains to around 30 seconds. It is currently available for swaps below a value of $1000 USD.",position:"BOTTOM",triggerRef:t,id:"express-delivery-tooltip"}),(0,gr.jsx)(ki,{ref:t,className:"cursor-help fill-t_main_accent_light w-[18px] h-[18px]"})]}),(0,gr.jsxs)("div",{className:"text-xs font-medium",children:[(0,gr.jsx)("span",{className:"text-xs font-medium opacity-60",children:"Max time: "}),e?"30 sec":"30 min"]})]})]})};var $p=require("react"),Kt=require("react/jsx-runtime"),eh=()=>{let{slippage:t,setSlippage:e}=re(),[r,n]=(0,$p.useState)(t),i=f=>{f.length===0?(n(""),e(a)):(f.length>=5&&(f=f.substring(0,5)),Number(f)<=100&&(n(f),e(f)))},a="1.5";return(0,Kt.jsxs)("div",{className:"flex flex-col gap-5 pt-5 border-t border-solid border-t_text_primary border-opacity-10",children:[(0,Kt.jsx)("h1",{className:"text-sm font-medium text-left",children:"Slippage"}),(0,Kt.jsxs)("div",{className:"flex items-center gap-2 w-full",children:[(0,Kt.jsx)("div",{className:"flex items-center bg-t_bg_tertiary bg-opacity-5 p-1 border border-solid border-t_text_primary border-opacity-10 rounded-xl gap-2",children:["0.5","1.5","3.0"].map(f=>(0,Kt.jsx)("button",{type:"button",onClick:()=>i(f),className:`block rounded-lg text-sm bg-transparent h-7 px-1 hover:bg-gradient-to-r hover:from-t_main_accent_light hover:to-t_main_accent_dark hover:opacity-100 ${t===f?"gradient-slippage-container-blue text-white opacity-100":"text-t_text_primary opacity-20"}`,children:`${f}%`},f))}),(0,Kt.jsx)("div",{className:`${r?"gradient-slippage-container-blue p-[1px] rounded-xl":""}`,children:(0,Kt.jsxs)("div",{className:"bg-t_bg_primary p-1 h-full border border-solid border-t_text_primary border-opacity-10 rounded-xl",children:[(0,Kt.jsx)(uo,{id:"slippage-input",placeholder:"1.5",regex:vs,value:r,onChange:i,className:`text-sm leading-none bg-transparent px-0.5 placeholder:text-t_text_primary/20 focus:outline-none ${r?"text-t_text_primary":"text-white"} `})," ","%"]})})]}),(0,Kt.jsxs)("div",{className:"text-sm opacity-60",children:[(0,Kt.jsx)("p",{children:"Slippage is the price variation you are willing to accept in the event that the price of the trade changes while it is processing."}),(0,Kt.jsx)("br",{}),(0,Kt.jsx)("p",{children:"If the trade fails due to too low slippage, you will receive USDC on the destination chain."})]})]})};var _a=require("react/jsx-runtime"),th=()=>(0,_a.jsxs)("div",{className:"flex flex-col gap-5 px-4",children:[(0,_a.jsx)(jp,{}),(0,_a.jsx)(Zp,{}),(0,_a.jsx)(eh,{})]});var Ma=require("react/jsx-runtime"),rh=()=>{let{dstChain:t,dstToken:e,srcChain:r,srcToken:n,setDstChain:i,setDstToken:a,setSrcChain:o,setSrcToken:f}=re();return(0,Ma.jsx)("div",{className:"h-[1px] w-full",children:(0,Ma.jsx)("button",{onClick:()=>{i(r),o(t),a(n),f(e)},"aria-label":"Switch target token with the source token",className:"absolute -translate-y-5 left-1/2 -translate-x-5 p-1 border border-solid border-t_text_primary border-opacity-10 rounded-xl bg-t_bg_secondary",children:(0,Ma.jsx)("div",{className:"relative bg-gradient-to-r from-t_main_accent_light to-t_main_accent_dark w-8 h-8 rounded-lg",children:(0,Ma.jsx)("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 fill-white",children:(0,Ma.jsx)(M1,{})})})})})};var _f={1:["0xdac17f958d2ee523a2206206994597c13d831ec7"]};var Ia=require("react");var nh=({rpcChainId:t,currentChainId:e,signer:r,tokenAddress:n})=>{let i=hf(),{supportedChains:a}=re(),o=(0,Ia.useMemo)(()=>{let f=a.find(d=>d.ecosystem==="evm"&&d.chainId===t)?.publicRpcUrls[0];return f&&n?new fe.Contract(n,tn,r&&(!e||e===t)?r:fe.getDefaultProvider(f)):null},[t,e,r,n,a]);return{balanceOf:(0,Ia.useCallback)(async f=>await i.query(o,"balanceOf",[f]),[o,i]),allowance:(0,Ia.useCallback)(async(f,d)=>await i.query(o,"allowance",[f,d]),[o,i]),approve:(0,Ia.useCallback)(async(f,d)=>await i.execute(o,"approve",[d,f]),[o,i])}};var Ut=require("react"),Gs=require("wagmi");var Vs=require("react"),ih=require("wagmi"),Jt=require("react/jsx-runtime"),e3=({connector:t,className:e})=>{switch(t.name){case"WalletConnect":return(0,Jt.jsx)(X1,{className:`w-[34px] h-[34px] rounded-md ${e||""}`});default:return(0,Jt.jsx)("img",{src:t.icon,alt:t.name,className:`w-[34px] h-[34px] rounded-md ${e||""}`})}},ah=({className:t,onClose:e})=>{let{connectors:r,connectAsync:n}=(0,ih.useConnect)(),i=(0,Vs.useMemo)(()=>r.filter(o=>{let f=o.type==="injected",d=o.name==="Injected";return o.type==="walletConnect"||f&&!d}),[r]),a=(0,Vs.useCallback)(async o=>{await n({connector:o}),e()},[n,e]);return(0,Jt.jsxs)("div",{className:`flex flex-col h-full ${t||""}`,children:[(0,Jt.jsxs)("div",{className:"flex justify-between",children:[(0,Jt.jsx)("div",{className:"text-base/4 mb-4 text-t_text_primary",children:"Pick wallet"}),(0,Jt.jsx)("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:e,children:(0,Jt.jsx)(lt,{})})]}),(0,Jt.jsx)("div",{className:"horizontal-separator"}),(0,Jt.jsx)("div",{className:"h-full pt-4",children:i.map(o=>(0,Jt.jsxs)("button",{onClick:()=>a(o),className:"flex items-center w-full gap-3 mt-2 mb-2 cursor-pointer p-4 border border-solid border-white border-opacity-0 hover:selected-wallet-item",children:[(0,Jt.jsx)(e3,{connector:o}),(0,Jt.jsx)("div",{className:"text-t_text_primary",children:o.name})]},o.id))})]})};var ti=require("react/jsx-runtime"),oh=()=>{let{address:t,chainId:e}=(0,Gs.useAccount)(),{switchChainAsync:r}=(0,Gs.useSwitchChain)(),[n,i]=(0,Ut.useState)(!1),{integrationConfig:a}=re(),{bridgeUI:o,error:f,srcChain:d,dstChain:p,srcToken:h,dstToken:w,srcValueWei:E,srcTokenBalanceWei:S,isFetchingRoute:A,isAsyncDataLoaded:_,hasOnConnectWalletCallback:I,onConnectWallet:N}=re(),{setTxStatus:L,setTxMsg:M,setTxModalOpen:V,enqueueTransaction:F}=rn(),B=(0,Ut.useMemo)(()=>d?.chainId,[d?.chainId]),J=(0,Ut.useMemo)(()=>p?.chainId,[p?.chainId]),Q=(0,Ut.useMemo)(()=>h?.address,[h?.address]),G=(0,Ut.useMemo)(()=>w?.address,[w?.address]),[ne,q]=(0,Ut.useState)("0"),{networks:{evm:ae}}=ba(),{allowance:T,approve:s}=nh({rpcChainId:B,currentChainId:ae.chainId,signer:ae.signer,tokenAddress:Q}),l=(0,Ut.useMemo)(()=>B?B===J?Wt[B]?.XSwapRouterSingleChain||"":Wt[B]?.XSwapRouter||"":"",[B,J]),g=(0,Ut.useCallback)(async()=>{if(l&&ae.address)try{let b=await T(ae.address,l);q(b.toString())}catch{q("0")}else q("0")},[T,ae.address,l]);(0,Ut.useEffect)(()=>{B&&_f[B]?.includes(Q)&&g()},[g,B,Q]);let v=(0,Ut.useCallback)(()=>{L(0),M(""),V(!0)},[V,M,L]),C=(0,Ut.useMemo)(()=>_?f?{text:f,fn:()=>{},disabled:!0}:t?!B||!J||!Q||!G?{text:"Select Tokens",fn:()=>{},disabled:!0}:B===J&&Q.toLowerCase()===G.toLowerCase()?{text:"Change Token",fn:()=>{},disabled:!0}:e?.toString()!==B?{text:"Change Chain",fn:async()=>await r({chainId:Number(B)}),disabled:!1}:E&&S&&er(E).gt(er(S))?{text:"Insufficient Balance",fn:()=>{},disabled:!0}:er(E||"0").lte(er("0"))?{text:"Enter Token Amount",fn:()=>{},disabled:!0}:A?{text:"Fetching Route",fn:()=>{},disabled:!0}:_f[B]?.includes(Q)&&ne!=="0"&&X.from(ne).lt(X.from(E))?{text:"Reset Approval",fn:async()=>{F({executeTransaction:()=>s("0",l),txStatus:1,txMsg:"You are going to reset your approval",handlers:{onSuccess:()=>{g(),L(5)}}})},disabled:!1}:{text:o?"Bridge":"Swap",fn:async()=>{v()},disabled:!1}:{text:a.defaultWalletPicker||I?"Connect Wallet":"Connect Wallet First",fn:()=>{a.defaultWalletPicker?i(!0):I&&N()},disabled:!a.defaultWalletPicker&&!I}:{text:"Loading XPay...",fn:()=>{},disabled:!0},[_,f,t,B,J,Q,G,e,E,S,A,ne,o,a.defaultWalletPicker,r,F,s,l,g,L,v]);return(0,ti.jsxs)(ti.Fragment,{children:[n&&(0,ti.jsx)(Aa,{onClose:()=>i(!1),children:(0,ti.jsx)(ah,{onClose:()=>i(!1)})}),(0,ti.jsx)("button",{type:"button",disabled:C.disabled,onClick:C.fn,className:`text-xl font-sans-bold font-bold w-full py-5 cursor-pointer disabled:cursor-not-allowed rounded-2xl border-none ${C.disabled?"bg-t_button_pr_off_bg text-t_button_pr_off_text":"bg-gradient-to-r from-t_main_accent_light to-t_main_accent_dark text-t_button_pr_text"}`,children:C.text})]})};var If=require("react");var ch=require("react");var Pa=require("react/jsx-runtime"),sh=()=>{let{srcTokenBalanceInfo:t,isFetchingBalance:e}=re();return(0,Pa.jsxs)("div",{className:"flex flex-col items-end",children:[(0,Pa.jsx)("p",{className:"text-xs font-medium opacity-60",children:"Balance:"}),e?(0,Pa.jsx)(Pr,{className:"w-[50px] h-[16px]"}):(0,Pa.jsx)("p",{className:`text-xs font-medium ${!t&&"opacity-60"}`,children:t||"-"})]})};var St=require("react/jsx-runtime"),fh=({type:t})=>{let{srcValue:e,srcValueUsd:r,dstValue:n,dstValueUsd:i,setSrcValue:a,isFetchingRoute:o}=re(),f=(0,ch.useMemo)(()=>t==="source"?r:i,[i,r,t]);return(0,St.jsxs)("div",{className:"flex justify-between items-center w-full p-4 gap-8 overflow-hidden",children:[(0,St.jsx)("div",{className:"flex flex-col font-medium w-full overflow-hidden text-left",children:t==="source"?(0,St.jsxs)(St.Fragment,{children:[(0,St.jsx)(uo,{id:"swap-amount-input",className:"bg-transparent border-none p-0 text-xl outline-0 font-sans-bold font-bold",regex:vs,value:e,onChange:d=>a(d)}),f&&(0,St.jsx)("div",{className:"text-sx opacity-60",children:`$${f}`})]}):o?(0,St.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,St.jsx)(Pr,{className:"w-[150px] h-[30px]"}),(0,St.jsx)(Pr,{className:"w-[100px] h-[20px]"})]}):(0,St.jsxs)(St.Fragment,{children:[(0,St.jsx)("div",{className:"text-xl text-t_text_secondary font-sans-bold font-bold",children:n||0}),f&&(0,St.jsx)("div",{className:"text-sx opacity-60",children:`$${f}`})]})}),t==="source"&&(0,St.jsx)(sh,{})]})};var xo=require("react");var ri=require("react"),lh=require("react-virtuoso");var zs=require("react"),Nr=require("react/jsx-runtime"),dh=({chain:t,type:e,onClick:r,disabled:n})=>{let{networks:{evm:i}}=ba(),{srcChain:a,dstChain:o,bridgeUI:f}=re(),d=(0,zs.useMemo)(()=>e==="source"?a?.chainId:o?.chainId,[o,a,e]),p=(0,zs.useMemo)(()=>i.signer&&i.chainId===t.chainId,[t.chainId,i.chainId,i.signer]),h=(0,zs.useMemo)(()=>{if(f)return e==="destination"?a?.chainId:o?.chainId},[f,o?.chainId,a?.chainId,e]),E=t.chainId===h?"Transfers between the same chains are not available":n?f?"Token is not available on this chain":`Swap from ${a?.displayName||"the source chain"} to this chain is currently not supported.`:"";return(0,Nr.jsx)("div",{className:"group relative",children:(0,Nr.jsxs)("div",{onClick:()=>{t.chainId===h||n||r(t.chainId)},className:`flex justify-between items-center gap-2 mt-2 mb-2 cursor-pointer p-4 border border-solid border-white border-opacity-0 hover:selected-chain-item ${d===t.chainId?"selected-chain-item":""} ${t.chainId===h||n?"disabled-chain-item cursor-default":""}`,children:[(0,Nr.jsxs)("div",{className:"flex gap-3 items-center w-full",children:[(0,Nr.jsx)("img",{src:t.image,alt:t.name,className:"w-[34px] h-[34px]"}),(0,Nr.jsx)("p",{children:t.displayName})]}),E&&(0,Nr.jsx)("div",{className:"w-full text-center opacity-0 group-hover:opacity-100 text-xs transition-opacity duration-200",children:E}),p&&(0,Nr.jsxs)("div",{className:"flex items-baseline gap-1",children:[(0,Nr.jsx)(B1,{}),(0,Nr.jsx)("div",{className:"text-t_text_green",children:"connected"})]})]})})};var Ht=require("react/jsx-runtime"),uh=({type:t,onClose:e})=>{let{setSrcChain:r,setDstChain:n,srcChainOptions:i,dstChainOptions:a}=re(),[o,f]=(0,ri.useState)(""),d=(0,ri.useRef)(null);(0,ri.useEffect)(()=>{d.current&&setTimeout(()=>{d.current?.focus()},10)},[]);let p=(0,ri.useMemo)(()=>{let w=t==="source"?i:a;return o?w.filter(E=>{let S=o.toLowerCase();return E.displayName.toLowerCase().includes(S)||E.chainId.toLowerCase().includes(S)}):w},[t,i,a,o]),h=w=>{let E=p.find(({chainId:S})=>S===w);if(!E)throw new Error("ChainPicker > selected chain id that is absent in chain options list.");t==="source"?r(E):n(E),e()};return(0,Ht.jsxs)("div",{className:"flex flex-col h-full",children:[(0,Ht.jsxs)("div",{className:"flex justify-between",children:[(0,Ht.jsx)("div",{className:"text-base/4 text-t_text_primary mb-4",children:`Pick ${t} chain`}),(0,Ht.jsx)("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:e,children:(0,Ht.jsx)(lt,{})})]}),(0,Ht.jsx)(Ws,{ref:d,inputIcon:(0,Ht.jsx)("div",{className:"fill-t_text_primary",children:(0,Ht.jsx)(Rs,{})}),placeholder:"Search chain name",value:o,handleChange:f}),(0,Ht.jsx)("div",{className:"horizontal-separator mt-4"}),(0,Ht.jsx)("div",{className:"h-full pt-4",children:p.length?(0,Ht.jsx)(lh.Virtuoso,{style:{height:"100%"},data:p,itemContent:(w,E)=>(0,Ht.jsx)(dh,{chain:E,type:t,disabled:E.disabled,onClick:h})}):(0,Ht.jsx)("div",{className:"flex justify-center mt-4",children:"No chain found."})})]})};var Xt=require("react/jsx-runtime"),ph=({chain:t,type:e,className:r})=>{let{srcChainLocked:n,dstChainLocked:i}=re(),a=(0,xo.useMemo)(()=>e==="destination"&&i,[e,i]),o=(0,xo.useMemo)(()=>e==="source"&&n,[e,n]),[f,d]=(0,xo.useState)(!1);return(0,Xt.jsxs)(Xt.Fragment,{children:[f&&(0,Xt.jsx)(Aa,{onClose:()=>d(!1),children:(0,Xt.jsx)(uh,{type:e,onClose:()=>d(!1)})}),(0,Xt.jsx)("button",{type:"button",disabled:a||o,onClick:()=>d(!0),className:`${r||""}`,children:(0,Xt.jsxs)("div",{className:"flex justify-between items-center p-4 gap-8",children:[(0,Xt.jsxs)("div",{className:"flex flex-col font-medium items-start",children:[(0,Xt.jsx)("p",{className:"text-xs opacity-60",children:e==="source"?"From:":"To:"}),(0,Xt.jsx)("p",{className:`${t?"":"opacity-60"}`,children:t?t.displayName:"Select"})]}),!a&&!o&&(0,Xt.jsx)("div",{className:"w-4 h-2 fill-t_text_primary",children:(0,Xt.jsx)(Ei,{})})]})})]})};var Mf=require("react/jsx-runtime"),hh=({type:t})=>{let{srcToken:e,srcTokenBalanceWei:r,srcTokenBalanceInfo:n,setSrcValue:i}=re();return(0,Mf.jsx)("button",{type:"button",className:`flex items-center w-16 justify-center p-4 gap-8 ${!n&&"opacity-60"} ${t==="source"&&"border-l border-solid border-t_text_primary border-opacity-10"}`,disabled:!n,onClick:()=>i(mt({amount:r,decimals:e?.decimals||18,precisionFractionalPlaces:e?.decimals||18})),children:t==="source"&&(0,Mf.jsx)("p",{className:`border-b border-solid border-t_text_primary ${!n&&"border-opacity-60"}`,children:"Max"})})};var ni=require("react");var gh=require("@fortawesome/free-solid-svg-icons"),yh=require("@fortawesome/react-fontawesome");var rt=require("react"),vh=require("react-virtuoso");var Ii=require("react/jsx-runtime"),xh=({token:t,selectedTokenAddress:e,onClick:r})=>(0,Ii.jsxs)("button",{type:"button",className:`flex gap-2 py-2 pr-[14px] pl-2 items-center border border-solid border-t_text_primary border-opacity-10 rounded-3xl text-start hover:bg-t_bg_tertiary hover:bg-opacity-10 ${t.address.toLowerCase()===e?.toLowerCase()?"bg-t_bg_tertiary bg-opacity-10":"bg-t_bg_primary"}`,onClick:r,children:[(0,Ii.jsx)($n,{token:t,className:"w-6 h-6",generatedLogoClassName:"w-6 h-6"}),(0,Ii.jsxs)("div",{className:"flex flex-col gap-1 text-xs font-medium !leading-3",children:[(0,Ii.jsx)("div",{className:"text-t_text_primary",children:t.name}),(0,Ii.jsx)("div",{className:"text-t_text_primary text-opacity-50",children:t.symbol})]})]});var Na=require("react"),mh=require("wagmi"),rr=require("react/jsx-runtime"),bh=({token:t,selectedTokenAddress:e,onClick:r,selectedChainId:n})=>{let{supportedChains:i,tokenPrices:a,isFetchingBalances:o}=re(),{address:f}=(0,mh.useAccount)(),d=(0,Na.useMemo)(()=>i.find(({chainId:S})=>S===t.chainId),[i,t]),p=(0,Na.useMemo)(()=>a[t.chainId]?.[t.address],[t,a]),h=(0,Na.useMemo)(()=>!t.balance||!t.decimals?null:Number(fe.utils.formatUnits(t.balance,t.decimals)),[t.balance,t.decimals]),w=(0,Na.useMemo)(()=>t.balance&&!t.balance.eq(0),[t.balance]),E=(0,Na.useMemo)(()=>!h||!p||!w?null:h*+p,[h,p,w]);return(0,rr.jsxs)("div",{className:`token-picker-container ${t.address.toLowerCase()===e?.toLowerCase()&&n&&t.chainId===n?"bg-t_bg_tertiary bg-opacity-10":""}`,onClick:r,children:[(0,rr.jsx)(ei,{token:t,chain:d,tokenLogoClassName:"min-w-9 w-9 h-9",generatedLogoClassName:"min-w-9 w-9 h-9 text-[16px]",chainLogoClassName:"w-5"}),(0,rr.jsxs)("div",{className:"flex justify-between items-center gap-1 w-full",children:[(0,rr.jsxs)("div",{className:"text-left",children:[(0,rr.jsx)("div",{className:"text-sm font-medium text-ellipsis text-t_text_primary",children:t.name}),(0,rr.jsx)("div",{className:"text-xs text-t_text_primary text-opacity-50 font-medium",children:t.symbol})]}),t.balance&&t.decimals&&f&&!o&&(0,rr.jsxs)("div",{className:"text-right",children:[(0,rr.jsx)("div",{className:"text-xs text-t_text_primary",children:t.balance.eq(0)||h>1e-4?mt({amount:t.balance.toString(),decimals:t.decimals,precisionFractionalPlaces:4}):"<0.0001"}),w&&(0,rr.jsx)("div",{className:"text-xs text-t_text_primary text-opacity-50",children:E?`$${E.toFixed(2)}`:"$ -"})]}),f&&o&&(0,rr.jsx)("div",{children:(0,rr.jsx)(Pr,{className:"w-[48px] h-[12px]"})})]})]})};var wh=require("wagmi"),ie=require("react/jsx-runtime"),Ch=({chain:t,tokens:e,otherTokens:r,selectedTokenAddress:n,isOpen:i,onSelect:a,setModalOpen:o,type:f})=>{let[d,p]=(0,rt.useState)(""),[h,w]=(0,rt.useState)(!1),[E,S]=(0,rt.useState)(!1),[A,_]=(0,rt.useState)(!1),[I,N]=(0,rt.useState)(null),[L,M]=(0,rt.useState)(!0),V=(0,rt.useRef)(0),F=(0,rt.useRef)(null),{bridgeUI:B,supportedChains:J,findTokenDataByAddressAndChain:Q,tokenPrices:G}=re(),{address:ne}=(0,wh.useAccount)(),q=so();(0,rt.useEffect)(()=>{S(!1),w(!1)},[i]);let ae=(0,rt.useCallback)(()=>{if(t&&I&&ha(d)){let y={};Pt||(y=JSON.parse(localStorage.getItem("custom-tokens")||"{}"));let m={address:I.address,symbol:I.symbol,name:I.name,tokenId:I.address,decimals:I.decimals,quickPick:!1,supported:!0,priority:0,chainId:t.chainId};Pt||(y[t.chainId]={...y[t.chainId]||{},[d.toLowerCase()]:m},localStorage.setItem("custom-tokens",JSON.stringify(y))),a(m),o(!1)}},[t,d,I,a,o]),T=(0,rt.useCallback)(async()=>{let y=Date.now();V.current=y;let m=J.find(({ecosystem:x,chainId:R})=>x==="evm"&&R===t?.chainId)?.publicRpcUrls[0],c=new fe.Contract(d.toLowerCase(),tn,fe.getDefaultProvider(m));_(!0);try{let x=await Promise.all([q.query(c,"decimals"),q.query(c,"name"),q.query(c,"symbol")]);if(y!==V.current)return;let[R,u,k]=x;N({address:d.toLowerCase(),decimals:R,name:u,symbol:k})}catch{N(null)}finally{y===V.current&&_(!1)}},[t,d,q,J]);(0,rt.useEffect)(()=>{!B&&ha(d)&&t&&!Q(d.toLowerCase(),t.chainId)?T():(_(!1),N(null))},[B,d,T,Q,t]),(0,rt.useEffect)(()=>{p("")},[i]);let s=(y,m)=>y.toLowerCase().indexOf(m.toLowerCase())>-1,l=(0,rt.useMemo)(()=>e?.filter(y=>s(y.symbol,d)||s(y.name,d)||y.address.toLowerCase()===d.toLowerCase()),[d,e]),g=(0,rt.useMemo)(()=>r?.filter(y=>s(y.symbol,d)||s(y.name,d)||y.address.toLowerCase()===d.toLowerCase()),[d,r]);(0,rt.useEffect)(()=>{i&&F.current&&setTimeout(()=>{F.current?.focus()},10)},[i]);let v=(0,rt.useMemo)(()=>{let y=u=>{if(!u.balance||!u.decimals)return 0;let k=Number(fe.utils.formatUnits(u.balance,u.decimals)),P=G[u.chainId]?.[u.address];return P?k*Number(P):0},m=[...l.filter(u=>X.from(u?.balance||"0").gt(0)),...g.filter(u=>X.from(u?.balance||"0").gt(0))].sort((u,k)=>{let P=y(u),O=y(k);return O!==P?O-P:k.priority-u.priority}),c=l.filter(u=>X.from(u?.balance||"0").eq(0)).sort((u,k)=>k.priority-u.priority),x=g.filter(u=>X.from(u?.balance||"0").eq(0)).sort((u,k)=>k.priority-u.priority);return(t?[...ne&&m.length&&f==="source"?[m]:[],c,x]:[...ne&&m.length&&f==="source"?[m]:[],[...c,...x]]).flat()},[l,g,t,ne,f,G]),C=(0,rt.useMemo)(()=>v.filter(y=>y.balance?.gt(0)),[v]),b=(0,rt.useMemo)(()=>t?[...f==="source"&&ne&&C.length?[C]:[],l,g]:[...f==="source"&&ne&&C.length?[C]:[],g],[t,f,ne,C,l,g]);return E?(0,ie.jsxs)(ie.Fragment,{children:[(0,ie.jsxs)("div",{className:"flex justify-between",children:[(0,ie.jsx)("div",{className:"text-base/4 mb-4",children:"Import token"}),(0,ie.jsx)("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:()=>o(!1),children:(0,ie.jsx)(lt,{})})]}),(0,ie.jsxs)("div",{className:"flex flex-col h-full gap-2",children:[I&&(0,ie.jsxs)("div",{className:"token-picker-container grow-0 bg-t_bg_secondary border border-solid border-t_text_primary border-opacity-10 rounded-xl py-2 pr-2 pl-4 hover:cursor-pointer",children:[(0,ie.jsx)(mo,{tokenName:I.name,className:"w-9 h-9 text-[15px]"}),(0,ie.jsxs)("div",{className:"flex justify-between items-center gap-1 overflow-hidden grow",children:[(0,ie.jsx)("div",{className:"overflow-hidden whitespace-nowrap text-ellipsis text-sm font-medium",children:I.name}),(0,ie.jsx)("div",{className:"token-picker__all__symbol",children:I.symbol})]}),(0,ie.jsxs)("div",{className:"text-sm flex items-center",children:[u1(d.toLowerCase()),(0,ie.jsx)("button",{type:"button",onClick:()=>navigator.clipboard.writeText(I.address.toLowerCase()),"aria-label":`Copy ${I.symbol} token address`,className:"flex items-center p-2 fill-white cursor-pointer hover:fill-t_main_accent_light",children:(0,ie.jsx)(R1,{className:"w-5 h-5"})})]})]}),(0,ie.jsx)("div",{className:"px-2 py-4 rounded-xl border border-x_orange text-sm",children:"Ensure that you have verified the token address and confirmed its correctness"}),(0,ie.jsxs)("div",{className:"bg-t_bg_secondary border border-solid border-t_text_primary border-opacity-10 rounded-xl p-2",children:[(0,ie.jsx)("div",{className:"text-sm mb-2",children:"Be mindful that anyone can create tokens, even counterfeit versions of existing ones. Certain tokens and their technical specifications might not be compatible with XSwap services. By importing such custom tokens, you acknowledge and consent to the associated risks."}),(0,ie.jsxs)("button",{type:"button",onClick:()=>w(y=>!y),className:"flex items-center",children:[(0,ie.jsx)("div",{className:"flex justify-center items-center p-1 w-6 h-6 border-2 border-white rounded-md mr-2",children:h&&(0,ie.jsx)(yh.FontAwesomeIcon,{icon:gh.faCheck,className:"w-4 h-4"})}),(0,ie.jsx)("div",{className:"font-bold",children:"Accept"})]})]}),(0,ie.jsx)("div",{className:"flex grow items-end justify-center",children:(0,ie.jsx)(Ir,{type:"button",disabled:!h,className:`token-picker__import-button w-full ${h?"":"!cursor-not-allowed"}`,onClick:ae,children:"Import"})})]})]}):(0,ie.jsxs)(ie.Fragment,{children:[(0,ie.jsxs)("div",{className:"flex justify-between",children:[(0,ie.jsx)("div",{className:"text-base/4 text-t_text_primary mb-4",children:`Pick ${f} token`}),(0,ie.jsx)("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:()=>o(!1),children:(0,ie.jsx)(lt,{})})]}),(0,ie.jsx)(Ws,{ref:F,inputIcon:(0,ie.jsx)("div",{className:"fill-t_text_primary",children:(0,ie.jsx)(Rs,{})}),placeholder:"Search name or paste address",value:d,handleChange:p}),(0,ie.jsx)("div",{className:`flex flex-wrap gap-1 my-4 mx-0 transition-all duration-300 ${L?"opacity-100 max-h-[200px]":"opacity-0 max-h-0 overflow-hidden"}`,children:e.filter(y=>y?.quickPick).map(y=>(0,ie.jsx)(xh,{token:y,selectedTokenAddress:n,onClick:()=>{a(y),o(!1)}},y.address))}),(0,ie.jsx)("div",{className:"flex flex-col mx-0 h-full",children:A?(0,ie.jsx)("div",{className:"flex justify-center w-full py-4 px-0",children:(0,ie.jsx)(nn,{className:"w-9 h-9"})}):(0,ie.jsx)(ie.Fragment,{children:I?(0,ie.jsxs)("div",{className:"token-picker-container hover:cursor-default",children:[(0,ie.jsx)(ei,{token:I,chain:t,tokenLogoClassName:"w-9 h-9",generatedLogoClassName:"w-9 h-9 text-[16px]",chainLogoClassName:"w-5"}),(0,ie.jsxs)("div",{className:"flex justify-between items-center gap-1 overflow-hidden grow",children:[(0,ie.jsxs)("div",{children:[(0,ie.jsx)("div",{className:"text-sm font-medium text-ellipsis",children:I.name}),(0,ie.jsx)("div",{className:"text-xs text-t_text_primary !text-opacity-50 font-medium",children:t?.displayName})]}),(0,ie.jsx)("div",{className:"token-picker__all__symbol",children:I.symbol})]}),(0,ie.jsx)("div",{children:(0,ie.jsx)(Ir,{type:"button",className:"h-8 py-0 px-4 text-t_text_primary leading-[14px] rounded-[32px] bg-gradient-to-r from-t_main_accent_light to-t_main_accent_dark",onClick:()=>S(!0),children:"Import"})})]}):(0,ie.jsx)("div",{className:"flex flex-col h-full gap-8 w-[calc(100%+32px)] mx-[-16px]",children:(0,ie.jsx)(vh.GroupedVirtuoso,{style:{maxHeight:"400px",height:"100%"},groupCounts:b.map(y=>y?.length),scrollerRef:y=>{y&&y.addEventListener("scroll",m=>{let c=m.target;M(c.scrollTop<10)})},groupContent:y=>(0,ie.jsxs)("div",{className:"py-1 bg-t_bg_primary text-t_text_primary",children:[(0,ie.jsx)("div",{className:"px-4 text-left",children:(()=>{if(t)switch(y){case 0:return ne?C.length&&f==="source"?"My tokens":`${t.displayName} network`:`${t.displayName} network`;case 1:return ne?`${t.displayName} network`:"Other networks";case 2:return"Other networks";default:return"Undefined group"}else switch(y){case 0:return ne&&C.length&&f==="source"?"My tokens":"All networks";case 1:return"All networks";default:return"Undefined group"}})()}),(0,ie.jsx)("div",{className:"horizontal-separator"}),!b[y]?.length&&(0,ie.jsx)("div",{className:"text-center py-1",children:"No token found"})]}),itemContent:y=>v[y]&&(0,ie.jsx)(bh,{token:v[y],selectedChainId:t?.chainId,selectedTokenAddress:n,onClick:()=>{a(v[y]),o(!1)}})})})})})]})};var Rt=require("react/jsx-runtime"),Ah=({chain:t,token:e,type:r,className:n})=>{let{bridgeUI:i,srcChainTokensOptions:a,srcChainOtherTokensOptions:o,dstChainTokensOptions:f,dstChainOtherTokensOptions:d,setSrcToken:p,setSrcChain:h,supportedChains:w,setDstToken:E,setDstChain:S,dstTokenLocked:A,srcTokenLocked:_}=re(),I=(0,ni.useMemo)(()=>r==="destination"&&A,[r,A]),N=(0,ni.useMemo)(()=>r==="source"&&_,[r,_]),[L,M]=(0,ni.useState)(!1),V=(0,ni.useMemo)(()=>r==="source"?a:f,[f,a,r]),F=(0,ni.useMemo)(()=>r==="destination"&&i,[i,r]),B=(0,ni.useMemo)(()=>r==="source"?o:d,[d,o,r]),J=Q=>{let G=w.find(ne=>ne.chainId===Q.chainId);r==="source"?(p(Q),h(G)):(E(Q),S(G)),M(!1)};return(0,Rt.jsxs)(Rt.Fragment,{children:[L&&(0,Rt.jsx)(Aa,{onClose:()=>M(!1),className:"z-[3]",children:(0,Rt.jsx)(Ch,{type:r,chain:t,tokens:V,otherTokens:B,selectedTokenAddress:e?.address,onSelect:J,isOpen:L,setModalOpen:M})}),(0,Rt.jsx)("button",{type:"button",disabled:F||I||N,onClick:()=>{M(!0)},className:`${n||""}`,children:(0,Rt.jsxs)("div",{className:"flex justify-between items-center p-4 gap-8 border-r border-solid border-t_text_primary border-opacity-10",children:[(0,Rt.jsxs)("div",{className:"flex gap-2 items-center",children:[(0,Rt.jsx)($n,{token:e,className:"w-9 h-9",generatedLogoClassName:"w-9 h-9 text-[16px]"}),(0,Rt.jsxs)("div",{className:"flex flex-col font-medium items-start",children:[(0,Rt.jsx)("p",{className:"text-xs opacity-60",children:"Token: "}),(0,Rt.jsx)("p",{className:`${e?"":"opacity-60"}`,children:e?e.symbol:r==="destination"&&i?"-":"Select"})]})]}),!F&&!I&&!N&&(0,Rt.jsx)("div",{className:"w-4 h-2 fill-t_text_primary",children:(0,Rt.jsx)(Ei,{})})]})})]})};var Bn=require("react/jsx-runtime"),Pf=({type:t})=>{let{srcChain:e,srcToken:r,dstChain:n,dstToken:i}=re(),a=(0,If.useMemo)(()=>t==="source"?r:i,[t,r,i]),o=(0,If.useMemo)(()=>t==="source"?e:n,[t,e,n]);return(0,Bn.jsxs)("div",{className:"flex flex-col x-border rounded-xl bg-t_bg_tertiary bg-opacity-5",children:[(0,Bn.jsxs)("div",{className:"flex border-b border-solid border-t_text_primary border-opacity-10",children:[(0,Bn.jsx)(Ah,{chain:o,token:a,type:t,className:"w-full flex-grow"}),(0,Bn.jsx)(ph,{chain:o,type:t,className:"w-full max-w-[160px]"})]}),(0,Bn.jsxs)("div",{className:`flex justify-between rounded-b-[11px] ${t==="destination"&&"bg-gradient-to-r from-t_main_accent_light/20 to-t_main_accent_dark/20"}`,children:[(0,Bn.jsx)(fh,{type:t}),(0,Bn.jsx)(hh,{type:t})]})]})};var Fn=require("react/jsx-runtime"),Th=()=>(0,Fn.jsxs)("div",{className:"flex flex-col gap-6 fill-t_text_primary",children:[(0,Fn.jsxs)("div",{className:"flex flex-col gap-[11px]",children:[(0,Fn.jsx)(Pf,{type:"source"}),(0,Fn.jsx)(rh,{}),(0,Fn.jsx)(Pf,{type:"destination"})]}),(0,Fn.jsx)(Hs,{}),(0,Fn.jsx)(oh,{})]});var Pi=require("react/jsx-runtime"),Nf=({onClose:t})=>{let{tab:e}=re(),r=(0,Sh.useMemo)(()=>e==="Settings"?(0,Pi.jsx)(th,{}):e==="History"?(0,Pi.jsx)(Jp,{}):(0,Pi.jsx)(Th,{}),[e]);return(0,Pi.jsxs)("div",{className:"relative flex flex-col gap-4 p-2 text-t_text_primary bg-t_bg_primary rounded-2xl flex-1",children:[(0,Pi.jsx)(Wp,{onClose:t}),r]})};var Eh=require("react"),Rr=require("react/jsx-runtime"),Ws=(0,Eh.forwardRef)((t,e)=>{let{inputIcon:r,required:n,name:i,value:a,placeholder:o,type:f,handleChange:d,error:p,warning:h,disabled:w=!1,className:E=""}=t;return(0,Rr.jsxs)(Rr.Fragment,{children:[(0,Rr.jsxs)("div",{className:"flex items-center border border-solid border-t_text_primary border-opacity-10 rounded-lg py-0 px-3 gap-2 bg-t_bg_secondary ",children:[r,(0,Rr.jsx)("input",{ref:e,disabled:w,required:!!n,name:i||"",value:a,placeholder:o,type:f||"text",className:`relative h-10 leading-10 z-[1] outline-none w-full text-t_text_primary bg-transparent border-none ${p?"border border-t_error_dark bg-gradient-to-r from-t_error_dark/15 to-t_bg_secondary/15 px-3 shadow-[0_0_6px_rgba(255,0,0,0.5)]":""} ${h?"border-t_warning_dark bg-gradient-to-r from-t_warning_dark/15 to-t_bg_secondary/15 px-3 shadow-[0_0_6px_rgba(255,165,0,0.5)]":""} ${E}`,onChange:S=>d(S.target.value)})]}),p&&(0,Rr.jsx)("div",{className:"flex justify-between pt-[10px]",children:(0,Rr.jsx)("div",{className:"px-5 text-t_text_red",children:p})}),h&&(0,Rr.jsx)("div",{className:"flex justify-between pt-[10px]",children:(0,Rr.jsx)("div",{className:"px-5 text-t_text_orange",children:h})})]})});var on=require("react"),Ra=class{static getTimeFromSeconds(e){let r=Math.floor(e/86400),n=Math.floor(e%(60*60*24)/(60*60)),i=Math.floor(e%(60*60)/60),a=Math.floor(e%60);return{days:r,hours:n,minutes:i,seconds:a}}static getSecondsFromExpiry(e){let r=new Date().getTime(),n=e.getTime();return Math.max(0,(n-r)/1e3)}},t3=({expiryTimestamp:t,onExpire:e,autoStart:r=!0})=>{let[n,i]=(0,on.useState)(r),[a,o]=(0,on.useState)(Ra.getSecondsFromExpiry(t)),f=(0,on.useCallback)(()=>{let w=Ra.getSecondsFromExpiry(t);w<=0&&(e&&e(),i(!1)),o(w)},[t,e]);(0,on.useEffect)(()=>{if(!n)return;let w=setInterval(f,1e3);return()=>clearInterval(w)},[n,f]);let d=(0,on.useCallback)(()=>i(!1),[]),p=(0,on.useCallback)(()=>i(!0),[]),h=(0,on.useCallback)(w=>{i(!0),o(Ra.getSecondsFromExpiry(w))},[]);return{...Ra.getTimeFromSeconds(a),isRunning:n,pause:d,resume:p,restart:h}},kh=t3;var qs=require("react"),yr=require("react/jsx-runtime");var _h=({expiryTimestamp:t,displayFormat:e=2,customTextOnExpire:r})=>{let[n,i]=(0,qs.useState)(t.getTime()<Date.now()),{seconds:a,minutes:o,hours:f,days:d,restart:p}=kh({expiryTimestamp:t,onExpire:()=>i(!0)});return(0,qs.useEffect)(()=>{p(t)},[t]),(0,yr.jsx)(yr.Fragment,{children:n&&r?(0,yr.jsx)(yr.Fragment,{children:r}):(0,yr.jsxs)(yr.Fragment,{children:[e===0&&(0,yr.jsx)("span",{children:`${(d*24+f)*60+o}:${a.toString().padStart(2,"0")}`}),e===1&&(0,yr.jsx)("span",{children:`${d*24+f}:${o.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`}),e===2&&(0,yr.jsx)("span",{children:`${d}:${f.toString().padStart(2,"0")}:${o.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`})]})})};var Ih=require("react");var Mh=require("react/jsx-runtime"),mo=({tokenName:t,className:e})=>(0,Mh.jsx)("div",{className:`rounded-full bg-white shadow-sm flex items-center justify-center text-black ${e}`,children:t.substring(0,1)});var Ks=require("react/jsx-runtime"),$n=({token:t,className:e,generatedLogoClassName:r})=>{let[n,i]=(0,Ih.useState)(!1);return t?n?(0,Ks.jsx)(mo,{tokenName:t.name,className:r}):t?.image?(0,Ks.jsx)("img",{src:t.image,alt:t.name,className:`border border-solid border-t_text_primary border-opacity-10 rounded-2xl ${e}`,onError:()=>i(!0)}):(0,Ks.jsx)(mo,{tokenName:t.name,className:r}):null};var bo=require("react/jsx-runtime"),ei=({token:t,chain:e,tokenLogoClassName:r,generatedLogoClassName:n,chainLogoClassName:i})=>(0,bo.jsxs)("div",{className:"relative flex items-end pr-1 pb-1",children:[(0,bo.jsx)($n,{token:t,className:r,generatedLogoClassName:n}),e&&(0,bo.jsx)("img",{src:e.image,alt:e.name,className:`absolute bottom-0 right-0 border border-solid border-t_bg_secondary rounded-3xl ${i}`})]});var Js=require("@tanstack/react-query"),ii=require("react"),Nh=require("react-error-boundary"),Xs=require("wagmi");function r3(t,e){function r(i){let a=document.getElementById(i);if(a&&a.shadowRoot){let o=new CSSStyleSheet;o.replaceSync(`:host { ${t}: ${e}; }`),a.shadowRoot.adoptedStyleSheets=[...a.shadowRoot.adoptedStyleSheets,o]}}["xpay-root","xpay-tx-status","xpay-widget"].forEach(r)}var n3={mainAccentLight:"#3681C6",mainAccentDark:"#2B4A9D",bgPrimary:"#FFFFFF",bgSecondary:"#FFFFFF1a",bgTertiary:"#020202",textPrimary:"#020202",textSecondary:"#3681C6",textRed:"#C62828",textOrange:"#FF6F00",textGreen:"#2E7D32",clickSecondary:"#3681C6",clickTertiary:"#020202",buttonPrText:"#ffffff",buttonPrOffBg:"#0202024D",buttonPrOffText:"#020202",labelText:"#FFFFFF",successDark:"#2E7D32",successLight:"#4CAF50",infoDark:"#3C3C3B",infoLight:"#90A4AE",warningDark:"#FF6F00",warningLight:"#FFCA28",errorDark:"#C62828",errorLight:"#F44336",chainlinkLogo:"#375BD2"},i3={mainAccentLight:"#3681C6",mainAccentDark:"#2B4A9D",bgPrimary:"#020202",bgSecondary:"#0F0F0F",bgTertiary:"#ffffff",textPrimary:"#FFFFFF",textSecondary:"#3681C6",textRed:"#F44336",textOrange:"#FFCA28",textGreen:"#4CAF50",clickSecondary:"#3681C6",clickTertiary:"#FFFFFF",buttonPrText:"#FFFFFF",buttonPrOffBg:"#272727",buttonPrOffText:"#90A4AE",labelText:"#FFFFFF",successDark:"#2E7D32",successLight:"#4CAF50",infoDark:"#3C3C3B",infoLight:"#D1D3D4",warningDark:"#FF6F00",warningLight:"#FFCA28",errorDark:"#C62828",errorLight:"#F44336",chainlinkLogo:"white"},a3={mainAccentLight:"--main-accent-light",mainAccentDark:"--main-accent-dark",bgPrimary:"--bg-primary",bgSecondary:"--bg-secondary",bgTertiary:"--bg-tertiary",textPrimary:"--text-primary",textSecondary:"--text-secondary",textTertiary:"--text-tertiary",textRed:"--text-red",textOrange:"--text-orange",textGreen:"--text-green",clickPrimary:"--click-primary",clickSecondary:"--click-secondary",clickTertiary:"--click-tertiary",buttonPrBg:"--button-pr-bg",buttonPrText:"--button-pr-text",buttonPrOffBg:"--button-pr-off-bg",buttonPrOffText:"--button-pr-off-text",labelBg:"--label-bg",labelText:"--label-text",successDark:"--success-dark",successLight:"--success-light",infoDark:"--info-dark",infoLight:"--info-light",warningDark:"--warning-dark",warningLight:"--warning-light",errorDark:"--error-dark",errorLight:"--error-light",width:"--modal-width",chainlinkLogo:"--chainlink-logo"};function Ph(t,e){let n={...t?{...n3}:{...i3},...e};for(let[i,a]of Object.entries(n)){let o=a3[i];o&&r3(o,a)}}var tt=require("react/jsx-runtime"),o3=new Js.QueryClient,s3=()=>{let{reconnect:t}=(0,Xs.useReconnect)();return(0,ii.useEffect)(()=>{let e=0,r=setInterval(()=>{t(),e++,e>=5&&clearInterval(r)},1e3);return()=>{clearInterval(r)}},[t]),(0,tt.jsx)(tt.Fragment,{})},c3=({onPendingTransactionsChange:t})=>{let{history:e}=xa(),r=(0,ii.useMemo)(()=>e.filter(n=>n.status==="IN_PROGRESS"),[e]);return(0,ii.useEffect)(()=>{t?t(r):window.xPayOnPendingTransactionsChange&&window.xPayOnPendingTransactionsChange(r)},[t,r]),(0,tt.jsx)(tt.Fragment,{})},Rf=({integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,supportedChains:d,onSubmit:p,onClose:h,overlay:w,lightTheme:E,defaultWalletPicker:S,styles:A,onPendingTransactionsChange:_,dstTokenLocked:I,dstChainLocked:N,srcTokenLocked:L,srcChainLocked:M,onDstTokenChange:V,onDstChainChange:F,onSrcTokenChange:B,onSrcChainChange:J,bridge:Q,onConnectWallet:G,override:ne,integratorFee:q,integratorFeeReceiverAddress:ae})=>{let T=l=>{l.stopPropagation(),l.nativeEvent.stopImmediatePropagation(),l.target===l.currentTarget&&w&&h()},s=(0,ii.useMemo)(()=>Ep(d),[d]);return(0,ii.useEffect)(()=>{Ph(E,A)},[E,A]),(0,ii.useEffect)(()=>{ne?.apiUrl&&_s(ne?.apiUrl)},[ne?.apiUrl]),(0,tt.jsx)(Nh.ErrorBoundary,{FallbackComponent:()=>(0,tt.jsx)("div",{children:"Something went wrong, please contact XSwap."}),children:(0,tt.jsx)(Xs.WagmiProvider,{config:s,children:(0,tt.jsxs)(Js.QueryClientProvider,{client:o3,children:[(0,tt.jsx)(s3,{}),(0,tt.jsxs)(ap,{children:[(0,tt.jsx)(c3,{onPendingTransactionsChange:_}),(0,tt.jsx)(up,{integrationConfig:{integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,defaultWalletPicker:S,dstTokenLocked:I,dstChainLocked:N,srcTokenLocked:L,srcChainLocked:M,onDstTokenChange:V,onDstChainChange:F,onSrcTokenChange:B,onSrcChainChange:J,bridge:Q,onConnectWallet:G,integratorFee:q,integratorFeeReceiverAddress:ae},supportedChains:d,wagmiConfig:s,overlay:w,children:(0,tt.jsx)(xp,{children:(0,tt.jsx)(Up,{children:w?(0,tt.jsx)("div",{className:"top-0 left-0 right-0 bottom-0 bg-[rgba(0,0,0,0.8)] fixed flex flex-col items-center justify-center z-10",onMouseDown:T,children:(0,tt.jsxs)("div",{className:"relative bg-t_bg_primary rounded-2xl overflow-auto text-t_text_primary border-[1px] border-solid border-[rgba(255,255,255,0.1)] w-x_modal min-w-x_modal max-w-x_modal min-h-[532px]",children:[(0,tt.jsx)(Nf,{onSubmit:p,onClose:h}),(0,tt.jsx)(kf,{})]})}):(0,tt.jsxs)("div",{className:"bg-t_bg_primary rounded-2xl overflow-auto text-t_text_primary border-[1px] border-solid border-[rgba(255,255,255,0.1)] min-h-[532px] w-x_modal min-w-x_modal max-w-x_modal flex flex-col",children:[(0,tt.jsx)(Nf,{onSubmit:()=>{},onClose:()=>{}}),(0,tt.jsx)(kf,{})]})})})})]})]})})})},Rh=async({integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,supportedChains:d,lightTheme:p,defaultWalletPicker:h,styles:w,onPendingTransactionsChange:E,dstTokenLocked:S,dstChainLocked:A,srcTokenLocked:_,srcChainLocked:I,override:N})=>{try{if(_n===null)throw new Error("XPay was incorrectly initialized");return await b1(),await new Promise(()=>{if(_n===null)throw new Error("XPay was incorrectly initialized");_n.render((0,tt.jsx)(Rf,{integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,supportedChains:d,lightTheme:p,styles:w,onSubmit:()=>{_n&&_n.render("")},onClose:()=>{_n&&_n.render("")},overlay:!0,defaultWalletPicker:h,onPendingTransactionsChange:E,dstTokenLocked:S,dstChainLocked:A,srcTokenLocked:_,srcChainLocked:I,override:N}))})}catch(L){throw new Error(`XSwap component error, ${L}`)}};var Ba=require("@fortawesome/free-solid-svg-icons"),Qs=require("@fortawesome/react-fontawesome");var Bh=require("date-fns"),Fh=require("react");var Ni=require("react/jsx-runtime"),Bf=({chain:t,token:e,amount:r})=>(0,Ni.jsxs)("div",{className:"flex gap-2",children:[(0,Ni.jsx)(ei,{token:e,chain:t,tokenLogoClassName:"min-w-9 w-9 h-9",generatedLogoClassName:"min-w-9 w-9 h-9 text-[16px]",chainLogoClassName:"w-5"}),(0,Ni.jsxs)("div",{className:"flex flex-col text-[12px]",children:[(0,Ni.jsx)("div",{className:"text-t_text_primary text-nowrap",children:`${Number(r)<1e-4?"<0.0001":r} ${e?.symbol?e?.symbol:"unknown"}`}),(0,Ni.jsx)("div",{className:"text-xs text-t_text_primary text-opacity-50",children:t?.displayName})]})]});var nt=require("react/jsx-runtime"),Zs=({transaction:t,supportedChains:e,srcToken:r,dstToken:n})=>{let a=(0,Fh.useCallback)(h=>(0,Bh.format)(new Date(h*1e3),"d MMM yyyy HH:mm:ss"),[])(t.timestamp),o=mt({amount:t.amountWei,decimals:r?.decimals||18,precisionFractionalPlaces:4}),f=mt({amount:t?.tokenOutAmount||"0",decimals:n?.decimals||18,precisionFractionalPlaces:4}),d=e.find(h=>h.chainId===t.sourceChainId),p=e.find(h=>h.chainId===t.targetChainId);return(0,nt.jsxs)("div",{className:"flex flex-col border border-t_text_primary border-opacity-10 rounded-lg bg-t_bg_primary p-4 gap-4 mb-2",children:[(0,nt.jsxs)("div",{className:"flex items-center gap-2 border-b border-solid border-t_text_primary border-opacity-10 pb-1",children:[(0,nt.jsx)("div",{className:"text-xs text-t_text_primary text-opacity-50",children:a}),(0,nt.jsxs)("div",{className:"flex grow justify-end items-center h-6",children:[t.status==="IN_PROGRESS"?(0,nt.jsxs)("div",{className:"flex items-center grow justify-end text-xs",children:[(0,nt.jsx)(Qs.FontAwesomeIcon,{icon:Ba.faHourglassHalf,className:"w-4 h-4 mr-1 text-t_text_orange"}),(0,nt.jsxs)("div",{className:"text-xs text-t_text_orange min-w-[108px]",children:["In progress (",(0,nt.jsx)(_h,{displayFormat:0,expiryTimestamp:new Date(t.estimatedDeliveryTimestamp),customTextOnExpire:"finalizing"}),")"]})]}):t.status==="DONE"?(0,nt.jsx)("div",{className:"flex items-center grow justify-end text-xs",children:(0,nt.jsx)("div",{className:" mr-1 text-t_text_green",children:"Done"})}):t.status==="REVERTED"?(0,nt.jsx)("div",{className:"flex items-center grow justify-end text-xs",children:(0,nt.jsx)("div",{className:"w-4 h-4 mr-1 text-t_text_red",children:"Reverted"})}):null,(0,nt.jsx)("a",{href:`${t.messageId?`${ua}${t.messageId}`:`${e.find(h=>h.chainId===t.sourceChainId)?.transactionExplorer}/${t.hash}`} `,target:"_blank",rel:"noreferrer",className:"no-underline ml-1.5 text-t_text_primary","aria-label":"Show the transaction in the chain explorer",children:(0,nt.jsx)(Qs.FontAwesomeIcon,{icon:Ba.faArrowUpRightFromSquare,className:"w-[14px] h-[14px] text-t_text_primary"})})]})]}),(0,nt.jsx)("div",{className:"flex flex-wrap gap-8",children:(0,nt.jsxs)("div",{className:"flex items-center gap-2",children:[(0,nt.jsx)(Bf,{chain:d,token:r,amount:o}),t.tokenOutAddress&&(0,nt.jsxs)(nt.Fragment,{children:[(0,nt.jsx)(Qs.FontAwesomeIcon,{icon:Ba.faArrowRight,className:"w-5 h-5 text-t_text_primary opacity-50 mx-1.5"}),(0,nt.jsx)(Bf,{chain:p,token:n,amount:f})]})]})})]})};var Lh=require("react/jsx-runtime"),Xp=({transaction:t})=>{let{supportedChains:e,findTokenDataByAddressAndChain:r}=re(),n=r(t.tokenAddress.toLowerCase(),t.sourceChainId),i=t.tokenOutAddress?r(t.tokenOutAddress?.toLowerCase(),t.targetChainId):void 0;return(0,Lh.jsx)(Zs,{transaction:t,supportedChains:e,srcToken:n,dstToken:i})};var Dh=require("react-dom"),Ff=require("react/jsx-runtime"),Hp=({id:t,children:e,onCloseClick:r,type:n="waiting",className:i})=>(0,Dh.createPortal)((0,Ff.jsx)("div",{className:"fixed box-border inset-0 z-20 flex items-center justify-center bg-black bg-opacity-80",onMouseDown:o=>{o.stopPropagation(),o.nativeEvent.stopImmediatePropagation(),o.target===o.currentTarget&&r()},children:(0,Ff.jsx)("div",{className:`relative bg-t_bg_primary rounded-3xl p-4 w-full min-w-[340px] overflow-auto max-w-x_modal border-2 ${n==="error"?"border-t_error_dark":n==="success"?"border-t_success_dark":n==="warning"?"border-t_warning_dark":n==="waiting"?"border-t_main_accent_dark":"border-t_text_primary border-opacity-10"} ${i}`,children:e})}),Ci,t);var go=require("react");var ut=require("react/jsx-runtime"),f3=({transaction:t,supportedChains:e,srcToken:r,dstToken:n})=>{let[i,a]=(0,go.useState)(!1),o=(0,go.useMemo)(()=>t?.status==="DONE"?"bg-t_bg_primary bg-gradient-to-r from-t_success_light/20 to-t_success_dark/20":"bg-t_bg_primary bg-gradient-to-r from-t_main_accent_light/20 to-t_main_accent_dark/20]",[t]),f=(0,go.useMemo)(()=>t?.status==="DONE"?"border border-solid border-t_success_dark":"border border-solid border-t_main_accent_dark",[t]);return(0,ut.jsxs)("div",{className:"flex gap-2 items-end justify-end flex-wrap",onClick:()=>a(d=>!d),children:[i&&(0,ut.jsx)(Zs,{transaction:t,supportedChains:e,srcToken:r,dstToken:n}),(0,ut.jsx)("div",{className:`text-t_text_primary rounded-xl h-14 w-20 mb-2 cursor-pointer ${o} ${f}`,children:(0,ut.jsxs)("div",{className:"flex gap-2 items-center h-14 w-20 justify-center fill-t_text_primary",children:[(0,ut.jsx)("div",{className:`${i?"rotate-180":""}`,children:(0,ut.jsx)(_1,{})}),(0,ut.jsx)("div",{className:"relative flex items-center justify-center w-9 h-9",children:t?.status==="DONE"?(0,ut.jsx)("div",{className:"w-5 h-5 fill-t_success_dark",children:(0,ut.jsx)(Ps,{})}):(0,ut.jsxs)(ut.Fragment,{children:[(0,ut.jsx)("div",{className:"w-5 h-5",children:(0,ut.jsx)(Y1,{})}),(0,ut.jsx)("div",{className:"absolute flex items-center justify-center top-0 left-0 right-0 bottom-0 text-t_text_primary",children:(0,ut.jsx)(nn,{className:"w-10 h-10"})})]})})]})})]})},Ri=[],Oh=t=>{Ri.some(({transaction:e})=>e.hash===e.hash)||Ri.push(t)},Uh=t=>{Ri=[...Ri.filter(r=>r.transaction.hash!==t)]},Hh=t=>{Ri=Ri.map(e=>e.transaction.hash===t?{...e,transaction:{...e.transaction,status:"DONE"}}:e)},Ys=()=>{let t=Ri.map(e=>(0,ut.jsx)(f3,{...e},e.transaction.hash));if(ks===null)throw new Error("XPay was incorrectly initialized");ks.render((0,ut.jsx)("div",{className:"fixed bottom-5 right-2 flex flex-col gap-3 pl-9 items-end w-full z-50",children:t}))};var Vh=Et(require("@r2wc/core")),Lf=Et(require("react")),Gh=require("react-dom/client"),d3=(t,e,r)=>{let n=(0,Gh.createRoot)(t),i=Lf.default.createElement(e,r);return n.render(i),{root:n,ReactComponent:e}},l3=({root:t,ReactComponent:e},r)=>{let n=Lf.default.createElement(e,r);t.render(n)},u3=({root:t})=>{t.unmount()},zh=(t,e={})=>(0,Vh.default)(t,e,{mount:d3,update:l3,unmount:u3});var yo=require("react");var Ln=require("react/jsx-runtime"),p3=({integratorId:t,dstChain:e,dstToken:r,srcChain:n,srcToken:i,customContractCalls:a=[],desc:o,dstDisplayToken:f,lightTheme:d,defaultWalletPicker:p,styles:h,onPendingTransactionsChange:w,dstTokenLocked:E,dstChainLocked:S,srcTokenLocked:A,srcChainLocked:_,onDstTokenChange:I,onDstChainChange:N,onSrcTokenChange:L,onSrcChainChange:M,onConnectWallet:V,bridge:F,override:B,integratorFee:J,integratorFeeReceiverAddress:Q})=>{let[G,ne]=(0,yo.useState)(!0),[q,ae]=(0,yo.useState)([]);(0,yo.useEffect)(()=>{(async()=>{ne(!0),B?.apiUrl&&_s(B.apiUrl);let s=(await Ti()).filter(({web3Environment:l,bridgeSupported:g,swapSupported:v})=>l==="mainnet"&&(g||v));ae(s),ne(!1)})()},[]);let T=(()=>{try{return typeof h=="string"?JSON.parse(h):h||void 0}catch(s){console.error("Error parsing styles:",s)}})();return(0,Ln.jsxs)(Ln.Fragment,{children:[(0,Ln.jsx)("style",{children:Ts}),G?(0,Ln.jsx)("div",{className:"min-h-[532px] w-full flex items-center justify-center",children:(0,Ln.jsx)(nn,{className:"w-10 h-10"})}):(0,Ln.jsx)(Rf,{integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,supportedChains:q,overlay:!1,lightTheme:d,defaultWalletPicker:p,styles:T,onPendingTransactionsChange:w,dstTokenLocked:E,dstChainLocked:S,srcTokenLocked:A,srcChainLocked:_,onDstTokenChange:I,onDstChainChange:N,onSrcTokenChange:L,onSrcChainChange:M,onConnectWallet:V,bridge:F,override:B,integratorFee:J,integratorFeeReceiverAddress:Q})]})},js=()=>{if(Pt||typeof customElements>"u")return{};let t=zh(p3,{shadow:"open",props:{integratorId:"string",dstChain:"string",dstToken:"string",srcChain:"string",srcToken:"string",customContractCalls:"json",desc:"string",dstDisplayToken:"string",lightTheme:"boolean",defaultWalletPicker:"boolean",styles:"json",onPendingTransactionsChange:"function",dstTokenLocked:"boolean",dstChainLocked:"boolean",srcTokenLocked:"boolean",srcChainLocked:"boolean",bridge:"boolean",onDstTokenChange:"function",onDstChainChange:"function",onSrcTokenChange:"function",onSrcChainChange:"function",override:"json",integratorFee:"number",integratorFeeReceiverAddress:"string"}});return t.prototype.connectedCallback=function(){this.id="xpay-widget"},t};var Wh=require("@tanstack/react-query"),qh=require("react");var Kh=require("react/jsx-runtime"),h3=js();!Wh.isServer&&typeof customElements<"u"&&(customElements.get("xpay-widget")||customElements.define("xpay-widget",h3));var $s=({integratorId:t,dstChain:e,dstToken:r,srcChain:n,srcToken:i,customContractCalls:a=[],desc:o,dstDisplayToken:f,lightTheme:d,defaultWalletPicker:p,styles:h,onPendingTransactionsChange:w,dstTokenLocked:E,dstChainLocked:S,srcTokenLocked:A,srcChainLocked:_,onDstTokenChange:I,onDstChainChange:N,onSrcTokenChange:L,onSrcChainChange:M,onConnectWallet:V,bridge:F,override:B,integratorFee:J,integratorFeeReceiverAddress:Q})=>((0,qh.useEffect)(()=>{window.xPayOnPendingTransactionsChange=w,window.xPayOnDstTokenChange=I,window.xPayOnDstChainChange=N,window.xPayOnSrcTokenChange=L,window.xPayOnSrcChainChange=M,window.xPayOnConnectWallet=V},[w,I,N,L,M,V]),(0,Kh.jsx)("xpay-widget",{"integrator-id":t,"dst-chain":e,"dst-token":r,"src-chain":n,"src-token":i,"custom-contract-calls":JSON.stringify(a),desc:o,"dst-display-token":f,"light-theme":d,"default-wallet-picker":p,styles:typeof h=="string"?h:JSON.stringify(h),"dst-token-locked":E,"dst-chain-locked":S,"src-token-locked":A,"src-chain-locked":_,bridge:F,override:JSON.stringify(B),"integrator-fee":J,"integrator-fee-receiver-address":Q}));var Xh=Et(require("async-retry"));var Jh=async(t,e)=>{let r=t.publicRpcUrls[0],n=new fe.Contract(e.toLowerCase(),tn,fe.getDefaultProvider(r));try{let i=async(p,h,w=[])=>p?.provider?await p[h](...w):null,a=await Promise.all([i(n,"decimals"),i(n,"name"),i(n,"symbol")]),[o,f,d]=a;return{address:e,symbol:d,tokenId:e,name:f,decimals:o,quickPick:!1,supported:!0,priority:0}}catch{throw new Error(`Provided token ${e} does not exists on chain ${t.displayName}`)}};var Rp=async(t,e,r,n)=>{let i=await x3(t,e),a=(await Ti()).filter(({web3Environment:J,swapSupported:Q})=>J==="mainnet"&&Q),o=i.logs?.find(J=>J.topics[0]===fe.utils.id(ju));if(!o)throw new Error(`No transaction event found for chain ${t} tx ${e}`);let f=o?.topics[1],p=new fe.utils.Interface($u).parseLog(o);if(!p)throw new Error(`No transaction event arguments found for chain ${t} tx ${e}`);let h=p.args,w=a.find(J=>J.chainId===t.toString());if(!w)throw new Error(`Unknown src chain ${t}`);let E=(h?.token.toString()).toLowerCase(),S=w.tokens.find(J=>J.address.toLowerCase()===E);S||(S=await Jh(w,E));let A=a.find(J=>J.ccipChainId===h?.destinationChainSelector?.toString()),_=A?.chainId;if(!_)throw new Error("Unknown destination chain!");let I;r&&(I=A.tokens.find(J=>J.address.toLowerCase()===r.toLowerCase()));let N=Date.now()/1e3,L={hash:i.transactionHash,timestamp:N,sourceChainId:w.chainId,targetChainId:A.chainId,amountWei:h?.tokenAmount.toString(),tokenAddress:S.address,tokenOutAddress:I?.address,tokenOutAmount:n,estimatedDeliveryTimestamp:h?.valueForInstantCcipRecieve.toString()!=="0"?N*1e3+30*1e3:N*1e3+30*60*1e3,status:"IN_PROGRESS"};Oh({transaction:L,supportedChains:a,dstToken:I,srcToken:S}),Ys();let M=Wt[_]?.XSwapRouter;if(!M)throw new Error("Unknown destination XSwapRouter!");let V=new fe.Contract(M,t1,fe.getDefaultProvider(a.find(J=>J.chainId===_)?.publicRpcUrls[0])),F={address:M,topics:[fe.utils.id(e1),f]},B=async()=>{Hh(e),Ys(),await new Promise(J=>setTimeout(()=>J(!0),Yu)),Uh(e),Ys()};Kc({transferId:f}).then(J=>{J.status==="DONE"?B():(setTimeout(()=>Kc({transferId:f}).then(Q=>{Q.status==="DONE"&&B()}),30*60*1e3),V.once(F,()=>B()))})},x3=async(t,e)=>{try{let r=(await Ti()).find(i=>i.chainId===t),n=new fe.providers.JsonRpcProvider(r?.publicRpcUrls[0]);return await(0,Xh.default)(async()=>{let i=await n.getTransactionReceipt(e);if(!i)throw new Error("Couldn't fetch tx receipt");return i})}catch{throw new Error(`Couldn't fetch tx ${e} receipt on chain ${t}`)}};var e0=async({integratorId:t,dstChain:e,dstToken:r,srcChain:n,srcToken:i,customContractCalls:a=[],desc:o,dstDisplayToken:f,lightTheme:d,defaultWalletPicker:p,styles:h,onPendingTransactionsChange:w,dstTokenLocked:E,dstChainLocked:S,srcTokenLocked:A,srcChainLocked:_,onDstTokenChange:I,onDstChainChange:N,onSrcTokenChange:L,onSrcChainChange:M,bridge:V})=>{let F=(await Ti()).filter(({web3Environment:B,swapSupported:J})=>B==="mainnet"&&J);m3(t,F,e,r,n,i),await Rh({integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,supportedChains:F,lightTheme:d,defaultWalletPicker:p,styles:h,onPendingTransactionsChange:w,dstTokenLocked:E,dstChainLocked:S,srcTokenLocked:A,srcChainLocked:_,onDstTokenChange:I,onDstChainChange:N,onSrcTokenChange:L,onSrcChainChange:M,bridge:V})},m3=(t,e,r,n,i,a)=>{if(!t)throw new Error("Provide integratorId or contact the team to generate one.");if(r){let o=e.find(({chainId:f})=>f===r);if(!o)throw new Error(`Provided chain '${r}' is not supported`);if(n&&(!ha(n)||o.tokens.findIndex(({address:f})=>f.toLowerCase()===n.toLowerCase())===-1))throw new Error(`Provided token address ${n} on chain ${r} is invalid`)}if(i){let o=e.find(({chainId:f})=>f===i);if(!o)throw new Error(`Provided chain '${i}' is not supported`);if(a&&(!ha(a)||o.tokens.findIndex(({address:f})=>f.toLowerCase()===a.toLowerCase())===-1))throw new Error(`Provided token address ${a} on chain ${i} is invalid`)}};var Qh=js();m1();var b3={openTransactionModal:e0,TxWidget:$s,TxWidgetWC:Qh},g3=b3;0&&(module.exports={ContractName,Ecosystem,Environment,TxStatus,TxWidget,TxWidgetWC,Web3Environment,XSwapCallType,openTransactionModal});
|
|
91
|
+
${t?"translate-x-[12px] bg-t_main_accent_light":"bg-t_bg_tertiary"} `})]})});ho.displayName="ToggleButton";var Qp=require("react"),an=require("react/jsx-runtime"),Zp=()=>{let t=(0,Qp.useRef)(null),{infiniteApproval:e,setInfiniteApproval:r}=re();return(0,an.jsxs)("div",{className:"flex flex-col gap-5 pt-5 border-t border-solid border-white border-opacity-10",children:[(0,an.jsx)("h1",{className:"text-sm font-medium text-left",children:"Approval"}),(0,an.jsx)("div",{className:"flex gap-2 items-center justify-between flex-wrap",children:(0,an.jsxs)("div",{className:"flex items-center",children:[(0,an.jsx)("h2",{className:"text-xs",children:"Infinite approval: "}),(0,an.jsx)(ho,{checked:e,onClick:()=>{r(n=>!n)}}),(0,an.jsx)(Ca,{text:"Enabling infinite approval allows to access your tokens without requiring repeated approvals for each transaction. This streamlines multiple transactions but may pose a security risk if the spender's address is compromised.",position:"BOTTOM",triggerRef:t,id:"infinite-approval-tooltip"}),(0,an.jsx)(ki,{ref:t,className:"cursor-help fill-t_main_accent_light w-[18px] h-[18px]"})]})})]})};var Yp=require("react"),gr=require("react/jsx-runtime"),jp=()=>{let t=(0,Yp.useRef)(null),{expressDelivery:e,setExpressDelivery:r}=re();return(0,gr.jsxs)("div",{className:"flex flex-col gap-5 pt-5 border-t border-solid border-t_text_primary border-opacity-10",children:[(0,gr.jsx)("h1",{className:"text-sm font-medium text-left",children:"Delivery"}),(0,gr.jsxs)("div",{className:"flex gap-2 items-center justify-between flex-wrap",children:[(0,gr.jsxs)("div",{className:"flex items-center",children:[(0,gr.jsx)("h2",{className:"text-xs",children:"Express delivery: "}),(0,gr.jsx)(ho,{checked:e,onClick:()=>{r(n=>!n)}}),(0,gr.jsx)(Ca,{text:"Express delivery is a special feature of XSwap that reduces transaction time across chains to around 30 seconds. It is currently available for swaps below a value of $1000 USD.",position:"BOTTOM",triggerRef:t,id:"express-delivery-tooltip"}),(0,gr.jsx)(ki,{ref:t,className:"cursor-help fill-t_main_accent_light w-[18px] h-[18px]"})]}),(0,gr.jsxs)("div",{className:"text-xs font-medium",children:[(0,gr.jsx)("span",{className:"text-xs font-medium opacity-60",children:"Max time: "}),e?"30 sec":"30 min"]})]})]})};var $p=require("react"),Kt=require("react/jsx-runtime"),eh=()=>{let{slippage:t,setSlippage:e}=re(),[r,n]=(0,$p.useState)(t),i=f=>{f.length===0?(n(""),e(a)):(f.length>=5&&(f=f.substring(0,5)),Number(f)<=100&&(n(f),e(f)))},a="1.5";return(0,Kt.jsxs)("div",{className:"flex flex-col gap-5 pt-5 border-t border-solid border-t_text_primary border-opacity-10",children:[(0,Kt.jsx)("h1",{className:"text-sm font-medium text-left",children:"Slippage"}),(0,Kt.jsxs)("div",{className:"flex items-center gap-2 w-full",children:[(0,Kt.jsx)("div",{className:"flex items-center bg-t_bg_tertiary bg-opacity-5 p-1 border border-solid border-t_text_primary border-opacity-10 rounded-xl gap-2",children:["0.5","1.5","3.0"].map(f=>(0,Kt.jsx)("button",{type:"button",onClick:()=>i(f),className:`block rounded-lg text-sm bg-transparent h-7 px-1 hover:bg-gradient-to-r hover:from-t_main_accent_light hover:to-t_main_accent_dark hover:opacity-100 ${t===f?"gradient-slippage-container-blue text-white opacity-100":"text-t_text_primary opacity-20"}`,children:`${f}%`},f))}),(0,Kt.jsx)("div",{className:`${r?"gradient-slippage-container-blue p-[1px] rounded-xl":""}`,children:(0,Kt.jsxs)("div",{className:"bg-t_bg_primary p-1 h-full border border-solid border-t_text_primary border-opacity-10 rounded-xl",children:[(0,Kt.jsx)(uo,{id:"slippage-input",placeholder:"1.5",regex:vs,value:r,onChange:i,className:`text-sm leading-none bg-transparent px-0.5 placeholder:text-t_text_primary/20 focus:outline-none ${r?"text-t_text_primary":"text-white"} `})," ","%"]})})]}),(0,Kt.jsxs)("div",{className:"text-sm opacity-60",children:[(0,Kt.jsx)("p",{children:"Slippage is the price variation you are willing to accept in the event that the price of the trade changes while it is processing."}),(0,Kt.jsx)("br",{}),(0,Kt.jsx)("p",{children:"If the trade fails due to too low slippage, you will receive USDC on the destination chain."})]})]})};var _a=require("react/jsx-runtime"),th=()=>(0,_a.jsxs)("div",{className:"flex flex-col gap-5 px-4",children:[(0,_a.jsx)(jp,{}),(0,_a.jsx)(Zp,{}),(0,_a.jsx)(eh,{})]});var Ma=require("react/jsx-runtime"),rh=()=>{let{dstChain:t,dstToken:e,srcChain:r,srcToken:n,setDstChain:i,setDstToken:a,setSrcChain:o,setSrcToken:f}=re();return(0,Ma.jsx)("div",{className:"h-[1px] w-full",children:(0,Ma.jsx)("button",{onClick:()=>{i(r),o(t),a(n),f(e)},"aria-label":"Switch target token with the source token",className:"absolute -translate-y-5 left-1/2 -translate-x-5 p-1 border border-solid border-t_text_primary border-opacity-10 rounded-xl bg-t_bg_secondary",children:(0,Ma.jsx)("div",{className:"relative bg-gradient-to-r from-t_main_accent_light to-t_main_accent_dark w-8 h-8 rounded-lg",children:(0,Ma.jsx)("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 fill-white",children:(0,Ma.jsx)(M1,{})})})})})};var _f={1:["0xdac17f958d2ee523a2206206994597c13d831ec7"]};var Ia=require("react");var nh=({rpcChainId:t,currentChainId:e,signer:r,tokenAddress:n})=>{let i=hf(),{supportedChains:a}=re(),o=(0,Ia.useMemo)(()=>{let f=a.find(d=>d.ecosystem==="evm"&&d.chainId===t)?.publicRpcUrls[0];return f&&n?new fe.Contract(n,tn,r&&(!e||e===t)?r:fe.getDefaultProvider(f)):null},[t,e,r,n,a]);return{balanceOf:(0,Ia.useCallback)(async f=>await i.query(o,"balanceOf",[f]),[o,i]),allowance:(0,Ia.useCallback)(async(f,d)=>await i.query(o,"allowance",[f,d]),[o,i]),approve:(0,Ia.useCallback)(async(f,d)=>await i.execute(o,"approve",[d,f]),[o,i])}};var Ut=require("react"),Gs=require("wagmi");var Vs=require("react"),ih=require("wagmi"),Jt=require("react/jsx-runtime"),e3=({connector:t,className:e})=>{switch(t.name){case"WalletConnect":return(0,Jt.jsx)(X1,{className:`w-[34px] h-[34px] rounded-md ${e||""}`});default:return(0,Jt.jsx)("img",{src:t.icon,alt:t.name,className:`w-[34px] h-[34px] rounded-md ${e||""}`})}},ah=({className:t,onClose:e})=>{let{connectors:r,connectAsync:n}=(0,ih.useConnect)(),i=(0,Vs.useMemo)(()=>r.filter(o=>{let f=o.type==="injected",d=o.name==="Injected";return o.type==="walletConnect"||f&&!d}),[r]),a=(0,Vs.useCallback)(async o=>{await n({connector:o}),e()},[n,e]);return(0,Jt.jsxs)("div",{className:`flex flex-col h-full ${t||""}`,children:[(0,Jt.jsxs)("div",{className:"flex justify-between",children:[(0,Jt.jsx)("div",{className:"text-base/4 mb-4 text-t_text_primary",children:"Pick wallet"}),(0,Jt.jsx)("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:e,children:(0,Jt.jsx)(lt,{})})]}),(0,Jt.jsx)("div",{className:"horizontal-separator"}),(0,Jt.jsx)("div",{className:"h-full pt-4",children:i.map(o=>(0,Jt.jsxs)("button",{onClick:()=>a(o),className:"flex items-center w-full gap-3 mt-2 mb-2 cursor-pointer p-4 border border-solid border-white border-opacity-0 hover:selected-wallet-item",children:[(0,Jt.jsx)(e3,{connector:o}),(0,Jt.jsx)("div",{className:"text-t_text_primary",children:o.name})]},o.id))})]})};var ti=require("react/jsx-runtime"),oh=()=>{let{address:t,chainId:e}=(0,Gs.useAccount)(),{switchChainAsync:r}=(0,Gs.useSwitchChain)(),[n,i]=(0,Ut.useState)(!1),{integrationConfig:a}=re(),{bridgeUI:o,error:f,srcChain:d,dstChain:p,srcToken:h,dstToken:w,srcValueWei:E,srcTokenBalanceWei:S,isFetchingRoute:A,isAsyncDataLoaded:_,hasOnConnectWalletCallback:I,onConnectWallet:N}=re(),{setTxStatus:L,setTxMsg:M,setTxModalOpen:V,enqueueTransaction:F}=rn(),B=(0,Ut.useMemo)(()=>d?.chainId,[d?.chainId]),J=(0,Ut.useMemo)(()=>p?.chainId,[p?.chainId]),Q=(0,Ut.useMemo)(()=>h?.address,[h?.address]),G=(0,Ut.useMemo)(()=>w?.address,[w?.address]),[ne,q]=(0,Ut.useState)("0"),{networks:{evm:ae}}=ba(),{allowance:T,approve:s}=nh({rpcChainId:B,currentChainId:ae.chainId,signer:ae.signer,tokenAddress:Q}),l=(0,Ut.useMemo)(()=>B?B===J?Wt[B]?.XSwapRouterSingleChain||"":Wt[B]?.XSwapRouter||"":"",[B,J]),g=(0,Ut.useCallback)(async()=>{if(l&&ae.address)try{let b=await T(ae.address,l);q(b.toString())}catch{q("0")}else q("0")},[T,ae.address,l]);(0,Ut.useEffect)(()=>{B&&_f[B]?.includes(Q)&&g()},[g,B,Q]);let v=(0,Ut.useCallback)(()=>{L(0),M(""),V(!0)},[V,M,L]),C=(0,Ut.useMemo)(()=>_?f?{text:f,fn:()=>{},disabled:!0}:t?!B||!J||!Q||!G?{text:"Select Tokens",fn:()=>{},disabled:!0}:B===J&&Q.toLowerCase()===G.toLowerCase()?{text:"Change Token",fn:()=>{},disabled:!0}:e?.toString()!==B?{text:"Change Chain",fn:async()=>await r({chainId:Number(B)}),disabled:!1}:E&&S&&er(E).gt(er(S))?{text:"Insufficient Balance",fn:()=>{},disabled:!0}:er(E||"0").lte(er("0"))?{text:"Enter Token Amount",fn:()=>{},disabled:!0}:A?{text:"Fetching Route",fn:()=>{},disabled:!0}:_f[B]?.includes(Q)&&ne!=="0"&&X.from(ne).lt(X.from(E))?{text:"Reset Approval",fn:async()=>{F({executeTransaction:()=>s("0",l),txStatus:1,txMsg:"You are going to reset your approval",handlers:{onSuccess:()=>{g(),L(5)}}})},disabled:!1}:{text:o?"Bridge":"Swap",fn:async()=>{v()},disabled:!1}:{text:a.defaultWalletPicker||I?"Connect Wallet":"Connect Wallet First",fn:()=>{a.defaultWalletPicker?i(!0):I&&N()},disabled:!a.defaultWalletPicker&&!I}:{text:"Loading XPay...",fn:()=>{},disabled:!0},[_,f,t,B,J,Q,G,e,E,S,A,ne,o,a.defaultWalletPicker,r,F,s,l,g,L,v]);return(0,ti.jsxs)(ti.Fragment,{children:[n&&(0,ti.jsx)(Aa,{onClose:()=>i(!1),children:(0,ti.jsx)(ah,{onClose:()=>i(!1)})}),(0,ti.jsx)("button",{type:"button",disabled:C.disabled,onClick:C.fn,className:`text-xl font-sans-bold font-bold w-full py-5 cursor-pointer disabled:cursor-not-allowed rounded-2xl border-none ${C.disabled?"bg-t_button_pr_off_bg text-t_button_pr_off_text":"bg-gradient-to-r from-t_main_accent_light to-t_main_accent_dark text-t_button_pr_text"}`,children:C.text})]})};var If=require("react");var ch=require("react");var Pa=require("react/jsx-runtime"),sh=()=>{let{srcTokenBalanceInfo:t,isFetchingBalance:e}=re();return(0,Pa.jsxs)("div",{className:"flex flex-col items-end",children:[(0,Pa.jsx)("p",{className:"text-xs font-medium opacity-60",children:"Balance:"}),e?(0,Pa.jsx)(Pr,{className:"w-[50px] h-[16px]"}):(0,Pa.jsx)("p",{className:`text-xs font-medium ${!t&&"opacity-60"}`,children:t||"-"})]})};var St=require("react/jsx-runtime"),fh=({type:t})=>{let{srcValue:e,srcValueUsd:r,dstValue:n,dstValueUsd:i,setSrcValue:a,isFetchingRoute:o}=re(),f=(0,ch.useMemo)(()=>t==="source"?r:i,[i,r,t]);return(0,St.jsxs)("div",{className:"flex justify-between items-center w-full p-4 gap-8 overflow-hidden",children:[(0,St.jsx)("div",{className:"flex flex-col font-medium w-full overflow-hidden text-left",children:t==="source"?(0,St.jsxs)(St.Fragment,{children:[(0,St.jsx)(uo,{id:"swap-amount-input",className:"bg-transparent border-none p-0 text-xl outline-0 font-sans-bold font-bold",regex:vs,value:e,onChange:d=>a(d)}),f&&(0,St.jsx)("div",{className:"text-sx opacity-60",children:`$${f}`})]}):o?(0,St.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,St.jsx)(Pr,{className:"w-[150px] h-[30px]"}),(0,St.jsx)(Pr,{className:"w-[100px] h-[20px]"})]}):(0,St.jsxs)(St.Fragment,{children:[(0,St.jsx)("div",{className:"text-xl text-t_text_secondary font-sans-bold font-bold",children:n||0}),f&&(0,St.jsx)("div",{className:"text-sx opacity-60",children:`$${f}`})]})}),t==="source"&&(0,St.jsx)(sh,{})]})};var xo=require("react");var ri=require("react"),lh=require("react-virtuoso");var zs=require("react"),Nr=require("react/jsx-runtime"),dh=({chain:t,type:e,onClick:r,disabled:n})=>{let{networks:{evm:i}}=ba(),{srcChain:a,dstChain:o,bridgeUI:f}=re(),d=(0,zs.useMemo)(()=>e==="source"?a?.chainId:o?.chainId,[o,a,e]),p=(0,zs.useMemo)(()=>i.signer&&i.chainId===t.chainId,[t.chainId,i.chainId,i.signer]),h=(0,zs.useMemo)(()=>{if(f)return e==="destination"?a?.chainId:o?.chainId},[f,o?.chainId,a?.chainId,e]),E=t.chainId===h?"Transfers between the same chains are not available":n?f?"Token is not available on this chain":`Swap from ${a?.displayName||"the source chain"} to this chain is currently not supported.`:"";return(0,Nr.jsx)("div",{className:"group relative",children:(0,Nr.jsxs)("div",{onClick:()=>{t.chainId===h||n||r(t.chainId)},className:`flex justify-between items-center gap-2 mt-2 mb-2 cursor-pointer p-4 border border-solid border-white border-opacity-0 hover:selected-chain-item ${d===t.chainId?"selected-chain-item":""} ${t.chainId===h||n?"disabled-chain-item cursor-default":""}`,children:[(0,Nr.jsxs)("div",{className:"flex gap-3 items-center w-full",children:[(0,Nr.jsx)("img",{src:t.image,alt:t.name,className:"w-[34px] h-[34px]"}),(0,Nr.jsx)("p",{children:t.displayName})]}),E&&(0,Nr.jsx)("div",{className:"w-full text-center opacity-0 group-hover:opacity-100 text-xs transition-opacity duration-200",children:E}),p&&(0,Nr.jsxs)("div",{className:"flex items-baseline gap-1",children:[(0,Nr.jsx)(B1,{}),(0,Nr.jsx)("div",{className:"text-t_text_green",children:"connected"})]})]})})};var Ht=require("react/jsx-runtime"),uh=({type:t,onClose:e})=>{let{setSrcChain:r,setDstChain:n,srcChainOptions:i,dstChainOptions:a}=re(),[o,f]=(0,ri.useState)(""),d=(0,ri.useRef)(null);(0,ri.useEffect)(()=>{d.current&&setTimeout(()=>{d.current?.focus()},10)},[]);let p=(0,ri.useMemo)(()=>{let w=t==="source"?i:a;return o?w.filter(E=>{let S=o.toLowerCase();return E.displayName.toLowerCase().includes(S)||E.chainId.toLowerCase().includes(S)}):w},[t,i,a,o]),h=w=>{let E=p.find(({chainId:S})=>S===w);if(!E)throw new Error("ChainPicker > selected chain id that is absent in chain options list.");t==="source"?r(E):n(E),e()};return(0,Ht.jsxs)("div",{className:"flex flex-col h-full",children:[(0,Ht.jsxs)("div",{className:"flex justify-between",children:[(0,Ht.jsx)("div",{className:"text-base/4 text-t_text_primary mb-4",children:`Pick ${t} chain`}),(0,Ht.jsx)("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:e,children:(0,Ht.jsx)(lt,{})})]}),(0,Ht.jsx)(Ws,{ref:d,inputIcon:(0,Ht.jsx)("div",{className:"fill-t_text_primary",children:(0,Ht.jsx)(Rs,{})}),placeholder:"Search chain name",value:o,handleChange:f}),(0,Ht.jsx)("div",{className:"horizontal-separator mt-4"}),(0,Ht.jsx)("div",{className:"h-full pt-4",children:p.length?(0,Ht.jsx)(lh.Virtuoso,{style:{height:"100%"},data:p,itemContent:(w,E)=>(0,Ht.jsx)(dh,{chain:E,type:t,disabled:E.disabled,onClick:h})}):(0,Ht.jsx)("div",{className:"flex justify-center mt-4",children:"No chain found."})})]})};var Xt=require("react/jsx-runtime"),ph=({chain:t,type:e,className:r})=>{let{srcChainLocked:n,dstChainLocked:i}=re(),a=(0,xo.useMemo)(()=>e==="destination"&&i,[e,i]),o=(0,xo.useMemo)(()=>e==="source"&&n,[e,n]),[f,d]=(0,xo.useState)(!1);return(0,Xt.jsxs)(Xt.Fragment,{children:[f&&(0,Xt.jsx)(Aa,{onClose:()=>d(!1),children:(0,Xt.jsx)(uh,{type:e,onClose:()=>d(!1)})}),(0,Xt.jsx)("button",{type:"button",disabled:a||o,onClick:()=>d(!0),className:`${r||""}`,children:(0,Xt.jsxs)("div",{className:"flex justify-between items-center p-4 gap-8",children:[(0,Xt.jsxs)("div",{className:"flex flex-col font-medium items-start",children:[(0,Xt.jsx)("p",{className:"text-xs opacity-60",children:e==="source"?"From:":"To:"}),(0,Xt.jsx)("p",{className:`${t?"":"opacity-60"}`,children:t?t.displayName:"Select"})]}),!a&&!o&&(0,Xt.jsx)("div",{className:"w-4 h-2 fill-t_text_primary",children:(0,Xt.jsx)(Ei,{})})]})})]})};var Mf=require("react/jsx-runtime"),hh=({type:t})=>{let{srcToken:e,srcTokenBalanceWei:r,srcTokenBalanceInfo:n,setSrcValue:i}=re();return(0,Mf.jsx)("button",{type:"button",className:`flex items-center w-16 justify-center p-4 gap-8 ${!n&&"opacity-60"} ${t==="source"&&"border-l border-solid border-t_text_primary border-opacity-10"}`,disabled:!n,onClick:()=>i(mt({amount:r,decimals:e?.decimals||18,precisionFractionalPlaces:e?.decimals||18})),children:t==="source"&&(0,Mf.jsx)("p",{className:`border-b border-solid border-t_text_primary ${!n&&"border-opacity-60"}`,children:"Max"})})};var ni=require("react");var gh=require("@fortawesome/free-solid-svg-icons"),yh=require("@fortawesome/react-fontawesome");var rt=require("react"),vh=require("react-virtuoso");var Ii=require("react/jsx-runtime"),xh=({token:t,selectedTokenAddress:e,onClick:r})=>(0,Ii.jsxs)("button",{type:"button",className:`flex gap-2 py-2 pr-[14px] pl-2 items-center border border-solid border-t_text_primary border-opacity-10 rounded-3xl text-start hover:bg-t_bg_tertiary hover:bg-opacity-10 ${t.address.toLowerCase()===e?.toLowerCase()?"bg-t_bg_tertiary bg-opacity-10":"bg-t_bg_primary"}`,onClick:r,children:[(0,Ii.jsx)($n,{token:t,className:"w-6 h-6",generatedLogoClassName:"w-6 h-6"}),(0,Ii.jsxs)("div",{className:"flex flex-col gap-1 text-xs font-medium !leading-3",children:[(0,Ii.jsx)("div",{className:"text-t_text_primary",children:t.name}),(0,Ii.jsx)("div",{className:"text-t_text_primary text-opacity-50",children:t.symbol})]})]});var Na=require("react"),mh=require("wagmi"),rr=require("react/jsx-runtime"),bh=({token:t,selectedTokenAddress:e,onClick:r,selectedChainId:n})=>{let{supportedChains:i,tokenPrices:a,isFetchingBalances:o}=re(),{address:f}=(0,mh.useAccount)(),d=(0,Na.useMemo)(()=>i.find(({chainId:S})=>S===t.chainId),[i,t]),p=(0,Na.useMemo)(()=>a[t.chainId]?.[t.address],[t,a]),h=(0,Na.useMemo)(()=>!t.balance||!t.decimals?null:Number(fe.utils.formatUnits(t.balance,t.decimals)),[t.balance,t.decimals]),w=(0,Na.useMemo)(()=>t.balance&&!t.balance.eq(0),[t.balance]),E=(0,Na.useMemo)(()=>!h||!p||!w?null:h*+p,[h,p,w]);return(0,rr.jsxs)("div",{className:`token-picker-container ${t.address.toLowerCase()===e?.toLowerCase()&&n&&t.chainId===n?"bg-t_bg_tertiary bg-opacity-10":""}`,onClick:r,children:[(0,rr.jsx)(ei,{token:t,chain:d,tokenLogoClassName:"min-w-9 w-9 h-9",generatedLogoClassName:"min-w-9 w-9 h-9 text-[16px]",chainLogoClassName:"w-5"}),(0,rr.jsxs)("div",{className:"flex justify-between items-center gap-1 w-full",children:[(0,rr.jsxs)("div",{className:"text-left",children:[(0,rr.jsx)("div",{className:"text-sm font-medium text-ellipsis text-t_text_primary",children:t.name}),(0,rr.jsx)("div",{className:"text-xs text-t_text_primary text-opacity-50 font-medium",children:t.symbol})]}),t.balance&&t.decimals&&f&&!o&&(0,rr.jsxs)("div",{className:"text-right",children:[(0,rr.jsx)("div",{className:"text-xs text-t_text_primary",children:t.balance.eq(0)||h>1e-4?mt({amount:t.balance.toString(),decimals:t.decimals,precisionFractionalPlaces:4}):"<0.0001"}),w&&(0,rr.jsx)("div",{className:"text-xs text-t_text_primary text-opacity-50",children:E?`$${E.toFixed(2)}`:"$ -"})]}),f&&o&&(0,rr.jsx)("div",{children:(0,rr.jsx)(Pr,{className:"w-[48px] h-[12px]"})})]})]})};var wh=require("wagmi"),ie=require("react/jsx-runtime"),Ch=({chain:t,tokens:e,otherTokens:r,selectedTokenAddress:n,isOpen:i,onSelect:a,setModalOpen:o,type:f})=>{let[d,p]=(0,rt.useState)(""),[h,w]=(0,rt.useState)(!1),[E,S]=(0,rt.useState)(!1),[A,_]=(0,rt.useState)(!1),[I,N]=(0,rt.useState)(null),[L,M]=(0,rt.useState)(!0),V=(0,rt.useRef)(0),F=(0,rt.useRef)(null),{bridgeUI:B,supportedChains:J,findTokenDataByAddressAndChain:Q,tokenPrices:G}=re(),{address:ne}=(0,wh.useAccount)(),q=so();(0,rt.useEffect)(()=>{S(!1),w(!1)},[i]);let ae=(0,rt.useCallback)(()=>{if(t&&I&&ha(d)){let y={};Pt||(y=JSON.parse(localStorage.getItem("custom-tokens")||"{}"));let m={address:I.address,symbol:I.symbol,name:I.name,tokenId:I.address,decimals:I.decimals,quickPick:!1,supported:!0,priority:0,chainId:t.chainId};Pt||(y[t.chainId]={...y[t.chainId]||{},[d.toLowerCase()]:m},localStorage.setItem("custom-tokens",JSON.stringify(y))),a(m),o(!1)}},[t,d,I,a,o]),T=(0,rt.useCallback)(async()=>{let y=Date.now();V.current=y;let m=J.find(({ecosystem:x,chainId:R})=>x==="evm"&&R===t?.chainId)?.publicRpcUrls[0],c=new fe.Contract(d.toLowerCase(),tn,fe.getDefaultProvider(m));_(!0);try{let x=await Promise.all([q.query(c,"decimals"),q.query(c,"name"),q.query(c,"symbol")]);if(y!==V.current)return;let[R,u,k]=x;N({address:d.toLowerCase(),decimals:R,name:u,symbol:k})}catch{N(null)}finally{y===V.current&&_(!1)}},[t,d,q,J]);(0,rt.useEffect)(()=>{!B&&ha(d)&&t&&!Q(d.toLowerCase(),t.chainId)?T():(_(!1),N(null))},[B,d,T,Q,t]),(0,rt.useEffect)(()=>{p("")},[i]);let s=(y,m)=>y.toLowerCase().indexOf(m.toLowerCase())>-1,l=(0,rt.useMemo)(()=>e?.filter(y=>s(y.symbol,d)||s(y.name,d)||y.address.toLowerCase()===d.toLowerCase()),[d,e]),g=(0,rt.useMemo)(()=>r?.filter(y=>s(y.symbol,d)||s(y.name,d)||y.address.toLowerCase()===d.toLowerCase()),[d,r]);(0,rt.useEffect)(()=>{i&&F.current&&setTimeout(()=>{F.current?.focus()},10)},[i]);let v=(0,rt.useMemo)(()=>{let y=u=>{if(!u.balance||!u.decimals)return 0;let k=Number(fe.utils.formatUnits(u.balance,u.decimals)),P=G[u.chainId]?.[u.address];return P?k*Number(P):0},m=[...l.filter(u=>X.from(u?.balance||"0").gt(0)),...g.filter(u=>X.from(u?.balance||"0").gt(0))].sort((u,k)=>{let P=y(u),O=y(k);return O!==P?O-P:k.priority-u.priority}),c=l.filter(u=>X.from(u?.balance||"0").eq(0)).sort((u,k)=>k.priority-u.priority),x=g.filter(u=>X.from(u?.balance||"0").eq(0)).sort((u,k)=>k.priority-u.priority);return(t?[...ne&&m.length?[m]:[],c,x]:[...ne&&m.length?[m]:[],[...c,...x]]).flat()},[l,g,t,ne,G]),C=(0,rt.useMemo)(()=>v.filter(y=>y.balance?.gt(0)),[v]),b=(0,rt.useMemo)(()=>t?[...ne&&C.length?[C]:[],l,g]:[...ne&&C.length?[C]:[],g],[t,ne,C,l,g]);return E?(0,ie.jsxs)(ie.Fragment,{children:[(0,ie.jsxs)("div",{className:"flex justify-between",children:[(0,ie.jsx)("div",{className:"text-base/4 mb-4",children:"Import token"}),(0,ie.jsx)("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:()=>o(!1),children:(0,ie.jsx)(lt,{})})]}),(0,ie.jsxs)("div",{className:"flex flex-col h-full gap-2",children:[I&&(0,ie.jsxs)("div",{className:"token-picker-container grow-0 bg-t_bg_secondary border border-solid border-t_text_primary border-opacity-10 rounded-xl py-2 pr-2 pl-4 hover:cursor-pointer",children:[(0,ie.jsx)(mo,{tokenName:I.name,className:"w-9 h-9 text-[15px]"}),(0,ie.jsxs)("div",{className:"flex justify-between items-center gap-1 overflow-hidden grow",children:[(0,ie.jsx)("div",{className:"overflow-hidden whitespace-nowrap text-ellipsis text-sm font-medium",children:I.name}),(0,ie.jsx)("div",{className:"token-picker__all__symbol",children:I.symbol})]}),(0,ie.jsxs)("div",{className:"text-sm flex items-center",children:[u1(d.toLowerCase()),(0,ie.jsx)("button",{type:"button",onClick:()=>navigator.clipboard.writeText(I.address.toLowerCase()),"aria-label":`Copy ${I.symbol} token address`,className:"flex items-center p-2 fill-white cursor-pointer hover:fill-t_main_accent_light",children:(0,ie.jsx)(R1,{className:"w-5 h-5"})})]})]}),(0,ie.jsx)("div",{className:"px-2 py-4 rounded-xl border border-x_orange text-sm",children:"Ensure that you have verified the token address and confirmed its correctness"}),(0,ie.jsxs)("div",{className:"bg-t_bg_secondary border border-solid border-t_text_primary border-opacity-10 rounded-xl p-2",children:[(0,ie.jsx)("div",{className:"text-sm mb-2",children:"Be mindful that anyone can create tokens, even counterfeit versions of existing ones. Certain tokens and their technical specifications might not be compatible with XSwap services. By importing such custom tokens, you acknowledge and consent to the associated risks."}),(0,ie.jsxs)("button",{type:"button",onClick:()=>w(y=>!y),className:"flex items-center",children:[(0,ie.jsx)("div",{className:"flex justify-center items-center p-1 w-6 h-6 border-2 border-white rounded-md mr-2",children:h&&(0,ie.jsx)(yh.FontAwesomeIcon,{icon:gh.faCheck,className:"w-4 h-4"})}),(0,ie.jsx)("div",{className:"font-bold",children:"Accept"})]})]}),(0,ie.jsx)("div",{className:"flex grow items-end justify-center",children:(0,ie.jsx)(Ir,{type:"button",disabled:!h,className:`token-picker__import-button w-full ${h?"":"!cursor-not-allowed"}`,onClick:ae,children:"Import"})})]})]}):(0,ie.jsxs)(ie.Fragment,{children:[(0,ie.jsxs)("div",{className:"flex justify-between",children:[(0,ie.jsx)("div",{className:"text-base/4 text-t_text_primary mb-4",children:`Pick ${f} token`}),(0,ie.jsx)("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:()=>o(!1),children:(0,ie.jsx)(lt,{})})]}),(0,ie.jsx)(Ws,{ref:F,inputIcon:(0,ie.jsx)("div",{className:"fill-t_text_primary",children:(0,ie.jsx)(Rs,{})}),placeholder:"Search name or paste address",value:d,handleChange:p}),(0,ie.jsx)("div",{className:`flex flex-wrap gap-1 my-4 mx-0 transition-all duration-300 ${L?"opacity-100 max-h-[200px]":"opacity-0 max-h-0 overflow-hidden"}`,children:e.filter(y=>y?.quickPick).map(y=>(0,ie.jsx)(xh,{token:y,selectedTokenAddress:n,onClick:()=>{a(y),o(!1)}},y.address))}),(0,ie.jsx)("div",{className:"flex flex-col mx-0 h-full",children:A?(0,ie.jsx)("div",{className:"flex justify-center w-full py-4 px-0",children:(0,ie.jsx)(nn,{className:"w-9 h-9"})}):(0,ie.jsx)(ie.Fragment,{children:I?(0,ie.jsxs)("div",{className:"token-picker-container hover:cursor-default",children:[(0,ie.jsx)(ei,{token:I,chain:t,tokenLogoClassName:"w-9 h-9",generatedLogoClassName:"w-9 h-9 text-[16px]",chainLogoClassName:"w-5"}),(0,ie.jsxs)("div",{className:"flex justify-between items-center gap-1 overflow-hidden grow",children:[(0,ie.jsxs)("div",{children:[(0,ie.jsx)("div",{className:"text-sm font-medium text-ellipsis",children:I.name}),(0,ie.jsx)("div",{className:"text-xs text-t_text_primary !text-opacity-50 font-medium",children:t?.displayName})]}),(0,ie.jsx)("div",{className:"token-picker__all__symbol",children:I.symbol})]}),(0,ie.jsx)("div",{children:(0,ie.jsx)(Ir,{type:"button",className:"h-8 py-0 px-4 text-t_text_primary leading-[14px] rounded-[32px] bg-gradient-to-r from-t_main_accent_light to-t_main_accent_dark",onClick:()=>S(!0),children:"Import"})})]}):(0,ie.jsx)("div",{className:"flex flex-col h-full gap-8 w-[calc(100%+32px)] mx-[-16px]",children:(0,ie.jsx)(vh.GroupedVirtuoso,{style:{maxHeight:"400px",height:"100%"},groupCounts:b.map(y=>y?.length),scrollerRef:y=>{y&&y.addEventListener("scroll",m=>{let c=m.target;M(c.scrollTop<10)})},groupContent:y=>(0,ie.jsxs)("div",{className:"py-1 bg-t_bg_primary text-t_text_primary",children:[(0,ie.jsx)("div",{className:"px-4 text-left",children:(()=>{if(t)switch(y){case 0:return ne?C.length?"My tokens":`${t.displayName} network`:`${t.displayName} network`;case 1:return ne?`${t.displayName} network`:"Other networks";case 2:return"Other networks";default:return"Undefined group"}else switch(y){case 0:return ne&&C.length?"My tokens":"All networks";case 1:return"All networks";default:return"Undefined group"}})()}),(0,ie.jsx)("div",{className:"horizontal-separator"}),!b[y]?.length&&(0,ie.jsx)("div",{className:"text-center py-1",children:"No token found"})]}),itemContent:y=>v[y]&&(0,ie.jsx)(bh,{token:v[y],selectedChainId:t?.chainId,selectedTokenAddress:n,onClick:()=>{a(v[y]),o(!1)}})})})})})]})};var Rt=require("react/jsx-runtime"),Ah=({chain:t,token:e,type:r,className:n})=>{let{bridgeUI:i,srcChainTokensOptions:a,srcChainOtherTokensOptions:o,dstChainTokensOptions:f,dstChainOtherTokensOptions:d,setSrcToken:p,setSrcChain:h,supportedChains:w,setDstToken:E,setDstChain:S,dstTokenLocked:A,srcTokenLocked:_}=re(),I=(0,ni.useMemo)(()=>r==="destination"&&A,[r,A]),N=(0,ni.useMemo)(()=>r==="source"&&_,[r,_]),[L,M]=(0,ni.useState)(!1),V=(0,ni.useMemo)(()=>r==="source"?a:f,[f,a,r]),F=(0,ni.useMemo)(()=>r==="destination"&&i,[i,r]),B=(0,ni.useMemo)(()=>r==="source"?o:d,[d,o,r]),J=Q=>{let G=w.find(ne=>ne.chainId===Q.chainId);r==="source"?(p(Q),h(G)):(E(Q),S(G)),M(!1)};return(0,Rt.jsxs)(Rt.Fragment,{children:[L&&(0,Rt.jsx)(Aa,{onClose:()=>M(!1),className:"z-[3]",children:(0,Rt.jsx)(Ch,{type:r,chain:t,tokens:V,otherTokens:B,selectedTokenAddress:e?.address,onSelect:J,isOpen:L,setModalOpen:M})}),(0,Rt.jsx)("button",{type:"button",disabled:F||I||N,onClick:()=>{M(!0)},className:`${n||""}`,children:(0,Rt.jsxs)("div",{className:"flex justify-between items-center p-4 gap-8 border-r border-solid border-t_text_primary border-opacity-10",children:[(0,Rt.jsxs)("div",{className:"flex gap-2 items-center",children:[(0,Rt.jsx)($n,{token:e,className:"w-9 h-9",generatedLogoClassName:"w-9 h-9 text-[16px]"}),(0,Rt.jsxs)("div",{className:"flex flex-col font-medium items-start",children:[(0,Rt.jsx)("p",{className:"text-xs opacity-60",children:"Token: "}),(0,Rt.jsx)("p",{className:`${e?"":"opacity-60"}`,children:e?e.symbol:r==="destination"&&i?"-":"Select"})]})]}),!F&&!I&&!N&&(0,Rt.jsx)("div",{className:"w-4 h-2 fill-t_text_primary",children:(0,Rt.jsx)(Ei,{})})]})})]})};var Bn=require("react/jsx-runtime"),Pf=({type:t})=>{let{srcChain:e,srcToken:r,dstChain:n,dstToken:i}=re(),a=(0,If.useMemo)(()=>t==="source"?r:i,[t,r,i]),o=(0,If.useMemo)(()=>t==="source"?e:n,[t,e,n]);return(0,Bn.jsxs)("div",{className:"flex flex-col x-border rounded-xl bg-t_bg_tertiary bg-opacity-5",children:[(0,Bn.jsxs)("div",{className:"flex border-b border-solid border-t_text_primary border-opacity-10",children:[(0,Bn.jsx)(Ah,{chain:o,token:a,type:t,className:"w-full flex-grow"}),(0,Bn.jsx)(ph,{chain:o,type:t,className:"w-full max-w-[160px]"})]}),(0,Bn.jsxs)("div",{className:`flex justify-between rounded-b-[11px] ${t==="destination"&&"bg-gradient-to-r from-t_main_accent_light/20 to-t_main_accent_dark/20"}`,children:[(0,Bn.jsx)(fh,{type:t}),(0,Bn.jsx)(hh,{type:t})]})]})};var Fn=require("react/jsx-runtime"),Th=()=>(0,Fn.jsxs)("div",{className:"flex flex-col gap-6 fill-t_text_primary",children:[(0,Fn.jsxs)("div",{className:"flex flex-col gap-[11px]",children:[(0,Fn.jsx)(Pf,{type:"source"}),(0,Fn.jsx)(rh,{}),(0,Fn.jsx)(Pf,{type:"destination"})]}),(0,Fn.jsx)(Hs,{}),(0,Fn.jsx)(oh,{})]});var Pi=require("react/jsx-runtime"),Nf=({onClose:t})=>{let{tab:e}=re(),r=(0,Sh.useMemo)(()=>e==="Settings"?(0,Pi.jsx)(th,{}):e==="History"?(0,Pi.jsx)(Jp,{}):(0,Pi.jsx)(Th,{}),[e]);return(0,Pi.jsxs)("div",{className:"relative flex flex-col gap-4 p-2 text-t_text_primary bg-t_bg_primary rounded-2xl flex-1",children:[(0,Pi.jsx)(Wp,{onClose:t}),r]})};var Eh=require("react"),Rr=require("react/jsx-runtime"),Ws=(0,Eh.forwardRef)((t,e)=>{let{inputIcon:r,required:n,name:i,value:a,placeholder:o,type:f,handleChange:d,error:p,warning:h,disabled:w=!1,className:E=""}=t;return(0,Rr.jsxs)(Rr.Fragment,{children:[(0,Rr.jsxs)("div",{className:"flex items-center border border-solid border-t_text_primary border-opacity-10 rounded-lg py-0 px-3 gap-2 bg-t_bg_secondary ",children:[r,(0,Rr.jsx)("input",{ref:e,disabled:w,required:!!n,name:i||"",value:a,placeholder:o,type:f||"text",className:`relative h-10 leading-10 z-[1] outline-none w-full text-t_text_primary bg-transparent border-none ${p?"border border-t_error_dark bg-gradient-to-r from-t_error_dark/15 to-t_bg_secondary/15 px-3 shadow-[0_0_6px_rgba(255,0,0,0.5)]":""} ${h?"border-t_warning_dark bg-gradient-to-r from-t_warning_dark/15 to-t_bg_secondary/15 px-3 shadow-[0_0_6px_rgba(255,165,0,0.5)]":""} ${E}`,onChange:S=>d(S.target.value)})]}),p&&(0,Rr.jsx)("div",{className:"flex justify-between pt-[10px]",children:(0,Rr.jsx)("div",{className:"px-5 text-t_text_red",children:p})}),h&&(0,Rr.jsx)("div",{className:"flex justify-between pt-[10px]",children:(0,Rr.jsx)("div",{className:"px-5 text-t_text_orange",children:h})})]})});var on=require("react"),Ra=class{static getTimeFromSeconds(e){let r=Math.floor(e/86400),n=Math.floor(e%(60*60*24)/(60*60)),i=Math.floor(e%(60*60)/60),a=Math.floor(e%60);return{days:r,hours:n,minutes:i,seconds:a}}static getSecondsFromExpiry(e){let r=new Date().getTime(),n=e.getTime();return Math.max(0,(n-r)/1e3)}},t3=({expiryTimestamp:t,onExpire:e,autoStart:r=!0})=>{let[n,i]=(0,on.useState)(r),[a,o]=(0,on.useState)(Ra.getSecondsFromExpiry(t)),f=(0,on.useCallback)(()=>{let w=Ra.getSecondsFromExpiry(t);w<=0&&(e&&e(),i(!1)),o(w)},[t,e]);(0,on.useEffect)(()=>{if(!n)return;let w=setInterval(f,1e3);return()=>clearInterval(w)},[n,f]);let d=(0,on.useCallback)(()=>i(!1),[]),p=(0,on.useCallback)(()=>i(!0),[]),h=(0,on.useCallback)(w=>{i(!0),o(Ra.getSecondsFromExpiry(w))},[]);return{...Ra.getTimeFromSeconds(a),isRunning:n,pause:d,resume:p,restart:h}},kh=t3;var qs=require("react"),yr=require("react/jsx-runtime");var _h=({expiryTimestamp:t,displayFormat:e=2,customTextOnExpire:r})=>{let[n,i]=(0,qs.useState)(t.getTime()<Date.now()),{seconds:a,minutes:o,hours:f,days:d,restart:p}=kh({expiryTimestamp:t,onExpire:()=>i(!0)});return(0,qs.useEffect)(()=>{p(t)},[t]),(0,yr.jsx)(yr.Fragment,{children:n&&r?(0,yr.jsx)(yr.Fragment,{children:r}):(0,yr.jsxs)(yr.Fragment,{children:[e===0&&(0,yr.jsx)("span",{children:`${(d*24+f)*60+o}:${a.toString().padStart(2,"0")}`}),e===1&&(0,yr.jsx)("span",{children:`${d*24+f}:${o.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`}),e===2&&(0,yr.jsx)("span",{children:`${d}:${f.toString().padStart(2,"0")}:${o.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`})]})})};var Ih=require("react");var Mh=require("react/jsx-runtime"),mo=({tokenName:t,className:e})=>(0,Mh.jsx)("div",{className:`rounded-full bg-white shadow-sm flex items-center justify-center text-black ${e}`,children:t.substring(0,1)});var Ks=require("react/jsx-runtime"),$n=({token:t,className:e,generatedLogoClassName:r})=>{let[n,i]=(0,Ih.useState)(!1);return t?n?(0,Ks.jsx)(mo,{tokenName:t.name,className:r}):t?.image?(0,Ks.jsx)("img",{src:t.image,alt:t.name,className:`border border-solid border-t_text_primary border-opacity-10 rounded-2xl ${e}`,onError:()=>i(!0)}):(0,Ks.jsx)(mo,{tokenName:t.name,className:r}):null};var bo=require("react/jsx-runtime"),ei=({token:t,chain:e,tokenLogoClassName:r,generatedLogoClassName:n,chainLogoClassName:i})=>(0,bo.jsxs)("div",{className:"relative flex items-end pr-1 pb-1",children:[(0,bo.jsx)($n,{token:t,className:r,generatedLogoClassName:n}),e&&(0,bo.jsx)("img",{src:e.image,alt:e.name,className:`absolute bottom-0 right-0 border border-solid border-t_bg_secondary rounded-3xl ${i}`})]});var Js=require("@tanstack/react-query"),ii=require("react"),Nh=require("react-error-boundary"),Xs=require("wagmi");function r3(t,e){function r(i){let a=document.getElementById(i);if(a&&a.shadowRoot){let o=new CSSStyleSheet;o.replaceSync(`:host { ${t}: ${e}; }`),a.shadowRoot.adoptedStyleSheets=[...a.shadowRoot.adoptedStyleSheets,o]}}["xpay-root","xpay-tx-status","xpay-widget"].forEach(r)}var n3={mainAccentLight:"#3681C6",mainAccentDark:"#2B4A9D",bgPrimary:"#FFFFFF",bgSecondary:"#FFFFFF1a",bgTertiary:"#020202",textPrimary:"#020202",textSecondary:"#3681C6",textRed:"#C62828",textOrange:"#FF6F00",textGreen:"#2E7D32",clickSecondary:"#3681C6",clickTertiary:"#020202",buttonPrText:"#ffffff",buttonPrOffBg:"#0202024D",buttonPrOffText:"#020202",labelText:"#FFFFFF",successDark:"#2E7D32",successLight:"#4CAF50",infoDark:"#3C3C3B",infoLight:"#90A4AE",warningDark:"#FF6F00",warningLight:"#FFCA28",errorDark:"#C62828",errorLight:"#F44336",chainlinkLogo:"#375BD2"},i3={mainAccentLight:"#3681C6",mainAccentDark:"#2B4A9D",bgPrimary:"#020202",bgSecondary:"#0F0F0F",bgTertiary:"#ffffff",textPrimary:"#FFFFFF",textSecondary:"#3681C6",textRed:"#F44336",textOrange:"#FFCA28",textGreen:"#4CAF50",clickSecondary:"#3681C6",clickTertiary:"#FFFFFF",buttonPrText:"#FFFFFF",buttonPrOffBg:"#272727",buttonPrOffText:"#90A4AE",labelText:"#FFFFFF",successDark:"#2E7D32",successLight:"#4CAF50",infoDark:"#3C3C3B",infoLight:"#D1D3D4",warningDark:"#FF6F00",warningLight:"#FFCA28",errorDark:"#C62828",errorLight:"#F44336",chainlinkLogo:"white"},a3={mainAccentLight:"--main-accent-light",mainAccentDark:"--main-accent-dark",bgPrimary:"--bg-primary",bgSecondary:"--bg-secondary",bgTertiary:"--bg-tertiary",textPrimary:"--text-primary",textSecondary:"--text-secondary",textTertiary:"--text-tertiary",textRed:"--text-red",textOrange:"--text-orange",textGreen:"--text-green",clickPrimary:"--click-primary",clickSecondary:"--click-secondary",clickTertiary:"--click-tertiary",buttonPrBg:"--button-pr-bg",buttonPrText:"--button-pr-text",buttonPrOffBg:"--button-pr-off-bg",buttonPrOffText:"--button-pr-off-text",labelBg:"--label-bg",labelText:"--label-text",successDark:"--success-dark",successLight:"--success-light",infoDark:"--info-dark",infoLight:"--info-light",warningDark:"--warning-dark",warningLight:"--warning-light",errorDark:"--error-dark",errorLight:"--error-light",width:"--modal-width",chainlinkLogo:"--chainlink-logo"};function Ph(t,e){let n={...t?{...n3}:{...i3},...e};for(let[i,a]of Object.entries(n)){let o=a3[i];o&&r3(o,a)}}var tt=require("react/jsx-runtime"),o3=new Js.QueryClient,s3=()=>{let{reconnect:t}=(0,Xs.useReconnect)();return(0,ii.useEffect)(()=>{let e=0,r=setInterval(()=>{t(),e++,e>=5&&clearInterval(r)},1e3);return()=>{clearInterval(r)}},[t]),(0,tt.jsx)(tt.Fragment,{})},c3=({onPendingTransactionsChange:t})=>{let{history:e}=xa(),r=(0,ii.useMemo)(()=>e.filter(n=>n.status==="IN_PROGRESS"),[e]);return(0,ii.useEffect)(()=>{t?t(r):window.xPayOnPendingTransactionsChange&&window.xPayOnPendingTransactionsChange(r)},[t,r]),(0,tt.jsx)(tt.Fragment,{})},Rf=({integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,supportedChains:d,onSubmit:p,onClose:h,overlay:w,lightTheme:E,defaultWalletPicker:S,styles:A,onPendingTransactionsChange:_,dstTokenLocked:I,dstChainLocked:N,srcTokenLocked:L,srcChainLocked:M,onDstTokenChange:V,onDstChainChange:F,onSrcTokenChange:B,onSrcChainChange:J,bridge:Q,onConnectWallet:G,override:ne,integratorFee:q,integratorFeeReceiverAddress:ae})=>{let T=l=>{l.stopPropagation(),l.nativeEvent.stopImmediatePropagation(),l.target===l.currentTarget&&w&&h()},s=(0,ii.useMemo)(()=>Ep(d),[d]);return(0,ii.useEffect)(()=>{Ph(E,A)},[E,A]),(0,ii.useEffect)(()=>{ne?.apiUrl&&_s(ne?.apiUrl)},[ne?.apiUrl]),(0,tt.jsx)(Nh.ErrorBoundary,{FallbackComponent:()=>(0,tt.jsx)("div",{children:"Something went wrong, please contact XSwap."}),children:(0,tt.jsx)(Xs.WagmiProvider,{config:s,children:(0,tt.jsxs)(Js.QueryClientProvider,{client:o3,children:[(0,tt.jsx)(s3,{}),(0,tt.jsxs)(ap,{children:[(0,tt.jsx)(c3,{onPendingTransactionsChange:_}),(0,tt.jsx)(up,{integrationConfig:{integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,defaultWalletPicker:S,dstTokenLocked:I,dstChainLocked:N,srcTokenLocked:L,srcChainLocked:M,onDstTokenChange:V,onDstChainChange:F,onSrcTokenChange:B,onSrcChainChange:J,bridge:Q,onConnectWallet:G,integratorFee:q,integratorFeeReceiverAddress:ae},supportedChains:d,wagmiConfig:s,overlay:w,children:(0,tt.jsx)(xp,{children:(0,tt.jsx)(Up,{children:w?(0,tt.jsx)("div",{className:"top-0 left-0 right-0 bottom-0 bg-[rgba(0,0,0,0.8)] fixed flex flex-col items-center justify-center z-10",onMouseDown:T,children:(0,tt.jsxs)("div",{className:"relative bg-t_bg_primary rounded-2xl overflow-auto text-t_text_primary border-[1px] border-solid border-[rgba(255,255,255,0.1)] w-x_modal min-w-x_modal max-w-x_modal min-h-[532px]",children:[(0,tt.jsx)(Nf,{onSubmit:p,onClose:h}),(0,tt.jsx)(kf,{})]})}):(0,tt.jsxs)("div",{className:"bg-t_bg_primary rounded-2xl overflow-auto text-t_text_primary border-[1px] border-solid border-[rgba(255,255,255,0.1)] min-h-[532px] w-x_modal min-w-x_modal max-w-x_modal flex flex-col",children:[(0,tt.jsx)(Nf,{onSubmit:()=>{},onClose:()=>{}}),(0,tt.jsx)(kf,{})]})})})})]})]})})})},Rh=async({integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,supportedChains:d,lightTheme:p,defaultWalletPicker:h,styles:w,onPendingTransactionsChange:E,dstTokenLocked:S,dstChainLocked:A,srcTokenLocked:_,srcChainLocked:I,override:N})=>{try{if(_n===null)throw new Error("XPay was incorrectly initialized");return await b1(),await new Promise(()=>{if(_n===null)throw new Error("XPay was incorrectly initialized");_n.render((0,tt.jsx)(Rf,{integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,supportedChains:d,lightTheme:p,styles:w,onSubmit:()=>{_n&&_n.render("")},onClose:()=>{_n&&_n.render("")},overlay:!0,defaultWalletPicker:h,onPendingTransactionsChange:E,dstTokenLocked:S,dstChainLocked:A,srcTokenLocked:_,srcChainLocked:I,override:N}))})}catch(L){throw new Error(`XSwap component error, ${L}`)}};var Ba=require("@fortawesome/free-solid-svg-icons"),Qs=require("@fortawesome/react-fontawesome");var Bh=require("date-fns"),Fh=require("react");var Ni=require("react/jsx-runtime"),Bf=({chain:t,token:e,amount:r})=>(0,Ni.jsxs)("div",{className:"flex gap-2",children:[(0,Ni.jsx)(ei,{token:e,chain:t,tokenLogoClassName:"min-w-9 w-9 h-9",generatedLogoClassName:"min-w-9 w-9 h-9 text-[16px]",chainLogoClassName:"w-5"}),(0,Ni.jsxs)("div",{className:"flex flex-col text-[12px]",children:[(0,Ni.jsx)("div",{className:"text-t_text_primary text-nowrap",children:`${Number(r)<1e-4?"<0.0001":r} ${e?.symbol?e?.symbol:"unknown"}`}),(0,Ni.jsx)("div",{className:"text-xs text-t_text_primary text-opacity-50",children:t?.displayName})]})]});var nt=require("react/jsx-runtime"),Zs=({transaction:t,supportedChains:e,srcToken:r,dstToken:n})=>{let a=(0,Fh.useCallback)(h=>(0,Bh.format)(new Date(h*1e3),"d MMM yyyy HH:mm:ss"),[])(t.timestamp),o=mt({amount:t.amountWei,decimals:r?.decimals||18,precisionFractionalPlaces:4}),f=mt({amount:t?.tokenOutAmount||"0",decimals:n?.decimals||18,precisionFractionalPlaces:4}),d=e.find(h=>h.chainId===t.sourceChainId),p=e.find(h=>h.chainId===t.targetChainId);return(0,nt.jsxs)("div",{className:"flex flex-col border border-t_text_primary border-opacity-10 rounded-lg bg-t_bg_primary p-4 gap-4 mb-2",children:[(0,nt.jsxs)("div",{className:"flex items-center gap-2 border-b border-solid border-t_text_primary border-opacity-10 pb-1",children:[(0,nt.jsx)("div",{className:"text-xs text-t_text_primary text-opacity-50",children:a}),(0,nt.jsxs)("div",{className:"flex grow justify-end items-center h-6",children:[t.status==="IN_PROGRESS"?(0,nt.jsxs)("div",{className:"flex items-center grow justify-end text-xs",children:[(0,nt.jsx)(Qs.FontAwesomeIcon,{icon:Ba.faHourglassHalf,className:"w-4 h-4 mr-1 text-t_text_orange"}),(0,nt.jsxs)("div",{className:"text-xs text-t_text_orange min-w-[108px]",children:["In progress (",(0,nt.jsx)(_h,{displayFormat:0,expiryTimestamp:new Date(t.estimatedDeliveryTimestamp),customTextOnExpire:"finalizing"}),")"]})]}):t.status==="DONE"?(0,nt.jsx)("div",{className:"flex items-center grow justify-end text-xs",children:(0,nt.jsx)("div",{className:" mr-1 text-t_text_green",children:"Done"})}):t.status==="REVERTED"?(0,nt.jsx)("div",{className:"flex items-center grow justify-end text-xs",children:(0,nt.jsx)("div",{className:"w-4 h-4 mr-1 text-t_text_red",children:"Reverted"})}):null,(0,nt.jsx)("a",{href:`${t.messageId?`${ua}${t.messageId}`:`${e.find(h=>h.chainId===t.sourceChainId)?.transactionExplorer}/${t.hash}`} `,target:"_blank",rel:"noreferrer",className:"no-underline ml-1.5 text-t_text_primary","aria-label":"Show the transaction in the chain explorer",children:(0,nt.jsx)(Qs.FontAwesomeIcon,{icon:Ba.faArrowUpRightFromSquare,className:"w-[14px] h-[14px] text-t_text_primary"})})]})]}),(0,nt.jsx)("div",{className:"flex flex-wrap gap-8",children:(0,nt.jsxs)("div",{className:"flex items-center gap-2",children:[(0,nt.jsx)(Bf,{chain:d,token:r,amount:o}),t.tokenOutAddress&&(0,nt.jsxs)(nt.Fragment,{children:[(0,nt.jsx)(Qs.FontAwesomeIcon,{icon:Ba.faArrowRight,className:"w-5 h-5 text-t_text_primary opacity-50 mx-1.5"}),(0,nt.jsx)(Bf,{chain:p,token:n,amount:f})]})]})})]})};var Lh=require("react/jsx-runtime"),Xp=({transaction:t})=>{let{supportedChains:e,findTokenDataByAddressAndChain:r}=re(),n=r(t.tokenAddress.toLowerCase(),t.sourceChainId),i=t.tokenOutAddress?r(t.tokenOutAddress?.toLowerCase(),t.targetChainId):void 0;return(0,Lh.jsx)(Zs,{transaction:t,supportedChains:e,srcToken:n,dstToken:i})};var Dh=require("react-dom"),Ff=require("react/jsx-runtime"),Hp=({id:t,children:e,onCloseClick:r,type:n="waiting",className:i})=>(0,Dh.createPortal)((0,Ff.jsx)("div",{className:"fixed box-border inset-0 z-20 flex items-center justify-center bg-black bg-opacity-80",onMouseDown:o=>{o.stopPropagation(),o.nativeEvent.stopImmediatePropagation(),o.target===o.currentTarget&&r()},children:(0,Ff.jsx)("div",{className:`relative bg-t_bg_primary rounded-3xl p-4 w-full min-w-[340px] overflow-auto max-w-x_modal border-2 ${n==="error"?"border-t_error_dark":n==="success"?"border-t_success_dark":n==="warning"?"border-t_warning_dark":n==="waiting"?"border-t_main_accent_dark":"border-t_text_primary border-opacity-10"} ${i}`,children:e})}),Ci,t);var go=require("react");var ut=require("react/jsx-runtime"),f3=({transaction:t,supportedChains:e,srcToken:r,dstToken:n})=>{let[i,a]=(0,go.useState)(!1),o=(0,go.useMemo)(()=>t?.status==="DONE"?"bg-t_bg_primary bg-gradient-to-r from-t_success_light/20 to-t_success_dark/20":"bg-t_bg_primary bg-gradient-to-r from-t_main_accent_light/20 to-t_main_accent_dark/20]",[t]),f=(0,go.useMemo)(()=>t?.status==="DONE"?"border border-solid border-t_success_dark":"border border-solid border-t_main_accent_dark",[t]);return(0,ut.jsxs)("div",{className:"flex gap-2 items-end justify-end flex-wrap",onClick:()=>a(d=>!d),children:[i&&(0,ut.jsx)(Zs,{transaction:t,supportedChains:e,srcToken:r,dstToken:n}),(0,ut.jsx)("div",{className:`text-t_text_primary rounded-xl h-14 w-20 mb-2 cursor-pointer ${o} ${f}`,children:(0,ut.jsxs)("div",{className:"flex gap-2 items-center h-14 w-20 justify-center fill-t_text_primary",children:[(0,ut.jsx)("div",{className:`${i?"rotate-180":""}`,children:(0,ut.jsx)(_1,{})}),(0,ut.jsx)("div",{className:"relative flex items-center justify-center w-9 h-9",children:t?.status==="DONE"?(0,ut.jsx)("div",{className:"w-5 h-5 fill-t_success_dark",children:(0,ut.jsx)(Ps,{})}):(0,ut.jsxs)(ut.Fragment,{children:[(0,ut.jsx)("div",{className:"w-5 h-5",children:(0,ut.jsx)(Y1,{})}),(0,ut.jsx)("div",{className:"absolute flex items-center justify-center top-0 left-0 right-0 bottom-0 text-t_text_primary",children:(0,ut.jsx)(nn,{className:"w-10 h-10"})})]})})]})})]})},Ri=[],Oh=t=>{Ri.some(({transaction:e})=>e.hash===e.hash)||Ri.push(t)},Uh=t=>{Ri=[...Ri.filter(r=>r.transaction.hash!==t)]},Hh=t=>{Ri=Ri.map(e=>e.transaction.hash===t?{...e,transaction:{...e.transaction,status:"DONE"}}:e)},Ys=()=>{let t=Ri.map(e=>(0,ut.jsx)(f3,{...e},e.transaction.hash));if(ks===null)throw new Error("XPay was incorrectly initialized");ks.render((0,ut.jsx)("div",{className:"fixed bottom-5 right-2 flex flex-col gap-3 pl-9 items-end w-full z-50",children:t}))};var Vh=Et(require("@r2wc/core")),Lf=Et(require("react")),Gh=require("react-dom/client"),d3=(t,e,r)=>{let n=(0,Gh.createRoot)(t),i=Lf.default.createElement(e,r);return n.render(i),{root:n,ReactComponent:e}},l3=({root:t,ReactComponent:e},r)=>{let n=Lf.default.createElement(e,r);t.render(n)},u3=({root:t})=>{t.unmount()},zh=(t,e={})=>(0,Vh.default)(t,e,{mount:d3,update:l3,unmount:u3});var yo=require("react");var Ln=require("react/jsx-runtime"),p3=({integratorId:t,dstChain:e,dstToken:r,srcChain:n,srcToken:i,customContractCalls:a=[],desc:o,dstDisplayToken:f,lightTheme:d,defaultWalletPicker:p,styles:h,onPendingTransactionsChange:w,dstTokenLocked:E,dstChainLocked:S,srcTokenLocked:A,srcChainLocked:_,onDstTokenChange:I,onDstChainChange:N,onSrcTokenChange:L,onSrcChainChange:M,onConnectWallet:V,bridge:F,override:B,integratorFee:J,integratorFeeReceiverAddress:Q})=>{let[G,ne]=(0,yo.useState)(!0),[q,ae]=(0,yo.useState)([]);(0,yo.useEffect)(()=>{(async()=>{ne(!0),B?.apiUrl&&_s(B.apiUrl);let s=(await Ti()).filter(({web3Environment:l,bridgeSupported:g,swapSupported:v})=>l==="mainnet"&&(g||v));ae(s),ne(!1)})()},[]);let T=(()=>{try{return typeof h=="string"?JSON.parse(h):h||void 0}catch(s){console.error("Error parsing styles:",s)}})();return(0,Ln.jsxs)(Ln.Fragment,{children:[(0,Ln.jsx)("style",{children:Ts}),G?(0,Ln.jsx)("div",{className:"min-h-[532px] w-full flex items-center justify-center",children:(0,Ln.jsx)(nn,{className:"w-10 h-10"})}):(0,Ln.jsx)(Rf,{integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,supportedChains:q,overlay:!1,lightTheme:d,defaultWalletPicker:p,styles:T,onPendingTransactionsChange:w,dstTokenLocked:E,dstChainLocked:S,srcTokenLocked:A,srcChainLocked:_,onDstTokenChange:I,onDstChainChange:N,onSrcTokenChange:L,onSrcChainChange:M,onConnectWallet:V,bridge:F,override:B,integratorFee:J,integratorFeeReceiverAddress:Q})]})},js=()=>{if(Pt||typeof customElements>"u")return{};let t=zh(p3,{shadow:"open",props:{integratorId:"string",dstChain:"string",dstToken:"string",srcChain:"string",srcToken:"string",customContractCalls:"json",desc:"string",dstDisplayToken:"string",lightTheme:"boolean",defaultWalletPicker:"boolean",styles:"json",onPendingTransactionsChange:"function",dstTokenLocked:"boolean",dstChainLocked:"boolean",srcTokenLocked:"boolean",srcChainLocked:"boolean",bridge:"boolean",onDstTokenChange:"function",onDstChainChange:"function",onSrcTokenChange:"function",onSrcChainChange:"function",override:"json",integratorFee:"number",integratorFeeReceiverAddress:"string"}});return t.prototype.connectedCallback=function(){this.id="xpay-widget"},t};var Wh=require("@tanstack/react-query"),qh=require("react");var Kh=require("react/jsx-runtime"),h3=js();!Wh.isServer&&typeof customElements<"u"&&(customElements.get("xpay-widget")||customElements.define("xpay-widget",h3));var $s=({integratorId:t,dstChain:e,dstToken:r,srcChain:n,srcToken:i,customContractCalls:a=[],desc:o,dstDisplayToken:f,lightTheme:d,defaultWalletPicker:p,styles:h,onPendingTransactionsChange:w,dstTokenLocked:E,dstChainLocked:S,srcTokenLocked:A,srcChainLocked:_,onDstTokenChange:I,onDstChainChange:N,onSrcTokenChange:L,onSrcChainChange:M,onConnectWallet:V,bridge:F,override:B,integratorFee:J,integratorFeeReceiverAddress:Q})=>((0,qh.useEffect)(()=>{window.xPayOnPendingTransactionsChange=w,window.xPayOnDstTokenChange=I,window.xPayOnDstChainChange=N,window.xPayOnSrcTokenChange=L,window.xPayOnSrcChainChange=M,window.xPayOnConnectWallet=V},[w,I,N,L,M,V]),(0,Kh.jsx)("xpay-widget",{"integrator-id":t,"dst-chain":e,"dst-token":r,"src-chain":n,"src-token":i,"custom-contract-calls":JSON.stringify(a),desc:o,"dst-display-token":f,"light-theme":d,"default-wallet-picker":p,styles:typeof h=="string"?h:JSON.stringify(h),"dst-token-locked":E,"dst-chain-locked":S,"src-token-locked":A,"src-chain-locked":_,bridge:F,override:JSON.stringify(B),"integrator-fee":J,"integrator-fee-receiver-address":Q}));var Xh=Et(require("async-retry"));var Jh=async(t,e)=>{let r=t.publicRpcUrls[0],n=new fe.Contract(e.toLowerCase(),tn,fe.getDefaultProvider(r));try{let i=async(p,h,w=[])=>p?.provider?await p[h](...w):null,a=await Promise.all([i(n,"decimals"),i(n,"name"),i(n,"symbol")]),[o,f,d]=a;return{address:e,symbol:d,tokenId:e,name:f,decimals:o,quickPick:!1,supported:!0,priority:0}}catch{throw new Error(`Provided token ${e} does not exists on chain ${t.displayName}`)}};var Rp=async(t,e,r,n)=>{let i=await x3(t,e),a=(await Ti()).filter(({web3Environment:J,swapSupported:Q})=>J==="mainnet"&&Q),o=i.logs?.find(J=>J.topics[0]===fe.utils.id(ju));if(!o)throw new Error(`No transaction event found for chain ${t} tx ${e}`);let f=o?.topics[1],p=new fe.utils.Interface($u).parseLog(o);if(!p)throw new Error(`No transaction event arguments found for chain ${t} tx ${e}`);let h=p.args,w=a.find(J=>J.chainId===t.toString());if(!w)throw new Error(`Unknown src chain ${t}`);let E=(h?.token.toString()).toLowerCase(),S=w.tokens.find(J=>J.address.toLowerCase()===E);S||(S=await Jh(w,E));let A=a.find(J=>J.ccipChainId===h?.destinationChainSelector?.toString()),_=A?.chainId;if(!_)throw new Error("Unknown destination chain!");let I;r&&(I=A.tokens.find(J=>J.address.toLowerCase()===r.toLowerCase()));let N=Date.now()/1e3,L={hash:i.transactionHash,timestamp:N,sourceChainId:w.chainId,targetChainId:A.chainId,amountWei:h?.tokenAmount.toString(),tokenAddress:S.address,tokenOutAddress:I?.address,tokenOutAmount:n,estimatedDeliveryTimestamp:h?.valueForInstantCcipRecieve.toString()!=="0"?N*1e3+30*1e3:N*1e3+30*60*1e3,status:"IN_PROGRESS"};Oh({transaction:L,supportedChains:a,dstToken:I,srcToken:S}),Ys();let M=Wt[_]?.XSwapRouter;if(!M)throw new Error("Unknown destination XSwapRouter!");let V=new fe.Contract(M,t1,fe.getDefaultProvider(a.find(J=>J.chainId===_)?.publicRpcUrls[0])),F={address:M,topics:[fe.utils.id(e1),f]},B=async()=>{Hh(e),Ys(),await new Promise(J=>setTimeout(()=>J(!0),Yu)),Uh(e),Ys()};Kc({transferId:f}).then(J=>{J.status==="DONE"?B():(setTimeout(()=>Kc({transferId:f}).then(Q=>{Q.status==="DONE"&&B()}),30*60*1e3),V.once(F,()=>B()))})},x3=async(t,e)=>{try{let r=(await Ti()).find(i=>i.chainId===t),n=new fe.providers.JsonRpcProvider(r?.publicRpcUrls[0]);return await(0,Xh.default)(async()=>{let i=await n.getTransactionReceipt(e);if(!i)throw new Error("Couldn't fetch tx receipt");return i})}catch{throw new Error(`Couldn't fetch tx ${e} receipt on chain ${t}`)}};var e0=async({integratorId:t,dstChain:e,dstToken:r,srcChain:n,srcToken:i,customContractCalls:a=[],desc:o,dstDisplayToken:f,lightTheme:d,defaultWalletPicker:p,styles:h,onPendingTransactionsChange:w,dstTokenLocked:E,dstChainLocked:S,srcTokenLocked:A,srcChainLocked:_,onDstTokenChange:I,onDstChainChange:N,onSrcTokenChange:L,onSrcChainChange:M,bridge:V})=>{let F=(await Ti()).filter(({web3Environment:B,swapSupported:J})=>B==="mainnet"&&J);m3(t,F,e,r,n,i),await Rh({integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,supportedChains:F,lightTheme:d,defaultWalletPicker:p,styles:h,onPendingTransactionsChange:w,dstTokenLocked:E,dstChainLocked:S,srcTokenLocked:A,srcChainLocked:_,onDstTokenChange:I,onDstChainChange:N,onSrcTokenChange:L,onSrcChainChange:M,bridge:V})},m3=(t,e,r,n,i,a)=>{if(!t)throw new Error("Provide integratorId or contact the team to generate one.");if(r){let o=e.find(({chainId:f})=>f===r);if(!o)throw new Error(`Provided chain '${r}' is not supported`);if(n&&(!ha(n)||o.tokens.findIndex(({address:f})=>f.toLowerCase()===n.toLowerCase())===-1))throw new Error(`Provided token address ${n} on chain ${r} is invalid`)}if(i){let o=e.find(({chainId:f})=>f===i);if(!o)throw new Error(`Provided chain '${i}' is not supported`);if(a&&(!ha(a)||o.tokens.findIndex(({address:f})=>f.toLowerCase()===a.toLowerCase())===-1))throw new Error(`Provided token address ${a} on chain ${i} is invalid`)}};var Qh=js();m1();var b3={openTransactionModal:e0,TxWidget:$s,TxWidgetWC:Qh},g3=b3;0&&(module.exports={ContractName,Ecosystem,Environment,TxStatus,TxWidget,TxWidgetWC,Web3Environment,XSwapCallType,openTransactionModal});
|
|
92
92
|
/*! Bundled license information:
|
|
93
93
|
|
|
94
94
|
js-sha3/src/sha3.js:
|