@nexus-cross/connect-kit-react 1.3.10-beta.7 → 1.3.10-beta.8
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.10-beta.7";var ht="__nexusCrossAppLauncherRuntime";function fo(){if(typeof window>"u")return null;let e=window;return e[ht]??(e[ht]={mode:"dapp-ui"}),e[ht]}function go(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 sn(){let e=fo();e&&(e.mode="connect-kit-react",e.connectKitVersion=mt,go(e))}import{useCallback as Be,useEffect as ie,useMemo as Ne,useRef as ke,useState as je}from"react";import{WagmiProvider as xo,useAccount as Io,useChainId as vo,useConnect as So,useDisconnect as Po,useSwitchChain as Ao}from"wagmi";import{QueryClient as Ro,QueryClientProvider as Bo}from"@tanstack/react-query";import{clearWalletSessionStorage as pn,onOpenOtherWallets as _o,pickInitialState as Eo,resolveCurrentWallet as Oo}from"@nexus-cross/connect-kit-wagmi";import{resolveThemeMode as No}from"@nexus-cross/connect-kit-core";import{buildDesignSystemCss as Fo}from"@nexus-cross/crossx-design-system";import{OnRampProvider as Wo}from"@nexus-cross/onramp/react";import{KycProvider as Do}from"@nexus-cross/kyc/react";import{createContext as yo,useContext as bo}from"react";var Ft=yo(null);function Ge(){let e=bo(Ft);if(!e)throw new Error("useCrossConnectKit must be used within <CrossConnectKitProvider>");return e}import{createContext as wo,useContext as an}from"react";var Ct=wo(null);function ho(){let e=an(Ct);if(!e)throw new Error("useCrossConnectKitTheme must be used within <CrossConnectKitProvider>");return e}function ft(){return an(Ct)}import{createContext as Co}from"react";var kt=Co(null);function cn(){let e=new Set,t=n=>{for(let i of[...e])try{i(n)}catch(o){console.debug("[crossx-kit] analytics handler threw",o)}};return{track:t,emit:n=>t({...n,timestamp:Date.now()}),subscribe:n=>(e.add(n),()=>{e.delete(n)})}}import{useCallback as ko,useMemo as dn}from"react";import{WalletConnectModal as ln}from"@nexus-cross/dapp-ui";import{jsx as un}from"react/jsx-runtime";var To=new Set(["cross_wallet","cross_extension","metamask","binance"]);function Wt({open:e,onOpenChange:t}){let{connect:n,availableWallets:i,oauth:o,extraWallets:c,walletAllowlist:g,kitConfig:y}=Ge(),r=ft()?.mode??"dark",f=dn(()=>{let m=g?new Set(g):null,k={};for(let x of i){if(!To.has(x.walletId)||m&&!m.has(x.walletId))continue;let v=x.walletId;k[v]=()=>{n(x.walletId)}}for(let[x,v]of Object.entries(c))v&&(m&&!m.has(x)||(k[x]=v));return k},[i,n,c,g]),w=dn(()=>{if(o)return{apple:()=>{o.signIn("apple")},google:()=>{o.signIn("google")}}},[o]),C=ko(m=>t(m),[t]);return un(ln,{wallets:f,socialProviders:w,termsUrl:y.legal?.termsUrl,privacyUrl:y.legal?.privacyUrl,theme:r,open:e,onOpenChange:C,children:un(ln.Content,{})})}import{jsx as Qe,jsxs as gn}from"react/jsx-runtime";var Lo=new Ro,Dt="crossx-kit:last-wallet-intent",Mo=15e3;function mn(e,t){return Promise.race([e.then(()=>{},()=>{}),new Promise(n=>setTimeout(n,t))])}function Go(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 Ko(){if(typeof window>"u")return null;try{return window.localStorage.getItem(Dt)??null}catch{return null}}function fn(e){if(!(typeof window>"u"))try{e?window.localStorage.setItem(Dt,e):window.localStorage.removeItem(Dt)}catch{}}function Uo(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 $o(e,t){if(!(typeof window>"u"))try{window.localStorage.setItem(e,t)}catch{}}function qo({children:e,config:t,activeProvider:n,onRequestProviderSwap:i,pendingConnectWalletId:o,clearPending:c,themeMode:g,themeTokens:y,extraWallets:p,walletAllowlist:r,emit:f}){let[w,C]=je(!1),[m,k]=je(()=>Ko()),[x,v]=je(null),{address:W,isConnected:I,isConnecting:V,isReconnecting:G,connector:N}=Io(),{connectors:j,connectAsync:z}=So(),{disconnectAsync:X}=Po(),{kitConfig:D,connectorRegistry:K,crossProvider:Pe,reownProvider:fe}=t,O=n==="cross"?Pe:fe,R=Ne(()=>!I||!N?null:Oo(K,N.id,m),[I,N,K,m]),Y=Ne(()=>K.entries.filter(l=>l.type!=="embedded"),[K]),$=Be(l=>K.getEntry(l)?.type??"external",[K]),ce=ke(null);ce.current=x;let Te=ke(R);Te.current=R;let Le=ke(W);Le.current=W;let xe=D.embeddedProjectId?.trim()||D.crossProjectId?.trim(),Ee=!!D.onRampEnabled&&!!xe,ye=Ne(()=>!Ee||!xe?null:{projectId:xe,walletState:{getAddress:()=>Le.current}},[Ee,xe]),Me=ke(N);Me.current=N;let de=D.embeddedProjectId?.trim()||D.crossProjectId?.trim(),Je=!!D.kycEnabled&&!!de,et=Ne(()=>!Je||!de?null:{projectId:de,getAccessToken:async()=>{let l=Me.current;if(!(!l||typeof l.getProvider!="function"))try{return(await(await l.getProvider())?.sdk?.getUserInfo?.())?.data?.accessToken||void 0}catch{return}}},[Je,de]);ie(()=>_o(()=>C(!0)),[]),ie(()=>{if(!w||typeof document>"u")return;let l=setTimeout(()=>{document.querySelectorAll("#__crossx-confirm-overlay").forEach(h=>h.remove())},50);return()=>clearTimeout(l)},[w]);let Ae=ke(I),tt=ke(I);Ae.current=I;let ct=ke(!1);ie(()=>{console.debug("[crossx-kit] state",{activeProvider:n,isConnected:I,isConnecting:V,isReconnecting:G,activeConnectorId:N?.id,currentWallet:R,lastIntent:m})},[n,I,V,G,N?.id,R,m]),ie(()=>{I&&!tt.current&&O?.closeModal?.({kitConfig:D}),tt.current=I},[I,O,D]),ie(()=>{I&&v(null)},[I]);let Re=vo(),{switchChainAsync:be}=Ao(),we=ke(null);ie(()=>{if(!D.enforceDefaultNetworkOnConnect)return;let l=D.defaultNetwork?.id;if(!l)return;if(!I||!W||!N){we.current=null;return}let h=`${N.id}:${W}`;we.current!==h&&(we.current=h,Re!==l&&be({chainId:l}).catch(()=>{}))},[D.enforceDefaultNetworkOnConnect,D.defaultNetwork,I,W,N,Re,be]);let qe=ke(w);ie(()=>{w&&!qe.current?f({name:"connect_modal_opened"}):!w&&qe.current&&f({name:"connect_modal_closed",completed:Ae.current}),qe.current=w},[w,f]);let s=ke(I);ie(()=>{if(I&&!s.current){let l=ce.current;l&&f({name:"connect_succeeded",walletId:l,walletType:$(l),chainId:Re})}s.current=I},[I,Re,f,$]);let a=Be(l=>j.find(h=>h.id===l),[j]);ie(()=>{let l=K.getEntry("cross_embedded");if(!l)return;let h=a(l.connectorId);if(!h)return;let T=!1;return(async()=>{try{let P=await h.getProvider();if(T)return;P?.sdk?.applyTheme?.(g,y??void 0)}catch(P){console.debug("[crossx-kit] applyTheme skipped:",P)}})(),()=>{T=!0}},[K,a,g,y]);let d=Be(l=>{k(l),fn(l)},[]),u=Be(()=>{k(null),fn(null),v(null)},[]);ie(()=>{if(!O?.subscribeModalState)return;let l=!1;return O.subscribeModalState({kitConfig:D},h=>{if(ct.current=h,h){l=!0;return}l&&(l=!1,setTimeout(()=>{if(Ae.current)return;let T=ce.current;T&&f({name:"connect_cancelled",walletId:T,stage:"popup"}),(async()=>{try{await X()}catch{}u()})()},250))})},[O,D,X,u,f]),ie(()=>{if(!x||I||typeof window>"u"||x==="cross_embedded")return;let l=typeof document<"u"&&!document.hasFocus(),h=null,T=()=>{l=!0},P=()=>{l&&(h&&clearTimeout(h),h=setTimeout(()=>{if(Ae.current||ct.current)return;let E=ce.current;E&&f({name:"connect_cancelled",walletId:E,stage:"popup"}),(async()=>{try{await X()}catch{}u()})()},1e3))};return window.addEventListener("blur",T),window.addEventListener("focus",P),()=>{window.removeEventListener("blur",T),window.removeEventListener("focus",P),h&&clearTimeout(h)}},[x,I,X,u,f]);let b=Be(async l=>{console.debug("[crossx-kit] runConnect enter",{walletId:l,activeProvider:n,isConnected:I,activeConnectorId:N?.id});let h=K.getEntry(l);if(!h){if((l==="metamask"||l==="binance")&&!fe){console.error(`[crossx-kit] "${l}" 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: "${l}"`);return}if(v(l),h.providerKind!==n){console.debug("[crossx-kit] provider swap needed",{from:n,to:h.providerKind,walletId:l}),d(l);try{await X()}catch{}await new Promise(E=>setTimeout(E,0)),i(h.providerKind,l);return}let T=$(l);if(f({name:"wallet_selected",walletId:l,walletType:T}),f({name:"connect_started",walletId:l,walletType:T}),d(l),O?.beforeConnect)try{let E=await O.beforeConnect({kitConfig:D,themeMode:g},l);if(console.debug("[crossx-kit] beforeConnect result",{walletId:l,result:E}),E==="handled")return}catch(E){console.warn('[crossx-kit] adapter.beforeConnect threw for "%s":',l,E)}let P=a(h.connectorId);if(console.debug("[crossx-kit] findConnector",{lookupId:h.connectorId,found:P?.id,availableIds:j.map(E=>E.id)}),!P){console.error(`[crossx-kit] Connector "${h.connectorId}" not found on provider "${h.providerKind}". Available: ${j.map(E=>E.id).join(", ")}`),f({name:"connect_failed",walletId:l,reason:"connector_not_found"}),u();return}try{console.debug("[crossx-kit] connectAsync start",{connectorId:P.id});let E=await z({connector:P});console.debug("[crossx-kit] connectAsync resolved",{accountsLen:E.accounts.length,chainId:E.chainId});return}catch(E){let le=Go(E);if(!le){console.error('[crossx-kit] connectAsync error for "%s":',l,E);try{await X()}catch{}}if(!h.fallbackConnectorId){le||f({name:"connect_failed",walletId:l,reason:"connector_error"}),u();return}}if(h.fallbackConnectorId){let E=a(h.fallbackConnectorId);if(E)try{await z({connector:E})}catch(le){console.error('[crossx-kit] Fallback connect failed for "%s":',l,le);try{await X()}catch{}f({name:"connect_failed",walletId:l,reason:"fallback_failed"}),u()}else f({name:"connect_failed",walletId:l,reason:"fallback_failed"}),u()}},[K,j,a,z,X,d,u,O,n,D,i,g,f,$]);ie(()=>{if(!o)return;let l=o;c(),b(l)},[o,n]);let B=Be(async()=>{C(!0)},[]),_=Be(async()=>{f({name:"disconnected",walletId:Te.current});try{await X()}catch(l){console.error("[crossx-kit] wagmi disconnect error:",l)}if(O?.teardown)try{await O.teardown({kitConfig:D})}catch(l){console.error("[crossx-kit] adapter teardown error:",l)}pn(),u()},[X,O,D,u,f]),A=Be(async()=>{await mn(X(),3e3);try{let l=K.getEntry("cross_embedded"),h=l&&a(l.connectorId);if(h?.getProvider){let T=await Promise.race([h.getProvider(),new Promise(E=>setTimeout(E,3e3))]),P=T?.sdk?.signOut;typeof P=="function"&&await mn(P.call(T.sdk),3e3)}}catch{}pn()},[K,a,X]),L=Be(async()=>{let l=K.getEntry("cross_embedded");if(!l)return null;let h=a(l.connectorId);if(!h)return null;try{let T=await h.getProvider(),P=T?.sdk;if(!P?.selectWallet)return null;let E=await P.selectWallet(P.currentAddress??void 0);return E?.address&&T.notifyAccountsChanged&&T.notifyAccountsChanged([E.address]),E&&f({name:"wallet_switched",index:E.index}),E}catch{return null}},[K,a,f]),Z=Ne(()=>{let l=t.oauth;return l?{signIn:async h=>{v("cross_embedded"),f({name:"wallet_selected",walletId:"cross_embedded",walletType:"embedded"}),f({name:"connect_started",walletId:"cross_embedded",walletType:"embedded"});try{await l.signIn(h)}catch(T){throw f({name:"connect_cancelled",walletId:"cross_embedded",stage:"popup"}),v(null),T}}}:null},[t.oauth,f]),S=ke(!1);ie(()=>{if(n!=="cross"||I||V||G||x!=null||S.current)return;let l=K.getEntry("cross_embedded");if(!l)return;let h=a(l.connectorId);if(!h)return;S.current=!0;let T=!1;return(async()=>{try{let P=await h.isAuthorized?.();if(T||!P)return;await z({connector:h})}catch{}})(),()=>{T=!0}},[n,I,V,G,x,K,a,z]),ie(()=>{if(x!=="cross_embedded"||I||typeof window>"u")return;let l=!document.hasFocus(),h=()=>{l=!0};window.addEventListener("blur",h);let T=setTimeout(()=>{Ae.current||l||(console.warn("[crossx-kit] embedded sign-in stalled before the OAuth popup opened \u2014 clearing the stale session so a retry starts clean"),f({name:"connect_cancelled",walletId:"cross_embedded",stage:"stalled"}),u(),A())},Mo);return()=>{window.removeEventListener("blur",h),clearTimeout(T)}},[x,I,u,A,f]);let F=x!=null&&!I,q=Ne(()=>({kitConfig:D,connectorRegistry:K,availableWallets:Y,connect:b,connectWallet:B,disconnect:_,selectWallet:L,currentWallet:R,lastIntent:m,isConnecting:F,connectingWalletId:x,openOtherWallets:()=>C(!0),closeOtherWallets:()=>C(!1),otherWalletsOpen:w,oauth:Z,extraWallets:p,walletAllowlist:r,onRampEnabled:Ee}),[D,K,Y,b,B,_,L,R,m,F,x,w,Z,p,r,Ee]),U=gn(Ft.Provider,{value:q,children:[e,Qe(Wt,{open:w,onOpenChange:C})]});return et&&(U=Qe(Do,{config:et,children:U})),ye&&(U=Qe(Wo,{config:ye,children:U})),U}var Ho=[/Connection interrupted while trying to subscribe/i,/No matching key\. subscription:/i,/Proposal expired/i];function Vo(e){let t=e?.message;return typeof t!="string"?!1:Ho.some(n=>n.test(t))}var jo={};function Qo(e){return e&&{...e,connections:new Map,current:null}}function zo({children:e,config:t,initialState:n,extraWallets:i=jo,walletAllowlist:o}){let[c,g]=je(()=>Uo(t.activeProviderStorageKey,t.defaultProvider)),[y,p]=je(null),r=ke(!1),f=ke(null);f.current||(f.current=cn());let w=f.current,C=Ne(()=>({subscribe:w.subscribe}),[w]),{kitConfig:m}=t,[k,x]=je(null),[v,W]=je(null),[I,V]=je(0),G=Ne(()=>No(m.theme,m.autoDetectTheme),[m.theme,m.autoDetectTheme,I]),N=k??G,j=v??m.themeTokens;ie(()=>{if(!m.autoDetectTheme||k||typeof window>"u"||!window.matchMedia)return;let R=window.matchMedia("(prefers-color-scheme: dark)"),Y=()=>V($=>$+1);try{return R.addEventListener("change",Y),()=>R.removeEventListener("change",Y)}catch{return R.addListener(Y),()=>R.removeListener(Y)}},[m.autoDetectTheme,k]),ie(()=>{if(typeof document>"u")return;let R=document.documentElement,Y=R.getAttribute("data-ds-theme"),$=R.getAttribute("data-theme");return R.setAttribute("data-ds-theme",N),$||R.setAttribute("data-theme",N),()=>{Y==null?R.removeAttribute("data-ds-theme"):R.setAttribute("data-ds-theme",Y),$==null&&R.removeAttribute("data-theme")}},[N]);let z=Ne(()=>Fo(t.designSystem),[t.designSystem]),X=Ne(()=>({mode:N,tokens:j,setThemeMode:R=>x(R),setThemeTokens:R=>W(R)}),[N,j]);ie(()=>{if(typeof window>"u")return;let R=Y=>{Vo(Y.reason)&&Y.preventDefault()};return window.addEventListener("unhandledrejection",R),()=>window.removeEventListener("unhandledrejection",R)},[]);let D=Be((R,Y)=>{r.current||(r.current=!0,p(Y),g(R),$o(t.activeProviderStorageKey,R),queueMicrotask(()=>{r.current=!1}))},[t.activeProviderStorageKey]),K=Be(()=>p(null),[]),Pe=c==="cross"?t.crossWagmiConfig:t.reownWagmiConfig,fe=Qo(Eo(n,c));if(!Pe){if(!(c==="cross"?t.reownWagmiConfig:t.crossWagmiConfig))throw new Error("[crossx-kit] createCrossxConfig returned no wagmi Config for either side");let Y=c==="cross"?"reown":"cross";queueMicrotask(()=>g(Y))}let O=Pe??(c==="cross"?t.reownWagmiConfig:t.crossWagmiConfig);return Qe(kt.Provider,{value:C,children:gn(Ct.Provider,{value:X,children:[Qe("style",{"data-crossx-design-system":"",children:z}),Qe(xo,{config:O,initialState:fe,children:Qe(Bo,{client:Lo,children:Qe(qo,{config:t,activeProvider:c,onRequestProviderSwap:D,pendingConnectWalletId:y,clearPending:K,themeMode:N,themeTokens:j,extraWallets:i,walletAllowlist:o??t.kitConfig.wallets??null,emit:w.emit,children:e})})},c)]})})}import{useCallback as Ye,useEffect as es,useMemo as At}from"react";import{useQueryClient as ts}from"@tanstack/react-query";import{useAccount as ns,useChainId as os,useConfig as rs,useSendTransaction as ss,useSwitchChain as is}from"wagmi";import{getPublicClient as Ht,readContracts as Kn}from"wagmi/actions";import{WalletInfo as Vt,ConnectorId as Ze,resolveEnvironment as as}from"@nexus-cross/dapp-ui";import{useOptionalOnRamp as cs,useOptionalOnRampEligibility as ds}from"@nexus-cross/onramp/react";import{APPLE_ICON as Xt,BINANCE_ICON as qn,CROSSX_ICON as zt,EXTENSION_ICON as ls,GOOGLE_ICON as Hn,METAMASK_ICON as Vn}from"@nexus-cross/connect-kit-wagmi";import{WALLET_LABELS as Rt}from"@nexus-cross/crossx-design-system";import{useCallback as oe,useMemo as ve,useRef as Xo}from"react";import{useQueries as wn,useQuery as ze}from"@tanstack/react-query";import{encodeFunctionData as gt,formatUnits as Pt,parseSignature as Yo,parseUnits as Zo}from"viem";import{getChainId as Lt,getPublicClient as En,readContract as _e,signTypedData as Jo,switchChain as hn,waitForTransactionReceipt as er,writeContract as Cn}from"wagmi/actions";import{useConfig as tr}from"wagmi";async function Tt(e,t,n){if(!(!n||t===void 0))try{if(e.getChainId()===t)return;await e.switchChain(t)}catch{}}var lt=10000n;function yn(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 xt(e,t){let n=yn(t);return n>=lt?0n:e*(lt-n)/lt}function bn(e,t){let n=yn(t);return(e*(lt+n)+(lt-1n))/lt}function nr(e){return e!=="bridge"}var $e="0x0000000000000000000000000000000000000000",Se=100,pt=18,or=180000n,rr=250000n,On=new Set([56,97]),sr=130n,ir=100n,ar={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"},cr={dev:"dev",stage:"stg",production:"prod"};function dr(e,t){let n=e?.[cr[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 lr={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"},ur=["BSC_CROSS","W_CROSS","NATIVE_CROSS","USDTX","CROSSD","USDTB","SWAP_BRIDGE_ROUTER"],pr={BSC_CROSS:$e,W_CROSS:$e,NATIVE_CROSS:$e,USDTX:$e,CROSSD:$e,USDTB:$e,SWAP_BRIDGE_ROUTER:$e},mr=/^0x[0-9a-fA-F]{40}$/;function fr(e,t){let n=typeof e=="string"?e:e?.[t];return typeof n=="string"&&mr.test(n)?n:null}function gr(e,t){if(!e?.bridge)return null;let n=e.envToNetwork?.[t]??(t==="production"?"mainnet":"testnet"),i={};for(let o of ur){let c=fr(e.bridge[o],n);if(!c)return null;i[o]=c}return i}var yr={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"}]}],Mt=[{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"}]}],kn=[{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"}]}],Tn=[{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"}]}],br=[{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"}]}],Ke=[{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:[]}],wr=[{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 Nn(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 Fe(e,t){let n=await fetch(e,{cache:"no-store",signal:t});if(!n.ok)throw new Error(`CrossD bridge adapter request failed: ${await Nn(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 xn(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 Nn(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 hr(e){return new Promise(t=>setTimeout(t,e))}async function Cr(e,t,{attempts:n=60,intervalMs:i=2e3}={}){for(let o=0;o<n;o+=1){try{let c=await Fe(`${e}/permit-hash/${t}`);if(Ut(c))return c}catch{}await hr(i)}return null}function se(e,t){return`${e}-${t.toLowerCase()}`}function pe(e){return se(e.chainId,e.address)}function We(e){return e==="swap"||e==="deposit-swap"||e==="swap-withdraw"}function kr(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.10-beta.8";var ht="__nexusCrossAppLauncherRuntime";function fo(){if(typeof window>"u")return null;let e=window;return e[ht]??(e[ht]={mode:"dapp-ui"}),e[ht]}function go(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 sn(){let e=fo();e&&(e.mode="connect-kit-react",e.connectKitVersion=mt,go(e))}import{useCallback as Be,useEffect as ie,useMemo as Ne,useRef as ke,useState as je}from"react";import{WagmiProvider as xo,useAccount as Io,useChainId as vo,useConnect as So,useDisconnect as Po,useSwitchChain as Ao}from"wagmi";import{QueryClient as Ro,QueryClientProvider as Bo}from"@tanstack/react-query";import{clearWalletSessionStorage as pn,onOpenOtherWallets as _o,pickInitialState as Eo,resolveCurrentWallet as Oo}from"@nexus-cross/connect-kit-wagmi";import{resolveThemeMode as No}from"@nexus-cross/connect-kit-core";import{buildDesignSystemCss as Fo}from"@nexus-cross/crossx-design-system";import{OnRampProvider as Wo}from"@nexus-cross/onramp/react";import{KycProvider as Do}from"@nexus-cross/kyc/react";import{createContext as yo,useContext as bo}from"react";var Ft=yo(null);function Ge(){let e=bo(Ft);if(!e)throw new Error("useCrossConnectKit must be used within <CrossConnectKitProvider>");return e}import{createContext as wo,useContext as an}from"react";var Ct=wo(null);function ho(){let e=an(Ct);if(!e)throw new Error("useCrossConnectKitTheme must be used within <CrossConnectKitProvider>");return e}function ft(){return an(Ct)}import{createContext as Co}from"react";var kt=Co(null);function cn(){let e=new Set,t=n=>{for(let i of[...e])try{i(n)}catch(o){console.debug("[crossx-kit] analytics handler threw",o)}};return{track:t,emit:n=>t({...n,timestamp:Date.now()}),subscribe:n=>(e.add(n),()=>{e.delete(n)})}}import{useCallback as ko,useMemo as dn}from"react";import{WalletConnectModal as ln}from"@nexus-cross/dapp-ui";import{jsx as un}from"react/jsx-runtime";var To=new Set(["cross_wallet","cross_extension","metamask","binance"]);function Wt({open:e,onOpenChange:t}){let{connect:n,availableWallets:i,oauth:o,extraWallets:c,walletAllowlist:g,kitConfig:y}=Ge(),r=ft()?.mode??"dark",f=dn(()=>{let m=g?new Set(g):null,k={};for(let x of i){if(!To.has(x.walletId)||m&&!m.has(x.walletId))continue;let v=x.walletId;k[v]=()=>{n(x.walletId)}}for(let[x,v]of Object.entries(c))v&&(m&&!m.has(x)||(k[x]=v));return k},[i,n,c,g]),w=dn(()=>{if(o)return{apple:()=>{o.signIn("apple")},google:()=>{o.signIn("google")}}},[o]),C=ko(m=>t(m),[t]);return un(ln,{wallets:f,socialProviders:w,termsUrl:y.legal?.termsUrl,privacyUrl:y.legal?.privacyUrl,theme:r,open:e,onOpenChange:C,children:un(ln.Content,{})})}import{jsx as Qe,jsxs as gn}from"react/jsx-runtime";var Lo=new Ro,Dt="crossx-kit:last-wallet-intent",Mo=15e3;function mn(e,t){return Promise.race([e.then(()=>{},()=>{}),new Promise(n=>setTimeout(n,t))])}function Go(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 Ko(){if(typeof window>"u")return null;try{return window.localStorage.getItem(Dt)??null}catch{return null}}function fn(e){if(!(typeof window>"u"))try{e?window.localStorage.setItem(Dt,e):window.localStorage.removeItem(Dt)}catch{}}function Uo(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 $o(e,t){if(!(typeof window>"u"))try{window.localStorage.setItem(e,t)}catch{}}function qo({children:e,config:t,activeProvider:n,onRequestProviderSwap:i,pendingConnectWalletId:o,clearPending:c,themeMode:g,themeTokens:y,extraWallets:p,walletAllowlist:r,emit:f}){let[w,C]=je(!1),[m,k]=je(()=>Ko()),[x,v]=je(null),{address:W,isConnected:I,isConnecting:V,isReconnecting:G,connector:N}=Io(),{connectors:j,connectAsync:z}=So(),{disconnectAsync:X}=Po(),{kitConfig:D,connectorRegistry:K,crossProvider:Pe,reownProvider:fe}=t,O=n==="cross"?Pe:fe,R=Ne(()=>!I||!N?null:Oo(K,N.id,m),[I,N,K,m]),Y=Ne(()=>K.entries.filter(l=>l.type!=="embedded"),[K]),$=Be(l=>K.getEntry(l)?.type??"external",[K]),ce=ke(null);ce.current=x;let Te=ke(R);Te.current=R;let Le=ke(W);Le.current=W;let xe=D.embeddedProjectId?.trim()||D.crossProjectId?.trim(),Ee=!!D.onRampEnabled&&!!xe,ye=Ne(()=>!Ee||!xe?null:{projectId:xe,walletState:{getAddress:()=>Le.current}},[Ee,xe]),Me=ke(N);Me.current=N;let de=D.embeddedProjectId?.trim()||D.crossProjectId?.trim(),Je=!!D.kycEnabled&&!!de,et=Ne(()=>!Je||!de?null:{projectId:de,getAccessToken:async()=>{let l=Me.current;if(!(!l||typeof l.getProvider!="function"))try{return(await(await l.getProvider())?.sdk?.getUserInfo?.())?.data?.accessToken||void 0}catch{return}}},[Je,de]);ie(()=>_o(()=>C(!0)),[]),ie(()=>{if(!w||typeof document>"u")return;let l=setTimeout(()=>{document.querySelectorAll("#__crossx-confirm-overlay").forEach(h=>h.remove())},50);return()=>clearTimeout(l)},[w]);let Ae=ke(I),tt=ke(I);Ae.current=I;let ct=ke(!1);ie(()=>{console.debug("[crossx-kit] state",{activeProvider:n,isConnected:I,isConnecting:V,isReconnecting:G,activeConnectorId:N?.id,currentWallet:R,lastIntent:m})},[n,I,V,G,N?.id,R,m]),ie(()=>{I&&!tt.current&&O?.closeModal?.({kitConfig:D}),tt.current=I},[I,O,D]),ie(()=>{I&&v(null)},[I]);let Re=vo(),{switchChainAsync:be}=Ao(),we=ke(null);ie(()=>{if(!D.enforceDefaultNetworkOnConnect)return;let l=D.defaultNetwork?.id;if(!l)return;if(!I||!W||!N){we.current=null;return}let h=`${N.id}:${W}`;we.current!==h&&(we.current=h,Re!==l&&be({chainId:l}).catch(()=>{}))},[D.enforceDefaultNetworkOnConnect,D.defaultNetwork,I,W,N,Re,be]);let qe=ke(w);ie(()=>{w&&!qe.current?f({name:"connect_modal_opened"}):!w&&qe.current&&f({name:"connect_modal_closed",completed:Ae.current}),qe.current=w},[w,f]);let s=ke(I);ie(()=>{if(I&&!s.current){let l=ce.current;l&&f({name:"connect_succeeded",walletId:l,walletType:$(l),chainId:Re})}s.current=I},[I,Re,f,$]);let a=Be(l=>j.find(h=>h.id===l),[j]);ie(()=>{let l=K.getEntry("cross_embedded");if(!l)return;let h=a(l.connectorId);if(!h)return;let T=!1;return(async()=>{try{let P=await h.getProvider();if(T)return;P?.sdk?.applyTheme?.(g,y??void 0)}catch(P){console.debug("[crossx-kit] applyTheme skipped:",P)}})(),()=>{T=!0}},[K,a,g,y]);let d=Be(l=>{k(l),fn(l)},[]),u=Be(()=>{k(null),fn(null),v(null)},[]);ie(()=>{if(!O?.subscribeModalState)return;let l=!1;return O.subscribeModalState({kitConfig:D},h=>{if(ct.current=h,h){l=!0;return}l&&(l=!1,setTimeout(()=>{if(Ae.current)return;let T=ce.current;T&&f({name:"connect_cancelled",walletId:T,stage:"popup"}),(async()=>{try{await X()}catch{}u()})()},250))})},[O,D,X,u,f]),ie(()=>{if(!x||I||typeof window>"u"||x==="cross_embedded")return;let l=typeof document<"u"&&!document.hasFocus(),h=null,T=()=>{l=!0},P=()=>{l&&(h&&clearTimeout(h),h=setTimeout(()=>{if(Ae.current||ct.current)return;let E=ce.current;E&&f({name:"connect_cancelled",walletId:E,stage:"popup"}),(async()=>{try{await X()}catch{}u()})()},1e3))};return window.addEventListener("blur",T),window.addEventListener("focus",P),()=>{window.removeEventListener("blur",T),window.removeEventListener("focus",P),h&&clearTimeout(h)}},[x,I,X,u,f]);let b=Be(async l=>{console.debug("[crossx-kit] runConnect enter",{walletId:l,activeProvider:n,isConnected:I,activeConnectorId:N?.id});let h=K.getEntry(l);if(!h){if((l==="metamask"||l==="binance")&&!fe){console.error(`[crossx-kit] "${l}" 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: "${l}"`);return}if(v(l),h.providerKind!==n){console.debug("[crossx-kit] provider swap needed",{from:n,to:h.providerKind,walletId:l}),d(l);try{await X()}catch{}await new Promise(E=>setTimeout(E,0)),i(h.providerKind,l);return}let T=$(l);if(f({name:"wallet_selected",walletId:l,walletType:T}),f({name:"connect_started",walletId:l,walletType:T}),d(l),O?.beforeConnect)try{let E=await O.beforeConnect({kitConfig:D,themeMode:g},l);if(console.debug("[crossx-kit] beforeConnect result",{walletId:l,result:E}),E==="handled")return}catch(E){console.warn('[crossx-kit] adapter.beforeConnect threw for "%s":',l,E)}let P=a(h.connectorId);if(console.debug("[crossx-kit] findConnector",{lookupId:h.connectorId,found:P?.id,availableIds:j.map(E=>E.id)}),!P){console.error(`[crossx-kit] Connector "${h.connectorId}" not found on provider "${h.providerKind}". Available: ${j.map(E=>E.id).join(", ")}`),f({name:"connect_failed",walletId:l,reason:"connector_not_found"}),u();return}try{console.debug("[crossx-kit] connectAsync start",{connectorId:P.id});let E=await z({connector:P});console.debug("[crossx-kit] connectAsync resolved",{accountsLen:E.accounts.length,chainId:E.chainId});return}catch(E){let le=Go(E);if(!le){console.error('[crossx-kit] connectAsync error for "%s":',l,E);try{await X()}catch{}}if(!h.fallbackConnectorId){le||f({name:"connect_failed",walletId:l,reason:"connector_error"}),u();return}}if(h.fallbackConnectorId){let E=a(h.fallbackConnectorId);if(E)try{await z({connector:E})}catch(le){console.error('[crossx-kit] Fallback connect failed for "%s":',l,le);try{await X()}catch{}f({name:"connect_failed",walletId:l,reason:"fallback_failed"}),u()}else f({name:"connect_failed",walletId:l,reason:"fallback_failed"}),u()}},[K,j,a,z,X,d,u,O,n,D,i,g,f,$]);ie(()=>{if(!o)return;let l=o;c(),b(l)},[o,n]);let B=Be(async()=>{C(!0)},[]),_=Be(async()=>{f({name:"disconnected",walletId:Te.current});try{await X()}catch(l){console.error("[crossx-kit] wagmi disconnect error:",l)}if(O?.teardown)try{await O.teardown({kitConfig:D})}catch(l){console.error("[crossx-kit] adapter teardown error:",l)}pn(),u()},[X,O,D,u,f]),A=Be(async()=>{await mn(X(),3e3);try{let l=K.getEntry("cross_embedded"),h=l&&a(l.connectorId);if(h?.getProvider){let T=await Promise.race([h.getProvider(),new Promise(E=>setTimeout(E,3e3))]),P=T?.sdk?.signOut;typeof P=="function"&&await mn(P.call(T.sdk),3e3)}}catch{}pn()},[K,a,X]),L=Be(async()=>{let l=K.getEntry("cross_embedded");if(!l)return null;let h=a(l.connectorId);if(!h)return null;try{let T=await h.getProvider(),P=T?.sdk;if(!P?.selectWallet)return null;let E=await P.selectWallet(P.currentAddress??void 0);return E?.address&&T.notifyAccountsChanged&&T.notifyAccountsChanged([E.address]),E&&f({name:"wallet_switched",index:E.index}),E}catch{return null}},[K,a,f]),Z=Ne(()=>{let l=t.oauth;return l?{signIn:async h=>{v("cross_embedded"),f({name:"wallet_selected",walletId:"cross_embedded",walletType:"embedded"}),f({name:"connect_started",walletId:"cross_embedded",walletType:"embedded"});try{await l.signIn(h)}catch(T){throw f({name:"connect_cancelled",walletId:"cross_embedded",stage:"popup"}),v(null),T}}}:null},[t.oauth,f]),S=ke(!1);ie(()=>{if(n!=="cross"||I||V||G||x!=null||S.current)return;let l=K.getEntry("cross_embedded");if(!l)return;let h=a(l.connectorId);if(!h)return;S.current=!0;let T=!1;return(async()=>{try{let P=await h.isAuthorized?.();if(T||!P)return;await z({connector:h})}catch{}})(),()=>{T=!0}},[n,I,V,G,x,K,a,z]),ie(()=>{if(x!=="cross_embedded"||I||typeof window>"u")return;let l=!document.hasFocus(),h=()=>{l=!0};window.addEventListener("blur",h);let T=setTimeout(()=>{Ae.current||l||(console.warn("[crossx-kit] embedded sign-in stalled before the OAuth popup opened \u2014 clearing the stale session so a retry starts clean"),f({name:"connect_cancelled",walletId:"cross_embedded",stage:"stalled"}),u(),A())},Mo);return()=>{window.removeEventListener("blur",h),clearTimeout(T)}},[x,I,u,A,f]);let F=x!=null&&!I,q=Ne(()=>({kitConfig:D,connectorRegistry:K,availableWallets:Y,connect:b,connectWallet:B,disconnect:_,selectWallet:L,currentWallet:R,lastIntent:m,isConnecting:F,connectingWalletId:x,openOtherWallets:()=>C(!0),closeOtherWallets:()=>C(!1),otherWalletsOpen:w,oauth:Z,extraWallets:p,walletAllowlist:r,onRampEnabled:Ee}),[D,K,Y,b,B,_,L,R,m,F,x,w,Z,p,r,Ee]),U=gn(Ft.Provider,{value:q,children:[e,Qe(Wt,{open:w,onOpenChange:C})]});return et&&(U=Qe(Do,{config:et,children:U})),ye&&(U=Qe(Wo,{config:ye,children:U})),U}var Ho=[/Connection interrupted while trying to subscribe/i,/No matching key\. subscription:/i,/Proposal expired/i];function Vo(e){let t=e?.message;return typeof t!="string"?!1:Ho.some(n=>n.test(t))}var jo={};function Qo(e){return e&&{...e,connections:new Map,current:null}}function zo({children:e,config:t,initialState:n,extraWallets:i=jo,walletAllowlist:o}){let[c,g]=je(()=>Uo(t.activeProviderStorageKey,t.defaultProvider)),[y,p]=je(null),r=ke(!1),f=ke(null);f.current||(f.current=cn());let w=f.current,C=Ne(()=>({subscribe:w.subscribe}),[w]),{kitConfig:m}=t,[k,x]=je(null),[v,W]=je(null),[I,V]=je(0),G=Ne(()=>No(m.theme,m.autoDetectTheme),[m.theme,m.autoDetectTheme,I]),N=k??G,j=v??m.themeTokens;ie(()=>{if(!m.autoDetectTheme||k||typeof window>"u"||!window.matchMedia)return;let R=window.matchMedia("(prefers-color-scheme: dark)"),Y=()=>V($=>$+1);try{return R.addEventListener("change",Y),()=>R.removeEventListener("change",Y)}catch{return R.addListener(Y),()=>R.removeListener(Y)}},[m.autoDetectTheme,k]),ie(()=>{if(typeof document>"u")return;let R=document.documentElement,Y=R.getAttribute("data-ds-theme"),$=R.getAttribute("data-theme");return R.setAttribute("data-ds-theme",N),$||R.setAttribute("data-theme",N),()=>{Y==null?R.removeAttribute("data-ds-theme"):R.setAttribute("data-ds-theme",Y),$==null&&R.removeAttribute("data-theme")}},[N]);let z=Ne(()=>Fo(t.designSystem),[t.designSystem]),X=Ne(()=>({mode:N,tokens:j,setThemeMode:R=>x(R),setThemeTokens:R=>W(R)}),[N,j]);ie(()=>{if(typeof window>"u")return;let R=Y=>{Vo(Y.reason)&&Y.preventDefault()};return window.addEventListener("unhandledrejection",R),()=>window.removeEventListener("unhandledrejection",R)},[]);let D=Be((R,Y)=>{r.current||(r.current=!0,p(Y),g(R),$o(t.activeProviderStorageKey,R),queueMicrotask(()=>{r.current=!1}))},[t.activeProviderStorageKey]),K=Be(()=>p(null),[]),Pe=c==="cross"?t.crossWagmiConfig:t.reownWagmiConfig,fe=Qo(Eo(n,c));if(!Pe){if(!(c==="cross"?t.reownWagmiConfig:t.crossWagmiConfig))throw new Error("[crossx-kit] createCrossxConfig returned no wagmi Config for either side");let Y=c==="cross"?"reown":"cross";queueMicrotask(()=>g(Y))}let O=Pe??(c==="cross"?t.reownWagmiConfig:t.crossWagmiConfig);return Qe(kt.Provider,{value:C,children:gn(Ct.Provider,{value:X,children:[Qe("style",{"data-crossx-design-system":"",children:z}),Qe(xo,{config:O,initialState:fe,children:Qe(Bo,{client:Lo,children:Qe(qo,{config:t,activeProvider:c,onRequestProviderSwap:D,pendingConnectWalletId:y,clearPending:K,themeMode:N,themeTokens:j,extraWallets:i,walletAllowlist:o??t.kitConfig.wallets??null,emit:w.emit,children:e})})},c)]})})}import{useCallback as Ye,useEffect as es,useMemo as At}from"react";import{useQueryClient as ts}from"@tanstack/react-query";import{useAccount as ns,useChainId as os,useConfig as rs,useSendTransaction as ss,useSwitchChain as is}from"wagmi";import{getPublicClient as Ht,readContracts as Kn}from"wagmi/actions";import{WalletInfo as Vt,ConnectorId as Ze,resolveEnvironment as as}from"@nexus-cross/dapp-ui";import{useOptionalOnRamp as cs,useOptionalOnRampEligibility as ds}from"@nexus-cross/onramp/react";import{APPLE_ICON as Xt,BINANCE_ICON as qn,CROSSX_ICON as zt,EXTENSION_ICON as ls,GOOGLE_ICON as Hn,METAMASK_ICON as Vn}from"@nexus-cross/connect-kit-wagmi";import{WALLET_LABELS as Rt}from"@nexus-cross/crossx-design-system";import{useCallback as oe,useMemo as ve,useRef as Xo}from"react";import{useQueries as wn,useQuery as ze}from"@tanstack/react-query";import{encodeFunctionData as gt,formatUnits as Pt,parseSignature as Yo,parseUnits as Zo}from"viem";import{getChainId as Lt,getPublicClient as En,readContract as _e,signTypedData as Jo,switchChain as hn,waitForTransactionReceipt as er,writeContract as Cn}from"wagmi/actions";import{useConfig as tr}from"wagmi";async function Tt(e,t,n){if(!(!n||t===void 0))try{if(e.getChainId()===t)return;await e.switchChain(t)}catch{}}var lt=10000n;function yn(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 xt(e,t){let n=yn(t);return n>=lt?0n:e*(lt-n)/lt}function bn(e,t){let n=yn(t);return(e*(lt+n)+(lt-1n))/lt}function nr(e){return e!=="bridge"}var $e="0x0000000000000000000000000000000000000000",Se=100,pt=18,or=180000n,rr=250000n,On=new Set([56,97]),sr=130n,ir=100n,ar={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"},cr={dev:"dev",stage:"stg",production:"prod"};function dr(e,t){let n=e?.[cr[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 lr={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"},ur=["BSC_CROSS","W_CROSS","NATIVE_CROSS","USDTX","CROSSD","USDTB","SWAP_BRIDGE_ROUTER"],pr={BSC_CROSS:$e,W_CROSS:$e,NATIVE_CROSS:$e,USDTX:$e,CROSSD:$e,USDTB:$e,SWAP_BRIDGE_ROUTER:$e},mr=/^0x[0-9a-fA-F]{40}$/;function fr(e,t){let n=typeof e=="string"?e:e?.[t];return typeof n=="string"&&mr.test(n)?n:null}function gr(e,t){if(!e?.bridge)return null;let n=e.envToNetwork?.[t]??(t==="production"?"mainnet":"testnet"),i={};for(let o of ur){let c=fr(e.bridge[o],n);if(!c)return null;i[o]=c}return i}var yr={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"}]}],Mt=[{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"}]}],kn=[{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"}]}],Tn=[{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"}]}],br=[{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"}]}],Ke=[{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:[]}],wr=[{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 Nn(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 Fe(e,t){let n=await fetch(e,{cache:"no-store",signal:t});if(!n.ok)throw new Error(`CrossD bridge adapter request failed: ${await Nn(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 xn(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 Nn(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 hr(e){return new Promise(t=>setTimeout(t,e))}async function Cr(e,t,{attempts:n=60,intervalMs:i=2e3}={}){for(let o=0;o<n;o+=1){try{let c=await Fe(`${e}/permit-hash/${t}`);if(Ut(c))return c}catch{}await hr(i)}return null}function se(e,t){return`${e}-${t.toLowerCase()}`}function pe(e){return se(e.chainId,e.address)}function We(e){return e==="swap"||e==="deposit-swap"||e==="swap-withdraw"}function kr(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 In(e){return e===56||e===97?"BSC":e===612044||e===612055?"CROSS":`Chain ${e}`}function re(e,t){return t?t.toLowerCase()===e.contracts.NATIVE_CROSS.toLowerCase()?e.contracts.W_CROSS:t:$e}function st(e){let t=Pt(e,pt);return t.includes(".")?t.replace(/\.?0+$/,""):t}function bt(e){return Zo(e||"0",pt)}function ge(e){try{return bt(e||"0")}catch{return 0n}}function Xe(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 Gt(e){let t=Pt(e,9);return(t.includes(".")?t.replace(/\.?0+$/,""):t)||"0"}function It(e){return e==="bridge"?or:rr}function vn(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 g=c/1000000n,y=(c%1000000n).toString().padStart(6,"0").replace(/0+$/,"");return y?`${g}.${y}`:`${g}`}function Tr(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 Sn(e,t,n,i,o,c=!1){let g=En(e,{chainId:t}),y=n;try{let r=await g?.estimateContractGas?.({account:o.account,address:o.address,abi:o.abi,functionName:o.functionName,args:o.args,value:o.value});typeof r=="bigint"&&r>0n&&(y=i?r*sr/ir:r)}catch{}let p={gas:y};if(On.has(t))try{let r=await g?.getGasPrice?.();typeof r=="bigint"&&r>0n&&(p.gasPrice=r)}catch{}else if(c)try{let r=await g?.estimateFeesPerGas?.();typeof r?.maxFeePerGas=="bigint"&&(p.maxFeePerGas=r.maxFeePerGas),typeof r?.maxPriorityFeePerGas=="bigint"&&(p.maxPriorityFeePerGas=r.maxPriorityFeePerGas)}catch{}return p}function yt(){return BigInt(Math.floor(Date.now()/1e3)+1800)}var xr={100:"0.01%",500:"0.05%",3e3:"0.3%",1e4:"1%"};function Ir(e){return xr[e]??`${e/1e4}%`}function vr(e,t){let n=Number(e||"0");return!Number.isFinite(n)||n<=0?"0":(n*t/1e6).toFixed(8).replace(/\.?0+$/,"")}function Pn(e){return st(e)}function An(e,t){let n=Number(t??"0");return!Number.isFinite(n)||n<=0?0n:e*BigInt(Math.floor(n))/1000n}function vt(e,t){if(!e)return!1;let n=e.toLowerCase();return t.some(i=>i.toLowerCase()===n)}function Sr(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=>vt(t,o.from)&&vt(n,o.to)||vt(t,o.to)&&vt(n,o.from))}function Pr(e){if(We(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 Ar({input:e,path:t,config:n}){if(!n||We(t.type))return"";let i=Xe(n.minimumValue),o=Xe(n.gasFee??n.gas_fee),c=t.type==="swap-bridge"?i+o*12n/10n:i;return c<=0n?"":e.fromAmount&&ge(e.fromAmount)<c&&t.type!=="swap"?`Minimum ${Pn(c)}`:t.type==="swap-bridge"&&e.toAmount&&ge(e.toAmount)<c?`Available ${Pn(c)} or more.`:""}function Rr({input:e,path:t,config:n}){if(!n||t.type!=="bridge"&&t.type!=="bridge-swap")return"";let i=Xe(n.gasFee??n.gas_fee);if(i<=0n||!e.fromAmount)return"";let o=ge(e.fromToken.balance||"0"),c=ge(e.fromAmount);return o-i<c?`Insufficient network fee(${e.fromToken.symbol})`:""}function Br(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,g])=>{g.forEach(y=>{y.localToken&&n.add(se(o,y.localToken)),y.remoteToken&&n.add(se(Number(c),y.remoteToken))})})}),Object.entries(t?.swapPools||t?.swap_pools||{}).forEach(([i,o])=>{o.forEach(c=>{c.token0&&n.add(se(Number(i),c.token0)),c.token1&&n.add(se(Number(i),c.token1))})}),n}function _r(e,t){return!e||!t?null:se(e,t)}function Er({envConfig:e,bridgePairList:t,swapPools:n,tokenInfo:i,tokenStats:o}){let c=Br(t,n),g=new Map;o?.forEach(p=>{let r=_r(Number(p.chainId??p.chain_id),p.address);r&&g.set(r,p)});let y={};return c.forEach(p=>{let[r,f]=p.split("-"),w=Number(r),C=i?.find(k=>Number(k.chainId??k.chain_id)===w&&k.address?.toLowerCase()===f);if(!C?.symbol||!C.name)return;let m=g.get(p);y[p]={key:p,chainId:w,address:f,symbol:C.symbol,name:C.name,decimals:C.decimals||pt,image:C.image||C.icon_url,price:m?.price?Number(m.price):void 0,isNativeToken:f.toLowerCase()===e.contracts.NATIVE_CROSS.toLowerCase()}}),y}function Fn(e,t){return t?.list?.find(n=>(n.localChain??n.local_chain)===e)?.bridge||""}function Wn(e,t,n){let[i,o]=e.split("-"),[c,g]=t.split("-"),y=Number(i),p=Number(c);for(let r of n?.list||[]){if((r.localChain??r.local_chain)!==y)continue;let f=r.pairs?.[c];if(f){for(let w of f)if(w.localToken?.toLowerCase()===o&&w.remoteToken?.toLowerCase()===g)return{type:"bridge",fromChain:y,fromToken:o,toChain:p,toToken:g,bridgeAddress:Fn(y,n)}}}return null}function Dn(e,t,n,i){let o,c=1/0;for(let g of e||[]){let y=i(g.token0),p=i(g.token1);if(y===t&&p===n||p===t&&y===n){let r=g.fee??Se;r<c&&(o=g,c=r)}}return o?{fee:c,poolAddress:o.poolAddress||o.pool_address||""}:null}function Ln(e,t,n,i){let[o,c]=e.split("-"),[g,y]=t.split("-");if(o!==g)return null;let p=Number(o),r=(n?.swapPools||n?.swap_pools)?.[o];if(!r)return null;let f=i.contracts.W_CROSS.toLowerCase(),w=i.contracts.NATIVE_CROSS.toLowerCase(),m=Dn(r,c,y,x=>x?.toLowerCase()===f?w:x?.toLowerCase());if(!m)return null;let k="swap";return p===i.chainIds.cross&&(c===w&&(k="deposit-swap"),y===w&&(k="swap-withdraw")),{pathType:k,step:{type:"swap",chain:p,fromToken:c,toToken:y,fee:m.fee,poolAddress:m.poolAddress}}}function Or(e,t,n,i){let[o,c]=e.split("-"),[g]=t.split("-");if(o===g)return null;let y=(n?.swapPools||n?.swap_pools)?.[o]||[],p=r=>r?.toLowerCase();for(let r of y){let f=p(r.token0),w=p(r.token1),C=f===c?w:w===c?f:null;if(!C)continue;let m=Wn(se(Number(o),C),t,i);if(!m)continue;let k=Dn(y,c,C,p);return[{type:"swap",chain:Number(o),fromToken:c,toToken:C,fee:k?.fee??Se,poolAddress:k?.poolAddress??""},m]}return null}function Nr(e,t,n,i,o){let[c,g]=e.split("-"),[y]=t.split("-");if(c===y)return null;for(let p of n?.list||[])if((p.localChain??p.local_chain)===Number(c))for(let r of p.pairs?.[y]||[]){if(r.localToken?.toLowerCase()!==g)continue;let f=r.remoteToken?.toLowerCase();if(!f)continue;let w=Ln(se(Number(y),f),t,i,o);if(w)return[{type:"bridge",fromChain:Number(c),fromToken:g,toChain:Number(y),toToken:f,bridgeAddress:Fn(Number(c),n)},w.step]}return null}function Fr({envConfig:e,bridgePairList:t,swapPools:n,enrichedTokens:i}){return(o,c)=>{let g=i[o],y=i[c];if(!g||!y||o===c)return null;let p=Wn(o,c,t);if(p)return{type:"bridge",steps:[p],from:g,to:y};let r=Ln(o,c,n,e);if(r)return{type:r.pathType,steps:[r.step],from:g,to:y};let f=Or(o,c,n,t);if(f)return{type:"swap-bridge",steps:f,from:g,to:y};let w=Nr(o,c,t,n,e);return w?{type:"bridge-swap",steps:w,from:g,to:y}:null}}function Rn(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 Wr(e){return e.length<=10?e:`${e.slice(0,6)}...${e.slice(-4)}`}function Dr(e){return e.includes(".")?e.replace(/\.?0+$/,"")||"0":e}function Lr(e,t){let n=e.startsWith("-"),i=n?e.slice(1):e,[o,c=""]=i.split("."),g=c.slice(0,t).replace(/0+$/,""),y=g?`${o}.${g}`:o;return n?`-${y}`:y}function Mr(e){let t=e.startsWith("-"),n=t?e.slice(1):e,[i,o]=n.split("."),c=i.replace(/\B(?=(\d{3})+(?!\d))/g,","),g=o?`${c}.${o}`:c;return t?`-${g}`:g}function Kt(e){if(e==null||e==="")return"0";let t=String(e),n=Number(t);return!Number.isFinite(n)||n===0?"0":Mr(Lr(t,4))}function Bn(e,t){if(e==null||e==="")return"0";try{return Dr(Pt(BigInt(String(e)),t.decimals))}catch{return"0"}}function Ut(e){return!!(e&&/^0x[0-9a-fA-F]+$/.test(e))}function Gr(e){return e?new Date(e*1e3).toISOString():new Date().toISOString()}function Kr(e,t){return t.toLowerCase()===e.contracts.W_CROSS.toLowerCase()?e.contracts.NATIVE_CROSS:t}function Ur(e,t){let n=Wr(t);return{name:n,symbol:n,chainId:e,address:t,decimals:pt,balance:"0"}}function _n({envConfig:e,tokenByBridgeKey:t,chainId:n,address:i}){if(!i)return null;let o=Kr(e,i);return t.get(se(n,o))||t.get(se(n,i))||Ur(n,o)}function St(e){return e?.toLowerCase()||""}function $r(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 qr(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 Hr({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=$r(t),g=t.swapTokenIn??t.swap_token_in,y=t.swapTokenOut??t.swap_token_out,p=t.swapAmountIn??t.swap_amount_in,r=t.swapAmountOut??t.swap_amount_out,f=t.fromToken??t.from_token,w=t.toToken??t.to_token,C=t.value,m=t.value;c==="swap"?(f=g,w=y,C=p,m=r):c==="swap-bridge"?(f=g,C=p,m=t.value):c==="bridge-swap"&&(w=y,C=p,m=r);let k=_n({envConfig:e,tokenByBridgeKey:n,chainId:i,address:f}),x=_n({envConfig:e,tokenByBridgeKey:n,chainId:o,address:w}),v=t.initiatedTxHash??t.initiated_tx_hash;return!k||!x||!Ut(v)?null:{id:`${v}-${t.index??""}`,timestamp:Gr(t.initiatedTime??t.initiated_time),txHash:v,fromToken:k,toToken:x,fromAmount:Bn(C,k),toAmount:Bn(m,x),summary:{pathType:c},status:qr(t,c)}}function Vr(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",g=n.quantity?.decimals??n.decimals??pt;try{t.set(se(i,o),Pt(BigInt(c||"0"),g))}catch{t.set(se(i,o),"0")}}),t}function Ue(e,t="first"){let n=e.steps.filter(i=>i.type==="swap");return t==="last"?n[n.length-1]:n[0]}function jr(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(g=>{let y=g.token0?.toLowerCase(),p=g.token1?.toLowerCase();return y===i&&p===o||y===o&&p===i});return c?.poolAddress||c?.pool_address||""}function Qr(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 zr(e){if(e===void 0)return;let t=10n**BigInt(pt),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 ut(e,t,n,i){let o=[e.from,e.to].find(c=>c.chainId===t&&c.address.toLowerCase()===n.toLowerCase())??i?.[se(t,n)];return{symbol:o?.symbol||n.slice(0,6),iconUrl:o?.image}}function Xr(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=>ut(e,o.chain,o.address,t))}function Yr({input:e,path:t,amountData:n,gasInfo:i,liquidity:o,enrichedTokens:c,priceImpact:g}){let y=e.fromAmount||"0",p=e.toAmount||"0",r=Ue(t),f=t.steps.find(V=>V.type==="bridge"),w=t.type!=="bridge",C=!We(t.type),m=r?vr(y,r.fee):"0",k=Number(y)>0||Number(p)>0,x=r?ut(t,r.chain,r.fromToken,c):{symbol:e.fromToken.symbol,iconUrl:e.fromToken.iconUrl},v=r?ut(t,r.chain,r.toToken,c):{symbol:e.toToken.symbol,iconUrl:e.toToken.iconUrl},W=f?ut(t,f.fromChain,f.fromToken,c):void 0,I=(V,G,N)=>k?G&&G>0n?{label:V,value:st(G),tone:"default",valueToken:N}:{label:V,value:"Free",tone:"accent"}:{label:V,value:"0"};return{pathType:t.type,priceImpact:g,liquidity:o,bridgeInfo:C&&f?[{label:"Route",value:`${In(f.fromChain)} \u2192 ${In(f.toChain)}`},I("Validator Fee",n?.exFee,W),I("Network Fee",n?.networkFee,W)]:void 0,swapInfo:w&&r?[{label:"Route",value:"",routeTokens:[ut(t,r.chain,r.fromToken,c),ut(t,r.chain,r.toToken,c)]},{label:"Price Impact",value:Tr(g)},{label:"In Amount",value:Kt(y),valueToken:x},{label:r&&We(t.type)?`Swap Fee (${Ir(r.fee??Se)})`:"Swap Fee",value:Kt(m),valueToken:x},{label:"Out Amount",value:Kt(p),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 $t({env:e,walletAddress:t,enabled:n=!0,restoreChainAfterSwitch:i=!0}){let o=tr(),c=Xo(new Map),y=ze({queryKey:["crossd-bridge-adapter",e,"remote-contracts"],queryFn:async({signal:s})=>{let a=gr(await Fe(lr[e],s),e);if(!a)throw new Error("CrossD bridge adapter: invalid contracts.json");return a},enabled:n,staleTime:5*6e4}).data??null,p=n&&!!y,r=ve(()=>({...yr[e],contracts:y??pr}),[e,y]),f=ze({queryKey:["crossd-bridge-adapter",e,"pairs"],queryFn:({signal:s})=>Fe(`${r.bridgeApi}/pairs`,s),enabled:p,staleTime:3e4}),w=ze({queryKey:["crossd-bridge-adapter",e,"swap-pools"],queryFn:({signal:s})=>Fe(`${r.bridgeApi}/swap-pools`,s),enabled:p,staleTime:3e4}),C=ve(()=>jr(w.data,r),[r,w.data]),m=ze({queryKey:["crossd-bridge-adapter",e,"available-liquidity",C],queryFn:async()=>await _e(o,{address:r.contracts.USDTX,abi:Mt,functionName:"balanceOf",args:[C],chainId:r.chainIds.cross}),enabled:p&&!!C,staleTime:3e4}),k=ze({queryKey:["crossd-bridge-adapter",e,"token-info"],queryFn:({signal:s})=>Fe(`${r.walletApi}/v1/public/token/info`,s),enabled:p,staleTime:3e4}),x=ze({queryKey:["crossd-bridge-adapter",e,"token-stats"],queryFn:({signal:s})=>Fe(`${r.walletApi}/v1/public/token/stats`,s),enabled:p,staleTime:3e4}),v=wn({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 Fe(`${r.walletApi}/v1/public/token/balance?${d}`,a)},enabled:p&&!!t,staleTime:0,refetchInterval:p&&t?5e3:!1}))}),W=wn({queries:[r.chainIds.cross,r.chainIds.bsc].map(s=>({queryKey:["crossd-bridge-adapter",e,"gas-suggestion",s],queryFn:async({signal:a})=>{try{let b=await En(o,{chainId:s})?.estimateFeesPerGas?.();if(b?.maxFeePerGas||b?.gasPrice)return{fast:{maxFee:b.maxFeePerGas?.toString()||b.gasPrice?.toString(),maxPriorityFee:b.maxPriorityFeePerGas?.toString()||"0"}}}catch{}let d=new URLSearchParams({chain_id:String(s),without_gas_limit:"false"});return Fe(`${r.walletApi}/v1/public/transaction/gas-suggestion/dynamic?${d}`,a)},enabled:p,staleTime:1e4,retry:1}))}),I=ze({queryKey:["crossd-bridge-adapter",e,"hidden-pairs"],queryFn:async({signal:s})=>dr(await Fe(ar[e],s),e),enabled:p,staleTime:5*6e4,retry:1}),V=ve(()=>I.data??[],[I.data]),G=ve(()=>Er({envConfig:r,bridgePairList:f.data,swapPools:w.data,tokenInfo:k.data,tokenStats:x.data}),[f.data,r,w.data,k.data,x.data]),N=ve(()=>Fr({envConfig:r,bridgePairList:f.data,swapPools:w.data,enrichedTokens:G}),[f.data,G,r,w.data]),j=ve(()=>Vr(v.map(s=>s.data).filter(s=>Array.isArray(s))),[v]),z=ve(()=>{let s=new Map;return Object.values(G).forEach(a=>{let d=Rn(a,j);s.set(a.key,d)}),s},[j,G]),X=ve(()=>{let s=new Map,a=z.get(se(r.chainIds.cross,r.contracts.NATIVE_CROSS));a&&s.set(r.chainIds.cross,{symbol:a.symbol,iconUrl:a.iconUrl});let d=k.data?.find(u=>Number(u.chainId??u.chain_id)===r.chainIds.bsc&&(u.symbol??"").toUpperCase()==="BNB");return d&&s.set(r.chainIds.bsc,{symbol:d.symbol??"BNB",iconUrl:d.image??d.icon_url}),s},[r,z,k.data]),D=ze({queryKey:["crossd-bridge-adapter",e,"history",t],queryFn:({signal:s})=>xn(`${r.bridgeApi}/history`,{owner:t,page:1,size:20,sort:"desc",status:"all"},s),enabled:p&&!!t,staleTime:0,refetchInterval:p&&t?5e3:!1}),K=ve(()=>(D.data?.histories||[]).map(s=>Hr({envConfig:r,item:s,tokenByBridgeKey:z})).filter(s=>!!s),[D.data?.histories,r,z]),Pe=ve(()=>zr(m.data),[m.data]),fe=W[0]?.data,O=W[1]?.data,R=ve(()=>{let s=new Map;return fe&&s.set(r.chainIds.cross,fe),O&&s.set(r.chainIds.bsc,O),s},[O,fe,r.chainIds.bsc,r.chainIds.cross]),Y=oe((s,a,d)=>{let u=R.get(s.from.chainId)?.fast,b=a?d?.gasLimit??It(s.type):0n,B=d?.gasPrice&&d.gasPrice>0n?d.gasPrice:0n,_=d?.maxFeePerGas&&d.maxFeePerGas>0n?d.maxFeePerGas:0n,A=d?.maxPriorityFeePerGas&&d.maxPriorityFeePerGas>0n?d.maxPriorityFeePerGas:0n,L=Xe(u?.maxFee??u?.max_fee),Z=Xe(u?.maxPriorityFee??u?.max_priority_fee),S=_>0n?_:L>0n?L:B,F=A>0n?A:Z>0n?Z:S,q=B>0n?B:S,Q=On.has(s.from.chainId)&&q>0n,l=b*(Q?q:S),h=z.get(se(s.from.chainId,r.contracts.NATIVE_CROSS)),T=s.type!=="swap-bridge",P=X.get(s.from.chainId);return{estTxFee:a?st(l):"0",priorityFeePerGas:a&&!Q?Gt(F):"0",maxFeePerGas:a&&!Q?Gt(S):"0",gasLimit:a?b.toString():"0",gasPrice:a&&Q?Gt(q):void 0,isDelegateFee:s.type==="swap-bridge"?!1:Sr(r,s.from.address,s.to.address),tokenIconUrl:T?h?.iconUrl:void 0,tokenSymbol:T?h?.symbol:void 0,gasCurrencyIconUrl:P?.iconUrl,gasCurrencySymbol:P?.symbol}},[r,R,X,z]),$=oe(async s=>{let a=Pr(s);if(!a)return null;let d=`${e}:${a.from}:${a.to}:${a.token.toLowerCase()}`,u=c.current.get(d);if(u)return u;let b=(async()=>{let B=new URLSearchParams({from:String(a.from),to:String(a.to),token:a.token});try{return(await Fe(`${r.bridgeApi}/token-config?${B}`)).config??null}catch{return null}})();return c.current.set(d,b),b},[e,r.bridgeApi]),ce=ve(()=>{let s=Object.values(G).map(d=>Rn(d,j)),a=se(r.chainIds.cross,r.contracts.CROSSD);return s.sort((d,u)=>{let b=pe(d).toLowerCase()===a.toLowerCase(),B=pe(u).toLowerCase()===a.toLowerCase();return b!==B?b?-1:1:pe(d).localeCompare(pe(u))})},[j,G,r]),Te=oe(s=>{let a=pe(s),d=a.toLowerCase(),u=[];Object.keys(G).forEach(_=>{let A=_.toLowerCase();if(d===A||V.some(S=>S.fromKey===d&&S.toKey===A))return;let L=N(a,_);if(!L)return;let Z=z.get(_);Z&&u.push({token:Z,path:L})});let b=se(r.chainIds.cross,r.contracts.CROSSD),B=se(r.chainIds.cross,r.contracts.NATIVE_CROSS);return u.sort((_,A)=>{if(d===b.toLowerCase()){let q=pe(_.token).toLowerCase()===B.toLowerCase(),Q=pe(A.token).toLowerCase()===B.toLowerCase();if(q!==Q)return q?-1:1}let L=We(_.path.type),Z=We(A.path.type);if(L!==Z)return L?-1:1;let S=_.token.chainId===s.chainId,F=A.token.chainId===s.chainId;return S!==F?S?-1:1:pe(_.token).localeCompare(pe(A.token))}),u.map(_=>_.token)},[G,r,N,V,z]),Le=oe(async s=>await _e(o,{address:r.contracts.SWAP_BRIDGE_ROUTER,abi:rt,functionName:"quoter",chainId:s}),[r.contracts.SWAP_BRIDGE_ROUTER,o]),xe=oe(async s=>{Lt(o)!==s&&await hn(o,{chainId:s})},[o]),Ee=oe(s=>Tt({getChainId:()=>Lt(o),switchChain:a=>hn(o,{chainId:a})},s,i),[i,o]),ye=oe(async s=>await _e(o,{address:r.contracts.SWAP_BRIDGE_ROUTER,abi:rt,functionName:"swapRouter",chainId:s}),[r.contracts.SWAP_BRIDGE_ROUTER,o]),Me=oe(async({path:s,step:a,amount:d,source:u})=>{let b=await Le(a.chain),B=a.poolAddress?_e(o,{address:a.poolAddress,abi:br,functionName:"slot0",chainId:a.chain}).then(L=>L?.[0]).catch(()=>{}):Promise.resolve(void 0);if(u==="from"){let L=await _e(o,{address:b,abi:Tn,functionName:"quoteExactInputSingle",args:[{tokenIn:re(r,a.fromToken),tokenOut:re(r,a.toToken),amountIn:bt(d),fee:a.fee??Se,sqrtPriceLimitX96:0n}],chainId:a.chain}),Z=vn(await B,L[1]);return{amount:st(L[0]),path:s,priceImpact:Z}}let _=await _e(o,{address:b,abi:Tn,functionName:"quoteExactOutputSingle",args:[{tokenIn:re(r,a.fromToken),tokenOut:re(r,a.toToken),amount:bt(d),fee:a.fee??Se,sqrtPriceLimitX96:0n}],chainId:a.chain}),A=vn(await B,_[1]);return{amount:st(_[0]),path:s,priceImpact:A}},[r,Le,o]),de=oe(async(s,a)=>{if(!t)throw new Error("Wallet is not connected.");let d=It(a.type);if(We(a.type)){let S=Ue(a,"first");if(!S)throw new Error("Swap route is not available.");let F=ge(s.fromAmount),q=ge(s.toAmount);if(F<=0n)throw new Error("Bridge amount is empty.");if(q<=0n)throw new Error("Bridge quote is not ready.");let Q=await ye(S.chain),U=xt(q,s.slippage),l=a.type==="swap-withdraw"?$e:t,h={tokenIn:re(r,S.fromToken),tokenOut:re(r,S.toToken),fee:S.fee??Se,recipient:l,deadline:yt(),amountIn:F,amountOutMinimum:U,sqrtPriceLimitX96:0n};if(a.type==="swap-withdraw"){let T=gt({abi:Ke,functionName:"exactInputSingle",args:[h]}),P=gt({abi:Ke,functionName:"unwrapWETH9",args:[U,t]});return{address:Q,abi:Ke,functionName:"multicall",args:[[T,P]],chainId:S.chain,fallbackGasLimit:d}}if(a.type==="deposit-swap"){let T=gt({abi:Ke,functionName:"exactInputSingle",args:[h]}),P=gt({abi:Ke,functionName:"refundETH",args:[]});return{address:Q,abi:Ke,functionName:"multicall",args:[[T,P]],value:F,chainId:S.chain,fallbackGasLimit:d}}return{address:Q,abi:Ke,functionName:"exactInputSingle",args:[h],chainId:S.chain,fallbackGasLimit:d}}if(a.type==="swap-bridge"){let S=Ue(a,"first");if(!S)throw new Error("Swap bridge route is not available.");let F=ge(s.fromAmount),q=ge(s.toAmount);if(F<=0n)throw new Error("Bridge amount is empty.");if(q<=0n)throw new Error("Bridge quote is not ready.");let Q=r.contracts.SWAP_BRIDGE_ROUTER,U=yt(),l={toChainID:BigInt(a.to.chainId),recipient:t,extraData:"0x"},h={tokenIn:re(r,a.from.address),tokenOut:re(r,S.toToken),fee:S.fee??Se,sqrtPriceLimitX96:0n,bridgeParams:l};if(s.lastChangedBy==="to"){let P={...h,amountOut:q,amountInMaximum:bn(F,s.slippage)};return{address:Q,abi:rt,functionName:"swapBridgeExactOutputSingle",args:[P,U],value:a.from.isNativeToken?P.amountInMaximum:void 0,chainId:a.from.chainId,fallbackGasLimit:d}}let T={...h,amountIn:F,amountOutMinimum:xt(q,s.slippage)};return{address:Q,abi:rt,functionName:"swapBridgeExactInputSingle",args:[T,U],value:a.from.isNativeToken?F:void 0,chainId:a.from.chainId,fallbackGasLimit:d}}let u=a.steps.find(S=>S.type==="bridge");if(!u?.bridgeAddress)throw new Error("Bridge route is not available.");let b=ge(s.fromAmount);if(b<=0n)throw new Error("Bridge amount is empty.");let B=await $(a),_=Xe(B?.gasFee??B?.gas_fee),A=An(b,B?.exFeeRate??B?.ex_fee_rate),L="0x";if(a.type==="bridge-swap"){let S=Ue(a,"last");if(!S)throw new Error("Bridge swap route is not available.");let F=ge(s.toAmount);if(F<=0n)throw new Error("Bridge quote is not ready.");let q=await ye(a.to.chainId),Q=xt(F,s.slippage),U=gt({abi:Ke,functionName:"exactInputSingle",args:[{tokenIn:re(r,S.fromToken),tokenOut:re(r,S.toToken),fee:S.fee??Se,recipient:t,deadline:yt(),amountIn:b,amountOutMinimum:Q,sqrtPriceLimitX96:0n}]});L=`${q}${U.slice(2)}`}let Z=[BigInt(a.to.chainId),a.from.address,t,b,_,A,L];return{address:u.bridgeAddress,abi:wr,functionName:"bridgeToken",args:Z,value:a.from.isNativeToken?b+A+_:void 0,chainId:a.from.chainId,fallbackGasLimit:d}},[r,$,ye,t]),Je=oe(async(s,a)=>{if(a.type==="bridge"||a.type==="bridge-swap")return de(s,a);if(!t)throw new Error("Wallet is not connected.");let d=ge(s.fromAmount);if(d<=0n)throw new Error("Bridge amount is empty.");if(a.type==="swap-bridge"){let _=Ue(a,"first");if(!_)throw new Error("Swap bridge route is not available.");let A=r.contracts.SWAP_BRIDGE_ROUTER,L={tokenIn:re(r,a.from.address),tokenOut:re(r,_.toToken),fee:_.fee??Se,sqrtPriceLimitX96:0n,bridgeParams:{toChainID:BigInt(a.to.chainId),recipient:t,extraData:"0x"},amountIn:d,amountOutMinimum:0n};return{address:A,abi:rt,functionName:"swapBridgeExactInputSingle",args:[L,yt()],value:a.from.isNativeToken?d:void 0,chainId:a.from.chainId,fallbackGasLimit:It(a.type)}}let u=Ue(a,"first");if(!u)throw new Error("Swap route is not available.");let b=await ye(u.chain),B={tokenIn:re(r,u.fromToken),tokenOut:re(r,u.toToken),fee:u.fee??Se,recipient:t,deadline:yt(),amountIn:d,amountOutMinimum:0n,sqrtPriceLimitX96:0n};return{address:b,abi:Ke,functionName:"exactInputSingle",args:[B],value:a.from.isNativeToken?d:void 0,chainId:u.chain,fallbackGasLimit:It(a.type)}},[de,r,ye,t]),et=oe(async(s,a)=>{if(!t)return null;try{let d=await Je(s,a),u=We(a.type)||a.type==="swap-bridge",b=await Sn(o,d.chainId,d.fallbackGasLimit,u,{account:t,address:d.address,abi:d.abi,functionName:d.functionName,args:d.args,value:d.value},!0);return{gasLimit:b.gas,gasPrice:b.gasPrice,maxFeePerGas:b.maxFeePerGas,maxPriorityFeePerGas:b.maxPriorityFeePerGas}}catch{return null}},[Je,o,t]),Ae=oe(async s=>{let a=pe(s.fromToken),d=pe(s.toToken),u=N(a,d);if(!u)return{error:"Route is not available."};let b=s.lastChangedBy==="to"?s.toAmount:s.fromAmount,B=!!b&&Number(b)>0,_=Qr(u,r)?Pe:void 0,A=async(U,l,h)=>{let T=B?await et(U,u):null,P=Y(u,B,T);return Yr({input:U,path:u,gasInfo:P,amountData:l,liquidity:_,enrichedTokens:G,priceImpact:h})};if(!b||Number(b)<=0)return{fromAmount:s.fromAmount,toAmount:s.toAmount,summary:await A(s)};let L=await $(u),Z=Xe(L?.gasFee??L?.gas_fee),S=u.type==="bridge"||u.type==="bridge-swap"?{networkFee:Z}:void 0,F=u.type==="bridge"?s.lastChangedBy==="to"?{...s,fromAmount:s.toAmount}:{...s,toAmount:s.fromAmount}:s,q=Ar({input:F,path:u,config:L});if(q)return{fromAmount:F.fromAmount,toAmount:F.toAmount,summary:await A(F,S),error:q};let Q=Rr({input:F,path:u,config:L});if(Q)return{fromAmount:F.fromAmount,toAmount:F.toAmount,summary:await A(F,S),error:Q};if(u.type==="bridge")return{fromAmount:F.fromAmount,toAmount:F.toAmount,summary:await A(F,S)};try{if(u.type==="swap-bridge"){let T=Ue(u,"first"),P=r.contracts.SWAP_BRIDGE_ROUTER;if(!T)return{error:"Swap bridge route is not ready."};let E=Oe=>Me({path:u,step:T,amount:Oe,source:"from"}).then(Ve=>Ve.priceImpact).catch(()=>{});if(s.lastChangedBy==="from"){let Oe=await _e(o,{address:P,abi:rt,functionName:"getAmountSwapBridgeOut",args:[BigInt(u.to.chainId),re(r,u.from.address),re(r,T.toToken),T.fee??Se,bt(s.fromAmount)],chainId:u.from.chainId}),Ve=st(Oe[1]),_t={...s,toAmount:Ve};return{toAmount:Ve,summary:await A(_t,{networkFee:Oe[3],exFee:Oe[4]},await E(s.fromAmount))}}let le=await _e(o,{address:P,abi:rt,functionName:"getAmountSwapBridgeIn",args:[BigInt(u.to.chainId),re(r,u.from.address),re(r,T.toToken),T.fee??Se,bt(s.toAmount)],chainId:u.from.chainId}),He=st(le[1]),nt={...s,fromAmount:He};return{fromAmount:He,summary:await A(nt,{networkFee:le[3],exFee:le[4]},await E(He))}}let U=u.type==="bridge-swap"?Ue(u,"last"):Ue(u,"first");if(!U)return{error:"Swap route is not available."};let l=await Me({path:u,step:U,amount:b,source:s.lastChangedBy});if(s.lastChangedBy==="from"){let T={...s,toAmount:l.amount};return{toAmount:l.amount,summary:await A(T,S,l.priceImpact)}}let h={...s,fromAmount:l.amount};return{fromAmount:l.amount,summary:await A(h,S,l.priceImpact)}}catch(U){return{fromAmount:s.fromAmount,toAmount:s.toAmount,summary:await A(s,S),error:kr(U)}}},[Pe,Y,G,r,et,N,$,Me,o]),tt=oe(async s=>{if(s.from.isNativeToken)return null;if(s.type==="swap"||s.type==="deposit-swap"||s.type==="swap-withdraw")return ye(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,ye]),ct=oe(async s=>{if(!t)throw new Error("Wallet is not connected.");let a=pe(s.fromToken),d=pe(s.toToken),u=N(a,d);if(!u)throw new Error("Route is not available.");if(!We(u.type)&&u.type!=="swap-bridge"||u.from.isNativeToken)return null;let b=ge(s.fromAmount);if(b<=0n)return null;let B=await tt(u);return!B||await _e(o,{address:u.from.address,abi:Mt,functionName:"allowance",args:[t,B],chainId:u.from.chainId})>=b?null:{token:s.fromToken,tokenAddress:u.from.address,spenderAddress:B,amount:s.fromAmount}},[N,tt,o,t]),Re=oe(async(s,a)=>{let d=ge(a.amount||s.fromAmount);if(d<=0n)throw new Error("Approval amount is empty.");await xe(a.token.chainId);let u=await Cn(o,{address:a.tokenAddress,abi:Mt,functionName:"approve",args:[a.spenderAddress,d],chainId:a.token.chainId});await er(o,{hash:u,chainId:a.token.chainId})},[xe,o]),be=oe(async(s,a)=>{let d=await de(s,a);await xe(d.chainId);let u=await Sn(o,d.chainId,d.fallbackGasLimit,nr(a.type),{account:t,address:d.address,abi:d.abi,functionName:d.functionName,args:d.args,value:d.value});return{txHash:await Cn(o,{address:d.address,abi:d.abi,functionName:d.functionName,args:d.args,value:d.value,chainId:d.chainId,...u}),fromToken:s.fromToken,toToken:s.toToken,fromAmount:s.fromAmount,toAmount:s.toAmount}},[de,xe,o,t]),we=oe(async(s,a)=>{let d=t;if(!d)throw new Error("Wallet is not connected.");let u=a.steps.find(Ve=>Ve.type==="bridge");if(!u?.bridgeAddress)throw new Error("Bridge route is not available.");let b=a.from.address,B=a.from.chainId,_=ge(s.fromAmount);if(_<=0n)throw new Error("Bridge amount is empty.");let A=await $(a),L=Xe(A?.gasFee??A?.gas_fee),Z=An(_,A?.exFeeRate??A?.ex_fee_rate),S=_+Z+L,[F,q]=await Promise.all([_e(o,{address:b,abi:kn,functionName:"name",chainId:B}),_e(o,{address:b,abi:kn,functionName:"nonces",args:[d],chainId:B})]),Q=BigInt(Math.floor(Date.now()/1e3)+300),U=await Jo(o,{domain:{name:F,version:"1",chainId:B,verifyingContract:b},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:u.bridgeAddress,value:S,nonce:q,deadline:Q}}),{r:l,s:h,v:T,yParity:P}=Yo(U),E=T!==void 0?Number(T):P+27,le={exFee:Z.toString(),from:B,fromToken:b,nonce:Number(q),gasFee:L.toString(),permitArgs:{account:d,deadline:Q.toString(),r:l,s:h,token:b,v:E,value:S.toString()},to:d,toChainID:String(a.to.chainId),value:S.toString()},He=await xn(`${r.bridgeApi}/permit`,le),nt=He?.requestId??He?.request_id;if(!nt)throw new Error("Bridge permit request failed.");let Oe=await Cr(r.bridgeApi,nt);if(!Ut(Oe))throw new Error("Bridge submitted, but confirmation timed out. Check History shortly.");return{txHash:Oe,fromToken:s.fromToken,toToken:s.toToken,fromAmount:s.fromAmount,toAmount:s.toAmount}},[r,$,o,t]),qe=oe(async s=>{let a=Lt(o),d=pe(s.fromToken),u=pe(s.toToken),b=N(d,u);if(!b)throw new Error("Route is not available.");if(!(We(b.type)||b.type==="swap-bridge"||b.type==="bridge-swap"||b.type==="bridge"))throw new Error("This bridge route is not supported yet.");let A=b.type==="bridge"&&b.from.chainId===r.chainIds.bsc&&b.from.address.toLowerCase()===r.contracts.BSC_CROSS.toLowerCase()?await we(s,b):await be(s,b);return await Ee(a),{...A,pathType:b.type,routeTokens:Xr(b,G)}},[G,r,N,Ee,we,be,o]);return{bridgeTokens:ce,bridgeHistory:K,getBridgeApproval:ct,approveBridge:Re,getBridgeQuote:Ae,getBridgeToTokens:Te,submitBridge:qe,isLoading:f.isLoading||w.isLoading||k.isLoading||x.isLoading||v.some(s=>s.isLoading)}}import{useEffect as Mn,useRef as Zr,useState as Gn}from"react";import{useAccount as Jr}from"wagmi";function qt(e){let{address:t,connector:n}=Jr(),{currentWallet:i}=Ge(),o=e?.walletId!==void 0?e.walletId:i,c=e?.connector!==void 0?e.connector:n,g=e?.address!==void 0?e.address:t,[y,p]=Gn({loginType:null,accountName:null,accounts:[],isResolved:!1}),r=Zr(new Map),[f,w]=Gn(0);return Mn(()=>{let C=!1;if(o!=="cross_embedded")return p({loginType:null,accountName:null,accounts:[],isResolved:!0}),()=>{C=!0};if(!c)return p({loginType:null,accountName:null,accounts:[],isResolved:!1}),()=>{C=!0};p(v=>({...v,isResolved:!1}));let m=20,k=300,x=async()=>{if(typeof c.getProvider!="function")return"retry";let v;try{v=await c.getProvider()}catch{return"retry"}let W=v?.sdk;if(!W)return"giveup";try{let O=W.getRNBridgeActiveWallet?.(),R=O?.walletName?.trim();O&&R&&r.current.set(O.address.toLowerCase(),R)}catch{}let[I,V]=await Promise.all([W.getUserInfo?.().catch(()=>null)??null,W.getAddresses?.().catch(()=>null)??null]);if(C)return"done";let G=I?.loginType,N=G==="google"||G==="apple"?G:null;if(!N)return"retry";let j=g?.toLowerCase(),z=j&&Array.isArray(V)?V.find(O=>O.address.toLowerCase()===j):null,X=Array.isArray(V)?V.filter(O=>/^0x[a-fA-F0-9]{40}$/.test(O.address)).map(O=>({address:O.address.toLowerCase(),...Number.isFinite(O.index)?{index:O.index}:{},...O.name?.trim()?{name:O.name.trim()}:{}})):[],D=j?r.current.get(j)?.trim():void 0,K=!z&&j&&/^0x[a-fA-F0-9]{40}$/.test(j)?[...X,{address:j,index:X.length,...D?{name:D}:{}}]:X,fe=D||z?.name?.trim()||(typeof z?.index=="number"?`Account ${z.index+1}`:g?`${g.slice(0,6)}\u2026${g.slice(-4)}`:null);return p({loginType:N,accountName:fe,accounts:K,isResolved:!0}),"done"};return(async()=>{for(let v=0;v<m;v++){if(C)return;let W=await x();if(W==="done")return;if(W==="giveup"){C||p({loginType:null,accountName:null,accounts:[],isResolved:!0});return}await new Promise(I=>setTimeout(I,k))}C||p({loginType:null,accountName:null,accounts:[],isResolved:!0})})(),()=>{C=!0}},[o,c,g,f]),Mn(()=>{if(o!=="cross_embedded"||!c||typeof c.getProvider!="function")return;let C=!1,m;return(async()=>{let k;try{k=await c.getProvider()}catch{return}if(C)return;let x=k?.sdk;x?.on&&(m=x.on("addressChanged",({address:v,walletName:W})=>{let I=W?.trim();I&&(r.current.set(v.toLowerCase(),I),w(V=>V+1))}))})(),()=>{C=!0,m?.()}},[o,c]),y}import{Fragment as $n,jsx as me,jsxs as it}from"react/jsx-runtime";var us=[{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"}]}],ps=[{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"}]}],ms={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"}},jt=10n**18n,fs={google:{name:"Google",iconUrl:Hn,connectorId:Ze.CROSSx},apple:{name:"Apple",iconUrl:Xt,connectorId:Ze.CROSSx},cross:{name:Rt.default,iconUrl:zt,connectorId:Ze.CROSSx},metamask:{name:"MetaMask",iconUrl:Vn,connectorId:Ze.MetaMask},binance:{name:"Binance Wallet",iconUrl:qn,connectorId:Ze.Binance}};function gs(e){switch(e){case"cross_embedded":return Ze.CROSSx;case"metamask":return Ze.MetaMask;case"binance":return Ze.Binance;default:return}}function ys(e,t){switch(e){case"cross_embedded":return t==="google"?{name:"Google",iconUrl:Hn}:t==="apple"?{name:"Apple",iconUrl:Xt}:{name:Rt.default,iconUrl:zt};case"cross_wallet":return{name:Rt.default,iconUrl:zt};case"cross_extension":return{name:Rt.extension,iconUrl:ls};case"metamask":return{name:"MetaMask",iconUrl:Vn};case"binance":return{name:"Binance Wallet",iconUrl:qn};default:return null}}function bs({label:e="Connect Wallet",className:t,style:n,walletInfoStyle:i,user:o,enablePortfolio:c,portfolio:g,theme:y,accountName:p,connectorId:r,showPortfolio:f,sendAccounts:w,getTransactionReceipt:C,sendTransaction:m,estimateGas:k,onDisconnect:x,onSelectWallet:v,onBuy:W,onRampRedirectUrl:I,bridgeTokens:V,bridgeHistory:G,getBridgeQuote:N,getBridgeToTokens:j,getBridgeApproval:z,approveBridge:X,submitBridge:D,showBalance:K=!0,env:Pe,...fe}){let{address:O,isConnected:R,connector:Y,chain:$}=ns(),ce=rs(),Te=os(),{switchChainAsync:Le}=is(),{sendTransactionAsync:xe}=ss(),{connectWallet:Ee,disconnect:ye,selectWallet:Me,currentWallet:de,isConnecting:Je,kitConfig:et}=Ge(),Ae=et?.restoreChainAfterSwitch!==!1,tt=ft(),ct=y??tt?.mode??"dark",Re=At(()=>as(Pe),[Pe]),be=o?.address??O,we=o?fs[o.provider]:null,{loginType:qe,accountName:s,accounts:a}=qt({walletId:de,connector:Y,address:be}),d=At(()=>we?{name:we.name,iconUrl:we.iconUrl}:ys(de,qe),[we,de,qe]),u=p??o?.name??s??void 0,b=we?we.connectorId:gs(de),B=r??b,_=g??f??!!c,A=$t({env:Re,walletAddress:be,enabled:R&&!!be&&K,restoreChainAfterSwitch:Ae}),L=V??A.bridgeTokens,Z=G??A.bridgeHistory,S=N??A.getBridgeQuote,F=j??A.getBridgeToTokens,q=z??A.getBridgeApproval,Q=X??A.approveBridge,U=D??A.submitBridge,l=Ye(()=>{Ee().catch(M=>{console.error("[crossx-kit] connectWallet error:",M)})},[Ee]),h=Ye(()=>{ye()},[ye]),T=x??h,P=cs(),{eligibility:E}=ds({network:$?String($.id):void 0}),le=E?.allowed===!0,He=At(()=>{if(W)return W;if(!(!P||!$||!le))return()=>P.open({crypto:$.nativeCurrency?.symbol??"USDT",network:String($.id),...I?{redirectUrl:I}:{}}).then(()=>{}).catch(M=>{throw console.warn("[crossx-kit] onramp open failed:",M),M})},[W,P,$,le,I]),nt=ts();es(()=>{if(P?.onStatus)return P.onStatus(()=>{nt.invalidateQueries()})},[P,nt]);let Oe=At(()=>{if(!W&&!(!P||!$)&&!le)return"On-ramp is not available in your region."},[W,P,$,le]),Ve=fe.onBridgeDisabledMessage,_t=fe.onSendDisabledMessage,Jn=o?o.provider==="google"||o.provider==="apple":de==="cross_embedded",eo=Ye(()=>{Me().catch(M=>{console.error("[crossx-kit] selectWallet error:",M)})},[Me]),en=v??(Jn?eo:void 0),to=Ye(async({hash:M,chainId:te})=>{let ne=Ht(ce,te?{chainId:te}:void 0);if(!ne)return null;try{return await ne.getTransactionReceipt({hash:M})}catch{return null}},[ce]),no=Ye(async M=>{let te=Te,ne=!1;M.chainId!==void 0&&M.chainId!==Te&&(await Le({chainId:M.chainId}),ne=!0);let ue=M.chainId===56||M.chainId===97?{...M,type:"legacy"}:M,J=await(m??xe)(ue);return await Tt({getChainId:()=>ne?M.chainId:te,switchChain:Ce=>Le({chainId:Ce})},te,Ae),J},[m,xe,Te,Le,Ae]),oo=_||m?no:void 0,ro=Ye(async M=>{let te=M.chainId??Te,ne=Ht(ce,te?{chainId:te}:void 0);if(!ne)throw new Error(`publicClient for chainId ${te??"unknown"} is not available \u2014 register the chain in createCrossxConfig({ networks }).`);let he=te===56||te===97,[ue,Ie]=await Promise.all([ne.estimateGas({account:M.from,to:M.to,value:M.value,data:M.data}),(async()=>{if(he)return{maxFeePerGas:void 0,maxPriorityFeePerGas:void 0,gasPrice:await ne.getGasPrice()};try{let J=await ne.estimateFeesPerGas();return{maxFeePerGas:J.maxFeePerGas,maxPriorityFeePerGas:J.maxPriorityFeePerGas,gasPrice:void 0}}catch{return{maxFeePerGas:void 0,maxPriorityFeePerGas:void 0,gasPrice:await ne.getGasPrice()}}})()]);return{gasLimit:ue,maxFeePerGas:Ie.maxFeePerGas,maxPriorityFeePerGas:Ie.maxPriorityFeePerGas,gasPrice:Ie.gasPrice}},[ce,Te]),so=k??ro,io=Ye(async M=>{let te={};if(!O||M.length===0)return te;let ne=M.flatMap(ue=>{let J={address:ue,abi:us,chainId:Te};return[{...J,functionName:"balanceOf",args:[O]},{...J,functionName:"totalSupply"},{...J,functionName:"decimals"}]}),he;try{he=await Kn(ce,{contracts:ne,allowFailure:!0})}catch{return te}return M.forEach((ue,Ie)=>{let J=Ie*3,Ce=he[J],wt=he[J+1],dt=he[J+2];!Ce||Ce.status!=="success"||(te[ue.toLowerCase()]={balance:Ce.result,totalSupply:wt&&wt.status==="success"?wt.result:void 0,decimals:dt&&dt.status==="success"?Number(dt.result):void 0})}),te},[ce,O,Te]),ao=Ye(async M=>{let te={earnedWei:0n,stakedWei:0n};if(!M)return te;let ne=ms[Re],he={address:ne.poolAddress,abi:ps,chainId:ne.crossChainId},ue;try{ue=await Kn(ce,{allowFailure:!0,contracts:[{...he,functionName:"earned",args:[M]},{...he,functionName:"balanceOf",args:[M]},{...he,functionName:"posaActive"},{...he,functionName:"lastRewardBlock"},{...he,functionName:"totalStaked"}]})}catch{return te}let Ie=ot=>ue[ot]&&ue[ot].status==="success"?ue[ot].result:0n,J=Ie(0),Ce=Ie(1);if(ue[2]&&ue[2].status==="success"?ue[2].result:!1)return{earnedWei:J,stakedWei:Ce};let dt=Ie(3),on=Ie(4);if(on===0n)return{earnedWei:J,stakedWei:Ce};let Et=0n;try{Et=await Ht(ce,{chainId:ne.crossChainId})?.getBlockNumber?.()??0n}catch{return{earnedWei:J,stakedWei:Ce}}if(Et<=dt)return{earnedWei:J,stakedWei:Ce};let Ot=0n;try{let ot=await fetch(ne.networkStatsUrl).then(Nt=>Nt.json()),rn=ot?.data?.block_reward??ot?.block_reward;if(rn){let[Nt,po=""]=String(rn).split("."),mo=(po+"0".repeat(18)).slice(0,18);Ot=BigInt(Nt||"0")*jt+BigInt(mo||"0")}}catch{}if(Ot===0n)return{earnedWei:J,stakedWei:Ce};let lo=(Et-dt)*Ot*jt/on,uo=Ce*lo/jt;return{earnedWei:J+uo,stakedWei:Ce}},[ce,Re]),tn=!en,nn=t?`cb-button ${t}`:"cb-button",co=t?`cb-pill ${t}`:"cb-pill";return Je&&!R?it($n,{children:[me("style",{children:Qt}),it("button",{type:"button",disabled:!0,className:nn,style:n,"aria-busy":"true",children:[me("span",{className:"cb-spinner","aria-hidden":"true"}),me("span",{className:"cb-button-label",children:"Connecting..."})]})]}):R&&be?it("span",{"data-crossx-wallet-info":tn?"external":"embedded",children:[me("style",{children:Qt}),tn&&me("style",{children:hs}),it(Vt,{...fe,env:Re,theme:ct,showBalance:K,walletAddress:be,accountName:u,sendAccounts:w??a,connectorId:B,showPortfolio:_,onDisconnect:T,onSelectWallet:en,onBuy:He,onBuyDisabledMessage:Oe,onBridgeDisabledMessage:Ve,onSendDisabledMessage:_t,sendTransaction:oo,getTransactionReceipt:C??to,estimateGas:so,lpBalanceReader:io,stakingRewardsReader:ao,bridgeTokens:L,bridgeHistory:Z,getBridgeQuote:S,getBridgeToTokens:F,getBridgeApproval:q,approveBridge:Q,submitBridge:U,style:i,children:[me(Vt.Trigger,{asChild:!0,children:it("button",{type:"button",className:co,style:n,"aria-label":`Connected with ${d?.name??"wallet"}: ${Un(be)}`,children:[d?.iconUrl?me("img",{src:d.iconUrl,alt:"",width:20,height:20,className:"cb-pill-icon","data-provider":d.iconUrl===Xt?"apple":void 0}):me("span",{className:"cb-pill-icon-placeholder","aria-hidden":"true"}),me("span",{className:"cb-pill-address",children:Un(be)})]})}),me(Vt.Content,{align:"end",sideOffset:8})]})]}):it($n,{children:[me("style",{children:Qt}),it("button",{type:"button",onClick:l,className:nn,style:n,"aria-label":typeof e=="string"?e:"Connect Wallet",children:[me(ws,{}),me("span",{className:"cb-button-label",children:e})]})]})}function ws(){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 hs=`
|
|
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 ie,B as se,C as de,D as pe,E as ce,F as le,G as ue,H as fe,I as Ce,J as we,a as S,b as V,c as W,d as X,e as L,f as h,g as j,h as B,i as F,j as D,k as U,l as q,m as z,n as $,o as G,p as H,q as J,r as Q,s as Y,t as Z,u as ee,v as ne,w as te,x as oe,y as re,z as ae}from"./chunk-
|
|
1
|
+
import{A as ie,B as se,C as de,D as pe,E as ce,F as le,G as ue,H as fe,I as Ce,J as we,a as S,b as V,c as W,d as X,e as L,f as h,g as j,h as B,i as F,j as D,k as U,l as q,m as z,n as $,o as G,p as H,q as J,r as Q,s as Y,t as Z,u as ee,v as ne,w as te,x as oe,y as re,z as ae}from"./chunk-4OFS6SYW.js";import{bscMainnetNetwork as v,bscTestnetNetwork as x,createCrossxConfig as E,crossMainnetNetwork as k,crossTestnetNetwork as O}from"@nexus-cross/connect-kit-wagmi";import{toNexusAdapter as A}from"@nexus-cross/connect-kit-wagmi/to-nexus";import{reownAdapter as M}from"@nexus-cross/connect-kit-wagmi/reown";import{embeddedConnectorFactory as P}from"@nexus-cross/connect-kit-wagmi/embedded";import{WALLET_BRAND_NAME as I}from"@nexus-cross/crossx-design-system";function d(e){try{return import.meta.env?.[e]}catch{return}}function p(e){if(!(typeof process>"u"))return process.env?.[e]}function K(){return d("VITE_CROSSX_ENVIRONMENT")??d("NEXT_PUBLIC_CROSSX_ENVIRONMENT")??p("NEXT_PUBLIC_CROSSX_ENVIRONMENT")??p("CROSSX_ENVIRONMENT")}function R(e){switch(e?.toLowerCase()){case"dev":case"development":return"development";case"stage":case"staging":case"stg":return"staging";default:return"production"}}function T(e){return e==="production"?[k,v]:[O,x]}function b(){let e=typeof window<"u"&&window.location?.origin?window.location.origin:"https://example.com";return{name:`${I} DApp`,url:e}}function _(e){let{app:c,appMetadata:l,networks:u,defaultNetwork:f,wallets:n,embedded:C=!0,environment:w,toNexus:t,reown:o,...r}=e,m=R(w??K()),i=u??T(m),a=Array.isArray(n)?null:n??"all",s=a!=="external-only"&&t!==!1,g=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??b(),networks:i,defaultNetwork:f??i[0],...Array.isArray(n)?{wallets:n}:{},...s?{crossProvider:A(y)}:{},...g?{reownProvider:M(N)}:{},...s&&C?{embeddedConnectorFactory:P}:{}})}export{re as AppLauncher,ie as AppLauncherContent,ae as AppLauncherTrigger,B as ConnectButton,fe as ConnectionStatus,oe as ConnectorId,L as CrossConnectKitProvider,X as CrossConnectModal,U as CrossRelayDeposit,q as CrossRelayHistory,z as CrossRelayRecovery,le as DEFAULT_TRUSTED_FACTORIES,ee as KycError,Z as KycProvider,ue as OnRampError,J as OnRampProvider,F as OtherWalletsModal,ce as RelayApiError,de as SkillsButton,te as WalletInfo,_ as createConnectKitConfig,pe as createRelayClient,Ce as formatBalance,we as formatWei,ne as launchKycVerification,$ as useConnectKitAnalytics,S as useCrossConnectKit,V as useCrossConnectKitTheme,h as useCrossdBridgeAdapter,j as useCrossxEmbeddedInfo,se as useGlobalMenu,Q as useKyc,G as useOnRamp,H as useOnRampEligibility,W as useOptionalCrossConnectKitTheme,Y as useOptionalKyc,D as useRelayWalletProps};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A,B,C,D,E,F,G,H,I,J,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-
|
|
1
|
+
import{A,B,C,D,E,F,G,H,I,J,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-4OFS6SYW.js";export{y as AppLauncher,A as AppLauncherContent,z as AppLauncherTrigger,h as ConnectButton,H as ConnectionStatus,x as ConnectorId,e as CrossConnectKitProvider,d as CrossConnectModal,k as CrossRelayDeposit,l as CrossRelayHistory,m as CrossRelayRecovery,F as DEFAULT_TRUSTED_FACTORIES,u as KycError,t as KycProvider,G as OnRampError,q as OnRampProvider,i as OtherWalletsModal,E as RelayApiError,C as SkillsButton,w as WalletInfo,D as createRelayClient,I as formatBalance,J as formatWei,v as launchKycVerification,n as useConnectKitAnalytics,a as useCrossConnectKit,b as useCrossConnectKitTheme,f as useCrossdBridgeAdapter,g as useCrossxEmbeddedInfo,B as useGlobalMenu,r as useKyc,o as useOnRamp,p as useOnRampEligibility,c as useOptionalCrossConnectKitTheme,s as useOptionalKyc,j as useRelayWalletProps};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexus-cross/connect-kit-react",
|
|
3
|
-
"version": "1.3.10-beta.
|
|
3
|
+
"version": "1.3.10-beta.8",
|
|
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.10-beta.
|
|
28
|
-
"@nexus-cross/connect-kit-wagmi": "1.3.10-beta.
|
|
29
|
-
"@nexus-cross/crossx-design-system": "1.3.10-beta.
|
|
30
|
-
"@nexus-cross/
|
|
31
|
-
"@nexus-cross/
|
|
32
|
-
"@nexus-cross/
|
|
27
|
+
"@nexus-cross/connect-kit-core": "1.3.10-beta.8",
|
|
28
|
+
"@nexus-cross/connect-kit-wagmi": "1.3.10-beta.8",
|
|
29
|
+
"@nexus-cross/crossx-design-system": "1.3.10-beta.8",
|
|
30
|
+
"@nexus-cross/dapp-ui": "1.3.10-beta.8",
|
|
31
|
+
"@nexus-cross/kyc": "1.3.10-beta.8",
|
|
32
|
+
"@nexus-cross/onramp": "1.3.10-beta.8"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@tanstack/react-query": "^5.60.0",
|