@nexus-cross/connect-kit-react 1.4.0-beta.4 → 1.4.0-beta.6
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-PEAZQ65Y.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-LFO3RMRX.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.4.0-beta.6";var It="__nexusCrossAppLauncherRuntime";function yo(){if(typeof window>"u")return null;let e=window;return e[It]??(e[It]={mode:"dapp-ui"}),e[It]}function bo(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=yo();e&&(e.mode="connect-kit-react",e.connectKitVersion=gt,bo(e))}import{useCallback as _e,useEffect as oe,useMemo as We,useRef as be,useState as Qe}from"react";import{WagmiProvider as vo,useAccount as Po,useChainId as So,useConnect as Ro,useDisconnect as Ao,useSwitchChain as Bo}from"wagmi";import{QueryClient as _o,QueryClientProvider as Eo}from"@tanstack/react-query";import{clearWalletSessionStorage as mn,onOpenOtherWallets as Oo,pickInitialState as No,resolveCurrentWallet as Wo}from"@nexus-cross/connect-kit-wagmi";import{resolveThemeMode as Fo}from"@nexus-cross/connect-kit-core";import{buildDesignSystemCss as Do}from"@nexus-cross/crossx-design-system";import{OnRampProvider as Lo}from"@nexus-cross/onramp/react";import{KycProvider as Go}from"@nexus-cross/kyc/react";import{createContext as ho,useContext as wo}from"react";var Dt=ho(null);function Be(){let e=wo(Dt);if(!e)throw new Error("useCrossConnectKit must be used within <CrossConnectKitProvider>");return e}import{createContext as Co,useContext as cn}from"react";var xt=Co(null);function ko(){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 To}from"react";var vt=To(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 Io,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,k={};for(let x of i){if(!xo.has(x.walletId)||p&&!p.has(x.walletId))continue;let v=x.walletId;k[v]=()=>{n(x.walletId)}}for(let[x,v]of Object.entries(c))v&&(p&&!p.has(x)||(k[x]=v));return k},[i,n,c,g]),h=ln(()=>{if(o)return{apple:()=>{o.signIn("apple")},google:()=>{o.signIn("google")}}},[o]),C=Io(p=>t(p),[t]);return pn(un,{wallets:m,socialProviders:h,termsUrl:y.legal?.termsUrl,privacyUrl:y.legal?.privacyUrl,theme:r,open:e,onOpenChange:C,children:pn(un.Content,{})})}import{jsx as ze,jsxs as yn}from"react/jsx-runtime";var Mo=new _o,Gt="crossx-kit:last-wallet-intent",Uo=15e3,Ko=1500,$o=3;function fn(e,t){return Promise.race([e.then(()=>{},()=>{}),new Promise(n=>setTimeout(n,t))])}function qo(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 Ho(){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 Vo(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 jo(e,t){if(!(typeof window>"u"))try{window.localStorage.setItem(e,t)}catch{}}function Qo({children:e,config:t,activeProvider:n,onRequestProviderSwap:i,pendingConnectWalletId:o,clearPending:c,themeMode:g,themeTokens:y,extraWallets:u,walletAllowlist:r,emit:m}){let[h,C]=Qe(!1),[p,k]=Qe(()=>Ho()),[x,v]=Qe(null),{address:W,isConnected:I,isConnecting:U,isReconnecting:D,connector:O}=Po(),{connectors:q,connectAsync:$}=Ro(),{disconnectAsync:z}=Ao(),{kitConfig:L,connectorRegistry:K,crossProvider:Re,reownProvider:de}=t,N=n==="cross"?Re:de,A=We(()=>!I||!O?null:Wo(K,O.id,p),[I,O,K,p]),Y=We(()=>K.entries.filter(l=>l.type!=="embedded"),[K]),V=_e(l=>K.getEntry(l)?.type??"external",[K]),ce=be(null);ce.current=x;let Ie=be(A);Ie.current=A;let qe=be(W);qe.current=W;let Oe=L.embeddedProjectId?.trim()||L.crossProjectId?.trim(),xe=!!L.onRampEnabled&&!!Oe,He=We(()=>!xe||!Oe?null:{projectId:Oe,walletState:{getAddress:()=>qe.current}},[xe,Oe]),we=be(O);we.current=O;let le=L.embeddedProjectId?.trim()||L.crossProjectId?.trim(),Ge=!!L.kycEnabled&&!!le,et=We(()=>!Ge||!le?null:{projectId:le,getAccessToken:async()=>{let l=we.current;if(!(!l||typeof l.getProvider!="function"))try{return(await(await l.getProvider())?.sdk?.getUserInfo?.())?.data?.accessToken||void 0}catch{return}}},[Ge,le]);oe(()=>Oo(()=>C(!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 ye=be(I),ct=be(I);ye.current=I;let tt=be(!1);oe(()=>{console.debug("[crossx-kit] state",{activeProvider:n,isConnected:I,isConnecting:U,isReconnecting:D,activeConnectorId:O?.id,currentWallet:A,lastIntent:p})},[n,I,U,D,O?.id,A,p]),oe(()=>{I&&!ct.current&&N?.closeModal?.({kitConfig:L}),ct.current=I},[I,N,L]),oe(()=>{I&&v(null)},[I]);let Ae=So(),{switchChainAsync:ve}=Bo(),ue=be(null);oe(()=>{if(!L.enforceDefaultNetworkOnConnect)return;let l=L.defaultNetwork?.id;if(!l)return;if(!I||!W||!O){ue.current=null;return}let b=`${O.id}:${W}`;ue.current!==b&&(ue.current=b,Ae!==l&&ve({chainId:l}).catch(()=>{}))},[L.enforceDefaultNetworkOnConnect,L.defaultNetwork,I,W,O,Ae,ve]);let Me=be(h);oe(()=>{h&&!Me.current?m({name:"connect_modal_opened"}):!h&&Me.current&&m({name:"connect_modal_closed",completed:ye.current}),Me.current=h},[h,m]);let dt=be(I);oe(()=>{if(I&&!dt.current){let l=ce.current;l&&m({name:"connect_succeeded",walletId:l,walletType:V(l),chainId:Ae})}dt.current=I},[I,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 T=!1;return(async()=>{try{let P=await b.getProvider();if(T)return;P?.sdk?.applyTheme?.(g,y??void 0)}catch(P){console.debug("[crossx-kit] applyTheme skipped:",P)}})(),()=>{T=!0}},[K,s,g,y]);let a=_e(l=>{k(l),gn(l)},[]),d=_e(()=>{k(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(ye.current)return;let T=ce.current;T&&m({name:"connect_cancelled",walletId:T,stage:"popup"}),(async()=>{try{await z()}catch{}d()})()},250))})},[N,L,z,d,m]),oe(()=>{if(!x||I||typeof window>"u"||x==="cross_embedded")return;let l=typeof document<"u"&&!document.hasFocus(),b=null,T=()=>{l=!0},P=()=>{l&&(b&&clearTimeout(b),b=setTimeout(()=>{if(ye.current||tt.current)return;let B=ce.current;B&&m({name:"connect_cancelled",walletId:B,stage:"popup"}),(async()=>{try{await z()}catch{}d()})()},1e3))};return window.addEventListener("blur",T),window.addEventListener("focus",P),()=>{window.removeEventListener("blur",T),window.removeEventListener("focus",P),b&&clearTimeout(b)}},[x,I,z,d,m]);let f=_e(async l=>{console.debug("[crossx-kit] runConnect enter",{walletId:l,activeProvider:n,isConnected:I,activeConnectorId:O?.id});let b=K.getEntry(l);if(!b){if((l==="metamask"||l==="binance")&&!de){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(B=>setTimeout(B,0)),i(b.providerKind,l);return}let T=V(l);if(m({name:"wallet_selected",walletId:l,walletType:T}),m({name:"connect_started",walletId:l,walletType:T}),a(l),N?.beforeConnect)try{let B=await N.beforeConnect({kitConfig:L,themeMode:g},l);if(console.debug("[crossx-kit] beforeConnect result",{walletId:l,result:B}),B==="handled")return}catch(B){console.warn('[crossx-kit] adapter.beforeConnect threw for "%s":',l,B)}let P=s(b.connectorId);if(console.debug("[crossx-kit] findConnector",{lookupId:b.connectorId,found:P?.id,availableIds:q.map(B=>B.id)}),!P){console.error(`[crossx-kit] Connector "${b.connectorId}" not found on provider "${b.providerKind}". Available: ${q.map(B=>B.id).join(", ")}`),m({name:"connect_failed",walletId:l,reason:"connector_not_found"}),d();return}try{console.debug("[crossx-kit] connectAsync start",{connectorId:P.id});let B=await $({connector:P});console.debug("[crossx-kit] connectAsync resolved",{accountsLen:B.accounts.length,chainId:B.chainId});return}catch(B){let pe=qo(B);if(!pe){console.error('[crossx-kit] connectAsync error for "%s":',l,B);try{await z()}catch{}}if(!b.fallbackConnectorId){pe||m({name:"connect_failed",walletId:l,reason:"connector_error"}),d();return}}if(b.fallbackConnectorId){let B=s(b.fallbackConnectorId);if(B)try{await $({connector:B})}catch(pe){console.error('[crossx-kit] Fallback connect failed for "%s":',l,pe);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()=>{C(!0)},[]),_=_e(async()=>{m({name:"disconnected",walletId:Ie.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]),E=_e(async()=>{await fn(z(),3e3);try{let l=K.getEntry("cross_embedded"),b=l&&s(l.connectorId);if(b?.getProvider){let T=await Promise.race([b.getProvider(),new Promise(B=>setTimeout(B,3e3))]),P=T?.sdk?.signOut;typeof P=="function"&&await fn(P.call(T.sdk),3e3)}}catch{}mn()},[K,s,z]),R=_e(async()=>{let l=K.getEntry("cross_embedded");if(!l)return null;let b=s(l.connectorId);if(!b)return null;try{let T=await b.getProvider(),P=T?.sdk;if(!P?.selectWallet)return null;let B=await P.selectWallet(P.currentAddress??void 0);return B?.address&&T.notifyAccountsChanged&&T.notifyAccountsChanged([B.address]),B&&m({name:"wallet_switched",index:B.index}),B}catch{return null}},[K,s,m]),G=We(()=>{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(T){throw m({name:"connect_cancelled",walletId:"cross_embedded",stage:"popup"}),v(null),T}}}:null},[t.oauth,m]),Z=be(!1);oe(()=>{if(n!=="cross"||I||U||D||x!=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 T=!1;return(async()=>{try{let P=await b.isAuthorized?.();if(T||!P)return;await $({connector:b})}catch{}})(),()=>{T=!0}},[n,I,U,D,x,K,s,$]);let S=be(0);oe(()=>{if(n!=="cross"||I||!U&&!D||S.current>=$o)return;let l=K.getEntry("cross_embedded");if(!l)return;let b=s(l.connectorId);if(!b)return;let T=!1,P=setInterval(()=>{(async()=>{if(T||ye.current)return;let B=await Promise.resolve(b.isAuthorized?.()).catch(()=>!1);if(!(T||!B||ye.current)){S.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{}}})()},Ko);return()=>{T=!0,clearInterval(P)}},[n,I,U,D,K,s,$]),oe(()=>{if(x!=="cross_embedded"||I||typeof window>"u")return;let l=!document.hasFocus(),b=()=>{l=!0};window.addEventListener("blur",b);let T=setTimeout(()=>{ye.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(),E())},Uo);return()=>{window.removeEventListener("blur",b),clearTimeout(T)}},[x,I,d,E,m]);let F=x!=null&&!I,j=We(()=>({kitConfig:L,connectorRegistry:K,availableWallets:Y,connect:f,connectWallet:w,disconnect:_,selectWallet:R,currentWallet:A,lastIntent:p,isConnecting:F,connectingWalletId:x,openOtherWallets:()=>C(!0),closeOtherWallets:()=>C(!1),otherWalletsOpen:h,oauth:G,extraWallets:u,walletAllowlist:r,onRampEnabled:xe}),[L,K,Y,f,w,_,R,A,p,F,x,h,G,u,r,xe]),H=yn(Dt.Provider,{value:j,children:[e,ze(Lt,{open:h,onOpenChange:C})]});return et&&(H=ze(Go,{config:et,children:H})),He&&(H=ze(Lo,{config:He,children:H})),H}var zo=[/Connection interrupted while trying to subscribe/i,/No matching key\. subscription:/i,/Proposal expired/i];function Xo(e){let t=e?.message;return typeof t!="string"?!1:zo.some(n=>n.test(t))}var Yo={};function Zo(e){return e&&{...e,connections:new Map,current:null}}function Jo({children:e,config:t,initialState:n,extraWallets:i=Yo,walletAllowlist:o}){let[c,g]=Qe(()=>Vo(t.activeProviderStorageKey,t.defaultProvider)),[y,u]=Qe(null),r=be(!1),m=be(null);m.current||(m.current=dn());let h=m.current,C=We(()=>({subscribe:h.subscribe}),[h]),{kitConfig:p}=t,[k,x]=Qe(null),[v,W]=Qe(null),[I,U]=Qe(0),D=We(()=>Fo(p.theme,p.autoDetectTheme),[p.theme,p.autoDetectTheme,I]),O=k??D,q=v??p.themeTokens;oe(()=>{if(!p.autoDetectTheme||k||typeof window>"u"||!window.matchMedia)return;let A=window.matchMedia("(prefers-color-scheme: dark)"),Y=()=>U(V=>V+1);try{return A.addEventListener("change",Y),()=>A.removeEventListener("change",Y)}catch{return A.addListener(Y),()=>A.removeListener(Y)}},[p.autoDetectTheme,k]),oe(()=>{if(typeof document>"u")return;let A=document.documentElement,Y=A.getAttribute("data-ds-theme"),V=A.getAttribute("data-theme");return A.setAttribute("data-ds-theme",O),V||A.setAttribute("data-theme",O),()=>{Y==null?A.removeAttribute("data-ds-theme"):A.setAttribute("data-ds-theme",Y),V==null&&A.removeAttribute("data-theme")}},[O]);let $=We(()=>Do(t.designSystem),[t.designSystem]),z=We(()=>({mode:O,tokens:q,setThemeMode:A=>x(A),setThemeTokens:A=>W(A)}),[O,q]);oe(()=>{if(typeof window>"u")return;let A=Y=>{Xo(Y.reason)&&Y.preventDefault()};return window.addEventListener("unhandledrejection",A),()=>window.removeEventListener("unhandledrejection",A)},[]);let L=_e((A,Y)=>{r.current||(r.current=!0,u(Y),g(A),jo(t.activeProviderStorageKey,A),queueMicrotask(()=>{r.current=!1}))},[t.activeProviderStorageKey]),K=_e(()=>u(null),[]),Re=c==="cross"?t.crossWagmiConfig:t.reownWagmiConfig,de=Zo(No(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(vt.Provider,{value:C,children:yn(xt.Provider,{value:z,children:[ze("style",{"data-crossx-design-system":"",children:$}),ze(vo,{config:N,initialState:de,children:ze(Eo,{client:Mo,children:ze(Qo,{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 rs,useMemo as Et}from"react";import{useQueryClient as ss}from"@tanstack/react-query";import{useAccount as is,useChainId as as,useConfig as cs,useSendTransaction as ds,useSwitchChain as ls}from"wagmi";import{getPublicClient as Vt,readContracts as Kn}from"wagmi/actions";import{WalletInfo as jt,ConnectorId as Je,resolveEnvironment as us,WALLET_REGISTRY as ps}from"@nexus-cross/dapp-ui";import{useOptionalOnRamp as ms,useOptionalOnRampEligibility as fs}from"@nexus-cross/onramp/react";import{APPLE_ICON as Yt,BINANCE_ICON as Hn,CROSSX_ICON as Xt,EXTENSION_ICON as gs,GOOGLE_ICON as Vn,METAMASK_ICON as jn}from"@nexus-cross/connect-kit-wagmi";import{WALLET_LABELS as kt}from"@nexus-cross/crossx-design-system";import{useCallback as re,useMemo as Te,useRef as er}from"react";import{useQueries as wn,useQuery as Xe}from"@tanstack/react-query";import{encodeFunctionData as bt,formatUnits as _t,parseSignature as tr,parseUnits as nr}from"viem";import{getChainId as Mt,getPublicClient as On,readContract as Ee,signTypedData as or,switchChain as Cn,waitForTransactionReceipt as rr,writeContract as kn}from"wagmi/actions";import{useConfig as sr}from"wagmi";async function Pt(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 St(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 ir(e){return e!=="bridge"}var $e="0x0000000000000000000000000000000000000000",Se=100,mt=18,ar=180000n,cr=500000n,Nn=new Set([56,97]),dr=130n,lr=100n,ur={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"},pr={dev:"dev",stage:"stg",production:"prod"};function mr(e,t){let n=e?.[pr[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 fr={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"},gr=["BSC_CROSS","W_CROSS","NATIVE_CROSS","USDTX","CROSSD","USDTB","SWAP_BRIDGE_ROUTER"],yr={BSC_CROSS:$e,W_CROSS:$e,NATIVE_CROSS:$e,USDTX:$e,CROSSD:$e,USDTB:$e,SWAP_BRIDGE_ROUTER:$e},br=/^0x[0-9a-fA-F]{40}$/;function hr(e,t){let n=typeof e=="string"?e:e?.[t];return typeof n=="string"&&br.test(n)?n:null}function wr(e,t){if(!e?.bridge)return null;let n=e.envToNetwork?.[t]??(t==="production"?"mainnet":"testnet"),i={};for(let o of gr){let c=hr(e.bridge[o],n);if(!c)return null;i[o]=c}return i}var Cr={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"}]}],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"}]}],In=[{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"}]}],kr=[{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:[]}],Tr=[{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 Wn(e){let t="";try{t=await e.text()}catch{}if(t){try{let n=JSON.parse(t),i=typeof n.data=="string"&&n.data||typeof n.message=="string"&&n.message||"";if(i)return`${i} (status ${e.status})`}catch{}return`${t.slice(0,300)} (status ${e.status})`}return`status ${e.status}`}async function Fe(e,t){let n=await fetch(e,{cache:"no-store",signal:t});if(!n.ok)throw new Error(`CrossD bridge adapter request failed: ${await Wn(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 Wn(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 Ir(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 Fe(`${e}/permit-hash/${t}`);if(qt(c))return c}catch{}await Ir(i)}return null}function ie(e,t){return`${e}-${t.toLowerCase()}`}function fe(e){return ie(e.chainId,e.address)}function De(e){return e==="swap"||e==="deposit-swap"||e==="swap-withdraw"}function vr(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:$e}function st(e){let t=_t(e,mt);return t.includes(".")?t.replace(/\.?0+$/,""):t}function wt(e){return nr(e||"0",mt)}function he(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=_t(e,9);return(t.includes(".")?t.replace(/\.?0+$/,""):t)||"0"}function Rt(e){return e==="bridge"?ar:cr}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 Pr(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*dr/lr: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 Sr={100:"0.01%",500:"0.05%",3e3:"0.3%",1e4:"1%"};function Rr(e){return Sr[e]??`${e/1e4}%`}function Ar(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 st(e)}function An(e,t){let n=Number(t??"0");return!Number.isFinite(n)||n<=0?0n:e*BigInt(Math.floor(n))/1000n}function At(e,t){if(!e)return!1;let n=e.toLowerCase();return t.some(i=>i.toLowerCase()===n)}function Br(e,t,n){return[{from:[e.contracts.USDTX],to:[e.contracts.CROSSD]},{from:[e.contracts.BSC_CROSS],to:[e.contracts.NATIVE_CROSS,e.contracts.W_CROSS]},{from:[e.contracts.NATIVE_CROSS,e.contracts.W_CROSS],to:[e.contracts.CROSSD]}].some(o=>At(t,o.from)&&At(n,o.to)||At(t,o.to)&&At(n,o.from))}function _r(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 Er({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&&he(e.fromAmount)<c&&t.type!=="swap"?`Minimum ${Rn(c)}`:t.type==="swap-bridge"&&e.toAmount&&he(e.toAmount)<c?`Available ${Rn(c)} or more.`:""}function Or({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=he(e.fromToken.balance||"0"),c=he(e.fromAmount);return o-i<c?`Insufficient network fee(${e.fromToken.symbol})`:""}function Nr(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 Wr(e,t){return!e||!t?null:ie(e,t)}function Fr({envConfig:e,bridgePairList:t,swapPools:n,tokenInfo:i,tokenStats:o}){let c=Nr(t,n),g=new Map;o?.forEach(u=>{let r=Wr(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),C=i?.find(k=>Number(k.chainId??k.chain_id)===h&&k.address?.toLowerCase()===m);if(!C?.symbol||!C.name)return;let p=g.get(u);y[u]={key:u,chainId:h,address:m,symbol:C.symbol,name:C.name,decimals:C.decimals||mt,image:C.image||C.icon_url,price:p?.price?Number(p.price):void 0,isNativeToken:m.toLowerCase()===e.contracts.NATIVE_CROSS.toLowerCase()}}),y}function Fn(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:Fn(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,x=>x?.toLowerCase()===m?h:x?.toLowerCase());if(!p)return null;let k="swap";return u===i.chainIds.cross&&(c===h&&(k="deposit-swap"),y===h&&(k="swap-withdraw")),{pathType:k,step:{type:"swap",chain:u,fromToken:c,toToken:y,fee:p.fee,poolAddress:p.poolAddress}}}function Dr(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),C=m===c?h:h===c?m:null;if(!C)continue;let p=Dn(ie(Number(o),C),t,i);if(!p)continue;let k=Ln(y,c,C,u);return[{type:"swap",chain:Number(o),fromToken:c,toToken:C,fee:k?.fee??Se,poolAddress:k?.poolAddress??""},p]}return null}function Lr(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:Fn(Number(c),n)},h.step]}return null}function Gr({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=Dr(o,c,n,t);if(m)return{type:"swap-bridge",steps:m,from:g,to:y};let h=Lr(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 Mr(e){return e.length<=10?e:`${e.slice(0,6)}...${e.slice(-4)}`}function Ur(e){return e.includes(".")?e.replace(/\.?0+$/,"")||"0":e}function Kr(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 $r(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":$r(Kr(t,4))}function _n(e,t){if(e==null||e==="")return"0";try{return Ur(_t(BigInt(String(e)),t.decimals))}catch{return"0"}}function qt(e){return!!(e&&/^0x[0-9a-fA-F]+$/.test(e))}function qr(e){return e?new Date(e*1e3).toISOString():new Date().toISOString()}function Hr(e,t){return t.toLowerCase()===e.contracts.W_CROSS.toLowerCase()?e.contracts.NATIVE_CROSS:t}function Vr(e,t){let n=Mr(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=Hr(e,i);return t.get(ie(n,o))||t.get(ie(n,i))||Vr(n,o)}function Bt(e){return e?.toLowerCase()||""}function jr(e){if(e.source==="swap")return"swap";let t=Bt(e.fromToken??e.from_token),n=Bt(e.toToken??e.to_token),i=Bt(e.swapTokenIn??e.swap_token_in),o=Bt(e.swapTokenOut??e.swap_token_out);return n&&i&&n===i?"bridge-swap":t&&o&&t===o?"swap-bridge":"bridge"}function Qr(e,t){let n=e.status??0,i=e.extracallSuccess??e.extracall_success??!1;return t==="bridge-swap"&&n===1&&!i?"failed":n===1?"success":"pending"}function zr({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=jr(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,C=t.value,p=t.value;c==="swap"?(m=g,h=y,C=u,p=r):c==="swap-bridge"?(m=g,C=u,p=t.value):c==="bridge-swap"&&(h=y,C=u,p=r);let k=En({envConfig:e,tokenByBridgeKey:n,chainId:i,address:m}),x=En({envConfig:e,tokenByBridgeKey:n,chainId:o,address:h}),v=t.initiatedTxHash??t.initiated_tx_hash;return!k||!x||!qt(v)?null:{id:`${v}-${t.index??""}`,timestamp:qr(t.initiatedTime??t.initiated_time),txHash:v,fromToken:k,toToken:x,fromAmount:_n(C,k),toAmount:_n(p,x),summary:{pathType:c},status:Qr(t,c)}}function Xr(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),_t(BigInt(c||"0"),g))}catch{t.set(ie(i,o),"0")}}),t}function Ke(e,t="first"){let n=e.steps.filter(i=>i.type==="swap");return t==="last"?n[n.length-1]:n[0]}function Yr(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 Zr(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 Jr(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 es(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 ts({input:e,path:t,amountData:n,gasInfo:i,liquidity:o,enrichedTokens:c,priceImpact:g}){let y=e.fromAmount||"0",u=e.toAmount||"0",r=Ke(t),m=t.steps.find(U=>U.type==="bridge"),h=t.type!=="bridge",C=!De(t.type),p=r?Ar(y,r.fee):"0",k=Number(y)>0||Number(u)>0,x=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},W=m?pt(t,m.fromChain,m.fromToken,c):void 0,I=(U,D,O)=>k?D&&D>0n?{label:U,value:st(D),tone:"default",valueToken:O}:{label:U,value:"Free",tone:"accent"}:{label:U,value:"0"};return{pathType:t.type,priceImpact:g,liquidity:o,bridgeInfo:C&&m?[{label:"Route",value:`${vn(m.fromChain)} \u2192 ${vn(m.toChain)}`},I("Validator Fee",n?.exFee,W),I("Network Fee",n?.networkFee,W)]: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:Pr(g)},{label:"In Amount",value:$t(y),valueToken:x},{label:r&&De(t.type)?`Swap Fee (${Rr(r.fee??Se)})`:"Swap Fee",value:$t(p),valueToken:x},{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=sr(),c=er(new Map),y=Xe({queryKey:["crossd-bridge-adapter",e,"remote-contracts"],queryFn:async({signal:s})=>{let a=wr(await Fe(fr[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=Te(()=>({...Cr[e],contracts:y??yr}),[e,y]),m=Xe({queryKey:["crossd-bridge-adapter",e,"pairs"],queryFn:({signal:s})=>Fe(`${r.bridgeApi}/pairs`,s),enabled:u,staleTime:3e4}),h=Xe({queryKey:["crossd-bridge-adapter",e,"swap-pools"],queryFn:({signal:s})=>Fe(`${r.bridgeApi}/swap-pools`,s),enabled:u,staleTime:3e4}),C=Te(()=>Yr(h.data,r),[r,h.data]),p=Xe({queryKey:["crossd-bridge-adapter",e,"available-liquidity",C],queryFn:async()=>await Ee(o,{address:r.contracts.USDTX,abi:Ut,functionName:"balanceOf",args:[C],chainId:r.chainIds.cross}),enabled:u&&!!C,staleTime:3e4}),k=Xe({queryKey:["crossd-bridge-adapter",e,"token-info"],queryFn:({signal:s})=>Fe(`${r.walletApi}/v1/public/token/info`,s),enabled:u,staleTime:3e4}),x=Xe({queryKey:["crossd-bridge-adapter",e,"token-stats"],queryFn:({signal:s})=>Fe(`${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 Fe(`${r.walletApi}/v1/public/token/balance?${d}`,a)},enabled:u&&!!t,staleTime:0,refetchInterval:u&&t?5e3:!1}))}),W=wn({queries:[r.chainIds.cross,r.chainIds.bsc].map(s=>({queryKey:["crossd-bridge-adapter",e,"gas-suggestion",s],queryFn:async({signal:a})=>{try{let 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 Fe(`${r.walletApi}/v1/public/transaction/gas-suggestion/dynamic?${d}`,a)},enabled:u,staleTime:1e4,retry:1}))}),I=Xe({queryKey:["crossd-bridge-adapter",e,"hidden-pairs"],queryFn:async({signal:s})=>mr(await Fe(ur[e],s),e),enabled:u,staleTime:5*6e4,retry:1}),U=Te(()=>I.data??[],[I.data]),D=Te(()=>Fr({envConfig:r,bridgePairList:m.data,swapPools:h.data,tokenInfo:k.data,tokenStats:x.data}),[m.data,r,h.data,k.data,x.data]),O=Te(()=>Gr({envConfig:r,bridgePairList:m.data,swapPools:h.data,enrichedTokens:D}),[m.data,D,r,h.data]),q=Te(()=>Xr(v.map(s=>s.data).filter(s=>Array.isArray(s))),[v]),$=Te(()=>{let s=new Map;return Object.values(D).forEach(a=>{let d=Bn(a,q);s.set(a.key,d)}),s},[q,D]),z=Te(()=>{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=k.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,$,k.data]),L=Xe({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:u&&!!t,staleTime:0,refetchInterval:u&&t?5e3:!1}),K=Te(()=>(L.data?.histories||[]).map(s=>zr({envConfig:r,item:s,tokenByBridgeKey:$})).filter(s=>!!s),[L.data?.histories,r,$]),Re=Te(()=>Jr(p.data),[p.data]),de=W[0]?.data,N=W[1]?.data,A=Te(()=>{let s=new Map;return de&&s.set(r.chainIds.cross,de),N&&s.set(r.chainIds.bsc,N),s},[N,de,r.chainIds.bsc,r.chainIds.cross]),Y=re((s,a,d)=>{let f=A.get(s.from.chainId)?.fast,w=a?d?.gasLimit??Rt(s.type):0n,_=d?.gasPrice&&d.gasPrice>0n?d.gasPrice:0n,E=d?.maxFeePerGas&&d.maxFeePerGas>0n?d.maxFeePerGas:0n,R=d?.maxPriorityFeePerGas&&d.maxPriorityFeePerGas>0n?d.maxPriorityFeePerGas:0n,G=Ye(f?.maxFee??f?.max_fee),Z=Ye(f?.maxPriorityFee??f?.max_priority_fee),S=E>0n?E:G>0n?G:_,F=R>0n?R:Z>0n?Z:S,j=_>0n?_:S,X=Nn.has(s.from.chainId)&&j>0n,l=w*(X?j:S),b=$.get(ie(s.from.chainId,r.contracts.NATIVE_CROSS)),T=s.type!=="swap-bridge",P=z.get(s.from.chainId);return{estTxFee:a?st(l):"0",priorityFeePerGas:a&&!X?Kt(F):"0",maxFeePerGas:a&&!X?Kt(S):"0",gasLimit:a?w.toString():"0",gasPrice:a&&X?Kt(j):void 0,isDelegateFee:s.type==="swap-bridge"?!1:Br(r,s.from.address,s.to.address),tokenIconUrl:T?b?.iconUrl:void 0,tokenSymbol:T?b?.symbol:void 0,gasCurrencyIconUrl:P?.iconUrl,gasCurrencySymbol:P?.symbol}},[r,A,z,$]),V=re(async s=>{let a=_r(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 Fe(`${r.bridgeApi}/token-config?${_}`)).config??null}catch{return null}})();return c.current.set(d,w),w},[e,r.bridgeApi]),ce=Te(()=>{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=fe(d).toLowerCase()===a.toLowerCase(),_=fe(f).toLowerCase()===a.toLowerCase();return w!==_?w?-1:1:fe(d).localeCompare(fe(f))})},[q,D,r]),Ie=Te(()=>{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]),qe=re(s=>{let a=fe(s),d=a.toLowerCase(),f=[];Object.keys(D).forEach(E=>{let R=E.toLowerCase();if(d===R||U.some(S=>S.fromKey===d&&S.toKey===R))return;let G=O(a,E);if(!G)return;let Z=$.get(E);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((E,R)=>{if(d===w.toLowerCase()){let j=fe(E.token).toLowerCase()===_.toLowerCase(),X=fe(R.token).toLowerCase()===_.toLowerCase();if(j!==X)return j?-1:1}let G=De(E.path.type),Z=De(R.path.type);if(G!==Z)return G?-1:1;let S=E.token.chainId===s.chainId,F=R.token.chainId===s.chainId;return S!==F?S?-1:1:fe(E.token).localeCompare(fe(R.token))}),f.map(E=>E.token)},[D,r,O,U,$]),Oe=re(async s=>await Ee(o,{address:r.contracts.SWAP_BRIDGE_ROUTER,abi:rt,functionName:"quoter",chainId:s}),[r.contracts.SWAP_BRIDGE_ROUTER,o]),xe=re(async s=>{Mt(o)!==s&&await Cn(o,{chainId:s})},[o]),He=re(s=>Pt({getChainId:()=>Mt(o),switchChain:a=>Cn(o,{chainId:a})},s,i),[i,o]),we=re(async s=>await Ee(o,{address:r.contracts.SWAP_BRIDGE_ROUTER,abi:rt,functionName:"swapRouter",chainId:s}),[r.contracts.SWAP_BRIDGE_ROUTER,o]),le=re(async({path:s,step:a,amount:d,source:f})=>{let w=await Oe(a.chain),_=a.poolAddress?Ee(o,{address:a.poolAddress,abi:kr,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:In,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:st(G[0]),path:s,priceImpact:Z}}let E=await Ee(o,{address:w,abi:In,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}),R=Pn(await _,E[1]);return{amount:st(E[0]),path:s,priceImpact:R}},[r,Oe,o]),Ge=re(async(s,a)=>{if(!t)throw new Error("Wallet is not connected.");let d=Rt(a.type);if(De(a.type)){let S=Ke(a,"first");if(!S)throw new Error("Swap route is not available.");let F=he(s.fromAmount),j=he(s.toAmount);if(F<=0n)throw new Error("Bridge amount is empty.");if(j<=0n)throw new Error("Bridge quote is not ready.");let X=await we(S.chain),H=St(j,s.slippage),l=a.type==="swap-withdraw"?$e:t,b={tokenIn:se(r,S.fromToken),tokenOut:se(r,S.toToken),fee:S.fee??Se,recipient:l,deadline:ht(),amountIn:F,amountOutMinimum:H,sqrtPriceLimitX96:0n};if(a.type==="swap-withdraw"){let T=bt({abi:Ue,functionName:"exactInputSingle",args:[b]}),P=bt({abi:Ue,functionName:"unwrapWETH9",args:[H,t]});return{address:X,abi:Ue,functionName:"multicall",args:[[T,P]],chainId:S.chain,fallbackGasLimit:d}}if(a.type==="deposit-swap"){let T=bt({abi:Ue,functionName:"exactInputSingle",args:[b]}),P=bt({abi:Ue,functionName:"refundETH",args:[]});return{address:X,abi:Ue,functionName:"multicall",args:[[T,P]],value:F,chainId:S.chain,fallbackGasLimit:d}}return{address:X,abi:Ue,functionName:"exactInputSingle",args:[b],chainId:S.chain,fallbackGasLimit:d}}if(a.type==="swap-bridge"){let S=Ke(a,"first");if(!S)throw new Error("Swap bridge route is not available.");let F=he(s.fromAmount),j=he(s.toAmount);if(F<=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,S.toToken),fee:S.fee??Se,sqrtPriceLimitX96:0n,bridgeParams:l};if(s.lastChangedBy==="to"){let P={...b,amountOut:j,amountInMaximum:hn(F,s.slippage)};return{address:X,abi:rt,functionName:"swapBridgeExactOutputSingle",args:[P,H],value:a.from.isNativeToken?P.amountInMaximum:void 0,chainId:a.from.chainId,fallbackGasLimit:d}}let T={...b,amountIn:F,amountOutMinimum:St(j,s.slippage)};return{address:X,abi:rt,functionName:"swapBridgeExactInputSingle",args:[T,H],value:a.from.isNativeToken?F:void 0,chainId:a.from.chainId,fallbackGasLimit:d}}let f=a.steps.find(S=>S.type==="bridge");if(!f?.bridgeAddress)throw new Error("Bridge route is not available.");let w=he(s.fromAmount);if(w<=0n)throw new Error("Bridge amount is empty.");let _=await V(a),E=Ye(_?.gasFee??_?.gas_fee),R=An(w,_?.exFeeRate??_?.ex_fee_rate),G="0x";if(a.type==="bridge-swap"){let S=Ke(a,"last");if(!S)throw new Error("Bridge swap route is not available.");let F=he(s.toAmount);if(F<=0n)throw new Error("Bridge quote is not ready.");let j=await we(a.to.chainId),X=St(F,s.slippage),H=bt({abi:Ue,functionName:"exactInputSingle",args:[{tokenIn:se(r,S.fromToken),tokenOut:se(r,S.toToken),fee:S.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,E,R,G];return{address:f.bridgeAddress,abi:Tr,functionName:"bridgeToken",args:Z,value:a.from.isNativeToken?w+R+E:void 0,chainId:a.from.chainId,fallbackGasLimit:d}},[r,V,we,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=he(s.fromAmount);if(d<=0n)throw new Error("Bridge amount is empty.");if(a.type==="swap-bridge"){let E=Ke(a,"first");if(!E)throw new Error("Swap bridge route is not available.");let R=r.contracts.SWAP_BRIDGE_ROUTER,G={tokenIn:se(r,a.from.address),tokenOut:se(r,E.toToken),fee:E.fee??Se,sqrtPriceLimitX96:0n,bridgeParams:{toChainID:BigInt(a.to.chainId),recipient:t,extraData:"0x"},amountIn:d,amountOutMinimum:0n};return{address:R,abi:rt,functionName:"swapBridgeExactInputSingle",args:[G,ht()],value:a.from.isNativeToken?d:void 0,chainId:a.from.chainId,fallbackGasLimit:Rt(a.type)}}let f=Ke(a,"first");if(!f)throw new Error("Swap route is not available.");let w=await we(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:Ue,functionName:"exactInputSingle",args:[_],value:a.from.isNativeToken?d:void 0,chainId:f.chain,fallbackGasLimit:Rt(a.type)}},[Ge,r,we,t]),ye=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]),ct=re(async s=>{let a=fe(s.fromToken),d=fe(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,E=Zr(f,r)?Re:void 0,R=async(H,l,b)=>{let T=_?await ye(H,f):null,P=Y(f,_,T);return ts({input:H,path:f,gasInfo:P,amountData:l,liquidity:E,enrichedTokens:D,priceImpact:b})};if(!w||Number(w)<=0)return{fromAmount:s.fromAmount,toAmount:s.toAmount,summary:await R(s)};let G=await V(f),Z=Ye(G?.gasFee??G?.gas_fee),S=f.type==="bridge"||f.type==="bridge-swap"?{networkFee:Z}:void 0,F=f.type==="bridge"?s.lastChangedBy==="to"?{...s,fromAmount:s.toAmount}:{...s,toAmount:s.fromAmount}:s,j=Er({input:F,path:f,config:G});if(j)return{fromAmount:F.fromAmount,toAmount:F.toAmount,summary:await R(F,S),error:j};let X=Or({input:F,path:f,config:G});if(X)return{fromAmount:F.fromAmount,toAmount:F.toAmount,summary:await R(F,S),error:X};if(f.type==="bridge")return{fromAmount:F.fromAmount,toAmount:F.toAmount,summary:await R(F,S)};try{if(f.type==="swap-bridge"){let T=Ke(f,"first"),P=r.contracts.SWAP_BRIDGE_ROUTER;if(!T)return{error:"Swap bridge route is not ready."};let B=Ne=>le({path:f,step:T,amount:Ne,source:"from"}).then(je=>je.priceImpact).catch(()=>{});if(s.lastChangedBy==="from"){let Ne=await Ee(o,{address:P,abi:rt,functionName:"getAmountSwapBridgeOut",args:[BigInt(f.to.chainId),se(r,f.from.address),se(r,T.toToken),T.fee??Se,wt(s.fromAmount)],chainId:f.from.chainId}),je=st(Ne[1]),Ot={...s,toAmount:je};return{toAmount:je,summary:await R(Ot,{networkFee:Ne[3],exFee:Ne[4]},await B(s.fromAmount))}}let pe=await Ee(o,{address:P,abi:rt,functionName:"getAmountSwapBridgeIn",args:[BigInt(f.to.chainId),se(r,f.from.address),se(r,T.toToken),T.fee??Se,wt(s.toAmount)],chainId:f.from.chainId}),Ve=st(pe[1]),nt={...s,fromAmount:Ve};return{fromAmount:Ve,summary:await R(nt,{networkFee:pe[3],exFee:pe[4]},await B(Ve))}}let H=f.type==="bridge-swap"?Ke(f,"last"):Ke(f,"first");if(!H)return{error:"Swap route is not available."};let l=await le({path:f,step:H,amount:w,source:s.lastChangedBy});if(s.lastChangedBy==="from"){let T={...s,toAmount:l.amount};return{toAmount:l.amount,summary:await R(T,S,l.priceImpact)}}let b={...s,fromAmount:l.amount};return{fromAmount:l.amount,summary:await R(b,S,l.priceImpact)}}catch(H){return{fromAmount:s.fromAmount,toAmount:s.toAmount,summary:await R(s,S),error:vr(H)}}},[Re,Y,D,r,ye,O,V,le,o]),tt=re(async s=>{if(s.from.isNativeToken)return null;if(s.type==="swap"||s.type==="deposit-swap"||s.type==="swap-withdraw")return we(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,we]),Ae=re(async s=>{if(!t)throw new Error("Wallet is not connected.");let a=fe(s.fromToken),d=fe(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=he(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]),ve=re(async(s,a)=>{let d=he(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 rr(o,{hash:f,chainId:a.token.chainId})},[xe,o]),ue=re(async(s,a)=>{let d=await Ge(s,a);await xe(d.chainId);let f=await Sn(o,d.chainId,d.fallbackGasLimit,ir(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,E=he(s.fromAmount);if(E<=0n)throw new Error("Bridge amount is empty.");let R=await V(a),G=Ye(R?.gasFee??R?.gas_fee),Z=An(E,R?.exFeeRate??R?.ex_fee_rate),S=E+Z+G,[F,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 or(o,{domain:{name:F,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:S,nonce:j,deadline:X}}),{r:l,s:b,v:T,yParity:P}=tr(H),B=T!==void 0?Number(T):P+27,pe={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:B,value:S.toString()},to:d,toChainID:String(a.to.chainId),value:S.toString()},Ve=await xn(`${r.bridgeApi}/permit`,pe),nt=Ve?.requestId??Ve?.request_id;if(!nt)throw new Error("Bridge permit request failed.");let Ne=await xr(r.bridgeApi,nt);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]),dt=re(async s=>{let a=Mt(o),d=fe(s.fromToken),f=fe(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 R=w.type==="bridge"&&w.from.chainId===r.chainIds.bsc&&w.from.address.toLowerCase()===r.contracts.BSC_CROSS.toLowerCase()?await Me(s,w):await ue(s,w);return await He(a),{...R,pathType:w.type,routeTokens:es(w,D)}},[D,r,O,He,Me,ue,o]);return{bridgeTokens:ce,bridgeHistory:K,getBridgeApproval:Ae,approveBridge:ve,getBridgeQuote:ct,getBridgeToTokens:qe,submitBridge:dt,oneUsdPairs:Ie,isLoading:m.isLoading||h.isLoading||k.isLoading||x.isLoading||v.some(s=>s.isLoading)}}import{useEffect as Mn,useRef as ns,useState as Un}from"react";import{useAccount as os}from"wagmi";function Ht(e){let{address:t,connector:n}=os(),{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=ns(new Map),[m,h]=Un(0);return Mn(()=>{let C=!1;if(o!=="cross_embedded")return u({loginType:null,accountName:null,accounts:[],isResolved:!0}),()=>{C=!0};if(!c)return u({loginType:null,accountName:null,accounts:[],isResolved:!1}),()=>{C=!0};u(v=>({...v,isResolved:!1}));let p=20,k=300,x=async()=>{if(typeof c.getProvider!="function")return"retry";let v;try{v=await c.getProvider()}catch{return"retry"}let W=v?.sdk;if(!W)return"giveup";try{let N=W.getRNBridgeActiveWallet?.(),A=N?.walletName?.trim();N&&A&&r.current.set(N.address.toLowerCase(),A)}catch{}let[I,U]=await Promise.all([W.getUserInfo?.().catch(()=>null)??null,W.getAddresses?.().catch(()=>null)??null]);if(C)return"done";let D=I?.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,de=L||$?.name?.trim()||(typeof $?.index=="number"?`Account ${$.index+1}`:g?`${g.slice(0,6)}\u2026${g.slice(-4)}`:null);return u({loginType:O,accountName:de,accounts:K,isResolved:!0}),"done"};return(async()=>{for(let v=0;v<p;v++){if(C)return;let W=await x();if(W==="done")return;if(W==="giveup"){C||u({loginType:null,accountName:null,accounts:[],isResolved:!0});return}await new Promise(I=>setTimeout(I,k))}C||u({loginType:null,accountName:null,accounts:[],isResolved:!0})})(),()=>{C=!0}},[o,c,g,m]),Mn(()=>{if(o!=="cross_embedded"||!c||typeof c.getProvider!="function")return;let C=!1,p;return(async()=>{let k;try{k=await c.getProvider()}catch{return}if(C)return;let x=k?.sdk;x?.on&&(p=x.on("addressChanged",({address:v,walletName:W})=>{let I=W?.trim();I&&(r.current.set(v.toLowerCase(),I),h(U=>U+1))}))})(),()=>{C=!0,p?.()}},[o,c]),y}import{Fragment as qn,jsx as ge,jsxs as it}from"react/jsx-runtime";var ys=[{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"}]}],bs=[{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"}]}],hs={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,ws={google:{name:"Google",iconUrl:Vn,connectorId:Je.CROSSx},apple:{name:"Apple",iconUrl:Yt,connectorId:Je.CROSSx},cross:{name:kt.default,iconUrl:Xt,connectorId:Je.CROSSx},metamask:{name:"MetaMask",iconUrl:jn,connectorId:Je.MetaMask},binance:{name:"Binance Wallet",iconUrl:Hn,connectorId:Je.Binance}};function Cs(e){switch(e){case"cross_embedded":return Je.CROSSx;case"metamask":return Je.MetaMask;case"binance":return Je.Binance;default:return}}function ks(e,t){switch(e){case"cross_embedded":return t==="google"?{name:"Google",iconUrl:Vn}:t==="apple"?{name:"Apple",iconUrl:Yt}:{name:kt.default,iconUrl:Xt};case"cross_wallet":return{name:kt.default,iconUrl:Xt};case"cross_extension":return{name:kt.extension,iconUrl:gs};case"metamask":return{name:"MetaMask",iconUrl:jn};case"binance":return{name:"Binance Wallet",iconUrl:Hn};default:return null}}function Ts(e){if(e)return e==="cross_embedded"?kt.default:ps[e]?.name}function Is({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:C,sendTransaction:p,estimateGas:k,onDisconnect:x,onSelectWallet:v,onBuy:W,onRampRedirectUrl:I,bridgeTokens:U,bridgeHistory:D,getBridgeQuote:O,getBridgeToTokens:q,getBridgeApproval:$,approveBridge:z,submitBridge:L,showBalance:K=!0,env:Re,...de}){let{address:N,isConnected:A,connector:Y,chain:V}=is(),ce=cs(),Ie=as(),{switchChainAsync:qe}=ls(),{sendTransactionAsync:Oe}=ds(),{connectWallet:xe,disconnect:He,selectWallet:we,currentWallet:le,isConnecting:Ge,kitConfig:et}=Be(),ye=et?.restoreChainAfterSwitch!==!1,ct=yt(),tt=y??ct?.mode??"dark",Ae=Et(()=>us(Re),[Re]),ve=o?.address??N,ue=o?ws[o.provider]:null,{loginType:Me,accountName:dt,accounts:s}=Ht({walletId:le,connector:Y,address:ve}),a=Et(()=>ue?{name:ue.name,iconUrl:ue.iconUrl}:ks(le,Me),[ue,le,Me]),d=u??o?.name??dt??void 0,f=de.connectorName??(ue?ue.name:Ts(le)),w=ue?ue.connectorId:Cs(le),_=r??w,E=g??m??!!c,R=Ct({env:Ae,walletAddress:ve,enabled:A&&!!ve&&K,restoreChainAfterSwitch:ye}),G=U??R.bridgeTokens,Z=D??R.bridgeHistory,S=O??R.getBridgeQuote,F=q??R.getBridgeToTokens,j=$??R.getBridgeApproval,X=z??R.approveBridge,H=L??R.submitBridge,l=Ze(()=>{xe().catch(M=>{console.error("[crossx-kit] connectWallet error:",M)})},[xe]),b=Ze(()=>{He()},[He]),T=x??b,P=ms(),{eligibility:B}=fs({network:V?String(V.id):void 0}),pe=B?.allowed===!0,Ve=Et(()=>{if(W)return W;if(!(!P||!V||!pe))return()=>P.open({crypto:V.nativeCurrency?.symbol??"USDT",network:String(V.id),...I?{redirectUrl:I}:{}}).then(()=>{}).catch(M=>{throw console.warn("[crossx-kit] onramp open failed:",M),M})},[W,P,V,pe,I]),nt=ss();rs(()=>{if(P?.onStatus)return P.onStatus(()=>{nt.invalidateQueries()})},[P,nt]);let Ne=Et(()=>{if(!W&&!(!P||!V)&&!pe)return"On-ramp is not available in your region."},[W,P,V,pe]),je=de.onBridgeDisabledMessage,Ot=de.onSendDisabledMessage,to=o?o.provider==="google"||o.provider==="apple":le==="cross_embedded",no=Ze(()=>{we().catch(M=>{console.error("[crossx-kit] selectWallet error:",M)})},[we]),tn=v??(to?no:void 0),oo=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]),ro=Ze(async M=>{let te=Ie,ne=!1;M.chainId!==void 0&&M.chainId!==Ie&&(await qe({chainId:M.chainId}),ne=!0);let me=M.chainId===56||M.chainId===97?{...M,type:"legacy"}:M,J=await(p??Oe)(me);return await Pt({getChainId:()=>ne?M.chainId:te,switchChain:ke=>qe({chainId:ke})},te,ye),J},[p,Oe,Ie,qe,ye]),so=E||p?ro:void 0,io=Ze(async M=>{let te=M.chainId??Ie,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 Ce=te===56||te===97,[me,Pe]=await Promise.all([ne.estimateGas({account:M.from,to:M.to,value:M.value,data:M.data}),(async()=>{if(Ce)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:me,maxFeePerGas:Pe.maxFeePerGas,maxPriorityFeePerGas:Pe.maxPriorityFeePerGas,gasPrice:Pe.gasPrice}},[ce,Ie]),ao=k??io,co=Ze(async M=>{let te={};if(!N||M.length===0)return te;let ne=M.flatMap(me=>{let J={address:me,abi:ys,chainId:Ie};return[{...J,functionName:"balanceOf",args:[N]},{...J,functionName:"totalSupply"},{...J,functionName:"decimals"}]}),Ce;try{Ce=await Kn(ce,{contracts:ne,allowFailure:!0})}catch{return te}return M.forEach((me,Pe)=>{let J=Pe*3,ke=Ce[J],Tt=Ce[J+1],lt=Ce[J+2];!ke||ke.status!=="success"||(te[me.toLowerCase()]={balance:ke.result,totalSupply:Tt&&Tt.status==="success"?Tt.result:void 0,decimals:lt&<.status==="success"?Number(lt.result):void 0})}),te},[ce,N,Ie]),lo=Ze(async M=>{let te={earnedWei:0n,stakedWei:0n};if(!M)return te;let ne=hs[Ae],Ce={address:ne.poolAddress,abi:bs,chainId:ne.crossChainId},me;try{me=await Kn(ce,{allowFailure:!0,contracts:[{...Ce,functionName:"earned",args:[M]},{...Ce,functionName:"balanceOf",args:[M]},{...Ce,functionName:"posaActive"},{...Ce,functionName:"lastRewardBlock"},{...Ce,functionName:"totalStaked"}]})}catch{return te}let Pe=ot=>me[ot]&&me[ot].status==="success"?me[ot].result:0n,J=Pe(0),ke=Pe(1);if(me[2]&&me[2].status==="success"?me[2].result:!1)return{earnedWei:J,stakedWei:ke};let lt=Pe(3),rn=Pe(4);if(rn===0n)return{earnedWei:J,stakedWei:ke};let Nt=0n;try{Nt=await Vt(ce,{chainId:ne.crossChainId})?.getBlockNumber?.()??0n}catch{return{earnedWei:J,stakedWei:ke}}if(Nt<=lt)return{earnedWei:J,stakedWei:ke};let Wt=0n;try{let ot=await fetch(ne.networkStatsUrl).then(Ft=>Ft.json()),sn=ot?.data?.block_reward??ot?.block_reward;if(sn){let[Ft,fo=""]=String(sn).split("."),go=(fo+"0".repeat(18)).slice(0,18);Wt=BigInt(Ft||"0")*Qt+BigInt(go||"0")}}catch{}if(Wt===0n)return{earnedWei:J,stakedWei:ke};let po=(Nt-lt)*Wt*Qt/rn,mo=ke*po/Qt;return{earnedWei:J+mo,stakedWei:ke}},[ce,Ae]),nn=!tn,on=t?`cb-button ${t}`:"cb-button",uo=t?`cb-pill ${t}`:"cb-pill";return Ge&&!A?it(qn,{children:[ge("style",{children:zt}),it("button",{type:"button",disabled:!0,className:on,style:n,"aria-busy":"true",children:[ge("span",{className:"cb-spinner","aria-hidden":"true"}),ge("span",{className:"cb-button-label",children:"Connecting..."})]})]}):A&&ve?it("span",{"data-crossx-wallet-info":nn?"external":"embedded",children:[ge("style",{children:zt}),nn&&ge("style",{children:vs}),it(jt,{...de,env:Ae,theme:tt,showBalance:K,walletAddress:ve,accountName:d,sendAccounts:h??s,connectorName:f,connectorId:_,showPortfolio:E,onDisconnect:T,onSelectWallet:tn,onBuy:Ve,onBuyDisabledMessage:Ne,onBridgeDisabledMessage:je,onSendDisabledMessage:Ot,sendTransaction:so,getTransactionReceipt:C??oo,estimateGas:ao,lpBalanceReader:co,stakingRewardsReader:lo,bridgeTokens:G,bridgeHistory:Z,getBridgeQuote:S,getBridgeToTokens:F,getBridgeApproval:j,approveBridge:X,submitBridge:H,style:i,children:[ge(jt.Trigger,{asChild:!0,children:it("button",{type:"button",className:uo,style:n,"aria-label":`Connected with ${a?.name??"wallet"}: ${$n(ve)}`,children:[a?.iconUrl?ge("img",{src:a.iconUrl,alt:"",width:20,height:20,className:"cb-pill-icon","data-provider":a.iconUrl===Yt?"apple":void 0}):ge("span",{className:"cb-pill-icon-placeholder","aria-hidden":"true"}),ge("span",{className:"cb-pill-address",children:$n(ve)})]})}),ge(jt.Content,{align:"end",sideOffset:8})]})]}):it(qn,{children:[ge("style",{children:zt}),it("button",{type:"button",onClick:l,className:on,style:n,"aria-label":typeof e=="string"?e:"Connect Wallet",children:[ge(xs,{}),ge("span",{className:"cb-button-label",children:e})]})]})}function xs(){return ge("svg",{className:"cb-button-icon",viewBox:"0 0 18 18",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:ge("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 vs=`
|
|
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 Ps,useMemo as zn,useState as Ss}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 Rs=["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"],As="Connect with one of our available wallet providers to continue.";function Bs({open:e,onClose:t,onSelect:n,title:i="Connect Wallet",description:o=As,troubleshootingTips:c=Rs}){let{availableWallets:g}=Be(),[y,u]=Ss({});Ps(()=>{if(!e)return;let p=Xn(Yn),k={};for(let v of p)v.installed!==void 0&&(k[v.id]=v.installed);u(k);let x=setTimeout(()=>{let v=Xn(Yn),W={};for(let I of v)I.installed!==void 0&&(W[I.id]=I.installed);u(W)},1e3);return()=>clearTimeout(x)},[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]),C=Qn((p,k)=>{p.stopPropagation(),t(),window.open(k,"_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 k=y[p.walletId],x=k===!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}),k!==void 0&&ae("span",{style:{...Q.badge,...k?Q.badgeInstalled:Q.badgeNotInstalled},children:k?"Installed":"Not Installed"})]}),ae("span",{style:Q.walletDesc,children:x?"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":k?"Connect with browser extension":"Scan QR code with app"})]})]}),p.guideUrl&&Le("button",{type:"button",onClick:v=>C(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 _s,useMemo as Zn}from"react";import{useAccount as Es,useConfig as Os,useSendTransaction as Ns,useSwitchChain as Ws,useWriteContract as Fs}from"wagmi";import{getBalance as Ds,readContract as Ls,readContracts as Gs,waitForTransactionReceipt as Ms}from"wagmi/actions";import{RelayDeposit as Zt}from"@nexus-cross/dapp-ui";import{jsx as Hs}from"react/jsx-runtime";var Us=56,Ks=[{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,Jn=!1;function ft(){let{address:e,chainId:t}=Es(),n=Os(),{sendTransactionAsync:i}=Ns(),{writeContractAsync:o}=Fs(),{switchChainAsync:c}=Ws(),g=n.chains.some(u=>u.id===Us);_s(()=>{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:at(u),to:r,value:m,data:h}),writeContract:async({chainId:u,address:r,abi:m,functionName:h,args:C})=>o({chainId:at(u),address:r,abi:m,functionName:h,args:C}),readContract:g?async({chainId:u,address:r,abi:m,functionName:h,args:C})=>Ls(n,{chainId:at(u),address:r,abi:m,functionName:h,args:C}):void 0,switchChain:async u=>{await c({chainId:at(u)})},waitForReceipt:async({chainId:u,hash:r})=>({status:(await Ms(n,{chainId:at(u),hash:r})).status==="success"?"success":"reverted"}),getBalance:async({chainId:u,address:r,token:m})=>{if(!m){let v=await Ds(n,{chainId:at(u),address:r});return{value:v.value,decimals:v.decimals,symbol:v.symbol}}let h={address:m,abi:Ks,chainId:at(u)},C=await Gs(n,{contracts:[{...h,functionName:"balanceOf",args:[r]},{...h,functionName:"decimals"},{...h,functionName:"symbol"}],allowFailure:!1}),[p,k,x]=C;return{value:p,decimals:k,symbol:x}}}),[n,g,i,o,c]);return Zn(()=>({walletAddress:e,walletChainId:t,...y}),[e,t,y])}function $s(e){let t=ft();return Hs(Zt,{...t,...e,requireWalletConnection:!0})}var qs=Object.assign($s,{Trigger:Zt.Trigger,Content:Zt.Content});import{useCallback as Vs,useMemo as eo}from"react";import{useAccount as js,useConfig as Qs}from"wagmi";import{waitForTransactionReceipt as zs}from"wagmi/actions";import{GetOneUsd as Xs,resolveEnvironment as Ys}from"@nexus-cross/dapp-ui";import{jsx as Js}from"react/jsx-runtime";function Zs({env:e,pairs:t,bridgeOptions:n,relay:i,restoreChainAfterSwitch:o=!0,waitForTransaction:c,onRequestConnect:g,...y}){let u=Ys(e),{address:r}=js(),m=Qs(),{connectWallet:h}=Be(),C=ft(),p=Ct({env:u,walletAddress:r,enabled:!0,restoreChainAfterSwitch:o}),{bridgeHistory:k,getBridgeQuote:x,getBridgeToTokens:v,getBridgeApproval:W,approveBridge:I,submitBridge:U}=p,D=eo(()=>({...n,history:k,getQuote:x,getToTokens:v,getApproval:W,approveBridge:I,submitBridge:U}),[I,k,n,W,x,v,U]),O=eo(()=>({...i,...C}),[i,C]),q=Vs(async $=>{if((await zs(m,{hash:$.txHash,chainId:$.fromToken.chainId})).status!=="success")throw new Error("Transaction reverted.")},[m]);return Js(Xs,{...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 ei}from"wagmi";import{RelayHistory as Jt}from"@nexus-cross/dapp-ui";import{jsx as oi}from"react/jsx-runtime";function ti(e){let{address:t}=ei();return oi(Jt,{walletAddress:t,...e})}var ni=Object.assign(ti,{Trigger:Jt.Trigger,Content:Jt.Content});import{RelayRecovery as en}from"@nexus-cross/dapp-ui";import{jsx as ii}from"react/jsx-runtime";function ri(e){let t=ft();return ii(en,{...t,...e})}var si=Object.assign(ri,{Trigger:en.Trigger,Content:en.Content});import{useContext as ai,useEffect as ci,useRef as di}from"react";function li(e){let t=ai(vt);if(!t)throw new Error("useConnectKitAnalytics must be used within <CrossConnectKitProvider>");let n=di(e);n.current=e;let{subscribe:i}=t;ci(()=>i(c=>n.current(c)),[i])}import{useOnRamp as uc,useOnRampEligibility as pc,OnRampProvider as mc}from"@nexus-cross/onramp/react";import{useKyc as gc,useOptionalKyc as yc,KycProvider as bc,KycError as hc,launchKycVerification as wc}from"@nexus-cross/kyc/react";import{WalletInfo as kc,ConnectorId as Tc}from"@nexus-cross/dapp-ui";import{AppLauncher as xc,AppLauncherTrigger as vc,AppLauncherContent as Pc,useGlobalMenu as Sc}from"@nexus-cross/dapp-ui";import{SkillsButton as Ac}from"@nexus-cross/dapp-ui";import{createRelayClient as _c,RelayApiError as Ec,DEFAULT_TRUSTED_FACTORIES as Oc,useRelayConfig as Nc,useRelayOrders as Wc,useRelayRecovery as Fc}from"@nexus-cross/dapp-ui";import{OnRampError as Lc}from"@nexus-cross/connect-kit-core";import{ConnectionStatus as Mc,formatBalance as Uc,formatWei as Kc}from"@nexus-cross/connect-kit-core";an();export{Be as a,ko as b,yt as c,Lt as d,Jo as e,Ct as f,Ht as g,Is as h,Bs as i,ft as j,qs as k,Zs as l,ni as m,si as n,li as o,uc as p,pc as q,mc as r,gc as s,yc as t,bc as u,hc as v,wc as w,kc as x,Tc as y,xc as z,vc as A,Pc as B,Sc as C,Ac as D,_c as E,Ec as F,Oc as G,Nc as H,Wc as I,Fc as J,Lc as K,Mc as L,Uc as M,Kc 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-PEAZQ65Y.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-PEAZQ65Y.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.4.0-beta.
|
|
3
|
+
"version": "1.4.0-beta.6",
|
|
4
4
|
"description": "React components and hooks for @nexus-cross/connect-kit wallet connection",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@nexus-cross/connect-kit-core": "1.4.0-beta.
|
|
28
|
-
"@nexus-cross/connect-kit-wagmi": "1.4.0-beta.
|
|
29
|
-
"@nexus-cross/crossx-design-system": "1.4.0-beta.
|
|
30
|
-
"@nexus-cross/
|
|
31
|
-
"@nexus-cross/
|
|
32
|
-
"@nexus-cross/onramp": "1.4.0-beta.
|
|
27
|
+
"@nexus-cross/connect-kit-core": "1.4.0-beta.6",
|
|
28
|
+
"@nexus-cross/connect-kit-wagmi": "1.4.0-beta.6",
|
|
29
|
+
"@nexus-cross/crossx-design-system": "1.4.0-beta.6",
|
|
30
|
+
"@nexus-cross/dapp-ui": "1.4.0-beta.6",
|
|
31
|
+
"@nexus-cross/kyc": "1.4.0-beta.6",
|
|
32
|
+
"@nexus-cross/onramp": "1.4.0-beta.6"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@tanstack/react-query": "^5.60.0",
|
package/dist/chunk-LFO3RMRX.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
var mt="1.4.0-beta.4";var ht="__nexusCrossAppLauncherRuntime";function fo(){if(typeof window>"u")return null;let e=window;return e[ht]??(e[ht]={mode:"dapp-ui"}),e[ht]}function go(e){if(e.scheduled)return;e.scheduled=!0;let t=()=>{if(e.scheduled=!1,e.loggedMode!==e.mode){if(e.mode==="connect-kit-react"){let n=e.connectKitVersion??mt;console.info(`[CROSSx App Launcher] connect-kit-react v${n} \uCD08\uAE30\uD654 \uC644\uB8CC (dapp-ui v${mt}, \uC0AC\uC6A9 \uBAA8\uB4DC: connect-kit)`)}else console.info(`[CROSSx App Launcher] dapp-ui v${mt} \uCD08\uAE30\uD654 \uC644\uB8CC (\uC0AC\uC6A9 \uBAA8\uB4DC: dapp-ui only)`);e.loggedMode=e.mode}};typeof queueMicrotask=="function"?queueMicrotask(t):Promise.resolve().then(t)}function sn(){let e=fo();e&&(e.mode="connect-kit-react",e.connectKitVersion=mt,go(e))}import{useCallback as _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};
|