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