@nexus-cross/connect-kit-react 1.3.10-beta.2 → 1.3.10-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-PVH43WDS.js +144 -0
- package/dist/client.d.ts +2 -2
- package/dist/client.js +1 -1
- package/dist/index.d.ts +120 -3
- package/dist/index.js +1 -1
- package/package.json +7 -7
- package/dist/chunk-GQVRIG4I.js +0 -144
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
var mt="1.3.10-beta.4";var ht="__nexusCrossAppLauncherRuntime";function fo(){if(typeof window>"u")return null;let e=window;return e[ht]??(e[ht]={mode:"dapp-ui"}),e[ht]}function go(e){if(e.scheduled)return;e.scheduled=!0;let t=()=>{if(e.scheduled=!1,e.loggedMode!==e.mode){if(e.mode==="connect-kit-react"){let n=e.connectKitVersion??mt;console.info(`[CROSSx App Launcher] connect-kit-react v${n} \uCD08\uAE30\uD654 \uC644\uB8CC (dapp-ui v${mt}, \uC0AC\uC6A9 \uBAA8\uB4DC: connect-kit)`)}else console.info(`[CROSSx App Launcher] dapp-ui v${mt} \uCD08\uAE30\uD654 \uC644\uB8CC (\uC0AC\uC6A9 \uBAA8\uB4DC: dapp-ui only)`);e.loggedMode=e.mode}};typeof queueMicrotask=="function"?queueMicrotask(t):Promise.resolve().then(t)}function sn(){let e=fo();e&&(e.mode="connect-kit-react",e.connectKitVersion=mt,go(e))}import{useCallback as Be,useEffect as ie,useMemo as Ne,useRef as ke,useState as je}from"react";import{WagmiProvider as xo,useAccount as Io,useChainId as vo,useConnect as So,useDisconnect as Po,useSwitchChain as Ao}from"wagmi";import{QueryClient as Ro,QueryClientProvider as Bo}from"@tanstack/react-query";import{clearWalletSessionStorage as pn,onOpenOtherWallets as _o,pickInitialState as Eo,resolveCurrentWallet as Oo}from"@nexus-cross/connect-kit-wagmi";import{resolveThemeMode as No}from"@nexus-cross/connect-kit-core";import{buildDesignSystemCss as Fo}from"@nexus-cross/crossx-design-system";import{OnRampProvider as Wo}from"@nexus-cross/onramp/react";import{KycProvider as Do}from"@nexus-cross/kyc/react";import{createContext as yo,useContext as bo}from"react";var Ft=yo(null);function Ge(){let e=bo(Ft);if(!e)throw new Error("useCrossConnectKit must be used within <CrossConnectKitProvider>");return e}import{createContext as wo,useContext as an}from"react";var Ct=wo(null);function ho(){let e=an(Ct);if(!e)throw new Error("useCrossConnectKitTheme must be used within <CrossConnectKitProvider>");return e}function ft(){return an(Ct)}import{createContext as Co}from"react";var kt=Co(null);function cn(){let e=new Set,t=n=>{for(let i of[...e])try{i(n)}catch(o){console.debug("[crossx-kit] analytics handler threw",o)}};return{track:t,emit:n=>t({...n,timestamp:Date.now()}),subscribe:n=>(e.add(n),()=>{e.delete(n)})}}import{useCallback as ko,useMemo as dn}from"react";import{WalletConnectModal as ln}from"@nexus-cross/dapp-ui";import{jsx as un}from"react/jsx-runtime";var To=new Set(["cross_wallet","cross_extension","metamask","binance"]);function Wt({open:e,onOpenChange:t}){let{connect:n,availableWallets:i,oauth:o,extraWallets:c,walletAllowlist:g,kitConfig:y}=Ge(),r=ft()?.mode??"dark",f=dn(()=>{let m=g?new Set(g):null,k={};for(let x of i){if(!To.has(x.walletId)||m&&!m.has(x.walletId))continue;let v=x.walletId;k[v]=()=>{n(x.walletId)}}for(let[x,v]of Object.entries(c))v&&(m&&!m.has(x)||(k[x]=v));return k},[i,n,c,g]),w=dn(()=>{if(o)return{apple:()=>{o.signIn("apple")},google:()=>{o.signIn("google")}}},[o]),C=ko(m=>t(m),[t]);return un(ln,{wallets:f,socialProviders:w,termsUrl:y.legal?.termsUrl,privacyUrl:y.legal?.privacyUrl,theme:r,open:e,onOpenChange:C,children:un(ln.Content,{})})}import{jsx as Qe,jsxs as gn}from"react/jsx-runtime";var Lo=new Ro,Dt="crossx-kit:last-wallet-intent",Mo=15e3;function mn(e,t){return Promise.race([e.then(()=>{},()=>{}),new Promise(n=>setTimeout(n,t))])}function Go(e){let t=[],n=e,i=0;for(;n&&i<5;){let o=n;typeof o.message=="string"&&t.push(o.message),n=o.cause,i+=1}return t.some(o=>/external wallet connection/i.test(o))}function Ko(){if(typeof window>"u")return null;try{return window.localStorage.getItem(Dt)??null}catch{return null}}function fn(e){if(!(typeof window>"u"))try{e?window.localStorage.setItem(Dt,e):window.localStorage.removeItem(Dt)}catch{}}function Uo(e,t){if(typeof window>"u")return t;try{let n=window.localStorage.getItem(e);return n==="cross"||n==="reown"?n:t}catch{return t}}function $o(e,t){if(!(typeof window>"u"))try{window.localStorage.setItem(e,t)}catch{}}function qo({children:e,config:t,activeProvider:n,onRequestProviderSwap:i,pendingConnectWalletId:o,clearPending:c,themeMode:g,themeTokens:y,extraWallets:p,walletAllowlist:r,emit:f}){let[w,C]=je(!1),[m,k]=je(()=>Ko()),[x,v]=je(null),{address:W,isConnected:I,isConnecting:V,isReconnecting:G,connector:N}=Io(),{connectors:j,connectAsync:z}=So(),{disconnectAsync:X}=Po(),{kitConfig:D,connectorRegistry:K,crossProvider:Pe,reownProvider:fe}=t,O=n==="cross"?Pe:fe,R=Ne(()=>!I||!N?null:Oo(K,N.id,m),[I,N,K,m]),Y=Ne(()=>K.entries.filter(l=>l.type!=="embedded"),[K]),$=Be(l=>K.getEntry(l)?.type??"external",[K]),ce=ke(null);ce.current=x;let Te=ke(R);Te.current=R;let Le=ke(W);Le.current=W;let xe=D.embeddedProjectId?.trim()||D.crossProjectId?.trim(),Ee=!!D.onRampEnabled&&!!xe,ye=Ne(()=>!Ee||!xe?null:{projectId:xe,walletState:{getAddress:()=>Le.current}},[Ee,xe]),Me=ke(N);Me.current=N;let de=D.embeddedProjectId?.trim()||D.crossProjectId?.trim(),Je=!!D.kycEnabled&&!!de,et=Ne(()=>!Je||!de?null:{projectId:de,getAccessToken:async()=>{let l=Me.current;if(!(!l||typeof l.getProvider!="function"))try{return(await(await l.getProvider())?.sdk?.getUserInfo?.())?.data?.accessToken||void 0}catch{return}}},[Je,de]);ie(()=>_o(()=>C(!0)),[]),ie(()=>{if(!w||typeof document>"u")return;let l=setTimeout(()=>{document.querySelectorAll("#__crossx-confirm-overlay").forEach(h=>h.remove())},50);return()=>clearTimeout(l)},[w]);let Ae=ke(I),tt=ke(I);Ae.current=I;let ct=ke(!1);ie(()=>{console.debug("[crossx-kit] state",{activeProvider:n,isConnected:I,isConnecting:V,isReconnecting:G,activeConnectorId:N?.id,currentWallet:R,lastIntent:m})},[n,I,V,G,N?.id,R,m]),ie(()=>{I&&!tt.current&&O?.closeModal?.({kitConfig:D}),tt.current=I},[I,O,D]),ie(()=>{I&&v(null)},[I]);let Re=vo(),{switchChainAsync:be}=Ao(),we=ke(null);ie(()=>{if(!D.enforceDefaultNetworkOnConnect)return;let l=D.defaultNetwork?.id;if(!l)return;if(!I||!W||!N){we.current=null;return}let h=`${N.id}:${W}`;we.current!==h&&(we.current=h,Re!==l&&be({chainId:l}).catch(()=>{}))},[D.enforceDefaultNetworkOnConnect,D.defaultNetwork,I,W,N,Re,be]);let qe=ke(w);ie(()=>{w&&!qe.current?f({name:"connect_modal_opened"}):!w&&qe.current&&f({name:"connect_modal_closed",completed:Ae.current}),qe.current=w},[w,f]);let s=ke(I);ie(()=>{if(I&&!s.current){let l=ce.current;l&&f({name:"connect_succeeded",walletId:l,walletType:$(l),chainId:Re})}s.current=I},[I,Re,f,$]);let a=Be(l=>j.find(h=>h.id===l),[j]);ie(()=>{let l=K.getEntry("cross_embedded");if(!l)return;let h=a(l.connectorId);if(!h)return;let T=!1;return(async()=>{try{let P=await h.getProvider();if(T)return;P?.sdk?.applyTheme?.(g,y??void 0)}catch(P){console.debug("[crossx-kit] applyTheme skipped:",P)}})(),()=>{T=!0}},[K,a,g,y]);let d=Be(l=>{k(l),fn(l)},[]),u=Be(()=>{k(null),fn(null),v(null)},[]);ie(()=>{if(!O?.subscribeModalState)return;let l=!1;return O.subscribeModalState({kitConfig:D},h=>{if(ct.current=h,h){l=!0;return}l&&(l=!1,setTimeout(()=>{if(Ae.current)return;let T=ce.current;T&&f({name:"connect_cancelled",walletId:T,stage:"popup"}),(async()=>{try{await X()}catch{}u()})()},250))})},[O,D,X,u,f]),ie(()=>{if(!x||I||typeof window>"u"||x==="cross_embedded")return;let l=typeof document<"u"&&!document.hasFocus(),h=null,T=()=>{l=!0},P=()=>{l&&(h&&clearTimeout(h),h=setTimeout(()=>{if(Ae.current||ct.current)return;let E=ce.current;E&&f({name:"connect_cancelled",walletId:E,stage:"popup"}),(async()=>{try{await X()}catch{}u()})()},1e3))};return window.addEventListener("blur",T),window.addEventListener("focus",P),()=>{window.removeEventListener("blur",T),window.removeEventListener("focus",P),h&&clearTimeout(h)}},[x,I,X,u,f]);let b=Be(async l=>{console.debug("[crossx-kit] runConnect enter",{walletId:l,activeProvider:n,isConnected:I,activeConnectorId:N?.id});let h=K.getEntry(l);if(!h){if((l==="metamask"||l==="binance")&&!fe){console.error(`[crossx-kit] "${l}" requires the Reown adapter, but it is not configured. Pass \`reownProjectId\` (and ensure \`reown\` is not set to \`false\`) when calling createConnectKitConfig() or createCrossxConfig() to enable WalletConnect-based wallets.`);return}console.error(`[crossx-kit] Unknown walletId: "${l}"`);return}if(v(l),h.providerKind!==n){console.debug("[crossx-kit] provider swap needed",{from:n,to:h.providerKind,walletId:l}),d(l);try{await X()}catch{}await new Promise(E=>setTimeout(E,0)),i(h.providerKind,l);return}let T=$(l);if(f({name:"wallet_selected",walletId:l,walletType:T}),f({name:"connect_started",walletId:l,walletType:T}),d(l),O?.beforeConnect)try{let E=await O.beforeConnect({kitConfig:D,themeMode:g},l);if(console.debug("[crossx-kit] beforeConnect result",{walletId:l,result:E}),E==="handled")return}catch(E){console.warn('[crossx-kit] adapter.beforeConnect threw for "%s":',l,E)}let P=a(h.connectorId);if(console.debug("[crossx-kit] findConnector",{lookupId:h.connectorId,found:P?.id,availableIds:j.map(E=>E.id)}),!P){console.error(`[crossx-kit] Connector "${h.connectorId}" not found on provider "${h.providerKind}". Available: ${j.map(E=>E.id).join(", ")}`),f({name:"connect_failed",walletId:l,reason:"connector_not_found"}),u();return}try{console.debug("[crossx-kit] connectAsync start",{connectorId:P.id});let E=await z({connector:P});console.debug("[crossx-kit] connectAsync resolved",{accountsLen:E.accounts.length,chainId:E.chainId});return}catch(E){let le=Go(E);if(!le){console.error('[crossx-kit] connectAsync error for "%s":',l,E);try{await X()}catch{}}if(!h.fallbackConnectorId){le||f({name:"connect_failed",walletId:l,reason:"connector_error"}),u();return}}if(h.fallbackConnectorId){let E=a(h.fallbackConnectorId);if(E)try{await z({connector:E})}catch(le){console.error('[crossx-kit] Fallback connect failed for "%s":',l,le);try{await X()}catch{}f({name:"connect_failed",walletId:l,reason:"fallback_failed"}),u()}else f({name:"connect_failed",walletId:l,reason:"fallback_failed"}),u()}},[K,j,a,z,X,d,u,O,n,D,i,g,f,$]);ie(()=>{if(!o)return;let l=o;c(),b(l)},[o,n]);let B=Be(async()=>{C(!0)},[]),_=Be(async()=>{f({name:"disconnected",walletId:Te.current});try{await X()}catch(l){console.error("[crossx-kit] wagmi disconnect error:",l)}if(O?.teardown)try{await O.teardown({kitConfig:D})}catch(l){console.error("[crossx-kit] adapter teardown error:",l)}pn(),u()},[X,O,D,u,f]),A=Be(async()=>{await mn(X(),3e3);try{let l=K.getEntry("cross_embedded"),h=l&&a(l.connectorId);if(h?.getProvider){let T=await Promise.race([h.getProvider(),new Promise(E=>setTimeout(E,3e3))]),P=T?.sdk?.signOut;typeof P=="function"&&await mn(P.call(T.sdk),3e3)}}catch{}pn()},[K,a,X]),L=Be(async()=>{let l=K.getEntry("cross_embedded");if(!l)return null;let h=a(l.connectorId);if(!h)return null;try{let T=await h.getProvider(),P=T?.sdk;if(!P?.selectWallet)return null;let E=await P.selectWallet(P.currentAddress??void 0);return E?.address&&T.notifyAccountsChanged&&T.notifyAccountsChanged([E.address]),E&&f({name:"wallet_switched",index:E.index}),E}catch{return null}},[K,a,f]),Z=Ne(()=>{let l=t.oauth;return l?{signIn:async h=>{v("cross_embedded"),f({name:"wallet_selected",walletId:"cross_embedded",walletType:"embedded"}),f({name:"connect_started",walletId:"cross_embedded",walletType:"embedded"});try{await l.signIn(h)}catch(T){throw f({name:"connect_cancelled",walletId:"cross_embedded",stage:"popup"}),v(null),T}}}:null},[t.oauth,f]),S=ke(!1);ie(()=>{if(n!=="cross"||I||V||G||x!=null||S.current)return;let l=K.getEntry("cross_embedded");if(!l)return;let h=a(l.connectorId);if(!h)return;S.current=!0;let T=!1;return(async()=>{try{let P=await h.isAuthorized?.();if(T||!P)return;await z({connector:h})}catch{}})(),()=>{T=!0}},[n,I,V,G,x,K,a,z]),ie(()=>{if(x!=="cross_embedded"||I||typeof window>"u")return;let l=!document.hasFocus(),h=()=>{l=!0};window.addEventListener("blur",h);let T=setTimeout(()=>{Ae.current||l||(console.warn("[crossx-kit] embedded sign-in stalled before the OAuth popup opened \u2014 clearing the stale session so a retry starts clean"),f({name:"connect_cancelled",walletId:"cross_embedded",stage:"stalled"}),u(),A())},Mo);return()=>{window.removeEventListener("blur",h),clearTimeout(T)}},[x,I,u,A,f]);let F=x!=null&&!I,q=Ne(()=>({kitConfig:D,connectorRegistry:K,availableWallets:Y,connect:b,connectWallet:B,disconnect:_,selectWallet:L,currentWallet:R,lastIntent:m,isConnecting:F,connectingWalletId:x,openOtherWallets:()=>C(!0),closeOtherWallets:()=>C(!1),otherWalletsOpen:w,oauth:Z,extraWallets:p,walletAllowlist:r,onRampEnabled:Ee}),[D,K,Y,b,B,_,L,R,m,F,x,w,Z,p,r,Ee]),U=gn(Ft.Provider,{value:q,children:[e,Qe(Wt,{open:w,onOpenChange:C})]});return et&&(U=Qe(Do,{config:et,children:U})),ye&&(U=Qe(Wo,{config:ye,children:U})),U}var Ho=[/Connection interrupted while trying to subscribe/i,/No matching key\. subscription:/i,/Proposal expired/i];function Vo(e){let t=e?.message;return typeof t!="string"?!1:Ho.some(n=>n.test(t))}var jo={};function Qo(e){return e&&{...e,connections:new Map,current:null}}function zo({children:e,config:t,initialState:n,extraWallets:i=jo,walletAllowlist:o}){let[c,g]=je(()=>Uo(t.activeProviderStorageKey,t.defaultProvider)),[y,p]=je(null),r=ke(!1),f=ke(null);f.current||(f.current=cn());let w=f.current,C=Ne(()=>({subscribe:w.subscribe}),[w]),{kitConfig:m}=t,[k,x]=je(null),[v,W]=je(null),[I,V]=je(0),G=Ne(()=>No(m.theme,m.autoDetectTheme),[m.theme,m.autoDetectTheme,I]),N=k??G,j=v??m.themeTokens;ie(()=>{if(!m.autoDetectTheme||k||typeof window>"u"||!window.matchMedia)return;let R=window.matchMedia("(prefers-color-scheme: dark)"),Y=()=>V($=>$+1);try{return R.addEventListener("change",Y),()=>R.removeEventListener("change",Y)}catch{return R.addListener(Y),()=>R.removeListener(Y)}},[m.autoDetectTheme,k]),ie(()=>{if(typeof document>"u")return;let R=document.documentElement,Y=R.getAttribute("data-ds-theme"),$=R.getAttribute("data-theme");return R.setAttribute("data-ds-theme",N),$||R.setAttribute("data-theme",N),()=>{Y==null?R.removeAttribute("data-ds-theme"):R.setAttribute("data-ds-theme",Y),$==null&&R.removeAttribute("data-theme")}},[N]);let z=Ne(()=>Fo(t.designSystem),[t.designSystem]),X=Ne(()=>({mode:N,tokens:j,setThemeMode:R=>x(R),setThemeTokens:R=>W(R)}),[N,j]);ie(()=>{if(typeof window>"u")return;let R=Y=>{Vo(Y.reason)&&Y.preventDefault()};return window.addEventListener("unhandledrejection",R),()=>window.removeEventListener("unhandledrejection",R)},[]);let D=Be((R,Y)=>{r.current||(r.current=!0,p(Y),g(R),$o(t.activeProviderStorageKey,R),queueMicrotask(()=>{r.current=!1}))},[t.activeProviderStorageKey]),K=Be(()=>p(null),[]),Pe=c==="cross"?t.crossWagmiConfig:t.reownWagmiConfig,fe=Qo(Eo(n,c));if(!Pe){if(!(c==="cross"?t.reownWagmiConfig:t.crossWagmiConfig))throw new Error("[crossx-kit] createCrossxConfig returned no wagmi Config for either side");let Y=c==="cross"?"reown":"cross";queueMicrotask(()=>g(Y))}let O=Pe??(c==="cross"?t.reownWagmiConfig:t.crossWagmiConfig);return Qe(kt.Provider,{value:C,children:gn(Ct.Provider,{value:X,children:[Qe("style",{"data-crossx-design-system":"",children:z}),Qe(xo,{config:O,initialState:fe,children:Qe(Bo,{client:Lo,children:Qe(qo,{config:t,activeProvider:c,onRequestProviderSwap:D,pendingConnectWalletId:y,clearPending:K,themeMode:N,themeTokens:j,extraWallets:i,walletAllowlist:o??t.kitConfig.wallets??null,emit:w.emit,children:e})})},c)]})})}import{useCallback as Ye,useEffect as es,useMemo as At}from"react";import{useQueryClient as ts}from"@tanstack/react-query";import{useAccount as ns,useChainId as os,useConfig as rs,useSendTransaction as ss,useSwitchChain as is}from"wagmi";import{getPublicClient as Ht,readContracts as Kn}from"wagmi/actions";import{WalletInfo as Vt,ConnectorId as Ze,resolveEnvironment as as}from"@nexus-cross/dapp-ui";import{useOptionalOnRamp as cs,useOptionalOnRampEligibility as ds}from"@nexus-cross/onramp/react";import{APPLE_ICON as Xt,BINANCE_ICON as qn,CROSSX_ICON as zt,EXTENSION_ICON as ls,GOOGLE_ICON as Hn,METAMASK_ICON as Vn}from"@nexus-cross/connect-kit-wagmi";import{WALLET_LABELS as Rt}from"@nexus-cross/crossx-design-system";import{useCallback as oe,useMemo as ve,useRef as Xo}from"react";import{useQueries as wn,useQuery as ze}from"@tanstack/react-query";import{encodeFunctionData as gt,formatUnits as Pt,parseSignature as Yo,parseUnits as Zo}from"viem";import{getChainId as Lt,getPublicClient as En,readContract as _e,signTypedData as Jo,switchChain as hn,waitForTransactionReceipt as er,writeContract as Cn}from"wagmi/actions";import{useConfig as tr}from"wagmi";async function Tt(e,t,n){if(!(!n||t===void 0))try{if(e.getChainId()===t)return;await e.switchChain(t)}catch{}}var lt=10000n;function yn(e){let t=e==="auto"?1:Number(e||"1");return!Number.isFinite(t)||t<0?100n:BigInt(Math.min(1e4,Math.floor(t*100)))}function xt(e,t){let n=yn(t);return n>=lt?0n:e*(lt-n)/lt}function bn(e,t){let n=yn(t);return(e*(lt+n)+(lt-1n))/lt}function nr(e){return e!=="bridge"}var $e="0x0000000000000000000000000000000000000000",Se=100,pt=18,or=180000n,rr=250000n,On=new Set([56,97]),sr=130n,ir=100n,ar={dev:"https://stg-contents.crosstoken.io/frontend/game-token/json/hidden-path.json",stage:"https://stg-contents.crosstoken.io/frontend/game-token/json/hidden-path.json",production:"https://contents.crosstoken.io/frontend/game-token/json/hidden-path.json"},cr={dev:"dev",stage:"stg",production:"prod"};function dr(e,t){let n=e?.[cr[t]]?.hiddenPairs;if(!Array.isArray(n))return null;let i=n.filter(o=>!!o&&typeof o=="object"&&typeof o.fromKey=="string"&&typeof o.toKey=="string");return i.length>0?i:null}var lr={dev:"https://stg-contents.crosstoken.io/frontend/common/app-launcher/contracts.json",stage:"https://stg-contents.crosstoken.io/frontend/common/app-launcher/contracts.json",production:"https://contents.crosstoken.io/frontend/common/app-launcher/contracts.json"},ur=["BSC_CROSS","W_CROSS","NATIVE_CROSS","USDTX","CROSSD","USDTB","SWAP_BRIDGE_ROUTER"],pr={BSC_CROSS:$e,W_CROSS:$e,NATIVE_CROSS:$e,USDTX:$e,CROSSD:$e,USDTB:$e,SWAP_BRIDGE_ROUTER:$e},mr=/^0x[0-9a-fA-F]{40}$/;function fr(e,t){let n=typeof e=="string"?e:e?.[t];return typeof n=="string"&&mr.test(n)?n:null}function gr(e,t){if(!e?.bridge)return null;let n=e.envToNetwork?.[t]??(t==="production"?"mainnet":"testnet"),i={};for(let o of ur){let c=fr(e.bridge[o],n);if(!c)return null;i[o]=c}return i}var yr={dev:{bridgeApi:"https://stg-bridge-api.crosstoken.io/bridge",walletApi:"https://stg-wallet-server.crosstoken.io/api",chainIds:{cross:612044,bsc:97}},stage:{bridgeApi:"https://stg-bridge-api.crosstoken.io/bridge",walletApi:"https://stg-wallet-server.crosstoken.io/api",chainIds:{cross:612044,bsc:97}},production:{bridgeApi:"https://bridge-api.crosstoken.io/bridge",walletApi:"https://wallet-server.crosstoken.io/api",chainIds:{cross:612055,bsc:56}}},rt=[{type:"function",name:"quoter",stateMutability:"view",inputs:[],outputs:[{name:"",type:"address"}]},{type:"function",name:"swapRouter",stateMutability:"view",inputs:[],outputs:[{name:"",type:"address"}]},{type:"function",name:"getAmountSwapBridgeOut",stateMutability:"view",inputs:[{name:"toChainID",type:"uint256"},{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"fee",type:"uint24"},{name:"amountIn",type:"uint256"}],outputs:[{name:"ok",type:"bool"},{name:"swapAmountOut",type:"uint256"},{name:"bridgeValue",type:"uint256"},{name:"networkFee",type:"uint256"},{name:"exFee",type:"uint256"}]},{type:"function",name:"getAmountSwapBridgeIn",stateMutability:"view",inputs:[{name:"toChainID",type:"uint256"},{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"fee",type:"uint24"},{name:"bridgeValue",type:"uint256"}],outputs:[{name:"ok",type:"bool"},{name:"amountIn",type:"uint256"},{name:"swapAmountOut",type:"uint256"},{name:"networkFee",type:"uint256"},{name:"exFee",type:"uint256"}]},{type:"function",name:"swapBridgeExactInputSingle",stateMutability:"nonpayable",inputs:[{name:"params",type:"tuple",components:[{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"fee",type:"uint24"},{name:"amountIn",type:"uint256"},{name:"amountOutMinimum",type:"uint256"},{name:"sqrtPriceLimitX96",type:"uint160"},{name:"bridgeParams",type:"tuple",components:[{name:"toChainID",type:"uint256"},{name:"recipient",type:"address"},{name:"extraData",type:"bytes"}]}]},{name:"deadline",type:"uint256"}],outputs:[{name:"amountOut",type:"uint256"}]},{type:"function",name:"swapBridgeExactOutputSingle",stateMutability:"nonpayable",inputs:[{name:"params",type:"tuple",components:[{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"fee",type:"uint24"},{name:"amountOut",type:"uint256"},{name:"amountInMaximum",type:"uint256"},{name:"sqrtPriceLimitX96",type:"uint160"},{name:"bridgeParams",type:"tuple",components:[{name:"toChainID",type:"uint256"},{name:"recipient",type:"address"},{name:"extraData",type:"bytes"}]}]},{name:"deadline",type:"uint256"}],outputs:[{name:"amountIn",type:"uint256"}]}],Mt=[{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"}],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"allowance",stateMutability:"view",inputs:[{name:"owner",type:"address"},{name:"spender",type:"address"}],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"approve",stateMutability:"nonpayable",inputs:[{name:"spender",type:"address"},{name:"amount",type:"uint256"}],outputs:[{name:"",type:"bool"}]}],kn=[{type:"function",name:"name",stateMutability:"view",inputs:[],outputs:[{name:"",type:"string"}]},{type:"function",name:"nonces",stateMutability:"view",inputs:[{name:"owner",type:"address"}],outputs:[{name:"",type:"uint256"}]}],Tn=[{type:"function",name:"quoteExactInputSingle",stateMutability:"nonpayable",inputs:[{name:"params",type:"tuple",components:[{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"amountIn",type:"uint256"},{name:"fee",type:"uint24"},{name:"sqrtPriceLimitX96",type:"uint160"}]}],outputs:[{name:"amountOut",type:"uint256"},{name:"sqrtPriceX96After",type:"uint160"},{name:"initializedTicksCrossed",type:"uint32"},{name:"gasEstimate",type:"uint256"}]},{type:"function",name:"quoteExactOutputSingle",stateMutability:"nonpayable",inputs:[{name:"params",type:"tuple",components:[{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"amount",type:"uint256"},{name:"fee",type:"uint24"},{name:"sqrtPriceLimitX96",type:"uint160"}]}],outputs:[{name:"amountIn",type:"uint256"},{name:"sqrtPriceX96After",type:"uint160"},{name:"initializedTicksCrossed",type:"uint32"},{name:"gasEstimate",type:"uint256"}]}],br=[{type:"function",name:"slot0",stateMutability:"view",inputs:[],outputs:[{name:"sqrtPriceX96",type:"uint160"},{name:"tick",type:"int24"},{name:"observationIndex",type:"uint16"},{name:"observationCardinality",type:"uint16"},{name:"observationCardinalityNext",type:"uint16"},{name:"feeProtocol",type:"uint8"},{name:"unlocked",type:"bool"}]}],Ke=[{type:"function",name:"exactInputSingle",stateMutability:"payable",inputs:[{name:"params",type:"tuple",components:[{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"fee",type:"uint24"},{name:"recipient",type:"address"},{name:"deadline",type:"uint256"},{name:"amountIn",type:"uint256"},{name:"amountOutMinimum",type:"uint256"},{name:"sqrtPriceLimitX96",type:"uint160"}]}],outputs:[{name:"amountOut",type:"uint256"}]},{type:"function",name:"multicall",stateMutability:"payable",inputs:[{name:"data",type:"bytes[]"}],outputs:[{name:"results",type:"bytes[]"}]},{type:"function",name:"unwrapWETH9",stateMutability:"payable",inputs:[{name:"amountMinimum",type:"uint256"},{name:"recipient",type:"address"}],outputs:[]},{type:"function",name:"refundETH",stateMutability:"payable",inputs:[],outputs:[]}],wr=[{type:"function",name:"bridgeToken",stateMutability:"payable",inputs:[{name:"toChainID",type:"uint256"},{name:"fromToken",type:"address"},{name:"to",type:"address"},{name:"value",type:"uint256"},{name:"gasFee",type:"uint256"},{name:"exFee",type:"uint256"},{name:"extraData",type:"bytes"}],outputs:[{name:"",type:"bool"}]}];async function Nn(e){let t="";try{t=await e.text()}catch{}if(t){try{let n=JSON.parse(t),i=typeof n.data=="string"&&n.data||typeof n.message=="string"&&n.message||"";if(i)return`${i} (status ${e.status})`}catch{}return`${t.slice(0,300)} (status ${e.status})`}return`status ${e.status}`}async function Fe(e,t){let n=await fetch(e,{cache:"no-store",signal:t});if(!n.ok)throw new Error(`CrossD bridge adapter request failed: ${await Nn(n)}`);let i=await n.json();if(i&&typeof i=="object"&&"code"in i&&typeof i.code=="number"&&i.code!==200)throw new Error(i.message||`CrossD bridge adapter API error: ${i.code}`);return i&&typeof i=="object"&&"data"in i?i.data:i}async function xn(e,t,n){let i=await fetch(e,{method:"POST",cache:"no-store",signal:n,headers:{"content-type":"application/json"},body:JSON.stringify(t)});if(!i.ok)throw new Error(`CrossD bridge adapter request failed: ${await Nn(i)}`);let o=await i.json();if(o&&typeof o=="object"&&"code"in o&&typeof o.code=="number"&&o.code!==200)throw new Error(o.message||`CrossD bridge adapter API error: ${o.code}`);return o&&typeof o=="object"&&"data"in o?o.data:o}function hr(e){return new Promise(t=>setTimeout(t,e))}async function Cr(e,t,{attempts:n=60,intervalMs:i=2e3}={}){for(let o=0;o<n;o+=1){try{let c=await Fe(`${e}/permit-hash/${t}`);if(Ut(c))return c}catch{}await hr(i)}return null}function se(e,t){return`${e}-${t.toLowerCase()}`}function pe(e){return se(e.chainId,e.address)}function We(e){return e==="swap"||e==="deposit-swap"||e==="swap-withdraw"}function kr(e){let t=e instanceof Error?e.message:typeof e=="string"?e:"",n=t.toLowerCase();return n.includes("quoteexactinputsingle")||n.includes("quoteexactoutputsingle")||n.includes("getamountswapbridgeout")||n.includes("getamountswapbridgein")||n.includes("execution reverted")?"Amount is too large for this route.":t.split(`
|
|
2
|
+
`)[0]?.trim()||"Failed to quote bridge."}function In(e){return e===56||e===97?"BSC":e===612044||e===612055?"CROSS":`Chain ${e}`}function re(e,t){return t?t.toLowerCase()===e.contracts.NATIVE_CROSS.toLowerCase()?e.contracts.W_CROSS:t:$e}function st(e){let t=Pt(e,pt);return t.includes(".")?t.replace(/\.?0+$/,""):t}function bt(e){return Zo(e||"0",pt)}function ge(e){try{return bt(e||"0")}catch{return 0n}}function Xe(e){if(typeof e=="bigint")return e;if(typeof e=="number")return BigInt(Math.trunc(e));if(!e)return 0n;try{return BigInt(e)}catch{return 0n}}function Gt(e){let t=Pt(e,9);return(t.includes(".")?t.replace(/\.?0+$/,""):t)||"0"}function It(e){return e==="bridge"?or:rr}function vn(e,t){if(!e||!t)return"0";let n=e*e;if(n===0n)return"0";let i=t*t,o=i>n?i-n:n-i;if(o===0n)return"0";let c=(o*100000000n+n/2n)/n;if(c>=100000000n)return"100";let g=c/1000000n,y=(c%1000000n).toString().padStart(6,"0").replace(/0+$/,"");return y?`${g}.${y}`:`${g}`}function Tr(e){if(!e||Number(e)===0)return"0%";let[t,n=""]=e.split("."),i=n.length>4?n.slice(0,4):n;return i?`${t}.${i}%`:`${t}%`}async function Sn(e,t,n,i,o,c=!1){let g=En(e,{chainId:t}),y=n;try{let r=await g?.estimateContractGas?.({account:o.account,address:o.address,abi:o.abi,functionName:o.functionName,args:o.args,value:o.value});typeof r=="bigint"&&r>0n&&(y=i?r*sr/ir:r)}catch{}let p={gas:y};if(On.has(t))try{let r=await g?.getGasPrice?.();typeof r=="bigint"&&r>0n&&(p.gasPrice=r)}catch{}else if(c)try{let r=await g?.estimateFeesPerGas?.();typeof r?.maxFeePerGas=="bigint"&&(p.maxFeePerGas=r.maxFeePerGas),typeof r?.maxPriorityFeePerGas=="bigint"&&(p.maxPriorityFeePerGas=r.maxPriorityFeePerGas)}catch{}return p}function yt(){return BigInt(Math.floor(Date.now()/1e3)+1800)}var xr={100:"0.01%",500:"0.05%",3e3:"0.3%",1e4:"1%"};function Ir(e){return xr[e]??`${e/1e4}%`}function vr(e,t){let n=Number(e||"0");return!Number.isFinite(n)||n<=0?"0":(n*t/1e6).toFixed(8).replace(/\.?0+$/,"")}function Pn(e){return st(e)}function An(e,t){let n=Number(t??"0");return!Number.isFinite(n)||n<=0?0n:e*BigInt(Math.floor(n))/1000n}function vt(e,t){if(!e)return!1;let n=e.toLowerCase();return t.some(i=>i.toLowerCase()===n)}function Sr(e,t,n){return[{from:[e.contracts.USDTX],to:[e.contracts.CROSSD]},{from:[e.contracts.BSC_CROSS],to:[e.contracts.NATIVE_CROSS,e.contracts.W_CROSS]},{from:[e.contracts.NATIVE_CROSS,e.contracts.W_CROSS],to:[e.contracts.CROSSD]}].some(o=>vt(t,o.from)&&vt(n,o.to)||vt(t,o.to)&&vt(n,o.from))}function Pr(e){if(We(e.type))return null;if(e.type==="swap-bridge"){let t=e.steps.find(n=>n.type==="bridge");return t?{from:t.fromChain,to:t.toChain,token:t.fromToken}:null}if(e.type==="bridge-swap"){let t=e.steps.find(n=>n.type==="bridge");return t?{from:t.fromChain,to:t.toChain,token:t.fromToken}:null}return{from:e.from.chainId,to:e.to.chainId,token:e.from.address}}function Ar({input:e,path:t,config:n}){if(!n||We(t.type))return"";let i=Xe(n.minimumValue),o=Xe(n.gasFee??n.gas_fee),c=t.type==="swap-bridge"?i+o*12n/10n:i;return c<=0n?"":e.fromAmount&&ge(e.fromAmount)<c&&t.type!=="swap"?`Minimum ${Pn(c)}`:t.type==="swap-bridge"&&e.toAmount&&ge(e.toAmount)<c?`Available ${Pn(c)} or more.`:""}function Rr({input:e,path:t,config:n}){if(!n||t.type!=="bridge"&&t.type!=="bridge-swap")return"";let i=Xe(n.gasFee??n.gas_fee);if(i<=0n||!e.fromAmount)return"";let o=ge(e.fromToken.balance||"0"),c=ge(e.fromAmount);return o-i<c?`Insufficient network fee(${e.fromToken.symbol})`:""}function Br(e,t){let n=new Set;return e?.list?.forEach(i=>{let o=i.localChain??i.local_chain;o&&Object.entries(i.pairs||{}).forEach(([c,g])=>{g.forEach(y=>{y.localToken&&n.add(se(o,y.localToken)),y.remoteToken&&n.add(se(Number(c),y.remoteToken))})})}),Object.entries(t?.swapPools||t?.swap_pools||{}).forEach(([i,o])=>{o.forEach(c=>{c.token0&&n.add(se(Number(i),c.token0)),c.token1&&n.add(se(Number(i),c.token1))})}),n}function _r(e,t){return!e||!t?null:se(e,t)}function Er({envConfig:e,bridgePairList:t,swapPools:n,tokenInfo:i,tokenStats:o}){let c=Br(t,n),g=new Map;o?.forEach(p=>{let r=_r(Number(p.chainId??p.chain_id),p.address);r&&g.set(r,p)});let y={};return c.forEach(p=>{let[r,f]=p.split("-"),w=Number(r),C=i?.find(k=>Number(k.chainId??k.chain_id)===w&&k.address?.toLowerCase()===f);if(!C?.symbol||!C.name)return;let m=g.get(p);y[p]={key:p,chainId:w,address:f,symbol:C.symbol,name:C.name,decimals:C.decimals||pt,image:C.image||C.icon_url,price:m?.price?Number(m.price):void 0,isNativeToken:f.toLowerCase()===e.contracts.NATIVE_CROSS.toLowerCase()}}),y}function Fn(e,t){return t?.list?.find(n=>(n.localChain??n.local_chain)===e)?.bridge||""}function Wn(e,t,n){let[i,o]=e.split("-"),[c,g]=t.split("-"),y=Number(i),p=Number(c);for(let r of n?.list||[]){if((r.localChain??r.local_chain)!==y)continue;let f=r.pairs?.[c];if(f){for(let w of f)if(w.localToken?.toLowerCase()===o&&w.remoteToken?.toLowerCase()===g)return{type:"bridge",fromChain:y,fromToken:o,toChain:p,toToken:g,bridgeAddress:Fn(y,n)}}}return null}function Dn(e,t,n,i){let o,c=1/0;for(let g of e||[]){let y=i(g.token0),p=i(g.token1);if(y===t&&p===n||p===t&&y===n){let r=g.fee??Se;r<c&&(o=g,c=r)}}return o?{fee:c,poolAddress:o.poolAddress||o.pool_address||""}:null}function Ln(e,t,n,i){let[o,c]=e.split("-"),[g,y]=t.split("-");if(o!==g)return null;let p=Number(o),r=(n?.swapPools||n?.swap_pools)?.[o];if(!r)return null;let f=i.contracts.W_CROSS.toLowerCase(),w=i.contracts.NATIVE_CROSS.toLowerCase(),m=Dn(r,c,y,x=>x?.toLowerCase()===f?w:x?.toLowerCase());if(!m)return null;let k="swap";return p===i.chainIds.cross&&(c===w&&(k="deposit-swap"),y===w&&(k="swap-withdraw")),{pathType:k,step:{type:"swap",chain:p,fromToken:c,toToken:y,fee:m.fee,poolAddress:m.poolAddress}}}function Or(e,t,n,i){let[o,c]=e.split("-"),[g]=t.split("-");if(o===g)return null;let y=(n?.swapPools||n?.swap_pools)?.[o]||[],p=r=>r?.toLowerCase();for(let r of y){let f=p(r.token0),w=p(r.token1),C=f===c?w:w===c?f:null;if(!C)continue;let m=Wn(se(Number(o),C),t,i);if(!m)continue;let k=Dn(y,c,C,p);return[{type:"swap",chain:Number(o),fromToken:c,toToken:C,fee:k?.fee??Se,poolAddress:k?.poolAddress??""},m]}return null}function Nr(e,t,n,i,o){let[c,g]=e.split("-"),[y]=t.split("-");if(c===y)return null;for(let p of n?.list||[])if((p.localChain??p.local_chain)===Number(c))for(let r of p.pairs?.[y]||[]){if(r.localToken?.toLowerCase()!==g)continue;let f=r.remoteToken?.toLowerCase();if(!f)continue;let w=Ln(se(Number(y),f),t,i,o);if(w)return[{type:"bridge",fromChain:Number(c),fromToken:g,toChain:Number(y),toToken:f,bridgeAddress:Fn(Number(c),n)},w.step]}return null}function Fr({envConfig:e,bridgePairList:t,swapPools:n,enrichedTokens:i}){return(o,c)=>{let g=i[o],y=i[c];if(!g||!y||o===c)return null;let p=Wn(o,c,t);if(p)return{type:"bridge",steps:[p],from:g,to:y};let r=Ln(o,c,n,e);if(r)return{type:r.pathType,steps:[r.step],from:g,to:y};let f=Or(o,c,n,t);if(f)return{type:"swap-bridge",steps:f,from:g,to:y};let w=Nr(o,c,t,n,e);return w?{type:"bridge-swap",steps:w,from:g,to:y}:null}}function Rn(e,t){return{name:e.name,symbol:e.symbol,chainId:e.chainId,address:e.address,decimals:e.decimals,balance:t.get(e.key)||"0",iconUrl:e.image,priceUsd:e.price}}function Wr(e){return e.length<=10?e:`${e.slice(0,6)}...${e.slice(-4)}`}function Dr(e){return e.includes(".")?e.replace(/\.?0+$/,"")||"0":e}function Lr(e,t){let n=e.startsWith("-"),i=n?e.slice(1):e,[o,c=""]=i.split("."),g=c.slice(0,t).replace(/0+$/,""),y=g?`${o}.${g}`:o;return n?`-${y}`:y}function Mr(e){let t=e.startsWith("-"),n=t?e.slice(1):e,[i,o]=n.split("."),c=i.replace(/\B(?=(\d{3})+(?!\d))/g,","),g=o?`${c}.${o}`:c;return t?`-${g}`:g}function Kt(e){if(e==null||e==="")return"0";let t=String(e),n=Number(t);return!Number.isFinite(n)||n===0?"0":Mr(Lr(t,4))}function Bn(e,t){if(e==null||e==="")return"0";try{return Dr(Pt(BigInt(String(e)),t.decimals))}catch{return"0"}}function Ut(e){return!!(e&&/^0x[0-9a-fA-F]+$/.test(e))}function Gr(e){return e?new Date(e*1e3).toISOString():new Date().toISOString()}function Kr(e,t){return t.toLowerCase()===e.contracts.W_CROSS.toLowerCase()?e.contracts.NATIVE_CROSS:t}function Ur(e,t){let n=Wr(t);return{name:n,symbol:n,chainId:e,address:t,decimals:pt,balance:"0"}}function _n({envConfig:e,tokenByBridgeKey:t,chainId:n,address:i}){if(!i)return null;let o=Kr(e,i);return t.get(se(n,o))||t.get(se(n,i))||Ur(n,o)}function St(e){return e?.toLowerCase()||""}function $r(e){if(e.source==="swap")return"swap";let t=St(e.fromToken??e.from_token),n=St(e.toToken??e.to_token),i=St(e.swapTokenIn??e.swap_token_in),o=St(e.swapTokenOut??e.swap_token_out);return n&&i&&n===i?"bridge-swap":t&&o&&t===o?"swap-bridge":"bridge"}function qr(e,t){let n=e.status??0,i=e.extracallSuccess??e.extracall_success??!1;return t==="bridge-swap"&&n===1&&!i?"failed":n===1?"success":"pending"}function Hr({envConfig:e,item:t,tokenByBridgeKey:n}){let i=Number(t.fromChainID??t.from_chain_id??0),o=Number(t.toChainID??t.to_chain_id??0);if(!i||!o)return null;let c=$r(t),g=t.swapTokenIn??t.swap_token_in,y=t.swapTokenOut??t.swap_token_out,p=t.swapAmountIn??t.swap_amount_in,r=t.swapAmountOut??t.swap_amount_out,f=t.fromToken??t.from_token,w=t.toToken??t.to_token,C=t.value,m=t.value;c==="swap"?(f=g,w=y,C=p,m=r):c==="swap-bridge"?(f=g,C=p,m=t.value):c==="bridge-swap"&&(w=y,C=p,m=r);let k=_n({envConfig:e,tokenByBridgeKey:n,chainId:i,address:f}),x=_n({envConfig:e,tokenByBridgeKey:n,chainId:o,address:w}),v=t.initiatedTxHash??t.initiated_tx_hash;return!k||!x||!Ut(v)?null:{id:`${v}-${t.index??""}`,timestamp:Gr(t.initiatedTime??t.initiated_time),txHash:v,fromToken:k,toToken:x,fromAmount:Bn(C,k),toAmount:Bn(m,x),summary:{pathType:c},status:qr(t,c)}}function Vr(e){let t=new Map;return e.flat().forEach(n=>{let i=Number(n.chainId??n.chain_id),o=n.address?.toLowerCase();if(!i||!o)return;let c=n.quantity?.numeric??n.balance??"0",g=n.quantity?.decimals??n.decimals??pt;try{t.set(se(i,o),Pt(BigInt(c||"0"),g))}catch{t.set(se(i,o),"0")}}),t}function Ue(e,t="first"){let n=e.steps.filter(i=>i.type==="swap");return t==="last"?n[n.length-1]:n[0]}function jr(e,t){let n=(e?.swapPools||e?.swap_pools)?.[String(t.chainIds.cross)];if(!n?.length)return"";let i=t.contracts.CROSSD.toLowerCase(),o=t.contracts.USDTX.toLowerCase(),c=n.find(g=>{let y=g.token0?.toLowerCase(),p=g.token1?.toLowerCase();return y===i&&p===o||y===o&&p===i});return c?.poolAddress||c?.pool_address||""}function Qr(e,t){return e.from.chainId===t.chainIds.cross&&e.from.address.toLowerCase()===t.contracts.CROSSD.toLowerCase()&&e.to.chainId===t.chainIds.bsc&&e.to.address.toLowerCase()===t.contracts.USDTB.toLowerCase()}function zr(e){if(e===void 0)return;let t=10n**BigInt(pt),n=e>=50000n*t?"normal":e>10000n*t?"low":"rebalancing",i=Number(e>0n?e*100n/(100000n*t):0n);return{label:"Available Liquidity",status:n,percentage:Math.min(i,100)}}function ut(e,t,n,i){let o=[e.from,e.to].find(c=>c.chainId===t&&c.address.toLowerCase()===n.toLowerCase())??i?.[se(t,n)];return{symbol:o?.symbol||n.slice(0,6),iconUrl:o?.image}}function Xr(e,t){let n=[];for(let o of e.steps)o.type==="swap"?(n.push({chain:o.chain,address:o.fromToken}),n.push({chain:o.chain,address:o.toToken})):(n.push({chain:o.fromChain,address:o.fromToken}),n.push({chain:o.toChain,address:o.toToken}));let i=n.filter((o,c)=>c===0||!(o.chain===n[c-1].chain&&o.address.toLowerCase()===n[c-1].address.toLowerCase()));return i.length===0?[{symbol:e.from.symbol,iconUrl:e.from.image},{symbol:e.to.symbol,iconUrl:e.to.image}]:i.map(o=>ut(e,o.chain,o.address,t))}function Yr({input:e,path:t,amountData:n,gasInfo:i,liquidity:o,enrichedTokens:c,priceImpact:g}){let y=e.fromAmount||"0",p=e.toAmount||"0",r=Ue(t),f=t.steps.find(V=>V.type==="bridge"),w=t.type!=="bridge",C=!We(t.type),m=r?vr(y,r.fee):"0",k=Number(y)>0||Number(p)>0,x=r?ut(t,r.chain,r.fromToken,c):{symbol:e.fromToken.symbol,iconUrl:e.fromToken.iconUrl},v=r?ut(t,r.chain,r.toToken,c):{symbol:e.toToken.symbol,iconUrl:e.toToken.iconUrl},W=f?ut(t,f.fromChain,f.fromToken,c):void 0,I=(V,G,N)=>k?G&&G>0n?{label:V,value:st(G),tone:"default",valueToken:N}:{label:V,value:"Free",tone:"accent"}:{label:V,value:"0"};return{pathType:t.type,priceImpact:g,liquidity:o,bridgeInfo:C&&f?[{label:"Route",value:`${In(f.fromChain)} \u2192 ${In(f.toChain)}`},I("Validator Fee",n?.exFee,W),I("Network Fee",n?.networkFee,W)]:void 0,swapInfo:w&&r?[{label:"Route",value:"",routeTokens:[ut(t,r.chain,r.fromToken,c),ut(t,r.chain,r.toToken,c)]},{label:"Price Impact",value:Tr(g)},{label:"In Amount",value:Kt(y),valueToken:x},{label:r&&We(t.type)?`Swap Fee (${Ir(r.fee??Se)})`:"Swap Fee",value:Kt(m),valueToken:x},{label:"Out Amount",value:Kt(p),valueToken:v}]:void 0,txFee:[...i?.gasPrice?[{label:"Gas Price",value:`${i.gasPrice} Gwei`}]:[{label:"Priority Fee Per Gas",value:`${i?.priorityFeePerGas||"0"} Gwei`},{label:"Max Fee Per Gas",value:`${i?.maxFeePerGas||"0"} Gwei`}],{label:"Gas Limit",value:i?.gasLimit||"0"}],txFeeInfo:i?{estTxFee:i.estTxFee,isDelegateFee:i.isDelegateFee,tokenIconUrl:i.gasCurrencyIconUrl,tokenSymbol:i.gasCurrencySymbol}:{estTxFee:"0",isDelegateFee:!1}}}function $t({env:e,walletAddress:t,enabled:n=!0,restoreChainAfterSwitch:i=!0}){let o=tr(),c=Xo(new Map),y=ze({queryKey:["crossd-bridge-adapter",e,"remote-contracts"],queryFn:async({signal:s})=>{let a=gr(await Fe(lr[e],s),e);if(!a)throw new Error("CrossD bridge adapter: invalid contracts.json");return a},enabled:n,staleTime:5*6e4}).data??null,p=n&&!!y,r=ve(()=>({...yr[e],contracts:y??pr}),[e,y]),f=ze({queryKey:["crossd-bridge-adapter",e,"pairs"],queryFn:({signal:s})=>Fe(`${r.bridgeApi}/pairs`,s),enabled:p,staleTime:3e4}),w=ze({queryKey:["crossd-bridge-adapter",e,"swap-pools"],queryFn:({signal:s})=>Fe(`${r.bridgeApi}/swap-pools`,s),enabled:p,staleTime:3e4}),C=ve(()=>jr(w.data,r),[r,w.data]),m=ze({queryKey:["crossd-bridge-adapter",e,"available-liquidity",C],queryFn:async()=>await _e(o,{address:r.contracts.USDTX,abi:Mt,functionName:"balanceOf",args:[C],chainId:r.chainIds.cross}),enabled:p&&!!C,staleTime:3e4}),k=ze({queryKey:["crossd-bridge-adapter",e,"token-info"],queryFn:({signal:s})=>Fe(`${r.walletApi}/v1/public/token/info`,s),enabled:p,staleTime:3e4}),x=ze({queryKey:["crossd-bridge-adapter",e,"token-stats"],queryFn:({signal:s})=>Fe(`${r.walletApi}/v1/public/token/stats`,s),enabled:p,staleTime:3e4}),v=wn({queries:[r.chainIds.cross,r.chainIds.bsc].map(s=>({queryKey:["crossd-bridge-adapter",e,"balance",t,s],queryFn:({signal:a})=>{let d=new URLSearchParams({networkId:`eip155:${s}`,account:t||""});return Fe(`${r.walletApi}/v1/public/token/balance?${d}`,a)},enabled:p&&!!t,staleTime:0,refetchInterval:p&&t?5e3:!1}))}),W=wn({queries:[r.chainIds.cross,r.chainIds.bsc].map(s=>({queryKey:["crossd-bridge-adapter",e,"gas-suggestion",s],queryFn:async({signal:a})=>{try{let b=await En(o,{chainId:s})?.estimateFeesPerGas?.();if(b?.maxFeePerGas||b?.gasPrice)return{fast:{maxFee:b.maxFeePerGas?.toString()||b.gasPrice?.toString(),maxPriorityFee:b.maxPriorityFeePerGas?.toString()||"0"}}}catch{}let d=new URLSearchParams({chain_id:String(s),without_gas_limit:"false"});return Fe(`${r.walletApi}/v1/public/transaction/gas-suggestion/dynamic?${d}`,a)},enabled:p,staleTime:1e4,retry:1}))}),I=ze({queryKey:["crossd-bridge-adapter",e,"hidden-pairs"],queryFn:async({signal:s})=>dr(await Fe(ar[e],s),e),enabled:p,staleTime:5*6e4,retry:1}),V=ve(()=>I.data??[],[I.data]),G=ve(()=>Er({envConfig:r,bridgePairList:f.data,swapPools:w.data,tokenInfo:k.data,tokenStats:x.data}),[f.data,r,w.data,k.data,x.data]),N=ve(()=>Fr({envConfig:r,bridgePairList:f.data,swapPools:w.data,enrichedTokens:G}),[f.data,G,r,w.data]),j=ve(()=>Vr(v.map(s=>s.data).filter(s=>Array.isArray(s))),[v]),z=ve(()=>{let s=new Map;return Object.values(G).forEach(a=>{let d=Rn(a,j);s.set(a.key,d)}),s},[j,G]),X=ve(()=>{let s=new Map,a=z.get(se(r.chainIds.cross,r.contracts.NATIVE_CROSS));a&&s.set(r.chainIds.cross,{symbol:a.symbol,iconUrl:a.iconUrl});let d=k.data?.find(u=>Number(u.chainId??u.chain_id)===r.chainIds.bsc&&(u.symbol??"").toUpperCase()==="BNB");return d&&s.set(r.chainIds.bsc,{symbol:d.symbol??"BNB",iconUrl:d.image??d.icon_url}),s},[r,z,k.data]),D=ze({queryKey:["crossd-bridge-adapter",e,"history",t],queryFn:({signal:s})=>xn(`${r.bridgeApi}/history`,{owner:t,page:1,size:20,sort:"desc",status:"all"},s),enabled:p&&!!t,staleTime:0,refetchInterval:p&&t?5e3:!1}),K=ve(()=>(D.data?.histories||[]).map(s=>Hr({envConfig:r,item:s,tokenByBridgeKey:z})).filter(s=>!!s),[D.data?.histories,r,z]),Pe=ve(()=>zr(m.data),[m.data]),fe=W[0]?.data,O=W[1]?.data,R=ve(()=>{let s=new Map;return fe&&s.set(r.chainIds.cross,fe),O&&s.set(r.chainIds.bsc,O),s},[O,fe,r.chainIds.bsc,r.chainIds.cross]),Y=oe((s,a,d)=>{let u=R.get(s.from.chainId)?.fast,b=a?d?.gasLimit??It(s.type):0n,B=d?.gasPrice&&d.gasPrice>0n?d.gasPrice:0n,_=d?.maxFeePerGas&&d.maxFeePerGas>0n?d.maxFeePerGas:0n,A=d?.maxPriorityFeePerGas&&d.maxPriorityFeePerGas>0n?d.maxPriorityFeePerGas:0n,L=Xe(u?.maxFee??u?.max_fee),Z=Xe(u?.maxPriorityFee??u?.max_priority_fee),S=_>0n?_:L>0n?L:B,F=A>0n?A:Z>0n?Z:S,q=B>0n?B:S,Q=On.has(s.from.chainId)&&q>0n,l=b*(Q?q:S),h=z.get(se(s.from.chainId,r.contracts.NATIVE_CROSS)),T=s.type!=="swap-bridge",P=X.get(s.from.chainId);return{estTxFee:a?st(l):"0",priorityFeePerGas:a&&!Q?Gt(F):"0",maxFeePerGas:a&&!Q?Gt(S):"0",gasLimit:a?b.toString():"0",gasPrice:a&&Q?Gt(q):void 0,isDelegateFee:s.type==="swap-bridge"?!1:Sr(r,s.from.address,s.to.address),tokenIconUrl:T?h?.iconUrl:void 0,tokenSymbol:T?h?.symbol:void 0,gasCurrencyIconUrl:P?.iconUrl,gasCurrencySymbol:P?.symbol}},[r,R,X,z]),$=oe(async s=>{let a=Pr(s);if(!a)return null;let d=`${e}:${a.from}:${a.to}:${a.token.toLowerCase()}`,u=c.current.get(d);if(u)return u;let b=(async()=>{let B=new URLSearchParams({from:String(a.from),to:String(a.to),token:a.token});try{return(await Fe(`${r.bridgeApi}/token-config?${B}`)).config??null}catch{return null}})();return c.current.set(d,b),b},[e,r.bridgeApi]),ce=ve(()=>{let s=Object.values(G).map(d=>Rn(d,j)),a=se(r.chainIds.cross,r.contracts.CROSSD);return s.sort((d,u)=>{let b=pe(d).toLowerCase()===a.toLowerCase(),B=pe(u).toLowerCase()===a.toLowerCase();return b!==B?b?-1:1:pe(d).localeCompare(pe(u))})},[j,G,r]),Te=oe(s=>{let a=pe(s),d=a.toLowerCase(),u=[];Object.keys(G).forEach(_=>{let A=_.toLowerCase();if(d===A||V.some(S=>S.fromKey===d&&S.toKey===A))return;let L=N(a,_);if(!L)return;let Z=z.get(_);Z&&u.push({token:Z,path:L})});let b=se(r.chainIds.cross,r.contracts.CROSSD),B=se(r.chainIds.cross,r.contracts.NATIVE_CROSS);return u.sort((_,A)=>{if(d===b.toLowerCase()){let q=pe(_.token).toLowerCase()===B.toLowerCase(),Q=pe(A.token).toLowerCase()===B.toLowerCase();if(q!==Q)return q?-1:1}let L=We(_.path.type),Z=We(A.path.type);if(L!==Z)return L?-1:1;let S=_.token.chainId===s.chainId,F=A.token.chainId===s.chainId;return S!==F?S?-1:1:pe(_.token).localeCompare(pe(A.token))}),u.map(_=>_.token)},[G,r,N,V,z]),Le=oe(async s=>await _e(o,{address:r.contracts.SWAP_BRIDGE_ROUTER,abi:rt,functionName:"quoter",chainId:s}),[r.contracts.SWAP_BRIDGE_ROUTER,o]),xe=oe(async s=>{Lt(o)!==s&&await hn(o,{chainId:s})},[o]),Ee=oe(s=>Tt({getChainId:()=>Lt(o),switchChain:a=>hn(o,{chainId:a})},s,i),[i,o]),ye=oe(async s=>await _e(o,{address:r.contracts.SWAP_BRIDGE_ROUTER,abi:rt,functionName:"swapRouter",chainId:s}),[r.contracts.SWAP_BRIDGE_ROUTER,o]),Me=oe(async({path:s,step:a,amount:d,source:u})=>{let b=await Le(a.chain),B=a.poolAddress?_e(o,{address:a.poolAddress,abi:br,functionName:"slot0",chainId:a.chain}).then(L=>L?.[0]).catch(()=>{}):Promise.resolve(void 0);if(u==="from"){let L=await _e(o,{address:b,abi:Tn,functionName:"quoteExactInputSingle",args:[{tokenIn:re(r,a.fromToken),tokenOut:re(r,a.toToken),amountIn:bt(d),fee:a.fee??Se,sqrtPriceLimitX96:0n}],chainId:a.chain}),Z=vn(await B,L[1]);return{amount:st(L[0]),path:s,priceImpact:Z}}let _=await _e(o,{address:b,abi:Tn,functionName:"quoteExactOutputSingle",args:[{tokenIn:re(r,a.fromToken),tokenOut:re(r,a.toToken),amount:bt(d),fee:a.fee??Se,sqrtPriceLimitX96:0n}],chainId:a.chain}),A=vn(await B,_[1]);return{amount:st(_[0]),path:s,priceImpact:A}},[r,Le,o]),de=oe(async(s,a)=>{if(!t)throw new Error("Wallet is not connected.");let d=It(a.type);if(We(a.type)){let S=Ue(a,"first");if(!S)throw new Error("Swap route is not available.");let F=ge(s.fromAmount),q=ge(s.toAmount);if(F<=0n)throw new Error("Bridge amount is empty.");if(q<=0n)throw new Error("Bridge quote is not ready.");let Q=await ye(S.chain),U=xt(q,s.slippage),l=a.type==="swap-withdraw"?$e:t,h={tokenIn:re(r,S.fromToken),tokenOut:re(r,S.toToken),fee:S.fee??Se,recipient:l,deadline:yt(),amountIn:F,amountOutMinimum:U,sqrtPriceLimitX96:0n};if(a.type==="swap-withdraw"){let T=gt({abi:Ke,functionName:"exactInputSingle",args:[h]}),P=gt({abi:Ke,functionName:"unwrapWETH9",args:[U,t]});return{address:Q,abi:Ke,functionName:"multicall",args:[[T,P]],chainId:S.chain,fallbackGasLimit:d}}if(a.type==="deposit-swap"){let T=gt({abi:Ke,functionName:"exactInputSingle",args:[h]}),P=gt({abi:Ke,functionName:"refundETH",args:[]});return{address:Q,abi:Ke,functionName:"multicall",args:[[T,P]],value:F,chainId:S.chain,fallbackGasLimit:d}}return{address:Q,abi:Ke,functionName:"exactInputSingle",args:[h],chainId:S.chain,fallbackGasLimit:d}}if(a.type==="swap-bridge"){let S=Ue(a,"first");if(!S)throw new Error("Swap bridge route is not available.");let F=ge(s.fromAmount),q=ge(s.toAmount);if(F<=0n)throw new Error("Bridge amount is empty.");if(q<=0n)throw new Error("Bridge quote is not ready.");let Q=r.contracts.SWAP_BRIDGE_ROUTER,U=yt(),l={toChainID:BigInt(a.to.chainId),recipient:t,extraData:"0x"},h={tokenIn:re(r,a.from.address),tokenOut:re(r,S.toToken),fee:S.fee??Se,sqrtPriceLimitX96:0n,bridgeParams:l};if(s.lastChangedBy==="to"){let P={...h,amountOut:q,amountInMaximum:bn(F,s.slippage)};return{address:Q,abi:rt,functionName:"swapBridgeExactOutputSingle",args:[P,U],value:a.from.isNativeToken?P.amountInMaximum:void 0,chainId:a.from.chainId,fallbackGasLimit:d}}let T={...h,amountIn:F,amountOutMinimum:xt(q,s.slippage)};return{address:Q,abi:rt,functionName:"swapBridgeExactInputSingle",args:[T,U],value:a.from.isNativeToken?F:void 0,chainId:a.from.chainId,fallbackGasLimit:d}}let u=a.steps.find(S=>S.type==="bridge");if(!u?.bridgeAddress)throw new Error("Bridge route is not available.");let b=ge(s.fromAmount);if(b<=0n)throw new Error("Bridge amount is empty.");let B=await $(a),_=Xe(B?.gasFee??B?.gas_fee),A=An(b,B?.exFeeRate??B?.ex_fee_rate),L="0x";if(a.type==="bridge-swap"){let S=Ue(a,"last");if(!S)throw new Error("Bridge swap route is not available.");let F=ge(s.toAmount);if(F<=0n)throw new Error("Bridge quote is not ready.");let q=await ye(a.to.chainId),Q=xt(F,s.slippage),U=gt({abi:Ke,functionName:"exactInputSingle",args:[{tokenIn:re(r,S.fromToken),tokenOut:re(r,S.toToken),fee:S.fee??Se,recipient:t,deadline:yt(),amountIn:b,amountOutMinimum:Q,sqrtPriceLimitX96:0n}]});L=`${q}${U.slice(2)}`}let Z=[BigInt(a.to.chainId),a.from.address,t,b,_,A,L];return{address:u.bridgeAddress,abi:wr,functionName:"bridgeToken",args:Z,value:a.from.isNativeToken?b+A+_:void 0,chainId:a.from.chainId,fallbackGasLimit:d}},[r,$,ye,t]),Je=oe(async(s,a)=>{if(a.type==="bridge"||a.type==="bridge-swap")return de(s,a);if(!t)throw new Error("Wallet is not connected.");let d=ge(s.fromAmount);if(d<=0n)throw new Error("Bridge amount is empty.");if(a.type==="swap-bridge"){let _=Ue(a,"first");if(!_)throw new Error("Swap bridge route is not available.");let A=r.contracts.SWAP_BRIDGE_ROUTER,L={tokenIn:re(r,a.from.address),tokenOut:re(r,_.toToken),fee:_.fee??Se,sqrtPriceLimitX96:0n,bridgeParams:{toChainID:BigInt(a.to.chainId),recipient:t,extraData:"0x"},amountIn:d,amountOutMinimum:0n};return{address:A,abi:rt,functionName:"swapBridgeExactInputSingle",args:[L,yt()],value:a.from.isNativeToken?d:void 0,chainId:a.from.chainId,fallbackGasLimit:It(a.type)}}let u=Ue(a,"first");if(!u)throw new Error("Swap route is not available.");let b=await ye(u.chain),B={tokenIn:re(r,u.fromToken),tokenOut:re(r,u.toToken),fee:u.fee??Se,recipient:t,deadline:yt(),amountIn:d,amountOutMinimum:0n,sqrtPriceLimitX96:0n};return{address:b,abi:Ke,functionName:"exactInputSingle",args:[B],value:a.from.isNativeToken?d:void 0,chainId:u.chain,fallbackGasLimit:It(a.type)}},[de,r,ye,t]),et=oe(async(s,a)=>{if(!t)return null;try{let d=await Je(s,a),u=We(a.type)||a.type==="swap-bridge",b=await Sn(o,d.chainId,d.fallbackGasLimit,u,{account:t,address:d.address,abi:d.abi,functionName:d.functionName,args:d.args,value:d.value},!0);return{gasLimit:b.gas,gasPrice:b.gasPrice,maxFeePerGas:b.maxFeePerGas,maxPriorityFeePerGas:b.maxPriorityFeePerGas}}catch{return null}},[Je,o,t]),Ae=oe(async s=>{let a=pe(s.fromToken),d=pe(s.toToken),u=N(a,d);if(!u)return{error:"Route is not available."};let b=s.lastChangedBy==="to"?s.toAmount:s.fromAmount,B=!!b&&Number(b)>0,_=Qr(u,r)?Pe:void 0,A=async(U,l,h)=>{let T=B?await et(U,u):null,P=Y(u,B,T);return Yr({input:U,path:u,gasInfo:P,amountData:l,liquidity:_,enrichedTokens:G,priceImpact:h})};if(!b||Number(b)<=0)return{fromAmount:s.fromAmount,toAmount:s.toAmount,summary:await A(s)};let L=await $(u),Z=Xe(L?.gasFee??L?.gas_fee),S=u.type==="bridge"||u.type==="bridge-swap"?{networkFee:Z}:void 0,F=u.type==="bridge"?s.lastChangedBy==="to"?{...s,fromAmount:s.toAmount}:{...s,toAmount:s.fromAmount}:s,q=Ar({input:F,path:u,config:L});if(q)return{fromAmount:F.fromAmount,toAmount:F.toAmount,summary:await A(F,S),error:q};let Q=Rr({input:F,path:u,config:L});if(Q)return{fromAmount:F.fromAmount,toAmount:F.toAmount,summary:await A(F,S),error:Q};if(u.type==="bridge")return{fromAmount:F.fromAmount,toAmount:F.toAmount,summary:await A(F,S)};try{if(u.type==="swap-bridge"){let T=Ue(u,"first"),P=r.contracts.SWAP_BRIDGE_ROUTER;if(!T)return{error:"Swap bridge route is not ready."};let E=Oe=>Me({path:u,step:T,amount:Oe,source:"from"}).then(Ve=>Ve.priceImpact).catch(()=>{});if(s.lastChangedBy==="from"){let Oe=await _e(o,{address:P,abi:rt,functionName:"getAmountSwapBridgeOut",args:[BigInt(u.to.chainId),re(r,u.from.address),re(r,T.toToken),T.fee??Se,bt(s.fromAmount)],chainId:u.from.chainId}),Ve=st(Oe[1]),_t={...s,toAmount:Ve};return{toAmount:Ve,summary:await A(_t,{networkFee:Oe[3],exFee:Oe[4]},await E(s.fromAmount))}}let le=await _e(o,{address:P,abi:rt,functionName:"getAmountSwapBridgeIn",args:[BigInt(u.to.chainId),re(r,u.from.address),re(r,T.toToken),T.fee??Se,bt(s.toAmount)],chainId:u.from.chainId}),He=st(le[1]),nt={...s,fromAmount:He};return{fromAmount:He,summary:await A(nt,{networkFee:le[3],exFee:le[4]},await E(He))}}let U=u.type==="bridge-swap"?Ue(u,"last"):Ue(u,"first");if(!U)return{error:"Swap route is not available."};let l=await Me({path:u,step:U,amount:b,source:s.lastChangedBy});if(s.lastChangedBy==="from"){let T={...s,toAmount:l.amount};return{toAmount:l.amount,summary:await A(T,S,l.priceImpact)}}let h={...s,fromAmount:l.amount};return{fromAmount:l.amount,summary:await A(h,S,l.priceImpact)}}catch(U){return{fromAmount:s.fromAmount,toAmount:s.toAmount,summary:await A(s,S),error:kr(U)}}},[Pe,Y,G,r,et,N,$,Me,o]),tt=oe(async s=>{if(s.from.isNativeToken)return null;if(s.type==="swap"||s.type==="deposit-swap"||s.type==="swap-withdraw")return ye(s.from.chainId);if(s.type==="swap-bridge")return r.contracts.SWAP_BRIDGE_ROUTER;let a=s.steps.find(d=>d.type==="bridge");return a?.bridgeAddress?a.bridgeAddress:null},[r.contracts.SWAP_BRIDGE_ROUTER,ye]),ct=oe(async s=>{if(!t)throw new Error("Wallet is not connected.");let a=pe(s.fromToken),d=pe(s.toToken),u=N(a,d);if(!u)throw new Error("Route is not available.");if(!We(u.type)&&u.type!=="swap-bridge"||u.from.isNativeToken)return null;let b=ge(s.fromAmount);if(b<=0n)return null;let B=await tt(u);return!B||await _e(o,{address:u.from.address,abi:Mt,functionName:"allowance",args:[t,B],chainId:u.from.chainId})>=b?null:{token:s.fromToken,tokenAddress:u.from.address,spenderAddress:B,amount:s.fromAmount}},[N,tt,o,t]),Re=oe(async(s,a)=>{let d=ge(a.amount||s.fromAmount);if(d<=0n)throw new Error("Approval amount is empty.");await xe(a.token.chainId);let u=await Cn(o,{address:a.tokenAddress,abi:Mt,functionName:"approve",args:[a.spenderAddress,d],chainId:a.token.chainId});await er(o,{hash:u,chainId:a.token.chainId})},[xe,o]),be=oe(async(s,a)=>{let d=await de(s,a);await xe(d.chainId);let u=await Sn(o,d.chainId,d.fallbackGasLimit,nr(a.type),{account:t,address:d.address,abi:d.abi,functionName:d.functionName,args:d.args,value:d.value});return{txHash:await Cn(o,{address:d.address,abi:d.abi,functionName:d.functionName,args:d.args,value:d.value,chainId:d.chainId,...u}),fromToken:s.fromToken,toToken:s.toToken,fromAmount:s.fromAmount,toAmount:s.toAmount}},[de,xe,o,t]),we=oe(async(s,a)=>{let d=t;if(!d)throw new Error("Wallet is not connected.");let u=a.steps.find(Ve=>Ve.type==="bridge");if(!u?.bridgeAddress)throw new Error("Bridge route is not available.");let b=a.from.address,B=a.from.chainId,_=ge(s.fromAmount);if(_<=0n)throw new Error("Bridge amount is empty.");let A=await $(a),L=Xe(A?.gasFee??A?.gas_fee),Z=An(_,A?.exFeeRate??A?.ex_fee_rate),S=_+Z+L,[F,q]=await Promise.all([_e(o,{address:b,abi:kn,functionName:"name",chainId:B}),_e(o,{address:b,abi:kn,functionName:"nonces",args:[d],chainId:B})]),Q=BigInt(Math.floor(Date.now()/1e3)+300),U=await Jo(o,{domain:{name:F,version:"1",chainId:B,verifyingContract:b},types:{Permit:[{name:"owner",type:"address"},{name:"spender",type:"address"},{name:"value",type:"uint256"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]},primaryType:"Permit",message:{owner:d,spender:u.bridgeAddress,value:S,nonce:q,deadline:Q}}),{r:l,s:h,v:T,yParity:P}=Yo(U),E=T!==void 0?Number(T):P+27,le={exFee:Z.toString(),from:B,fromToken:b,nonce:Number(q),gasFee:L.toString(),permitArgs:{account:d,deadline:Q.toString(),r:l,s:h,token:b,v:E,value:S.toString()},to:d,toChainID:String(a.to.chainId),value:S.toString()},He=await xn(`${r.bridgeApi}/permit`,le),nt=He?.requestId??He?.request_id;if(!nt)throw new Error("Bridge permit request failed.");let Oe=await Cr(r.bridgeApi,nt);if(!Ut(Oe))throw new Error("Bridge submitted, but confirmation timed out. Check History shortly.");return{txHash:Oe,fromToken:s.fromToken,toToken:s.toToken,fromAmount:s.fromAmount,toAmount:s.toAmount}},[r,$,o,t]),qe=oe(async s=>{let a=Lt(o),d=pe(s.fromToken),u=pe(s.toToken),b=N(d,u);if(!b)throw new Error("Route is not available.");if(!(We(b.type)||b.type==="swap-bridge"||b.type==="bridge-swap"||b.type==="bridge"))throw new Error("This bridge route is not supported yet.");let A=b.type==="bridge"&&b.from.chainId===r.chainIds.bsc&&b.from.address.toLowerCase()===r.contracts.BSC_CROSS.toLowerCase()?await we(s,b):await be(s,b);return await Ee(a),{...A,pathType:b.type,routeTokens:Xr(b,G)}},[G,r,N,Ee,we,be,o]);return{bridgeTokens:ce,bridgeHistory:K,getBridgeApproval:ct,approveBridge:Re,getBridgeQuote:Ae,getBridgeToTokens:Te,submitBridge:qe,isLoading:f.isLoading||w.isLoading||k.isLoading||x.isLoading||v.some(s=>s.isLoading)}}import{useEffect as Mn,useRef as Zr,useState as Gn}from"react";import{useAccount as Jr}from"wagmi";function qt(e){let{address:t,connector:n}=Jr(),{currentWallet:i}=Ge(),o=e?.walletId!==void 0?e.walletId:i,c=e?.connector!==void 0?e.connector:n,g=e?.address!==void 0?e.address:t,[y,p]=Gn({loginType:null,accountName:null,accounts:[],isResolved:!1}),r=Zr(new Map),[f,w]=Gn(0);return Mn(()=>{let C=!1;if(o!=="cross_embedded")return p({loginType:null,accountName:null,accounts:[],isResolved:!0}),()=>{C=!0};if(!c)return p({loginType:null,accountName:null,accounts:[],isResolved:!1}),()=>{C=!0};p(v=>({...v,isResolved:!1}));let m=20,k=300,x=async()=>{if(typeof c.getProvider!="function")return"retry";let v;try{v=await c.getProvider()}catch{return"retry"}let W=v?.sdk;if(!W)return"giveup";try{let O=W.getRNBridgeActiveWallet?.(),R=O?.walletName?.trim();O&&R&&r.current.set(O.address.toLowerCase(),R)}catch{}let[I,V]=await Promise.all([W.getUserInfo?.().catch(()=>null)??null,W.getAddresses?.().catch(()=>null)??null]);if(C)return"done";let G=I?.loginType,N=G==="google"||G==="apple"?G:null;if(!N)return"retry";let j=g?.toLowerCase(),z=j&&Array.isArray(V)?V.find(O=>O.address.toLowerCase()===j):null,X=Array.isArray(V)?V.filter(O=>/^0x[a-fA-F0-9]{40}$/.test(O.address)).map(O=>({address:O.address.toLowerCase(),...Number.isFinite(O.index)?{index:O.index}:{},...O.name?.trim()?{name:O.name.trim()}:{}})):[],D=j?r.current.get(j)?.trim():void 0,K=!z&&j&&/^0x[a-fA-F0-9]{40}$/.test(j)?[...X,{address:j,index:X.length,...D?{name:D}:{}}]:X,fe=D||z?.name?.trim()||(typeof z?.index=="number"?`Account ${z.index+1}`:g?`${g.slice(0,6)}\u2026${g.slice(-4)}`:null);return p({loginType:N,accountName:fe,accounts:K,isResolved:!0}),"done"};return(async()=>{for(let v=0;v<m;v++){if(C)return;let W=await x();if(W==="done")return;if(W==="giveup"){C||p({loginType:null,accountName:null,accounts:[],isResolved:!0});return}await new Promise(I=>setTimeout(I,k))}C||p({loginType:null,accountName:null,accounts:[],isResolved:!0})})(),()=>{C=!0}},[o,c,g,f]),Mn(()=>{if(o!=="cross_embedded"||!c||typeof c.getProvider!="function")return;let C=!1,m;return(async()=>{let k;try{k=await c.getProvider()}catch{return}if(C)return;let x=k?.sdk;x?.on&&(m=x.on("addressChanged",({address:v,walletName:W})=>{let I=W?.trim();I&&(r.current.set(v.toLowerCase(),I),w(V=>V+1))}))})(),()=>{C=!0,m?.()}},[o,c]),y}import{Fragment as $n,jsx as me,jsxs as it}from"react/jsx-runtime";var us=[{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"}],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"totalSupply",stateMutability:"view",inputs:[],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"decimals",stateMutability:"view",inputs:[],outputs:[{name:"",type:"uint8"}]}],ps=[{type:"function",name:"earned",stateMutability:"view",inputs:[{name:"account",type:"address"}],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"}],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"posaActive",stateMutability:"view",inputs:[],outputs:[{name:"",type:"bool"}]},{type:"function",name:"lastRewardBlock",stateMutability:"view",inputs:[],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"totalStaked",stateMutability:"view",inputs:[],outputs:[{name:"",type:"uint256"}]}],ms={dev:{poolAddress:"0x0000000c5BB5C7B081237B5efaFC753D61201b94",crossChainId:612044,networkStatsUrl:"https://stg-posa-api.crosstoken.io/api/v1/network/stats"},stage:{poolAddress:"0x0000000c5BB5C7B081237B5efaFC753D61201b94",crossChainId:612044,networkStatsUrl:"https://stg-posa-api.crosstoken.io/api/v1/network/stats"},production:{poolAddress:"0x000000068122d9bB43B4BCF5497A10EdfA9F5E93",crossChainId:612055,networkStatsUrl:"https://posa-api.crosstoken.io/api/v1/network/stats"}},jt=10n**18n,fs={google:{name:"Google",iconUrl:Hn,connectorId:Ze.CROSSx},apple:{name:"Apple",iconUrl:Xt,connectorId:Ze.CROSSx},cross:{name:Rt.default,iconUrl:zt,connectorId:Ze.CROSSx},metamask:{name:"MetaMask",iconUrl:Vn,connectorId:Ze.MetaMask},binance:{name:"Binance Wallet",iconUrl:qn,connectorId:Ze.Binance}};function gs(e){switch(e){case"cross_embedded":return Ze.CROSSx;case"metamask":return Ze.MetaMask;case"binance":return Ze.Binance;default:return}}function ys(e,t){switch(e){case"cross_embedded":return t==="google"?{name:"Google",iconUrl:Hn}:t==="apple"?{name:"Apple",iconUrl:Xt}:{name:Rt.default,iconUrl:zt};case"cross_wallet":return{name:Rt.default,iconUrl:zt};case"cross_extension":return{name:Rt.extension,iconUrl:ls};case"metamask":return{name:"MetaMask",iconUrl:Vn};case"binance":return{name:"Binance Wallet",iconUrl:qn};default:return null}}function bs({label:e="Connect Wallet",className:t,style:n,walletInfoStyle:i,user:o,enablePortfolio:c,portfolio:g,theme:y,accountName:p,connectorId:r,showPortfolio:f,sendAccounts:w,getTransactionReceipt:C,sendTransaction:m,estimateGas:k,onDisconnect:x,onSelectWallet:v,onBuy:W,onRampRedirectUrl:I,bridgeTokens:V,bridgeHistory:G,getBridgeQuote:N,getBridgeToTokens:j,getBridgeApproval:z,approveBridge:X,submitBridge:D,showBalance:K=!0,env:Pe,...fe}){let{address:O,isConnected:R,connector:Y,chain:$}=ns(),ce=rs(),Te=os(),{switchChainAsync:Le}=is(),{sendTransactionAsync:xe}=ss(),{connectWallet:Ee,disconnect:ye,selectWallet:Me,currentWallet:de,isConnecting:Je,kitConfig:et}=Ge(),Ae=et?.restoreChainAfterSwitch!==!1,tt=ft(),ct=y??tt?.mode??"dark",Re=At(()=>as(Pe),[Pe]),be=o?.address??O,we=o?fs[o.provider]:null,{loginType:qe,accountName:s,accounts:a}=qt({walletId:de,connector:Y,address:be}),d=At(()=>we?{name:we.name,iconUrl:we.iconUrl}:ys(de,qe),[we,de,qe]),u=p??o?.name??s??void 0,b=we?we.connectorId:gs(de),B=r??b,_=g??f??!!c,A=$t({env:Re,walletAddress:be,enabled:R&&!!be&&K,restoreChainAfterSwitch:Ae}),L=V??A.bridgeTokens,Z=G??A.bridgeHistory,S=N??A.getBridgeQuote,F=j??A.getBridgeToTokens,q=z??A.getBridgeApproval,Q=X??A.approveBridge,U=D??A.submitBridge,l=Ye(()=>{Ee().catch(M=>{console.error("[crossx-kit] connectWallet error:",M)})},[Ee]),h=Ye(()=>{ye()},[ye]),T=x??h,P=cs(),{eligibility:E}=ds({network:$?String($.id):void 0}),le=E?.allowed===!0,He=At(()=>{if(W)return W;if(!(!P||!$||!le))return()=>P.open({crypto:$.nativeCurrency?.symbol??"USDT",network:String($.id),...I?{redirectUrl:I}:{}}).then(()=>{}).catch(M=>{throw console.warn("[crossx-kit] onramp open failed:",M),M})},[W,P,$,le,I]),nt=ts();es(()=>{if(P?.onStatus)return P.onStatus(()=>{nt.invalidateQueries()})},[P,nt]);let Oe=At(()=>{if(!W&&!(!P||!$)&&!le)return"On-ramp is not available in your region."},[W,P,$,le]),Ve=fe.onBridgeDisabledMessage,_t=fe.onSendDisabledMessage,Jn=o?o.provider==="google"||o.provider==="apple":de==="cross_embedded",eo=Ye(()=>{Me().catch(M=>{console.error("[crossx-kit] selectWallet error:",M)})},[Me]),en=v??(Jn?eo:void 0),to=Ye(async({hash:M,chainId:te})=>{let ne=Ht(ce,te?{chainId:te}:void 0);if(!ne)return null;try{return await ne.getTransactionReceipt({hash:M})}catch{return null}},[ce]),no=Ye(async M=>{let te=Te,ne=!1;M.chainId!==void 0&&M.chainId!==Te&&(await Le({chainId:M.chainId}),ne=!0);let ue=M.chainId===56||M.chainId===97?{...M,type:"legacy"}:M,J=await(m??xe)(ue);return await Tt({getChainId:()=>ne?M.chainId:te,switchChain:Ce=>Le({chainId:Ce})},te,Ae),J},[m,xe,Te,Le,Ae]),oo=_||m?no:void 0,ro=Ye(async M=>{let te=M.chainId??Te,ne=Ht(ce,te?{chainId:te}:void 0);if(!ne)throw new Error(`publicClient for chainId ${te??"unknown"} is not available \u2014 register the chain in createCrossxConfig({ networks }).`);let he=te===56||te===97,[ue,Ie]=await Promise.all([ne.estimateGas({account:M.from,to:M.to,value:M.value,data:M.data}),(async()=>{if(he)return{maxFeePerGas:void 0,maxPriorityFeePerGas:void 0,gasPrice:await ne.getGasPrice()};try{let J=await ne.estimateFeesPerGas();return{maxFeePerGas:J.maxFeePerGas,maxPriorityFeePerGas:J.maxPriorityFeePerGas,gasPrice:void 0}}catch{return{maxFeePerGas:void 0,maxPriorityFeePerGas:void 0,gasPrice:await ne.getGasPrice()}}})()]);return{gasLimit:ue,maxFeePerGas:Ie.maxFeePerGas,maxPriorityFeePerGas:Ie.maxPriorityFeePerGas,gasPrice:Ie.gasPrice}},[ce,Te]),so=k??ro,io=Ye(async M=>{let te={};if(!O||M.length===0)return te;let ne=M.flatMap(ue=>{let J={address:ue,abi:us,chainId:Te};return[{...J,functionName:"balanceOf",args:[O]},{...J,functionName:"totalSupply"},{...J,functionName:"decimals"}]}),he;try{he=await Kn(ce,{contracts:ne,allowFailure:!0})}catch{return te}return M.forEach((ue,Ie)=>{let J=Ie*3,Ce=he[J],wt=he[J+1],dt=he[J+2];!Ce||Ce.status!=="success"||(te[ue.toLowerCase()]={balance:Ce.result,totalSupply:wt&&wt.status==="success"?wt.result:void 0,decimals:dt&&dt.status==="success"?Number(dt.result):void 0})}),te},[ce,O,Te]),ao=Ye(async M=>{let te={earnedWei:0n,stakedWei:0n};if(!M)return te;let ne=ms[Re],he={address:ne.poolAddress,abi:ps,chainId:ne.crossChainId},ue;try{ue=await Kn(ce,{allowFailure:!0,contracts:[{...he,functionName:"earned",args:[M]},{...he,functionName:"balanceOf",args:[M]},{...he,functionName:"posaActive"},{...he,functionName:"lastRewardBlock"},{...he,functionName:"totalStaked"}]})}catch{return te}let Ie=ot=>ue[ot]&&ue[ot].status==="success"?ue[ot].result:0n,J=Ie(0),Ce=Ie(1);if(ue[2]&&ue[2].status==="success"?ue[2].result:!1)return{earnedWei:J,stakedWei:Ce};let dt=Ie(3),on=Ie(4);if(on===0n)return{earnedWei:J,stakedWei:Ce};let Et=0n;try{Et=await Ht(ce,{chainId:ne.crossChainId})?.getBlockNumber?.()??0n}catch{return{earnedWei:J,stakedWei:Ce}}if(Et<=dt)return{earnedWei:J,stakedWei:Ce};let Ot=0n;try{let ot=await fetch(ne.networkStatsUrl).then(Nt=>Nt.json()),rn=ot?.data?.block_reward??ot?.block_reward;if(rn){let[Nt,po=""]=String(rn).split("."),mo=(po+"0".repeat(18)).slice(0,18);Ot=BigInt(Nt||"0")*jt+BigInt(mo||"0")}}catch{}if(Ot===0n)return{earnedWei:J,stakedWei:Ce};let lo=(Et-dt)*Ot*jt/on,uo=Ce*lo/jt;return{earnedWei:J+uo,stakedWei:Ce}},[ce,Re]),tn=!en,nn=t?`cb-button ${t}`:"cb-button",co=t?`cb-pill ${t}`:"cb-pill";return Je&&!R?it($n,{children:[me("style",{children:Qt}),it("button",{type:"button",disabled:!0,className:nn,style:n,"aria-busy":"true",children:[me("span",{className:"cb-spinner","aria-hidden":"true"}),me("span",{className:"cb-button-label",children:"Connecting..."})]})]}):R&&be?it("span",{"data-crossx-wallet-info":tn?"external":"embedded",children:[me("style",{children:Qt}),tn&&me("style",{children:hs}),it(Vt,{...fe,env:Re,theme:ct,showBalance:K,walletAddress:be,accountName:u,sendAccounts:w??a,connectorId:B,showPortfolio:_,onDisconnect:T,onSelectWallet:en,onBuy:He,onBuyDisabledMessage:Oe,onBridgeDisabledMessage:Ve,onSendDisabledMessage:_t,sendTransaction:oo,getTransactionReceipt:C??to,estimateGas:so,lpBalanceReader:io,stakingRewardsReader:ao,bridgeTokens:L,bridgeHistory:Z,getBridgeQuote:S,getBridgeToTokens:F,getBridgeApproval:q,approveBridge:Q,submitBridge:U,style:i,children:[me(Vt.Trigger,{asChild:!0,children:it("button",{type:"button",className:co,style:n,"aria-label":`Connected with ${d?.name??"wallet"}: ${Un(be)}`,children:[d?.iconUrl?me("img",{src:d.iconUrl,alt:"",width:20,height:20,className:"cb-pill-icon","data-provider":d.iconUrl===Xt?"apple":void 0}):me("span",{className:"cb-pill-icon-placeholder","aria-hidden":"true"}),me("span",{className:"cb-pill-address",children:Un(be)})]})}),me(Vt.Content,{align:"end",sideOffset:8})]})]}):it($n,{children:[me("style",{children:Qt}),it("button",{type:"button",onClick:l,className:nn,style:n,"aria-label":typeof e=="string"?e:"Connect Wallet",children:[me(ws,{}),me("span",{className:"cb-button-label",children:e})]})]})}function ws(){return me("svg",{className:"cb-button-icon",viewBox:"0 0 18 18",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:me("path",{d:"M11.4368 10.5007C11.4368 9.9538 11.6544 9.42855 12.041 9.04175C12.4278 8.65492 12.9529 8.4375 13.5 8.4375H15.1875V6.00073L15.1732 5.92822C15.1639 5.90585 15.15 5.88528 15.1326 5.8678C15.0973 5.83263 15.0494 5.81287 14.9996 5.81287H3.74963C3.4787 5.81287 3.21001 5.75949 2.95972 5.65576C2.90937 5.63488 2.86089 5.61017 2.8125 5.58545V14.2504C2.8125 14.4989 2.91141 14.7371 3.08716 14.9128C3.2629 15.0886 3.50109 15.1875 3.74963 15.1875H15.0007C15.0252 15.1875 15.0495 15.1826 15.0721 15.1732C15.0948 15.1638 15.1152 15.1499 15.1326 15.1326C15.1499 15.1152 15.1638 15.0948 15.1732 15.0721C15.1826 15.0495 15.1875 15.0252 15.1875 15.0007V12.5629H13.5C12.9529 12.5629 12.4278 12.3454 12.041 11.9586C11.6545 11.5719 11.4369 11.0475 11.4368 10.5007ZM12.5618 10.5007C12.5619 10.7491 12.6609 10.9875 12.8364 11.1632C13.0123 11.3391 13.2513 11.4379 13.5 11.4379H15.75C15.7998 11.4379 15.8477 11.4182 15.8829 11.3829C15.9182 11.3477 15.9379 11.2998 15.9379 11.25V9.75037C15.9379 9.70054 15.9182 9.65266 15.8829 9.61743C15.8477 9.5822 15.7998 9.5625 15.75 9.5625H13.5C13.2513 9.5625 13.0123 9.66131 12.8364 9.83716C12.6607 10.013 12.5618 10.2522 12.5618 10.5007ZM13.6879 3.00037C13.6879 2.95054 13.6682 2.90266 13.6329 2.86743C13.5977 2.8322 13.5498 2.8125 13.5 2.8125H3.74963C3.50109 2.8125 3.2629 2.91141 3.08716 3.08716C2.91141 3.2629 2.8125 3.50109 2.8125 3.74963L2.81689 3.84192C2.82585 3.93354 2.8486 4.02351 2.88391 4.10889C2.93096 4.22263 3.00015 4.32614 3.08716 4.41321C3.17403 4.50009 3.2769 4.56936 3.39038 4.61646C3.50412 4.66359 3.62651 4.68787 3.74963 4.68787H13.6879V3.00037ZM14.8129 4.68787H14.9996C15.3473 4.68787 15.6808 4.82576 15.9269 5.07129C16.173 5.31702 16.3119 5.65077 16.3125 5.99854V8.56494C16.4469 8.62873 16.5711 8.7148 16.6783 8.82202C16.9246 9.06823 17.0629 9.40217 17.0629 9.75037V11.25C17.0629 11.5982 16.9246 11.9321 16.6783 12.1783C16.5712 12.2855 16.4468 12.3706 16.3125 12.4343V14.9985L16.3059 15.1282C16.2934 15.2564 16.2619 15.3822 16.2125 15.5017C16.1466 15.6612 16.05 15.806 15.928 15.928C15.806 16.05 15.6612 16.1466 15.5017 16.2125C15.3425 16.2783 15.1719 16.3126 14.9996 16.3125H3.74963C3.20272 16.3125 2.67847 16.095 2.29175 15.7083C1.90502 15.3215 1.6875 14.7973 1.6875 14.2504V3.74963C1.6875 3.20272 1.90502 2.67847 2.29175 2.29175C2.67847 1.90502 3.20272 1.6875 3.74963 1.6875H13.5C13.8482 1.6875 14.1821 1.82581 14.4283 2.07202C14.6746 2.31823 14.8129 2.65217 14.8129 3.00037V4.68787Z",fill:"currentColor"})})}var hs=`
|
|
3
|
+
[data-crossx-wallet-info="external"] .wi-select-wallet-btn {
|
|
4
|
+
display: none !important;
|
|
5
|
+
}
|
|
6
|
+
`;function Un(e){return`${e.slice(0,6)}...${e.slice(-4)}`}var Qt=`
|
|
7
|
+
.cb-button {
|
|
8
|
+
-webkit-font-smoothing: antialiased;
|
|
9
|
+
--cb-bg: var(--ds-accent-primary-default, #00D5AA);
|
|
10
|
+
--cb-bg-hover: var(--ds-accent-primary-high, #00a0a2);
|
|
11
|
+
--cb-color: var(--ds-accent-primary-on, #000);
|
|
12
|
+
--cb-border: none;
|
|
13
|
+
--cb-radius: 8px;
|
|
14
|
+
--cb-height: 36px;
|
|
15
|
+
--cb-padding: 0 16px;
|
|
16
|
+
--cb-font-family: Inter, system-ui, -apple-system, sans-serif;
|
|
17
|
+
--cb-font-size: 14px;
|
|
18
|
+
--cb-font-weight: 500;
|
|
19
|
+
--cb-gap: 8px;
|
|
20
|
+
--cb-transition: background-color 0.15s ease, transform 0.1s ease;
|
|
21
|
+
--cb-loading-opacity: 0.7;
|
|
22
|
+
--cb-press-scale: 0.95;
|
|
23
|
+
--cb-spinner-size: 14px;
|
|
24
|
+
--cb-spinner-thumb: currentColor;
|
|
25
|
+
--cb-spinner-track: color-mix(in srgb, currentColor 20%, transparent);
|
|
26
|
+
--cb-icon-size: 18px;
|
|
27
|
+
|
|
28
|
+
display: inline-flex;
|
|
29
|
+
align-items: center;
|
|
30
|
+
justify-content: center;
|
|
31
|
+
box-sizing: border-box;
|
|
32
|
+
height: var(--cb-height);
|
|
33
|
+
gap: var(--cb-gap);
|
|
34
|
+
padding: var(--cb-padding);
|
|
35
|
+
border-radius: var(--cb-radius);
|
|
36
|
+
border: var(--cb-border);
|
|
37
|
+
background: var(--cb-bg);
|
|
38
|
+
color: var(--cb-color);
|
|
39
|
+
font-family: var(--cb-font-family);
|
|
40
|
+
font-size: var(--cb-font-size);
|
|
41
|
+
font-weight: var(--cb-font-weight);
|
|
42
|
+
cursor: pointer;
|
|
43
|
+
transition: var(--cb-transition);
|
|
44
|
+
}
|
|
45
|
+
.cb-button:hover:not(:disabled) { background: var(--cb-bg-hover); }
|
|
46
|
+
.cb-button:active:not(:disabled) { transform: scale(var(--cb-press-scale)); }
|
|
47
|
+
.cb-button:disabled, .cb-button[aria-busy="true"] {
|
|
48
|
+
cursor: default;
|
|
49
|
+
opacity: var(--cb-loading-opacity);
|
|
50
|
+
}
|
|
51
|
+
.cb-spinner {
|
|
52
|
+
display: inline-block;
|
|
53
|
+
width: var(--cb-spinner-size);
|
|
54
|
+
height: var(--cb-spinner-size);
|
|
55
|
+
border: 2px solid var(--cb-spinner-track);
|
|
56
|
+
border-top-color: var(--cb-spinner-thumb);
|
|
57
|
+
border-radius: 50%;
|
|
58
|
+
animation: cck-cb-spin 0.6s linear infinite;
|
|
59
|
+
flex-shrink: 0;
|
|
60
|
+
}
|
|
61
|
+
.cb-button-icon {
|
|
62
|
+
width: var(--cb-icon-size);
|
|
63
|
+
height: var(--cb-icon-size);
|
|
64
|
+
flex-shrink: 0;
|
|
65
|
+
}
|
|
66
|
+
.cb-button-label { white-space: nowrap; }
|
|
67
|
+
.cb-pill {
|
|
68
|
+
--cb-pill-bg: var(--ds-surface-default, #1e232e);
|
|
69
|
+
--cb-pill-bg-hover: var(--ds-surface-medium, #252b39);
|
|
70
|
+
--cb-pill-color: var(--ds-content-high, #ffffffd9);
|
|
71
|
+
--cb-pill-border: 1px solid var(--ds-border-default, #ffffff12);
|
|
72
|
+
--cb-pill-border-hover: 1px solid var(--ds-border-medium, #ffffff2e);
|
|
73
|
+
--cb-pill-radius: 8px;
|
|
74
|
+
--cb-pill-height: 36px;
|
|
75
|
+
--cb-pill-padding: 0 12px;
|
|
76
|
+
--cb-pill-press-scale: 0.95;
|
|
77
|
+
--cb-pill-font-family: Inter, system-ui, -apple-system, sans-serif;
|
|
78
|
+
--cb-pill-font-size: 14px;
|
|
79
|
+
--cb-pill-font-weight: 500;
|
|
80
|
+
--cb-pill-gap: 8px;
|
|
81
|
+
--cb-pill-icon-size: 20px;
|
|
82
|
+
--cb-pill-icon-placeholder-bg: var(--ds-surface-high, #2a2d3a);
|
|
83
|
+
--cb-pill-address-font: Inter, system-ui, -apple-system, sans-serif;
|
|
84
|
+
--cb-pill-address-font-size: 14px;
|
|
85
|
+
--cb-pill-address-letter-spacing: -0.01em;
|
|
86
|
+
|
|
87
|
+
display: inline-flex;
|
|
88
|
+
align-items: center;
|
|
89
|
+
box-sizing: border-box;
|
|
90
|
+
height: var(--cb-pill-height);
|
|
91
|
+
gap: var(--cb-pill-gap);
|
|
92
|
+
padding: var(--cb-pill-padding);
|
|
93
|
+
border-radius: var(--cb-pill-radius);
|
|
94
|
+
border: var(--cb-pill-border);
|
|
95
|
+
background: var(--cb-pill-bg);
|
|
96
|
+
color: var(--cb-pill-color);
|
|
97
|
+
font-family: var(--cb-pill-font-family);
|
|
98
|
+
font-size: var(--cb-pill-font-size);
|
|
99
|
+
font-weight: var(--cb-pill-font-weight);
|
|
100
|
+
cursor: pointer;
|
|
101
|
+
}
|
|
102
|
+
.cb-pill:hover,
|
|
103
|
+
.cb-pill[data-state="open"] { background: var(--cb-pill-bg-hover); border: var(--cb-pill-border-hover, 1px solid var(--ds-border-medium, #ffffff2e)); }
|
|
104
|
+
.cb-pill:active:not(:disabled) { transform: scale(var(--cb-pill-press-scale)); }
|
|
105
|
+
.cb-pill-icon {
|
|
106
|
+
width: var(--cb-pill-icon-size);
|
|
107
|
+
height: var(--cb-pill-icon-size);
|
|
108
|
+
border-radius: 50%;
|
|
109
|
+
object-fit: contain;
|
|
110
|
+
flex-shrink: 0;
|
|
111
|
+
background: transparent;
|
|
112
|
+
}
|
|
113
|
+
/* Apple is a monochrome black logomark in an <img> data URI (can't follow
|
|
114
|
+
theme via currentColor). Flip it to white in dark mode so it stays
|
|
115
|
+
visible on the dark pill; multicolor marks (Google/MetaMask/Binance/
|
|
116
|
+
CROSSx) are untouched. */
|
|
117
|
+
[data-theme="dark"] .cb-pill-icon[data-provider="apple"] {
|
|
118
|
+
filter: invert(1);
|
|
119
|
+
}
|
|
120
|
+
.cb-pill-icon-placeholder {
|
|
121
|
+
display: inline-block;
|
|
122
|
+
width: var(--cb-pill-icon-size);
|
|
123
|
+
height: var(--cb-pill-icon-size);
|
|
124
|
+
border-radius: 50%;
|
|
125
|
+
background: var(--cb-pill-icon-placeholder-bg);
|
|
126
|
+
flex-shrink: 0;
|
|
127
|
+
}
|
|
128
|
+
.cb-pill-address {
|
|
129
|
+
font-family: var(--cb-pill-address-font);
|
|
130
|
+
font-size: var(--cb-pill-address-font-size);
|
|
131
|
+
letter-spacing: var(--cb-pill-address-letter-spacing);
|
|
132
|
+
}
|
|
133
|
+
@media (max-width: 767.98px) {
|
|
134
|
+
.cb-button, .cb-pill {
|
|
135
|
+
width: 36px;
|
|
136
|
+
min-width: 36px;
|
|
137
|
+
padding: 0;
|
|
138
|
+
}
|
|
139
|
+
.cb-button-label, .cb-pill-address { display: none; }
|
|
140
|
+
}
|
|
141
|
+
@keyframes cck-cb-spin {
|
|
142
|
+
to { transform: rotate(360deg); }
|
|
143
|
+
}
|
|
144
|
+
`;import{useCallback as jn,useEffect as Cs,useMemo as Qn,useState as ks}from"react";import{detectWallets as zn,DEFAULT_WALLET_REGISTRY as Xn}from"@nexus-cross/connect-kit-wagmi";import{jsx as ae,jsxs as De}from"react/jsx-runtime";var Ts=["Ensure your wallet extension is installed and unlocked","Try refreshing the page","Some wallets may require you to first open the extension","You can try clicking the wallet anyway"],xs="Connect with one of our available wallet providers to continue.";function Is({open:e,onClose:t,onSelect:n,title:i="Connect Wallet",description:o=xs,troubleshootingTips:c=Ts}){let{availableWallets:g}=Ge(),[y,p]=ks({});Cs(()=>{if(!e)return;let m=zn(Xn),k={};for(let v of m)v.installed!==void 0&&(k[v.id]=v.installed);p(k);let x=setTimeout(()=>{let v=zn(Xn),W={};for(let I of v)I.installed!==void 0&&(W[I.id]=I.installed);p(W)},1e3);return()=>clearTimeout(x)},[e]);let r=Qn(()=>typeof navigator>"u"?!1:/Mobi|Android/i.test(navigator.userAgent),[]),f=Qn(()=>r?g.filter(m=>m.type!=="extension"):g,[g,r]),w=jn(m=>{if(!y[m.walletId]&&m.installUrl&&m.type==="extension"){window.open(m.installUrl,"_blank");return}t(),n(m.walletId)},[t,n,y]),C=jn((m,k)=>{m.stopPropagation(),t(),window.open(k,"_blank")},[t]);return e?ae("div",{style:H.overlay,onClick:t,children:De("div",{style:H.modal,onClick:m=>m.stopPropagation(),children:[De("div",{style:H.header,children:[ae("h2",{style:H.title,children:i}),ae("button",{type:"button",onClick:t,style:H.closeBtn,"aria-label":"Close",children:De("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[ae("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),ae("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),ae("p",{style:H.desc,children:o}),ae("div",{style:H.walletList,children:f.map(m=>{let k=y[m.walletId],x=k===!1&&m.type==="extension"&&!!m.installUrl;return De("div",{style:H.walletGroup,children:[De("button",{type:"button",onClick:()=>w(m),style:{...H.walletItem,...m.walletId==="cross_wallet"?H.walletItemAccent:{}},"aria-label":`Connect with ${m.name}`,children:[m.iconUrl?ae("img",{src:m.iconUrl,alt:"",style:H.walletIcon}):ae("div",{style:H.walletIconPlaceholder}),De("div",{style:H.walletInfo,children:[De("div",{style:H.walletNameRow,children:[ae("span",{style:H.walletName,children:m.name}),k!==void 0&&ae("span",{style:{...H.badge,...k?H.badgeInstalled:H.badgeNotInstalled},children:k?"Installed":"Not Installed"})]}),ae("span",{style:H.walletDesc,children:x?"Extension not detected \u2014 click to install":m.type==="extension"?"Browser extension approval is required":m.walletId==="cross_wallet"?"App approval is required":m.walletId==="binance"?"Mobile app only \u2014 Add CROSS network first":k?"Connect with browser extension":"Scan QR code with app"})]})]}),m.guideUrl&&De("button",{type:"button",onClick:v=>C(v,m.guideUrl),style:H.guideBtn,children:[ae("span",{"aria-hidden":"true",children:"\u26A0\uFE0F"}),m.guideLabel??"Required Settings"]})]},m.walletId)})}),De("div",{style:H.troubleshoot,children:[ae("h3",{style:H.troubleshootTitle,children:"Wallet not detected?"}),ae("ul",{style:H.troubleshootList,children:c.map(m=>De("li",{style:H.troubleshootItem,children:[ae("span",{style:H.troubleshootDot,"aria-hidden":"true"}),ae("span",{children:m})]},m))})]})]})}):null}var ee={surfaceBg:"var(--wi-surface-bg, #121212)",surfaceDefault:"var(--wi-surface-default, rgba(255,255,255,0.05))",surfaceSubtle:"var(--wi-surface-subtle, rgba(255,255,255,0.1))",borderDefault:"var(--wi-border-default, rgba(255,255,255,0.05))",textPrimary:"var(--wi-texticon-primary, #ffffff)",textSecondary:"var(--wi-texticon-secondary, rgba(255,255,255,0.7))",textTertiary:"var(--wi-texticon-tertiary, rgba(255,255,255,0.5))",primary:"var(--wi-primary, #019d92)",primarySoft:"var(--crossx-kit-primary-soft, rgba(1,157,146,0.15))",accentGradient:"var(--crossx-kit-accent-gradient, linear-gradient(113deg, rgba(255,255,255,0.05) 0%, rgba(1,157,146,0.12) 70%, rgba(255,255,255,0.05) 70%, rgba(1,157,146,0.12) 80%, rgba(255,255,255,0.05) 80%))",warningBg:"var(--crossx-kit-warning-bg, rgba(245,158,11,0.1))",warningBorder:"var(--crossx-kit-warning-border, rgba(245,158,11,0.25))",warningText:"var(--crossx-kit-warning-text, #fbbf24)"},H={overlay:{position:"fixed",inset:0,zIndex:1e4,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.6)",backdropFilter:"blur(4px)"},modal:{width:"100%",maxWidth:"420px",margin:"16px",background:ee.surfaceBg,border:`1px solid ${ee.borderDefault}`,borderRadius:"20px",overflow:"hidden"},header:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"20px 24px 0"},title:{fontSize:"18px",fontWeight:700,color:ee.textPrimary,margin:0},closeBtn:{background:"none",border:"none",color:ee.textTertiary,cursor:"pointer",padding:"4px",borderRadius:"8px",display:"flex",alignItems:"center",justifyContent:"center"},desc:{padding:"8px 24px 16px",fontSize:"13px",color:ee.textTertiary,margin:0,lineHeight:1.5},walletList:{display:"flex",flexDirection:"column",gap:"6px",padding:"0 12px 12px"},walletGroup:{display:"flex",flexDirection:"column",borderRadius:"12px",overflow:"hidden",background:ee.surfaceDefault},walletItem:{display:"flex",alignItems:"center",gap:"14px",width:"100%",padding:"14px",background:"transparent",border:"none",color:ee.textPrimary,cursor:"pointer",textAlign:"left"},walletItemAccent:{background:ee.accentGradient},walletIcon:{width:"40px",height:"40px",borderRadius:"10px",flexShrink:0},walletIconPlaceholder:{width:"40px",height:"40px",borderRadius:"10px",background:ee.surfaceSubtle,flexShrink:0},walletInfo:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"3px"},walletNameRow:{display:"flex",alignItems:"center",gap:"8px"},walletName:{fontSize:"15px",fontWeight:700,lineHeight:1.3,color:ee.textPrimary},badge:{fontSize:"10px",fontWeight:600,padding:"2px 7px",borderRadius:"99px",lineHeight:1},badgeInstalled:{background:ee.primarySoft,color:ee.primary},badgeNotInstalled:{background:"rgba(255,255,255,0.05)",color:ee.textTertiary},walletDesc:{fontSize:"11px",color:ee.textSecondary,lineHeight:1.3},guideBtn:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",margin:"0 14px 14px",padding:"10px 12px",borderRadius:"10px",border:`1px solid ${ee.warningBorder}`,background:ee.warningBg,color:ee.warningText,fontWeight:600,fontSize:"13px",cursor:"pointer"},troubleshoot:{margin:"0 12px 16px",background:ee.surfaceDefault,borderRadius:"12px",padding:"14px 16px"},troubleshootTitle:{fontSize:"12px",fontWeight:700,color:ee.textPrimary,margin:"0 0 8px"},troubleshootList:{listStyle:"none",padding:0,margin:0,display:"flex",flexDirection:"column",gap:"8px"},troubleshootItem:{display:"flex",alignItems:"flex-start",gap:"8px",fontSize:"11px",color:ee.textSecondary,lineHeight:1.5},troubleshootDot:{flexShrink:0,width:"4px",height:"4px",marginTop:"6px",borderRadius:"50%",background:ee.textSecondary}};import{useEffect as vs,useMemo as Yn}from"react";import{useAccount as Ss,useConfig as Ps,useSendTransaction as As,useSwitchChain as Rs,useWriteContract as Bs}from"wagmi";import{getBalance as _s,readContract as Es,readContracts as Os,waitForTransactionReceipt as Ns}from"wagmi/actions";import{RelayDeposit as Yt}from"@nexus-cross/dapp-ui";import{jsx as Ms}from"react/jsx-runtime";var Fs=56,Ws=[{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"}],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"decimals",stateMutability:"view",inputs:[],outputs:[{name:"",type:"uint8"}]},{type:"function",name:"symbol",stateMutability:"view",inputs:[],outputs:[{name:"",type:"string"}]}],at=e=>e,Zn=!1;function Bt(){let{address:e,chainId:t}=Ss(),n=Ps(),{sendTransactionAsync:i}=As(),{writeContractAsync:o}=Bs(),{switchChainAsync:c}=Rs(),g=n.chains.some(p=>p.id===Fs);vs(()=>{g||Zn||(Zn=!0,console.warn("[connect-kit] CrossRelayDeposit: BNB Smart Chain (56) is not in the wagmi config \u2014 one-click deposit verification and fund recovery are disabled. Add `bsc` to `createCrossxConfig({ networks })` to enable them."))},[g]);let y=Yn(()=>({sendTransaction:async({chainId:p,to:r,value:f,data:w})=>i({chainId:at(p),to:r,value:f,data:w}),writeContract:async({chainId:p,address:r,abi:f,functionName:w,args:C})=>o({chainId:at(p),address:r,abi:f,functionName:w,args:C}),readContract:g?async({chainId:p,address:r,abi:f,functionName:w,args:C})=>Es(n,{chainId:at(p),address:r,abi:f,functionName:w,args:C}):void 0,switchChain:async p=>{await c({chainId:at(p)})},waitForReceipt:async({chainId:p,hash:r})=>({status:(await Ns(n,{chainId:at(p),hash:r})).status==="success"?"success":"reverted"}),getBalance:async({chainId:p,address:r,token:f})=>{if(!f){let v=await _s(n,{chainId:at(p),address:r});return{value:v.value,decimals:v.decimals,symbol:v.symbol}}let w={address:f,abi:Ws,chainId:at(p)},C=await Os(n,{contracts:[{...w,functionName:"balanceOf",args:[r]},{...w,functionName:"decimals"},{...w,functionName:"symbol"}],allowFailure:!1}),[m,k,x]=C;return{value:m,decimals:k,symbol:x}}}),[n,g,i,o,c]);return Yn(()=>({walletAddress:e,walletChainId:t,...y}),[e,t,y])}function Ds(e){let t=Bt();return Ms(Yt,{...t,...e})}var Ls=Object.assign(Ds,{Trigger:Yt.Trigger,Content:Yt.Content});import{useAccount as Gs}from"wagmi";import{RelayHistory as Zt}from"@nexus-cross/dapp-ui";import{jsx as $s}from"react/jsx-runtime";function Ks(e){let{address:t}=Gs();return $s(Zt,{walletAddress:t,...e})}var Us=Object.assign(Ks,{Trigger:Zt.Trigger,Content:Zt.Content});import{RelayRecovery as Jt}from"@nexus-cross/dapp-ui";import{jsx as Vs}from"react/jsx-runtime";function qs(e){let t=Bt();return Vs(Jt,{...t,...e})}var Hs=Object.assign(qs,{Trigger:Jt.Trigger,Content:Jt.Content});import{useContext as js,useEffect as Qs,useRef as zs}from"react";function Xs(e){let t=js(kt);if(!t)throw new Error("useConnectKitAnalytics must be used within <CrossConnectKitProvider>");let n=zs(e);n.current=e;let{subscribe:i}=t;Qs(()=>i(c=>n.current(c)),[i])}import{useOnRamp as Ka,useOnRampEligibility as Ua,OnRampProvider as $a}from"@nexus-cross/onramp/react";import{useKyc as Ha,useOptionalKyc as Va,KycProvider as ja,KycError as Qa,launchKycVerification as za}from"@nexus-cross/kyc/react";import{WalletInfo as Ya,ConnectorId as Za}from"@nexus-cross/dapp-ui";import{AppLauncher as ec,AppLauncherTrigger as tc,AppLauncherContent as nc,useGlobalMenu as oc}from"@nexus-cross/dapp-ui";import{SkillsButton as sc}from"@nexus-cross/dapp-ui";import{createRelayClient as ac,RelayApiError as cc,DEFAULT_TRUSTED_FACTORIES as dc}from"@nexus-cross/dapp-ui";import{OnRampError as uc}from"@nexus-cross/connect-kit-core";import{ConnectionStatus as mc,formatBalance as fc,formatWei as gc}from"@nexus-cross/connect-kit-core";sn();export{Ge as a,ho as b,ft as c,Wt as d,zo as e,$t as f,qt as g,bs as h,Is as i,Bt as j,Ls as k,Us as l,Hs as m,Xs as n,Ka as o,Ua as p,$a as q,Ha as r,Va as s,ja as t,Qa as u,za as v,Ya as w,Za as x,ec as y,tc as z,nc as A,oc as B,sc as C,ac as D,cc as E,dc as F,uc as G,mc as H,fc as I,gc as J};
|
package/dist/client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { ConnectButton, ConnectButtonProps, CrossConnectKitContextValue, CrossConnectKitProvider, CrossConnectKitProviderProps, CrossConnectKitThemeContextValue, CrossConnectModal, CrossConnectModalProps, CrossxEmbeddedInfo, OtherWalletsModal, OtherWalletsModalProps, WalletProvider, WalletUser, useConnectKitAnalytics, useCrossConnectKit, useCrossConnectKitTheme, useCrossdBridgeAdapter, useCrossxEmbeddedInfo, useOptionalCrossConnectKitTheme } from './index.js';
|
|
1
|
+
export { ConnectButton, ConnectButtonProps, CrossConnectKitContextValue, CrossConnectKitProvider, CrossConnectKitProviderProps, CrossConnectKitThemeContextValue, CrossConnectModal, CrossConnectModalProps, CrossRelayDeposit, CrossRelayDepositProps, CrossRelayHistory, CrossRelayHistoryProps, CrossRelayRecovery, CrossRelayRecoveryProps, CrossxEmbeddedInfo, OtherWalletsModal, OtherWalletsModalProps, WalletProvider, WalletUser, useConnectKitAnalytics, useCrossConnectKit, useCrossConnectKitTheme, useCrossdBridgeAdapter, useCrossxEmbeddedInfo, useOptionalCrossConnectKitTheme, useRelayWalletProps } from './index.js';
|
|
2
2
|
export { OnRampProvider, OnRampProviderProps, UseOnRampEligibilityOptions, UseOnRampEligibilityResult, UseOnRampOptions, UseOnRampResult, useOnRamp, useOnRampEligibility } from '@nexus-cross/onramp/react';
|
|
3
3
|
export { KycError, KycErrorCode, KycIdentity, KycLaunchTarget, KycLoginType, KycProvider, KycProviderProps, KycRejectType, KycStatus, KycVerificationHandle, KycVerificationMode, LaunchKycVerificationOptions, UseKycOptions, UseKycResult, launchKycVerification, useKyc, useOptionalKyc } from '@nexus-cross/kyc/react';
|
|
4
|
-
export { AppLauncher, AppLauncherContent, AppLauncherContentProps, AppLauncherProps, AppLauncherTrigger, AppLauncherTriggerProps, AppLauncherTriggerStyle, ConnectButtonStyle, ConnectorId, GlobalMenu, GlobalMenuItem, GlobalMenuItemUrl, SendTransactionArgs, SendTransactionFn, SkillsButton, SkillsButtonProps, SkillsButtonStyle, WalletInfo, WalletInfoContentProps, WalletInfoProps, WalletInfoStyle, WalletInfoTriggerProps, useGlobalMenu } from '@nexus-cross/dapp-ui';
|
|
4
|
+
export { AppLauncher, AppLauncherContent, AppLauncherContentProps, AppLauncherProps, AppLauncherTrigger, AppLauncherTriggerProps, AppLauncherTriggerStyle, Catalog, ConnectButtonStyle, ConnectorId, DEFAULT_TRUSTED_FACTORIES, DepositAddressResult, GlobalMenu, GlobalMenuItem, GlobalMenuItemUrl, OrderSummary, OriginOption, QuoteResult, RecoveryInfo, RelayApiError, RelayBalance, RelayClient, RelayClientOptions, RelayContractCall, RelayDrawerDirection, RelayHex, RelayTheme, RelayTxRequest, RelayWalletProps, SendTransactionArgs, SendTransactionFn, SkillsButton, SkillsButtonProps, SkillsButtonStyle, WalletInfo, WalletInfoContentProps, WalletInfoProps, WalletInfoStyle, WalletInfoTriggerProps, createRelayClient, useGlobalMenu } from '@nexus-cross/dapp-ui';
|
|
5
5
|
import { AppMetadata, NetworkConfig, WalletId } from '@nexus-cross/connect-kit-core';
|
|
6
6
|
export { Account, ChainBalance, ColorOverrides, ConnectCancelStage, ConnectFailReason, ConnectKitEvent, ConnectKitEventName, ConnectionStatus, ConnectorType, CrossConnectKitConfig, ModalView, OnRampDisallowReason, OnRampEligibility, OnRampError, OnRampErrorCode, OnRampOpenParams, OnRampProviderId, OnRampSession, OnRampStatus, OnRampStatusEvent, Theme, ThemeMode, ThemeTokens, WalletDescriptor, WalletId, WalletState, formatBalance, formatWei } from '@nexus-cross/connect-kit-core';
|
|
7
7
|
import { CreateCrossxConfigOptions, CrossxConfig } from '@nexus-cross/connect-kit-wagmi';
|
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,D as pe,E as ce,F as le,G as ue,H as fe,I as Ce,J as we,a as S,b as V,c as W,d as X,e as L,f as h,g as j,h as B,i as F,j as D,k as U,l as q,m as z,n as $,o as G,p as H,q as J,r as Q,s as Y,t as Z,u as ee,v as ne,w as te,x as oe,y as re,z as ae}from"./chunk-PVH43WDS.js";import{bscMainnetNetwork as v,bscTestnetNetwork as x,createCrossxConfig as E,crossMainnetNetwork as k,crossTestnetNetwork as O}from"@nexus-cross/connect-kit-wagmi";import{toNexusAdapter as A}from"@nexus-cross/connect-kit-wagmi/to-nexus";import{reownAdapter as M}from"@nexus-cross/connect-kit-wagmi/reown";import{embeddedConnectorFactory as P}from"@nexus-cross/connect-kit-wagmi/embedded";import{WALLET_BRAND_NAME as I}from"@nexus-cross/crossx-design-system";function d(e){try{return import.meta.env?.[e]}catch{return}}function p(e){if(!(typeof process>"u"))return process.env?.[e]}function K(){return d("VITE_CROSSX_ENVIRONMENT")??d("NEXT_PUBLIC_CROSSX_ENVIRONMENT")??p("NEXT_PUBLIC_CROSSX_ENVIRONMENT")??p("CROSSX_ENVIRONMENT")}function R(e){switch(e?.toLowerCase()){case"dev":case"development":return"development";case"stage":case"staging":case"stg":return"staging";default:return"production"}}function T(e){return e==="production"?[k,v]:[O,x]}function b(){let e=typeof window<"u"&&window.location?.origin?window.location.origin:"https://example.com";return{name:`${I} DApp`,url:e}}function _(e){let{app:c,appMetadata:l,networks:u,defaultNetwork:f,wallets:n,embedded:C=!0,environment:w,toNexus:t,reown:o,...r}=e,m=R(w??K()),i=u??T(m),a=Array.isArray(n)?null:n??"all",s=a!=="external-only"&&t!==!1,g=a!=="cross-only"&&o!==!1&&!!r.reownProjectId,y=t===!1?void 0:t,N=o===!1?void 0:o;if(a==="external-only"&&!r.reownProjectId)throw new Error('[crossx-kit] createConnectKitConfig({ wallets: "external-only" }) requires `reownProjectId`.');return E({...r,appMetadata:l??c??b(),networks:i,defaultNetwork:f??i[0],...Array.isArray(n)?{wallets:n}:{},...s?{crossProvider:A(y)}:{},...g?{reownProvider:M(N)}:{},...s&&C?{embeddedConnectorFactory:P}:{}})}export{re as AppLauncher,ie as AppLauncherContent,ae as AppLauncherTrigger,B as ConnectButton,fe as ConnectionStatus,oe as ConnectorId,L as CrossConnectKitProvider,X as CrossConnectModal,U as CrossRelayDeposit,q as CrossRelayHistory,z as CrossRelayRecovery,le as DEFAULT_TRUSTED_FACTORIES,ee as KycError,Z as KycProvider,ue as OnRampError,J as OnRampProvider,F as OtherWalletsModal,ce as RelayApiError,de as SkillsButton,te as WalletInfo,_ as createConnectKitConfig,pe as createRelayClient,Ce as formatBalance,we as formatWei,ne as launchKycVerification,$ as useConnectKitAnalytics,S as useCrossConnectKit,V as useCrossConnectKitTheme,h as useCrossdBridgeAdapter,j as useCrossxEmbeddedInfo,se as useGlobalMenu,Q as useKyc,G as useOnRamp,H as useOnRampEligibility,W as useOptionalCrossConnectKitTheme,Y as useOptionalKyc,D as useRelayWalletProps};
|
package/dist/index.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { CrossxConfig, CrossConnectKitInitialState, ConnectorRegistry, Connector
|
|
|
4
4
|
export { ConnectorEntry, ConnectorRegistry } from '@nexus-cross/connect-kit-wagmi';
|
|
5
5
|
import { WalletId, CrossConnectKitConfig, OAuthPort, ThemeMode, ThemeTokens, ConnectKitEvent } from '@nexus-cross/connect-kit-core';
|
|
6
6
|
export { Account, ChainBalance, ColorOverrides, ConnectCancelStage, ConnectFailReason, ConnectKitEvent, ConnectKitEventName, ConnectionStatus, ConnectorType, CrossConnectKitConfig, ModalView, OnRampDisallowReason, OnRampEligibility, OnRampError, OnRampErrorCode, OnRampOpenParams, OnRampProviderId, OnRampSession, OnRampStatus, OnRampStatusEvent, Theme, ThemeMode, ThemeTokens, WalletDescriptor, WalletId, WalletState, formatBalance, formatWei } from '@nexus-cross/connect-kit-core';
|
|
7
|
-
import { WalletInfoProps, ConnectButtonStyle, WalletInfoStyle, Environment, BridgeToken, BridgeHistoryItem, BridgeGetApprovalFn, BridgeApproveFn, BridgeQuoteFn, BridgeGetToTokensFn, BridgeSubmitFn } from '@nexus-cross/dapp-ui';
|
|
8
|
-
export { AppLauncher, AppLauncherContent, AppLauncherContentProps, AppLauncherProps, AppLauncherTrigger, AppLauncherTriggerProps, AppLauncherTriggerStyle, ConnectButtonStyle, ConnectorId, GlobalMenu, GlobalMenuItem, GlobalMenuItemUrl, SendTransactionArgs, SendTransactionFn, SkillsButton, SkillsButtonProps, SkillsButtonStyle, WalletInfo, WalletInfoContentProps, WalletInfoProps, WalletInfoStyle, WalletInfoTriggerProps, useGlobalMenu } from '@nexus-cross/dapp-ui';
|
|
7
|
+
import { WalletInfoProps, ConnectButtonStyle, WalletInfoStyle, RelayDepositProps, RelayWalletProps, RelayDeposit, RelayHistoryProps, RelayHistory, RelayRecoveryProps, RelayRecovery, Environment, BridgeToken, BridgeHistoryItem, BridgeGetApprovalFn, BridgeApproveFn, BridgeQuoteFn, BridgeGetToTokensFn, BridgeSubmitFn } from '@nexus-cross/dapp-ui';
|
|
8
|
+
export { AppLauncher, AppLauncherContent, AppLauncherContentProps, AppLauncherProps, AppLauncherTrigger, AppLauncherTriggerProps, AppLauncherTriggerStyle, Catalog, ConnectButtonStyle, ConnectorId, DEFAULT_TRUSTED_FACTORIES, DepositAddressResult, GlobalMenu, GlobalMenuItem, GlobalMenuItemUrl, OrderSummary, OriginOption, QuoteResult, RecoveryInfo, RelayApiError, RelayBalance, RelayClient, RelayClientOptions, RelayContractCall, RelayDrawerDirection, RelayHex, RelayTheme, RelayTxRequest, RelayWalletProps, SendTransactionArgs, SendTransactionFn, SkillsButton, SkillsButtonProps, SkillsButtonStyle, WalletInfo, WalletInfoContentProps, WalletInfoProps, WalletInfoStyle, WalletInfoTriggerProps, createRelayClient, useGlobalMenu } from '@nexus-cross/dapp-ui';
|
|
9
9
|
import { Connector } from 'wagmi';
|
|
10
10
|
export { OnRampProvider, OnRampProviderProps, UseOnRampEligibilityOptions, UseOnRampEligibilityResult, UseOnRampOptions, UseOnRampResult, useOnRamp, useOnRampEligibility } from '@nexus-cross/onramp/react';
|
|
11
11
|
export { KycError, KycErrorCode, KycIdentity, KycLaunchTarget, KycLoginType, KycProvider, KycProviderProps, KycRejectType, KycStatus, KycVerificationHandle, KycVerificationMode, LaunchKycVerificationOptions, UseKycOptions, UseKycResult, launchKycVerification, useKyc, useOptionalKyc } from '@nexus-cross/kyc/react';
|
|
@@ -188,6 +188,123 @@ interface CrossConnectModalProps {
|
|
|
188
188
|
*/
|
|
189
189
|
declare function CrossConnectModal({ open, onOpenChange, }: CrossConnectModalProps): react_jsx_runtime.JSX.Element;
|
|
190
190
|
|
|
191
|
+
/**
|
|
192
|
+
* Derives the `RelayWalletProps` bundle that `<RelayDeposit>` consumes from the
|
|
193
|
+
* host's wagmi config + connected account.
|
|
194
|
+
*
|
|
195
|
+
* Every function on the returned object is stable across renders. This is
|
|
196
|
+
* load-bearing, not a micro-optimisation: `useDepositAddress` keys its
|
|
197
|
+
* balance-fetch and receipt-wait effects off the *identity* of
|
|
198
|
+
* `getBalance` / `waitForReceipt` (deps `[getBalance, address, origin, …]` and
|
|
199
|
+
* `[txHash, waitForReceipt]`), so an inline object literal here would re-fire
|
|
200
|
+
* those effects on every render — a request loop.
|
|
201
|
+
*
|
|
202
|
+
* Deliberately TWO memos. The functions are keyed only on what they actually
|
|
203
|
+
* close over (`config`, `hasBsc`, and the hooks' `*Async` mutate fns, all of
|
|
204
|
+
* which wagmi keeps referentially stable); `address`/`chainId` are merged in
|
|
205
|
+
* afterwards. None of the six functions reads either value — each call carries
|
|
206
|
+
* its own `chainId`/`address` argument — so folding them into the function memo
|
|
207
|
+
* would re-identify all six on every wallet account/chain change for no reason,
|
|
208
|
+
* with two real consequences:
|
|
209
|
+
*
|
|
210
|
+
* 1. `getBalance` re-identifies → the balance effect refetches (3 RPC reads)
|
|
211
|
+
* on every chain switch, i.e. on every one-click deposit, which switches
|
|
212
|
+
* chain as its first step.
|
|
213
|
+
* 2. `waitForReceipt` re-identifies mid-wait → the receipt effect re-runs with
|
|
214
|
+
* the OLD `txHash` against the NEW `origin.chainId`, reporting a landed
|
|
215
|
+
* deposit as failed. This is precisely the retarget hazard those narrow
|
|
216
|
+
* effect deps exist to avoid.
|
|
217
|
+
*
|
|
218
|
+
* Splitting is safe because dapp-ui keys its effects on the individual function
|
|
219
|
+
* props, never on the bundle's own identity.
|
|
220
|
+
*/
|
|
221
|
+
declare function useRelayWalletProps(): RelayWalletProps;
|
|
222
|
+
/**
|
|
223
|
+
* Everything `<RelayDeposit>` accepts except the wallet capabilities — those are
|
|
224
|
+
* derived from wagmi. Passing them explicitly is intentionally not allowed:
|
|
225
|
+
* this wrapper exists so the DApp never has to.
|
|
226
|
+
*/
|
|
227
|
+
type CrossRelayDepositProps = Omit<RelayDepositProps, keyof RelayWalletProps>;
|
|
228
|
+
declare function CrossRelayDepositRoot(props: CrossRelayDepositProps): react_jsx_runtime.JSX.Element;
|
|
229
|
+
/**
|
|
230
|
+
* wagmi-wired `<RelayDeposit>`: the cross-chain deposit modal with
|
|
231
|
+
* `sendTransaction` / `writeContract` / balance reads / chain switching already
|
|
232
|
+
* bound to the host's wagmi config.
|
|
233
|
+
*
|
|
234
|
+
* ```tsx
|
|
235
|
+
* <CrossRelayDeposit apiBaseUrl="https://relay.example.com">
|
|
236
|
+
* <CrossRelayDeposit.Trigger><button>Deposit</button></CrossRelayDeposit.Trigger>
|
|
237
|
+
* <CrossRelayDeposit.Content />
|
|
238
|
+
* </CrossRelayDeposit>
|
|
239
|
+
* ```
|
|
240
|
+
*
|
|
241
|
+
* `.Trigger` / `.Content` are dapp-ui's own subcomponents, re-exposed unchanged
|
|
242
|
+
* so hosts don't need a second import (and so `<CrossRelayDeposit.Content>`
|
|
243
|
+
* still reads the same `RelayDepositContext` the root provides).
|
|
244
|
+
*
|
|
245
|
+
* The annotation is kept explicit even though dapp-ui's barrel now exports
|
|
246
|
+
* `RelayDepositTriggerProps` / `RelayDepositContentProps` (so TS4023 no longer
|
|
247
|
+
* applies): `Pick<typeof RelayDeposit, …>` states the compound shape by
|
|
248
|
+
* referring to the imported value, which stays correct without this file having
|
|
249
|
+
* to track those prop types by name.
|
|
250
|
+
*/
|
|
251
|
+
declare const CrossRelayDeposit: typeof CrossRelayDepositRoot & Pick<typeof RelayDeposit, 'Trigger' | 'Content'>;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Everything `<RelayHistory>` accepts except `walletAddress`, which comes from
|
|
255
|
+
* wagmi. `recipient` is still accepted and still wins — the history subject can
|
|
256
|
+
* legitimately be an address other than the connected one.
|
|
257
|
+
*/
|
|
258
|
+
type CrossRelayHistoryProps = Omit<RelayHistoryProps, 'walletAddress'>;
|
|
259
|
+
declare function CrossRelayHistoryRoot(props: CrossRelayHistoryProps): react_jsx_runtime.JSX.Element;
|
|
260
|
+
/**
|
|
261
|
+
* wagmi-wired `<RelayHistory>`: the transfer-history modal, defaulted to the
|
|
262
|
+
* connected account.
|
|
263
|
+
*
|
|
264
|
+
* ```tsx
|
|
265
|
+
* <CrossRelayHistory apiBaseUrl="https://relay.example.com">
|
|
266
|
+
* <CrossRelayHistory.Trigger><button>History</button></CrossRelayHistory.Trigger>
|
|
267
|
+
* <CrossRelayHistory.Content />
|
|
268
|
+
* </CrossRelayHistory>
|
|
269
|
+
* ```
|
|
270
|
+
*
|
|
271
|
+
* Explicitly annotated for the same reason as `CrossRelayDeposit`: dapp-ui's
|
|
272
|
+
* barrel does export `RelayHistoryTriggerProps` / `RelayHistoryContentProps`
|
|
273
|
+
* now, but naming the compound shape via `Pick<typeof RelayHistory, …>` keeps
|
|
274
|
+
* the emitted `.d.ts` correct without tracking those prop types here.
|
|
275
|
+
*/
|
|
276
|
+
declare const CrossRelayHistory: typeof CrossRelayHistoryRoot & Pick<typeof RelayHistory, 'Trigger' | 'Content'>;
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Everything `<RelayRecovery>` accepts except the wallet capabilities — those are
|
|
280
|
+
* derived from wagmi. Passing them explicitly is intentionally not allowed:
|
|
281
|
+
* this wrapper exists so the DApp never has to. `recipient` is still accepted
|
|
282
|
+
* and still wins over the connected address.
|
|
283
|
+
*/
|
|
284
|
+
type CrossRelayRecoveryProps = Omit<RelayRecoveryProps, keyof RelayWalletProps>;
|
|
285
|
+
declare function CrossRelayRecoveryRoot(props: CrossRelayRecoveryProps): react_jsx_runtime.JSX.Element;
|
|
286
|
+
/**
|
|
287
|
+
* wagmi-wired `<RelayRecovery>`: the standalone "Recover stuck funds" modal,
|
|
288
|
+
* defaulted to the connected account, with `writeContract` / `readContract` /
|
|
289
|
+
* `waitForReceipt` / chain switching already bound to the host's wagmi config.
|
|
290
|
+
*
|
|
291
|
+
* ```tsx
|
|
292
|
+
* <CrossRelayRecovery apiBaseUrl="https://relay.example.com">
|
|
293
|
+
* <CrossRelayRecovery.Trigger><button>Recover funds</button></CrossRelayRecovery.Trigger>
|
|
294
|
+
* <CrossRelayRecovery.Content />
|
|
295
|
+
* </CrossRelayRecovery>
|
|
296
|
+
* ```
|
|
297
|
+
*
|
|
298
|
+
* Independent of `<CrossRelayDeposit>`'s own `showRecovery` gear — a host may
|
|
299
|
+
* offer either, both, or neither.
|
|
300
|
+
*
|
|
301
|
+
* `.Trigger` / `.Content` are dapp-ui's own subcomponents, re-exposed unchanged
|
|
302
|
+
* so hosts don't need a second import (and so `<CrossRelayRecovery.Content>`
|
|
303
|
+
* still reads the same `RelayRecoveryContext` the root provides). Explicitly
|
|
304
|
+
* annotated for the same reason as `CrossRelayDeposit`.
|
|
305
|
+
*/
|
|
306
|
+
declare const CrossRelayRecovery: typeof CrossRelayRecoveryRoot & Pick<typeof RelayRecovery, 'Trigger' | 'Content'>;
|
|
307
|
+
|
|
191
308
|
interface CrossConnectKitContextValue {
|
|
192
309
|
kitConfig: CrossConnectKitConfig;
|
|
193
310
|
connectorRegistry: ConnectorRegistry;
|
|
@@ -409,4 +526,4 @@ type CrossdBridgeAdapter = {
|
|
|
409
526
|
};
|
|
410
527
|
declare function useCrossdBridgeAdapter({ env, walletAddress, enabled, restoreChainAfterSwitch, }: CrossdBridgeAdapterOptions): CrossdBridgeAdapter;
|
|
411
528
|
|
|
412
|
-
export { ConnectButton, type ConnectButtonProps, type CrossConnectKitContextValue, CrossConnectKitProvider, type CrossConnectKitProviderProps, type CrossConnectKitThemeContextValue, CrossConnectModal, type CrossConnectModalProps, type CrossxEmbeddedInfo, OtherWalletsModal, type OtherWalletsModalProps, type WalletProvider, type WalletUser, useConnectKitAnalytics, useCrossConnectKit, useCrossConnectKitTheme, useCrossdBridgeAdapter, useCrossxEmbeddedInfo, useOptionalCrossConnectKitTheme };
|
|
529
|
+
export { ConnectButton, type ConnectButtonProps, type CrossConnectKitContextValue, CrossConnectKitProvider, type CrossConnectKitProviderProps, type CrossConnectKitThemeContextValue, CrossConnectModal, type CrossConnectModalProps, CrossRelayDeposit, type CrossRelayDepositProps, CrossRelayHistory, type CrossRelayHistoryProps, CrossRelayRecovery, type CrossRelayRecoveryProps, type CrossxEmbeddedInfo, OtherWalletsModal, type OtherWalletsModalProps, type WalletProvider, type WalletUser, useConnectKitAnalytics, useCrossConnectKit, useCrossConnectKitTheme, useCrossdBridgeAdapter, useCrossxEmbeddedInfo, useOptionalCrossConnectKitTheme, useRelayWalletProps };
|
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,D,E,F,G,H,I,J,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"./chunk-PVH43WDS.js";export{y as AppLauncher,A as AppLauncherContent,z as AppLauncherTrigger,h as ConnectButton,H as ConnectionStatus,x as ConnectorId,e as CrossConnectKitProvider,d as CrossConnectModal,k as CrossRelayDeposit,l as CrossRelayHistory,m as CrossRelayRecovery,F as DEFAULT_TRUSTED_FACTORIES,u as KycError,t as KycProvider,G as OnRampError,q as OnRampProvider,i as OtherWalletsModal,E as RelayApiError,C as SkillsButton,w as WalletInfo,D as createRelayClient,I as formatBalance,J as formatWei,v as launchKycVerification,n as useConnectKitAnalytics,a as useCrossConnectKit,b as useCrossConnectKitTheme,f as useCrossdBridgeAdapter,g as useCrossxEmbeddedInfo,B as useGlobalMenu,r as useKyc,o as useOnRamp,p as useOnRampEligibility,c as useOptionalCrossConnectKitTheme,s as useOptionalKyc,j as useRelayWalletProps};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexus-cross/connect-kit-react",
|
|
3
|
-
"version": "1.3.10-beta.
|
|
3
|
+
"version": "1.3.10-beta.4",
|
|
4
4
|
"description": "React components and hooks for @nexus-cross/connect-kit wallet connection",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@nexus-cross/connect-kit-core": "1.3.10-beta.
|
|
28
|
-
"@nexus-cross/connect-kit-wagmi": "1.3.10-beta.
|
|
29
|
-
"@nexus-cross/crossx-design-system": "1.3.10-beta.
|
|
30
|
-
"@nexus-cross/dapp-ui": "1.3.10-beta.
|
|
31
|
-
"@nexus-cross/kyc": "1.3.10-beta.
|
|
32
|
-
"@nexus-cross/onramp": "1.3.10-beta.
|
|
27
|
+
"@nexus-cross/connect-kit-core": "1.3.10-beta.4",
|
|
28
|
+
"@nexus-cross/connect-kit-wagmi": "1.3.10-beta.4",
|
|
29
|
+
"@nexus-cross/crossx-design-system": "1.3.10-beta.4",
|
|
30
|
+
"@nexus-cross/dapp-ui": "1.3.10-beta.4",
|
|
31
|
+
"@nexus-cross/kyc": "1.3.10-beta.4",
|
|
32
|
+
"@nexus-cross/onramp": "1.3.10-beta.4"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@tanstack/react-query": "^5.60.0",
|
package/dist/chunk-GQVRIG4I.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
var mt="1.3.10-beta.2";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
|
-
`)[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
|
-
[data-crossx-wallet-info="external"] .wi-select-wallet-btn {
|
|
4
|
-
display: none !important;
|
|
5
|
-
}
|
|
6
|
-
`;function Ln(e){return`${e.slice(0,6)}...${e.slice(-4)}`}var Vt=`
|
|
7
|
-
.cb-button {
|
|
8
|
-
-webkit-font-smoothing: antialiased;
|
|
9
|
-
--cb-bg: var(--ds-accent-primary-default, #00D5AA);
|
|
10
|
-
--cb-bg-hover: var(--ds-accent-primary-high, #00a0a2);
|
|
11
|
-
--cb-color: var(--ds-accent-primary-on, #000);
|
|
12
|
-
--cb-border: none;
|
|
13
|
-
--cb-radius: 8px;
|
|
14
|
-
--cb-height: 36px;
|
|
15
|
-
--cb-padding: 0 16px;
|
|
16
|
-
--cb-font-family: Inter, system-ui, -apple-system, sans-serif;
|
|
17
|
-
--cb-font-size: 14px;
|
|
18
|
-
--cb-font-weight: 500;
|
|
19
|
-
--cb-gap: 8px;
|
|
20
|
-
--cb-transition: background-color 0.15s ease, transform 0.1s ease;
|
|
21
|
-
--cb-loading-opacity: 0.7;
|
|
22
|
-
--cb-press-scale: 0.95;
|
|
23
|
-
--cb-spinner-size: 14px;
|
|
24
|
-
--cb-spinner-thumb: currentColor;
|
|
25
|
-
--cb-spinner-track: color-mix(in srgb, currentColor 20%, transparent);
|
|
26
|
-
--cb-icon-size: 18px;
|
|
27
|
-
|
|
28
|
-
display: inline-flex;
|
|
29
|
-
align-items: center;
|
|
30
|
-
justify-content: center;
|
|
31
|
-
box-sizing: border-box;
|
|
32
|
-
height: var(--cb-height);
|
|
33
|
-
gap: var(--cb-gap);
|
|
34
|
-
padding: var(--cb-padding);
|
|
35
|
-
border-radius: var(--cb-radius);
|
|
36
|
-
border: var(--cb-border);
|
|
37
|
-
background: var(--cb-bg);
|
|
38
|
-
color: var(--cb-color);
|
|
39
|
-
font-family: var(--cb-font-family);
|
|
40
|
-
font-size: var(--cb-font-size);
|
|
41
|
-
font-weight: var(--cb-font-weight);
|
|
42
|
-
cursor: pointer;
|
|
43
|
-
transition: var(--cb-transition);
|
|
44
|
-
}
|
|
45
|
-
.cb-button:hover:not(:disabled) { background: var(--cb-bg-hover); }
|
|
46
|
-
.cb-button:active:not(:disabled) { transform: scale(var(--cb-press-scale)); }
|
|
47
|
-
.cb-button:disabled, .cb-button[aria-busy="true"] {
|
|
48
|
-
cursor: default;
|
|
49
|
-
opacity: var(--cb-loading-opacity);
|
|
50
|
-
}
|
|
51
|
-
.cb-spinner {
|
|
52
|
-
display: inline-block;
|
|
53
|
-
width: var(--cb-spinner-size);
|
|
54
|
-
height: var(--cb-spinner-size);
|
|
55
|
-
border: 2px solid var(--cb-spinner-track);
|
|
56
|
-
border-top-color: var(--cb-spinner-thumb);
|
|
57
|
-
border-radius: 50%;
|
|
58
|
-
animation: cck-cb-spin 0.6s linear infinite;
|
|
59
|
-
flex-shrink: 0;
|
|
60
|
-
}
|
|
61
|
-
.cb-button-icon {
|
|
62
|
-
width: var(--cb-icon-size);
|
|
63
|
-
height: var(--cb-icon-size);
|
|
64
|
-
flex-shrink: 0;
|
|
65
|
-
}
|
|
66
|
-
.cb-button-label { white-space: nowrap; }
|
|
67
|
-
.cb-pill {
|
|
68
|
-
--cb-pill-bg: var(--ds-surface-default, #1e232e);
|
|
69
|
-
--cb-pill-bg-hover: var(--ds-surface-medium, #252b39);
|
|
70
|
-
--cb-pill-color: var(--ds-content-high, #ffffffd9);
|
|
71
|
-
--cb-pill-border: 1px solid var(--ds-border-default, #ffffff12);
|
|
72
|
-
--cb-pill-border-hover: 1px solid var(--ds-border-medium, #ffffff2e);
|
|
73
|
-
--cb-pill-radius: 8px;
|
|
74
|
-
--cb-pill-height: 36px;
|
|
75
|
-
--cb-pill-padding: 0 12px;
|
|
76
|
-
--cb-pill-press-scale: 0.95;
|
|
77
|
-
--cb-pill-font-family: Inter, system-ui, -apple-system, sans-serif;
|
|
78
|
-
--cb-pill-font-size: 14px;
|
|
79
|
-
--cb-pill-font-weight: 500;
|
|
80
|
-
--cb-pill-gap: 8px;
|
|
81
|
-
--cb-pill-icon-size: 20px;
|
|
82
|
-
--cb-pill-icon-placeholder-bg: var(--ds-surface-high, #2a2d3a);
|
|
83
|
-
--cb-pill-address-font: Inter, system-ui, -apple-system, sans-serif;
|
|
84
|
-
--cb-pill-address-font-size: 14px;
|
|
85
|
-
--cb-pill-address-letter-spacing: -0.01em;
|
|
86
|
-
|
|
87
|
-
display: inline-flex;
|
|
88
|
-
align-items: center;
|
|
89
|
-
box-sizing: border-box;
|
|
90
|
-
height: var(--cb-pill-height);
|
|
91
|
-
gap: var(--cb-pill-gap);
|
|
92
|
-
padding: var(--cb-pill-padding);
|
|
93
|
-
border-radius: var(--cb-pill-radius);
|
|
94
|
-
border: var(--cb-pill-border);
|
|
95
|
-
background: var(--cb-pill-bg);
|
|
96
|
-
color: var(--cb-pill-color);
|
|
97
|
-
font-family: var(--cb-pill-font-family);
|
|
98
|
-
font-size: var(--cb-pill-font-size);
|
|
99
|
-
font-weight: var(--cb-pill-font-weight);
|
|
100
|
-
cursor: pointer;
|
|
101
|
-
}
|
|
102
|
-
.cb-pill:hover,
|
|
103
|
-
.cb-pill[data-state="open"] { background: var(--cb-pill-bg-hover); border: var(--cb-pill-border-hover, 1px solid var(--ds-border-medium, #ffffff2e)); }
|
|
104
|
-
.cb-pill:active:not(:disabled) { transform: scale(var(--cb-pill-press-scale)); }
|
|
105
|
-
.cb-pill-icon {
|
|
106
|
-
width: var(--cb-pill-icon-size);
|
|
107
|
-
height: var(--cb-pill-icon-size);
|
|
108
|
-
border-radius: 50%;
|
|
109
|
-
object-fit: contain;
|
|
110
|
-
flex-shrink: 0;
|
|
111
|
-
background: transparent;
|
|
112
|
-
}
|
|
113
|
-
/* Apple is a monochrome black logomark in an <img> data URI (can't follow
|
|
114
|
-
theme via currentColor). Flip it to white in dark mode so it stays
|
|
115
|
-
visible on the dark pill; multicolor marks (Google/MetaMask/Binance/
|
|
116
|
-
CROSSx) are untouched. */
|
|
117
|
-
[data-theme="dark"] .cb-pill-icon[data-provider="apple"] {
|
|
118
|
-
filter: invert(1);
|
|
119
|
-
}
|
|
120
|
-
.cb-pill-icon-placeholder {
|
|
121
|
-
display: inline-block;
|
|
122
|
-
width: var(--cb-pill-icon-size);
|
|
123
|
-
height: var(--cb-pill-icon-size);
|
|
124
|
-
border-radius: 50%;
|
|
125
|
-
background: var(--cb-pill-icon-placeholder-bg);
|
|
126
|
-
flex-shrink: 0;
|
|
127
|
-
}
|
|
128
|
-
.cb-pill-address {
|
|
129
|
-
font-family: var(--cb-pill-address-font);
|
|
130
|
-
font-size: var(--cb-pill-address-font-size);
|
|
131
|
-
letter-spacing: var(--cb-pill-address-letter-spacing);
|
|
132
|
-
}
|
|
133
|
-
@media (max-width: 767.98px) {
|
|
134
|
-
.cb-button, .cb-pill {
|
|
135
|
-
width: 36px;
|
|
136
|
-
min-width: 36px;
|
|
137
|
-
padding: 0;
|
|
138
|
-
}
|
|
139
|
-
.cb-button-label, .cb-pill-address { display: none; }
|
|
140
|
-
}
|
|
141
|
-
@keyframes cck-cb-spin {
|
|
142
|
-
to { transform: rotate(360deg); }
|
|
143
|
-
}
|
|
144
|
-
`;import{useCallback as Un,useEffect as ps,useMemo as $n,useState as fs}from"react";import{detectWallets as qn,DEFAULT_WALLET_REGISTRY as Hn}from"@nexus-cross/connect-kit-wagmi";import{jsx as ae,jsxs as Le}from"react/jsx-runtime";var gs=["Ensure your wallet extension is installed and unlocked","Try refreshing the page","Some wallets may require you to first open the extension","You can try clicking the wallet anyway"],bs="Connect with one of our available wallet providers to continue.";function ys({open:e,onClose:t,onSelect:n,title:i="Connect Wallet",description:o=bs,troubleshootingTips:c=gs}){let{availableWallets:p}=Ge(),[b,f]=fs({});ps(()=>{if(!e)return;let m=qn(Hn),C={};for(let A of m)A.installed!==void 0&&(C[A.id]=A.installed);f(C);let I=setTimeout(()=>{let A=qn(Hn),W={};for(let x of A)x.installed!==void 0&&(W[x.id]=x.installed);f(W)},1e3);return()=>clearTimeout(I)},[e]);let r=$n(()=>typeof navigator>"u"?!1:/Mobi|Android/i.test(navigator.userAgent),[]),g=$n(()=>r?p.filter(m=>m.type!=="extension"):p,[p,r]),h=Un(m=>{if(!b[m.walletId]&&m.installUrl&&m.type==="extension"){window.open(m.installUrl,"_blank");return}t(),n(m.walletId)},[t,n,b]),T=Un((m,C)=>{m.stopPropagation(),t(),window.open(C,"_blank")},[t]);return e?ae("div",{style:H.overlay,onClick:t,children:Le("div",{style:H.modal,onClick:m=>m.stopPropagation(),children:[Le("div",{style:H.header,children:[ae("h2",{style:H.title,children:i}),ae("button",{type:"button",onClick:t,style:H.closeBtn,"aria-label":"Close",children:Le("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[ae("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),ae("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),ae("p",{style:H.desc,children:o}),ae("div",{style:H.walletList,children:g.map(m=>{let C=b[m.walletId],I=C===!1&&m.type==="extension"&&!!m.installUrl;return Le("div",{style:H.walletGroup,children:[Le("button",{type:"button",onClick:()=>h(m),style:{...H.walletItem,...m.walletId==="cross_wallet"?H.walletItemAccent:{}},"aria-label":`Connect with ${m.name}`,children:[m.iconUrl?ae("img",{src:m.iconUrl,alt:"",style:H.walletIcon}):ae("div",{style:H.walletIconPlaceholder}),Le("div",{style:H.walletInfo,children:[Le("div",{style:H.walletNameRow,children:[ae("span",{style:H.walletName,children:m.name}),C!==void 0&&ae("span",{style:{...H.badge,...C?H.badgeInstalled:H.badgeNotInstalled},children:C?"Installed":"Not Installed"})]}),ae("span",{style:H.walletDesc,children:I?"Extension not detected \u2014 click to install":m.type==="extension"?"Browser extension approval is required":m.walletId==="cross_wallet"?"App approval is required":m.walletId==="binance"?"Mobile app only \u2014 Add CROSS network first":C?"Connect with browser extension":"Scan QR code with app"})]})]}),m.guideUrl&&Le("button",{type:"button",onClick:A=>T(A,m.guideUrl),style:H.guideBtn,children:[ae("span",{"aria-hidden":"true",children:"\u26A0\uFE0F"}),m.guideLabel??"Required Settings"]})]},m.walletId)})}),Le("div",{style:H.troubleshoot,children:[ae("h3",{style:H.troubleshootTitle,children:"Wallet not detected?"}),ae("ul",{style:H.troubleshootList,children:c.map(m=>Le("li",{style:H.troubleshootItem,children:[ae("span",{style:H.troubleshootDot,"aria-hidden":"true"}),ae("span",{children:m})]},m))})]})]})}):null}var ee={surfaceBg:"var(--wi-surface-bg, #121212)",surfaceDefault:"var(--wi-surface-default, rgba(255,255,255,0.05))",surfaceSubtle:"var(--wi-surface-subtle, rgba(255,255,255,0.1))",borderDefault:"var(--wi-border-default, rgba(255,255,255,0.05))",textPrimary:"var(--wi-texticon-primary, #ffffff)",textSecondary:"var(--wi-texticon-secondary, rgba(255,255,255,0.7))",textTertiary:"var(--wi-texticon-tertiary, rgba(255,255,255,0.5))",primary:"var(--wi-primary, #019d92)",primarySoft:"var(--crossx-kit-primary-soft, rgba(1,157,146,0.15))",accentGradient:"var(--crossx-kit-accent-gradient, linear-gradient(113deg, rgba(255,255,255,0.05) 0%, rgba(1,157,146,0.12) 70%, rgba(255,255,255,0.05) 70%, rgba(1,157,146,0.12) 80%, rgba(255,255,255,0.05) 80%))",warningBg:"var(--crossx-kit-warning-bg, rgba(245,158,11,0.1))",warningBorder:"var(--crossx-kit-warning-border, rgba(245,158,11,0.25))",warningText:"var(--crossx-kit-warning-text, #fbbf24)"},H={overlay:{position:"fixed",inset:0,zIndex:1e4,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.6)",backdropFilter:"blur(4px)"},modal:{width:"100%",maxWidth:"420px",margin:"16px",background:ee.surfaceBg,border:`1px solid ${ee.borderDefault}`,borderRadius:"20px",overflow:"hidden"},header:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"20px 24px 0"},title:{fontSize:"18px",fontWeight:700,color:ee.textPrimary,margin:0},closeBtn:{background:"none",border:"none",color:ee.textTertiary,cursor:"pointer",padding:"4px",borderRadius:"8px",display:"flex",alignItems:"center",justifyContent:"center"},desc:{padding:"8px 24px 16px",fontSize:"13px",color:ee.textTertiary,margin:0,lineHeight:1.5},walletList:{display:"flex",flexDirection:"column",gap:"6px",padding:"0 12px 12px"},walletGroup:{display:"flex",flexDirection:"column",borderRadius:"12px",overflow:"hidden",background:ee.surfaceDefault},walletItem:{display:"flex",alignItems:"center",gap:"14px",width:"100%",padding:"14px",background:"transparent",border:"none",color:ee.textPrimary,cursor:"pointer",textAlign:"left"},walletItemAccent:{background:ee.accentGradient},walletIcon:{width:"40px",height:"40px",borderRadius:"10px",flexShrink:0},walletIconPlaceholder:{width:"40px",height:"40px",borderRadius:"10px",background:ee.surfaceSubtle,flexShrink:0},walletInfo:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"3px"},walletNameRow:{display:"flex",alignItems:"center",gap:"8px"},walletName:{fontSize:"15px",fontWeight:700,lineHeight:1.3,color:ee.textPrimary},badge:{fontSize:"10px",fontWeight:600,padding:"2px 7px",borderRadius:"99px",lineHeight:1},badgeInstalled:{background:ee.primarySoft,color:ee.primary},badgeNotInstalled:{background:"rgba(255,255,255,0.05)",color:ee.textTertiary},walletDesc:{fontSize:"11px",color:ee.textSecondary,lineHeight:1.3},guideBtn:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",margin:"0 14px 14px",padding:"10px 12px",borderRadius:"10px",border:`1px solid ${ee.warningBorder}`,background:ee.warningBg,color:ee.warningText,fontWeight:600,fontSize:"13px",cursor:"pointer"},troubleshoot:{margin:"0 12px 16px",background:ee.surfaceDefault,borderRadius:"12px",padding:"14px 16px"},troubleshootTitle:{fontSize:"12px",fontWeight:700,color:ee.textPrimary,margin:"0 0 8px"},troubleshootList:{listStyle:"none",padding:0,margin:0,display:"flex",flexDirection:"column",gap:"8px"},troubleshootItem:{display:"flex",alignItems:"flex-start",gap:"8px",fontSize:"11px",color:ee.textSecondary,lineHeight:1.5},troubleshootDot:{flexShrink:0,width:"4px",height:"4px",marginTop:"6px",borderRadius:"50%",background:ee.textSecondary}};import{useContext as ws,useEffect as hs,useRef as Cs}from"react";function ks(e){let t=ws(Ct);if(!t)throw new Error("useConnectKitAnalytics must be used within <CrossConnectKitProvider>");let n=Cs(e);n.current=e;let{subscribe:i}=t;hs(()=>i(c=>n.current(c)),[i])}import{useOnRamp as zi,useOnRampEligibility as Xi,OnRampProvider as Yi}from"@nexus-cross/onramp/react";import{useKyc as Ji,useOptionalKyc as ea,KycProvider as ta,KycError as na,launchKycVerification as oa}from"@nexus-cross/kyc/react";import{WalletInfo as sa,ConnectorId as ia}from"@nexus-cross/dapp-ui";import{AppLauncher as ca,AppLauncherTrigger as da,AppLauncherContent as la,useGlobalMenu as ua}from"@nexus-cross/dapp-ui";import{SkillsButton as pa}from"@nexus-cross/dapp-ui";import{OnRampError as ga}from"@nexus-cross/connect-kit-core";import{ConnectionStatus as ya,formatBalance as wa,formatWei as ha}from"@nexus-cross/connect-kit-core";en();export{Ge as a,mo as b,pt as c,Nt as d,Uo as e,Kt as f,Ut as g,ls as h,ys as i,ks as j,zi as k,Xi as l,Yi as m,Ji as n,ea as o,ta as p,na as q,oa as r,sa as s,ia as t,ca as u,da as v,la as w,ua as x,pa as y,ga as z,ya as A,wa as B,ha as C};
|