@naculus/connect-appkit-react 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var xs=Object.create;var Ot=Object.defineProperty;var vs=Object.getOwnPropertyDescriptor;var As=Object.getOwnPropertyNames;var bs=Object.getPrototypeOf,Rs=Object.prototype.hasOwnProperty;var Ts=(e,t)=>{for(var o in t)Ot(e,o,{get:t[o],enumerable:!0})},dr=(e,t,o,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of As(t))!Rs.call(e,n)&&n!==o&&Ot(e,n,{get:()=>t[n],enumerable:!(s=vs(t,n))||s.enumerable});return e};var Be=(e,t,o)=>(o=e!=null?xs(bs(e)):{},dr(t||!e||!e.__esModule?Ot(o,"default",{value:e,enumerable:!0}):o,e)),Is=e=>dr(Ot({},"__esModule",{value:!0}),e);var Ys={};Ts(Ys,{AppkitAccordion:()=>Qo,AppkitAccountButton:()=>Xo,AppkitAlertDialog:()=>Yo,AppkitAvatar:()=>Jo,AppkitBadge:()=>Zo,AppkitButton:()=>es,AppkitCard:()=>ts,AppkitCardContent:()=>ns,AppkitCardDescription:()=>rs,AppkitCardFooter:()=>os,AppkitCardHeader:()=>ss,AppkitCardTitle:()=>as,AppkitCheckbox:()=>is,AppkitCollapsible:()=>ls,AppkitConnectButton:()=>cs,AppkitDialog:()=>us,AppkitDropdownMenu:()=>ps,AppkitInput:()=>ds,AppkitPopover:()=>ms,AppkitProgress:()=>fs,AppkitScrollArea:()=>gs,AppkitSelect:()=>hs,AppkitSeparator:()=>ys,AppkitSkeleton:()=>Cs,AppkitSwitch:()=>Ss,AppkitTabs:()=>Es,AppkitToggleGroup:()=>ws,AppkitTooltip:()=>ks,DEFAULT_EVM_CHAINS:()=>Yn,LAMPORTS_PER_SOL:()=>J.LAMPORTS_PER_SOL,PassphraseCancelledError:()=>J.PassphraseCancelledError,PassphraseGate:()=>J.PassphraseGate,SolanaRpcError:()=>J.SolanaRpcError,TokenSelector:()=>pr,TxMonitorContext:()=>Zn,WALLET_ERROR_DESCRIPTIONS:()=>cr,WALLET_ERROR_TITLES:()=>lr,Web3ConnectProvider:()=>kr,Web3Context:()=>Ft,buildDelegationPolicyMessage:()=>Jn.buildDelegationPolicyMessage,clearClient:()=>yr,createClient:()=>Dt,formatSol:()=>J.formatSol,getChainById:()=>wr,getClient:()=>Mt,getDefaultChains:()=>Bt,getLatestBlockhash:()=>J.getLatestBlockhash,getLocale:()=>Bo,getSignatureStatus:()=>J.getSignatureStatus,getSolanaBalance:()=>J.getSolanaBalance,getUserFriendlyError:()=>Ct,isRetryableError:()=>yn,parseSol:()=>J.parseSol,resetSessionKeyManager:()=>Kr,setLocale:()=>Lo,t:()=>hn,useAccount:()=>F,useBalance:()=>br,useCapabilities:()=>Kt,useChain:()=>le,useCompareCosts:()=>Gn,useConnect:()=>Tr,useCreateSessionKey:()=>Lr,useDelegate:()=>Ur,useDelegation:()=>st,useDelegationPolicy:()=>qr,useDisconnect:()=>Vr,useERC20Allowance:()=>Qr,useERC20Approve:()=>Xr,useERC20Transfer:()=>Yr,useERC20TransferSimulation:()=>to,useEmbeddedWallet:()=>jr,useExecuteCalls:()=>zt,useExecuteRoute:()=>zn,useLastTx:()=>ro,useLookupAddress:()=>ao,useNotification:()=>lo,usePassphraseGate:()=>uo,usePaymentFetch:()=>Wr,useResolveName:()=>mo,useRevokeSession:()=>Br,useRouteQuote:()=>Qn,useSIWxLogin:()=>ln,useSIWxSession:()=>ho,useSendCalls:()=>$t,useSendTransaction:()=>ut,useSendUserOperation:()=>fo,useSendWithSession:()=>Fr,useSession:()=>go,useSessionKeys:()=>Xt,useSignInWithEthereum:()=>yo,useSignInWithX:()=>ft,useSignMessage:()=>Jt,useSimulateTransfer:()=>Eo,useSiwxAuthSession:()=>wo,useSmartAccount:()=>xo,useSolanaAccount:()=>fn,useSolanaBalance:()=>bo,useSolanaRoles:()=>Io,useSolanaSessionKey:()=>_r,useSolanaTransaction:()=>Po,useSwitchChain:()=>No,useTokenBalance:()=>Oo,useTokenList:()=>Wt,useTokenSearch:()=>Nt,useTransactionSimulation:()=>nn,useTxHistory:()=>_o,useTxMonitor:()=>no,useUserOpStatus:()=>Do,useValidateDestination:()=>Ho,useViemClient:()=>ce,useWallet:()=>qo,useWeb3:()=>I,useWeb3ErrorHandler:()=>Vo,validateDestination:()=>ir});module.exports=Is(Ys);var J=require("@naculus/connect-core");var mr=require("@naculus/connect-appkit-core"),de=require("react");function Gn(e,t){let{operation:o,chains:s,options:n}=e,[u,i]=(0,de.useState)([]),[g,c]=(0,de.useState)(!1),[l,h]=(0,de.useState)(null),r=(0,de.useRef)(!0),a=(0,de.useRef)(0),p=(0,mr.compareCostsKey)(e),d=(0,de.useCallback)(async()=>{if(!s||s.length===0){i([]);return}if(!t)return;let y=++a.current;c(!0),h(null);try{let S=await t(o,s,n);r.current&&y===a.current&&i(S)}catch(S){r.current&&y===a.current&&(h(S instanceof Error?S:new Error(String(S))),i([]))}finally{r.current&&y===a.current&&c(!1)}},[p,t]);(0,de.useEffect)(()=>{d()},[d]),(0,de.useEffect)(()=>(r.current=!0,()=>{r.current=!1}),[]);let m=(0,de.useCallback)(async()=>{await d()},[d]);return{comparisons:u,loading:g,error:l,refresh:m}}var _t=require("@naculus/connect-appkit-core"),ye=require("react");function zn(e){let[t,o]=(0,ye.useState)(!1),[s,n]=(0,ye.useState)(null),[u,i]=(0,ye.useState)(null),g=(0,ye.useRef)(!0),c=(0,ye.useRef)(!1);(0,ye.useEffect)(()=>(g.current=!0,()=>{g.current=!1}),[]);let l=(0,ye.useCallback)(async(r,a,p)=>{if(!e)return i({code:"no_executor",message:"No executeRoute function provided"}),n(null),null;let d=(0,_t.validateRouteRecipient)(r,a);if(d)return i(d),n(null),null;if(c.current)return i({code:"execution_in_progress",message:"A route execution is already in progress"}),null;c.current=!0,o(!0),i(null),n(null);try{let m=await e(r,a,p);return g.current&&n(m),m}catch(m){return g.current&&i((0,_t.toExecuteRouteError)(m)),null}finally{c.current=!1,g.current&&o(!1)}},[e]),h=(0,ye.useCallback)(()=>{n(null),i(null),o(!1)},[]);return{execute:l,executing:t,result:s,error:u,reset:h}}var fr=require("@naculus/connect-appkit-core"),ie=require("react");function Qn(e,t){let{fromChain:o,toChain:s,fromToken:n,toToken:u,amount:i,options:g}=e,[c,l]=(0,ie.useState)([]),[h,r]=(0,ie.useState)(!1),[a,p]=(0,ie.useState)(null),d=(0,ie.useRef)(null),m=(0,ie.useRef)(!0),y=(0,ie.useCallback)(async()=>{if(!(0,fr.isQuotableInput)({fromChain:o,toChain:s,fromToken:n,amount:i})){l([]);return}if(t){r(!0),p(null);try{let E=await t(o,s,n,i,g,u);m.current&&l(E)}catch(E){m.current&&(p(E instanceof Error?E:new Error(String(E))),l([]))}finally{m.current&&r(!1)}}},[o,s,n,u,i,g,t]);(0,ie.useEffect)(()=>{if(d.current&&clearTimeout(d.current),!o||!s||!n||!i){l([]);return}return d.current=setTimeout(()=>{y()},300),()=>{d.current&&clearTimeout(d.current)}},[y,o,s,n,i]),(0,ie.useEffect)(()=>(m.current=!0,()=>{m.current=!1}),[]);let S=(0,ie.useCallback)(async()=>{await y()},[y]),w=(0,ie.useCallback)(()=>{l([]),p(null),r(!1)},[]);return{quotes:c,loading:h,error:a,refresh:S,clear:w}}var X=require("@naculus/connect-core"),ee=require("@naculus/connector-evm-injected"),gr=require("@naculus/connect-core"),hr=require("@naculus/connector-walletconnect"),Xn=null;function Dt(e){let t=null,o=(0,hr.createWalletConnectConnector)({projectId:e.projectId,metadata:e.metadata,...e.walletConnect?.client?{client:e.walletConnect.client}:{},...e.walletConnect?.openUrl?{openUrl:e.walletConnect.openUrl}:{}}),s=null,n=null,u=null,i=null,g=e.passphrasePrompt&&e.enableEmbedded&&!e.embeddedConfig?.encryptionPassphrase?new gr.PassphraseGate:null;e.enableEmbedded&&(n=import("@naculus/connector-embedded").then(r=>{let a={...e.embeddedConfig};g&&(a.encryptionPassphrase=g.request),e.enablePasskeys&&a.encryptionPassphrase&&!a.prfUnlock&&(a.prfUnlock={async derive(d){i&&await i;let m=u;return m?.hasCredential()?m.derivePrfKey(d):null}}),s=r.createPocketConnector(a),t?._setEmbeddedConnector(s)}).catch(r=>{X.logger.warn("react/client","Embedded wallet connector not available:",r),s=null})),e.enablePasskeys&&(i=import("@naculus/connector-passkeys").then(r=>{u=r.createPasskeysConnector(),t?._setPasskeysConnector(u)}).catch(r=>{X.logger.warn("react/client","Passkeys connector not available:",r),u=null}));let c=null,l=null;e.enableSolana&&(l=import("@naculus/connector-solana").then(r=>{let a=r.solanaConnector;e.solanaDefaultChain&&"configure"in a&&a.configure({defaultChain:e.solanaDefaultChain}),c=a,typeof window<"u"&&"startDiscovery"in a&&a.startDiscovery();for(let p of e.solanaWallets??[])a.registerWallet?.(p);t?._setSolanaConnector(c)}).catch(r=>{X.logger.warn("react/client","Solana connector not available:",r),c=null})),typeof window<"u"&&ee.eip6963Connector.startDiscovery();for(let{info:r,provider:a}of e.injectedProviders??[])ee.eip6963Connector.registerProvider(r,a);let h={connector:o,get embeddedConnector(){return s},getEmbeddedConnector:async()=>(n&&await n,s),get passkeysConnector(){return u},passphraseGate:g,solanaRpcUrl:e.solanaRpcUrl??null,get solanaConnector(){return c},connect:()=>o.connect(),connectInjected:async r=>ee.eip6963Connector.connect(r),connectEmbedded:async()=>{if(n&&await n,!s)throw new Error("Embedded wallet not enabled. Set enableEmbedded: true in config.");return s.connect()},connectPasskeys:async()=>{if(i&&await i,!u)throw new Error("Passkeys connector not enabled. Set enablePasskeys: true in config.");return u.connect()},startPairing:()=>o.startPairing(),completePairing:()=>o.completePairing(),cancelPairing:()=>o.cancelPairing?.(),signMessage:async(r,a)=>{if(r.id?.startsWith("eip6963-"))return ee.eip6963Connector.signMessage(r,a);if(r.walletType==="passkeys"&&u)return u.signMessage(r,a);if(r.walletType==="embedded"){if(!s)throw new X.WalletError("wallet_unavailable","Embedded wallet connector not available.");return s.signMessage(r,a)}if(r.walletType==="solana"){if(l&&await l,c)return c.signMessage(r,a);throw new X.WalletError("wallet_unavailable","Solana connector not available. Ensure enableSolana is true and @naculus/connector-solana is installed.")}return o.signMessage(r,a)},signTransaction:async(r,a)=>{if(r.id?.startsWith("eip6963-"))return ee.eip6963Connector.signTransaction(r,a);if(r.walletType==="embedded"){if(!s)throw new X.WalletError("wallet_unavailable","Embedded wallet connector not available.");return s.signTransaction(r,a)}if(r.walletType==="solana"){if(l&&await l,c)return c.signTransaction(r,a);throw new X.WalletError("wallet_unavailable","Solana connector not available. Ensure enableSolana is true and @naculus/connector-solana is installed.")}return o.signTransaction(r,a)},sendTransaction:async(r,a)=>{if(r.id?.startsWith("eip6963-"))return ee.eip6963Connector.sendTransaction(r,a);if(r.walletType==="passkeys"&&u)return u.sendTransaction(r,a);if(r.walletType==="embedded"){if(!s)throw new X.WalletError("wallet_unavailable","Embedded wallet connector not available.");return s.sendTransaction(r,a)}if(r.walletType==="solana"){if(l&&await l,c)return c.sendTransaction(r,a);throw new X.WalletError("wallet_unavailable","Solana connector not available. Ensure enableSolana is true and @naculus/connector-solana is installed.")}return o.sendTransaction(r,a)},onAccountsChanged:(r,a)=>{let p=()=>{};return r.id?.startsWith("eip6963-")?ee.eip6963Connector.onAccountsChanged?.(r,a)??p:r.walletType==="embedded"?s?.onAccountsChanged?.(r,a)??p:r.walletType==="passkeys"?p:r.walletType==="solana"?c?.onAccountsChanged?.(r,a)??p:o.onAccountsChanged?.(r,a)??p},onChainChanged:(r,a)=>{let p=()=>{};return r.id?.startsWith("eip6963-")?ee.eip6963Connector.onChainChanged?.(r,a)??p:r.walletType==="passkeys"||r.walletType==="embedded"?p:r.walletType==="solana"?c?.onChainChanged?.(r,a)??p:o.onChainChanged?.(r,a)??p},getCapabilities:r=>r.id?.startsWith("eip6963-")?ee.eip6963Connector.getCapabilities?.(r):r.walletType==="passkeys"?u?.getCapabilities?.(r):r.walletType==="solana"?c?.getCapabilities?.(r):r.walletType==="embedded"?s?.getCapabilities?.(r):o.getCapabilities?.(r),sendCalls:async(r,a,p,d)=>{if(r.id?.startsWith("eip6963-"))return ee.eip6963Connector.sendCalls(r,a,p,d);if(r.walletType==="passkeys"&&u)return u.sendCalls(r,a,p,d);if(r.walletType==="solana"){if(l&&await l,c)return c.sendCalls(r,a,p,d);throw new X.WalletError("wallet_unavailable","Solana connector not available. Ensure enableSolana is true and @naculus/connector-solana is installed.")}if(r.walletType==="embedded"){if(!s?.sendCalls)throw new X.WalletError("method_not_allowed","Embedded wallet does not support sendCalls");return s.sendCalls(r,a,p,d)}if(!o.sendCalls)throw new X.WalletError("method_not_allowed","sendCalls not supported by this connector");return o.sendCalls(r,a,p,d)},showCallsStatus:async(r,a)=>{if(r.id?.startsWith("eip6963-"))return ee.eip6963Connector.showCallsStatus(r,a);if(r.walletType==="passkeys"||r.walletType==="embedded")throw new X.WalletError("method_unsupported",`${r.walletType} wallets have no UI to display a call bundle.`);if(!o.showCallsStatus)throw new X.WalletError("method_unsupported","This connector cannot display call status.");return o.showCallsStatus(r,a)},getCallsStatus:async(r,a)=>{if(r.id?.startsWith("eip6963-")&&ee.eip6963Connector.getCallsStatus)return ee.eip6963Connector.getCallsStatus(r,a);if(r.walletType==="passkeys"&&u?.getCallsStatus)return u.getCallsStatus(r,a);if(r.walletType==="embedded")throw new X.WalletError("method_not_allowed","Embedded wallet does not support getCallsStatus");if(!o.getCallsStatus)throw new X.WalletError("method_not_allowed","getCallsStatus not supported by this connector");return o.getCallsStatus(r,a)},reconnect:async r=>r.walletType==="eip6963"?ee.eip6963Connector.reconnect(r):r.walletType==="embedded"?s?s.reconnect(r):r:r.walletType==="solana"?r:o.reconnect(r),disconnect:async r=>{if(r.id?.startsWith("eip6963-")||r.walletType==="eip6963")return ee.eip6963Connector.disconnect(r);if(r.walletType==="embedded"&&s)return s.disconnect();if(r.walletType==="passkeys"&&u)return u.disconnect(r);if(r.walletType==="solana"){if(l&&await l,c)return c.disconnect(r);throw new X.WalletError("wallet_unavailable","Solana connector not available. Ensure enableSolana is true and @naculus/connector-solana is installed.")}return o.disconnect(r)},getAllConnectors:()=>{let r=[o];return s&&r.push(s),u&&r.push(u),c&&r.push(c),r},_setEmbeddedConnector:r=>{s=r},_setPasskeysConnector:r=>{u=r},_setSolanaConnector:r=>{c=r}};return t=h,Xn=h,h}function Mt(){return Xn}function yr(){Xn=null}var kt=require("@naculus/connect-core"),vr=require("react");var Z=require("@naculus/connect-core"),wt=require("@naculus/connector-evm-injected"),O=require("react");var Cr=require("@naculus/connect-core"),Lt=require("@naculus/siwx");function Ze(e,t){let o=t.split(":",1)[0],n=(e.namespaces[o]?.accounts??[]).filter(u=>u.startsWith(`${o}:`)).map(u=>({namespace:o,caip10:u}))[0];if(n)return{...n,address:n.caip10.split(":").pop()??n.caip10}}function Us(e){return e.namespaces.eip155?.chains?.[0]??e.namespaces.solana?.chains?.[0]??e.namespaces.xrpl?.chains?.[0]??"eip155:1"}async function Sr(e){let{session:t,siwx:o,signMessage:s}=e;if(!o||!t)return{kind:"skipped"};try{let n=Us(t),u=Ze(t,n);if(!u)throw new Error("No account found in session");let{address:i}=u,g=await o.createMessage({address:i,chainId:n}),c=(0,Lt.parseSiwxMessage)(g);if(!c?.nonce)throw new Error("SIWx message must contain a nonce");await(0,Lt.issueNonce)(c.nonce);let l=await s(t,{message:g,address:i,chainId:n});return await o.handleSignComplete?.({message:g,signature:l}),{kind:"authenticated",address:i,chainId:n}}catch(n){let u=n instanceof Error?n:new Error("Wallet authentication failed");return Cr.logger.error("appkit/core","SIWx authentication failed:",n),{kind:"failed",error:u,fatal:o.required!==!1}}}var Me=require("@naculus/connect-appkit-core");var Er=require("@naculus/connect-appkit-core"),xe=require("@naculus/connect-core"),Ps=[{caip2:"eip155:5",name:"Goerli",rpcUrl:"https://goerli.blockpi.network/v1/rpc/public",explorerUrl:"https://goerli.etherscan.io",token:"ETH"},{caip2:"eip155:80001",name:"Mumbai",rpcUrl:"https://rpc-mumbai.maticvigil.com",explorerUrl:"https://mumbai.polygonscan.com",token:"MATIC"},{caip2:"eip155:421613",name:"Arbitrum Goerli",rpcUrl:"https://goerli-rollup.arbitrum.io/rpc",explorerUrl:"https://goerli.arbiscan.io",token:"ETH"},{caip2:"eip155:420",name:"Optimism Goerli",rpcUrl:"https://goerli.optimism.io",explorerUrl:"https://goerli-optimism.etherscan.io",token:"ETH"}];function Ws(e){let t=xe.CHAINS[e];if(!t||!t.explorerUrl)return null;let o=t.caip2Id;return{caip2:o,name:t.name,rpcUrl:(0,xe.getRpcUrl)(o,xe.DEFAULT_RPC_URLS[o]??""),explorerUrl:t.explorerUrl,token:t.nativeCurrency.symbol}}function Ns(){if(!xe.CHAINS)return[];let e=[],t=Object.keys(xe.CHAINS).map(Number).sort((o,s)=>o-s);for(let o of t){let s=Ws(o);s&&e.push(s)}for(let o of Ps){let s=(0,xe.eip155Reference)(o.caip2);(s===null||!xe.CHAINS[s])&&e.push(o)}return e}var Yn=Ns();function wr(e,t){return(0,Er.resolveChain)(e,t)??void 0}function Bt(){return[...Yn]}var xr=require("react/jsx-runtime"),Ft=(0,O.createContext)(null);function kr({children:e,config:t,autoConnect:o=!0}){let[s,n]=(0,O.useReducer)(Me.web3Reducer,Me.initialWeb3State),u=(0,O.useMemo)(()=>t.chains??Bt(),[t.chains]),i=t.connectionTimeout??3e4,g=t.maxRetries??2,c=(0,O.useMemo)(()=>t.sessionStorage??new Z.LocalStorageSessionStorage(t.storageKey??"naculus_web3_session",t.encryptionKey),[t.sessionStorage,t.storageKey,t.encryptionKey]),l=(0,O.useMemo)(()=>Dt({projectId:t.projectId,metadata:t.metadata,enableEmbedded:t.enableEmbedded,embeddedConfig:t.embeddedConfig,enablePasskeys:t.enablePasskeys,enableSolana:t.enableSolana,solanaDefaultChain:t.solanaDefaultChain,walletConnect:t.walletConnect,solanaWallets:t.solanaWallets,injectedProviders:t.injectedProviders}),[t.projectId,t.metadata,t.enableEmbedded,t.embeddedConfig,t.enablePasskeys,t.enableSolana,t.solanaDefaultChain,t.walletConnect,t.solanaWallets,t.injectedProviders]),h=(0,O.useRef)(null),r=(0,O.useRef)(null),a=(0,O.useMemo)(()=>{let f=(0,Z.createConnectorManager)();for(let N of[wt.eip6963Connector,...l.getAllConnectors()])f.register(N.id,N);let C={},k={};for(let N of u){let q=N.caip2;N.rpcUrl&&(C[q]=N.rpcUrl),N.token&&(k[q]={name:N.name,symbol:N.token,decimals:18})}let U=(0,Z.createSessionManager)(f,{autoRefreshFeeOnSwitch:t.autoRefreshFeeOnSwitch??!0,defaultRpcUrls:C,defaultCurrencies:k,encryptionKey:t.encryptionKey});return h.current=U,U},[l,u,t.autoRefreshFeeOnSwitch,t.encryptionKey]);(0,O.useEffect)(()=>{let f=q=>{let{walletSession:qe}=q.bundle;n({type:"SET_SESSION",payload:qe});let pe=[];Object.values(qe.namespaces).forEach(Et=>{pe.push(...Et.accounts)}),n({type:"SET_ACCOUNTS",payload:pe}),n({type:"SET_CHAIN",payload:q.bundle.activeChainId}),n({type:"SET_STATUS",payload:"connected"})},C=()=>{n({type:"RESET"})},k=q=>{n({type:"SET_CHAIN",payload:q.newChainId})},U=q=>f(q),N=()=>{c.clear(),n({type:"RESET"})};return a.on("sessionConnected",f),a.on("sessionDisconnected",C),a.on("chainChanged",k),a.on("sessionScopeChanged",U),a.on("sessionRevoked",N),()=>{a.off("sessionConnected",f),a.off("sessionDisconnected",C),a.off("chainChanged",k),a.off("sessionScopeChanged",U),a.off("sessionRevoked",N)}},[a,c]),(0,O.useEffect)(()=>{let f=()=>{c.clear(),n({type:"RESET"})};l.connector.onSessionExpiry(f)},[l,c]);let p=(0,O.useCallback)(()=>{for(let f of[wt.eip6963Connector,...l.getAllConnectors()])a.registerConnector(f)},[l,a]),d=(0,O.useCallback)(async f=>{p();let C=[wt.eip6963Connector,...l.getAllConnectors()].find(U=>U.id===f.walletType||U.kind===f.walletType);C&&!f.connectorId&&(f.connectorId=C.id);let k=f.namespaces.eip155?.chains?.[0]??f.namespaces.solana?.chains?.[0]??f.namespaces.xrpl?.chains?.[0];k&&await a.attach(f,k)},[l,a,p]),m=(0,O.useCallback)(f=>{if(n({type:"SET_SESSION",payload:f}),f){let C=[];Object.values(f.namespaces).forEach(q=>{C.push(...q.accounts)}),n({type:"SET_ACCOUNTS",payload:C});let k=f.namespaces.eip155?.chains?.[0],U=f.namespaces.solana?.chains?.[0],N=f.namespaces.xrpl?.chains?.[0];n({type:"SET_CHAIN",payload:k??U??N??null})}else n({type:"SET_ACCOUNTS",payload:[]}),n({type:"SET_CHAIN",payload:null})},[]);(0,O.useEffect)(()=>{let f=s.session,C=l;return!f||!C?.onAccountsChanged?void 0:C.onAccountsChanged(f,U=>{if(U.length===0){c.clear().finally(()=>n({type:"RESET"}));return}m(f),c.save(f)})},[s.session,l,c,m]),(0,O.useEffect)(()=>{let f=s.session,C=l;if(!(!f||!C?.onChainChanged))return C.onChainChanged(f,k=>{m(f),c.save(f);let U=a.syncExternalChain;if(!U)return;let N=U.call(a,k).catch(q=>{Z.logger.warn("react/provider","External chain sync error:",q)});r.current=N,N.finally(()=>{r.current===N&&(r.current=null)})})},[s.session,l,c,m,a]);let y=(0,O.useCallback)(async f=>{if(!t.siwx||!f)return!0;n({type:"SET_STATUS",payload:"authenticating"});let C=await Sr({session:f,siwx:t.siwx,signMessage:(k,U)=>l.signMessage(k,U)});return C.kind==="failed"&&C.fatal?(await c.clear(),n({type:"RESET"}),n({type:"SET_ERROR",payload:C.error}),!1):!0},[t.siwx,l,c]),S=(0,O.useCallback)(async()=>{n({type:"SET_STATUS",payload:"connecting"}),n({type:"SET_ERROR",payload:null});try{let f=await(0,Me.withTimeout)(l.connect(),i,"Wallet connect");await c.save(f),m(f);try{await d(f)}catch(C){Z.logger.warn("react/provider","SessionManager sync error:",C)}if(!await y(f))return;n({type:"SET_STATUS",payload:"connected"})}catch(f){let C=f instanceof Error?f.message:"Connection failed";n({type:"SET_ERROR",payload:f instanceof Error?f:new Error(C)}),n({type:"SET_STATUS",payload:"disconnected"})}},[l,c,m,i,y,d]),w=(0,O.useCallback)(async()=>{n({type:"SET_STATUS",payload:"connecting"}),n({type:"SET_ERROR",payload:null});try{let f=await l.connectEmbedded();if(await c.save(f),m(f),await d(f),!await y(f))return;n({type:"SET_STATUS",payload:"connected"})}catch(f){let C=f instanceof Error?f.message:"Embedded wallet connection failed";n({type:"SET_ERROR",payload:f instanceof Error?f:new Error(C)}),n({type:"SET_STATUS",payload:"disconnected"})}},[l,c,m,y,d]),E=(0,O.useCallback)(async()=>{n({type:"SET_STATUS",payload:"connecting"}),n({type:"SET_ERROR",payload:null});try{let f=await l.connectPasskeys();if(await c.save(f),m(f),await d(f),!await y(f))return;n({type:"SET_STATUS",payload:"connected"})}catch(f){let C=f instanceof Error?f.message:"Passkeys connection failed";n({type:"SET_ERROR",payload:f instanceof Error?f:new Error(C)}),n({type:"SET_STATUS",payload:"disconnected"})}},[l,c,m,y,d]),A=(0,O.useCallback)(async()=>{if(!s.session){n({type:"RESET"});return}try{await l.disconnect(s.session)}catch(f){Z.logger.error("react/provider","Disconnect error:",f)}try{let f=h.current;f&&await f.disconnect()}catch(f){Z.logger.warn("react/provider","SessionManager disconnect error:",f)}await c.clear(),n({type:"RESET"})},[l,s.session,c]),R=(0,O.useCallback)(async f=>{n({type:"SET_STATUS",payload:"connecting"}),n({type:"SET_ERROR",payload:null});try{let C=await(0,Me.withTimeout)(l.connectInjected(f),i,"Injected wallet connect");await c.save(C),m(C);try{await d(C)}catch(k){Z.logger.warn("react/provider","SessionManager sync error:",k)}if(!await y(C))return;n({type:"SET_STATUS",payload:"connected"})}catch(C){let k=C instanceof Error?C.message:"Connection failed";n({type:"SET_ERROR",payload:C instanceof Error?C:new Error(k)}),n({type:"SET_STATUS",payload:"disconnected"})}},[l,c,m,i,y,d]),x=(0,O.useCallback)(async()=>l.startPairing(),[l]),T=(0,O.useCallback)(()=>{l.cancelPairing?.()},[l]),v=(0,O.useCallback)(async()=>{let f=await l.completePairing();return await c.save(f),m(f),await d(f),await y(f)&&n({type:"SET_STATUS",payload:"connected"}),f},[l,c,m,y,d]),b=(0,O.useCallback)(async f=>{let C=t.siwx;if(!C||C.required===!1)return!0;try{if(await C.hasValidSession?.())return!0}catch(k){Z.logger.warn("react/provider","siwx.hasValidSession failed",k)}return y(f)},[t.siwx,y]),P=(0,O.useCallback)(async()=>{let f=await c.load();if(!f){n({type:"SET_STATUS",payload:"disconnected"});return}n({type:"SET_STATUS",payload:"reconnecting"});try{let C=await(0,Me.withRetry)(()=>l.reconnect(f),{maxRetries:g,baseDelay:1e3,label:"reconnect"});m(C);try{let k=h.current;k&&(p(),await k.restoreFromPersistence())}catch(k){Z.logger.warn("react/provider","SessionManager restore error:",k)}if(!await b(C))return;n({type:"SET_STATUS",payload:"connected"})}catch(C){Z.logger.error("react/provider","Reconnect error:",C),await c.clear(),n({type:"SET_STATUS",payload:"disconnected"}),n({type:"SET_SESSION",payload:null})}},[l,c,m,g,p,b]),W=(0,O.useCallback)(async f=>{r.current&&await r.current;let C=h.current;if(C?.getActiveBundle()){await C.switchChain(f),m(s.session);return}if(!s.session)throw new Error("No active session");try{s.session.walletType==="eip6963"||s.session.id?.startsWith("eip6963-")?await wt.eip6963Connector.switchChain(s.session,f):s.session.walletType==="embedded"&&l.embeddedConnector?await l.embeddedConnector.switchChain?.(s.session,f):s.session.walletType==="passkeys"&&l.passkeysConnector?await l.passkeysConnector.switchChain?.(s.session,f):s.session.walletType==="solana"&&l.solanaConnector?await l.solanaConnector.switchChain?.(s.session,f):await l.connector.switchChain(s.session,f),m(s.session)}catch(k){throw new Z.WalletError("chain_unsupported","Failed to switch chain",k)}},[l,s.session,m]);(0,O.useEffect)(()=>{o&&P()},[o,P]);let B=(0,O.useCallback)(()=>{n({type:"SET_ERROR",payload:null})},[]),V=(0,O.useMemo)(()=>({...s,connect:S,connectEmbedded:w,connectPasskeys:E,disconnect:A,reconnect:P,switchChain:W,startPairing:x,completePairing:v,cancelPairing:T,connectInjected:R,clearError:B,isConnected:s.status==="connected",chains:u,client:l,sessionManager:a}),[s,S,w,E,A,P,W,x,v,T,R,B,u,l,a]);return(0,xr.jsx)(Ft.Provider,{value:V,children:e})}function I(){let e=(0,O.useContext)(Ft);if(!e)throw new Error("useWeb3 must be used within a Web3ConnectProvider");return e}function F(){let{accounts:e,isConnected:t}=I(),o=(0,vr.useMemo)(()=>!t||e.length===0?null:e.map(n=>{let u=(0,kt.parseCaip10)(n);return u?{address:n,namespace:u.namespace,isEVM:u.namespace==="eip155"&&(0,kt.isEvmAddress)(u.address)}:{address:n,namespace:null,isEVM:(0,kt.isEvmAddress)(n)}}),[e,t]),s=o?.find(n=>n.isEVM)?.address??null;return{accounts:o,evmAccount:s,primaryAccount:e[0]??null,isConnected:t,count:e.length}}var et=require("@naculus/connect-appkit-core"),z=require("react");var tt=require("viem"),Ar=require("@naculus/connect-core");function br(e){let{evmAccount:t,isConnected:o}=F(),{chainId:s,chains:n}=I(),[u,i]=(0,z.useState)(null),[g,c]=(0,z.useState)(!1),[l,h]=(0,z.useState)(null),[r,a]=(0,z.useState)(null),p=e?.refreshInterval,d=(0,z.useRef)(null),m=(0,z.useMemo)(()=>(0,et.resolveChain)(n,s),[s,n]),y=m?(0,et.chainNumber)(m):null,S=(0,z.useMemo)(()=>m?(0,et.toViemChain)(m,y):null,[m,y]),w=(0,z.useMemo)(()=>m?.token??null,[m]),[E,A]=(0,z.useState)(null);(0,z.useEffect)(()=>{if(!S||!m?.rpcUrl){A(null);return}let v=(0,tt.createPublicClient)({transport:(0,tt.http)(m.rpcUrl),chain:S});return A(v),()=>{}},[m,S]);let R=(0,z.useCallback)(async()=>{if(!t||!E){i(null);return}c(!0),h(null);try{let b=t.includes(":")?t.split(":").pop():t,[P,W]=await Promise.all([E.getBalance({address:b}),s?(0,Ar.getNativeTokenPriceUsd)(s,m?.rpcUrl).catch(()=>null):Promise.resolve(null)]);i(P.toString()),a(W)}catch(v){h(v instanceof Error?v:new Error("Failed to fetch balance")),i(null),a(null)}finally{c(!1)}},[t,E,s,m?.rpcUrl]);(0,z.useEffect)(()=>{o&&t&&R()},[o,t,R]),(0,z.useEffect)(()=>(p&&p>0&&o&&t&&(d.current=setInterval(R,p)),()=>{d.current&&(clearInterval(d.current),d.current=null)}),[p,o,t,R]);let x=(0,z.useMemo)(()=>{if(u===null)return null;try{return(0,tt.formatEther)(BigInt(u))}catch{return null}},[u]),T=(0,z.useMemo)(()=>{if(r===null||x===null)return null;let v=parseFloat(x);if(Number.isNaN(v))return null;let b=v*r;return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(b)},[r,x]);return{balance:u,formatted:x,symbol:w,usdPrice:r,usdValue:T,isLoading:g,error:l,refetch:R,chain:m}}var nt=require("@naculus/connect-appkit-core"),Te=require("react");function _(e){return e??Mt()}function Kt(){let{client:e,session:t,chainId:o}=I(),[s,n]=(0,Te.useState)(null),[u,i]=(0,Te.useState)(!1),[g,c]=(0,Te.useState)(null),l=(0,Te.useRef)(0),h=(0,Te.useCallback)(async()=>{let r=++l.current,a=_(e);if(!a?.getCapabilities||!t){n(null),i(!1),c(null);return}i(!0),c(null);try{let p=await a.getCapabilities(t);if(r!==l.current)return;n((0,nt.normalizeCapabilities)(p))}catch(p){if(r!==l.current)return;n(null),c(p instanceof Error?p:new Error("Capability query failed"))}finally{r===l.current&&i(!1)}},[e,t]);return(0,Te.useEffect)(()=>{h()},[h]),{capabilities:s,current:(0,nt.selectChainCapabilities)(s,o),atomic:(0,nt.atomicSupportFor)(s,o),isFetching:u,error:g,refetch:h}}var Ht=require("react"),rt=require("@naculus/connect-appkit-core");function le(){let{chainId:e,session:t,switchChain:o,chains:s}=I(),n=(0,Ht.useMemo)(()=>(0,rt.resolveChain)(s,e),[s,e]),u=(0,Ht.useMemo)(()=>t?(0,rt.describeChain)(s,e):null,[s,e,t]),i=(0,Ht.useMemo)(()=>(0,rt.chainsForNamespace)(s,e),[s,e]);return{chainId:e,currentChain:n,chainInfo:u,availableChains:i,chains:i,isEvm:e?.startsWith("eip155:")??!1,switchChain:o}}var xt=require("react");var Rr=require("@naculus/connect-core");function Tr(){let{connect:e,status:t}=I(),[o,s]=(0,xt.useState)(!1),[n,u]=(0,xt.useState)(null);return{connect:(0,xt.useCallback)(async()=>{s(!0),u(null);try{await e()}catch(g){let c=g instanceof Error?g.message:"Connection failed";u(g instanceof Rr.WalletError?g:new Error(c))}finally{s(!1)}},[e]),isConnecting:o||t==="connecting",error:n}}var Ir=require("@naculus/connect-appkit-core"),Le=require("@naculus/connect-core"),te=require("react");var Vt=require("@naculus/connect-appkit-core"),qt=require("react"),Ve=require("viem");function ce(){let{evmAccount:e,isConnected:t}=F(),{currentChain:o,chains:s}=le(),n=o?(0,Vt.chainNumber)(o):null,u=(0,qt.useMemo)(()=>o?(0,Vt.toViemChain)(o,n):null,[o,n]),i=(0,qt.useMemo)(()=>u?(0,Ve.createPublicClient)({transport:(0,Ve.http)(u.rpcUrls.default.http[0]),chain:u}):null,[u]),g=(0,qt.useMemo)(()=>{if(!t||!e||!u)return null;let c=e.includes(":")?e.split(":").pop():e;return(0,Ve.createWalletClient)({transport:(0,Ve.http)(u.rpcUrls.default.http[0]),chain:u,account:c})},[t,e,u]);return{publicClient:i,walletClient:g,chains:s}}function Ur(e){let{evmAccount:t}=F(),{session:o,chainId:s,client:n}=I(),{publicClient:u}=ce(),[i,g]=(0,te.useState)(null),[c,l]=(0,te.useState)(!1),[h,r]=(0,te.useState)(null),a=(0,te.useRef)(0),p=(0,te.useRef)(!1);(0,te.useEffect)(()=>()=>{a.current+=1},[]),(0,te.useEffect)(()=>{a.current+=1,g(null),l(!1),r(null)},[o,s,t]);let d=(0,te.useCallback)(async(w,E)=>{let A=v=>(r(v),null);if(p.current)return A(new Error("A delegation is already in progress"));let R=(0,Ir.bareEvmAddress)(t);if(!o||!R||!s)return A(new Le.WalletError("wallet_unavailable","No connected EVM account"));if(!u||u.chain?.id!==(0,Le.eip155Reference)(s))return A(new Le.WalletError("chain_mismatch",`No RPC client for ${s}; refusing to read the nonce elsewhere.`));let x=o.walletType==="embedded"?_(n)?.embeddedConnector??{}:{},T=++a.current;p.current=!0,l(!0),r(null),g(null);try{let v=await(0,Le.delegateAccount)({connector:x,session:o,account:R,chainId:s,delegate:w,allowlist:E,getTransactionCount:(b,P)=>u.getTransactionCount({address:b,blockTag:P})});return T!==a.current?null:(g(v),v)}catch(v){return T!==a.current?null:A(v instanceof Error?v:new Error("Failed to send delegation"))}finally{p.current=!1,T===a.current&&l(!1)}},[s,n,t,u,o]),m=(0,te.useCallback)(w=>d(w,e.allowlist),[d,e.allowlist]),y=(0,te.useCallback)(()=>d(Le.REVOKE_DELEGATE,[]),[d]),S=(0,te.useCallback)(()=>{a.current+=1,g(null),l(!1),r(null)},[]);return{delegate:m,revoke:y,result:i,isPending:c,error:h,reset:S}}var Pr=require("@naculus/connect-appkit-core"),me=require("react");function Wr(e){let[t,o]=(0,me.useState)(0),[s,n]=(0,me.useState)(null),[u,i]=(0,me.useState)(null),g=(0,me.useRef)(0),c=(0,me.useRef)(0),l=(0,me.useRef)(e);l.current=e,(0,me.useEffect)(()=>()=>{g.current+=1,c.current+=1},[]);let h=(0,me.useCallback)(async(a,p)=>{let d=++g.current,m=c.current;o(y=>y+1),i(null);try{let y=await l.current(a,p),S=(0,Pr.describePayment)(a,y);return S&&m===c.current&&n(S),y}catch(y){let S=y instanceof Error?y:new Error("Paid request failed");throw d===g.current&&i(S),S}finally{o(y=>y-1)}},[]),r=(0,me.useCallback)(()=>{g.current+=1,c.current+=1,n(null),i(null)},[]);return{payFetch:h,isPending:t>0,lastPayment:s,error:u,reset:r}}var Or=require("@naculus/connect-appkit-core"),ne=require("react");function Nr(){return Promise.reject(new Error("No Solana session key manager is connected"))}function _r(e){let[t,o]=(0,ne.useState)([]),[s,n]=(0,ne.useState)(0),[u,i]=(0,ne.useState)(null),g=(0,ne.useRef)(0),c=e?.manager,l=e?.rpc,h=e?.owner,r=(0,ne.useMemo)(()=>c&&l&&h?(0,Or.createSolanaSessionKeyFlow)({manager:c,rpc:l,owner:h}):null,[c,l,h]),a=(0,ne.useCallback)(async(y,S)=>{let w=++g.current;n(E=>E+1),i(null);try{return await y()}catch(E){let A=E instanceof Error?E:new Error(S);throw w===g.current&&i(A),A}finally{if(r&&w===g.current){let E=await r.list().catch(()=>null);E&&w===g.current&&o(E)}n(E=>E-1)}},[r]),p=(0,ne.useCallback)(async()=>{if(!r){o([]);return}let y=g.current,S=await r.list();y===g.current&&o(S)},[r]);(0,ne.useEffect)(()=>(g.current+=1,p().catch(()=>{}),()=>{g.current+=1}),[p]);let d=(0,ne.useCallback)(y=>r?a(()=>r.create(y),"Could not create the key"):Nr(),[r,a]),m=(0,ne.useCallback)(y=>r?a(()=>r.revoke(y),"Could not revoke the key"):Nr(),[r,a]);return{keys:t,create:d,revoke:m,refresh:p,isPending:s>0,error:u}}var ot=require("@naculus/connect-core"),Ie=require("react");function st(){let{publicClient:e}=ce(),{evmAccount:t}=F(),[o,s]=(0,Ie.useState)(ot.UNKNOWN_DELEGATION),[n,u]=(0,Ie.useState)(!1),[i,g]=(0,Ie.useState)(null),c=(0,Ie.useRef)(0),l=t?.includes(":")?t.split(":").pop():t,h=(0,Ie.useCallback)(async()=>{let r=++c.current;if(!e||!l){s(ot.UNKNOWN_DELEGATION),u(!1),g(null);return}u(!0),g(null);try{let a=await e.getCode({address:l});if(r!==c.current)return;s((0,ot.readDelegation)(a??"0x"))}catch(a){if(r!==c.current)return;s(ot.UNKNOWN_DELEGATION),g(a instanceof Error?a:new Error("Code read failed"))}finally{r===c.current&&u(!1)}},[e,l]);return(0,Ie.useEffect)(()=>{h()},[h]),{...o,isFetching:n,error:i,refetch:h}}var it=require("@naculus/connect-appkit-core"),re=require("react"),Hr=require("viem");var Gt=require("@naculus/connect-core");var je=require("react");var fe=require("@naculus/connect-core"),ve=require("react");var Dr=require("@naculus/connect-core");function jt(e){let t=typeof e=="string"?e:e&&typeof e=="object"&&"hash"in e?e.hash:void 0;if(typeof t=="string"&&/^0x[0-9a-fA-F]{64}$/.test(t))return t;throw new Dr.WalletError("tx_failed","Wallet did not return a valid 32-byte transaction hash")}function $t(){let{session:e,chainId:t,client:o}=I(),[s,n]=(0,ve.useState)("idle"),[u,i]=(0,ve.useState)(null),[g,c]=(0,ve.useState)(null),[l,h]=(0,ve.useState)(null),[r,a]=(0,ve.useState)(null),p=(0,ve.useCallback)(async(S,w)=>{if(!e){n("failed");let E=new fe.WalletError("wallet_unavailable","No active session");throw i(E),E}if(S.length===0){n("failed");let E=new fe.WalletError("invalid_input","At least one call is required");throw i(E),E}n("awaiting_approval"),i(null),c(null);try{let E=_(o);if(!E)throw new fe.WalletError("wallet_unavailable","Client not initialized");let A=w?.chainId??t??void 0,R=w?.strategy??(0,fe.chooseExecutionStrategy)(await(0,fe.getAccountCapabilities)(E,e,A),S.length);if(a(R),R==="atomic-batch"){let T=await E.sendCalls(e,S,A,{atomicRequired:!0,...w?.paymasterService?{paymasterService:w.paymasterService}:{}});return n("submitted"),c(T),T}let x="";for(let T=0;T<S.length;T++){let v=S[T];try{x=jt(await E.sendTransaction(e,{transaction:{to:v.to,data:v.data,value:v.value},chainId:A}))}catch(b){throw new fe.WalletError("tx_failed",`Call ${T+1} of ${S.length} failed after ${T} already landed (sent sequentially \u2014 this wallet cannot batch atomically): ${b instanceof Error?b.message:String(b)}`)}}return n("submitted"),c(x),x}catch(E){n("failed");let A=E instanceof Error?E.message:"sendCalls failed";throw i(E instanceof Error?E:new Error(A)),E}},[e,t,o]),d=(0,ve.useCallback)(async S=>{if(!e)throw new fe.WalletError("wallet_unavailable","No active session");let w=S??g;if(!w)throw new fe.WalletError("invalid_input","No bundle hash available");if(!S&&r==="sequential")throw new fe.WalletError("invalid_input","Calls were sent sequentially, so there is no bundle to query. Track the returned transaction hash instead.");let E=_(o);if(!E)throw new fe.WalletError("wallet_unavailable","Client not initialized");let A=await E.getCallsStatus(e,w);return h(A),A},[e,g,o,r]),m=(0,ve.useCallback)(async S=>{if(!e)return!1;let w=S??g;if(!w||!S&&r==="sequential")return!1;let E=_(o);if(!E?.showCallsStatus)return!1;try{return await E.showCallsStatus(e,w),!0}catch{return!1}},[e,g,o,r]),y=(0,ve.useCallback)(()=>{n("idle"),i(null),c(null),h(null),a(null)},[]);return{sendCalls:p,getCallsStatus:d,showCallsStatus:m,status:s,error:u,batchHash:g,callsStatus:l,execution:r,reset:y,isSending:s==="awaiting_approval"}}function zt(e={}){let{current:t,atomic:o}=Kt(),{delegated:s,delegate:n}=st(),{sendCalls:u}=$t(),[i,g]=(0,je.useState)(!1),[c,l]=(0,je.useState)(null),[h,r]=(0,je.useState)(null),a=e.atomicity??"preferred",p=e.sponsorship??"any",d=e.paymasterService,m=e.userOperation,y=e.userOperationSponsored??!1,S=!!(t?.raw?.paymasterService?.supported&&d),w=(0,je.useCallback)((A,R=a)=>{let x=(0,Gt.planExecution)({atomicBatch:o==="supported",discovered:o!=="unknown",sponsoredTransactions:!1,...t?.maxBatchSize===void 0?{}:{maxBatchSize:t.maxBatchSize}},A,{atomicity:R,sponsorship:p}),T=p==="required"&&!y;if(x.strategy==="atomic-batch"&&!T)return{...x,reason:x.reason+(S?" A paymaster service will be requested, but the wallet's final fee payer must be checked after execution.":""),route:"wallet-batch"};let v=s&&o!=="supported"?` This account does delegate to ${n} under EIP-7702, so it is capable of batching even though the wallet has not offered to.`:"",b=R!=="any"&&!x.atomic||p==="required";return m&&b&&!T?{strategy:"atomic-batch",atomic:!0,sponsored:y,reason:p==="required"&&!x.sponsored?"The wallet batch is not configured for sponsored gas, so the calls are executed through the configured sponsored UserOperation route.":"This wallet cannot batch, so the calls are executed as a single UserOperation through the smart account, which lands as one transaction.",route:"user-operation"}:T?{strategy:"refuse",atomic:x.atomic,sponsored:!1,reason:"Sponsored gas was required, but there is no executable sponsored route: no paymaster is configured for a wallet batch, and capability advertising alone cannot pay for a sequential transaction.",route:null}:x.strategy==="refuse"?{...x,reason:x.reason+v,route:null}:{...x,reason:x.reason+v,route:"sequential"}},[o,t,S,m,y,a,p,s,n]),E=(0,je.useCallback)(async(A,R=a)=>{g(!0),l(null);try{let x=w(A.length,R);if(x.route===null)throw new Gt.WalletError("method_not_allowed",x.reason);return r(x.route),x.route==="user-operation"?await m(A):await u(A,{strategy:x.route==="wallet-batch"?"atomic-batch":"sequential",...x.route==="wallet-batch"&&S?{paymasterService:d}:{}})}catch(x){let T=x instanceof Error?x:new Error("Execution failed");throw l(T),T}finally{g(!1)}},[w,u,m,a,d,S]);return{preview:w,execute:E,isExecuting:i,error:c,lastRoute:h,reset:()=>{l(null),r(null)}}}var Qt=require("@naculus/connect-appkit-core"),Mr=require("@naculus/connect-core"),K=require("react");function at(e){return(0,Qt.getSharedSessionKeyManager)(e)}function Xt(e){let{session:t}=I(),[o,s]=(0,K.useState)([]),[n,u]=(0,K.useState)(!1),[i,g]=(0,K.useState)(null),c=(0,K.useRef)(!0),l=(0,K.useCallback)(()=>g(null),[]),h=at(e),r=h.isStorageAvailable(),a=(0,K.useCallback)(async()=>{if(!t){s([]);return}u(!0),g(null);try{let d=await h.listSessions();c.current&&s(d)}catch(d){c.current&&g(d instanceof Error?d:new Error("Failed to load session keys"))}finally{c.current&&u(!1)}},[t,h]);(0,K.useEffect)(()=>(c.current=!0,a(),()=>{c.current=!1}),[a]);let p=o.filter(d=>d.status==="active");return{sessions:o,activeSessions:p,loading:n,error:i,refresh:a,clearError:l,storageAvailable:r}}function Lr(e){let{session:t}=I(),[o,s]=(0,K.useState)(null),[n,u]=(0,K.useState)(!1),[i,g]=(0,K.useState)(null),c=(0,K.useCallback)(()=>g(null),[]),l=at(e);return{createSessionKey:(0,K.useCallback)(async(r,a)=>{if(!t)throw new Mr.WalletError("wallet_unavailable","No active wallet session");u(!0),g(null);try{let p=a??void 0,d=await l.createSessionKey(r,p);return s(d),d}catch(p){let d=p instanceof Error?p:new Error("Failed to create session key");throw g(d),d}finally{u(!1)}},[t,l]),lastCreated:o,isCreating:n,error:i,clearError:c}}function Br(e){let[t,o]=(0,K.useState)(!1),[s,n]=(0,K.useState)(null),u=(0,K.useCallback)(()=>n(null),[]),i=at(e);return{revokeSession:(0,K.useCallback)(async c=>{o(!0),n(null);try{await i.revokeSession(c)}catch(l){let h=l instanceof Error?l:new Error("Failed to revoke session key");throw n(h),h}finally{o(!1)}},[i]),isRevoking:t,error:s,clearError:u}}function Fr(e){let[t,o]=(0,K.useState)(!1),[s,n]=(0,K.useState)(null),u=(0,K.useCallback)(()=>n(null),[]),i=at(e),g=(0,K.useCallback)(async(l,h,r)=>{o(!0),n(null);try{return await i.signWithSessionKey(l,h,r)}catch(a){let p=a instanceof Error?a:new Error("Failed to sign with session key");throw n(p),p}finally{o(!1)}},[i]),c=(0,K.useCallback)(async(l,h)=>{o(!0),n(null);try{return await i.checkSessionScope(l,h)}catch(r){let a=r instanceof Error?r:new Error("Failed to check session scope");throw n(a),a}finally{o(!1)}},[i]);return{signWithSession:g,checkScope:c,isBusy:t,error:s,clearError:u}}function Kr(){(0,Qt.resetSharedSessionKeyManager)()}var vt=require("react");var Yt=require("@naculus/connect-core");function Jt(){let{session:e,chainId:t,client:o}=I(),[s,n]=(0,vt.useState)(!1),[u,i]=(0,vt.useState)(null);return{signMessage:(0,vt.useCallback)(async c=>{if(!e){let h=new Yt.WalletError("wallet_unavailable","No active session");throw i(h),h}let l=e.namespaces.eip155?.accounts[0]??Object.values(e.namespaces)[0]?.accounts[0];if(!l){let h=new Yt.WalletError("wallet_unavailable","No account found");throw i(h),h}n(!0),i(null);try{let h=_(o);if(!h)throw new Yt.WalletError("wallet_unavailable","Client not initialized");return await h.signMessage(e,{message:c,address:l,chainId:t??void 0})}catch(h){let r=h instanceof Error?h.message:"Signing failed",a=h instanceof Error?h:new Error(r);throw i(a),a}finally{n(!1)}},[e,t,o]),isSigning:s,error:u}}var Jn=require("@naculus/connect-appkit-core");function qr(e={}){let{evmAccount:t}=F(),o=(0,it.bareEvmAddress)(t),s=st(),n=zt(e.execution),{signMessage:u}=Jt(),i=Xt(e.managerConfig),g=at(e.managerConfig),[c,l]=(0,re.useState)(!1),[h,r]=(0,re.useState)(null),[a,p]=(0,re.useState)(()=>new Set),[d,m]=(0,re.useState)(!1),y=e.origin??(typeof window<"u"?window.location.origin:"unknown"),S=!!e.managerConfig?.encryptionKey,w=e.execution?.sponsorship,{refresh:E,storageAvailable:A}=i,{preview:R}=n,{delegated:x,delegate:T}=s,v=(0,re.useMemo)(()=>(0,it.createDelegationPolicyFlow)({manager:g,origin:y,signer:()=>o,signMessage:u,verifySignature:async({message:C,signature:k,signerAddress:U})=>(await(0,Hr.recoverMessageAddress)({message:C,signature:k})).toLowerCase()===U.toLowerCase(),previewExecution:R,sponsorship:w,adapter:e.adapter,signTypedData:e.signTypedData,chainId:()=>e.chainId??null,delegation:()=>({delegated:x,delegate:T}),encryptionKeyConfigured:S,storageAvailable:()=>A,refresh:E}),[g,y,o,u,R,w,e.adapter,e.signTypedData,e.chainId,x,T,S,A,E]);(0,re.useEffect)(()=>{let C=!1,k=i.sessions.filter(it.isVerifiablePolicy);return k.length===0?(p(new Set),m(!1),()=>{C=!0}):(m(!0),Promise.all(k.map(async U=>[U.id,await v.verifyStoredPolicy(U)])).then(U=>{C||p(new Set(U.filter(([,N])=>N).map(([N])=>N)))}).catch(U=>{C||(p(new Set),r(U instanceof Error?U:new Error("Policy verification failed")))}).finally(()=>{C||m(!1)}),()=>{C=!0})},[i.sessions,v]);let b=(0,re.useCallback)(()=>{r(null),i.clearError()},[i]),P=(0,re.useCallback)(async(C,k)=>{l(!0),r(null);try{return await C()}catch(U){let N=U instanceof Error?U:new Error(k);throw r(N),N}finally{l(!1)}},[]),W=(0,re.useCallback)(C=>P(()=>v.createPolicy(C),"Policy creation failed"),[v,P]),B=(0,re.useCallback)(C=>P(()=>v.revokePolicy(C),"Policy revocation failed"),[v,P]),V=(0,re.useCallback)((C,k)=>P(()=>v.executePolicy(C,k),"Policy execution failed"),[v,P]),f=i.activeSessions.filter(C=>a.has(C.id));return{policies:i.sessions,activePolicies:f,storageAvailable:i.storageAvailable,loading:i.loading||d,isBusy:c,error:h??i.error,delegation:s,createPolicy:W,revokePolicy:B,previewPolicyExecution:v.previewPolicyExecution,signPolicyDigest:v.signPolicyDigest,executePolicy:V,refresh:i.refresh,clearError:b}}var $e=require("react");function Vr(){let{disconnect:e,status:t}=I(),[o,s]=(0,$e.useState)(!1),[n,u]=(0,$e.useState)(null),i=(0,$e.useRef)(!0);return{disconnect:(0,$e.useCallback)(async()=>{if(t!=="disconnected"){s(!0),u(null);try{await e()}catch(c){if(!i.current)return;u(c instanceof Error?c:new Error("Disconnect failed"))}finally{i.current&&s(!1)}}},[e,t]),isDisconnecting:o,error:n,cleanup:()=>{i.current=!1}}}var Zt=require("@naculus/connect-core"),j=require("react");function Fe(e){let t=e.activeNamespace??"eip155",o=Array.isArray(e.accounts)?e.accounts.map(({namespace:s,address:n,derivationPath:u})=>({namespace:s,address:n,...u?{derivationPath:u}:{}})):e.address?[{namespace:t,address:e.address}]:[];return{accounts:o,activeNamespace:t,createdAt:e.createdAt??0,...e.chainId?{chainId:e.chainId}:{},...e.version?{version:e.version}:{},recoveryAvailable:!!e.mnemonic,address:o.find(s=>s.namespace===t)?.address??e.address}}function jr(){let{connectEmbedded:e,client:t}=I(),[o,s]=(0,j.useState)(null),n=(0,j.useRef)(null),u=(0,j.useRef)(4),i=(0,j.useRef)(!1),g=(0,j.useRef)(null),[c,l]=(0,j.useState)(!1),[h,r]=(0,j.useState)(!1),[a,p]=(0,j.useState)(null),d=()=>p(null),m=(0,j.useCallback)(()=>{let f=n.current;return n.current=null,f},[]),y=(0,j.useCallback)(()=>{let f=_(t);if(!f?.embeddedConnector)throw new Zt.WalletError("wallet_unavailable","Embedded wallet not enabled.");return f.embeddedConnector},[t]),S=(0,j.useCallback)(()=>{try{return y().getWallet()?.privateKey??null}catch{return null}},[y]),w=(0,j.useCallback)(async()=>{let f=_(t);if(!f)throw new Zt.WalletError("wallet_unavailable","Embedded wallet not enabled.");let C=f.getEmbeddedConnector?await f.getEmbeddedConnector():f.embeddedConnector;if(!C)throw new Zt.WalletError("wallet_unavailable","Embedded wallet not enabled.");return C},[t]),E=(0,j.useCallback)(()=>{try{return _(t)?.passphraseGate??null}catch{return null}},[t]),A=(0,j.useCallback)(f=>{f?.code==="decryption_failed"&&E()?.forget("That passphrase did not open the wallet.")},[E]),R=(0,j.useCallback)(async()=>{i.current=!1,p(null);try{let f=await w();if(!await f.load())return!1;let k=f.getWallet();return k?(n.current=null,l(!1),s(Fe(k)),!0):!1}catch(f){return i.current=!0,A(f),p(f instanceof Error?f:new Error("Failed to restore embedded wallet")),!1}},[A,w]);(0,j.useEffect)(()=>{let f=!1,C=null;return R().then(k=>{f||k||i.current||(C=setTimeout(()=>{f||R()},100))}),()=>{f=!0,C&&clearTimeout(C)}},[R]);let x=async()=>{r(!0),p(null);try{let f=await w(),C=await f.load(),k=f.getWallet();C&&k&&(s(Fe(k)),n.current=k.mnemonic||null,l(!k.mnemonic)),await e();let U=f.getWallet();U&&(s(Fe(U)),U.mnemonic&&!C&&(n.current=U.mnemonic,l(!0)))}catch(f){A(f),p(f instanceof Error?f:new Error("Embedded wallet connection failed"))}finally{r(!1)}},T=async()=>{r(!0),p(null);try{let f=await w();E()?.expect("create");let C=await f.generateWallet();return s(Fe(C)),n.current=C.mnemonic,l(!0),C}catch(f){return p(f instanceof Error?f:new Error("Failed to generate wallet")),null}finally{r(!1)}},v=async f=>{r(!0),p(null);try{let C=await w();E()?.expect("create");let k=await C.importFromMnemonic(f);return s(Fe(k)),n.current=null,l(!1),k}catch(C){return p(C instanceof Error?C:new Error("Failed to import wallet")),null}finally{r(!1)}},b=async f=>{r(!0),p(null);try{let C=await w();E()?.expect("create");let k=await C.importFromPrivateKey(f);return s(Fe(k)),n.current=null,l(!1),k}catch(C){return p(C instanceof Error?C:new Error("Failed to import wallet")),null}finally{r(!1)}},P=async()=>{r(!0),p(null);try{await(await w()).wipe(),s(null),n.current=null,l(!1)}catch(f){p(f instanceof Error?f:new Error("Failed to wipe wallet"))}finally{r(!1)}},W=(0,j.useCallback)(f=>{let C=y();C.setActiveNamespace(f);let k=C.getWallet();s(k?Fe(k):null)},[y]),B=(0,j.useCallback)(async()=>{let f=await w(),C=await f.backfillAccounts();if(C.length>0){let k=f.getWallet();s(k?Fe(k):null)}return C.map(({namespace:k,address:U,derivationPath:N})=>({namespace:k,address:U,...N?{derivationPath:N}:{}}))},[w]),V=()=>{n.current=null,l(!1)};return{connectEmbedded:x,restoreWallet:R,generateWallet:T,importFromMnemonic:v,importFromPrivateKey:b,wipe:P,wallet:o,hasWallet:o!==null,address:o?.address??null,accounts:o?.accounts??[],activeNamespace:o?.activeNamespace??null,setActiveNamespace:W,backfillAccounts:B,seedPhrase:n.current,getSeedPhrase:m,getPrivateKey:S,backupPending:c,confirmBackup:V,isBusy:h,error:a,clearError:d,storageSecurityLevel:(()=>{try{let f=y(),C=f.getStorageSecurityLevel?.()??4;return f.getWallet()?(u.current=C,C):o?u.current:C}catch{return o?u.current:4}})(),securityReport:(()=>{let f=null;try{f=y().getStorageSecurityReport?.()??null}catch{f=null}if(!f)return g.current=null,null;let C=JSON.stringify(f);return g.current?.json===C?g.current.value:(g.current={json:C,value:f},f)})()}}var zr=require("@naculus/connect-appkit-core"),Se=require("react");var $r=require("@naculus/connect-core"),Ce=require("react"),Gr=require("@naculus/connect-appkit-core");function Os(e){return[e.token.address.toLowerCase(),e.token.chainId??"",e.token.decimals??"",e.chainId??"",e.owner??"",e.spender??"",e.connected?"1":"0",e.publicClient?"1":"0",e.walletClient?"1":"0",e.session?.id??""].join("|")}function lt(e){let{token:t,chainId:o}=e,s=t.address.toLowerCase(),n=Os(e),u=(0,Ce.useMemo)(()=>({key:n}),[n]),i=(0,Ce.useRef)(n),g=(0,Ce.useRef)(!0);(0,Ce.useLayoutEffect)(()=>{i.current=n},[n]),(0,Ce.useEffect)(()=>(g.current=!0,()=>{g.current=!1}),[]);let c=(0,Ce.useCallback)(()=>g.current&&i.current===n,[n]),l=(0,Ce.useCallback)(()=>{if(!c())throw new $r.WalletError("session_inactive","Wallet or token context changed. Retry the operation with the current account and chain.");let h=(0,Gr.tokenChainMismatch)({address:s,chainId:t.chainId},o);if(h)throw h},[c,s,t.chainId,o]);return{identity:u,isCurrent:c,assertCurrent:l}}var en=require("@naculus/connect-core");function Qr(e){let{publicClient:t}=ce(),{currentChain:o}=le(),{identity:s,isCurrent:n,assertCurrent:u}=lt({token:e.token,chainId:o?(0,zr.chainNumber)(o)??void 0:void 0,owner:e.owner,spender:e.spender,publicClient:t}),[i,g]=(0,Se.useState)(null),c=i?.identity===s?i.raw:null,l=i?.identity===s&&i.fetching,h=i?.identity===s?i.error:null,r=(0,Se.useRef)(null),a=(0,Se.useRef)(0),p=(0,Se.useCallback)(async()=>{if(!n())return;let m=++a.current,y=()=>n()&&m===a.current;if(g({identity:s,raw:null,fetching:!!t,error:null}),!!t)try{u();let S=await t.readContract({address:e.token.address,abi:en.ERC20_MIN_ABI,functionName:"allowance",args:[e.owner,e.spender]});if(!y())return;g({identity:s,raw:S,fetching:!1,error:null})}catch(S){if(!y())return;g({identity:s,raw:null,fetching:!1,error:S instanceof Error?S:new Error("Failed to fetch allowance")})}},[t,e.token.address,e.token.chainId,e.owner,e.spender,s,n,u]);return(0,Se.useEffect)(()=>{p().catch(m=>console.warn("useERC20Allowance: initial fetch failed:",m))},[p]),(0,Se.useEffect)(()=>(e.refreshInterval&&e.refreshInterval>0&&(r.current=setInterval(p,e.refreshInterval)),()=>{r.current&&(clearInterval(r.current),r.current=null)}),[e.refreshInterval,p]),{allowance:(0,Se.useMemo)(()=>{if(c===null)return null;let m=e.token.decimals;return m===void 0?null:(0,en.formatUnits)(c,m)},[c,e.token.decimals]),allowanceRaw:c,isFetching:l,error:h,refetch:p}}var ge=require("@naculus/connect-appkit-core"),oe=require("@naculus/connect-core"),Ee=require("react");var tn=require("@naculus/connect-core"),ct=require("react");function ut(){let{session:e,chainId:t,client:o}=I(),[s,n]=(0,ct.useState)("idle"),[u,i]=(0,ct.useState)(null),g=(0,ct.useCallback)(async l=>{if(!e){n("failed");let r=new tn.WalletError("wallet_unavailable","No active session");throw i(r),r}let h=e.namespaces.eip155?.accounts.find(r=>/^eip155:\d+:0x[0-9a-fA-F]{40}$/.test(r)||/^0x[0-9a-fA-F]{40}$/.test(r));if(!h){n("failed");let r=new tn.WalletError("wallet_unavailable","No EVM account found");throw i(r),r}n("awaiting_approval"),i(null);try{let r={...l,from:l.from??h.split(":").pop()},a=_(o);if(!a)throw new tn.WalletError("wallet_unavailable","Client not initialized");let p=await a.sendTransaction(e,{transaction:r,chainId:t??void 0}),d=jt(p);return n("submitted"),d}catch(r){n("failed");let a=r instanceof Error?r.message:"Transaction failed";throw i(r instanceof Error?r:new Error(a)),r}},[e,t,o]),c=(0,ct.useCallback)(()=>{n("idle"),i(null)},[]);return{sendTransaction:g,status:s,error:u,reset:c,isSending:s==="awaiting_approval"}}function _s(e){return e.includes(":")?e.split(":").pop():e}var Ds=2n**256n-1n;function Xr(e){let{publicClient:t,walletClient:o}=ce(),{evmAccount:s,isConnected:n}=F(),{currentChain:u}=le(),{session:i,client:g}=I(),{sendTransaction:c,isSending:l,error:h,reset:r}=ut(),[a,p]=(0,Ee.useState)(null),{identity:d,isCurrent:m,assertCurrent:y}=lt({token:e.token,chainId:u?(0,ge.chainNumber)(u)??void 0:void 0,owner:s,spender:e.spender,connected:n,publicClient:t,walletClient:o,session:i,client:g}),[S,w]=(0,Ee.useState)(null),E=S?.identity===d?S.raw:null,A=S?.identity===d&&S.fetching,R=(0,Ee.useRef)((0,ge.createDecimalsCache)(e.token,e.token.decimals)),x=(0,Ee.useRef)(0),T=a??h,v=s?_s(s):null,b=(0,Ee.useCallback)(async()=>{if(!m())return null;let C=++x.current,k=()=>m()&&C===x.current;if(w({identity:d,raw:null,fetching:!!t&&!!v&&n}),p(null),!t||!v||!n)return null;try{y();let U=await t.readContract({address:e.token.address,abi:oe.ERC20_MIN_ABI,functionName:"allowance",args:[v,e.spender]});return k()?(w({identity:d,raw:U,fetching:!1}),U):null}catch(U){return k()&&(w({identity:d,raw:null,fetching:!1}),p(U instanceof Error?U:new Error("Failed to fetch allowance"))),null}},[t,v,e.token.address,e.token.chainId,e.spender,d,m,y,n]),P=(()=>{if(E===null)return null;let C=(0,ge.readDecimals)(R.current,e.token,e.token.decimals);return C===void 0?null:(0,oe.formatUnits)(E,C)})(),W=(0,Ee.useCallback)(async C=>{if(p(null),r(),!n||!s){let k=new oe.WalletError("wallet_unavailable","No connected account");throw p(k),k}if(!t){let k=new oe.WalletError("wallet_unavailable","No public client");throw p(k),k}try{y();let k=(0,ge.encodeErc20Approve)(e.spender,C),U=_(g);if(i&&U){let q=await c({to:e.token.address,data:k,value:"0"});return b(),q}if(o){let{request:q}=await t.simulateContract({address:e.token.address,abi:oe.ERC20_MIN_ABI,functionName:"approve",args:[e.spender,C],account:v});y();let qe=await o.writeContract(q);return b(),qe}let N=await c({to:e.token.address,data:k,value:"0"});return b(),N}catch(k){let U=k instanceof Error?k:new Error("Approve failed");throw m()&&p(U),U}},[e,t,o,s,n,i,g,v,c,r,b,y,m]),B=(0,Ee.useCallback)(async C=>{try{if(y(),!t)throw new oe.WalletError("wallet_unavailable","No public client");let k=(0,ge.readDecimals)(R.current,e.token,e.token.decimals);k===void 0&&(k=await t.readContract({address:e.token.address,abi:oe.ERC20_MIN_ABI,functionName:"decimals"}),y(),(0,ge.writeDecimals)(R.current,e.token,k));let U=(0,oe.parseUnits)(C,k);return await W(U)}catch(k){throw m()&&p(k instanceof Error?k:new Error("Approve failed")),k}},[e.token,t,W,y,m]),V=(0,Ee.useCallback)(async()=>W(Ds),[W]),f=(0,Ee.useCallback)(async C=>{if(!m()||!n||!v||!t)return!1;try{y()}catch(q){return p(q instanceof Error?q:new Error("Cannot check allowance")),!1}let k=E??await b();if(k===null)return!1;let U=(0,ge.readDecimals)(R.current,e.token,e.token.decimals);if(U===void 0){if(!t)throw new oe.WalletError("wallet_unavailable","Cannot check allowance: no public client to read token decimals.");if(U=await t.readContract({address:e.token.address,abi:oe.ERC20_MIN_ABI,functionName:"decimals"}),!m())return!1;(0,ge.writeDecimals)(R.current,e.token,U)}let N=(0,oe.parseUnits)(C,U);return m()&&k>=N},[E,b,e.token.address,e.token.chainId,e.token.decimals,t,m,y,n,v]);return{approve:B,approveMax:V,allowance:P,allowanceRaw:E,hasAllowance:f,isApproving:l,isFetchingAllowance:A,error:T,refetchAllowance:b}}var Ue=require("@naculus/connect-appkit-core"),Ke=require("@naculus/connect-core"),pt=require("react");function Ms(e){return e.includes(":")?e.split(":").pop():e}function Yr(e){let{publicClient:t,walletClient:o}=ce(),{evmAccount:s,isConnected:n}=F(),{currentChain:u}=le(),{session:i,client:g}=I(),{sendTransaction:c,isSending:l,error:h,reset:r}=ut(),[a,p]=(0,pt.useState)(null),{isCurrent:d,assertCurrent:m}=lt({token:e.token,chainId:u?(0,Ue.chainNumber)(u)??void 0:void 0,owner:s,connected:n,publicClient:t,walletClient:o,session:i,client:g}),y=(0,pt.useRef)((0,Ue.createDecimalsCache)(e.token,e.token.decimals)),S=a??h;return{sendTransfer:(0,pt.useCallback)(async(E,A)=>{if(p(null),r(),!n||!s){let R=new Ke.WalletError("wallet_unavailable","No connected account");throw p(R),R}if(!t){let R=new Ke.WalletError("wallet_unavailable","No public client available");throw p(R),R}try{m();let R=Ms(s),x=(0,Ue.readDecimals)(y.current,e.token,e.token.decimals);x===void 0&&(x=await t.readContract({address:e.token.address,abi:Ke.ERC20_MIN_ABI,functionName:"decimals"}),m(),(0,Ue.writeDecimals)(y.current,e.token,x));let T=(0,Ke.parseUnits)(A,x),v=(0,Ue.encodeErc20Transfer)(E,T),b=_(g);if(i&&b)return await c({to:e.token.address,data:v,value:"0"});if(o){let{request:W}=await t.simulateContract({address:e.token.address,abi:Ke.ERC20_MIN_ABI,functionName:"transfer",args:[E,T],account:R});return m(),await o.writeContract(W)}return await c({to:e.token.address,data:v,value:"0"})}catch(R){let x=R instanceof Error?R:new Error("Transfer failed");throw d()&&p(x),x}},[e.token,t,o,s,n,i,g,c,r,m,d]),isSending:l,error:S}}var rn=require("@naculus/connect-appkit-core"),Zr=require("@naculus/connect-core"),eo=require("react");var Jr=require("@naculus/connect-appkit-core"),Ae=require("react");function nn(e,t){I();let{evmAccount:o}=F(),{currentChain:s}=le(),{publicClient:n}=ce(),[u,i]=(0,Ae.useState)(void 0),[g,c]=(0,Ae.useState)(!1),[l,h]=(0,Ae.useState)(null),r=(0,Ae.useRef)(void 0),a=(0,Ae.useCallback)(async()=>{e&&(c(!0),h(null));try{let d=await(0,Jr.simulateTransactionPreview)(e,{chainId:t,currentChain:s,publicClient:n,evmAccount:o});return i(d),d}catch(d){let m=d instanceof Error?d:new Error("Simulation failed");throw h(m),m}finally{e&&c(!1)}},[e,t,s,n,o]);(0,Ae.useEffect)(()=>{if(e)return r.current&&clearTimeout(r.current),r.current=setTimeout(()=>{a().catch(()=>{})},300),()=>{r.current&&clearTimeout(r.current)}},[e,a]);let p=(0,Ae.useCallback)(()=>{i(void 0),h(null),c(!1)},[]);return{result:u,isSimulating:g,error:l,simulate:a,reset:p}}function to(e){let{evmAccount:t,isConnected:o}=F(),{currentChain:s}=le(),n=e.token.chainId??(s?(0,rn.chainNumber)(s)??void 0:void 0),u=(0,eo.useMemo)(()=>{if(!(!o||!t))try{let g=e.token.decimals;if(g===void 0)return;let c=(0,Zr.parseUnits)(e.amount,g),l=(0,rn.encodeErc20Transfer)(e.to,c);return{to:e.token.address,data:l,value:"0"}}catch{return}},[e.token.address,e.token.decimals,e.to,e.amount,t,o]),i=nn(u,n);return{result:u?i.result:void 0,isSimulating:!!u&&i.isSimulating,error:u?i.error:null,reSimulate:i.simulate,reset:i.reset}}var Pe=require("react");var we=require("react"),on=require("react"),Zn=(0,on.createContext)(null);function At(){return(0,on.useContext)(Zn)}function no(e,t,o){let s=At(),n=o??s,[u,i]=(0,we.useState)(null),[g,c]=(0,we.useState)(!1),[l,h]=(0,we.useState)(!1),[r,a]=(0,we.useState)(null),p=(0,we.useRef)(void 0),d=(0,we.useCallback)(async()=>{if(!(!n||!e)){c(!0),a(null);try{await n.refreshTx(e,t);let S=n.getTxStatus(e,t);S&&i(S)}catch(S){a(S instanceof Error?S:new Error(String(S)))}finally{c(!1)}}},[n,e,t]),m=(0,we.useCallback)(()=>{!n||!e||(n.stopWatching(e,t),h(!1))},[n,e,t]);(0,we.useEffect)(()=>{if(!n||!e||!t){i(null),h(!1);return}p.current&&p.current!==e&&n.stopWatching(p.current),p.current=e;let S=!1;h(!0),c(!0),a(null);let w=n.getTxStatus(e,t);w&&(i(w),c(!1)),n.watchTx(e,t,{}).then(A=>{S||(i(A),c(!1))}).catch(A=>{S||(a(A instanceof Error?A:new Error(String(A))),c(!1))});let E=A=>{S||i({...A})};return n.on("statusChange",E),()=>{S=!0,h(!1),n.off("statusChange",E)}},[n,e,t]);let y=u?.status??"idle";return{entry:u,status:y,isLoading:g,isWatching:l,error:r,refresh:d,stopWatching:m}}function ro(e){let t=At(),o=e??t,[s,n]=(0,Pe.useState)(null),[u,i]=(0,Pe.useState)(null),[g,c]=(0,Pe.useState)(null),l=(0,Pe.useRef)(null),h=(0,Pe.useRef)(null),r=(0,Pe.useRef)(null);o&&(h.current||(h.current=p=>{i(p),(!l.current||p.createdAt>=l.current.createdAt)&&(n(p),l.current=p)},o.on("confirmed",h.current)),r.current||(r.current=p=>{c(p),(!l.current||p.createdAt>=l.current.createdAt)&&(n(p),l.current=p)},o.on("failed",r.current)));let a=(0,Pe.useCallback)(()=>{n(null),i(null),c(null),l.current=null},[]);return{lastTx:s,lastConfirmedTx:u,lastFailedTx:g,clear:a}}var so=require("react");var ue=require("react"),oo=require("@naculus/connect-appkit-core");function sn({input:e,skip:t=!1,resolverConfig:o,scope:s,query:n}){let[u,i]=(0,ue.useState)(null),[g,c]=(0,ue.useState)(!1),[l,h]=(0,ue.useState)(null),r=(0,ue.useRef)(0),a=(0,ue.useRef)(!0);(0,ue.useEffect)(()=>(a.current=!0,()=>{a.current=!1}),[]);let p=(0,ue.useMemo)(()=>(0,oo.getResolver)(o),[o]),d=(0,ue.useCallback)(()=>{let m=e.trim();if(!m||t){r.current+=1,i(null),c(!1),h(null);return}let y=++r.current;c(!0),h(null),n(p,m,s).then(S=>{!a.current||y!==r.current||(i(S),c(!1))}).catch(S=>{!a.current||y!==r.current||(h(S instanceof Error?S:new Error(String(S))),i(null),c(!1))})},[e,t,s,p,n]);return(0,ue.useEffect)(()=>{d()},[d]),{data:u,isLoading:g,error:l,refetch:d}}function ao(e,t){let o=(0,so.useCallback)((s,n,u)=>s.lookupAddress(n,u),[]);return sn({input:e,skip:t?.skip,resolverConfig:t?.resolverConfig,scope:t?.chainId,query:o})}var $=require("react"),Q=require("@naculus/connect-appkit-core"),io=require("@naculus/connect-core");function lo(e){let t=(0,$.useRef)(null);t.current||(t.current=e?.channel??new io.InAppChannel);let o=t.current,[s,n]=(0,$.useState)(()=>o.getHistory()),[u,i]=(0,$.useState)(()=>Q.DEFAULT_NOTIFICATION_SETTINGS);(0,$.useEffect)(()=>{let w=e?.storage??(0,Q.createNotificationSettingsStorage)();(0,Q.loadNotificationSettings)(w).then(E=>{E&&i(E)})},[]),(0,$.useEffect)(()=>(o.onNotification=w=>{n(E=>[...E,w])},o.restore().then(()=>{n(o.getHistory())}),()=>{o.onNotification=void 0}),[]);let g=(0,$.useMemo)(()=>s.filter(w=>!w.read).length,[s]),c=(0,$.useCallback)(()=>{o.clear(),n([])},[o]),l=(0,$.useCallback)(w=>{(0,Q.clearOneInAppNotification)(o,w).then(()=>{n(o.getHistory())})},[o]),h=(0,$.useCallback)(w=>{o.markAsRead(w),n(E=>E.map(A=>A.id===w?{...A,read:!0}:A))},[o]),r=(0,$.useCallback)(()=>{o.markAllAsRead(),n(w=>w.map(E=>({...E,read:!0})))},[o]),a=(0,$.useCallback)(w=>{(0,Q.addInAppNotification)(o,w)},[o]),p=(0,$.useCallback)(w=>{i(E=>{let A=(0,Q.updateNotificationSettings)(E,w(E)),R=e?.storage??(0,Q.createNotificationSettingsStorage)();return(0,Q.saveNotificationSettings)(R,A),A})},[e?.storage]),d=(0,$.useCallback)(w=>p(()=>w),[p]),m=(0,$.useCallback)(w=>{d((0,Q.channelsUpdate)(w))},[d]),y=(0,$.useCallback)(w=>{p(E=>(0,Q.mutedChainSettings)(E,w,!0))},[p]),S=(0,$.useCallback)(w=>{p(E=>(0,Q.mutedChainSettings)(E,w,!1))},[p]);return{notifications:s,unreadCount:g,addNotification:a,clear:c,clearOne:l,markAsRead:h,markAllAsRead:r,settings:u,updateSettings:d,setChannels:m,muteChain:y,unmuteChain:S}}var dt=require("react");var co=()=>null,Ls=()=>()=>{};function uo(){let{client:e}=I(),t=_(e)?.passphraseGate??null,o=(0,dt.useSyncExternalStore)(t?.subscribe??Ls,t?.getSnapshot??co,co),s=(0,dt.useCallback)(i=>t?.submit(i),[t]),n=(0,dt.useCallback)(()=>t?.cancel(),[t]),u=(0,dt.useCallback)(i=>t?.forget(i),[t]);return{request:o,submit:s,cancel:n,forget:u,isUnlocked:t?.isUnlocked??!1,gate:t}}var po=require("react");function mo(e,t){let o=(0,po.useCallback)((s,n)=>s.resolveName(n),[]);return sn({input:e,skip:t?.skip,resolverConfig:t?.resolverConfig,query:o})}var We=require("@naculus/connect-appkit-core"),Ge=require("@naculus/connect-core"),se=require("react");async function Bs(e,t,o,s,n){let u=_(t);if(!u)throw new Ge.WalletError("wallet_unavailable","Client not initialized");let i=[o,s];if(e.walletType==="eip6963"||e.id?.startsWith("eip6963-")){let{eip6963Connector:g}=await import("@naculus/connector-evm-injected"),c=g.getDiscoveredWallets().find(h=>h.id===e.walletId),l=c?await c.provider.request({method:"personal_sign",params:i}):await g.request({method:"personal_sign",params:i});return(0,We.assertHexSignature)(l)}if(e.walletType==="walletconnect")return(0,We.assertHexSignature)(await u.connector.request({method:"personal_sign",params:i}));if(e.walletType==="embedded"){let g=u.embeddedConnector;if(!g?.signHash)throw new Ge.WalletError("method_unsupported","This embedded wallet build cannot sign a raw digest. Upgrade @naculus/connector-embedded or pass an explicit signer.");return(0,We.assertHexSignature)(await g.signHash(e,o))}throw e.walletType==="passkeys"?new Ge.WalletError("method_unsupported","Passkeys sign with P-256, which a SimpleAccount cannot verify. Use a smart account with a WebAuthn validator, or pass an explicit signer."):new Ge.WalletError("method_unsupported",`Raw UserOperation signing is not available for ${e.walletType} on ${n}. Pass a signer that signs the raw 32-byte hash.`)}function fo(e){let{evmAccount:t}=F(),{session:o,chainId:s,client:n}=I(),[u,i]=(0,se.useState)(null),[g,c]=(0,se.useState)(null),[l,h]=(0,se.useState)(!1),[r,a]=(0,se.useState)(!1),[p,d]=(0,se.useState)(null),m=(0,se.useRef)(0),y=(0,se.useRef)(!1);(0,se.useEffect)(()=>()=>{m.current+=1,y.current=!1},[]),(0,se.useEffect)(()=>{m.current+=1,y.current=!1,i(null),c(null),h(!1),a(!1),d(null)},[n,s,t,e?.accountType,e?.bundlerUrl,e?.chainId,e?.entryPoint,e?.owner,e?.rpcUrl,e?.salt,e?.signerMode,o]);let S=(0,se.useCallback)(async(E,A)=>{let R=b=>(d(b),null);if(!e?.rpcUrl)return R(new Error("RPC URL not configured"));if(!e.bundlerUrl)return R(new Error("Bundler URL not configured"));if(!E.length)return R(new Error("At least one call is required"));if(y.current)return R(new Error("A UserOperation is already in progress"));let x=(0,We.bareEvmAddress)(e.owner??t);if(!x)return R(new Ge.WalletError("wallet_unavailable","No EVM account found"));let T;try{T=(0,We.resolveUserOpChain)(e.chainId,s)}catch(b){return R(b)}if(!e.signer&&!o)return R(new Ge.WalletError("wallet_unavailable","No active session"));let v=++m.current;y.current=!0,h(!0),a(!0),d(null),i(null),c(null);try{let{SmartAccountManager:b}=await import("@naculus/connect-core"),P=e.signer??(f=>Bs(o,n,f,x,T)),W=new b({rpcUrl:e.rpcUrl,bundlerClient:{url:e.bundlerUrl},chainId:T,signer:P,signerMode:e.signer?e.signerMode??"eip191":"raw"}),B=(0,We.buildSmartAccountConfig)(x,T,e),V=await W.sendUserOperation(B,E,A);return v!==m.current?null:(a(!1),i(V.userOpHash),W.getUserOperationReceipt(V.userOpHash).then(f=>{v===m.current&&c(f)}).catch(()=>{}),V)}catch(b){if(v!==m.current)return null;let P=b instanceof Error?b:new Error("Failed to send UserOperation");return d(P),null}finally{y.current=!1,v===m.current&&(h(!1),a(!1))}},[n,s,t,e,o]),w=(0,se.useCallback)(()=>{m.current+=1,i(null),c(null),h(!1),a(!1),d(null)},[]);return{sendUserOp:S,userOpHash:u,receipt:g,isPending:l,isEstimating:r,error:p,reset:w}}var bt=require("react");function Fs(e,t){if(!e)return()=>{};let o=()=>t();return e.on("sessionConnected",o),e.on("sessionDisconnected",o),e.on("chainChanged",o),e.on("sessionScopeChanged",o),e.on("sessionRevoked",o),()=>{e.off("sessionConnected",o),e.off("sessionDisconnected",o),e.off("chainChanged",o),e.off("sessionScopeChanged",o),e.off("sessionRevoked",o)}}var er=Object.freeze({session:null,chainSessions:[],activeChainId:null,isConnected:!1,connectorId:null}),tr=new WeakMap;function Ks(e,t){if(e.length!==t.length)return!1;for(let o=0;o<e.length;o++)if(e[o]!==t[o])return!1;return!0}function Hs(e){if(!e)return er;let t=e.getActiveBundle(),o=tr.get(e);if(!t)return o&&o.session===null?o:(tr.set(e,er),er);let s=Array.from(t.chainSessions.values());if(o&&o.session===t.walletSession&&o.activeChainId===t.activeChainId&&Ks(o.chainSessions,s))return o;let n={session:t.walletSession,chainSessions:s,activeChainId:t.activeChainId,isConnected:!0,connectorId:t.walletSession.walletType};return tr.set(e,n),n}function go(e){let t=I(),o=e??t.sessionManager??null,s=(0,bt.useCallback)(u=>Fs(o,u),[o]),n=(0,bt.useCallback)(()=>Hs(o),[o]);return(0,bt.useSyncExternalStore)(s,n)}var an=require("@naculus/connect-appkit-core"),Rt=require("@naculus/connect-core"),Ne=require("@naculus/siwx"),mt=require("react");var qs=86400;function ln(){let{session:e,chainId:t,client:o}=I(),[s,n]=(0,mt.useState)(!1),[u,i]=(0,mt.useState)(null),g=(0,mt.useCallback)(()=>i(null),[]);return{signIn:(0,mt.useCallback)(async l=>{if(!e)throw new Rt.WalletError("wallet_unavailable","No active session");let h=l?.chainId??t;if(!h)throw new Rt.WalletError("invalid_chain","No chain to sign for. Connect a wallet or pass options.chainId.");let r=Ze(e,h);if(!r)throw new Rt.WalletError("wallet_unavailable","No account found");let a=_(o);if(!a)throw new Rt.WalletError("wallet_unavailable","Client not initialized");let{address:p}=r,d=typeof window>"u"?void 0:window.location,m=l?.domain??(0,an.defaultSiwxDomain)(d),y=l?.uri??(0,an.defaultSiwxUri)(d);n(!0),i(null);try{let S=(0,Ne.generateNonce)();await(0,Ne.issueNonce)(S);let w=(0,Ne.nowISO)(),E=l?.expirySeconds??qs,A=new Date(Date.now()+E*1e3).toISOString(),R=(0,Ne.createSiwxMessage)({domain:m,address:p,uri:y,version:1,chainId:h,nonce:S,issuedAt:w,expirationTime:A,statement:l?.statement,resources:l?.resources,requestId:l?.requestId}),x=await a.signMessage(e,{message:R,address:p,chainId:h??void 0}),T={message:{raw:R,domain:m,address:p,statement:l?.statement??null,uri:y,version:1,chainId:h,nonce:S,issuedAt:w,blockchain:(0,Ne.getBlockchainName)(h),expirationTime:A,notBefore:null,resources:l?.resources??[],requestId:l?.requestId??null},signature:x};return n(!1),T}catch(S){let w=S instanceof Error?S:new Error("SIWx sign-in failed");throw i(w),n(!1),w}},[e,t,o]),isSigningIn:s,error:u,clearError:g}}var nr=require("@naculus/connect-appkit-core"),cn=require("@naculus/connect-core"),Tt=require("@naculus/siwx"),ae=require("react");function ho(e){let{storagePrefix:t="naculus_",autoRestore:o=!0,defaultExpirySeconds:s=86400}=e??{},[n,u]=(0,ae.useState)(null),[i,g]=(0,ae.useState)(o),[c,l]=(0,ae.useState)(!1),[h,r]=(0,ae.useState)(null),{chainId:a}=I(),p=ln(),d=(0,ae.useRef)((0,Tt.createLocalStorageSiwxSessionStorage)(`${t}siwx_session`)),m=(0,ae.useCallback)(()=>r(null),[]);(0,ae.useEffect)(()=>{if(!o){g(!1);return}let x=!1;return(async()=>{try{let v=await d.current.get();if(x)return;v?(cn.logger.info("react/useSIWxSession","Restored persisted SIWx session"),u(v),r(null)):u(null)}catch(T){cn.logger.warn("react/useSIWxSession","Failed to restore SIWx session:",T),u(null)}finally{x||g(!1)}})(),()=>{x=!0}},[o]),(0,ae.useEffect)(()=>{if(!n?.expiresAt)return;let x=new Date(n.expiresAt).getTime()-Date.now();if(x<=0){u(null);return}let T=setTimeout(()=>{u(v=>v&&v.id===n.id?null:v)},x);return()=>clearTimeout(T)},[n?.id,n?.expiresAt]);let y=(0,ae.useCallback)(async x=>{l(!0),r(null);try{let T={expirySeconds:s,chainId:a??void 0,...x},v=await p.signIn(T),b=(0,nr.siwxResultToSession)(v);return await d.current.set(b),u(b),l(!1),b}catch(T){let v=T instanceof Error?T:new Error("SIWx sign-in failed");throw r(v),l(!1),v}},[p,a,s]),S=(0,ae.useCallback)(async()=>{try{await d.current.remove()}catch(x){cn.logger.warn("react/useSIWxSession","Failed to clear session:",x)}u(null),r(null)},[]),w=(0,ae.useCallback)(async()=>{if(!n)throw new Error("No active session to refresh");l(!0),r(null);try{let x=await p.signIn({domain:n.domain,statement:n.message.statement??void 0,uri:n.message.uri,chainId:n.chainId,expirySeconds:s,resources:n.message.resources.length>0?n.message.resources:void 0,requestId:n.message.requestId??void 0}),T={...(0,nr.siwxResultToSession)(x),id:n.id,refreshedAt:new Date().toISOString()};return await d.current.set(T),u(T),l(!1),T}catch(x){let T=x instanceof Error?x:new Error("Session refresh failed");throw r(T),l(!1),T}},[n,p,s]),E=n!==null&&!(0,Tt.checkSessionExpired)(n),A=(0,Tt.checkSessionExpired)(n),R=n?.expiresAt?Math.max(0,new Date(n.expiresAt).getTime()-Date.now()):null;return{session:E?n:null,isAuthenticated:E,isRestoring:i,isSigningIn:c,isExpired:A,timeUntilExpiry:R,signIn:y,signOut:S,refresh:w,error:h,clearError:m}}var un=require("@naculus/connect-appkit-core"),It=require("@naculus/connect-core"),Oe=require("@naculus/siwx"),ze=require("react");function ft(){let{session:e,chainId:t,client:o}=I(),[s,n]=(0,ze.useState)(!1),[u,i]=(0,ze.useState)(null),[g,c]=(0,ze.useState)(null),l=(0,ze.useCallback)(()=>c(null),[]);return{signIn:(0,ze.useCallback)(async r=>{if(!e)throw new It.WalletError("wallet_unavailable","No active session");let a=r?.chainId??t;if(!a)throw new It.WalletError("invalid_chain","No chain to sign for. Connect a wallet or pass options.chainId.");let p=Ze(e,a);if(!p)throw new It.WalletError("wallet_unavailable","No account found");let d=_(o);if(!d)throw new It.WalletError("wallet_unavailable","Client not initialized");let{address:m}=p,y=typeof window>"u"?void 0:window.location,S=r?.domain??(0,un.defaultSiwxDomain)(y),w=r?.uri??(0,un.defaultSiwxUri)(y);n(!0),c(null);try{let E=(0,Oe.generateNonce)();await(0,Oe.issueNonce)(E);let A=(0,Oe.nowISO)(),R=(0,Oe.createSiwxMessage)({domain:S,address:m,uri:w,version:1,chainId:a,nonce:E,issuedAt:A,statement:r?.statement,expirationTime:r?.expirySeconds?new Date(Date.now()+r.expirySeconds*1e3).toISOString():void 0,resources:r?.resources,requestId:r?.requestId}),x=await d.signMessage(e,{message:R,address:m,chainId:a??void 0}),T=r?.expirySeconds?new Date(Date.now()+r.expirySeconds*1e3).toISOString():null,v={message:{raw:R,domain:S,address:m,statement:r?.statement??null,uri:w,version:1,chainId:a,nonce:E,issuedAt:A,blockchain:(0,Oe.getBlockchainName)(a),expirationTime:T,notBefore:null,resources:r?.resources??[],requestId:r?.requestId??null},signature:x};return i(v),v}catch(E){let A=E instanceof Error?E:new Error("SIWx sign-in failed");throw c(A),A}finally{n(!1)}},[e,t,o]),isSigningIn:s,result:u,error:g,clearError:l}}var pn=require("@naculus/connect-core");var rr=require("react");function Vs(){let{session:e,chainId:t}=I();return(0,rr.useCallback)(o=>{if(!e)throw new pn.WalletError("wallet_unavailable","No active session");let s=o??t;if(s&&!s.startsWith("eip155:"))throw new pn.WalletError("namespace_mismatch",`Ethereum SIWx requires an eip155 chain, received ${s}`);let n=e.namespaces.eip155;if(!n||n.accounts.length===0)throw new pn.WalletError("namespace_mismatch","No EVM (eip155) accounts found in session")},[e,t])}function yo(){let e=Vs(),t=ft();return{signIn:(0,rr.useCallback)(async s=>(e(s?.chainId),t.signIn(s)),[e,t.signIn]),isSigningIn:t.isSigningIn,result:t.result,error:t.error,clearError:t.clearError}}var Co=require("@naculus/connect-appkit-core"),So=require("@naculus/wallet-engine"),_e=require("react");function Eo(e){let t=e?.rpcUrl,o=e?.chainId,s=(0,_e.useRef)(null),n=(0,_e.useCallback)(()=>(s.current||(s.current=new So.SimulationManager({enabled:!0,rpcUrl:t,autoSimulate:!1})),s.current),[t]),[u,i]=(0,_e.useState)(null),[g,c]=(0,_e.useState)(!1),[l,h]=(0,_e.useState)(null),r=(0,_e.useCallback)(async(p,d,m,y,S)=>{c(!0),h(null);try{let w=n(),E=(0,Co.resolveSimulationEndpoint)(S?.chainId,o,S?.rpcUrl,t),A=await w.simulateERC20Transfer(p,d,m,y,E.chainId,S?.decimals,E.rpcUrl);return i(A),A}catch(w){let E=w instanceof Error?w:new Error(String(w));throw h(E),E}finally{c(!1)}},[t,o,n]),a=(0,_e.useCallback)(()=>{i(null),h(null),c(!1)},[]);return{result:u,loading:g,error:l,simulate:r,reset:a}}var mn=require("@naculus/connect-appkit-core"),Qe=require("@naculus/connect-core"),he=require("react");var dn="siwx_auth";function js(e){return new Qe.LocalStorageAdapter(e)}function wo(e){let{storagePrefix:t="naculus_",autoRestore:o=!0}=e??{},[s,n]=(0,he.useState)(null),[u,i]=(0,he.useState)(o),[g,c]=(0,he.useState)(!1),[l,h]=(0,he.useState)(null),r=ft(),a=(0,he.useRef)(js(t)),p=(0,he.useCallback)(()=>h(null),[]);(0,he.useEffect)(()=>{if(!o){i(!1);return}let y=!1;return(async()=>{try{let S=a.current,w=await S.get(dn);if(y)return;w&&!(0,mn.isSiwxExpired)(w,new Date)&&(0,mn.isSiwxNotBeforeValid)(w,new Date)?(Qe.logger.info("react/useSiwxAuthSession","Restored persisted SIWx auth session"),n(w),h(null)):w&&(Qe.logger.info("react/useSiwxAuthSession","Persisted SIWx auth expired, clearing"),await S.remove(dn))}catch(S){Qe.logger.warn("react/useSiwxAuthSession","Failed to restore SIWx auth:",S)}finally{y||i(!1)}})(),()=>{y=!0}},[o]);let d=(0,he.useCallback)(async y=>{c(!0),h(null);try{let S=await r.signIn(y);return await a.current.set(dn,S),n(S),c(!1),S}catch(S){let w=S instanceof Error?S:new Error("SIWx sign-in failed");throw h(w),c(!1),w}},[r]),m=(0,he.useCallback)(async()=>{try{await a.current.remove(dn)}catch(y){Qe.logger.warn("react/useSiwxAuthSession","Failed to clear SIWx auth:",y)}n(null),h(null)},[]);return{isSignedIn:s!==null,isRestoring:u,siwxResult:s,isSigningIn:g,error:l,signIn:d,signOut:m,clearError:p}}var Xe=require("@naculus/connect-appkit-core"),or=require("@naculus/connect-core"),G=require("react");function ko(e){return new or.WalletError("wallet_unavailable",e)}function xo(e){let{evmAccount:t}=F(),{session:o,chainId:s,client:n}=I(),[u,i]=(0,G.useState)(null),[g,c]=(0,G.useState)(!1),[l,h]=(0,G.useState)(null),[r,a]=(0,G.useState)(!1),[p,d]=(0,G.useState)(null),m=(0,G.useRef)(null),y=(0,G.useRef)(0),S=(0,G.useRef)(!1);(0,G.useEffect)(()=>{if(m.current=null,!e?.rpcUrl)return;let b=!1;return import("@naculus/connect-core").then(({SmartAccountManager:P})=>{if(b)return;let W=(0,Xe.resolveEvmChainId)(e.chainId,s);W&&(m.current=new P({rpcUrl:e.rpcUrl,chainId:W,bundlerClient:{url:e.bundlerUrl??""}}))}).catch(P=>{b||d(P instanceof Error?P:new Error("Failed to load account-abstraction module"))}),()=>{b=!0}},[s,e?.rpcUrl,e?.bundlerUrl,e?.chainId]),(0,G.useEffect)(()=>{y.current+=1,S.current=!1,i(null),c(!1),h(null),a(!1),d(null)},[t,s,e?.rpcUrl,e?.bundlerUrl,e?.chainId,e?.entryPoint,e?.accountType,e?.salt]);let w=(0,G.useCallback)(()=>{let b=(0,Xe.bareEvmAddress)(t);if(!b||!m.current)return null;let P=(0,Xe.resolveEvmChainId)(e?.chainId,s);return P?(0,Xe.buildSmartAccountConfig)(b,P,{accountType:e?.accountType,entryPoint:e?.entryPoint,salt:e?.salt}):null},[t,s,e?.accountType,e?.chainId,e?.entryPoint,e?.salt]),E=(0,G.useCallback)(b=>(d(b),null),[]),A=(0,G.useCallback)(()=>S.current?null:(S.current=!0,y.current),[]),R=(0,G.useCallback)(b=>{y.current===b&&(S.current=!1)},[]),x=(0,G.useCallback)(async()=>{let b=w();if(!b||!m.current)return E(new Error("Smart account not configured"));let P=A();if(P===null)return E(new Error("Smart account operation already in progress"));a(!0),d(null);try{let B=await m.current.createAccount(b);return y.current!==P?null:(i(B.address),c(B.isDeployed),h(B),B)}catch(W){if(y.current!==P)return null;let B=W instanceof Error?W:new Error("Failed to create smart account");return d(B),null}finally{y.current===P&&a(!1),R(P)}},[A,E,R,w]),T=(0,G.useCallback)(async()=>{let b=w();if(!b||!m.current)return E(new Error("Smart account not configured"));if(!o)return E(ko("No active session"));let P=_(n);if(!P)return E(ko("Client not initialized"));if(s&&s!==b.chainId)return E(new or.WalletError("chain_mismatch",`Connected chain ${s} does not match smart account chain ${b.chainId}.`));let W=A();if(W===null)return E(new Error("Smart account operation already in progress"));a(!0),d(null);try{let B=m.current,V=await B.createAccount(b);if(y.current!==W)return null;if(V.isDeployed)return i(V.address),c(!0),h(V),V.address;let f=await B.getDeployCallData(b),C=await P.sendTransaction(o,{transaction:{to:f.to,data:f.data,value:f.value.toString()},chainId:b.chainId});if(y.current!==W)return null;let k=await B.createAccount(b);return i(k.address),c(k.isDeployed),h(k),C}catch(B){if(y.current!==W)return null;let V=B instanceof Error?B:new Error("Failed to deploy smart account");return d(V),null}finally{y.current===W&&a(!1),R(W)}},[n,s,A,E,R,w,o]),v=(0,G.useCallback)(async()=>{let b=w();if(!b||!m.current)return null;let P=y.current;try{let W=await m.current.getAccountAddress(b);return y.current!==P?null:(i(W),W)}catch(W){return y.current!==P||d(W instanceof Error?W:new Error("Failed to get smart account address")),null}},[w]);return{address:u,isDeployed:g,accountInfo:l,isLoading:r,error:p,createWallet:x,deployWallet:T,getAddress:v}}var vo=require("react");function fn(){let{accounts:e,isConnected:t}=I();return(0,vo.useMemo)(()=>{if(!t)return{address:null,caip10:null,chainId:null,isConnected:!1};let o=e.find(i=>i.startsWith("solana:"))??null;if(!o)return{address:null,caip10:null,chainId:null,isConnected:t};let s=o.split(":"),n=s.length>=3?s[s.length-1]:null,u=s.length>=3?s.slice(0,-1).join(":"):null;return{address:n,caip10:o,chainId:u,isConnected:t}},[e,t])}var be=require("react"),Ao=require("@naculus/connect-core");function bo(e={}){let{client:t}=I(),{address:o}=fn(),s=e.address??o,n=e.rpcUrl??_(t)?.solanaRpcUrl??null,[u,i]=(0,be.useState)(null),[g,c]=(0,be.useState)(!1),[l,h]=(0,be.useState)(null),r=(0,be.useRef)(0),a=(0,be.useCallback)(async()=>{if(!s||!n){i(null);return}let p=++r.current;c(!0),h(null);try{let d=await(0,Ao.getSolanaBalance)(n,s);if(p!==r.current)return;i(d)}catch(d){if(p!==r.current)return;i(null),h(d instanceof Error?d:new Error("Balance read failed"))}finally{p===r.current&&c(!1)}},[s,n]);return(0,be.useEffect)(()=>{a()},[a]),(0,be.useEffect)(()=>{if(!e.refreshInterval||e.refreshInterval<=0)return;let p=setInterval(()=>{a()},e.refreshInterval);return()=>clearInterval(p)},[e.refreshInterval,a]),{balance:u,isFetching:g,error:l,isConfigured:!!n,refetch:a}}var Ro=require("@naculus/connect-appkit-core"),To=require("react");function Io(){let{client:e,session:t,accounts:o}=I();return(0,To.useMemo)(()=>{let s=_(e)?.solanaConnector,{roles:n,absence:u}=(0,Ro.readSolanaRoles)(s,t);return{roles:n,absence:u,identity:n?.identity??null,signer:n?.signer??null,payer:n?.payer??null}},[e,t,o])}var sr=require("@naculus/connect-core"),He=require("react"),Uo=require("@naculus/connect-core");function Po(){let{client:e,session:t}=I(),[o,s]=(0,He.useState)(!1),[n,u]=(0,He.useState)(!1),[i,g]=(0,He.useState)(null),c=()=>{let a=_(e);if(!a||!t)throw new sr.WalletError("wallet_unavailable","No connected wallet.");return a},l=(0,He.useCallback)(async a=>{s(!0),g(null);try{return await c().signTransaction(t,{transaction:a})}catch(p){let d=p instanceof Error?p:new Error("Signing failed");throw g(d),d}finally{s(!1)}},[e,t]),h=(0,He.useCallback)(async a=>{u(!0),g(null);try{return await c().sendTransaction(t,{transaction:a})}catch(p){let d=p instanceof Error?p:new Error("Send failed");throw g(d),d}finally{u(!1)}},[e,t]),r=(0,He.useCallback)(async a=>{let p=_(e)?.solanaRpcUrl;if(!p)throw new sr.WalletError("no_rpc","Set solanaRpcUrl on the client to read a signature's status.");return(0,Uo.getSignatureStatus)(p,a)},[e]);return{signTransaction:l,sendTransaction:h,getStatus:r,isSigning:o,isSending:n,error:i,reset:()=>g(null)}}var gt=require("react"),Wo=require("@naculus/connect-appkit-core");function No(){let{switchChain:e,chainId:t}=I(),[o,s]=(0,gt.useState)(!1),[n,u]=(0,gt.useState)(null),i=(0,gt.useCallback)(async c=>{s(!0),u(null);try{await e(c)}catch(l){let h=(0,Wo.toChainSwitchError)(l);throw u(h),h}finally{s(!1)}},[e]),g=(0,gt.useCallback)(()=>{u(null)},[]);return{switchChain:i,isSwitching:o,currentChainId:t,error:n,clearError:g}}var ht=require("@naculus/connect-appkit-core"),Y=require("react");var yt=require("viem"),$s=[{name:"balanceOf",type:"function",stateMutability:"view",inputs:[{name:"owner",type:"address"}],outputs:[{name:"balance",type:"uint256"}]}];function Oo(e){let{evmAccount:t,isConnected:o}=F(),{chainId:s,chains:n}=I(),[u,i]=(0,Y.useState)([]),[g,c]=(0,Y.useState)(!1),[l,h]=(0,Y.useState)(null),{tokens:r,refreshInterval:a}=e,p=(0,Y.useRef)(null),d=(0,Y.useMemo)(()=>r.map(x=>x.address.toLowerCase()+"|"+x.decimals+"|"+x.symbol).join(","),[r]),m=(0,Y.useMemo)(()=>(0,ht.resolveChain)(n,s),[s,n]),y=m?(0,ht.chainNumber)(m):null,S=(0,Y.useMemo)(()=>m?(0,ht.toViemChain)(m,y):null,[m,y]),[w,E]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{if(!S||!m?.rpcUrl){E(null);return}let x=(0,yt.createPublicClient)({transport:(0,yt.http)(m.rpcUrl),chain:S});E(x)},[m,S]);let A=(0,Y.useCallback)(async()=>{if(!t||!w||r.length===0){i([]);return}c(!0),h(null);try{let x=t.includes(":")?t.split(":").pop():t,v=(await Promise.allSettled(r.map(async b=>{try{let P=await w.readContract({address:b.address,abi:$s,functionName:"balanceOf",args:[x]});return{address:b.address,symbol:b.symbol,decimals:b.decimals,name:b.name,balance:P.toString(),formatted:(0,yt.formatUnits)(P,b.decimals)}}catch{return{address:b.address,symbol:b.symbol,decimals:b.decimals,name:b.name,balance:null,formatted:null}}}))).map(b=>b.status==="fulfilled"?b.value:{address:"",symbol:"?",decimals:0,balance:null,formatted:null});i(v)}catch(x){h(x instanceof Error?x:new Error("Failed to fetch token balances"))}finally{c(!1)}},[t,w,d]);(0,Y.useEffect)(()=>{o&&t&&r.length>0&&A()},[o,t,d,A]),(0,Y.useEffect)(()=>(a&&a>0&&o&&t&&r.length>0&&(p.current=setInterval(A,a)),()=>{p.current&&(clearInterval(p.current),p.current=null)}),[a,o,t,d,A]);let R=(0,Y.useCallback)(x=>u.find(T=>T.address.toLowerCase()===x.toLowerCase()),[u]);return{tokenBalances:u,isLoading:g,error:l,refetch:A,getTokenBalance:R,chain:m}}var Re=require("react");function _o(e,t,o){let s=At(),n=o??s,[u,i]=(0,Re.useState)([]),[g,c]=(0,Re.useState)(!1),[l,h]=(0,Re.useState)(null),r=(0,Re.useRef)(0),a=(0,Re.useCallback)(async()=>{if(n){c(!0),h(null),r.current++;try{let d=await n.getTxHistory(e,t);i(d)}catch(d){h(d instanceof Error?d:new Error(String(d)))}finally{c(!1)}}},[n,e,t]);(0,Re.useEffect)(()=>{a().catch(()=>{})},[a]),(0,Re.useEffect)(()=>{if(!n)return;let d=()=>{a().catch(()=>{})};return n.on("statusChange",d),()=>{n.off("statusChange",d)}},[n,a]);let p={pending:u.filter(d=>d.status==="pending").length,confirmed:u.filter(d=>d.status==="confirmed").length,failed:u.filter(d=>d.status==="failed").length};return{entries:u,isLoading:g,error:l,refresh:a,summary:p}}var gn=require("@naculus/connect-appkit-core"),H=require("react");function Do(e){let t=e?.bundlerUrl,o=e?.pollInterval??2e3,s=e?.maxRetries??30,[n,u]=(0,H.useState)("idle"),[i,g]=(0,H.useState)(null),[c,l]=(0,H.useState)(e?.userOpHash??null),[h,r]=(0,H.useState)(null),[a,p]=(0,H.useState)(!1),[d,m]=(0,H.useState)(0),y=(0,H.useRef)(0),[S,w]=(0,H.useState)(0),E=(0,H.useRef)(null),A=(0,H.useRef)(null),R=(0,H.useRef)(0),x=(0,H.useRef)(0),T=(0,H.useRef)(null),v=(0,H.useCallback)(()=>{E.current&&(clearInterval(E.current),E.current=null),A.current&&(clearTimeout(A.current),A.current=null)},[]),b=(0,H.useCallback)(async(C,k)=>{if(!t||k!==R.current)return;let U=x.current+1;x.current=U,m(U);let N=new AbortController;T.current=N;let q=pe=>{k===R.current&&(u("not_found"),p(!1),v(),r(pe))},qe=pe=>{if(k===R.current){if(U<=s){A.current=setTimeout(()=>{b(C,k)},o);return}q(pe)}};try{let pe=await(0,gn.fetchUserOperationReceipt)(t,C,N.signal);if(k!==R.current)return;if(pe){g(pe),u(pe.success?"confirmed":"failed"),p(!1),v();return}u("pending"),qe(new Error("UserOperation not included after maximum retries"))}catch(pe){if(k!==R.current||N.signal.aborted)return;let Et=pe instanceof Error?pe:new Error("Unknown bundler response failure");if(Et instanceof gn.InvalidUserOperationReceiptError){q(Et);return}qe(new Error(`UserOperation status unavailable after ${U} attempt${U===1?"":"s"}: ${Et.message}`))}finally{T.current===N&&(T.current=null)}},[t,o,s,v]),P=(0,H.useCallback)(C=>{R.current+=1;let k=R.current;if(T.current?.abort(),T.current=null,v(),l(C),g(null),r(null),x.current=0,m(0),w(0),y.current=Date.now(),!t){u("not_found"),p(!1),r(new Error("Bundler URL not configured"));return}u("pending"),p(!0),E.current=setInterval(()=>{w(Date.now()-y.current)},1e3),b(C,k)},[t,v,b]),W=(0,H.useCallback)(()=>{R.current+=1,T.current?.abort(),T.current=null,v(),p(!1)},[v]),B=(0,H.useCallback)(()=>{R.current+=1,T.current?.abort(),T.current=null,v(),l(null),u("idle"),g(null),r(null),p(!1),x.current=0,m(0),w(0)},[v]),V=e?.userOpHash??null,f=e?.autoStart!==!1;return(0,H.useEffect)(()=>{V&&f&&P(V)},[V,f,P]),(0,H.useEffect)(()=>()=>{R.current+=1,T.current?.abort(),T.current=null,v()},[v]),{status:n,receipt:i,userOpHash:c,error:h,isPolling:a,elapsedMs:S,attempts:d,start:P,stop:W,reset:B}}var Fo=require("@naculus/connect-appkit-core"),Ko=require("react");var Gs={"storage.critical.title":"Insecure Storage Detected","storage.critical.body":"Your browser does not support IndexedDB. Wallet data is stored in plaintext in localStorage and could be exposed to XSS attacks. We strongly recommend switching to a modern browser.","storage.warning.title":"Storage Security Warning","storage.warning.body":"Your browser does not support IndexedDB, but your wallet data is encrypted with AES-256-GCM. Consider switching browsers for better origin isolation.","address.empty":"Address is empty","address.invalid_format":"Invalid address format (expected 0x + 40 hex chars)","address.zero_address":"Address is the zero address \u2014 funds would be permanently lost","address.burn_address":"Address appears to be a burn address \u2014 funds would be permanently lost","wallet.connect":"Connect Wallet","wallet.disconnect":"Disconnect","wallet.connecting":"Connecting...","wallet.copy_address":"Copy address","wallet.copied":"Copied!","wallet.view_on_explorer":"View on Explorer","wallet.retry":"Retry","wallet.connection_failed":"Connection failed","wallet.scan_qr":"Scan with your wallet app","embedded.generate":"Create Wallet","embedded.import":"Import Wallet","embedded.backup_seed":"Back up your seed phrase","embedded.backup_warning":"Anyone with your seed phrase can access your funds. Store it securely.","embedded.backup_done":"I've saved my seed phrase","embedded.wipe":"Remove Wallet","embedded.wipe_confirm":"Are you sure? This cannot be undone."},zs={"storage.critical.title":"\u5075\u6E2C\u5230\u4E0D\u5B89\u5168\u5132\u5B58","storage.critical.body":"\u60A8\u7684\u700F\u89BD\u5668\u4E0D\u652F\u63F4 IndexedDB\u3002\u9322\u5305\u8CC7\u6599\u4EE5\u660E\u6587\u5132\u5B58\u5728 localStorage \u4E2D\uFF0C\u53EF\u80FD\u66B4\u9732\u65BC XSS \u653B\u64CA\u3002\u5F37\u70C8\u5EFA\u8B70\u66F4\u63DB\u81F3\u73FE\u4EE3\u700F\u89BD\u5668\u3002","storage.warning.title":"\u5132\u5B58\u5B89\u5168\u8B66\u544A","storage.warning.body":"\u60A8\u7684\u700F\u89BD\u5668\u4E0D\u652F\u63F4 IndexedDB\uFF0C\u4F46\u9322\u5305\u8CC7\u6599\u5DF2\u4F7F\u7528 AES-256-GCM \u52A0\u5BC6\u3002\u5EFA\u8B70\u66F4\u63DB\u700F\u89BD\u5668\u4EE5\u7372\u5F97\u66F4\u597D\u7684\u9694\u96E2\u4FDD\u8B77\u3002","address.empty":"\u5730\u5740\u70BA\u7A7A","address.invalid_format":"\u7121\u6548\u7684\u5730\u5740\u683C\u5F0F\uFF08\u61C9\u70BA 0x + 40 \u500B\u5341\u516D\u9032\u4F4D\u5B57\u5143\uFF09","address.zero_address":"\u6B64\u70BA\u96F6\u5730\u5740 \u2014 \u8CC7\u91D1\u5C07\u6C38\u4E45\u4E1F\u5931","address.burn_address":"\u6B64\u5730\u5740\u70BA\u71D2\u6BC0\u5730\u5740 \u2014 \u8CC7\u91D1\u5C07\u6C38\u4E45\u4E1F\u5931","wallet.connect":"\u9023\u63A5\u9322\u5305","wallet.disconnect":"\u65B7\u958B\u9023\u7DDA","wallet.connecting":"\u9023\u7DDA\u4E2D...","wallet.copy_address":"\u8907\u88FD\u5730\u5740","wallet.copied":"\u5DF2\u8907\u88FD\uFF01","wallet.view_on_explorer":"\u5728\u700F\u89BD\u5668\u67E5\u770B","wallet.retry":"\u91CD\u8A66","wallet.connection_failed":"\u9023\u7DDA\u5931\u6557","wallet.scan_qr":"\u4F7F\u7528\u9322\u5305 App \u6383\u63CF","embedded.generate":"\u5EFA\u7ACB\u9322\u5305","embedded.import":"\u532F\u5165\u9322\u5305","embedded.backup_seed":"\u5099\u4EFD\u52A9\u8A18\u8A5E","embedded.backup_warning":"\u4EFB\u4F55\u4EBA\u53D6\u5F97\u60A8\u7684\u52A9\u8A18\u8A5E\u90FD\u53EF\u4EE5\u5B58\u53D6\u60A8\u7684\u8CC7\u91D1\u3002\u8ACB\u5B89\u5168\u5132\u5B58\u3002","embedded.backup_done":"\u6211\u5DF2\u5132\u5B58\u52A9\u8A18\u8A5E","embedded.wipe":"\u79FB\u9664\u9322\u5305","embedded.wipe_confirm":"\u78BA\u5B9A\u8981\u79FB\u9664\u55CE\uFF1F\u6B64\u64CD\u4F5C\u7121\u6CD5\u5FA9\u539F\u3002"},Mo={en:Gs,zh:zs},ar="en";function Lo(e){ar=e}function Bo(){return ar}function hn(e){return Mo[ar][e]??Mo.en[e]??e}function ir(e){let{isValid:t,level:o,issue:s}=(0,Fo.validateDestination)(e);return{isValid:t,level:o,warning:s?hn(`address.${s}`):null}}function Ho({address:e}){return{validation:(0,Ko.useMemo)(()=>ir(e),[e])}}function qo(){let{status:e,session:t,accounts:o,chainId:s,error:n,connect:u,disconnect:i,reconnect:g,switchChain:c}=I(),l=e==="connected",h=e==="connecting",r=e==="reconnecting",a=o[0]??null;return{status:e,session:t,accounts:o,chainId:s,error:n,isConnected:l,isConnecting:h,isReconnecting:r,isDisconnected:e==="disconnected",currentAccount:a,connect:u,disconnect:i,reconnect:g,switchChain:c}}var Ye=require("react");var lr={wallet_unavailable:"Wallet Not Detected",user_rejected:"Connection Rejected",deeplink_timeout:"Wallet Connection Timed Out",session_expired:"Session Expired",intent_expired:"Connection Request Expired",namespace_mismatch:"Network Mismatch",chain_unsupported:"Unsupported Network",method_not_allowed:"Action Not Allowed",signature_rejected:"Signature Rejected",tx_failed:"Transaction Failed"},cr={wallet_unavailable:"No wallet found. Please install a compatible wallet (e.g., MetaMask, WalletConnect) and try again.",user_rejected:"The connection request was declined in your wallet. You can try again whenever you're ready.",deeplink_timeout:"The wallet didn't respond in time. This can happen if the wallet app isn't installed or takes too long to open.",session_expired:"Your wallet session has expired. Please reconnect to continue.",intent_expired:"The connection request expired. Please try connecting again.",namespace_mismatch:"This wallet doesn't support the required network. Try using a different wallet or network.",chain_unsupported:"This network isn't supported. Please switch to a supported network in your wallet.",method_not_allowed:"This action isn't supported by your current wallet or network.",signature_rejected:"The signature request was declined in your wallet.",tx_failed:"The transaction couldn't be completed. This could be due to insufficient funds, network congestion, or a contract error."},Ut="Something went wrong",Pt="An unexpected error occurred. Please try again. If the problem persists, check your connection and wallet configuration.";function Ct(e){if(!e)return{title:Ut,description:Pt};let t=e;if(t.name==="WalletError"&&t.code){let o=t.code,s=lr[o]??Ut,n=cr[o]??t.message??Pt;return{title:s,description:n,code:o}}if(e instanceof Error){let o=e.message;return/user rejected/i.test(o)||/rejected/.test(o)?{title:"Request Rejected",description:"The request was declined.",code:"user_rejected"}:/timeout/i.test(o)||/timed? ?out/i.test(o)?{title:"Request Timed Out",description:"The request took too long. Please try again.",code:"deeplink_timeout"}:/insufficient funds/i.test(o)?{title:"Insufficient Funds",description:"You don't have enough funds to complete this transaction.",code:"tx_failed"}:/network/i.test(o)||/chain/i.test(o)?{title:"Network Error",description:o,code:"chain_unsupported"}:{title:Ut,description:o||Pt}}return typeof e=="string"?{title:Ut,description:e||Pt}:{title:Ut,description:Pt}}function yn(e){if(e===null||typeof e!="object")return!1;let t=e;return t.name!=="WalletError"||!t.code?!1:["deeplink_timeout","session_expired","intent_expired","tx_failed"].includes(t.code)}function Vo(){let{error:e,clearError:t}=I(),o=(0,Ye.useMemo)(()=>e?Ct(e):null,[e]),s=(0,Ye.useMemo)(()=>e?yn(e):!1,[e]),n=(0,Ye.useCallback)(()=>{t()},[t]),u=(0,Ye.useCallback)(g=>Ct(g),[]),i=(0,Ye.useCallback)(g=>async()=>{try{return await g()}catch(c){let l=Ct(c);if(c instanceof Error){let h=c;try{h.title=l.title,h.friendlyMessage=l.description,h.code===void 0&&l.code!==void 0&&(h.code=l.code)}catch{}throw h}throw Object.assign(new Error(l.description,{cause:c}),{title:l.title,code:l.code,friendlyMessage:l.description})}},[]);return{error:e,friendlyError:o,clearError:n,isRetryable:s,formatError:u,wrapAsync:i}}var ke=require("react"),jo=require("@naculus/connect-core"),ur=require("@naculus/connect-appkit-core");function Wt(e,t){let o=(0,ke.useRef)(null),[s,n]=(0,ke.useState)([]),[u,i]=(0,ke.useState)(t?.autoLoad!==!1),[g,c]=(0,ke.useState)(!1),[l,h]=(0,ke.useState)(null);if(!o.current){let p={};t?.sources&&(p.sources=t.sources),o.current=new jo.TokenListManager(p)}let r=(0,ke.useCallback)(async()=>{let p=o.current;if(p){i(!0),h(null);try{await p.load();let d=e?(0,ur.eip155ChainIdToNumber)(e):void 0,m=p.getTokens(d!==void 0?{chainId:d}:void 0);n(m),c(!0)}catch(d){h(d instanceof Error?d:new Error(String(d)))}finally{i(!1)}}},[e]),a=(0,ke.useCallback)(async()=>{let p=o.current;if(p){i(!0),h(null);try{await p.refresh();let d=e?(0,ur.eip155ChainIdToNumber)(e):void 0,m=p.getTokens(d!==void 0?{chainId:d}:void 0);n(m),c(!0)}catch(d){h(d instanceof Error?d:new Error(String(d)))}finally{i(!1)}}},[e]);return(0,ke.useEffect)(()=>{t?.autoLoad!==!1&&r()},[r,t?.autoLoad]),{tokens:s,isLoading:u,isLoaded:g,error:l,refetch:a}}var Je=require("react"),Go=require("@naculus/connect-core");var De=require("@naculus/connect-core");function $o(){return[{name:"built-in",tokens:[...De.ETHEREUM_MAINNET_TOKENS,...De.POLYGON_TOKENS,...De.OPTIMISM_TOKENS,...De.ARBITRUM_TOKENS,...De.BASE_TOKENS],enabled:!0},{name:"uniswap-default",url:"https://tokens.uniswap.org",enabled:!0,refreshInterval:1440*60*1e3}]}var zo=require("@naculus/connect-appkit-core"),Qs=300,Cn=null;function Xs(){return Cn||(Cn=new Go.TokenListManager({sources:$o()}),Cn.load().catch(()=>{})),Cn}function Nt(e,t){let[o,s]=(0,Je.useState)({exact:[],fuzzy:[],hasMore:!1}),[n,u]=(0,Je.useState)(!1),i=(0,Je.useRef)(null),g=e.trim();return(0,Je.useEffect)(()=>{if(!g){s({exact:[],fuzzy:[],hasMore:!1}),u(!1);return}return i.current&&clearTimeout(i.current),u(!0),i.current=setTimeout(()=>{let c=Xs(),l=t?(0,zo.eip155ChainIdToNumber)(t):void 0,h=c.search(g,{chainId:l,limit:20});s(h),u(!1)},Qs),()=>{i.current&&clearTimeout(i.current)}},[g,t]),{results:o,isSearching:n}}var St=Be(require("react"),1);var L=require("react/jsx-runtime");function pr({chainId:e,onSelect:t,onClose:o,options:s}){let[n,u]=St.default.useState(""),{tokens:i,isLoading:g,error:c}=Wt(e),{results:l,isSearching:h}=Nt(n,n?e:void 0),r=s?.showRecommendations??!0,a=St.default.useMemo(()=>{if(n.trim()){let y=[...l.exact,...l.fuzzy].map(S=>S.token);return s?.filter?y.filter(s.filter):y}let m=i;return s?.filter?m.filter(s.filter):m},[n,l,i,s?.filter]),p=St.default.useMemo(()=>!r||n.trim()?[]:i.slice(0,6),[i,r,n]),d=(0,St.useCallback)(m=>{t(m),o()},[t,o]);return(0,L.jsxs)("div",{style:{background:"hsl(var(--background))",borderRadius:"12px",padding:"16px",color:"hsl(var(--foreground))",minWidth:"320px",maxWidth:"400px",fontFamily:"system-ui, sans-serif"},children:[(0,L.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px"},children:[(0,L.jsx)("h3",{style:{margin:0,fontSize:"16px",fontWeight:600},children:"Select Token"}),(0,L.jsx)("button",{type:"button",onClick:o,style:{background:"none",border:"none",color:"hsl(var(--muted-foreground))",cursor:"pointer",fontSize:"18px",padding:"4px 8px"},children:"\u2715"})]}),(0,L.jsx)("input",{type:"text",placeholder:"Search token name or paste address",value:n,onChange:m=>u(m.target.value),style:{width:"100%",padding:"10px 12px",borderRadius:"8px",border:"1px solid #333",background:"hsl(var(--card))",color:"hsl(var(--foreground))",fontSize:"14px",outline:"none",boxSizing:"border-box",marginBottom:"12px"},autoFocus:!0}),g&&!h&&(0,L.jsx)("div",{style:{textAlign:"center",padding:"20px",color:"hsl(var(--muted-foreground))"},children:"Loading tokens..."}),c&&(0,L.jsxs)("div",{style:{textAlign:"center",padding:"12px",color:"hsl(var(--destructive))",fontSize:"13px"},children:["Error: ",c.message]}),r&&p.length>0&&!n.trim()&&(0,L.jsxs)("div",{style:{marginBottom:"12px"},children:[(0,L.jsx)("div",{style:{fontSize:"11px",color:"hsl(var(--muted-foreground))",textTransform:"uppercase",letterSpacing:"0.5px",marginBottom:"8px"},children:"Popular"}),(0,L.jsx)("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap"},children:p.map(m=>(0,L.jsxs)("button",{type:"button",onClick:()=>d(m),style:{background:"hsl(var(--card))",border:"1px solid #333",borderRadius:"20px",padding:"6px 14px",color:"hsl(var(--foreground))",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"4px"},children:[m.logoURI?(0,L.jsx)("img",{src:m.logoURI,alt:"",style:{width:"16px",height:"16px",borderRadius:"50%"},onError:y=>{y.target.style.display="none"}}):null,m.symbol]},`${m.chainId}:${m.address}`))})]}),n.trim()&&!g&&(0,L.jsx)("div",{style:{fontSize:"11px",color:"hsl(var(--muted-foreground))",marginBottom:"8px"},children:a.length>0?(0,L.jsxs)(L.Fragment,{children:[l.exact.length," exact, ",l.fuzzy.length," fuzzy",l.hasMore?" (more available)":""]}):"No results found"}),(0,L.jsx)("div",{style:{maxHeight:"320px",overflowY:"auto",display:"flex",flexDirection:"column",gap:"2px"},children:a.map(m=>(0,L.jsxs)("button",{type:"button",onClick:()=>d(m),style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 8px",background:"transparent",border:"none",borderRadius:"8px",color:"hsl(var(--foreground))",cursor:"pointer",textAlign:"left",width:"100%",fontSize:"14px"},onMouseEnter:y=>{y.target.style.background="hsl(var(--card))"},onMouseLeave:y=>{y.target.style.background="transparent"},children:[(0,L.jsx)("div",{style:{width:"32px",height:"32px",borderRadius:"50%",background:"hsl(var(--border))",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"12px",fontWeight:600,flexShrink:0,overflow:"hidden"},children:m.logoURI?(0,L.jsx)("img",{src:m.logoURI,alt:m.symbol,style:{width:"100%",height:"100%"},onError:y=>{let S=y.target;S.style.display="none",S.parentElement.textContent=m.symbol.slice(0,2)}}):m.symbol.slice(0,2)}),(0,L.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,L.jsx)("div",{style:{fontWeight:600,fontSize:"14px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m.symbol}),(0,L.jsx)("div",{style:{fontSize:"12px",color:"hsl(var(--muted-foreground))",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m.name})]}),(0,L.jsxs)("div",{style:{fontSize:"11px",color:"#666",textAlign:"right",flexShrink:0},children:[(0,L.jsxs)("div",{children:[m.decimals," decimals"]}),(0,L.jsxs)("div",{children:["Chain ",m.chainId]})]})]},`${m.chainId}:${m.address}`))})]})}var D=require("@stencil/react-output-target/runtime"),M=Be(require("react"),1),Sn=require("@naculus/connect-appkit-wc/dist/components/appkit-accordion.js"),En=require("@naculus/connect-appkit-wc/dist/components/appkit-account-button.js"),wn=require("@naculus/connect-appkit-wc/dist/components/appkit-alert-dialog.js"),kn=require("@naculus/connect-appkit-wc/dist/components/appkit-avatar.js"),xn=require("@naculus/connect-appkit-wc/dist/components/appkit-badge.js"),vn=require("@naculus/connect-appkit-wc/dist/components/appkit-button.js"),An=require("@naculus/connect-appkit-wc/dist/components/appkit-card-content.js"),bn=require("@naculus/connect-appkit-wc/dist/components/appkit-card-description.js"),Rn=require("@naculus/connect-appkit-wc/dist/components/appkit-card-footer.js"),Tn=require("@naculus/connect-appkit-wc/dist/components/appkit-card-header.js"),In=require("@naculus/connect-appkit-wc/dist/components/appkit-card-title.js"),Un=require("@naculus/connect-appkit-wc/dist/components/appkit-card.js"),Pn=require("@naculus/connect-appkit-wc/dist/components/appkit-checkbox.js"),Wn=require("@naculus/connect-appkit-wc/dist/components/appkit-collapsible.js"),Nn=require("@naculus/connect-appkit-wc/dist/components/appkit-connect-button.js"),On=require("@naculus/connect-appkit-wc/dist/components/appkit-dialog.js"),_n=require("@naculus/connect-appkit-wc/dist/components/appkit-dropdown-menu.js"),Dn=require("@naculus/connect-appkit-wc/dist/components/appkit-input.js"),Mn=require("@naculus/connect-appkit-wc/dist/components/appkit-popover.js"),Ln=require("@naculus/connect-appkit-wc/dist/components/appkit-progress.js"),Bn=require("@naculus/connect-appkit-wc/dist/components/appkit-scroll-area.js"),Fn=require("@naculus/connect-appkit-wc/dist/components/appkit-select.js"),Kn=require("@naculus/connect-appkit-wc/dist/components/appkit-separator.js"),Hn=require("@naculus/connect-appkit-wc/dist/components/appkit-skeleton.js"),qn=require("@naculus/connect-appkit-wc/dist/components/appkit-switch.js"),Vn=require("@naculus/connect-appkit-wc/dist/components/appkit-tabs.js"),jn=require("@naculus/connect-appkit-wc/dist/components/appkit-toggle-group.js"),$n=require("@naculus/connect-appkit-wc/dist/components/appkit-tooltip.js"),Qo=(0,D.createComponent)({tagName:"appkit-accordion",elementClass:Sn.AppkitAccordion,react:M.default,events:{onAppkitToggle:"appkitToggle"},defineCustomElement:Sn.defineCustomElement}),Xo=(0,D.createComponent)({tagName:"appkit-account-button",elementClass:En.AppkitAccountButton,react:M.default,events:{},defineCustomElement:En.defineCustomElement}),Yo=(0,D.createComponent)({tagName:"appkit-alert-dialog",elementClass:wn.AppkitAlertDialog,react:M.default,events:{onAppkitClose:"appkitClose",onAppkitOpenChange:"appkitOpenChange"},defineCustomElement:wn.defineCustomElement}),Jo=(0,D.createComponent)({tagName:"appkit-avatar",elementClass:kn.AppkitAvatar,react:M.default,events:{},defineCustomElement:kn.defineCustomElement}),Zo=(0,D.createComponent)({tagName:"appkit-badge",elementClass:xn.AppkitBadge,react:M.default,events:{},defineCustomElement:xn.defineCustomElement}),es=(0,D.createComponent)({tagName:"appkit-button",elementClass:vn.AppkitButton,react:M.default,events:{},defineCustomElement:vn.defineCustomElement}),ts=(0,D.createComponent)({tagName:"appkit-card",elementClass:Un.AppkitCard,react:M.default,events:{},defineCustomElement:Un.defineCustomElement}),ns=(0,D.createComponent)({tagName:"appkit-card-content",elementClass:An.AppkitCardContent,react:M.default,events:{},defineCustomElement:An.defineCustomElement}),rs=(0,D.createComponent)({tagName:"appkit-card-description",elementClass:bn.AppkitCardDescription,react:M.default,events:{},defineCustomElement:bn.defineCustomElement}),os=(0,D.createComponent)({tagName:"appkit-card-footer",elementClass:Rn.AppkitCardFooter,react:M.default,events:{},defineCustomElement:Rn.defineCustomElement}),ss=(0,D.createComponent)({tagName:"appkit-card-header",elementClass:Tn.AppkitCardHeader,react:M.default,events:{},defineCustomElement:Tn.defineCustomElement}),as=(0,D.createComponent)({tagName:"appkit-card-title",elementClass:In.AppkitCardTitle,react:M.default,events:{},defineCustomElement:In.defineCustomElement}),is=(0,D.createComponent)({tagName:"appkit-checkbox",elementClass:Pn.AppkitCheckbox,react:M.default,events:{onAppkitChange:"appkitChange"},defineCustomElement:Pn.defineCustomElement}),ls=(0,D.createComponent)({tagName:"appkit-collapsible",elementClass:Wn.AppkitCollapsible,react:M.default,events:{onAppkitToggle:"appkitToggle"},defineCustomElement:Wn.defineCustomElement}),cs=(0,D.createComponent)({tagName:"appkit-connect-button",elementClass:Nn.AppkitConnectButton,react:M.default,events:{onAppkitConnect:"appkitConnect",onAppkitDisconnect:"appkitDisconnect",onAppkitStartPairing:"appkitStartPairing",onAppkitRetry:"appkitRetry",onAppkitCancelPairing:"appkitCancelPairing",onAppkitMobileDeepLink:"appkitMobileDeepLink",onAppkitCopyAddress:"appkitCopyAddress"},defineCustomElement:Nn.defineCustomElement}),us=(0,D.createComponent)({tagName:"appkit-dialog",elementClass:On.AppkitDialog,react:M.default,events:{onAppkitClose:"appkitClose",onAppkitOpenChange:"appkitOpenChange"},defineCustomElement:On.defineCustomElement}),ps=(0,D.createComponent)({tagName:"appkit-dropdown-menu",elementClass:_n.AppkitDropdownMenu,react:M.default,events:{onAppkitSelect:"appkitSelect"},defineCustomElement:_n.defineCustomElement}),ds=(0,D.createComponent)({tagName:"appkit-input",elementClass:Dn.AppkitInput,react:M.default,events:{onAppkitChange:"appkitChange"},defineCustomElement:Dn.defineCustomElement}),ms=(0,D.createComponent)({tagName:"appkit-popover",elementClass:Mn.AppkitPopover,react:M.default,events:{onAppkitOpenChange:"appkitOpenChange"},defineCustomElement:Mn.defineCustomElement}),fs=(0,D.createComponent)({tagName:"appkit-progress",elementClass:Ln.AppkitProgress,react:M.default,events:{},defineCustomElement:Ln.defineCustomElement}),gs=(0,D.createComponent)({tagName:"appkit-scroll-area",elementClass:Bn.AppkitScrollArea,react:M.default,events:{},defineCustomElement:Bn.defineCustomElement}),hs=(0,D.createComponent)({tagName:"appkit-select",elementClass:Fn.AppkitSelect,react:M.default,events:{onAppkitChange:"appkitChange"},defineCustomElement:Fn.defineCustomElement}),ys=(0,D.createComponent)({tagName:"appkit-separator",elementClass:Kn.AppkitSeparator,react:M.default,events:{},defineCustomElement:Kn.defineCustomElement}),Cs=(0,D.createComponent)({tagName:"appkit-skeleton",elementClass:Hn.AppkitSkeleton,react:M.default,events:{},defineCustomElement:Hn.defineCustomElement}),Ss=(0,D.createComponent)({tagName:"appkit-switch",elementClass:qn.AppkitSwitch,react:M.default,events:{onAppkitChange:"appkitChange"},defineCustomElement:qn.defineCustomElement}),Es=(0,D.createComponent)({tagName:"appkit-tabs",elementClass:Vn.AppkitTabs,react:M.default,events:{onAppkitTabChange:"appkitTabChange"},defineCustomElement:Vn.defineCustomElement}),ws=(0,D.createComponent)({tagName:"appkit-toggle-group",elementClass:jn.AppkitToggleGroup,react:M.default,events:{onAppkitChange:"appkitChange"},defineCustomElement:jn.defineCustomElement}),ks=(0,D.createComponent)({tagName:"appkit-tooltip",elementClass:$n.AppkitTooltip,react:M.default,events:{},defineCustomElement:$n.defineCustomElement});0&&(module.exports={AppkitAccordion,AppkitAccountButton,AppkitAlertDialog,AppkitAvatar,AppkitBadge,AppkitButton,AppkitCard,AppkitCardContent,AppkitCardDescription,AppkitCardFooter,AppkitCardHeader,AppkitCardTitle,AppkitCheckbox,AppkitCollapsible,AppkitConnectButton,AppkitDialog,AppkitDropdownMenu,AppkitInput,AppkitPopover,AppkitProgress,AppkitScrollArea,AppkitSelect,AppkitSeparator,AppkitSkeleton,AppkitSwitch,AppkitTabs,AppkitToggleGroup,AppkitTooltip,DEFAULT_EVM_CHAINS,LAMPORTS_PER_SOL,PassphraseCancelledError,PassphraseGate,SolanaRpcError,TokenSelector,TxMonitorContext,WALLET_ERROR_DESCRIPTIONS,WALLET_ERROR_TITLES,Web3ConnectProvider,Web3Context,buildDelegationPolicyMessage,clearClient,createClient,formatSol,getChainById,getClient,getDefaultChains,getLatestBlockhash,getLocale,getSignatureStatus,getSolanaBalance,getUserFriendlyError,isRetryableError,parseSol,resetSessionKeyManager,setLocale,t,useAccount,useBalance,useCapabilities,useChain,useCompareCosts,useConnect,useCreateSessionKey,useDelegate,useDelegation,useDelegationPolicy,useDisconnect,useERC20Allowance,useERC20Approve,useERC20Transfer,useERC20TransferSimulation,useEmbeddedWallet,useExecuteCalls,useExecuteRoute,useLastTx,useLookupAddress,useNotification,usePassphraseGate,usePaymentFetch,useResolveName,useRevokeSession,useRouteQuote,useSIWxLogin,useSIWxSession,useSendCalls,useSendTransaction,useSendUserOperation,useSendWithSession,useSession,useSessionKeys,useSignInWithEthereum,useSignInWithX,useSignMessage,useSimulateTransfer,useSiwxAuthSession,useSmartAccount,useSolanaAccount,useSolanaBalance,useSolanaRoles,useSolanaSessionKey,useSolanaTransaction,useSwitchChain,useTokenBalance,useTokenList,useTokenSearch,useTransactionSimulation,useTxHistory,useTxMonitor,useUserOpStatus,useValidateDestination,useViemClient,useWallet,useWeb3,useWeb3ErrorHandler,validateDestination});
1
+ "use strict";var Rs=Object.create;var Dt=Object.defineProperty;var Ts=Object.getOwnPropertyDescriptor;var Is=Object.getOwnPropertyNames;var Us=Object.getPrototypeOf,Ps=Object.prototype.hasOwnProperty;var Ws=(e,t)=>{for(var o in t)Dt(e,o,{get:t[o],enumerable:!0})},fr=(e,t,o,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Is(t))!Ps.call(e,n)&&n!==o&&Dt(e,n,{get:()=>t[n],enumerable:!(s=Ts(t,n))||s.enumerable});return e};var Ke=(e,t,o)=>(o=e!=null?Rs(Us(e)):{},fr(t||!e||!e.__esModule?Dt(o,"default",{value:e,enumerable:!0}):o,e)),Ns=e=>fr(Dt({},"__esModule",{value:!0}),e);var ta={};Ws(ta,{AppkitAccordion:()=>Zo,AppkitAccountButton:()=>es,AppkitAlertDialog:()=>ts,AppkitAvatar:()=>ns,AppkitBadge:()=>rs,AppkitButton:()=>os,AppkitCard:()=>ss,AppkitCardContent:()=>as,AppkitCardDescription:()=>is,AppkitCardFooter:()=>ls,AppkitCardHeader:()=>cs,AppkitCardTitle:()=>us,AppkitCheckbox:()=>ps,AppkitCollapsible:()=>ds,AppkitConnectButton:()=>ms,AppkitDialog:()=>fs,AppkitDropdownMenu:()=>gs,AppkitInput:()=>hs,AppkitPopover:()=>ys,AppkitProgress:()=>Cs,AppkitScrollArea:()=>Ss,AppkitSelect:()=>Es,AppkitSeparator:()=>ws,AppkitSkeleton:()=>ks,AppkitSwitch:()=>xs,AppkitTabs:()=>vs,AppkitToggleGroup:()=>bs,AppkitTooltip:()=>As,DEFAULT_EVM_CHAINS:()=>Zn,LAMPORTS_PER_SOL:()=>Z.LAMPORTS_PER_SOL,PassphraseCancelledError:()=>Z.PassphraseCancelledError,PassphraseGate:()=>Z.PassphraseGate,SolanaRpcError:()=>Z.SolanaRpcError,TokenSelector:()=>mr,TxMonitorContext:()=>tr,WALLET_ERROR_DESCRIPTIONS:()=>pr,WALLET_ERROR_TITLES:()=>ur,Web3ConnectProvider:()=>vr,Web3Context:()=>Ht,buildDelegationPolicyMessage:()=>er.buildDelegationPolicyMessage,clearClient:()=>Sr,createClient:()=>Lt,formatSol:()=>Z.formatSol,getChainById:()=>xr,getClient:()=>Bt,getDefaultChains:()=>Kt,getLatestBlockhash:()=>Z.getLatestBlockhash,getLocale:()=>qo,getSignatureStatus:()=>Z.getSignatureStatus,getSolanaBalance:()=>Z.getSolanaBalance,getUserFriendlyError:()=>Et,isRetryableError:()=>Sn,parseSol:()=>Z.parseSol,resetSessionKeyManager:()=>jr,setLocale:()=>Ho,t:()=>Cn,useAccount:()=>K,useBalance:()=>Tr,useCapabilities:()=>qt,useChain:()=>ce,useCompareCosts:()=>Qn,useConnect:()=>Ur,useCreateSessionKey:()=>Hr,useDelegate:()=>Wr,useDelegation:()=>it,useDelegationPolicy:()=>Gr,useDisconnect:()=>zr,useERC20Allowance:()=>Zr,useERC20Approve:()=>eo,useERC20Transfer:()=>to,useERC20TransferSimulation:()=>so,useEmbeddedWallet:()=>Qr,useExecuteCalls:()=>Xt,useExecuteRoute:()=>Xn,useLastTx:()=>io,useLookupAddress:()=>uo,useMppSession:()=>Dr,useNotification:()=>mo,usePassphraseGate:()=>go,usePaymentFetch:()=>Or,useResolveName:()=>yo,useRevokeSession:()=>qr,useRouteQuote:()=>Yn,useSIWxLogin:()=>un,useSIWxSession:()=>Eo,useSendCalls:()=>zt,useSendTransaction:()=>dt,useSendUserOperation:()=>Co,useSendWithSession:()=>Vr,useSession:()=>So,useSessionKeys:()=>Jt,useSignInWithEthereum:()=>wo,useSignInWithX:()=>ht,useSignMessage:()=>en,useSimulateTransfer:()=>vo,useSiwxAuthSession:()=>bo,useSmartAccount:()=>Ro,useSolanaAccount:()=>hn,useSolanaBalance:()=>Uo,useSolanaRoles:()=>No,useSolanaSessionKey:()=>Br,useSolanaTransaction:()=>_o,useSwitchChain:()=>Mo,useTokenBalance:()=>Lo,useTokenList:()=>Ot,useTokenSearch:()=>_t,useTransactionSimulation:()=>on,useTxHistory:()=>Bo,useTxMonitor:()=>ao,useUserOpStatus:()=>Fo,useValidateDestination:()=>$o,useViemClient:()=>ue,useWallet:()=>Go,useWeb3:()=>I,useWeb3ErrorHandler:()=>zo,validateDestination:()=>cr});module.exports=Ns(ta);var Z=require("@naculus/connect-core");var gr=require("@naculus/connect-appkit-core"),me=require("react");function Qn(e,t){let{operation:o,chains:s,options:n}=e,[u,i]=(0,me.useState)([]),[g,l]=(0,me.useState)(!1),[c,h]=(0,me.useState)(null),r=(0,me.useRef)(!0),a=(0,me.useRef)(0),p=(0,gr.compareCostsKey)(e),d=(0,me.useCallback)(async()=>{if(!s||s.length===0){i([]);return}if(!t)return;let y=++a.current;l(!0),h(null);try{let S=await t(o,s,n);r.current&&y===a.current&&i(S)}catch(S){r.current&&y===a.current&&(h(S instanceof Error?S:new Error(String(S))),i([]))}finally{r.current&&y===a.current&&l(!1)}},[p,t]);(0,me.useEffect)(()=>{d()},[d]),(0,me.useEffect)(()=>(r.current=!0,()=>{r.current=!1}),[]);let m=(0,me.useCallback)(async()=>{await d()},[d]);return{comparisons:u,loading:g,error:c,refresh:m}}var Mt=require("@naculus/connect-appkit-core"),Ce=require("react");function Xn(e){let[t,o]=(0,Ce.useState)(!1),[s,n]=(0,Ce.useState)(null),[u,i]=(0,Ce.useState)(null),g=(0,Ce.useRef)(!0),l=(0,Ce.useRef)(!1);(0,Ce.useEffect)(()=>(g.current=!0,()=>{g.current=!1}),[]);let c=(0,Ce.useCallback)(async(r,a,p)=>{if(!e)return i({code:"no_executor",message:"No executeRoute function provided"}),n(null),null;let d=(0,Mt.validateRouteRecipient)(r,a);if(d)return i(d),n(null),null;if(l.current)return i({code:"execution_in_progress",message:"A route execution is already in progress"}),null;l.current=!0,o(!0),i(null),n(null);try{let m=await e(r,a,p);return g.current&&n(m),m}catch(m){return g.current&&i((0,Mt.toExecuteRouteError)(m)),null}finally{l.current=!1,g.current&&o(!1)}},[e]),h=(0,Ce.useCallback)(()=>{n(null),i(null),o(!1)},[]);return{execute:c,executing:t,result:s,error:u,reset:h}}var hr=require("@naculus/connect-appkit-core"),le=require("react");function Yn(e,t){let{fromChain:o,toChain:s,fromToken:n,toToken:u,amount:i,options:g}=e,[l,c]=(0,le.useState)([]),[h,r]=(0,le.useState)(!1),[a,p]=(0,le.useState)(null),d=(0,le.useRef)(null),m=(0,le.useRef)(!0),y=(0,le.useCallback)(async()=>{if(!(0,hr.isQuotableInput)({fromChain:o,toChain:s,fromToken:n,amount:i})){c([]);return}if(t){r(!0),p(null);try{let C=await t(o,s,n,i,g,u);m.current&&c(C)}catch(C){m.current&&(p(C instanceof Error?C:new Error(String(C))),c([]))}finally{m.current&&r(!1)}}},[o,s,n,u,i,g,t]);(0,le.useEffect)(()=>{if(d.current&&clearTimeout(d.current),!o||!s||!n||!i){c([]);return}return d.current=setTimeout(()=>{y()},300),()=>{d.current&&clearTimeout(d.current)}},[y,o,s,n,i]),(0,le.useEffect)(()=>(m.current=!0,()=>{m.current=!1}),[]);let S=(0,le.useCallback)(async()=>{await y()},[y]),v=(0,le.useCallback)(()=>{c([]),p(null),r(!1)},[]);return{quotes:l,loading:h,error:a,refresh:S,clear:v}}var Y=require("@naculus/connect-core"),te=require("@naculus/connector-evm-injected"),yr=require("@naculus/connect-core"),Cr=require("@naculus/connector-walletconnect"),Jn=null;function Lt(e){let t=null,o=(0,Cr.createWalletConnectConnector)({projectId:e.projectId,metadata:e.metadata,...e.walletConnect?.client?{client:e.walletConnect.client}:{},...e.walletConnect?.openUrl?{openUrl:e.walletConnect.openUrl}:{}}),s=null,n=null,u=null,i=null,g=e.passphrasePrompt&&e.enableEmbedded&&!e.embeddedConfig?.encryptionPassphrase?new yr.PassphraseGate:null;e.enableEmbedded&&(n=import("@naculus/connector-embedded").then(r=>{let a={...e.embeddedConfig};g&&(a.encryptionPassphrase=g.request),e.enablePasskeys&&a.encryptionPassphrase&&!a.prfUnlock&&(a.prfUnlock={async derive(d){i&&await i;let m=u;return m?.hasCredential()?m.derivePrfKey(d):null}}),s=r.createPocketConnector(a),t?._setEmbeddedConnector(s)}).catch(r=>{Y.logger.warn("react/client","Embedded wallet connector not available:",r),s=null})),e.enablePasskeys&&(i=import("@naculus/connector-passkeys").then(r=>{u=r.createPasskeysConnector(),t?._setPasskeysConnector(u)}).catch(r=>{Y.logger.warn("react/client","Passkeys connector not available:",r),u=null}));let l=null,c=null;e.enableSolana&&(c=import("@naculus/connector-solana").then(r=>{let a=r.solanaConnector;e.solanaDefaultChain&&"configure"in a&&a.configure({defaultChain:e.solanaDefaultChain}),l=a,typeof window<"u"&&"startDiscovery"in a&&a.startDiscovery();for(let p of e.solanaWallets??[])a.registerWallet?.(p);t?._setSolanaConnector(l)}).catch(r=>{Y.logger.warn("react/client","Solana connector not available:",r),l=null})),typeof window<"u"&&te.eip6963Connector.startDiscovery();for(let{info:r,provider:a}of e.injectedProviders??[])te.eip6963Connector.registerProvider(r,a);let h={connector:o,get embeddedConnector(){return s},getEmbeddedConnector:async()=>(n&&await n,s),get passkeysConnector(){return u},passphraseGate:g,solanaRpcUrl:e.solanaRpcUrl??null,get solanaConnector(){return l},connect:()=>o.connect(),connectInjected:async r=>te.eip6963Connector.connect(r),connectEmbedded:async()=>{if(n&&await n,!s)throw new Error("Embedded wallet not enabled. Set enableEmbedded: true in config.");return s.connect()},connectPasskeys:async()=>{if(i&&await i,!u)throw new Error("Passkeys connector not enabled. Set enablePasskeys: true in config.");return u.connect()},startPairing:()=>o.startPairing(),completePairing:()=>o.completePairing(),cancelPairing:()=>o.cancelPairing?.(),signMessage:async(r,a)=>{if(r.id?.startsWith("eip6963-"))return te.eip6963Connector.signMessage(r,a);if(r.walletType==="passkeys"&&u)return u.signMessage(r,a);if(r.walletType==="embedded"){if(!s)throw new Y.WalletError("wallet_unavailable","Embedded wallet connector not available.");return s.signMessage(r,a)}if(r.walletType==="solana"){if(c&&await c,l)return l.signMessage(r,a);throw new Y.WalletError("wallet_unavailable","Solana connector not available. Ensure enableSolana is true and @naculus/connector-solana is installed.")}return o.signMessage(r,a)},signTransaction:async(r,a)=>{if(r.id?.startsWith("eip6963-"))return te.eip6963Connector.signTransaction(r,a);if(r.walletType==="embedded"){if(!s)throw new Y.WalletError("wallet_unavailable","Embedded wallet connector not available.");return s.signTransaction(r,a)}if(r.walletType==="solana"){if(c&&await c,l)return l.signTransaction(r,a);throw new Y.WalletError("wallet_unavailable","Solana connector not available. Ensure enableSolana is true and @naculus/connector-solana is installed.")}return o.signTransaction(r,a)},sendTransaction:async(r,a)=>{if(r.id?.startsWith("eip6963-"))return te.eip6963Connector.sendTransaction(r,a);if(r.walletType==="passkeys"&&u)return u.sendTransaction(r,a);if(r.walletType==="embedded"){if(!s)throw new Y.WalletError("wallet_unavailable","Embedded wallet connector not available.");return s.sendTransaction(r,a)}if(r.walletType==="solana"){if(c&&await c,l)return l.sendTransaction(r,a);throw new Y.WalletError("wallet_unavailable","Solana connector not available. Ensure enableSolana is true and @naculus/connector-solana is installed.")}return o.sendTransaction(r,a)},onAccountsChanged:(r,a)=>{let p=()=>{};return r.id?.startsWith("eip6963-")?te.eip6963Connector.onAccountsChanged?.(r,a)??p:r.walletType==="embedded"?s?.onAccountsChanged?.(r,a)??p:r.walletType==="passkeys"?p:r.walletType==="solana"?l?.onAccountsChanged?.(r,a)??p:o.onAccountsChanged?.(r,a)??p},onChainChanged:(r,a)=>{let p=()=>{};return r.id?.startsWith("eip6963-")?te.eip6963Connector.onChainChanged?.(r,a)??p:r.walletType==="passkeys"||r.walletType==="embedded"?p:r.walletType==="solana"?l?.onChainChanged?.(r,a)??p:o.onChainChanged?.(r,a)??p},getCapabilities:r=>r.id?.startsWith("eip6963-")?te.eip6963Connector.getCapabilities?.(r):r.walletType==="passkeys"?u?.getCapabilities?.(r):r.walletType==="solana"?l?.getCapabilities?.(r):r.walletType==="embedded"?s?.getCapabilities?.(r):o.getCapabilities?.(r),sendCalls:async(r,a,p,d)=>{if(r.id?.startsWith("eip6963-"))return te.eip6963Connector.sendCalls(r,a,p,d);if(r.walletType==="passkeys"&&u)return u.sendCalls(r,a,p,d);if(r.walletType==="solana"){if(c&&await c,l)return l.sendCalls(r,a,p,d);throw new Y.WalletError("wallet_unavailable","Solana connector not available. Ensure enableSolana is true and @naculus/connector-solana is installed.")}if(r.walletType==="embedded"){if(!s?.sendCalls)throw new Y.WalletError("method_not_allowed","Embedded wallet does not support sendCalls");return s.sendCalls(r,a,p,d)}if(!o.sendCalls)throw new Y.WalletError("method_not_allowed","sendCalls not supported by this connector");return o.sendCalls(r,a,p,d)},showCallsStatus:async(r,a)=>{if(r.id?.startsWith("eip6963-"))return te.eip6963Connector.showCallsStatus(r,a);if(r.walletType==="passkeys"||r.walletType==="embedded")throw new Y.WalletError("method_unsupported",`${r.walletType} wallets have no UI to display a call bundle.`);if(!o.showCallsStatus)throw new Y.WalletError("method_unsupported","This connector cannot display call status.");return o.showCallsStatus(r,a)},getCallsStatus:async(r,a)=>{if(r.id?.startsWith("eip6963-")&&te.eip6963Connector.getCallsStatus)return te.eip6963Connector.getCallsStatus(r,a);if(r.walletType==="passkeys"&&u?.getCallsStatus)return u.getCallsStatus(r,a);if(r.walletType==="embedded")throw new Y.WalletError("method_not_allowed","Embedded wallet does not support getCallsStatus");if(!o.getCallsStatus)throw new Y.WalletError("method_not_allowed","getCallsStatus not supported by this connector");return o.getCallsStatus(r,a)},reconnect:async r=>r.walletType==="eip6963"?te.eip6963Connector.reconnect(r):r.walletType==="embedded"?s?s.reconnect(r):r:r.walletType==="solana"?r:o.reconnect(r),disconnect:async r=>{if(r.id?.startsWith("eip6963-")||r.walletType==="eip6963")return te.eip6963Connector.disconnect(r);if(r.walletType==="embedded"&&s)return s.disconnect();if(r.walletType==="passkeys"&&u)return u.disconnect(r);if(r.walletType==="solana"){if(c&&await c,l)return l.disconnect(r);throw new Y.WalletError("wallet_unavailable","Solana connector not available. Ensure enableSolana is true and @naculus/connector-solana is installed.")}return o.disconnect(r)},getAllConnectors:()=>{let r=[o];return s&&r.push(s),u&&r.push(u),l&&r.push(l),r},_setEmbeddedConnector:r=>{s=r},_setPasskeysConnector:r=>{u=r},_setSolanaConnector:r=>{l=r}};return t=h,Jn=h,h}function Bt(){return Jn}function Sr(){Jn=null}var vt=require("@naculus/connect-core"),Ar=require("react");var ee=require("@naculus/connect-core"),xt=require("@naculus/connector-evm-injected"),O=require("react");var Er=require("@naculus/connect-core"),Ft=require("@naculus/siwx");function tt(e,t){let o=t.split(":",1)[0],n=(e.namespaces[o]?.accounts??[]).filter(u=>u.startsWith(`${o}:`)).map(u=>({namespace:o,caip10:u}))[0];if(n)return{...n,address:n.caip10.split(":").pop()??n.caip10}}function Os(e){return e.namespaces.eip155?.chains?.[0]??e.namespaces.solana?.chains?.[0]??e.namespaces.xrpl?.chains?.[0]??"eip155:1"}async function wr(e){let{session:t,siwx:o,signMessage:s}=e;if(!o||!t)return{kind:"skipped"};try{let n=Os(t),u=tt(t,n);if(!u)throw new Error("No account found in session");let{address:i}=u,g=await o.createMessage({address:i,chainId:n}),l=(0,Ft.parseSiwxMessage)(g);if(!l?.nonce)throw new Error("SIWx message must contain a nonce");await(0,Ft.issueNonce)(l.nonce);let c=await s(t,{message:g,address:i,chainId:n});return await o.handleSignComplete?.({message:g,signature:c}),{kind:"authenticated",address:i,chainId:n}}catch(n){let u=n instanceof Error?n:new Error("Wallet authentication failed");return Er.logger.error("appkit/core","SIWx authentication failed:",n),{kind:"failed",error:u,fatal:o.required!==!1}}}var Be=require("@naculus/connect-appkit-core");var kr=require("@naculus/connect-appkit-core"),be=require("@naculus/connect-core"),_s=[{caip2:"eip155:5",name:"Goerli",rpcUrl:"https://goerli.blockpi.network/v1/rpc/public",explorerUrl:"https://goerli.etherscan.io",token:"ETH"},{caip2:"eip155:80001",name:"Mumbai",rpcUrl:"https://rpc-mumbai.maticvigil.com",explorerUrl:"https://mumbai.polygonscan.com",token:"MATIC"},{caip2:"eip155:421613",name:"Arbitrum Goerli",rpcUrl:"https://goerli-rollup.arbitrum.io/rpc",explorerUrl:"https://goerli.arbiscan.io",token:"ETH"},{caip2:"eip155:420",name:"Optimism Goerli",rpcUrl:"https://goerli.optimism.io",explorerUrl:"https://goerli-optimism.etherscan.io",token:"ETH"}];function Ds(e){let t=be.CHAINS[e];if(!t||!t.explorerUrl)return null;let o=t.caip2Id;return{caip2:o,name:t.name,rpcUrl:(0,be.getRpcUrl)(o,be.DEFAULT_RPC_URLS[o]??""),explorerUrl:t.explorerUrl,token:t.nativeCurrency.symbol}}function Ms(){if(!be.CHAINS)return[];let e=[],t=Object.keys(be.CHAINS).map(Number).sort((o,s)=>o-s);for(let o of t){let s=Ds(o);s&&e.push(s)}for(let o of _s){let s=(0,be.eip155Reference)(o.caip2);(s===null||!be.CHAINS[s])&&e.push(o)}return e}var Zn=Ms();function xr(e,t){return(0,kr.resolveChain)(e,t)??void 0}function Kt(){return[...Zn]}var br=require("react/jsx-runtime"),Ht=(0,O.createContext)(null);function vr({children:e,config:t,autoConnect:o=!0}){let[s,n]=(0,O.useReducer)(Be.web3Reducer,Be.initialWeb3State),u=(0,O.useMemo)(()=>t.chains??Kt(),[t.chains]),i=t.connectionTimeout??3e4,g=t.maxRetries??2,l=(0,O.useMemo)(()=>t.sessionStorage??new ee.LocalStorageSessionStorage(t.storageKey??"naculus_web3_session",t.encryptionKey),[t.sessionStorage,t.storageKey,t.encryptionKey]),c=(0,O.useMemo)(()=>Lt({projectId:t.projectId,metadata:t.metadata,enableEmbedded:t.enableEmbedded,embeddedConfig:t.embeddedConfig,enablePasskeys:t.enablePasskeys,enableSolana:t.enableSolana,solanaDefaultChain:t.solanaDefaultChain,walletConnect:t.walletConnect,solanaWallets:t.solanaWallets,injectedProviders:t.injectedProviders}),[t.projectId,t.metadata,t.enableEmbedded,t.embeddedConfig,t.enablePasskeys,t.enableSolana,t.solanaDefaultChain,t.walletConnect,t.solanaWallets,t.injectedProviders]),h=(0,O.useRef)(null),r=(0,O.useRef)(null),a=(0,O.useMemo)(()=>{let f=(0,ee.createConnectorManager)();for(let N of[xt.eip6963Connector,...c.getAllConnectors()])f.register(N.id,N);let E={},w={};for(let N of u){let j=N.caip2;N.rpcUrl&&(E[j]=N.rpcUrl),N.token&&(w[j]={name:N.name,symbol:N.token,decimals:18})}let U=(0,ee.createSessionManager)(f,{autoRefreshFeeOnSwitch:t.autoRefreshFeeOnSwitch??!0,defaultRpcUrls:E,defaultCurrencies:w,encryptionKey:t.encryptionKey});return h.current=U,U},[c,u,t.autoRefreshFeeOnSwitch,t.encryptionKey]);(0,O.useEffect)(()=>{let f=j=>{let{walletSession:je}=j.bundle;n({type:"SET_SESSION",payload:je});let de=[];Object.values(je.namespaces).forEach(kt=>{de.push(...kt.accounts)}),n({type:"SET_ACCOUNTS",payload:de}),n({type:"SET_CHAIN",payload:j.bundle.activeChainId}),n({type:"SET_STATUS",payload:"connected"})},E=()=>{n({type:"RESET"})},w=j=>{n({type:"SET_CHAIN",payload:j.newChainId})},U=j=>f(j),N=()=>{l.clear(),n({type:"RESET"})};return a.on("sessionConnected",f),a.on("sessionDisconnected",E),a.on("chainChanged",w),a.on("sessionScopeChanged",U),a.on("sessionRevoked",N),()=>{a.off("sessionConnected",f),a.off("sessionDisconnected",E),a.off("chainChanged",w),a.off("sessionScopeChanged",U),a.off("sessionRevoked",N)}},[a,l]),(0,O.useEffect)(()=>{let f=()=>{l.clear(),n({type:"RESET"})};c.connector.onSessionExpiry(f)},[c,l]);let p=(0,O.useCallback)(()=>{for(let f of[xt.eip6963Connector,...c.getAllConnectors()])a.registerConnector(f)},[c,a]),d=(0,O.useCallback)(async f=>{p();let E=[xt.eip6963Connector,...c.getAllConnectors()].find(U=>U.id===f.walletType||U.kind===f.walletType);E&&!f.connectorId&&(f.connectorId=E.id);let w=f.namespaces.eip155?.chains?.[0]??f.namespaces.solana?.chains?.[0]??f.namespaces.xrpl?.chains?.[0];w&&await a.attach(f,w)},[c,a,p]),m=(0,O.useCallback)(f=>{if(n({type:"SET_SESSION",payload:f}),f){let E=[];Object.values(f.namespaces).forEach(j=>{E.push(...j.accounts)}),n({type:"SET_ACCOUNTS",payload:E});let w=f.namespaces.eip155?.chains?.[0],U=f.namespaces.solana?.chains?.[0],N=f.namespaces.xrpl?.chains?.[0];n({type:"SET_CHAIN",payload:w??U??N??null})}else n({type:"SET_ACCOUNTS",payload:[]}),n({type:"SET_CHAIN",payload:null})},[]);(0,O.useEffect)(()=>{let f=s.session,E=c;return!f||!E?.onAccountsChanged?void 0:E.onAccountsChanged(f,U=>{if(U.length===0){l.clear().finally(()=>n({type:"RESET"}));return}m(f),l.save(f)})},[s.session,c,l,m]),(0,O.useEffect)(()=>{let f=s.session,E=c;if(!(!f||!E?.onChainChanged))return E.onChainChanged(f,w=>{m(f),l.save(f);let U=a.syncExternalChain;if(!U)return;let N=U.call(a,w).catch(j=>{ee.logger.warn("react/provider","External chain sync error:",j)});r.current=N,N.finally(()=>{r.current===N&&(r.current=null)})})},[s.session,c,l,m,a]);let y=(0,O.useCallback)(async f=>{if(!t.siwx||!f)return!0;n({type:"SET_STATUS",payload:"authenticating"});let E=await wr({session:f,siwx:t.siwx,signMessage:(w,U)=>c.signMessage(w,U)});return E.kind==="failed"&&E.fatal?(await l.clear(),n({type:"RESET"}),n({type:"SET_ERROR",payload:E.error}),!1):!0},[t.siwx,c,l]),S=(0,O.useCallback)(async()=>{n({type:"SET_STATUS",payload:"connecting"}),n({type:"SET_ERROR",payload:null});try{let f=await(0,Be.withTimeout)(c.connect(),i,"Wallet connect");await l.save(f),m(f);try{await d(f)}catch(E){ee.logger.warn("react/provider","SessionManager sync error:",E)}if(!await y(f))return;n({type:"SET_STATUS",payload:"connected"})}catch(f){let E=f instanceof Error?f.message:"Connection failed";n({type:"SET_ERROR",payload:f instanceof Error?f:new Error(E)}),n({type:"SET_STATUS",payload:"disconnected"})}},[c,l,m,i,y,d]),v=(0,O.useCallback)(async()=>{n({type:"SET_STATUS",payload:"connecting"}),n({type:"SET_ERROR",payload:null});try{let f=await c.connectEmbedded();if(await l.save(f),m(f),await d(f),!await y(f))return;n({type:"SET_STATUS",payload:"connected"})}catch(f){let E=f instanceof Error?f.message:"Embedded wallet connection failed";n({type:"SET_ERROR",payload:f instanceof Error?f:new Error(E)}),n({type:"SET_STATUS",payload:"disconnected"})}},[c,l,m,y,d]),C=(0,O.useCallback)(async()=>{n({type:"SET_STATUS",payload:"connecting"}),n({type:"SET_ERROR",payload:null});try{let f=await c.connectPasskeys();if(await l.save(f),m(f),await d(f),!await y(f))return;n({type:"SET_STATUS",payload:"connected"})}catch(f){let E=f instanceof Error?f.message:"Passkeys connection failed";n({type:"SET_ERROR",payload:f instanceof Error?f:new Error(E)}),n({type:"SET_STATUS",payload:"disconnected"})}},[c,l,m,y,d]),b=(0,O.useCallback)(async()=>{if(!s.session){n({type:"RESET"});return}try{await c.disconnect(s.session)}catch(f){ee.logger.error("react/provider","Disconnect error:",f)}try{let f=h.current;f&&await f.disconnect()}catch(f){ee.logger.warn("react/provider","SessionManager disconnect error:",f)}await l.clear(),n({type:"RESET"})},[c,s.session,l]),R=(0,O.useCallback)(async f=>{n({type:"SET_STATUS",payload:"connecting"}),n({type:"SET_ERROR",payload:null});try{let E=await(0,Be.withTimeout)(c.connectInjected(f),i,"Injected wallet connect");await l.save(E),m(E);try{await d(E)}catch(w){ee.logger.warn("react/provider","SessionManager sync error:",w)}if(!await y(E))return;n({type:"SET_STATUS",payload:"connected"})}catch(E){let w=E instanceof Error?E.message:"Connection failed";n({type:"SET_ERROR",payload:E instanceof Error?E:new Error(w)}),n({type:"SET_STATUS",payload:"disconnected"})}},[c,l,m,i,y,d]),k=(0,O.useCallback)(async()=>c.startPairing(),[c]),T=(0,O.useCallback)(()=>{c.cancelPairing?.()},[c]),x=(0,O.useCallback)(async()=>{let f=await c.completePairing();return await l.save(f),m(f),await d(f),await y(f)&&n({type:"SET_STATUS",payload:"connected"}),f},[c,l,m,y,d]),A=(0,O.useCallback)(async f=>{let E=t.siwx;if(!E||E.required===!1)return!0;try{if(await E.hasValidSession?.())return!0}catch(w){ee.logger.warn("react/provider","siwx.hasValidSession failed",w)}return y(f)},[t.siwx,y]),P=(0,O.useCallback)(async()=>{let f=await l.load();if(!f){n({type:"SET_STATUS",payload:"disconnected"});return}n({type:"SET_STATUS",payload:"reconnecting"});try{let E=await(0,Be.withRetry)(()=>c.reconnect(f),{maxRetries:g,baseDelay:1e3,label:"reconnect"});m(E);try{let w=h.current;w&&(p(),await w.restoreFromPersistence())}catch(w){ee.logger.warn("react/provider","SessionManager restore error:",w)}if(!await A(E))return;n({type:"SET_STATUS",payload:"connected"})}catch(E){ee.logger.error("react/provider","Reconnect error:",E),await l.clear(),n({type:"SET_STATUS",payload:"disconnected"}),n({type:"SET_SESSION",payload:null})}},[c,l,m,g,p,A]),W=(0,O.useCallback)(async f=>{r.current&&await r.current;let E=h.current;if(E?.getActiveBundle()){await E.switchChain(f),m(s.session);return}if(!s.session)throw new Error("No active session");try{s.session.walletType==="eip6963"||s.session.id?.startsWith("eip6963-")?await xt.eip6963Connector.switchChain(s.session,f):s.session.walletType==="embedded"&&c.embeddedConnector?await c.embeddedConnector.switchChain?.(s.session,f):s.session.walletType==="passkeys"&&c.passkeysConnector?await c.passkeysConnector.switchChain?.(s.session,f):s.session.walletType==="solana"&&c.solanaConnector?await c.solanaConnector.switchChain?.(s.session,f):await c.connector.switchChain(s.session,f),m(s.session)}catch(w){throw new ee.WalletError("chain_unsupported","Failed to switch chain",w)}},[c,s.session,m]);(0,O.useEffect)(()=>{o&&P()},[o,P]);let D=(0,O.useCallback)(()=>{n({type:"SET_ERROR",payload:null})},[]),B=(0,O.useMemo)(()=>({...s,connect:S,connectEmbedded:v,connectPasskeys:C,disconnect:b,reconnect:P,switchChain:W,startPairing:k,completePairing:x,cancelPairing:T,connectInjected:R,clearError:D,isConnected:s.status==="connected",chains:u,client:c,sessionManager:a}),[s,S,v,C,b,P,W,k,x,T,R,D,u,c,a]);return(0,br.jsx)(Ht.Provider,{value:B,children:e})}function I(){let e=(0,O.useContext)(Ht);if(!e)throw new Error("useWeb3 must be used within a Web3ConnectProvider");return e}function K(){let{accounts:e,isConnected:t}=I(),o=(0,Ar.useMemo)(()=>!t||e.length===0?null:e.map(n=>{let u=(0,vt.parseCaip10)(n);return u?{address:n,namespace:u.namespace,isEVM:u.namespace==="eip155"&&(0,vt.isEvmAddress)(u.address)}:{address:n,namespace:null,isEVM:(0,vt.isEvmAddress)(n)}}),[e,t]),s=o?.find(n=>n.isEVM)?.address??null;return{accounts:o,evmAccount:s,primaryAccount:e[0]??null,isConnected:t,count:e.length}}var nt=require("@naculus/connect-appkit-core"),X=require("react");var rt=require("viem"),Rr=require("@naculus/connect-core");function Tr(e){let{evmAccount:t,isConnected:o}=K(),{chainId:s,chains:n}=I(),[u,i]=(0,X.useState)(null),[g,l]=(0,X.useState)(!1),[c,h]=(0,X.useState)(null),[r,a]=(0,X.useState)(null),p=e?.refreshInterval,d=(0,X.useRef)(null),m=(0,X.useMemo)(()=>(0,nt.resolveChain)(n,s),[s,n]),y=m?(0,nt.chainNumber)(m):null,S=(0,X.useMemo)(()=>m?(0,nt.toViemChain)(m,y):null,[m,y]),v=(0,X.useMemo)(()=>m?.token??null,[m]),[C,b]=(0,X.useState)(null);(0,X.useEffect)(()=>{if(!S||!m?.rpcUrl){b(null);return}let x=(0,rt.createPublicClient)({transport:(0,rt.http)(m.rpcUrl),chain:S});return b(x),()=>{}},[m,S]);let R=(0,X.useCallback)(async()=>{if(!t||!C){i(null);return}l(!0),h(null);try{let A=t.includes(":")?t.split(":").pop():t,[P,W]=await Promise.all([C.getBalance({address:A}),s?(0,Rr.getNativeTokenPriceUsd)(s,m?.rpcUrl).catch(()=>null):Promise.resolve(null)]);i(P.toString()),a(W)}catch(x){h(x instanceof Error?x:new Error("Failed to fetch balance")),i(null),a(null)}finally{l(!1)}},[t,C,s,m?.rpcUrl]);(0,X.useEffect)(()=>{o&&t&&R()},[o,t,R]),(0,X.useEffect)(()=>(p&&p>0&&o&&t&&(d.current=setInterval(R,p)),()=>{d.current&&(clearInterval(d.current),d.current=null)}),[p,o,t,R]);let k=(0,X.useMemo)(()=>{if(u===null)return null;try{return(0,rt.formatEther)(BigInt(u))}catch{return null}},[u]),T=(0,X.useMemo)(()=>{if(r===null||k===null)return null;let x=parseFloat(k);if(Number.isNaN(x))return null;let A=x*r;return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(A)},[r,k]);return{balance:u,formatted:k,symbol:v,usdPrice:r,usdValue:T,isLoading:g,error:c,refetch:R,chain:m}}var ot=require("@naculus/connect-appkit-core"),Ue=require("react");function _(e){return e??Bt()}function qt(){let{client:e,session:t,chainId:o}=I(),[s,n]=(0,Ue.useState)(null),[u,i]=(0,Ue.useState)(!1),[g,l]=(0,Ue.useState)(null),c=(0,Ue.useRef)(0),h=(0,Ue.useCallback)(async()=>{let r=++c.current,a=_(e);if(!a?.getCapabilities||!t){n(null),i(!1),l(null);return}i(!0),l(null);try{let p=await a.getCapabilities(t);if(r!==c.current)return;n((0,ot.normalizeCapabilities)(p))}catch(p){if(r!==c.current)return;n(null),l(p instanceof Error?p:new Error("Capability query failed"))}finally{r===c.current&&i(!1)}},[e,t]);return(0,Ue.useEffect)(()=>{h()},[h]),{capabilities:s,current:(0,ot.selectChainCapabilities)(s,o),atomic:(0,ot.atomicSupportFor)(s,o),isFetching:u,error:g,refetch:h}}var Vt=require("react"),st=require("@naculus/connect-appkit-core");function ce(){let{chainId:e,session:t,switchChain:o,chains:s}=I(),n=(0,Vt.useMemo)(()=>(0,st.resolveChain)(s,e),[s,e]),u=(0,Vt.useMemo)(()=>t?(0,st.describeChain)(s,e):null,[s,e,t]),i=(0,Vt.useMemo)(()=>(0,st.chainsForNamespace)(s,e),[s,e]);return{chainId:e,currentChain:n,chainInfo:u,availableChains:i,chains:i,isEvm:e?.startsWith("eip155:")??!1,switchChain:o}}var bt=require("react");var Ir=require("@naculus/connect-core");function Ur(){let{connect:e,status:t}=I(),[o,s]=(0,bt.useState)(!1),[n,u]=(0,bt.useState)(null);return{connect:(0,bt.useCallback)(async()=>{s(!0),u(null);try{await e()}catch(g){let l=g instanceof Error?g.message:"Connection failed";u(g instanceof Ir.WalletError?g:new Error(l))}finally{s(!1)}},[e]),isConnecting:o||t==="connecting",error:n}}var Pr=require("@naculus/connect-appkit-core"),Fe=require("@naculus/connect-core"),ne=require("react");var $t=require("@naculus/connect-appkit-core"),jt=require("react"),$e=require("viem");function ue(){let{evmAccount:e,isConnected:t}=K(),{currentChain:o,chains:s}=ce(),n=o?(0,$t.chainNumber)(o):null,u=(0,jt.useMemo)(()=>o?(0,$t.toViemChain)(o,n):null,[o,n]),i=(0,jt.useMemo)(()=>u?(0,$e.createPublicClient)({transport:(0,$e.http)(u.rpcUrls.default.http[0]),chain:u}):null,[u]),g=(0,jt.useMemo)(()=>{if(!t||!e||!u)return null;let l=e.includes(":")?e.split(":").pop():e;return(0,$e.createWalletClient)({transport:(0,$e.http)(u.rpcUrls.default.http[0]),chain:u,account:l})},[t,e,u]);return{publicClient:i,walletClient:g,chains:s}}function Wr(e){let{evmAccount:t}=K(),{session:o,chainId:s,client:n}=I(),{publicClient:u}=ue(),[i,g]=(0,ne.useState)(null),[l,c]=(0,ne.useState)(!1),[h,r]=(0,ne.useState)(null),a=(0,ne.useRef)(0),p=(0,ne.useRef)(!1);(0,ne.useEffect)(()=>()=>{a.current+=1},[]),(0,ne.useEffect)(()=>{a.current+=1,g(null),c(!1),r(null)},[o,s,t]);let d=(0,ne.useCallback)(async(v,C)=>{let b=x=>(r(x),null);if(p.current)return b(new Error("A delegation is already in progress"));let R=(0,Pr.bareEvmAddress)(t);if(!o||!R||!s)return b(new Fe.WalletError("wallet_unavailable","No connected EVM account"));if(!u||u.chain?.id!==(0,Fe.eip155Reference)(s))return b(new Fe.WalletError("chain_mismatch",`No RPC client for ${s}; refusing to read the nonce elsewhere.`));let k=o.walletType==="embedded"?_(n)?.embeddedConnector??{}:{},T=++a.current;p.current=!0,c(!0),r(null),g(null);try{let x=await(0,Fe.delegateAccount)({connector:k,session:o,account:R,chainId:s,delegate:v,allowlist:C,getTransactionCount:(A,P)=>u.getTransactionCount({address:A,blockTag:P})});return T!==a.current?null:(g(x),x)}catch(x){return T!==a.current?null:b(x instanceof Error?x:new Error("Failed to send delegation"))}finally{p.current=!1,T===a.current&&c(!1)}},[s,n,t,u,o]),m=(0,ne.useCallback)(v=>d(v,e.allowlist),[d,e.allowlist]),y=(0,ne.useCallback)(()=>d(Fe.REVOKE_DELEGATE,[]),[d]),S=(0,ne.useCallback)(()=>{a.current+=1,g(null),c(!1),r(null)},[]);return{delegate:m,revoke:y,result:i,isPending:l,error:h,reset:S}}var Nr=require("@naculus/connect-appkit-core"),fe=require("react");function Or(e){let[t,o]=(0,fe.useState)(0),[s,n]=(0,fe.useState)(null),[u,i]=(0,fe.useState)(null),g=(0,fe.useRef)(0),l=(0,fe.useRef)(0),c=(0,fe.useRef)(e);c.current=e,(0,fe.useEffect)(()=>()=>{g.current+=1,l.current+=1},[]);let h=(0,fe.useCallback)(async(a,p)=>{let d=++g.current,m=l.current;o(y=>y+1),i(null);try{let y=await c.current(a,p),S=(0,Nr.describePayment)(a,y);return S&&m===l.current&&n(S),y}catch(y){let S=y instanceof Error?y:new Error("Paid request failed");throw d===g.current&&i(S),S}finally{o(y=>y-1)}},[]),r=(0,fe.useCallback)(()=>{g.current+=1,l.current+=1,n(null),i(null)},[]);return{payFetch:h,isPending:t>0,lastPayment:s,error:u,reset:r}}var Se=require("@naculus/connect-appkit-core"),q=require("react");function _r(e){return e instanceof Error?e:new Error("MPP session operation failed")}function Dr(e){let[t,o]=(0,q.useState)(0),[s,n]=(0,q.useState)(()=>e.meter.pending),[u,i]=(0,q.useState)(()=>(0,Se.readCurrentMppSessionChannel)(e)),[g,l]=(0,q.useState)(null),[c,h]=(0,q.useState)(null),[r,a]=(0,q.useState)(null),p=(0,q.useRef)(0),d=(0,q.useRef)(0),m=(0,q.useRef)(!0),y=(0,q.useRef)(e);y.current=e,(0,q.useEffect)(()=>{p.current+=1,d.current+=1,o(0),n(e.meter.pending),i((0,Se.readCurrentMppSessionChannel)(e)),l(null),h(null),a(null)},[e]),(0,q.useEffect)(()=>()=>{m.current=!1,p.current+=1,d.current+=1},[]);let S=(0,q.useCallback)(async(x,A,P=!1)=>{let W=++p.current,D=d.current,B=y.current;o(f=>f+1),a(null);try{let f=await x(B);if(m.current&&D===d.current){A?.(f);let E=(0,Se.readCurrentMppSessionChannel)(B);i(E),n(B.meter.pending),(P||!E)&&h(null)}return f}catch(f){let E=_r(f);if(m.current&&D===d.current){let w=(0,Se.readCurrentMppSessionChannel)(B);i(w),n(B.meter.pending);let U=(0,Se.readMppRecoveryChannelId)(f);U?h(U):w||h(null),W===p.current&&a(E)}throw E}finally{m.current&&D===d.current&&o(f=>f-1)}},[]),v=(0,q.useCallback)((x,A)=>S(P=>P(x,A),P=>{let W=(0,Se.readMppSessionReceipt)(P.receipt);W&&l(W)}),[S]),C=(0,q.useCallback)(()=>S(x=>x.close(),x=>{let A=(0,Se.readMppSessionReceipt)(x.receipt);A&&l(A)},!0),[S]),b=(0,q.useCallback)(()=>S(x=>x.forceClose(),void 0,!0),[S]),R=(0,q.useCallback)(x=>{try{y.current.meter.add(x),n(y.current.meter.pending),a(null)}catch(A){let P=_r(A);throw a(P),h((0,Se.readMppRecoveryChannelId)(A)),P}},[]),k=(0,q.useCallback)(()=>{p.current+=1,d.current+=1,o(0),n(y.current.meter.pending),i((0,Se.readCurrentMppSessionChannel)(y.current)),l(null),h(null),a(null)},[]),T=(0,q.useMemo)(()=>({add:R}),[R]);return{fetch:v,meter:T,pending:s,channel:u,lastReceipt:g,recoveryChannelId:c,isPending:t>0,error:r,close:C,forceClose:b,reset:k}}var Lr=require("@naculus/connect-appkit-core"),re=require("react");function Mr(){return Promise.reject(new Error("No Solana session key manager is connected"))}function Br(e){let[t,o]=(0,re.useState)([]),[s,n]=(0,re.useState)(0),[u,i]=(0,re.useState)(null),g=(0,re.useRef)(0),l=e?.manager,c=e?.rpc,h=e?.owner,r=(0,re.useMemo)(()=>l&&c&&h?(0,Lr.createSolanaSessionKeyFlow)({manager:l,rpc:c,owner:h}):null,[l,c,h]),a=(0,re.useCallback)(async(y,S)=>{let v=++g.current;n(C=>C+1),i(null);try{return await y()}catch(C){let b=C instanceof Error?C:new Error(S);throw v===g.current&&i(b),b}finally{if(r&&v===g.current){let C=await r.list().catch(()=>null);C&&v===g.current&&o(C)}n(C=>C-1)}},[r]),p=(0,re.useCallback)(async()=>{if(!r){o([]);return}let y=g.current,S=await r.list();y===g.current&&o(S)},[r]);(0,re.useEffect)(()=>(g.current+=1,p().catch(()=>{}),()=>{g.current+=1}),[p]);let d=(0,re.useCallback)(y=>r?a(()=>r.create(y),"Could not create the key"):Mr(),[r,a]),m=(0,re.useCallback)(y=>r?a(()=>r.revoke(y),"Could not revoke the key"):Mr(),[r,a]);return{keys:t,create:d,revoke:m,refresh:p,isPending:s>0,error:u}}var at=require("@naculus/connect-core"),Pe=require("react");function it(){let{publicClient:e}=ue(),{evmAccount:t}=K(),[o,s]=(0,Pe.useState)(at.UNKNOWN_DELEGATION),[n,u]=(0,Pe.useState)(!1),[i,g]=(0,Pe.useState)(null),l=(0,Pe.useRef)(0),c=t?.includes(":")?t.split(":").pop():t,h=(0,Pe.useCallback)(async()=>{let r=++l.current;if(!e||!c){s(at.UNKNOWN_DELEGATION),u(!1),g(null);return}u(!0),g(null);try{let a=await e.getCode({address:c});if(r!==l.current)return;s((0,at.readDelegation)(a??"0x"))}catch(a){if(r!==l.current)return;s(at.UNKNOWN_DELEGATION),g(a instanceof Error?a:new Error("Code read failed"))}finally{r===l.current&&u(!1)}},[e,c]);return(0,Pe.useEffect)(()=>{h()},[h]),{...o,isFetching:n,error:i,refetch:h}}var ct=require("@naculus/connect-appkit-core"),oe=require("react"),$r=require("viem");var Qt=require("@naculus/connect-core");var Ge=require("react");var ge=require("@naculus/connect-core"),Ae=require("react");var Fr=require("@naculus/connect-core");function Gt(e){let t=typeof e=="string"?e:e&&typeof e=="object"&&"hash"in e?e.hash:void 0;if(typeof t=="string"&&/^0x[0-9a-fA-F]{64}$/.test(t))return t;throw new Fr.WalletError("tx_failed","Wallet did not return a valid 32-byte transaction hash")}function zt(){let{session:e,chainId:t,client:o}=I(),[s,n]=(0,Ae.useState)("idle"),[u,i]=(0,Ae.useState)(null),[g,l]=(0,Ae.useState)(null),[c,h]=(0,Ae.useState)(null),[r,a]=(0,Ae.useState)(null),p=(0,Ae.useCallback)(async(S,v)=>{if(!e){n("failed");let C=new ge.WalletError("wallet_unavailable","No active session");throw i(C),C}if(S.length===0){n("failed");let C=new ge.WalletError("invalid_input","At least one call is required");throw i(C),C}n("awaiting_approval"),i(null),l(null);try{let C=_(o);if(!C)throw new ge.WalletError("wallet_unavailable","Client not initialized");let b=v?.chainId??t??void 0,R=v?.strategy??(0,ge.chooseExecutionStrategy)(await(0,ge.getAccountCapabilities)(C,e,b),S.length);if(a(R),R==="atomic-batch"){let T=await C.sendCalls(e,S,b,{atomicRequired:!0,...v?.paymasterService?{paymasterService:v.paymasterService}:{}});return n("submitted"),l(T),T}let k="";for(let T=0;T<S.length;T++){let x=S[T];try{k=Gt(await C.sendTransaction(e,{transaction:{to:x.to,data:x.data,value:x.value},chainId:b}))}catch(A){throw new ge.WalletError("tx_failed",`Call ${T+1} of ${S.length} failed after ${T} already landed (sent sequentially \u2014 this wallet cannot batch atomically): ${A instanceof Error?A.message:String(A)}`)}}return n("submitted"),l(k),k}catch(C){n("failed");let b=C instanceof Error?C.message:"sendCalls failed";throw i(C instanceof Error?C:new Error(b)),C}},[e,t,o]),d=(0,Ae.useCallback)(async S=>{if(!e)throw new ge.WalletError("wallet_unavailable","No active session");let v=S??g;if(!v)throw new ge.WalletError("invalid_input","No bundle hash available");if(!S&&r==="sequential")throw new ge.WalletError("invalid_input","Calls were sent sequentially, so there is no bundle to query. Track the returned transaction hash instead.");let C=_(o);if(!C)throw new ge.WalletError("wallet_unavailable","Client not initialized");let b=await C.getCallsStatus(e,v);return h(b),b},[e,g,o,r]),m=(0,Ae.useCallback)(async S=>{if(!e)return!1;let v=S??g;if(!v||!S&&r==="sequential")return!1;let C=_(o);if(!C?.showCallsStatus)return!1;try{return await C.showCallsStatus(e,v),!0}catch{return!1}},[e,g,o,r]),y=(0,Ae.useCallback)(()=>{n("idle"),i(null),l(null),h(null),a(null)},[]);return{sendCalls:p,getCallsStatus:d,showCallsStatus:m,status:s,error:u,batchHash:g,callsStatus:c,execution:r,reset:y,isSending:s==="awaiting_approval"}}function Xt(e={}){let{current:t,atomic:o}=qt(),{delegated:s,delegate:n}=it(),{sendCalls:u}=zt(),[i,g]=(0,Ge.useState)(!1),[l,c]=(0,Ge.useState)(null),[h,r]=(0,Ge.useState)(null),a=e.atomicity??"preferred",p=e.sponsorship??"any",d=e.paymasterService,m=e.userOperation,y=e.userOperationSponsored??!1,S=!!(t?.raw?.paymasterService?.supported&&d),v=(0,Ge.useCallback)((b,R=a)=>{let k=(0,Qt.planExecution)({atomicBatch:o==="supported",discovered:o!=="unknown",sponsoredTransactions:!1,...t?.maxBatchSize===void 0?{}:{maxBatchSize:t.maxBatchSize}},b,{atomicity:R,sponsorship:p}),T=p==="required"&&!y;if(k.strategy==="atomic-batch"&&!T)return{...k,reason:k.reason+(S?" A paymaster service will be requested, but the wallet's final fee payer must be checked after execution.":""),route:"wallet-batch"};let x=s&&o!=="supported"?` This account does delegate to ${n} under EIP-7702, so it is capable of batching even though the wallet has not offered to.`:"",A=R!=="any"&&!k.atomic||p==="required";return m&&A&&!T?{strategy:"atomic-batch",atomic:!0,sponsored:y,reason:p==="required"&&!k.sponsored?"The wallet batch is not configured for sponsored gas, so the calls are executed through the configured sponsored UserOperation route.":"This wallet cannot batch, so the calls are executed as a single UserOperation through the smart account, which lands as one transaction.",route:"user-operation"}:T?{strategy:"refuse",atomic:k.atomic,sponsored:!1,reason:"Sponsored gas was required, but there is no executable sponsored route: no paymaster is configured for a wallet batch, and capability advertising alone cannot pay for a sequential transaction.",route:null}:k.strategy==="refuse"?{...k,reason:k.reason+x,route:null}:{...k,reason:k.reason+x,route:"sequential"}},[o,t,S,m,y,a,p,s,n]),C=(0,Ge.useCallback)(async(b,R=a)=>{g(!0),c(null);try{let k=v(b.length,R);if(k.route===null)throw new Qt.WalletError("method_not_allowed",k.reason);return r(k.route),k.route==="user-operation"?await m(b):await u(b,{strategy:k.route==="wallet-batch"?"atomic-batch":"sequential",...k.route==="wallet-batch"&&S?{paymasterService:d}:{}})}catch(k){let T=k instanceof Error?k:new Error("Execution failed");throw c(T),T}finally{g(!1)}},[v,u,m,a,d,S]);return{preview:v,execute:C,isExecuting:i,error:l,lastRoute:h,reset:()=>{c(null),r(null)}}}var Yt=require("@naculus/connect-appkit-core"),Kr=require("@naculus/connect-core"),H=require("react");function lt(e){return(0,Yt.getSharedSessionKeyManager)(e)}function Jt(e){let{session:t}=I(),[o,s]=(0,H.useState)([]),[n,u]=(0,H.useState)(!1),[i,g]=(0,H.useState)(null),l=(0,H.useRef)(!0),c=(0,H.useCallback)(()=>g(null),[]),h=lt(e),r=h.isStorageAvailable(),a=(0,H.useCallback)(async()=>{if(!t){s([]);return}u(!0),g(null);try{let d=await h.listSessions();l.current&&s(d)}catch(d){l.current&&g(d instanceof Error?d:new Error("Failed to load session keys"))}finally{l.current&&u(!1)}},[t,h]);(0,H.useEffect)(()=>(l.current=!0,a(),()=>{l.current=!1}),[a]);let p=o.filter(d=>d.status==="active");return{sessions:o,activeSessions:p,loading:n,error:i,refresh:a,clearError:c,storageAvailable:r}}function Hr(e){let{session:t}=I(),[o,s]=(0,H.useState)(null),[n,u]=(0,H.useState)(!1),[i,g]=(0,H.useState)(null),l=(0,H.useCallback)(()=>g(null),[]),c=lt(e);return{createSessionKey:(0,H.useCallback)(async(r,a)=>{if(!t)throw new Kr.WalletError("wallet_unavailable","No active wallet session");u(!0),g(null);try{let p=a??void 0,d=await c.createSessionKey(r,p);return s(d),d}catch(p){let d=p instanceof Error?p:new Error("Failed to create session key");throw g(d),d}finally{u(!1)}},[t,c]),lastCreated:o,isCreating:n,error:i,clearError:l}}function qr(e){let[t,o]=(0,H.useState)(!1),[s,n]=(0,H.useState)(null),u=(0,H.useCallback)(()=>n(null),[]),i=lt(e);return{revokeSession:(0,H.useCallback)(async l=>{o(!0),n(null);try{await i.revokeSession(l)}catch(c){let h=c instanceof Error?c:new Error("Failed to revoke session key");throw n(h),h}finally{o(!1)}},[i]),isRevoking:t,error:s,clearError:u}}function Vr(e){let[t,o]=(0,H.useState)(!1),[s,n]=(0,H.useState)(null),u=(0,H.useCallback)(()=>n(null),[]),i=lt(e),g=(0,H.useCallback)(async(c,h,r)=>{o(!0),n(null);try{return await i.signWithSessionKey(c,h,r)}catch(a){let p=a instanceof Error?a:new Error("Failed to sign with session key");throw n(p),p}finally{o(!1)}},[i]),l=(0,H.useCallback)(async(c,h)=>{o(!0),n(null);try{return await i.checkSessionScope(c,h)}catch(r){let a=r instanceof Error?r:new Error("Failed to check session scope");throw n(a),a}finally{o(!1)}},[i]);return{signWithSession:g,checkScope:l,isBusy:t,error:s,clearError:u}}function jr(){(0,Yt.resetSharedSessionKeyManager)()}var At=require("react");var Zt=require("@naculus/connect-core");function en(){let{session:e,chainId:t,client:o}=I(),[s,n]=(0,At.useState)(!1),[u,i]=(0,At.useState)(null);return{signMessage:(0,At.useCallback)(async l=>{if(!e){let h=new Zt.WalletError("wallet_unavailable","No active session");throw i(h),h}let c=e.namespaces.eip155?.accounts[0]??Object.values(e.namespaces)[0]?.accounts[0];if(!c){let h=new Zt.WalletError("wallet_unavailable","No account found");throw i(h),h}n(!0),i(null);try{let h=_(o);if(!h)throw new Zt.WalletError("wallet_unavailable","Client not initialized");return await h.signMessage(e,{message:l,address:c,chainId:t??void 0})}catch(h){let r=h instanceof Error?h.message:"Signing failed",a=h instanceof Error?h:new Error(r);throw i(a),a}finally{n(!1)}},[e,t,o]),isSigning:s,error:u}}var er=require("@naculus/connect-appkit-core");function Gr(e={}){let{evmAccount:t}=K(),o=(0,ct.bareEvmAddress)(t),s=it(),n=Xt(e.execution),{signMessage:u}=en(),i=Jt(e.managerConfig),g=lt(e.managerConfig),[l,c]=(0,oe.useState)(!1),[h,r]=(0,oe.useState)(null),[a,p]=(0,oe.useState)(()=>new Set),[d,m]=(0,oe.useState)(!1),y=e.origin??(typeof window<"u"?window.location.origin:"unknown"),S=!!e.managerConfig?.encryptionKey,v=e.execution?.sponsorship,{refresh:C,storageAvailable:b}=i,{preview:R}=n,{delegated:k,delegate:T}=s,x=(0,oe.useMemo)(()=>(0,ct.createDelegationPolicyFlow)({manager:g,origin:y,signer:()=>o,signMessage:u,verifySignature:async({message:E,signature:w,signerAddress:U})=>(await(0,$r.recoverMessageAddress)({message:E,signature:w})).toLowerCase()===U.toLowerCase(),previewExecution:R,sponsorship:v,adapter:e.adapter,signTypedData:e.signTypedData,chainId:()=>e.chainId??null,delegation:()=>({delegated:k,delegate:T}),encryptionKeyConfigured:S,storageAvailable:()=>b,refresh:C}),[g,y,o,u,R,v,e.adapter,e.signTypedData,e.chainId,k,T,S,b,C]);(0,oe.useEffect)(()=>{let E=!1,w=i.sessions.filter(ct.isVerifiablePolicy);return w.length===0?(p(new Set),m(!1),()=>{E=!0}):(m(!0),Promise.all(w.map(async U=>[U.id,await x.verifyStoredPolicy(U)])).then(U=>{E||p(new Set(U.filter(([,N])=>N).map(([N])=>N)))}).catch(U=>{E||(p(new Set),r(U instanceof Error?U:new Error("Policy verification failed")))}).finally(()=>{E||m(!1)}),()=>{E=!0})},[i.sessions,x]);let A=(0,oe.useCallback)(()=>{r(null),i.clearError()},[i]),P=(0,oe.useCallback)(async(E,w)=>{c(!0),r(null);try{return await E()}catch(U){let N=U instanceof Error?U:new Error(w);throw r(N),N}finally{c(!1)}},[]),W=(0,oe.useCallback)(E=>P(()=>x.createPolicy(E),"Policy creation failed"),[x,P]),D=(0,oe.useCallback)(E=>P(()=>x.revokePolicy(E),"Policy revocation failed"),[x,P]),B=(0,oe.useCallback)((E,w)=>P(()=>x.executePolicy(E,w),"Policy execution failed"),[x,P]),f=i.activeSessions.filter(E=>a.has(E.id));return{policies:i.sessions,activePolicies:f,storageAvailable:i.storageAvailable,loading:i.loading||d,isBusy:l,error:h??i.error,delegation:s,createPolicy:W,revokePolicy:D,previewPolicyExecution:x.previewPolicyExecution,signPolicyDigest:x.signPolicyDigest,executePolicy:B,refresh:i.refresh,clearError:A}}var ze=require("react");function zr(){let{disconnect:e,status:t}=I(),[o,s]=(0,ze.useState)(!1),[n,u]=(0,ze.useState)(null),i=(0,ze.useRef)(!0);return{disconnect:(0,ze.useCallback)(async()=>{if(t!=="disconnected"){s(!0),u(null);try{await e()}catch(l){if(!i.current)return;u(l instanceof Error?l:new Error("Disconnect failed"))}finally{i.current&&s(!1)}}},[e,t]),isDisconnecting:o,error:n,cleanup:()=>{i.current=!1}}}var tn=require("@naculus/connect-core"),G=require("react");function He(e){let t=e.activeNamespace??"eip155",o=Array.isArray(e.accounts)?e.accounts.map(({namespace:s,address:n,derivationPath:u})=>({namespace:s,address:n,...u?{derivationPath:u}:{}})):e.address?[{namespace:t,address:e.address}]:[];return{accounts:o,activeNamespace:t,createdAt:e.createdAt??0,...e.chainId?{chainId:e.chainId}:{},...e.version?{version:e.version}:{},recoveryAvailable:!!e.mnemonic,address:o.find(s=>s.namespace===t)?.address??e.address}}function Qr(){let{connectEmbedded:e,client:t}=I(),[o,s]=(0,G.useState)(null),n=(0,G.useRef)(null),u=(0,G.useRef)(4),i=(0,G.useRef)(!1),g=(0,G.useRef)(null),[l,c]=(0,G.useState)(!1),[h,r]=(0,G.useState)(!1),[a,p]=(0,G.useState)(null),d=()=>p(null),m=(0,G.useCallback)(()=>{let f=n.current;return n.current=null,f},[]),y=(0,G.useCallback)(()=>{let f=_(t);if(!f?.embeddedConnector)throw new tn.WalletError("wallet_unavailable","Embedded wallet not enabled.");return f.embeddedConnector},[t]),S=(0,G.useCallback)(()=>{try{return y().getWallet()?.privateKey??null}catch{return null}},[y]),v=(0,G.useCallback)(async()=>{let f=_(t);if(!f)throw new tn.WalletError("wallet_unavailable","Embedded wallet not enabled.");let E=f.getEmbeddedConnector?await f.getEmbeddedConnector():f.embeddedConnector;if(!E)throw new tn.WalletError("wallet_unavailable","Embedded wallet not enabled.");return E},[t]),C=(0,G.useCallback)(()=>{try{return _(t)?.passphraseGate??null}catch{return null}},[t]),b=(0,G.useCallback)(f=>{f?.code==="decryption_failed"&&C()?.forget("That passphrase did not open the wallet.")},[C]),R=(0,G.useCallback)(async()=>{i.current=!1,p(null);try{let f=await v();if(!await f.load())return!1;let w=f.getWallet();return w?(n.current=null,c(!1),s(He(w)),!0):!1}catch(f){return i.current=!0,b(f),p(f instanceof Error?f:new Error("Failed to restore embedded wallet")),!1}},[b,v]);(0,G.useEffect)(()=>{let f=!1,E=null;return R().then(w=>{f||w||i.current||(E=setTimeout(()=>{f||R()},100))}),()=>{f=!0,E&&clearTimeout(E)}},[R]);let k=async()=>{r(!0),p(null);try{let f=await v(),E=await f.load(),w=f.getWallet();E&&w&&(s(He(w)),n.current=w.mnemonic||null,c(!w.mnemonic)),await e();let U=f.getWallet();U&&(s(He(U)),U.mnemonic&&!E&&(n.current=U.mnemonic,c(!0)))}catch(f){b(f),p(f instanceof Error?f:new Error("Embedded wallet connection failed"))}finally{r(!1)}},T=async()=>{r(!0),p(null);try{let f=await v();C()?.expect("create");let E=await f.generateWallet();return s(He(E)),n.current=E.mnemonic,c(!0),E}catch(f){return p(f instanceof Error?f:new Error("Failed to generate wallet")),null}finally{r(!1)}},x=async f=>{r(!0),p(null);try{let E=await v();C()?.expect("create");let w=await E.importFromMnemonic(f);return s(He(w)),n.current=null,c(!1),w}catch(E){return p(E instanceof Error?E:new Error("Failed to import wallet")),null}finally{r(!1)}},A=async f=>{r(!0),p(null);try{let E=await v();C()?.expect("create");let w=await E.importFromPrivateKey(f);return s(He(w)),n.current=null,c(!1),w}catch(E){return p(E instanceof Error?E:new Error("Failed to import wallet")),null}finally{r(!1)}},P=async()=>{r(!0),p(null);try{await(await v()).wipe(),s(null),n.current=null,c(!1)}catch(f){p(f instanceof Error?f:new Error("Failed to wipe wallet"))}finally{r(!1)}},W=(0,G.useCallback)(f=>{let E=y();E.setActiveNamespace(f);let w=E.getWallet();s(w?He(w):null)},[y]),D=(0,G.useCallback)(async()=>{let f=await v(),E=await f.backfillAccounts();if(E.length>0){let w=f.getWallet();s(w?He(w):null)}return E.map(({namespace:w,address:U,derivationPath:N})=>({namespace:w,address:U,...N?{derivationPath:N}:{}}))},[v]),B=()=>{n.current=null,c(!1)};return{connectEmbedded:k,restoreWallet:R,generateWallet:T,importFromMnemonic:x,importFromPrivateKey:A,wipe:P,wallet:o,hasWallet:o!==null,address:o?.address??null,accounts:o?.accounts??[],activeNamespace:o?.activeNamespace??null,setActiveNamespace:W,backfillAccounts:D,seedPhrase:n.current,getSeedPhrase:m,getPrivateKey:S,backupPending:l,confirmBackup:B,isBusy:h,error:a,clearError:d,storageSecurityLevel:(()=>{try{let f=y(),E=f.getStorageSecurityLevel?.()??4;return f.getWallet()?(u.current=E,E):o?u.current:E}catch{return o?u.current:4}})(),securityReport:(()=>{let f=null;try{f=y().getStorageSecurityReport?.()??null}catch{f=null}if(!f)return g.current=null,null;let E=JSON.stringify(f);return g.current?.json===E?g.current.value:(g.current={json:E,value:f},f)})()}}var Jr=require("@naculus/connect-appkit-core"),we=require("react");var Xr=require("@naculus/connect-core"),Ee=require("react"),Yr=require("@naculus/connect-appkit-core");function Ls(e){return[e.token.address.toLowerCase(),e.token.chainId??"",e.token.decimals??"",e.chainId??"",e.owner??"",e.spender??"",e.connected?"1":"0",e.publicClient?"1":"0",e.walletClient?"1":"0",e.session?.id??""].join("|")}function ut(e){let{token:t,chainId:o}=e,s=t.address.toLowerCase(),n=Ls(e),u=(0,Ee.useMemo)(()=>({key:n}),[n]),i=(0,Ee.useRef)(n),g=(0,Ee.useRef)(!0);(0,Ee.useLayoutEffect)(()=>{i.current=n},[n]),(0,Ee.useEffect)(()=>(g.current=!0,()=>{g.current=!1}),[]);let l=(0,Ee.useCallback)(()=>g.current&&i.current===n,[n]),c=(0,Ee.useCallback)(()=>{if(!l())throw new Xr.WalletError("session_inactive","Wallet or token context changed. Retry the operation with the current account and chain.");let h=(0,Yr.tokenChainMismatch)({address:s,chainId:t.chainId},o);if(h)throw h},[l,s,t.chainId,o]);return{identity:u,isCurrent:l,assertCurrent:c}}var nn=require("@naculus/connect-core");function Zr(e){let{publicClient:t}=ue(),{currentChain:o}=ce(),{identity:s,isCurrent:n,assertCurrent:u}=ut({token:e.token,chainId:o?(0,Jr.chainNumber)(o)??void 0:void 0,owner:e.owner,spender:e.spender,publicClient:t}),[i,g]=(0,we.useState)(null),l=i?.identity===s?i.raw:null,c=i?.identity===s&&i.fetching,h=i?.identity===s?i.error:null,r=(0,we.useRef)(null),a=(0,we.useRef)(0),p=(0,we.useCallback)(async()=>{if(!n())return;let m=++a.current,y=()=>n()&&m===a.current;if(g({identity:s,raw:null,fetching:!!t,error:null}),!!t)try{u();let S=await t.readContract({address:e.token.address,abi:nn.ERC20_MIN_ABI,functionName:"allowance",args:[e.owner,e.spender]});if(!y())return;g({identity:s,raw:S,fetching:!1,error:null})}catch(S){if(!y())return;g({identity:s,raw:null,fetching:!1,error:S instanceof Error?S:new Error("Failed to fetch allowance")})}},[t,e.token.address,e.token.chainId,e.owner,e.spender,s,n,u]);return(0,we.useEffect)(()=>{p().catch(m=>console.warn("useERC20Allowance: initial fetch failed:",m))},[p]),(0,we.useEffect)(()=>(e.refreshInterval&&e.refreshInterval>0&&(r.current=setInterval(p,e.refreshInterval)),()=>{r.current&&(clearInterval(r.current),r.current=null)}),[e.refreshInterval,p]),{allowance:(0,we.useMemo)(()=>{if(l===null)return null;let m=e.token.decimals;return m===void 0?null:(0,nn.formatUnits)(l,m)},[l,e.token.decimals]),allowanceRaw:l,isFetching:c,error:h,refetch:p}}var he=require("@naculus/connect-appkit-core"),se=require("@naculus/connect-core"),ke=require("react");var rn=require("@naculus/connect-core"),pt=require("react");function dt(){let{session:e,chainId:t,client:o}=I(),[s,n]=(0,pt.useState)("idle"),[u,i]=(0,pt.useState)(null),g=(0,pt.useCallback)(async c=>{if(!e){n("failed");let r=new rn.WalletError("wallet_unavailable","No active session");throw i(r),r}let h=e.namespaces.eip155?.accounts.find(r=>/^eip155:\d+:0x[0-9a-fA-F]{40}$/.test(r)||/^0x[0-9a-fA-F]{40}$/.test(r));if(!h){n("failed");let r=new rn.WalletError("wallet_unavailable","No EVM account found");throw i(r),r}n("awaiting_approval"),i(null);try{let r={...c,from:c.from??h.split(":").pop()},a=_(o);if(!a)throw new rn.WalletError("wallet_unavailable","Client not initialized");let p=await a.sendTransaction(e,{transaction:r,chainId:t??void 0}),d=Gt(p);return n("submitted"),d}catch(r){n("failed");let a=r instanceof Error?r.message:"Transaction failed";throw i(r instanceof Error?r:new Error(a)),r}},[e,t,o]),l=(0,pt.useCallback)(()=>{n("idle"),i(null)},[]);return{sendTransaction:g,status:s,error:u,reset:l,isSending:s==="awaiting_approval"}}function Bs(e){return e.includes(":")?e.split(":").pop():e}var Fs=2n**256n-1n;function eo(e){let{publicClient:t,walletClient:o}=ue(),{evmAccount:s,isConnected:n}=K(),{currentChain:u}=ce(),{session:i,client:g}=I(),{sendTransaction:l,isSending:c,error:h,reset:r}=dt(),[a,p]=(0,ke.useState)(null),{identity:d,isCurrent:m,assertCurrent:y}=ut({token:e.token,chainId:u?(0,he.chainNumber)(u)??void 0:void 0,owner:s,spender:e.spender,connected:n,publicClient:t,walletClient:o,session:i,client:g}),[S,v]=(0,ke.useState)(null),C=S?.identity===d?S.raw:null,b=S?.identity===d&&S.fetching,R=(0,ke.useRef)((0,he.createDecimalsCache)(e.token,e.token.decimals)),k=(0,ke.useRef)(0),T=a??h,x=s?Bs(s):null,A=(0,ke.useCallback)(async()=>{if(!m())return null;let E=++k.current,w=()=>m()&&E===k.current;if(v({identity:d,raw:null,fetching:!!t&&!!x&&n}),p(null),!t||!x||!n)return null;try{y();let U=await t.readContract({address:e.token.address,abi:se.ERC20_MIN_ABI,functionName:"allowance",args:[x,e.spender]});return w()?(v({identity:d,raw:U,fetching:!1}),U):null}catch(U){return w()&&(v({identity:d,raw:null,fetching:!1}),p(U instanceof Error?U:new Error("Failed to fetch allowance"))),null}},[t,x,e.token.address,e.token.chainId,e.spender,d,m,y,n]),P=(()=>{if(C===null)return null;let E=(0,he.readDecimals)(R.current,e.token,e.token.decimals);return E===void 0?null:(0,se.formatUnits)(C,E)})(),W=(0,ke.useCallback)(async E=>{if(p(null),r(),!n||!s){let w=new se.WalletError("wallet_unavailable","No connected account");throw p(w),w}if(!t){let w=new se.WalletError("wallet_unavailable","No public client");throw p(w),w}try{y();let w=(0,he.encodeErc20Approve)(e.spender,E),U=_(g);if(i&&U){let j=await l({to:e.token.address,data:w,value:"0"});return A(),j}if(o){let{request:j}=await t.simulateContract({address:e.token.address,abi:se.ERC20_MIN_ABI,functionName:"approve",args:[e.spender,E],account:x});y();let je=await o.writeContract(j);return A(),je}let N=await l({to:e.token.address,data:w,value:"0"});return A(),N}catch(w){let U=w instanceof Error?w:new Error("Approve failed");throw m()&&p(U),U}},[e,t,o,s,n,i,g,x,l,r,A,y,m]),D=(0,ke.useCallback)(async E=>{try{if(y(),!t)throw new se.WalletError("wallet_unavailable","No public client");let w=(0,he.readDecimals)(R.current,e.token,e.token.decimals);w===void 0&&(w=await t.readContract({address:e.token.address,abi:se.ERC20_MIN_ABI,functionName:"decimals"}),y(),(0,he.writeDecimals)(R.current,e.token,w));let U=(0,se.parseUnits)(E,w);return await W(U)}catch(w){throw m()&&p(w instanceof Error?w:new Error("Approve failed")),w}},[e.token,t,W,y,m]),B=(0,ke.useCallback)(async()=>W(Fs),[W]),f=(0,ke.useCallback)(async E=>{if(!m()||!n||!x||!t)return!1;try{y()}catch(j){return p(j instanceof Error?j:new Error("Cannot check allowance")),!1}let w=C??await A();if(w===null)return!1;let U=(0,he.readDecimals)(R.current,e.token,e.token.decimals);if(U===void 0){if(!t)throw new se.WalletError("wallet_unavailable","Cannot check allowance: no public client to read token decimals.");if(U=await t.readContract({address:e.token.address,abi:se.ERC20_MIN_ABI,functionName:"decimals"}),!m())return!1;(0,he.writeDecimals)(R.current,e.token,U)}let N=(0,se.parseUnits)(E,U);return m()&&w>=N},[C,A,e.token.address,e.token.chainId,e.token.decimals,t,m,y,n,x]);return{approve:D,approveMax:B,allowance:P,allowanceRaw:C,hasAllowance:f,isApproving:c,isFetchingAllowance:b,error:T,refetchAllowance:A}}var We=require("@naculus/connect-appkit-core"),qe=require("@naculus/connect-core"),mt=require("react");function Ks(e){return e.includes(":")?e.split(":").pop():e}function to(e){let{publicClient:t,walletClient:o}=ue(),{evmAccount:s,isConnected:n}=K(),{currentChain:u}=ce(),{session:i,client:g}=I(),{sendTransaction:l,isSending:c,error:h,reset:r}=dt(),[a,p]=(0,mt.useState)(null),{isCurrent:d,assertCurrent:m}=ut({token:e.token,chainId:u?(0,We.chainNumber)(u)??void 0:void 0,owner:s,connected:n,publicClient:t,walletClient:o,session:i,client:g}),y=(0,mt.useRef)((0,We.createDecimalsCache)(e.token,e.token.decimals)),S=a??h;return{sendTransfer:(0,mt.useCallback)(async(C,b)=>{if(p(null),r(),!n||!s){let R=new qe.WalletError("wallet_unavailable","No connected account");throw p(R),R}if(!t){let R=new qe.WalletError("wallet_unavailable","No public client available");throw p(R),R}try{m();let R=Ks(s),k=(0,We.readDecimals)(y.current,e.token,e.token.decimals);k===void 0&&(k=await t.readContract({address:e.token.address,abi:qe.ERC20_MIN_ABI,functionName:"decimals"}),m(),(0,We.writeDecimals)(y.current,e.token,k));let T=(0,qe.parseUnits)(b,k),x=(0,We.encodeErc20Transfer)(C,T),A=_(g);if(i&&A)return await l({to:e.token.address,data:x,value:"0"});if(o){let{request:W}=await t.simulateContract({address:e.token.address,abi:qe.ERC20_MIN_ABI,functionName:"transfer",args:[C,T],account:R});return m(),await o.writeContract(W)}return await l({to:e.token.address,data:x,value:"0"})}catch(R){let k=R instanceof Error?R:new Error("Transfer failed");throw d()&&p(k),k}},[e.token,t,o,s,n,i,g,l,r,m,d]),isSending:c,error:S}}var sn=require("@naculus/connect-appkit-core"),ro=require("@naculus/connect-core"),oo=require("react");var no=require("@naculus/connect-appkit-core"),Re=require("react");function on(e,t){I();let{evmAccount:o}=K(),{currentChain:s}=ce(),{publicClient:n}=ue(),[u,i]=(0,Re.useState)(void 0),[g,l]=(0,Re.useState)(!1),[c,h]=(0,Re.useState)(null),r=(0,Re.useRef)(void 0),a=(0,Re.useCallback)(async()=>{e&&(l(!0),h(null));try{let d=await(0,no.simulateTransactionPreview)(e,{chainId:t,currentChain:s,publicClient:n,evmAccount:o});return i(d),d}catch(d){let m=d instanceof Error?d:new Error("Simulation failed");throw h(m),m}finally{e&&l(!1)}},[e,t,s,n,o]);(0,Re.useEffect)(()=>{if(e)return r.current&&clearTimeout(r.current),r.current=setTimeout(()=>{a().catch(()=>{})},300),()=>{r.current&&clearTimeout(r.current)}},[e,a]);let p=(0,Re.useCallback)(()=>{i(void 0),h(null),l(!1)},[]);return{result:u,isSimulating:g,error:c,simulate:a,reset:p}}function so(e){let{evmAccount:t,isConnected:o}=K(),{currentChain:s}=ce(),n=e.token.chainId??(s?(0,sn.chainNumber)(s)??void 0:void 0),u=(0,oo.useMemo)(()=>{if(!(!o||!t))try{let g=e.token.decimals;if(g===void 0)return;let l=(0,ro.parseUnits)(e.amount,g),c=(0,sn.encodeErc20Transfer)(e.to,l);return{to:e.token.address,data:c,value:"0"}}catch{return}},[e.token.address,e.token.decimals,e.to,e.amount,t,o]),i=on(u,n);return{result:u?i.result:void 0,isSimulating:!!u&&i.isSimulating,error:u?i.error:null,reSimulate:i.simulate,reset:i.reset}}var Ne=require("react");var xe=require("react"),an=require("react"),tr=(0,an.createContext)(null);function Rt(){return(0,an.useContext)(tr)}function ao(e,t,o){let s=Rt(),n=o??s,[u,i]=(0,xe.useState)(null),[g,l]=(0,xe.useState)(!1),[c,h]=(0,xe.useState)(!1),[r,a]=(0,xe.useState)(null),p=(0,xe.useRef)(void 0),d=(0,xe.useCallback)(async()=>{if(!(!n||!e)){l(!0),a(null);try{await n.refreshTx(e,t);let S=n.getTxStatus(e,t);S&&i(S)}catch(S){a(S instanceof Error?S:new Error(String(S)))}finally{l(!1)}}},[n,e,t]),m=(0,xe.useCallback)(()=>{!n||!e||(n.stopWatching(e,t),h(!1))},[n,e,t]);(0,xe.useEffect)(()=>{if(!n||!e||!t){i(null),h(!1);return}p.current&&p.current!==e&&n.stopWatching(p.current),p.current=e;let S=!1;h(!0),l(!0),a(null);let v=n.getTxStatus(e,t);v&&(i(v),l(!1)),n.watchTx(e,t,{}).then(b=>{S||(i(b),l(!1))}).catch(b=>{S||(a(b instanceof Error?b:new Error(String(b))),l(!1))});let C=b=>{S||i({...b})};return n.on("statusChange",C),()=>{S=!0,h(!1),n.off("statusChange",C)}},[n,e,t]);let y=u?.status??"idle";return{entry:u,status:y,isLoading:g,isWatching:c,error:r,refresh:d,stopWatching:m}}function io(e){let t=Rt(),o=e??t,[s,n]=(0,Ne.useState)(null),[u,i]=(0,Ne.useState)(null),[g,l]=(0,Ne.useState)(null),c=(0,Ne.useRef)(null),h=(0,Ne.useRef)(null),r=(0,Ne.useRef)(null);o&&(h.current||(h.current=p=>{i(p),(!c.current||p.createdAt>=c.current.createdAt)&&(n(p),c.current=p)},o.on("confirmed",h.current)),r.current||(r.current=p=>{l(p),(!c.current||p.createdAt>=c.current.createdAt)&&(n(p),c.current=p)},o.on("failed",r.current)));let a=(0,Ne.useCallback)(()=>{n(null),i(null),l(null),c.current=null},[]);return{lastTx:s,lastConfirmedTx:u,lastFailedTx:g,clear:a}}var co=require("react");var pe=require("react"),lo=require("@naculus/connect-appkit-core");function ln({input:e,skip:t=!1,resolverConfig:o,scope:s,query:n}){let[u,i]=(0,pe.useState)(null),[g,l]=(0,pe.useState)(!1),[c,h]=(0,pe.useState)(null),r=(0,pe.useRef)(0),a=(0,pe.useRef)(!0);(0,pe.useEffect)(()=>(a.current=!0,()=>{a.current=!1}),[]);let p=(0,pe.useMemo)(()=>(0,lo.getResolver)(o),[o]),d=(0,pe.useCallback)(()=>{let m=e.trim();if(!m||t){r.current+=1,i(null),l(!1),h(null);return}let y=++r.current;l(!0),h(null),n(p,m,s).then(S=>{!a.current||y!==r.current||(i(S),l(!1))}).catch(S=>{!a.current||y!==r.current||(h(S instanceof Error?S:new Error(String(S))),i(null),l(!1))})},[e,t,s,p,n]);return(0,pe.useEffect)(()=>{d()},[d]),{data:u,isLoading:g,error:c,refetch:d}}function uo(e,t){let o=(0,co.useCallback)((s,n,u)=>s.lookupAddress(n,u),[]);return ln({input:e,skip:t?.skip,resolverConfig:t?.resolverConfig,scope:t?.chainId,query:o})}var z=require("react"),$=require("@naculus/connect-appkit-core"),po=require("@naculus/connect-core");function mo(e){let t=(0,z.useRef)(null);t.current||(t.current=e?.channel??new po.InAppChannel);let o=t.current,[s,n]=(0,z.useState)(()=>o.getHistory()),[u,i]=(0,z.useState)(()=>$.DEFAULT_NOTIFICATION_SETTINGS),g=(0,z.useRef)([]);(0,z.useEffect)(()=>{let C=e?.storage??(0,$.createNotificationSettingsStorage)(),b=R=>{let k=g.current??[];if(g.current=null,k.length===0){R&&i(R);return}i(()=>{let T=(0,$.replayNotificationSettings)(R,k);return(0,$.saveNotificationSettings)(C,T),T})};(0,$.loadNotificationSettings)(C).then(b,()=>b(null))},[]),(0,z.useEffect)(()=>(o.onNotification=C=>{n(b=>[...b,C])},o.restore().then(()=>{n(o.getHistory())}),()=>{o.onNotification=void 0}),[]);let l=(0,z.useMemo)(()=>s.filter(C=>!C.read).length,[s]),c=(0,z.useCallback)(()=>{o.clear(),n([])},[o]),h=(0,z.useCallback)(C=>{(0,$.clearOneInAppNotification)(o,C).then(()=>{n(o.getHistory())})},[o]),r=(0,z.useCallback)(C=>{o.markAsRead(C),n(b=>b.map(R=>R.id===C?{...R,read:!0}:R))},[o]),a=(0,z.useCallback)(()=>{o.markAllAsRead(),n(C=>C.map(b=>({...b,read:!0})))},[o]),p=(0,z.useCallback)(C=>{(0,$.addInAppNotification)(o,C)},[o]),d=(0,z.useCallback)(C=>{g.current?.push(C),i(b=>{let R=(0,$.updateNotificationSettings)(b,C(b)),k=e?.storage??(0,$.createNotificationSettingsStorage)();return(0,$.saveNotificationSettings)(k,R),R})},[e?.storage]),m=(0,z.useCallback)(C=>d(()=>C),[d]),y=(0,z.useCallback)(C=>{m((0,$.channelsUpdate)(C))},[m]),S=(0,z.useCallback)(C=>{d(b=>(0,$.mutedChainSettings)(b,C,!0))},[d]),v=(0,z.useCallback)(C=>{d(b=>(0,$.mutedChainSettings)(b,C,!1))},[d]);return{notifications:s,unreadCount:l,addNotification:p,clear:c,clearOne:h,markAsRead:r,markAllAsRead:a,settings:u,updateSettings:m,setChannels:y,muteChain:S,unmuteChain:v}}var ft=require("react");var fo=()=>null,Hs=()=>()=>{};function go(){let{client:e}=I(),t=_(e)?.passphraseGate??null,o=(0,ft.useSyncExternalStore)(t?.subscribe??Hs,t?.getSnapshot??fo,fo),s=(0,ft.useCallback)(i=>t?.submit(i),[t]),n=(0,ft.useCallback)(()=>t?.cancel(),[t]),u=(0,ft.useCallback)(i=>t?.forget(i),[t]);return{request:o,submit:s,cancel:n,forget:u,isUnlocked:t?.isUnlocked??!1,gate:t}}var ho=require("react");function yo(e,t){let o=(0,ho.useCallback)((s,n)=>s.resolveName(n),[]);return ln({input:e,skip:t?.skip,resolverConfig:t?.resolverConfig,query:o})}var Oe=require("@naculus/connect-appkit-core"),Qe=require("@naculus/connect-core"),ae=require("react");async function qs(e,t,o,s,n){let u=_(t);if(!u)throw new Qe.WalletError("wallet_unavailable","Client not initialized");let i=[o,s];if(e.walletType==="eip6963"||e.id?.startsWith("eip6963-")){let{eip6963Connector:g}=await import("@naculus/connector-evm-injected"),l=g.getDiscoveredWallets().find(h=>h.id===e.walletId),c=l?await l.provider.request({method:"personal_sign",params:i}):await g.request({method:"personal_sign",params:i});return(0,Oe.assertHexSignature)(c)}if(e.walletType==="walletconnect")return(0,Oe.assertHexSignature)(await u.connector.request({method:"personal_sign",params:i}));if(e.walletType==="embedded"){let g=u.embeddedConnector;if(!g?.signHash)throw new Qe.WalletError("method_unsupported","This embedded wallet build cannot sign a raw digest. Upgrade @naculus/connector-embedded or pass an explicit signer.");return(0,Oe.assertHexSignature)(await g.signHash(e,o))}throw e.walletType==="passkeys"?new Qe.WalletError("method_unsupported","Passkeys sign with P-256, which a SimpleAccount cannot verify. Use a smart account with a WebAuthn validator, or pass an explicit signer."):new Qe.WalletError("method_unsupported",`Raw UserOperation signing is not available for ${e.walletType} on ${n}. Pass a signer that signs the raw 32-byte hash.`)}function Co(e){let{evmAccount:t}=K(),{session:o,chainId:s,client:n}=I(),[u,i]=(0,ae.useState)(null),[g,l]=(0,ae.useState)(null),[c,h]=(0,ae.useState)(!1),[r,a]=(0,ae.useState)(!1),[p,d]=(0,ae.useState)(null),m=(0,ae.useRef)(0),y=(0,ae.useRef)(!1);(0,ae.useEffect)(()=>()=>{m.current+=1,y.current=!1},[]),(0,ae.useEffect)(()=>{m.current+=1,y.current=!1,i(null),l(null),h(!1),a(!1),d(null)},[n,s,t,e?.accountType,e?.bundlerUrl,e?.chainId,e?.entryPoint,e?.owner,e?.rpcUrl,e?.salt,e?.signerMode,o]);let S=(0,ae.useCallback)(async(C,b)=>{let R=A=>(d(A),null);if(!e?.rpcUrl)return R(new Error("RPC URL not configured"));if(!e.bundlerUrl)return R(new Error("Bundler URL not configured"));if(!C.length)return R(new Error("At least one call is required"));if(y.current)return R(new Error("A UserOperation is already in progress"));let k=(0,Oe.bareEvmAddress)(e.owner??t);if(!k)return R(new Qe.WalletError("wallet_unavailable","No EVM account found"));let T;try{T=(0,Oe.resolveUserOpChain)(e.chainId,s)}catch(A){return R(A)}if(!e.signer&&!o)return R(new Qe.WalletError("wallet_unavailable","No active session"));let x=++m.current;y.current=!0,h(!0),a(!0),d(null),i(null),l(null);try{let{SmartAccountManager:A}=await import("@naculus/connect-core"),P=e.signer??(f=>qs(o,n,f,k,T)),W=new A({rpcUrl:e.rpcUrl,bundlerClient:{url:e.bundlerUrl},chainId:T,signer:P,signerMode:e.signer?e.signerMode??"eip191":"raw"}),D=(0,Oe.buildSmartAccountConfig)(k,T,e),B=await W.sendUserOperation(D,C,b);return x!==m.current?null:(a(!1),i(B.userOpHash),W.getUserOperationReceipt(B.userOpHash).then(f=>{x===m.current&&l(f)}).catch(()=>{}),B)}catch(A){if(x!==m.current)return null;let P=A instanceof Error?A:new Error("Failed to send UserOperation");return d(P),null}finally{y.current=!1,x===m.current&&(h(!1),a(!1))}},[n,s,t,e,o]),v=(0,ae.useCallback)(()=>{m.current+=1,i(null),l(null),h(!1),a(!1),d(null)},[]);return{sendUserOp:S,userOpHash:u,receipt:g,isPending:c,isEstimating:r,error:p,reset:v}}var Tt=require("react");function Vs(e,t){if(!e)return()=>{};let o=()=>t();return e.on("sessionConnected",o),e.on("sessionDisconnected",o),e.on("chainChanged",o),e.on("sessionScopeChanged",o),e.on("sessionRevoked",o),()=>{e.off("sessionConnected",o),e.off("sessionDisconnected",o),e.off("chainChanged",o),e.off("sessionScopeChanged",o),e.off("sessionRevoked",o)}}var nr=Object.freeze({session:null,chainSessions:[],activeChainId:null,isConnected:!1,connectorId:null}),rr=new WeakMap;function js(e,t){if(e.length!==t.length)return!1;for(let o=0;o<e.length;o++)if(e[o]!==t[o])return!1;return!0}function $s(e){if(!e)return nr;let t=e.getActiveBundle(),o=rr.get(e);if(!t)return o&&o.session===null?o:(rr.set(e,nr),nr);let s=Array.from(t.chainSessions.values());if(o&&o.session===t.walletSession&&o.activeChainId===t.activeChainId&&js(o.chainSessions,s))return o;let n={session:t.walletSession,chainSessions:s,activeChainId:t.activeChainId,isConnected:!0,connectorId:t.walletSession.walletType};return rr.set(e,n),n}function So(e){let t=I(),o=e??t.sessionManager??null,s=(0,Tt.useCallback)(u=>Vs(o,u),[o]),n=(0,Tt.useCallback)(()=>$s(o),[o]);return(0,Tt.useSyncExternalStore)(s,n)}var cn=require("@naculus/connect-appkit-core"),It=require("@naculus/connect-core"),_e=require("@naculus/siwx"),gt=require("react");var Gs=86400;function un(){let{session:e,chainId:t,client:o}=I(),[s,n]=(0,gt.useState)(!1),[u,i]=(0,gt.useState)(null),g=(0,gt.useCallback)(()=>i(null),[]);return{signIn:(0,gt.useCallback)(async c=>{if(!e)throw new It.WalletError("wallet_unavailable","No active session");let h=c?.chainId??t;if(!h)throw new It.WalletError("invalid_chain","No chain to sign for. Connect a wallet or pass options.chainId.");let r=tt(e,h);if(!r)throw new It.WalletError("wallet_unavailable","No account found");let a=_(o);if(!a)throw new It.WalletError("wallet_unavailable","Client not initialized");let{address:p}=r,d=typeof window>"u"?void 0:window.location,m=c?.domain??(0,cn.defaultSiwxDomain)(d),y=c?.uri??(0,cn.defaultSiwxUri)(d);n(!0),i(null);try{let S=(0,_e.generateNonce)();await(0,_e.issueNonce)(S);let v=(0,_e.nowISO)(),C=c?.expirySeconds??Gs,b=new Date(Date.now()+C*1e3).toISOString(),R=(0,_e.createSiwxMessage)({domain:m,address:p,uri:y,version:1,chainId:h,nonce:S,issuedAt:v,expirationTime:b,statement:c?.statement,resources:c?.resources,requestId:c?.requestId}),k=await a.signMessage(e,{message:R,address:p,chainId:h??void 0}),T={message:{raw:R,domain:m,address:p,statement:c?.statement??null,uri:y,version:1,chainId:h,nonce:S,issuedAt:v,blockchain:(0,_e.getBlockchainName)(h),expirationTime:b,notBefore:null,resources:c?.resources??[],requestId:c?.requestId??null},signature:k};return n(!1),T}catch(S){let v=S instanceof Error?S:new Error("SIWx sign-in failed");throw i(v),n(!1),v}},[e,t,o]),isSigningIn:s,error:u,clearError:g}}var or=require("@naculus/connect-appkit-core"),pn=require("@naculus/connect-core"),Ut=require("@naculus/siwx"),ie=require("react");function Eo(e){let{storagePrefix:t="naculus_",autoRestore:o=!0,defaultExpirySeconds:s=86400}=e??{},[n,u]=(0,ie.useState)(null),[i,g]=(0,ie.useState)(o),[l,c]=(0,ie.useState)(!1),[h,r]=(0,ie.useState)(null),{chainId:a}=I(),p=un(),d=(0,ie.useRef)((0,Ut.createLocalStorageSiwxSessionStorage)(`${t}siwx_session`)),m=(0,ie.useCallback)(()=>r(null),[]);(0,ie.useEffect)(()=>{if(!o){g(!1);return}let k=!1;return(async()=>{try{let x=await d.current.get();if(k)return;x?(pn.logger.info("react/useSIWxSession","Restored persisted SIWx session"),u(x),r(null)):u(null)}catch(T){pn.logger.warn("react/useSIWxSession","Failed to restore SIWx session:",T),u(null)}finally{k||g(!1)}})(),()=>{k=!0}},[o]),(0,ie.useEffect)(()=>{if(!n?.expiresAt)return;let k=new Date(n.expiresAt).getTime()-Date.now();if(k<=0){u(null);return}let T=setTimeout(()=>{u(x=>x&&x.id===n.id?null:x)},k);return()=>clearTimeout(T)},[n?.id,n?.expiresAt]);let y=(0,ie.useCallback)(async k=>{c(!0),r(null);try{let T={expirySeconds:s,chainId:a??void 0,...k},x=await p.signIn(T),A=(0,or.siwxResultToSession)(x);return await d.current.set(A),u(A),c(!1),A}catch(T){let x=T instanceof Error?T:new Error("SIWx sign-in failed");throw r(x),c(!1),x}},[p,a,s]),S=(0,ie.useCallback)(async()=>{try{await d.current.remove()}catch(k){pn.logger.warn("react/useSIWxSession","Failed to clear session:",k)}u(null),r(null)},[]),v=(0,ie.useCallback)(async()=>{if(!n)throw new Error("No active session to refresh");c(!0),r(null);try{let k=await p.signIn({domain:n.domain,statement:n.message.statement??void 0,uri:n.message.uri,chainId:n.chainId,expirySeconds:s,resources:n.message.resources.length>0?n.message.resources:void 0,requestId:n.message.requestId??void 0}),T={...(0,or.siwxResultToSession)(k),id:n.id,refreshedAt:new Date().toISOString()};return await d.current.set(T),u(T),c(!1),T}catch(k){let T=k instanceof Error?k:new Error("Session refresh failed");throw r(T),c(!1),T}},[n,p,s]),C=n!==null&&!(0,Ut.checkSessionExpired)(n),b=(0,Ut.checkSessionExpired)(n),R=n?.expiresAt?Math.max(0,new Date(n.expiresAt).getTime()-Date.now()):null;return{session:C?n:null,isAuthenticated:C,isRestoring:i,isSigningIn:l,isExpired:b,timeUntilExpiry:R,signIn:y,signOut:S,refresh:v,error:h,clearError:m}}var dn=require("@naculus/connect-appkit-core"),Pt=require("@naculus/connect-core"),De=require("@naculus/siwx"),Xe=require("react");function ht(){let{session:e,chainId:t,client:o}=I(),[s,n]=(0,Xe.useState)(!1),[u,i]=(0,Xe.useState)(null),[g,l]=(0,Xe.useState)(null),c=(0,Xe.useCallback)(()=>l(null),[]);return{signIn:(0,Xe.useCallback)(async r=>{if(!e)throw new Pt.WalletError("wallet_unavailable","No active session");let a=r?.chainId??t;if(!a)throw new Pt.WalletError("invalid_chain","No chain to sign for. Connect a wallet or pass options.chainId.");let p=tt(e,a);if(!p)throw new Pt.WalletError("wallet_unavailable","No account found");let d=_(o);if(!d)throw new Pt.WalletError("wallet_unavailable","Client not initialized");let{address:m}=p,y=typeof window>"u"?void 0:window.location,S=r?.domain??(0,dn.defaultSiwxDomain)(y),v=r?.uri??(0,dn.defaultSiwxUri)(y);n(!0),l(null);try{let C=(0,De.generateNonce)();await(0,De.issueNonce)(C);let b=(0,De.nowISO)(),R=(0,De.createSiwxMessage)({domain:S,address:m,uri:v,version:1,chainId:a,nonce:C,issuedAt:b,statement:r?.statement,expirationTime:r?.expirySeconds?new Date(Date.now()+r.expirySeconds*1e3).toISOString():void 0,resources:r?.resources,requestId:r?.requestId}),k=await d.signMessage(e,{message:R,address:m,chainId:a??void 0}),T=r?.expirySeconds?new Date(Date.now()+r.expirySeconds*1e3).toISOString():null,x={message:{raw:R,domain:S,address:m,statement:r?.statement??null,uri:v,version:1,chainId:a,nonce:C,issuedAt:b,blockchain:(0,De.getBlockchainName)(a),expirationTime:T,notBefore:null,resources:r?.resources??[],requestId:r?.requestId??null},signature:k};return i(x),x}catch(C){let b=C instanceof Error?C:new Error("SIWx sign-in failed");throw l(b),b}finally{n(!1)}},[e,t,o]),isSigningIn:s,result:u,error:g,clearError:c}}var mn=require("@naculus/connect-core");var sr=require("react");function zs(){let{session:e,chainId:t}=I();return(0,sr.useCallback)(o=>{if(!e)throw new mn.WalletError("wallet_unavailable","No active session");let s=o??t;if(s&&!s.startsWith("eip155:"))throw new mn.WalletError("namespace_mismatch",`Ethereum SIWx requires an eip155 chain, received ${s}`);let n=e.namespaces.eip155;if(!n||n.accounts.length===0)throw new mn.WalletError("namespace_mismatch","No EVM (eip155) accounts found in session")},[e,t])}function wo(){let e=zs(),t=ht();return{signIn:(0,sr.useCallback)(async s=>(e(s?.chainId),t.signIn(s)),[e,t.signIn]),isSigningIn:t.isSigningIn,result:t.result,error:t.error,clearError:t.clearError}}var ko=require("@naculus/connect-appkit-core"),xo=require("@naculus/wallet-engine"),Me=require("react");function vo(e){let t=e?.rpcUrl,o=e?.chainId,s=(0,Me.useRef)(null),n=(0,Me.useCallback)(()=>(s.current||(s.current=new xo.SimulationManager({enabled:!0,rpcUrl:t,autoSimulate:!1})),s.current),[t]),[u,i]=(0,Me.useState)(null),[g,l]=(0,Me.useState)(!1),[c,h]=(0,Me.useState)(null),r=(0,Me.useCallback)(async(p,d,m,y,S)=>{l(!0),h(null);try{let v=n(),C=(0,ko.resolveSimulationEndpoint)(S?.chainId,o,S?.rpcUrl,t),b=await v.simulateERC20Transfer(p,d,m,y,C.chainId,S?.decimals,C.rpcUrl);return i(b),b}catch(v){let C=v instanceof Error?v:new Error(String(v));throw h(C),C}finally{l(!1)}},[t,o,n]),a=(0,Me.useCallback)(()=>{i(null),h(null),l(!1)},[]);return{result:u,loading:g,error:c,simulate:r,reset:a}}var gn=require("@naculus/connect-appkit-core"),Ye=require("@naculus/connect-core"),ye=require("react");var fn="siwx_auth";function Qs(e){return new Ye.LocalStorageAdapter(e)}function bo(e){let{storagePrefix:t="naculus_",autoRestore:o=!0}=e??{},[s,n]=(0,ye.useState)(null),[u,i]=(0,ye.useState)(o),[g,l]=(0,ye.useState)(!1),[c,h]=(0,ye.useState)(null),r=ht(),a=(0,ye.useRef)(Qs(t)),p=(0,ye.useCallback)(()=>h(null),[]);(0,ye.useEffect)(()=>{if(!o){i(!1);return}let y=!1;return(async()=>{try{let S=a.current,v=await S.get(fn);if(y)return;v&&!(0,gn.isSiwxExpired)(v,new Date)&&(0,gn.isSiwxNotBeforeValid)(v,new Date)?(Ye.logger.info("react/useSiwxAuthSession","Restored persisted SIWx auth session"),n(v),h(null)):v&&(Ye.logger.info("react/useSiwxAuthSession","Persisted SIWx auth expired, clearing"),await S.remove(fn))}catch(S){Ye.logger.warn("react/useSiwxAuthSession","Failed to restore SIWx auth:",S)}finally{y||i(!1)}})(),()=>{y=!0}},[o]);let d=(0,ye.useCallback)(async y=>{l(!0),h(null);try{let S=await r.signIn(y);return await a.current.set(fn,S),n(S),l(!1),S}catch(S){let v=S instanceof Error?S:new Error("SIWx sign-in failed");throw h(v),l(!1),v}},[r]),m=(0,ye.useCallback)(async()=>{try{await a.current.remove(fn)}catch(y){Ye.logger.warn("react/useSiwxAuthSession","Failed to clear SIWx auth:",y)}n(null),h(null)},[]);return{isSignedIn:s!==null,isRestoring:u,siwxResult:s,isSigningIn:g,error:c,signIn:d,signOut:m,clearError:p}}var Je=require("@naculus/connect-appkit-core"),ar=require("@naculus/connect-core"),Q=require("react");function Ao(e){return new ar.WalletError("wallet_unavailable",e)}function Ro(e){let{evmAccount:t}=K(),{session:o,chainId:s,client:n}=I(),[u,i]=(0,Q.useState)(null),[g,l]=(0,Q.useState)(!1),[c,h]=(0,Q.useState)(null),[r,a]=(0,Q.useState)(!1),[p,d]=(0,Q.useState)(null),m=(0,Q.useRef)(null),y=(0,Q.useRef)(0),S=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{if(m.current=null,!e?.rpcUrl)return;let A=!1;return import("@naculus/connect-core").then(({SmartAccountManager:P})=>{if(A)return;let W=(0,Je.resolveEvmChainId)(e.chainId,s);W&&(m.current=new P({rpcUrl:e.rpcUrl,chainId:W,bundlerClient:{url:e.bundlerUrl??""}}))}).catch(P=>{A||d(P instanceof Error?P:new Error("Failed to load account-abstraction module"))}),()=>{A=!0}},[s,e?.rpcUrl,e?.bundlerUrl,e?.chainId]),(0,Q.useEffect)(()=>{y.current+=1,S.current=!1,i(null),l(!1),h(null),a(!1),d(null)},[t,s,e?.rpcUrl,e?.bundlerUrl,e?.chainId,e?.entryPoint,e?.accountType,e?.salt]);let v=(0,Q.useCallback)(()=>{let A=(0,Je.bareEvmAddress)(t);if(!A||!m.current)return null;let P=(0,Je.resolveEvmChainId)(e?.chainId,s);return P?(0,Je.buildSmartAccountConfig)(A,P,{accountType:e?.accountType,entryPoint:e?.entryPoint,salt:e?.salt}):null},[t,s,e?.accountType,e?.chainId,e?.entryPoint,e?.salt]),C=(0,Q.useCallback)(A=>(d(A),null),[]),b=(0,Q.useCallback)(()=>S.current?null:(S.current=!0,y.current),[]),R=(0,Q.useCallback)(A=>{y.current===A&&(S.current=!1)},[]),k=(0,Q.useCallback)(async()=>{let A=v();if(!A||!m.current)return C(new Error("Smart account not configured"));let P=b();if(P===null)return C(new Error("Smart account operation already in progress"));a(!0),d(null);try{let D=await m.current.createAccount(A);return y.current!==P?null:(i(D.address),l(D.isDeployed),h(D),D)}catch(W){if(y.current!==P)return null;let D=W instanceof Error?W:new Error("Failed to create smart account");return d(D),null}finally{y.current===P&&a(!1),R(P)}},[b,C,R,v]),T=(0,Q.useCallback)(async()=>{let A=v();if(!A||!m.current)return C(new Error("Smart account not configured"));if(!o)return C(Ao("No active session"));let P=_(n);if(!P)return C(Ao("Client not initialized"));if(s&&s!==A.chainId)return C(new ar.WalletError("chain_mismatch",`Connected chain ${s} does not match smart account chain ${A.chainId}.`));let W=b();if(W===null)return C(new Error("Smart account operation already in progress"));a(!0),d(null);try{let D=m.current,B=await D.createAccount(A);if(y.current!==W)return null;if(B.isDeployed)return i(B.address),l(!0),h(B),B.address;let f=await D.getDeployCallData(A),E=await P.sendTransaction(o,{transaction:{to:f.to,data:f.data,value:f.value.toString()},chainId:A.chainId});if(y.current!==W)return null;let w=await D.createAccount(A);return i(w.address),l(w.isDeployed),h(w),E}catch(D){if(y.current!==W)return null;let B=D instanceof Error?D:new Error("Failed to deploy smart account");return d(B),null}finally{y.current===W&&a(!1),R(W)}},[n,s,b,C,R,v,o]),x=(0,Q.useCallback)(async()=>{let A=v();if(!A||!m.current)return null;let P=y.current;try{let W=await m.current.getAccountAddress(A);return y.current!==P?null:(i(W),W)}catch(W){return y.current!==P||d(W instanceof Error?W:new Error("Failed to get smart account address")),null}},[v]);return{address:u,isDeployed:g,accountInfo:c,isLoading:r,error:p,createWallet:k,deployWallet:T,getAddress:x}}var To=require("react");function hn(){let{accounts:e,isConnected:t}=I();return(0,To.useMemo)(()=>{if(!t)return{address:null,caip10:null,chainId:null,isConnected:!1};let o=e.find(i=>i.startsWith("solana:"))??null;if(!o)return{address:null,caip10:null,chainId:null,isConnected:t};let s=o.split(":"),n=s.length>=3?s[s.length-1]:null,u=s.length>=3?s.slice(0,-1).join(":"):null;return{address:n,caip10:o,chainId:u,isConnected:t}},[e,t])}var Te=require("react"),Io=require("@naculus/connect-core");function Uo(e={}){let{client:t}=I(),{address:o}=hn(),s=e.address??o,n=e.rpcUrl??_(t)?.solanaRpcUrl??null,[u,i]=(0,Te.useState)(null),[g,l]=(0,Te.useState)(!1),[c,h]=(0,Te.useState)(null),r=(0,Te.useRef)(0),a=(0,Te.useCallback)(async()=>{if(!s||!n){i(null);return}let p=++r.current;l(!0),h(null);try{let d=await(0,Io.getSolanaBalance)(n,s);if(p!==r.current)return;i(d)}catch(d){if(p!==r.current)return;i(null),h(d instanceof Error?d:new Error("Balance read failed"))}finally{p===r.current&&l(!1)}},[s,n]);return(0,Te.useEffect)(()=>{a()},[a]),(0,Te.useEffect)(()=>{if(!e.refreshInterval||e.refreshInterval<=0)return;let p=setInterval(()=>{a()},e.refreshInterval);return()=>clearInterval(p)},[e.refreshInterval,a]),{balance:u,isFetching:g,error:c,isConfigured:!!n,refetch:a}}var Po=require("@naculus/connect-appkit-core"),Wo=require("react");function No(){let{client:e,session:t,accounts:o}=I();return(0,Wo.useMemo)(()=>{let s=_(e)?.solanaConnector,{roles:n,absence:u}=(0,Po.readSolanaRoles)(s,t);return{roles:n,absence:u,identity:n?.identity??null,signer:n?.signer??null,payer:n?.payer??null}},[e,t,o])}var ir=require("@naculus/connect-core"),Ve=require("react"),Oo=require("@naculus/connect-core");function _o(){let{client:e,session:t}=I(),[o,s]=(0,Ve.useState)(!1),[n,u]=(0,Ve.useState)(!1),[i,g]=(0,Ve.useState)(null),l=()=>{let a=_(e);if(!a||!t)throw new ir.WalletError("wallet_unavailable","No connected wallet.");return a},c=(0,Ve.useCallback)(async a=>{s(!0),g(null);try{return await l().signTransaction(t,{transaction:a})}catch(p){let d=p instanceof Error?p:new Error("Signing failed");throw g(d),d}finally{s(!1)}},[e,t]),h=(0,Ve.useCallback)(async a=>{u(!0),g(null);try{return await l().sendTransaction(t,{transaction:a})}catch(p){let d=p instanceof Error?p:new Error("Send failed");throw g(d),d}finally{u(!1)}},[e,t]),r=(0,Ve.useCallback)(async a=>{let p=_(e)?.solanaRpcUrl;if(!p)throw new ir.WalletError("no_rpc","Set solanaRpcUrl on the client to read a signature's status.");return(0,Oo.getSignatureStatus)(p,a)},[e]);return{signTransaction:c,sendTransaction:h,getStatus:r,isSigning:o,isSending:n,error:i,reset:()=>g(null)}}var yt=require("react"),Do=require("@naculus/connect-appkit-core");function Mo(){let{switchChain:e,chainId:t}=I(),[o,s]=(0,yt.useState)(!1),[n,u]=(0,yt.useState)(null),i=(0,yt.useCallback)(async l=>{s(!0),u(null);try{await e(l)}catch(c){let h=(0,Do.toChainSwitchError)(c);throw u(h),h}finally{s(!1)}},[e]),g=(0,yt.useCallback)(()=>{u(null)},[]);return{switchChain:i,isSwitching:o,currentChainId:t,error:n,clearError:g}}var Ct=require("@naculus/connect-appkit-core"),J=require("react");var St=require("viem"),Xs=[{name:"balanceOf",type:"function",stateMutability:"view",inputs:[{name:"owner",type:"address"}],outputs:[{name:"balance",type:"uint256"}]}];function Lo(e){let{evmAccount:t,isConnected:o}=K(),{chainId:s,chains:n}=I(),[u,i]=(0,J.useState)([]),[g,l]=(0,J.useState)(!1),[c,h]=(0,J.useState)(null),{tokens:r,refreshInterval:a}=e,p=(0,J.useRef)(null),d=(0,J.useMemo)(()=>r.map(k=>k.address.toLowerCase()+"|"+k.decimals+"|"+k.symbol).join(","),[r]),m=(0,J.useMemo)(()=>(0,Ct.resolveChain)(n,s),[s,n]),y=m?(0,Ct.chainNumber)(m):null,S=(0,J.useMemo)(()=>m?(0,Ct.toViemChain)(m,y):null,[m,y]),[v,C]=(0,J.useState)(null);(0,J.useEffect)(()=>{if(!S||!m?.rpcUrl){C(null);return}let k=(0,St.createPublicClient)({transport:(0,St.http)(m.rpcUrl),chain:S});C(k)},[m,S]);let b=(0,J.useCallback)(async()=>{if(!t||!v||r.length===0){i([]);return}l(!0),h(null);try{let k=t.includes(":")?t.split(":").pop():t,x=(await Promise.allSettled(r.map(async A=>{try{let P=await v.readContract({address:A.address,abi:Xs,functionName:"balanceOf",args:[k]});return{address:A.address,symbol:A.symbol,decimals:A.decimals,name:A.name,balance:P.toString(),formatted:(0,St.formatUnits)(P,A.decimals)}}catch{return{address:A.address,symbol:A.symbol,decimals:A.decimals,name:A.name,balance:null,formatted:null}}}))).map(A=>A.status==="fulfilled"?A.value:{address:"",symbol:"?",decimals:0,balance:null,formatted:null});i(x)}catch(k){h(k instanceof Error?k:new Error("Failed to fetch token balances"))}finally{l(!1)}},[t,v,d]);(0,J.useEffect)(()=>{o&&t&&r.length>0&&b()},[o,t,d,b]),(0,J.useEffect)(()=>(a&&a>0&&o&&t&&r.length>0&&(p.current=setInterval(b,a)),()=>{p.current&&(clearInterval(p.current),p.current=null)}),[a,o,t,d,b]);let R=(0,J.useCallback)(k=>u.find(T=>T.address.toLowerCase()===k.toLowerCase()),[u]);return{tokenBalances:u,isLoading:g,error:c,refetch:b,getTokenBalance:R,chain:m}}var Ie=require("react");function Bo(e,t,o){let s=Rt(),n=o??s,[u,i]=(0,Ie.useState)([]),[g,l]=(0,Ie.useState)(!1),[c,h]=(0,Ie.useState)(null),r=(0,Ie.useRef)(0),a=(0,Ie.useCallback)(async()=>{if(n){l(!0),h(null),r.current++;try{let d=await n.getTxHistory(e,t);i(d)}catch(d){h(d instanceof Error?d:new Error(String(d)))}finally{l(!1)}}},[n,e,t]);(0,Ie.useEffect)(()=>{a().catch(()=>{})},[a]),(0,Ie.useEffect)(()=>{if(!n)return;let d=()=>{a().catch(()=>{})};return n.on("statusChange",d),()=>{n.off("statusChange",d)}},[n,a]);let p={pending:u.filter(d=>d.status==="pending").length,confirmed:u.filter(d=>d.status==="confirmed").length,failed:u.filter(d=>d.status==="failed").length};return{entries:u,isLoading:g,error:c,refresh:a,summary:p}}var yn=require("@naculus/connect-appkit-core"),V=require("react");function Fo(e){let t=e?.bundlerUrl,o=e?.pollInterval??2e3,s=e?.maxRetries??30,[n,u]=(0,V.useState)("idle"),[i,g]=(0,V.useState)(null),[l,c]=(0,V.useState)(e?.userOpHash??null),[h,r]=(0,V.useState)(null),[a,p]=(0,V.useState)(!1),[d,m]=(0,V.useState)(0),y=(0,V.useRef)(0),[S,v]=(0,V.useState)(0),C=(0,V.useRef)(null),b=(0,V.useRef)(null),R=(0,V.useRef)(0),k=(0,V.useRef)(0),T=(0,V.useRef)(null),x=(0,V.useCallback)(()=>{C.current&&(clearInterval(C.current),C.current=null),b.current&&(clearTimeout(b.current),b.current=null)},[]),A=(0,V.useCallback)(async(E,w)=>{if(!t||w!==R.current)return;let U=k.current+1;k.current=U,m(U);let N=new AbortController;T.current=N;let j=de=>{w===R.current&&(u("not_found"),p(!1),x(),r(de))},je=de=>{if(w===R.current){if(U<=s){b.current=setTimeout(()=>{A(E,w)},o);return}j(de)}};try{let de=await(0,yn.fetchUserOperationReceipt)(t,E,N.signal);if(w!==R.current)return;if(de){g(de),u(de.success?"confirmed":"failed"),p(!1),x();return}u("pending"),je(new Error("UserOperation not included after maximum retries"))}catch(de){if(w!==R.current||N.signal.aborted)return;let kt=de instanceof Error?de:new Error("Unknown bundler response failure");if(kt instanceof yn.InvalidUserOperationReceiptError){j(kt);return}je(new Error(`UserOperation status unavailable after ${U} attempt${U===1?"":"s"}: ${kt.message}`))}finally{T.current===N&&(T.current=null)}},[t,o,s,x]),P=(0,V.useCallback)(E=>{R.current+=1;let w=R.current;if(T.current?.abort(),T.current=null,x(),c(E),g(null),r(null),k.current=0,m(0),v(0),y.current=Date.now(),!t){u("not_found"),p(!1),r(new Error("Bundler URL not configured"));return}u("pending"),p(!0),C.current=setInterval(()=>{v(Date.now()-y.current)},1e3),A(E,w)},[t,x,A]),W=(0,V.useCallback)(()=>{R.current+=1,T.current?.abort(),T.current=null,x(),p(!1)},[x]),D=(0,V.useCallback)(()=>{R.current+=1,T.current?.abort(),T.current=null,x(),c(null),u("idle"),g(null),r(null),p(!1),k.current=0,m(0),v(0)},[x]),B=e?.userOpHash??null,f=e?.autoStart!==!1;return(0,V.useEffect)(()=>{B&&f&&P(B)},[B,f,P]),(0,V.useEffect)(()=>()=>{R.current+=1,T.current?.abort(),T.current=null,x()},[x]),{status:n,receipt:i,userOpHash:l,error:h,isPolling:a,elapsedMs:S,attempts:d,start:P,stop:W,reset:D}}var Vo=require("@naculus/connect-appkit-core"),jo=require("react");var Ys={"storage.critical.title":"Insecure Storage Detected","storage.critical.body":"Your browser does not support IndexedDB. Wallet data is stored in plaintext in localStorage and could be exposed to XSS attacks. We strongly recommend switching to a modern browser.","storage.warning.title":"Storage Security Warning","storage.warning.body":"Your browser does not support IndexedDB, but your wallet data is encrypted with AES-256-GCM. Consider switching browsers for better origin isolation.","address.empty":"Address is empty","address.invalid_format":"Invalid address format (expected 0x + 40 hex chars)","address.zero_address":"Address is the zero address \u2014 funds would be permanently lost","address.burn_address":"Address appears to be a burn address \u2014 funds would be permanently lost","wallet.connect":"Connect Wallet","wallet.disconnect":"Disconnect","wallet.connecting":"Connecting...","wallet.copy_address":"Copy address","wallet.copied":"Copied!","wallet.view_on_explorer":"View on Explorer","wallet.retry":"Retry","wallet.connection_failed":"Connection failed","wallet.scan_qr":"Scan with your wallet app","embedded.generate":"Create Wallet","embedded.import":"Import Wallet","embedded.backup_seed":"Back up your seed phrase","embedded.backup_warning":"Anyone with your seed phrase can access your funds. Store it securely.","embedded.backup_done":"I've saved my seed phrase","embedded.wipe":"Remove Wallet","embedded.wipe_confirm":"Are you sure? This cannot be undone."},Js={"storage.critical.title":"\u5075\u6E2C\u5230\u4E0D\u5B89\u5168\u5132\u5B58","storage.critical.body":"\u60A8\u7684\u700F\u89BD\u5668\u4E0D\u652F\u63F4 IndexedDB\u3002\u9322\u5305\u8CC7\u6599\u4EE5\u660E\u6587\u5132\u5B58\u5728 localStorage \u4E2D\uFF0C\u53EF\u80FD\u66B4\u9732\u65BC XSS \u653B\u64CA\u3002\u5F37\u70C8\u5EFA\u8B70\u66F4\u63DB\u81F3\u73FE\u4EE3\u700F\u89BD\u5668\u3002","storage.warning.title":"\u5132\u5B58\u5B89\u5168\u8B66\u544A","storage.warning.body":"\u60A8\u7684\u700F\u89BD\u5668\u4E0D\u652F\u63F4 IndexedDB\uFF0C\u4F46\u9322\u5305\u8CC7\u6599\u5DF2\u4F7F\u7528 AES-256-GCM \u52A0\u5BC6\u3002\u5EFA\u8B70\u66F4\u63DB\u700F\u89BD\u5668\u4EE5\u7372\u5F97\u66F4\u597D\u7684\u9694\u96E2\u4FDD\u8B77\u3002","address.empty":"\u5730\u5740\u70BA\u7A7A","address.invalid_format":"\u7121\u6548\u7684\u5730\u5740\u683C\u5F0F\uFF08\u61C9\u70BA 0x + 40 \u500B\u5341\u516D\u9032\u4F4D\u5B57\u5143\uFF09","address.zero_address":"\u6B64\u70BA\u96F6\u5730\u5740 \u2014 \u8CC7\u91D1\u5C07\u6C38\u4E45\u4E1F\u5931","address.burn_address":"\u6B64\u5730\u5740\u70BA\u71D2\u6BC0\u5730\u5740 \u2014 \u8CC7\u91D1\u5C07\u6C38\u4E45\u4E1F\u5931","wallet.connect":"\u9023\u63A5\u9322\u5305","wallet.disconnect":"\u65B7\u958B\u9023\u7DDA","wallet.connecting":"\u9023\u7DDA\u4E2D...","wallet.copy_address":"\u8907\u88FD\u5730\u5740","wallet.copied":"\u5DF2\u8907\u88FD\uFF01","wallet.view_on_explorer":"\u5728\u700F\u89BD\u5668\u67E5\u770B","wallet.retry":"\u91CD\u8A66","wallet.connection_failed":"\u9023\u7DDA\u5931\u6557","wallet.scan_qr":"\u4F7F\u7528\u9322\u5305 App \u6383\u63CF","embedded.generate":"\u5EFA\u7ACB\u9322\u5305","embedded.import":"\u532F\u5165\u9322\u5305","embedded.backup_seed":"\u5099\u4EFD\u52A9\u8A18\u8A5E","embedded.backup_warning":"\u4EFB\u4F55\u4EBA\u53D6\u5F97\u60A8\u7684\u52A9\u8A18\u8A5E\u90FD\u53EF\u4EE5\u5B58\u53D6\u60A8\u7684\u8CC7\u91D1\u3002\u8ACB\u5B89\u5168\u5132\u5B58\u3002","embedded.backup_done":"\u6211\u5DF2\u5132\u5B58\u52A9\u8A18\u8A5E","embedded.wipe":"\u79FB\u9664\u9322\u5305","embedded.wipe_confirm":"\u78BA\u5B9A\u8981\u79FB\u9664\u55CE\uFF1F\u6B64\u64CD\u4F5C\u7121\u6CD5\u5FA9\u539F\u3002"},Ko={en:Ys,zh:Js},lr="en";function Ho(e){lr=e}function qo(){return lr}function Cn(e){return Ko[lr][e]??Ko.en[e]??e}function cr(e){let{isValid:t,level:o,issue:s}=(0,Vo.validateDestination)(e);return{isValid:t,level:o,warning:s?Cn(`address.${s}`):null}}function $o({address:e}){return{validation:(0,jo.useMemo)(()=>cr(e),[e])}}function Go(){let{status:e,session:t,accounts:o,chainId:s,error:n,connect:u,disconnect:i,reconnect:g,switchChain:l}=I(),c=e==="connected",h=e==="connecting",r=e==="reconnecting",a=o[0]??null;return{status:e,session:t,accounts:o,chainId:s,error:n,isConnected:c,isConnecting:h,isReconnecting:r,isDisconnected:e==="disconnected",currentAccount:a,connect:u,disconnect:i,reconnect:g,switchChain:l}}var Ze=require("react");var ur={wallet_unavailable:"Wallet Not Detected",user_rejected:"Connection Rejected",deeplink_timeout:"Wallet Connection Timed Out",session_expired:"Session Expired",intent_expired:"Connection Request Expired",namespace_mismatch:"Network Mismatch",chain_unsupported:"Unsupported Network",method_not_allowed:"Action Not Allowed",signature_rejected:"Signature Rejected",tx_failed:"Transaction Failed"},pr={wallet_unavailable:"No wallet found. Please install a compatible wallet (e.g., MetaMask, WalletConnect) and try again.",user_rejected:"The connection request was declined in your wallet. You can try again whenever you're ready.",deeplink_timeout:"The wallet didn't respond in time. This can happen if the wallet app isn't installed or takes too long to open.",session_expired:"Your wallet session has expired. Please reconnect to continue.",intent_expired:"The connection request expired. Please try connecting again.",namespace_mismatch:"This wallet doesn't support the required network. Try using a different wallet or network.",chain_unsupported:"This network isn't supported. Please switch to a supported network in your wallet.",method_not_allowed:"This action isn't supported by your current wallet or network.",signature_rejected:"The signature request was declined in your wallet.",tx_failed:"The transaction couldn't be completed. This could be due to insufficient funds, network congestion, or a contract error."},Wt="Something went wrong",Nt="An unexpected error occurred. Please try again. If the problem persists, check your connection and wallet configuration.";function Et(e){if(!e)return{title:Wt,description:Nt};let t=e;if(t.name==="WalletError"&&t.code){let o=t.code,s=ur[o]??Wt,n=pr[o]??t.message??Nt;return{title:s,description:n,code:o}}if(e instanceof Error){let o=e.message;return/user rejected/i.test(o)||/rejected/.test(o)?{title:"Request Rejected",description:"The request was declined.",code:"user_rejected"}:/timeout/i.test(o)||/timed? ?out/i.test(o)?{title:"Request Timed Out",description:"The request took too long. Please try again.",code:"deeplink_timeout"}:/insufficient funds/i.test(o)?{title:"Insufficient Funds",description:"You don't have enough funds to complete this transaction.",code:"tx_failed"}:/network/i.test(o)||/chain/i.test(o)?{title:"Network Error",description:o,code:"chain_unsupported"}:{title:Wt,description:o||Nt}}return typeof e=="string"?{title:Wt,description:e||Nt}:{title:Wt,description:Nt}}function Sn(e){if(e===null||typeof e!="object")return!1;let t=e;return t.name!=="WalletError"||!t.code?!1:["deeplink_timeout","session_expired","intent_expired","tx_failed"].includes(t.code)}function zo(){let{error:e,clearError:t}=I(),o=(0,Ze.useMemo)(()=>e?Et(e):null,[e]),s=(0,Ze.useMemo)(()=>e?Sn(e):!1,[e]),n=(0,Ze.useCallback)(()=>{t()},[t]),u=(0,Ze.useCallback)(g=>Et(g),[]),i=(0,Ze.useCallback)(g=>async()=>{try{return await g()}catch(l){let c=Et(l);if(l instanceof Error){let h=l;try{h.title=c.title,h.friendlyMessage=c.description,h.code===void 0&&c.code!==void 0&&(h.code=c.code)}catch{}throw h}throw Object.assign(new Error(c.description,{cause:l}),{title:c.title,code:c.code,friendlyMessage:c.description})}},[]);return{error:e,friendlyError:o,clearError:n,isRetryable:s,formatError:u,wrapAsync:i}}var ve=require("react"),Qo=require("@naculus/connect-core"),dr=require("@naculus/connect-appkit-core");function Ot(e,t){let o=(0,ve.useRef)(null),[s,n]=(0,ve.useState)([]),[u,i]=(0,ve.useState)(t?.autoLoad!==!1),[g,l]=(0,ve.useState)(!1),[c,h]=(0,ve.useState)(null);if(!o.current){let p={};t?.sources&&(p.sources=t.sources),o.current=new Qo.TokenListManager(p)}let r=(0,ve.useCallback)(async()=>{let p=o.current;if(p){i(!0),h(null);try{await p.load();let d=e?(0,dr.eip155ChainIdToNumber)(e):void 0,m=p.getTokens(d!==void 0?{chainId:d}:void 0);n(m),l(!0)}catch(d){h(d instanceof Error?d:new Error(String(d)))}finally{i(!1)}}},[e]),a=(0,ve.useCallback)(async()=>{let p=o.current;if(p){i(!0),h(null);try{await p.refresh();let d=e?(0,dr.eip155ChainIdToNumber)(e):void 0,m=p.getTokens(d!==void 0?{chainId:d}:void 0);n(m),l(!0)}catch(d){h(d instanceof Error?d:new Error(String(d)))}finally{i(!1)}}},[e]);return(0,ve.useEffect)(()=>{t?.autoLoad!==!1&&r()},[r,t?.autoLoad]),{tokens:s,isLoading:u,isLoaded:g,error:c,refetch:a}}var et=require("react"),Yo=require("@naculus/connect-core");var Le=require("@naculus/connect-core");function Xo(){return[{name:"built-in",tokens:[...Le.ETHEREUM_MAINNET_TOKENS,...Le.POLYGON_TOKENS,...Le.OPTIMISM_TOKENS,...Le.ARBITRUM_TOKENS,...Le.BASE_TOKENS],enabled:!0},{name:"uniswap-default",url:"https://tokens.uniswap.org",enabled:!0,refreshInterval:1440*60*1e3}]}var Jo=require("@naculus/connect-appkit-core"),Zs=300,En=null;function ea(){return En||(En=new Yo.TokenListManager({sources:Xo()}),En.load().catch(()=>{})),En}function _t(e,t){let[o,s]=(0,et.useState)({exact:[],fuzzy:[],hasMore:!1}),[n,u]=(0,et.useState)(!1),i=(0,et.useRef)(null),g=e.trim();return(0,et.useEffect)(()=>{if(!g){s({exact:[],fuzzy:[],hasMore:!1}),u(!1);return}return i.current&&clearTimeout(i.current),u(!0),i.current=setTimeout(()=>{let l=ea(),c=t?(0,Jo.eip155ChainIdToNumber)(t):void 0,h=l.search(g,{chainId:c,limit:20});s(h),u(!1)},Zs),()=>{i.current&&clearTimeout(i.current)}},[g,t]),{results:o,isSearching:n}}var wt=Ke(require("react"),1);var F=require("react/jsx-runtime");function mr({chainId:e,onSelect:t,onClose:o,options:s}){let[n,u]=wt.default.useState(""),{tokens:i,isLoading:g,error:l}=Ot(e),{results:c,isSearching:h}=_t(n,n?e:void 0),r=s?.showRecommendations??!0,a=wt.default.useMemo(()=>{if(n.trim()){let y=[...c.exact,...c.fuzzy].map(S=>S.token);return s?.filter?y.filter(s.filter):y}let m=i;return s?.filter?m.filter(s.filter):m},[n,c,i,s?.filter]),p=wt.default.useMemo(()=>!r||n.trim()?[]:i.slice(0,6),[i,r,n]),d=(0,wt.useCallback)(m=>{t(m),o()},[t,o]);return(0,F.jsxs)("div",{style:{background:"hsl(var(--background))",borderRadius:"12px",padding:"16px",color:"hsl(var(--foreground))",minWidth:"320px",maxWidth:"400px",fontFamily:"system-ui, sans-serif"},children:[(0,F.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px"},children:[(0,F.jsx)("h3",{style:{margin:0,fontSize:"16px",fontWeight:600},children:"Select Token"}),(0,F.jsx)("button",{type:"button",onClick:o,style:{background:"none",border:"none",color:"hsl(var(--muted-foreground))",cursor:"pointer",fontSize:"18px",padding:"4px 8px"},children:"\u2715"})]}),(0,F.jsx)("input",{type:"text",placeholder:"Search token name or paste address",value:n,onChange:m=>u(m.target.value),style:{width:"100%",padding:"10px 12px",borderRadius:"8px",border:"1px solid #333",background:"hsl(var(--card))",color:"hsl(var(--foreground))",fontSize:"14px",outline:"none",boxSizing:"border-box",marginBottom:"12px"},autoFocus:!0}),g&&!h&&(0,F.jsx)("div",{style:{textAlign:"center",padding:"20px",color:"hsl(var(--muted-foreground))"},children:"Loading tokens..."}),l&&(0,F.jsxs)("div",{style:{textAlign:"center",padding:"12px",color:"hsl(var(--destructive))",fontSize:"13px"},children:["Error: ",l.message]}),r&&p.length>0&&!n.trim()&&(0,F.jsxs)("div",{style:{marginBottom:"12px"},children:[(0,F.jsx)("div",{style:{fontSize:"11px",color:"hsl(var(--muted-foreground))",textTransform:"uppercase",letterSpacing:"0.5px",marginBottom:"8px"},children:"Popular"}),(0,F.jsx)("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap"},children:p.map(m=>(0,F.jsxs)("button",{type:"button",onClick:()=>d(m),style:{background:"hsl(var(--card))",border:"1px solid #333",borderRadius:"20px",padding:"6px 14px",color:"hsl(var(--foreground))",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",gap:"4px"},children:[m.logoURI?(0,F.jsx)("img",{src:m.logoURI,alt:"",style:{width:"16px",height:"16px",borderRadius:"50%"},onError:y=>{y.target.style.display="none"}}):null,m.symbol]},`${m.chainId}:${m.address}`))})]}),n.trim()&&!g&&(0,F.jsx)("div",{style:{fontSize:"11px",color:"hsl(var(--muted-foreground))",marginBottom:"8px"},children:a.length>0?(0,F.jsxs)(F.Fragment,{children:[c.exact.length," exact, ",c.fuzzy.length," fuzzy",c.hasMore?" (more available)":""]}):"No results found"}),(0,F.jsx)("div",{style:{maxHeight:"320px",overflowY:"auto",display:"flex",flexDirection:"column",gap:"2px"},children:a.map(m=>(0,F.jsxs)("button",{type:"button",onClick:()=>d(m),style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 8px",background:"transparent",border:"none",borderRadius:"8px",color:"hsl(var(--foreground))",cursor:"pointer",textAlign:"left",width:"100%",fontSize:"14px"},onMouseEnter:y=>{y.target.style.background="hsl(var(--card))"},onMouseLeave:y=>{y.target.style.background="transparent"},children:[(0,F.jsx)("div",{style:{width:"32px",height:"32px",borderRadius:"50%",background:"hsl(var(--border))",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"12px",fontWeight:600,flexShrink:0,overflow:"hidden"},children:m.logoURI?(0,F.jsx)("img",{src:m.logoURI,alt:m.symbol,style:{width:"100%",height:"100%"},onError:y=>{let S=y.target;S.style.display="none",S.parentElement.textContent=m.symbol.slice(0,2)}}):m.symbol.slice(0,2)}),(0,F.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,F.jsx)("div",{style:{fontWeight:600,fontSize:"14px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m.symbol}),(0,F.jsx)("div",{style:{fontSize:"12px",color:"hsl(var(--muted-foreground))",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m.name})]}),(0,F.jsxs)("div",{style:{fontSize:"11px",color:"#666",textAlign:"right",flexShrink:0},children:[(0,F.jsxs)("div",{children:[m.decimals," decimals"]}),(0,F.jsxs)("div",{children:["Chain ",m.chainId]})]})]},`${m.chainId}:${m.address}`))})]})}var M=require("@stencil/react-output-target/runtime"),L=Ke(require("react"),1),wn=require("@naculus/connect-appkit-wc/dist/components/appkit-accordion.js"),kn=require("@naculus/connect-appkit-wc/dist/components/appkit-account-button.js"),xn=require("@naculus/connect-appkit-wc/dist/components/appkit-alert-dialog.js"),vn=require("@naculus/connect-appkit-wc/dist/components/appkit-avatar.js"),bn=require("@naculus/connect-appkit-wc/dist/components/appkit-badge.js"),An=require("@naculus/connect-appkit-wc/dist/components/appkit-button.js"),Rn=require("@naculus/connect-appkit-wc/dist/components/appkit-card-content.js"),Tn=require("@naculus/connect-appkit-wc/dist/components/appkit-card-description.js"),In=require("@naculus/connect-appkit-wc/dist/components/appkit-card-footer.js"),Un=require("@naculus/connect-appkit-wc/dist/components/appkit-card-header.js"),Pn=require("@naculus/connect-appkit-wc/dist/components/appkit-card-title.js"),Wn=require("@naculus/connect-appkit-wc/dist/components/appkit-card.js"),Nn=require("@naculus/connect-appkit-wc/dist/components/appkit-checkbox.js"),On=require("@naculus/connect-appkit-wc/dist/components/appkit-collapsible.js"),_n=require("@naculus/connect-appkit-wc/dist/components/appkit-connect-button.js"),Dn=require("@naculus/connect-appkit-wc/dist/components/appkit-dialog.js"),Mn=require("@naculus/connect-appkit-wc/dist/components/appkit-dropdown-menu.js"),Ln=require("@naculus/connect-appkit-wc/dist/components/appkit-input.js"),Bn=require("@naculus/connect-appkit-wc/dist/components/appkit-popover.js"),Fn=require("@naculus/connect-appkit-wc/dist/components/appkit-progress.js"),Kn=require("@naculus/connect-appkit-wc/dist/components/appkit-scroll-area.js"),Hn=require("@naculus/connect-appkit-wc/dist/components/appkit-select.js"),qn=require("@naculus/connect-appkit-wc/dist/components/appkit-separator.js"),Vn=require("@naculus/connect-appkit-wc/dist/components/appkit-skeleton.js"),jn=require("@naculus/connect-appkit-wc/dist/components/appkit-switch.js"),$n=require("@naculus/connect-appkit-wc/dist/components/appkit-tabs.js"),Gn=require("@naculus/connect-appkit-wc/dist/components/appkit-toggle-group.js"),zn=require("@naculus/connect-appkit-wc/dist/components/appkit-tooltip.js"),Zo=(0,M.createComponent)({tagName:"appkit-accordion",elementClass:wn.AppkitAccordion,react:L.default,events:{onAppkitToggle:"appkitToggle"},defineCustomElement:wn.defineCustomElement}),es=(0,M.createComponent)({tagName:"appkit-account-button",elementClass:kn.AppkitAccountButton,react:L.default,events:{},defineCustomElement:kn.defineCustomElement}),ts=(0,M.createComponent)({tagName:"appkit-alert-dialog",elementClass:xn.AppkitAlertDialog,react:L.default,events:{onAppkitClose:"appkitClose",onAppkitOpenChange:"appkitOpenChange"},defineCustomElement:xn.defineCustomElement}),ns=(0,M.createComponent)({tagName:"appkit-avatar",elementClass:vn.AppkitAvatar,react:L.default,events:{},defineCustomElement:vn.defineCustomElement}),rs=(0,M.createComponent)({tagName:"appkit-badge",elementClass:bn.AppkitBadge,react:L.default,events:{},defineCustomElement:bn.defineCustomElement}),os=(0,M.createComponent)({tagName:"appkit-button",elementClass:An.AppkitButton,react:L.default,events:{},defineCustomElement:An.defineCustomElement}),ss=(0,M.createComponent)({tagName:"appkit-card",elementClass:Wn.AppkitCard,react:L.default,events:{},defineCustomElement:Wn.defineCustomElement}),as=(0,M.createComponent)({tagName:"appkit-card-content",elementClass:Rn.AppkitCardContent,react:L.default,events:{},defineCustomElement:Rn.defineCustomElement}),is=(0,M.createComponent)({tagName:"appkit-card-description",elementClass:Tn.AppkitCardDescription,react:L.default,events:{},defineCustomElement:Tn.defineCustomElement}),ls=(0,M.createComponent)({tagName:"appkit-card-footer",elementClass:In.AppkitCardFooter,react:L.default,events:{},defineCustomElement:In.defineCustomElement}),cs=(0,M.createComponent)({tagName:"appkit-card-header",elementClass:Un.AppkitCardHeader,react:L.default,events:{},defineCustomElement:Un.defineCustomElement}),us=(0,M.createComponent)({tagName:"appkit-card-title",elementClass:Pn.AppkitCardTitle,react:L.default,events:{},defineCustomElement:Pn.defineCustomElement}),ps=(0,M.createComponent)({tagName:"appkit-checkbox",elementClass:Nn.AppkitCheckbox,react:L.default,events:{onAppkitChange:"appkitChange"},defineCustomElement:Nn.defineCustomElement}),ds=(0,M.createComponent)({tagName:"appkit-collapsible",elementClass:On.AppkitCollapsible,react:L.default,events:{onAppkitToggle:"appkitToggle"},defineCustomElement:On.defineCustomElement}),ms=(0,M.createComponent)({tagName:"appkit-connect-button",elementClass:_n.AppkitConnectButton,react:L.default,events:{onAppkitConnect:"appkitConnect",onAppkitDisconnect:"appkitDisconnect",onAppkitStartPairing:"appkitStartPairing",onAppkitRetry:"appkitRetry",onAppkitCancelPairing:"appkitCancelPairing",onAppkitMobileDeepLink:"appkitMobileDeepLink",onAppkitCopyAddress:"appkitCopyAddress"},defineCustomElement:_n.defineCustomElement}),fs=(0,M.createComponent)({tagName:"appkit-dialog",elementClass:Dn.AppkitDialog,react:L.default,events:{onAppkitClose:"appkitClose",onAppkitOpenChange:"appkitOpenChange"},defineCustomElement:Dn.defineCustomElement}),gs=(0,M.createComponent)({tagName:"appkit-dropdown-menu",elementClass:Mn.AppkitDropdownMenu,react:L.default,events:{onAppkitSelect:"appkitSelect"},defineCustomElement:Mn.defineCustomElement}),hs=(0,M.createComponent)({tagName:"appkit-input",elementClass:Ln.AppkitInput,react:L.default,events:{onAppkitChange:"appkitChange"},defineCustomElement:Ln.defineCustomElement}),ys=(0,M.createComponent)({tagName:"appkit-popover",elementClass:Bn.AppkitPopover,react:L.default,events:{onAppkitOpenChange:"appkitOpenChange"},defineCustomElement:Bn.defineCustomElement}),Cs=(0,M.createComponent)({tagName:"appkit-progress",elementClass:Fn.AppkitProgress,react:L.default,events:{},defineCustomElement:Fn.defineCustomElement}),Ss=(0,M.createComponent)({tagName:"appkit-scroll-area",elementClass:Kn.AppkitScrollArea,react:L.default,events:{},defineCustomElement:Kn.defineCustomElement}),Es=(0,M.createComponent)({tagName:"appkit-select",elementClass:Hn.AppkitSelect,react:L.default,events:{onAppkitChange:"appkitChange"},defineCustomElement:Hn.defineCustomElement}),ws=(0,M.createComponent)({tagName:"appkit-separator",elementClass:qn.AppkitSeparator,react:L.default,events:{},defineCustomElement:qn.defineCustomElement}),ks=(0,M.createComponent)({tagName:"appkit-skeleton",elementClass:Vn.AppkitSkeleton,react:L.default,events:{},defineCustomElement:Vn.defineCustomElement}),xs=(0,M.createComponent)({tagName:"appkit-switch",elementClass:jn.AppkitSwitch,react:L.default,events:{onAppkitChange:"appkitChange"},defineCustomElement:jn.defineCustomElement}),vs=(0,M.createComponent)({tagName:"appkit-tabs",elementClass:$n.AppkitTabs,react:L.default,events:{onAppkitTabChange:"appkitTabChange"},defineCustomElement:$n.defineCustomElement}),bs=(0,M.createComponent)({tagName:"appkit-toggle-group",elementClass:Gn.AppkitToggleGroup,react:L.default,events:{onAppkitChange:"appkitChange"},defineCustomElement:Gn.defineCustomElement}),As=(0,M.createComponent)({tagName:"appkit-tooltip",elementClass:zn.AppkitTooltip,react:L.default,events:{},defineCustomElement:zn.defineCustomElement});0&&(module.exports={AppkitAccordion,AppkitAccountButton,AppkitAlertDialog,AppkitAvatar,AppkitBadge,AppkitButton,AppkitCard,AppkitCardContent,AppkitCardDescription,AppkitCardFooter,AppkitCardHeader,AppkitCardTitle,AppkitCheckbox,AppkitCollapsible,AppkitConnectButton,AppkitDialog,AppkitDropdownMenu,AppkitInput,AppkitPopover,AppkitProgress,AppkitScrollArea,AppkitSelect,AppkitSeparator,AppkitSkeleton,AppkitSwitch,AppkitTabs,AppkitToggleGroup,AppkitTooltip,DEFAULT_EVM_CHAINS,LAMPORTS_PER_SOL,PassphraseCancelledError,PassphraseGate,SolanaRpcError,TokenSelector,TxMonitorContext,WALLET_ERROR_DESCRIPTIONS,WALLET_ERROR_TITLES,Web3ConnectProvider,Web3Context,buildDelegationPolicyMessage,clearClient,createClient,formatSol,getChainById,getClient,getDefaultChains,getLatestBlockhash,getLocale,getSignatureStatus,getSolanaBalance,getUserFriendlyError,isRetryableError,parseSol,resetSessionKeyManager,setLocale,t,useAccount,useBalance,useCapabilities,useChain,useCompareCosts,useConnect,useCreateSessionKey,useDelegate,useDelegation,useDelegationPolicy,useDisconnect,useERC20Allowance,useERC20Approve,useERC20Transfer,useERC20TransferSimulation,useEmbeddedWallet,useExecuteCalls,useExecuteRoute,useLastTx,useLookupAddress,useMppSession,useNotification,usePassphraseGate,usePaymentFetch,useResolveName,useRevokeSession,useRouteQuote,useSIWxLogin,useSIWxSession,useSendCalls,useSendTransaction,useSendUserOperation,useSendWithSession,useSession,useSessionKeys,useSignInWithEthereum,useSignInWithX,useSignMessage,useSimulateTransfer,useSiwxAuthSession,useSmartAccount,useSolanaAccount,useSolanaBalance,useSolanaRoles,useSolanaSessionKey,useSolanaTransaction,useSwitchChain,useTokenBalance,useTokenList,useTokenSearch,useTransactionSimulation,useTxHistory,useTxMonitor,useUserOpStatus,useValidateDestination,useViemClient,useWallet,useWeb3,useWeb3ErrorHandler,validateDestination});
2
2
  //# sourceMappingURL=index.cjs.map