@nexus-cross/connect-kit-react 1.3.4 → 1.3.5-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- var mt="1.3.4";var wt="__nexusCrossAppLauncherRuntime";function ro(){if(typeof window>"u")return null;let e=window;return e[wt]??(e[wt]={mode:"dapp-ui"}),e[wt]}function so(e){if(e.scheduled)return;e.scheduled=!0;let t=()=>{if(e.scheduled=!1,e.loggedMode!==e.mode){if(e.mode==="connect-kit-react"){let n=e.connectKitVersion??mt;console.info(`[CROSSx App Launcher] connect-kit-react v${n} \uCD08\uAE30\uD654 \uC644\uB8CC (dapp-ui v${mt}, \uC0AC\uC6A9 \uBAA8\uB4DC: connect-kit)`)}else console.info(`[CROSSx App Launcher] dapp-ui v${mt} \uCD08\uAE30\uD654 \uC644\uB8CC (\uC0AC\uC6A9 \uBAA8\uB4DC: dapp-ui only)`);e.loggedMode=e.mode}};typeof queueMicrotask=="function"?queueMicrotask(t):Promise.resolve().then(t)}function Zt(){let e=ro();e&&(e.mode="connect-kit-react",e.connectKitVersion=mt,so(e))}import{useCallback as Be,useEffect as le,useMemo as Le,useRef as He,useState as Ve}from"react";import{WagmiProvider as po,useAccount as fo,useChainId as go,useConnect as bo,useDisconnect as yo,useSwitchChain as ho}from"wagmi";import{QueryClient as wo,QueryClientProvider as Co}from"@tanstack/react-query";import{clearWalletSessionStorage as on,onOpenOtherWallets as ko,pickInitialState as To,resolveCurrentWallet as Io}from"@nexus-cross/connect-kit-wagmi";import{resolveThemeMode as xo}from"@nexus-cross/connect-kit-core";import{buildDesignSystemCss as So}from"@nexus-cross/crossx-design-system";import{OnRampProvider as vo}from"@nexus-cross/onramp/react";import{KycProvider as Po}from"@nexus-cross/kyc/react";import{createContext as io,useContext as ao}from"react";var Et=io(null);function We(){let e=ao(Et);if(!e)throw new Error("useCrossConnectKit must be used within <CrossConnectKitProvider>");return e}import{createContext as co,useContext as Jt}from"react";var Ct=co(null);function lo(){let e=Jt(Ct);if(!e)throw new Error("useCrossConnectKitTheme must be used within <CrossConnectKitProvider>");return e}function pt(){return Jt(Ct)}import{useCallback as uo,useMemo as en}from"react";import{WalletConnectModal as tn}from"@nexus-cross/dapp-ui";import{jsx as nn}from"react/jsx-runtime";var mo=new Set(["cross_wallet","cross_extension","metamask","binance"]);function _t({open:e,onOpenChange:t}){let{connect:n,availableWallets:i,oauth:o,extraWallets:c,walletAllowlist:p,kitConfig:b}=We(),r=pt()?.mode??"dark",C=en(()=>{let g=p?new Set(p):null,w={};for(let P of i){if(!mo.has(P.walletId)||g&&!g.has(P.walletId))continue;let v=P.walletId;w[v]=()=>{n(P.walletId)}}for(let[P,v]of Object.entries(c))v&&(g&&!g.has(P)||(w[P]=v));return w},[i,n,c,p]),T=en(()=>{if(o)return{apple:()=>{o.signIn("apple")},google:()=>{o.signIn("google")}}},[o]),I=uo(g=>t(g),[t]);return nn(tn,{wallets:C,socialProviders:T,termsUrl:b.legal?.termsUrl,privacyUrl:b.legal?.privacyUrl,theme:r,open:e,onOpenChange:I,children:nn(tn.Content,{})})}import{jsx as ot,jsxs as an}from"react/jsx-runtime";var Ao=new wo,Ot="crossx-kit:last-wallet-intent",Ro=15e3;function rn(e,t){return Promise.race([e.then(()=>{},()=>{}),new Promise(n=>setTimeout(n,t))])}function Bo(e){let t=[],n=e,i=0;for(;n&&i<5;){let o=n;typeof o.message=="string"&&t.push(o.message),n=o.cause,i+=1}return t.some(o=>/external wallet connection/i.test(o))}function Eo(){if(typeof window>"u")return null;try{return window.localStorage.getItem(Ot)??null}catch{return null}}function sn(e){if(!(typeof window>"u"))try{e?window.localStorage.setItem(Ot,e):window.localStorage.removeItem(Ot)}catch{}}function _o(e,t){if(typeof window>"u")return t;try{let n=window.localStorage.getItem(e);return n==="cross"||n==="reown"?n:t}catch{return t}}function Oo(e,t){if(!(typeof window>"u"))try{window.localStorage.setItem(e,t)}catch{}}function No({children:e,config:t,activeProvider:n,onRequestProviderSwap:i,pendingConnectWalletId:o,clearPending:c,themeMode:p,themeTokens:b,extraWallets:f,walletAllowlist:r}){let[C,T]=Ve(!1),[I,g]=Ve(()=>Eo()),[w,P]=Ve(null),{address:v,isConnected:x,isConnecting:N,isReconnecting:U,connector:B}=fo(),{connectors:V,connectAsync:j}=bo(),{disconnectAsync:M}=yo(),{kitConfig:F,connectorRegistry:G,crossProvider:ve,reownProvider:O}=t,E=n==="cross"?ve:O,W=Le(()=>!x||!B?null:Io(G,B.id,I),[x,B,G,I]),he=Le(()=>G.entries.filter(u=>u.type!=="embedded"),[G]),Ye=He(v);Ye.current=v;let X=F.embeddedProjectId?.trim()||F.crossProjectId?.trim(),ie=!!F.onRampEnabled&&!!X,we=Le(()=>!ie||!X?null:{projectId:X,walletState:{getAddress:()=>Ye.current}},[ie,X]),Ne=He(B);Ne.current=B;let Ce=F.embeddedProjectId?.trim()||F.crossProjectId?.trim(),Ue=!!F.kycEnabled&&!!Ce,fe=Le(()=>!Ue||!Ce?null:{projectId:Ce,getAccessToken:async()=>{let u=Ne.current;if(!(!u||typeof u.getProvider!="function"))try{return(await(await u.getProvider())?.sdk?.getUserInfo?.())?.data?.accessToken||void 0}catch{return}}},[Ue,Ce]);le(()=>ko(()=>T(!0)),[]),le(()=>{if(!C||typeof document>"u")return;let u=setTimeout(()=>{document.querySelectorAll("#__crossx-confirm-overlay").forEach(l=>l.remove())},50);return()=>clearTimeout(u)},[C]);let xe=He(x),ae=He(x);xe.current=x;let Ze=He(!1);le(()=>{console.debug("[crossx-kit] state",{activeProvider:n,isConnected:x,isConnecting:N,isReconnecting:U,activeConnectorId:B?.id,currentWallet:W,lastIntent:I})},[n,x,N,U,B?.id,W,I]),le(()=>{x&&!ae.current&&E?.closeModal?.({kitConfig:F}),ae.current=x},[x,E,F]),le(()=>{x&&P(null)},[x]);let Je=go(),{switchChainAsync:Ke}=ho(),$e=He(null);le(()=>{if(!F.enforceDefaultNetworkOnConnect)return;let u=F.defaultNetwork?.id;if(!u)return;if(!x||!v||!B){$e.current=null;return}let l=`${B.id}:${v}`;$e.current!==l&&($e.current=l,Je!==u&&Ke({chainId:u}).catch(()=>{}))},[F.enforceDefaultNetworkOnConnect,F.defaultNetwork,x,v,B,Je,Ke]);let ce=Be(u=>V.find(l=>l.id===u),[V]);le(()=>{let u=G.getEntry("cross_embedded");if(!u)return;let l=ce(u.connectorId);if(!l)return;let k=!1;return(async()=>{try{let h=await l.getProvider();if(k)return;h?.sdk?.applyTheme?.(p,b??void 0)}catch(h){console.debug("[crossx-kit] applyTheme skipped:",h)}})(),()=>{k=!0}},[G,ce,p,b]);let Pe=Be(u=>{g(u),sn(u)},[]),q=Be(()=>{g(null),sn(null),P(null)},[]);le(()=>{if(!E?.subscribeModalState)return;let u=!1;return E.subscribeModalState({kitConfig:F},l=>{if(Ze.current=l,l){u=!0;return}u&&(u=!1,setTimeout(()=>{xe.current||(async()=>{try{await M()}catch{}q()})()},250))})},[E,F,M,q]),le(()=>{if(!w||x||typeof window>"u"||w==="cross_embedded")return;let u=typeof document<"u"&&!document.hasFocus(),l=null,k=()=>{u=!0},h=()=>{u&&(l&&clearTimeout(l),l=setTimeout(()=>{xe.current||Ze.current||(async()=>{try{await M()}catch{}q()})()},1e3))};return window.addEventListener("blur",k),window.addEventListener("focus",h),()=>{window.removeEventListener("blur",k),window.removeEventListener("focus",h),l&&clearTimeout(l)}},[w,x,M,q]);let ge=Be(async u=>{console.debug("[crossx-kit] runConnect enter",{walletId:u,activeProvider:n,isConnected:x,activeConnectorId:B?.id});let l=G.getEntry(u);if(!l){if((u==="metamask"||u==="binance")&&!O){console.error(`[crossx-kit] "${u}" requires the Reown adapter, but it is not configured. Pass \`reownProjectId\` (and ensure \`reown\` is not set to \`false\`) when calling createConnectKitConfig() or createCrossxConfig() to enable WalletConnect-based wallets.`);return}console.error(`[crossx-kit] Unknown walletId: "${u}"`);return}if(P(u),l.providerKind!==n){console.debug("[crossx-kit] provider swap needed",{from:n,to:l.providerKind,walletId:u}),Pe(u);try{await M()}catch{}await new Promise(h=>setTimeout(h,0)),i(l.providerKind,u);return}if(Pe(u),E?.beforeConnect)try{let h=await E.beforeConnect({kitConfig:F,themeMode:p},u);if(console.debug("[crossx-kit] beforeConnect result",{walletId:u,result:h}),h==="handled")return}catch(h){console.warn('[crossx-kit] adapter.beforeConnect threw for "%s":',u,h)}let k=ce(l.connectorId);if(console.debug("[crossx-kit] findConnector",{lookupId:l.connectorId,found:k?.id,availableIds:V.map(h=>h.id)}),!k){console.error(`[crossx-kit] Connector "${l.connectorId}" not found on provider "${l.providerKind}". Available: ${V.map(h=>h.id).join(", ")}`),q();return}try{console.debug("[crossx-kit] connectAsync start",{connectorId:k.id});let h=await j({connector:k});console.debug("[crossx-kit] connectAsync resolved",{accountsLen:h.accounts.length,chainId:h.chainId});return}catch(h){if(!Bo(h)){console.error('[crossx-kit] connectAsync error for "%s":',u,h);try{await M()}catch{}}if(!l.fallbackConnectorId){q();return}}if(l.fallbackConnectorId){let h=ce(l.fallbackConnectorId);if(h)try{await j({connector:h})}catch(L){console.error('[crossx-kit] Fallback connect failed for "%s":',u,L);try{await M()}catch{}q()}else q()}},[G,V,ce,j,M,Pe,q,E,n,F,i,p]);le(()=>{if(!o)return;let u=o;c(),ge(u)},[o,n]);let et=Be(async()=>{T(!0)},[]),s=Be(async()=>{try{await M()}catch(u){console.error("[crossx-kit] wagmi disconnect error:",u)}if(E?.teardown)try{await E.teardown({kitConfig:F})}catch(u){console.error("[crossx-kit] adapter teardown error:",u)}on(),q()},[M,E,F,q]),a=Be(async()=>{await rn(M(),3e3);try{let u=G.getEntry("cross_embedded"),l=u&&ce(u.connectorId);if(l?.getProvider){let k=await Promise.race([l.getProvider(),new Promise(L=>setTimeout(L,3e3))]),h=k?.sdk?.signOut;typeof h=="function"&&await rn(h.call(k.sdk),3e3)}}catch{}on()},[G,ce,M]),d=Be(async()=>{let u=G.getEntry("cross_embedded");if(!u)return null;let l=ce(u.connectorId);if(!l)return null;try{let k=await l.getProvider(),h=k?.sdk;if(!h?.selectWallet)return null;let L=await h.selectWallet(h.currentAddress??void 0);return L?.address&&k.notifyAccountsChanged&&k.notifyAccountsChanged([L.address]),L}catch{return null}},[G,ce]),m=Le(()=>{let u=t.oauth;return u?{signIn:async l=>{P("cross_embedded");try{await u.signIn(l)}catch(k){throw P(null),k}}}:null},[t.oauth]),y=He(!1);le(()=>{if(n!=="cross"||x||N||U||w!=null||y.current)return;let u=G.getEntry("cross_embedded");if(!u)return;let l=ce(u.connectorId);if(!l)return;y.current=!0;let k=!1;return(async()=>{try{let h=await l.isAuthorized?.();if(k||!h)return;await j({connector:l})}catch{}})(),()=>{k=!0}},[n,x,N,U,w,G,ce,j]),le(()=>{if(w!=="cross_embedded"||x||typeof window>"u")return;let u=!document.hasFocus(),l=()=>{u=!0};window.addEventListener("blur",l);let k=setTimeout(()=>{xe.current||u||(console.warn("[crossx-kit] embedded sign-in stalled before the OAuth popup opened \u2014 clearing the stale session so a retry starts clean"),q(),a())},Ro);return()=>{window.removeEventListener("blur",l),clearTimeout(k)}},[w,x,q,a]);let A=w!=null&&!x,R=Le(()=>({kitConfig:F,connectorRegistry:G,availableWallets:he,connect:ge,connectWallet:et,disconnect:s,selectWallet:d,currentWallet:W,lastIntent:I,isConnecting:A,connectingWalletId:w,openOtherWallets:()=>T(!0),closeOtherWallets:()=>T(!1),otherWalletsOpen:C,oauth:m,extraWallets:f,walletAllowlist:r,onRampEnabled:ie}),[F,G,he,ge,et,s,d,W,I,A,w,C,m,f,r,ie]),_=an(Et.Provider,{value:R,children:[e,ot(_t,{open:C,onOpenChange:T})]});return fe&&(_=ot(Po,{config:fe,children:_})),we&&(_=ot(vo,{config:we,children:_})),_}var Fo=[/Connection interrupted while trying to subscribe/i,/No matching key\. subscription:/i,/Proposal expired/i];function Wo(e){let t=e?.message;return typeof t!="string"?!1:Fo.some(n=>n.test(t))}var Lo={};function Do(e){return e&&{...e,connections:new Map,current:null}}function Mo({children:e,config:t,initialState:n,extraWallets:i=Lo,walletAllowlist:o}){let[c,p]=Ve(()=>_o(t.activeProviderStorageKey,t.defaultProvider)),[b,f]=Ve(null),r=He(!1),{kitConfig:C}=t,[T,I]=Ve(null),[g,w]=Ve(null),[P,v]=Ve(0),x=Le(()=>xo(C.theme,C.autoDetectTheme),[C.theme,C.autoDetectTheme,P]),N=T??x,U=g??C.themeTokens;le(()=>{if(!C.autoDetectTheme||T||typeof window>"u"||!window.matchMedia)return;let O=window.matchMedia("(prefers-color-scheme: dark)"),E=()=>v(W=>W+1);try{return O.addEventListener("change",E),()=>O.removeEventListener("change",E)}catch{return O.addListener(E),()=>O.removeListener(E)}},[C.autoDetectTheme,T]),le(()=>{if(typeof document>"u")return;let O=document.documentElement,E=O.getAttribute("data-ds-theme"),W=O.getAttribute("data-theme");return O.setAttribute("data-ds-theme",N),W||O.setAttribute("data-theme",N),()=>{E==null?O.removeAttribute("data-ds-theme"):O.setAttribute("data-ds-theme",E),W==null&&O.removeAttribute("data-theme")}},[N]);let B=Le(()=>So(t.designSystem),[t.designSystem]),V=Le(()=>({mode:N,tokens:U,setThemeMode:O=>I(O),setThemeTokens:O=>w(O)}),[N,U]);le(()=>{if(typeof window>"u")return;let O=E=>{Wo(E.reason)&&E.preventDefault()};return window.addEventListener("unhandledrejection",O),()=>window.removeEventListener("unhandledrejection",O)},[]);let j=Be((O,E)=>{r.current||(r.current=!0,f(E),p(O),Oo(t.activeProviderStorageKey,O),queueMicrotask(()=>{r.current=!1}))},[t.activeProviderStorageKey]),M=Be(()=>f(null),[]),F=c==="cross"?t.crossWagmiConfig:t.reownWagmiConfig,G=Do(To(n,c));if(!F){if(!(c==="cross"?t.reownWagmiConfig:t.crossWagmiConfig))throw new Error("[crossx-kit] createCrossxConfig returned no wagmi Config for either side");let E=c==="cross"?"reown":"cross";queueMicrotask(()=>p(E))}let ve=F??(c==="cross"?t.reownWagmiConfig:t.crossWagmiConfig);return an(Ct.Provider,{value:V,children:[ot("style",{"data-crossx-design-system":"",children:B}),ot(po,{config:ve,initialState:G,children:ot(Co,{client:Ao,children:ot(No,{config:t,activeProvider:c,onRequestProviderSwap:j,pendingConnectWalletId:b,clearPending:M,themeMode:N,themeTokens:U,extraWallets:i,walletAllowlist:o??t.kitConfig.wallets??null,children:e})})},c)]})}import{useCallback as ze,useEffect as qr,useMemo as yt}from"react";import{useQueryClient as Hr}from"@tanstack/react-query";import{useAccount as Vr,useChainId as jr,useConfig as Qr,useSendTransaction as zr,useSwitchChain as Xr}from"wagmi";import{getPublicClient as Ut,readContracts as On}from"wagmi/actions";import{WalletInfo as Kt,ConnectorId as Xe,resolveEnvironment as Yr}from"@nexus-cross/dapp-ui";import{useOptionalOnRamp as Zr,useOptionalOnRampEligibility as Jr}from"@nexus-cross/onramp/react";import{APPLE_ICON as Vt,BINANCE_ICON as Wn,CROSSX_ICON as Ht,EXTENSION_ICON as es,GOOGLE_ICON as Ln,METAMASK_ICON as Dn}from"@nexus-cross/connect-kit-wagmi";import{useCallback as te,useMemo as Te,useRef as Go}from"react";import{useQueries as ln,useQuery as je}from"@tanstack/react-query";import{encodeFunctionData as ft,formatUnits as vt,parseSignature as Uo,parseUnits as Ko}from"viem";import{getChainId as Nt,getPublicClient as xn,readContract as Se,signTypedData as $o,switchChain as un,waitForTransactionReceipt as qo,writeContract as mn}from"wagmi/actions";import{useConfig as Ho}from"wagmi";async function kt(e,t,n){if(!(!n||t===void 0))try{if(e.getChainId()===t)return;await e.switchChain(t)}catch{}}var dt=10000n;function cn(e){let t=e==="auto"?1:Number(e||"1");return!Number.isFinite(t)||t<0?100n:BigInt(Math.min(1e4,Math.floor(t*100)))}function Tt(e,t){let n=cn(t);return n>=dt?0n:e*(dt-n)/dt}function dn(e,t){let n=cn(t);return(e*(dt+n)+(dt-1n))/dt}function Vo(e){return e!=="bridge"}var Ge="0x0000000000000000000000000000000000000000",Ie=100,ut=18,jo=180000n,Qo=250000n,Sn=new Set([56,97]),zo=130n,Xo=100n,Yo={dev:"https://stg-contents.crosstoken.io/frontend/game-token/json/hidden-path.json",stage:"https://stg-contents.crosstoken.io/frontend/game-token/json/hidden-path.json",production:"https://contents.crosstoken.io/frontend/game-token/json/hidden-path.json"},Zo={dev:"dev",stage:"stg",production:"prod"};function Jo(e,t){let n=e?.[Zo[t]]?.hiddenPairs;if(!Array.isArray(n))return null;let i=n.filter(o=>!!o&&typeof o=="object"&&typeof o.fromKey=="string"&&typeof o.toKey=="string");return i.length>0?i:null}var er={dev:"https://stg-contents.crosstoken.io/frontend/common/app-launcher/contracts.json",stage:"https://stg-contents.crosstoken.io/frontend/common/app-launcher/contracts.json",production:"https://contents.crosstoken.io/frontend/common/app-launcher/contracts.json"},tr=["BSC_CROSS","W_CROSS","NATIVE_CROSS","USDTX","CROSSD","USDTB","SWAP_BRIDGE_ROUTER"],nr={BSC_CROSS:Ge,W_CROSS:Ge,NATIVE_CROSS:Ge,USDTX:Ge,CROSSD:Ge,USDTB:Ge,SWAP_BRIDGE_ROUTER:Ge},or=/^0x[0-9a-fA-F]{40}$/;function rr(e,t){let n=typeof e=="string"?e:e?.[t];return typeof n=="string"&&or.test(n)?n:null}function sr(e,t){if(!e?.bridge)return null;let n=e.envToNetwork?.[t]??(t==="production"?"mainnet":"testnet"),i={};for(let o of tr){let c=rr(e.bridge[o],n);if(!c)return null;i[o]=c}return i}var ir={dev:{bridgeApi:"https://stg-bridge-api.crosstoken.io/bridge",walletApi:"https://stg-wallet-server.crosstoken.io/api",chainIds:{cross:612044,bsc:97}},stage:{bridgeApi:"https://stg-bridge-api.crosstoken.io/bridge",walletApi:"https://stg-wallet-server.crosstoken.io/api",chainIds:{cross:612044,bsc:97}},production:{bridgeApi:"https://bridge-api.crosstoken.io/bridge",walletApi:"https://wallet-server.crosstoken.io/api",chainIds:{cross:612055,bsc:56}}},rt=[{type:"function",name:"quoter",stateMutability:"view",inputs:[],outputs:[{name:"",type:"address"}]},{type:"function",name:"swapRouter",stateMutability:"view",inputs:[],outputs:[{name:"",type:"address"}]},{type:"function",name:"getAmountSwapBridgeOut",stateMutability:"view",inputs:[{name:"toChainID",type:"uint256"},{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"fee",type:"uint24"},{name:"amountIn",type:"uint256"}],outputs:[{name:"ok",type:"bool"},{name:"swapAmountOut",type:"uint256"},{name:"bridgeValue",type:"uint256"},{name:"networkFee",type:"uint256"},{name:"exFee",type:"uint256"}]},{type:"function",name:"getAmountSwapBridgeIn",stateMutability:"view",inputs:[{name:"toChainID",type:"uint256"},{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"fee",type:"uint24"},{name:"bridgeValue",type:"uint256"}],outputs:[{name:"ok",type:"bool"},{name:"amountIn",type:"uint256"},{name:"swapAmountOut",type:"uint256"},{name:"networkFee",type:"uint256"},{name:"exFee",type:"uint256"}]},{type:"function",name:"swapBridgeExactInputSingle",stateMutability:"nonpayable",inputs:[{name:"params",type:"tuple",components:[{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"fee",type:"uint24"},{name:"amountIn",type:"uint256"},{name:"amountOutMinimum",type:"uint256"},{name:"sqrtPriceLimitX96",type:"uint160"},{name:"bridgeParams",type:"tuple",components:[{name:"toChainID",type:"uint256"},{name:"recipient",type:"address"},{name:"extraData",type:"bytes"}]}]},{name:"deadline",type:"uint256"}],outputs:[{name:"amountOut",type:"uint256"}]},{type:"function",name:"swapBridgeExactOutputSingle",stateMutability:"nonpayable",inputs:[{name:"params",type:"tuple",components:[{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"fee",type:"uint24"},{name:"amountOut",type:"uint256"},{name:"amountInMaximum",type:"uint256"},{name:"sqrtPriceLimitX96",type:"uint160"},{name:"bridgeParams",type:"tuple",components:[{name:"toChainID",type:"uint256"},{name:"recipient",type:"address"},{name:"extraData",type:"bytes"}]}]},{name:"deadline",type:"uint256"}],outputs:[{name:"amountIn",type:"uint256"}]}],Ft=[{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"}],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"allowance",stateMutability:"view",inputs:[{name:"owner",type:"address"},{name:"spender",type:"address"}],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"approve",stateMutability:"nonpayable",inputs:[{name:"spender",type:"address"},{name:"amount",type:"uint256"}],outputs:[{name:"",type:"bool"}]}],pn=[{type:"function",name:"name",stateMutability:"view",inputs:[],outputs:[{name:"",type:"string"}]},{type:"function",name:"nonces",stateMutability:"view",inputs:[{name:"owner",type:"address"}],outputs:[{name:"",type:"uint256"}]}],fn=[{type:"function",name:"quoteExactInputSingle",stateMutability:"nonpayable",inputs:[{name:"params",type:"tuple",components:[{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"amountIn",type:"uint256"},{name:"fee",type:"uint24"},{name:"sqrtPriceLimitX96",type:"uint160"}]}],outputs:[{name:"amountOut",type:"uint256"},{name:"sqrtPriceX96After",type:"uint160"},{name:"initializedTicksCrossed",type:"uint32"},{name:"gasEstimate",type:"uint256"}]},{type:"function",name:"quoteExactOutputSingle",stateMutability:"nonpayable",inputs:[{name:"params",type:"tuple",components:[{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"amount",type:"uint256"},{name:"fee",type:"uint24"},{name:"sqrtPriceLimitX96",type:"uint160"}]}],outputs:[{name:"amountIn",type:"uint256"},{name:"sqrtPriceX96After",type:"uint160"},{name:"initializedTicksCrossed",type:"uint32"},{name:"gasEstimate",type:"uint256"}]}],ar=[{type:"function",name:"slot0",stateMutability:"view",inputs:[],outputs:[{name:"sqrtPriceX96",type:"uint160"},{name:"tick",type:"int24"},{name:"observationIndex",type:"uint16"},{name:"observationCardinality",type:"uint16"},{name:"observationCardinalityNext",type:"uint16"},{name:"feeProtocol",type:"uint8"},{name:"unlocked",type:"bool"}]}],De=[{type:"function",name:"exactInputSingle",stateMutability:"payable",inputs:[{name:"params",type:"tuple",components:[{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"fee",type:"uint24"},{name:"recipient",type:"address"},{name:"deadline",type:"uint256"},{name:"amountIn",type:"uint256"},{name:"amountOutMinimum",type:"uint256"},{name:"sqrtPriceLimitX96",type:"uint160"}]}],outputs:[{name:"amountOut",type:"uint256"}]},{type:"function",name:"multicall",stateMutability:"payable",inputs:[{name:"data",type:"bytes[]"}],outputs:[{name:"results",type:"bytes[]"}]},{type:"function",name:"unwrapWETH9",stateMutability:"payable",inputs:[{name:"amountMinimum",type:"uint256"},{name:"recipient",type:"address"}],outputs:[]},{type:"function",name:"refundETH",stateMutability:"payable",inputs:[],outputs:[]}],cr=[{type:"function",name:"bridgeToken",stateMutability:"payable",inputs:[{name:"toChainID",type:"uint256"},{name:"fromToken",type:"address"},{name:"to",type:"address"},{name:"value",type:"uint256"},{name:"gasFee",type:"uint256"},{name:"exFee",type:"uint256"},{name:"extraData",type:"bytes"}],outputs:[{name:"",type:"bool"}]}];async function vn(e){let t="";try{t=await e.text()}catch{}if(t){try{let n=JSON.parse(t),i=typeof n.data=="string"&&n.data||typeof n.message=="string"&&n.message||"";if(i)return`${i} (status ${e.status})`}catch{}return`${t.slice(0,300)} (status ${e.status})`}return`status ${e.status}`}async function Ee(e,t){let n=await fetch(e,{cache:"no-store",signal:t});if(!n.ok)throw new Error(`CrossD bridge adapter request failed: ${await vn(n)}`);let i=await n.json();if(i&&typeof i=="object"&&"code"in i&&typeof i.code=="number"&&i.code!==200)throw new Error(i.message||`CrossD bridge adapter API error: ${i.code}`);return i&&typeof i=="object"&&"data"in i?i.data:i}async function gn(e,t,n){let i=await fetch(e,{method:"POST",cache:"no-store",signal:n,headers:{"content-type":"application/json"},body:JSON.stringify(t)});if(!i.ok)throw new Error(`CrossD bridge adapter request failed: ${await vn(i)}`);let o=await i.json();if(o&&typeof o=="object"&&"code"in o&&typeof o.code=="number"&&o.code!==200)throw new Error(o.message||`CrossD bridge adapter API error: ${o.code}`);return o&&typeof o=="object"&&"data"in o?o.data:o}function dr(e){return new Promise(t=>setTimeout(t,e))}async function lr(e,t,{attempts:n=60,intervalMs:i=2e3}={}){for(let o=0;o<n;o+=1){try{let c=await Ee(`${e}/permit-hash/${t}`);if(Dt(c))return c}catch{}await dr(i)}return null}function oe(e,t){return`${e}-${t.toLowerCase()}`}function ue(e){return oe(e.chainId,e.address)}function _e(e){return e==="swap"||e==="deposit-swap"||e==="swap-withdraw"}function ur(e){let t=e instanceof Error?e.message:typeof e=="string"?e:"",n=t.toLowerCase();return n.includes("quoteexactinputsingle")||n.includes("quoteexactoutputsingle")||n.includes("getamountswapbridgeout")||n.includes("getamountswapbridgein")||n.includes("execution reverted")?"Amount is too large for this route.":t.split(`
1
+ var mt="1.3.5";var wt="__nexusCrossAppLauncherRuntime";function ro(){if(typeof window>"u")return null;let e=window;return e[wt]??(e[wt]={mode:"dapp-ui"}),e[wt]}function so(e){if(e.scheduled)return;e.scheduled=!0;let t=()=>{if(e.scheduled=!1,e.loggedMode!==e.mode){if(e.mode==="connect-kit-react"){let n=e.connectKitVersion??mt;console.info(`[CROSSx App Launcher] connect-kit-react v${n} \uCD08\uAE30\uD654 \uC644\uB8CC (dapp-ui v${mt}, \uC0AC\uC6A9 \uBAA8\uB4DC: connect-kit)`)}else console.info(`[CROSSx App Launcher] dapp-ui v${mt} \uCD08\uAE30\uD654 \uC644\uB8CC (\uC0AC\uC6A9 \uBAA8\uB4DC: dapp-ui only)`);e.loggedMode=e.mode}};typeof queueMicrotask=="function"?queueMicrotask(t):Promise.resolve().then(t)}function Zt(){let e=ro();e&&(e.mode="connect-kit-react",e.connectKitVersion=mt,so(e))}import{useCallback as Be,useEffect as le,useMemo as Le,useRef as He,useState as Ve}from"react";import{WagmiProvider as po,useAccount as fo,useChainId as go,useConnect as bo,useDisconnect as yo,useSwitchChain as ho}from"wagmi";import{QueryClient as wo,QueryClientProvider as Co}from"@tanstack/react-query";import{clearWalletSessionStorage as on,onOpenOtherWallets as ko,pickInitialState as To,resolveCurrentWallet as Io}from"@nexus-cross/connect-kit-wagmi";import{resolveThemeMode as xo}from"@nexus-cross/connect-kit-core";import{buildDesignSystemCss as So}from"@nexus-cross/crossx-design-system";import{OnRampProvider as vo}from"@nexus-cross/onramp/react";import{KycProvider as Po}from"@nexus-cross/kyc/react";import{createContext as io,useContext as ao}from"react";var Et=io(null);function We(){let e=ao(Et);if(!e)throw new Error("useCrossConnectKit must be used within <CrossConnectKitProvider>");return e}import{createContext as co,useContext as Jt}from"react";var Ct=co(null);function lo(){let e=Jt(Ct);if(!e)throw new Error("useCrossConnectKitTheme must be used within <CrossConnectKitProvider>");return e}function pt(){return Jt(Ct)}import{useCallback as uo,useMemo as en}from"react";import{WalletConnectModal as tn}from"@nexus-cross/dapp-ui";import{jsx as nn}from"react/jsx-runtime";var mo=new Set(["cross_wallet","cross_extension","metamask","binance"]);function _t({open:e,onOpenChange:t}){let{connect:n,availableWallets:i,oauth:o,extraWallets:c,walletAllowlist:p,kitConfig:b}=We(),r=pt()?.mode??"dark",C=en(()=>{let g=p?new Set(p):null,w={};for(let P of i){if(!mo.has(P.walletId)||g&&!g.has(P.walletId))continue;let v=P.walletId;w[v]=()=>{n(P.walletId)}}for(let[P,v]of Object.entries(c))v&&(g&&!g.has(P)||(w[P]=v));return w},[i,n,c,p]),T=en(()=>{if(o)return{apple:()=>{o.signIn("apple")},google:()=>{o.signIn("google")}}},[o]),I=uo(g=>t(g),[t]);return nn(tn,{wallets:C,socialProviders:T,termsUrl:b.legal?.termsUrl,privacyUrl:b.legal?.privacyUrl,theme:r,open:e,onOpenChange:I,children:nn(tn.Content,{})})}import{jsx as ot,jsxs as an}from"react/jsx-runtime";var Ao=new wo,Ot="crossx-kit:last-wallet-intent",Ro=15e3;function rn(e,t){return Promise.race([e.then(()=>{},()=>{}),new Promise(n=>setTimeout(n,t))])}function Bo(e){let t=[],n=e,i=0;for(;n&&i<5;){let o=n;typeof o.message=="string"&&t.push(o.message),n=o.cause,i+=1}return t.some(o=>/external wallet connection/i.test(o))}function Eo(){if(typeof window>"u")return null;try{return window.localStorage.getItem(Ot)??null}catch{return null}}function sn(e){if(!(typeof window>"u"))try{e?window.localStorage.setItem(Ot,e):window.localStorage.removeItem(Ot)}catch{}}function _o(e,t){if(typeof window>"u")return t;try{let n=window.localStorage.getItem(e);return n==="cross"||n==="reown"?n:t}catch{return t}}function Oo(e,t){if(!(typeof window>"u"))try{window.localStorage.setItem(e,t)}catch{}}function No({children:e,config:t,activeProvider:n,onRequestProviderSwap:i,pendingConnectWalletId:o,clearPending:c,themeMode:p,themeTokens:b,extraWallets:f,walletAllowlist:r}){let[C,T]=Ve(!1),[I,g]=Ve(()=>Eo()),[w,P]=Ve(null),{address:v,isConnected:x,isConnecting:N,isReconnecting:U,connector:B}=fo(),{connectors:V,connectAsync:j}=bo(),{disconnectAsync:M}=yo(),{kitConfig:F,connectorRegistry:G,crossProvider:ve,reownProvider:O}=t,E=n==="cross"?ve:O,W=Le(()=>!x||!B?null:Io(G,B.id,I),[x,B,G,I]),he=Le(()=>G.entries.filter(u=>u.type!=="embedded"),[G]),Ye=He(v);Ye.current=v;let X=F.embeddedProjectId?.trim()||F.crossProjectId?.trim(),ie=!!F.onRampEnabled&&!!X,we=Le(()=>!ie||!X?null:{projectId:X,walletState:{getAddress:()=>Ye.current}},[ie,X]),Ne=He(B);Ne.current=B;let Ce=F.embeddedProjectId?.trim()||F.crossProjectId?.trim(),Ue=!!F.kycEnabled&&!!Ce,fe=Le(()=>!Ue||!Ce?null:{projectId:Ce,getAccessToken:async()=>{let u=Ne.current;if(!(!u||typeof u.getProvider!="function"))try{return(await(await u.getProvider())?.sdk?.getUserInfo?.())?.data?.accessToken||void 0}catch{return}}},[Ue,Ce]);le(()=>ko(()=>T(!0)),[]),le(()=>{if(!C||typeof document>"u")return;let u=setTimeout(()=>{document.querySelectorAll("#__crossx-confirm-overlay").forEach(l=>l.remove())},50);return()=>clearTimeout(u)},[C]);let xe=He(x),ae=He(x);xe.current=x;let Ze=He(!1);le(()=>{console.debug("[crossx-kit] state",{activeProvider:n,isConnected:x,isConnecting:N,isReconnecting:U,activeConnectorId:B?.id,currentWallet:W,lastIntent:I})},[n,x,N,U,B?.id,W,I]),le(()=>{x&&!ae.current&&E?.closeModal?.({kitConfig:F}),ae.current=x},[x,E,F]),le(()=>{x&&P(null)},[x]);let Je=go(),{switchChainAsync:Ke}=ho(),$e=He(null);le(()=>{if(!F.enforceDefaultNetworkOnConnect)return;let u=F.defaultNetwork?.id;if(!u)return;if(!x||!v||!B){$e.current=null;return}let l=`${B.id}:${v}`;$e.current!==l&&($e.current=l,Je!==u&&Ke({chainId:u}).catch(()=>{}))},[F.enforceDefaultNetworkOnConnect,F.defaultNetwork,x,v,B,Je,Ke]);let ce=Be(u=>V.find(l=>l.id===u),[V]);le(()=>{let u=G.getEntry("cross_embedded");if(!u)return;let l=ce(u.connectorId);if(!l)return;let k=!1;return(async()=>{try{let h=await l.getProvider();if(k)return;h?.sdk?.applyTheme?.(p,b??void 0)}catch(h){console.debug("[crossx-kit] applyTheme skipped:",h)}})(),()=>{k=!0}},[G,ce,p,b]);let Pe=Be(u=>{g(u),sn(u)},[]),q=Be(()=>{g(null),sn(null),P(null)},[]);le(()=>{if(!E?.subscribeModalState)return;let u=!1;return E.subscribeModalState({kitConfig:F},l=>{if(Ze.current=l,l){u=!0;return}u&&(u=!1,setTimeout(()=>{xe.current||(async()=>{try{await M()}catch{}q()})()},250))})},[E,F,M,q]),le(()=>{if(!w||x||typeof window>"u"||w==="cross_embedded")return;let u=typeof document<"u"&&!document.hasFocus(),l=null,k=()=>{u=!0},h=()=>{u&&(l&&clearTimeout(l),l=setTimeout(()=>{xe.current||Ze.current||(async()=>{try{await M()}catch{}q()})()},1e3))};return window.addEventListener("blur",k),window.addEventListener("focus",h),()=>{window.removeEventListener("blur",k),window.removeEventListener("focus",h),l&&clearTimeout(l)}},[w,x,M,q]);let ge=Be(async u=>{console.debug("[crossx-kit] runConnect enter",{walletId:u,activeProvider:n,isConnected:x,activeConnectorId:B?.id});let l=G.getEntry(u);if(!l){if((u==="metamask"||u==="binance")&&!O){console.error(`[crossx-kit] "${u}" requires the Reown adapter, but it is not configured. Pass \`reownProjectId\` (and ensure \`reown\` is not set to \`false\`) when calling createConnectKitConfig() or createCrossxConfig() to enable WalletConnect-based wallets.`);return}console.error(`[crossx-kit] Unknown walletId: "${u}"`);return}if(P(u),l.providerKind!==n){console.debug("[crossx-kit] provider swap needed",{from:n,to:l.providerKind,walletId:u}),Pe(u);try{await M()}catch{}await new Promise(h=>setTimeout(h,0)),i(l.providerKind,u);return}if(Pe(u),E?.beforeConnect)try{let h=await E.beforeConnect({kitConfig:F,themeMode:p},u);if(console.debug("[crossx-kit] beforeConnect result",{walletId:u,result:h}),h==="handled")return}catch(h){console.warn('[crossx-kit] adapter.beforeConnect threw for "%s":',u,h)}let k=ce(l.connectorId);if(console.debug("[crossx-kit] findConnector",{lookupId:l.connectorId,found:k?.id,availableIds:V.map(h=>h.id)}),!k){console.error(`[crossx-kit] Connector "${l.connectorId}" not found on provider "${l.providerKind}". Available: ${V.map(h=>h.id).join(", ")}`),q();return}try{console.debug("[crossx-kit] connectAsync start",{connectorId:k.id});let h=await j({connector:k});console.debug("[crossx-kit] connectAsync resolved",{accountsLen:h.accounts.length,chainId:h.chainId});return}catch(h){if(!Bo(h)){console.error('[crossx-kit] connectAsync error for "%s":',u,h);try{await M()}catch{}}if(!l.fallbackConnectorId){q();return}}if(l.fallbackConnectorId){let h=ce(l.fallbackConnectorId);if(h)try{await j({connector:h})}catch(L){console.error('[crossx-kit] Fallback connect failed for "%s":',u,L);try{await M()}catch{}q()}else q()}},[G,V,ce,j,M,Pe,q,E,n,F,i,p]);le(()=>{if(!o)return;let u=o;c(),ge(u)},[o,n]);let et=Be(async()=>{T(!0)},[]),s=Be(async()=>{try{await M()}catch(u){console.error("[crossx-kit] wagmi disconnect error:",u)}if(E?.teardown)try{await E.teardown({kitConfig:F})}catch(u){console.error("[crossx-kit] adapter teardown error:",u)}on(),q()},[M,E,F,q]),a=Be(async()=>{await rn(M(),3e3);try{let u=G.getEntry("cross_embedded"),l=u&&ce(u.connectorId);if(l?.getProvider){let k=await Promise.race([l.getProvider(),new Promise(L=>setTimeout(L,3e3))]),h=k?.sdk?.signOut;typeof h=="function"&&await rn(h.call(k.sdk),3e3)}}catch{}on()},[G,ce,M]),d=Be(async()=>{let u=G.getEntry("cross_embedded");if(!u)return null;let l=ce(u.connectorId);if(!l)return null;try{let k=await l.getProvider(),h=k?.sdk;if(!h?.selectWallet)return null;let L=await h.selectWallet(h.currentAddress??void 0);return L?.address&&k.notifyAccountsChanged&&k.notifyAccountsChanged([L.address]),L}catch{return null}},[G,ce]),m=Le(()=>{let u=t.oauth;return u?{signIn:async l=>{P("cross_embedded");try{await u.signIn(l)}catch(k){throw P(null),k}}}:null},[t.oauth]),y=He(!1);le(()=>{if(n!=="cross"||x||N||U||w!=null||y.current)return;let u=G.getEntry("cross_embedded");if(!u)return;let l=ce(u.connectorId);if(!l)return;y.current=!0;let k=!1;return(async()=>{try{let h=await l.isAuthorized?.();if(k||!h)return;await j({connector:l})}catch{}})(),()=>{k=!0}},[n,x,N,U,w,G,ce,j]),le(()=>{if(w!=="cross_embedded"||x||typeof window>"u")return;let u=!document.hasFocus(),l=()=>{u=!0};window.addEventListener("blur",l);let k=setTimeout(()=>{xe.current||u||(console.warn("[crossx-kit] embedded sign-in stalled before the OAuth popup opened \u2014 clearing the stale session so a retry starts clean"),q(),a())},Ro);return()=>{window.removeEventListener("blur",l),clearTimeout(k)}},[w,x,q,a]);let A=w!=null&&!x,R=Le(()=>({kitConfig:F,connectorRegistry:G,availableWallets:he,connect:ge,connectWallet:et,disconnect:s,selectWallet:d,currentWallet:W,lastIntent:I,isConnecting:A,connectingWalletId:w,openOtherWallets:()=>T(!0),closeOtherWallets:()=>T(!1),otherWalletsOpen:C,oauth:m,extraWallets:f,walletAllowlist:r,onRampEnabled:ie}),[F,G,he,ge,et,s,d,W,I,A,w,C,m,f,r,ie]),_=an(Et.Provider,{value:R,children:[e,ot(_t,{open:C,onOpenChange:T})]});return fe&&(_=ot(Po,{config:fe,children:_})),we&&(_=ot(vo,{config:we,children:_})),_}var Fo=[/Connection interrupted while trying to subscribe/i,/No matching key\. subscription:/i,/Proposal expired/i];function Wo(e){let t=e?.message;return typeof t!="string"?!1:Fo.some(n=>n.test(t))}var Lo={};function Do(e){return e&&{...e,connections:new Map,current:null}}function Mo({children:e,config:t,initialState:n,extraWallets:i=Lo,walletAllowlist:o}){let[c,p]=Ve(()=>_o(t.activeProviderStorageKey,t.defaultProvider)),[b,f]=Ve(null),r=He(!1),{kitConfig:C}=t,[T,I]=Ve(null),[g,w]=Ve(null),[P,v]=Ve(0),x=Le(()=>xo(C.theme,C.autoDetectTheme),[C.theme,C.autoDetectTheme,P]),N=T??x,U=g??C.themeTokens;le(()=>{if(!C.autoDetectTheme||T||typeof window>"u"||!window.matchMedia)return;let O=window.matchMedia("(prefers-color-scheme: dark)"),E=()=>v(W=>W+1);try{return O.addEventListener("change",E),()=>O.removeEventListener("change",E)}catch{return O.addListener(E),()=>O.removeListener(E)}},[C.autoDetectTheme,T]),le(()=>{if(typeof document>"u")return;let O=document.documentElement,E=O.getAttribute("data-ds-theme"),W=O.getAttribute("data-theme");return O.setAttribute("data-ds-theme",N),W||O.setAttribute("data-theme",N),()=>{E==null?O.removeAttribute("data-ds-theme"):O.setAttribute("data-ds-theme",E),W==null&&O.removeAttribute("data-theme")}},[N]);let B=Le(()=>So(t.designSystem),[t.designSystem]),V=Le(()=>({mode:N,tokens:U,setThemeMode:O=>I(O),setThemeTokens:O=>w(O)}),[N,U]);le(()=>{if(typeof window>"u")return;let O=E=>{Wo(E.reason)&&E.preventDefault()};return window.addEventListener("unhandledrejection",O),()=>window.removeEventListener("unhandledrejection",O)},[]);let j=Be((O,E)=>{r.current||(r.current=!0,f(E),p(O),Oo(t.activeProviderStorageKey,O),queueMicrotask(()=>{r.current=!1}))},[t.activeProviderStorageKey]),M=Be(()=>f(null),[]),F=c==="cross"?t.crossWagmiConfig:t.reownWagmiConfig,G=Do(To(n,c));if(!F){if(!(c==="cross"?t.reownWagmiConfig:t.crossWagmiConfig))throw new Error("[crossx-kit] createCrossxConfig returned no wagmi Config for either side");let E=c==="cross"?"reown":"cross";queueMicrotask(()=>p(E))}let ve=F??(c==="cross"?t.reownWagmiConfig:t.crossWagmiConfig);return an(Ct.Provider,{value:V,children:[ot("style",{"data-crossx-design-system":"",children:B}),ot(po,{config:ve,initialState:G,children:ot(Co,{client:Ao,children:ot(No,{config:t,activeProvider:c,onRequestProviderSwap:j,pendingConnectWalletId:b,clearPending:M,themeMode:N,themeTokens:U,extraWallets:i,walletAllowlist:o??t.kitConfig.wallets??null,children:e})})},c)]})}import{useCallback as ze,useEffect as qr,useMemo as yt}from"react";import{useQueryClient as Hr}from"@tanstack/react-query";import{useAccount as Vr,useChainId as jr,useConfig as Qr,useSendTransaction as zr,useSwitchChain as Xr}from"wagmi";import{getPublicClient as Ut,readContracts as On}from"wagmi/actions";import{WalletInfo as Kt,ConnectorId as Xe,resolveEnvironment as Yr}from"@nexus-cross/dapp-ui";import{useOptionalOnRamp as Zr,useOptionalOnRampEligibility as Jr}from"@nexus-cross/onramp/react";import{APPLE_ICON as Vt,BINANCE_ICON as Wn,CROSSX_ICON as Ht,EXTENSION_ICON as es,GOOGLE_ICON as Ln,METAMASK_ICON as Dn}from"@nexus-cross/connect-kit-wagmi";import{useCallback as te,useMemo as Te,useRef as Go}from"react";import{useQueries as ln,useQuery as je}from"@tanstack/react-query";import{encodeFunctionData as ft,formatUnits as vt,parseSignature as Uo,parseUnits as Ko}from"viem";import{getChainId as Nt,getPublicClient as xn,readContract as Se,signTypedData as $o,switchChain as un,waitForTransactionReceipt as qo,writeContract as mn}from"wagmi/actions";import{useConfig as Ho}from"wagmi";async function kt(e,t,n){if(!(!n||t===void 0))try{if(e.getChainId()===t)return;await e.switchChain(t)}catch{}}var dt=10000n;function cn(e){let t=e==="auto"?1:Number(e||"1");return!Number.isFinite(t)||t<0?100n:BigInt(Math.min(1e4,Math.floor(t*100)))}function Tt(e,t){let n=cn(t);return n>=dt?0n:e*(dt-n)/dt}function dn(e,t){let n=cn(t);return(e*(dt+n)+(dt-1n))/dt}function Vo(e){return e!=="bridge"}var Ge="0x0000000000000000000000000000000000000000",Ie=100,ut=18,jo=180000n,Qo=250000n,Sn=new Set([56,97]),zo=130n,Xo=100n,Yo={dev:"https://stg-contents.crosstoken.io/frontend/game-token/json/hidden-path.json",stage:"https://stg-contents.crosstoken.io/frontend/game-token/json/hidden-path.json",production:"https://contents.crosstoken.io/frontend/game-token/json/hidden-path.json"},Zo={dev:"dev",stage:"stg",production:"prod"};function Jo(e,t){let n=e?.[Zo[t]]?.hiddenPairs;if(!Array.isArray(n))return null;let i=n.filter(o=>!!o&&typeof o=="object"&&typeof o.fromKey=="string"&&typeof o.toKey=="string");return i.length>0?i:null}var er={dev:"https://stg-contents.crosstoken.io/frontend/common/app-launcher/contracts.json",stage:"https://stg-contents.crosstoken.io/frontend/common/app-launcher/contracts.json",production:"https://contents.crosstoken.io/frontend/common/app-launcher/contracts.json"},tr=["BSC_CROSS","W_CROSS","NATIVE_CROSS","USDTX","CROSSD","USDTB","SWAP_BRIDGE_ROUTER"],nr={BSC_CROSS:Ge,W_CROSS:Ge,NATIVE_CROSS:Ge,USDTX:Ge,CROSSD:Ge,USDTB:Ge,SWAP_BRIDGE_ROUTER:Ge},or=/^0x[0-9a-fA-F]{40}$/;function rr(e,t){let n=typeof e=="string"?e:e?.[t];return typeof n=="string"&&or.test(n)?n:null}function sr(e,t){if(!e?.bridge)return null;let n=e.envToNetwork?.[t]??(t==="production"?"mainnet":"testnet"),i={};for(let o of tr){let c=rr(e.bridge[o],n);if(!c)return null;i[o]=c}return i}var ir={dev:{bridgeApi:"https://stg-bridge-api.crosstoken.io/bridge",walletApi:"https://stg-wallet-server.crosstoken.io/api",chainIds:{cross:612044,bsc:97}},stage:{bridgeApi:"https://stg-bridge-api.crosstoken.io/bridge",walletApi:"https://stg-wallet-server.crosstoken.io/api",chainIds:{cross:612044,bsc:97}},production:{bridgeApi:"https://bridge-api.crosstoken.io/bridge",walletApi:"https://wallet-server.crosstoken.io/api",chainIds:{cross:612055,bsc:56}}},rt=[{type:"function",name:"quoter",stateMutability:"view",inputs:[],outputs:[{name:"",type:"address"}]},{type:"function",name:"swapRouter",stateMutability:"view",inputs:[],outputs:[{name:"",type:"address"}]},{type:"function",name:"getAmountSwapBridgeOut",stateMutability:"view",inputs:[{name:"toChainID",type:"uint256"},{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"fee",type:"uint24"},{name:"amountIn",type:"uint256"}],outputs:[{name:"ok",type:"bool"},{name:"swapAmountOut",type:"uint256"},{name:"bridgeValue",type:"uint256"},{name:"networkFee",type:"uint256"},{name:"exFee",type:"uint256"}]},{type:"function",name:"getAmountSwapBridgeIn",stateMutability:"view",inputs:[{name:"toChainID",type:"uint256"},{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"fee",type:"uint24"},{name:"bridgeValue",type:"uint256"}],outputs:[{name:"ok",type:"bool"},{name:"amountIn",type:"uint256"},{name:"swapAmountOut",type:"uint256"},{name:"networkFee",type:"uint256"},{name:"exFee",type:"uint256"}]},{type:"function",name:"swapBridgeExactInputSingle",stateMutability:"nonpayable",inputs:[{name:"params",type:"tuple",components:[{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"fee",type:"uint24"},{name:"amountIn",type:"uint256"},{name:"amountOutMinimum",type:"uint256"},{name:"sqrtPriceLimitX96",type:"uint160"},{name:"bridgeParams",type:"tuple",components:[{name:"toChainID",type:"uint256"},{name:"recipient",type:"address"},{name:"extraData",type:"bytes"}]}]},{name:"deadline",type:"uint256"}],outputs:[{name:"amountOut",type:"uint256"}]},{type:"function",name:"swapBridgeExactOutputSingle",stateMutability:"nonpayable",inputs:[{name:"params",type:"tuple",components:[{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"fee",type:"uint24"},{name:"amountOut",type:"uint256"},{name:"amountInMaximum",type:"uint256"},{name:"sqrtPriceLimitX96",type:"uint160"},{name:"bridgeParams",type:"tuple",components:[{name:"toChainID",type:"uint256"},{name:"recipient",type:"address"},{name:"extraData",type:"bytes"}]}]},{name:"deadline",type:"uint256"}],outputs:[{name:"amountIn",type:"uint256"}]}],Ft=[{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"}],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"allowance",stateMutability:"view",inputs:[{name:"owner",type:"address"},{name:"spender",type:"address"}],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"approve",stateMutability:"nonpayable",inputs:[{name:"spender",type:"address"},{name:"amount",type:"uint256"}],outputs:[{name:"",type:"bool"}]}],pn=[{type:"function",name:"name",stateMutability:"view",inputs:[],outputs:[{name:"",type:"string"}]},{type:"function",name:"nonces",stateMutability:"view",inputs:[{name:"owner",type:"address"}],outputs:[{name:"",type:"uint256"}]}],fn=[{type:"function",name:"quoteExactInputSingle",stateMutability:"nonpayable",inputs:[{name:"params",type:"tuple",components:[{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"amountIn",type:"uint256"},{name:"fee",type:"uint24"},{name:"sqrtPriceLimitX96",type:"uint160"}]}],outputs:[{name:"amountOut",type:"uint256"},{name:"sqrtPriceX96After",type:"uint160"},{name:"initializedTicksCrossed",type:"uint32"},{name:"gasEstimate",type:"uint256"}]},{type:"function",name:"quoteExactOutputSingle",stateMutability:"nonpayable",inputs:[{name:"params",type:"tuple",components:[{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"amount",type:"uint256"},{name:"fee",type:"uint24"},{name:"sqrtPriceLimitX96",type:"uint160"}]}],outputs:[{name:"amountIn",type:"uint256"},{name:"sqrtPriceX96After",type:"uint160"},{name:"initializedTicksCrossed",type:"uint32"},{name:"gasEstimate",type:"uint256"}]}],ar=[{type:"function",name:"slot0",stateMutability:"view",inputs:[],outputs:[{name:"sqrtPriceX96",type:"uint160"},{name:"tick",type:"int24"},{name:"observationIndex",type:"uint16"},{name:"observationCardinality",type:"uint16"},{name:"observationCardinalityNext",type:"uint16"},{name:"feeProtocol",type:"uint8"},{name:"unlocked",type:"bool"}]}],De=[{type:"function",name:"exactInputSingle",stateMutability:"payable",inputs:[{name:"params",type:"tuple",components:[{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"fee",type:"uint24"},{name:"recipient",type:"address"},{name:"deadline",type:"uint256"},{name:"amountIn",type:"uint256"},{name:"amountOutMinimum",type:"uint256"},{name:"sqrtPriceLimitX96",type:"uint160"}]}],outputs:[{name:"amountOut",type:"uint256"}]},{type:"function",name:"multicall",stateMutability:"payable",inputs:[{name:"data",type:"bytes[]"}],outputs:[{name:"results",type:"bytes[]"}]},{type:"function",name:"unwrapWETH9",stateMutability:"payable",inputs:[{name:"amountMinimum",type:"uint256"},{name:"recipient",type:"address"}],outputs:[]},{type:"function",name:"refundETH",stateMutability:"payable",inputs:[],outputs:[]}],cr=[{type:"function",name:"bridgeToken",stateMutability:"payable",inputs:[{name:"toChainID",type:"uint256"},{name:"fromToken",type:"address"},{name:"to",type:"address"},{name:"value",type:"uint256"},{name:"gasFee",type:"uint256"},{name:"exFee",type:"uint256"},{name:"extraData",type:"bytes"}],outputs:[{name:"",type:"bool"}]}];async function vn(e){let t="";try{t=await e.text()}catch{}if(t){try{let n=JSON.parse(t),i=typeof n.data=="string"&&n.data||typeof n.message=="string"&&n.message||"";if(i)return`${i} (status ${e.status})`}catch{}return`${t.slice(0,300)} (status ${e.status})`}return`status ${e.status}`}async function Ee(e,t){let n=await fetch(e,{cache:"no-store",signal:t});if(!n.ok)throw new Error(`CrossD bridge adapter request failed: ${await vn(n)}`);let i=await n.json();if(i&&typeof i=="object"&&"code"in i&&typeof i.code=="number"&&i.code!==200)throw new Error(i.message||`CrossD bridge adapter API error: ${i.code}`);return i&&typeof i=="object"&&"data"in i?i.data:i}async function gn(e,t,n){let i=await fetch(e,{method:"POST",cache:"no-store",signal:n,headers:{"content-type":"application/json"},body:JSON.stringify(t)});if(!i.ok)throw new Error(`CrossD bridge adapter request failed: ${await vn(i)}`);let o=await i.json();if(o&&typeof o=="object"&&"code"in o&&typeof o.code=="number"&&o.code!==200)throw new Error(o.message||`CrossD bridge adapter API error: ${o.code}`);return o&&typeof o=="object"&&"data"in o?o.data:o}function dr(e){return new Promise(t=>setTimeout(t,e))}async function lr(e,t,{attempts:n=60,intervalMs:i=2e3}={}){for(let o=0;o<n;o+=1){try{let c=await Ee(`${e}/permit-hash/${t}`);if(Dt(c))return c}catch{}await dr(i)}return null}function oe(e,t){return`${e}-${t.toLowerCase()}`}function ue(e){return oe(e.chainId,e.address)}function _e(e){return e==="swap"||e==="deposit-swap"||e==="swap-withdraw"}function ur(e){let t=e instanceof Error?e.message:typeof e=="string"?e:"",n=t.toLowerCase();return n.includes("quoteexactinputsingle")||n.includes("quoteexactoutputsingle")||n.includes("getamountswapbridgeout")||n.includes("getamountswapbridgein")||n.includes("execution reverted")?"Amount is too large for this route.":t.split(`
2
2
  `)[0]?.trim()||"Failed to quote bridge."}function bn(e){return e===56||e===97?"BSC":e===612044||e===612055?"CROSS":`Chain ${e}`}function ne(e,t){return t?t.toLowerCase()===e.contracts.NATIVE_CROSS.toLowerCase()?e.contracts.W_CROSS:t:Ge}function st(e){let t=vt(e,ut);return t.includes(".")?t.replace(/\.?0+$/,""):t}function bt(e){return Ko(e||"0",ut)}function pe(e){try{return bt(e||"0")}catch{return 0n}}function Qe(e){if(typeof e=="bigint")return e;if(typeof e=="number")return BigInt(Math.trunc(e));if(!e)return 0n;try{return BigInt(e)}catch{return 0n}}function Wt(e){let t=vt(e,9);return(t.includes(".")?t.replace(/\.?0+$/,""):t)||"0"}function It(e){return e==="bridge"?jo:Qo}function yn(e,t){if(!e||!t)return"0";let n=e*e;if(n===0n)return"0";let i=t*t,o=i>n?i-n:n-i;if(o===0n)return"0";let c=(o*100000000n+n/2n)/n;if(c>=100000000n)return"100";let p=c/1000000n,b=(c%1000000n).toString().padStart(6,"0").replace(/0+$/,"");return b?`${p}.${b}`:`${p}`}function mr(e){if(!e||Number(e)===0)return"0%";let[t,n=""]=e.split("."),i=n.length>4?n.slice(0,4):n;return i?`${t}.${i}%`:`${t}%`}async function hn(e,t,n,i,o,c=!1){let p=xn(e,{chainId:t}),b=n;try{let r=await p?.estimateContractGas?.({account:o.account,address:o.address,abi:o.abi,functionName:o.functionName,args:o.args,value:o.value});typeof r=="bigint"&&r>0n&&(b=i?r*zo/Xo:r)}catch{}let f={gas:b};if(Sn.has(t))try{let r=await p?.getGasPrice?.();typeof r=="bigint"&&r>0n&&(f.gasPrice=r)}catch{}else if(c)try{let r=await p?.estimateFeesPerGas?.();typeof r?.maxFeePerGas=="bigint"&&(f.maxFeePerGas=r.maxFeePerGas),typeof r?.maxPriorityFeePerGas=="bigint"&&(f.maxPriorityFeePerGas=r.maxPriorityFeePerGas)}catch{}return f}function gt(){return BigInt(Math.floor(Date.now()/1e3)+1800)}var pr={100:"0.01%",500:"0.05%",3e3:"0.3%",1e4:"1%"};function fr(e){return pr[e]??`${e/1e4}%`}function gr(e,t){let n=Number(e||"0");return!Number.isFinite(n)||n<=0?"0":(n*t/1e6).toFixed(8).replace(/\.?0+$/,"")}function wn(e){return st(e)}function Cn(e,t){let n=Number(t??"0");return!Number.isFinite(n)||n<=0?0n:e*BigInt(Math.floor(n))/1000n}function xt(e,t){if(!e)return!1;let n=e.toLowerCase();return t.some(i=>i.toLowerCase()===n)}function br(e,t,n){return[{from:[e.contracts.USDTX],to:[e.contracts.CROSSD]},{from:[e.contracts.BSC_CROSS],to:[e.contracts.NATIVE_CROSS,e.contracts.W_CROSS]},{from:[e.contracts.NATIVE_CROSS,e.contracts.W_CROSS],to:[e.contracts.CROSSD]}].some(o=>xt(t,o.from)&&xt(n,o.to)||xt(t,o.to)&&xt(n,o.from))}function yr(e){if(_e(e.type))return null;if(e.type==="swap-bridge"){let t=e.steps.find(n=>n.type==="bridge");return t?{from:t.fromChain,to:t.toChain,token:t.fromToken}:null}if(e.type==="bridge-swap"){let t=e.steps.find(n=>n.type==="bridge");return t?{from:t.fromChain,to:t.toChain,token:t.fromToken}:null}return{from:e.from.chainId,to:e.to.chainId,token:e.from.address}}function hr({input:e,path:t,config:n}){if(!n||_e(t.type))return"";let i=Qe(n.minimumValue),o=Qe(n.gasFee??n.gas_fee),c=t.type==="swap-bridge"?i+o*12n/10n:i;return c<=0n?"":e.fromAmount&&pe(e.fromAmount)<c&&t.type!=="swap"?`Minimum ${wn(c)}`:t.type==="swap-bridge"&&e.toAmount&&pe(e.toAmount)<c?`Available ${wn(c)} or more.`:""}function wr({input:e,path:t,config:n}){if(!n||t.type!=="bridge"&&t.type!=="bridge-swap")return"";let i=Qe(n.gasFee??n.gas_fee);if(i<=0n||!e.fromAmount)return"";let o=pe(e.fromToken.balance||"0"),c=pe(e.fromAmount);return o-i<c?`Insufficient network fee(${e.fromToken.symbol})`:""}function Cr(e,t){let n=new Set;return e?.list?.forEach(i=>{let o=i.localChain??i.local_chain;o&&Object.entries(i.pairs||{}).forEach(([c,p])=>{p.forEach(b=>{b.localToken&&n.add(oe(o,b.localToken)),b.remoteToken&&n.add(oe(Number(c),b.remoteToken))})})}),Object.entries(t?.swapPools||t?.swap_pools||{}).forEach(([i,o])=>{o.forEach(c=>{c.token0&&n.add(oe(Number(i),c.token0)),c.token1&&n.add(oe(Number(i),c.token1))})}),n}function kr(e,t){return!e||!t?null:oe(e,t)}function Tr({envConfig:e,bridgePairList:t,swapPools:n,tokenInfo:i,tokenStats:o}){let c=Cr(t,n),p=new Map;o?.forEach(f=>{let r=kr(Number(f.chainId??f.chain_id),f.address);r&&p.set(r,f)});let b={};return c.forEach(f=>{let[r,C]=f.split("-"),T=Number(r),I=i?.find(w=>Number(w.chainId??w.chain_id)===T&&w.address?.toLowerCase()===C);if(!I?.symbol||!I.name)return;let g=p.get(f);b[f]={key:f,chainId:T,address:C,symbol:I.symbol,name:I.name,decimals:I.decimals||ut,image:I.image||I.icon_url,price:g?.price?Number(g.price):void 0,isNativeToken:C.toLowerCase()===e.contracts.NATIVE_CROSS.toLowerCase()}}),b}function Pn(e,t){return t?.list?.find(n=>(n.localChain??n.local_chain)===e)?.bridge||""}function An(e,t,n){let[i,o]=e.split("-"),[c,p]=t.split("-"),b=Number(i),f=Number(c);for(let r of n?.list||[]){if((r.localChain??r.local_chain)!==b)continue;let C=r.pairs?.[c];if(C){for(let T of C)if(T.localToken?.toLowerCase()===o&&T.remoteToken?.toLowerCase()===p)return{type:"bridge",fromChain:b,fromToken:o,toChain:f,toToken:p,bridgeAddress:Pn(b,n)}}}return null}function Rn(e,t,n,i){let o,c=1/0;for(let p of e||[]){let b=i(p.token0),f=i(p.token1);if(b===t&&f===n||f===t&&b===n){let r=p.fee??Ie;r<c&&(o=p,c=r)}}return o?{fee:c,poolAddress:o.poolAddress||o.pool_address||""}:null}function Bn(e,t,n,i){let[o,c]=e.split("-"),[p,b]=t.split("-");if(o!==p)return null;let f=Number(o),r=(n?.swapPools||n?.swap_pools)?.[o];if(!r)return null;let C=i.contracts.W_CROSS.toLowerCase(),T=i.contracts.NATIVE_CROSS.toLowerCase(),g=Rn(r,c,b,P=>P?.toLowerCase()===C?T:P?.toLowerCase());if(!g)return null;let w="swap";return f===i.chainIds.cross&&(c===T&&(w="deposit-swap"),b===T&&(w="swap-withdraw")),{pathType:w,step:{type:"swap",chain:f,fromToken:c,toToken:b,fee:g.fee,poolAddress:g.poolAddress}}}function Ir(e,t,n,i){let[o,c]=e.split("-"),[p]=t.split("-");if(o===p)return null;let b=(n?.swapPools||n?.swap_pools)?.[o]||[],f=r=>r?.toLowerCase();for(let r of b){let C=f(r.token0),T=f(r.token1),I=C===c?T:T===c?C:null;if(!I)continue;let g=An(oe(Number(o),I),t,i);if(!g)continue;let w=Rn(b,c,I,f);return[{type:"swap",chain:Number(o),fromToken:c,toToken:I,fee:w?.fee??Ie,poolAddress:w?.poolAddress??""},g]}return null}function xr(e,t,n,i,o){let[c,p]=e.split("-"),[b]=t.split("-");if(c===b)return null;for(let f of n?.list||[])if((f.localChain??f.local_chain)===Number(c))for(let r of f.pairs?.[b]||[]){if(r.localToken?.toLowerCase()!==p)continue;let C=r.remoteToken?.toLowerCase();if(!C)continue;let T=Bn(oe(Number(b),C),t,i,o);if(T)return[{type:"bridge",fromChain:Number(c),fromToken:p,toChain:Number(b),toToken:C,bridgeAddress:Pn(Number(c),n)},T.step]}return null}function Sr({envConfig:e,bridgePairList:t,swapPools:n,enrichedTokens:i}){return(o,c)=>{let p=i[o],b=i[c];if(!p||!b||o===c)return null;let f=An(o,c,t);if(f)return{type:"bridge",steps:[f],from:p,to:b};let r=Bn(o,c,n,e);if(r)return{type:r.pathType,steps:[r.step],from:p,to:b};let C=Ir(o,c,n,t);if(C)return{type:"swap-bridge",steps:C,from:p,to:b};let T=xr(o,c,t,n,e);return T?{type:"bridge-swap",steps:T,from:p,to:b}:null}}function kn(e,t){return{name:e.name,symbol:e.symbol,chainId:e.chainId,address:e.address,decimals:e.decimals,balance:t.get(e.key)||"0",iconUrl:e.image,priceUsd:e.price}}function vr(e){return e.length<=10?e:`${e.slice(0,6)}...${e.slice(-4)}`}function Pr(e){return e.includes(".")?e.replace(/\.?0+$/,"")||"0":e}function Ar(e,t){let n=e.startsWith("-"),i=n?e.slice(1):e,[o,c=""]=i.split("."),p=c.slice(0,t).replace(/0+$/,""),b=p?`${o}.${p}`:o;return n?`-${b}`:b}function Rr(e){let t=e.startsWith("-"),n=t?e.slice(1):e,[i,o]=n.split("."),c=i.replace(/\B(?=(\d{3})+(?!\d))/g,","),p=o?`${c}.${o}`:c;return t?`-${p}`:p}function Lt(e){if(e==null||e==="")return"0";let t=String(e),n=Number(t);return!Number.isFinite(n)||n===0?"0":Rr(Ar(t,4))}function Tn(e,t){if(e==null||e==="")return"0";try{return Pr(vt(BigInt(String(e)),t.decimals))}catch{return"0"}}function Dt(e){return!!(e&&/^0x[0-9a-fA-F]+$/.test(e))}function Br(e){return e?new Date(e*1e3).toISOString():new Date().toISOString()}function Er(e,t){return t.toLowerCase()===e.contracts.W_CROSS.toLowerCase()?e.contracts.NATIVE_CROSS:t}function _r(e,t){let n=vr(t);return{name:n,symbol:n,chainId:e,address:t,decimals:ut,balance:"0"}}function In({envConfig:e,tokenByBridgeKey:t,chainId:n,address:i}){if(!i)return null;let o=Er(e,i);return t.get(oe(n,o))||t.get(oe(n,i))||_r(n,o)}function St(e){return e?.toLowerCase()||""}function Or(e){if(e.source==="swap")return"swap";let t=St(e.fromToken??e.from_token),n=St(e.toToken??e.to_token),i=St(e.swapTokenIn??e.swap_token_in),o=St(e.swapTokenOut??e.swap_token_out);return n&&i&&n===i?"bridge-swap":t&&o&&t===o?"swap-bridge":"bridge"}function Nr(e,t){let n=e.status??0,i=e.extracallSuccess??e.extracall_success??!1;return t==="bridge-swap"&&n===1&&!i?"failed":n===1?"success":"pending"}function Fr({envConfig:e,item:t,tokenByBridgeKey:n}){let i=Number(t.fromChainID??t.from_chain_id??0),o=Number(t.toChainID??t.to_chain_id??0);if(!i||!o)return null;let c=Or(t),p=t.swapTokenIn??t.swap_token_in,b=t.swapTokenOut??t.swap_token_out,f=t.swapAmountIn??t.swap_amount_in,r=t.swapAmountOut??t.swap_amount_out,C=t.fromToken??t.from_token,T=t.toToken??t.to_token,I=t.value,g=t.value;c==="swap"?(C=p,T=b,I=f,g=r):c==="swap-bridge"?(C=p,I=f,g=t.value):c==="bridge-swap"&&(T=b,I=f,g=r);let w=In({envConfig:e,tokenByBridgeKey:n,chainId:i,address:C}),P=In({envConfig:e,tokenByBridgeKey:n,chainId:o,address:T}),v=t.initiatedTxHash??t.initiated_tx_hash;return!w||!P||!Dt(v)?null:{id:`${v}-${t.index??""}`,timestamp:Br(t.initiatedTime??t.initiated_time),txHash:v,fromToken:w,toToken:P,fromAmount:Tn(I,w),toAmount:Tn(g,P),summary:{pathType:c},status:Nr(t,c)}}function Wr(e){let t=new Map;return e.flat().forEach(n=>{let i=Number(n.chainId??n.chain_id),o=n.address?.toLowerCase();if(!i||!o)return;let c=n.quantity?.numeric??n.balance??"0",p=n.quantity?.decimals??n.decimals??ut;try{t.set(oe(i,o),vt(BigInt(c||"0"),p))}catch{t.set(oe(i,o),"0")}}),t}function Me(e,t="first"){let n=e.steps.filter(i=>i.type==="swap");return t==="last"?n[n.length-1]:n[0]}function Lr(e,t){let n=(e?.swapPools||e?.swap_pools)?.[String(t.chainIds.cross)];if(!n?.length)return"";let i=t.contracts.CROSSD.toLowerCase(),o=t.contracts.USDTX.toLowerCase(),c=n.find(p=>{let b=p.token0?.toLowerCase(),f=p.token1?.toLowerCase();return b===i&&f===o||b===o&&f===i});return c?.poolAddress||c?.pool_address||""}function Dr(e,t){return e.from.chainId===t.chainIds.cross&&e.from.address.toLowerCase()===t.contracts.CROSSD.toLowerCase()&&e.to.chainId===t.chainIds.bsc&&e.to.address.toLowerCase()===t.contracts.USDTB.toLowerCase()}function Mr(e){if(e===void 0)return;let t=10n**BigInt(ut),n=e>=50000n*t?"normal":e>10000n*t?"low":"rebalancing",i=Number(e>0n?e*100n/(100000n*t):0n);return{label:"Available Liquidity",status:n,percentage:Math.min(i,100)}}function lt(e,t,n,i){let o=[e.from,e.to].find(c=>c.chainId===t&&c.address.toLowerCase()===n.toLowerCase())??i?.[oe(t,n)];return{symbol:o?.symbol||n.slice(0,6),iconUrl:o?.image}}function Gr(e,t){let n=[];for(let o of e.steps)o.type==="swap"?(n.push({chain:o.chain,address:o.fromToken}),n.push({chain:o.chain,address:o.toToken})):(n.push({chain:o.fromChain,address:o.fromToken}),n.push({chain:o.toChain,address:o.toToken}));let i=n.filter((o,c)=>c===0||!(o.chain===n[c-1].chain&&o.address.toLowerCase()===n[c-1].address.toLowerCase()));return i.length===0?[{symbol:e.from.symbol,iconUrl:e.from.image},{symbol:e.to.symbol,iconUrl:e.to.image}]:i.map(o=>lt(e,o.chain,o.address,t))}function Ur({input:e,path:t,amountData:n,gasInfo:i,liquidity:o,enrichedTokens:c,priceImpact:p}){let b=e.fromAmount||"0",f=e.toAmount||"0",r=Me(t),C=t.steps.find(U=>U.type==="bridge"),T=t.type!=="bridge",I=!_e(t.type),g=r?gr(b,r.fee):"0",w=Number(b)>0||Number(f)>0,P=r?lt(t,r.chain,r.fromToken,c):{symbol:e.fromToken.symbol,iconUrl:e.fromToken.iconUrl},v=r?lt(t,r.chain,r.toToken,c):{symbol:e.toToken.symbol,iconUrl:e.toToken.iconUrl},x=C?lt(t,C.fromChain,C.fromToken,c):void 0,N=(U,B,V)=>w?B&&B>0n?{label:U,value:st(B),tone:"default",valueToken:V}:{label:U,value:"Free",tone:"accent"}:{label:U,value:"0"};return{pathType:t.type,priceImpact:p,liquidity:o,bridgeInfo:I&&C?[{label:"Route",value:`${bn(C.fromChain)} \u2192 ${bn(C.toChain)}`},N("Validator Fee",n?.exFee,x),N("Network Fee",n?.networkFee,x)]:void 0,swapInfo:T&&r?[{label:"Route",value:"",routeTokens:[lt(t,r.chain,r.fromToken,c),lt(t,r.chain,r.toToken,c)]},{label:"Price Impact",value:mr(p)},{label:"In Amount",value:Lt(b),valueToken:P},{label:r&&_e(t.type)?`Swap Fee (${fr(r.fee??Ie)})`:"Swap Fee",value:Lt(g),valueToken:P},{label:"Out Amount",value:Lt(f),valueToken:v}]:void 0,txFee:[...i?.gasPrice?[{label:"Gas Price",value:`${i.gasPrice} Gwei`}]:[{label:"Priority Fee Per Gas",value:`${i?.priorityFeePerGas||"0"} Gwei`},{label:"Max Fee Per Gas",value:`${i?.maxFeePerGas||"0"} Gwei`}],{label:"Gas Limit",value:i?.gasLimit||"0"}],txFeeInfo:i?{estTxFee:i.estTxFee,isDelegateFee:i.isDelegateFee,tokenIconUrl:i.gasCurrencyIconUrl,tokenSymbol:i.gasCurrencySymbol}:{estTxFee:"0",isDelegateFee:!1}}}function Mt({env:e,walletAddress:t,enabled:n=!0,restoreChainAfterSwitch:i=!0}){let o=Ho(),c=Go(new Map),b=je({queryKey:["crossd-bridge-adapter",e,"remote-contracts"],queryFn:async({signal:s})=>{let a=sr(await Ee(er[e],s),e);if(!a)throw new Error("CrossD bridge adapter: invalid contracts.json");return a},enabled:n,staleTime:5*6e4}).data??null,f=n&&!!b,r=Te(()=>({...ir[e],contracts:b??nr}),[e,b]),C=je({queryKey:["crossd-bridge-adapter",e,"pairs"],queryFn:({signal:s})=>Ee(`${r.bridgeApi}/pairs`,s),enabled:f,staleTime:3e4}),T=je({queryKey:["crossd-bridge-adapter",e,"swap-pools"],queryFn:({signal:s})=>Ee(`${r.bridgeApi}/swap-pools`,s),enabled:f,staleTime:3e4}),I=Te(()=>Lr(T.data,r),[r,T.data]),g=je({queryKey:["crossd-bridge-adapter",e,"available-liquidity",I],queryFn:async()=>await Se(o,{address:r.contracts.USDTX,abi:Ft,functionName:"balanceOf",args:[I],chainId:r.chainIds.cross}),enabled:f&&!!I,staleTime:3e4}),w=je({queryKey:["crossd-bridge-adapter",e,"token-info"],queryFn:({signal:s})=>Ee(`${r.walletApi}/v1/public/token/info`,s),enabled:f,staleTime:3e4}),P=je({queryKey:["crossd-bridge-adapter",e,"token-stats"],queryFn:({signal:s})=>Ee(`${r.walletApi}/v1/public/token/stats`,s),enabled:f,staleTime:3e4}),v=ln({queries:[r.chainIds.cross,r.chainIds.bsc].map(s=>({queryKey:["crossd-bridge-adapter",e,"balance",t,s],queryFn:({signal:a})=>{let d=new URLSearchParams({networkId:`eip155:${s}`,account:t||""});return Ee(`${r.walletApi}/v1/public/token/balance?${d}`,a)},enabled:f&&!!t,staleTime:0,refetchInterval:f&&t?5e3:!1}))}),x=ln({queries:[r.chainIds.cross,r.chainIds.bsc].map(s=>({queryKey:["crossd-bridge-adapter",e,"gas-suggestion",s],queryFn:async({signal:a})=>{try{let y=await xn(o,{chainId:s})?.estimateFeesPerGas?.();if(y?.maxFeePerGas||y?.gasPrice)return{fast:{maxFee:y.maxFeePerGas?.toString()||y.gasPrice?.toString(),maxPriorityFee:y.maxPriorityFeePerGas?.toString()||"0"}}}catch{}let d=new URLSearchParams({chain_id:String(s),without_gas_limit:"false"});return Ee(`${r.walletApi}/v1/public/transaction/gas-suggestion/dynamic?${d}`,a)},enabled:f,staleTime:1e4,retry:1}))}),N=je({queryKey:["crossd-bridge-adapter",e,"hidden-pairs"],queryFn:async({signal:s})=>Jo(await Ee(Yo[e],s),e),enabled:f,staleTime:5*6e4,retry:1}),U=Te(()=>N.data??[],[N.data]),B=Te(()=>Tr({envConfig:r,bridgePairList:C.data,swapPools:T.data,tokenInfo:w.data,tokenStats:P.data}),[C.data,r,T.data,w.data,P.data]),V=Te(()=>Sr({envConfig:r,bridgePairList:C.data,swapPools:T.data,enrichedTokens:B}),[C.data,B,r,T.data]),j=Te(()=>Wr(v.map(s=>s.data).filter(s=>Array.isArray(s))),[v]),M=Te(()=>{let s=new Map;return Object.values(B).forEach(a=>{let d=kn(a,j);s.set(a.key,d)}),s},[j,B]),F=Te(()=>{let s=new Map,a=M.get(oe(r.chainIds.cross,r.contracts.NATIVE_CROSS));a&&s.set(r.chainIds.cross,{symbol:a.symbol,iconUrl:a.iconUrl});let d=w.data?.find(m=>Number(m.chainId??m.chain_id)===r.chainIds.bsc&&(m.symbol??"").toUpperCase()==="BNB");return d&&s.set(r.chainIds.bsc,{symbol:d.symbol??"BNB",iconUrl:d.image??d.icon_url}),s},[r,M,w.data]),G=je({queryKey:["crossd-bridge-adapter",e,"history",t],queryFn:({signal:s})=>gn(`${r.bridgeApi}/history`,{owner:t,page:1,size:20,sort:"desc",status:"all"},s),enabled:f&&!!t,staleTime:0,refetchInterval:f&&t?5e3:!1}),ve=Te(()=>(G.data?.histories||[]).map(s=>Fr({envConfig:r,item:s,tokenByBridgeKey:M})).filter(s=>!!s),[G.data?.histories,r,M]),O=Te(()=>Mr(g.data),[g.data]),E=x[0]?.data,W=x[1]?.data,he=Te(()=>{let s=new Map;return E&&s.set(r.chainIds.cross,E),W&&s.set(r.chainIds.bsc,W),s},[W,E,r.chainIds.bsc,r.chainIds.cross]),Ye=te((s,a,d)=>{let m=he.get(s.from.chainId)?.fast,y=a?d?.gasLimit??It(s.type):0n,A=d?.gasPrice&&d.gasPrice>0n?d.gasPrice:0n,R=d?.maxFeePerGas&&d.maxFeePerGas>0n?d.maxFeePerGas:0n,S=d?.maxPriorityFeePerGas&&d.maxPriorityFeePerGas>0n?d.maxPriorityFeePerGas:0n,_=Qe(m?.maxFee??m?.max_fee),u=Qe(m?.maxPriorityFee??m?.max_priority_fee),l=R>0n?R:_>0n?_:A,k=S>0n?S:u>0n?u:l,h=A>0n?A:l,L=Sn.has(s.from.chainId)&&h>0n,J=y*(L?h:l),re=M.get(oe(s.from.chainId,r.contracts.NATIVE_CROSS)),H=s.type!=="swap-bridge",K=F.get(s.from.chainId);return{estTxFee:a?st(J):"0",priorityFeePerGas:a&&!L?Wt(k):"0",maxFeePerGas:a&&!L?Wt(l):"0",gasLimit:a?y.toString():"0",gasPrice:a&&L?Wt(h):void 0,isDelegateFee:s.type==="swap-bridge"?!1:br(r,s.from.address,s.to.address),tokenIconUrl:H?re?.iconUrl:void 0,tokenSymbol:H?re?.symbol:void 0,gasCurrencyIconUrl:K?.iconUrl,gasCurrencySymbol:K?.symbol}},[r,he,F,M]),X=te(async s=>{let a=yr(s);if(!a)return null;let d=`${e}:${a.from}:${a.to}:${a.token.toLowerCase()}`,m=c.current.get(d);if(m)return m;let y=(async()=>{let A=new URLSearchParams({from:String(a.from),to:String(a.to),token:a.token});try{return(await Ee(`${r.bridgeApi}/token-config?${A}`)).config??null}catch{return null}})();return c.current.set(d,y),y},[e,r.bridgeApi]),ie=Te(()=>{let s=Object.values(B).map(d=>kn(d,j)),a=oe(r.chainIds.cross,r.contracts.CROSSD);return s.sort((d,m)=>{let y=ue(d).toLowerCase()===a.toLowerCase(),A=ue(m).toLowerCase()===a.toLowerCase();return y!==A?y?-1:1:ue(d).localeCompare(ue(m))})},[j,B,r]),we=te(s=>{let a=ue(s),d=a.toLowerCase(),m=[];Object.keys(B).forEach(R=>{let S=R.toLowerCase();if(d===S||U.some(l=>l.fromKey===d&&l.toKey===S))return;let _=V(a,R);if(!_)return;let u=M.get(R);u&&m.push({token:u,path:_})});let y=oe(r.chainIds.cross,r.contracts.CROSSD),A=oe(r.chainIds.cross,r.contracts.NATIVE_CROSS);return m.sort((R,S)=>{if(d===y.toLowerCase()){let h=ue(R.token).toLowerCase()===A.toLowerCase(),L=ue(S.token).toLowerCase()===A.toLowerCase();if(h!==L)return h?-1:1}let _=_e(R.path.type),u=_e(S.path.type);if(_!==u)return _?-1:1;let l=R.token.chainId===s.chainId,k=S.token.chainId===s.chainId;return l!==k?l?-1:1:ue(R.token).localeCompare(ue(S.token))}),m.map(R=>R.token)},[B,r,V,U,M]),Ne=te(async s=>await Se(o,{address:r.contracts.SWAP_BRIDGE_ROUTER,abi:rt,functionName:"quoter",chainId:s}),[r.contracts.SWAP_BRIDGE_ROUTER,o]),Ce=te(async s=>{Nt(o)!==s&&await un(o,{chainId:s})},[o]),Ue=te(s=>kt({getChainId:()=>Nt(o),switchChain:a=>un(o,{chainId:a})},s,i),[i,o]),fe=te(async s=>await Se(o,{address:r.contracts.SWAP_BRIDGE_ROUTER,abi:rt,functionName:"swapRouter",chainId:s}),[r.contracts.SWAP_BRIDGE_ROUTER,o]),xe=te(async({path:s,step:a,amount:d,source:m})=>{let y=await Ne(a.chain),A=a.poolAddress?Se(o,{address:a.poolAddress,abi:ar,functionName:"slot0",chainId:a.chain}).then(_=>_?.[0]).catch(()=>{}):Promise.resolve(void 0);if(m==="from"){let _=await Se(o,{address:y,abi:fn,functionName:"quoteExactInputSingle",args:[{tokenIn:ne(r,a.fromToken),tokenOut:ne(r,a.toToken),amountIn:bt(d),fee:a.fee??Ie,sqrtPriceLimitX96:0n}],chainId:a.chain}),u=yn(await A,_[1]);return{amount:st(_[0]),path:s,priceImpact:u}}let R=await Se(o,{address:y,abi:fn,functionName:"quoteExactOutputSingle",args:[{tokenIn:ne(r,a.fromToken),tokenOut:ne(r,a.toToken),amount:bt(d),fee:a.fee??Ie,sqrtPriceLimitX96:0n}],chainId:a.chain}),S=yn(await A,R[1]);return{amount:st(R[0]),path:s,priceImpact:S}},[r,Ne,o]),ae=te(async(s,a)=>{if(!t)throw new Error("Wallet is not connected.");let d=It(a.type);if(_e(a.type)){let l=Me(a,"first");if(!l)throw new Error("Swap route is not available.");let k=pe(s.fromAmount),h=pe(s.toAmount);if(k<=0n)throw new Error("Bridge amount is empty.");if(h<=0n)throw new Error("Bridge quote is not ready.");let L=await fe(l.chain),Y=Tt(h,s.slippage),J=a.type==="swap-withdraw"?Ge:t,re={tokenIn:ne(r,l.fromToken),tokenOut:ne(r,l.toToken),fee:l.fee??Ie,recipient:J,deadline:gt(),amountIn:k,amountOutMinimum:Y,sqrtPriceLimitX96:0n};if(a.type==="swap-withdraw"){let H=ft({abi:De,functionName:"exactInputSingle",args:[re]}),K=ft({abi:De,functionName:"unwrapWETH9",args:[Y,t]});return{address:L,abi:De,functionName:"multicall",args:[[H,K]],chainId:l.chain,fallbackGasLimit:d}}if(a.type==="deposit-swap"){let H=ft({abi:De,functionName:"exactInputSingle",args:[re]}),K=ft({abi:De,functionName:"refundETH",args:[]});return{address:L,abi:De,functionName:"multicall",args:[[H,K]],value:k,chainId:l.chain,fallbackGasLimit:d}}return{address:L,abi:De,functionName:"exactInputSingle",args:[re],chainId:l.chain,fallbackGasLimit:d}}if(a.type==="swap-bridge"){let l=Me(a,"first");if(!l)throw new Error("Swap bridge route is not available.");let k=pe(s.fromAmount),h=pe(s.toAmount);if(k<=0n)throw new Error("Bridge amount is empty.");if(h<=0n)throw new Error("Bridge quote is not ready.");let L=r.contracts.SWAP_BRIDGE_ROUTER,Y=gt(),J={toChainID:BigInt(a.to.chainId),recipient:t,extraData:"0x"},re={tokenIn:ne(r,a.from.address),tokenOut:ne(r,l.toToken),fee:l.fee??Ie,sqrtPriceLimitX96:0n,bridgeParams:J};if(s.lastChangedBy==="to"){let K={...re,amountOut:h,amountInMaximum:dn(k,s.slippage)};return{address:L,abi:rt,functionName:"swapBridgeExactOutputSingle",args:[K,Y],value:a.from.isNativeToken?K.amountInMaximum:void 0,chainId:a.from.chainId,fallbackGasLimit:d}}let H={...re,amountIn:k,amountOutMinimum:Tt(h,s.slippage)};return{address:L,abi:rt,functionName:"swapBridgeExactInputSingle",args:[H,Y],value:a.from.isNativeToken?k:void 0,chainId:a.from.chainId,fallbackGasLimit:d}}let m=a.steps.find(l=>l.type==="bridge");if(!m?.bridgeAddress)throw new Error("Bridge route is not available.");let y=pe(s.fromAmount);if(y<=0n)throw new Error("Bridge amount is empty.");let A=await X(a),R=Qe(A?.gasFee??A?.gas_fee),S=Cn(y,A?.exFeeRate??A?.ex_fee_rate),_="0x";if(a.type==="bridge-swap"){let l=Me(a,"last");if(!l)throw new Error("Bridge swap route is not available.");let k=pe(s.toAmount);if(k<=0n)throw new Error("Bridge quote is not ready.");let h=await fe(a.to.chainId),L=Tt(k,s.slippage),Y=ft({abi:De,functionName:"exactInputSingle",args:[{tokenIn:ne(r,l.fromToken),tokenOut:ne(r,l.toToken),fee:l.fee??Ie,recipient:t,deadline:gt(),amountIn:y,amountOutMinimum:L,sqrtPriceLimitX96:0n}]});_=`${h}${Y.slice(2)}`}let u=[BigInt(a.to.chainId),a.from.address,t,y,R,S,_];return{address:m.bridgeAddress,abi:cr,functionName:"bridgeToken",args:u,value:a.from.isNativeToken?y+S+R:void 0,chainId:a.from.chainId,fallbackGasLimit:d}},[r,X,fe,t]),Ze=te(async(s,a)=>{if(a.type==="bridge"||a.type==="bridge-swap")return ae(s,a);if(!t)throw new Error("Wallet is not connected.");let d=pe(s.fromAmount);if(d<=0n)throw new Error("Bridge amount is empty.");if(a.type==="swap-bridge"){let R=Me(a,"first");if(!R)throw new Error("Swap bridge route is not available.");let S=r.contracts.SWAP_BRIDGE_ROUTER,_={tokenIn:ne(r,a.from.address),tokenOut:ne(r,R.toToken),fee:R.fee??Ie,sqrtPriceLimitX96:0n,bridgeParams:{toChainID:BigInt(a.to.chainId),recipient:t,extraData:"0x"},amountIn:d,amountOutMinimum:0n};return{address:S,abi:rt,functionName:"swapBridgeExactInputSingle",args:[_,gt()],value:a.from.isNativeToken?d:void 0,chainId:a.from.chainId,fallbackGasLimit:It(a.type)}}let m=Me(a,"first");if(!m)throw new Error("Swap route is not available.");let y=await fe(m.chain),A={tokenIn:ne(r,m.fromToken),tokenOut:ne(r,m.toToken),fee:m.fee??Ie,recipient:t,deadline:gt(),amountIn:d,amountOutMinimum:0n,sqrtPriceLimitX96:0n};return{address:y,abi:De,functionName:"exactInputSingle",args:[A],value:a.from.isNativeToken?d:void 0,chainId:m.chain,fallbackGasLimit:It(a.type)}},[ae,r,fe,t]),Je=te(async(s,a)=>{if(!t)return null;try{let d=await Ze(s,a),m=_e(a.type)||a.type==="swap-bridge",y=await hn(o,d.chainId,d.fallbackGasLimit,m,{account:t,address:d.address,abi:d.abi,functionName:d.functionName,args:d.args,value:d.value},!0);return{gasLimit:y.gas,gasPrice:y.gasPrice,maxFeePerGas:y.maxFeePerGas,maxPriorityFeePerGas:y.maxPriorityFeePerGas}}catch{return null}},[Ze,o,t]),Ke=te(async s=>{let a=ue(s.fromToken),d=ue(s.toToken),m=V(a,d);if(!m)return{error:"Route is not available."};let y=s.lastChangedBy==="to"?s.toAmount:s.fromAmount,A=!!y&&Number(y)>0,R=Dr(m,r)?O:void 0,S=async(Y,J,re)=>{let H=A?await Je(Y,m):null,K=Ye(m,A,H);return Ur({input:Y,path:m,gasInfo:K,amountData:J,liquidity:R,enrichedTokens:B,priceImpact:re})};if(!y||Number(y)<=0)return{fromAmount:s.fromAmount,toAmount:s.toAmount,summary:await S(s)};let _=await X(m),u=Qe(_?.gasFee??_?.gas_fee),l=m.type==="bridge"||m.type==="bridge-swap"?{networkFee:u}:void 0,k=m.type==="bridge"?s.lastChangedBy==="to"?{...s,fromAmount:s.toAmount}:{...s,toAmount:s.fromAmount}:s,h=hr({input:k,path:m,config:_});if(h)return{fromAmount:k.fromAmount,toAmount:k.toAmount,summary:await S(k,l),error:h};let L=wr({input:k,path:m,config:_});if(L)return{fromAmount:k.fromAmount,toAmount:k.toAmount,summary:await S(k,l),error:L};if(m.type==="bridge")return{fromAmount:k.fromAmount,toAmount:k.toAmount,summary:await S(k,l)};try{if(m.type==="swap-bridge"){let H=Me(m,"first"),K=r.contracts.SWAP_BRIDGE_ROUTER;if(!H)return{error:"Swap bridge route is not ready."};let at=Re=>xe({path:m,step:H,amount:Re,source:"from"}).then(Fe=>Fe.priceImpact).catch(()=>{});if(s.lastChangedBy==="from"){let Re=await Se(o,{address:K,abi:rt,functionName:"getAmountSwapBridgeOut",args:[BigInt(m.to.chainId),ne(r,m.from.address),ne(r,H.toToken),H.fee??Ie,bt(s.fromAmount)],chainId:m.from.chainId}),Fe=st(Re[1]),Pt={...s,toAmount:Fe};return{toAmount:Fe,summary:await S(Pt,{networkFee:Re[3],exFee:Re[4]},await at(s.fromAmount))}}let Ae=await Se(o,{address:K,abi:rt,functionName:"getAmountSwapBridgeIn",args:[BigInt(m.to.chainId),ne(r,m.from.address),ne(r,H.toToken),H.fee??Ie,bt(s.toAmount)],chainId:m.from.chainId}),qe=st(Ae[1]),tt={...s,fromAmount:qe};return{fromAmount:qe,summary:await S(tt,{networkFee:Ae[3],exFee:Ae[4]},await at(qe))}}let Y=m.type==="bridge-swap"?Me(m,"last"):Me(m,"first");if(!Y)return{error:"Swap route is not available."};let J=await xe({path:m,step:Y,amount:y,source:s.lastChangedBy});if(s.lastChangedBy==="from"){let H={...s,toAmount:J.amount};return{toAmount:J.amount,summary:await S(H,l,J.priceImpact)}}let re={...s,fromAmount:J.amount};return{fromAmount:J.amount,summary:await S(re,l,J.priceImpact)}}catch(Y){return{fromAmount:s.fromAmount,toAmount:s.toAmount,summary:await S(s,l),error:ur(Y)}}},[O,Ye,B,r,Je,V,X,xe,o]),$e=te(async s=>{if(s.from.isNativeToken)return null;if(s.type==="swap"||s.type==="deposit-swap"||s.type==="swap-withdraw")return fe(s.from.chainId);if(s.type==="swap-bridge")return r.contracts.SWAP_BRIDGE_ROUTER;let a=s.steps.find(d=>d.type==="bridge");return a?.bridgeAddress?a.bridgeAddress:null},[r.contracts.SWAP_BRIDGE_ROUTER,fe]),ce=te(async s=>{if(!t)throw new Error("Wallet is not connected.");let a=ue(s.fromToken),d=ue(s.toToken),m=V(a,d);if(!m)throw new Error("Route is not available.");if(!_e(m.type)&&m.type!=="swap-bridge"||m.from.isNativeToken)return null;let y=pe(s.fromAmount);if(y<=0n)return null;let A=await $e(m);return!A||await Se(o,{address:m.from.address,abi:Ft,functionName:"allowance",args:[t,A],chainId:m.from.chainId})>=y?null:{token:s.fromToken,tokenAddress:m.from.address,spenderAddress:A,amount:s.fromAmount}},[V,$e,o,t]),Pe=te(async(s,a)=>{let d=pe(a.amount||s.fromAmount);if(d<=0n)throw new Error("Approval amount is empty.");await Ce(a.token.chainId);let m=await mn(o,{address:a.tokenAddress,abi:Ft,functionName:"approve",args:[a.spenderAddress,d],chainId:a.token.chainId});await qo(o,{hash:m,chainId:a.token.chainId})},[Ce,o]),q=te(async(s,a)=>{let d=await ae(s,a);await Ce(d.chainId);let m=await hn(o,d.chainId,d.fallbackGasLimit,Vo(a.type),{account:t,address:d.address,abi:d.abi,functionName:d.functionName,args:d.args,value:d.value});return{txHash:await mn(o,{address:d.address,abi:d.abi,functionName:d.functionName,args:d.args,value:d.value,chainId:d.chainId,...m}),fromToken:s.fromToken,toToken:s.toToken,fromAmount:s.fromAmount,toAmount:s.toAmount}},[ae,Ce,o,t]),ge=te(async(s,a)=>{let d=t;if(!d)throw new Error("Wallet is not connected.");let m=a.steps.find(Fe=>Fe.type==="bridge");if(!m?.bridgeAddress)throw new Error("Bridge route is not available.");let y=a.from.address,A=a.from.chainId,R=pe(s.fromAmount);if(R<=0n)throw new Error("Bridge amount is empty.");let S=await X(a),_=Qe(S?.gasFee??S?.gas_fee),u=Cn(R,S?.exFeeRate??S?.ex_fee_rate),l=R+u+_,[k,h]=await Promise.all([Se(o,{address:y,abi:pn,functionName:"name",chainId:A}),Se(o,{address:y,abi:pn,functionName:"nonces",args:[d],chainId:A})]),L=BigInt(Math.floor(Date.now()/1e3)+300),Y=await $o(o,{domain:{name:k,version:"1",chainId:A,verifyingContract:y},types:{Permit:[{name:"owner",type:"address"},{name:"spender",type:"address"},{name:"value",type:"uint256"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]},primaryType:"Permit",message:{owner:d,spender:m.bridgeAddress,value:l,nonce:h,deadline:L}}),{r:J,s:re,v:H,yParity:K}=Uo(Y),at=H!==void 0?Number(H):K+27,Ae={exFee:u.toString(),from:A,fromToken:y,nonce:Number(h),gasFee:_.toString(),permitArgs:{account:d,deadline:L.toString(),r:J,s:re,token:y,v:at,value:l.toString()},to:d,toChainID:String(a.to.chainId),value:l.toString()},qe=await gn(`${r.bridgeApi}/permit`,Ae),tt=qe?.requestId??qe?.request_id;if(!tt)throw new Error("Bridge permit request failed.");let Re=await lr(r.bridgeApi,tt);if(!Dt(Re))throw new Error("Bridge submitted, but confirmation timed out. Check History shortly.");return{txHash:Re,fromToken:s.fromToken,toToken:s.toToken,fromAmount:s.fromAmount,toAmount:s.toAmount}},[r,X,o,t]),et=te(async s=>{let a=Nt(o),d=ue(s.fromToken),m=ue(s.toToken),y=V(d,m);if(!y)throw new Error("Route is not available.");if(!(_e(y.type)||y.type==="swap-bridge"||y.type==="bridge-swap"||y.type==="bridge"))throw new Error("This bridge route is not supported yet.");let S=y.type==="bridge"&&y.from.chainId===r.chainIds.bsc&&y.from.address.toLowerCase()===r.contracts.BSC_CROSS.toLowerCase()?await ge(s,y):await q(s,y);return await Ue(a),{...S,pathType:y.type,routeTokens:Gr(y,B)}},[B,r,V,Ue,ge,q,o]);return{bridgeTokens:ie,bridgeHistory:ve,getBridgeApproval:ce,approveBridge:Pe,getBridgeQuote:Ke,getBridgeToTokens:we,submitBridge:et,isLoading:C.isLoading||T.isLoading||w.isLoading||P.isLoading||v.some(s=>s.isLoading)}}import{useEffect as En,useRef as Kr,useState as _n}from"react";import{useAccount as $r}from"wagmi";function Gt(e){let{address:t,connector:n}=$r(),{currentWallet:i}=We(),o=e?.walletId!==void 0?e.walletId:i,c=e?.connector!==void 0?e.connector:n,p=e?.address!==void 0?e.address:t,[b,f]=_n({loginType:null,accountName:null,accounts:[],isResolved:!1}),r=Kr(new Map),[C,T]=_n(0);return En(()=>{let I=!1;if(o!=="cross_embedded")return f({loginType:null,accountName:null,accounts:[],isResolved:!0}),()=>{I=!0};if(!c)return f({loginType:null,accountName:null,accounts:[],isResolved:!1}),()=>{I=!0};f(v=>({...v,isResolved:!1}));let g=20,w=300,P=async()=>{if(typeof c.getProvider!="function")return"retry";let v;try{v=await c.getProvider()}catch{return"retry"}let x=v?.sdk;if(!x)return"giveup";try{let W=x.getRNBridgeActiveWallet?.(),he=W?.walletName?.trim();W&&he&&r.current.set(W.address.toLowerCase(),he)}catch{}let[N,U]=await Promise.all([x.getUserInfo?.().catch(()=>null)??null,x.getAddresses?.().catch(()=>null)??null]);if(I)return"done";let B=N?.loginType,V=B==="google"||B==="apple"?B:null;if(!V)return"retry";let j=p?.toLowerCase(),M=j&&Array.isArray(U)?U.find(W=>W.address.toLowerCase()===j):null,F=Array.isArray(U)?U.filter(W=>/^0x[a-fA-F0-9]{40}$/.test(W.address)).map(W=>({address:W.address.toLowerCase(),...Number.isFinite(W.index)?{index:W.index}:{},...W.name?.trim()?{name:W.name.trim()}:{}})):[],G=j?r.current.get(j)?.trim():void 0,ve=!M&&j&&/^0x[a-fA-F0-9]{40}$/.test(j)?[...F,{address:j,index:F.length,...G?{name:G}:{}}]:F,E=G||M?.name?.trim()||(typeof M?.index=="number"?`Account ${M.index+1}`:p?`${p.slice(0,6)}\u2026${p.slice(-4)}`:null);return f({loginType:V,accountName:E,accounts:ve,isResolved:!0}),"done"};return(async()=>{for(let v=0;v<g;v++){if(I)return;let x=await P();if(x==="done")return;if(x==="giveup"){I||f({loginType:null,accountName:null,accounts:[],isResolved:!0});return}await new Promise(N=>setTimeout(N,w))}I||f({loginType:null,accountName:null,accounts:[],isResolved:!0})})(),()=>{I=!0}},[o,c,p,C]),En(()=>{if(o!=="cross_embedded"||!c||typeof c.getProvider!="function")return;let I=!1,g;return(async()=>{let w;try{w=await c.getProvider()}catch{return}if(I)return;let P=w?.sdk;P?.on&&(g=P.on("addressChanged",({address:v,walletName:x})=>{let N=x?.trim();N&&(r.current.set(v.toLowerCase(),N),T(U=>U+1))}))})(),()=>{I=!0,g?.()}},[o,c]),b}import{Fragment as Fn,jsx as me,jsxs as it}from"react/jsx-runtime";var ts=[{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"}],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"totalSupply",stateMutability:"view",inputs:[],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"decimals",stateMutability:"view",inputs:[],outputs:[{name:"",type:"uint8"}]}],ns=[{type:"function",name:"earned",stateMutability:"view",inputs:[{name:"account",type:"address"}],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"}],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"posaActive",stateMutability:"view",inputs:[],outputs:[{name:"",type:"bool"}]},{type:"function",name:"lastRewardBlock",stateMutability:"view",inputs:[],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"totalStaked",stateMutability:"view",inputs:[],outputs:[{name:"",type:"uint256"}]}],os={dev:{poolAddress:"0x0000000c5BB5C7B081237B5efaFC753D61201b94",crossChainId:612044,networkStatsUrl:"https://stg-posa-api.crosstoken.io/api/v1/network/stats"},stage:{poolAddress:"0x0000000c5BB5C7B081237B5efaFC753D61201b94",crossChainId:612044,networkStatsUrl:"https://stg-posa-api.crosstoken.io/api/v1/network/stats"},production:{poolAddress:"0x000000068122d9bB43B4BCF5497A10EdfA9F5E93",crossChainId:612055,networkStatsUrl:"https://posa-api.crosstoken.io/api/v1/network/stats"}},$t=10n**18n,rs={google:{name:"Google",iconUrl:Ln,connectorId:Xe.CROSSx},apple:{name:"Apple",iconUrl:Vt,connectorId:Xe.CROSSx},cross:{name:"CROSSx",iconUrl:Ht,connectorId:Xe.CROSSx},metamask:{name:"MetaMask",iconUrl:Dn,connectorId:Xe.MetaMask},binance:{name:"Binance Wallet",iconUrl:Wn,connectorId:Xe.Binance}};function ss(e){switch(e){case"cross_embedded":return Xe.CROSSx;case"metamask":return Xe.MetaMask;case"binance":return Xe.Binance;default:return}}function is(e,t){switch(e){case"cross_embedded":return t==="google"?{name:"Google",iconUrl:Ln}:t==="apple"?{name:"Apple",iconUrl:Vt}:{name:"CROSSx",iconUrl:Ht};case"cross_wallet":return{name:"CROSSx Wallet",iconUrl:Ht};case"cross_extension":return{name:"CROSSx Extension",iconUrl:es};case"metamask":return{name:"MetaMask",iconUrl:Dn};case"binance":return{name:"Binance Wallet",iconUrl:Wn};default:return null}}var as="Bridge is available only with the CROSSx 2.0 wallet.",cs="Send is available only with the CROSSx 2.0 wallet.";function ds({label:e="Connect Wallet",className:t,style:n,walletInfoStyle:i,user:o,enablePortfolio:c,portfolio:p,theme:b,accountName:f,connectorId:r,showPortfolio:C,sendAccounts:T,getTransactionReceipt:I,sendTransaction:g,estimateGas:w,onDisconnect:P,onSelectWallet:v,onBuy:x,onRampRedirectUrl:N,bridgeTokens:U,bridgeHistory:B,getBridgeQuote:V,getBridgeToTokens:j,getBridgeApproval:M,approveBridge:F,submitBridge:G,showBalance:ve=!0,env:O,...E}){let{address:W,isConnected:he,connector:Ye,chain:X}=Vr(),ie=Qr(),we=jr(),{switchChainAsync:Ne}=Xr(),{sendTransactionAsync:Ce}=zr(),{connectWallet:Ue,disconnect:fe,selectWallet:xe,currentWallet:ae,isConnecting:Ze,kitConfig:Je}=We(),Ke=Je?.restoreChainAfterSwitch!==!1,$e=pt(),ce=b??$e?.mode??"dark",Pe=yt(()=>Yr(O),[O]),q=o?.address??W,ge=o?rs[o.provider]:null,{loginType:et,accountName:s,accounts:a}=Gt({walletId:ae,connector:Ye,address:q}),d=yt(()=>ge?{name:ge.name,iconUrl:ge.iconUrl}:is(ae,et),[ge,ae,et]),m=f??o?.name??s??void 0,y=ge?ge.connectorId:ss(ae),A=r??y,R=p??C??!!c,S=Mt({env:Pe,walletAddress:q,enabled:he&&!!q&&ve,restoreChainAfterSwitch:Ke}),_=U??S.bridgeTokens,u=B??S.bridgeHistory,l=V??S.getBridgeQuote,k=j??S.getBridgeToTokens,h=M??S.getBridgeApproval,L=F??S.approveBridge,Y=G??S.submitBridge,J=ze(()=>{Ue().catch(D=>{console.error("[crossx-kit] connectWallet error:",D)})},[Ue]),re=ze(()=>{fe()},[fe]),H=P??re,K=Zr(),{eligibility:at}=Jr({network:X?String(X.id):void 0}),Ae=at?.allowed===!0,qe=yt(()=>{if(x)return x;if(!(!K||!X||!Ae))return()=>K.open({crypto:X.nativeCurrency?.symbol??"USDT",network:String(X.id),...N?{redirectUrl:N}:{}}).then(()=>{}).catch(D=>{throw console.warn("[crossx-kit] onramp open failed:",D),D})},[x,K,X,Ae,N]),tt=Hr();qr(()=>{if(K?.onStatus)return K.onStatus(()=>{tt.invalidateQueries()})},[K,tt]);let Re=yt(()=>{if(!x&&!(!K||!X)&&!Ae)return"On-ramp is not available in your region."},[x,K,X,Ae]),Fe=yt(()=>o?o.provider==="google"||o.provider==="apple":ae==="cross_embedded",[o,ae]),Pt=E.onBridgeDisabledMessage??(Fe?void 0:as),$n=E.onSendDisabledMessage??(Fe?void 0:cs),qn=o?o.provider==="google"||o.provider==="apple":ae==="cross_embedded",Hn=ze(()=>{xe().catch(D=>{console.error("[crossx-kit] selectWallet error:",D)})},[xe]),jt=v??(qn?Hn:void 0),Vn=ze(async({hash:D,chainId:Z})=>{let ee=Ut(ie,Z?{chainId:Z}:void 0);if(!ee)return null;try{return await ee.getTransactionReceipt({hash:D})}catch{return null}},[ie]),jn=ze(async D=>{let Z=we,ee=!1;D.chainId!==void 0&&D.chainId!==we&&(await Ne({chainId:D.chainId}),ee=!0);let de=D.chainId===56||D.chainId===97?{...D,type:"legacy"}:D,Q=await(g??Ce)(de);return await kt({getChainId:()=>ee?D.chainId:Z,switchChain:ye=>Ne({chainId:ye})},Z,Ke),Q},[g,Ce,we,Ne,Ke]),Qn=R||g?jn:void 0,zn=ze(async D=>{let Z=D.chainId??we,ee=Ut(ie,Z?{chainId:Z}:void 0);if(!ee)throw new Error(`publicClient for chainId ${Z??"unknown"} is not available \u2014 register the chain in createCrossxConfig({ networks }).`);let be=Z===56||Z===97,[de,ke]=await Promise.all([ee.estimateGas({account:D.from,to:D.to,value:D.value,data:D.data}),(async()=>{if(be)return{maxFeePerGas:void 0,maxPriorityFeePerGas:void 0,gasPrice:await ee.getGasPrice()};try{let Q=await ee.estimateFeesPerGas();return{maxFeePerGas:Q.maxFeePerGas,maxPriorityFeePerGas:Q.maxPriorityFeePerGas,gasPrice:void 0}}catch{return{maxFeePerGas:void 0,maxPriorityFeePerGas:void 0,gasPrice:await ee.getGasPrice()}}})()]);return{gasLimit:de,maxFeePerGas:ke.maxFeePerGas,maxPriorityFeePerGas:ke.maxPriorityFeePerGas,gasPrice:ke.gasPrice}},[ie,we]),Xn=w??zn,Yn=ze(async D=>{let Z={};if(!W||D.length===0)return Z;let ee=D.flatMap(de=>{let Q={address:de,abi:ts,chainId:we};return[{...Q,functionName:"balanceOf",args:[W]},{...Q,functionName:"totalSupply"},{...Q,functionName:"decimals"}]}),be;try{be=await On(ie,{contracts:ee,allowFailure:!0})}catch{return Z}return D.forEach((de,ke)=>{let Q=ke*3,ye=be[Q],ht=be[Q+1],ct=be[Q+2];!ye||ye.status!=="success"||(Z[de.toLowerCase()]={balance:ye.result,totalSupply:ht&&ht.status==="success"?ht.result:void 0,decimals:ct&&ct.status==="success"?Number(ct.result):void 0})}),Z},[ie,W,we]),Zn=ze(async D=>{let Z={earnedWei:0n,stakedWei:0n};if(!D)return Z;let ee=os[Pe],be={address:ee.poolAddress,abi:ns,chainId:ee.crossChainId},de;try{de=await On(ie,{allowFailure:!0,contracts:[{...be,functionName:"earned",args:[D]},{...be,functionName:"balanceOf",args:[D]},{...be,functionName:"posaActive"},{...be,functionName:"lastRewardBlock"},{...be,functionName:"totalStaked"}]})}catch{return Z}let ke=nt=>de[nt]&&de[nt].status==="success"?de[nt].result:0n,Q=ke(0),ye=ke(1);if(de[2]&&de[2].status==="success"?de[2].result:!1)return{earnedWei:Q,stakedWei:ye};let ct=ke(3),Xt=ke(4);if(Xt===0n)return{earnedWei:Q,stakedWei:ye};let At=0n;try{At=await Ut(ie,{chainId:ee.crossChainId})?.getBlockNumber?.()??0n}catch{return{earnedWei:Q,stakedWei:ye}}if(At<=ct)return{earnedWei:Q,stakedWei:ye};let Rt=0n;try{let nt=await fetch(ee.networkStatsUrl).then(Bt=>Bt.json()),Yt=nt?.data?.block_reward??nt?.block_reward;if(Yt){let[Bt,no=""]=String(Yt).split("."),oo=(no+"0".repeat(18)).slice(0,18);Rt=BigInt(Bt||"0")*$t+BigInt(oo||"0")}}catch{}if(Rt===0n)return{earnedWei:Q,stakedWei:ye};let eo=(At-ct)*Rt*$t/Xt,to=ye*eo/$t;return{earnedWei:Q+to,stakedWei:ye}},[ie,Pe]),Qt=!jt,zt=t?`cb-button ${t}`:"cb-button",Jn=t?`cb-pill ${t}`:"cb-pill";return Ze&&!he?it(Fn,{children:[me("style",{children:qt}),it("button",{type:"button",disabled:!0,className:zt,style:n,"aria-busy":"true",children:[me("span",{className:"cb-spinner","aria-hidden":"true"}),me("span",{className:"cb-button-label",children:"Connecting..."})]})]}):he&&q?it("span",{"data-crossx-wallet-info":Qt?"external":"embedded",children:[me("style",{children:qt}),Qt&&me("style",{children:us}),it(Kt,{...E,env:Pe,theme:ce,showBalance:ve,walletAddress:q,accountName:m,sendAccounts:T??a,connectorId:A,showPortfolio:R,onDisconnect:H,onSelectWallet:jt,onBuy:qe,onBuyDisabledMessage:Re,onBridgeDisabledMessage:Pt,onSendDisabledMessage:$n,sendTransaction:Qn,getTransactionReceipt:I??Vn,estimateGas:Xn,lpBalanceReader:Yn,stakingRewardsReader:Zn,bridgeTokens:_,bridgeHistory:u,getBridgeQuote:l,getBridgeToTokens:k,getBridgeApproval:h,approveBridge:L,submitBridge:Y,style:i,children:[me(Kt.Trigger,{asChild:!0,children:it("button",{type:"button",className:Jn,style:n,"aria-label":`Connected with ${d?.name??"wallet"}: ${Nn(q)}`,children:[d?.iconUrl?me("img",{src:d.iconUrl,alt:"",width:20,height:20,className:"cb-pill-icon","data-provider":d.iconUrl===Vt?"apple":void 0}):me("span",{className:"cb-pill-icon-placeholder","aria-hidden":"true"}),me("span",{className:"cb-pill-address",children:Nn(q)})]})}),me(Kt.Content,{align:"end",sideOffset:8})]})]}):it(Fn,{children:[me("style",{children:qt}),it("button",{type:"button",onClick:J,className:zt,style:n,"aria-label":typeof e=="string"?e:"Connect Wallet",children:[me(ls,{}),me("span",{className:"cb-button-label",children:e})]})]})}function ls(){return me("svg",{className:"cb-button-icon",viewBox:"0 0 18 18",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:me("path",{d:"M11.4368 10.5007C11.4368 9.9538 11.6544 9.42855 12.041 9.04175C12.4278 8.65492 12.9529 8.4375 13.5 8.4375H15.1875V6.00073L15.1732 5.92822C15.1639 5.90585 15.15 5.88528 15.1326 5.8678C15.0973 5.83263 15.0494 5.81287 14.9996 5.81287H3.74963C3.4787 5.81287 3.21001 5.75949 2.95972 5.65576C2.90937 5.63488 2.86089 5.61017 2.8125 5.58545V14.2504C2.8125 14.4989 2.91141 14.7371 3.08716 14.9128C3.2629 15.0886 3.50109 15.1875 3.74963 15.1875H15.0007C15.0252 15.1875 15.0495 15.1826 15.0721 15.1732C15.0948 15.1638 15.1152 15.1499 15.1326 15.1326C15.1499 15.1152 15.1638 15.0948 15.1732 15.0721C15.1826 15.0495 15.1875 15.0252 15.1875 15.0007V12.5629H13.5C12.9529 12.5629 12.4278 12.3454 12.041 11.9586C11.6545 11.5719 11.4369 11.0475 11.4368 10.5007ZM12.5618 10.5007C12.5619 10.7491 12.6609 10.9875 12.8364 11.1632C13.0123 11.3391 13.2513 11.4379 13.5 11.4379H15.75C15.7998 11.4379 15.8477 11.4182 15.8829 11.3829C15.9182 11.3477 15.9379 11.2998 15.9379 11.25V9.75037C15.9379 9.70054 15.9182 9.65266 15.8829 9.61743C15.8477 9.5822 15.7998 9.5625 15.75 9.5625H13.5C13.2513 9.5625 13.0123 9.66131 12.8364 9.83716C12.6607 10.013 12.5618 10.2522 12.5618 10.5007ZM13.6879 3.00037C13.6879 2.95054 13.6682 2.90266 13.6329 2.86743C13.5977 2.8322 13.5498 2.8125 13.5 2.8125H3.74963C3.50109 2.8125 3.2629 2.91141 3.08716 3.08716C2.91141 3.2629 2.8125 3.50109 2.8125 3.74963L2.81689 3.84192C2.82585 3.93354 2.8486 4.02351 2.88391 4.10889C2.93096 4.22263 3.00015 4.32614 3.08716 4.41321C3.17403 4.50009 3.2769 4.56936 3.39038 4.61646C3.50412 4.66359 3.62651 4.68787 3.74963 4.68787H13.6879V3.00037ZM14.8129 4.68787H14.9996C15.3473 4.68787 15.6808 4.82576 15.9269 5.07129C16.173 5.31702 16.3119 5.65077 16.3125 5.99854V8.56494C16.4469 8.62873 16.5711 8.7148 16.6783 8.82202C16.9246 9.06823 17.0629 9.40217 17.0629 9.75037V11.25C17.0629 11.5982 16.9246 11.9321 16.6783 12.1783C16.5712 12.2855 16.4468 12.3706 16.3125 12.4343V14.9985L16.3059 15.1282C16.2934 15.2564 16.2619 15.3822 16.2125 15.5017C16.1466 15.6612 16.05 15.806 15.928 15.928C15.806 16.05 15.6612 16.1466 15.5017 16.2125C15.3425 16.2783 15.1719 16.3126 14.9996 16.3125H3.74963C3.20272 16.3125 2.67847 16.095 2.29175 15.7083C1.90502 15.3215 1.6875 14.7973 1.6875 14.2504V3.74963C1.6875 3.20272 1.90502 2.67847 2.29175 2.29175C2.67847 1.90502 3.20272 1.6875 3.74963 1.6875H13.5C13.8482 1.6875 14.1821 1.82581 14.4283 2.07202C14.6746 2.31823 14.8129 2.65217 14.8129 3.00037V4.68787Z",fill:"currentColor"})})}var us=`
3
3
  [data-crossx-wallet-info="external"] .wi-select-wallet-btn {
4
4
  display: none !important;
package/dist/client.js CHANGED
@@ -1 +1 @@
1
- import{A as ae,B as ie,a as S,b as _,c as V,d as X,e as W,f as h,g as j,h as F,i as L,j as B,k as U,l as q,m as z,n as D,o as G,p as H,q as J,r as Q,s as Y,t as Z,u as $,v as ee,w as ne,x as te,y as oe,z as re}from"./chunk-4TWKECXR.js";import{bscMainnetNetwork as v,bscTestnetNetwork as x,createCrossxConfig as E,crossMainnetNetwork as O,crossTestnetNetwork as k}from"@nexus-cross/connect-kit-wagmi";import{toNexusAdapter as M}from"@nexus-cross/connect-kit-wagmi/to-nexus";import{reownAdapter as P}from"@nexus-cross/connect-kit-wagmi/reown";import{embeddedConnectorFactory as A}from"@nexus-cross/connect-kit-wagmi/embedded";function d(e){try{return import.meta.env?.[e]}catch{return}}function p(e){if(!(typeof process>"u"))return process.env?.[e]}function I(){return d("VITE_CROSSX_ENVIRONMENT")??d("NEXT_PUBLIC_CROSSX_ENVIRONMENT")??p("NEXT_PUBLIC_CROSSX_ENVIRONMENT")??p("CROSSX_ENVIRONMENT")}function K(e){switch(e?.toLowerCase()){case"dev":case"development":return"development";case"stage":case"staging":case"stg":return"staging";default:return"production"}}function R(e){return e==="production"?[O,v]:[k,x]}function T(){return{name:"CROSSx DApp",url:typeof window<"u"&&window.location?.origin?window.location.origin:"https://example.com"}}function b(e){let{app:c,appMetadata:l,networks:u,defaultNetwork:f,wallets:n,embedded:C=!0,environment:w,toNexus:t,reown:o,...r}=e,g=K(w??I()),i=u??R(g),a=Array.isArray(n)?null:n??"all",s=a!=="external-only"&&t!==!1,m=a!=="cross-only"&&o!==!1&&!!r.reownProjectId,y=t===!1?void 0:t,N=o===!1?void 0:o;if(a==="external-only"&&!r.reownProjectId)throw new Error('[crossx-kit] createConnectKitConfig({ wallets: "external-only" }) requires `reownProjectId`.');return E({...r,appMetadata:l??c??T(),networks:i,defaultNetwork:f??i[0],...Array.isArray(n)?{wallets:n}:{},...s?{crossProvider:M(y)}:{},...m?{reownProvider:P(N)}:{},...s&&C?{embeddedConnectorFactory:A}:{}})}export{Z as AppLauncher,ee as AppLauncherContent,$ as AppLauncherTrigger,F as ConnectButton,re as ConnectionStatus,Y as ConnectorId,W as CrossConnectKitProvider,X as CrossConnectModal,H as KycError,G as KycProvider,oe as OnRampError,q as OnRampProvider,L as OtherWalletsModal,te as SkillsButton,Q as WalletInfo,b as createConnectKitConfig,ae as formatBalance,ie as formatWei,J as launchKycVerification,S as useCrossConnectKit,_ as useCrossConnectKitTheme,h as useCrossdBridgeAdapter,j as useCrossxEmbeddedInfo,ne as useGlobalMenu,z as useKyc,B as useOnRamp,U as useOnRampEligibility,V as useOptionalCrossConnectKitTheme,D as useOptionalKyc};
1
+ import{A as ae,B as ie,a as S,b as _,c as V,d as X,e as W,f as h,g as j,h as F,i as L,j as B,k as U,l as q,m as z,n as D,o as G,p as H,q as J,r as Q,s as Y,t as Z,u as $,v as ee,w as ne,x as te,y as oe,z as re}from"./chunk-DM53GB35.js";import{bscMainnetNetwork as v,bscTestnetNetwork as x,createCrossxConfig as E,crossMainnetNetwork as O,crossTestnetNetwork as k}from"@nexus-cross/connect-kit-wagmi";import{toNexusAdapter as M}from"@nexus-cross/connect-kit-wagmi/to-nexus";import{reownAdapter as P}from"@nexus-cross/connect-kit-wagmi/reown";import{embeddedConnectorFactory as A}from"@nexus-cross/connect-kit-wagmi/embedded";function d(e){try{return import.meta.env?.[e]}catch{return}}function p(e){if(!(typeof process>"u"))return process.env?.[e]}function I(){return d("VITE_CROSSX_ENVIRONMENT")??d("NEXT_PUBLIC_CROSSX_ENVIRONMENT")??p("NEXT_PUBLIC_CROSSX_ENVIRONMENT")??p("CROSSX_ENVIRONMENT")}function K(e){switch(e?.toLowerCase()){case"dev":case"development":return"development";case"stage":case"staging":case"stg":return"staging";default:return"production"}}function R(e){return e==="production"?[O,v]:[k,x]}function T(){return{name:"CROSSx DApp",url:typeof window<"u"&&window.location?.origin?window.location.origin:"https://example.com"}}function b(e){let{app:c,appMetadata:l,networks:u,defaultNetwork:f,wallets:n,embedded:C=!0,environment:w,toNexus:t,reown:o,...r}=e,g=K(w??I()),i=u??R(g),a=Array.isArray(n)?null:n??"all",s=a!=="external-only"&&t!==!1,m=a!=="cross-only"&&o!==!1&&!!r.reownProjectId,y=t===!1?void 0:t,N=o===!1?void 0:o;if(a==="external-only"&&!r.reownProjectId)throw new Error('[crossx-kit] createConnectKitConfig({ wallets: "external-only" }) requires `reownProjectId`.');return E({...r,appMetadata:l??c??T(),networks:i,defaultNetwork:f??i[0],...Array.isArray(n)?{wallets:n}:{},...s?{crossProvider:M(y)}:{},...m?{reownProvider:P(N)}:{},...s&&C?{embeddedConnectorFactory:A}:{}})}export{Z as AppLauncher,ee as AppLauncherContent,$ as AppLauncherTrigger,F as ConnectButton,re as ConnectionStatus,Y as ConnectorId,W as CrossConnectKitProvider,X as CrossConnectModal,H as KycError,G as KycProvider,oe as OnRampError,q as OnRampProvider,L as OtherWalletsModal,te as SkillsButton,Q as WalletInfo,b as createConnectKitConfig,ae as formatBalance,ie as formatWei,J as launchKycVerification,S as useCrossConnectKit,_ as useCrossConnectKitTheme,h as useCrossdBridgeAdapter,j as useCrossxEmbeddedInfo,ne as useGlobalMenu,z as useKyc,B as useOnRamp,U as useOnRampEligibility,V as useOptionalCrossConnectKitTheme,D as useOptionalKyc};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{A,B,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"./chunk-4TWKECXR.js";export{t as AppLauncher,v as AppLauncherContent,u as AppLauncherTrigger,h as ConnectButton,z as ConnectionStatus,s as ConnectorId,e as CrossConnectKitProvider,d as CrossConnectModal,p as KycError,o as KycProvider,y as OnRampError,l as OnRampProvider,i as OtherWalletsModal,x as SkillsButton,r as WalletInfo,A as formatBalance,B as formatWei,q as launchKycVerification,a as useCrossConnectKit,b as useCrossConnectKitTheme,f as useCrossdBridgeAdapter,g as useCrossxEmbeddedInfo,w as useGlobalMenu,m as useKyc,j as useOnRamp,k as useOnRampEligibility,c as useOptionalCrossConnectKitTheme,n as useOptionalKyc};
1
+ import{A,B,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"./chunk-DM53GB35.js";export{t as AppLauncher,v as AppLauncherContent,u as AppLauncherTrigger,h as ConnectButton,z as ConnectionStatus,s as ConnectorId,e as CrossConnectKitProvider,d as CrossConnectModal,p as KycError,o as KycProvider,y as OnRampError,l as OnRampProvider,i as OtherWalletsModal,x as SkillsButton,r as WalletInfo,A as formatBalance,B as formatWei,q as launchKycVerification,a as useCrossConnectKit,b as useCrossConnectKitTheme,f as useCrossdBridgeAdapter,g as useCrossxEmbeddedInfo,w as useGlobalMenu,m as useKyc,j as useOnRamp,k as useOnRampEligibility,c as useOptionalCrossConnectKitTheme,n as useOptionalKyc};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexus-cross/connect-kit-react",
3
- "version": "1.3.4",
3
+ "version": "1.3.5-beta.1",
4
4
  "description": "React components and hooks for @nexus-cross/connect-kit wallet connection",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -24,12 +24,12 @@
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "@nexus-cross/connect-kit-core": "1.3.4",
28
- "@nexus-cross/connect-kit-wagmi": "1.3.4",
29
- "@nexus-cross/crossx-design-system": "1.3.4",
30
- "@nexus-cross/dapp-ui": "1.3.4",
31
- "@nexus-cross/kyc": "1.3.4",
32
- "@nexus-cross/onramp": "1.3.4"
27
+ "@nexus-cross/connect-kit-core": "1.3.5-beta.1",
28
+ "@nexus-cross/connect-kit-wagmi": "1.3.5-beta.1",
29
+ "@nexus-cross/crossx-design-system": "1.3.5-beta.1",
30
+ "@nexus-cross/dapp-ui": "1.3.5-beta.1",
31
+ "@nexus-cross/kyc": "1.3.5-beta.1",
32
+ "@nexus-cross/onramp": "1.3.5-beta.1"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@tanstack/react-query": "^5.60.0",