@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.mjs
CHANGED
|
@@ -88,7 +88,7 @@ nuik2Z3UwnCBNAiE2pBa3qQbD26+YBAnrbNmr4xK8wpDThAKwhdiuoIjum4saQg0VdFRVSxiR01e
|
|
|
88
88
|
EEYyDQde+0pTfR+Wmen0BJLu0r6ONsMwNA4n0jC0MEyNMBVG+JhcW37DNCMzk6fe0P6/6ZaOfwAl
|
|
89
89
|
LqsAAAAldEVYdGRhdGU6Y3JlYXRlADIwMjQtMDUtMjdUMTE6NTQ6MjkrMDA6MDCo6mafAAAAJXRF
|
|
90
90
|
WHRkYXRlOm1vZGlmeQAyMDI0LTA1LTI3VDExOjU0OjI5KzAwOjAw2bfeIwAAAABJRU5ErkJggg==`})});import{useMemo as h5}from"react";var Ia=()=>h5(()=>({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()*pc)),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()*pc)})}catch(r){throw r?.error?.data?.message?new Error(r?.error?.data?.message):r}}}),[]),Sc=Ia;import{useCallback as zS}from"react";import{useCallback as x5,useRef as m5}from"react";var U1=({delayMs:t,instantExecution:e})=>{let r=m5(null);return{debounce:x5(i=>{r.current&&(clearTimeout(r.current),r.current=null),e&&e(),r.current=setTimeout(i,t)},[t,e])}};import{useCallback as jS}from"react";var $S=new se.utils.Interface(Gu);import b5 from"bignumber.js";import{useSnackbar as g5}from"notistack";import{createContext as y5,useCallback as ss,useContext as v5,useEffect as Ec,useMemo as w5,useState as H1}from"react";import{useAccount as C5}from"wagmi";import{jsx as Vi,jsxs as A5}from"react/jsx-runtime";var V1=y5({}),G1="pending_transactions",kc=()=>wt?{}:JSON.parse(localStorage.getItem(G1)||"{}"),_c=t=>{wt||localStorage.setItem(G1,JSON.stringify(t))},z1=({children:t})=>{let{address:e}=C5(),[r,n]=H1([]),[i,a]=H1(!1),{enqueueSnackbar:o,closeSnackbar:f}=g5(),{debounce:d}=U1({delayMs:600});Ec(()=>{wt||localStorage.removeItem("transactions-history")},[]);let p=ss(async()=>{try{if(!e)return;let A=await ts({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=Qo;if(new b5(M.source.valueForInstantCcipRecieve||"0").gt(0))B=F+30*1e3;else{let J=F+Ko?.[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=kc(),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}_c(L),n(_.sort((M,V)=>V.timestamp-M.timestamp))}catch(A){console.error(A),o(Vi(In,{message:{text:"Failed to fetch history!",variant:"error"}}),{persist:!1})}finally{a(!0)}},[e,ts,o]);Ec(()=>{i||d(p);let A=setInterval(()=>{d(p)},6e4);return()=>clearInterval(A)},[e,p,ts,d,i]);let h=ss((A,_)=>{n(I=>{let N=I.filter(M=>M.hash!==A.hash),L=kc();return _c({...L,[_]:[A,...N]}),[A,...N]})},[]),w=ss(A=>{o(Vi(In,{message:{text:"Destination chain transaction mined successfully!",variant:"success",action:()=>A5("div",{className:"flex items-center flex-nowrap",children:[Vi(hr,{type:"button",onClick:()=>{window.open(`${Ui}${A}`)},children:"View"}),Vi("div",{className:"transaction-provider__close fill-white leading-[0px]",onClick:()=>f(A),children:Vi(at,{})})]})}}),{persist:!1,key:A})},[o]),E=ss((A,_)=>{n(I=>{let N=I.map(M=>M.hash===A.hash&&M.status!=="DONE"?A:M),L=kc();switch(_c({...L,[_]:[...N]}),A.status){case"DONE":{w(A.hash);break}case"REVERTED":break}return[...N]})},[w]);Ec(()=>{a(!1),n([])},[e]);let S=w5(()=>({history:r,addTransactionToLocalHistory:h,updateTransactionInLocalHistory:E,historyLoadedOnce:i}),[r,h,E,i]);return Vi(V1.Provider,{value:S,children:t})};function Gi(){return v5(V1)}import k5 from"bignumber.js";import{createContext as _5,useCallback as Pa,useContext as M5,useEffect as Ct,useMemo as lt,useRef as J1,useState as Xe}from"react";import{useAccount as I5}from"wagmi";var W1=({supportedChains:t})=>{let e=t.find(r=>r.chainId===Oi)||t[0];if(!e)throw new Error("getDefaultSourceChain > couldn't find default source chain");return e},q1=({supportedChains:t})=>{let e=t.find(r=>r.chainId===Xo)||t[0];if(!e)throw new Error("getDefaultDestinationChain > couldn't find default destination chain");return e},cs=(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},T5=({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())},Mc=t=>t.swapSupported,Ic=({sourceChain:t,targetChain:e})=>{if(!t)throw new Error("isSwapTargetChainValid > sourceChain should be defined.");return e.swapSupported&&t.supportedDstForSwap?.includes(e.chainId)},Pc=t=>!t||t.bridgeSupported,K1=({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},S5=({source:t,target:e,supportedChains:r})=>{let n=t.chain||W1({supportedChains:r}),i=e.chain||q1({supportedChains:r}),a=t.token||cs(n,dc),o=e.token||cs(i,lc,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(!Mc(n)&&(n=W1({supportedChains:r}),a=void 0,!Mc(n)&&(console.error("[WRONG CONFIG] default swap source chain is invalid."),n=r.find(f=>Mc(f)),!n)))throw new Error("mapToValidSwap > None of the chains supports swap. Couldn't set source chain.");if(!Ic({sourceChain:n,targetChain:i})&&(i=q1({supportedChains:r}),o=void 0,!Ic({sourceChain:n,targetChain:i})&&(console.error("[WRONG CONFIG] default swap target chain is invalid."),i=r.find(f=>Ic({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=cs(n,dc)),(!o||a===o)&&(o=cs(i,lc,n.chainId===i.chainId,a?.tokenId)),{source:{chain:n,token:a},target:{chain:i,token:o}}},E5=({source:t,target:e,supportedChains:r,bridgeTokensDictionary:n})=>{let i=t.chain,a=e.chain,o=t.token,f=e.token;if(!Pc(i)&&(i=void 0,o=void 0,!Pc(i)&&(console.error("[WRONG CONFIG] default bridge source chain is invalid."),i=r.find(d=>Pc(d)),!i)))throw new Error("mapToValidSwap > None of the chains supports bridge. Couldn't set source chain.");if(K1({sourceChain:i,targetChain:a,sourceToken:o})||(f=void 0,K1({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=T5({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}}},fs=({type:t,...e})=>t==="SWAP"?S5(e):E5(e);import{jsx as P5}from"react/jsx-runtime";var At=()=>{throw new Error("Not implemented")},nt={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:At,setError:At,setSrcChain:At,setDstChain:At,setSrcToken:At,setDstToken:At,setSrcValue:At,setExpressDelivery:At,setInfiniteApproval:At,setSlippage:At,setRoute:At,setSrcTokenBalanceWei:At,quoteRoute:At,refreshBalance:At,findTokenDataByAddressAndChain:At,bridgeTokensDictionary:null,onConnectWallet:At,hasOnConnectWalletCallback:!1,srcChainOptions:[],dstChainOptions:[]},X1=_5(nt),Q1=({children:t,integrationConfig:e,supportedChains:r,wagmiConfig:n,overlay:i})=>{let{address:a,chainId:o}=I5(),[f,d]=Xe(!1),[p,h]=Xe(nt.tab),[w,E]=Xe(nt.error),[S,A]=Xe(nt.expressDelivery),[_,I]=Xe(nt.slippage),[N,L]=Xe(nt.infiniteApproval),[M,V]=Xe(nt.srcChain),[F,B]=Xe(nt.dstChain),[J,Q]=Xe(nt.feeToken),[G,re]=Xe(nt.srcToken),[q,ne]=Xe(nt.dstToken),[T,s]=Xe(nt.tokenPrices),[l,g]=Xe({}),[v,C]=Xe([]),[b,y]=Xe(nt.srcValue),[m,c]=Xe(nt.srcTokenBalanceWei),[x,R]=Xe(nt.srcChainTokensOptions),[u,k]=Xe(nt.dstChainTokensOptions),[P,O]=Xe(nt.srcChainOtherTokensOptions),[z,j]=Xe(nt.dstChainOtherTokensOptions),[Y,Z]=Xe([]),[Qe,$]=Xe([]),[fe,gr]=Xe(nt.isFetchingBalance),[Oe,Be]=Xe(nt.isFetchingBalances),[zr,Fe]=Xe(nt.isFetchingRoute),[we,zt]=Xe(nt.route),Te=J1(null),Le=J1(crypto.randomUUID()),Wr=lt(()=>!!e?.srcTokenLocked,[e?.srcTokenLocked]),Ue=lt(()=>!!e?.dstTokenLocked,[e?.dstTokenLocked]),He=lt(()=>!!e?.dstChainLocked,[e?.dstChainLocked]),qr=lt(()=>!!e?.srcChainLocked,[e?.srcChainLocked]),ae=lt(()=>!!e.bridge,[e.bridge]),Ve=lt(()=>!!(e.onConnectWallet||window.xPayOnConnectWallet),[e.onConnectWallet]),Wt=lt(()=>{let K=wt?{}:JSON.parse(localStorage.getItem("custom-tokens")||"{}"),oe={};return r.forEach(ie=>{oe[ie.chainId]={},ie.tokens.forEach(ee=>{oe[ie.chainId][ee.address]=ee})}),hc(oe,K)},[r]),_e=lt(()=>{let K={};return Object.entries(Wt).forEach(([oe,ie])=>{K[oe]=Object.entries(ie).filter(([,ee])=>ee.supported).sort(([,ee],[,me])=>me.priority-ee.priority).map(([,ee])=>({chainId:oe,...ee}))}),K},[Wt]),de=lt(()=>{if(!v||v.length===0)return null;let K={},oe=(ie,ee,me,le)=>{K[ie]||(K[ie]={}),K[ie][ee]||(K[ie][ee]={}),K[ie][ee][me]=le};for(let ie of v){let ee=Object.entries(ie);if(ee.length!==2)continue;let[me,le]=ee[0],[Ce,ut]=ee[1];oe(me,le,Ce,ut),oe(Ce,ut,me,le)}return Object.keys(K).length>0?K:null},[v]),Kr=lt(()=>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]),Se=lt(()=>Zo({amount:b,decimals:G?.decimals||18}),[G?.decimals,b]),Ee=lt(()=>ft({amount:we?.estAmountOut||"0",decimals:q?.decimals||18,precisionFractionalPlaces:Math.min(8,q?.decimals||18)}),[we]),Jr=lt(()=>Zo({amount:Ee,decimals:q?.decimals||18}),[q?.decimals,Ee]),Ge=lt(()=>q&&F&&T&&T[F?.chainId]&&T[F?.chainId]?.[q.address]?(Number(Ee)*Number(T[F?.chainId]?.[q.address])).toFixed(2):null,[T,q,Ee,F]),ze=lt(()=>ft({amount:we?.minAmountOut||"0",decimals:q?.decimals||18,precisionFractionalPlaces:Math.min(4,q?.decimals||18)}),[we]),yr=lt(()=>S&&!!we&&X.from(we.xSwapFees?.expressDeliveryFee||"0").gt("0"),[S,we]),We=lt(()=>r.length>0&&v.length>0,[r,v]),qe=lt(()=>{if(!G||!m||!a)return"";if(Ht(m).eq(0))return"0";let K=ft({amount:m,decimals:G.decimals,precisionFractionalPlaces:G.decimals});return new k5(K).lt("0.00001")?"<0.00001":ft({amount:m,decimals:G.decimals,precisionFractionalPlaces:5})},[G,m]),Ft=Pa(K=>{if(!K)return[];if(!ae)return _e[K]||[];if(!_e[K]||!de)return[];let oe=Object.keys(de[K]||{});return _e[K].filter(ie=>oe.includes(ie.address))},[de,ae,_e]),Ie=Pa(async()=>{if(!M||!F||!G||!q||!Se||Ht(Se).eq(0)||ae&&!de){zt(void 0);return}let{source:K,target:oe}=fs({source:{chain:M,token:G},target:{chain:F,token:q},type:ae?"BRIDGE":"SWAP",supportedChains:r,bridgeTokensDictionary:de||{}});if(!(K.chain?.chainId!==M?.chainId||oe.chain?.chainId!==F?.chainId||K.token?.address!==G?.address||oe.token?.address!==q?.address))try{E(""),Fe(!0),Te.current&&Te.current.abort(uc),Te.current=new AbortController;let ie=await yc({integratorId:e.integratorId,fromChain:M.chainId,toChain:F.chainId,fromAddress:a||Rt[M.chainId]?.FeeCollector||"",toAddress:a||Rt[F.chainId]?.FeeCollector||"",fromToken:G.address,toToken:q.address,fromAmount:Se,slippage:Number(_),customContractCalls:e.customContractCalls,paymentToken:ir.AddressZero,expressDelivery:S,infiniteApproval:N,integratorFee:e.integratorFee,integratorFeeReceiverAddress:e.integratorFeeReceiverAddress},Te.current.signal);zt(ie),Te.current=null}catch(ie){ie!==uc&&(Te.current=null,console.error(ie),E("Could not find route!"),zt(void 0))}finally{Te.current||Fe(!1)}},[a,ae,F,q,yc,yr,_,M,G,Se]),Pe=Pa(async()=>{if(!a||!M?.publicRpcUrls[0]||!G||!G?.address)return;let K=crypto.randomUUID();Le.current=K,gr(!0);let oe=await zu(a,G.address,M?.publicRpcUrls[0]);K===Le.current&&(c(Zo({amount:oe,decimals:G.decimals})),gr(!1))},[a,M,G]),Xr=Pa((K,oe)=>Wt[oe]?.[K],[Wt]),Ke=Pa(()=>{e.onConnectWallet?e.onConnectWallet():window.xPayOnConnectWallet&&window.xPayOnConnectWallet()},[e]);return Ct(()=>{if(r.length>0){let K=r.map(oe=>oe.chainId);$u({chainId:K}).then(oe=>{s(oe)})}},[r]),Ct(()=>{(async()=>{let K=await t1();C(K)})()},[]),Ct(()=>{Ie()},[Ie]),Ct(()=>{Pe()},[Pe]),Ct(()=>{a&&r.length>0&&(Be(!0),e1({walletAddress:a}).then(K=>{g(K),Be(!1)}))},[a,r.length]),Ct(()=>{Q(M?.tokens.find(({address:K})=>K.toLowerCase()===ir.AddressZero.toLowerCase()))},[M]),Ct(()=>{(async()=>{let K=F?.chainId===M?.chainId,oe=Ft(M?.chainId).filter(({symbol:ce})=>K?ce!==q?.symbol:!0);R(oe);let ie=Ft(F?.chainId).filter(({symbol:ce})=>K?ce!==G?.symbol:!0);k(ie);let ee=[],me=r.filter(({chainId:ce,web3Environment:pe,swapSupported:ot,bridgeSupported:Ne})=>ce!==M?.chainId&&pe==="mainnet"&&(ae&&Ne||!ae&&ot));for(let{chainId:ce}of me)ee.push(...Ft(ce).filter(({symbol:pe})=>ce===F?.chainId?pe!==q?.symbol:!0));O(ee);let le=[],Ce=r.filter(({chainId:ce,web3Environment:pe,swapSupported:ot,bridgeSupported:Ne})=>ce!==F?.chainId&&pe==="mainnet"&&(ae&&Ne&&M?.supportedDstForBridge?.includes(ce)||!ae&&ot&&M?.supportedDstForSwap?.includes(ce)));for(let{chainId:ce}of Ce)le.push(...Ft(ce).filter(({symbol:pe})=>ce===M?.chainId?pe!==G?.symbol:!0));j(le);let ut=ce=>ce.map(pe=>({...pe,balance:X.from(l[pe.chainId]?.[pe.address]||0)}));R(ut(oe)),k(ut(ie)),O(ut(ee)),j(ut(le))})()},[ae,M,F,Ft,r,G?.symbol,q?.symbol,l]),Ct(()=>{let K=r.filter(({web3Environment:ee,swapSupported:me,bridgeSupported:le})=>ee==="mainnet"&&(ae&&le||!ae&&me)),oe=[];if(ae&&F&&q&&de){let ee=K.filter(({chainId:me})=>{let le=de[me]||{};return Object.values(le).some(Ce=>Ce[F.chainId])});oe=K.filter(me=>!ee.some(le=>le.chainId===me.chainId)).map(me=>me.chainId)}let ie=new Set;if(M&&K.filter(ee=>ae?!M.supportedDstForBridge?.includes(ee.chainId):!M.supportedDstForSwap?.includes(ee.chainId)).forEach(ee=>ie.add(ee.chainId)),ae&&M&&de&&!G){let ee=de[M.chainId];ee?K.filter(me=>!Object.values(ee).some(le=>le[me.chainId])).forEach(me=>ie.add(me.chainId)):K.forEach(me=>ie.add(me.chainId))}if(ae&&M&&de&&G){let ee=de[M.chainId]?.[G.address];K.filter(me=>!ee?.[me.chainId]).forEach(me=>ie.add(me.chainId))}Z(mc(K,oe)),$(mc(K,[...ie]))},[r,ae,M,G,F,q,de]),Ct(()=>{if(!o||!f||e?.srcChainId)return;let K=r.find(({chainId:oe})=>oe===`${o}`);K&&V(K)},[o,f,r,e?.srcChainId]),Ct(()=>{f&&(re(void 0),ne(void 0),V(void 0),B(void 0))},[ae]),Ct(()=>{if(f||!r||r.length===0||!de)return;let K=M||e?.srcChainId||(o?`${o}`:void 0)||(ae?void 0:Oi),oe=r.find(({chainId:ot})=>ot===K),ie=F||e?.dstChainId||(ae?void 0:Xo),ee=r.find(({chainId:ot})=>ot===ie),me,le,Ce=xc(e.srcTokenAddr,e?.srcChainId,r),ut=xc(e.dstTokenAddr,e?.dstChainId,r);oe&&(le=oe.tokens.find(({address:ot})=>ot.toLowerCase()===Ce?.toLowerCase())),ee&&(me=ee.tokens.find(({address:ot})=>ot.toLowerCase()===ut));let{source:ce,target:pe}=fs({source:{chain:oe,token:le},target:{chain:ee,token:me},type:ae?"BRIDGE":"SWAP",supportedChains:r,bridgeTokensDictionary:de});V(ce.chain),B(pe.chain),re(ce.token),ne(pe.token),d(!0)},[e?.srcChainId,e?.srcTokenAddr,e?.dstChainId,e?.dstTokenAddr,r,ae,o,f,de]),Ct(()=>{if(!de||r.length===0||!f)return;let{source:K,target:oe}=fs({source:{chain:M,token:G},target:{chain:F,token:q},type:ae?"BRIDGE":"SWAP",supportedChains:r,bridgeTokensDictionary:de});K.chain?.chainId!==M?.chainId&&V(K.chain),oe.chain?.chainId!==F?.chainId&&B(oe.chain),(K.token?.address!==G?.address||K.token?.name!==G?.name)&&re(K.token),(oe.token?.address!==q?.address||oe.token?.name!==q?.name)&&ne(oe.token)},[M,G,F,q,ae,r,de,f]),Ct(()=>{f&&(e.onDstChainChange?e.onDstChainChange(F?.chainId):window.xPayOnDstChainChange&&window.xPayOnDstChainChange(F?.chainId))},[e.onDstChainChange,F]),Ct(()=>{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]),Ct(()=>{f&&(e.onSrcChainChange?e.onSrcChainChange(M?.chainId):window.xPayOnSrcChainChange&&window.xPayOnSrcChainChange(M?.chainId))},[e.onSrcChainChange,M]),Ct(()=>{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]),P5(X1.Provider,{value:{bridgeUI:ae,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:Y,dstChainOptions:Qe,tokenPrices:T,dstChain:F,setDstChain:B,dstChainTokensOptions:u,dstChainOtherTokensOptions:z,srcToken:G,setSrcToken:re,dstToken:q,setDstToken:ne,srcValue:b,setSrcValue:y,srcValueWei:Se,srcValueUsd:Kr,dstValue:Ee,dstValueWei:Jr,dstValueUsd:Ge,dstValueMin:ze,expressDelivery:S,setExpressDelivery:A,infiniteApproval:N,setInfiniteApproval:L,slippage:_,setSlippage:I,route:we,setRoute:zt,isAsyncDataLoaded:We,srcTokenBalanceWei:m,setSrcTokenBalanceWei:c,srcTokenBalanceInfo:qe,isFetchingRoute:zr,isFetchingBalance:fe,isFetchingBalances:Oe,isExpressDeliveryActive:yr,quoteRoute:Ie,refreshBalance:Pe,findTokenDataByAddressAndChain:Xr,srcTokenLocked:Wr,srcChainLocked:qr,dstTokenLocked:Ue,dstChainLocked:He,bridgeTokensDictionary:de,onConnectWallet:Ke,hasOnConnectWalletCallback:Ve},children:t})},te=()=>M5(X1);import{createContext as N5,useCallback as Z1,useContext as R5,useMemo as B5}from"react";import{jsx as F5}from"react/jsx-runtime";var Y1=N5({}),j1=({children:t})=>{let e=Z1(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=Z1(({executeTransaction:i,handlers:a,network:o="evm"})=>{let f=Date.now();return o==="evm"&&e({executeTransaction:i,handlers:a}),f},[e]),n=B5(()=>({enqueueTransaction:r}),[r]);return F5(Y1.Provider,{value:n,children:t})};function $1(){return R5(Y1)}import{useEffect as U5,useMemo as H5,useState as V5}from"react";import{useAccount as G5}from"wagmi";import{useMemo as L5}from"react";import{useConnectorClient as D5}from"wagmi";function O5(t){let{account:e,transport:r}=t;return new qo.Web3Provider(r,"any").getSigner(e.address)}async function ep({chainId:t}={}){let{data:e}=D5({chainId:t});return L5(()=>e?O5(e):void 0,[e])}var z5=()=>{let[t,e]=V5(),r=ep();U5(()=>{r.then(a=>e(a))},[r]);let n=G5();return{networks:{evm:H5(()=>({networkName:"EVM",chainId:n.chainId?.toString()||Oi,address:n.address,signer:t,provider:t?.provider}),[n.address,n.chainId,t])}}},zi=z5;import{useCallback as up}from"react";import{useMemo as K5,useState as J5}from"react";import{jsx as Nc,jsxs as W5}from"react/jsx-runtime";var tp=()=>{let{isExpressDeliveryActive:t}=te();return W5("div",{className:"flex items-center",children:[Nc("div",{className:`w-4 h-4 mr-1 ${t?"fill-t_success_light":"fill-t_text_primary opacity-50"} `,children:Nc(I1,{})}),Nc("span",{className:`text-xs font-medium sm:text-sm ${t?"text-t_success_light":"opacity-50"}`,children:t?"Fast ~ 30sec ":"Normal ~ 30min"})]})};import{jsx as Rc,jsxs as q5}from"react/jsx-runtime";var rp=({name:t,value:e})=>{let{isFetchingRoute:r}=te();return q5("div",{className:"flex gap-x-1 justify-between text-xs font-medium",children:[Rc("div",{className:"opacity-60",children:t}),Rc("div",{children:r?Rc(xr,{className:"w-[60px] h-full"}):e})]})};import{jsx as Bc}from"react/jsx-runtime";var np=()=>{let{route:t,slippage:e,feeToken:r,dstToken:n,expressDelivery:i}=te(),a=[{name:"CCIP Fee: ",value:`${ft({amount:t?.xSwapFees.ccipFee||"0",decimals:r?.decimals||18,precisionFractionalPlaces:5})||0} ${r?.symbol||""}`},{name:"Native Fee: ",value:`${ft({amount:t?.xSwapFees.xSwapFee.nativeFee||"0",decimals:r?.decimals||18,precisionFractionalPlaces:5})||0} ${r?.symbol||""}`},...i?[{name:"Express delivery Fee: ",value:`${ft({amount:t?.xSwapFees.expressDeliveryFee||"0",decimals:r?.decimals||18,precisionFractionalPlaces:5})||0} ${r?.symbol||""}`}]:[],{name:"Slippage: ",value:`${e}%`},{name:"Min out: ",value:`${ft({amount:t?.minAmountOut||"0",decimals:n?.decimals||18,precisionFractionalPlaces:5})||0} ${n?.symbol||""}`}];return Bc("div",{className:"border-t border-solid border-t_text_primary border-opacity-10 pt-3 mt-3",children:Bc("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})=>Bc(rp,{name:o,value:f},o))})})};import{jsx as mr,jsxs as ds}from"react/jsx-runtime";var ls=()=>{let[t,e]=J5(!1),{route:r,feeToken:n,isFetchingRoute:i,srcChain:a,dstChain:o}=te(),f=K5(()=>{if(!r)return"0";let d=Ht(r.xSwapFees.ccipFee||"0").add(Ht(r.xSwapFees.xSwapFee.nativeFee||"0")).add(Ht(r.xSwapFees.expressDeliveryFee||"0")).toString();return ft({amount:d,decimals:n?.decimals||18,precisionFractionalPlaces:5})},[n?.decimals,r]);return mr("div",{className:"flex flex-col x-border rounded-xl py-2 px-4 bg-t_bg_tertiary bg-opacity-5",children:ds("button",{"aria-label":`${t?"Collapse":"Expand"} fees panel`,type:"button",onClick:()=>e(d=>!d),children:[ds("div",{className:"flex justify-between",children:[ds("div",{className:"flex gap-2 items-center text-xs font-medium sm:text-sm fill-t_text_primary",children:[mr(N1,{}),mr("p",{className:"opacity-60",children:"Fee: "}),i?mr(xr,{className:"w-[100px] h-full"}):mr("p",{children:`${f} ${n?.symbol||""}`})]}),ds("div",{className:"flex gap-2 items-center fill-t_text_primary",children:[r&&!i&&a?.chainId!==o?.chainId&&mr(tp,{}),t?mr("div",{className:"w-4 h-2 rotate-180",children:mr(ri,{})}):mr("div",{className:"w-4 h-2",children:mr(ri,{})})]})]}),t&&mr(np,{})]})})};import{jsx as us}from"react/jsx-runtime";var ip=()=>us("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:us("div",{className:"relative bg-gradient-to-r from-t_main_accent_light to-t_main_accent_dark w-8 h-8 rounded-xl",children:us("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 fill-white",children:us(ns,{})})})});import*as X5 from"viem/chains";import{mainnet as ap}from"viem/chains";import{createConfig as Q5,createStorage as Z5,http as Y5}from"@wagmi/core";import{injected as j5,walletConnect as $5,coinbaseWallet as e3}from"@wagmi/connectors";var t3=Z5({key:"xpay.wagmi.store",storage:wt?void 0:localStorage}),op=t=>{let e=r3(t),r=n3(e);return Q5({chains:e,transports:r,connectors:[j5(),e3({appLogoUrl:"https://xswap.link/favicon.ico",appName:"XSwap"}),$5({projectId:"c392898b45ac587a280b5eb33e92aeb0",showQrModal:!0})],storage:t3})},r3=t=>{let e=[ap];return e.push(...Object.values(X5).filter(r=>r.id!==ap.id&&t.some(({chainId:n})=>n===r.id.toString()))),e},n3=t=>{let e={};return t.forEach(r=>{e[r.id]=Y5()}),e};import{useEffect as i3,useState as sp}from"react";import{createPortal as a3}from"react-dom";import{jsx as s3}from"react/jsx-runtime";var o3={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"},Wi=({id:t,position:e,text:r,triggerRef:n})=>{let[i,a]=sp({top:0,left:0}),[o,f]=sp(!1);return i3(()=>{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]),a3(o&&s3("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 ${o3[e]}`,style:{top:i.top,left:i.left},children:r}),$n,t)};import{useRef as c3}from"react";import{jsx as Na,jsxs as cp}from"react/jsx-runtime";var fp=({onCloseClick:t})=>{let e=c3(null);return cp("div",{className:"flex justify-between items-center text-base font-medium",children:[Na("div",{className:"text-t_text_primary",children:"Confirmation"}),cp("div",{className:"flex gap-4 items-center",children:[Na(Wi,{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"}),Na(ni,{ref:e,className:"cursor-help fill-t_main_accent_light w-[18px] h-[18px]"}),Na("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:t,children:Na(at,{})})]})]})};import{useMemo as dp}from"react";import{jsx as Tt,jsxs as Fc}from"react/jsx-runtime";var lp=()=>{let{txStatus:t,txNeedsApproval:e,txMsg:r}=Vr(),n=dp(()=>[{icon:a=>Tt("div",{className:`${a}`,children:Tt(Ac,{})}),title:"sign approval transaction",state:t===1?"triggered":t>1?"completed":"none",show:r?t===1||t===2:e},{icon:a=>Tt("div",{className:`${a}`,children:Tt(Tc,{})}),title:"confirming approval transaction...",state:t===2?"triggered":t>2?"completed":"none",show:r?t===1||t===2:e},{icon:a=>Tt("div",{className:`${a}`,children:Tt(Ac,{})}),title:"sign transaction",state:t===3?"triggered":t>3?"completed":"none",show:r?t===3||t===4:!0},{icon:a=>Tt("div",{className:`${a}`,children:Tt(Tc,{})}),title:"confirming transaction...",state:t===4?"triggered":t>4?"completed":"none",show:r?t===3||t===4:!0}],[r,e,t]),i=dp(()=>n.filter(({show:a})=>a),[n]);return Tt("div",{className:"flex flex-col gap-1",children:i.map(({icon:a,title:o,state:f},d)=>Fc("div",{className:"flex flex-col px-4 gap-1",children:[Fc("div",{className:"flex justify-between items-center",children:[Fc("div",{className:"flex items-center gap-2",children:[a(`${f==="triggered"?"fill-t_main_accent_light":"fill-t_text_primary opacity-50"}`),Tt("div",{className:`${f!=="triggered"?"opacity-50":f==="triggered"&&"text-t_text_secondary"}`,children:o})]}),Tt("div",{children:f==="completed"?Tt("div",{className:"fill-t_success_dark",children:Tt(is,{})}):f==="triggered"?Tt("div",{className:"animate-spin-slow fill-t_main_accent_light",children:Tt(B1,{})}):null})]}),d!==i.length-1&&Tt("div",{className:"vertical-separator py-3 ml-2"})]},o))})};import{useMemo as ps}from"react";import{jsx as Ra,jsxs as Ba}from"react/jsx-runtime";var Lc=({type:t})=>{let{srcToken:e,srcChain:r,dstToken:n,dstChain:i,srcValue:a,srcValueUsd:o,dstValue:f,dstValueUsd:d}=te(),p=ps(()=>t==="source"?e:n,[n,e,t]),h=ps(()=>t==="source"?r:i,[i,r,t]),w=ps(()=>t==="source"?a:f,[f,a,t]),E=ps(()=>t==="source"?o:d,[d,o,t]);return Ba("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:[Ba("div",{className:"flex flex-col",children:[Ra("div",{className:"opacity-60 text-sm mb-2",children:`You ${t==="source"?"pay":"receive"}`}),Ra("div",{className:`${t==="destination"&&"text-t_text_secondary"}`,children:w}),Ba("div",{className:"opacity-60",children:["$",E]})]}),Ba("div",{className:"flex items-center gap-3",children:[Ba("div",{className:"flex flex-col text-right",children:[Ra("div",{children:p?.symbol}),Ra("div",{className:"opacity-60",children:h?.displayName})]}),Ra(Pn,{token:p,className:"w-9 h-9",generatedLogoClassName:"w-9 h-9"})]})]})};import{Fragment as f3,jsx as Nn,jsxs as Dc}from"react/jsx-runtime";var pp=({onCloseClick:t})=>{let{supportedChains:e,srcChain:r,srcToken:n,dstChain:i,dstToken:a,srcValueWei:o,dstValueWei:f,route:d,refreshBalance:p}=te(),{txStatus:h,setTxStatus:w,txMsg:E,enqueueTransaction:S,setTxNeedsApproval:A}=Vr(),{addTransactionToLocalHistory:_,updateTransactionInLocalHistory:I}=Gi(),{networks:{evm:{signer:N}}}=zi(),L=Ia(),M=up(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+Ko?.[r?.chainId]?.[i?.chainId]||Qo,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)",re="MessageReceived(bytes32,uint64,address,bytes)",q=se.getDefaultProvider(e.find(T=>T.ecosystem==="evm"&&T.chainId===i.chainId)?.publicRpcUrls[0]),ne=async(T,s,l)=>{let g=F.logs?.find(v=>v.topics[0]===se.utils.id(s));if(g){let v=g?.topics[1];B.messageId=v;let C=new se.Contract(Rt[i?.chainId]?.[T],T==="XSwapRouter"?Hu:Vu,q),b={address:Rt[i.chainId]?.[T],topics:[se.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 ne("XSwapRouter",J,Q),await ne("CustomXSwapRouter",G,re)}_(B,F.from)},[_,I,r,i,n,a,o,f,e,d]),V=up(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&&hp(r?.chainId,B.transactionHash,a?.address,f)}}})};n.address!==ir.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 Dc("div",{className:"flex flex-col text-t_text_primary gap-5",children:[Nn(fp,{onCloseClick:t}),E?Nn("div",{children:E}):Dc(f3,{children:[Dc("div",{className:"relative flex flex-col gap-5 fill-white",children:[Nn(Lc,{type:"source"}),Nn(ip,{}),Nn(Lc,{type:"destination"})]}),Nn(ls,{})]}),h===0?Nn(hr,{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"}):Nn(lp,{})]})};import{jsx as Oc,jsxs as xp}from"react/jsx-runtime";var Uc=({chain:t,token:e,value:r})=>xp("div",{className:"flex items-center gap-2",children:[Oc(Rn,{chain:t,token:e,chainLogoClassName:"w-5",tokenLogoClassName:"w-9 h-9",generatedLogoClassName:"w-9 h-9 text-[16px]"}),xp("div",{className:"flex flex-col w-min sm:w-auto",children:[Oc("div",{children:`${r} ${e?.symbol}`}),Oc("div",{className:"opacity-60",children:t?.displayName})]})]});import{Fragment as mp,jsx as mt,jsxs as Fa}from"react/jsx-runtime";var bp=({onCloseClick:t})=>{let{txError:e,txExplorerUrl:r,txMsg:n}=Vr(),{isExpressDeliveryActive:i,srcChain:a,srcToken:o,dstChain:f,dstToken:d,srcValue:p,dstValue:h}=te();return mt("div",{className:"flex flex-col gap-5 text-t_text_primary justify-center items-center",children:e?Fa(mp,{children:[mt("div",{className:"flex justify-end fill-t_text_primary cursor-pointer w-full",onClick:t,children:mt(at,{className:"w-3.5 h-3.5"})}),mt(g1,{}),mt("div",{className:"text-2xl font-bold",children:"Transaction failed"}),mt("div",{className:"text-center",children:e})]}):Fa(mp,{children:[mt("div",{className:"flex justify-end fill-t_text_primary cursor-pointer w-full",onClick:t,children:mt(at,{className:"w-3.5 h-3.5"})}),mt(k1,{}),Fa("div",{className:"flex flex-col items-center",children:[mt("div",{className:"text-2xl font-bold",children:"Transaction success!"}),!n&&a!==f&&mt("div",{className:"text-sm font-normal opacity-60",children:`Approximated time of delivery: ${i?"30 sec":"30 min"}`})]}),!n&&Fa("div",{className:"flex items-center gap-2",children:[mt(Uc,{chain:a,token:o,value:p}),mt("div",{className:"-rotate-90 flex justify-center w-8 fill-t_text_primary opacity-50",children:mt(ns,{})}),mt(Uc,{chain:f,token:d,value:h})]}),Fa("a",{href:r,target:"_blank",rel:"noreferrer",className:"flex gap-4 items-center mb-2 fill-t_main_accent_light",children:[mt("p",{className:"text-t_text_secondary underline",children:"View details on Explorer"}),mt(C1,{})]})]})})};import{jsx as gp}from"react/jsx-runtime";var yp=({onCloseClick:t})=>{let{txStatus:e,txError:r}=Vr();return e===5||r?gp(bp,{onCloseClick:t}):gp(pp,{onCloseClick:t})};import{useSnackbar as d3}from"notistack";import{createContext as l3,useCallback as La,useContext as u3,useEffect as p3,useMemo as Hc,useRef as vp,useState as ln}from"react";import{useAccount as h3}from"wagmi";import{jsx as nr,jsxs as Vc}from"react/jsx-runtime";var wp=l3({}),Cp=({children:t})=>{let{chainId:e}=h3(),{enqueueTransaction:r}=$1(),{enqueueSnackbar:n,closeSnackbar:i}=d3(),[a,o]=ln("evm"),f=vp(!1),[d,p]=ln(!1),[h,w]=ln(""),E=vp(),[S,A]=ln(""),[_,I]=ln(""),[N,L]=ln(void 0),[M,V]=ln(!1),[F,B]=ln(!1),[J,Q]=ln(0),{supportedChains:G,setSrcValue:re}=te(),q=y=>{E.current===y&&(f.current=!1,p(!1))};p3(()=>{if(!d&&(S&&(n(nr(In,{message:{text:S,variant:"error"}})),A("")),M&&h)){let y=h;n(nr(In,{message:{text:`Transaction ${Wu(h)} is about to be mined!`,variant:"warning",action:()=>Vc("div",{className:"flex items-center flex-nowrap",children:[nr(hr,{type:"button",onClick:()=>{window.open(`${G.find(m=>m.chainId===e?.toString()&&m.ecosystem===a)?.transactionExplorer}/${h}`||"")},children:"Check"}),nr("div",{className:"fill-t_text_primary w-[14px] h-[14px] cursor-pointer p-[14px] leading-[0px]",onClick:()=>i(y),children:nr(at,{})})]}),animation:()=>nr(Gr,{className:"w-4 h-4"})}}),{persist:!0,key:y}),w("")}},[M,a,h,S,n,i,e,d,G]);let ne=La((y,m,c)=>{let x=`${m}/${y}`;if(c){let u=c.events?.find(k=>k.event==="MessageSent")?.args?.messageId;return u?`${Ui}${u}`:x}else return x},[]),T=La((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(nr(In,{message:{text:"Transaction mined successfully!",variant:"success",action:()=>Vc("div",{className:"flex items-center flex-nowrap",children:[nr(hr,{type:"button",onClick:()=>{window.open(ne(h,G.find(k=>k.chainId===e?.toString()&&k.ecosystem===a)?.transactionExplorer||"",R))},children:"View"}),nr("div",{className:"fill-t_text_primary w-[14px] h-[14px] cursor-pointer p-[14px] leading-[0px]",onClick:()=>i(u),children:nr(at,{})})]})}}),{persist:!1,key:u})}m?.onSuccess&&m?.onSuccess(R),A(""),V(!1)}},x.onError=R=>{E.current===y&&(A(qu(R)),m?.onError?.(R),V(!1))},x},[i,h,n,ne,G,e,a]),s=La(({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=Hc(()=>ne(h,G.find(y=>y.chainId===e?.toString()&&y.ecosystem===a)?.transactionExplorer||"",N),[e,a,ne,G,h,N]),g=La(y=>{p(y),f.current=y},[]),v=Hc(()=>S?"error":J===5?"success":"neutral",[S,J]),C=Hc(()=>({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=La(()=>{A(""),re(""),g(!1)},[A,re,g]);return Vc(wp.Provider,{value:C,children:[d&&nr(Ap,{id:"tx_modal",className:"max-w-x_modal",type:v,onCloseClick:b,children:nr(yp,{onCloseClick:b})}),t]})};function Vr(){return u3(wp)}import{jsx as Tp}from"react/jsx-runtime";var qi=({className:t,children:e,onClose:r})=>{let{overlay:n}=te();return Tp("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:Tp("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})})};import{jsx as Gc,jsxs as x3}from"react/jsx-runtime";var zc=()=>x3("div",{className:"flex justify-center items-center gap-2 my-3",children:[Gc("span",{className:"text-t_text_primary opacity-50",children:"Powered by"}),Gc("div",{className:"flex items-center gap-1 fill-t_chainlink_logo",children:Gc(d1,{})})]});import{forwardRef as m3,useCallback as b3,useMemo as g3}from"react";import{jsx as y3}from"react/jsx-runtime";var Da=m3(({value:t,onChange:e,id:r,placeholder:n,regex:i,className:a,disabled:o},f)=>{let d=g3(()=>t.length<2?2:t.length,[t]),p=b3(h=>{h.target.value!=="."&&i.test(h.target.value)&&e(h.target.value.replace(/,/g,"."))},[e,i,r]);return y3("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})});Da.displayName="SafeInput";import{jsx as v3}from"react/jsx-runtime";var xr=({className:t})=>v3("div",{className:`bg-t_bg_tertiary bg-opacity-15 rounded animate-pulse ${t||""}`});import{jsx as Wc,jsxs as w3}from"react/jsx-runtime";var Gr=({className:t})=>Wc("div",{role:"status",className:t||"",children:w3("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:[Wc("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"}),Wc("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"})]})});import{useMemo as i6}from"react";import{Fragment as C3,jsx as un,jsxs as A3}from"react/jsx-runtime";var Sp=({onClose:t})=>{let{tab:e,setTab:r,overlay:n}=te();return un("div",{className:"flex gap-5 items-center",children:e==="Swap"?A3(C3,{children:[un("button",{type:"button",onClick:()=>r("Settings"),"aria-label":"Open settings",className:"fill-white",children:un(T1,{})}),un("button",{type:"button",onClick:()=>r("History"),"aria-label":"Open history",className:"fill-white",children:un(v1,{})}),n&&un("button",{type:"button",onClick:()=>t(),"aria-label":"Close",className:"fill-t_text_primary",children:un(at,{})})]}):un("button",{type:"button",onClick:()=>{r("Swap")},"aria-label":"Switch to swap view",className:"fill-t_text_primary",children:un(at,{})})})};import{jsx as Ep,jsxs as T3}from"react/jsx-runtime";var kp=({onClose:t})=>{let{tab:e,bridgeUI:r}=te();return T3("div",{className:"flex justify-between mt-2 px-4",children:[Ep("div",{className:"text-xl font-sans-bold font-bold",children:e==="Swap"&&r?"Bridge":e}),Ep(Sp,{onClose:t})]})};import{useMemo as S3}from"react";import{Virtuoso as E3}from"react-virtuoso";import{jsx as Ki}from"react/jsx-runtime";var _p=()=>{let{history:t,historyLoadedOnce:e}=Gi(),r=S3(()=>!t||t.length===0?e?Ki("div",{className:"text-center py-4 text-[#9e9e9e]",children:"Your history is empty"}):Ki("div",{className:"flex justify-center w-full py-4 fill-t_text_primary",children:Ki(Gr,{className:"w-8 h-8"})}):Ki(E3,{data:t,style:{height:"532px"},itemContent:(n,i)=>Ki(Mp,{transaction:i})}),[t,e]);return Ki("div",{className:"flex-1 overflow-hidden",children:r})};import{jsx as qc,jsxs as k3}from"react/jsx-runtime";var Oa=({checked:t,onClick:e})=>qc("div",{children:k3("span",{className:"inline-flex w-14 h-9 p-3 relative align-middle box-border overflow-hidden cursor-pointer",onClick:e,children:[qc("span",{className:"h-full w-full rounded-lg bg-t_bg_tertiary bg-opacity-30"}),qc("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"} `})]})});Oa.displayName="ToggleButton";import{useRef as _3}from"react";import{jsx as Ji,jsxs as Ip}from"react/jsx-runtime";var Pp=()=>{let t=_3(null),{infiniteApproval:e,setInfiniteApproval:r}=te();return Ip("div",{className:"flex flex-col gap-5 pt-5 border-t border-solid border-white border-opacity-10",children:[Ji("h1",{className:"text-sm font-medium text-left",children:"Approval"}),Ji("div",{className:"flex gap-2 items-center justify-between flex-wrap",children:Ip("div",{className:"flex items-center",children:[Ji("h2",{className:"text-xs",children:"Infinite approval: "}),Ji(Oa,{checked:e,onClick:()=>{r(n=>!n)}}),Ji(Wi,{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"}),Ji(ni,{ref:t,className:"cursor-help fill-t_main_accent_light w-[18px] h-[18px]"})]})})]})};import{useRef as M3}from"react";import{jsx as Xi,jsxs as hs}from"react/jsx-runtime";var Np=()=>{let t=M3(null),{expressDelivery:e,setExpressDelivery:r}=te();return hs("div",{className:"flex flex-col gap-5 pt-5 border-t border-solid border-t_text_primary border-opacity-10",children:[Xi("h1",{className:"text-sm font-medium text-left",children:"Delivery"}),hs("div",{className:"flex gap-2 items-center justify-between flex-wrap",children:[hs("div",{className:"flex items-center",children:[Xi("h2",{className:"text-xs",children:"Express delivery: "}),Xi(Oa,{checked:e,onClick:()=>{r(n=>!n)}}),Xi(Wi,{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"}),Xi(ni,{ref:t,className:"cursor-help fill-t_main_accent_light w-[18px] h-[18px]"})]}),hs("div",{className:"text-xs font-medium",children:[Xi("span",{className:"text-xs font-medium opacity-60",children:"Max time: "}),e?"30 sec":"30 min"]})]})]})};import{useState as I3}from"react";import{jsx as Bn,jsxs as xs}from"react/jsx-runtime";var Rp=()=>{let{slippage:t,setSlippage:e}=te(),[r,n]=I3(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 xs("div",{className:"flex flex-col gap-5 pt-5 border-t border-solid border-t_text_primary border-opacity-10",children:[Bn("h1",{className:"text-sm font-medium text-left",children:"Slippage"}),xs("div",{className:"flex items-center gap-2 w-full",children:[Bn("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=>Bn("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))}),Bn("div",{className:`${r?"gradient-slippage-container-blue p-[1px] rounded-xl":""}`,children:xs("div",{className:"bg-t_bg_primary p-1 h-full border border-solid border-t_text_primary border-opacity-10 rounded-xl",children:[Bn(Da,{id:"slippage-input",placeholder:"1.5",regex:Jo,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"} `})," ","%"]})})]}),xs("div",{className:"text-sm opacity-60",children:[Bn("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."}),Bn("br",{}),Bn("p",{children:"If the trade fails due to too low slippage, you will receive USDC on the destination chain."})]})]})};import{jsx as Kc,jsxs as P3}from"react/jsx-runtime";var Bp=()=>P3("div",{className:"flex flex-col gap-5 px-4",children:[Kc(Np,{}),Kc(Pp,{}),Kc(Rp,{})]});import{jsx as Ua}from"react/jsx-runtime";var Fp=()=>{let{dstChain:t,dstToken:e,srcChain:r,srcToken:n,setDstChain:i,setDstToken:a,setSrcChain:o,setSrcToken:f}=te();return Ua("div",{className:"h-[1px] w-full",children:Ua("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:Ua("div",{className:"relative bg-gradient-to-r from-t_main_accent_light to-t_main_accent_dark w-8 h-8 rounded-lg",children:Ua("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 fill-white",children:Ua(f1,{})})})})})};var Jc={1:["0xdac17f958d2ee523a2206206994597c13d831ec7"]};import{useCallback as Xc,useMemo as N3}from"react";var Lp=({rpcChainId:t,currentChainId:e,signer:r,tokenAddress:n})=>{let i=Sc(),{supportedChains:a}=te(),o=N3(()=>{let f=a.find(d=>d.ecosystem==="evm"&&d.chainId===t)?.publicRpcUrls[0];return f&&n?new se.Contract(n,Ur,r&&(!e||e===t)?r:se.getDefaultProvider(f)):null},[t,e,r,n,a]);return{balanceOf:Xc(async f=>await i.query(o,"balanceOf",[f]),[o,i]),allowance:Xc(async(f,d)=>await i.query(o,"allowance",[f,d]),[o,i]),approve:Xc(async(f,d)=>await i.execute(o,"approve",[d,f]),[o,i])}};import{useCallback as Op,useEffect as D3,useMemo as Qi,useState as Up}from"react";import{useAccount as O3,useSwitchChain as U3}from"wagmi";import{useCallback as R3,useMemo as B3}from"react";import{useConnect as F3}from"wagmi";import{jsx as pn,jsxs as Qc}from"react/jsx-runtime";var L3=({connector:t,className:e})=>{switch(t.name){case"WalletConnect":return pn(L1,{className:`w-[34px] h-[34px] rounded-md ${e||""}`});default:return pn("img",{src:t.icon,alt:t.name,className:`w-[34px] h-[34px] rounded-md ${e||""}`})}},Dp=({className:t,onClose:e})=>{let{connectors:r,connectAsync:n}=F3(),i=B3(()=>r.filter(o=>{let f=o.type==="injected",d=o.name==="Injected";return o.type==="walletConnect"||f&&!d}),[r]),a=R3(async o=>{await n({connector:o}),e()},[n,e]);return Qc("div",{className:`flex flex-col h-full ${t||""}`,children:[Qc("div",{className:"flex justify-between",children:[pn("div",{className:"text-base/4 mb-4 text-t_text_primary",children:"Pick wallet"}),pn("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:e,children:pn(at,{})})]}),pn("div",{className:"horizontal-separator"}),pn("div",{className:"h-full pt-4",children:i.map(o=>Qc("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:[pn(L3,{connector:o}),pn("div",{className:"text-t_text_primary",children:o.name})]},o.id))})]})};import{Fragment as H3,jsx as Zc,jsxs as V3}from"react/jsx-runtime";var Hp=()=>{let{address:t,chainId:e}=O3(),{switchChainAsync:r}=U3(),[n,i]=Up(!1),{integrationConfig:a}=te(),{bridgeUI:o,error:f,srcChain:d,dstChain:p,srcToken:h,dstToken:w,srcValueWei:E,srcTokenBalanceWei:S,isFetchingRoute:A,isAsyncDataLoaded:_,hasOnConnectWalletCallback:I,onConnectWallet:N}=te(),{setTxStatus:L,setTxMsg:M,setTxModalOpen:V,enqueueTransaction:F}=Vr(),B=Qi(()=>d?.chainId,[d?.chainId]),J=Qi(()=>p?.chainId,[p?.chainId]),Q=Qi(()=>h?.address,[h?.address]),G=Qi(()=>w?.address,[w?.address]),[re,q]=Up("0"),{networks:{evm:ne}}=zi(),{allowance:T,approve:s}=Lp({rpcChainId:B,currentChainId:ne.chainId,signer:ne.signer,tokenAddress:Q}),l=Qi(()=>B?B===J?Rt[B]?.XSwapRouterSingleChain||"":Rt[B]?.XSwapRouter||"":"",[B,J]),g=Op(async()=>{if(l&&ne.address)try{let b=await T(ne.address,l);q(b.toString())}catch{q("0")}else q("0")},[T,ne.address,l]);D3(()=>{B&&Jc[B]?.includes(Q)&&g()},[g,B,Q]);let v=Op(()=>{L(0),M(""),V(!0)},[V,M,L]),C=Qi(()=>_?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&&Ht(E).gt(Ht(S))?{text:"Insufficient Balance",fn:()=>{},disabled:!0}:Ht(E||"0").lte(Ht("0"))?{text:"Enter Token Amount",fn:()=>{},disabled:!0}:A?{text:"Fetching Route",fn:()=>{},disabled:!0}:Jc[B]?.includes(Q)&&re!=="0"&&X.from(re).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,re,o,a.defaultWalletPicker,r,F,s,l,g,L,v]);return V3(H3,{children:[n&&Zc(qi,{onClose:()=>i(!1),children:Zc(Dp,{onClose:()=>i(!1)})}),Zc("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})]})};import{useMemo as ih}from"react";import{useMemo as z3}from"react";import{jsx as Yc,jsxs as G3}from"react/jsx-runtime";var Vp=()=>{let{srcTokenBalanceInfo:t,isFetchingBalance:e}=te();return G3("div",{className:"flex flex-col items-end",children:[Yc("p",{className:"text-xs font-medium opacity-60",children:"Balance:"}),e?Yc(xr,{className:"w-[50px] h-[16px]"}):Yc("p",{className:`text-xs font-medium ${!t&&"opacity-60"}`,children:t||"-"})]})};import{Fragment as Gp,jsx as Fn,jsxs as ms}from"react/jsx-runtime";var zp=({type:t})=>{let{srcValue:e,srcValueUsd:r,dstValue:n,dstValueUsd:i,setSrcValue:a,isFetchingRoute:o}=te(),f=z3(()=>t==="source"?r:i,[i,r,t]);return ms("div",{className:"flex justify-between items-center w-full p-4 gap-8 overflow-hidden",children:[Fn("div",{className:"flex flex-col font-medium w-full overflow-hidden text-left",children:t==="source"?ms(Gp,{children:[Fn(Da,{id:"swap-amount-input",className:"bg-transparent border-none p-0 text-xl outline-0 font-sans-bold font-bold",regex:Jo,value:e,onChange:d=>a(d)}),f&&Fn("div",{className:"text-sx opacity-60",children:`$${f}`})]}):o?ms("div",{className:"flex flex-col gap-1",children:[Fn(xr,{className:"w-[150px] h-[30px]"}),Fn(xr,{className:"w-[100px] h-[20px]"})]}):ms(Gp,{children:[Fn("div",{className:"text-xl text-t_text_secondary font-sans-bold font-bold",children:n||0}),f&&Fn("div",{className:"text-sx opacity-60",children:`$${f}`})]})}),t==="source"&&Fn(Vp,{})]})};import{useMemo as Jp,useState as Q3}from"react";import{useMemo as W3,useState as q3,useRef as K3,useEffect as J3}from"react";import{Virtuoso as X3}from"react-virtuoso";import{useMemo as jc}from"react";import{jsx as Zi,jsxs as $c}from"react/jsx-runtime";var Wp=({chain:t,type:e,onClick:r,disabled:n})=>{let{networks:{evm:i}}=zi(),{srcChain:a,dstChain:o,bridgeUI:f}=te(),d=jc(()=>e==="source"?a?.chainId:o?.chainId,[o,a,e]),p=jc(()=>i.signer&&i.chainId===t.chainId,[t.chainId,i.chainId,i.signer]),h=jc(()=>{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 Zi("div",{className:"group relative",children:$c("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:[$c("div",{className:"flex gap-3 items-center w-full",children:[Zi("img",{src:t.image,alt:t.name,className:"w-[34px] h-[34px]"}),Zi("p",{children:t.displayName})]}),E&&Zi("div",{className:"w-full text-center opacity-0 group-hover:opacity-100 text-xs transition-opacity duration-200",children:E}),p&&$c("div",{className:"flex items-baseline gap-1",children:[Zi(m1,{}),Zi("div",{className:"text-t_text_green",children:"connected"})]})]})})};import{jsx as br,jsxs as qp}from"react/jsx-runtime";var Kp=({type:t,onClose:e})=>{let{setSrcChain:r,setDstChain:n,srcChainOptions:i,dstChainOptions:a}=te(),[o,f]=q3(""),d=K3(null);J3(()=>{d.current&&setTimeout(()=>{d.current?.focus()},10)},[]);let p=W3(()=>{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 qp("div",{className:"flex flex-col h-full",children:[qp("div",{className:"flex justify-between",children:[br("div",{className:"text-base/4 text-t_text_primary mb-4",children:`Pick ${t} chain`}),br("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:e,children:br(at,{})})]}),br(bs,{ref:d,inputIcon:br("div",{className:"fill-t_text_primary",children:br(as,{})}),placeholder:"Search chain name",value:o,handleChange:f}),br("div",{className:"horizontal-separator mt-4"}),br("div",{className:"h-full pt-4",children:p.length?br(X3,{style:{height:"100%"},data:p,itemContent:(w,E)=>br(Wp,{chain:E,type:t,disabled:E.disabled,onClick:h})}):br("div",{className:"flex justify-center mt-4",children:"No chain found."})})]})};import{Fragment as Z3,jsx as ii,jsxs as ef}from"react/jsx-runtime";var Xp=({chain:t,type:e,className:r})=>{let{srcChainLocked:n,dstChainLocked:i}=te(),a=Jp(()=>e==="destination"&&i,[e,i]),o=Jp(()=>e==="source"&&n,[e,n]),[f,d]=Q3(!1);return ef(Z3,{children:[f&&ii(qi,{onClose:()=>d(!1),children:ii(Kp,{type:e,onClose:()=>d(!1)})}),ii("button",{type:"button",disabled:a||o,onClick:()=>d(!0),className:`${r||""}`,children:ef("div",{className:"flex justify-between items-center p-4 gap-8",children:[ef("div",{className:"flex flex-col font-medium items-start",children:[ii("p",{className:"text-xs opacity-60",children:e==="source"?"From:":"To:"}),ii("p",{className:`${t?"":"opacity-60"}`,children:t?t.displayName:"Select"})]}),!a&&!o&&ii("div",{className:"w-4 h-2 fill-t_text_primary",children:ii(ri,{})})]})})]})};import{jsx as Qp}from"react/jsx-runtime";var Zp=({type:t})=>{let{srcToken:e,srcTokenBalanceWei:r,srcTokenBalanceInfo:n,setSrcValue:i}=te();return Qp("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(ft({amount:r,decimals:e?.decimals||18,precisionFractionalPlaces:e?.decimals||18})),children:t==="source"&&Qp("p",{className:`border-b border-solid border-t_text_primary ${!n&&"border-opacity-60"}`,children:"Max"})})};import{useMemo as za,useState as r6}from"react";import{faCheck as j3}from"@fortawesome/free-solid-svg-icons";import{FontAwesomeIcon as $3}from"@fortawesome/react-fontawesome";import{useCallback as eh,useEffect as ys,useMemo as Va,useRef as th,useState as Yi}from"react";import{GroupedVirtuoso as e6}from"react-virtuoso";import{jsx as tf,jsxs as Yp}from"react/jsx-runtime";var jp=({token:t,selectedTokenAddress:e,onClick:r})=>Yp("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:[tf(Pn,{token:t,className:"w-6 h-6",generatedLogoClassName:"w-6 h-6"}),Yp("div",{className:"flex flex-col gap-1 text-xs font-medium !leading-3",children:[tf("div",{className:"text-t_text_primary",children:t.name}),tf("div",{className:"text-t_text_primary text-opacity-50",children:t.symbol})]})]});import{useMemo as Ha}from"react";import{useAccount as Y3}from"wagmi";import{jsx as ai,jsxs as gs}from"react/jsx-runtime";var $p=({token:t,selectedTokenAddress:e,onClick:r,selectedChainId:n})=>{let{supportedChains:i,tokenPrices:a,isFetchingBalances:o}=te(),{address:f}=Y3(),d=Ha(()=>i.find(({chainId:S})=>S===t.chainId),[i,t]),p=Ha(()=>a[t.chainId]?.[t.address],[t,a]),h=Ha(()=>!t.balance||!t.decimals?null:Number(se.utils.formatUnits(t.balance,t.decimals)),[t.balance,t.decimals]),w=Ha(()=>t.balance&&!t.balance.eq(0),[t.balance]),E=Ha(()=>!h||!p||!w?null:h*+p,[h,p,w]);return gs("div",{className:`token-picker-container ${t.address.toLowerCase()===e?.toLowerCase()&&n&&t.chainId===n?"bg-t_bg_tertiary bg-opacity-10":""}`,onClick:r,children:[ai(Rn,{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"}),gs("div",{className:"flex justify-between items-center gap-1 w-full",children:[gs("div",{className:"text-left",children:[ai("div",{className:"text-sm font-medium text-ellipsis text-t_text_primary",children:t.name}),ai("div",{className:"text-xs text-t_text_primary text-opacity-50 font-medium",children:t.symbol})]}),t.balance&&t.decimals&&f&&!o&&gs("div",{className:"text-right",children:[ai("div",{className:"text-xs text-t_text_primary",children:t.balance.eq(0)||h>1e-4?ft({amount:t.balance.toString(),decimals:t.decimals,precisionFractionalPlaces:4}):"<0.0001"}),w&&ai("div",{className:"text-xs text-t_text_primary text-opacity-50",children:E?`$${E.toFixed(2)}`:"$ -"})]}),f&&o&&ai("div",{children:ai(xr,{className:"w-[48px] h-[12px]"})})]})]})};import{useAccount as t6}from"wagmi";import{Fragment as rf,jsx as xe,jsxs as Bt}from"react/jsx-runtime";var rh=({chain:t,tokens:e,otherTokens:r,selectedTokenAddress:n,isOpen:i,onSelect:a,setModalOpen:o,type:f})=>{let[d,p]=Yi(""),[h,w]=Yi(!1),[E,S]=Yi(!1),[A,_]=Yi(!1),[I,N]=Yi(null),[L,M]=Yi(!0),V=th(0),F=th(null),{bridgeUI:B,supportedChains:J,findTokenDataByAddressAndChain:Q,tokenPrices:G}=te(),{address:re}=t6(),q=Ia();ys(()=>{S(!1),w(!1)},[i]);let ne=eh(()=>{if(t&&I&&Hi(d)){let y={};wt||(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};wt||(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=eh(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 se.Contract(d.toLowerCase(),Ur,se.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]);ys(()=>{!B&&Hi(d)&&t&&!Q(d.toLowerCase(),t.chainId)?T():(_(!1),N(null))},[B,d,T,Q,t]),ys(()=>{p("")},[i]);let s=(y,m)=>y.toLowerCase().indexOf(m.toLowerCase())>-1,l=Va(()=>e?.filter(y=>s(y.symbol,d)||s(y.name,d)||y.address.toLowerCase()===d.toLowerCase()),[d,e]),g=Va(()=>r?.filter(y=>s(y.symbol,d)||s(y.name,d)||y.address.toLowerCase()===d.toLowerCase()),[d,r]);ys(()=>{i&&F.current&&setTimeout(()=>{F.current?.focus()},10)},[i]);let v=Va(()=>{let y=u=>{if(!u.balance||!u.decimals)return 0;let k=Number(se.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?[...re&&m.length&&f==="source"?[m]:[],c,x]:[...re&&m.length&&f==="source"?[m]:[],[...c,...x]]).flat()},[l,g,t,re,f,G]),C=Va(()=>v.filter(y=>y.balance?.gt(0)),[v]),b=Va(()=>t?[...f==="source"&&re&&C.length?[C]:[],l,g]:[...f==="source"&&re&&C.length?[C]:[],g],[t,f,re,C,l,g]);return E?Bt(rf,{children:[Bt("div",{className:"flex justify-between",children:[xe("div",{className:"text-base/4 mb-4",children:"Import token"}),xe("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:()=>o(!1),children:xe(at,{})})]}),Bt("div",{className:"flex flex-col h-full gap-2",children:[I&&Bt("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:[xe(Ga,{tokenName:I.name,className:"w-9 h-9 text-[15px]"}),Bt("div",{className:"flex justify-between items-center gap-1 overflow-hidden grow",children:[xe("div",{className:"overflow-hidden whitespace-nowrap text-ellipsis text-sm font-medium",children:I.name}),xe("div",{className:"token-picker__all__symbol",children:I.symbol})]}),Bt("div",{className:"text-sm flex items-center",children:[Ku(d.toLowerCase()),xe("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:xe(h1,{className:"w-5 h-5"})})]})]}),xe("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"}),Bt("div",{className:"bg-t_bg_secondary border border-solid border-t_text_primary border-opacity-10 rounded-xl p-2",children:[xe("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."}),Bt("button",{type:"button",onClick:()=>w(y=>!y),className:"flex items-center",children:[xe("div",{className:"flex justify-center items-center p-1 w-6 h-6 border-2 border-white rounded-md mr-2",children:h&&xe($3,{icon:j3,className:"w-4 h-4"})}),xe("div",{className:"font-bold",children:"Accept"})]})]}),xe("div",{className:"flex grow items-end justify-center",children:xe(hr,{type:"button",disabled:!h,className:`token-picker__import-button w-full ${h?"":"!cursor-not-allowed"}`,onClick:ne,children:"Import"})})]})]}):Bt(rf,{children:[Bt("div",{className:"flex justify-between",children:[xe("div",{className:"text-base/4 text-t_text_primary mb-4",children:`Pick ${f} token`}),xe("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:()=>o(!1),children:xe(at,{})})]}),xe(bs,{ref:F,inputIcon:xe("div",{className:"fill-t_text_primary",children:xe(as,{})}),placeholder:"Search name or paste address",value:d,handleChange:p}),xe("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=>xe(jp,{token:y,selectedTokenAddress:n,onClick:()=>{a(y),o(!1)}},y.address))}),xe("div",{className:"flex flex-col mx-0 h-full",children:A?xe("div",{className:"flex justify-center w-full py-4 px-0",children:xe(Gr,{className:"w-9 h-9"})}):xe(rf,{children:I?Bt("div",{className:"token-picker-container hover:cursor-default",children:[xe(Rn,{token:I,chain:t,tokenLogoClassName:"w-9 h-9",generatedLogoClassName:"w-9 h-9 text-[16px]",chainLogoClassName:"w-5"}),Bt("div",{className:"flex justify-between items-center gap-1 overflow-hidden grow",children:[Bt("div",{children:[xe("div",{className:"text-sm font-medium text-ellipsis",children:I.name}),xe("div",{className:"text-xs text-t_text_primary !text-opacity-50 font-medium",children:t?.displayName})]}),xe("div",{className:"token-picker__all__symbol",children:I.symbol})]}),xe("div",{children:xe(hr,{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"})})]}):xe("div",{className:"flex flex-col h-full gap-8 w-[calc(100%+32px)] mx-[-16px]",children:xe(e6,{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=>Bt("div",{className:"py-1 bg-t_bg_primary text-t_text_primary",children:[xe("div",{className:"px-4 text-left",children:(()=>{if(t)switch(y){case 0:return re?C.length&&f==="source"?"My tokens":`${t.displayName} network`:`${t.displayName} network`;case 1:return re?`${t.displayName} network`:"Other networks";case 2:return"Other networks";default:return"Undefined group"}else switch(y){case 0:return re&&C.length&&f==="source"?"My tokens":"All networks";case 1:return"All networks";default:return"Undefined group"}})()}),xe("div",{className:"horizontal-separator"}),!b[y]?.length&&xe("div",{className:"text-center py-1",children:"No token found"})]}),itemContent:y=>v[y]&&xe($p,{token:v[y],selectedChainId:t?.chainId,selectedTokenAddress:n,onClick:()=>{a(v[y]),o(!1)}})})})})})]})};import{Fragment as n6,jsx as Ln,jsxs as vs}from"react/jsx-runtime";var nh=({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:_}=te(),I=za(()=>r==="destination"&&A,[r,A]),N=za(()=>r==="source"&&_,[r,_]),[L,M]=r6(!1),V=za(()=>r==="source"?a:f,[f,a,r]),F=za(()=>r==="destination"&&i,[i,r]),B=za(()=>r==="source"?o:d,[d,o,r]),J=Q=>{let G=w.find(re=>re.chainId===Q.chainId);r==="source"?(p(Q),h(G)):(E(Q),S(G)),M(!1)};return vs(n6,{children:[L&&Ln(qi,{onClose:()=>M(!1),className:"z-[3]",children:Ln(rh,{type:r,chain:t,tokens:V,otherTokens:B,selectedTokenAddress:e?.address,onSelect:J,isOpen:L,setModalOpen:M})}),Ln("button",{type:"button",disabled:F||I||N,onClick:()=>{M(!0)},className:`${n||""}`,children:vs("div",{className:"flex justify-between items-center p-4 gap-8 border-r border-solid border-t_text_primary border-opacity-10",children:[vs("div",{className:"flex gap-2 items-center",children:[Ln(Pn,{token:e,className:"w-9 h-9",generatedLogoClassName:"w-9 h-9 text-[16px]"}),vs("div",{className:"flex flex-col font-medium items-start",children:[Ln("p",{className:"text-xs opacity-60",children:"Token: "}),Ln("p",{className:`${e?"":"opacity-60"}`,children:e?e.symbol:r==="destination"&&i?"-":"Select"})]})]}),!F&&!I&&!N&&Ln("div",{className:"w-4 h-2 fill-t_text_primary",children:Ln(ri,{})})]})})]})};import{jsx as ws,jsxs as nf}from"react/jsx-runtime";var af=({type:t})=>{let{srcChain:e,srcToken:r,dstChain:n,dstToken:i}=te(),a=ih(()=>t==="source"?r:i,[t,r,i]),o=ih(()=>t==="source"?e:n,[t,e,n]);return nf("div",{className:"flex flex-col x-border rounded-xl bg-t_bg_tertiary bg-opacity-5",children:[nf("div",{className:"flex border-b border-solid border-t_text_primary border-opacity-10",children:[ws(nh,{chain:o,token:a,type:t,className:"w-full flex-grow"}),ws(Xp,{chain:o,type:t,className:"w-full max-w-[160px]"})]}),nf("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:[ws(zp,{type:t}),ws(Zp,{type:t})]})]})};import{jsx as Wa,jsxs as ah}from"react/jsx-runtime";var oh=()=>ah("div",{className:"flex flex-col gap-6 fill-t_text_primary",children:[ah("div",{className:"flex flex-col gap-[11px]",children:[Wa(af,{type:"source"}),Wa(Fp,{}),Wa(af,{type:"destination"})]}),Wa(ls,{}),Wa(Hp,{})]});import{jsx as Cs,jsxs as a6}from"react/jsx-runtime";var of=({onClose:t})=>{let{tab:e}=te(),r=i6(()=>e==="Settings"?Cs(Bp,{}):e==="History"?Cs(_p,{}):Cs(oh,{}),[e]);return a6("div",{className:"relative flex flex-col gap-4 p-2 text-t_text_primary bg-t_bg_primary rounded-2xl flex-1",children:[Cs(kp,{onClose:t}),r]})};import{forwardRef as o6}from"react";import{Fragment as s6,jsx as qa,jsxs as sh}from"react/jsx-runtime";var bs=o6((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 sh(s6,{children:[sh("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,qa("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&&qa("div",{className:"flex justify-between pt-[10px]",children:qa("div",{className:"px-5 text-t_text_red",children:p})}),h&&qa("div",{className:"flex justify-between pt-[10px]",children:qa("div",{className:"px-5 text-t_text_orange",children:h})})]})});import{useState as ch,useEffect as c6,useCallback as As}from"react";var ji=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)}},f6=({expiryTimestamp:t,onExpire:e,autoStart:r=!0})=>{let[n,i]=ch(r),[a,o]=ch(ji.getSecondsFromExpiry(t)),f=As(()=>{let w=ji.getSecondsFromExpiry(t);w<=0&&(e&&e(),i(!1)),o(w)},[t,e]);c6(()=>{if(!n)return;let w=setInterval(f,1e3);return()=>clearInterval(w)},[n,f]);let d=As(()=>i(!1),[]),p=As(()=>i(!0),[]),h=As(w=>{i(!0),o(ji.getSecondsFromExpiry(w))},[]);return{...ji.getTimeFromSeconds(a),isRunning:n,pause:d,resume:p,restart:h}},fh=f6;import{useEffect as d6,useState as l6}from"react";import{Fragment as sf,jsx as Ka,jsxs as u6}from"react/jsx-runtime";var dh=({expiryTimestamp:t,displayFormat:e=2,customTextOnExpire:r})=>{let[n,i]=l6(t.getTime()<Date.now()),{seconds:a,minutes:o,hours:f,days:d,restart:p}=fh({expiryTimestamp:t,onExpire:()=>i(!0)});return d6(()=>{p(t)},[t]),Ka(sf,{children:n&&r?Ka(sf,{children:r}):u6(sf,{children:[e===0&&Ka("span",{children:`${(d*24+f)*60+o}:${a.toString().padStart(2,"0")}`}),e===1&&Ka("span",{children:`${d*24+f}:${o.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`}),e===2&&Ka("span",{children:`${d}:${f.toString().padStart(2,"0")}:${o.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`})]})})};import{useState as h6}from"react";import{jsx as p6}from"react/jsx-runtime";var Ga=({tokenName:t,className:e})=>p6("div",{className:`rounded-full bg-white shadow-sm flex items-center justify-center text-black ${e}`,children:t.substring(0,1)});import{jsx as cf}from"react/jsx-runtime";var Pn=({token:t,className:e,generatedLogoClassName:r})=>{let[n,i]=h6(!1);return t?n?cf(Ga,{tokenName:t.name,className:r}):t?.image?cf("img",{src:t.image,alt:t.name,className:`border border-solid border-t_text_primary border-opacity-10 rounded-2xl ${e}`,onError:()=>i(!0)}):cf(Ga,{tokenName:t.name,className:r}):null};import{jsx as lh,jsxs as x6}from"react/jsx-runtime";var Rn=({token:t,chain:e,tokenLogoClassName:r,generatedLogoClassName:n,chainLogoClassName:i})=>x6("div",{className:"relative flex items-end pr-1 pb-1",children:[lh(Pn,{token:t,className:r,generatedLogoClassName:n}),e&&lh("img",{src:e.image,alt:e.name,className:`absolute bottom-0 right-0 border border-solid border-t_bg_secondary rounded-3xl ${i}`})]});import{QueryClient as v6,QueryClientProvider as w6}from"@tanstack/react-query";import{useEffect as Ss,useMemo as ph}from"react";import{ErrorBoundary as C6}from"react-error-boundary";import{useReconnect as A6,WagmiProvider as T6}from"wagmi";function m6(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 b6={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"},g6={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"},y6={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 uh(t,e){let n={...t?{...b6}:{...g6},...e};for(let[i,a]of Object.entries(n)){let o=y6[i];o&&m6(o,a)}}import{Fragment as xh,jsx as St,jsxs as Ts}from"react/jsx-runtime";var S6=new v6,E6=()=>{let{reconnect:t}=A6();return Ss(()=>{let e=0,r=setInterval(()=>{t(),e++,e>=5&&clearInterval(r)},1e3);return()=>{clearInterval(r)}},[t]),St(xh,{})},k6=({onPendingTransactionsChange:t})=>{let{history:e}=Gi(),r=ph(()=>e.filter(n=>n.status==="IN_PROGRESS"),[e]);return Ss(()=>{t?t(r):window.xPayOnPendingTransactionsChange&&window.xPayOnPendingTransactionsChange(r)},[t,r]),St(xh,{})},ff=({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:re,integratorFee:q,integratorFeeReceiverAddress:ne})=>{let T=l=>{l.stopPropagation(),l.nativeEvent.stopImmediatePropagation(),l.target===l.currentTarget&&w&&h()},s=ph(()=>op(d),[d]);return Ss(()=>{uh(E,A)},[E,A]),Ss(()=>{re?.apiUrl&&es(re?.apiUrl)},[re?.apiUrl]),St(C6,{FallbackComponent:()=>St("div",{children:"Something went wrong, please contact XSwap."}),children:St(T6,{config:s,children:Ts(w6,{client:S6,children:[St(E6,{}),Ts(z1,{children:[St(k6,{onPendingTransactionsChange:_}),St(Q1,{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:ne},supportedChains:d,wagmiConfig:s,overlay:w,children:St(j1,{children:St(Cp,{children:w?St("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:Ts("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:[St(of,{onSubmit:p,onClose:h}),St(zc,{})]})}):Ts("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:[St(of,{onSubmit:()=>{},onClose:()=>{}}),St(zc,{})]})})})})]})]})})})},hh=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(dn===null)throw new Error("XPay was incorrectly initialized");return await Yu(),await new Promise(()=>{if(dn===null)throw new Error("XPay was incorrectly initialized");dn.render(St(ff,{integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,supportedChains:d,lightTheme:p,styles:w,onSubmit:()=>{dn&&dn.render("")},onClose:()=>{dn&&dn.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}`)}};import{faArrowRight as _6,faArrowUpRightFromSquare as M6,faHourglassHalf as I6}from"@fortawesome/free-solid-svg-icons";import{FontAwesomeIcon as uf}from"@fortawesome/react-fontawesome";import{format as P6}from"date-fns";import{useCallback as N6}from"react";import{jsx as df,jsxs as mh}from"react/jsx-runtime";var lf=({chain:t,token:e,amount:r})=>mh("div",{className:"flex gap-2",children:[df(Rn,{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"}),mh("div",{className:"flex flex-col text-[12px]",children:[df("div",{className:"text-t_text_primary text-nowrap",children:`${Number(r)<1e-4?"<0.0001":r} ${e?.symbol?e?.symbol:"unknown"}`}),df("div",{className:"text-xs text-t_text_primary text-opacity-50",children:t?.displayName})]})]});import{Fragment as R6,jsx as Vt,jsxs as oi}from"react/jsx-runtime";var Es=({transaction:t,supportedChains:e,srcToken:r,dstToken:n})=>{let a=N6(h=>P6(new Date(h*1e3),"d MMM yyyy HH:mm:ss"),[])(t.timestamp),o=ft({amount:t.amountWei,decimals:r?.decimals||18,precisionFractionalPlaces:4}),f=ft({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 oi("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:[oi("div",{className:"flex items-center gap-2 border-b border-solid border-t_text_primary border-opacity-10 pb-1",children:[Vt("div",{className:"text-xs text-t_text_primary text-opacity-50",children:a}),oi("div",{className:"flex grow justify-end items-center h-6",children:[t.status==="IN_PROGRESS"?oi("div",{className:"flex items-center grow justify-end text-xs",children:[Vt(uf,{icon:I6,className:"w-4 h-4 mr-1 text-t_text_orange"}),oi("div",{className:"text-xs text-t_text_orange min-w-[108px]",children:["In progress (",Vt(dh,{displayFormat:0,expiryTimestamp:new Date(t.estimatedDeliveryTimestamp),customTextOnExpire:"finalizing"}),")"]})]}):t.status==="DONE"?Vt("div",{className:"flex items-center grow justify-end text-xs",children:Vt("div",{className:" mr-1 text-t_text_green",children:"Done"})}):t.status==="REVERTED"?Vt("div",{className:"flex items-center grow justify-end text-xs",children:Vt("div",{className:"w-4 h-4 mr-1 text-t_text_red",children:"Reverted"})}):null,Vt("a",{href:`${t.messageId?`${Ui}${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:Vt(uf,{icon:M6,className:"w-[14px] h-[14px] text-t_text_primary"})})]})]}),Vt("div",{className:"flex flex-wrap gap-8",children:oi("div",{className:"flex items-center gap-2",children:[Vt(lf,{chain:d,token:r,amount:o}),t.tokenOutAddress&&oi(R6,{children:[Vt(uf,{icon:_6,className:"w-5 h-5 text-t_text_primary opacity-50 mx-1.5"}),Vt(lf,{chain:p,token:n,amount:f})]})]})})]})};import{jsx as B6}from"react/jsx-runtime";var Mp=({transaction:t})=>{let{supportedChains:e,findTokenDataByAddressAndChain:r}=te(),n=r(t.tokenAddress.toLowerCase(),t.sourceChainId),i=t.tokenOutAddress?r(t.tokenOutAddress?.toLowerCase(),t.targetChainId):void 0;return B6(Es,{transaction:t,supportedChains:e,srcToken:n,dstToken:i})};import{createPortal as F6}from"react-dom";import{jsx as bh}from"react/jsx-runtime";var Ap=({id:t,children:e,onCloseClick:r,type:n="waiting",className:i})=>F6(bh("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:bh("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})}),$n,t);import{useMemo as gh,useState as L6}from"react";import{Fragment as O6,jsx as Gt,jsxs as pf}from"react/jsx-runtime";var D6=({transaction:t,supportedChains:e,srcToken:r,dstToken:n})=>{let[i,a]=L6(!1),o=gh(()=>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=gh(()=>t?.status==="DONE"?"border border-solid border-t_success_dark":"border border-solid border-t_main_accent_dark",[t]);return pf("div",{className:"flex gap-2 items-end justify-end flex-wrap",onClick:()=>a(d=>!d),children:[i&&Gt(Es,{transaction:t,supportedChains:e,srcToken:r,dstToken:n}),Gt("div",{className:`text-t_text_primary rounded-xl h-14 w-20 mb-2 cursor-pointer ${o} ${f}`,children:pf("div",{className:"flex gap-2 items-center h-14 w-20 justify-center fill-t_text_primary",children:[Gt("div",{className:`${i?"rotate-180":""}`,children:Gt(s1,{})}),Gt("div",{className:"relative flex items-center justify-center w-9 h-9",children:t?.status==="DONE"?Gt("div",{className:"w-5 h-5 fill-t_success_dark",children:Gt(is,{})}):pf(O6,{children:[Gt("div",{className:"w-5 h-5",children:Gt(O1,{})}),Gt("div",{className:"absolute flex items-center justify-center top-0 left-0 right-0 bottom-0 text-t_text_primary",children:Gt(Gr,{className:"w-10 h-10"})})]})})]})})]})},si=[],yh=t=>{si.some(({transaction:e})=>e.hash===e.hash)||si.push(t)},vh=t=>{si=[...si.filter(r=>r.transaction.hash!==t)]},wh=t=>{si=si.map(e=>e.transaction.hash===t?{...e,transaction:{...e.transaction,status:"DONE"}}:e)},ks=()=>{let t=si.map(e=>Gt(D6,{...e},e.transaction.hash));if($o===null)throw new Error("XPay was incorrectly initialized");$o.render(Gt("div",{className:"fixed bottom-5 right-2 flex flex-col gap-3 pl-9 items-end w-full z-50",children:t}))};import U6 from"@r2wc/core";import Ch from"react";import{createRoot as H6}from"react-dom/client";var V6=(t,e,r)=>{let n=H6(t),i=Ch.createElement(e,r);return n.render(i),{root:n,ReactComponent:e}},G6=({root:t,ReactComponent:e},r)=>{let n=Ch.createElement(e,r);t.render(n)},z6=({root:t})=>{t.unmount()},Ah=(t,e={})=>U6(t,e,{mount:V6,update:G6,unmount:z6});import{useEffect as W6,useState as Th}from"react";import{Fragment as K6,jsx as _s,jsxs as J6}from"react/jsx-runtime";var q6=({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,re]=Th(!0),[q,ne]=Th([]);W6(()=>{(async()=>{re(!0),B?.apiUrl&&es(B.apiUrl);let s=(await ti()).filter(({web3Environment:l,bridgeSupported:g,swapSupported:v})=>l==="mainnet"&&(g||v));ne(s),re(!1)})()},[]);let T=(()=>{try{return typeof h=="string"?JSON.parse(h):h||void 0}catch(s){console.error("Error parsing styles:",s)}})();return J6(K6,{children:[_s("style",{children:Yo}),G?_s("div",{className:"min-h-[532px] w-full flex items-center justify-center",children:_s(Gr,{className:"w-10 h-10"})}):_s(ff,{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})]})},Ms=()=>{if(wt||typeof customElements>"u")return{};let t=Ah(q6,{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};import{isServer as X6}from"@tanstack/react-query";import{useEffect as Q6}from"react";import{jsx as Y6}from"react/jsx-runtime";var Z6=Ms();!X6&&typeof customElements<"u"&&(customElements.get("xpay-widget")||customElements.define("xpay-widget",Z6));var hf=({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})=>(Q6(()=>{window.xPayOnPendingTransactionsChange=w,window.xPayOnDstTokenChange=I,window.xPayOnDstChainChange=N,window.xPayOnSrcTokenChange=L,window.xPayOnSrcChainChange=M,window.xPayOnConnectWallet=V},[w,I,N,L,M,V]),Y6("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}));import j6 from"async-retry";var Sh=async(t,e)=>{let r=t.publicRpcUrls[0],n=new se.Contract(e.toLowerCase(),Ur,se.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 hp=async(t,e,r,n)=>{let i=await $6(t,e),a=(await ti()).filter(({web3Environment:J,swapSupported:Q})=>J==="mainnet"&&Q),o=i.logs?.find(J=>J.topics[0]===se.utils.id(Nu));if(!o)throw new Error(`No transaction event found for chain ${t} tx ${e}`);let f=o?.topics[1],p=new se.utils.Interface(Ru).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 Sh(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"};yh({transaction:L,supportedChains:a,dstToken:I,srcToken:S}),ks();let M=Rt[_]?.XSwapRouter;if(!M)throw new Error("Unknown destination XSwapRouter!");let V=new se.Contract(M,Fu,se.getDefaultProvider(a.find(J=>J.chainId===_)?.publicRpcUrls[0])),F={address:M,topics:[se.utils.id(Bu),f]},B=async()=>{wh(e),ks(),await new Promise(J=>setTimeout(()=>J(!0),Pu)),vh(e),ks()};vc({transferId:f}).then(J=>{J.status==="DONE"?B():(setTimeout(()=>vc({transferId:f}).then(Q=>{Q.status==="DONE"&&B()}),30*60*1e3),V.once(F,()=>B()))})},$6=async(t,e)=>{try{let r=(await ti()).find(i=>i.chainId===t),n=new se.providers.JsonRpcProvider(r?.publicRpcUrls[0]);return await j6(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 xf=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);e4(t,F,e,r,n,i),await hh({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})},e4=(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&&(!Hi(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&&(!Hi(a)||o.tokens.findIndex(({address:f})=>f.toLowerCase()===a.toLowerCase())===-1))throw new Error(`Provided token address ${a} on chain ${i} is invalid`)}};var t4=Ms();Zu();var r4={openTransactionModal:xf,TxWidget:hf,TxWidgetWC:t4},gF=r4;export{gf as ContractName,vn as Ecosystem,Rh as Environment,ci as TxStatus,hf as TxWidget,t4 as TxWidgetWC,ea as Web3Environment,yf as XSwapCallType,gF as default,xf as openTransactionModal};
|
|
91
|
+
${t?"translate-x-[12px] bg-t_main_accent_light":"bg-t_bg_tertiary"} `})]})});Oa.displayName="ToggleButton";import{useRef as _3}from"react";import{jsx as Ji,jsxs as Ip}from"react/jsx-runtime";var Pp=()=>{let t=_3(null),{infiniteApproval:e,setInfiniteApproval:r}=te();return Ip("div",{className:"flex flex-col gap-5 pt-5 border-t border-solid border-white border-opacity-10",children:[Ji("h1",{className:"text-sm font-medium text-left",children:"Approval"}),Ji("div",{className:"flex gap-2 items-center justify-between flex-wrap",children:Ip("div",{className:"flex items-center",children:[Ji("h2",{className:"text-xs",children:"Infinite approval: "}),Ji(Oa,{checked:e,onClick:()=>{r(n=>!n)}}),Ji(Wi,{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"}),Ji(ni,{ref:t,className:"cursor-help fill-t_main_accent_light w-[18px] h-[18px]"})]})})]})};import{useRef as M3}from"react";import{jsx as Xi,jsxs as hs}from"react/jsx-runtime";var Np=()=>{let t=M3(null),{expressDelivery:e,setExpressDelivery:r}=te();return hs("div",{className:"flex flex-col gap-5 pt-5 border-t border-solid border-t_text_primary border-opacity-10",children:[Xi("h1",{className:"text-sm font-medium text-left",children:"Delivery"}),hs("div",{className:"flex gap-2 items-center justify-between flex-wrap",children:[hs("div",{className:"flex items-center",children:[Xi("h2",{className:"text-xs",children:"Express delivery: "}),Xi(Oa,{checked:e,onClick:()=>{r(n=>!n)}}),Xi(Wi,{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"}),Xi(ni,{ref:t,className:"cursor-help fill-t_main_accent_light w-[18px] h-[18px]"})]}),hs("div",{className:"text-xs font-medium",children:[Xi("span",{className:"text-xs font-medium opacity-60",children:"Max time: "}),e?"30 sec":"30 min"]})]})]})};import{useState as I3}from"react";import{jsx as Bn,jsxs as xs}from"react/jsx-runtime";var Rp=()=>{let{slippage:t,setSlippage:e}=te(),[r,n]=I3(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 xs("div",{className:"flex flex-col gap-5 pt-5 border-t border-solid border-t_text_primary border-opacity-10",children:[Bn("h1",{className:"text-sm font-medium text-left",children:"Slippage"}),xs("div",{className:"flex items-center gap-2 w-full",children:[Bn("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=>Bn("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))}),Bn("div",{className:`${r?"gradient-slippage-container-blue p-[1px] rounded-xl":""}`,children:xs("div",{className:"bg-t_bg_primary p-1 h-full border border-solid border-t_text_primary border-opacity-10 rounded-xl",children:[Bn(Da,{id:"slippage-input",placeholder:"1.5",regex:Jo,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"} `})," ","%"]})})]}),xs("div",{className:"text-sm opacity-60",children:[Bn("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."}),Bn("br",{}),Bn("p",{children:"If the trade fails due to too low slippage, you will receive USDC on the destination chain."})]})]})};import{jsx as Kc,jsxs as P3}from"react/jsx-runtime";var Bp=()=>P3("div",{className:"flex flex-col gap-5 px-4",children:[Kc(Np,{}),Kc(Pp,{}),Kc(Rp,{})]});import{jsx as Ua}from"react/jsx-runtime";var Fp=()=>{let{dstChain:t,dstToken:e,srcChain:r,srcToken:n,setDstChain:i,setDstToken:a,setSrcChain:o,setSrcToken:f}=te();return Ua("div",{className:"h-[1px] w-full",children:Ua("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:Ua("div",{className:"relative bg-gradient-to-r from-t_main_accent_light to-t_main_accent_dark w-8 h-8 rounded-lg",children:Ua("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 fill-white",children:Ua(f1,{})})})})})};var Jc={1:["0xdac17f958d2ee523a2206206994597c13d831ec7"]};import{useCallback as Xc,useMemo as N3}from"react";var Lp=({rpcChainId:t,currentChainId:e,signer:r,tokenAddress:n})=>{let i=Sc(),{supportedChains:a}=te(),o=N3(()=>{let f=a.find(d=>d.ecosystem==="evm"&&d.chainId===t)?.publicRpcUrls[0];return f&&n?new se.Contract(n,Ur,r&&(!e||e===t)?r:se.getDefaultProvider(f)):null},[t,e,r,n,a]);return{balanceOf:Xc(async f=>await i.query(o,"balanceOf",[f]),[o,i]),allowance:Xc(async(f,d)=>await i.query(o,"allowance",[f,d]),[o,i]),approve:Xc(async(f,d)=>await i.execute(o,"approve",[d,f]),[o,i])}};import{useCallback as Op,useEffect as D3,useMemo as Qi,useState as Up}from"react";import{useAccount as O3,useSwitchChain as U3}from"wagmi";import{useCallback as R3,useMemo as B3}from"react";import{useConnect as F3}from"wagmi";import{jsx as pn,jsxs as Qc}from"react/jsx-runtime";var L3=({connector:t,className:e})=>{switch(t.name){case"WalletConnect":return pn(L1,{className:`w-[34px] h-[34px] rounded-md ${e||""}`});default:return pn("img",{src:t.icon,alt:t.name,className:`w-[34px] h-[34px] rounded-md ${e||""}`})}},Dp=({className:t,onClose:e})=>{let{connectors:r,connectAsync:n}=F3(),i=B3(()=>r.filter(o=>{let f=o.type==="injected",d=o.name==="Injected";return o.type==="walletConnect"||f&&!d}),[r]),a=R3(async o=>{await n({connector:o}),e()},[n,e]);return Qc("div",{className:`flex flex-col h-full ${t||""}`,children:[Qc("div",{className:"flex justify-between",children:[pn("div",{className:"text-base/4 mb-4 text-t_text_primary",children:"Pick wallet"}),pn("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:e,children:pn(at,{})})]}),pn("div",{className:"horizontal-separator"}),pn("div",{className:"h-full pt-4",children:i.map(o=>Qc("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:[pn(L3,{connector:o}),pn("div",{className:"text-t_text_primary",children:o.name})]},o.id))})]})};import{Fragment as H3,jsx as Zc,jsxs as V3}from"react/jsx-runtime";var Hp=()=>{let{address:t,chainId:e}=O3(),{switchChainAsync:r}=U3(),[n,i]=Up(!1),{integrationConfig:a}=te(),{bridgeUI:o,error:f,srcChain:d,dstChain:p,srcToken:h,dstToken:w,srcValueWei:E,srcTokenBalanceWei:S,isFetchingRoute:A,isAsyncDataLoaded:_,hasOnConnectWalletCallback:I,onConnectWallet:N}=te(),{setTxStatus:L,setTxMsg:M,setTxModalOpen:V,enqueueTransaction:F}=Vr(),B=Qi(()=>d?.chainId,[d?.chainId]),J=Qi(()=>p?.chainId,[p?.chainId]),Q=Qi(()=>h?.address,[h?.address]),G=Qi(()=>w?.address,[w?.address]),[re,q]=Up("0"),{networks:{evm:ne}}=zi(),{allowance:T,approve:s}=Lp({rpcChainId:B,currentChainId:ne.chainId,signer:ne.signer,tokenAddress:Q}),l=Qi(()=>B?B===J?Rt[B]?.XSwapRouterSingleChain||"":Rt[B]?.XSwapRouter||"":"",[B,J]),g=Op(async()=>{if(l&&ne.address)try{let b=await T(ne.address,l);q(b.toString())}catch{q("0")}else q("0")},[T,ne.address,l]);D3(()=>{B&&Jc[B]?.includes(Q)&&g()},[g,B,Q]);let v=Op(()=>{L(0),M(""),V(!0)},[V,M,L]),C=Qi(()=>_?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&&Ht(E).gt(Ht(S))?{text:"Insufficient Balance",fn:()=>{},disabled:!0}:Ht(E||"0").lte(Ht("0"))?{text:"Enter Token Amount",fn:()=>{},disabled:!0}:A?{text:"Fetching Route",fn:()=>{},disabled:!0}:Jc[B]?.includes(Q)&&re!=="0"&&X.from(re).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,re,o,a.defaultWalletPicker,r,F,s,l,g,L,v]);return V3(H3,{children:[n&&Zc(qi,{onClose:()=>i(!1),children:Zc(Dp,{onClose:()=>i(!1)})}),Zc("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})]})};import{useMemo as ih}from"react";import{useMemo as z3}from"react";import{jsx as Yc,jsxs as G3}from"react/jsx-runtime";var Vp=()=>{let{srcTokenBalanceInfo:t,isFetchingBalance:e}=te();return G3("div",{className:"flex flex-col items-end",children:[Yc("p",{className:"text-xs font-medium opacity-60",children:"Balance:"}),e?Yc(xr,{className:"w-[50px] h-[16px]"}):Yc("p",{className:`text-xs font-medium ${!t&&"opacity-60"}`,children:t||"-"})]})};import{Fragment as Gp,jsx as Fn,jsxs as ms}from"react/jsx-runtime";var zp=({type:t})=>{let{srcValue:e,srcValueUsd:r,dstValue:n,dstValueUsd:i,setSrcValue:a,isFetchingRoute:o}=te(),f=z3(()=>t==="source"?r:i,[i,r,t]);return ms("div",{className:"flex justify-between items-center w-full p-4 gap-8 overflow-hidden",children:[Fn("div",{className:"flex flex-col font-medium w-full overflow-hidden text-left",children:t==="source"?ms(Gp,{children:[Fn(Da,{id:"swap-amount-input",className:"bg-transparent border-none p-0 text-xl outline-0 font-sans-bold font-bold",regex:Jo,value:e,onChange:d=>a(d)}),f&&Fn("div",{className:"text-sx opacity-60",children:`$${f}`})]}):o?ms("div",{className:"flex flex-col gap-1",children:[Fn(xr,{className:"w-[150px] h-[30px]"}),Fn(xr,{className:"w-[100px] h-[20px]"})]}):ms(Gp,{children:[Fn("div",{className:"text-xl text-t_text_secondary font-sans-bold font-bold",children:n||0}),f&&Fn("div",{className:"text-sx opacity-60",children:`$${f}`})]})}),t==="source"&&Fn(Vp,{})]})};import{useMemo as Jp,useState as Q3}from"react";import{useMemo as W3,useState as q3,useRef as K3,useEffect as J3}from"react";import{Virtuoso as X3}from"react-virtuoso";import{useMemo as jc}from"react";import{jsx as Zi,jsxs as $c}from"react/jsx-runtime";var Wp=({chain:t,type:e,onClick:r,disabled:n})=>{let{networks:{evm:i}}=zi(),{srcChain:a,dstChain:o,bridgeUI:f}=te(),d=jc(()=>e==="source"?a?.chainId:o?.chainId,[o,a,e]),p=jc(()=>i.signer&&i.chainId===t.chainId,[t.chainId,i.chainId,i.signer]),h=jc(()=>{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 Zi("div",{className:"group relative",children:$c("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:[$c("div",{className:"flex gap-3 items-center w-full",children:[Zi("img",{src:t.image,alt:t.name,className:"w-[34px] h-[34px]"}),Zi("p",{children:t.displayName})]}),E&&Zi("div",{className:"w-full text-center opacity-0 group-hover:opacity-100 text-xs transition-opacity duration-200",children:E}),p&&$c("div",{className:"flex items-baseline gap-1",children:[Zi(m1,{}),Zi("div",{className:"text-t_text_green",children:"connected"})]})]})})};import{jsx as br,jsxs as qp}from"react/jsx-runtime";var Kp=({type:t,onClose:e})=>{let{setSrcChain:r,setDstChain:n,srcChainOptions:i,dstChainOptions:a}=te(),[o,f]=q3(""),d=K3(null);J3(()=>{d.current&&setTimeout(()=>{d.current?.focus()},10)},[]);let p=W3(()=>{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 qp("div",{className:"flex flex-col h-full",children:[qp("div",{className:"flex justify-between",children:[br("div",{className:"text-base/4 text-t_text_primary mb-4",children:`Pick ${t} chain`}),br("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:e,children:br(at,{})})]}),br(bs,{ref:d,inputIcon:br("div",{className:"fill-t_text_primary",children:br(as,{})}),placeholder:"Search chain name",value:o,handleChange:f}),br("div",{className:"horizontal-separator mt-4"}),br("div",{className:"h-full pt-4",children:p.length?br(X3,{style:{height:"100%"},data:p,itemContent:(w,E)=>br(Wp,{chain:E,type:t,disabled:E.disabled,onClick:h})}):br("div",{className:"flex justify-center mt-4",children:"No chain found."})})]})};import{Fragment as Z3,jsx as ii,jsxs as ef}from"react/jsx-runtime";var Xp=({chain:t,type:e,className:r})=>{let{srcChainLocked:n,dstChainLocked:i}=te(),a=Jp(()=>e==="destination"&&i,[e,i]),o=Jp(()=>e==="source"&&n,[e,n]),[f,d]=Q3(!1);return ef(Z3,{children:[f&&ii(qi,{onClose:()=>d(!1),children:ii(Kp,{type:e,onClose:()=>d(!1)})}),ii("button",{type:"button",disabled:a||o,onClick:()=>d(!0),className:`${r||""}`,children:ef("div",{className:"flex justify-between items-center p-4 gap-8",children:[ef("div",{className:"flex flex-col font-medium items-start",children:[ii("p",{className:"text-xs opacity-60",children:e==="source"?"From:":"To:"}),ii("p",{className:`${t?"":"opacity-60"}`,children:t?t.displayName:"Select"})]}),!a&&!o&&ii("div",{className:"w-4 h-2 fill-t_text_primary",children:ii(ri,{})})]})})]})};import{jsx as Qp}from"react/jsx-runtime";var Zp=({type:t})=>{let{srcToken:e,srcTokenBalanceWei:r,srcTokenBalanceInfo:n,setSrcValue:i}=te();return Qp("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(ft({amount:r,decimals:e?.decimals||18,precisionFractionalPlaces:e?.decimals||18})),children:t==="source"&&Qp("p",{className:`border-b border-solid border-t_text_primary ${!n&&"border-opacity-60"}`,children:"Max"})})};import{useMemo as za,useState as r6}from"react";import{faCheck as j3}from"@fortawesome/free-solid-svg-icons";import{FontAwesomeIcon as $3}from"@fortawesome/react-fontawesome";import{useCallback as eh,useEffect as ys,useMemo as Va,useRef as th,useState as Yi}from"react";import{GroupedVirtuoso as e6}from"react-virtuoso";import{jsx as tf,jsxs as Yp}from"react/jsx-runtime";var jp=({token:t,selectedTokenAddress:e,onClick:r})=>Yp("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:[tf(Pn,{token:t,className:"w-6 h-6",generatedLogoClassName:"w-6 h-6"}),Yp("div",{className:"flex flex-col gap-1 text-xs font-medium !leading-3",children:[tf("div",{className:"text-t_text_primary",children:t.name}),tf("div",{className:"text-t_text_primary text-opacity-50",children:t.symbol})]})]});import{useMemo as Ha}from"react";import{useAccount as Y3}from"wagmi";import{jsx as ai,jsxs as gs}from"react/jsx-runtime";var $p=({token:t,selectedTokenAddress:e,onClick:r,selectedChainId:n})=>{let{supportedChains:i,tokenPrices:a,isFetchingBalances:o}=te(),{address:f}=Y3(),d=Ha(()=>i.find(({chainId:S})=>S===t.chainId),[i,t]),p=Ha(()=>a[t.chainId]?.[t.address],[t,a]),h=Ha(()=>!t.balance||!t.decimals?null:Number(se.utils.formatUnits(t.balance,t.decimals)),[t.balance,t.decimals]),w=Ha(()=>t.balance&&!t.balance.eq(0),[t.balance]),E=Ha(()=>!h||!p||!w?null:h*+p,[h,p,w]);return gs("div",{className:`token-picker-container ${t.address.toLowerCase()===e?.toLowerCase()&&n&&t.chainId===n?"bg-t_bg_tertiary bg-opacity-10":""}`,onClick:r,children:[ai(Rn,{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"}),gs("div",{className:"flex justify-between items-center gap-1 w-full",children:[gs("div",{className:"text-left",children:[ai("div",{className:"text-sm font-medium text-ellipsis text-t_text_primary",children:t.name}),ai("div",{className:"text-xs text-t_text_primary text-opacity-50 font-medium",children:t.symbol})]}),t.balance&&t.decimals&&f&&!o&&gs("div",{className:"text-right",children:[ai("div",{className:"text-xs text-t_text_primary",children:t.balance.eq(0)||h>1e-4?ft({amount:t.balance.toString(),decimals:t.decimals,precisionFractionalPlaces:4}):"<0.0001"}),w&&ai("div",{className:"text-xs text-t_text_primary text-opacity-50",children:E?`$${E.toFixed(2)}`:"$ -"})]}),f&&o&&ai("div",{children:ai(xr,{className:"w-[48px] h-[12px]"})})]})]})};import{useAccount as t6}from"wagmi";import{Fragment as rf,jsx as xe,jsxs as Bt}from"react/jsx-runtime";var rh=({chain:t,tokens:e,otherTokens:r,selectedTokenAddress:n,isOpen:i,onSelect:a,setModalOpen:o,type:f})=>{let[d,p]=Yi(""),[h,w]=Yi(!1),[E,S]=Yi(!1),[A,_]=Yi(!1),[I,N]=Yi(null),[L,M]=Yi(!0),V=th(0),F=th(null),{bridgeUI:B,supportedChains:J,findTokenDataByAddressAndChain:Q,tokenPrices:G}=te(),{address:re}=t6(),q=Ia();ys(()=>{S(!1),w(!1)},[i]);let ne=eh(()=>{if(t&&I&&Hi(d)){let y={};wt||(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};wt||(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=eh(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 se.Contract(d.toLowerCase(),Ur,se.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]);ys(()=>{!B&&Hi(d)&&t&&!Q(d.toLowerCase(),t.chainId)?T():(_(!1),N(null))},[B,d,T,Q,t]),ys(()=>{p("")},[i]);let s=(y,m)=>y.toLowerCase().indexOf(m.toLowerCase())>-1,l=Va(()=>e?.filter(y=>s(y.symbol,d)||s(y.name,d)||y.address.toLowerCase()===d.toLowerCase()),[d,e]),g=Va(()=>r?.filter(y=>s(y.symbol,d)||s(y.name,d)||y.address.toLowerCase()===d.toLowerCase()),[d,r]);ys(()=>{i&&F.current&&setTimeout(()=>{F.current?.focus()},10)},[i]);let v=Va(()=>{let y=u=>{if(!u.balance||!u.decimals)return 0;let k=Number(se.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?[...re&&m.length?[m]:[],c,x]:[...re&&m.length?[m]:[],[...c,...x]]).flat()},[l,g,t,re,G]),C=Va(()=>v.filter(y=>y.balance?.gt(0)),[v]),b=Va(()=>t?[...re&&C.length?[C]:[],l,g]:[...re&&C.length?[C]:[],g],[t,re,C,l,g]);return E?Bt(rf,{children:[Bt("div",{className:"flex justify-between",children:[xe("div",{className:"text-base/4 mb-4",children:"Import token"}),xe("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:()=>o(!1),children:xe(at,{})})]}),Bt("div",{className:"flex flex-col h-full gap-2",children:[I&&Bt("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:[xe(Ga,{tokenName:I.name,className:"w-9 h-9 text-[15px]"}),Bt("div",{className:"flex justify-between items-center gap-1 overflow-hidden grow",children:[xe("div",{className:"overflow-hidden whitespace-nowrap text-ellipsis text-sm font-medium",children:I.name}),xe("div",{className:"token-picker__all__symbol",children:I.symbol})]}),Bt("div",{className:"text-sm flex items-center",children:[Ku(d.toLowerCase()),xe("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:xe(h1,{className:"w-5 h-5"})})]})]}),xe("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"}),Bt("div",{className:"bg-t_bg_secondary border border-solid border-t_text_primary border-opacity-10 rounded-xl p-2",children:[xe("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."}),Bt("button",{type:"button",onClick:()=>w(y=>!y),className:"flex items-center",children:[xe("div",{className:"flex justify-center items-center p-1 w-6 h-6 border-2 border-white rounded-md mr-2",children:h&&xe($3,{icon:j3,className:"w-4 h-4"})}),xe("div",{className:"font-bold",children:"Accept"})]})]}),xe("div",{className:"flex grow items-end justify-center",children:xe(hr,{type:"button",disabled:!h,className:`token-picker__import-button w-full ${h?"":"!cursor-not-allowed"}`,onClick:ne,children:"Import"})})]})]}):Bt(rf,{children:[Bt("div",{className:"flex justify-between",children:[xe("div",{className:"text-base/4 text-t_text_primary mb-4",children:`Pick ${f} token`}),xe("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:()=>o(!1),children:xe(at,{})})]}),xe(bs,{ref:F,inputIcon:xe("div",{className:"fill-t_text_primary",children:xe(as,{})}),placeholder:"Search name or paste address",value:d,handleChange:p}),xe("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=>xe(jp,{token:y,selectedTokenAddress:n,onClick:()=>{a(y),o(!1)}},y.address))}),xe("div",{className:"flex flex-col mx-0 h-full",children:A?xe("div",{className:"flex justify-center w-full py-4 px-0",children:xe(Gr,{className:"w-9 h-9"})}):xe(rf,{children:I?Bt("div",{className:"token-picker-container hover:cursor-default",children:[xe(Rn,{token:I,chain:t,tokenLogoClassName:"w-9 h-9",generatedLogoClassName:"w-9 h-9 text-[16px]",chainLogoClassName:"w-5"}),Bt("div",{className:"flex justify-between items-center gap-1 overflow-hidden grow",children:[Bt("div",{children:[xe("div",{className:"text-sm font-medium text-ellipsis",children:I.name}),xe("div",{className:"text-xs text-t_text_primary !text-opacity-50 font-medium",children:t?.displayName})]}),xe("div",{className:"token-picker__all__symbol",children:I.symbol})]}),xe("div",{children:xe(hr,{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"})})]}):xe("div",{className:"flex flex-col h-full gap-8 w-[calc(100%+32px)] mx-[-16px]",children:xe(e6,{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=>Bt("div",{className:"py-1 bg-t_bg_primary text-t_text_primary",children:[xe("div",{className:"px-4 text-left",children:(()=>{if(t)switch(y){case 0:return re?C.length?"My tokens":`${t.displayName} network`:`${t.displayName} network`;case 1:return re?`${t.displayName} network`:"Other networks";case 2:return"Other networks";default:return"Undefined group"}else switch(y){case 0:return re&&C.length?"My tokens":"All networks";case 1:return"All networks";default:return"Undefined group"}})()}),xe("div",{className:"horizontal-separator"}),!b[y]?.length&&xe("div",{className:"text-center py-1",children:"No token found"})]}),itemContent:y=>v[y]&&xe($p,{token:v[y],selectedChainId:t?.chainId,selectedTokenAddress:n,onClick:()=>{a(v[y]),o(!1)}})})})})})]})};import{Fragment as n6,jsx as Ln,jsxs as vs}from"react/jsx-runtime";var nh=({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:_}=te(),I=za(()=>r==="destination"&&A,[r,A]),N=za(()=>r==="source"&&_,[r,_]),[L,M]=r6(!1),V=za(()=>r==="source"?a:f,[f,a,r]),F=za(()=>r==="destination"&&i,[i,r]),B=za(()=>r==="source"?o:d,[d,o,r]),J=Q=>{let G=w.find(re=>re.chainId===Q.chainId);r==="source"?(p(Q),h(G)):(E(Q),S(G)),M(!1)};return vs(n6,{children:[L&&Ln(qi,{onClose:()=>M(!1),className:"z-[3]",children:Ln(rh,{type:r,chain:t,tokens:V,otherTokens:B,selectedTokenAddress:e?.address,onSelect:J,isOpen:L,setModalOpen:M})}),Ln("button",{type:"button",disabled:F||I||N,onClick:()=>{M(!0)},className:`${n||""}`,children:vs("div",{className:"flex justify-between items-center p-4 gap-8 border-r border-solid border-t_text_primary border-opacity-10",children:[vs("div",{className:"flex gap-2 items-center",children:[Ln(Pn,{token:e,className:"w-9 h-9",generatedLogoClassName:"w-9 h-9 text-[16px]"}),vs("div",{className:"flex flex-col font-medium items-start",children:[Ln("p",{className:"text-xs opacity-60",children:"Token: "}),Ln("p",{className:`${e?"":"opacity-60"}`,children:e?e.symbol:r==="destination"&&i?"-":"Select"})]})]}),!F&&!I&&!N&&Ln("div",{className:"w-4 h-2 fill-t_text_primary",children:Ln(ri,{})})]})})]})};import{jsx as ws,jsxs as nf}from"react/jsx-runtime";var af=({type:t})=>{let{srcChain:e,srcToken:r,dstChain:n,dstToken:i}=te(),a=ih(()=>t==="source"?r:i,[t,r,i]),o=ih(()=>t==="source"?e:n,[t,e,n]);return nf("div",{className:"flex flex-col x-border rounded-xl bg-t_bg_tertiary bg-opacity-5",children:[nf("div",{className:"flex border-b border-solid border-t_text_primary border-opacity-10",children:[ws(nh,{chain:o,token:a,type:t,className:"w-full flex-grow"}),ws(Xp,{chain:o,type:t,className:"w-full max-w-[160px]"})]}),nf("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:[ws(zp,{type:t}),ws(Zp,{type:t})]})]})};import{jsx as Wa,jsxs as ah}from"react/jsx-runtime";var oh=()=>ah("div",{className:"flex flex-col gap-6 fill-t_text_primary",children:[ah("div",{className:"flex flex-col gap-[11px]",children:[Wa(af,{type:"source"}),Wa(Fp,{}),Wa(af,{type:"destination"})]}),Wa(ls,{}),Wa(Hp,{})]});import{jsx as Cs,jsxs as a6}from"react/jsx-runtime";var of=({onClose:t})=>{let{tab:e}=te(),r=i6(()=>e==="Settings"?Cs(Bp,{}):e==="History"?Cs(_p,{}):Cs(oh,{}),[e]);return a6("div",{className:"relative flex flex-col gap-4 p-2 text-t_text_primary bg-t_bg_primary rounded-2xl flex-1",children:[Cs(kp,{onClose:t}),r]})};import{forwardRef as o6}from"react";import{Fragment as s6,jsx as qa,jsxs as sh}from"react/jsx-runtime";var bs=o6((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 sh(s6,{children:[sh("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,qa("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&&qa("div",{className:"flex justify-between pt-[10px]",children:qa("div",{className:"px-5 text-t_text_red",children:p})}),h&&qa("div",{className:"flex justify-between pt-[10px]",children:qa("div",{className:"px-5 text-t_text_orange",children:h})})]})});import{useState as ch,useEffect as c6,useCallback as As}from"react";var ji=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)}},f6=({expiryTimestamp:t,onExpire:e,autoStart:r=!0})=>{let[n,i]=ch(r),[a,o]=ch(ji.getSecondsFromExpiry(t)),f=As(()=>{let w=ji.getSecondsFromExpiry(t);w<=0&&(e&&e(),i(!1)),o(w)},[t,e]);c6(()=>{if(!n)return;let w=setInterval(f,1e3);return()=>clearInterval(w)},[n,f]);let d=As(()=>i(!1),[]),p=As(()=>i(!0),[]),h=As(w=>{i(!0),o(ji.getSecondsFromExpiry(w))},[]);return{...ji.getTimeFromSeconds(a),isRunning:n,pause:d,resume:p,restart:h}},fh=f6;import{useEffect as d6,useState as l6}from"react";import{Fragment as sf,jsx as Ka,jsxs as u6}from"react/jsx-runtime";var dh=({expiryTimestamp:t,displayFormat:e=2,customTextOnExpire:r})=>{let[n,i]=l6(t.getTime()<Date.now()),{seconds:a,minutes:o,hours:f,days:d,restart:p}=fh({expiryTimestamp:t,onExpire:()=>i(!0)});return d6(()=>{p(t)},[t]),Ka(sf,{children:n&&r?Ka(sf,{children:r}):u6(sf,{children:[e===0&&Ka("span",{children:`${(d*24+f)*60+o}:${a.toString().padStart(2,"0")}`}),e===1&&Ka("span",{children:`${d*24+f}:${o.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`}),e===2&&Ka("span",{children:`${d}:${f.toString().padStart(2,"0")}:${o.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`})]})})};import{useState as h6}from"react";import{jsx as p6}from"react/jsx-runtime";var Ga=({tokenName:t,className:e})=>p6("div",{className:`rounded-full bg-white shadow-sm flex items-center justify-center text-black ${e}`,children:t.substring(0,1)});import{jsx as cf}from"react/jsx-runtime";var Pn=({token:t,className:e,generatedLogoClassName:r})=>{let[n,i]=h6(!1);return t?n?cf(Ga,{tokenName:t.name,className:r}):t?.image?cf("img",{src:t.image,alt:t.name,className:`border border-solid border-t_text_primary border-opacity-10 rounded-2xl ${e}`,onError:()=>i(!0)}):cf(Ga,{tokenName:t.name,className:r}):null};import{jsx as lh,jsxs as x6}from"react/jsx-runtime";var Rn=({token:t,chain:e,tokenLogoClassName:r,generatedLogoClassName:n,chainLogoClassName:i})=>x6("div",{className:"relative flex items-end pr-1 pb-1",children:[lh(Pn,{token:t,className:r,generatedLogoClassName:n}),e&&lh("img",{src:e.image,alt:e.name,className:`absolute bottom-0 right-0 border border-solid border-t_bg_secondary rounded-3xl ${i}`})]});import{QueryClient as v6,QueryClientProvider as w6}from"@tanstack/react-query";import{useEffect as Ss,useMemo as ph}from"react";import{ErrorBoundary as C6}from"react-error-boundary";import{useReconnect as A6,WagmiProvider as T6}from"wagmi";function m6(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 b6={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"},g6={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"},y6={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 uh(t,e){let n={...t?{...b6}:{...g6},...e};for(let[i,a]of Object.entries(n)){let o=y6[i];o&&m6(o,a)}}import{Fragment as xh,jsx as St,jsxs as Ts}from"react/jsx-runtime";var S6=new v6,E6=()=>{let{reconnect:t}=A6();return Ss(()=>{let e=0,r=setInterval(()=>{t(),e++,e>=5&&clearInterval(r)},1e3);return()=>{clearInterval(r)}},[t]),St(xh,{})},k6=({onPendingTransactionsChange:t})=>{let{history:e}=Gi(),r=ph(()=>e.filter(n=>n.status==="IN_PROGRESS"),[e]);return Ss(()=>{t?t(r):window.xPayOnPendingTransactionsChange&&window.xPayOnPendingTransactionsChange(r)},[t,r]),St(xh,{})},ff=({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:re,integratorFee:q,integratorFeeReceiverAddress:ne})=>{let T=l=>{l.stopPropagation(),l.nativeEvent.stopImmediatePropagation(),l.target===l.currentTarget&&w&&h()},s=ph(()=>op(d),[d]);return Ss(()=>{uh(E,A)},[E,A]),Ss(()=>{re?.apiUrl&&es(re?.apiUrl)},[re?.apiUrl]),St(C6,{FallbackComponent:()=>St("div",{children:"Something went wrong, please contact XSwap."}),children:St(T6,{config:s,children:Ts(w6,{client:S6,children:[St(E6,{}),Ts(z1,{children:[St(k6,{onPendingTransactionsChange:_}),St(Q1,{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:ne},supportedChains:d,wagmiConfig:s,overlay:w,children:St(j1,{children:St(Cp,{children:w?St("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:Ts("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:[St(of,{onSubmit:p,onClose:h}),St(zc,{})]})}):Ts("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:[St(of,{onSubmit:()=>{},onClose:()=>{}}),St(zc,{})]})})})})]})]})})})},hh=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(dn===null)throw new Error("XPay was incorrectly initialized");return await Yu(),await new Promise(()=>{if(dn===null)throw new Error("XPay was incorrectly initialized");dn.render(St(ff,{integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,supportedChains:d,lightTheme:p,styles:w,onSubmit:()=>{dn&&dn.render("")},onClose:()=>{dn&&dn.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}`)}};import{faArrowRight as _6,faArrowUpRightFromSquare as M6,faHourglassHalf as I6}from"@fortawesome/free-solid-svg-icons";import{FontAwesomeIcon as uf}from"@fortawesome/react-fontawesome";import{format as P6}from"date-fns";import{useCallback as N6}from"react";import{jsx as df,jsxs as mh}from"react/jsx-runtime";var lf=({chain:t,token:e,amount:r})=>mh("div",{className:"flex gap-2",children:[df(Rn,{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"}),mh("div",{className:"flex flex-col text-[12px]",children:[df("div",{className:"text-t_text_primary text-nowrap",children:`${Number(r)<1e-4?"<0.0001":r} ${e?.symbol?e?.symbol:"unknown"}`}),df("div",{className:"text-xs text-t_text_primary text-opacity-50",children:t?.displayName})]})]});import{Fragment as R6,jsx as Vt,jsxs as oi}from"react/jsx-runtime";var Es=({transaction:t,supportedChains:e,srcToken:r,dstToken:n})=>{let a=N6(h=>P6(new Date(h*1e3),"d MMM yyyy HH:mm:ss"),[])(t.timestamp),o=ft({amount:t.amountWei,decimals:r?.decimals||18,precisionFractionalPlaces:4}),f=ft({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 oi("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:[oi("div",{className:"flex items-center gap-2 border-b border-solid border-t_text_primary border-opacity-10 pb-1",children:[Vt("div",{className:"text-xs text-t_text_primary text-opacity-50",children:a}),oi("div",{className:"flex grow justify-end items-center h-6",children:[t.status==="IN_PROGRESS"?oi("div",{className:"flex items-center grow justify-end text-xs",children:[Vt(uf,{icon:I6,className:"w-4 h-4 mr-1 text-t_text_orange"}),oi("div",{className:"text-xs text-t_text_orange min-w-[108px]",children:["In progress (",Vt(dh,{displayFormat:0,expiryTimestamp:new Date(t.estimatedDeliveryTimestamp),customTextOnExpire:"finalizing"}),")"]})]}):t.status==="DONE"?Vt("div",{className:"flex items-center grow justify-end text-xs",children:Vt("div",{className:" mr-1 text-t_text_green",children:"Done"})}):t.status==="REVERTED"?Vt("div",{className:"flex items-center grow justify-end text-xs",children:Vt("div",{className:"w-4 h-4 mr-1 text-t_text_red",children:"Reverted"})}):null,Vt("a",{href:`${t.messageId?`${Ui}${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:Vt(uf,{icon:M6,className:"w-[14px] h-[14px] text-t_text_primary"})})]})]}),Vt("div",{className:"flex flex-wrap gap-8",children:oi("div",{className:"flex items-center gap-2",children:[Vt(lf,{chain:d,token:r,amount:o}),t.tokenOutAddress&&oi(R6,{children:[Vt(uf,{icon:_6,className:"w-5 h-5 text-t_text_primary opacity-50 mx-1.5"}),Vt(lf,{chain:p,token:n,amount:f})]})]})})]})};import{jsx as B6}from"react/jsx-runtime";var Mp=({transaction:t})=>{let{supportedChains:e,findTokenDataByAddressAndChain:r}=te(),n=r(t.tokenAddress.toLowerCase(),t.sourceChainId),i=t.tokenOutAddress?r(t.tokenOutAddress?.toLowerCase(),t.targetChainId):void 0;return B6(Es,{transaction:t,supportedChains:e,srcToken:n,dstToken:i})};import{createPortal as F6}from"react-dom";import{jsx as bh}from"react/jsx-runtime";var Ap=({id:t,children:e,onCloseClick:r,type:n="waiting",className:i})=>F6(bh("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:bh("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})}),$n,t);import{useMemo as gh,useState as L6}from"react";import{Fragment as O6,jsx as Gt,jsxs as pf}from"react/jsx-runtime";var D6=({transaction:t,supportedChains:e,srcToken:r,dstToken:n})=>{let[i,a]=L6(!1),o=gh(()=>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=gh(()=>t?.status==="DONE"?"border border-solid border-t_success_dark":"border border-solid border-t_main_accent_dark",[t]);return pf("div",{className:"flex gap-2 items-end justify-end flex-wrap",onClick:()=>a(d=>!d),children:[i&&Gt(Es,{transaction:t,supportedChains:e,srcToken:r,dstToken:n}),Gt("div",{className:`text-t_text_primary rounded-xl h-14 w-20 mb-2 cursor-pointer ${o} ${f}`,children:pf("div",{className:"flex gap-2 items-center h-14 w-20 justify-center fill-t_text_primary",children:[Gt("div",{className:`${i?"rotate-180":""}`,children:Gt(s1,{})}),Gt("div",{className:"relative flex items-center justify-center w-9 h-9",children:t?.status==="DONE"?Gt("div",{className:"w-5 h-5 fill-t_success_dark",children:Gt(is,{})}):pf(O6,{children:[Gt("div",{className:"w-5 h-5",children:Gt(O1,{})}),Gt("div",{className:"absolute flex items-center justify-center top-0 left-0 right-0 bottom-0 text-t_text_primary",children:Gt(Gr,{className:"w-10 h-10"})})]})})]})})]})},si=[],yh=t=>{si.some(({transaction:e})=>e.hash===e.hash)||si.push(t)},vh=t=>{si=[...si.filter(r=>r.transaction.hash!==t)]},wh=t=>{si=si.map(e=>e.transaction.hash===t?{...e,transaction:{...e.transaction,status:"DONE"}}:e)},ks=()=>{let t=si.map(e=>Gt(D6,{...e},e.transaction.hash));if($o===null)throw new Error("XPay was incorrectly initialized");$o.render(Gt("div",{className:"fixed bottom-5 right-2 flex flex-col gap-3 pl-9 items-end w-full z-50",children:t}))};import U6 from"@r2wc/core";import Ch from"react";import{createRoot as H6}from"react-dom/client";var V6=(t,e,r)=>{let n=H6(t),i=Ch.createElement(e,r);return n.render(i),{root:n,ReactComponent:e}},G6=({root:t,ReactComponent:e},r)=>{let n=Ch.createElement(e,r);t.render(n)},z6=({root:t})=>{t.unmount()},Ah=(t,e={})=>U6(t,e,{mount:V6,update:G6,unmount:z6});import{useEffect as W6,useState as Th}from"react";import{Fragment as K6,jsx as _s,jsxs as J6}from"react/jsx-runtime";var q6=({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,re]=Th(!0),[q,ne]=Th([]);W6(()=>{(async()=>{re(!0),B?.apiUrl&&es(B.apiUrl);let s=(await ti()).filter(({web3Environment:l,bridgeSupported:g,swapSupported:v})=>l==="mainnet"&&(g||v));ne(s),re(!1)})()},[]);let T=(()=>{try{return typeof h=="string"?JSON.parse(h):h||void 0}catch(s){console.error("Error parsing styles:",s)}})();return J6(K6,{children:[_s("style",{children:Yo}),G?_s("div",{className:"min-h-[532px] w-full flex items-center justify-center",children:_s(Gr,{className:"w-10 h-10"})}):_s(ff,{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})]})},Ms=()=>{if(wt||typeof customElements>"u")return{};let t=Ah(q6,{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};import{isServer as X6}from"@tanstack/react-query";import{useEffect as Q6}from"react";import{jsx as Y6}from"react/jsx-runtime";var Z6=Ms();!X6&&typeof customElements<"u"&&(customElements.get("xpay-widget")||customElements.define("xpay-widget",Z6));var hf=({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})=>(Q6(()=>{window.xPayOnPendingTransactionsChange=w,window.xPayOnDstTokenChange=I,window.xPayOnDstChainChange=N,window.xPayOnSrcTokenChange=L,window.xPayOnSrcChainChange=M,window.xPayOnConnectWallet=V},[w,I,N,L,M,V]),Y6("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}));import j6 from"async-retry";var Sh=async(t,e)=>{let r=t.publicRpcUrls[0],n=new se.Contract(e.toLowerCase(),Ur,se.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 hp=async(t,e,r,n)=>{let i=await $6(t,e),a=(await ti()).filter(({web3Environment:J,swapSupported:Q})=>J==="mainnet"&&Q),o=i.logs?.find(J=>J.topics[0]===se.utils.id(Nu));if(!o)throw new Error(`No transaction event found for chain ${t} tx ${e}`);let f=o?.topics[1],p=new se.utils.Interface(Ru).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 Sh(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"};yh({transaction:L,supportedChains:a,dstToken:I,srcToken:S}),ks();let M=Rt[_]?.XSwapRouter;if(!M)throw new Error("Unknown destination XSwapRouter!");let V=new se.Contract(M,Fu,se.getDefaultProvider(a.find(J=>J.chainId===_)?.publicRpcUrls[0])),F={address:M,topics:[se.utils.id(Bu),f]},B=async()=>{wh(e),ks(),await new Promise(J=>setTimeout(()=>J(!0),Pu)),vh(e),ks()};vc({transferId:f}).then(J=>{J.status==="DONE"?B():(setTimeout(()=>vc({transferId:f}).then(Q=>{Q.status==="DONE"&&B()}),30*60*1e3),V.once(F,()=>B()))})},$6=async(t,e)=>{try{let r=(await ti()).find(i=>i.chainId===t),n=new se.providers.JsonRpcProvider(r?.publicRpcUrls[0]);return await j6(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 xf=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);e4(t,F,e,r,n,i),await hh({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})},e4=(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&&(!Hi(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&&(!Hi(a)||o.tokens.findIndex(({address:f})=>f.toLowerCase()===a.toLowerCase())===-1))throw new Error(`Provided token address ${a} on chain ${i} is invalid`)}};var t4=Ms();Zu();var r4={openTransactionModal:xf,TxWidget:hf,TxWidgetWC:t4},gF=r4;export{gf as ContractName,vn as Ecosystem,Rh as Environment,ci as TxStatus,hf as TxWidget,t4 as TxWidgetWC,ea as Web3Environment,yf as XSwapCallType,gF as default,xf as openTransactionModal};
|
|
92
92
|
/*! Bundled license information:
|
|
93
93
|
|
|
94
94
|
js-sha3/src/sha3.js:
|
package/package.json
CHANGED
|
@@ -236,21 +236,21 @@ export const TokenPicker = ({
|
|
|
236
236
|
// Create groups based on chain and wallet connection status
|
|
237
237
|
const groups = chain
|
|
238
238
|
? [
|
|
239
|
-
...(!!address && ownedFilteredTokens.length
|
|
239
|
+
...(!!address && ownedFilteredTokens.length
|
|
240
240
|
? [ownedFilteredTokens]
|
|
241
241
|
: []),
|
|
242
242
|
currentChainTokens,
|
|
243
243
|
otherChainTokens,
|
|
244
244
|
]
|
|
245
245
|
: [
|
|
246
|
-
...(!!address && ownedFilteredTokens.length
|
|
246
|
+
...(!!address && ownedFilteredTokens.length
|
|
247
247
|
? [ownedFilteredTokens]
|
|
248
248
|
: []),
|
|
249
249
|
[...currentChainTokens, ...otherChainTokens],
|
|
250
250
|
];
|
|
251
251
|
|
|
252
252
|
return groups.flat();
|
|
253
|
-
}, [filteredTokens, otherFilteredTokens, chain, address,
|
|
253
|
+
}, [filteredTokens, otherFilteredTokens, chain, address, tokenPrices]);
|
|
254
254
|
|
|
255
255
|
const ownedTokens = useMemo(
|
|
256
256
|
() => allTokens.filter((token) => token.balance?.gt(0)),
|
|
@@ -260,19 +260,15 @@ export const TokenPicker = ({
|
|
|
260
260
|
const tokenGroups = useMemo(() => {
|
|
261
261
|
return chain
|
|
262
262
|
? [
|
|
263
|
-
...(
|
|
264
|
-
? [ownedTokens]
|
|
265
|
-
: []),
|
|
263
|
+
...(!!address && ownedTokens.length ? [ownedTokens] : []),
|
|
266
264
|
filteredTokens,
|
|
267
265
|
otherFilteredTokens,
|
|
268
266
|
]
|
|
269
267
|
: [
|
|
270
|
-
...(
|
|
271
|
-
? [ownedTokens]
|
|
272
|
-
: []),
|
|
268
|
+
...(!!address && ownedTokens.length ? [ownedTokens] : []),
|
|
273
269
|
otherFilteredTokens,
|
|
274
270
|
];
|
|
275
|
-
}, [chain,
|
|
271
|
+
}, [chain, address, ownedTokens, filteredTokens, otherFilteredTokens]);
|
|
276
272
|
|
|
277
273
|
return showImportWarning ? (
|
|
278
274
|
<>
|
|
@@ -465,7 +461,7 @@ export const TokenPicker = ({
|
|
|
465
461
|
if (!address) {
|
|
466
462
|
return `${chain.displayName} network`;
|
|
467
463
|
}
|
|
468
|
-
return ownedTokens.length
|
|
464
|
+
return ownedTokens.length
|
|
469
465
|
? "My tokens"
|
|
470
466
|
: `${chain.displayName} network`;
|
|
471
467
|
}
|
|
@@ -489,7 +485,7 @@ export const TokenPicker = ({
|
|
|
489
485
|
if (!address) {
|
|
490
486
|
return "All networks";
|
|
491
487
|
}
|
|
492
|
-
return ownedTokens.length
|
|
488
|
+
return ownedTokens.length
|
|
493
489
|
? "My tokens"
|
|
494
490
|
: "All networks";
|
|
495
491
|
}
|