@xswap-link/sdk 0.9.3 → 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs
CHANGED
|
@@ -88,7 +88,7 @@ nuik2Z3UwnCBNAiE2pBa3qQbD26+YBAnrbNmr4xK8wpDThAKwhdiuoIjum4saQg0VdFRVSxiR01e
|
|
|
88
88
|
+tHaDt+BgfDlGm2DttBa4/DGMuCH953whNoGi6isW570Vx/IE8K2bFvZCKFspI1QCiFtbGWDUgih
|
|
89
89
|
EEYyDQde+0pTfR+Wmen0BJLu0r6ONsMwNA4n0jC0MEyNMBVG+JhcW37DNCMzk6fe0P6/6ZaOfwAl
|
|
90
90
|
LqsAAAAldEVYdGRhdGU6Y3JlYXRlADIwMjQtMDUtMjdUMTE6NTQ6MjkrMDA6MDCo6mafAAAAJXRF
|
|
91
|
-
WHRkYXRlOm1vZGlmeQAyMDI0LTA1LTI3VDExOjU0OjI5KzAwOjAw2bfeIwAAAABJRU5ErkJggg==`})});import A3 from"bignumber.js";import{useSnackbar as T3}from"notistack";import{createContext as S3,useCallback as ss,useContext as E3,useEffect as Sc,useMemo as k3,useState as q1}from"react";import{useAccount as _3}from"wagmi";import{jsx as qi,jsxs as M3}from"react/jsx-runtime";var W1=S3({}),K1="pending_transactions",Ec=()=>vt?{}:JSON.parse(localStorage.getItem(K1)||"{}"),kc=t=>{vt||localStorage.setItem(K1,JSON.stringify(t))},X1=({children:t})=>{let{address:e}=_3(),[r,n]=q1([]),[i,a]=q1(!1),{enqueueSnackbar:o,closeSnackbar:f}=T3(),{debounce:d}=o1({delayMs:600});Sc(()=>{vt||localStorage.removeItem("transactions-history")},[]);let p=ss(async()=>{try{if(!e)return;let C=await rs({walletAddress:e}),k=[];for(let N of C.history){if(!N.source)continue;let U;N.failed&&(U="REVERTED"),N.target?U="DONE":U="IN_PROGRESS";let O=new Date(N.source?.blockTime).getTime(),R=jo;if(new A3(N.source.valueForInstantCcipRecieve||"0").gt(0))R=O+30*1e3;else{let W=O+Qo?.[N.source.blockchainId]?.[N.source.targetBlockchainId];W&&(R=W)}k.push({messageId:N.messageId,hash:N.source.transactionHash,timestamp:O/1e3,sourceChainId:N.source.blockchainId,targetChainId:N.source.targetBlockchainId,amountWei:N.source.tokenAmount,tokenAddress:N.source.tokenAddress,tokenOutAddress:N.target?.tokenAddress||N.source.tokenOutAddress,tokenOutAmount:N.target?.tokenAmount||N.source.estimatedAmountOut,estimatedDeliveryTimestamp:R,status:U})}let M={};for(let N of k)M[N.hash]=N;let I=Ec(),F={};for(let[N,U]of Object.entries(I)){if(N.toLowerCase().toLowerCase()!==e.toLowerCase())continue;let O=[];for(let R of U){if(!M[R.hash]){k.push(R),O.push(R);continue}M[R.hash]&&R.status==="DONE"&&M[R.hash]?.status==="IN_PROGRESS"&&(M[R.hash].status="DONE"),M[R.hash].status==="DONE"||M[R.hash].status}F[N.toLowerCase()]=O}kc(F),n(k.sort((N,U)=>U.timestamp-N.timestamp))}catch(C){console.error(C),o(qi(kn,{message:{text:"Failed to fetch history!",variant:"error"}}),{persist:!1})}finally{a(!0)}},[e,rs,o]);Sc(()=>{i||d(p);let C=setInterval(()=>{d(p)},6e4);return()=>clearInterval(C)},[e,p,rs,d,i]);let h=ss((C,k)=>{n(M=>{let I=M.filter(N=>N.hash!==C.hash),F=Ec();return kc({...F,[k]:[C,...I]}),[C,...I]})},[]),v=ss(C=>{o(qi(kn,{message:{text:"Destination chain transaction mined successfully!",variant:"success",action:()=>M3("div",{className:"flex items-center flex-nowrap",children:[qi(ur,{type:"button",onClick:()=>{window.open(`${Vi}${C}`)},children:"View"}),qi("div",{className:"transaction-provider__close fill-white leading-[0px]",onClick:()=>f(C),children:qi(ot,{})})]})}}),{persist:!1,key:C})},[o]),E=ss((C,k)=>{n(M=>{let I=M.map(N=>N.hash===C.hash&&N.status!=="DONE"?C:N),F=Ec();switch(kc({...F,[k]:[...I]}),C.status){case"DONE":{v(C.hash);break}case"REVERTED":break}return[...I]})},[v]);Sc(()=>{a(!1),n([])},[e]);let S=k3(()=>({history:r,addTransactionToLocalHistory:h,updateTransactionInLocalHistory:E,historyLoadedOnce:i}),[r,h,E,i]);return qi(W1.Provider,{value:S,children:t})};function _n(){return E3(W1)}var J1=({supportedChains:t})=>{let e=t.find(r=>r.chainId===Gi)||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===Yo)||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},I3=({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())},_c=t=>t.swapSupported,Mc=({sourceChain:t,targetChain:e})=>{if(!t)throw new Error("isSwapTargetChainValid > sourceChain should be defined.");return e.swapSupported&&!t.disabledForDestination?.includes(e.chainId)},Ic=t=>!t||t.bridgeSupported,Pc=({sourceChain:t,targetChain:e,sourceToken:r})=>{let n=!0,i=!1;return r&&e&&(n=!!e.tokens.find(a=>a.tokenId===r.tokenId)),t&&e&&(i=t.chainId===e.chainId),n&&!i},P3=({source:t,target:e,supportedChains:r})=>{let n=t.chain||J1({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(!_c(n)&&(n=J1({supportedChains:r}),a=void 0,!_c(n)&&(console.error("[WRONG CONFIG] default swap source chain is invalid."),n=r.find(f=>_c(f)),!n)))throw new Error("mapToValidSwap > None of the chains supports swap. Couldn't set source chain.");if(!Mc({sourceChain:n,targetChain:i})&&(i=Q1({supportedChains:r}),o=void 0,!Mc({sourceChain:n,targetChain:i})&&(console.error("[WRONG CONFIG] default swap target chain is invalid."),i=r.find(f=>Mc({sourceChain:n,targetChain:f})),!i)))throw new Error("mapToValidSwap > None of the chains supports swap. Couldn't set target chain.");return 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}}},N3=({source:t,target:e,supportedChains:r,bridgeTokensDictionary:n})=>{let i=t.chain,a=e.chain,o=t.token,f=e.token;if(!Ic(i)&&(i=void 0,o=void 0,!Ic(i)&&(console.error("[WRONG CONFIG] default bridge source chain is invalid."),i=r.find(d=>Ic(d)),!i)))throw new Error("mapToValidSwap > None of the chains supports bridge. Couldn't set source chain.");if(!Pc({sourceChain:i,targetChain:a,sourceToken:o})&&(a=void 0,f=void 0,!Pc({sourceChain:i,targetChain:a,sourceToken:o})&&(console.error("[WRONG CONFIG] default bridge target chain is invalid."),a=r.find(d=>Pc({sourceChain:i,targetChain:d,sourceToken:o})),!a)))throw new Error("mapToValidSwap > None of the chains supports bridge. Couldn't set target chain.");if(o&&i&&(Object.keys(n[i.chainId]?.[o.address.toLowerCase()]||{}).length>0||(o=void 0)),!o){let d=I3({chain:i,bridgeTokensDictionary:n});d&&i&&a?!!n[i.chainId]?.[d.address.toLowerCase()]?.[a.chainId]?o=d:(console.error("[WRONG CONFIG] default bridge source token is invalid."),o=void 0):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||(a=void 0),{source:{chain:i,token:o},target:{chain:a,token:f}}},Nc=({type:t,...e})=>t==="SWAP"?P3(e):N3(e);import{jsx as D3}from"react/jsx-runtime";var xt=()=>{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:"",lastTx:void 0,expressDelivery:!0,infiniteApproval:!0,slippage:"1.5",route:void 0,isAsyncDataLoaded:!1,srcTokenBalanceWei:"",srcTokenBalanceInfo:"-",isFetchingBalance:!1,isFetchingRoute:!1,isExpressDeliveryActive:!0,setTab:xt,setError:xt,setSrcChain:xt,setDstChain:xt,setSrcToken:xt,setDstToken:xt,setSrcValue:xt,setLastTxHash:xt,setExpressDelivery:xt,setInfiniteApproval:xt,setSlippage:xt,setRoute:xt,setSrcTokenBalanceWei:xt,quoteRoute:xt,refreshBalance:xt,findTokenDataByAddressAndChain:xt,bridgeTokensDictionary:null,onConnectWallet:xt,hasOnConnectWalletCallback:!1},Z1=B3(nt),Y1=({children:t,integrationConfig:e,supportedChains:r,wagmiConfig:n,overlay:i})=>{let{address:a,chainId:o}=L3(),[f,d]=tt(nt.tab),[p,h]=tt(nt.error),[v,E]=tt(nt.expressDelivery),[S,C]=tt(nt.infiniteApproval),k=dt(()=>!!e?.srcTokenLocked,[e?.srcTokenLocked]),M=dt(()=>!!e?.dstTokenLocked,[e?.dstTokenLocked]),I=dt(()=>!!e?.srcChainLocked,[e?.srcChainLocked]),F=dt(()=>!!e?.dstChainLocked,[e?.dstChainLocked]),N=dt(()=>!!e.bridge,[e.bridge]),[U,O]=tt(nt.slippage),[R,W]=tt(nt.srcChain),[z,Y]=tt(nt.dstChain),[re,$]=tt(nt.feeToken),[Q,T]=tt(nt.srcToken),[s,l]=tt(nt.dstToken),[g,w]=tt(nt.srcValue),[A,b]=tt(nt.isFetchingBalance),[y,m]=tt(nt.srcTokenBalanceWei),[c,x]=tt(nt.isFetchingRoute),[B,u]=tt(nt.route),[_,P]=tt(""),[D,V]=tt(nt.srcChainTokensOptions),[ee,Z]=tt(nt.dstChainTokensOptions),[X,qe]=tt(nt.tokenPrices),[j,ae]=tt(nt.srcChainOtherTokensOptions),[Or,Ne]=tt(nt.dstChainOtherTokensOptions),Ce=Rc(null),xr=Rc(0),Re=Rc(crypto.randomUUID()),{history:Be}=_n();Nt(()=>{if(r.length>0){let K=r.map(de=>de.chainId);t1({chainId:K}).then(de=>{qe(de)})}},[r]);let Gt=dt(()=>{let K=vt?{}:JSON.parse(localStorage.getItem("custom-tokens")||"{}"),de={};return r.forEach(oe=>{de[oe.chainId]={},oe.tokens.forEach(se=>{de[oe.chainId][se.address]=se})}),xc(de,K)},[r]),ke=dt(()=>{let K={};return Object.entries(Gt).forEach(([de,oe])=>{K[de]=Object.entries(oe).filter(([,se])=>se.supported).sort(([,se],[,Ye])=>Ye.priority-se.priority).map(([,se])=>({chainId:de,...se}))}),K},[Gt]),[Fe,Ur]=tt([]);Nt(()=>{(async()=>{let K=await n1();Ur(K)})()},[]);let me=dt(()=>{let K={};for(let de of Fe){let[oe,se]=Object.entries(de)[0],[Ye,pe]=Object.entries(de)[1];K[oe]||(K[oe]={}),K[oe][se]||(K[oe][se]={}),K[oe][se][Ye]=pe,K[Ye]||(K[Ye]={}),K[Ye][pe]||(K[Ye][pe]={}),K[Ye][pe][oe]=se}return Object.keys(K).length?K:null},[Fe]),Ae=Ba(K=>K?me&&N?ke[K]?ke[K].filter(de=>Object.keys(me[K]||{}).includes(de.address)):[]:ke[K]||[]:[],[me,N,ke]),Hr=dt(()=>{if(!Q||!y||!a)return"";if(Ot(y).eq(0))return"0";let K=ft({amount:y,decimals:Q.decimals,precisionFractionalPlaces:Q.decimals});return new R3(K).lt("0.00001")?"<0.00001":ft({amount:y,decimals:Q.decimals,precisionFractionalPlaces:5})},[Q,y]),Oe=dt(()=>Be?.find(({hash:K})=>K===_),[Be,_]),Te=dt(()=>$o({amount:g,decimals:Q?.decimals||18}),[Q?.decimals,g]),Gr=dt(()=>Q&&R&&X&&X[R.chainId]&&X[R.chainId]?.[Q.address]?(Number(g)*Number(X[R.chainId]?.[Q.address])).toFixed(2):null,[X,Q,g,R]),Se=dt(()=>ft({amount:B?.estAmountOut||"0",decimals:s?.decimals||18,precisionFractionalPlaces:Math.min(8,s?.decimals||18)}),[B]),Ue=dt(()=>$o({amount:Se,decimals:s?.decimals||18}),[s?.decimals,Se]),Vr=dt(()=>s&&z&&X&&X[z?.chainId]&&X[z?.chainId]?.[s.address]?(Number(Se)*Number(X[z?.chainId]?.[s.address])).toFixed(2):null,[X,s,Se,z]),He=dt(()=>ft({amount:B?.minAmountOut||"0",decimals:s?.decimals||18,precisionFractionalPlaces:Math.min(4,s?.decimals||18)}),[B]),Le=dt(()=>v&&!!B&&J.from(B.xSwapFees?.expressDeliveryFee||"0").gt("0"),[v,B]),zr=dt(()=>r.length>0,[r]),Me=Ba(async()=>{if(!R||!z||!Q||!s||!Te||Ot(Te).eq(0)){u(void 0);return}try{h(""),x(!0),Ce.current&&Ce.current.abort(uc),Ce.current=new AbortController;let K=await gc({integratorId:e.integratorId,fromChain:R.chainId,toChain:z.chainId,fromAddress:a||_t[R.chainId]?.FeeCollector||"",toAddress:a||_t[z.chainId]?.FeeCollector||"",fromToken:Q.address,toToken:s.address,fromAmount:Te,slippage:Number(U),customContractCalls:e.customContractCalls,paymentToken:rr.AddressZero,expressDelivery:v,infiniteApproval:S},Ce.current.signal);u(K),x(!1),Ce.current=null}catch(K){K!==uc&&(console.error(K),h("Could not find route!"),u(void 0))}},[a,z,s,gc,Le,U,R,Q,Te]);Nt(()=>{Me()},[Me]),Nt(()=>{(async()=>{let K=Ae(R?.chainId).filter(({symbol:ce})=>z?.chainId===R?.chainId?ce!==s?.symbol:!0);V(K);let de=Ae(z?.chainId).filter(({symbol:ce})=>z?.chainId===R?.chainId?ce!==Q?.symbol:!0);Z(de);let oe=[],se=r.filter(({chainId:ce,web3Environment:it,swapSupported:he,bridgeSupported:ie})=>ce===R?.chainId||it!=="mainnet"?!1:N?ie:he);for(let{chainId:ce}of se)oe.push(...Ae(ce).filter(({symbol:it})=>ce===z?.chainId?it!==s?.symbol:!0));ae(oe);let Ye=[],pe=r.filter(({chainId:ce,web3Environment:it,swapSupported:he})=>ce!==z?.chainId&&it==="mainnet"&&he);for(let{chainId:ce}of pe)Ye.push(...Ae(ce).filter(({symbol:it})=>ce===R?.chainId?it!==Q?.symbol:!0));if(Ne(Ye),a){let ce=Date.now();xr.current=ce;let it=await r1({walletAddress:a}),he=ie=>ie.map(tr=>({...tr,balance:J.from(it[tr.chainId][tr.address]||0)}));xr.current===ce&&(V(he(K)),Z(he(de)),ae(he(oe)),Ne(he(Ye)))}})()},[N,R,z,a,Ae,r,Q?.symbol,s?.symbol]);let Ie=Ba(async()=>{if(!a||!R?.publicRpcUrls[0]||!Q)return;let K=crypto.randomUUID();Re.current=K,b(!0);let de=await hc(a,Q.address,R?.publicRpcUrls[0]);K===Re.current&&(m($o({amount:de,decimals:Q.decimals})),b(!1))},[a,R,Q]),qr=Ba((K,de)=>Gt[de]?.[K],[Gt]);Nt(()=>{Ie()},[Ie]),Nt(()=>{$(R?.tokens.find(({address:K})=>K.toLowerCase()===rr.AddressZero.toLowerCase()))},[R]);let[ve,Ge]=tt(!1);Nt(()=>{if(!o||!ve||e?.srcChainId)return;let K=r.find(({chainId:de})=>de===`${o}`);K&&W(K)},[o,ve,r,e?.srcChainId]),Nt(()=>{ve||(T(void 0),l(void 0),W(void 0),Y(void 0))},[N]),Nt(()=>{if(ve||!r||r.length===0||!me)return;let K=e.srcTokenAddr,de=e.dstTokenAddr;K&&!ne.utils.isAddress(K)&&(K=r.find(ie=>ie.chainId===e?.srcChainId)?.tokens.find(ie=>ie.tokenId===e?.srcTokenAddr)?.address?.toLowerCase()),de&&!ne.utils.isAddress(de)&&(de=r.find(ie=>ie.chainId===e?.dstChainId)?.tokens.find(ie=>ie.tokenId===e?.dstTokenAddr)?.address?.toLowerCase());let oe=R||e?.srcChainId||(o?`${o}`:void 0)||(N?void 0:Gi),se=r.find(({chainId:ie})=>ie===oe),Ye;se&&(Ye=se.tokens.find(({address:ie})=>ie.toLowerCase()===K?.toLowerCase()));let pe=N?void 0:r.find(({chainId:ie})=>ie===Yo);e.dstChainId&&(pe=r.find(({chainId:ie})=>ie===e.dstChainId));let ce;pe&&(ce=pe.tokens.find(({address:ie})=>ie.toLowerCase()===de));let{source:it,target:he}=Nc({source:{chain:se,token:Ye},target:{chain:pe,token:ce},type:N?"BRIDGE":"SWAP",supportedChains:r,bridgeTokensDictionary:me});W(it.chain),Y(he.chain),T(it.token),l(he.token),Ge(!0)},[e?.srcChainId,e?.srcTokenAddr,e?.dstChainId,e?.dstTokenAddr,r,N,o,ve,me]),Nt(()=>{if(!me||r.length===0||!ve)return;let{source:K,target:de}=Nc({source:{chain:R,token:Q},target:{chain:z,token:s},type:N?"BRIDGE":"SWAP",supportedChains:r,bridgeTokensDictionary:me});K.chain?.chainId!==R?.chainId&&W(K.chain),de.chain?.chainId!==z?.chainId&&Y(de.chain),K.token?.address!==Q?.address&&T(K.token),de.token?.address!==s?.address&&l(de.token)},[R,Q,z,s,N,r,me]),Nt(()=>{e.onDstChainChange?e.onDstChainChange(z?.chainId):window.xPayOnDstChainChange&&window.xPayOnDstChainChange(z?.chainId)},[e.onDstChainChange,z]),Nt(()=>{let K=s?{address:s.address.toLowerCase(),symbol:s.tokenId}:void 0;e.onDstTokenChange?e.onDstTokenChange(K):window.xPayOnDstTokenChange&&window.xPayOnDstTokenChange(K)},[e.onDstTokenChange,s]),Nt(()=>{e.onSrcChainChange?e.onSrcChainChange(R?.chainId):window.xPayOnSrcChainChange&&window.xPayOnSrcChainChange(R?.chainId)},[e.onSrcChainChange,R]),Nt(()=>{let K=Q?{address:Q.address.toLowerCase(),symbol:Q.tokenId}:void 0;e.onSrcTokenChange?e.onSrcTokenChange(K):window.xPayOnSrcTokenChange&&window.xPayOnSrcTokenChange(K)},[e.onSrcTokenChange,Q]);let Wr=Ba(()=>{e.onConnectWallet?e.onConnectWallet():window.xPayOnConnectWallet&&window.xPayOnConnectWallet()},[e]),Ve=dt(()=>!!(e.onConnectWallet||window.xPayOnConnectWallet),[e.onConnectWallet]);return D3(Z1.Provider,{value:{bridgeUI:N,integrationConfig:e,wagmiConfig:n,supportedChains:r,tab:f,setTab:d,overlay:i,error:p,setError:h,feeToken:re,srcChain:R,setSrcChain:W,srcChainTokensOptions:D,srcChainOtherTokensOptions:j,tokenPrices:X,dstChain:z,setDstChain:Y,dstChainTokensOptions:ee,dstChainOtherTokensOptions:Or,srcToken:Q,setSrcToken:T,dstToken:s,setDstToken:l,srcValue:g,setSrcValue:w,srcValueWei:Te,srcValueUsd:Gr,dstValue:Se,dstValueWei:Ue,dstValueUsd:Vr,dstValueMin:He,lastTx:Oe,setLastTxHash:P,expressDelivery:v,setExpressDelivery:E,infiniteApproval:S,setInfiniteApproval:C,slippage:U,setSlippage:O,route:B,setRoute:u,isAsyncDataLoaded:zr,srcTokenBalanceWei:y,setSrcTokenBalanceWei:m,srcTokenBalanceInfo:Hr,isFetchingRoute:c,isFetchingBalance:A,isExpressDeliveryActive:Le,quoteRoute:Me,refreshBalance:Ie,findTokenDataByAddressAndChain:qr,srcTokenLocked:k,srcChainLocked:I,dstTokenLocked:M,dstChainLocked:F,bridgeTokensDictionary:me,onConnectWallet:Wr,hasOnConnectWalletCallback:Ve},children:t})},te=()=>F3(Z1);import{jsx as vk}from"react/jsx-runtime";var Mn={rank:0,setRank:()=>{throw new Error("GlobalDataState > setRank is not implemented")},xPower:"0",updateXPower:()=>{throw new Error("GlobalDataState > updateXPower is not implemented")},xSwapBalance:"0",updateXSwapBalance:()=>{throw new Error("GlobalDataState > updateXSwapBalance is not implemented")},unfinishedQuestsCount:0,setUnfinishedQuestsCount:()=>{throw new Error("GlobalDataState > setUnfinishedQuestsCount is not implemented")}},yk=O3({rank:Mn.rank,setRank:Mn.setRank,xPower:Mn.xPower,updateXPower:Mn.updateXPower,xSwapBalance:Mn.xSwapBalance,updateXSwapBalance:Mn.updateXSwapBalance,unfinishedQuestsCount:Mn.unfinishedQuestsCount,setUnfinishedQuestsCount:Mn.setUnfinishedQuestsCount});import{createContext as U3,useCallback as j1,useContext as H3,useMemo as G3}from"react";import{jsx as V3}from"react/jsx-runtime";var $1=U3({}),ep=({children:t})=>{let e=j1(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=j1(({executeTransaction:i,handlers:a,network:o="evm"})=>{let f=Date.now();return o==="evm"&&e({executeTransaction:i,handlers:a}),f},[e]),n=G3(()=>({enqueueTransaction:r}),[r]);return V3($1.Provider,{value:n,children:t})};function tp(){return H3($1)}import{useEffect as K3,useMemo as X3,useState as J3}from"react";import{useAccount as Q3}from"wagmi";import{useMemo as z3}from"react";import{useConnectorClient as q3}from"wagmi";function W3(t){let{account:e,transport:r}=t;return new Jo.Web3Provider(r,"any").getSigner(e.address)}async function rp({chainId:t}={}){let{data:e}=q3({chainId:t});return z3(()=>e?W3(e):void 0,[e])}var Z3=()=>{let[t,e]=J3(),r=rp();K3(()=>{r.then(a=>e(a))},[r]);let n=Q3();return{networks:{evm:X3(()=>({networkName:"EVM",chainId:n.chainId?.toString()||Gi,address:n.address,signer:t,provider:t?.provider}),[n.address,n.chainId,t])}}},Wi=Z3;import{useCallback as hp}from"react";import{useMemo as $3,useState as e5}from"react";import{jsx as Bc,jsxs as Y3}from"react/jsx-runtime";var np=()=>{let{isExpressDeliveryActive:t}=te();return Y3("div",{className:"flex items-center",children:[Bc("div",{className:`w-4 h-4 mr-1 ${t?"fill-t_success_light":"fill-t_text_primary opacity-50"} `,children:Bc(B1,{})}),Bc("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 Fc,jsxs as j3}from"react/jsx-runtime";var ip=({name:t,value:e})=>{let{isFetchingRoute:r}=te();return j3("div",{className:"flex gap-x-1 justify-between text-xs font-medium",children:[Fc("div",{className:"opacity-60",children:t}),Fc("div",{children:r?Fc(pr,{className:"w-[60px] h-full"}):e})]})};import{jsx as Lc}from"react/jsx-runtime";var ap=()=>{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 Lc("div",{className:"border-t border-solid border-t_text_primary border-opacity-10 pt-3 mt-3",children:Lc("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})=>Lc(ip,{name:o,value:f},o))})})};import{jsx as hr,jsxs as fs}from"react/jsx-runtime";var ds=()=>{let[t,e]=e5(!1),{route:r,feeToken:n,isFetchingRoute:i,srcChain:a,dstChain:o}=te(),f=$3(()=>{if(!r)return"0";let d=Ot(r.xSwapFees.ccipFee||"0").add(Ot(r.xSwapFees.xSwapFee.nativeFee||"0")).add(Ot(r.xSwapFees.expressDeliveryFee||"0")).toString();return ft({amount:d,decimals:n?.decimals||18,precisionFractionalPlaces:5})},[n?.decimals,r]);return hr("div",{className:"flex flex-col x-border rounded-xl py-2 px-4 bg-t_bg_tertiary bg-opacity-5",children:fs("button",{"aria-label":`${t?"Collapse":"Expand"} fees panel`,type:"button",onClick:()=>e(d=>!d),children:[fs("div",{className:"flex justify-between",children:[fs("div",{className:"flex gap-2 items-center text-xs font-medium sm:text-sm fill-t_text_primary",children:[hr(L1,{}),hr("p",{className:"opacity-60",children:"Fee: "}),i?hr(pr,{className:"w-[100px] h-full"}):hr("p",{children:`${f} ${n?.symbol||""}`})]}),fs("div",{className:"flex gap-2 items-center fill-t_text_primary",children:[r&&!i&&a?.chainId!==o?.chainId&&hr(np,{}),t?hr("div",{className:"w-4 h-2 rotate-180",children:hr(ii,{})}):hr("div",{className:"w-4 h-2",children:hr(ii,{})})]})]}),t&&hr(ap,{})]})})};import{jsx as ls}from"react/jsx-runtime";var op=()=>ls("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:ls("div",{className:"relative bg-gradient-to-r from-t_main_accent_light to-t_main_accent_dark w-8 h-8 rounded-xl",children:ls("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 fill-white",children:ls(is,{})})})});import*as t5 from"viem/chains";import{mainnet as sp}from"viem/chains";import{createConfig as r5,createStorage as n5,http as i5}from"@wagmi/core";import{injected as a5,walletConnect as o5,coinbaseWallet as s5}from"@wagmi/connectors";var c5=n5({key:"xpay.wagmi.store",storage:vt?void 0:localStorage}),cp=t=>{let e=f5(t),r=d5(e);return r5({chains:e,transports:r,connectors:[a5(),s5({appLogoUrl:"https://xswap.link/favicon.ico",appName:"XSwap"}),o5({projectId:"c392898b45ac587a280b5eb33e92aeb0",showQrModal:!0})],storage:c5})},f5=t=>{let e=[sp];return e.push(...Object.values(t5).filter(r=>r.id!==sp.id&&t.some(({chainId:n})=>n===r.id.toString()))),e},d5=t=>{let e={};return t.forEach(r=>{e[r.id]=i5()}),e};import{useEffect as l5,useState as fp}from"react";import{createPortal as u5}from"react-dom";import{jsx as h5}from"react/jsx-runtime";var p5={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"},Ki=({id:t,position:e,text:r,triggerRef:n})=>{let[i,a]=fp({top:0,left:0}),[o,f]=fp(!1);return l5(()=>{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)},v=()=>{f(!1)};return d&&(d.addEventListener("mouseenter",h),d.addEventListener("mouseleave",v)),window.addEventListener("scroll",p,!0),window.addEventListener("resize",p,!0),()=>{d&&(d.removeEventListener("mouseenter",h),d.removeEventListener("mouseleave",v)),window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p,!0)}},[n,e]),u5(o&&h5("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 ${p5[e]}`,style:{top:i.top,left:i.left},children:r}),ti,t)};import{useRef as x5}from"react";import{jsx as Fa,jsxs as dp}from"react/jsx-runtime";var lp=({onCloseClick:t})=>{let e=x5(null);return dp("div",{className:"flex justify-between items-center text-base font-medium",children:[Fa("div",{className:"text-t_text_primary",children:"Confirmation"}),dp("div",{className:"flex gap-4 items-center",children:[Fa(Ki,{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"}),Fa(ai,{ref:e,className:"cursor-help fill-t_main_accent_light w-[18px] h-[18px]"}),Fa("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:t,children:Fa(ot,{})})]})]})};import{useMemo as up}from"react";import{jsx as Ct,jsxs as Dc}from"react/jsx-runtime";var pp=()=>{let{txStatus:t,txNeedsApproval:e,txMsg:r}=Lr(),n=up(()=>[{icon:a=>Ct("div",{className:`${a}`,children:Ct(Ac,{})}),title:"sign approval transaction",state:t===1?"triggered":t>1?"completed":"none",show:r?t===1||t===2:e},{icon:a=>Ct("div",{className:`${a}`,children:Ct(Tc,{})}),title:"confirming approval transaction...",state:t===2?"triggered":t>2?"completed":"none",show:r?t===1||t===2:e},{icon:a=>Ct("div",{className:`${a}`,children:Ct(Ac,{})}),title:"sign transaction",state:t===3?"triggered":t>3?"completed":"none",show:r?t===3||t===4:!0},{icon:a=>Ct("div",{className:`${a}`,children:Ct(Tc,{})}),title:"confirming transaction...",state:t===4?"triggered":t>4?"completed":"none",show:r?t===3||t===4:!0}],[r,e,t]),i=up(()=>n.filter(({show:a})=>a),[n]);return Ct("div",{className:"flex flex-col gap-1",children:i.map(({icon:a,title:o,state:f},d)=>Dc("div",{className:"flex flex-col px-4 gap-1",children:[Dc("div",{className:"flex justify-between items-center",children:[Dc("div",{className:"flex items-center gap-2",children:[a(`${f==="triggered"?"fill-t_main_accent_light":"fill-t_text_primary opacity-50"}`),Ct("div",{className:`${f!=="triggered"?"opacity-50":f==="triggered"&&"text-t_text_secondary"}`,children:o})]}),Ct("div",{children:f==="completed"?Ct("div",{className:"fill-t_success_dark",children:Ct(as,{})}):f==="triggered"?Ct("div",{className:"animate-spin-slow fill-t_main_accent_light",children:Ct(O1,{})}):null})]}),d!==i.length-1&&Ct("div",{className:"vertical-separator py-3 ml-2"})]},o))})};import{useMemo as us}from"react";import{jsx as La,jsxs as Da}from"react/jsx-runtime";var Oc=({type:t})=>{let{srcToken:e,srcChain:r,dstToken:n,dstChain:i,srcValue:a,srcValueUsd:o,dstValue:f,dstValueUsd:d}=te(),p=us(()=>t==="source"?e:n,[n,e,t]),h=us(()=>t==="source"?r:i,[i,r,t]),v=us(()=>t==="source"?a:f,[f,a,t]),E=us(()=>t==="source"?o:d,[d,o,t]);return Da("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:[Da("div",{className:"flex flex-col",children:[La("div",{className:"opacity-60 text-sm mb-2",children:`You ${t==="source"?"pay":"receive"}`}),La("div",{className:`${t==="destination"&&"text-t_text_secondary"}`,children:v}),Da("div",{className:"opacity-60",children:["$",E]})]}),Da("div",{className:"flex items-center gap-3",children:[Da("div",{className:"flex flex-col text-right",children:[La("div",{children:p?.symbol}),La("div",{className:"opacity-60",children:h?.displayName})]}),La(In,{token:p,className:"w-9 h-9",generatedLogoClassName:"w-9 h-9"})]})]})};import{Fragment as m5,jsx as Pn,jsxs as Uc}from"react/jsx-runtime";var xp=({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:v,txMsg:E,enqueueTransaction:S,setTxNeedsApproval:C}=Lr(),{addTransactionToLocalHistory:k,updateTransactionInLocalHistory:M}=_n(),{networks:{evm:{signer:I}}}=Wi(),F=Ma(),N=hp(async O=>{if(!r||!i||!n||!a||!d)return;let R={hash:O.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+Qo?.[r?.chainId]?.[i?.chainId]||jo,status:"IN_PROGRESS"};if(r.chainId===i.chainId)R.estimatedDeliveryTimestamp=R.timestamp,R.status="DONE";else{let W="MessageSent(bytes32,uint64,address,bytes,address,uint256,uint256,address,uint256)",z="MessageReceived(bytes32,uint64,address,bytes,address,uint256)",Y="MessageSent(bytes32,uint64,address,address,address,address,uint256)",re="MessageReceived(bytes32,uint64,address,bytes)",$=ne.getDefaultProvider(e.find(T=>T.ecosystem==="evm"&&T.chainId===i.chainId)?.publicRpcUrls[0]),Q=async(T,s,l)=>{let g=O.logs?.find(w=>w.topics[0]===ne.utils.id(s));if(g){let w=g?.topics[1];R.messageId=w;let A=new ne.Contract(_t[i?.chainId]?.[T],T==="XSwapRouter"?qu:Wu,$),b={address:_t[i.chainId]?.[T],topics:[ne.utils.id(l),w]};(await A.queryFilter(b)).length>0?(R.status="DONE",M(R,O.from)):A.once(b,()=>{R.status="DONE",M(R,O.from)})}};await Q("XSwapRouter",W,z),await Q("CustomXSwapRouter",Y,re)}k(R,O.from)},[k,M,r,i,n,a,o,f,e,d]),U=hp(async()=>{if(n&&d){let O=()=>{S({executeTransaction:()=>{if(!(!d.transactions.swap||!I))return F.executeCalldata(I,d.transactions.swap)},txStatus:3,handlers:{onSuccess:R=>{v(5),p(),N(R),r?.chainId&&i?.chainId&&r?.chainId!==i?.chainId&&mp(r?.chainId,R.transactionHash,a?.address,f)}}})};n.address!==rr.AddressZero&&d.transactions.approve?(C(!0),S({executeTransaction:()=>{if(!(!d.transactions.approve||!I))return F.executeCalldata(I,d.transactions.approve)},txStatus:1,handlers:{onSuccess:()=>O()}})):(C(!1),O())}},[n,d,S,I,F,v,p,N,r?.chainId,i?.chainId,a?.address,f,C]);return Uc("div",{className:"flex flex-col text-t_text_primary gap-5",children:[Pn(lp,{onCloseClick:t}),E?Pn("div",{children:E}):Uc(m5,{children:[Uc("div",{className:"relative flex flex-col gap-5 fill-white",children:[Pn(Oc,{type:"source"}),Pn(op,{}),Pn(Oc,{type:"destination"})]}),Pn(ds,{})]}),h===0?Pn(ur,{variant:"filled-squared",onClick:()=>{U()},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"}):Pn(pp,{})]})};import{jsx as Hc,jsxs as bp}from"react/jsx-runtime";var Gc=({chain:t,token:e,value:r})=>bp("div",{className:"flex items-center gap-2",children:[Hc(Nn,{chain:t,token:e,chainLogoClassName:"w-5",tokenLogoClassName:"w-9 h-9",generatedLogoClassName:"w-9 h-9 text-[16px]"}),bp("div",{className:"flex flex-col w-min sm:w-auto",children:[Hc("div",{children:`${r} ${e?.symbol}`}),Hc("div",{className:"opacity-60",children:t?.displayName})]})]});import{Fragment as gp,jsx as mt,jsxs as Oa}from"react/jsx-runtime";var yp=({onCloseClick:t})=>{let{txError:e,txExplorerUrl:r,txMsg:n}=Lr(),{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?Oa(gp,{children:[mt("div",{className:"flex justify-end fill-t_text_primary cursor-pointer w-full",onClick:t,children:mt(ot,{className:"w-3.5 h-3.5"})}),mt(v1,{}),mt("div",{className:"text-2xl font-bold",children:"Transaction failed"}),mt("div",{className:"text-center",children:e})]}):Oa(gp,{children:[mt("div",{className:"flex justify-end fill-t_text_primary cursor-pointer w-full",onClick:t,children:mt(ot,{className:"w-3.5 h-3.5"})}),mt(P1,{}),Oa("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&&Oa("div",{className:"flex items-center gap-2",children:[mt(Gc,{chain:a,token:o,value:p}),mt("div",{className:"-rotate-90 flex justify-center w-8 fill-t_text_primary opacity-50",children:mt(is,{})}),mt(Gc,{chain:f,token:d,value:h})]}),Oa("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(S1,{})]})]})})};import{jsx as wp}from"react/jsx-runtime";var vp=({onCloseClick:t})=>{let{txStatus:e,txError:r}=Lr();return e===5||r?wp(yp,{onCloseClick:t}):wp(xp,{onCloseClick:t})};import{useSnackbar as b5}from"notistack";import{createContext as g5,useCallback as Ua,useContext as y5,useEffect as w5,useMemo as Vc,useRef as Cp,useState as fn}from"react";import{useAccount as v5}from"wagmi";import{jsx as er,jsxs as zc}from"react/jsx-runtime";var Ap=g5({}),Tp=({children:t})=>{let{chainId:e}=v5(),{enqueueTransaction:r}=tp(),{enqueueSnackbar:n,closeSnackbar:i}=b5(),[a,o]=fn("evm"),f=Cp(!1),[d,p]=fn(!1),[h,v]=fn(""),E=Cp(),[S,C]=fn(""),[k,M]=fn(""),[I,F]=fn(void 0),[N,U]=fn(!1),[O,R]=fn(!1),[W,z]=fn(0),{supportedChains:Y,setSrcValue:re}=te(),$=y=>{E.current===y&&(f.current=!1,p(!1))};w5(()=>{if(!d&&(S&&(n(er(kn,{message:{text:S,variant:"error"}})),C("")),N&&h)){let y=h;n(er(kn,{message:{text:`Transaction ${Xu(h)} is about to be mined!`,variant:"warning",action:()=>zc("div",{className:"flex items-center flex-nowrap",children:[er(ur,{type:"button",onClick:()=>{window.open(`${Y.find(m=>m.chainId===e?.toString()&&m.ecosystem===a)?.transactionExplorer}/${h}`||"")},children:"Check"}),er("div",{className:"fill-t_text_primary w-[14px] h-[14px] cursor-pointer p-[14px] leading-[0px]",onClick:()=>i(y),children:er(ot,{})})]}),animation:()=>er(Dr,{className:"w-4 h-4"})}}),{persist:!0,key:y}),v("")}},[N,a,h,S,n,i,e,d,Y]);let Q=Ua((y,m,c)=>{let x=`${m}/${y}`;if(c){let u=c.events?.find(_=>_.event==="MessageSent")?.args?.messageId;return u?`${Vi}${u}`:x}else return x},[]),T=Ua((y,m,c=!0)=>{let x={...m};return x.onConfirm=B=>{E.current===y&&(m?.onConfirm&&m?.onConfirm(B),v(B?.hash||""),z(u=>u+1))},x.onSuccess=B=>{if(i(B?.transactionHash),E.current===y){if(F(B),!f.current&&c){let u=`${h}-success`;n(er(kn,{message:{text:"Transaction mined successfully!",variant:"success",action:()=>zc("div",{className:"flex items-center flex-nowrap",children:[er(ur,{type:"button",onClick:()=>{window.open(Q(h,Y.find(_=>_.chainId===e?.toString()&&_.ecosystem===a)?.transactionExplorer||"",B))},children:"View"}),er("div",{className:"fill-t_text_primary w-[14px] h-[14px] cursor-pointer p-[14px] leading-[0px]",onClick:()=>i(u),children:er(ot,{})})]})}}),{persist:!1,key:u})}m?.onSuccess&&m?.onSuccess(B),C(""),U(!1)}},x.onError=B=>{E.current===y&&(C(Ju(B)),m?.onError?.(B),U(!1))},x},[i,h,n,Q,Y,e,a]),s=Ua(({executeTransaction:y,txStatus:m,txMsg:c="",handlers:x,network:B="evm",showDefaultSuccessMessage:u=!0})=>{let _=Date.now(),P=x;return B==="evm"&&(P=T(_,x,u)),r({executeTransaction:y,txStatus:m,handlers:P,network:B}),E.current=_,f.current=!0,v(""),C(""),M(c),z(m),F(void 0),U(!0),o(B),p(!0),_},[T,r]),l=Vc(()=>Q(h,Y.find(y=>y.chainId===e?.toString()&&y.ecosystem===a)?.transactionExplorer||"",I),[e,a,Q,Y,h,I]),g=Ua(y=>{p(y),f.current=y},[]),w=Vc(()=>S?"error":W===5?"success":"neutral",[S,W]),A=Vc(()=>({enqueueTransaction:s,closeTransactionModal:$,isTxModalOpen:d,setTxModalOpen:p,loading:N,txStatus:W,setTxStatus:z,txExplorerUrl:l,txHash:h,txError:S,txMsg:k,setTxMsg:M,setTxError:C,txNeedsApproval:O,setTxNeedsApproval:R}),[s,d,N,W,l,h,S,k,O]),b=Ua(()=>{C(""),re(""),g(!1)},[C,re,g]);return zc(Ap.Provider,{value:A,children:[d&&er(Sp,{id:"tx_modal",className:"max-w-x_modal",type:w,onCloseClick:b,children:er(vp,{onCloseClick:b})}),t]})};function Lr(){return y5(Ap)}import{jsx as Ep}from"react/jsx-runtime";var Xi=({className:t,children:e,onClose:r})=>{let{overlay:n}=te();return Ep("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.stopPropagation(),i.nativeEvent.stopImmediatePropagation(),i.preventDefault(),i.target===i.currentTarget&&n&&r()},children:Ep("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 oi,jsxs as ps}from"react/jsx-runtime";var qc=()=>ps("div",{className:"flex justify-center items-center gap-2 my-3",children:[oi("span",{className:"text-t_text_primary opacity-50",children:"Powered by"}),ps("div",{className:"flex items-center gap-1",children:[oi(G1,{}),oi("span",{className:"text-t_text_primary text-xl leading-none font-bold opacity-90",children:"Swap"})]}),oi("span",{className:"text-t_text_primary opacity-50",children:"\u2715"}),ps("div",{className:"flex items-center gap-1",children:[oi(p1,{}),ps("span",{className:"flex flex-col",children:[oi("span",{className:"text-t_text_primary text-xs leading-none",children:"Chainlink"}),oi("span",{className:"text-sm text-[#2C4FBC] font-bold leading-none ",children:"CCIP"})]})]})]});import{forwardRef as C5,useCallback as A5,useMemo as T5}from"react";import{jsx as S5}from"react/jsx-runtime";var Ha=C5(({value:t,onChange:e,id:r,placeholder:n,regex:i,className:a,disabled:o},f)=>{let d=T5(()=>t.length<2?2:t.length,[t]),p=A5(h=>{h.target.value!=="."&&i.test(h.target.value)&&e(h.target.value.replace(/,/g,"."))},[e,i,r]);return S5("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})});Ha.displayName="SafeInput";import{jsx as E5}from"react/jsx-runtime";var pr=({className:t})=>E5("div",{className:`bg-t_bg_tertiary bg-opacity-15 rounded animate-pulse ${t||""}`});import{jsx as Wc,jsxs as k5}from"react/jsx-runtime";var Dr=({className:t})=>Wc("div",{role:"status",className:t||"",children:k5("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 s6}from"react";import{Fragment as _5,jsx as dn,jsxs as M5}from"react/jsx-runtime";var kp=({onClose:t})=>{let{tab:e,setTab:r,overlay:n}=te();return dn("div",{className:"flex gap-5 items-center",children:e==="Swap"?M5(_5,{children:[dn("button",{type:"button",onClick:()=>r("Settings"),"aria-label":"Open settings",className:"fill-white",children:dn(_1,{})}),dn("button",{type:"button",onClick:()=>r("History"),"aria-label":"Open history",className:"fill-white",children:dn(A1,{})}),n&&dn("button",{type:"button",onClick:()=>t(),"aria-label":"Close",className:"fill-t_text_primary",children:dn(ot,{})})]}):dn("button",{type:"button",onClick:()=>{r("Swap")},"aria-label":"Switch to swap view",className:"fill-t_text_primary",children:dn(ot,{})})})};import{jsx as _p,jsxs as I5}from"react/jsx-runtime";var Mp=({onClose:t})=>{let{tab:e,bridgeUI:r}=te();return I5("div",{className:"flex justify-between",children:[_p("div",{className:"text-xl font-sans-bold font-bold",children:e==="Swap"&&r?"Bridge":e}),_p(kp,{onClose:t})]})};import{useMemo as P5}from"react";import{Virtuoso as N5}from"react-virtuoso";import{jsx as Ji}from"react/jsx-runtime";var Ip=()=>{let{history:t,historyLoadedOnce:e}=_n(),r=P5(()=>!t||t.length===0?e?Ji("div",{className:"text-center py-4 text-[#9e9e9e]",children:"Your history is empty"}):Ji("div",{className:"flex justify-center w-full py-4 fill-t_text_primary",children:Ji(Dr,{className:"w-8 h-8"})}):Ji(N5,{data:t,style:{height:"532px"},itemContent:(n,i)=>Ji(Pp,{transaction:i})}),[t,e]);return Ji("div",{className:"flex-1 overflow-hidden",children:r})};import{jsx as Kc,jsxs as R5}from"react/jsx-runtime";var Ga=({checked:t,onClick:e})=>Kc("div",{children:R5("span",{className:"inline-flex w-14 h-9 p-3 relative align-middle box-border overflow-hidden cursor-pointer",onClick:e,children:[Kc("span",{className:"h-full w-full rounded-lg bg-t_bg_tertiary bg-opacity-30"}),Kc("span",{className:`transition-all w-5 h-5 rounded-full absolute translate-y-[-4px]
|
|
91
|
+
WHRkYXRlOm1vZGlmeQAyMDI0LTA1LTI3VDExOjU0OjI5KzAwOjAw2bfeIwAAAABJRU5ErkJggg==`})});import A3 from"bignumber.js";import{useSnackbar as T3}from"notistack";import{createContext as S3,useCallback as ss,useContext as E3,useEffect as Sc,useMemo as k3,useState as q1}from"react";import{useAccount as _3}from"wagmi";import{jsx as qi,jsxs as M3}from"react/jsx-runtime";var W1=S3({}),K1="pending_transactions",Ec=()=>vt?{}:JSON.parse(localStorage.getItem(K1)||"{}"),kc=t=>{vt||localStorage.setItem(K1,JSON.stringify(t))},X1=({children:t})=>{let{address:e}=_3(),[r,n]=q1([]),[i,a]=q1(!1),{enqueueSnackbar:o,closeSnackbar:f}=T3(),{debounce:d}=o1({delayMs:600});Sc(()=>{vt||localStorage.removeItem("transactions-history")},[]);let p=ss(async()=>{try{if(!e)return;let C=await rs({walletAddress:e}),k=[];for(let N of C.history){if(!N.source)continue;let U;N.failed&&(U="REVERTED"),N.target?U="DONE":U="IN_PROGRESS";let O=new Date(N.source?.blockTime).getTime(),R=jo;if(new A3(N.source.valueForInstantCcipRecieve||"0").gt(0))R=O+30*1e3;else{let W=O+Qo?.[N.source.blockchainId]?.[N.source.targetBlockchainId];W&&(R=W)}k.push({messageId:N.messageId,hash:N.source.transactionHash,timestamp:O/1e3,sourceChainId:N.source.blockchainId,targetChainId:N.source.targetBlockchainId,amountWei:N.source.tokenAmount,tokenAddress:N.source.tokenAddress,tokenOutAddress:N.target?.tokenAddress||N.source.tokenOutAddress,tokenOutAmount:N.target?.tokenAmount||N.source.estimatedAmountOut,estimatedDeliveryTimestamp:R,status:U})}let M={};for(let N of k)M[N.hash]=N;let I=Ec(),F={};for(let[N,U]of Object.entries(I)){if(N.toLowerCase().toLowerCase()!==e.toLowerCase())continue;let O=[];for(let R of U){if(!M[R.hash]){k.push(R),O.push(R);continue}M[R.hash]&&R.status==="DONE"&&M[R.hash]?.status==="IN_PROGRESS"&&(M[R.hash].status="DONE"),M[R.hash].status==="DONE"||M[R.hash].status}F[N.toLowerCase()]=O}kc(F),n(k.sort((N,U)=>U.timestamp-N.timestamp))}catch(C){console.error(C),o(qi(kn,{message:{text:"Failed to fetch history!",variant:"error"}}),{persist:!1})}finally{a(!0)}},[e,rs,o]);Sc(()=>{i||d(p);let C=setInterval(()=>{d(p)},6e4);return()=>clearInterval(C)},[e,p,rs,d,i]);let h=ss((C,k)=>{n(M=>{let I=M.filter(N=>N.hash!==C.hash),F=Ec();return kc({...F,[k]:[C,...I]}),[C,...I]})},[]),v=ss(C=>{o(qi(kn,{message:{text:"Destination chain transaction mined successfully!",variant:"success",action:()=>M3("div",{className:"flex items-center flex-nowrap",children:[qi(ur,{type:"button",onClick:()=>{window.open(`${Vi}${C}`)},children:"View"}),qi("div",{className:"transaction-provider__close fill-white leading-[0px]",onClick:()=>f(C),children:qi(ot,{})})]})}}),{persist:!1,key:C})},[o]),E=ss((C,k)=>{n(M=>{let I=M.map(N=>N.hash===C.hash&&N.status!=="DONE"?C:N),F=Ec();switch(kc({...F,[k]:[...I]}),C.status){case"DONE":{v(C.hash);break}case"REVERTED":break}return[...I]})},[v]);Sc(()=>{a(!1),n([])},[e]);let S=k3(()=>({history:r,addTransactionToLocalHistory:h,updateTransactionInLocalHistory:E,historyLoadedOnce:i}),[r,h,E,i]);return qi(W1.Provider,{value:S,children:t})};function _n(){return E3(W1)}var J1=({supportedChains:t})=>{let e=t.find(r=>r.chainId===Gi)||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===Yo)||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},I3=({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())},_c=t=>t.swapSupported,Mc=({sourceChain:t,targetChain:e})=>{if(!t)throw new Error("isSwapTargetChainValid > sourceChain should be defined.");return e.swapSupported&&!t.disabledForDestination?.includes(e.chainId)},Ic=t=>!t||t.bridgeSupported,Pc=({sourceChain:t,targetChain:e,sourceToken:r})=>{let n=!0,i=!1;return r&&e&&(n=!!e.tokens.find(a=>a.tokenId===r.tokenId)),t&&e&&(i=t.chainId===e.chainId),n&&!i},P3=({source:t,target:e,supportedChains:r})=>{let n=t.chain||J1({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(!_c(n)&&(n=J1({supportedChains:r}),a=void 0,!_c(n)&&(console.error("[WRONG CONFIG] default swap source chain is invalid."),n=r.find(f=>_c(f)),!n)))throw new Error("mapToValidSwap > None of the chains supports swap. Couldn't set source chain.");if(!Mc({sourceChain:n,targetChain:i})&&(i=Q1({supportedChains:r}),o=void 0,!Mc({sourceChain:n,targetChain:i})&&(console.error("[WRONG CONFIG] default swap target chain is invalid."),i=r.find(f=>Mc({sourceChain:n,targetChain:f})),!i)))throw new Error("mapToValidSwap > None of the chains supports swap. Couldn't set target chain.");return 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}}},N3=({source:t,target:e,supportedChains:r,bridgeTokensDictionary:n})=>{let i=t.chain,a=e.chain,o=t.token,f=e.token;if(!Ic(i)&&(i=void 0,o=void 0,!Ic(i)&&(console.error("[WRONG CONFIG] default bridge source chain is invalid."),i=r.find(d=>Ic(d)),!i)))throw new Error("mapToValidSwap > None of the chains supports bridge. Couldn't set source chain.");if(!Pc({sourceChain:i,targetChain:a,sourceToken:o})&&(a=void 0,f=void 0,!Pc({sourceChain:i,targetChain:a,sourceToken:o})&&(console.error("[WRONG CONFIG] default bridge target chain is invalid."),a=r.find(d=>Pc({sourceChain:i,targetChain:d,sourceToken:o})),!a)))throw new Error("mapToValidSwap > None of the chains supports bridge. Couldn't set target chain.");if(o&&i&&(Object.keys(n[i.chainId]?.[o.address.toLowerCase()]||{}).length>0||(o=void 0)),!o){let d=I3({chain:i,bridgeTokensDictionary:n});d&&i&&a?!!n[i.chainId]?.[d.address.toLowerCase()]?.[a.chainId]?o=d:(console.error("[WRONG CONFIG] default bridge source token is invalid."),o=void 0):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||(a=void 0),{source:{chain:i,token:o},target:{chain:a,token:f}}},Nc=({type:t,...e})=>t==="SWAP"?P3(e):N3(e);import{jsx as D3}from"react/jsx-runtime";var xt=()=>{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:"",lastTx:void 0,expressDelivery:!0,infiniteApproval:!0,slippage:"1.5",route:void 0,isAsyncDataLoaded:!1,srcTokenBalanceWei:"",srcTokenBalanceInfo:"-",isFetchingBalance:!1,isFetchingRoute:!1,isExpressDeliveryActive:!0,setTab:xt,setError:xt,setSrcChain:xt,setDstChain:xt,setSrcToken:xt,setDstToken:xt,setSrcValue:xt,setLastTxHash:xt,setExpressDelivery:xt,setInfiniteApproval:xt,setSlippage:xt,setRoute:xt,setSrcTokenBalanceWei:xt,quoteRoute:xt,refreshBalance:xt,findTokenDataByAddressAndChain:xt,bridgeTokensDictionary:null,onConnectWallet:xt,hasOnConnectWalletCallback:!1},Z1=B3(nt),Y1=({children:t,integrationConfig:e,supportedChains:r,wagmiConfig:n,overlay:i})=>{let{address:a,chainId:o}=L3(),[f,d]=tt(nt.tab),[p,h]=tt(nt.error),[v,E]=tt(nt.expressDelivery),[S,C]=tt(nt.infiniteApproval),k=dt(()=>!!e?.srcTokenLocked,[e?.srcTokenLocked]),M=dt(()=>!!e?.dstTokenLocked,[e?.dstTokenLocked]),I=dt(()=>!!e?.srcChainLocked,[e?.srcChainLocked]),F=dt(()=>!!e?.dstChainLocked,[e?.dstChainLocked]),N=dt(()=>!!e.bridge,[e.bridge]),[U,O]=tt(nt.slippage),[R,W]=tt(nt.srcChain),[z,Y]=tt(nt.dstChain),[re,$]=tt(nt.feeToken),[Q,T]=tt(nt.srcToken),[s,l]=tt(nt.dstToken),[g,w]=tt(nt.srcValue),[A,b]=tt(nt.isFetchingBalance),[y,m]=tt(nt.srcTokenBalanceWei),[c,x]=tt(nt.isFetchingRoute),[B,u]=tt(nt.route),[_,P]=tt(""),[D,V]=tt(nt.srcChainTokensOptions),[ee,Z]=tt(nt.dstChainTokensOptions),[X,qe]=tt(nt.tokenPrices),[j,ae]=tt(nt.srcChainOtherTokensOptions),[Or,Ne]=tt(nt.dstChainOtherTokensOptions),Ce=Rc(null),xr=Rc(0),Re=Rc(crypto.randomUUID()),{history:Be}=_n();Nt(()=>{if(r.length>0){let K=r.map(de=>de.chainId);t1({chainId:K}).then(de=>{qe(de)})}},[r]);let Gt=dt(()=>{let K=vt?{}:JSON.parse(localStorage.getItem("custom-tokens")||"{}"),de={};return r.forEach(oe=>{de[oe.chainId]={},oe.tokens.forEach(se=>{de[oe.chainId][se.address]=se})}),xc(de,K)},[r]),ke=dt(()=>{let K={};return Object.entries(Gt).forEach(([de,oe])=>{K[de]=Object.entries(oe).filter(([,se])=>se.supported).sort(([,se],[,Ye])=>Ye.priority-se.priority).map(([,se])=>({chainId:de,...se}))}),K},[Gt]),[Fe,Ur]=tt([]);Nt(()=>{(async()=>{let K=await n1();Ur(K)})()},[]);let me=dt(()=>{let K={};for(let de of Fe){let[oe,se]=Object.entries(de)[0],[Ye,pe]=Object.entries(de)[1];K[oe]||(K[oe]={}),K[oe][se]||(K[oe][se]={}),K[oe][se][Ye]=pe,K[Ye]||(K[Ye]={}),K[Ye][pe]||(K[Ye][pe]={}),K[Ye][pe][oe]=se}return Object.keys(K).length?K:null},[Fe]),Ae=Ba(K=>K?me&&N?ke[K]?ke[K].filter(de=>Object.keys(me[K]||{}).includes(de.address)):[]:ke[K]||[]:[],[me,N,ke]),Hr=dt(()=>{if(!Q||!y||!a)return"";if(Ot(y).eq(0))return"0";let K=ft({amount:y,decimals:Q.decimals,precisionFractionalPlaces:Q.decimals});return new R3(K).lt("0.00001")?"<0.00001":ft({amount:y,decimals:Q.decimals,precisionFractionalPlaces:5})},[Q,y]),Oe=dt(()=>Be?.find(({hash:K})=>K===_),[Be,_]),Te=dt(()=>$o({amount:g,decimals:Q?.decimals||18}),[Q?.decimals,g]),Gr=dt(()=>Q&&R&&X&&X[R.chainId]&&X[R.chainId]?.[Q.address]?(Number(g)*Number(X[R.chainId]?.[Q.address])).toFixed(2):null,[X,Q,g,R]),Se=dt(()=>ft({amount:B?.estAmountOut||"0",decimals:s?.decimals||18,precisionFractionalPlaces:Math.min(8,s?.decimals||18)}),[B]),Ue=dt(()=>$o({amount:Se,decimals:s?.decimals||18}),[s?.decimals,Se]),Vr=dt(()=>s&&z&&X&&X[z?.chainId]&&X[z?.chainId]?.[s.address]?(Number(Se)*Number(X[z?.chainId]?.[s.address])).toFixed(2):null,[X,s,Se,z]),He=dt(()=>ft({amount:B?.minAmountOut||"0",decimals:s?.decimals||18,precisionFractionalPlaces:Math.min(4,s?.decimals||18)}),[B]),Le=dt(()=>v&&!!B&&J.from(B.xSwapFees?.expressDeliveryFee||"0").gt("0"),[v,B]),zr=dt(()=>r.length>0,[r]),Me=Ba(async()=>{if(!R||!z||!Q||!s||!Te||Ot(Te).eq(0)){u(void 0);return}try{h(""),x(!0),Ce.current&&Ce.current.abort(uc),Ce.current=new AbortController;let K=await gc({integratorId:e.integratorId,fromChain:R.chainId,toChain:z.chainId,fromAddress:a||_t[R.chainId]?.FeeCollector||"",toAddress:a||_t[z.chainId]?.FeeCollector||"",fromToken:Q.address,toToken:s.address,fromAmount:Te,slippage:Number(U),customContractCalls:e.customContractCalls,paymentToken:rr.AddressZero,expressDelivery:v,infiniteApproval:S},Ce.current.signal);u(K),x(!1),Ce.current=null}catch(K){K!==uc&&(console.error(K),h("Could not find route!"),u(void 0))}},[a,z,s,gc,Le,U,R,Q,Te]);Nt(()=>{Me()},[Me]),Nt(()=>{(async()=>{let K=Ae(R?.chainId).filter(({symbol:ce})=>z?.chainId===R?.chainId?ce!==s?.symbol:!0);V(K);let de=Ae(z?.chainId).filter(({symbol:ce})=>z?.chainId===R?.chainId?ce!==Q?.symbol:!0);Z(de);let oe=[],se=r.filter(({chainId:ce,web3Environment:it,swapSupported:he,bridgeSupported:ie})=>ce===R?.chainId||it!=="mainnet"?!1:N?ie:he);for(let{chainId:ce}of se)oe.push(...Ae(ce).filter(({symbol:it})=>ce===z?.chainId?it!==s?.symbol:!0));ae(oe);let Ye=[],pe=r.filter(({chainId:ce,web3Environment:it,swapSupported:he})=>ce!==z?.chainId&&it==="mainnet"&&he);for(let{chainId:ce}of pe)Ye.push(...Ae(ce).filter(({symbol:it})=>ce===R?.chainId?it!==Q?.symbol:!0));if(Ne(Ye),a){let ce=Date.now();xr.current=ce;let it=await r1({walletAddress:a}),he=ie=>ie.map(tr=>({...tr,balance:J.from(it[tr.chainId][tr.address]||0)}));xr.current===ce&&(V(he(K)),Z(he(de)),ae(he(oe)),Ne(he(Ye)))}})()},[N,R,z,a,Ae,r,Q?.symbol,s?.symbol]);let Ie=Ba(async()=>{if(!a||!R?.publicRpcUrls[0]||!Q)return;let K=crypto.randomUUID();Re.current=K,b(!0);let de=await hc(a,Q.address,R?.publicRpcUrls[0]);K===Re.current&&(m($o({amount:de,decimals:Q.decimals})),b(!1))},[a,R,Q]),qr=Ba((K,de)=>Gt[de]?.[K],[Gt]);Nt(()=>{Ie()},[Ie]),Nt(()=>{$(R?.tokens.find(({address:K})=>K.toLowerCase()===rr.AddressZero.toLowerCase()))},[R]);let[ve,Ge]=tt(!1);Nt(()=>{if(!o||!ve||e?.srcChainId)return;let K=r.find(({chainId:de})=>de===`${o}`);K&&W(K)},[o,ve,r,e?.srcChainId]),Nt(()=>{ve||(T(void 0),l(void 0),W(void 0),Y(void 0))},[N]),Nt(()=>{if(ve||!r||r.length===0||!me)return;let K=e.srcTokenAddr,de=e.dstTokenAddr;K&&!ne.utils.isAddress(K)&&(K=r.find(ie=>ie.chainId===e?.srcChainId)?.tokens.find(ie=>ie.tokenId===e?.srcTokenAddr)?.address?.toLowerCase()),de&&!ne.utils.isAddress(de)&&(de=r.find(ie=>ie.chainId===e?.dstChainId)?.tokens.find(ie=>ie.tokenId===e?.dstTokenAddr)?.address?.toLowerCase());let oe=R||e?.srcChainId||(o?`${o}`:void 0)||(N?void 0:Gi),se=r.find(({chainId:ie})=>ie===oe),Ye;se&&(Ye=se.tokens.find(({address:ie})=>ie.toLowerCase()===K?.toLowerCase()));let pe=N?void 0:r.find(({chainId:ie})=>ie===Yo);e.dstChainId&&(pe=r.find(({chainId:ie})=>ie===e.dstChainId));let ce;pe&&(ce=pe.tokens.find(({address:ie})=>ie.toLowerCase()===de));let{source:it,target:he}=Nc({source:{chain:se,token:Ye},target:{chain:pe,token:ce},type:N?"BRIDGE":"SWAP",supportedChains:r,bridgeTokensDictionary:me});W(it.chain),Y(he.chain),T(it.token),l(he.token),Ge(!0)},[e?.srcChainId,e?.srcTokenAddr,e?.dstChainId,e?.dstTokenAddr,r,N,o,ve,me]),Nt(()=>{if(!me||r.length===0||!ve)return;let{source:K,target:de}=Nc({source:{chain:R,token:Q},target:{chain:z,token:s},type:N?"BRIDGE":"SWAP",supportedChains:r,bridgeTokensDictionary:me});K.chain?.chainId!==R?.chainId&&W(K.chain),de.chain?.chainId!==z?.chainId&&Y(de.chain),K.token?.address!==Q?.address&&T(K.token),de.token?.address!==s?.address&&l(de.token)},[R,Q,z,s,N,r,me]),Nt(()=>{e.onDstChainChange?e.onDstChainChange(z?.chainId):window.xPayOnDstChainChange&&window.xPayOnDstChainChange(z?.chainId)},[e.onDstChainChange,z]),Nt(()=>{let K=s?{address:s.address.toLowerCase(),symbol:s.tokenId}:void 0;e.onDstTokenChange?e.onDstTokenChange(K):window.xPayOnDstTokenChange&&window.xPayOnDstTokenChange(K)},[e.onDstTokenChange,s]),Nt(()=>{e.onSrcChainChange?e.onSrcChainChange(R?.chainId):window.xPayOnSrcChainChange&&window.xPayOnSrcChainChange(R?.chainId)},[e.onSrcChainChange,R]),Nt(()=>{let K=Q?{address:Q.address.toLowerCase(),symbol:Q.tokenId}:void 0;e.onSrcTokenChange?e.onSrcTokenChange(K):window.xPayOnSrcTokenChange&&window.xPayOnSrcTokenChange(K)},[e.onSrcTokenChange,Q]);let Wr=Ba(()=>{e.onConnectWallet?e.onConnectWallet():window.xPayOnConnectWallet&&window.xPayOnConnectWallet()},[e]),Ve=dt(()=>!!(e.onConnectWallet||window.xPayOnConnectWallet),[e.onConnectWallet]);return D3(Z1.Provider,{value:{bridgeUI:N,integrationConfig:e,wagmiConfig:n,supportedChains:r,tab:f,setTab:d,overlay:i,error:p,setError:h,feeToken:re,srcChain:R,setSrcChain:W,srcChainTokensOptions:D,srcChainOtherTokensOptions:j,tokenPrices:X,dstChain:z,setDstChain:Y,dstChainTokensOptions:ee,dstChainOtherTokensOptions:Or,srcToken:Q,setSrcToken:T,dstToken:s,setDstToken:l,srcValue:g,setSrcValue:w,srcValueWei:Te,srcValueUsd:Gr,dstValue:Se,dstValueWei:Ue,dstValueUsd:Vr,dstValueMin:He,lastTx:Oe,setLastTxHash:P,expressDelivery:v,setExpressDelivery:E,infiniteApproval:S,setInfiniteApproval:C,slippage:U,setSlippage:O,route:B,setRoute:u,isAsyncDataLoaded:zr,srcTokenBalanceWei:y,setSrcTokenBalanceWei:m,srcTokenBalanceInfo:Hr,isFetchingRoute:c,isFetchingBalance:A,isExpressDeliveryActive:Le,quoteRoute:Me,refreshBalance:Ie,findTokenDataByAddressAndChain:qr,srcTokenLocked:k,srcChainLocked:I,dstTokenLocked:M,dstChainLocked:F,bridgeTokensDictionary:me,onConnectWallet:Wr,hasOnConnectWalletCallback:Ve},children:t})},te=()=>F3(Z1);import{jsx as vk}from"react/jsx-runtime";var Mn={rank:0,setRank:()=>{throw new Error("GlobalDataState > setRank is not implemented")},xPower:"0",updateXPower:()=>{throw new Error("GlobalDataState > updateXPower is not implemented")},xSwapBalance:"0",updateXSwapBalance:()=>{throw new Error("GlobalDataState > updateXSwapBalance is not implemented")},unfinishedQuestsCount:0,setUnfinishedQuestsCount:()=>{throw new Error("GlobalDataState > setUnfinishedQuestsCount is not implemented")}},yk=O3({rank:Mn.rank,setRank:Mn.setRank,xPower:Mn.xPower,updateXPower:Mn.updateXPower,xSwapBalance:Mn.xSwapBalance,updateXSwapBalance:Mn.updateXSwapBalance,unfinishedQuestsCount:Mn.unfinishedQuestsCount,setUnfinishedQuestsCount:Mn.setUnfinishedQuestsCount});import{createContext as U3,useCallback as j1,useContext as H3,useMemo as G3}from"react";import{jsx as V3}from"react/jsx-runtime";var $1=U3({}),ep=({children:t})=>{let e=j1(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=j1(({executeTransaction:i,handlers:a,network:o="evm"})=>{let f=Date.now();return o==="evm"&&e({executeTransaction:i,handlers:a}),f},[e]),n=G3(()=>({enqueueTransaction:r}),[r]);return V3($1.Provider,{value:n,children:t})};function tp(){return H3($1)}import{useEffect as K3,useMemo as X3,useState as J3}from"react";import{useAccount as Q3}from"wagmi";import{useMemo as z3}from"react";import{useConnectorClient as q3}from"wagmi";function W3(t){let{account:e,transport:r}=t;return new Jo.Web3Provider(r,"any").getSigner(e.address)}async function rp({chainId:t}={}){let{data:e}=q3({chainId:t});return z3(()=>e?W3(e):void 0,[e])}var Z3=()=>{let[t,e]=J3(),r=rp();K3(()=>{r.then(a=>e(a))},[r]);let n=Q3();return{networks:{evm:X3(()=>({networkName:"EVM",chainId:n.chainId?.toString()||Gi,address:n.address,signer:t,provider:t?.provider}),[n.address,n.chainId,t])}}},Wi=Z3;import{useCallback as hp}from"react";import{useMemo as $3,useState as e5}from"react";import{jsx as Bc,jsxs as Y3}from"react/jsx-runtime";var np=()=>{let{isExpressDeliveryActive:t}=te();return Y3("div",{className:"flex items-center",children:[Bc("div",{className:`w-4 h-4 mr-1 ${t?"fill-t_success_light":"fill-t_text_primary opacity-50"} `,children:Bc(B1,{})}),Bc("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 Fc,jsxs as j3}from"react/jsx-runtime";var ip=({name:t,value:e})=>{let{isFetchingRoute:r}=te();return j3("div",{className:"flex gap-x-1 justify-between text-xs font-medium",children:[Fc("div",{className:"opacity-60",children:t}),Fc("div",{children:r?Fc(pr,{className:"w-[60px] h-full"}):e})]})};import{jsx as Lc}from"react/jsx-runtime";var ap=()=>{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 Lc("div",{className:"border-t border-solid border-t_text_primary border-opacity-10 pt-3 mt-3",children:Lc("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})=>Lc(ip,{name:o,value:f},o))})})};import{jsx as hr,jsxs as fs}from"react/jsx-runtime";var ds=()=>{let[t,e]=e5(!1),{route:r,feeToken:n,isFetchingRoute:i,srcChain:a,dstChain:o}=te(),f=$3(()=>{if(!r)return"0";let d=Ot(r.xSwapFees.ccipFee||"0").add(Ot(r.xSwapFees.xSwapFee.nativeFee||"0")).add(Ot(r.xSwapFees.expressDeliveryFee||"0")).toString();return ft({amount:d,decimals:n?.decimals||18,precisionFractionalPlaces:5})},[n?.decimals,r]);return hr("div",{className:"flex flex-col x-border rounded-xl py-2 px-4 bg-t_bg_tertiary bg-opacity-5",children:fs("button",{"aria-label":`${t?"Collapse":"Expand"} fees panel`,type:"button",onClick:()=>e(d=>!d),children:[fs("div",{className:"flex justify-between",children:[fs("div",{className:"flex gap-2 items-center text-xs font-medium sm:text-sm fill-t_text_primary",children:[hr(L1,{}),hr("p",{className:"opacity-60",children:"Fee: "}),i?hr(pr,{className:"w-[100px] h-full"}):hr("p",{children:`${f} ${n?.symbol||""}`})]}),fs("div",{className:"flex gap-2 items-center fill-t_text_primary",children:[r&&!i&&a?.chainId!==o?.chainId&&hr(np,{}),t?hr("div",{className:"w-4 h-2 rotate-180",children:hr(ii,{})}):hr("div",{className:"w-4 h-2",children:hr(ii,{})})]})]}),t&&hr(ap,{})]})})};import{jsx as ls}from"react/jsx-runtime";var op=()=>ls("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:ls("div",{className:"relative bg-gradient-to-r from-t_main_accent_light to-t_main_accent_dark w-8 h-8 rounded-xl",children:ls("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 fill-white",children:ls(is,{})})})});import*as t5 from"viem/chains";import{mainnet as sp}from"viem/chains";import{createConfig as r5,createStorage as n5,http as i5}from"@wagmi/core";import{injected as a5,walletConnect as o5,coinbaseWallet as s5}from"@wagmi/connectors";var c5=n5({key:"xpay.wagmi.store",storage:vt?void 0:localStorage}),cp=t=>{let e=f5(t),r=d5(e);return r5({chains:e,transports:r,connectors:[a5(),s5({appLogoUrl:"https://xswap.link/favicon.ico",appName:"XSwap"}),o5({projectId:"c392898b45ac587a280b5eb33e92aeb0",showQrModal:!0})],storage:c5})},f5=t=>{let e=[sp];return e.push(...Object.values(t5).filter(r=>r.id!==sp.id&&t.some(({chainId:n})=>n===r.id.toString()))),e},d5=t=>{let e={};return t.forEach(r=>{e[r.id]=i5()}),e};import{useEffect as l5,useState as fp}from"react";import{createPortal as u5}from"react-dom";import{jsx as h5}from"react/jsx-runtime";var p5={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"},Ki=({id:t,position:e,text:r,triggerRef:n})=>{let[i,a]=fp({top:0,left:0}),[o,f]=fp(!1);return l5(()=>{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)},v=()=>{f(!1)};return d&&(d.addEventListener("mouseenter",h),d.addEventListener("mouseleave",v)),window.addEventListener("scroll",p,!0),window.addEventListener("resize",p,!0),()=>{d&&(d.removeEventListener("mouseenter",h),d.removeEventListener("mouseleave",v)),window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p,!0)}},[n,e]),u5(o&&h5("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 ${p5[e]}`,style:{top:i.top,left:i.left},children:r}),ti,t)};import{useRef as x5}from"react";import{jsx as Fa,jsxs as dp}from"react/jsx-runtime";var lp=({onCloseClick:t})=>{let e=x5(null);return dp("div",{className:"flex justify-between items-center text-base font-medium",children:[Fa("div",{className:"text-t_text_primary",children:"Confirmation"}),dp("div",{className:"flex gap-4 items-center",children:[Fa(Ki,{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"}),Fa(ai,{ref:e,className:"cursor-help fill-t_main_accent_light w-[18px] h-[18px]"}),Fa("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:t,children:Fa(ot,{})})]})]})};import{useMemo as up}from"react";import{jsx as Ct,jsxs as Dc}from"react/jsx-runtime";var pp=()=>{let{txStatus:t,txNeedsApproval:e,txMsg:r}=Lr(),n=up(()=>[{icon:a=>Ct("div",{className:`${a}`,children:Ct(Ac,{})}),title:"sign approval transaction",state:t===1?"triggered":t>1?"completed":"none",show:r?t===1||t===2:e},{icon:a=>Ct("div",{className:`${a}`,children:Ct(Tc,{})}),title:"confirming approval transaction...",state:t===2?"triggered":t>2?"completed":"none",show:r?t===1||t===2:e},{icon:a=>Ct("div",{className:`${a}`,children:Ct(Ac,{})}),title:"sign transaction",state:t===3?"triggered":t>3?"completed":"none",show:r?t===3||t===4:!0},{icon:a=>Ct("div",{className:`${a}`,children:Ct(Tc,{})}),title:"confirming transaction...",state:t===4?"triggered":t>4?"completed":"none",show:r?t===3||t===4:!0}],[r,e,t]),i=up(()=>n.filter(({show:a})=>a),[n]);return Ct("div",{className:"flex flex-col gap-1",children:i.map(({icon:a,title:o,state:f},d)=>Dc("div",{className:"flex flex-col px-4 gap-1",children:[Dc("div",{className:"flex justify-between items-center",children:[Dc("div",{className:"flex items-center gap-2",children:[a(`${f==="triggered"?"fill-t_main_accent_light":"fill-t_text_primary opacity-50"}`),Ct("div",{className:`${f!=="triggered"?"opacity-50":f==="triggered"&&"text-t_text_secondary"}`,children:o})]}),Ct("div",{children:f==="completed"?Ct("div",{className:"fill-t_success_dark",children:Ct(as,{})}):f==="triggered"?Ct("div",{className:"animate-spin-slow fill-t_main_accent_light",children:Ct(O1,{})}):null})]}),d!==i.length-1&&Ct("div",{className:"vertical-separator py-3 ml-2"})]},o))})};import{useMemo as us}from"react";import{jsx as La,jsxs as Da}from"react/jsx-runtime";var Oc=({type:t})=>{let{srcToken:e,srcChain:r,dstToken:n,dstChain:i,srcValue:a,srcValueUsd:o,dstValue:f,dstValueUsd:d}=te(),p=us(()=>t==="source"?e:n,[n,e,t]),h=us(()=>t==="source"?r:i,[i,r,t]),v=us(()=>t==="source"?a:f,[f,a,t]),E=us(()=>t==="source"?o:d,[d,o,t]);return Da("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:[Da("div",{className:"flex flex-col",children:[La("div",{className:"opacity-60 text-sm mb-2",children:`You ${t==="source"?"pay":"receive"}`}),La("div",{className:`${t==="destination"&&"text-t_text_secondary"}`,children:v}),Da("div",{className:"opacity-60",children:["$",E]})]}),Da("div",{className:"flex items-center gap-3",children:[Da("div",{className:"flex flex-col text-right",children:[La("div",{children:p?.symbol}),La("div",{className:"opacity-60",children:h?.displayName})]}),La(In,{token:p,className:"w-9 h-9",generatedLogoClassName:"w-9 h-9"})]})]})};import{Fragment as m5,jsx as Pn,jsxs as Uc}from"react/jsx-runtime";var xp=({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:v,txMsg:E,enqueueTransaction:S,setTxNeedsApproval:C}=Lr(),{addTransactionToLocalHistory:k,updateTransactionInLocalHistory:M}=_n(),{networks:{evm:{signer:I}}}=Wi(),F=Ma(),N=hp(async O=>{if(!r||!i||!n||!a||!d)return;let R={hash:O.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+Qo?.[r?.chainId]?.[i?.chainId]||jo,status:"IN_PROGRESS"};if(r.chainId===i.chainId)R.estimatedDeliveryTimestamp=R.timestamp,R.status="DONE";else{let W="MessageSent(bytes32,uint64,address,bytes,address,uint256,uint256,address,uint256)",z="MessageReceived(bytes32,uint64,address,bytes,address,uint256)",Y="MessageSent(bytes32,uint64,address,address,address,address,uint256)",re="MessageReceived(bytes32,uint64,address,bytes)",$=ne.getDefaultProvider(e.find(T=>T.ecosystem==="evm"&&T.chainId===i.chainId)?.publicRpcUrls[0]),Q=async(T,s,l)=>{let g=O.logs?.find(w=>w.topics[0]===ne.utils.id(s));if(g){let w=g?.topics[1];R.messageId=w;let A=new ne.Contract(_t[i?.chainId]?.[T],T==="XSwapRouter"?qu:Wu,$),b={address:_t[i.chainId]?.[T],topics:[ne.utils.id(l),w]};(await A.queryFilter(b)).length>0?(R.status="DONE",M(R,O.from)):A.once(b,()=>{R.status="DONE",M(R,O.from)})}};await Q("XSwapRouter",W,z),await Q("CustomXSwapRouter",Y,re)}k(R,O.from)},[k,M,r,i,n,a,o,f,e,d]),U=hp(async()=>{if(n&&d){let O=()=>{S({executeTransaction:()=>{if(!(!d.transactions.swap||!I))return F.executeCalldata(I,d.transactions.swap)},txStatus:3,handlers:{onSuccess:R=>{v(5),p(),N(R),r?.chainId&&i?.chainId&&r?.chainId!==i?.chainId&&mp(r?.chainId,R.transactionHash,a?.address,f)}}})};n.address!==rr.AddressZero&&d.transactions.approve?(C(!0),S({executeTransaction:()=>{if(!(!d.transactions.approve||!I))return F.executeCalldata(I,d.transactions.approve)},txStatus:1,handlers:{onSuccess:()=>O()}})):(C(!1),O())}},[n,d,S,I,F,v,p,N,r?.chainId,i?.chainId,a?.address,f,C]);return Uc("div",{className:"flex flex-col text-t_text_primary gap-5",children:[Pn(lp,{onCloseClick:t}),E?Pn("div",{children:E}):Uc(m5,{children:[Uc("div",{className:"relative flex flex-col gap-5 fill-white",children:[Pn(Oc,{type:"source"}),Pn(op,{}),Pn(Oc,{type:"destination"})]}),Pn(ds,{})]}),h===0?Pn(ur,{variant:"filled-squared",onClick:()=>{U()},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"}):Pn(pp,{})]})};import{jsx as Hc,jsxs as bp}from"react/jsx-runtime";var Gc=({chain:t,token:e,value:r})=>bp("div",{className:"flex items-center gap-2",children:[Hc(Nn,{chain:t,token:e,chainLogoClassName:"w-5",tokenLogoClassName:"w-9 h-9",generatedLogoClassName:"w-9 h-9 text-[16px]"}),bp("div",{className:"flex flex-col w-min sm:w-auto",children:[Hc("div",{children:`${r} ${e?.symbol}`}),Hc("div",{className:"opacity-60",children:t?.displayName})]})]});import{Fragment as gp,jsx as mt,jsxs as Oa}from"react/jsx-runtime";var yp=({onCloseClick:t})=>{let{txError:e,txExplorerUrl:r,txMsg:n}=Lr(),{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?Oa(gp,{children:[mt("div",{className:"flex justify-end fill-t_text_primary cursor-pointer w-full",onClick:t,children:mt(ot,{className:"w-3.5 h-3.5"})}),mt(v1,{}),mt("div",{className:"text-2xl font-bold",children:"Transaction failed"}),mt("div",{className:"text-center",children:e})]}):Oa(gp,{children:[mt("div",{className:"flex justify-end fill-t_text_primary cursor-pointer w-full",onClick:t,children:mt(ot,{className:"w-3.5 h-3.5"})}),mt(P1,{}),Oa("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&&Oa("div",{className:"flex items-center gap-2",children:[mt(Gc,{chain:a,token:o,value:p}),mt("div",{className:"-rotate-90 flex justify-center w-8 fill-t_text_primary opacity-50",children:mt(is,{})}),mt(Gc,{chain:f,token:d,value:h})]}),Oa("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(S1,{})]})]})})};import{jsx as wp}from"react/jsx-runtime";var vp=({onCloseClick:t})=>{let{txStatus:e,txError:r}=Lr();return e===5||r?wp(yp,{onCloseClick:t}):wp(xp,{onCloseClick:t})};import{useSnackbar as b5}from"notistack";import{createContext as g5,useCallback as Ua,useContext as y5,useEffect as w5,useMemo as Vc,useRef as Cp,useState as fn}from"react";import{useAccount as v5}from"wagmi";import{jsx as er,jsxs as zc}from"react/jsx-runtime";var Ap=g5({}),Tp=({children:t})=>{let{chainId:e}=v5(),{enqueueTransaction:r}=tp(),{enqueueSnackbar:n,closeSnackbar:i}=b5(),[a,o]=fn("evm"),f=Cp(!1),[d,p]=fn(!1),[h,v]=fn(""),E=Cp(),[S,C]=fn(""),[k,M]=fn(""),[I,F]=fn(void 0),[N,U]=fn(!1),[O,R]=fn(!1),[W,z]=fn(0),{supportedChains:Y,setSrcValue:re}=te(),$=y=>{E.current===y&&(f.current=!1,p(!1))};w5(()=>{if(!d&&(S&&(n(er(kn,{message:{text:S,variant:"error"}})),C("")),N&&h)){let y=h;n(er(kn,{message:{text:`Transaction ${Xu(h)} is about to be mined!`,variant:"warning",action:()=>zc("div",{className:"flex items-center flex-nowrap",children:[er(ur,{type:"button",onClick:()=>{window.open(`${Y.find(m=>m.chainId===e?.toString()&&m.ecosystem===a)?.transactionExplorer}/${h}`||"")},children:"Check"}),er("div",{className:"fill-t_text_primary w-[14px] h-[14px] cursor-pointer p-[14px] leading-[0px]",onClick:()=>i(y),children:er(ot,{})})]}),animation:()=>er(Dr,{className:"w-4 h-4"})}}),{persist:!0,key:y}),v("")}},[N,a,h,S,n,i,e,d,Y]);let Q=Ua((y,m,c)=>{let x=`${m}/${y}`;if(c){let u=c.events?.find(_=>_.event==="MessageSent")?.args?.messageId;return u?`${Vi}${u}`:x}else return x},[]),T=Ua((y,m,c=!0)=>{let x={...m};return x.onConfirm=B=>{E.current===y&&(m?.onConfirm&&m?.onConfirm(B),v(B?.hash||""),z(u=>u+1))},x.onSuccess=B=>{if(i(B?.transactionHash),E.current===y){if(F(B),!f.current&&c){let u=`${h}-success`;n(er(kn,{message:{text:"Transaction mined successfully!",variant:"success",action:()=>zc("div",{className:"flex items-center flex-nowrap",children:[er(ur,{type:"button",onClick:()=>{window.open(Q(h,Y.find(_=>_.chainId===e?.toString()&&_.ecosystem===a)?.transactionExplorer||"",B))},children:"View"}),er("div",{className:"fill-t_text_primary w-[14px] h-[14px] cursor-pointer p-[14px] leading-[0px]",onClick:()=>i(u),children:er(ot,{})})]})}}),{persist:!1,key:u})}m?.onSuccess&&m?.onSuccess(B),C(""),U(!1)}},x.onError=B=>{E.current===y&&(C(Ju(B)),m?.onError?.(B),U(!1))},x},[i,h,n,Q,Y,e,a]),s=Ua(({executeTransaction:y,txStatus:m,txMsg:c="",handlers:x,network:B="evm",showDefaultSuccessMessage:u=!0})=>{let _=Date.now(),P=x;return B==="evm"&&(P=T(_,x,u)),r({executeTransaction:y,txStatus:m,handlers:P,network:B}),E.current=_,f.current=!0,v(""),C(""),M(c),z(m),F(void 0),U(!0),o(B),p(!0),_},[T,r]),l=Vc(()=>Q(h,Y.find(y=>y.chainId===e?.toString()&&y.ecosystem===a)?.transactionExplorer||"",I),[e,a,Q,Y,h,I]),g=Ua(y=>{p(y),f.current=y},[]),w=Vc(()=>S?"error":W===5?"success":"neutral",[S,W]),A=Vc(()=>({enqueueTransaction:s,closeTransactionModal:$,isTxModalOpen:d,setTxModalOpen:p,loading:N,txStatus:W,setTxStatus:z,txExplorerUrl:l,txHash:h,txError:S,txMsg:k,setTxMsg:M,setTxError:C,txNeedsApproval:O,setTxNeedsApproval:R}),[s,d,N,W,l,h,S,k,O]),b=Ua(()=>{C(""),re(""),g(!1)},[C,re,g]);return zc(Ap.Provider,{value:A,children:[d&&er(Sp,{id:"tx_modal",className:"max-w-x_modal",type:w,onCloseClick:b,children:er(vp,{onCloseClick:b})}),t]})};function Lr(){return y5(Ap)}import{jsx as Ep}from"react/jsx-runtime";var Xi=({className:t,children:e,onClose:r})=>{let{overlay:n}=te();return Ep("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.stopPropagation(),i.nativeEvent.stopImmediatePropagation(),i.preventDefault(),i.target===i.currentTarget&&n&&r()},children:Ep("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 oi,jsxs as ps}from"react/jsx-runtime";var qc=()=>ps("div",{className:"flex justify-center items-center gap-2 my-3",children:[oi("span",{className:"text-t_text_primary opacity-50",children:"Powered by"}),ps("div",{className:"flex items-center gap-1",children:[oi(G1,{}),oi("span",{className:"text-t_text_primary text-xl leading-none font-bold opacity-90",children:"Swap"})]}),oi("span",{className:"text-t_text_primary opacity-50",children:"\u2715"}),ps("div",{className:"flex items-center gap-1",children:[oi(p1,{}),ps("span",{className:"flex flex-col",children:[oi("span",{className:"text-t_text_primary text-xs leading-none",children:"Chainlink"}),oi("span",{className:"text-sm text-[#2C4FBC] font-bold leading-none ",children:"CCIP"})]})]})]});import{forwardRef as C5,useCallback as A5,useMemo as T5}from"react";import{jsx as S5}from"react/jsx-runtime";var Ha=C5(({value:t,onChange:e,id:r,placeholder:n,regex:i,className:a,disabled:o},f)=>{let d=T5(()=>t.length<2?2:t.length,[t]),p=A5(h=>{h.target.value!=="."&&i.test(h.target.value)&&e(h.target.value.replace(/,/g,"."))},[e,i,r]);return S5("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})});Ha.displayName="SafeInput";import{jsx as E5}from"react/jsx-runtime";var pr=({className:t})=>E5("div",{className:`bg-t_bg_tertiary bg-opacity-15 rounded animate-pulse ${t||""}`});import{jsx as Wc,jsxs as k5}from"react/jsx-runtime";var Dr=({className:t})=>Wc("div",{role:"status",className:t||"",children:k5("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 s6}from"react";import{Fragment as _5,jsx as dn,jsxs as M5}from"react/jsx-runtime";var kp=({onClose:t})=>{let{tab:e,setTab:r,overlay:n}=te();return dn("div",{className:"flex gap-5 items-center",children:e==="Swap"?M5(_5,{children:[dn("button",{type:"button",onClick:()=>r("Settings"),"aria-label":"Open settings",className:"fill-white",children:dn(_1,{})}),dn("button",{type:"button",onClick:()=>r("History"),"aria-label":"Open history",className:"fill-white",children:dn(A1,{})}),n&&dn("button",{type:"button",onClick:()=>t(),"aria-label":"Close",className:"fill-t_text_primary",children:dn(ot,{})})]}):dn("button",{type:"button",onClick:()=>{r("Swap")},"aria-label":"Switch to swap view",className:"fill-t_text_primary",children:dn(ot,{})})})};import{jsx as _p,jsxs as I5}from"react/jsx-runtime";var Mp=({onClose:t})=>{let{tab:e,bridgeUI:r}=te();return I5("div",{className:"flex justify-between",children:[_p("div",{className:"text-xl font-sans-bold font-bold",children:e==="Swap"&&r?"Bridge":e}),_p(kp,{onClose:t})]})};import{useMemo as P5}from"react";import{Virtuoso as N5}from"react-virtuoso";import{jsx as Ji}from"react/jsx-runtime";var Ip=()=>{let{history:t,historyLoadedOnce:e}=_n(),r=P5(()=>!t||t.length===0?e?Ji("div",{className:"text-center py-4 text-[#9e9e9e]",children:"Your history is empty"}):Ji("div",{className:"flex justify-center w-full py-4 fill-t_text_primary",children:Ji(Dr,{className:"w-8 h-8"})}):Ji(N5,{data:t,style:{height:"532px"},itemContent:(n,i)=>Ji(Pp,{transaction:i})}),[t,e]);return Ji("div",{className:"flex-1 overflow-hidden",children:r})};import{jsx as Kc,jsxs as R5}from"react/jsx-runtime";var Ga=({checked:t,onClick:e})=>Kc("div",{children:R5("span",{className:"inline-flex w-14 h-9 p-3 relative align-middle box-border overflow-hidden cursor-pointer",onClick:e,children:[Kc("span",{className:"h-full w-full rounded-lg bg-t_bg_tertiary bg-opacity-30"}),Kc("span",{className:`transition-all w-5 h-5 rounded-full absolute translate-y-[-4px]
|
|
92
92
|
${t?"translate-x-[12px] bg-t_main_accent_light":"bg-t_bg_tertiary"} `})]})});Ga.displayName="ToggleButton";import{useRef as B5}from"react";import{jsx as Qi,jsxs as Np}from"react/jsx-runtime";var Rp=()=>{let t=B5(null),{infiniteApproval:e,setInfiniteApproval:r}=te();return Np("div",{className:"flex flex-col gap-5 pt-5 border-t border-solid border-white border-opacity-10",children:[Qi("h1",{className:"text-sm font-medium text-left",children:"Approval"}),Qi("div",{className:"flex gap-2 items-center justify-between flex-wrap",children:Np("div",{className:"flex items-center",children:[Qi("h2",{className:"text-xs",children:"Infinite approval: "}),Qi(Ga,{checked:e,onClick:()=>{r(n=>!n)}}),Qi(Ki,{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"}),Qi(ai,{ref:t,className:"cursor-help fill-t_main_accent_light w-[18px] h-[18px]"})]})})]})};import{useRef as F5}from"react";import{jsx as Zi,jsxs as hs}from"react/jsx-runtime";var Bp=()=>{let t=F5(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:[Zi("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:[Zi("h2",{className:"text-xs",children:"Express delivery: "}),Zi(Ga,{checked:e,onClick:()=>{r(n=>!n)}}),Zi(Ki,{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"}),Zi(ai,{ref:t,className:"cursor-help fill-t_main_accent_light w-[18px] h-[18px]"})]}),hs("div",{className:"text-xs font-medium",children:[Zi("span",{className:"text-xs font-medium opacity-60",children:"Max time: "}),e?"30 sec":"30 min"]})]})]})};import{useState as L5}from"react";import{jsx as Rn,jsxs as xs}from"react/jsx-runtime";var Fp=()=>{let{slippage:t,setSlippage:e}=te(),[r,n]=L5(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:[Rn("h1",{className:"text-sm font-medium text-left",children:"Slippage"}),xs("div",{className:"flex items-center gap-2 w-full",children:[Rn("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=>Rn("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))}),Rn("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:[Rn(Ha,{id:"slippage-input",placeholder:"1.5",regex:Zo,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:[Rn("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."}),Rn("br",{}),Rn("p",{children:"If the trade fails due to too low slippage, you will receive USDC on the destination chain."})]})]})};import{jsx as Xc,jsxs as D5}from"react/jsx-runtime";var Lp=()=>D5("div",{className:"flex flex-col gap-5",children:[Xc(Bp,{}),Xc(Rp,{}),Xc(Fp,{})]});import{jsx as Va}from"react/jsx-runtime";var Dp=()=>{let{dstChain:t,dstToken:e,srcChain:r,srcToken:n,setDstChain:i,setDstToken:a,setSrcChain:o,setSrcToken:f}=te();return Va("div",{className:"h-[1px] w-full",children:Va("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:Va("div",{className:"relative bg-gradient-to-r from-t_main_accent_light to-t_main_accent_dark w-8 h-8 rounded-lg",children:Va("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 fill-white",children:Va(u1,{})})})})})};var Jc={1:["0xdac17f958d2ee523a2206206994597c13d831ec7"]};import{useCallback as Qc,useMemo as O5}from"react";var Op=({rpcChainId:t,currentChainId:e,signer:r,tokenAddress:n})=>{let i=wc(),{supportedChains:a}=te(),o=O5(()=>{let f=a.find(d=>d.ecosystem==="evm"&&d.chainId===t)?.publicRpcUrls[0];return f&&n?new ne.Contract(n,Fr,r&&(!e||e===t)?r:ne.getDefaultProvider(f)):null},[t,e,r,n,a]);return{balanceOf:Qc(async f=>await i.query(o,"balanceOf",[f]),[o,i]),allowance:Qc(async(f,d)=>await i.query(o,"allowance",[f,d]),[o,i]),approve:Qc(async(f,d)=>await i.execute(o,"approve",[d,f]),[o,i])}};import{useCallback as Hp,useEffect as z5,useMemo as Yi,useState as Gp}from"react";import{useAccount as q5,useSwitchChain as W5}from"wagmi";import{useCallback as U5,useMemo as H5}from"react";import{useConnect as G5}from"wagmi";import{jsx as ln,jsxs as Zc}from"react/jsx-runtime";var V5=({connector:t,className:e})=>{switch(t.name){case"WalletConnect":return ln(H1,{className:`w-[34px] h-[34px] rounded-md ${e||""}`});default:return ln("img",{src:t.icon,alt:t.name,className:`w-[34px] h-[34px] rounded-md ${e||""}`})}},Up=({className:t,onClose:e})=>{let{connectors:r,connectAsync:n}=G5(),i=H5(()=>r.filter(o=>{let f=o.type==="injected",d=o.name==="Injected";return o.type==="walletConnect"||f&&!d}),[r]),a=U5(async o=>{await n({connector:o}),e()},[n,e]);return Zc("div",{className:`flex flex-col h-full ${t||""}`,children:[Zc("div",{className:"flex justify-between",children:[ln("div",{className:"text-base/4 mb-4 text-t_text_primary",children:"Pick wallet"}),ln("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:e,children:ln(ot,{})})]}),ln("div",{className:"horizontal-separator"}),ln("div",{className:"h-full pt-4",children:i.map(o=>Zc("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:[ln(V5,{connector:o}),ln("div",{className:"text-t_text_primary",children:o.name})]},o.id))})]})};import{Fragment as K5,jsx as Yc,jsxs as X5}from"react/jsx-runtime";var Vp=()=>{let{address:t,chainId:e}=q5(),{switchChainAsync:r}=W5(),[n,i]=Gp(!1),{integrationConfig:a}=te(),{bridgeUI:o,error:f,srcChain:d,dstChain:p,srcToken:h,dstToken:v,srcValueWei:E,srcTokenBalanceWei:S,isFetchingRoute:C,isAsyncDataLoaded:k,hasOnConnectWalletCallback:M,onConnectWallet:I}=te(),{setTxStatus:F,setTxMsg:N,setTxModalOpen:U,enqueueTransaction:O}=Lr(),R=Yi(()=>d?.chainId,[d?.chainId]),W=Yi(()=>p?.chainId,[p?.chainId]),z=Yi(()=>h?.address,[h?.address]),Y=Yi(()=>v?.address,[v?.address]),[re,$]=Gp("0"),{networks:{evm:Q}}=Wi(),{allowance:T,approve:s}=Op({rpcChainId:R,currentChainId:Q.chainId,signer:Q.signer,tokenAddress:z}),l=Yi(()=>R?R===W?_t[R]?.XSwapRouterSingleChain||"":_t[R]?.XSwapRouter||"":"",[R,W]),g=Hp(async()=>{if(l&&Q.address)try{let b=await T(Q.address,l);$(b.toString())}catch{$("0")}else $("0")},[T,Q.address,l]);z5(()=>{R&&Jc[R]?.includes(z)&&g()},[g,R,z]);let w=Hp(()=>{F(0),N(""),U(!0)},[U,N,F]),A=Yi(()=>k?f?{text:f,fn:()=>{},disabled:!0}:t?!R||!W||!z||!Y?{text:"Select Tokens",fn:()=>{},disabled:!0}:R===W&&z.toLowerCase()===Y.toLowerCase()?{text:"Change Token",fn:()=>{},disabled:!0}:e?.toString()!==R?{text:"Change Chain",fn:async()=>await r({chainId:Number(R)}),disabled:!1}:E&&S&&Ot(E).gt(Ot(S))?{text:"Insufficient Balance",fn:()=>{},disabled:!0}:Ot(E||"0").lte(Ot("0"))?{text:"Enter Token Amount",fn:()=>{},disabled:!0}:C?{text:"Fetching Route",fn:()=>{},disabled:!0}:Jc[R]?.includes(z)&&re!=="0"&&J.from(re).lt(J.from(E))?{text:"Reset Approval",fn:async()=>{O({executeTransaction:()=>s("0",l),txStatus:1,txMsg:"You are going to reset your approval",handlers:{onSuccess:()=>{g(),F(5)}}})},disabled:!1}:{text:o?"Bridge":"Swap",fn:async()=>{w()},disabled:!1}:{text:a.defaultWalletPicker||M?"Connect Wallet":"Connect Wallet First",fn:()=>{a.defaultWalletPicker?i(!0):M&&I()},disabled:!a.defaultWalletPicker&&!M}:{text:"Loading XPay...",fn:()=>{},disabled:!0},[k,f,t,R,W,z,Y,e,E,S,C,re,o,a.defaultWalletPicker,r,O,s,l,g,F,w]);return X5(K5,{children:[n&&Yc(Xi,{onClose:()=>i(!1),children:Yc(Up,{onClose:()=>i(!1)})}),Yc("button",{type:"button",disabled:A.disabled,onClick:A.fn,className:`text-xl font-sans-bold font-bold w-full py-5 cursor-pointer disabled:cursor-not-allowed rounded-2xl border-none ${A.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:A.text})]})};import{useMemo as ch}from"react";import{useMemo as Q5}from"react";import{jsx as jc,jsxs as J5}from"react/jsx-runtime";var zp=()=>{let{srcTokenBalanceInfo:t,isFetchingBalance:e}=te();return J5("div",{className:"flex flex-col items-end",children:[jc("p",{className:"text-xs font-medium opacity-60",children:"Balance:"}),e?jc(pr,{className:"w-[50px] h-[16px]"}):jc("p",{className:`text-xs font-medium ${!t&&"opacity-60"}`,children:t||"-"})]})};import{Fragment as qp,jsx as Bn,jsxs as ms}from"react/jsx-runtime";var Wp=({type:t})=>{let{srcValue:e,srcValueUsd:r,dstValue:n,dstValueUsd:i,setSrcValue:a,isFetchingRoute:o}=te(),f=Q5(()=>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:[Bn("div",{className:"flex flex-col font-medium w-full overflow-hidden text-left",children:t==="source"?ms(qp,{children:[Bn(Ha,{id:"swap-amount-input",className:"bg-transparent border-none p-0 text-xl outline-0 font-sans-bold font-bold",regex:Zo,value:e,onChange:d=>a(d)}),f&&Bn("div",{className:"text-sx opacity-60",children:`$${f}`})]}):o?ms("div",{className:"flex flex-col gap-1",children:[Bn(pr,{className:"w-[150px] h-[30px]"}),Bn(pr,{className:"w-[100px] h-[20px]"})]}):ms(qp,{children:[Bn("div",{className:"text-xl text-t_text_secondary font-sans-bold font-bold",children:n||0}),f&&Bn("div",{className:"text-sx opacity-60",children:`$${f}`})]})}),t==="source"&&Bn(zp,{})]})};import{useCallback as Qp,useMemo as Zp,useState as Y5}from"react";import{useMemo as tf}from"react";import{Virtuoso as Z5}from"react-virtuoso";import{useMemo as $c}from"react";import{jsx as ji,jsxs as ef}from"react/jsx-runtime";var Kp=({chain:t,type:e,onClick:r,disabled:n})=>{let{networks:{evm:i}}=Wi(),{srcChain:a,dstChain:o,bridgeUI:f}=te(),d=$c(()=>e==="source"?a?.chainId:o?.chainId,[o,a,e]),p=$c(()=>i.signer&&i.chainId===t.chainId,[t.chainId,i.chainId,i.signer]),h=$c(()=>{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 ji("div",{className:"group relative",children:ef("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:[ef("div",{className:"flex gap-3 items-center w-full",children:[ji("img",{src:t.image,alt:t.name,className:"w-[34px] h-[34px]"}),ji("p",{children:t.displayName})]}),E&&ji("div",{className:"w-full text-center opacity-0 group-hover:opacity-100 text-xs transition-opacity duration-200",children:E}),p&&ef("div",{className:"flex items-baseline gap-1",children:[ji(y1,{}),ji("div",{className:"text-t_text_green",children:"connected"})]})]})})};import{jsx as Fn,jsxs as Xp}from"react/jsx-runtime";var Jp=({type:t,setSrcChain:e,setDstChain:r,onClose:n})=>{let{srcChain:i,srcToken:a,dstChain:o,dstToken:f,bridgeUI:d,bridgeTokensDictionary:p,supportedChains:h}=te(),v=tf(()=>h.filter(({web3Environment:k,swapSupported:M,bridgeSupported:I})=>k==="mainnet"&&(d&&I||!d&&M)),[d,h]),E=k=>{let M=h.find(({chainId:I})=>I===k);if(!M)throw new Error("ChainPicker > selected chain id that is absent in supportedChains list.");t==="source"?e(M):r(M),n()},S=tf(()=>{if(!i?.chainId||!a?.address)return[];if(!d){let k=h.find(M=>M.chainId===i.chainId)?.disabledForDestination||[];return t==="destination"?v?.filter(M=>k.includes(M.chainId)).map(({chainId:M})=>M):[]}if(t==="destination"){let k=p?.[i.chainId]?.[a.address];return v?.filter(I=>!k?.[I.chainId]).map(({chainId:I})=>I)}else{if(!o||!f)return[];let k=p?.[o.chainId]?.[f.address];return v?.filter(I=>!k?.[I.chainId]).map(({chainId:I})=>I)}},[p,d,v,i,a,o,f,t,h]),C=tf(()=>v.map(k=>({...k,disabled:S.includes(k.chainId)})).sort((k,M)=>k.disabled===M.disabled?0:k.disabled?1:-1),[v,S]);return Xp("div",{className:"flex flex-col h-full",children:[Xp("div",{className:"flex justify-between",children:[Fn("div",{className:"text-base/4 text-t_text_primary mb-4",children:`Pick ${t} chain`}),Fn("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:n,children:Fn(ot,{})})]}),Fn("div",{className:"horizontal-separator"}),Fn("div",{className:"h-full pt-4",children:v.length?Fn(Z5,{style:{height:"100%"},data:C,itemContent:(k,M)=>Fn(Kp,{chain:M,type:t,disabled:M.disabled,onClick:E})}):Fn("div",{className:"flex justify-center mt-4",children:'"No chain found."'})})]})};import{Fragment as j5,jsx as si,jsxs as rf}from"react/jsx-runtime";var Yp=({chain:t,type:e,className:r})=>{let{setSrcChain:n,setDstChain:i,srcToken:a,setSrcToken:o,dstToken:f,setDstToken:d,srcChainLocked:p,dstChainLocked:h,bridgeUI:v,bridgeTokensDictionary:E}=te(),S=Zp(()=>e==="destination"&&h,[e,h]),C=Zp(()=>e==="source"&&p,[e,p]),[k,M]=Y5(!1),I=Qp(N=>{let U;if(v){let O=Object.keys(E?.[N.chainId]||{}).map(R=>R.toLowerCase());if(U=N.tokens.find(R=>R.symbol===a?.symbol&&O.includes(R.address.toLowerCase())),!U){let R=O[0];if(!R)throw new Error(`Couldn't find any available bridgeable token on the chain ${N.chainId}, but bridging is available`);if(U=N.tokens.find(W=>W.address.toLowerCase()===R.toLowerCase()),!U)throw new Error(`Found bridgeable token (${R}) on the chain ${N.chainId}, but token was not defined in chains collection`)}}else U=N.tokens.find(O=>O.symbol===a?.symbol)||N.tokens.find(O=>O.symbol===N.tokenSymbol);n(N),o(U)},[n,o,a,E,v]),F=Qp(N=>{let U=N.tokens.find(O=>O.symbol===f?.symbol)||N.tokens.find(O=>O.symbol===N.tokenSymbol);i(N),d(U)},[i,d,f]);return rf(j5,{children:[k&&si(Xi,{onClose:()=>M(!1),children:si(Jp,{type:e,setSrcChain:I,setDstChain:F,onClose:()=>M(!1)})}),si("button",{type:"button",disabled:S||C,onClick:()=>M(!0),className:`${r||""}`,children:rf("div",{className:"flex justify-between items-center p-4 gap-8",children:[rf("div",{className:"flex flex-col font-medium items-start",children:[si("p",{className:"text-xs opacity-60",children:e==="source"?"From:":"To:"}),si("p",{className:`${t?"":"opacity-60"}`,children:t?t.displayName:"Select"})]}),!S&&!C&&si("div",{className:"w-4 h-2 fill-t_text_primary",children:si(ii,{})})]})})]})};import{jsx as jp}from"react/jsx-runtime";var $p=({type:t})=>{let{srcToken:e,srcTokenBalanceWei:r,srcTokenBalanceInfo:n,setSrcValue:i}=te();return jp("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"&&jp("p",{className:`border-b border-solid border-t_text_primary ${!n&&"border-opacity-60"}`,children:"Max"})})};import{useMemo as Wa,useState as a6}from"react";import{faCheck as t6}from"@fortawesome/free-solid-svg-icons";import{FontAwesomeIcon as r6}from"@fortawesome/react-fontawesome";import{useCallback as nh,useEffect as gs,useMemo as ys,useRef as ih,useState as $i}from"react";import{GroupedVirtuoso as n6}from"react-virtuoso";import{jsx as nf,jsxs as eh}from"react/jsx-runtime";var th=({token:t,selectedTokenAddress:e,onClick:r})=>eh("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:[nf(In,{token:t,className:"w-6 h-6",generatedLogoClassName:"w-6 h-6"}),eh("div",{className:"flex flex-col gap-1 text-xs font-medium !leading-3",children:[nf("div",{className:"text-t_text_primary",children:t.name}),nf("div",{className:"text-t_text_primary text-opacity-50",children:t.symbol})]})]});import{useMemo as za}from"react";import{useAccount as $5}from"wagmi";import{Fragment as e6,jsx as Ln,jsxs as bs}from"react/jsx-runtime";var rh=({token:t,selectedTokenAddress:e,onClick:r,selectedChainId:n})=>{let{supportedChains:i,tokenPrices:a}=te(),{address:o}=$5(),f=za(()=>i.find(({chainId:E})=>E===t.chainId),[i,t]),d=za(()=>a[t.chainId]?.[t.address],[t,a]),p=za(()=>!t.balance||!t.decimals?null:Number(ne.utils.formatUnits(t.balance,t.decimals)),[t.balance,t.decimals]),h=za(()=>t.balance&&!t.balance.eq(0),[t.balance]),v=za(()=>!p||!d||!h?null:p*+d,[p,d,h]);return bs("div",{className:`token-picker-container ${t.address.toLowerCase()===e?.toLowerCase()&&n&&t.chainId===n?"bg-t_bg_tertiary bg-opacity-10":""}`,onClick:r,children:[Ln(Nn,{token:t,chain:f,tokenLogoClassName:"min-w-9 w-9 h-9",generatedLogoClassName:"min-w-9 w-9 h-9 text-[16px]",chainLogoClassName:"w-5"}),bs("div",{className:"flex justify-between items-center gap-1 w-full",children:[bs("div",{className:"text-left",children:[Ln("div",{className:"text-sm font-medium text-ellipsis text-t_text_primary",children:t.name}),Ln("div",{className:"text-xs text-t_text_primary text-opacity-50 font-medium",children:t.symbol})]}),t.balance&&t.decimals?bs("div",{className:"text-right",children:[Ln("div",{className:"text-xs text-t_text_primary",children:t.balance.eq(0)||p>1e-4?ft({amount:t.balance.toString(),decimals:t.decimals,precisionFractionalPlaces:4}):"<0.0001"}),h&&Ln("div",{className:"text-xs text-t_text_primary text-opacity-50",children:v?`$${v.toFixed(2)}`:"$ -"})]}):Ln(e6,{children:o?Ln("div",{children:Ln(pr,{className:"w-[48px] h-[12px]"})}):null})]})]})};import{useAccount as i6}from"wagmi";import{Fragment as af,jsx as ue,jsxs as Rt}from"react/jsx-runtime";var ah=({chain:t,tokens:e,otherTokens:r,selectedTokenAddress:n,isOpen:i,onSelect:a,setModalOpen:o,type:f})=>{let[d,p]=$i(""),[h,v]=$i(!1),[E,S]=$i(!1),[C,k]=$i(!1),[M,I]=$i(null),[F,N]=$i(!0),U=ih(0),O=ih(null),{bridgeUI:R,supportedChains:W,findTokenDataByAddressAndChain:z,tokenPrices:Y}=te(),{address:re}=i6(),$=Ma();gs(()=>{S(!1),v(!1)},[i]);let Q=nh(()=>{if(t&&M&&zi(d)){let y={};vt||(y=JSON.parse(localStorage.getItem("custom-tokens")||"{}"));let m={address:M.address,symbol:M.symbol,name:M.name,tokenId:M.address,decimals:M.decimals,quickPick:!1,supported:!0,priority:0,chainId:t.chainId};vt||(y[t.chainId]={...y[t.chainId]||{},[d.toLowerCase()]:m},localStorage.setItem("custom-tokens",JSON.stringify(y))),a(m),o(!1)}},[t,d,M,a,o]),T=nh(async()=>{let y=Date.now();U.current=y;let m=W.find(({ecosystem:x,chainId:B})=>x==="evm"&&B===t?.chainId)?.publicRpcUrls[0],c=new ne.Contract(d.toLowerCase(),Fr,ne.getDefaultProvider(m));k(!0);try{let x=await Promise.all([$.query(c,"decimals"),$.query(c,"name"),$.query(c,"symbol")]);if(y!==U.current)return;let[B,u,_]=x;I({address:d.toLowerCase(),decimals:B,name:u,symbol:_})}catch{I(null)}finally{y===U.current&&k(!1)}},[t,d,$,W]);gs(()=>{!R&&zi(d)&&t&&!z(d.toLowerCase(),t.chainId)?T():(k(!1),I(null))},[R,d,T,z,t]),gs(()=>{p("")},[i]);let s=(y,m)=>y.toLowerCase().indexOf(m.toLowerCase())>-1,l=ys(()=>e?.filter(y=>s(y.symbol,d)||s(y.name,d)||y.address.toLowerCase()===d.toLowerCase()),[d,e]),g=ys(()=>r?.filter(y=>s(y.symbol,d)||s(y.name,d)||y.address.toLowerCase()===d.toLowerCase()),[d,r]);gs(()=>{i&&O.current&&setTimeout(()=>{O.current?.focus()},10)},[i]);let w=ys(()=>{let y=u=>{if(!u.balance||!u.decimals)return 0;let _=Number(ne.utils.formatUnits(u.balance,u.decimals)),P=Y[u.chainId]?.[u.address];return P?_*Number(P):0},m=[...l.filter(u=>J.from(u?.balance||"0").gt(0)),...g.filter(u=>J.from(u?.balance||"0").gt(0))].sort((u,_)=>{let P=y(u),D=y(_);return D!==P?D-P:_.priority-u.priority}),c=l.filter(u=>J.from(u?.balance||"0").eq(0)).sort((u,_)=>_.priority-u.priority),x=g.filter(u=>J.from(u?.balance||"0").eq(0)).sort((u,_)=>_.priority-u.priority);return(t?[...re&&m.length?[m]:[],c,x]:[...re&&m.length?[m]:[],[...c,...x]]).flat()},[l,g,t,re,Y]),A=ys(()=>w.filter(y=>y.balance?.gt(0)),[w]),b=t?[...re&&A.length?[A]:[],l,g]:[...re&&A.length?[A]:[],g];return E?Rt(af,{children:[Rt("div",{className:"flex justify-between",children:[ue("div",{className:"text-base/4 mb-4",children:"Import token"}),ue("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:()=>o(!1),children:ue(ot,{})})]}),Rt("div",{className:"flex flex-col h-full gap-2",children:[M&&Rt("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:[ue(qa,{tokenName:M.name,className:"w-9 h-9 text-[15px]"}),Rt("div",{className:"flex justify-between items-center gap-1 overflow-hidden grow",children:[ue("div",{className:"overflow-hidden whitespace-nowrap text-ellipsis text-sm font-medium",children:M.name}),ue("div",{className:"token-picker__all__symbol",children:M.symbol})]}),Rt("div",{className:"text-sm flex items-center",children:[Qu(d.toLowerCase()),ue("button",{type:"button",onClick:()=>navigator.clipboard.writeText(M.address.toLowerCase()),"aria-label":`Copy ${M.symbol} token address`,className:"flex items-center p-2 fill-white cursor-pointer hover:fill-t_main_accent_light",children:ue(b1,{className:"w-5 h-5"})})]})]}),ue("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"}),Rt("div",{className:"bg-t_bg_secondary border border-solid border-t_text_primary border-opacity-10 rounded-xl p-2",children:[ue("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."}),Rt("button",{type:"button",onClick:()=>v(y=>!y),className:"flex items-center",children:[ue("div",{className:"flex justify-center items-center p-1 w-6 h-6 border-2 border-white rounded-md mr-2",children:h&&ue(r6,{icon:t6,className:"w-4 h-4"})}),ue("div",{className:"font-bold",children:"Accept"})]})]}),ue("div",{className:"flex grow items-end justify-center",children:ue(ur,{type:"button",disabled:!h,className:`token-picker__import-button w-full ${h?"":"!cursor-not-allowed"}`,onClick:Q,children:"Import"})})]})]}):Rt(af,{children:[Rt("div",{className:"flex justify-between",children:[ue("div",{className:"text-base/4 text-t_text_primary mb-4",children:`Pick ${f} token`}),ue("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:()=>o(!1),children:ue(ot,{})})]}),ue(oh,{ref:O,inputIcon:ue("div",{className:"fill-t_text_primary",children:ue(k1,{})}),placeholder:"Search name or paste address",value:d,handleChange:p}),ue("div",{className:`flex flex-wrap gap-1 my-4 mx-0 transition-all duration-300 ${F?"opacity-100 max-h-[200px]":"opacity-0 max-h-0 overflow-hidden"}`,children:e.filter(y=>y?.quickPick).map(y=>ue(th,{token:y,selectedTokenAddress:n,onClick:()=>{a(y),o(!1)}},y.address))}),ue("div",{className:"flex flex-col mx-0 h-full",children:C?ue("div",{className:"flex justify-center w-full py-4 px-0",children:ue(Dr,{className:"w-9 h-9"})}):ue(af,{children:M?Rt("div",{className:"token-picker-container hover:cursor-default",children:[ue(Nn,{token:M,chain:t,tokenLogoClassName:"w-9 h-9",generatedLogoClassName:"w-9 h-9 text-[16px]",chainLogoClassName:"w-5"}),Rt("div",{className:"flex justify-between items-center gap-1 overflow-hidden grow",children:[Rt("div",{children:[ue("div",{className:"text-sm font-medium text-ellipsis",children:M.name}),ue("div",{className:"text-xs text-t_text_primary !text-opacity-50 font-medium",children:t?.displayName})]}),ue("div",{className:"token-picker__all__symbol",children:M.symbol})]}),ue("div",{children:ue(ur,{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"})})]}):ue("div",{className:"flex flex-col h-full gap-8 w-[calc(100%+32px)] mx-[-16px]",children:ue(n6,{style:{maxHeight:"400px",height:"100%"},groupCounts:b.map(y=>y?.length),scrollerRef:y=>{y&&y.addEventListener("scroll",m=>{let c=m.target;N(c.scrollTop<10)})},groupContent:y=>Rt("div",{className:"py-1 bg-t_bg_primary text-t_text_primary",children:[ue("div",{className:"px-4 text-left",children:(()=>{if(t)switch(y){case 0:return re?A.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&&A.length?"My tokens":"All networks";case 1:return"All networks";default:return"Undefined group"}})()}),ue("div",{className:"horizontal-separator"}),!b[y]?.length&&ue("div",{className:"text-center py-1",children:"No token found"})]}),itemContent:y=>w[y]&&ue(rh,{token:w[y],selectedChainId:t?.chainId,selectedTokenAddress:n,onClick:()=>{a(w[y]),o(!1)}})})})})})]})};import{Fragment as o6,jsx as Dn,jsxs as ws}from"react/jsx-runtime";var sh=({chain:t,token:e,type:r,className:n})=>{let{bridgeUI:i,srcChainTokensOptions:a,srcChainOtherTokensOptions:o,dstChainTokensOptions:f,dstChainOtherTokensOptions:d,setSrcToken:p,setSrcChain:h,supportedChains:v,setDstToken:E,setDstChain:S,dstTokenLocked:C,srcTokenLocked:k}=te(),M=Wa(()=>r==="destination"&&C,[r,C]),I=Wa(()=>r==="source"&&k,[r,k]),[F,N]=a6(!1),U=Wa(()=>r==="source"?a:f,[f,a,r]),O=Wa(()=>r==="destination"&&i,[i,r]),R=Wa(()=>r==="source"?o:d,[d,o,r]),W=z=>{let Y=v.find(re=>re.chainId===z.chainId);r==="source"?(p(z),h(Y)):(E(z),S(Y)),N(!1)};return ws(o6,{children:[F&&Dn(Xi,{onClose:()=>N(!1),className:"z-50",children:Dn(ah,{type:r,chain:t,tokens:U,otherTokens:R,selectedTokenAddress:e?.address,onSelect:W,isOpen:F,setModalOpen:N})}),Dn("button",{type:"button",disabled:O||M||I,onClick:()=>{N(!0)},className:`${n||""}`,children:ws("div",{className:"flex justify-between items-center p-4 gap-8 border-r border-solid border-t_text_primary border-opacity-10",children:[ws("div",{className:"flex gap-2 items-center",children:[Dn(In,{token:e,className:"w-9 h-9",generatedLogoClassName:"w-9 h-9 text-[16px]"}),ws("div",{className:"flex flex-col font-medium items-start",children:[Dn("p",{className:"text-xs opacity-60",children:"Token: "}),Dn("p",{className:`${e?"":"opacity-60"}`,children:e?e.symbol:r==="destination"&&i?"-":"Select"})]})]}),!O&&!M&&!I&&Dn("div",{className:"w-4 h-2 fill-t_text_primary",children:Dn(ii,{})})]})})]})};import{jsx as vs,jsxs as of}from"react/jsx-runtime";var sf=({type:t})=>{let{srcChain:e,srcToken:r,dstChain:n,dstToken:i}=te(),a=ch(()=>t==="source"?r:i,[t,r,i]),o=ch(()=>t==="source"?e:n,[t,e,n]);return of("div",{className:"flex flex-col x-border rounded-xl bg-t_bg_tertiary bg-opacity-5",children:[of("div",{className:"flex border-b border-solid border-t_text_primary border-opacity-10",children:[vs(sh,{chain:o,token:a,type:t,className:"w-full flex-grow"}),vs(Yp,{chain:o,type:t,className:"w-full max-w-[160px]"})]}),of("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:[vs(Wp,{type:t}),vs($p,{type:t})]})]})};import{jsx as Ka,jsxs as fh}from"react/jsx-runtime";var dh=()=>fh("div",{className:"flex flex-col gap-6 fill-t_text_primary",children:[fh("div",{className:"flex flex-col gap-[11px]",children:[Ka(sf,{type:"source"}),Ka(Dp,{}),Ka(sf,{type:"destination"})]}),Ka(ds,{}),Ka(Vp,{})]});import{jsx as Cs,jsxs as c6}from"react/jsx-runtime";var cf=({onClose:t})=>{let{tab:e}=te(),r=s6(()=>e==="Settings"?Cs(Lp,{}):e==="History"?Cs(Ip,{}):Cs(dh,{}),[e]);return c6("div",{className:"relative flex flex-col gap-5 p-4 text-t_text_primary bg-t_bg_primary rounded-3xl flex-1",children:[Cs(Mp,{onClose:t}),r]})};import{forwardRef as f6}from"react";import{Fragment as d6,jsx as Xa,jsxs as lh}from"react/jsx-runtime";var oh=f6((t,e)=>{let{inputIcon:r,required:n,name:i,value:a,placeholder:o,type:f,handleChange:d,error:p,warning:h,disabled:v=!1,className:E=""}=t;return lh(d6,{children:[lh("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,Xa("input",{ref:e,disabled:v,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&&Xa("div",{className:"flex justify-between pt-[10px]",children:Xa("div",{className:"px-5 text-t_text_red",children:p})}),h&&Xa("div",{className:"flex justify-between pt-[10px]",children:Xa("div",{className:"px-5 text-t_text_orange",children:h})})]})});import{useState as uh,useEffect as l6,useCallback as As}from"react";var ea=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)}},u6=({expiryTimestamp:t,onExpire:e,autoStart:r=!0})=>{let[n,i]=uh(r),[a,o]=uh(ea.getSecondsFromExpiry(t)),f=As(()=>{let v=ea.getSecondsFromExpiry(t);v<=0&&(e&&e(),i(!1)),o(v)},[t,e]);l6(()=>{if(!n)return;let v=setInterval(f,1e3);return()=>clearInterval(v)},[n,f]);let d=As(()=>i(!1),[]),p=As(()=>i(!0),[]),h=As(v=>{i(!0),o(ea.getSecondsFromExpiry(v))},[]);return{...ea.getTimeFromSeconds(a),isRunning:n,pause:d,resume:p,restart:h}},ph=u6;import{useEffect as p6,useState as h6}from"react";import{Fragment as ff,jsx as Ja,jsxs as x6}from"react/jsx-runtime";var hh=({expiryTimestamp:t,displayFormat:e=2,customTextOnExpire:r})=>{let[n,i]=h6(t.getTime()<Date.now()),{seconds:a,minutes:o,hours:f,days:d,restart:p}=ph({expiryTimestamp:t,onExpire:()=>i(!0)});return p6(()=>{p(t)},[t]),Ja(ff,{children:n&&r?Ja(ff,{children:r}):x6(ff,{children:[e===0&&Ja("span",{children:`${(d*24+f)*60+o}:${a.toString().padStart(2,"0")}`}),e===1&&Ja("span",{children:`${d*24+f}:${o.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`}),e===2&&Ja("span",{children:`${d}:${f.toString().padStart(2,"0")}:${o.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`})]})})};import{useState as b6}from"react";import{jsx as m6}from"react/jsx-runtime";var qa=({tokenName:t,className:e})=>m6("div",{className:`rounded-full bg-white shadow-sm flex items-center justify-center text-black ${e}`,children:t.substring(0,1)});import{jsx as df}from"react/jsx-runtime";var In=({token:t,className:e,generatedLogoClassName:r})=>{let[n,i]=b6(!1);return t?n?df(qa,{tokenName:t.name,className:r}):t?.image?df("img",{src:t.image,alt:t.name,className:`border border-solid border-t_text_primary border-opacity-10 rounded-2xl ${e}`,onError:()=>i(!0)}):df(qa,{tokenName:t.name,className:r}):null};import{jsx as xh,jsxs as g6}from"react/jsx-runtime";var Nn=({token:t,chain:e,tokenLogoClassName:r,generatedLogoClassName:n,chainLogoClassName:i})=>g6("div",{className:"relative flex items-end pr-1 pb-1",children:[xh(In,{token:t,className:r,generatedLogoClassName:n}),e&&xh("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 A6,QueryClientProvider as T6}from"@tanstack/react-query";import{useEffect as lf,useMemo as bh}from"react";import{ErrorBoundary as S6}from"react-error-boundary";import{useReconnect as E6,WagmiProvider as k6}from"wagmi";function y6(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 w6={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"},v6={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"},C6={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"};function mh(t,e){let n={...t?{...w6}:{...v6},...e};for(let[i,a]of Object.entries(n)){let o=C6[i];o&&y6(o,a)}}import{Fragment as yh,jsx as At,jsxs as Ts}from"react/jsx-runtime";var _6=new A6,M6=()=>{let{reconnect:t}=E6();return lf(()=>{let e=0,r=setInterval(()=>{t(),e++,e>=5&&clearInterval(r)},1e3);return()=>{clearInterval(r)}},[t]),At(yh,{})},I6=({onPendingTransactionsChange:t})=>{let{history:e}=_n(),r=bh(()=>e.filter(n=>n.status==="IN_PROGRESS"),[e]);return lf(()=>{t?t(r):window.xPayOnPendingTransactionsChange&&window.xPayOnPendingTransactionsChange(r)},[t,r]),At(yh,{})},uf=({integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,supportedChains:d,onSubmit:p,onClose:h,overlay:v,lightTheme:E,defaultWalletPicker:S,styles:C,onPendingTransactionsChange:k,dstTokenLocked:M,dstChainLocked:I,srcTokenLocked:F,srcChainLocked:N,onDstTokenChange:U,onDstChainChange:O,onSrcTokenChange:R,onSrcChainChange:W,bridge:z,onConnectWallet:Y})=>{let re=Q=>{Q.stopPropagation(),Q.nativeEvent.stopImmediatePropagation(),Q.target===Q.currentTarget&&v&&h()},$=bh(()=>cp(d),[d]);return lf(()=>{mh(E,C)},[E,C]),At(S6,{FallbackComponent:()=>At("div",{children:"Something went wrong, please contact XSwap."}),children:At(k6,{config:$,children:Ts(T6,{client:_6,children:[At(M6,{}),Ts(X1,{children:[At(I6,{onPendingTransactionsChange:k}),At(Y1,{integrationConfig:{integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,defaultWalletPicker:S,dstTokenLocked:M,dstChainLocked:I,srcTokenLocked:F,srcChainLocked:N,onDstTokenChange:U,onDstChainChange:O,onSrcTokenChange:R,onSrcChainChange:W,bridge:z,onConnectWallet:Y},supportedChains:d,wagmiConfig:$,overlay:v,children:At(ep,{children:At(Tp,{children:v?At("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:re,children:Ts("div",{className:"relative bg-t_bg_primary rounded-3xl overflow-auto text-t_text_primary border-2 border-solid border-[rgba(255,255,255,0.1)] w-x_modal min-w-x_modal max-w-x_modal min-h-[532px]",children:[At(cf,{onSubmit:p,onClose:h}),At(qc,{})]})}):Ts("div",{className:"bg-t_bg_primary rounded-3xl overflow-auto text-t_text_primary border-2 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:[At(cf,{onSubmit:()=>{},onClose:()=>{}}),At(qc,{})]})})})})]})]})})})},gh=async({integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,supportedChains:d,lightTheme:p,defaultWalletPicker:h,styles:v,onPendingTransactionsChange:E,dstTokenLocked:S,dstChainLocked:C,srcTokenLocked:k,srcChainLocked:M})=>{try{if(cn===null)throw new Error("XPay was incorrectly initialized");return await ju(),await new Promise(()=>{if(cn===null)throw new Error("XPay was incorrectly initialized");cn.render(At(uf,{integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,supportedChains:d,lightTheme:p,styles:v,onSubmit:()=>{cn&&cn.render("")},onClose:()=>{cn&&cn.render("")},overlay:!0,defaultWalletPicker:h,onPendingTransactionsChange:E,dstTokenLocked:S,dstChainLocked:C,srcTokenLocked:k,srcChainLocked:M}))})}catch(I){throw new Error(`XSwap component error, ${I}`)}};import{faArrowRight as P6,faArrowUpRightFromSquare as N6,faHourglassHalf as R6}from"@fortawesome/free-solid-svg-icons";import{FontAwesomeIcon as xf}from"@fortawesome/react-fontawesome";import{format as B6}from"date-fns";import{useCallback as F6}from"react";import{jsx as pf,jsxs as wh}from"react/jsx-runtime";var hf=({chain:t,token:e,amount:r})=>wh("div",{className:"flex gap-2",children:[pf(Nn,{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"}),wh("div",{className:"flex flex-col text-[12px]",children:[pf("div",{className:"text-t_text_primary text-nowrap",children:`${Number(r)<1e-4?"<0.0001":r} ${e?.symbol?e?.symbol:"unknown"}`}),pf("div",{className:"text-xs text-t_text_primary text-opacity-50",children:t?.displayName})]})]});import{Fragment as L6,jsx as Ut,jsxs as ci}from"react/jsx-runtime";var Ss=({transaction:t,supportedChains:e,srcToken:r,dstToken:n})=>{let a=F6(h=>B6(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 ci("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:[ci("div",{className:"flex items-center gap-2 border-b border-solid border-t_text_primary border-opacity-10 pb-1",children:[Ut("div",{className:"text-xs text-t_text_primary text-opacity-50",children:a}),ci("div",{className:"flex grow justify-end items-center h-6",children:[t.status==="IN_PROGRESS"?ci("div",{className:"flex items-center grow justify-end text-xs",children:[Ut(xf,{icon:R6,className:"w-4 h-4 mr-1 text-t_text_orange"}),ci("div",{className:"text-xs text-t_text_orange min-w-[108px]",children:["In progress (",Ut(hh,{displayFormat:0,expiryTimestamp:new Date(t.estimatedDeliveryTimestamp),customTextOnExpire:"finalizing"}),")"]})]}):t.status==="DONE"?Ut("div",{className:"flex items-center grow justify-end text-xs",children:Ut("div",{className:" mr-1 text-t_text_green",children:"Done"})}):t.status==="REVERTED"?Ut("div",{className:"flex items-center grow justify-end text-xs",children:Ut("div",{className:"w-4 h-4 mr-1 text-t_text_red",children:"Reverted"})}):null,Ut("a",{href:`${t.messageId?`${Vi}${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:Ut(xf,{icon:N6,className:"w-[14px] h-[14px] text-t_text_primary"})})]})]}),Ut("div",{className:"flex flex-wrap gap-8",children:ci("div",{className:"flex items-center gap-2",children:[Ut(hf,{chain:d,token:r,amount:o}),t.tokenOutAddress&&ci(L6,{children:[Ut(xf,{icon:P6,className:"w-5 h-5 text-t_text_primary opacity-50 mx-1.5"}),Ut(hf,{chain:p,token:n,amount:f})]})]})})]})};import{jsx as D6}from"react/jsx-runtime";var Pp=({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 D6(Ss,{transaction:t,supportedChains:e,srcToken:n,dstToken:i})};import{createPortal as O6}from"react-dom";import{jsx as vh}from"react/jsx-runtime";var Sp=({id:t,children:e,onCloseClick:r,type:n="waiting",className:i})=>O6(vh("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:vh("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})}),ti,t);import{useMemo as Ch,useState as U6}from"react";import{Fragment as G6,jsx as Ht,jsxs as mf}from"react/jsx-runtime";var H6=({transaction:t,supportedChains:e,srcToken:r,dstToken:n})=>{let[i,a]=U6(!1),o=Ch(()=>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=Ch(()=>t?.status==="DONE"?"border border-solid border-t_success_dark":"border border-solid border-t_main_accent_dark",[t]);return mf("div",{className:"flex gap-2 items-end justify-end flex-wrap",onClick:()=>a(d=>!d),children:[i&&Ht(Ss,{transaction:t,supportedChains:e,srcToken:r,dstToken:n}),Ht("div",{className:`text-t_text_primary rounded-xl h-14 w-20 mb-2 cursor-pointer ${o} ${f}`,children:mf("div",{className:"flex gap-2 items-center h-14 w-20 justify-center fill-t_text_primary",children:[Ht("div",{className:`${i?"rotate-180":""}`,children:Ht(d1,{})}),Ht("div",{className:"relative flex items-center justify-center w-9 h-9",children:t?.status==="DONE"?Ht("div",{className:"w-5 h-5 fill-t_success_dark",children:Ht(as,{})}):mf(G6,{children:[Ht("div",{className:"w-5 h-5",children:Ht(z1,{})}),Ht("div",{className:"absolute flex items-center justify-center top-0 left-0 right-0 bottom-0 text-t_text_primary",children:Ht(Dr,{className:"w-10 h-10"})})]})})]})})]})},fi=[],Ah=t=>{fi.some(({transaction:e})=>e.hash===e.hash)||fi.push(t)},Th=t=>{fi=[...fi.filter(r=>r.transaction.hash!==t)]},Sh=t=>{fi=fi.map(e=>e.transaction.hash===t?{...e,transaction:{...e.transaction,status:"DONE"}}:e)},Es=()=>{let t=fi.map(e=>Ht(H6,{...e},e.transaction.hash));if(ts===null)throw new Error("XPay was incorrectly initialized");ts.render(Ht("div",{className:"fixed bottom-5 right-2 flex flex-col gap-3 pl-9 items-end w-full z-50",children:t}))};import V6 from"@r2wc/core";import Eh from"react";import{createRoot as z6}from"react-dom/client";var q6=(t,e,r)=>{let n=z6(t),i=Eh.createElement(e,r);return n.render(i),{root:n,ReactComponent:e}},W6=({root:t,ReactComponent:e},r)=>{let n=Eh.createElement(e,r);t.render(n)},K6=({root:t})=>{t.unmount()},kh=(t,e={})=>V6(t,e,{mount:q6,update:W6,unmount:K6});import{useEffect as X6,useState as _h}from"react";import{Fragment as Q6,jsx as ks,jsxs as Z6}from"react/jsx-runtime";var J6=({integratorId:t,dstChain:e,dstToken:r,srcChain:n,srcToken:i,customContractCalls:a=[],desc:o,dstDisplayToken:f,lightTheme:d,defaultWalletPicker:p,styles:h,onPendingTransactionsChange:v,dstTokenLocked:E,dstChainLocked:S,srcTokenLocked:C,srcChainLocked:k,onDstTokenChange:M,onDstChainChange:I,onSrcTokenChange:F,onSrcChainChange:N,onConnectWallet:U,bridge:O})=>{let[R,W]=_h(!0),[z,Y]=_h([]);X6(()=>{(async()=>{W(!0);let $=(await ni()).filter(({web3Environment:Q,bridgeSupported:T,swapSupported:s})=>Q==="mainnet"&&(T||s));Y($),W(!1)})()},[]);let re=(()=>{try{return typeof h=="string"?JSON.parse(h):h||void 0}catch($){console.error("Error parsing styles:",$)}})();return Z6(Q6,{children:[ks("style",{children:Qa}),R?ks("div",{className:"min-h-[532px] w-full flex items-center justify-center",children:ks(Dr,{className:"w-10 h-10"})}):ks(uf,{integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,supportedChains:z,overlay:!1,lightTheme:d,defaultWalletPicker:p,styles:re,onPendingTransactionsChange:v,dstTokenLocked:E,dstChainLocked:S,srcTokenLocked:C,srcChainLocked:k,onDstTokenChange:M,onDstChainChange:I,onSrcTokenChange:F,onSrcChainChange:N,onConnectWallet:U,bridge:O})]})},_s=()=>{if(vt||typeof customElements>"u")return{};let t=kh(J6,{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"}});return t.prototype.connectedCallback=function(){this.id="xpay-widget"},t};import{isServer as Y6}from"@tanstack/react-query";import{useEffect as j6}from"react";import{jsx as eb}from"react/jsx-runtime";var $6=_s();!Y6&&typeof customElements<"u"&&(customElements.get("xpay-widget")||customElements.define("xpay-widget",$6));var bf=({integratorId:t,dstChain:e,dstToken:r,srcChain:n,srcToken:i,customContractCalls:a=[],desc:o,dstDisplayToken:f,lightTheme:d,defaultWalletPicker:p,styles:h,onPendingTransactionsChange:v,dstTokenLocked:E,dstChainLocked:S,srcTokenLocked:C,srcChainLocked:k,onDstTokenChange:M,onDstChainChange:I,onSrcTokenChange:F,onSrcChainChange:N,onConnectWallet:U,bridge:O})=>(j6(()=>{window.xPayOnPendingTransactionsChange=v,window.xPayOnDstTokenChange=M,window.xPayOnDstChainChange=I,window.xPayOnSrcTokenChange=F,window.xPayOnSrcChainChange=N,window.xPayOnConnectWallet=U},[v,M,I,F,N,U]),eb("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":C,"src-chain-locked":k,bridge:O}));import tb from"async-retry";var Mh=async(t,e)=>{let r=t.publicRpcUrls[0],n=new ne.Contract(e.toLowerCase(),Fr,ne.getDefaultProvider(r));try{let i=async(p,h,v=[])=>p?.provider?await p[h](...v):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 mp=async(t,e,r,n)=>{let i=await rb(t,e),a=(await ni()).filter(({web3Environment:W,swapSupported:z})=>W==="mainnet"&&z),o=i.logs?.find(W=>W.topics[0]===ne.utils.id(Lu));if(!o)throw new Error(`No transaction event found for chain ${t} tx ${e}`);let f=o?.topics[1],p=new ne.utils.Interface(Du).parseLog(o);if(!p)throw new Error(`No transaction event arguments found for chain ${t} tx ${e}`);let h=p.args,v=a.find(W=>W.chainId===t.toString());if(!v)throw new Error(`Unknown src chain ${t}`);let E=(h?.token.toString()).toLowerCase(),S=v.tokens.find(W=>W.address.toLowerCase()===E);S||(S=await Mh(v,E));let C=a.find(W=>W.ccipChainId===h?.destinationChainSelector?.toString()),k=C?.chainId;if(!k)throw new Error("Unknown destination chain!");let M;r&&(M=C.tokens.find(W=>W.address.toLowerCase()===r.toLowerCase()));let I=Date.now()/1e3,F={hash:i.transactionHash,timestamp:I,sourceChainId:v.chainId,targetChainId:C.chainId,amountWei:h?.tokenAmount.toString(),tokenAddress:S.address,tokenOutAddress:M?.address,tokenOutAmount:n,estimatedDeliveryTimestamp:h?.valueForInstantCcipRecieve.toString()!=="0"?I*1e3+30*1e3:I*1e3+30*60*1e3,status:"IN_PROGRESS"};Ah({transaction:F,supportedChains:a,dstToken:M,srcToken:S}),Es();let N=_t[k]?.XSwapRouter;if(!N)throw new Error("Unknown destination XSwapRouter!");let U=new ne.Contract(N,Uu,ne.getDefaultProvider(a.find(W=>W.chainId===k)?.publicRpcUrls[0])),O={address:N,topics:[ne.utils.id(Ou),f]},R=async()=>{Sh(e),Es(),await new Promise(W=>setTimeout(()=>W(!0),Fu)),Th(e),Es()};yc({transferId:f}).then(W=>{W.status==="DONE"?R():(setTimeout(()=>yc({transferId:f}).then(z=>{z.status==="DONE"&&R()}),30*60*1e3),U.once(O,()=>R()))})},rb=async(t,e)=>{try{let r=(await ni()).find(i=>i.chainId===t),n=new ne.providers.JsonRpcProvider(r?.publicRpcUrls[0]);return await tb(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 gf=async({integratorId:t,dstChain:e,dstToken:r,srcChain:n,srcToken:i,customContractCalls:a=[],desc:o,dstDisplayToken:f,lightTheme:d,defaultWalletPicker:p,styles:h,onPendingTransactionsChange:v,dstTokenLocked:E,dstChainLocked:S,srcTokenLocked:C,srcChainLocked:k,onDstTokenChange:M,onDstChainChange:I,onSrcTokenChange:F,onSrcChainChange:N,bridge:U})=>{let O=(await ni()).filter(({web3Environment:R,swapSupported:W})=>R==="mainnet"&&W);nb(t,O,e,r,n,i),await gh({integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,supportedChains:O,lightTheme:d,defaultWalletPicker:p,styles:h,onPendingTransactionsChange:v,dstTokenLocked:E,dstChainLocked:S,srcTokenLocked:C,srcChainLocked:k,onDstTokenChange:M,onDstChainChange:I,onSrcTokenChange:F,onSrcChainChange:N,bridge:U})},nb=(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&&(!zi(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&&(!zi(a)||o.tokens.findIndex(({address:f})=>f.toLowerCase()===a.toLowerCase())===-1))throw new Error(`Provided token address ${a} on chain ${i} is invalid`)}};var ib=_s();Yu();var ab={openTransactionModal:gf,TxWidget:bf,TxWidgetWC:ib},YF=ab;export{Cf as ContractName,Kr as Ecosystem,Gh as Environment,di as TxStatus,bf as TxWidget,ib as TxWidgetWC,li as Web3Environment,Af as XSwapCallType,YF as default,gf as openTransactionModal};
|
|
93
93
|
/*! Bundled license information:
|
|
94
94
|
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@ export const Fees: FC = () => {
|
|
|
16
16
|
decimals: feeToken?.decimals || 18,
|
|
17
17
|
precisionFractionalPlaces: 5,
|
|
18
18
|
}) || 0
|
|
19
|
-
} ${feeToken?.symbol}`,
|
|
19
|
+
} ${feeToken?.symbol || ""}`,
|
|
20
20
|
},
|
|
21
21
|
{
|
|
22
22
|
name: "Native Fee: ",
|
|
@@ -26,7 +26,7 @@ export const Fees: FC = () => {
|
|
|
26
26
|
decimals: feeToken?.decimals || 18,
|
|
27
27
|
precisionFractionalPlaces: 5,
|
|
28
28
|
}) || 0
|
|
29
|
-
} ${feeToken?.symbol}`,
|
|
29
|
+
} ${feeToken?.symbol || ""}`,
|
|
30
30
|
},
|
|
31
31
|
...(expressDelivery
|
|
32
32
|
? [
|
|
@@ -38,7 +38,7 @@ export const Fees: FC = () => {
|
|
|
38
38
|
decimals: feeToken?.decimals || 18,
|
|
39
39
|
precisionFractionalPlaces: 5,
|
|
40
40
|
}) || 0
|
|
41
|
-
} ${feeToken?.symbol}`,
|
|
41
|
+
} ${feeToken?.symbol || ""}`,
|
|
42
42
|
},
|
|
43
43
|
]
|
|
44
44
|
: []),
|
|
@@ -51,7 +51,7 @@ export const Fees: FC = () => {
|
|
|
51
51
|
decimals: dstToken?.decimals || 18,
|
|
52
52
|
precisionFractionalPlaces: 5,
|
|
53
53
|
}) || 0
|
|
54
|
-
} ${dstToken?.symbol}`,
|
|
54
|
+
} ${dstToken?.symbol || ""}`,
|
|
55
55
|
},
|
|
56
56
|
];
|
|
57
57
|
|