@nexus-cross/connect-kit-react 1.3.12-beta.1 → 1.3.12
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/README.md +18 -0
- package/dist/chunk-RLAXM7N4.js +144 -0
- package/dist/client.d.ts +2 -2
- package/dist/client.js +1 -1
- package/dist/index.d.ts +20 -3
- package/dist/index.js +1 -1
- package/package.json +7 -7
- package/dist/chunk-72GKZILX.js +0 -144
package/README.md
CHANGED
|
@@ -67,6 +67,24 @@ section.
|
|
|
67
67
|
|
|
68
68
|
## Components
|
|
69
69
|
|
|
70
|
+
### `<CrossGetOneUsd>`
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
// Mount once in a persistent app/root layout, not inside a route page.
|
|
74
|
+
<CrossGetOneUsd env="production" theme="dark" />
|
|
75
|
+
<CrossGetOneUsd env="production" theme="dark" mode="button" />
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
`floating` FAB 또는 레이아웃 안의 `button`에서 Swap, Bridge, Relay 입금을
|
|
79
|
+
선택하고 같은 화면에서 실행한다. 트랜잭션 상태는 두 모드 모두 우측 하단에
|
|
80
|
+
플로팅된다. `CrossConnectKitProvider` 아래에서 사용하면 원격 컨트랙트 페어,
|
|
81
|
+
CrossD transaction adapter, Relay wallet 함수가 자동으로 연결된다. Swap/Bridge
|
|
82
|
+
제출 뒤 FAB가 진행 상태로 전환되고, wagmi 영수증 확인이 끝날 때까지 중복 제출을
|
|
83
|
+
막은 뒤 완료 문구를 4초간 표시한다. 자세한 API는
|
|
84
|
+
[`docs/dapp-ui/get-one-usd.md`](../../docs/dapp-ui/get-one-usd.md)를 참고한다.
|
|
85
|
+
같은 SPA 안에서 페이지를 이동해도 플로팅 트랜잭션 상태를 유지하려면
|
|
86
|
+
`CrossGetOneUsd`를 라우터가 교체하지 않는 공통 App Layout에 한 번만 마운트한다.
|
|
87
|
+
|
|
70
88
|
### `<CrossConnectKitProvider>`
|
|
71
89
|
|
|
72
90
|
```tsx
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
var gt="1.3.12";var Tt="__nexusCrossAppLauncherRuntime";function go(){if(typeof window>"u")return null;let e=window;return e[Tt]??(e[Tt]={mode:"dapp-ui"}),e[Tt]}function yo(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??gt;console.info(`[CROSSx App Launcher] connect-kit-react v${n} \uCD08\uAE30\uD654 \uC644\uB8CC (dapp-ui v${gt}, \uC0AC\uC6A9 \uBAA8\uB4DC: connect-kit)`)}else console.info(`[CROSSx App Launcher] dapp-ui v${gt} \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 an(){let e=go();e&&(e.mode="connect-kit-react",e.connectKitVersion=gt,yo(e))}import{useCallback as _e,useEffect as oe,useMemo as Fe,useRef as ge,useState as Qe}from"react";import{WagmiProvider as Io,useAccount as vo,useChainId as Po,useConnect as So,useDisconnect as Ro,useSwitchChain as Ao}from"wagmi";import{QueryClient as Bo,QueryClientProvider as _o}from"@tanstack/react-query";import{clearWalletSessionStorage as mn,onOpenOtherWallets as Eo,pickInitialState as Oo,resolveCurrentWallet as No}from"@nexus-cross/connect-kit-wagmi";import{resolveThemeMode as Fo}from"@nexus-cross/connect-kit-core";import{buildDesignSystemCss as Wo}from"@nexus-cross/crossx-design-system";import{OnRampProvider as Do}from"@nexus-cross/onramp/react";import{KycProvider as Lo}from"@nexus-cross/kyc/react";import{createContext as bo,useContext as ho}from"react";var Dt=bo(null);function Be(){let e=ho(Dt);if(!e)throw new Error("useCrossConnectKit must be used within <CrossConnectKitProvider>");return e}import{createContext as wo,useContext as cn}from"react";var xt=wo(null);function Co(){let e=cn(xt);if(!e)throw new Error("useCrossConnectKitTheme must be used within <CrossConnectKitProvider>");return e}function yt(){return cn(xt)}import{createContext as ko}from"react";var It=ko(null);function dn(){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 To,useMemo as ln}from"react";import{WalletConnectModal as un}from"@nexus-cross/dapp-ui";import{jsx as pn}from"react/jsx-runtime";var xo=new Set(["cross_wallet","cross_extension","metamask","binance"]);function Lt({open:e,onOpenChange:t}){let{connect:n,availableWallets:i,oauth:o,extraWallets:c,walletAllowlist:g,kitConfig:y}=Be(),r=yt()?.mode??"dark",m=ln(()=>{let p=g?new Set(g):null,T={};for(let I of i){if(!xo.has(I.walletId)||p&&!p.has(I.walletId))continue;let v=I.walletId;T[v]=()=>{n(I.walletId)}}for(let[I,v]of Object.entries(c))v&&(p&&!p.has(I)||(T[I]=v));return T},[i,n,c,g]),h=ln(()=>{if(o)return{apple:()=>{o.signIn("apple")},google:()=>{o.signIn("google")}}},[o]),k=To(p=>t(p),[t]);return pn(un,{wallets:m,socialProviders:h,termsUrl:y.legal?.termsUrl,privacyUrl:y.legal?.privacyUrl,theme:r,open:e,onOpenChange:k,children:pn(un.Content,{})})}import{jsx as ze,jsxs as yn}from"react/jsx-runtime";var Go=new Bo,Gt="crossx-kit:last-wallet-intent",Mo=15e3,Uo=1500,Ko=3;function fn(e,t){return Promise.race([e.then(()=>{},()=>{}),new Promise(n=>setTimeout(n,t))])}function $o(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 qo(){if(typeof window>"u")return null;try{return window.localStorage.getItem(Gt)??null}catch{return null}}function gn(e){if(!(typeof window>"u"))try{e?window.localStorage.setItem(Gt,e):window.localStorage.removeItem(Gt)}catch{}}function Ho(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 Vo(e,t){if(!(typeof window>"u"))try{window.localStorage.setItem(e,t)}catch{}}function jo({children:e,config:t,activeProvider:n,onRequestProviderSwap:i,pendingConnectWalletId:o,clearPending:c,themeMode:g,themeTokens:y,extraWallets:u,walletAllowlist:r,emit:m}){let[h,k]=Qe(!1),[p,T]=Qe(()=>qo()),[I,v]=Qe(null),{address:F,isConnected:x,isConnecting:U,isReconnecting:D,connector:O}=vo(),{connectors:q,connectAsync:$}=So(),{disconnectAsync:z}=Ro(),{kitConfig:L,connectorRegistry:K,crossProvider:Re,reownProvider:pe}=t,N=n==="cross"?Re:pe,B=Fe(()=>!x||!O?null:No(K,O.id,p),[x,O,K,p]),Y=Fe(()=>K.entries.filter(l=>l.type!=="embedded"),[K]),V=_e(l=>K.getEntry(l)?.type??"external",[K]),ce=ge(null);ce.current=I;let Te=ge(B);Te.current=B;let He=ge(F);He.current=F;let Oe=L.embeddedProjectId?.trim()||L.crossProjectId?.trim(),xe=!!L.onRampEnabled&&!!Oe,Ve=Fe(()=>!xe||!Oe?null:{projectId:Oe,walletState:{getAddress:()=>He.current}},[xe,Oe]),be=ge(O);be.current=O;let me=L.embeddedProjectId?.trim()||L.crossProjectId?.trim(),Ge=!!L.kycEnabled&&!!me,et=Fe(()=>!Ge||!me?null:{projectId:me,getAccessToken:async()=>{let l=be.current;if(!(!l||typeof l.getProvider!="function"))try{return(await(await l.getProvider())?.sdk?.getUserInfo?.())?.data?.accessToken||void 0}catch{return}}},[Ge,me]);oe(()=>Eo(()=>k(!0)),[]),oe(()=>{if(!h||typeof document>"u")return;let l=setTimeout(()=>{document.querySelectorAll("#__crossx-confirm-overlay").forEach(b=>b.remove())},50);return()=>clearTimeout(l)},[h]);let fe=ge(x),at=ge(x);fe.current=x;let tt=ge(!1);oe(()=>{console.debug("[crossx-kit] state",{activeProvider:n,isConnected:x,isConnecting:U,isReconnecting:D,activeConnectorId:O?.id,currentWallet:B,lastIntent:p})},[n,x,U,D,O?.id,B,p]),oe(()=>{x&&!at.current&&N?.closeModal?.({kitConfig:L}),at.current=x},[x,N,L]),oe(()=>{x&&v(null)},[x]);let Ae=Po(),{switchChainAsync:Ie}=Ao(),he=ge(null);oe(()=>{if(!L.enforceDefaultNetworkOnConnect)return;let l=L.defaultNetwork?.id;if(!l)return;if(!x||!F||!O){he.current=null;return}let b=`${O.id}:${F}`;he.current!==b&&(he.current=b,Ae!==l&&Ie({chainId:l}).catch(()=>{}))},[L.enforceDefaultNetworkOnConnect,L.defaultNetwork,x,F,O,Ae,Ie]);let Me=ge(h);oe(()=>{h&&!Me.current?m({name:"connect_modal_opened"}):!h&&Me.current&&m({name:"connect_modal_closed",completed:fe.current}),Me.current=h},[h,m]);let ct=ge(x);oe(()=>{if(x&&!ct.current){let l=ce.current;l&&m({name:"connect_succeeded",walletId:l,walletType:V(l),chainId:Ae})}ct.current=x},[x,Ae,m,V]);let s=_e(l=>q.find(b=>b.id===l),[q]);oe(()=>{let l=K.getEntry("cross_embedded");if(!l)return;let b=s(l.connectorId);if(!b)return;let C=!1;return(async()=>{try{let A=await b.getProvider();if(C)return;A?.sdk?.applyTheme?.(g,y??void 0)}catch(A){console.debug("[crossx-kit] applyTheme skipped:",A)}})(),()=>{C=!0}},[K,s,g,y]);let a=_e(l=>{T(l),gn(l)},[]),d=_e(()=>{T(null),gn(null),v(null)},[]);oe(()=>{if(!N?.subscribeModalState)return;let l=!1;return N.subscribeModalState({kitConfig:L},b=>{if(tt.current=b,b){l=!0;return}l&&(l=!1,setTimeout(()=>{if(fe.current)return;let C=ce.current;C&&m({name:"connect_cancelled",walletId:C,stage:"popup"}),(async()=>{try{await z()}catch{}d()})()},250))})},[N,L,z,d,m]),oe(()=>{if(!I||x||typeof window>"u"||I==="cross_embedded")return;let l=typeof document<"u"&&!document.hasFocus(),b=null,C=()=>{l=!0},A=()=>{l&&(b&&clearTimeout(b),b=setTimeout(()=>{if(fe.current||tt.current)return;let R=ce.current;R&&m({name:"connect_cancelled",walletId:R,stage:"popup"}),(async()=>{try{await z()}catch{}d()})()},1e3))};return window.addEventListener("blur",C),window.addEventListener("focus",A),()=>{window.removeEventListener("blur",C),window.removeEventListener("focus",A),b&&clearTimeout(b)}},[I,x,z,d,m]);let f=_e(async l=>{console.debug("[crossx-kit] runConnect enter",{walletId:l,activeProvider:n,isConnected:x,activeConnectorId:O?.id});let b=K.getEntry(l);if(!b){if((l==="metamask"||l==="binance")&&!pe){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),b.providerKind!==n){console.debug("[crossx-kit] provider swap needed",{from:n,to:b.providerKind,walletId:l}),a(l);try{await z()}catch{}await new Promise(R=>setTimeout(R,0)),i(b.providerKind,l);return}let C=V(l);if(m({name:"wallet_selected",walletId:l,walletType:C}),m({name:"connect_started",walletId:l,walletType:C}),a(l),N?.beforeConnect)try{let R=await N.beforeConnect({kitConfig:L,themeMode:g},l);if(console.debug("[crossx-kit] beforeConnect result",{walletId:l,result:R}),R==="handled")return}catch(R){console.warn('[crossx-kit] adapter.beforeConnect threw for "%s":',l,R)}let A=s(b.connectorId);if(console.debug("[crossx-kit] findConnector",{lookupId:b.connectorId,found:A?.id,availableIds:q.map(R=>R.id)}),!A){console.error(`[crossx-kit] Connector "${b.connectorId}" not found on provider "${b.providerKind}". Available: ${q.map(R=>R.id).join(", ")}`),m({name:"connect_failed",walletId:l,reason:"connector_not_found"}),d();return}try{console.debug("[crossx-kit] connectAsync start",{connectorId:A.id});let R=await $({connector:A});console.debug("[crossx-kit] connectAsync resolved",{accountsLen:R.accounts.length,chainId:R.chainId});return}catch(R){let ve=$o(R);if(!ve){console.error('[crossx-kit] connectAsync error for "%s":',l,R);try{await z()}catch{}}if(!b.fallbackConnectorId){ve||m({name:"connect_failed",walletId:l,reason:"connector_error"}),d();return}}if(b.fallbackConnectorId){let R=s(b.fallbackConnectorId);if(R)try{await $({connector:R})}catch(ve){console.error('[crossx-kit] Fallback connect failed for "%s":',l,ve);try{await z()}catch{}m({name:"connect_failed",walletId:l,reason:"fallback_failed"}),d()}else m({name:"connect_failed",walletId:l,reason:"fallback_failed"}),d()}},[K,q,s,$,z,a,d,N,n,L,i,g,m,V]);oe(()=>{if(!o)return;let l=o;c(),f(l)},[o,n]);let w=_e(async()=>{k(!0)},[]),_=_e(async()=>{m({name:"disconnected",walletId:Te.current});try{await z()}catch(l){console.error("[crossx-kit] wagmi disconnect error:",l)}if(N?.teardown)try{await N.teardown({kitConfig:L})}catch(l){console.error("[crossx-kit] adapter teardown error:",l)}mn(),d()},[z,N,L,d,m]),S=_e(async()=>{await fn(z(),3e3);try{let l=K.getEntry("cross_embedded"),b=l&&s(l.connectorId);if(b?.getProvider){let C=await Promise.race([b.getProvider(),new Promise(R=>setTimeout(R,3e3))]),A=C?.sdk?.signOut;typeof A=="function"&&await fn(A.call(C.sdk),3e3)}}catch{}mn()},[K,s,z]),E=_e(async()=>{let l=K.getEntry("cross_embedded");if(!l)return null;let b=s(l.connectorId);if(!b)return null;try{let C=await b.getProvider(),A=C?.sdk;if(!A?.selectWallet)return null;let R=await A.selectWallet(A.currentAddress??void 0);return R?.address&&C.notifyAccountsChanged&&C.notifyAccountsChanged([R.address]),R&&m({name:"wallet_switched",index:R.index}),R}catch{return null}},[K,s,m]),G=Fe(()=>{let l=t.oauth;return l?{signIn:async b=>{v("cross_embedded"),m({name:"wallet_selected",walletId:"cross_embedded",walletType:"embedded"}),m({name:"connect_started",walletId:"cross_embedded",walletType:"embedded"});try{await l.signIn(b)}catch(C){throw m({name:"connect_cancelled",walletId:"cross_embedded",stage:"popup"}),v(null),C}}}:null},[t.oauth,m]),Z=ge(!1);oe(()=>{if(n!=="cross"||x||U||D||I!=null||Z.current)return;let l=K.getEntry("cross_embedded");if(!l)return;let b=s(l.connectorId);if(!b)return;Z.current=!0;let C=!1;return(async()=>{try{let A=await b.isAuthorized?.();if(C||!A)return;await $({connector:b})}catch{}})(),()=>{C=!0}},[n,x,U,D,I,K,s,$]);let P=ge(0);oe(()=>{if(n!=="cross"||x||!U&&!D||P.current>=Ko)return;let l=K.getEntry("cross_embedded");if(!l)return;let b=s(l.connectorId);if(!b)return;let C=!1,A=setInterval(()=>{(async()=>{if(C||fe.current)return;let R=await Promise.resolve(b.isAuthorized?.()).catch(()=>!1);if(!(C||!R||fe.current)){P.current+=1,console.warn("[crossx-kit] wagmi reconnect stalled while the SDK holds a session \u2014 forcing an explicit connect to realign");try{await $({connector:b})}catch{}}})()},Uo);return()=>{C=!0,clearInterval(A)}},[n,x,U,D,K,s,$]),oe(()=>{if(I!=="cross_embedded"||x||typeof window>"u")return;let l=!document.hasFocus(),b=()=>{l=!0};window.addEventListener("blur",b);let C=setTimeout(()=>{fe.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"),m({name:"connect_cancelled",walletId:"cross_embedded",stage:"stalled"}),d(),S())},Mo);return()=>{window.removeEventListener("blur",b),clearTimeout(C)}},[I,x,d,S,m]);let W=I!=null&&!x,j=Fe(()=>({kitConfig:L,connectorRegistry:K,availableWallets:Y,connect:f,connectWallet:w,disconnect:_,selectWallet:E,currentWallet:B,lastIntent:p,isConnecting:W,connectingWalletId:I,openOtherWallets:()=>k(!0),closeOtherWallets:()=>k(!1),otherWalletsOpen:h,oauth:G,extraWallets:u,walletAllowlist:r,onRampEnabled:xe}),[L,K,Y,f,w,_,E,B,p,W,I,h,G,u,r,xe]),H=yn(Dt.Provider,{value:j,children:[e,ze(Lt,{open:h,onOpenChange:k})]});return et&&(H=ze(Lo,{config:et,children:H})),Ve&&(H=ze(Do,{config:Ve,children:H})),H}var Qo=[/Connection interrupted while trying to subscribe/i,/No matching key\. subscription:/i,/Proposal expired/i];function zo(e){let t=e?.message;return typeof t!="string"?!1:Qo.some(n=>n.test(t))}var Xo={};function Yo(e){return e&&{...e,connections:new Map,current:null}}function Zo({children:e,config:t,initialState:n,extraWallets:i=Xo,walletAllowlist:o}){let[c,g]=Qe(()=>Ho(t.activeProviderStorageKey,t.defaultProvider)),[y,u]=Qe(null),r=ge(!1),m=ge(null);m.current||(m.current=dn());let h=m.current,k=Fe(()=>({subscribe:h.subscribe}),[h]),{kitConfig:p}=t,[T,I]=Qe(null),[v,F]=Qe(null),[x,U]=Qe(0),D=Fe(()=>Fo(p.theme,p.autoDetectTheme),[p.theme,p.autoDetectTheme,x]),O=T??D,q=v??p.themeTokens;oe(()=>{if(!p.autoDetectTheme||T||typeof window>"u"||!window.matchMedia)return;let B=window.matchMedia("(prefers-color-scheme: dark)"),Y=()=>U(V=>V+1);try{return B.addEventListener("change",Y),()=>B.removeEventListener("change",Y)}catch{return B.addListener(Y),()=>B.removeListener(Y)}},[p.autoDetectTheme,T]),oe(()=>{if(typeof document>"u")return;let B=document.documentElement,Y=B.getAttribute("data-ds-theme"),V=B.getAttribute("data-theme");return B.setAttribute("data-ds-theme",O),V||B.setAttribute("data-theme",O),()=>{Y==null?B.removeAttribute("data-ds-theme"):B.setAttribute("data-ds-theme",Y),V==null&&B.removeAttribute("data-theme")}},[O]);let $=Fe(()=>Wo(t.designSystem),[t.designSystem]),z=Fe(()=>({mode:O,tokens:q,setThemeMode:B=>I(B),setThemeTokens:B=>F(B)}),[O,q]);oe(()=>{if(typeof window>"u")return;let B=Y=>{zo(Y.reason)&&Y.preventDefault()};return window.addEventListener("unhandledrejection",B),()=>window.removeEventListener("unhandledrejection",B)},[]);let L=_e((B,Y)=>{r.current||(r.current=!0,u(Y),g(B),Vo(t.activeProviderStorageKey,B),queueMicrotask(()=>{r.current=!1}))},[t.activeProviderStorageKey]),K=_e(()=>u(null),[]),Re=c==="cross"?t.crossWagmiConfig:t.reownWagmiConfig,pe=Yo(Oo(n,c));if(!Re){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 N=Re??(c==="cross"?t.reownWagmiConfig:t.crossWagmiConfig);return ze(It.Provider,{value:k,children:yn(xt.Provider,{value:z,children:[ze("style",{"data-crossx-design-system":"",children:$}),ze(Io,{config:N,initialState:pe,children:ze(_o,{client:Go,children:ze(jo,{config:t,activeProvider:c,onRequestProviderSwap:L,pendingConnectWalletId:y,clearPending:K,themeMode:O,themeTokens:q,extraWallets:i,walletAllowlist:o??t.kitConfig.wallets??null,emit:h.emit,children:e})})},c)]})})}import{useCallback as Ze,useEffect as os,useMemo as _t}from"react";import{useQueryClient as rs}from"@tanstack/react-query";import{useAccount as ss,useChainId as is,useConfig as as,useSendTransaction as cs,useSwitchChain as ds}from"wagmi";import{getPublicClient as Vt,readContracts as Kn}from"wagmi/actions";import{WalletInfo as jt,ConnectorId as Je,resolveEnvironment as ls}from"@nexus-cross/dapp-ui";import{useOptionalOnRamp as us,useOptionalOnRampEligibility as ps}from"@nexus-cross/onramp/react";import{APPLE_ICON as Yt,BINANCE_ICON as Hn,CROSSX_ICON as Xt,EXTENSION_ICON as ms,GOOGLE_ICON as Vn,METAMASK_ICON as jn}from"@nexus-cross/connect-kit-wagmi";import{WALLET_LABELS as Et}from"@nexus-cross/crossx-design-system";import{useCallback as re,useMemo as ke,useRef as Jo}from"react";import{useQueries as wn,useQuery as Xe}from"@tanstack/react-query";import{encodeFunctionData as bt,formatUnits as Bt,parseSignature as er,parseUnits as tr}from"viem";import{getChainId as Mt,getPublicClient as On,readContract as Ee,signTypedData as nr,switchChain as Cn,waitForTransactionReceipt as or,writeContract as kn}from"wagmi/actions";import{useConfig as rr}from"wagmi";async function vt(e,t,n){if(!(!n||t===void 0))try{if(e.getChainId()===t)return;await e.switchChain(t)}catch{}}var ut=10000n;function bn(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 Pt(e,t){let n=bn(t);return n>=ut?0n:e*(ut-n)/ut}function hn(e,t){let n=bn(t);return(e*(ut+n)+(ut-1n))/ut}function sr(e){return e!=="bridge"}var qe="0x0000000000000000000000000000000000000000",Se=100,mt=18,ir=180000n,ar=250000n,Nn=new Set([56,97]),cr=130n,dr=100n,lr={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"},ur={dev:"dev",stage:"stg",production:"prod"};function pr(e,t){let n=e?.[ur[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 mr={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"},fr=["BSC_CROSS","W_CROSS","NATIVE_CROSS","USDTX","CROSSD","USDTB","SWAP_BRIDGE_ROUTER"],gr={BSC_CROSS:qe,W_CROSS:qe,NATIVE_CROSS:qe,USDTX:qe,CROSSD:qe,USDTB:qe,SWAP_BRIDGE_ROUTER:qe},yr=/^0x[0-9a-fA-F]{40}$/;function br(e,t){let n=typeof e=="string"?e:e?.[t];return typeof n=="string"&&yr.test(n)?n:null}function hr(e,t){if(!e?.bridge)return null;let n=e.envToNetwork?.[t]??(t==="production"?"mainnet":"testnet"),i={};for(let o of fr){let c=br(e.bridge[o],n);if(!c)return null;i[o]=c}return i}var wr={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}}},ot=[{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"}]}],Ut=[{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"}]}],Tn=[{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"}]}],xn=[{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"}]}],Cr=[{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:[]}],kr=[{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 Fn(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 We(e,t){let n=await fetch(e,{cache:"no-store",signal:t});if(!n.ok)throw new Error(`CrossD bridge adapter request failed: ${await Fn(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 In(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 Fn(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 Tr(e){return new Promise(t=>setTimeout(t,e))}async function xr(e,t,{attempts:n=60,intervalMs:i=2e3}={}){for(let o=0;o<n;o+=1){try{let c=await We(`${e}/permit-hash/${t}`);if(qt(c))return c}catch{}await Tr(i)}return null}function ie(e,t){return`${e}-${t.toLowerCase()}`}function le(e){return ie(e.chainId,e.address)}function De(e){return e==="swap"||e==="deposit-swap"||e==="swap-withdraw"}function Ir(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 vn(e){return e===56||e===97?"BSC":e===612044||e===612055?"ONEchain":`Chain ${e}`}function se(e,t){return t?t.toLowerCase()===e.contracts.NATIVE_CROSS.toLowerCase()?e.contracts.W_CROSS:t:qe}function rt(e){let t=Bt(e,mt);return t.includes(".")?t.replace(/\.?0+$/,""):t}function wt(e){return tr(e||"0",mt)}function ye(e){try{return wt(e||"0")}catch{return 0n}}function Ye(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 Kt(e){let t=Bt(e,9);return(t.includes(".")?t.replace(/\.?0+$/,""):t)||"0"}function St(e){return e==="bridge"?ir:ar}function Pn(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 vr(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=On(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*cr/dr:r)}catch{}let u={gas:y};if(Nn.has(t))try{let r=await g?.getGasPrice?.();typeof r=="bigint"&&r>0n&&(u.gasPrice=r)}catch{}else if(c)try{let r=await g?.estimateFeesPerGas?.();typeof r?.maxFeePerGas=="bigint"&&(u.maxFeePerGas=r.maxFeePerGas),typeof r?.maxPriorityFeePerGas=="bigint"&&(u.maxPriorityFeePerGas=r.maxPriorityFeePerGas)}catch{}return u}function ht(){return BigInt(Math.floor(Date.now()/1e3)+1800)}var Pr={100:"0.01%",500:"0.05%",3e3:"0.3%",1e4:"1%"};function Sr(e){return Pr[e]??`${e/1e4}%`}function Rr(e,t){let n=Number(e||"0");return!Number.isFinite(n)||n<=0?"0":(n*t/1e6).toFixed(8).replace(/\.?0+$/,"")}function Rn(e){return rt(e)}function An(e,t){let n=Number(t??"0");return!Number.isFinite(n)||n<=0?0n:e*BigInt(Math.floor(n))/1000n}function Rt(e,t){if(!e)return!1;let n=e.toLowerCase();return t.some(i=>i.toLowerCase()===n)}function Ar(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=>Rt(t,o.from)&&Rt(n,o.to)||Rt(t,o.to)&&Rt(n,o.from))}function Br(e){if(De(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 _r({input:e,path:t,config:n}){if(!n||De(t.type))return"";let i=Ye(n.minimumValue),o=Ye(n.gasFee??n.gas_fee),c=t.type==="swap-bridge"?i+o*12n/10n:i;return c<=0n?"":e.fromAmount&&ye(e.fromAmount)<c&&t.type!=="swap"?`Minimum ${Rn(c)}`:t.type==="swap-bridge"&&e.toAmount&&ye(e.toAmount)<c?`Available ${Rn(c)} or more.`:""}function Er({input:e,path:t,config:n}){if(!n||t.type!=="bridge"&&t.type!=="bridge-swap")return"";let i=Ye(n.gasFee??n.gas_fee);if(i<=0n||!e.fromAmount)return"";let o=ye(e.fromToken.balance||"0"),c=ye(e.fromAmount);return o-i<c?`Insufficient network fee(${e.fromToken.symbol})`:""}function Or(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(ie(o,y.localToken)),y.remoteToken&&n.add(ie(Number(c),y.remoteToken))})})}),Object.entries(t?.swapPools||t?.swap_pools||{}).forEach(([i,o])=>{o.forEach(c=>{c.token0&&n.add(ie(Number(i),c.token0)),c.token1&&n.add(ie(Number(i),c.token1))})}),n}function Nr(e,t){return!e||!t?null:ie(e,t)}function Fr({envConfig:e,bridgePairList:t,swapPools:n,tokenInfo:i,tokenStats:o}){let c=Or(t,n),g=new Map;o?.forEach(u=>{let r=Nr(Number(u.chainId??u.chain_id),u.address);r&&g.set(r,u)});let y={};return c.forEach(u=>{let[r,m]=u.split("-"),h=Number(r),k=i?.find(T=>Number(T.chainId??T.chain_id)===h&&T.address?.toLowerCase()===m);if(!k?.symbol||!k.name)return;let p=g.get(u);y[u]={key:u,chainId:h,address:m,symbol:k.symbol,name:k.name,decimals:k.decimals||mt,image:k.image||k.icon_url,price:p?.price?Number(p.price):void 0,isNativeToken:m.toLowerCase()===e.contracts.NATIVE_CROSS.toLowerCase()}}),y}function Wn(e,t){return t?.list?.find(n=>(n.localChain??n.local_chain)===e)?.bridge||""}function Dn(e,t,n){let[i,o]=e.split("-"),[c,g]=t.split("-"),y=Number(i),u=Number(c);for(let r of n?.list||[]){if((r.localChain??r.local_chain)!==y)continue;let m=r.pairs?.[c];if(m){for(let h of m)if(h.localToken?.toLowerCase()===o&&h.remoteToken?.toLowerCase()===g)return{type:"bridge",fromChain:y,fromToken:o,toChain:u,toToken:g,bridgeAddress:Wn(y,n)}}}return null}function Ln(e,t,n,i){let o,c=1/0;for(let g of e||[]){let y=i(g.token0),u=i(g.token1);if(y===t&&u===n||u===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 Gn(e,t,n,i){let[o,c]=e.split("-"),[g,y]=t.split("-");if(o!==g)return null;let u=Number(o),r=(n?.swapPools||n?.swap_pools)?.[o];if(!r)return null;let m=i.contracts.W_CROSS.toLowerCase(),h=i.contracts.NATIVE_CROSS.toLowerCase(),p=Ln(r,c,y,I=>I?.toLowerCase()===m?h:I?.toLowerCase());if(!p)return null;let T="swap";return u===i.chainIds.cross&&(c===h&&(T="deposit-swap"),y===h&&(T="swap-withdraw")),{pathType:T,step:{type:"swap",chain:u,fromToken:c,toToken:y,fee:p.fee,poolAddress:p.poolAddress}}}function Wr(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]||[],u=r=>r?.toLowerCase();for(let r of y){let m=u(r.token0),h=u(r.token1),k=m===c?h:h===c?m:null;if(!k)continue;let p=Dn(ie(Number(o),k),t,i);if(!p)continue;let T=Ln(y,c,k,u);return[{type:"swap",chain:Number(o),fromToken:c,toToken:k,fee:T?.fee??Se,poolAddress:T?.poolAddress??""},p]}return null}function Dr(e,t,n,i,o){let[c,g]=e.split("-"),[y]=t.split("-");if(c===y)return null;for(let u of n?.list||[])if((u.localChain??u.local_chain)===Number(c))for(let r of u.pairs?.[y]||[]){if(r.localToken?.toLowerCase()!==g)continue;let m=r.remoteToken?.toLowerCase();if(!m)continue;let h=Gn(ie(Number(y),m),t,i,o);if(h)return[{type:"bridge",fromChain:Number(c),fromToken:g,toChain:Number(y),toToken:m,bridgeAddress:Wn(Number(c),n)},h.step]}return null}function Lr({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 u=Dn(o,c,t);if(u)return{type:"bridge",steps:[u],from:g,to:y};let r=Gn(o,c,n,e);if(r)return{type:r.pathType,steps:[r.step],from:g,to:y};let m=Wr(o,c,n,t);if(m)return{type:"swap-bridge",steps:m,from:g,to:y};let h=Dr(o,c,t,n,e);return h?{type:"bridge-swap",steps:h,from:g,to:y}:null}}function Bn(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 Gr(e){return e.length<=10?e:`${e.slice(0,6)}...${e.slice(-4)}`}function Mr(e){return e.includes(".")?e.replace(/\.?0+$/,"")||"0":e}function Ur(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 Kr(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 $t(e){if(e==null||e==="")return"0";let t=String(e),n=Number(t);return!Number.isFinite(n)||n===0?"0":Kr(Ur(t,4))}function _n(e,t){if(e==null||e==="")return"0";try{return Mr(Bt(BigInt(String(e)),t.decimals))}catch{return"0"}}function qt(e){return!!(e&&/^0x[0-9a-fA-F]+$/.test(e))}function $r(e){return e?new Date(e*1e3).toISOString():new Date().toISOString()}function qr(e,t){return t.toLowerCase()===e.contracts.W_CROSS.toLowerCase()?e.contracts.NATIVE_CROSS:t}function Hr(e,t){let n=Gr(t);return{name:n,symbol:n,chainId:e,address:t,decimals:mt,balance:"0"}}function En({envConfig:e,tokenByBridgeKey:t,chainId:n,address:i}){if(!i)return null;let o=qr(e,i);return t.get(ie(n,o))||t.get(ie(n,i))||Hr(n,o)}function At(e){return e?.toLowerCase()||""}function Vr(e){if(e.source==="swap")return"swap";let t=At(e.fromToken??e.from_token),n=At(e.toToken??e.to_token),i=At(e.swapTokenIn??e.swap_token_in),o=At(e.swapTokenOut??e.swap_token_out);return n&&i&&n===i?"bridge-swap":t&&o&&t===o?"swap-bridge":"bridge"}function jr(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 Qr({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=Vr(t),g=t.swapTokenIn??t.swap_token_in,y=t.swapTokenOut??t.swap_token_out,u=t.swapAmountIn??t.swap_amount_in,r=t.swapAmountOut??t.swap_amount_out,m=t.fromToken??t.from_token,h=t.toToken??t.to_token,k=t.value,p=t.value;c==="swap"?(m=g,h=y,k=u,p=r):c==="swap-bridge"?(m=g,k=u,p=t.value):c==="bridge-swap"&&(h=y,k=u,p=r);let T=En({envConfig:e,tokenByBridgeKey:n,chainId:i,address:m}),I=En({envConfig:e,tokenByBridgeKey:n,chainId:o,address:h}),v=t.initiatedTxHash??t.initiated_tx_hash;return!T||!I||!qt(v)?null:{id:`${v}-${t.index??""}`,timestamp:$r(t.initiatedTime??t.initiated_time),txHash:v,fromToken:T,toToken:I,fromAmount:_n(k,T),toAmount:_n(p,I),summary:{pathType:c},status:jr(t,c)}}function zr(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??mt;try{t.set(ie(i,o),Bt(BigInt(c||"0"),g))}catch{t.set(ie(i,o),"0")}}),t}function $e(e,t="first"){let n=e.steps.filter(i=>i.type==="swap");return t==="last"?n[n.length-1]:n[0]}function Xr(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(),u=g.token1?.toLowerCase();return y===i&&u===o||y===o&&u===i});return c?.poolAddress||c?.pool_address||""}function Yr(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(mt),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 pt(e,t,n,i){let o=[e.from,e.to].find(c=>c.chainId===t&&c.address.toLowerCase()===n.toLowerCase())??i?.[ie(t,n)];return{symbol:o?.symbol||n.slice(0,6),iconUrl:o?.image}}function Jr(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=>pt(e,o.chain,o.address,t))}function es({input:e,path:t,amountData:n,gasInfo:i,liquidity:o,enrichedTokens:c,priceImpact:g}){let y=e.fromAmount||"0",u=e.toAmount||"0",r=$e(t),m=t.steps.find(U=>U.type==="bridge"),h=t.type!=="bridge",k=!De(t.type),p=r?Rr(y,r.fee):"0",T=Number(y)>0||Number(u)>0,I=r?pt(t,r.chain,r.fromToken,c):{symbol:e.fromToken.symbol,iconUrl:e.fromToken.iconUrl},v=r?pt(t,r.chain,r.toToken,c):{symbol:e.toToken.symbol,iconUrl:e.toToken.iconUrl},F=m?pt(t,m.fromChain,m.fromToken,c):void 0,x=(U,D,O)=>T?D&&D>0n?{label:U,value:rt(D),tone:"default",valueToken:O}:{label:U,value:"Free",tone:"accent"}:{label:U,value:"0"};return{pathType:t.type,priceImpact:g,liquidity:o,bridgeInfo:k&&m?[{label:"Route",value:`${vn(m.fromChain)} \u2192 ${vn(m.toChain)}`},x("Validator Fee",n?.exFee,F),x("Network Fee",n?.networkFee,F)]:void 0,swapInfo:h&&r?[{label:"Route",value:"",routeTokens:[pt(t,r.chain,r.fromToken,c),pt(t,r.chain,r.toToken,c)]},{label:"Price Impact",value:vr(g)},{label:"In Amount",value:$t(y),valueToken:I},{label:r&&De(t.type)?`Swap Fee (${Sr(r.fee??Se)})`:"Swap Fee",value:$t(p),valueToken:I},{label:"Out Amount",value:$t(u),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 Ct({env:e,walletAddress:t,enabled:n=!0,restoreChainAfterSwitch:i=!0}){let o=rr(),c=Jo(new Map),y=Xe({queryKey:["crossd-bridge-adapter",e,"remote-contracts"],queryFn:async({signal:s})=>{let a=hr(await We(mr[e],s),e);if(!a)throw new Error("CrossD bridge adapter: invalid contracts.json");return a},enabled:n,staleTime:5*6e4}).data??null,u=n&&!!y,r=ke(()=>({...wr[e],contracts:y??gr}),[e,y]),m=Xe({queryKey:["crossd-bridge-adapter",e,"pairs"],queryFn:({signal:s})=>We(`${r.bridgeApi}/pairs`,s),enabled:u,staleTime:3e4}),h=Xe({queryKey:["crossd-bridge-adapter",e,"swap-pools"],queryFn:({signal:s})=>We(`${r.bridgeApi}/swap-pools`,s),enabled:u,staleTime:3e4}),k=ke(()=>Xr(h.data,r),[r,h.data]),p=Xe({queryKey:["crossd-bridge-adapter",e,"available-liquidity",k],queryFn:async()=>await Ee(o,{address:r.contracts.USDTX,abi:Ut,functionName:"balanceOf",args:[k],chainId:r.chainIds.cross}),enabled:u&&!!k,staleTime:3e4}),T=Xe({queryKey:["crossd-bridge-adapter",e,"token-info"],queryFn:({signal:s})=>We(`${r.walletApi}/v1/public/token/info`,s),enabled:u,staleTime:3e4}),I=Xe({queryKey:["crossd-bridge-adapter",e,"token-stats"],queryFn:({signal:s})=>We(`${r.walletApi}/v1/public/token/stats`,s),enabled:u,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 We(`${r.walletApi}/v1/public/token/balance?${d}`,a)},enabled:u&&!!t,staleTime:0,refetchInterval:u&&t?5e3:!1}))}),F=wn({queries:[r.chainIds.cross,r.chainIds.bsc].map(s=>({queryKey:["crossd-bridge-adapter",e,"gas-suggestion",s],queryFn:async({signal:a})=>{try{let w=await On(o,{chainId:s})?.estimateFeesPerGas?.();if(w?.maxFeePerGas||w?.gasPrice)return{fast:{maxFee:w.maxFeePerGas?.toString()||w.gasPrice?.toString(),maxPriorityFee:w.maxPriorityFeePerGas?.toString()||"0"}}}catch{}let d=new URLSearchParams({chain_id:String(s),without_gas_limit:"false"});return We(`${r.walletApi}/v1/public/transaction/gas-suggestion/dynamic?${d}`,a)},enabled:u,staleTime:1e4,retry:1}))}),x=Xe({queryKey:["crossd-bridge-adapter",e,"hidden-pairs"],queryFn:async({signal:s})=>pr(await We(lr[e],s),e),enabled:u,staleTime:5*6e4,retry:1}),U=ke(()=>x.data??[],[x.data]),D=ke(()=>Fr({envConfig:r,bridgePairList:m.data,swapPools:h.data,tokenInfo:T.data,tokenStats:I.data}),[m.data,r,h.data,T.data,I.data]),O=ke(()=>Lr({envConfig:r,bridgePairList:m.data,swapPools:h.data,enrichedTokens:D}),[m.data,D,r,h.data]),q=ke(()=>zr(v.map(s=>s.data).filter(s=>Array.isArray(s))),[v]),$=ke(()=>{let s=new Map;return Object.values(D).forEach(a=>{let d=Bn(a,q);s.set(a.key,d)}),s},[q,D]),z=ke(()=>{let s=new Map,a=$.get(ie(r.chainIds.cross,r.contracts.NATIVE_CROSS));a&&s.set(r.chainIds.cross,{symbol:a.symbol,iconUrl:a.iconUrl});let d=T.data?.find(f=>Number(f.chainId??f.chain_id)===r.chainIds.bsc&&(f.symbol??"").toUpperCase()==="BNB");return d&&s.set(r.chainIds.bsc,{symbol:d.symbol??"BNB",iconUrl:d.image??d.icon_url}),s},[r,$,T.data]),L=Xe({queryKey:["crossd-bridge-adapter",e,"history",t],queryFn:({signal:s})=>In(`${r.bridgeApi}/history`,{owner:t,page:1,size:20,sort:"desc",status:"all"},s),enabled:u&&!!t,staleTime:0,refetchInterval:u&&t?5e3:!1}),K=ke(()=>(L.data?.histories||[]).map(s=>Qr({envConfig:r,item:s,tokenByBridgeKey:$})).filter(s=>!!s),[L.data?.histories,r,$]),Re=ke(()=>Zr(p.data),[p.data]),pe=F[0]?.data,N=F[1]?.data,B=ke(()=>{let s=new Map;return pe&&s.set(r.chainIds.cross,pe),N&&s.set(r.chainIds.bsc,N),s},[N,pe,r.chainIds.bsc,r.chainIds.cross]),Y=re((s,a,d)=>{let f=B.get(s.from.chainId)?.fast,w=a?d?.gasLimit??St(s.type):0n,_=d?.gasPrice&&d.gasPrice>0n?d.gasPrice:0n,S=d?.maxFeePerGas&&d.maxFeePerGas>0n?d.maxFeePerGas:0n,E=d?.maxPriorityFeePerGas&&d.maxPriorityFeePerGas>0n?d.maxPriorityFeePerGas:0n,G=Ye(f?.maxFee??f?.max_fee),Z=Ye(f?.maxPriorityFee??f?.max_priority_fee),P=S>0n?S:G>0n?G:_,W=E>0n?E:Z>0n?Z:P,j=_>0n?_:P,X=Nn.has(s.from.chainId)&&j>0n,l=w*(X?j:P),b=$.get(ie(s.from.chainId,r.contracts.NATIVE_CROSS)),C=s.type!=="swap-bridge",A=z.get(s.from.chainId);return{estTxFee:a?rt(l):"0",priorityFeePerGas:a&&!X?Kt(W):"0",maxFeePerGas:a&&!X?Kt(P):"0",gasLimit:a?w.toString():"0",gasPrice:a&&X?Kt(j):void 0,isDelegateFee:s.type==="swap-bridge"?!1:Ar(r,s.from.address,s.to.address),tokenIconUrl:C?b?.iconUrl:void 0,tokenSymbol:C?b?.symbol:void 0,gasCurrencyIconUrl:A?.iconUrl,gasCurrencySymbol:A?.symbol}},[r,B,z,$]),V=re(async s=>{let a=Br(s);if(!a)return null;let d=`${e}:${a.from}:${a.to}:${a.token.toLowerCase()}`,f=c.current.get(d);if(f)return f;let w=(async()=>{let _=new URLSearchParams({from:String(a.from),to:String(a.to),token:a.token});try{return(await We(`${r.bridgeApi}/token-config?${_}`)).config??null}catch{return null}})();return c.current.set(d,w),w},[e,r.bridgeApi]),ce=ke(()=>{let s=Object.values(D).map(d=>Bn(d,q)),a=ie(r.chainIds.cross,r.contracts.CROSSD);return s.sort((d,f)=>{let w=le(d).toLowerCase()===a.toLowerCase(),_=le(f).toLowerCase()===a.toLowerCase();return w!==_?w?-1:1:le(d).localeCompare(le(f))})},[q,D,r]),Te=ke(()=>{if(y)return{target:{chainId:r.chainIds.cross,address:r.contracts.CROSSD},swap:{from:{chainId:r.chainIds.cross,address:r.contracts.NATIVE_CROSS},feeDelegated:!0},bridge:{from:[{chainId:r.chainIds.bsc,address:r.contracts.USDTB},{chainId:r.chainIds.cross,address:r.contracts.USDTX}]}}},[r,y]),He=re(s=>{let a=le(s),d=a.toLowerCase(),f=[];Object.keys(D).forEach(S=>{let E=S.toLowerCase();if(d===E||U.some(P=>P.fromKey===d&&P.toKey===E))return;let G=O(a,S);if(!G)return;let Z=$.get(S);Z&&f.push({token:Z,path:G})});let w=ie(r.chainIds.cross,r.contracts.CROSSD),_=ie(r.chainIds.cross,r.contracts.NATIVE_CROSS);return f.sort((S,E)=>{if(d===w.toLowerCase()){let j=le(S.token).toLowerCase()===_.toLowerCase(),X=le(E.token).toLowerCase()===_.toLowerCase();if(j!==X)return j?-1:1}let G=De(S.path.type),Z=De(E.path.type);if(G!==Z)return G?-1:1;let P=S.token.chainId===s.chainId,W=E.token.chainId===s.chainId;return P!==W?P?-1:1:le(S.token).localeCompare(le(E.token))}),f.map(S=>S.token)},[D,r,O,U,$]),Oe=re(async s=>await Ee(o,{address:r.contracts.SWAP_BRIDGE_ROUTER,abi:ot,functionName:"quoter",chainId:s}),[r.contracts.SWAP_BRIDGE_ROUTER,o]),xe=re(async s=>{Mt(o)!==s&&await Cn(o,{chainId:s})},[o]),Ve=re(s=>vt({getChainId:()=>Mt(o),switchChain:a=>Cn(o,{chainId:a})},s,i),[i,o]),be=re(async s=>await Ee(o,{address:r.contracts.SWAP_BRIDGE_ROUTER,abi:ot,functionName:"swapRouter",chainId:s}),[r.contracts.SWAP_BRIDGE_ROUTER,o]),me=re(async({path:s,step:a,amount:d,source:f})=>{let w=await Oe(a.chain),_=a.poolAddress?Ee(o,{address:a.poolAddress,abi:Cr,functionName:"slot0",chainId:a.chain}).then(G=>G?.[0]).catch(()=>{}):Promise.resolve(void 0);if(f==="from"){let G=await Ee(o,{address:w,abi:xn,functionName:"quoteExactInputSingle",args:[{tokenIn:se(r,a.fromToken),tokenOut:se(r,a.toToken),amountIn:wt(d),fee:a.fee??Se,sqrtPriceLimitX96:0n}],chainId:a.chain}),Z=Pn(await _,G[1]);return{amount:rt(G[0]),path:s,priceImpact:Z}}let S=await Ee(o,{address:w,abi:xn,functionName:"quoteExactOutputSingle",args:[{tokenIn:se(r,a.fromToken),tokenOut:se(r,a.toToken),amount:wt(d),fee:a.fee??Se,sqrtPriceLimitX96:0n}],chainId:a.chain}),E=Pn(await _,S[1]);return{amount:rt(S[0]),path:s,priceImpact:E}},[r,Oe,o]),Ge=re(async(s,a)=>{if(!t)throw new Error("Wallet is not connected.");let d=St(a.type);if(De(a.type)){let P=$e(a,"first");if(!P)throw new Error("Swap route is not available.");let W=ye(s.fromAmount),j=ye(s.toAmount);if(W<=0n)throw new Error("Bridge amount is empty.");if(j<=0n)throw new Error("Bridge quote is not ready.");let X=await be(P.chain),H=Pt(j,s.slippage),l=a.type==="swap-withdraw"?qe:t,b={tokenIn:se(r,P.fromToken),tokenOut:se(r,P.toToken),fee:P.fee??Se,recipient:l,deadline:ht(),amountIn:W,amountOutMinimum:H,sqrtPriceLimitX96:0n};if(a.type==="swap-withdraw"){let C=bt({abi:Ke,functionName:"exactInputSingle",args:[b]}),A=bt({abi:Ke,functionName:"unwrapWETH9",args:[H,t]});return{address:X,abi:Ke,functionName:"multicall",args:[[C,A]],chainId:P.chain,fallbackGasLimit:d}}if(a.type==="deposit-swap"){let C=bt({abi:Ke,functionName:"exactInputSingle",args:[b]}),A=bt({abi:Ke,functionName:"refundETH",args:[]});return{address:X,abi:Ke,functionName:"multicall",args:[[C,A]],value:W,chainId:P.chain,fallbackGasLimit:d}}return{address:X,abi:Ke,functionName:"exactInputSingle",args:[b],chainId:P.chain,fallbackGasLimit:d}}if(a.type==="swap-bridge"){let P=$e(a,"first");if(!P)throw new Error("Swap bridge route is not available.");let W=ye(s.fromAmount),j=ye(s.toAmount);if(W<=0n)throw new Error("Bridge amount is empty.");if(j<=0n)throw new Error("Bridge quote is not ready.");let X=r.contracts.SWAP_BRIDGE_ROUTER,H=ht(),l={toChainID:BigInt(a.to.chainId),recipient:t,extraData:"0x"},b={tokenIn:se(r,a.from.address),tokenOut:se(r,P.toToken),fee:P.fee??Se,sqrtPriceLimitX96:0n,bridgeParams:l};if(s.lastChangedBy==="to"){let A={...b,amountOut:j,amountInMaximum:hn(W,s.slippage)};return{address:X,abi:ot,functionName:"swapBridgeExactOutputSingle",args:[A,H],value:a.from.isNativeToken?A.amountInMaximum:void 0,chainId:a.from.chainId,fallbackGasLimit:d}}let C={...b,amountIn:W,amountOutMinimum:Pt(j,s.slippage)};return{address:X,abi:ot,functionName:"swapBridgeExactInputSingle",args:[C,H],value:a.from.isNativeToken?W:void 0,chainId:a.from.chainId,fallbackGasLimit:d}}let f=a.steps.find(P=>P.type==="bridge");if(!f?.bridgeAddress)throw new Error("Bridge route is not available.");let w=ye(s.fromAmount);if(w<=0n)throw new Error("Bridge amount is empty.");let _=await V(a),S=Ye(_?.gasFee??_?.gas_fee),E=An(w,_?.exFeeRate??_?.ex_fee_rate),G="0x";if(a.type==="bridge-swap"){let P=$e(a,"last");if(!P)throw new Error("Bridge swap route is not available.");let W=ye(s.toAmount);if(W<=0n)throw new Error("Bridge quote is not ready.");let j=await be(a.to.chainId),X=Pt(W,s.slippage),H=bt({abi:Ke,functionName:"exactInputSingle",args:[{tokenIn:se(r,P.fromToken),tokenOut:se(r,P.toToken),fee:P.fee??Se,recipient:t,deadline:ht(),amountIn:w,amountOutMinimum:X,sqrtPriceLimitX96:0n}]});G=`${j}${H.slice(2)}`}let Z=[BigInt(a.to.chainId),a.from.address,t,w,S,E,G];return{address:f.bridgeAddress,abi:kr,functionName:"bridgeToken",args:Z,value:a.from.isNativeToken?w+E+S:void 0,chainId:a.from.chainId,fallbackGasLimit:d}},[r,V,be,t]),et=re(async(s,a)=>{if(a.type==="bridge"||a.type==="bridge-swap")return Ge(s,a);if(!t)throw new Error("Wallet is not connected.");let d=ye(s.fromAmount);if(d<=0n)throw new Error("Bridge amount is empty.");if(a.type==="swap-bridge"){let S=$e(a,"first");if(!S)throw new Error("Swap bridge route is not available.");let E=r.contracts.SWAP_BRIDGE_ROUTER,G={tokenIn:se(r,a.from.address),tokenOut:se(r,S.toToken),fee:S.fee??Se,sqrtPriceLimitX96:0n,bridgeParams:{toChainID:BigInt(a.to.chainId),recipient:t,extraData:"0x"},amountIn:d,amountOutMinimum:0n};return{address:E,abi:ot,functionName:"swapBridgeExactInputSingle",args:[G,ht()],value:a.from.isNativeToken?d:void 0,chainId:a.from.chainId,fallbackGasLimit:St(a.type)}}let f=$e(a,"first");if(!f)throw new Error("Swap route is not available.");let w=await be(f.chain),_={tokenIn:se(r,f.fromToken),tokenOut:se(r,f.toToken),fee:f.fee??Se,recipient:t,deadline:ht(),amountIn:d,amountOutMinimum:0n,sqrtPriceLimitX96:0n};return{address:w,abi:Ke,functionName:"exactInputSingle",args:[_],value:a.from.isNativeToken?d:void 0,chainId:f.chain,fallbackGasLimit:St(a.type)}},[Ge,r,be,t]),fe=re(async(s,a)=>{if(!t)return null;try{let d=await et(s,a),f=De(a.type)||a.type==="swap-bridge",w=await Sn(o,d.chainId,d.fallbackGasLimit,f,{account:t,address:d.address,abi:d.abi,functionName:d.functionName,args:d.args,value:d.value},!0);return{gasLimit:w.gas,gasPrice:w.gasPrice,maxFeePerGas:w.maxFeePerGas,maxPriorityFeePerGas:w.maxPriorityFeePerGas}}catch{return null}},[et,o,t]),at=re(async s=>{let a=le(s.fromToken),d=le(s.toToken),f=O(a,d);if(!f)return{error:"Route is not available."};let w=s.lastChangedBy==="to"?s.toAmount:s.fromAmount,_=!!w&&Number(w)>0,S=Yr(f,r)?Re:void 0,E=async(H,l,b)=>{let C=_?await fe(H,f):null,A=Y(f,_,C);return es({input:H,path:f,gasInfo:A,amountData:l,liquidity:S,enrichedTokens:D,priceImpact:b})};if(!w||Number(w)<=0)return{fromAmount:s.fromAmount,toAmount:s.toAmount,summary:await E(s)};let G=await V(f),Z=Ye(G?.gasFee??G?.gas_fee),P=f.type==="bridge"||f.type==="bridge-swap"?{networkFee:Z}:void 0,W=f.type==="bridge"?s.lastChangedBy==="to"?{...s,fromAmount:s.toAmount}:{...s,toAmount:s.fromAmount}:s,j=_r({input:W,path:f,config:G});if(j)return{fromAmount:W.fromAmount,toAmount:W.toAmount,summary:await E(W,P),error:j};let X=Er({input:W,path:f,config:G});if(X)return{fromAmount:W.fromAmount,toAmount:W.toAmount,summary:await E(W,P),error:X};if(f.type==="bridge")return{fromAmount:W.fromAmount,toAmount:W.toAmount,summary:await E(W,P)};try{if(f.type==="swap-bridge"){let C=$e(f,"first"),A=r.contracts.SWAP_BRIDGE_ROUTER;if(!C)return{error:"Swap bridge route is not ready."};let R=Ne=>me({path:f,step:C,amount:Ne,source:"from"}).then(je=>je.priceImpact).catch(()=>{});if(s.lastChangedBy==="from"){let Ne=await Ee(o,{address:A,abi:ot,functionName:"getAmountSwapBridgeOut",args:[BigInt(f.to.chainId),se(r,f.from.address),se(r,C.toToken),C.fee??Se,wt(s.fromAmount)],chainId:f.from.chainId}),je=rt(Ne[1]),Ot={...s,toAmount:je};return{toAmount:je,summary:await E(Ot,{networkFee:Ne[3],exFee:Ne[4]},await R(s.fromAmount))}}let ve=await Ee(o,{address:A,abi:ot,functionName:"getAmountSwapBridgeIn",args:[BigInt(f.to.chainId),se(r,f.from.address),se(r,C.toToken),C.fee??Se,wt(s.toAmount)],chainId:f.from.chainId}),Ue=rt(ve[1]),dt={...s,fromAmount:Ue};return{fromAmount:Ue,summary:await E(dt,{networkFee:ve[3],exFee:ve[4]},await R(Ue))}}let H=f.type==="bridge-swap"?$e(f,"last"):$e(f,"first");if(!H)return{error:"Swap route is not available."};let l=await me({path:f,step:H,amount:w,source:s.lastChangedBy});if(s.lastChangedBy==="from"){let C={...s,toAmount:l.amount};return{toAmount:l.amount,summary:await E(C,P,l.priceImpact)}}let b={...s,fromAmount:l.amount};return{fromAmount:l.amount,summary:await E(b,P,l.priceImpact)}}catch(H){return{fromAmount:s.fromAmount,toAmount:s.toAmount,summary:await E(s,P),error:Ir(H)}}},[Re,Y,D,r,fe,O,V,me,o]),tt=re(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]),Ae=re(async s=>{if(!t)throw new Error("Wallet is not connected.");let a=le(s.fromToken),d=le(s.toToken),f=O(a,d);if(!f)throw new Error("Route is not available.");if(!De(f.type)&&f.type!=="swap-bridge"||f.from.isNativeToken)return null;let w=ye(s.fromAmount);if(w<=0n)return null;let _=await tt(f);return!_||await Ee(o,{address:f.from.address,abi:Ut,functionName:"allowance",args:[t,_],chainId:f.from.chainId})>=w?null:{token:s.fromToken,tokenAddress:f.from.address,spenderAddress:_,amount:s.fromAmount}},[O,tt,o,t]),Ie=re(async(s,a)=>{let d=ye(a.amount||s.fromAmount);if(d<=0n)throw new Error("Approval amount is empty.");await xe(a.token.chainId);let f=await kn(o,{address:a.tokenAddress,abi:Ut,functionName:"approve",args:[a.spenderAddress,d],chainId:a.token.chainId});await or(o,{hash:f,chainId:a.token.chainId})},[xe,o]),he=re(async(s,a)=>{let d=await Ge(s,a);await xe(d.chainId);let f=await Sn(o,d.chainId,d.fallbackGasLimit,sr(a.type),{account:t,address:d.address,abi:d.abi,functionName:d.functionName,args:d.args,value:d.value});return{txHash:await kn(o,{address:d.address,abi:d.abi,functionName:d.functionName,args:d.args,value:d.value,chainId:d.chainId,...f}),fromToken:s.fromToken,toToken:s.toToken,fromAmount:s.fromAmount,toAmount:s.toAmount}},[Ge,xe,o,t]),Me=re(async(s,a)=>{let d=t;if(!d)throw new Error("Wallet is not connected.");let f=a.steps.find(je=>je.type==="bridge");if(!f?.bridgeAddress)throw new Error("Bridge route is not available.");let w=a.from.address,_=a.from.chainId,S=ye(s.fromAmount);if(S<=0n)throw new Error("Bridge amount is empty.");let E=await V(a),G=Ye(E?.gasFee??E?.gas_fee),Z=An(S,E?.exFeeRate??E?.ex_fee_rate),P=S+Z+G,[W,j]=await Promise.all([Ee(o,{address:w,abi:Tn,functionName:"name",chainId:_}),Ee(o,{address:w,abi:Tn,functionName:"nonces",args:[d],chainId:_})]),X=BigInt(Math.floor(Date.now()/1e3)+300),H=await nr(o,{domain:{name:W,version:"1",chainId:_,verifyingContract:w},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:f.bridgeAddress,value:P,nonce:j,deadline:X}}),{r:l,s:b,v:C,yParity:A}=er(H),R=C!==void 0?Number(C):A+27,ve={exFee:Z.toString(),from:_,fromToken:w,nonce:Number(j),gasFee:G.toString(),permitArgs:{account:d,deadline:X.toString(),r:l,s:b,token:w,v:R,value:P.toString()},to:d,toChainID:String(a.to.chainId),value:P.toString()},Ue=await In(`${r.bridgeApi}/permit`,ve),dt=Ue?.requestId??Ue?.request_id;if(!dt)throw new Error("Bridge permit request failed.");let Ne=await xr(r.bridgeApi,dt);if(!qt(Ne))throw new Error("Bridge submitted, but confirmation timed out. Check History shortly.");return{txHash:Ne,fromToken:s.fromToken,toToken:s.toToken,fromAmount:s.fromAmount,toAmount:s.toAmount}},[r,V,o,t]),ct=re(async s=>{let a=Mt(o),d=le(s.fromToken),f=le(s.toToken),w=O(d,f);if(!w)throw new Error("Route is not available.");if(!(De(w.type)||w.type==="swap-bridge"||w.type==="bridge-swap"||w.type==="bridge"))throw new Error("This bridge route is not supported yet.");let E=w.type==="bridge"&&w.from.chainId===r.chainIds.bsc&&w.from.address.toLowerCase()===r.contracts.BSC_CROSS.toLowerCase()?await Me(s,w):await he(s,w);return await Ve(a),{...E,pathType:w.type,routeTokens:Jr(w,D)}},[D,r,O,Ve,Me,he,o]);return{bridgeTokens:ce,bridgeHistory:K,getBridgeApproval:Ae,approveBridge:Ie,getBridgeQuote:at,getBridgeToTokens:He,submitBridge:ct,oneUsdPairs:Te,isLoading:m.isLoading||h.isLoading||T.isLoading||I.isLoading||v.some(s=>s.isLoading)}}import{useEffect as Mn,useRef as ts,useState as Un}from"react";import{useAccount as ns}from"wagmi";function Ht(e){let{address:t,connector:n}=ns(),{currentWallet:i}=Be(),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,u]=Un({loginType:null,accountName:null,accounts:[],isResolved:!1}),r=ts(new Map),[m,h]=Un(0);return Mn(()=>{let k=!1;if(o!=="cross_embedded")return u({loginType:null,accountName:null,accounts:[],isResolved:!0}),()=>{k=!0};if(!c)return u({loginType:null,accountName:null,accounts:[],isResolved:!1}),()=>{k=!0};u(v=>({...v,isResolved:!1}));let p=20,T=300,I=async()=>{if(typeof c.getProvider!="function")return"retry";let v;try{v=await c.getProvider()}catch{return"retry"}let F=v?.sdk;if(!F)return"giveup";try{let N=F.getRNBridgeActiveWallet?.(),B=N?.walletName?.trim();N&&B&&r.current.set(N.address.toLowerCase(),B)}catch{}let[x,U]=await Promise.all([F.getUserInfo?.().catch(()=>null)??null,F.getAddresses?.().catch(()=>null)??null]);if(k)return"done";let D=x?.loginType,O=D==="google"||D==="apple"?D:null;if(!O)return"retry";let q=g?.toLowerCase(),$=q&&Array.isArray(U)?U.find(N=>N.address.toLowerCase()===q):null,z=Array.isArray(U)?U.filter(N=>/^0x[a-fA-F0-9]{40}$/.test(N.address)).map(N=>({address:N.address.toLowerCase(),...Number.isFinite(N.index)?{index:N.index}:{},...N.name?.trim()?{name:N.name.trim()}:{}})):[],L=q?r.current.get(q)?.trim():void 0,K=!$&&q&&/^0x[a-fA-F0-9]{40}$/.test(q)?[...z,{address:q,index:z.length,...L?{name:L}:{}}]:z,pe=L||$?.name?.trim()||(typeof $?.index=="number"?`Account ${$.index+1}`:g?`${g.slice(0,6)}\u2026${g.slice(-4)}`:null);return u({loginType:O,accountName:pe,accounts:K,isResolved:!0}),"done"};return(async()=>{for(let v=0;v<p;v++){if(k)return;let F=await I();if(F==="done")return;if(F==="giveup"){k||u({loginType:null,accountName:null,accounts:[],isResolved:!0});return}await new Promise(x=>setTimeout(x,T))}k||u({loginType:null,accountName:null,accounts:[],isResolved:!0})})(),()=>{k=!0}},[o,c,g,m]),Mn(()=>{if(o!=="cross_embedded"||!c||typeof c.getProvider!="function")return;let k=!1,p;return(async()=>{let T;try{T=await c.getProvider()}catch{return}if(k)return;let I=T?.sdk;I?.on&&(p=I.on("addressChanged",({address:v,walletName:F})=>{let x=F?.trim();x&&(r.current.set(v.toLowerCase(),x),h(U=>U+1))}))})(),()=>{k=!0,p?.()}},[o,c]),y}import{Fragment as qn,jsx as ue,jsxs as st}from"react/jsx-runtime";var fs=[{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"}]}],gs=[{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"}]}],ys={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"}},Qt=10n**18n,bs={google:{name:"Google",iconUrl:Vn,connectorId:Je.CROSSx},apple:{name:"Apple",iconUrl:Yt,connectorId:Je.CROSSx},cross:{name:Et.default,iconUrl:Xt,connectorId:Je.CROSSx},metamask:{name:"MetaMask",iconUrl:jn,connectorId:Je.MetaMask},binance:{name:"Binance Wallet",iconUrl:Hn,connectorId:Je.Binance}};function hs(e){switch(e){case"cross_embedded":return Je.CROSSx;case"metamask":return Je.MetaMask;case"binance":return Je.Binance;default:return}}function ws(e,t){switch(e){case"cross_embedded":return t==="google"?{name:"Google",iconUrl:Vn}:t==="apple"?{name:"Apple",iconUrl:Yt}:{name:Et.default,iconUrl:Xt};case"cross_wallet":return{name:Et.default,iconUrl:Xt};case"cross_extension":return{name:Et.extension,iconUrl:ms};case"metamask":return{name:"MetaMask",iconUrl:jn};case"binance":return{name:"Binance Wallet",iconUrl:Hn};default:return null}}function Cs({label:e="Connect Wallet",className:t,style:n,walletInfoStyle:i,user:o,enablePortfolio:c,portfolio:g,theme:y,accountName:u,connectorId:r,showPortfolio:m,sendAccounts:h,getTransactionReceipt:k,sendTransaction:p,estimateGas:T,onDisconnect:I,onSelectWallet:v,onBuy:F,onRampRedirectUrl:x,bridgeTokens:U,bridgeHistory:D,getBridgeQuote:O,getBridgeToTokens:q,getBridgeApproval:$,approveBridge:z,submitBridge:L,showBalance:K=!0,env:Re,...pe}){let{address:N,isConnected:B,connector:Y,chain:V}=ss(),ce=as(),Te=is(),{switchChainAsync:He}=ds(),{sendTransactionAsync:Oe}=cs(),{connectWallet:xe,disconnect:Ve,selectWallet:be,currentWallet:me,isConnecting:Ge,kitConfig:et}=Be(),fe=et?.restoreChainAfterSwitch!==!1,at=yt(),tt=y??at?.mode??"dark",Ae=_t(()=>ls(Re),[Re]),Ie=o?.address??N,he=o?bs[o.provider]:null,{loginType:Me,accountName:ct,accounts:s}=Ht({walletId:me,connector:Y,address:Ie}),a=_t(()=>he?{name:he.name,iconUrl:he.iconUrl}:ws(me,Me),[he,me,Me]),d=u??o?.name??ct??void 0,f=he?he.connectorId:hs(me),w=r??f,_=g??m??!!c,S=Ct({env:Ae,walletAddress:Ie,enabled:B&&!!Ie&&K,restoreChainAfterSwitch:fe}),E=U??S.bridgeTokens,G=D??S.bridgeHistory,Z=O??S.getBridgeQuote,P=q??S.getBridgeToTokens,W=$??S.getBridgeApproval,j=z??S.approveBridge,X=L??S.submitBridge,H=Ze(()=>{xe().catch(M=>{console.error("[crossx-kit] connectWallet error:",M)})},[xe]),l=Ze(()=>{Ve()},[Ve]),b=I??l,C=us(),{eligibility:A}=ps({network:V?String(V.id):void 0}),R=A?.allowed===!0,ve=_t(()=>{if(F)return F;if(!(!C||!V||!R))return()=>C.open({crypto:V.nativeCurrency?.symbol??"USDT",network:String(V.id),...x?{redirectUrl:x}:{}}).then(()=>{}).catch(M=>{throw console.warn("[crossx-kit] onramp open failed:",M),M})},[F,C,V,R,x]),Ue=rs();os(()=>{if(C?.onStatus)return C.onStatus(()=>{Ue.invalidateQueries()})},[C,Ue]);let dt=_t(()=>{if(!F&&!(!C||!V)&&!R)return"On-ramp is not available in your region."},[F,C,V,R]),Ne=pe.onBridgeDisabledMessage,je=pe.onSendDisabledMessage,Ot=o?o.provider==="google"||o.provider==="apple":me==="cross_embedded",to=Ze(()=>{be().catch(M=>{console.error("[crossx-kit] selectWallet error:",M)})},[be]),tn=v??(Ot?to:void 0),no=Ze(async({hash:M,chainId:te})=>{let ne=Vt(ce,te?{chainId:te}:void 0);if(!ne)return null;try{return await ne.getTransactionReceipt({hash:M})}catch{return null}},[ce]),oo=Ze(async M=>{let te=Te,ne=!1;M.chainId!==void 0&&M.chainId!==Te&&(await He({chainId:M.chainId}),ne=!0);let de=M.chainId===56||M.chainId===97?{...M,type:"legacy"}:M,J=await(p??Oe)(de);return await vt({getChainId:()=>ne?M.chainId:te,switchChain:Ce=>He({chainId:Ce})},te,fe),J},[p,Oe,Te,He,fe]),ro=_||p?oo:void 0,so=Ze(async M=>{let te=M.chainId??Te,ne=Vt(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 we=te===56||te===97,[de,Pe]=await Promise.all([ne.estimateGas({account:M.from,to:M.to,value:M.value,data:M.data}),(async()=>{if(we)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:de,maxFeePerGas:Pe.maxFeePerGas,maxPriorityFeePerGas:Pe.maxPriorityFeePerGas,gasPrice:Pe.gasPrice}},[ce,Te]),io=T??so,ao=Ze(async M=>{let te={};if(!N||M.length===0)return te;let ne=M.flatMap(de=>{let J={address:de,abi:fs,chainId:Te};return[{...J,functionName:"balanceOf",args:[N]},{...J,functionName:"totalSupply"},{...J,functionName:"decimals"}]}),we;try{we=await Kn(ce,{contracts:ne,allowFailure:!0})}catch{return te}return M.forEach((de,Pe)=>{let J=Pe*3,Ce=we[J],kt=we[J+1],lt=we[J+2];!Ce||Ce.status!=="success"||(te[de.toLowerCase()]={balance:Ce.result,totalSupply:kt&&kt.status==="success"?kt.result:void 0,decimals:lt&<.status==="success"?Number(lt.result):void 0})}),te},[ce,N,Te]),co=Ze(async M=>{let te={earnedWei:0n,stakedWei:0n};if(!M)return te;let ne=ys[Ae],we={address:ne.poolAddress,abi:gs,chainId:ne.crossChainId},de;try{de=await Kn(ce,{allowFailure:!0,contracts:[{...we,functionName:"earned",args:[M]},{...we,functionName:"balanceOf",args:[M]},{...we,functionName:"posaActive"},{...we,functionName:"lastRewardBlock"},{...we,functionName:"totalStaked"}]})}catch{return te}let Pe=nt=>de[nt]&&de[nt].status==="success"?de[nt].result:0n,J=Pe(0),Ce=Pe(1);if(de[2]&&de[2].status==="success"?de[2].result:!1)return{earnedWei:J,stakedWei:Ce};let lt=Pe(3),rn=Pe(4);if(rn===0n)return{earnedWei:J,stakedWei:Ce};let Nt=0n;try{Nt=await Vt(ce,{chainId:ne.crossChainId})?.getBlockNumber?.()??0n}catch{return{earnedWei:J,stakedWei:Ce}}if(Nt<=lt)return{earnedWei:J,stakedWei:Ce};let Ft=0n;try{let nt=await fetch(ne.networkStatsUrl).then(Wt=>Wt.json()),sn=nt?.data?.block_reward??nt?.block_reward;if(sn){let[Wt,mo=""]=String(sn).split("."),fo=(mo+"0".repeat(18)).slice(0,18);Ft=BigInt(Wt||"0")*Qt+BigInt(fo||"0")}}catch{}if(Ft===0n)return{earnedWei:J,stakedWei:Ce};let uo=(Nt-lt)*Ft*Qt/rn,po=Ce*uo/Qt;return{earnedWei:J+po,stakedWei:Ce}},[ce,Ae]),nn=!tn,on=t?`cb-button ${t}`:"cb-button",lo=t?`cb-pill ${t}`:"cb-pill";return Ge&&!B?st(qn,{children:[ue("style",{children:zt}),st("button",{type:"button",disabled:!0,className:on,style:n,"aria-busy":"true",children:[ue("span",{className:"cb-spinner","aria-hidden":"true"}),ue("span",{className:"cb-button-label",children:"Connecting..."})]})]}):B&&Ie?st("span",{"data-crossx-wallet-info":nn?"external":"embedded",children:[ue("style",{children:zt}),nn&&ue("style",{children:Ts}),st(jt,{...pe,env:Ae,theme:tt,showBalance:K,walletAddress:Ie,accountName:d,sendAccounts:h??s,connectorId:w,showPortfolio:_,onDisconnect:b,onSelectWallet:tn,onBuy:ve,onBuyDisabledMessage:dt,onBridgeDisabledMessage:Ne,onSendDisabledMessage:je,sendTransaction:ro,getTransactionReceipt:k??no,estimateGas:io,lpBalanceReader:ao,stakingRewardsReader:co,bridgeTokens:E,bridgeHistory:G,getBridgeQuote:Z,getBridgeToTokens:P,getBridgeApproval:W,approveBridge:j,submitBridge:X,style:i,children:[ue(jt.Trigger,{asChild:!0,children:st("button",{type:"button",className:lo,style:n,"aria-label":`Connected with ${a?.name??"wallet"}: ${$n(Ie)}`,children:[a?.iconUrl?ue("img",{src:a.iconUrl,alt:"",width:20,height:20,className:"cb-pill-icon","data-provider":a.iconUrl===Yt?"apple":void 0}):ue("span",{className:"cb-pill-icon-placeholder","aria-hidden":"true"}),ue("span",{className:"cb-pill-address",children:$n(Ie)})]})}),ue(jt.Content,{align:"end",sideOffset:8})]})]}):st(qn,{children:[ue("style",{children:zt}),st("button",{type:"button",onClick:H,className:on,style:n,"aria-label":typeof e=="string"?e:"Connect Wallet",children:[ue(ks,{}),ue("span",{className:"cb-button-label",children:e})]})]})}function ks(){return ue("svg",{className:"cb-button-icon",viewBox:"0 0 18 18",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:ue("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 Ts=`
|
|
3
|
+
[data-crossx-wallet-info="external"] .wi-select-wallet-btn {
|
|
4
|
+
display: none !important;
|
|
5
|
+
}
|
|
6
|
+
`;function $n(e){return`${e.slice(0,6)}...${e.slice(-4)}`}var zt=`
|
|
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 Qn,useEffect as xs,useMemo as zn,useState as Is}from"react";import{detectWallets as Xn,DEFAULT_WALLET_REGISTRY as Yn}from"@nexus-cross/connect-kit-wagmi";import{jsx as ae,jsxs as Le}from"react/jsx-runtime";var vs=["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"],Ps="Connect with one of our available wallet providers to continue.";function Ss({open:e,onClose:t,onSelect:n,title:i="Connect Wallet",description:o=Ps,troubleshootingTips:c=vs}){let{availableWallets:g}=Be(),[y,u]=Is({});xs(()=>{if(!e)return;let p=Xn(Yn),T={};for(let v of p)v.installed!==void 0&&(T[v.id]=v.installed);u(T);let I=setTimeout(()=>{let v=Xn(Yn),F={};for(let x of v)x.installed!==void 0&&(F[x.id]=x.installed);u(F)},1e3);return()=>clearTimeout(I)},[e]);let r=zn(()=>typeof navigator>"u"?!1:/Mobi|Android/i.test(navigator.userAgent),[]),m=zn(()=>r?g.filter(p=>p.type!=="extension"):g,[g,r]),h=Qn(p=>{if(!y[p.walletId]&&p.installUrl&&p.type==="extension"){window.open(p.installUrl,"_blank");return}t(),n(p.walletId)},[t,n,y]),k=Qn((p,T)=>{p.stopPropagation(),t(),window.open(T,"_blank")},[t]);return e?ae("div",{style:Q.overlay,onClick:t,children:Le("div",{style:Q.modal,onClick:p=>p.stopPropagation(),children:[Le("div",{style:Q.header,children:[ae("h2",{style:Q.title,children:i}),ae("button",{type:"button",onClick:t,style:Q.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:Q.desc,children:o}),ae("div",{style:Q.walletList,children:m.map(p=>{let T=y[p.walletId],I=T===!1&&p.type==="extension"&&!!p.installUrl;return Le("div",{style:Q.walletGroup,children:[Le("button",{type:"button",onClick:()=>h(p),style:{...Q.walletItem,...p.walletId==="cross_wallet"?Q.walletItemAccent:{}},"aria-label":`Connect with ${p.name}`,children:[p.iconUrl?ae("img",{src:p.iconUrl,alt:"",style:Q.walletIcon}):ae("div",{style:Q.walletIconPlaceholder}),Le("div",{style:Q.walletInfo,children:[Le("div",{style:Q.walletNameRow,children:[ae("span",{style:Q.walletName,children:p.name}),T!==void 0&&ae("span",{style:{...Q.badge,...T?Q.badgeInstalled:Q.badgeNotInstalled},children:T?"Installed":"Not Installed"})]}),ae("span",{style:Q.walletDesc,children:I?"Extension not detected \u2014 click to install":p.type==="extension"?"Browser extension approval is required":p.walletId==="cross_wallet"?"App approval is required":p.walletId==="binance"?"Mobile app only \u2014 Add CROSS network first":T?"Connect with browser extension":"Scan QR code with app"})]})]}),p.guideUrl&&Le("button",{type:"button",onClick:v=>k(v,p.guideUrl),style:Q.guideBtn,children:[ae("span",{"aria-hidden":"true",children:"\u26A0\uFE0F"}),p.guideLabel??"Required Settings"]})]},p.walletId)})}),Le("div",{style:Q.troubleshoot,children:[ae("h3",{style:Q.troubleshootTitle,children:"Wallet not detected?"}),ae("ul",{style:Q.troubleshootList,children:c.map(p=>Le("li",{style:Q.troubleshootItem,children:[ae("span",{style:Q.troubleshootDot,"aria-hidden":"true"}),ae("span",{children:p})]},p))})]})]})}):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)"},Q={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 Rs,useMemo as Zn}from"react";import{useAccount as As,useConfig as Bs,useSendTransaction as _s,useSwitchChain as Es,useWriteContract as Os}from"wagmi";import{getBalance as Ns,readContract as Fs,readContracts as Ws,waitForTransactionReceipt as Ds}from"wagmi/actions";import{RelayDeposit as Zt}from"@nexus-cross/dapp-ui";import{jsx as Ks}from"react/jsx-runtime";var Ls=56,Gs=[{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"}]}],it=e=>e,Jn=!1;function ft(){let{address:e,chainId:t}=As(),n=Bs(),{sendTransactionAsync:i}=_s(),{writeContractAsync:o}=Os(),{switchChainAsync:c}=Es(),g=n.chains.some(u=>u.id===Ls);Rs(()=>{g||Jn||(Jn=!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=Zn(()=>({sendTransaction:async({chainId:u,to:r,value:m,data:h})=>i({chainId:it(u),to:r,value:m,data:h}),writeContract:async({chainId:u,address:r,abi:m,functionName:h,args:k})=>o({chainId:it(u),address:r,abi:m,functionName:h,args:k}),readContract:g?async({chainId:u,address:r,abi:m,functionName:h,args:k})=>Fs(n,{chainId:it(u),address:r,abi:m,functionName:h,args:k}):void 0,switchChain:async u=>{await c({chainId:it(u)})},waitForReceipt:async({chainId:u,hash:r})=>({status:(await Ds(n,{chainId:it(u),hash:r})).status==="success"?"success":"reverted"}),getBalance:async({chainId:u,address:r,token:m})=>{if(!m){let v=await Ns(n,{chainId:it(u),address:r});return{value:v.value,decimals:v.decimals,symbol:v.symbol}}let h={address:m,abi:Gs,chainId:it(u)},k=await Ws(n,{contracts:[{...h,functionName:"balanceOf",args:[r]},{...h,functionName:"decimals"},{...h,functionName:"symbol"}],allowFailure:!1}),[p,T,I]=k;return{value:p,decimals:T,symbol:I}}}),[n,g,i,o,c]);return Zn(()=>({walletAddress:e,walletChainId:t,...y}),[e,t,y])}function Ms(e){let t=ft();return Ks(Zt,{...t,...e,requireWalletConnection:!0})}var Us=Object.assign(Ms,{Trigger:Zt.Trigger,Content:Zt.Content});import{useCallback as $s,useMemo as eo}from"react";import{useAccount as qs,useConfig as Hs}from"wagmi";import{waitForTransactionReceipt as Vs}from"wagmi/actions";import{GetOneUsd as js,resolveEnvironment as Qs}from"@nexus-cross/dapp-ui";import{jsx as Xs}from"react/jsx-runtime";function zs({env:e,pairs:t,bridgeOptions:n,relay:i,restoreChainAfterSwitch:o=!0,waitForTransaction:c,onRequestConnect:g,...y}){let u=Qs(e),{address:r}=qs(),m=Hs(),{connectWallet:h}=Be(),k=ft(),p=Ct({env:u,walletAddress:r,enabled:!0,restoreChainAfterSwitch:o}),{bridgeHistory:T,getBridgeQuote:I,getBridgeToTokens:v,getBridgeApproval:F,approveBridge:x,submitBridge:U}=p,D=eo(()=>({...n,history:T,getQuote:I,getToTokens:v,getApproval:F,approveBridge:x,submitBridge:U}),[x,T,n,F,I,v,U]),O=eo(()=>({...i,...k}),[i,k]),q=$s(async $=>{if((await Vs(m,{hash:$.txHash,chainId:$.fromToken.chainId})).status!=="success")throw new Error("Transaction reverted.")},[m]);return Xs(js,{...y,env:u,walletAddress:r,tokens:p.bridgeTokens,pairs:t??p.oneUsdPairs,loading:p.isLoading,bridge:D,relay:O,waitForTransaction:c??q,onRequestConnect:g??h})}import{useAccount as Ys}from"wagmi";import{RelayHistory as Jt}from"@nexus-cross/dapp-ui";import{jsx as ei}from"react/jsx-runtime";function Zs(e){let{address:t}=Ys();return ei(Jt,{walletAddress:t,...e})}var Js=Object.assign(Zs,{Trigger:Jt.Trigger,Content:Jt.Content});import{RelayRecovery as en}from"@nexus-cross/dapp-ui";import{jsx as oi}from"react/jsx-runtime";function ti(e){let t=ft();return oi(en,{...t,...e})}var ni=Object.assign(ti,{Trigger:en.Trigger,Content:en.Content});import{useContext as ri,useEffect as si,useRef as ii}from"react";function ai(e){let t=ri(It);if(!t)throw new Error("useConnectKitAnalytics must be used within <CrossConnectKitProvider>");let n=ii(e);n.current=e;let{subscribe:i}=t;si(()=>i(c=>n.current(c)),[i])}import{useOnRamp as cc,useOnRampEligibility as dc,OnRampProvider as lc}from"@nexus-cross/onramp/react";import{useKyc as pc,useOptionalKyc as mc,KycProvider as fc,KycError as gc,launchKycVerification as yc}from"@nexus-cross/kyc/react";import{WalletInfo as hc,ConnectorId as wc}from"@nexus-cross/dapp-ui";import{AppLauncher as kc,AppLauncherTrigger as Tc,AppLauncherContent as xc,useGlobalMenu as Ic}from"@nexus-cross/dapp-ui";import{SkillsButton as Pc}from"@nexus-cross/dapp-ui";import{createRelayClient as Rc,RelayApiError as Ac,DEFAULT_TRUSTED_FACTORIES as Bc,useRelayConfig as _c,useRelayOrders as Ec,useRelayRecovery as Oc}from"@nexus-cross/dapp-ui";import{OnRampError as Fc}from"@nexus-cross/connect-kit-core";import{ConnectionStatus as Dc,formatBalance as Lc,formatWei as Gc}from"@nexus-cross/connect-kit-core";an();export{Be as a,Co as b,yt as c,Lt as d,Zo as e,Ct as f,Ht as g,Cs as h,Ss as i,ft as j,Us as k,zs as l,Js as m,ni as n,ai as o,cc as p,dc as q,lc as r,pc as s,mc as t,fc as u,gc as v,yc as w,hc as x,wc as y,kc as z,Tc as A,xc as B,Ic as C,Pc as D,Rc as E,Ac as F,Bc as G,_c as H,Ec as I,Oc as J,Fc as K,Dc as L,Lc as M,Gc as N};
|
package/dist/client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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';
|
|
1
|
+
export { ConnectButton, ConnectButtonProps, CrossConnectKitContextValue, CrossConnectKitProvider, CrossConnectKitProviderProps, CrossConnectKitThemeContextValue, CrossConnectModal, CrossConnectModalProps, CrossGetOneUsd, CrossGetOneUsdBridgeOptions, CrossGetOneUsdProps, CrossGetOneUsdRelayProps, 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, Catalog, ConnectButtonStyle, ConnectorId, DEFAULT_TRUSTED_FACTORIES, DepositAddressResult, GlobalMenu, GlobalMenuItem, GlobalMenuItemUrl, OrderSummary, OriginOption, QuoteResult, RecoveryInfo, RecoverySuccessResult, RelayApiError, RelayBalance, RelayClient, RelayClientOptions, RelayContractCall, RelayDrawerDirection, RelayHex, RelayRecoveryAction, RelayRecoveryQueryKey, RelayRecoveryQueryOptions, RelayRecoveryState, RelayRecoveryStep, RelayTheme, RelayTxRequest, RelayWalletProps, SendTransactionArgs, SendTransactionFn, SkillsButton, SkillsButtonProps, SkillsButtonStyle, UseRelayConfigOptions, UseRelayConfigResult, UseRelayOrdersOptions, UseRelayOrdersResult, UseRelayRecoveryOptions, UseRelayRecoveryResult, WalletInfo, WalletInfoContentProps, WalletInfoProps, WalletInfoStyle, WalletInfoTriggerProps, createRelayClient, useGlobalMenu, useRelayConfig, useRelayOrders, useRelayRecovery } from '@nexus-cross/dapp-ui';
|
|
4
|
+
export { AppLauncher, AppLauncherContent, AppLauncherContentProps, AppLauncherProps, AppLauncherTrigger, AppLauncherTriggerProps, AppLauncherTriggerStyle, Catalog, ConnectButtonStyle, ConnectorId, DEFAULT_TRUSTED_FACTORIES, DepositAddressResult, GetOneUsdActionId, GetOneUsdEvent, GetOneUsdMode, GetOneUsdPairs, GetOneUsdTokenRef, GlobalMenu, GlobalMenuItem, GlobalMenuItemUrl, OrderSummary, OriginOption, QuoteResult, RecoveryInfo, RecoverySuccessResult, RelayApiError, RelayBalance, RelayClient, RelayClientOptions, RelayContractCall, RelayDrawerDirection, RelayHex, RelayRecoveryAction, RelayRecoveryQueryKey, RelayRecoveryQueryOptions, RelayRecoveryState, RelayRecoveryStep, RelayTheme, RelayTxRequest, RelayWalletProps, SendTransactionArgs, SendTransactionFn, SkillsButton, SkillsButtonProps, SkillsButtonStyle, UseRelayConfigOptions, UseRelayConfigResult, UseRelayOrdersOptions, UseRelayOrdersResult, UseRelayRecoveryOptions, UseRelayRecoveryResult, WalletInfo, WalletInfoContentProps, WalletInfoProps, WalletInfoStyle, WalletInfoTriggerProps, createRelayClient, useGlobalMenu, useRelayConfig, useRelayOrders, useRelayRecovery } 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,D as pe,E as ce,F as le,G as ue,H as fe,I as Ce,J as we,K as me,L as ge,M as ye,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,K as me,L as ge,M as ye,N as Ne,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-RLAXM7N4.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{ae as AppLauncher,se as AppLauncherContent,ie as AppLauncherTrigger,B as ConnectButton,ge as ConnectionStatus,re as ConnectorId,L as CrossConnectKitProvider,X as CrossConnectModal,q as CrossGetOneUsd,U as CrossRelayDeposit,z as CrossRelayHistory,$ as CrossRelayRecovery,ue as DEFAULT_TRUSTED_FACTORIES,ne as KycError,ee as KycProvider,me as OnRampError,Q as OnRampProvider,F as OtherWalletsModal,le as RelayApiError,pe as SkillsButton,oe as WalletInfo,_ as createConnectKitConfig,ce as createRelayClient,ye as formatBalance,Ne as formatWei,te as launchKycVerification,G as useConnectKitAnalytics,S as useCrossConnectKit,V as useCrossConnectKitTheme,h as useCrossdBridgeAdapter,j as useCrossxEmbeddedInfo,de as useGlobalMenu,Y as useKyc,H as useOnRamp,J as useOnRampEligibility,W as useOptionalCrossConnectKitTheme,Z as useOptionalKyc,fe as useRelayConfig,Ce as useRelayOrders,we as useRelayRecovery,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, 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, RecoverySuccessResult, RelayApiError, RelayBalance, RelayClient, RelayClientOptions, RelayContractCall, RelayDrawerDirection, RelayHex, RelayRecoveryAction, RelayRecoveryQueryKey, RelayRecoveryQueryOptions, RelayRecoveryState, RelayRecoveryStep, RelayTheme, RelayTxRequest, RelayWalletProps, SendTransactionArgs, SendTransactionFn, SkillsButton, SkillsButtonProps, SkillsButtonStyle, UseRelayConfigOptions, UseRelayConfigResult, UseRelayOrdersOptions, UseRelayOrdersResult, UseRelayRecoveryOptions, UseRelayRecoveryResult, WalletInfo, WalletInfoContentProps, WalletInfoProps, WalletInfoStyle, WalletInfoTriggerProps, createRelayClient, useGlobalMenu, useRelayConfig, useRelayOrders, useRelayRecovery } from '@nexus-cross/dapp-ui';
|
|
7
|
+
import { WalletInfoProps, ConnectButtonStyle, WalletInfoStyle, RelayDepositProps, RelayWalletProps, RelayDeposit, GetOneUsdProps, GetOneUsdPairs, GetOneUsdBridgeProps, GetOneUsdRelayProps, 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, GetOneUsdActionId, GetOneUsdEvent, GetOneUsdMode, GetOneUsdPairs, GetOneUsdTokenRef, GlobalMenu, GlobalMenuItem, GlobalMenuItemUrl, OrderSummary, OriginOption, QuoteResult, RecoveryInfo, RecoverySuccessResult, RelayApiError, RelayBalance, RelayClient, RelayClientOptions, RelayContractCall, RelayDrawerDirection, RelayHex, RelayRecoveryAction, RelayRecoveryQueryKey, RelayRecoveryQueryOptions, RelayRecoveryState, RelayRecoveryStep, RelayTheme, RelayTxRequest, RelayWalletProps, SendTransactionArgs, SendTransactionFn, SkillsButton, SkillsButtonProps, SkillsButtonStyle, UseRelayConfigOptions, UseRelayConfigResult, UseRelayOrdersOptions, UseRelayOrdersResult, UseRelayRecoveryOptions, UseRelayRecoveryResult, WalletInfo, WalletInfoContentProps, WalletInfoProps, WalletInfoStyle, WalletInfoTriggerProps, createRelayClient, useGlobalMenu, useRelayConfig, useRelayOrders, useRelayRecovery } 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';
|
|
@@ -251,6 +251,22 @@ declare function CrossRelayDepositRoot(props: CrossRelayDepositProps): react_jsx
|
|
|
251
251
|
*/
|
|
252
252
|
declare const CrossRelayDeposit: typeof CrossRelayDepositRoot & Pick<typeof RelayDeposit, 'Trigger' | 'Content'>;
|
|
253
253
|
|
|
254
|
+
type ManagedBridgeKey = "history" | "getQuote" | "getToTokens" | "getApproval" | "approveBridge" | "submitBridge";
|
|
255
|
+
type CrossGetOneUsdBridgeOptions = Omit<GetOneUsdBridgeProps, ManagedBridgeKey>;
|
|
256
|
+
type CrossGetOneUsdRelayProps = Omit<GetOneUsdRelayProps, keyof RelayWalletProps>;
|
|
257
|
+
interface CrossGetOneUsdProps extends Omit<GetOneUsdProps, "walletAddress" | "tokens" | "pairs" | "loading" | "bridge" | "relay"> {
|
|
258
|
+
/** Override the standard pairs resolved from remote contracts.json. */
|
|
259
|
+
pairs?: GetOneUsdPairs;
|
|
260
|
+
bridgeOptions?: CrossGetOneUsdBridgeOptions;
|
|
261
|
+
relay?: CrossGetOneUsdRelayProps;
|
|
262
|
+
restoreChainAfterSwitch?: boolean;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Turn-key Get ONEUSD widget. CrossD quote/submit ports and Relay wallet
|
|
266
|
+
* capabilities are derived from the surrounding CrossConnectKitProvider.
|
|
267
|
+
*/
|
|
268
|
+
declare function CrossGetOneUsd({ env, pairs, bridgeOptions, relay, restoreChainAfterSwitch, waitForTransaction, onRequestConnect, ...props }: CrossGetOneUsdProps): react_jsx_runtime.JSX.Element;
|
|
269
|
+
|
|
254
270
|
/**
|
|
255
271
|
* Everything `<RelayHistory>` accepts except `walletAddress`, which comes from
|
|
256
272
|
* wagmi. `recipient` is still accepted and still wins — the history subject can
|
|
@@ -523,8 +539,9 @@ type CrossdBridgeAdapter = {
|
|
|
523
539
|
getBridgeQuote: BridgeQuoteFn;
|
|
524
540
|
getBridgeToTokens: BridgeGetToTokensFn;
|
|
525
541
|
submitBridge: BridgeSubmitFn;
|
|
542
|
+
oneUsdPairs?: GetOneUsdPairs;
|
|
526
543
|
isLoading: boolean;
|
|
527
544
|
};
|
|
528
545
|
declare function useCrossdBridgeAdapter({ env, walletAddress, enabled, restoreChainAfterSwitch, }: CrossdBridgeAdapterOptions): CrossdBridgeAdapter;
|
|
529
546
|
|
|
530
|
-
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 };
|
|
547
|
+
export { ConnectButton, type ConnectButtonProps, type CrossConnectKitContextValue, CrossConnectKitProvider, type CrossConnectKitProviderProps, type CrossConnectKitThemeContextValue, CrossConnectModal, type CrossConnectModalProps, CrossGetOneUsd, type CrossGetOneUsdBridgeOptions, type CrossGetOneUsdProps, type CrossGetOneUsdRelayProps, 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,D,E,F,G,H,I,J,K,L,M,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,K,L,M,N,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-RLAXM7N4.js";export{z as AppLauncher,B as AppLauncherContent,A as AppLauncherTrigger,h as ConnectButton,L as ConnectionStatus,y as ConnectorId,e as CrossConnectKitProvider,d as CrossConnectModal,l as CrossGetOneUsd,k as CrossRelayDeposit,m as CrossRelayHistory,n as CrossRelayRecovery,G as DEFAULT_TRUSTED_FACTORIES,v as KycError,u as KycProvider,K as OnRampError,r as OnRampProvider,i as OtherWalletsModal,F as RelayApiError,D as SkillsButton,x as WalletInfo,E as createRelayClient,M as formatBalance,N as formatWei,w as launchKycVerification,o as useConnectKitAnalytics,a as useCrossConnectKit,b as useCrossConnectKitTheme,f as useCrossdBridgeAdapter,g as useCrossxEmbeddedInfo,C as useGlobalMenu,s as useKyc,p as useOnRamp,q as useOnRampEligibility,c as useOptionalCrossConnectKitTheme,t as useOptionalKyc,H as useRelayConfig,I as useRelayOrders,J as useRelayRecovery,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.12
|
|
3
|
+
"version": "1.3.12",
|
|
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-
|
|
28
|
-
"@nexus-cross/connect-kit-
|
|
29
|
-
"@nexus-cross/crossx-design-system": "1.3.12
|
|
30
|
-
"@nexus-cross/dapp-ui": "1.3.12
|
|
31
|
-
"@nexus-cross/kyc": "1.3.12
|
|
32
|
-
"@nexus-cross/onramp": "1.3.12
|
|
27
|
+
"@nexus-cross/connect-kit-wagmi": "1.3.12",
|
|
28
|
+
"@nexus-cross/connect-kit-core": "1.3.12",
|
|
29
|
+
"@nexus-cross/crossx-design-system": "1.3.12",
|
|
30
|
+
"@nexus-cross/dapp-ui": "1.3.12",
|
|
31
|
+
"@nexus-cross/kyc": "1.3.12",
|
|
32
|
+
"@nexus-cross/onramp": "1.3.12"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@tanstack/react-query": "^5.60.0",
|
package/dist/chunk-72GKZILX.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
var mt="1.3.12-beta.1";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 _e,useEffect as re,useMemo as Fe,useRef as ge,useState as je}from"react";import{WagmiProvider as xo,useAccount as Io,useChainId as vo,useConnect as So,useDisconnect as Po,useSwitchChain as Ro}from"wagmi";import{QueryClient as Ao,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 Ke(){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:b}=Ke(),r=ft()?.mode??"dark",f=dn(()=>{let m=g?new Set(g):null,T={};for(let I of i){if(!To.has(I.walletId)||m&&!m.has(I.walletId))continue;let v=I.walletId;T[v]=()=>{n(I.walletId)}}for(let[I,v]of Object.entries(c))v&&(m&&!m.has(I)||(T[I]=v));return T},[i,n,c,g]),h=dn(()=>{if(o)return{apple:()=>{o.signIn("apple")},google:()=>{o.signIn("google")}}},[o]),k=ko(m=>t(m),[t]);return un(ln,{wallets:f,socialProviders:h,termsUrl:b.legal?.termsUrl,privacyUrl:b.legal?.privacyUrl,theme:r,open:e,onOpenChange:k,children:un(ln.Content,{})})}import{jsx as Qe,jsxs as gn}from"react/jsx-runtime";var Lo=new Ao,Dt="crossx-kit:last-wallet-intent",Mo=15e3,Go=1500,Ko=3;function mn(e,t){return Promise.race([e.then(()=>{},()=>{}),new Promise(n=>setTimeout(n,t))])}function Uo(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 $o(){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 qo(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 Ho(e,t){if(!(typeof window>"u"))try{window.localStorage.setItem(e,t)}catch{}}function Vo({children:e,config:t,activeProvider:n,onRequestProviderSwap:i,pendingConnectWalletId:o,clearPending:c,themeMode:g,themeTokens:b,extraWallets:p,walletAllowlist:r,emit:f}){let[h,k]=je(!1),[m,T]=je(()=>$o()),[I,v]=je(null),{address:F,isConnected:x,isConnecting:U,isReconnecting:W,connector:O}=Io(),{connectors:Q,connectAsync:q}=So(),{disconnectAsync:X}=Po(),{kitConfig:D,connectorRegistry:G,crossProvider:Ae,reownProvider:fe}=t,E=n==="cross"?Ae:fe,A=Fe(()=>!x||!O?null:Oo(G,O.id,m),[x,O,G,m]),Y=Fe(()=>G.entries.filter(l=>l.type!=="embedded"),[G]),H=_e(l=>G.getEntry(l)?.type??"external",[G]),de=ge(null);de.current=I;let Ie=ge(A);Ie.current=A;let Me=ge(F);Me.current=F;let ve=D.embeddedProjectId?.trim()||D.crossProjectId?.trim(),Oe=!!D.onRampEnabled&&!!ve,be=Fe(()=>!Oe||!ve?null:{projectId:ve,walletState:{getAddress:()=>Me.current}},[Oe,ve]),Ge=ge(O);Ge.current=O;let le=D.embeddedProjectId?.trim()||D.crossProjectId?.trim(),Je=!!D.kycEnabled&&!!le,et=Fe(()=>!Je||!le?null:{projectId:le,getAccessToken:async()=>{let l=Ge.current;if(!(!l||typeof l.getProvider!="function"))try{return(await(await l.getProvider())?.sdk?.getUserInfo?.())?.data?.accessToken||void 0}catch{return}}},[Je,le]);re(()=>_o(()=>k(!0)),[]),re(()=>{if(!h||typeof document>"u")return;let l=setTimeout(()=>{document.querySelectorAll("#__crossx-confirm-overlay").forEach(y=>y.remove())},50);return()=>clearTimeout(l)},[h]);let we=ge(x),tt=ge(x);we.current=x;let ct=ge(!1);re(()=>{console.debug("[crossx-kit] state",{activeProvider:n,isConnected:x,isConnecting:U,isReconnecting:W,activeConnectorId:O?.id,currentWallet:A,lastIntent:m})},[n,x,U,W,O?.id,A,m]),re(()=>{x&&!tt.current&&E?.closeModal?.({kitConfig:D}),tt.current=x},[x,E,D]),re(()=>{x&&v(null)},[x]);let Be=vo(),{switchChainAsync:he}=Ro(),Ce=ge(null);re(()=>{if(!D.enforceDefaultNetworkOnConnect)return;let l=D.defaultNetwork?.id;if(!l)return;if(!x||!F||!O){Ce.current=null;return}let y=`${O.id}:${F}`;Ce.current!==y&&(Ce.current=y,Be!==l&&he({chainId:l}).catch(()=>{}))},[D.enforceDefaultNetworkOnConnect,D.defaultNetwork,x,F,O,Be,he]);let He=ge(h);re(()=>{h&&!He.current?f({name:"connect_modal_opened"}):!h&&He.current&&f({name:"connect_modal_closed",completed:we.current}),He.current=h},[h,f]);let s=ge(x);re(()=>{if(x&&!s.current){let l=de.current;l&&f({name:"connect_succeeded",walletId:l,walletType:H(l),chainId:Be})}s.current=x},[x,Be,f,H]);let a=_e(l=>Q.find(y=>y.id===l),[Q]);re(()=>{let l=G.getEntry("cross_embedded");if(!l)return;let y=a(l.connectorId);if(!y)return;let C=!1;return(async()=>{try{let K=await y.getProvider();if(C)return;K?.sdk?.applyTheme?.(g,b??void 0)}catch(K){console.debug("[crossx-kit] applyTheme skipped:",K)}})(),()=>{C=!0}},[G,a,g,b]);let d=_e(l=>{T(l),fn(l)},[]),u=_e(()=>{T(null),fn(null),v(null)},[]);re(()=>{if(!E?.subscribeModalState)return;let l=!1;return E.subscribeModalState({kitConfig:D},y=>{if(ct.current=y,y){l=!0;return}l&&(l=!1,setTimeout(()=>{if(we.current)return;let C=de.current;C&&f({name:"connect_cancelled",walletId:C,stage:"popup"}),(async()=>{try{await X()}catch{}u()})()},250))})},[E,D,X,u,f]),re(()=>{if(!I||x||typeof window>"u"||I==="cross_embedded")return;let l=typeof document<"u"&&!document.hasFocus(),y=null,C=()=>{l=!0},K=()=>{l&&(y&&clearTimeout(y),y=setTimeout(()=>{if(we.current||ct.current)return;let R=de.current;R&&f({name:"connect_cancelled",walletId:R,stage:"popup"}),(async()=>{try{await X()}catch{}u()})()},1e3))};return window.addEventListener("blur",C),window.addEventListener("focus",K),()=>{window.removeEventListener("blur",C),window.removeEventListener("focus",K),y&&clearTimeout(y)}},[I,x,X,u,f]);let w=_e(async l=>{console.debug("[crossx-kit] runConnect enter",{walletId:l,activeProvider:n,isConnected:x,activeConnectorId:O?.id});let y=G.getEntry(l);if(!y){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),y.providerKind!==n){console.debug("[crossx-kit] provider swap needed",{from:n,to:y.providerKind,walletId:l}),d(l);try{await X()}catch{}await new Promise(R=>setTimeout(R,0)),i(y.providerKind,l);return}let C=H(l);if(f({name:"wallet_selected",walletId:l,walletType:C}),f({name:"connect_started",walletId:l,walletType:C}),d(l),E?.beforeConnect)try{let R=await E.beforeConnect({kitConfig:D,themeMode:g},l);if(console.debug("[crossx-kit] beforeConnect result",{walletId:l,result:R}),R==="handled")return}catch(R){console.warn('[crossx-kit] adapter.beforeConnect threw for "%s":',l,R)}let K=a(y.connectorId);if(console.debug("[crossx-kit] findConnector",{lookupId:y.connectorId,found:K?.id,availableIds:Q.map(R=>R.id)}),!K){console.error(`[crossx-kit] Connector "${y.connectorId}" not found on provider "${y.providerKind}". Available: ${Q.map(R=>R.id).join(", ")}`),f({name:"connect_failed",walletId:l,reason:"connector_not_found"}),u();return}try{console.debug("[crossx-kit] connectAsync start",{connectorId:K.id});let R=await q({connector:K});console.debug("[crossx-kit] connectAsync resolved",{accountsLen:R.accounts.length,chainId:R.chainId});return}catch(R){let ke=Uo(R);if(!ke){console.error('[crossx-kit] connectAsync error for "%s":',l,R);try{await X()}catch{}}if(!y.fallbackConnectorId){ke||f({name:"connect_failed",walletId:l,reason:"connector_error"}),u();return}}if(y.fallbackConnectorId){let R=a(y.fallbackConnectorId);if(R)try{await q({connector:R})}catch(ke){console.error('[crossx-kit] Fallback connect failed for "%s":',l,ke);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()}},[G,Q,a,q,X,d,u,E,n,D,i,g,f,H]);re(()=>{if(!o)return;let l=o;c(),w(l)},[o,n]);let B=_e(async()=>{k(!0)},[]),_=_e(async()=>{f({name:"disconnected",walletId:Ie.current});try{await X()}catch(l){console.error("[crossx-kit] wagmi disconnect error:",l)}if(E?.teardown)try{await E.teardown({kitConfig:D})}catch(l){console.error("[crossx-kit] adapter teardown error:",l)}pn(),u()},[X,E,D,u,f]),P=_e(async()=>{await mn(X(),3e3);try{let l=G.getEntry("cross_embedded"),y=l&&a(l.connectorId);if(y?.getProvider){let C=await Promise.race([y.getProvider(),new Promise(R=>setTimeout(R,3e3))]),K=C?.sdk?.signOut;typeof K=="function"&&await mn(K.call(C.sdk),3e3)}}catch{}pn()},[G,a,X]),L=_e(async()=>{let l=G.getEntry("cross_embedded");if(!l)return null;let y=a(l.connectorId);if(!y)return null;try{let C=await y.getProvider(),K=C?.sdk;if(!K?.selectWallet)return null;let R=await K.selectWallet(K.currentAddress??void 0);return R?.address&&C.notifyAccountsChanged&&C.notifyAccountsChanged([R.address]),R&&f({name:"wallet_switched",index:R.index}),R}catch{return null}},[G,a,f]),Z=Fe(()=>{let l=t.oauth;return l?{signIn:async y=>{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(y)}catch(C){throw f({name:"connect_cancelled",walletId:"cross_embedded",stage:"popup"}),v(null),C}}}:null},[t.oauth,f]),S=ge(!1);re(()=>{if(n!=="cross"||x||U||W||I!=null||S.current)return;let l=G.getEntry("cross_embedded");if(!l)return;let y=a(l.connectorId);if(!y)return;S.current=!0;let C=!1;return(async()=>{try{let K=await y.isAuthorized?.();if(C||!K)return;await q({connector:y})}catch{}})(),()=>{C=!0}},[n,x,U,W,I,G,a,q]);let N=ge(0);re(()=>{if(n!=="cross"||x||!U&&!W||N.current>=Ko)return;let l=G.getEntry("cross_embedded");if(!l)return;let y=a(l.connectorId);if(!y)return;let C=!1,K=setInterval(()=>{(async()=>{if(C||we.current)return;let R=await Promise.resolve(y.isAuthorized?.()).catch(()=>!1);if(!(C||!R||we.current)){N.current+=1,console.warn("[crossx-kit] wagmi reconnect stalled while the SDK holds a session \u2014 forcing an explicit connect to realign");try{await q({connector:y})}catch{}}})()},Go);return()=>{C=!0,clearInterval(K)}},[n,x,U,W,G,a,q]),re(()=>{if(I!=="cross_embedded"||x||typeof window>"u")return;let l=!document.hasFocus(),y=()=>{l=!0};window.addEventListener("blur",y);let C=setTimeout(()=>{we.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(),P())},Mo);return()=>{window.removeEventListener("blur",y),clearTimeout(C)}},[I,x,u,P,f]);let $=I!=null&&!x,V=Fe(()=>({kitConfig:D,connectorRegistry:G,availableWallets:Y,connect:w,connectWallet:B,disconnect:_,selectWallet:L,currentWallet:A,lastIntent:m,isConnecting:$,connectingWalletId:I,openOtherWallets:()=>k(!0),closeOtherWallets:()=>k(!1),otherWalletsOpen:h,oauth:Z,extraWallets:p,walletAllowlist:r,onRampEnabled:Oe}),[D,G,Y,w,B,_,L,A,m,$,I,h,Z,p,r,Oe]),z=gn(Ft.Provider,{value:V,children:[e,Qe(Wt,{open:h,onOpenChange:k})]});return et&&(z=Qe(Do,{config:et,children:z})),be&&(z=Qe(Wo,{config:be,children:z})),z}var jo=[/Connection interrupted while trying to subscribe/i,/No matching key\. subscription:/i,/Proposal expired/i];function Qo(e){let t=e?.message;return typeof t!="string"?!1:jo.some(n=>n.test(t))}var zo={};function Xo(e){return e&&{...e,connections:new Map,current:null}}function Yo({children:e,config:t,initialState:n,extraWallets:i=zo,walletAllowlist:o}){let[c,g]=je(()=>qo(t.activeProviderStorageKey,t.defaultProvider)),[b,p]=je(null),r=ge(!1),f=ge(null);f.current||(f.current=cn());let h=f.current,k=Fe(()=>({subscribe:h.subscribe}),[h]),{kitConfig:m}=t,[T,I]=je(null),[v,F]=je(null),[x,U]=je(0),W=Fe(()=>No(m.theme,m.autoDetectTheme),[m.theme,m.autoDetectTheme,x]),O=T??W,Q=v??m.themeTokens;re(()=>{if(!m.autoDetectTheme||T||typeof window>"u"||!window.matchMedia)return;let A=window.matchMedia("(prefers-color-scheme: dark)"),Y=()=>U(H=>H+1);try{return A.addEventListener("change",Y),()=>A.removeEventListener("change",Y)}catch{return A.addListener(Y),()=>A.removeListener(Y)}},[m.autoDetectTheme,T]),re(()=>{if(typeof document>"u")return;let A=document.documentElement,Y=A.getAttribute("data-ds-theme"),H=A.getAttribute("data-theme");return A.setAttribute("data-ds-theme",O),H||A.setAttribute("data-theme",O),()=>{Y==null?A.removeAttribute("data-ds-theme"):A.setAttribute("data-ds-theme",Y),H==null&&A.removeAttribute("data-theme")}},[O]);let q=Fe(()=>Fo(t.designSystem),[t.designSystem]),X=Fe(()=>({mode:O,tokens:Q,setThemeMode:A=>I(A),setThemeTokens:A=>F(A)}),[O,Q]);re(()=>{if(typeof window>"u")return;let A=Y=>{Qo(Y.reason)&&Y.preventDefault()};return window.addEventListener("unhandledrejection",A),()=>window.removeEventListener("unhandledrejection",A)},[]);let D=_e((A,Y)=>{r.current||(r.current=!0,p(Y),g(A),Ho(t.activeProviderStorageKey,A),queueMicrotask(()=>{r.current=!1}))},[t.activeProviderStorageKey]),G=_e(()=>p(null),[]),Ae=c==="cross"?t.crossWagmiConfig:t.reownWagmiConfig,fe=Xo(Eo(n,c));if(!Ae){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 E=Ae??(c==="cross"?t.reownWagmiConfig:t.crossWagmiConfig);return Qe(kt.Provider,{value:k,children:gn(Ct.Provider,{value:X,children:[Qe("style",{"data-crossx-design-system":"",children:q}),Qe(xo,{config:E,initialState:fe,children:Qe(Bo,{client:Lo,children:Qe(Vo,{config:t,activeProvider:c,onRequestProviderSwap:D,pendingConnectWalletId:b,clearPending:G,themeMode:O,themeTokens:Q,extraWallets:i,walletAllowlist:o??t.kitConfig.wallets??null,emit:h.emit,children:e})})},c)]})})}import{useCallback as Ye,useEffect as ns,useMemo as Rt}from"react";import{useQueryClient as os}from"@tanstack/react-query";import{useAccount as rs,useChainId as ss,useConfig as is,useSendTransaction as as,useSwitchChain as cs}from"wagmi";import{getPublicClient as Ht,readContracts as Kn}from"wagmi/actions";import{WalletInfo as Vt,ConnectorId as Ze,resolveEnvironment as ds}from"@nexus-cross/dapp-ui";import{useOptionalOnRamp as ls,useOptionalOnRampEligibility as us}from"@nexus-cross/onramp/react";import{APPLE_ICON as Xt,BINANCE_ICON as qn,CROSSX_ICON as zt,EXTENSION_ICON as ps,GOOGLE_ICON as Hn,METAMASK_ICON as Vn}from"@nexus-cross/connect-kit-wagmi";import{WALLET_LABELS as At}from"@nexus-cross/crossx-design-system";import{useCallback as se,useMemo as Pe,useRef as Zo}from"react";import{useQueries as wn,useQuery as ze}from"@tanstack/react-query";import{encodeFunctionData as gt,formatUnits as Pt,parseSignature as Jo,parseUnits as er}from"viem";import{getChainId as Lt,getPublicClient as En,readContract as Ee,signTypedData as tr,switchChain as hn,waitForTransactionReceipt as nr,writeContract as Cn}from"wagmi/actions";import{useConfig as or}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 rr(e){return e!=="bridge"}var qe="0x0000000000000000000000000000000000000000",Re=100,pt=18,sr=180000n,ir=250000n,On=new Set([56,97]),ar=130n,cr=100n,dr={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"},lr={dev:"dev",stage:"stg",production:"prod"};function ur(e,t){let n=e?.[lr[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 pr={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"},mr=["BSC_CROSS","W_CROSS","NATIVE_CROSS","USDTX","CROSSD","USDTB","SWAP_BRIDGE_ROUTER"],fr={BSC_CROSS:qe,W_CROSS:qe,NATIVE_CROSS:qe,USDTX:qe,CROSSD:qe,USDTB:qe,SWAP_BRIDGE_ROUTER:qe},gr=/^0x[0-9a-fA-F]{40}$/;function yr(e,t){let n=typeof e=="string"?e:e?.[t];return typeof n=="string"&&gr.test(n)?n:null}function br(e,t){if(!e?.bridge)return null;let n=e.envToNetwork?.[t]??(t==="production"?"mainnet":"testnet"),i={};for(let o of mr){let c=yr(e.bridge[o],n);if(!c)return null;i[o]=c}return i}var wr={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"}]}],hr=[{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"}]}],Ue=[{type:"function",name:"exactInputSingle",stateMutability:"payable",inputs:[{name:"params",type:"tuple",components:[{name:"tokenIn",type:"address"},{name:"tokenOut",type:"address"},{name:"fee",type:"uint24"},{name:"recipient",type:"address"},{name:"deadline",type:"uint256"},{name:"amountIn",type:"uint256"},{name:"amountOutMinimum",type:"uint256"},{name:"sqrtPriceLimitX96",type:"uint160"}]}],outputs:[{name:"amountOut",type:"uint256"}]},{type:"function",name:"multicall",stateMutability:"payable",inputs:[{name:"data",type:"bytes[]"}],outputs:[{name:"results",type:"bytes[]"}]},{type:"function",name:"unwrapWETH9",stateMutability:"payable",inputs:[{name:"amountMinimum",type:"uint256"},{name:"recipient",type:"address"}],outputs:[]},{type:"function",name:"refundETH",stateMutability:"payable",inputs:[],outputs:[]}],Cr=[{type:"function",name:"bridgeToken",stateMutability:"payable",inputs:[{name:"toChainID",type:"uint256"},{name:"fromToken",type:"address"},{name:"to",type:"address"},{name:"value",type:"uint256"},{name:"gasFee",type:"uint256"},{name:"exFee",type:"uint256"},{name:"extraData",type:"bytes"}],outputs:[{name:"",type:"bool"}]}];async function 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 We(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 kr(e){return new Promise(t=>setTimeout(t,e))}async function Tr(e,t,{attempts:n=60,intervalMs:i=2e3}={}){for(let o=0;o<n;o+=1){try{let c=await We(`${e}/permit-hash/${t}`);if(Ut(c))return c}catch{}await kr(i)}return null}function ae(e,t){return`${e}-${t.toLowerCase()}`}function pe(e){return ae(e.chainId,e.address)}function De(e){return e==="swap"||e==="deposit-swap"||e==="swap-withdraw"}function xr(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 ie(e,t){return t?t.toLowerCase()===e.contracts.NATIVE_CROSS.toLowerCase()?e.contracts.W_CROSS:t:qe}function st(e){let t=Pt(e,pt);return t.includes(".")?t.replace(/\.?0+$/,""):t}function bt(e){return er(e||"0",pt)}function ye(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"?sr:ir}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,b=(c%1000000n).toString().padStart(6,"0").replace(/0+$/,"");return b?`${g}.${b}`:`${g}`}function Ir(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}),b=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&&(b=i?r*ar/cr:r)}catch{}let p={gas:b};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 vr={100:"0.01%",500:"0.05%",3e3:"0.3%",1e4:"1%"};function Sr(e){return vr[e]??`${e/1e4}%`}function Pr(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 Rn(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 Rr(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 Ar(e){if(De(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 Br({input:e,path:t,config:n}){if(!n||De(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&&ye(e.fromAmount)<c&&t.type!=="swap"?`Minimum ${Pn(c)}`:t.type==="swap-bridge"&&e.toAmount&&ye(e.toAmount)<c?`Available ${Pn(c)} or more.`:""}function _r({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=ye(e.fromToken.balance||"0"),c=ye(e.fromAmount);return o-i<c?`Insufficient network fee(${e.fromToken.symbol})`:""}function Er(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(b=>{b.localToken&&n.add(ae(o,b.localToken)),b.remoteToken&&n.add(ae(Number(c),b.remoteToken))})})}),Object.entries(t?.swapPools||t?.swap_pools||{}).forEach(([i,o])=>{o.forEach(c=>{c.token0&&n.add(ae(Number(i),c.token0)),c.token1&&n.add(ae(Number(i),c.token1))})}),n}function Or(e,t){return!e||!t?null:ae(e,t)}function Nr({envConfig:e,bridgePairList:t,swapPools:n,tokenInfo:i,tokenStats:o}){let c=Er(t,n),g=new Map;o?.forEach(p=>{let r=Or(Number(p.chainId??p.chain_id),p.address);r&&g.set(r,p)});let b={};return c.forEach(p=>{let[r,f]=p.split("-"),h=Number(r),k=i?.find(T=>Number(T.chainId??T.chain_id)===h&&T.address?.toLowerCase()===f);if(!k?.symbol||!k.name)return;let m=g.get(p);b[p]={key:p,chainId:h,address:f,symbol:k.symbol,name:k.name,decimals:k.decimals||pt,image:k.image||k.icon_url,price:m?.price?Number(m.price):void 0,isNativeToken:f.toLowerCase()===e.contracts.NATIVE_CROSS.toLowerCase()}}),b}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("-"),b=Number(i),p=Number(c);for(let r of n?.list||[]){if((r.localChain??r.local_chain)!==b)continue;let f=r.pairs?.[c];if(f){for(let h of f)if(h.localToken?.toLowerCase()===o&&h.remoteToken?.toLowerCase()===g)return{type:"bridge",fromChain:b,fromToken:o,toChain:p,toToken:g,bridgeAddress:Fn(b,n)}}}return null}function Dn(e,t,n,i){let o,c=1/0;for(let g of e||[]){let b=i(g.token0),p=i(g.token1);if(b===t&&p===n||p===t&&b===n){let r=g.fee??Re;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,b]=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(),h=i.contracts.NATIVE_CROSS.toLowerCase(),m=Dn(r,c,b,I=>I?.toLowerCase()===f?h:I?.toLowerCase());if(!m)return null;let T="swap";return p===i.chainIds.cross&&(c===h&&(T="deposit-swap"),b===h&&(T="swap-withdraw")),{pathType:T,step:{type:"swap",chain:p,fromToken:c,toToken:b,fee:m.fee,poolAddress:m.poolAddress}}}function Fr(e,t,n,i){let[o,c]=e.split("-"),[g]=t.split("-");if(o===g)return null;let b=(n?.swapPools||n?.swap_pools)?.[o]||[],p=r=>r?.toLowerCase();for(let r of b){let f=p(r.token0),h=p(r.token1),k=f===c?h:h===c?f:null;if(!k)continue;let m=Wn(ae(Number(o),k),t,i);if(!m)continue;let T=Dn(b,c,k,p);return[{type:"swap",chain:Number(o),fromToken:c,toToken:k,fee:T?.fee??Re,poolAddress:T?.poolAddress??""},m]}return null}function Wr(e,t,n,i,o){let[c,g]=e.split("-"),[b]=t.split("-");if(c===b)return null;for(let p of n?.list||[])if((p.localChain??p.local_chain)===Number(c))for(let r of p.pairs?.[b]||[]){if(r.localToken?.toLowerCase()!==g)continue;let f=r.remoteToken?.toLowerCase();if(!f)continue;let h=Ln(ae(Number(b),f),t,i,o);if(h)return[{type:"bridge",fromChain:Number(c),fromToken:g,toChain:Number(b),toToken:f,bridgeAddress:Fn(Number(c),n)},h.step]}return null}function Dr({envConfig:e,bridgePairList:t,swapPools:n,enrichedTokens:i}){return(o,c)=>{let g=i[o],b=i[c];if(!g||!b||o===c)return null;let p=Wn(o,c,t);if(p)return{type:"bridge",steps:[p],from:g,to:b};let r=Ln(o,c,n,e);if(r)return{type:r.pathType,steps:[r.step],from:g,to:b};let f=Fr(o,c,n,t);if(f)return{type:"swap-bridge",steps:f,from:g,to:b};let h=Wr(o,c,t,n,e);return h?{type:"bridge-swap",steps:h,from:g,to:b}:null}}function An(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 Lr(e){return e.length<=10?e:`${e.slice(0,6)}...${e.slice(-4)}`}function Mr(e){return e.includes(".")?e.replace(/\.?0+$/,"")||"0":e}function Gr(e,t){let n=e.startsWith("-"),i=n?e.slice(1):e,[o,c=""]=i.split("."),g=c.slice(0,t).replace(/0+$/,""),b=g?`${o}.${g}`:o;return n?`-${b}`:b}function Kr(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":Kr(Gr(t,4))}function Bn(e,t){if(e==null||e==="")return"0";try{return Mr(Pt(BigInt(String(e)),t.decimals))}catch{return"0"}}function Ut(e){return!!(e&&/^0x[0-9a-fA-F]+$/.test(e))}function Ur(e){return e?new Date(e*1e3).toISOString():new Date().toISOString()}function $r(e,t){return t.toLowerCase()===e.contracts.W_CROSS.toLowerCase()?e.contracts.NATIVE_CROSS:t}function qr(e,t){let n=Lr(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=$r(e,i);return t.get(ae(n,o))||t.get(ae(n,i))||qr(n,o)}function St(e){return e?.toLowerCase()||""}function Hr(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 Vr(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 jr({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=Hr(t),g=t.swapTokenIn??t.swap_token_in,b=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,h=t.toToken??t.to_token,k=t.value,m=t.value;c==="swap"?(f=g,h=b,k=p,m=r):c==="swap-bridge"?(f=g,k=p,m=t.value):c==="bridge-swap"&&(h=b,k=p,m=r);let T=_n({envConfig:e,tokenByBridgeKey:n,chainId:i,address:f}),I=_n({envConfig:e,tokenByBridgeKey:n,chainId:o,address:h}),v=t.initiatedTxHash??t.initiated_tx_hash;return!T||!I||!Ut(v)?null:{id:`${v}-${t.index??""}`,timestamp:Ur(t.initiatedTime??t.initiated_time),txHash:v,fromToken:T,toToken:I,fromAmount:Bn(k,T),toAmount:Bn(m,I),summary:{pathType:c},status:Vr(t,c)}}function Qr(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(ae(i,o),Pt(BigInt(c||"0"),g))}catch{t.set(ae(i,o),"0")}}),t}function $e(e,t="first"){let n=e.steps.filter(i=>i.type==="swap");return t==="last"?n[n.length-1]:n[0]}function zr(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 b=g.token0?.toLowerCase(),p=g.token1?.toLowerCase();return b===i&&p===o||b===o&&p===i});return c?.poolAddress||c?.pool_address||""}function Xr(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 Yr(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?.[ae(t,n)];return{symbol:o?.symbol||n.slice(0,6),iconUrl:o?.image}}function Zr(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 Jr({input:e,path:t,amountData:n,gasInfo:i,liquidity:o,enrichedTokens:c,priceImpact:g}){let b=e.fromAmount||"0",p=e.toAmount||"0",r=$e(t),f=t.steps.find(U=>U.type==="bridge"),h=t.type!=="bridge",k=!De(t.type),m=r?Pr(b,r.fee):"0",T=Number(b)>0||Number(p)>0,I=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},F=f?ut(t,f.fromChain,f.fromToken,c):void 0,x=(U,W,O)=>T?W&&W>0n?{label:U,value:st(W),tone:"default",valueToken:O}:{label:U,value:"Free",tone:"accent"}:{label:U,value:"0"};return{pathType:t.type,priceImpact:g,liquidity:o,bridgeInfo:k&&f?[{label:"Route",value:`${In(f.fromChain)} \u2192 ${In(f.toChain)}`},x("Validator Fee",n?.exFee,F),x("Network Fee",n?.networkFee,F)]:void 0,swapInfo:h&&r?[{label:"Route",value:"",routeTokens:[ut(t,r.chain,r.fromToken,c),ut(t,r.chain,r.toToken,c)]},{label:"Price Impact",value:Ir(g)},{label:"In Amount",value:Kt(b),valueToken:I},{label:r&&De(t.type)?`Swap Fee (${Sr(r.fee??Re)})`:"Swap Fee",value:Kt(m),valueToken:I},{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=or(),c=Zo(new Map),b=ze({queryKey:["crossd-bridge-adapter",e,"remote-contracts"],queryFn:async({signal:s})=>{let a=br(await We(pr[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&&!!b,r=Pe(()=>({...wr[e],contracts:b??fr}),[e,b]),f=ze({queryKey:["crossd-bridge-adapter",e,"pairs"],queryFn:({signal:s})=>We(`${r.bridgeApi}/pairs`,s),enabled:p,staleTime:3e4}),h=ze({queryKey:["crossd-bridge-adapter",e,"swap-pools"],queryFn:({signal:s})=>We(`${r.bridgeApi}/swap-pools`,s),enabled:p,staleTime:3e4}),k=Pe(()=>zr(h.data,r),[r,h.data]),m=ze({queryKey:["crossd-bridge-adapter",e,"available-liquidity",k],queryFn:async()=>await Ee(o,{address:r.contracts.USDTX,abi:Mt,functionName:"balanceOf",args:[k],chainId:r.chainIds.cross}),enabled:p&&!!k,staleTime:3e4}),T=ze({queryKey:["crossd-bridge-adapter",e,"token-info"],queryFn:({signal:s})=>We(`${r.walletApi}/v1/public/token/info`,s),enabled:p,staleTime:3e4}),I=ze({queryKey:["crossd-bridge-adapter",e,"token-stats"],queryFn:({signal:s})=>We(`${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 We(`${r.walletApi}/v1/public/token/balance?${d}`,a)},enabled:p&&!!t,staleTime:0,refetchInterval:p&&t?5e3:!1}))}),F=wn({queries:[r.chainIds.cross,r.chainIds.bsc].map(s=>({queryKey:["crossd-bridge-adapter",e,"gas-suggestion",s],queryFn:async({signal:a})=>{try{let w=await En(o,{chainId:s})?.estimateFeesPerGas?.();if(w?.maxFeePerGas||w?.gasPrice)return{fast:{maxFee:w.maxFeePerGas?.toString()||w.gasPrice?.toString(),maxPriorityFee:w.maxPriorityFeePerGas?.toString()||"0"}}}catch{}let d=new URLSearchParams({chain_id:String(s),without_gas_limit:"false"});return We(`${r.walletApi}/v1/public/transaction/gas-suggestion/dynamic?${d}`,a)},enabled:p,staleTime:1e4,retry:1}))}),x=ze({queryKey:["crossd-bridge-adapter",e,"hidden-pairs"],queryFn:async({signal:s})=>ur(await We(dr[e],s),e),enabled:p,staleTime:5*6e4,retry:1}),U=Pe(()=>x.data??[],[x.data]),W=Pe(()=>Nr({envConfig:r,bridgePairList:f.data,swapPools:h.data,tokenInfo:T.data,tokenStats:I.data}),[f.data,r,h.data,T.data,I.data]),O=Pe(()=>Dr({envConfig:r,bridgePairList:f.data,swapPools:h.data,enrichedTokens:W}),[f.data,W,r,h.data]),Q=Pe(()=>Qr(v.map(s=>s.data).filter(s=>Array.isArray(s))),[v]),q=Pe(()=>{let s=new Map;return Object.values(W).forEach(a=>{let d=An(a,Q);s.set(a.key,d)}),s},[Q,W]),X=Pe(()=>{let s=new Map,a=q.get(ae(r.chainIds.cross,r.contracts.NATIVE_CROSS));a&&s.set(r.chainIds.cross,{symbol:a.symbol,iconUrl:a.iconUrl});let d=T.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,q,T.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}),G=Pe(()=>(D.data?.histories||[]).map(s=>jr({envConfig:r,item:s,tokenByBridgeKey:q})).filter(s=>!!s),[D.data?.histories,r,q]),Ae=Pe(()=>Yr(m.data),[m.data]),fe=F[0]?.data,E=F[1]?.data,A=Pe(()=>{let s=new Map;return fe&&s.set(r.chainIds.cross,fe),E&&s.set(r.chainIds.bsc,E),s},[E,fe,r.chainIds.bsc,r.chainIds.cross]),Y=se((s,a,d)=>{let u=A.get(s.from.chainId)?.fast,w=a?d?.gasLimit??It(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,L=Xe(u?.maxFee??u?.max_fee),Z=Xe(u?.maxPriorityFee??u?.max_priority_fee),S=_>0n?_:L>0n?L:B,N=P>0n?P:Z>0n?Z:S,$=B>0n?B:S,V=On.has(s.from.chainId)&&$>0n,z=w*(V?$:S),l=q.get(ae(s.from.chainId,r.contracts.NATIVE_CROSS)),y=s.type!=="swap-bridge",C=X.get(s.from.chainId);return{estTxFee:a?st(z):"0",priorityFeePerGas:a&&!V?Gt(N):"0",maxFeePerGas:a&&!V?Gt(S):"0",gasLimit:a?w.toString():"0",gasPrice:a&&V?Gt($):void 0,isDelegateFee:s.type==="swap-bridge"?!1:Rr(r,s.from.address,s.to.address),tokenIconUrl:y?l?.iconUrl:void 0,tokenSymbol:y?l?.symbol:void 0,gasCurrencyIconUrl:C?.iconUrl,gasCurrencySymbol:C?.symbol}},[r,A,X,q]),H=se(async s=>{let a=Ar(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 w=(async()=>{let B=new URLSearchParams({from:String(a.from),to:String(a.to),token:a.token});try{return(await We(`${r.bridgeApi}/token-config?${B}`)).config??null}catch{return null}})();return c.current.set(d,w),w},[e,r.bridgeApi]),de=Pe(()=>{let s=Object.values(W).map(d=>An(d,Q)),a=ae(r.chainIds.cross,r.contracts.CROSSD);return s.sort((d,u)=>{let w=pe(d).toLowerCase()===a.toLowerCase(),B=pe(u).toLowerCase()===a.toLowerCase();return w!==B?w?-1:1:pe(d).localeCompare(pe(u))})},[Q,W,r]),Ie=se(s=>{let a=pe(s),d=a.toLowerCase(),u=[];Object.keys(W).forEach(_=>{let P=_.toLowerCase();if(d===P||U.some(S=>S.fromKey===d&&S.toKey===P))return;let L=O(a,_);if(!L)return;let Z=q.get(_);Z&&u.push({token:Z,path:L})});let w=ae(r.chainIds.cross,r.contracts.CROSSD),B=ae(r.chainIds.cross,r.contracts.NATIVE_CROSS);return u.sort((_,P)=>{if(d===w.toLowerCase()){let $=pe(_.token).toLowerCase()===B.toLowerCase(),V=pe(P.token).toLowerCase()===B.toLowerCase();if($!==V)return $?-1:1}let L=De(_.path.type),Z=De(P.path.type);if(L!==Z)return L?-1:1;let S=_.token.chainId===s.chainId,N=P.token.chainId===s.chainId;return S!==N?S?-1:1:pe(_.token).localeCompare(pe(P.token))}),u.map(_=>_.token)},[W,r,O,U,q]),Me=se(async s=>await Ee(o,{address:r.contracts.SWAP_BRIDGE_ROUTER,abi:rt,functionName:"quoter",chainId:s}),[r.contracts.SWAP_BRIDGE_ROUTER,o]),ve=se(async s=>{Lt(o)!==s&&await hn(o,{chainId:s})},[o]),Oe=se(s=>Tt({getChainId:()=>Lt(o),switchChain:a=>hn(o,{chainId:a})},s,i),[i,o]),be=se(async s=>await Ee(o,{address:r.contracts.SWAP_BRIDGE_ROUTER,abi:rt,functionName:"swapRouter",chainId:s}),[r.contracts.SWAP_BRIDGE_ROUTER,o]),Ge=se(async({path:s,step:a,amount:d,source:u})=>{let w=await Me(a.chain),B=a.poolAddress?Ee(o,{address:a.poolAddress,abi:hr,functionName:"slot0",chainId:a.chain}).then(L=>L?.[0]).catch(()=>{}):Promise.resolve(void 0);if(u==="from"){let L=await Ee(o,{address:w,abi:Tn,functionName:"quoteExactInputSingle",args:[{tokenIn:ie(r,a.fromToken),tokenOut:ie(r,a.toToken),amountIn:bt(d),fee:a.fee??Re,sqrtPriceLimitX96:0n}],chainId:a.chain}),Z=vn(await B,L[1]);return{amount:st(L[0]),path:s,priceImpact:Z}}let _=await Ee(o,{address:w,abi:Tn,functionName:"quoteExactOutputSingle",args:[{tokenIn:ie(r,a.fromToken),tokenOut:ie(r,a.toToken),amount:bt(d),fee:a.fee??Re,sqrtPriceLimitX96:0n}],chainId:a.chain}),P=vn(await B,_[1]);return{amount:st(_[0]),path:s,priceImpact:P}},[r,Me,o]),le=se(async(s,a)=>{if(!t)throw new Error("Wallet is not connected.");let d=It(a.type);if(De(a.type)){let S=$e(a,"first");if(!S)throw new Error("Swap route is not available.");let N=ye(s.fromAmount),$=ye(s.toAmount);if(N<=0n)throw new Error("Bridge amount is empty.");if($<=0n)throw new Error("Bridge quote is not ready.");let V=await be(S.chain),J=xt($,s.slippage),z=a.type==="swap-withdraw"?qe:t,l={tokenIn:ie(r,S.fromToken),tokenOut:ie(r,S.toToken),fee:S.fee??Re,recipient:z,deadline:yt(),amountIn:N,amountOutMinimum:J,sqrtPriceLimitX96:0n};if(a.type==="swap-withdraw"){let y=gt({abi:Ue,functionName:"exactInputSingle",args:[l]}),C=gt({abi:Ue,functionName:"unwrapWETH9",args:[J,t]});return{address:V,abi:Ue,functionName:"multicall",args:[[y,C]],chainId:S.chain,fallbackGasLimit:d}}if(a.type==="deposit-swap"){let y=gt({abi:Ue,functionName:"exactInputSingle",args:[l]}),C=gt({abi:Ue,functionName:"refundETH",args:[]});return{address:V,abi:Ue,functionName:"multicall",args:[[y,C]],value:N,chainId:S.chain,fallbackGasLimit:d}}return{address:V,abi:Ue,functionName:"exactInputSingle",args:[l],chainId:S.chain,fallbackGasLimit:d}}if(a.type==="swap-bridge"){let S=$e(a,"first");if(!S)throw new Error("Swap bridge route is not available.");let N=ye(s.fromAmount),$=ye(s.toAmount);if(N<=0n)throw new Error("Bridge amount is empty.");if($<=0n)throw new Error("Bridge quote is not ready.");let V=r.contracts.SWAP_BRIDGE_ROUTER,J=yt(),z={toChainID:BigInt(a.to.chainId),recipient:t,extraData:"0x"},l={tokenIn:ie(r,a.from.address),tokenOut:ie(r,S.toToken),fee:S.fee??Re,sqrtPriceLimitX96:0n,bridgeParams:z};if(s.lastChangedBy==="to"){let C={...l,amountOut:$,amountInMaximum:bn(N,s.slippage)};return{address:V,abi:rt,functionName:"swapBridgeExactOutputSingle",args:[C,J],value:a.from.isNativeToken?C.amountInMaximum:void 0,chainId:a.from.chainId,fallbackGasLimit:d}}let y={...l,amountIn:N,amountOutMinimum:xt($,s.slippage)};return{address:V,abi:rt,functionName:"swapBridgeExactInputSingle",args:[y,J],value:a.from.isNativeToken?N: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 w=ye(s.fromAmount);if(w<=0n)throw new Error("Bridge amount is empty.");let B=await H(a),_=Xe(B?.gasFee??B?.gas_fee),P=Rn(w,B?.exFeeRate??B?.ex_fee_rate),L="0x";if(a.type==="bridge-swap"){let S=$e(a,"last");if(!S)throw new Error("Bridge swap route is not available.");let N=ye(s.toAmount);if(N<=0n)throw new Error("Bridge quote is not ready.");let $=await be(a.to.chainId),V=xt(N,s.slippage),J=gt({abi:Ue,functionName:"exactInputSingle",args:[{tokenIn:ie(r,S.fromToken),tokenOut:ie(r,S.toToken),fee:S.fee??Re,recipient:t,deadline:yt(),amountIn:w,amountOutMinimum:V,sqrtPriceLimitX96:0n}]});L=`${$}${J.slice(2)}`}let Z=[BigInt(a.to.chainId),a.from.address,t,w,_,P,L];return{address:u.bridgeAddress,abi:Cr,functionName:"bridgeToken",args:Z,value:a.from.isNativeToken?w+P+_:void 0,chainId:a.from.chainId,fallbackGasLimit:d}},[r,H,be,t]),Je=se(async(s,a)=>{if(a.type==="bridge"||a.type==="bridge-swap")return le(s,a);if(!t)throw new Error("Wallet is not connected.");let d=ye(s.fromAmount);if(d<=0n)throw new Error("Bridge amount is empty.");if(a.type==="swap-bridge"){let _=$e(a,"first");if(!_)throw new Error("Swap bridge route is not available.");let P=r.contracts.SWAP_BRIDGE_ROUTER,L={tokenIn:ie(r,a.from.address),tokenOut:ie(r,_.toToken),fee:_.fee??Re,sqrtPriceLimitX96:0n,bridgeParams:{toChainID:BigInt(a.to.chainId),recipient:t,extraData:"0x"},amountIn:d,amountOutMinimum:0n};return{address:P,abi:rt,functionName:"swapBridgeExactInputSingle",args:[L,yt()],value:a.from.isNativeToken?d:void 0,chainId:a.from.chainId,fallbackGasLimit:It(a.type)}}let u=$e(a,"first");if(!u)throw new Error("Swap route is not available.");let w=await be(u.chain),B={tokenIn:ie(r,u.fromToken),tokenOut:ie(r,u.toToken),fee:u.fee??Re,recipient:t,deadline:yt(),amountIn:d,amountOutMinimum:0n,sqrtPriceLimitX96:0n};return{address:w,abi:Ue,functionName:"exactInputSingle",args:[B],value:a.from.isNativeToken?d:void 0,chainId:u.chain,fallbackGasLimit:It(a.type)}},[le,r,be,t]),et=se(async(s,a)=>{if(!t)return null;try{let d=await Je(s,a),u=De(a.type)||a.type==="swap-bridge",w=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:w.gas,gasPrice:w.gasPrice,maxFeePerGas:w.maxFeePerGas,maxPriorityFeePerGas:w.maxPriorityFeePerGas}}catch{return null}},[Je,o,t]),we=se(async s=>{let a=pe(s.fromToken),d=pe(s.toToken),u=O(a,d);if(!u)return{error:"Route is not available."};let w=s.lastChangedBy==="to"?s.toAmount:s.fromAmount,B=!!w&&Number(w)>0,_=Xr(u,r)?Ae:void 0,P=async(J,z,l)=>{let y=B?await et(J,u):null,C=Y(u,B,y);return Jr({input:J,path:u,gasInfo:C,amountData:z,liquidity:_,enrichedTokens:W,priceImpact:l})};if(!w||Number(w)<=0)return{fromAmount:s.fromAmount,toAmount:s.toAmount,summary:await P(s)};let L=await H(u),Z=Xe(L?.gasFee??L?.gas_fee),S=u.type==="bridge"||u.type==="bridge-swap"?{networkFee:Z}:void 0,N=u.type==="bridge"?s.lastChangedBy==="to"?{...s,fromAmount:s.toAmount}:{...s,toAmount:s.fromAmount}:s,$=Br({input:N,path:u,config:L});if($)return{fromAmount:N.fromAmount,toAmount:N.toAmount,summary:await P(N,S),error:$};let V=_r({input:N,path:u,config:L});if(V)return{fromAmount:N.fromAmount,toAmount:N.toAmount,summary:await P(N,S),error:V};if(u.type==="bridge")return{fromAmount:N.fromAmount,toAmount:N.toAmount,summary:await P(N,S)};try{if(u.type==="swap-bridge"){let y=$e(u,"first"),C=r.contracts.SWAP_BRIDGE_ROUTER;if(!y)return{error:"Swap bridge route is not ready."};let K=Ne=>Ge({path:u,step:y,amount:Ne,source:"from"}).then(Ve=>Ve.priceImpact).catch(()=>{});if(s.lastChangedBy==="from"){let Ne=await Ee(o,{address:C,abi:rt,functionName:"getAmountSwapBridgeOut",args:[BigInt(u.to.chainId),ie(r,u.from.address),ie(r,y.toToken),y.fee??Re,bt(s.fromAmount)],chainId:u.from.chainId}),Ve=st(Ne[1]),_t={...s,toAmount:Ve};return{toAmount:Ve,summary:await P(_t,{networkFee:Ne[3],exFee:Ne[4]},await K(s.fromAmount))}}let R=await Ee(o,{address:C,abi:rt,functionName:"getAmountSwapBridgeIn",args:[BigInt(u.to.chainId),ie(r,u.from.address),ie(r,y.toToken),y.fee??Re,bt(s.toAmount)],chainId:u.from.chainId}),ke=st(R[1]),nt={...s,fromAmount:ke};return{fromAmount:ke,summary:await P(nt,{networkFee:R[3],exFee:R[4]},await K(ke))}}let J=u.type==="bridge-swap"?$e(u,"last"):$e(u,"first");if(!J)return{error:"Swap route is not available."};let z=await Ge({path:u,step:J,amount:w,source:s.lastChangedBy});if(s.lastChangedBy==="from"){let y={...s,toAmount:z.amount};return{toAmount:z.amount,summary:await P(y,S,z.priceImpact)}}let l={...s,fromAmount:z.amount};return{fromAmount:z.amount,summary:await P(l,S,z.priceImpact)}}catch(J){return{fromAmount:s.fromAmount,toAmount:s.toAmount,summary:await P(s,S),error:xr(J)}}},[Ae,Y,W,r,et,O,H,Ge,o]),tt=se(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]),ct=se(async s=>{if(!t)throw new Error("Wallet is not connected.");let a=pe(s.fromToken),d=pe(s.toToken),u=O(a,d);if(!u)throw new Error("Route is not available.");if(!De(u.type)&&u.type!=="swap-bridge"||u.from.isNativeToken)return null;let w=ye(s.fromAmount);if(w<=0n)return null;let B=await tt(u);return!B||await Ee(o,{address:u.from.address,abi:Mt,functionName:"allowance",args:[t,B],chainId:u.from.chainId})>=w?null:{token:s.fromToken,tokenAddress:u.from.address,spenderAddress:B,amount:s.fromAmount}},[O,tt,o,t]),Be=se(async(s,a)=>{let d=ye(a.amount||s.fromAmount);if(d<=0n)throw new Error("Approval amount is empty.");await ve(a.token.chainId);let u=await Cn(o,{address:a.tokenAddress,abi:Mt,functionName:"approve",args:[a.spenderAddress,d],chainId:a.token.chainId});await nr(o,{hash:u,chainId:a.token.chainId})},[ve,o]),he=se(async(s,a)=>{let d=await le(s,a);await ve(d.chainId);let u=await Sn(o,d.chainId,d.fallbackGasLimit,rr(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}},[le,ve,o,t]),Ce=se(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 w=a.from.address,B=a.from.chainId,_=ye(s.fromAmount);if(_<=0n)throw new Error("Bridge amount is empty.");let P=await H(a),L=Xe(P?.gasFee??P?.gas_fee),Z=Rn(_,P?.exFeeRate??P?.ex_fee_rate),S=_+Z+L,[N,$]=await Promise.all([Ee(o,{address:w,abi:kn,functionName:"name",chainId:B}),Ee(o,{address:w,abi:kn,functionName:"nonces",args:[d],chainId:B})]),V=BigInt(Math.floor(Date.now()/1e3)+300),J=await tr(o,{domain:{name:N,version:"1",chainId:B,verifyingContract:w},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:$,deadline:V}}),{r:z,s:l,v:y,yParity:C}=Jo(J),K=y!==void 0?Number(y):C+27,R={exFee:Z.toString(),from:B,fromToken:w,nonce:Number($),gasFee:L.toString(),permitArgs:{account:d,deadline:V.toString(),r:z,s:l,token:w,v:K,value:S.toString()},to:d,toChainID:String(a.to.chainId),value:S.toString()},ke=await xn(`${r.bridgeApi}/permit`,R),nt=ke?.requestId??ke?.request_id;if(!nt)throw new Error("Bridge permit request failed.");let Ne=await Tr(r.bridgeApi,nt);if(!Ut(Ne))throw new Error("Bridge submitted, but confirmation timed out. Check History shortly.");return{txHash:Ne,fromToken:s.fromToken,toToken:s.toToken,fromAmount:s.fromAmount,toAmount:s.toAmount}},[r,H,o,t]),He=se(async s=>{let a=Lt(o),d=pe(s.fromToken),u=pe(s.toToken),w=O(d,u);if(!w)throw new Error("Route is not available.");if(!(De(w.type)||w.type==="swap-bridge"||w.type==="bridge-swap"||w.type==="bridge"))throw new Error("This bridge route is not supported yet.");let P=w.type==="bridge"&&w.from.chainId===r.chainIds.bsc&&w.from.address.toLowerCase()===r.contracts.BSC_CROSS.toLowerCase()?await Ce(s,w):await he(s,w);return await Oe(a),{...P,pathType:w.type,routeTokens:Zr(w,W)}},[W,r,O,Oe,Ce,he,o]);return{bridgeTokens:de,bridgeHistory:G,getBridgeApproval:ct,approveBridge:Be,getBridgeQuote:we,getBridgeToTokens:Ie,submitBridge:He,isLoading:f.isLoading||h.isLoading||T.isLoading||I.isLoading||v.some(s=>s.isLoading)}}import{useEffect as Mn,useRef as es,useState as Gn}from"react";import{useAccount as ts}from"wagmi";function qt(e){let{address:t,connector:n}=ts(),{currentWallet:i}=Ke(),o=e?.walletId!==void 0?e.walletId:i,c=e?.connector!==void 0?e.connector:n,g=e?.address!==void 0?e.address:t,[b,p]=Gn({loginType:null,accountName:null,accounts:[],isResolved:!1}),r=es(new Map),[f,h]=Gn(0);return Mn(()=>{let k=!1;if(o!=="cross_embedded")return p({loginType:null,accountName:null,accounts:[],isResolved:!0}),()=>{k=!0};if(!c)return p({loginType:null,accountName:null,accounts:[],isResolved:!1}),()=>{k=!0};p(v=>({...v,isResolved:!1}));let m=20,T=300,I=async()=>{if(typeof c.getProvider!="function")return"retry";let v;try{v=await c.getProvider()}catch{return"retry"}let F=v?.sdk;if(!F)return"giveup";try{let E=F.getRNBridgeActiveWallet?.(),A=E?.walletName?.trim();E&&A&&r.current.set(E.address.toLowerCase(),A)}catch{}let[x,U]=await Promise.all([F.getUserInfo?.().catch(()=>null)??null,F.getAddresses?.().catch(()=>null)??null]);if(k)return"done";let W=x?.loginType,O=W==="google"||W==="apple"?W:null;if(!O)return"retry";let Q=g?.toLowerCase(),q=Q&&Array.isArray(U)?U.find(E=>E.address.toLowerCase()===Q):null,X=Array.isArray(U)?U.filter(E=>/^0x[a-fA-F0-9]{40}$/.test(E.address)).map(E=>({address:E.address.toLowerCase(),...Number.isFinite(E.index)?{index:E.index}:{},...E.name?.trim()?{name:E.name.trim()}:{}})):[],D=Q?r.current.get(Q)?.trim():void 0,G=!q&&Q&&/^0x[a-fA-F0-9]{40}$/.test(Q)?[...X,{address:Q,index:X.length,...D?{name:D}:{}}]:X,fe=D||q?.name?.trim()||(typeof q?.index=="number"?`Account ${q.index+1}`:g?`${g.slice(0,6)}\u2026${g.slice(-4)}`:null);return p({loginType:O,accountName:fe,accounts:G,isResolved:!0}),"done"};return(async()=>{for(let v=0;v<m;v++){if(k)return;let F=await I();if(F==="done")return;if(F==="giveup"){k||p({loginType:null,accountName:null,accounts:[],isResolved:!0});return}await new Promise(x=>setTimeout(x,T))}k||p({loginType:null,accountName:null,accounts:[],isResolved:!0})})(),()=>{k=!0}},[o,c,g,f]),Mn(()=>{if(o!=="cross_embedded"||!c||typeof c.getProvider!="function")return;let k=!1,m;return(async()=>{let T;try{T=await c.getProvider()}catch{return}if(k)return;let I=T?.sdk;I?.on&&(m=I.on("addressChanged",({address:v,walletName:F})=>{let x=F?.trim();x&&(r.current.set(v.toLowerCase(),x),h(U=>U+1))}))})(),()=>{k=!0,m?.()}},[o,c]),b}import{Fragment as $n,jsx as me,jsxs as it}from"react/jsx-runtime";var ms=[{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"}]}],fs=[{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"}]}],gs={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,ys={google:{name:"Google",iconUrl:Hn,connectorId:Ze.CROSSx},apple:{name:"Apple",iconUrl:Xt,connectorId:Ze.CROSSx},cross:{name:At.default,iconUrl:zt,connectorId:Ze.CROSSx},metamask:{name:"MetaMask",iconUrl:Vn,connectorId:Ze.MetaMask},binance:{name:"Binance Wallet",iconUrl:qn,connectorId:Ze.Binance}};function bs(e){switch(e){case"cross_embedded":return Ze.CROSSx;case"metamask":return Ze.MetaMask;case"binance":return Ze.Binance;default:return}}function ws(e,t){switch(e){case"cross_embedded":return t==="google"?{name:"Google",iconUrl:Hn}:t==="apple"?{name:"Apple",iconUrl:Xt}:{name:At.default,iconUrl:zt};case"cross_wallet":return{name:At.default,iconUrl:zt};case"cross_extension":return{name:At.extension,iconUrl:ps};case"metamask":return{name:"MetaMask",iconUrl:Vn};case"binance":return{name:"Binance Wallet",iconUrl:qn};default:return null}}function hs({label:e="Connect Wallet",className:t,style:n,walletInfoStyle:i,user:o,enablePortfolio:c,portfolio:g,theme:b,accountName:p,connectorId:r,showPortfolio:f,sendAccounts:h,getTransactionReceipt:k,sendTransaction:m,estimateGas:T,onDisconnect:I,onSelectWallet:v,onBuy:F,onRampRedirectUrl:x,bridgeTokens:U,bridgeHistory:W,getBridgeQuote:O,getBridgeToTokens:Q,getBridgeApproval:q,approveBridge:X,submitBridge:D,showBalance:G=!0,env:Ae,...fe}){let{address:E,isConnected:A,connector:Y,chain:H}=rs(),de=is(),Ie=ss(),{switchChainAsync:Me}=cs(),{sendTransactionAsync:ve}=as(),{connectWallet:Oe,disconnect:be,selectWallet:Ge,currentWallet:le,isConnecting:Je,kitConfig:et}=Ke(),we=et?.restoreChainAfterSwitch!==!1,tt=ft(),ct=b??tt?.mode??"dark",Be=Rt(()=>ds(Ae),[Ae]),he=o?.address??E,Ce=o?ys[o.provider]:null,{loginType:He,accountName:s,accounts:a}=qt({walletId:le,connector:Y,address:he}),d=Rt(()=>Ce?{name:Ce.name,iconUrl:Ce.iconUrl}:ws(le,He),[Ce,le,He]),u=p??o?.name??s??void 0,w=Ce?Ce.connectorId:bs(le),B=r??w,_=g??f??!!c,P=$t({env:Be,walletAddress:he,enabled:A&&!!he&&G,restoreChainAfterSwitch:we}),L=U??P.bridgeTokens,Z=W??P.bridgeHistory,S=O??P.getBridgeQuote,N=Q??P.getBridgeToTokens,$=q??P.getBridgeApproval,V=X??P.approveBridge,J=D??P.submitBridge,z=Ye(()=>{Oe().catch(M=>{console.error("[crossx-kit] connectWallet error:",M)})},[Oe]),l=Ye(()=>{be()},[be]),y=I??l,C=ls(),{eligibility:K}=us({network:H?String(H.id):void 0}),R=K?.allowed===!0,ke=Rt(()=>{if(F)return F;if(!(!C||!H||!R))return()=>C.open({crypto:H.nativeCurrency?.symbol??"USDT",network:String(H.id),...x?{redirectUrl:x}:{}}).then(()=>{}).catch(M=>{throw console.warn("[crossx-kit] onramp open failed:",M),M})},[F,C,H,R,x]),nt=os();ns(()=>{if(C?.onStatus)return C.onStatus(()=>{nt.invalidateQueries()})},[C,nt]);let Ne=Rt(()=>{if(!F&&!(!C||!H)&&!R)return"On-ramp is not available in your region."},[F,C,H,R]),Ve=fe.onBridgeDisabledMessage,_t=fe.onSendDisabledMessage,Jn=o?o.provider==="google"||o.provider==="apple":le==="cross_embedded",eo=Ye(()=>{Ge().catch(M=>{console.error("[crossx-kit] selectWallet error:",M)})},[Ge]),en=v??(Jn?eo:void 0),to=Ye(async({hash:M,chainId:ne})=>{let oe=Ht(de,ne?{chainId:ne}:void 0);if(!oe)return null;try{return await oe.getTransactionReceipt({hash:M})}catch{return null}},[de]),no=Ye(async M=>{let ne=Ie,oe=!1;M.chainId!==void 0&&M.chainId!==Ie&&(await Me({chainId:M.chainId}),oe=!0);let ue=M.chainId===56||M.chainId===97?{...M,type:"legacy"}:M,ee=await(m??ve)(ue);return await Tt({getChainId:()=>oe?M.chainId:ne,switchChain:xe=>Me({chainId:xe})},ne,we),ee},[m,ve,Ie,Me,we]),oo=_||m?no:void 0,ro=Ye(async M=>{let ne=M.chainId??Ie,oe=Ht(de,ne?{chainId:ne}:void 0);if(!oe)throw new Error(`publicClient for chainId ${ne??"unknown"} is not available \u2014 register the chain in createCrossxConfig({ networks }).`);let Te=ne===56||ne===97,[ue,Se]=await Promise.all([oe.estimateGas({account:M.from,to:M.to,value:M.value,data:M.data}),(async()=>{if(Te)return{maxFeePerGas:void 0,maxPriorityFeePerGas:void 0,gasPrice:await oe.getGasPrice()};try{let ee=await oe.estimateFeesPerGas();return{maxFeePerGas:ee.maxFeePerGas,maxPriorityFeePerGas:ee.maxPriorityFeePerGas,gasPrice:void 0}}catch{return{maxFeePerGas:void 0,maxPriorityFeePerGas:void 0,gasPrice:await oe.getGasPrice()}}})()]);return{gasLimit:ue,maxFeePerGas:Se.maxFeePerGas,maxPriorityFeePerGas:Se.maxPriorityFeePerGas,gasPrice:Se.gasPrice}},[de,Ie]),so=T??ro,io=Ye(async M=>{let ne={};if(!E||M.length===0)return ne;let oe=M.flatMap(ue=>{let ee={address:ue,abi:ms,chainId:Ie};return[{...ee,functionName:"balanceOf",args:[E]},{...ee,functionName:"totalSupply"},{...ee,functionName:"decimals"}]}),Te;try{Te=await Kn(de,{contracts:oe,allowFailure:!0})}catch{return ne}return M.forEach((ue,Se)=>{let ee=Se*3,xe=Te[ee],wt=Te[ee+1],dt=Te[ee+2];!xe||xe.status!=="success"||(ne[ue.toLowerCase()]={balance:xe.result,totalSupply:wt&&wt.status==="success"?wt.result:void 0,decimals:dt&&dt.status==="success"?Number(dt.result):void 0})}),ne},[de,E,Ie]),ao=Ye(async M=>{let ne={earnedWei:0n,stakedWei:0n};if(!M)return ne;let oe=gs[Be],Te={address:oe.poolAddress,abi:fs,chainId:oe.crossChainId},ue;try{ue=await Kn(de,{allowFailure:!0,contracts:[{...Te,functionName:"earned",args:[M]},{...Te,functionName:"balanceOf",args:[M]},{...Te,functionName:"posaActive"},{...Te,functionName:"lastRewardBlock"},{...Te,functionName:"totalStaked"}]})}catch{return ne}let Se=ot=>ue[ot]&&ue[ot].status==="success"?ue[ot].result:0n,ee=Se(0),xe=Se(1);if(ue[2]&&ue[2].status==="success"?ue[2].result:!1)return{earnedWei:ee,stakedWei:xe};let dt=Se(3),on=Se(4);if(on===0n)return{earnedWei:ee,stakedWei:xe};let Et=0n;try{Et=await Ht(de,{chainId:oe.crossChainId})?.getBlockNumber?.()??0n}catch{return{earnedWei:ee,stakedWei:xe}}if(Et<=dt)return{earnedWei:ee,stakedWei:xe};let Ot=0n;try{let ot=await fetch(oe.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:ee,stakedWei:xe};let lo=(Et-dt)*Ot*jt/on,uo=xe*lo/jt;return{earnedWei:ee+uo,stakedWei:xe}},[de,Be]),tn=!en,nn=t?`cb-button ${t}`:"cb-button",co=t?`cb-pill ${t}`:"cb-pill";return Je&&!A?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..."})]})]}):A&&he?it("span",{"data-crossx-wallet-info":tn?"external":"embedded",children:[me("style",{children:Qt}),tn&&me("style",{children:ks}),it(Vt,{...fe,env:Be,theme:ct,showBalance:G,walletAddress:he,accountName:u,sendAccounts:h??a,connectorId:B,showPortfolio:_,onDisconnect:y,onSelectWallet:en,onBuy:ke,onBuyDisabledMessage:Ne,onBridgeDisabledMessage:Ve,onSendDisabledMessage:_t,sendTransaction:oo,getTransactionReceipt:k??to,estimateGas:so,lpBalanceReader:io,stakingRewardsReader:ao,bridgeTokens:L,bridgeHistory:Z,getBridgeQuote:S,getBridgeToTokens:N,getBridgeApproval:$,approveBridge:V,submitBridge:J,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(he)}`,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(he)})]})}),me(Vt.Content,{align:"end",sideOffset:8})]})]}):it($n,{children:[me("style",{children:Qt}),it("button",{type:"button",onClick:z,className:nn,style:n,"aria-label":typeof e=="string"?e:"Connect Wallet",children:[me(Cs,{}),me("span",{className:"cb-button-label",children:e})]})]})}function Cs(){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 ks=`
|
|
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 Ts,useMemo as Qn,useState as xs}from"react";import{detectWallets as zn,DEFAULT_WALLET_REGISTRY as Xn}from"@nexus-cross/connect-kit-wagmi";import{jsx as ce,jsxs as Le}from"react/jsx-runtime";var Is=["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"],vs="Connect with one of our available wallet providers to continue.";function Ss({open:e,onClose:t,onSelect:n,title:i="Connect Wallet",description:o=vs,troubleshootingTips:c=Is}){let{availableWallets:g}=Ke(),[b,p]=xs({});Ts(()=>{if(!e)return;let m=zn(Xn),T={};for(let v of m)v.installed!==void 0&&(T[v.id]=v.installed);p(T);let I=setTimeout(()=>{let v=zn(Xn),F={};for(let x of v)x.installed!==void 0&&(F[x.id]=x.installed);p(F)},1e3);return()=>clearTimeout(I)},[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]),h=jn(m=>{if(!b[m.walletId]&&m.installUrl&&m.type==="extension"){window.open(m.installUrl,"_blank");return}t(),n(m.walletId)},[t,n,b]),k=jn((m,T)=>{m.stopPropagation(),t(),window.open(T,"_blank")},[t]);return e?ce("div",{style:j.overlay,onClick:t,children:Le("div",{style:j.modal,onClick:m=>m.stopPropagation(),children:[Le("div",{style:j.header,children:[ce("h2",{style:j.title,children:i}),ce("button",{type:"button",onClick:t,style:j.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:[ce("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),ce("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),ce("p",{style:j.desc,children:o}),ce("div",{style:j.walletList,children:f.map(m=>{let T=b[m.walletId],I=T===!1&&m.type==="extension"&&!!m.installUrl;return Le("div",{style:j.walletGroup,children:[Le("button",{type:"button",onClick:()=>h(m),style:{...j.walletItem,...m.walletId==="cross_wallet"?j.walletItemAccent:{}},"aria-label":`Connect with ${m.name}`,children:[m.iconUrl?ce("img",{src:m.iconUrl,alt:"",style:j.walletIcon}):ce("div",{style:j.walletIconPlaceholder}),Le("div",{style:j.walletInfo,children:[Le("div",{style:j.walletNameRow,children:[ce("span",{style:j.walletName,children:m.name}),T!==void 0&&ce("span",{style:{...j.badge,...T?j.badgeInstalled:j.badgeNotInstalled},children:T?"Installed":"Not Installed"})]}),ce("span",{style:j.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":T?"Connect with browser extension":"Scan QR code with app"})]})]}),m.guideUrl&&Le("button",{type:"button",onClick:v=>k(v,m.guideUrl),style:j.guideBtn,children:[ce("span",{"aria-hidden":"true",children:"\u26A0\uFE0F"}),m.guideLabel??"Required Settings"]})]},m.walletId)})}),Le("div",{style:j.troubleshoot,children:[ce("h3",{style:j.troubleshootTitle,children:"Wallet not detected?"}),ce("ul",{style:j.troubleshootList,children:c.map(m=>Le("li",{style:j.troubleshootItem,children:[ce("span",{style:j.troubleshootDot,"aria-hidden":"true"}),ce("span",{children:m})]},m))})]})]})}):null}var te={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)"},j={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:te.surfaceBg,border:`1px solid ${te.borderDefault}`,borderRadius:"20px",overflow:"hidden"},header:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"20px 24px 0"},title:{fontSize:"18px",fontWeight:700,color:te.textPrimary,margin:0},closeBtn:{background:"none",border:"none",color:te.textTertiary,cursor:"pointer",padding:"4px",borderRadius:"8px",display:"flex",alignItems:"center",justifyContent:"center"},desc:{padding:"8px 24px 16px",fontSize:"13px",color:te.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:te.surfaceDefault},walletItem:{display:"flex",alignItems:"center",gap:"14px",width:"100%",padding:"14px",background:"transparent",border:"none",color:te.textPrimary,cursor:"pointer",textAlign:"left"},walletItemAccent:{background:te.accentGradient},walletIcon:{width:"40px",height:"40px",borderRadius:"10px",flexShrink:0},walletIconPlaceholder:{width:"40px",height:"40px",borderRadius:"10px",background:te.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:te.textPrimary},badge:{fontSize:"10px",fontWeight:600,padding:"2px 7px",borderRadius:"99px",lineHeight:1},badgeInstalled:{background:te.primarySoft,color:te.primary},badgeNotInstalled:{background:"rgba(255,255,255,0.05)",color:te.textTertiary},walletDesc:{fontSize:"11px",color:te.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 ${te.warningBorder}`,background:te.warningBg,color:te.warningText,fontWeight:600,fontSize:"13px",cursor:"pointer"},troubleshoot:{margin:"0 12px 16px",background:te.surfaceDefault,borderRadius:"12px",padding:"14px 16px"},troubleshootTitle:{fontSize:"12px",fontWeight:700,color:te.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:te.textSecondary,lineHeight:1.5},troubleshootDot:{flexShrink:0,width:"4px",height:"4px",marginTop:"6px",borderRadius:"50%",background:te.textSecondary}};import{useEffect as Ps,useMemo as Yn}from"react";import{useAccount as Rs,useConfig as As,useSendTransaction as Bs,useSwitchChain as _s,useWriteContract as Es}from"wagmi";import{getBalance as Os,readContract as Ns,readContracts as Fs,waitForTransactionReceipt as Ws}from"wagmi/actions";import{RelayDeposit as Yt}from"@nexus-cross/dapp-ui";import{jsx as Ks}from"react/jsx-runtime";var Ds=56,Ls=[{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}=Rs(),n=As(),{sendTransactionAsync:i}=Bs(),{writeContractAsync:o}=Es(),{switchChainAsync:c}=_s(),g=n.chains.some(p=>p.id===Ds);Ps(()=>{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 b=Yn(()=>({sendTransaction:async({chainId:p,to:r,value:f,data:h})=>i({chainId:at(p),to:r,value:f,data:h}),writeContract:async({chainId:p,address:r,abi:f,functionName:h,args:k})=>o({chainId:at(p),address:r,abi:f,functionName:h,args:k}),readContract:g?async({chainId:p,address:r,abi:f,functionName:h,args:k})=>Ns(n,{chainId:at(p),address:r,abi:f,functionName:h,args:k}):void 0,switchChain:async p=>{await c({chainId:at(p)})},waitForReceipt:async({chainId:p,hash:r})=>({status:(await Ws(n,{chainId:at(p),hash:r})).status==="success"?"success":"reverted"}),getBalance:async({chainId:p,address:r,token:f})=>{if(!f){let v=await Os(n,{chainId:at(p),address:r});return{value:v.value,decimals:v.decimals,symbol:v.symbol}}let h={address:f,abi:Ls,chainId:at(p)},k=await Fs(n,{contracts:[{...h,functionName:"balanceOf",args:[r]},{...h,functionName:"decimals"},{...h,functionName:"symbol"}],allowFailure:!1}),[m,T,I]=k;return{value:m,decimals:T,symbol:I}}}),[n,g,i,o,c]);return Yn(()=>({walletAddress:e,walletChainId:t,...b}),[e,t,b])}function Ms(e){let t=Bt();return Ks(Yt,{...t,...e,requireWalletConnection:!0})}var Gs=Object.assign(Ms,{Trigger:Yt.Trigger,Content:Yt.Content});import{useAccount as Us}from"wagmi";import{RelayHistory as Zt}from"@nexus-cross/dapp-ui";import{jsx as Hs}from"react/jsx-runtime";function $s(e){let{address:t}=Us();return Hs(Zt,{walletAddress:t,...e})}var qs=Object.assign($s,{Trigger:Zt.Trigger,Content:Zt.Content});import{RelayRecovery as Jt}from"@nexus-cross/dapp-ui";import{jsx as Qs}from"react/jsx-runtime";function Vs(e){let t=Bt();return Qs(Jt,{...t,...e})}var js=Object.assign(Vs,{Trigger:Jt.Trigger,Content:Jt.Content});import{useContext as zs,useEffect as Xs,useRef as Ys}from"react";function Zs(e){let t=zs(kt);if(!t)throw new Error("useConnectKitAnalytics must be used within <CrossConnectKitProvider>");let n=Ys(e);n.current=e;let{subscribe:i}=t;Xs(()=>i(c=>n.current(c)),[i])}import{useOnRamp as $a,useOnRampEligibility as qa,OnRampProvider as Ha}from"@nexus-cross/onramp/react";import{useKyc as ja,useOptionalKyc as Qa,KycProvider as za,KycError as Xa,launchKycVerification as Ya}from"@nexus-cross/kyc/react";import{WalletInfo as Ja,ConnectorId as ec}from"@nexus-cross/dapp-ui";import{AppLauncher as nc,AppLauncherTrigger as oc,AppLauncherContent as rc,useGlobalMenu as sc}from"@nexus-cross/dapp-ui";import{SkillsButton as ac}from"@nexus-cross/dapp-ui";import{createRelayClient as dc,RelayApiError as lc,DEFAULT_TRUSTED_FACTORIES as uc,useRelayConfig as pc,useRelayOrders as mc,useRelayRecovery as fc}from"@nexus-cross/dapp-ui";import{OnRampError as yc}from"@nexus-cross/connect-kit-core";import{ConnectionStatus as wc,formatBalance as hc,formatWei as Cc}from"@nexus-cross/connect-kit-core";sn();export{Ke as a,ho as b,ft as c,Wt as d,Yo as e,$t as f,qt as g,hs as h,Ss as i,Bt as j,Gs as k,qs as l,js as m,Zs as n,$a as o,qa as p,Ha as q,ja as r,Qa as s,za as t,Xa as u,Ya as v,Ja as w,ec as x,nc as y,oc as z,rc as A,sc as B,ac as C,dc as D,lc as E,uc as F,pc as G,mc as H,fc as I,yc as J,wc as K,hc as L,Cc as M};
|