@xswap-link/sdk 0.9.5 → 0.9.6

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
@@ -89,7 +89,7 @@ nuik2Z3UwnCBNAiE2pBa3qQbD26+YBAnrbNmr4xK8wpDThAKwhdiuoIjum4saQg0VdFRVSxiR01e
89
89
  EEYyDQde+0pTfR+Wmen0BJLu0r6ONsMwNA4n0jC0MEyNMBVG+JhcW37DNCMzk6fe0P6/6ZaOfwAl
90
90
  LqsAAAAldEVYdGRhdGU6Y3JlYXRlADIwMjQtMDUtMjdUMTE6NTQ6MjkrMDA6MDCo6mafAAAAJXRF
91
91
  WHRkYXRlOm1vZGlmeQAyMDI0LTA1LTI3VDExOjU0OjI5KzAwOjAw2bfeIwAAAABJRU5ErkJggg==`})});import A3 from"bignumber.js";import{useSnackbar as T3}from"notistack";import{createContext as S3,useCallback as cs,useContext as E3,useEffect as kc,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",_c=()=>vt?{}:JSON.parse(localStorage.getItem(K1)||"{}"),Mc=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}=s1({delayMs:600});kc(()=>{vt||localStorage.removeItem("transactions-history")},[]);let p=cs(async()=>{try{if(!e)return;let C=await rs({walletAddress:e}),M=[];for(let _ of C.history){if(!_.source)continue;let L;_.failed&&(L="REVERTED"),_.target?L="DONE":L="IN_PROGRESS";let U=new Date(_.source?.blockTime).getTime(),R=Yo;if(new A3(_.source.valueForInstantCcipRecieve||"0").gt(0))R=U+30*1e3;else{let W=U+Jo?.[_.source.blockchainId]?.[_.source.targetBlockchainId];W&&(R=W)}M.push({messageId:_.messageId,hash:_.source.transactionHash,timestamp:U/1e3,sourceChainId:_.source.blockchainId,targetChainId:_.source.targetBlockchainId,amountWei:_.source.tokenAmount,tokenAddress:_.source.tokenAddress,tokenOutAddress:_.target?.tokenAddress||_.source.tokenOutAddress,tokenOutAmount:_.target?.tokenAmount||_.source.estimatedAmountOut,estimatedDeliveryTimestamp:R,status:L})}let I={};for(let _ of M)I[_.hash]=_;let N=_c(),B={};for(let[_,L]of Object.entries(N)){if(_.toLowerCase().toLowerCase()!==e.toLowerCase())continue;let U=[];for(let R of L){if(!I[R.hash]){M.push(R),U.push(R);continue}I[R.hash]&&R.status==="DONE"&&I[R.hash]?.status==="IN_PROGRESS"&&(I[R.hash].status="DONE"),I[R.hash].status==="DONE"||I[R.hash].status}B[_.toLowerCase()]=U}Mc(B),n(M.sort((_,L)=>L.timestamp-_.timestamp))}catch(C){console.error(C),o(qi(_n,{message:{text:"Failed to fetch history!",variant:"error"}}),{persist:!1})}finally{a(!0)}},[e,rs,o]);kc(()=>{i||d(p);let C=setInterval(()=>{d(p)},6e4);return()=>clearInterval(C)},[e,p,rs,d,i]);let h=cs((C,M)=>{n(I=>{let N=I.filter(_=>_.hash!==C.hash),B=_c();return Mc({...B,[M]:[C,...N]}),[C,...N]})},[]),v=cs(C=>{o(qi(_n,{message:{text:"Destination chain transaction mined successfully!",variant:"success",action:()=>M3("div",{className:"flex items-center flex-nowrap",children:[qi(hr,{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=cs((C,M)=>{n(I=>{let N=I.map(_=>_.hash===C.hash&&_.status!=="DONE"?C:_),B=_c();switch(Mc({...B,[M]:[...N]}),C.status){case"DONE":{v(C.hash);break}case"REVERTED":break}return[...N]})},[v]);kc(()=>{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 Mn(){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===Zo)||t[0];if(!e)throw new Error("getDefaultDestinationChain > couldn't find default destination chain");return e},fs=(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())},Ic=t=>t.swapSupported,Pc=({sourceChain:t,targetChain:e})=>{if(!t)throw new Error("isSwapTargetChainValid > sourceChain should be defined.");return e.swapSupported&&!t.disabledForDestination?.includes(e.chainId)},Nc=t=>!t||t.bridgeSupported,Rc=({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||fs(n,uc),o=e.token||fs(i,pc,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(!Ic(n)&&(n=J1({supportedChains:r}),a=void 0,!Ic(n)&&(console.error("[WRONG CONFIG] default swap source chain is invalid."),n=r.find(f=>Ic(f)),!n)))throw new Error("mapToValidSwap > None of the chains supports swap. Couldn't set source chain.");if(!Pc({sourceChain:n,targetChain:i})&&(i=Q1({supportedChains:r}),o=void 0,!Pc({sourceChain:n,targetChain:i})&&(console.error("[WRONG CONFIG] default swap target chain is invalid."),i=r.find(f=>Pc({sourceChain:n,targetChain:f})),!i)))throw new Error("mapToValidSwap > None of the chains supports swap. Couldn't set target chain.");return a||(a=fs(n,uc)),(!o||a===o)&&(o=fs(i,pc,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(!Nc(i)&&(i=void 0,o=void 0,!Nc(i)&&(console.error("[WRONG CONFIG] default bridge source chain is invalid."),i=r.find(d=>Nc(d)),!i)))throw new Error("mapToValidSwap > None of the chains supports bridge. Couldn't set source chain.");if(!Rc({sourceChain:i,targetChain:a,sourceToken:o})&&(a=void 0,f=void 0,!Rc({sourceChain:i,targetChain:a,sourceToken:o})&&(console.error("[WRONG CONFIG] default bridge target chain is invalid."),a=r.find(d=>Rc({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}}},Bc=({type:t,...e})=>t==="SWAP"?P3(e):N3(e);import{jsx as D3}from"react/jsx-runtime";var xt=()=>{throw new Error("Not implemented")},it={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},Y1=B3(it),j1=({children:t,integrationConfig:e,supportedChains:r,wagmiConfig:n,overlay:i})=>{let{address:a,chainId:o}=L3(),[f,d]=$e(it.tab),[p,h]=$e(it.error),[v,E]=$e(it.expressDelivery),[S,C]=$e(it.infiniteApproval),M=dt(()=>!!e?.srcTokenLocked,[e?.srcTokenLocked]),I=dt(()=>!!e?.dstTokenLocked,[e?.dstTokenLocked]),N=dt(()=>!!e?.srcChainLocked,[e?.srcChainLocked]),B=dt(()=>!!e?.dstChainLocked,[e?.dstChainLocked]),_=dt(()=>!!e.bridge,[e.bridge]),[L,U]=$e(it.slippage),[R,W]=$e(it.srcChain),[z,Y]=$e(it.dstChain),[ne,$]=$e(it.feeToken),[J,T]=$e(it.srcToken),[s,l]=$e(it.dstToken),[g,w]=$e(it.srcValue),[A,b]=$e(it.isFetchingBalance),[y,m]=$e(it.srcTokenBalanceWei),[c,x]=$e(it.isFetchingRoute),[F,u]=$e(it.route),[k,P]=$e(""),[O,V]=$e(it.srcChainTokensOptions),[ee,Q]=$e(it.dstChainTokensOptions),[K,Xe]=$e(it.tokenPrices),[j,ae]=$e(it.srcChainOtherTokensOptions),[zr,Ie]=$e(it.dstChainOtherTokensOptions),ve=Z1(null),gr=Z1(crypto.randomUUID()),{history:Pe}=Mn(),[Ne,qr]=$e({});It(()=>{if(r.length>0){let Z=r.map(re=>re.chainId);r1({chainId:Z}).then(re=>{Xe(re)})}},[r]);let Te=dt(()=>{let Z=vt?{}:JSON.parse(localStorage.getItem("custom-tokens")||"{}"),re={};return r.forEach(oe=>{re[oe.chainId]={},oe.tokens.forEach(qe=>{re[oe.chainId][qe.address]=qe})}),bc(re,Z)},[r]),Se=dt(()=>{let Z={};return Object.entries(Te).forEach(([re,oe])=>{Z[re]=Object.entries(oe).filter(([,qe])=>qe.supported).sort(([,qe],[,fe])=>fe.priority-qe.priority).map(([,qe])=>({chainId:re,...qe}))}),Z},[Te]),[yr,Be]=$e([]);It(()=>{(async()=>{let Z=await i1();Be(Z)})()},[]);let xe=dt(()=>{let Z={};for(let re of yr){let[oe,qe]=Object.entries(re)[0],[fe,pe]=Object.entries(re)[1];Z[oe]||(Z[oe]={}),Z[oe][qe]||(Z[oe][qe]={}),Z[oe][qe][fe]=pe,Z[fe]||(Z[fe]={}),Z[fe][pe]||(Z[fe][pe]={}),Z[fe][pe][oe]=qe}return Object.keys(Z).length?Z:null},[yr]),Ft=Ba(Z=>Z?xe&&_?Se[Z]?Se[Z].filter(re=>Object.keys(xe[Z]||{}).includes(re.address)):[]:Se[Z]||[]:[],[xe,_,Se]),Fe=dt(()=>{if(!J||!y||!a)return"";if(Gt(y).eq(0))return"0";let Z=ft({amount:y,decimals:J.decimals,precisionFractionalPlaces:J.decimals});return new R3(Z).lt("0.00001")?"<0.00001":ft({amount:y,decimals:J.decimals,precisionFractionalPlaces:5})},[J,y]),Le=dt(()=>Pe?.find(({hash:Z})=>Z===k),[Pe,k]),Lt=dt(()=>jo({amount:g,decimals:J?.decimals||18}),[J?.decimals,g]),De=dt(()=>J&&R&&K&&K[R.chainId]&&K[R.chainId]?.[J.address]?(Number(g)*Number(K[R.chainId]?.[J.address])).toFixed(2):null,[K,J,g,R]),Ce=dt(()=>ft({amount:F?.estAmountOut||"0",decimals:s?.decimals||18,precisionFractionalPlaces:Math.min(8,s?.decimals||18)}),[F]),Wr=dt(()=>jo({amount:Ce,decimals:s?.decimals||18}),[s?.decimals,Ce]),Oe=dt(()=>s&&z&&K&&K[z?.chainId]&&K[z?.chainId]?.[s.address]?(Number(Ce)*Number(K[z?.chainId]?.[s.address])).toFixed(2):null,[K,s,Ce,z]),Ue=dt(()=>ft({amount:F?.minAmountOut||"0",decimals:s?.decimals||18,precisionFractionalPlaces:Math.min(4,s?.decimals||18)}),[F]),wr=dt(()=>v&&!!F&&X.from(F.xSwapFees?.expressDeliveryFee||"0").gt("0"),[v,F]),He=dt(()=>r.length>0,[r]),ke=Ba(async()=>{if(!R||!z||!J||!s||!Lt||Gt(Lt).eq(0)){u(void 0);return}try{h(""),x(!0),ve.current&&ve.current.abort(hc),ve.current=new AbortController;let Z=await wc({integratorId:e.integratorId,fromChain:R.chainId,toChain:z.chainId,fromAddress:a||Mt[R.chainId]?.FeeCollector||"",toAddress:a||Mt[z.chainId]?.FeeCollector||"",fromToken:J.address,toToken:s.address,fromAmount:Lt,slippage:Number(L),customContractCalls:e.customContractCalls,paymentToken:ir.AddressZero,expressDelivery:v,infiniteApproval:S},ve.current.signal);u(Z),ve.current=null}catch(Z){Z!==hc&&(console.error(Z),h("Could not find route!"),u(void 0))}finally{x(!1)}},[a,z,s,wc,wr,L,R,J,Lt]);It(()=>{ke()},[ke]),It(()=>{a&&r.length>0&&n1({walletAddress:a}).then(Z=>{qr(Z)})},[a,r.length]),It(()=>{(async()=>{let Z=Ft(R?.chainId).filter(({symbol:se})=>z?.chainId===R?.chainId?se!==s?.symbol:!0);V(Z);let re=Ft(z?.chainId).filter(({symbol:se})=>z?.chainId===R?.chainId?se!==J?.symbol:!0);Q(re);let oe=[],qe=r.filter(({chainId:se,web3Environment:de,swapSupported:_e,bridgeSupported:We})=>se===R?.chainId||de!=="mainnet"?!1:_?We:_e);for(let{chainId:se}of qe)oe.push(...Ft(se).filter(({symbol:de})=>se===z?.chainId?de!==s?.symbol:!0));ae(oe);let fe=[],pe=r.filter(({chainId:se,web3Environment:de,swapSupported:_e})=>se!==z?.chainId&&de==="mainnet"&&_e);for(let{chainId:se}of pe)fe.push(...Ft(se).filter(({symbol:de})=>se===R?.chainId?de!==J?.symbol:!0));Ie(fe);let Tt=se=>se.map(de=>({...de,balance:X.from(Ne[de.chainId]?.[de.address]||0)}));V(Tt(Z)),Q(Tt(re)),ae(Tt(oe)),Ie(Tt(fe))})()},[_,R,z,Ft,r,J?.symbol,s?.symbol,Ne]);let nr=Ba(async()=>{if(!a||!R?.publicRpcUrls[0]||!J)return;let Z=crypto.randomUUID();gr.current=Z,b(!0);let re=await mc(a,J.address,R?.publicRpcUrls[0]);Z===gr.current&&(m(jo({amount:re,decimals:J.decimals})),b(!1))},[a,R,J]),Ge=Ba((Z,re)=>Te[re]?.[Z],[Te]);It(()=>{nr()},[nr]),It(()=>{$(R?.tokens.find(({address:Z})=>Z.toLowerCase()===ir.AddressZero.toLowerCase()))},[R]);let[we,Kr]=$e(!1);It(()=>{if(!o||!we||e?.srcChainId)return;let Z=r.find(({chainId:re})=>re===`${o}`);Z&&W(Z)},[o,we,r,e?.srcChainId]),It(()=>{we||(T(void 0),l(void 0),W(void 0),Y(void 0))},[_]),It(()=>{if(we||!r||r.length===0||!xe)return;let Z=e.srcTokenAddr,re=e.dstTokenAddr;Z&&!ie.utils.isAddress(Z)&&(Z=r.find(_e=>_e.chainId===e?.srcChainId)?.tokens.find(_e=>_e.tokenId===e?.srcTokenAddr)?.address?.toLowerCase()),re&&!ie.utils.isAddress(re)&&(re=r.find(_e=>_e.chainId===e?.dstChainId)?.tokens.find(_e=>_e.tokenId===e?.dstTokenAddr)?.address?.toLowerCase());let oe=R||e?.srcChainId||(o?`${o}`:void 0)||(_?void 0:Gi),qe=r.find(({chainId:_e})=>_e===oe),fe;qe&&(fe=qe.tokens.find(({address:_e})=>_e.toLowerCase()===Z?.toLowerCase()));let pe=_?void 0:r.find(({chainId:_e})=>_e===Zo);e.dstChainId&&(pe=r.find(({chainId:_e})=>_e===e.dstChainId));let Tt;pe&&(Tt=pe.tokens.find(({address:_e})=>_e.toLowerCase()===re));let{source:se,target:de}=Bc({source:{chain:qe,token:fe},target:{chain:pe,token:Tt},type:_?"BRIDGE":"SWAP",supportedChains:r,bridgeTokensDictionary:xe});W(se.chain),Y(de.chain),T(se.token),l(de.token),Kr(!0)},[e?.srcChainId,e?.srcTokenAddr,e?.dstChainId,e?.dstTokenAddr,r,_,o,we,xe]),It(()=>{if(!xe||r.length===0||!we)return;let{source:Z,target:re}=Bc({source:{chain:R,token:J},target:{chain:z,token:s},type:_?"BRIDGE":"SWAP",supportedChains:r,bridgeTokensDictionary:xe});Z.chain?.chainId!==R?.chainId&&W(Z.chain),re.chain?.chainId!==z?.chainId&&Y(re.chain),Z.token?.address!==J?.address&&T(Z.token),re.token?.address!==s?.address&&l(re.token)},[R,J,z,s,_,r,xe]),It(()=>{e.onDstChainChange?e.onDstChainChange(z?.chainId):window.xPayOnDstChainChange&&window.xPayOnDstChainChange(z?.chainId)},[e.onDstChainChange,z]),It(()=>{let Z=s?{address:s.address.toLowerCase(),symbol:s.tokenId}:void 0;e.onDstTokenChange?e.onDstTokenChange(Z):window.xPayOnDstTokenChange&&window.xPayOnDstTokenChange(Z)},[e.onDstTokenChange,s]),It(()=>{e.onSrcChainChange?e.onSrcChainChange(R?.chainId):window.xPayOnSrcChainChange&&window.xPayOnSrcChainChange(R?.chainId)},[e.onSrcChainChange,R]),It(()=>{let Z=J?{address:J.address.toLowerCase(),symbol:J.tokenId}:void 0;e.onSrcTokenChange?e.onSrcTokenChange(Z):window.xPayOnSrcTokenChange&&window.xPayOnSrcTokenChange(Z)},[e.onSrcTokenChange,J]);let Ve=Ba(()=>{e.onConnectWallet?e.onConnectWallet():window.xPayOnConnectWallet&&window.xPayOnConnectWallet()},[e]),ze=dt(()=>!!(e.onConnectWallet||window.xPayOnConnectWallet),[e.onConnectWallet]);return D3(Y1.Provider,{value:{bridgeUI:_,integrationConfig:e,wagmiConfig:n,supportedChains:r,tab:f,setTab:d,overlay:i,error:p,setError:h,feeToken:ne,srcChain:R,setSrcChain:W,srcChainTokensOptions:O,srcChainOtherTokensOptions:j,tokenPrices:K,dstChain:z,setDstChain:Y,dstChainTokensOptions:ee,dstChainOtherTokensOptions:zr,srcToken:J,setSrcToken:T,dstToken:s,setDstToken:l,srcValue:g,setSrcValue:w,srcValueWei:Lt,srcValueUsd:De,dstValue:Ce,dstValueWei:Wr,dstValueUsd:Oe,dstValueMin:Ue,lastTx:Le,setLastTxHash:P,expressDelivery:v,setExpressDelivery:E,infiniteApproval:S,setInfiniteApproval:C,slippage:L,setSlippage:U,route:F,setRoute:u,isAsyncDataLoaded:He,srcTokenBalanceWei:y,setSrcTokenBalanceWei:m,srcTokenBalanceInfo:Fe,isFetchingRoute:c,isFetchingBalance:A,isExpressDeliveryActive:wr,quoteRoute:ke,refreshBalance:nr,findTokenDataByAddressAndChain:Ge,srcTokenLocked:M,srcChainLocked:N,dstTokenLocked:I,dstChainLocked:B,bridgeTokensDictionary:xe,onConnectWallet:Ve,hasOnConnectWalletCallback:ze},children:t})},te=()=>F3(Y1);import{jsx as Tk}from"react/jsx-runtime";var In={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")}},Ck=O3({rank:In.rank,setRank:In.setRank,xPower:In.xPower,updateXPower:In.updateXPower,xSwapBalance:In.xSwapBalance,updateXSwapBalance:In.updateXSwapBalance,unfinishedQuestsCount:In.unfinishedQuestsCount,setUnfinishedQuestsCount:In.setUnfinishedQuestsCount});import{createContext as U3,useCallback as $1,useContext as H3,useMemo as G3}from"react";import{jsx as V3}from"react/jsx-runtime";var ep=U3({}),tp=({children:t})=>{let e=$1(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=$1(({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(ep.Provider,{value:n,children:t})};function rp(){return H3(ep)}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 Xo.Web3Provider(r,"any").getSigner(e.address)}async function np({chainId:t}={}){let{data:e}=q3({chainId:t});return z3(()=>e?W3(e):void 0,[e])}var Z3=()=>{let[t,e]=J3(),r=np();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 xp}from"react";import{useMemo as $3,useState as e5}from"react";import{jsx as Fc,jsxs as Y3}from"react/jsx-runtime";var ip=()=>{let{isExpressDeliveryActive:t}=te();return Y3("div",{className:"flex items-center",children:[Fc("div",{className:`w-4 h-4 mr-1 ${t?"fill-t_success_light":"fill-t_text_primary opacity-50"} `,children:Fc(B1,{})}),Fc("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 Lc,jsxs as j3}from"react/jsx-runtime";var ap=({name:t,value:e})=>{let{isFetchingRoute:r}=te();return j3("div",{className:"flex gap-x-1 justify-between text-xs font-medium",children:[Lc("div",{className:"opacity-60",children:t}),Lc("div",{children:r?Lc(xr,{className:"w-[60px] h-full"}):e})]})};import{jsx as Dc}from"react/jsx-runtime";var op=()=>{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 Dc("div",{className:"border-t border-solid border-t_text_primary border-opacity-10 pt-3 mt-3",children:Dc("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})=>Dc(ap,{name:o,value:f},o))})})};import{jsx as mr,jsxs as ds}from"react/jsx-runtime";var ls=()=>{let[t,e]=e5(!1),{route:r,feeToken:n,isFetchingRoute:i,srcChain:a,dstChain:o}=te(),f=$3(()=>{if(!r)return"0";let d=Gt(r.xSwapFees.ccipFee||"0").add(Gt(r.xSwapFees.xSwapFee.nativeFee||"0")).add(Gt(r.xSwapFees.expressDeliveryFee||"0")).toString();return ft({amount:d,decimals:n?.decimals||18,precisionFractionalPlaces:5})},[n?.decimals,r]);return mr("div",{className:"flex flex-col x-border rounded-xl py-2 px-4 bg-t_bg_tertiary bg-opacity-5",children:ds("button",{"aria-label":`${t?"Collapse":"Expand"} fees panel`,type:"button",onClick:()=>e(d=>!d),children:[ds("div",{className:"flex justify-between",children:[ds("div",{className:"flex gap-2 items-center text-xs font-medium sm:text-sm fill-t_text_primary",children:[mr(L1,{}),mr("p",{className:"opacity-60",children:"Fee: "}),i?mr(xr,{className:"w-[100px] h-full"}):mr("p",{children:`${f} ${n?.symbol||""}`})]}),ds("div",{className:"flex gap-2 items-center fill-t_text_primary",children:[r&&!i&&a?.chainId!==o?.chainId&&mr(ip,{}),t?mr("div",{className:"w-4 h-2 rotate-180",children:mr(ii,{})}):mr("div",{className:"w-4 h-2",children:mr(ii,{})})]})]}),t&&mr(op,{})]})})};import{jsx as us}from"react/jsx-runtime";var sp=()=>us("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-14 p-1 border border-solid border-t_text_primary border-opacity-10 rounded-xl bg-t_bg_secondary",children:us("div",{className:"relative bg-gradient-to-r from-t_main_accent_light to-t_main_accent_dark w-8 h-8 rounded-xl",children:us("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 fill-white",children:us(is,{})})})});import*as t5 from"viem/chains";import{mainnet as cp}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}),fp=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=[cp];return e.push(...Object.values(t5).filter(r=>r.id!==cp.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 dp}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]=dp({top:0,left:0}),[o,f]=dp(!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 lp}from"react/jsx-runtime";var up=({onCloseClick:t})=>{let e=x5(null);return lp("div",{className:"flex justify-between items-center text-base font-medium",children:[Fa("div",{className:"text-t_text_primary",children:"Confirmation"}),lp("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 pp}from"react";import{jsx as Ct,jsxs as Oc}from"react/jsx-runtime";var hp=()=>{let{txStatus:t,txNeedsApproval:e,txMsg:r}=Gr(),n=pp(()=>[{icon:a=>Ct("div",{className:`${a}`,children:Ct(Sc,{})}),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(Ec,{})}),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(Sc,{})}),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(Ec,{})}),title:"confirming transaction...",state:t===4?"triggered":t>4?"completed":"none",show:r?t===3||t===4:!0}],[r,e,t]),i=pp(()=>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)=>Oc("div",{className:"flex flex-col px-4 gap-1",children:[Oc("div",{className:"flex justify-between items-center",children:[Oc("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 ps}from"react";import{jsx as La,jsxs as Da}from"react/jsx-runtime";var Uc=({type:t})=>{let{srcToken:e,srcChain:r,dstToken:n,dstChain:i,srcValue:a,srcValueUsd:o,dstValue:f,dstValueUsd:d}=te(),p=ps(()=>t==="source"?e:n,[n,e,t]),h=ps(()=>t==="source"?r:i,[i,r,t]),v=ps(()=>t==="source"?a:f,[f,a,t]),E=ps(()=>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(Pn,{token:p,className:"w-9 h-9",generatedLogoClassName:"w-9 h-9"})]})]})};import{Fragment as m5,jsx as Nn,jsxs as Hc}from"react/jsx-runtime";var mp=({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}=Gr(),{addTransactionToLocalHistory:M,updateTransactionInLocalHistory:I}=Mn(),{networks:{evm:{signer:N}}}=Wi(),B=Ma(),_=xp(async U=>{if(!r||!i||!n||!a||!d)return;let R={hash:U.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+Jo?.[r?.chainId]?.[i?.chainId]||Yo,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)",ne="MessageReceived(bytes32,uint64,address,bytes)",$=ie.getDefaultProvider(e.find(T=>T.ecosystem==="evm"&&T.chainId===i.chainId)?.publicRpcUrls[0]),J=async(T,s,l)=>{let g=U.logs?.find(w=>w.topics[0]===ie.utils.id(s));if(g){let w=g?.topics[1];R.messageId=w;let A=new ie.Contract(Mt[i?.chainId]?.[T],T==="XSwapRouter"?zu:qu,$),b={address:Mt[i.chainId]?.[T],topics:[ie.utils.id(l),w]};(await A.queryFilter(b)).length>0?(R.status="DONE",I(R,U.from)):A.once(b,()=>{R.status="DONE",I(R,U.from)})}};await J("XSwapRouter",W,z),await J("CustomXSwapRouter",Y,ne)}M(R,U.from)},[M,I,r,i,n,a,o,f,e,d]),L=xp(async()=>{if(n&&d){let U=()=>{S({executeTransaction:()=>{if(!(!d.transactions.swap||!N))return B.executeCalldata(N,d.transactions.swap)},txStatus:3,handlers:{onSuccess:R=>{v(5),p(),_(R),r?.chainId&&i?.chainId&&r?.chainId!==i?.chainId&&bp(r?.chainId,R.transactionHash,a?.address,f)}}})};n.address!==ir.AddressZero&&d.transactions.approve?(C(!0),S({executeTransaction:()=>{if(!(!d.transactions.approve||!N))return B.executeCalldata(N,d.transactions.approve)},txStatus:1,handlers:{onSuccess:()=>U()}})):(C(!1),U())}},[n,d,S,N,B,v,p,_,r?.chainId,i?.chainId,a?.address,f,C]);return Hc("div",{className:"flex flex-col text-t_text_primary gap-5",children:[Nn(up,{onCloseClick:t}),E?Nn("div",{children:E}):Hc(m5,{children:[Hc("div",{className:"relative flex flex-col gap-5 fill-white",children:[Nn(Uc,{type:"source"}),Nn(sp,{}),Nn(Uc,{type:"destination"})]}),Nn(ls,{})]}),h===0?Nn(hr,{variant:"filled-squared",onClick:()=>{L()},type:"button",className:"text-white border-none h-14 text-sm font-bold w-full py-5 cursor-pointer bg-gradient-to-r from-t_main_accent_light to-t_main_accent_dark rounded-lg",children:"Sign and swap"}):Nn(hp,{})]})};import{jsx as Gc,jsxs as gp}from"react/jsx-runtime";var Vc=({chain:t,token:e,value:r})=>gp("div",{className:"flex items-center gap-2",children:[Gc(Rn,{chain:t,token:e,chainLogoClassName:"w-5",tokenLogoClassName:"w-9 h-9",generatedLogoClassName:"w-9 h-9 text-[16px]"}),gp("div",{className:"flex flex-col w-min sm:w-auto",children:[Gc("div",{children:`${r} ${e?.symbol}`}),Gc("div",{className:"opacity-60",children:t?.displayName})]})]});import{Fragment as yp,jsx as mt,jsxs as Oa}from"react/jsx-runtime";var wp=({onCloseClick:t})=>{let{txError:e,txExplorerUrl:r,txMsg:n}=Gr(),{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(yp,{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(C1,{}),mt("div",{className:"text-2xl font-bold",children:"Transaction failed"}),mt("div",{className:"text-center",children:e})]}):Oa(yp,{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(Vc,{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(Vc,{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(E1,{})]})]})})};import{jsx as vp}from"react/jsx-runtime";var Cp=({onCloseClick:t})=>{let{txStatus:e,txError:r}=Gr();return e===5||r?vp(wp,{onCloseClick:t}):vp(mp,{onCloseClick:t})};import{useSnackbar as b5}from"notistack";import{createContext as g5,useCallback as Ua,useContext as y5,useEffect as w5,useMemo as zc,useRef as Ap,useState as dn}from"react";import{useAccount as v5}from"wagmi";import{jsx as rr,jsxs as qc}from"react/jsx-runtime";var Tp=g5({}),Sp=({children:t})=>{let{chainId:e}=v5(),{enqueueTransaction:r}=rp(),{enqueueSnackbar:n,closeSnackbar:i}=b5(),[a,o]=dn("evm"),f=Ap(!1),[d,p]=dn(!1),[h,v]=dn(""),E=Ap(),[S,C]=dn(""),[M,I]=dn(""),[N,B]=dn(void 0),[_,L]=dn(!1),[U,R]=dn(!1),[W,z]=dn(0),{supportedChains:Y,setSrcValue:ne}=te(),$=y=>{E.current===y&&(f.current=!1,p(!1))};w5(()=>{if(!d&&(S&&(n(rr(_n,{message:{text:S,variant:"error"}})),C("")),_&&h)){let y=h;n(rr(_n,{message:{text:`Transaction ${Ku(h)} is about to be mined!`,variant:"warning",action:()=>qc("div",{className:"flex items-center flex-nowrap",children:[rr(hr,{type:"button",onClick:()=>{window.open(`${Y.find(m=>m.chainId===e?.toString()&&m.ecosystem===a)?.transactionExplorer}/${h}`||"")},children:"Check"}),rr("div",{className:"fill-t_text_primary w-[14px] h-[14px] cursor-pointer p-[14px] leading-[0px]",onClick:()=>i(y),children:rr(ot,{})})]}),animation:()=>rr(Vr,{className:"w-4 h-4"})}}),{persist:!0,key:y}),v("")}},[_,a,h,S,n,i,e,d,Y]);let J=Ua((y,m,c)=>{let x=`${m}/${y}`;if(c){let u=c.events?.find(k=>k.event==="MessageSent")?.args?.messageId;return u?`${Vi}${u}`:x}else return x},[]),T=Ua((y,m,c=!0)=>{let x={...m};return x.onConfirm=F=>{E.current===y&&(m?.onConfirm&&m?.onConfirm(F),v(F?.hash||""),z(u=>u+1))},x.onSuccess=F=>{if(i(F?.transactionHash),E.current===y){if(B(F),!f.current&&c){let u=`${h}-success`;n(rr(_n,{message:{text:"Transaction mined successfully!",variant:"success",action:()=>qc("div",{className:"flex items-center flex-nowrap",children:[rr(hr,{type:"button",onClick:()=>{window.open(J(h,Y.find(k=>k.chainId===e?.toString()&&k.ecosystem===a)?.transactionExplorer||"",F))},children:"View"}),rr("div",{className:"fill-t_text_primary w-[14px] h-[14px] cursor-pointer p-[14px] leading-[0px]",onClick:()=>i(u),children:rr(ot,{})})]})}}),{persist:!1,key:u})}m?.onSuccess&&m?.onSuccess(F),C(""),L(!1)}},x.onError=F=>{E.current===y&&(C(Xu(F)),m?.onError?.(F),L(!1))},x},[i,h,n,J,Y,e,a]),s=Ua(({executeTransaction:y,txStatus:m,txMsg:c="",handlers:x,network:F="evm",showDefaultSuccessMessage:u=!0})=>{let k=Date.now(),P=x;return F==="evm"&&(P=T(k,x,u)),r({executeTransaction:y,txStatus:m,handlers:P,network:F}),E.current=k,f.current=!0,v(""),C(""),I(c),z(m),B(void 0),L(!0),o(F),p(!0),k},[T,r]),l=zc(()=>J(h,Y.find(y=>y.chainId===e?.toString()&&y.ecosystem===a)?.transactionExplorer||"",N),[e,a,J,Y,h,N]),g=Ua(y=>{p(y),f.current=y},[]),w=zc(()=>S?"error":W===5?"success":"neutral",[S,W]),A=zc(()=>({enqueueTransaction:s,closeTransactionModal:$,isTxModalOpen:d,setTxModalOpen:p,loading:_,txStatus:W,setTxStatus:z,txExplorerUrl:l,txHash:h,txError:S,txMsg:M,setTxMsg:I,setTxError:C,txNeedsApproval:U,setTxNeedsApproval:R}),[s,d,_,W,l,h,S,M,U]),b=Ua(()=>{C(""),ne(""),g(!1)},[C,ne,g]);return qc(Tp.Provider,{value:A,children:[d&&rr(Ep,{id:"tx_modal",className:"max-w-x_modal",type:w,onCloseClick:b,children:rr(Cp,{onCloseClick:b})}),t]})};function Gr(){return y5(Tp)}import{jsx as kp}from"react/jsx-runtime";var Xi=({className:t,children:e,onClose:r})=>{let{overlay:n}=te();return kp("div",{className:`${n?"fixed bg-[rgba(0,0,0,0.8)]":"absolute"} top-0 left-0 right-0 bottom-0 flex items-center justify-center z-10 ${t||""}`,onMouseDown:i=>{i.target===i.currentTarget&&n&&(i.stopPropagation(),i.nativeEvent.stopImmediatePropagation(),i.preventDefault(),r())},children:kp("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 hs}from"react/jsx-runtime";var Wc=()=>hs("div",{className:"flex justify-center items-center gap-2 my-3",children:[oi("span",{className:"text-t_text_primary opacity-50",children:"Powered by"}),hs("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"}),hs("div",{className:"flex items-center gap-1",children:[oi(h1,{}),hs("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 xr=({className:t})=>E5("div",{className:`bg-t_bg_tertiary bg-opacity-15 rounded animate-pulse ${t||""}`});import{jsx as Kc,jsxs as k5}from"react/jsx-runtime";var Vr=({className:t})=>Kc("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:[Kc("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"}),Kc("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 d6}from"react";import{Fragment as _5,jsx as ln,jsxs as M5}from"react/jsx-runtime";var _p=({onClose:t})=>{let{tab:e,setTab:r,overlay:n}=te();return ln("div",{className:"flex gap-5 items-center",children:e==="Swap"?M5(_5,{children:[ln("button",{type:"button",onClick:()=>r("Settings"),"aria-label":"Open settings",className:"fill-white",children:ln(_1,{})}),ln("button",{type:"button",onClick:()=>r("History"),"aria-label":"Open history",className:"fill-white",children:ln(T1,{})}),n&&ln("button",{type:"button",onClick:()=>t(),"aria-label":"Close",className:"fill-t_text_primary",children:ln(ot,{})})]}):ln("button",{type:"button",onClick:()=>{r("Swap")},"aria-label":"Switch to swap view",className:"fill-t_text_primary",children:ln(ot,{})})})};import{jsx as Mp,jsxs as I5}from"react/jsx-runtime";var Ip=({onClose:t})=>{let{tab:e,bridgeUI:r}=te();return I5("div",{className:"flex justify-between mt-2 px-4",children:[Mp("div",{className:"text-xl font-sans-bold font-bold",children:e==="Swap"&&r?"Bridge":e}),Mp(_p,{onClose:t})]})};import{useMemo as P5}from"react";import{Virtuoso as N5}from"react-virtuoso";import{jsx as Ji}from"react/jsx-runtime";var Pp=()=>{let{history:t,historyLoadedOnce:e}=Mn(),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(Vr,{className:"w-8 h-8"})}):Ji(N5,{data:t,style:{height:"532px"},itemContent:(n,i)=>Ji(Np,{transaction:i})}),[t,e]);return Ji("div",{className:"flex-1 overflow-hidden",children:r})};import{jsx as Xc,jsxs as R5}from"react/jsx-runtime";var Ga=({checked:t,onClick:e})=>Xc("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:[Xc("span",{className:"h-full w-full rounded-lg bg-t_bg_tertiary bg-opacity-30"}),Xc("span",{className:`transition-all w-5 h-5 rounded-full absolute translate-y-[-4px]
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 Rp}from"react/jsx-runtime";var Bp=()=>{let t=B5(null),{infiniteApproval:e,setInfiniteApproval:r}=te();return Rp("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:Rp("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 xs}from"react/jsx-runtime";var Fp=()=>{let t=F5(null),{expressDelivery:e,setExpressDelivery:r}=te();return xs("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"}),xs("div",{className:"flex gap-2 items-center justify-between flex-wrap",children:[xs("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]"})]}),xs("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 Bn,jsxs as ms}from"react/jsx-runtime";var Lp=()=>{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 ms("div",{className:"flex flex-col gap-5 pt-5 border-t border-solid border-t_text_primary border-opacity-10",children:[Bn("h1",{className:"text-sm font-medium text-left",children:"Slippage"}),ms("div",{className:"flex items-center gap-2 w-full",children:[Bn("div",{className:"flex items-center bg-t_bg_tertiary bg-opacity-5 p-1 border border-solid border-t_text_primary border-opacity-10 rounded-xl gap-2",children:["0.5","1.5","3.0"].map(f=>Bn("button",{type:"button",onClick:()=>i(f),className:`block rounded-lg text-sm bg-transparent h-7 px-1 hover:bg-gradient-to-r hover:from-t_main_accent_light hover:to-t_main_accent_dark hover:opacity-100 ${t===f?"gradient-slippage-container-blue text-white opacity-100":"text-t_text_primary opacity-20"}`,children:`${f}%`},f))}),Bn("div",{className:`${r?"gradient-slippage-container-blue p-[1px] rounded-xl":""}`,children:ms("div",{className:"bg-t_bg_primary p-1 h-full border border-solid border-t_text_primary border-opacity-10 rounded-xl",children:[Bn(Ha,{id:"slippage-input",placeholder:"1.5",regex:Qo,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"} `})," ","%"]})})]}),ms("div",{className:"text-sm opacity-60",children:[Bn("p",{children:"Slippage is the price variation you are willing to accept in the event that the price of the trade changes while it is processing."}),Bn("br",{}),Bn("p",{children:"If the trade fails due to too low slippage, you will receive USDC on the destination chain."})]})]})};import{jsx as Jc,jsxs as D5}from"react/jsx-runtime";var Dp=()=>D5("div",{className:"flex flex-col gap-5",children:[Jc(Fp,{}),Jc(Bp,{}),Jc(Lp,{})]});import{jsx as Va}from"react/jsx-runtime";var Op=()=>{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(p1,{})})})})})};var Qc={1:["0xdac17f958d2ee523a2206206994597c13d831ec7"]};import{useCallback as Zc,useMemo as O5}from"react";var Up=({rpcChainId:t,currentChainId:e,signer:r,tokenAddress:n})=>{let i=Cc(),{supportedChains:a}=te(),o=O5(()=>{let f=a.find(d=>d.ecosystem==="evm"&&d.chainId===t)?.publicRpcUrls[0];return f&&n?new ie.Contract(n,Hr,r&&(!e||e===t)?r:ie.getDefaultProvider(f)):null},[t,e,r,n,a]);return{balanceOf:Zc(async f=>await i.query(o,"balanceOf",[f]),[o,i]),allowance:Zc(async(f,d)=>await i.query(o,"allowance",[f,d]),[o,i]),approve:Zc(async(f,d)=>await i.execute(o,"approve",[d,f]),[o,i])}};import{useCallback as Gp,useEffect as z5,useMemo as Yi,useState as Vp}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 un,jsxs as Yc}from"react/jsx-runtime";var V5=({connector:t,className:e})=>{switch(t.name){case"WalletConnect":return un(H1,{className:`w-[34px] h-[34px] rounded-md ${e||""}`});default:return un("img",{src:t.icon,alt:t.name,className:`w-[34px] h-[34px] rounded-md ${e||""}`})}},Hp=({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 Yc("div",{className:`flex flex-col h-full ${t||""}`,children:[Yc("div",{className:"flex justify-between",children:[un("div",{className:"text-base/4 mb-4 text-t_text_primary",children:"Pick wallet"}),un("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:e,children:un(ot,{})})]}),un("div",{className:"horizontal-separator"}),un("div",{className:"h-full pt-4",children:i.map(o=>Yc("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:[un(V5,{connector:o}),un("div",{className:"text-t_text_primary",children:o.name})]},o.id))})]})};import{Fragment as K5,jsx as jc,jsxs as X5}from"react/jsx-runtime";var zp=()=>{let{address:t,chainId:e}=q5(),{switchChainAsync:r}=W5(),[n,i]=Vp(!1),{integrationConfig:a}=te(),{bridgeUI:o,error:f,srcChain:d,dstChain:p,srcToken:h,dstToken:v,srcValueWei:E,srcTokenBalanceWei:S,isFetchingRoute:C,isAsyncDataLoaded:M,hasOnConnectWalletCallback:I,onConnectWallet:N}=te(),{setTxStatus:B,setTxMsg:_,setTxModalOpen:L,enqueueTransaction:U}=Gr(),R=Yi(()=>d?.chainId,[d?.chainId]),W=Yi(()=>p?.chainId,[p?.chainId]),z=Yi(()=>h?.address,[h?.address]),Y=Yi(()=>v?.address,[v?.address]),[ne,$]=Vp("0"),{networks:{evm:J}}=Wi(),{allowance:T,approve:s}=Up({rpcChainId:R,currentChainId:J.chainId,signer:J.signer,tokenAddress:z}),l=Yi(()=>R?R===W?Mt[R]?.XSwapRouterSingleChain||"":Mt[R]?.XSwapRouter||"":"",[R,W]),g=Gp(async()=>{if(l&&J.address)try{let b=await T(J.address,l);$(b.toString())}catch{$("0")}else $("0")},[T,J.address,l]);z5(()=>{R&&Qc[R]?.includes(z)&&g()},[g,R,z]);let w=Gp(()=>{B(0),_(""),L(!0)},[L,_,B]),A=Yi(()=>M?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&&Gt(E).gt(Gt(S))?{text:"Insufficient Balance",fn:()=>{},disabled:!0}:Gt(E||"0").lte(Gt("0"))?{text:"Enter Token Amount",fn:()=>{},disabled:!0}:C?{text:"Fetching Route",fn:()=>{},disabled:!0}:Qc[R]?.includes(z)&&ne!=="0"&&X.from(ne).lt(X.from(E))?{text:"Reset Approval",fn:async()=>{U({executeTransaction:()=>s("0",l),txStatus:1,txMsg:"You are going to reset your approval",handlers:{onSuccess:()=>{g(),B(5)}}})},disabled:!1}:{text:o?"Bridge":"Swap",fn:async()=>{w()},disabled:!1}:{text:a.defaultWalletPicker||I?"Connect Wallet":"Connect Wallet First",fn:()=>{a.defaultWalletPicker?i(!0):I&&N()},disabled:!a.defaultWalletPicker&&!I}:{text:"Loading XPay...",fn:()=>{},disabled:!0},[M,f,t,R,W,z,Y,e,E,S,C,ne,o,a.defaultWalletPicker,r,U,s,l,g,B,w]);return X5(K5,{children:[n&&jc(Xi,{onClose:()=>i(!1),children:jc(Hp,{onClose:()=>i(!1)})}),jc("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 $c,jsxs as J5}from"react/jsx-runtime";var qp=()=>{let{srcTokenBalanceInfo:t,isFetchingBalance:e}=te();return J5("div",{className:"flex flex-col items-end",children:[$c("p",{className:"text-xs font-medium opacity-60",children:"Balance:"}),e?$c(xr,{className:"w-[50px] h-[16px]"}):$c("p",{className:`text-xs font-medium ${!t&&"opacity-60"}`,children:t||"-"})]})};import{Fragment as Wp,jsx as Fn,jsxs as bs}from"react/jsx-runtime";var Kp=({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 bs("div",{className:"flex justify-between items-center w-full p-4 gap-8 overflow-hidden",children:[Fn("div",{className:"flex flex-col font-medium w-full overflow-hidden text-left",children:t==="source"?bs(Wp,{children:[Fn(Ha,{id:"swap-amount-input",className:"bg-transparent border-none p-0 text-xl outline-0 font-sans-bold font-bold",regex:Qo,value:e,onChange:d=>a(d)}),f&&Fn("div",{className:"text-sx opacity-60",children:`$${f}`})]}):o?bs("div",{className:"flex flex-col gap-1",children:[Fn(xr,{className:"w-[150px] h-[30px]"}),Fn(xr,{className:"w-[100px] h-[20px]"})]}):bs(Wp,{children:[Fn("div",{className:"text-xl text-t_text_secondary font-sans-bold font-bold",children:n||0}),f&&Fn("div",{className:"text-sx opacity-60",children:`$${f}`})]})}),t==="source"&&Fn(qp,{})]})};import{useCallback as Zp,useMemo as Yp,useState as e6}from"react";import{useMemo as rf,useState as Z5,useRef as Y5,useEffect as j5}from"react";import{Virtuoso as $5}from"react-virtuoso";import{useMemo as ef}from"react";import{jsx as ji,jsxs as tf}from"react/jsx-runtime";var Xp=({chain:t,type:e,onClick:r,disabled:n})=>{let{networks:{evm:i}}=Wi(),{srcChain:a,dstChain:o,bridgeUI:f}=te(),d=ef(()=>e==="source"?a?.chainId:o?.chainId,[o,a,e]),p=ef(()=>i.signer&&i.chainId===t.chainId,[t.chainId,i.chainId,i.signer]),h=ef(()=>{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:tf("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:[tf("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&&tf("div",{className:"flex items-baseline gap-1",children:[ji(w1,{}),ji("div",{className:"text-t_text_green",children:"connected"})]})]})})};import{jsx as br,jsxs as Jp}from"react/jsx-runtime";var Qp=({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,E]=Z5(""),S=Y5(null);j5(()=>{S.current&&setTimeout(()=>{S.current?.focus()},10)},[]);let C=rf(()=>{let B=h.filter(({web3Environment:_,swapSupported:L,bridgeSupported:U})=>_==="mainnet"&&(d&&U||!d&&L));return v?B.filter(_=>{let L=v.toLowerCase();return _.displayName.toLowerCase().includes(L)||_.chainId.toLowerCase().includes(L)}):B},[d,h,v]),M=B=>{let _=h.find(({chainId:L})=>L===B);if(!_)throw new Error("ChainPicker > selected chain id that is absent in supportedChains list.");t==="source"?e(_):r(_),n()},I=rf(()=>{if(!i?.chainId||!a?.address)return[];if(!d){let B=h.find(_=>_.chainId===i.chainId)?.disabledForDestination||[];return t==="destination"?C?.filter(_=>B.includes(_.chainId)).map(({chainId:_})=>_):[]}if(t==="destination"){let B=p?.[i.chainId]?.[a.address];return C?.filter(L=>!B?.[L.chainId]).map(({chainId:L})=>L)}else{if(!o||!f)return[];let B=p?.[o.chainId]?.[f.address];return C?.filter(L=>!B?.[L.chainId]).map(({chainId:L})=>L)}},[p,d,C,i,a,o,f,t,h]),N=rf(()=>C.map(B=>({...B,disabled:I.includes(B.chainId)})).sort((B,_)=>B.disabled===_.disabled?0:B.disabled?1:-1),[C,I]);return Jp("div",{className:"flex flex-col h-full",children:[Jp("div",{className:"flex justify-between",children:[br("div",{className:"text-base/4 text-t_text_primary mb-4",children:`Pick ${t} chain`}),br("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:n,children:br(ot,{})})]}),br(gs,{ref:S,inputIcon:br("div",{className:"fill-t_text_primary",children:br(os,{})}),placeholder:"Search chain name",value:v,handleChange:E}),br("div",{className:"horizontal-separator mt-4"}),br("div",{className:"h-full pt-4",children:N.length?br($5,{style:{height:"100%"},data:N,itemContent:(B,_)=>br(Xp,{chain:_,type:t,disabled:_.disabled,onClick:M})}):br("div",{className:"flex justify-center mt-4",children:"No chain found."})})]})};import{Fragment as t6,jsx as si,jsxs as nf}from"react/jsx-runtime";var jp=({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=Yp(()=>e==="destination"&&h,[e,h]),C=Yp(()=>e==="source"&&p,[e,p]),[M,I]=e6(!1),N=Zp(_=>{let L;if(v){let U=Object.keys(E?.[_.chainId]||{}).map(R=>R.toLowerCase());if(L=_.tokens.find(R=>R.symbol===a?.symbol&&U.includes(R.address.toLowerCase())),!L){let R=U[0];if(!R)throw new Error(`Couldn't find any available bridgeable token on the chain ${_.chainId}, but bridging is available`);if(L=_.tokens.find(W=>W.address.toLowerCase()===R.toLowerCase()),!L)throw new Error(`Found bridgeable token (${R}) on the chain ${_.chainId}, but token was not defined in chains collection`)}}else L=_.tokens.find(U=>U.symbol===a?.symbol)||_.tokens.find(U=>U.symbol===_.tokenSymbol);n(_),o(L)},[n,o,a,E,v]),B=Zp(_=>{let L=_.tokens.find(U=>U.symbol===f?.symbol)||_.tokens.find(U=>U.symbol===_.tokenSymbol);i(_),d(L)},[i,d,f]);return nf(t6,{children:[M&&si(Xi,{onClose:()=>I(!1),children:si(Qp,{type:e,setSrcChain:N,setDstChain:B,onClose:()=>I(!1)})}),si("button",{type:"button",disabled:S||C,onClick:()=>I(!0),className:`${r||""}`,children:nf("div",{className:"flex justify-between items-center p-4 gap-8",children:[nf("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 $p}from"react/jsx-runtime";var eh=({type:t})=>{let{srcToken:e,srcTokenBalanceWei:r,srcTokenBalanceInfo:n,setSrcValue:i}=te();return $p("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"&&$p("p",{className:`border-b border-solid border-t_text_primary ${!n&&"border-opacity-60"}`,children:"Max"})})};import{useMemo as Wa,useState as c6}from"react";import{faCheck as i6}from"@fortawesome/free-solid-svg-icons";import{FontAwesomeIcon as a6}from"@fortawesome/react-fontawesome";import{useCallback as ih,useEffect as ws,useMemo as vs,useRef as ah,useState as $i}from"react";import{GroupedVirtuoso as o6}from"react-virtuoso";import{jsx as af,jsxs as th}from"react/jsx-runtime";var rh=({token:t,selectedTokenAddress:e,onClick:r})=>th("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:[af(Pn,{token:t,className:"w-6 h-6",generatedLogoClassName:"w-6 h-6"}),th("div",{className:"flex flex-col gap-1 text-xs font-medium !leading-3",children:[af("div",{className:"text-t_text_primary",children:t.name}),af("div",{className:"text-t_text_primary text-opacity-50",children:t.symbol})]})]});import{useMemo as za}from"react";import{useAccount as r6}from"wagmi";import{Fragment as n6,jsx as Ln,jsxs as ys}from"react/jsx-runtime";var nh=({token:t,selectedTokenAddress:e,onClick:r,selectedChainId:n})=>{let{supportedChains:i,tokenPrices:a}=te(),{address:o}=r6(),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(ie.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 ys("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(Rn,{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"}),ys("div",{className:"flex justify-between items-center gap-1 w-full",children:[ys("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?ys("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(n6,{children:o?Ln("div",{children:Ln(xr,{className:"w-[48px] h-[12px]"})}):null})]})]})};import{useAccount as s6}from"wagmi";import{Fragment as of,jsx as ue,jsxs as Bt}from"react/jsx-runtime";var oh=({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,M]=$i(!1),[I,N]=$i(null),[B,_]=$i(!0),L=ah(0),U=ah(null),{bridgeUI:R,supportedChains:W,findTokenDataByAddressAndChain:z,tokenPrices:Y}=te(),{address:ne}=s6(),$=Ma();ws(()=>{S(!1),v(!1)},[i]);let J=ih(()=>{if(t&&I&&zi(d)){let y={};vt||(y=JSON.parse(localStorage.getItem("custom-tokens")||"{}"));let m={address:I.address,symbol:I.symbol,name:I.name,tokenId:I.address,decimals:I.decimals,quickPick:!1,supported:!0,priority:0,chainId:t.chainId};vt||(y[t.chainId]={...y[t.chainId]||{},[d.toLowerCase()]:m},localStorage.setItem("custom-tokens",JSON.stringify(y))),a(m),o(!1)}},[t,d,I,a,o]),T=ih(async()=>{let y=Date.now();L.current=y;let m=W.find(({ecosystem:x,chainId:F})=>x==="evm"&&F===t?.chainId)?.publicRpcUrls[0],c=new ie.Contract(d.toLowerCase(),Hr,ie.getDefaultProvider(m));M(!0);try{let x=await Promise.all([$.query(c,"decimals"),$.query(c,"name"),$.query(c,"symbol")]);if(y!==L.current)return;let[F,u,k]=x;N({address:d.toLowerCase(),decimals:F,name:u,symbol:k})}catch{N(null)}finally{y===L.current&&M(!1)}},[t,d,$,W]);ws(()=>{!R&&zi(d)&&t&&!z(d.toLowerCase(),t.chainId)?T():(M(!1),N(null))},[R,d,T,z,t]),ws(()=>{p("")},[i]);let s=(y,m)=>y.toLowerCase().indexOf(m.toLowerCase())>-1,l=vs(()=>e?.filter(y=>s(y.symbol,d)||s(y.name,d)||y.address.toLowerCase()===d.toLowerCase()),[d,e]),g=vs(()=>r?.filter(y=>s(y.symbol,d)||s(y.name,d)||y.address.toLowerCase()===d.toLowerCase()),[d,r]);ws(()=>{i&&U.current&&setTimeout(()=>{U.current?.focus()},10)},[i]);let w=vs(()=>{let y=u=>{if(!u.balance||!u.decimals)return 0;let k=Number(ie.utils.formatUnits(u.balance,u.decimals)),P=Y[u.chainId]?.[u.address];return P?k*Number(P):0},m=[...l.filter(u=>X.from(u?.balance||"0").gt(0)),...g.filter(u=>X.from(u?.balance||"0").gt(0))].sort((u,k)=>{let P=y(u),O=y(k);return O!==P?O-P:k.priority-u.priority}),c=l.filter(u=>X.from(u?.balance||"0").eq(0)).sort((u,k)=>k.priority-u.priority),x=g.filter(u=>X.from(u?.balance||"0").eq(0)).sort((u,k)=>k.priority-u.priority);return(t?[...ne&&m.length?[m]:[],c,x]:[...ne&&m.length?[m]:[],[...c,...x]]).flat()},[l,g,t,ne,Y]),A=vs(()=>w.filter(y=>y.balance?.gt(0)),[w]),b=t?[...ne&&A.length?[A]:[],l,g]:[...ne&&A.length?[A]:[],g];return E?Bt(of,{children:[Bt("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,{})})]}),Bt("div",{className:"flex flex-col h-full gap-2",children:[I&&Bt("div",{className:"token-picker-container grow-0 bg-t_bg_secondary border border-solid border-t_text_primary border-opacity-10 rounded-xl py-2 pr-2 pl-4 hover:cursor-pointer",children:[ue(qa,{tokenName:I.name,className:"w-9 h-9 text-[15px]"}),Bt("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:I.name}),ue("div",{className:"token-picker__all__symbol",children:I.symbol})]}),Bt("div",{className:"text-sm flex items-center",children:[Ju(d.toLowerCase()),ue("button",{type:"button",onClick:()=>navigator.clipboard.writeText(I.address.toLowerCase()),"aria-label":`Copy ${I.symbol} token address`,className:"flex items-center p-2 fill-white cursor-pointer hover:fill-t_main_accent_light",children:ue(g1,{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"}),Bt("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."}),Bt("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(a6,{icon:i6,className:"w-4 h-4"})}),ue("div",{className:"font-bold",children:"Accept"})]})]}),ue("div",{className:"flex grow items-end justify-center",children:ue(hr,{type:"button",disabled:!h,className:`token-picker__import-button w-full ${h?"":"!cursor-not-allowed"}`,onClick:J,children:"Import"})})]})]}):Bt(of,{children:[Bt("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(gs,{ref:U,inputIcon:ue("div",{className:"fill-t_text_primary",children:ue(os,{})}),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 ${B?"opacity-100 max-h-[200px]":"opacity-0 max-h-0 overflow-hidden"}`,children:e.filter(y=>y?.quickPick).map(y=>ue(rh,{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(Vr,{className:"w-9 h-9"})}):ue(of,{children:I?Bt("div",{className:"token-picker-container hover:cursor-default",children:[ue(Rn,{token:I,chain:t,tokenLogoClassName:"w-9 h-9",generatedLogoClassName:"w-9 h-9 text-[16px]",chainLogoClassName:"w-5"}),Bt("div",{className:"flex justify-between items-center gap-1 overflow-hidden grow",children:[Bt("div",{children:[ue("div",{className:"text-sm font-medium text-ellipsis",children:I.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:I.symbol})]}),ue("div",{children:ue(hr,{type:"button",className:"h-8 py-0 px-4 text-t_text_primary leading-[14px] rounded-[32px] bg-gradient-to-r from-t_main_accent_light to-t_main_accent_dark",onClick:()=>S(!0),children:"Import"})})]}):ue("div",{className:"flex flex-col h-full gap-8 w-[calc(100%+32px)] mx-[-16px]",children:ue(o6,{style:{maxHeight:"400px",height:"100%"},groupCounts:b.map(y=>y?.length),scrollerRef:y=>{y&&y.addEventListener("scroll",m=>{let c=m.target;_(c.scrollTop<10)})},groupContent:y=>Bt("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 ne?A.length?"My tokens":`${t.displayName} network`:`${t.displayName} network`;case 1:return ne?`${t.displayName} network`:"Other networks";case 2:return"Other networks";default:return"Undefined group"}else switch(y){case 0:return ne&&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(nh,{token:w[y],selectedChainId:t?.chainId,selectedTokenAddress:n,onClick:()=>{a(w[y]),o(!1)}})})})})})]})};import{Fragment as f6,jsx as Dn,jsxs as Cs}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:M}=te(),I=Wa(()=>r==="destination"&&C,[r,C]),N=Wa(()=>r==="source"&&M,[r,M]),[B,_]=c6(!1),L=Wa(()=>r==="source"?a:f,[f,a,r]),U=Wa(()=>r==="destination"&&i,[i,r]),R=Wa(()=>r==="source"?o:d,[d,o,r]),W=z=>{let Y=v.find(ne=>ne.chainId===z.chainId);r==="source"?(p(z),h(Y)):(E(z),S(Y)),_(!1)};return Cs(f6,{children:[B&&Dn(Xi,{onClose:()=>_(!1),className:"z-[3]",children:Dn(oh,{type:r,chain:t,tokens:L,otherTokens:R,selectedTokenAddress:e?.address,onSelect:W,isOpen:B,setModalOpen:_})}),Dn("button",{type:"button",disabled:U||I||N,onClick:()=>{_(!0)},className:`${n||""}`,children:Cs("div",{className:"flex justify-between items-center p-4 gap-8 border-r border-solid border-t_text_primary border-opacity-10",children:[Cs("div",{className:"flex gap-2 items-center",children:[Dn(Pn,{token:e,className:"w-9 h-9",generatedLogoClassName:"w-9 h-9 text-[16px]"}),Cs("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"})]})]}),!U&&!I&&!N&&Dn("div",{className:"w-4 h-2 fill-t_text_primary",children:Dn(ii,{})})]})})]})};import{jsx as As,jsxs as sf}from"react/jsx-runtime";var cf=({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 sf("div",{className:"flex flex-col x-border rounded-xl bg-t_bg_tertiary bg-opacity-5",children:[sf("div",{className:"flex border-b border-solid border-t_text_primary border-opacity-10",children:[As(sh,{chain:o,token:a,type:t,className:"w-full flex-grow"}),As(jp,{chain:o,type:t,className:"w-full max-w-[160px]"})]}),sf("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:[As(Kp,{type:t}),As(eh,{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(cf,{type:"source"}),Ka(Op,{}),Ka(cf,{type:"destination"})]}),Ka(ls,{}),Ka(zp,{})]});import{jsx as Ts,jsxs as l6}from"react/jsx-runtime";var ff=({onClose:t})=>{let{tab:e}=te(),r=d6(()=>e==="Settings"?Ts(Dp,{}):e==="History"?Ts(Pp,{}):Ts(dh,{}),[e]);return l6("div",{className:"relative flex flex-col gap-4 p-2 text-t_text_primary bg-t_bg_primary rounded-2xl flex-1",children:[Ts(Ip,{onClose:t}),r]})};import{forwardRef as u6}from"react";import{Fragment as p6,jsx as Xa,jsxs as lh}from"react/jsx-runtime";var gs=u6((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(p6,{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 h6,useCallback as Ss}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)}},x6=({expiryTimestamp:t,onExpire:e,autoStart:r=!0})=>{let[n,i]=uh(r),[a,o]=uh(ea.getSecondsFromExpiry(t)),f=Ss(()=>{let v=ea.getSecondsFromExpiry(t);v<=0&&(e&&e(),i(!1)),o(v)},[t,e]);h6(()=>{if(!n)return;let v=setInterval(f,1e3);return()=>clearInterval(v)},[n,f]);let d=Ss(()=>i(!1),[]),p=Ss(()=>i(!0),[]),h=Ss(v=>{i(!0),o(ea.getSecondsFromExpiry(v))},[]);return{...ea.getTimeFromSeconds(a),isRunning:n,pause:d,resume:p,restart:h}},ph=x6;import{useEffect as m6,useState as b6}from"react";import{Fragment as df,jsx as Ja,jsxs as g6}from"react/jsx-runtime";var hh=({expiryTimestamp:t,displayFormat:e=2,customTextOnExpire:r})=>{let[n,i]=b6(t.getTime()<Date.now()),{seconds:a,minutes:o,hours:f,days:d,restart:p}=ph({expiryTimestamp:t,onExpire:()=>i(!0)});return m6(()=>{p(t)},[t]),Ja(df,{children:n&&r?Ja(df,{children:r}):g6(df,{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 w6}from"react";import{jsx as y6}from"react/jsx-runtime";var qa=({tokenName:t,className:e})=>y6("div",{className:`rounded-full bg-white shadow-sm flex items-center justify-center text-black ${e}`,children:t.substring(0,1)});import{jsx as lf}from"react/jsx-runtime";var Pn=({token:t,className:e,generatedLogoClassName:r})=>{let[n,i]=w6(!1);return t?n?lf(qa,{tokenName:t.name,className:r}):t?.image?lf("img",{src:t.image,alt:t.name,className:`border border-solid border-t_text_primary border-opacity-10 rounded-2xl ${e}`,onError:()=>i(!0)}):lf(qa,{tokenName:t.name,className:r}):null};import{jsx as xh,jsxs as v6}from"react/jsx-runtime";var Rn=({token:t,chain:e,tokenLogoClassName:r,generatedLogoClassName:n,chainLogoClassName:i})=>v6("div",{className:"relative flex items-end pr-1 pb-1",children:[xh(Pn,{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 E6,QueryClientProvider as k6}from"@tanstack/react-query";import{useEffect as uf,useMemo as bh}from"react";import{ErrorBoundary as _6}from"react-error-boundary";import{useReconnect as M6,WagmiProvider as I6}from"wagmi";function C6(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 A6={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"},T6={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"},S6={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?{...A6}:{...T6},...e};for(let[i,a]of Object.entries(n)){let o=S6[i];o&&C6(o,a)}}import{Fragment as yh,jsx as At,jsxs as Es}from"react/jsx-runtime";var P6=new E6,N6=()=>{let{reconnect:t}=M6();return uf(()=>{let e=0,r=setInterval(()=>{t(),e++,e>=5&&clearInterval(r)},1e3);return()=>{clearInterval(r)}},[t]),At(yh,{})},R6=({onPendingTransactionsChange:t})=>{let{history:e}=Mn(),r=bh(()=>e.filter(n=>n.status==="IN_PROGRESS"),[e]);return uf(()=>{t?t(r):window.xPayOnPendingTransactionsChange&&window.xPayOnPendingTransactionsChange(r)},[t,r]),At(yh,{})},pf=({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:M,dstTokenLocked:I,dstChainLocked:N,srcTokenLocked:B,srcChainLocked:_,onDstTokenChange:L,onDstChainChange:U,onSrcTokenChange:R,onSrcChainChange:W,bridge:z,onConnectWallet:Y})=>{let ne=J=>{J.stopPropagation(),J.nativeEvent.stopImmediatePropagation(),J.target===J.currentTarget&&v&&h()},$=bh(()=>fp(d),[d]);return uf(()=>{mh(E,C)},[E,C]),At(_6,{FallbackComponent:()=>At("div",{children:"Something went wrong, please contact XSwap."}),children:At(I6,{config:$,children:Es(k6,{client:P6,children:[At(N6,{}),Es(X1,{children:[At(R6,{onPendingTransactionsChange:M}),At(j1,{integrationConfig:{integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,defaultWalletPicker:S,dstTokenLocked:I,dstChainLocked:N,srcTokenLocked:B,srcChainLocked:_,onDstTokenChange:L,onDstChainChange:U,onSrcTokenChange:R,onSrcChainChange:W,bridge:z,onConnectWallet:Y},supportedChains:d,wagmiConfig:$,overlay:v,children:At(tp,{children:At(Sp,{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:ne,children:Es("div",{className:"relative bg-t_bg_primary rounded-2xl overflow-auto text-t_text_primary border-[1px] border-solid border-[rgba(255,255,255,0.1)] w-x_modal min-w-x_modal max-w-x_modal min-h-[532px]",children:[At(ff,{onSubmit:p,onClose:h}),At(Wc,{})]})}):Es("div",{className:"bg-t_bg_primary rounded-2xl overflow-auto text-t_text_primary border-[1px] border-solid border-[rgba(255,255,255,0.1)] min-h-[532px] w-x_modal min-w-x_modal max-w-x_modal flex flex-col",children:[At(ff,{onSubmit:()=>{},onClose:()=>{}}),At(Wc,{})]})})})})]})]})})})},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:M,srcChainLocked:I})=>{try{if(fn===null)throw new Error("XPay was incorrectly initialized");return await $u(),await new Promise(()=>{if(fn===null)throw new Error("XPay was incorrectly initialized");fn.render(At(pf,{integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,supportedChains:d,lightTheme:p,styles:v,onSubmit:()=>{fn&&fn.render("")},onClose:()=>{fn&&fn.render("")},overlay:!0,defaultWalletPicker:h,onPendingTransactionsChange:E,dstTokenLocked:S,dstChainLocked:C,srcTokenLocked:M,srcChainLocked:I}))})}catch(N){throw new Error(`XSwap component error, ${N}`)}};import{faArrowRight as B6,faArrowUpRightFromSquare as F6,faHourglassHalf as L6}from"@fortawesome/free-solid-svg-icons";import{FontAwesomeIcon as mf}from"@fortawesome/react-fontawesome";import{format as D6}from"date-fns";import{useCallback as O6}from"react";import{jsx as hf,jsxs as wh}from"react/jsx-runtime";var xf=({chain:t,token:e,amount:r})=>wh("div",{className:"flex gap-2",children:[hf(Rn,{token:e,chain:t,tokenLogoClassName:"min-w-9 w-9 h-9",generatedLogoClassName:"min-w-9 w-9 h-9 text-[16px]",chainLogoClassName:"w-5"}),wh("div",{className:"flex flex-col text-[12px]",children:[hf("div",{className:"text-t_text_primary text-nowrap",children:`${Number(r)<1e-4?"<0.0001":r} ${e?.symbol?e?.symbol:"unknown"}`}),hf("div",{className:"text-xs text-t_text_primary text-opacity-50",children:t?.displayName})]})]});import{Fragment as U6,jsx as Vt,jsxs as ci}from"react/jsx-runtime";var ks=({transaction:t,supportedChains:e,srcToken:r,dstToken:n})=>{let a=O6(h=>D6(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:[Vt("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:[Vt(mf,{icon:L6,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 (",Vt(hh,{displayFormat:0,expiryTimestamp:new Date(t.estimatedDeliveryTimestamp),customTextOnExpire:"finalizing"}),")"]})]}):t.status==="DONE"?Vt("div",{className:"flex items-center grow justify-end text-xs",children:Vt("div",{className:" mr-1 text-t_text_green",children:"Done"})}):t.status==="REVERTED"?Vt("div",{className:"flex items-center grow justify-end text-xs",children:Vt("div",{className:"w-4 h-4 mr-1 text-t_text_red",children:"Reverted"})}):null,Vt("a",{href:`${t.messageId?`${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:Vt(mf,{icon:F6,className:"w-[14px] h-[14px] text-t_text_primary"})})]})]}),Vt("div",{className:"flex flex-wrap gap-8",children:ci("div",{className:"flex items-center gap-2",children:[Vt(xf,{chain:d,token:r,amount:o}),t.tokenOutAddress&&ci(U6,{children:[Vt(mf,{icon:B6,className:"w-5 h-5 text-t_text_primary opacity-50 mx-1.5"}),Vt(xf,{chain:p,token:n,amount:f})]})]})})]})};import{jsx as H6}from"react/jsx-runtime";var Np=({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 H6(ks,{transaction:t,supportedChains:e,srcToken:n,dstToken:i})};import{createPortal as G6}from"react-dom";import{jsx as vh}from"react/jsx-runtime";var Ep=({id:t,children:e,onCloseClick:r,type:n="waiting",className:i})=>G6(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 V6}from"react";import{Fragment as q6,jsx as zt,jsxs as bf}from"react/jsx-runtime";var z6=({transaction:t,supportedChains:e,srcToken:r,dstToken:n})=>{let[i,a]=V6(!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 bf("div",{className:"flex gap-2 items-end justify-end flex-wrap",onClick:()=>a(d=>!d),children:[i&&zt(ks,{transaction:t,supportedChains:e,srcToken:r,dstToken:n}),zt("div",{className:`text-t_text_primary rounded-xl h-14 w-20 mb-2 cursor-pointer ${o} ${f}`,children:bf("div",{className:"flex gap-2 items-center h-14 w-20 justify-center fill-t_text_primary",children:[zt("div",{className:`${i?"rotate-180":""}`,children:zt(l1,{})}),zt("div",{className:"relative flex items-center justify-center w-9 h-9",children:t?.status==="DONE"?zt("div",{className:"w-5 h-5 fill-t_success_dark",children:zt(as,{})}):bf(q6,{children:[zt("div",{className:"w-5 h-5",children:zt(z1,{})}),zt("div",{className:"absolute flex items-center justify-center top-0 left-0 right-0 bottom-0 text-t_text_primary",children:zt(Vr,{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)},_s=()=>{let t=fi.map(e=>zt(z6,{...e},e.transaction.hash));if(ts===null)throw new Error("XPay was incorrectly initialized");ts.render(zt("div",{className:"fixed bottom-5 right-2 flex flex-col gap-3 pl-9 items-end w-full z-50",children:t}))};import W6 from"@r2wc/core";import Eh from"react";import{createRoot as K6}from"react-dom/client";var X6=(t,e,r)=>{let n=K6(t),i=Eh.createElement(e,r);return n.render(i),{root:n,ReactComponent:e}},J6=({root:t,ReactComponent:e},r)=>{let n=Eh.createElement(e,r);t.render(n)},Q6=({root:t})=>{t.unmount()},kh=(t,e={})=>W6(t,e,{mount:X6,update:J6,unmount:Q6});import{useEffect as Z6,useState as _h}from"react";import{Fragment as j6,jsx as Ms,jsxs as $6}from"react/jsx-runtime";var Y6=({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:M,onDstTokenChange:I,onDstChainChange:N,onSrcTokenChange:B,onSrcChainChange:_,onConnectWallet:L,bridge:U})=>{let[R,W]=_h(!0),[z,Y]=_h([]);Z6(()=>{(async()=>{W(!0);let $=(await ni()).filter(({web3Environment:J,bridgeSupported:T,swapSupported:s})=>J==="mainnet"&&(T||s));Y($),W(!1)})()},[]);let ne=(()=>{try{return typeof h=="string"?JSON.parse(h):h||void 0}catch($){console.error("Error parsing styles:",$)}})();return $6(j6,{children:[Ms("style",{children:$o}),R?Ms("div",{className:"min-h-[532px] w-full flex items-center justify-center",children:Ms(Vr,{className:"w-10 h-10"})}):Ms(pf,{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:ne,onPendingTransactionsChange:v,dstTokenLocked:E,dstChainLocked:S,srcTokenLocked:C,srcChainLocked:M,onDstTokenChange:I,onDstChainChange:N,onSrcTokenChange:B,onSrcChainChange:_,onConnectWallet:L,bridge:U})]})},Is=()=>{if(vt||typeof customElements>"u")return{};let t=kh(Y6,{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 eb}from"@tanstack/react-query";import{useEffect as tb}from"react";import{jsx as nb}from"react/jsx-runtime";var rb=Is();!eb&&typeof customElements<"u"&&(customElements.get("xpay-widget")||customElements.define("xpay-widget",rb));var gf=({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:M,onDstTokenChange:I,onDstChainChange:N,onSrcTokenChange:B,onSrcChainChange:_,onConnectWallet:L,bridge:U})=>(tb(()=>{window.xPayOnPendingTransactionsChange=v,window.xPayOnDstTokenChange=I,window.xPayOnDstChainChange=N,window.xPayOnSrcTokenChange=B,window.xPayOnSrcChainChange=_,window.xPayOnConnectWallet=L},[v,I,N,B,_,L]),nb("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":M,bridge:U}));import ib from"async-retry";var Mh=async(t,e)=>{let r=t.publicRpcUrls[0],n=new ie.Contract(e.toLowerCase(),Hr,ie.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 bp=async(t,e,r,n)=>{let i=await ab(t,e),a=(await ni()).filter(({web3Environment:W,swapSupported:z})=>W==="mainnet"&&z),o=i.logs?.find(W=>W.topics[0]===ie.utils.id(Fu));if(!o)throw new Error(`No transaction event found for chain ${t} tx ${e}`);let f=o?.topics[1],p=new ie.utils.Interface(Lu).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()),M=C?.chainId;if(!M)throw new Error("Unknown destination chain!");let I;r&&(I=C.tokens.find(W=>W.address.toLowerCase()===r.toLowerCase()));let N=Date.now()/1e3,B={hash:i.transactionHash,timestamp:N,sourceChainId:v.chainId,targetChainId:C.chainId,amountWei:h?.tokenAmount.toString(),tokenAddress:S.address,tokenOutAddress:I?.address,tokenOutAmount:n,estimatedDeliveryTimestamp:h?.valueForInstantCcipRecieve.toString()!=="0"?N*1e3+30*1e3:N*1e3+30*60*1e3,status:"IN_PROGRESS"};Ah({transaction:B,supportedChains:a,dstToken:I,srcToken:S}),_s();let _=Mt[M]?.XSwapRouter;if(!_)throw new Error("Unknown destination XSwapRouter!");let L=new ie.Contract(_,Ou,ie.getDefaultProvider(a.find(W=>W.chainId===M)?.publicRpcUrls[0])),U={address:_,topics:[ie.utils.id(Du),f]},R=async()=>{Sh(e),_s(),await new Promise(W=>setTimeout(()=>W(!0),Bu)),Th(e),_s()};vc({transferId:f}).then(W=>{W.status==="DONE"?R():(setTimeout(()=>vc({transferId:f}).then(z=>{z.status==="DONE"&&R()}),30*60*1e3),L.once(U,()=>R()))})},ab=async(t,e)=>{try{let r=(await ni()).find(i=>i.chainId===t),n=new ie.providers.JsonRpcProvider(r?.publicRpcUrls[0]);return await ib(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 yf=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:M,onDstTokenChange:I,onDstChainChange:N,onSrcTokenChange:B,onSrcChainChange:_,bridge:L})=>{let U=(await ni()).filter(({web3Environment:R,swapSupported:W})=>R==="mainnet"&&W);ob(t,U,e,r,n,i),await gh({integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,supportedChains:U,lightTheme:d,defaultWalletPicker:p,styles:h,onPendingTransactionsChange:v,dstTokenLocked:E,dstChainLocked:S,srcTokenLocked:C,srcChainLocked:M,onDstTokenChange:I,onDstChainChange:N,onSrcTokenChange:B,onSrcChainChange:_,bridge:L})},ob=(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 sb=Is();ju();var cb={openTransactionModal:yf,TxWidget:gf,TxWidgetWC:sb},tL=cb;export{vf as ContractName,Xr as Ecosystem,Dh as Environment,di as TxStatus,gf as TxWidget,sb as TxWidgetWC,li as Web3Environment,Cf as XSwapCallType,tL as default,yf as openTransactionModal};
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 Rp}from"react/jsx-runtime";var Bp=()=>{let t=B5(null),{infiniteApproval:e,setInfiniteApproval:r}=te();return Rp("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:Rp("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 xs}from"react/jsx-runtime";var Fp=()=>{let t=F5(null),{expressDelivery:e,setExpressDelivery:r}=te();return xs("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"}),xs("div",{className:"flex gap-2 items-center justify-between flex-wrap",children:[xs("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]"})]}),xs("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 Bn,jsxs as ms}from"react/jsx-runtime";var Lp=()=>{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 ms("div",{className:"flex flex-col gap-5 pt-5 border-t border-solid border-t_text_primary border-opacity-10",children:[Bn("h1",{className:"text-sm font-medium text-left",children:"Slippage"}),ms("div",{className:"flex items-center gap-2 w-full",children:[Bn("div",{className:"flex items-center bg-t_bg_tertiary bg-opacity-5 p-1 border border-solid border-t_text_primary border-opacity-10 rounded-xl gap-2",children:["0.5","1.5","3.0"].map(f=>Bn("button",{type:"button",onClick:()=>i(f),className:`block rounded-lg text-sm bg-transparent h-7 px-1 hover:bg-gradient-to-r hover:from-t_main_accent_light hover:to-t_main_accent_dark hover:opacity-100 ${t===f?"gradient-slippage-container-blue text-white opacity-100":"text-t_text_primary opacity-20"}`,children:`${f}%`},f))}),Bn("div",{className:`${r?"gradient-slippage-container-blue p-[1px] rounded-xl":""}`,children:ms("div",{className:"bg-t_bg_primary p-1 h-full border border-solid border-t_text_primary border-opacity-10 rounded-xl",children:[Bn(Ha,{id:"slippage-input",placeholder:"1.5",regex:Qo,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"} `})," ","%"]})})]}),ms("div",{className:"text-sm opacity-60",children:[Bn("p",{children:"Slippage is the price variation you are willing to accept in the event that the price of the trade changes while it is processing."}),Bn("br",{}),Bn("p",{children:"If the trade fails due to too low slippage, you will receive USDC on the destination chain."})]})]})};import{jsx as Jc,jsxs as D5}from"react/jsx-runtime";var Dp=()=>D5("div",{className:"flex flex-col gap-5 px-4",children:[Jc(Fp,{}),Jc(Bp,{}),Jc(Lp,{})]});import{jsx as Va}from"react/jsx-runtime";var Op=()=>{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(p1,{})})})})})};var Qc={1:["0xdac17f958d2ee523a2206206994597c13d831ec7"]};import{useCallback as Zc,useMemo as O5}from"react";var Up=({rpcChainId:t,currentChainId:e,signer:r,tokenAddress:n})=>{let i=Cc(),{supportedChains:a}=te(),o=O5(()=>{let f=a.find(d=>d.ecosystem==="evm"&&d.chainId===t)?.publicRpcUrls[0];return f&&n?new ie.Contract(n,Hr,r&&(!e||e===t)?r:ie.getDefaultProvider(f)):null},[t,e,r,n,a]);return{balanceOf:Zc(async f=>await i.query(o,"balanceOf",[f]),[o,i]),allowance:Zc(async(f,d)=>await i.query(o,"allowance",[f,d]),[o,i]),approve:Zc(async(f,d)=>await i.execute(o,"approve",[d,f]),[o,i])}};import{useCallback as Gp,useEffect as z5,useMemo as Yi,useState as Vp}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 un,jsxs as Yc}from"react/jsx-runtime";var V5=({connector:t,className:e})=>{switch(t.name){case"WalletConnect":return un(H1,{className:`w-[34px] h-[34px] rounded-md ${e||""}`});default:return un("img",{src:t.icon,alt:t.name,className:`w-[34px] h-[34px] rounded-md ${e||""}`})}},Hp=({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 Yc("div",{className:`flex flex-col h-full ${t||""}`,children:[Yc("div",{className:"flex justify-between",children:[un("div",{className:"text-base/4 mb-4 text-t_text_primary",children:"Pick wallet"}),un("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:e,children:un(ot,{})})]}),un("div",{className:"horizontal-separator"}),un("div",{className:"h-full pt-4",children:i.map(o=>Yc("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:[un(V5,{connector:o}),un("div",{className:"text-t_text_primary",children:o.name})]},o.id))})]})};import{Fragment as K5,jsx as jc,jsxs as X5}from"react/jsx-runtime";var zp=()=>{let{address:t,chainId:e}=q5(),{switchChainAsync:r}=W5(),[n,i]=Vp(!1),{integrationConfig:a}=te(),{bridgeUI:o,error:f,srcChain:d,dstChain:p,srcToken:h,dstToken:v,srcValueWei:E,srcTokenBalanceWei:S,isFetchingRoute:C,isAsyncDataLoaded:M,hasOnConnectWalletCallback:I,onConnectWallet:N}=te(),{setTxStatus:B,setTxMsg:_,setTxModalOpen:L,enqueueTransaction:U}=Gr(),R=Yi(()=>d?.chainId,[d?.chainId]),W=Yi(()=>p?.chainId,[p?.chainId]),z=Yi(()=>h?.address,[h?.address]),Y=Yi(()=>v?.address,[v?.address]),[ne,$]=Vp("0"),{networks:{evm:J}}=Wi(),{allowance:T,approve:s}=Up({rpcChainId:R,currentChainId:J.chainId,signer:J.signer,tokenAddress:z}),l=Yi(()=>R?R===W?Mt[R]?.XSwapRouterSingleChain||"":Mt[R]?.XSwapRouter||"":"",[R,W]),g=Gp(async()=>{if(l&&J.address)try{let b=await T(J.address,l);$(b.toString())}catch{$("0")}else $("0")},[T,J.address,l]);z5(()=>{R&&Qc[R]?.includes(z)&&g()},[g,R,z]);let w=Gp(()=>{B(0),_(""),L(!0)},[L,_,B]),A=Yi(()=>M?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&&Gt(E).gt(Gt(S))?{text:"Insufficient Balance",fn:()=>{},disabled:!0}:Gt(E||"0").lte(Gt("0"))?{text:"Enter Token Amount",fn:()=>{},disabled:!0}:C?{text:"Fetching Route",fn:()=>{},disabled:!0}:Qc[R]?.includes(z)&&ne!=="0"&&X.from(ne).lt(X.from(E))?{text:"Reset Approval",fn:async()=>{U({executeTransaction:()=>s("0",l),txStatus:1,txMsg:"You are going to reset your approval",handlers:{onSuccess:()=>{g(),B(5)}}})},disabled:!1}:{text:o?"Bridge":"Swap",fn:async()=>{w()},disabled:!1}:{text:a.defaultWalletPicker||I?"Connect Wallet":"Connect Wallet First",fn:()=>{a.defaultWalletPicker?i(!0):I&&N()},disabled:!a.defaultWalletPicker&&!I}:{text:"Loading XPay...",fn:()=>{},disabled:!0},[M,f,t,R,W,z,Y,e,E,S,C,ne,o,a.defaultWalletPicker,r,U,s,l,g,B,w]);return X5(K5,{children:[n&&jc(Xi,{onClose:()=>i(!1),children:jc(Hp,{onClose:()=>i(!1)})}),jc("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 $c,jsxs as J5}from"react/jsx-runtime";var qp=()=>{let{srcTokenBalanceInfo:t,isFetchingBalance:e}=te();return J5("div",{className:"flex flex-col items-end",children:[$c("p",{className:"text-xs font-medium opacity-60",children:"Balance:"}),e?$c(xr,{className:"w-[50px] h-[16px]"}):$c("p",{className:`text-xs font-medium ${!t&&"opacity-60"}`,children:t||"-"})]})};import{Fragment as Wp,jsx as Fn,jsxs as bs}from"react/jsx-runtime";var Kp=({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 bs("div",{className:"flex justify-between items-center w-full p-4 gap-8 overflow-hidden",children:[Fn("div",{className:"flex flex-col font-medium w-full overflow-hidden text-left",children:t==="source"?bs(Wp,{children:[Fn(Ha,{id:"swap-amount-input",className:"bg-transparent border-none p-0 text-xl outline-0 font-sans-bold font-bold",regex:Qo,value:e,onChange:d=>a(d)}),f&&Fn("div",{className:"text-sx opacity-60",children:`$${f}`})]}):o?bs("div",{className:"flex flex-col gap-1",children:[Fn(xr,{className:"w-[150px] h-[30px]"}),Fn(xr,{className:"w-[100px] h-[20px]"})]}):bs(Wp,{children:[Fn("div",{className:"text-xl text-t_text_secondary font-sans-bold font-bold",children:n||0}),f&&Fn("div",{className:"text-sx opacity-60",children:`$${f}`})]})}),t==="source"&&Fn(qp,{})]})};import{useCallback as Zp,useMemo as Yp,useState as e6}from"react";import{useMemo as rf,useState as Z5,useRef as Y5,useEffect as j5}from"react";import{Virtuoso as $5}from"react-virtuoso";import{useMemo as ef}from"react";import{jsx as ji,jsxs as tf}from"react/jsx-runtime";var Xp=({chain:t,type:e,onClick:r,disabled:n})=>{let{networks:{evm:i}}=Wi(),{srcChain:a,dstChain:o,bridgeUI:f}=te(),d=ef(()=>e==="source"?a?.chainId:o?.chainId,[o,a,e]),p=ef(()=>i.signer&&i.chainId===t.chainId,[t.chainId,i.chainId,i.signer]),h=ef(()=>{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:tf("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:[tf("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&&tf("div",{className:"flex items-baseline gap-1",children:[ji(w1,{}),ji("div",{className:"text-t_text_green",children:"connected"})]})]})})};import{jsx as br,jsxs as Jp}from"react/jsx-runtime";var Qp=({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,E]=Z5(""),S=Y5(null);j5(()=>{S.current&&setTimeout(()=>{S.current?.focus()},10)},[]);let C=rf(()=>{let B=h.filter(({web3Environment:_,swapSupported:L,bridgeSupported:U})=>_==="mainnet"&&(d&&U||!d&&L));return v?B.filter(_=>{let L=v.toLowerCase();return _.displayName.toLowerCase().includes(L)||_.chainId.toLowerCase().includes(L)}):B},[d,h,v]),M=B=>{let _=h.find(({chainId:L})=>L===B);if(!_)throw new Error("ChainPicker > selected chain id that is absent in supportedChains list.");t==="source"?e(_):r(_),n()},I=rf(()=>{if(!i?.chainId||!a?.address)return[];if(!d){let B=h.find(_=>_.chainId===i.chainId)?.disabledForDestination||[];return t==="destination"?C?.filter(_=>B.includes(_.chainId)).map(({chainId:_})=>_):[]}if(t==="destination"){let B=p?.[i.chainId]?.[a.address];return C?.filter(L=>!B?.[L.chainId]).map(({chainId:L})=>L)}else{if(!o||!f)return[];let B=p?.[o.chainId]?.[f.address];return C?.filter(L=>!B?.[L.chainId]).map(({chainId:L})=>L)}},[p,d,C,i,a,o,f,t,h]),N=rf(()=>C.map(B=>({...B,disabled:I.includes(B.chainId)})).sort((B,_)=>B.disabled===_.disabled?0:B.disabled?1:-1),[C,I]);return Jp("div",{className:"flex flex-col h-full",children:[Jp("div",{className:"flex justify-between",children:[br("div",{className:"text-base/4 text-t_text_primary mb-4",children:`Pick ${t} chain`}),br("div",{className:"w-4 h-4 fill-t_text_primary cursor-pointer",onClick:n,children:br(ot,{})})]}),br(gs,{ref:S,inputIcon:br("div",{className:"fill-t_text_primary",children:br(os,{})}),placeholder:"Search chain name",value:v,handleChange:E}),br("div",{className:"horizontal-separator mt-4"}),br("div",{className:"h-full pt-4",children:N.length?br($5,{style:{height:"100%"},data:N,itemContent:(B,_)=>br(Xp,{chain:_,type:t,disabled:_.disabled,onClick:M})}):br("div",{className:"flex justify-center mt-4",children:"No chain found."})})]})};import{Fragment as t6,jsx as si,jsxs as nf}from"react/jsx-runtime";var jp=({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=Yp(()=>e==="destination"&&h,[e,h]),C=Yp(()=>e==="source"&&p,[e,p]),[M,I]=e6(!1),N=Zp(_=>{let L;if(v){let U=Object.keys(E?.[_.chainId]||{}).map(R=>R.toLowerCase());if(L=_.tokens.find(R=>R.symbol===a?.symbol&&U.includes(R.address.toLowerCase())),!L){let R=U[0];if(!R)throw new Error(`Couldn't find any available bridgeable token on the chain ${_.chainId}, but bridging is available`);if(L=_.tokens.find(W=>W.address.toLowerCase()===R.toLowerCase()),!L)throw new Error(`Found bridgeable token (${R}) on the chain ${_.chainId}, but token was not defined in chains collection`)}}else L=_.tokens.find(U=>U.symbol===a?.symbol)||_.tokens.find(U=>U.symbol===_.tokenSymbol);n(_),o(L)},[n,o,a,E,v]),B=Zp(_=>{let L=_.tokens.find(U=>U.symbol===f?.symbol)||_.tokens.find(U=>U.symbol===_.tokenSymbol);i(_),d(L)},[i,d,f]);return nf(t6,{children:[M&&si(Xi,{onClose:()=>I(!1),children:si(Qp,{type:e,setSrcChain:N,setDstChain:B,onClose:()=>I(!1)})}),si("button",{type:"button",disabled:S||C,onClick:()=>I(!0),className:`${r||""}`,children:nf("div",{className:"flex justify-between items-center p-4 gap-8",children:[nf("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 $p}from"react/jsx-runtime";var eh=({type:t})=>{let{srcToken:e,srcTokenBalanceWei:r,srcTokenBalanceInfo:n,setSrcValue:i}=te();return $p("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"&&$p("p",{className:`border-b border-solid border-t_text_primary ${!n&&"border-opacity-60"}`,children:"Max"})})};import{useMemo as Wa,useState as c6}from"react";import{faCheck as i6}from"@fortawesome/free-solid-svg-icons";import{FontAwesomeIcon as a6}from"@fortawesome/react-fontawesome";import{useCallback as ih,useEffect as ws,useMemo as vs,useRef as ah,useState as $i}from"react";import{GroupedVirtuoso as o6}from"react-virtuoso";import{jsx as af,jsxs as th}from"react/jsx-runtime";var rh=({token:t,selectedTokenAddress:e,onClick:r})=>th("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:[af(Pn,{token:t,className:"w-6 h-6",generatedLogoClassName:"w-6 h-6"}),th("div",{className:"flex flex-col gap-1 text-xs font-medium !leading-3",children:[af("div",{className:"text-t_text_primary",children:t.name}),af("div",{className:"text-t_text_primary text-opacity-50",children:t.symbol})]})]});import{useMemo as za}from"react";import{useAccount as r6}from"wagmi";import{Fragment as n6,jsx as Ln,jsxs as ys}from"react/jsx-runtime";var nh=({token:t,selectedTokenAddress:e,onClick:r,selectedChainId:n})=>{let{supportedChains:i,tokenPrices:a}=te(),{address:o}=r6(),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(ie.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 ys("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(Rn,{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"}),ys("div",{className:"flex justify-between items-center gap-1 w-full",children:[ys("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?ys("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(n6,{children:o?Ln("div",{children:Ln(xr,{className:"w-[48px] h-[12px]"})}):null})]})]})};import{useAccount as s6}from"wagmi";import{Fragment as of,jsx as ue,jsxs as Bt}from"react/jsx-runtime";var oh=({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,M]=$i(!1),[I,N]=$i(null),[B,_]=$i(!0),L=ah(0),U=ah(null),{bridgeUI:R,supportedChains:W,findTokenDataByAddressAndChain:z,tokenPrices:Y}=te(),{address:ne}=s6(),$=Ma();ws(()=>{S(!1),v(!1)},[i]);let J=ih(()=>{if(t&&I&&zi(d)){let y={};vt||(y=JSON.parse(localStorage.getItem("custom-tokens")||"{}"));let m={address:I.address,symbol:I.symbol,name:I.name,tokenId:I.address,decimals:I.decimals,quickPick:!1,supported:!0,priority:0,chainId:t.chainId};vt||(y[t.chainId]={...y[t.chainId]||{},[d.toLowerCase()]:m},localStorage.setItem("custom-tokens",JSON.stringify(y))),a(m),o(!1)}},[t,d,I,a,o]),T=ih(async()=>{let y=Date.now();L.current=y;let m=W.find(({ecosystem:x,chainId:F})=>x==="evm"&&F===t?.chainId)?.publicRpcUrls[0],c=new ie.Contract(d.toLowerCase(),Hr,ie.getDefaultProvider(m));M(!0);try{let x=await Promise.all([$.query(c,"decimals"),$.query(c,"name"),$.query(c,"symbol")]);if(y!==L.current)return;let[F,u,k]=x;N({address:d.toLowerCase(),decimals:F,name:u,symbol:k})}catch{N(null)}finally{y===L.current&&M(!1)}},[t,d,$,W]);ws(()=>{!R&&zi(d)&&t&&!z(d.toLowerCase(),t.chainId)?T():(M(!1),N(null))},[R,d,T,z,t]),ws(()=>{p("")},[i]);let s=(y,m)=>y.toLowerCase().indexOf(m.toLowerCase())>-1,l=vs(()=>e?.filter(y=>s(y.symbol,d)||s(y.name,d)||y.address.toLowerCase()===d.toLowerCase()),[d,e]),g=vs(()=>r?.filter(y=>s(y.symbol,d)||s(y.name,d)||y.address.toLowerCase()===d.toLowerCase()),[d,r]);ws(()=>{i&&U.current&&setTimeout(()=>{U.current?.focus()},10)},[i]);let w=vs(()=>{let y=u=>{if(!u.balance||!u.decimals)return 0;let k=Number(ie.utils.formatUnits(u.balance,u.decimals)),P=Y[u.chainId]?.[u.address];return P?k*Number(P):0},m=[...l.filter(u=>X.from(u?.balance||"0").gt(0)),...g.filter(u=>X.from(u?.balance||"0").gt(0))].sort((u,k)=>{let P=y(u),O=y(k);return O!==P?O-P:k.priority-u.priority}),c=l.filter(u=>X.from(u?.balance||"0").eq(0)).sort((u,k)=>k.priority-u.priority),x=g.filter(u=>X.from(u?.balance||"0").eq(0)).sort((u,k)=>k.priority-u.priority);return(t?[...ne&&m.length?[m]:[],c,x]:[...ne&&m.length?[m]:[],[...c,...x]]).flat()},[l,g,t,ne,Y]),A=vs(()=>w.filter(y=>y.balance?.gt(0)),[w]),b=t?[...ne&&A.length?[A]:[],l,g]:[...ne&&A.length?[A]:[],g];return E?Bt(of,{children:[Bt("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,{})})]}),Bt("div",{className:"flex flex-col h-full gap-2",children:[I&&Bt("div",{className:"token-picker-container grow-0 bg-t_bg_secondary border border-solid border-t_text_primary border-opacity-10 rounded-xl py-2 pr-2 pl-4 hover:cursor-pointer",children:[ue(qa,{tokenName:I.name,className:"w-9 h-9 text-[15px]"}),Bt("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:I.name}),ue("div",{className:"token-picker__all__symbol",children:I.symbol})]}),Bt("div",{className:"text-sm flex items-center",children:[Ju(d.toLowerCase()),ue("button",{type:"button",onClick:()=>navigator.clipboard.writeText(I.address.toLowerCase()),"aria-label":`Copy ${I.symbol} token address`,className:"flex items-center p-2 fill-white cursor-pointer hover:fill-t_main_accent_light",children:ue(g1,{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"}),Bt("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."}),Bt("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(a6,{icon:i6,className:"w-4 h-4"})}),ue("div",{className:"font-bold",children:"Accept"})]})]}),ue("div",{className:"flex grow items-end justify-center",children:ue(hr,{type:"button",disabled:!h,className:`token-picker__import-button w-full ${h?"":"!cursor-not-allowed"}`,onClick:J,children:"Import"})})]})]}):Bt(of,{children:[Bt("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(gs,{ref:U,inputIcon:ue("div",{className:"fill-t_text_primary",children:ue(os,{})}),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 ${B?"opacity-100 max-h-[200px]":"opacity-0 max-h-0 overflow-hidden"}`,children:e.filter(y=>y?.quickPick).map(y=>ue(rh,{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(Vr,{className:"w-9 h-9"})}):ue(of,{children:I?Bt("div",{className:"token-picker-container hover:cursor-default",children:[ue(Rn,{token:I,chain:t,tokenLogoClassName:"w-9 h-9",generatedLogoClassName:"w-9 h-9 text-[16px]",chainLogoClassName:"w-5"}),Bt("div",{className:"flex justify-between items-center gap-1 overflow-hidden grow",children:[Bt("div",{children:[ue("div",{className:"text-sm font-medium text-ellipsis",children:I.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:I.symbol})]}),ue("div",{children:ue(hr,{type:"button",className:"h-8 py-0 px-4 text-t_text_primary leading-[14px] rounded-[32px] bg-gradient-to-r from-t_main_accent_light to-t_main_accent_dark",onClick:()=>S(!0),children:"Import"})})]}):ue("div",{className:"flex flex-col h-full gap-8 w-[calc(100%+32px)] mx-[-16px]",children:ue(o6,{style:{maxHeight:"400px",height:"100%"},groupCounts:b.map(y=>y?.length),scrollerRef:y=>{y&&y.addEventListener("scroll",m=>{let c=m.target;_(c.scrollTop<10)})},groupContent:y=>Bt("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 ne?A.length?"My tokens":`${t.displayName} network`:`${t.displayName} network`;case 1:return ne?`${t.displayName} network`:"Other networks";case 2:return"Other networks";default:return"Undefined group"}else switch(y){case 0:return ne&&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(nh,{token:w[y],selectedChainId:t?.chainId,selectedTokenAddress:n,onClick:()=>{a(w[y]),o(!1)}})})})})})]})};import{Fragment as f6,jsx as Dn,jsxs as Cs}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:M}=te(),I=Wa(()=>r==="destination"&&C,[r,C]),N=Wa(()=>r==="source"&&M,[r,M]),[B,_]=c6(!1),L=Wa(()=>r==="source"?a:f,[f,a,r]),U=Wa(()=>r==="destination"&&i,[i,r]),R=Wa(()=>r==="source"?o:d,[d,o,r]),W=z=>{let Y=v.find(ne=>ne.chainId===z.chainId);r==="source"?(p(z),h(Y)):(E(z),S(Y)),_(!1)};return Cs(f6,{children:[B&&Dn(Xi,{onClose:()=>_(!1),className:"z-[3]",children:Dn(oh,{type:r,chain:t,tokens:L,otherTokens:R,selectedTokenAddress:e?.address,onSelect:W,isOpen:B,setModalOpen:_})}),Dn("button",{type:"button",disabled:U||I||N,onClick:()=>{_(!0)},className:`${n||""}`,children:Cs("div",{className:"flex justify-between items-center p-4 gap-8 border-r border-solid border-t_text_primary border-opacity-10",children:[Cs("div",{className:"flex gap-2 items-center",children:[Dn(Pn,{token:e,className:"w-9 h-9",generatedLogoClassName:"w-9 h-9 text-[16px]"}),Cs("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"})]})]}),!U&&!I&&!N&&Dn("div",{className:"w-4 h-2 fill-t_text_primary",children:Dn(ii,{})})]})})]})};import{jsx as As,jsxs as sf}from"react/jsx-runtime";var cf=({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 sf("div",{className:"flex flex-col x-border rounded-xl bg-t_bg_tertiary bg-opacity-5",children:[sf("div",{className:"flex border-b border-solid border-t_text_primary border-opacity-10",children:[As(sh,{chain:o,token:a,type:t,className:"w-full flex-grow"}),As(jp,{chain:o,type:t,className:"w-full max-w-[160px]"})]}),sf("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:[As(Kp,{type:t}),As(eh,{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(cf,{type:"source"}),Ka(Op,{}),Ka(cf,{type:"destination"})]}),Ka(ls,{}),Ka(zp,{})]});import{jsx as Ts,jsxs as l6}from"react/jsx-runtime";var ff=({onClose:t})=>{let{tab:e}=te(),r=d6(()=>e==="Settings"?Ts(Dp,{}):e==="History"?Ts(Pp,{}):Ts(dh,{}),[e]);return l6("div",{className:"relative flex flex-col gap-4 p-2 text-t_text_primary bg-t_bg_primary rounded-2xl flex-1",children:[Ts(Ip,{onClose:t}),r]})};import{forwardRef as u6}from"react";import{Fragment as p6,jsx as Xa,jsxs as lh}from"react/jsx-runtime";var gs=u6((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(p6,{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 h6,useCallback as Ss}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)}},x6=({expiryTimestamp:t,onExpire:e,autoStart:r=!0})=>{let[n,i]=uh(r),[a,o]=uh(ea.getSecondsFromExpiry(t)),f=Ss(()=>{let v=ea.getSecondsFromExpiry(t);v<=0&&(e&&e(),i(!1)),o(v)},[t,e]);h6(()=>{if(!n)return;let v=setInterval(f,1e3);return()=>clearInterval(v)},[n,f]);let d=Ss(()=>i(!1),[]),p=Ss(()=>i(!0),[]),h=Ss(v=>{i(!0),o(ea.getSecondsFromExpiry(v))},[]);return{...ea.getTimeFromSeconds(a),isRunning:n,pause:d,resume:p,restart:h}},ph=x6;import{useEffect as m6,useState as b6}from"react";import{Fragment as df,jsx as Ja,jsxs as g6}from"react/jsx-runtime";var hh=({expiryTimestamp:t,displayFormat:e=2,customTextOnExpire:r})=>{let[n,i]=b6(t.getTime()<Date.now()),{seconds:a,minutes:o,hours:f,days:d,restart:p}=ph({expiryTimestamp:t,onExpire:()=>i(!0)});return m6(()=>{p(t)},[t]),Ja(df,{children:n&&r?Ja(df,{children:r}):g6(df,{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 w6}from"react";import{jsx as y6}from"react/jsx-runtime";var qa=({tokenName:t,className:e})=>y6("div",{className:`rounded-full bg-white shadow-sm flex items-center justify-center text-black ${e}`,children:t.substring(0,1)});import{jsx as lf}from"react/jsx-runtime";var Pn=({token:t,className:e,generatedLogoClassName:r})=>{let[n,i]=w6(!1);return t?n?lf(qa,{tokenName:t.name,className:r}):t?.image?lf("img",{src:t.image,alt:t.name,className:`border border-solid border-t_text_primary border-opacity-10 rounded-2xl ${e}`,onError:()=>i(!0)}):lf(qa,{tokenName:t.name,className:r}):null};import{jsx as xh,jsxs as v6}from"react/jsx-runtime";var Rn=({token:t,chain:e,tokenLogoClassName:r,generatedLogoClassName:n,chainLogoClassName:i})=>v6("div",{className:"relative flex items-end pr-1 pb-1",children:[xh(Pn,{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 E6,QueryClientProvider as k6}from"@tanstack/react-query";import{useEffect as uf,useMemo as bh}from"react";import{ErrorBoundary as _6}from"react-error-boundary";import{useReconnect as M6,WagmiProvider as I6}from"wagmi";function C6(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 A6={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"},T6={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"},S6={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?{...A6}:{...T6},...e};for(let[i,a]of Object.entries(n)){let o=S6[i];o&&C6(o,a)}}import{Fragment as yh,jsx as At,jsxs as Es}from"react/jsx-runtime";var P6=new E6,N6=()=>{let{reconnect:t}=M6();return uf(()=>{let e=0,r=setInterval(()=>{t(),e++,e>=5&&clearInterval(r)},1e3);return()=>{clearInterval(r)}},[t]),At(yh,{})},R6=({onPendingTransactionsChange:t})=>{let{history:e}=Mn(),r=bh(()=>e.filter(n=>n.status==="IN_PROGRESS"),[e]);return uf(()=>{t?t(r):window.xPayOnPendingTransactionsChange&&window.xPayOnPendingTransactionsChange(r)},[t,r]),At(yh,{})},pf=({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:M,dstTokenLocked:I,dstChainLocked:N,srcTokenLocked:B,srcChainLocked:_,onDstTokenChange:L,onDstChainChange:U,onSrcTokenChange:R,onSrcChainChange:W,bridge:z,onConnectWallet:Y})=>{let ne=J=>{J.stopPropagation(),J.nativeEvent.stopImmediatePropagation(),J.target===J.currentTarget&&v&&h()},$=bh(()=>fp(d),[d]);return uf(()=>{mh(E,C)},[E,C]),At(_6,{FallbackComponent:()=>At("div",{children:"Something went wrong, please contact XSwap."}),children:At(I6,{config:$,children:Es(k6,{client:P6,children:[At(N6,{}),Es(X1,{children:[At(R6,{onPendingTransactionsChange:M}),At(j1,{integrationConfig:{integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,defaultWalletPicker:S,dstTokenLocked:I,dstChainLocked:N,srcTokenLocked:B,srcChainLocked:_,onDstTokenChange:L,onDstChainChange:U,onSrcTokenChange:R,onSrcChainChange:W,bridge:z,onConnectWallet:Y},supportedChains:d,wagmiConfig:$,overlay:v,children:At(tp,{children:At(Sp,{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:ne,children:Es("div",{className:"relative bg-t_bg_primary rounded-2xl overflow-auto text-t_text_primary border-[1px] border-solid border-[rgba(255,255,255,0.1)] w-x_modal min-w-x_modal max-w-x_modal min-h-[532px]",children:[At(ff,{onSubmit:p,onClose:h}),At(Wc,{})]})}):Es("div",{className:"bg-t_bg_primary rounded-2xl overflow-auto text-t_text_primary border-[1px] border-solid border-[rgba(255,255,255,0.1)] min-h-[532px] w-x_modal min-w-x_modal max-w-x_modal flex flex-col",children:[At(ff,{onSubmit:()=>{},onClose:()=>{}}),At(Wc,{})]})})})})]})]})})})},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:M,srcChainLocked:I})=>{try{if(fn===null)throw new Error("XPay was incorrectly initialized");return await $u(),await new Promise(()=>{if(fn===null)throw new Error("XPay was incorrectly initialized");fn.render(At(pf,{integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,supportedChains:d,lightTheme:p,styles:v,onSubmit:()=>{fn&&fn.render("")},onClose:()=>{fn&&fn.render("")},overlay:!0,defaultWalletPicker:h,onPendingTransactionsChange:E,dstTokenLocked:S,dstChainLocked:C,srcTokenLocked:M,srcChainLocked:I}))})}catch(N){throw new Error(`XSwap component error, ${N}`)}};import{faArrowRight as B6,faArrowUpRightFromSquare as F6,faHourglassHalf as L6}from"@fortawesome/free-solid-svg-icons";import{FontAwesomeIcon as mf}from"@fortawesome/react-fontawesome";import{format as D6}from"date-fns";import{useCallback as O6}from"react";import{jsx as hf,jsxs as wh}from"react/jsx-runtime";var xf=({chain:t,token:e,amount:r})=>wh("div",{className:"flex gap-2",children:[hf(Rn,{token:e,chain:t,tokenLogoClassName:"min-w-9 w-9 h-9",generatedLogoClassName:"min-w-9 w-9 h-9 text-[16px]",chainLogoClassName:"w-5"}),wh("div",{className:"flex flex-col text-[12px]",children:[hf("div",{className:"text-t_text_primary text-nowrap",children:`${Number(r)<1e-4?"<0.0001":r} ${e?.symbol?e?.symbol:"unknown"}`}),hf("div",{className:"text-xs text-t_text_primary text-opacity-50",children:t?.displayName})]})]});import{Fragment as U6,jsx as Vt,jsxs as ci}from"react/jsx-runtime";var ks=({transaction:t,supportedChains:e,srcToken:r,dstToken:n})=>{let a=O6(h=>D6(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:[Vt("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:[Vt(mf,{icon:L6,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 (",Vt(hh,{displayFormat:0,expiryTimestamp:new Date(t.estimatedDeliveryTimestamp),customTextOnExpire:"finalizing"}),")"]})]}):t.status==="DONE"?Vt("div",{className:"flex items-center grow justify-end text-xs",children:Vt("div",{className:" mr-1 text-t_text_green",children:"Done"})}):t.status==="REVERTED"?Vt("div",{className:"flex items-center grow justify-end text-xs",children:Vt("div",{className:"w-4 h-4 mr-1 text-t_text_red",children:"Reverted"})}):null,Vt("a",{href:`${t.messageId?`${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:Vt(mf,{icon:F6,className:"w-[14px] h-[14px] text-t_text_primary"})})]})]}),Vt("div",{className:"flex flex-wrap gap-8",children:ci("div",{className:"flex items-center gap-2",children:[Vt(xf,{chain:d,token:r,amount:o}),t.tokenOutAddress&&ci(U6,{children:[Vt(mf,{icon:B6,className:"w-5 h-5 text-t_text_primary opacity-50 mx-1.5"}),Vt(xf,{chain:p,token:n,amount:f})]})]})})]})};import{jsx as H6}from"react/jsx-runtime";var Np=({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 H6(ks,{transaction:t,supportedChains:e,srcToken:n,dstToken:i})};import{createPortal as G6}from"react-dom";import{jsx as vh}from"react/jsx-runtime";var Ep=({id:t,children:e,onCloseClick:r,type:n="waiting",className:i})=>G6(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 V6}from"react";import{Fragment as q6,jsx as zt,jsxs as bf}from"react/jsx-runtime";var z6=({transaction:t,supportedChains:e,srcToken:r,dstToken:n})=>{let[i,a]=V6(!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 bf("div",{className:"flex gap-2 items-end justify-end flex-wrap",onClick:()=>a(d=>!d),children:[i&&zt(ks,{transaction:t,supportedChains:e,srcToken:r,dstToken:n}),zt("div",{className:`text-t_text_primary rounded-xl h-14 w-20 mb-2 cursor-pointer ${o} ${f}`,children:bf("div",{className:"flex gap-2 items-center h-14 w-20 justify-center fill-t_text_primary",children:[zt("div",{className:`${i?"rotate-180":""}`,children:zt(l1,{})}),zt("div",{className:"relative flex items-center justify-center w-9 h-9",children:t?.status==="DONE"?zt("div",{className:"w-5 h-5 fill-t_success_dark",children:zt(as,{})}):bf(q6,{children:[zt("div",{className:"w-5 h-5",children:zt(z1,{})}),zt("div",{className:"absolute flex items-center justify-center top-0 left-0 right-0 bottom-0 text-t_text_primary",children:zt(Vr,{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)},_s=()=>{let t=fi.map(e=>zt(z6,{...e},e.transaction.hash));if(ts===null)throw new Error("XPay was incorrectly initialized");ts.render(zt("div",{className:"fixed bottom-5 right-2 flex flex-col gap-3 pl-9 items-end w-full z-50",children:t}))};import W6 from"@r2wc/core";import Eh from"react";import{createRoot as K6}from"react-dom/client";var X6=(t,e,r)=>{let n=K6(t),i=Eh.createElement(e,r);return n.render(i),{root:n,ReactComponent:e}},J6=({root:t,ReactComponent:e},r)=>{let n=Eh.createElement(e,r);t.render(n)},Q6=({root:t})=>{t.unmount()},kh=(t,e={})=>W6(t,e,{mount:X6,update:J6,unmount:Q6});import{useEffect as Z6,useState as _h}from"react";import{Fragment as j6,jsx as Ms,jsxs as $6}from"react/jsx-runtime";var Y6=({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:M,onDstTokenChange:I,onDstChainChange:N,onSrcTokenChange:B,onSrcChainChange:_,onConnectWallet:L,bridge:U})=>{let[R,W]=_h(!0),[z,Y]=_h([]);Z6(()=>{(async()=>{W(!0);let $=(await ni()).filter(({web3Environment:J,bridgeSupported:T,swapSupported:s})=>J==="mainnet"&&(T||s));Y($),W(!1)})()},[]);let ne=(()=>{try{return typeof h=="string"?JSON.parse(h):h||void 0}catch($){console.error("Error parsing styles:",$)}})();return $6(j6,{children:[Ms("style",{children:$o}),R?Ms("div",{className:"min-h-[532px] w-full flex items-center justify-center",children:Ms(Vr,{className:"w-10 h-10"})}):Ms(pf,{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:ne,onPendingTransactionsChange:v,dstTokenLocked:E,dstChainLocked:S,srcTokenLocked:C,srcChainLocked:M,onDstTokenChange:I,onDstChainChange:N,onSrcTokenChange:B,onSrcChainChange:_,onConnectWallet:L,bridge:U})]})},Is=()=>{if(vt||typeof customElements>"u")return{};let t=kh(Y6,{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 eb}from"@tanstack/react-query";import{useEffect as tb}from"react";import{jsx as nb}from"react/jsx-runtime";var rb=Is();!eb&&typeof customElements<"u"&&(customElements.get("xpay-widget")||customElements.define("xpay-widget",rb));var gf=({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:M,onDstTokenChange:I,onDstChainChange:N,onSrcTokenChange:B,onSrcChainChange:_,onConnectWallet:L,bridge:U})=>(tb(()=>{window.xPayOnPendingTransactionsChange=v,window.xPayOnDstTokenChange=I,window.xPayOnDstChainChange=N,window.xPayOnSrcTokenChange=B,window.xPayOnSrcChainChange=_,window.xPayOnConnectWallet=L},[v,I,N,B,_,L]),nb("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":M,bridge:U}));import ib from"async-retry";var Mh=async(t,e)=>{let r=t.publicRpcUrls[0],n=new ie.Contract(e.toLowerCase(),Hr,ie.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 bp=async(t,e,r,n)=>{let i=await ab(t,e),a=(await ni()).filter(({web3Environment:W,swapSupported:z})=>W==="mainnet"&&z),o=i.logs?.find(W=>W.topics[0]===ie.utils.id(Fu));if(!o)throw new Error(`No transaction event found for chain ${t} tx ${e}`);let f=o?.topics[1],p=new ie.utils.Interface(Lu).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()),M=C?.chainId;if(!M)throw new Error("Unknown destination chain!");let I;r&&(I=C.tokens.find(W=>W.address.toLowerCase()===r.toLowerCase()));let N=Date.now()/1e3,B={hash:i.transactionHash,timestamp:N,sourceChainId:v.chainId,targetChainId:C.chainId,amountWei:h?.tokenAmount.toString(),tokenAddress:S.address,tokenOutAddress:I?.address,tokenOutAmount:n,estimatedDeliveryTimestamp:h?.valueForInstantCcipRecieve.toString()!=="0"?N*1e3+30*1e3:N*1e3+30*60*1e3,status:"IN_PROGRESS"};Ah({transaction:B,supportedChains:a,dstToken:I,srcToken:S}),_s();let _=Mt[M]?.XSwapRouter;if(!_)throw new Error("Unknown destination XSwapRouter!");let L=new ie.Contract(_,Ou,ie.getDefaultProvider(a.find(W=>W.chainId===M)?.publicRpcUrls[0])),U={address:_,topics:[ie.utils.id(Du),f]},R=async()=>{Sh(e),_s(),await new Promise(W=>setTimeout(()=>W(!0),Bu)),Th(e),_s()};vc({transferId:f}).then(W=>{W.status==="DONE"?R():(setTimeout(()=>vc({transferId:f}).then(z=>{z.status==="DONE"&&R()}),30*60*1e3),L.once(U,()=>R()))})},ab=async(t,e)=>{try{let r=(await ni()).find(i=>i.chainId===t),n=new ie.providers.JsonRpcProvider(r?.publicRpcUrls[0]);return await ib(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 yf=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:M,onDstTokenChange:I,onDstChainChange:N,onSrcTokenChange:B,onSrcChainChange:_,bridge:L})=>{let U=(await ni()).filter(({web3Environment:R,swapSupported:W})=>R==="mainnet"&&W);ob(t,U,e,r,n,i),await gh({integratorId:t,dstChainId:e,dstTokenAddr:r,srcChainId:n,srcTokenAddr:i,customContractCalls:a,desc:o,dstDisplayTokenAddr:f,supportedChains:U,lightTheme:d,defaultWalletPicker:p,styles:h,onPendingTransactionsChange:v,dstTokenLocked:E,dstChainLocked:S,srcTokenLocked:C,srcChainLocked:M,onDstTokenChange:I,onDstChainChange:N,onSrcTokenChange:B,onSrcChainChange:_,bridge:L})},ob=(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 sb=Is();ju();var cb={openTransactionModal:yf,TxWidget:gf,TxWidgetWC:sb},tL=cb;export{vf as ContractName,Xr as Ecosystem,Dh as Environment,di as TxStatus,gf as TxWidget,sb as TxWidgetWC,li as Web3Environment,Cf as XSwapCallType,tL as default,yf as openTransactionModal};
93
93
  /*! Bundled license information:
94
94
 
95
95
  js-sha3/src/sha3.js:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xswap-link/sdk",
3
- "version": "0.9.5",
3
+ "version": "0.9.6",
4
4
  "description": "JavaScript SDK for XSwap platform",
5
5
  "homepage": "https://github.com/xswap-link/xswap-sdk",
6
6
  "repository": {
@@ -4,7 +4,7 @@ import { Slippage } from "./Slippage";
4
4
 
5
5
  export const SettingsView = () => {
6
6
  return (
7
- <div className="flex flex-col gap-5">
7
+ <div className="flex flex-col gap-5 px-4">
8
8
  <Delivery />
9
9
  <InfiniteApproval />
10
10
  <Slippage />