@naculus/connect-appkit-react 0.3.0 → 0.4.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 +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +31 -2
- package/dist/index.d.ts +31 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{formatSol as bC,getLatestBlockhash as RC,getSignatureStatus as TC,getSolanaBalance as IC,LAMPORTS_PER_SOL as UC,PassphraseCancelledError as PC,PassphraseGate as WC,parseSol as OC,SolanaRpcError as NC}from"@naculus/connect-core";import{compareCostsKey as vr}from"@naculus/connect-appkit-core";import{useCallback as Zt,useEffect as en,useRef as tn,useState as Xe}from"react";function nn(e,t){let{operation:o,chains:s,options:n}=e,[l,i]=Xe([]),[C,u]=Xe(!1),[c,g]=Xe(null),r=tn(!0),a=tn(0),p=vr(e),f=Zt(async()=>{if(!s||s.length===0){i([]);return}if(!t)return;let S=++a.current;u(!0),g(null);try{let h=await t(o,s,n);r.current&&S===a.current&&i(h)}catch(h){r.current&&S===a.current&&(g(h instanceof Error?h:new Error(String(h))),i([]))}finally{r.current&&S===a.current&&u(!1)}},[p,t]);en(()=>{f()},[f]),en(()=>(r.current=!0,()=>{r.current=!1}),[]);let d=Zt(async()=>{await f()},[f]);return{comparisons:l,loading:C,error:c,refresh:d}}import{toExecuteRouteError as Ar,validateRouteRecipient as br}from"@naculus/connect-appkit-core";import{useCallback as rn,useEffect as Rr,useRef as on,useState as Ye}from"react";function sn(e){let[t,o]=Ye(!1),[s,n]=Ye(null),[l,i]=Ye(null),C=on(!0),u=on(!1);Rr(()=>(C.current=!0,()=>{C.current=!1}),[]);let c=rn(async(r,a,p)=>{if(!e)return i({code:"no_executor",message:"No executeRoute function provided"}),n(null),null;let f=br(r,a);if(f)return i(f),n(null),null;if(u.current)return i({code:"execution_in_progress",message:"A route execution is already in progress"}),null;u.current=!0,o(!0),i(null),n(null);try{let d=await e(r,a,p);return C.current&&n(d),d}catch(d){return C.current&&i(Ar(d)),null}finally{u.current=!1,C.current&&o(!1)}},[e]),g=rn(()=>{n(null),i(null),o(!1)},[]);return{execute:c,executing:t,result:s,error:l,reset:g}}import{isQuotableInput as Tr}from"@naculus/connect-appkit-core";import{useCallback as Je,useEffect as an,useRef as ln,useState as Ze}from"react";function cn(e,t){let{fromChain:o,toChain:s,fromToken:n,toToken:l,amount:i,options:C}=e,[u,c]=Ze([]),[g,r]=Ze(!1),[a,p]=Ze(null),f=ln(null),d=ln(!0),S=Je(async()=>{if(!Tr({fromChain:o,toChain:s,fromToken:n,amount:i})){c([]);return}if(t){r(!0),p(null);try{let E=await t(o,s,n,i,C,l);d.current&&c(E)}catch(E){d.current&&(p(E instanceof Error?E:new Error(String(E))),c([]))}finally{d.current&&r(!1)}}},[o,s,n,l,i,C,t]);an(()=>{if(f.current&&clearTimeout(f.current),!o||!s||!n||!i){c([]);return}return f.current=setTimeout(()=>{S()},300),()=>{f.current&&clearTimeout(f.current)}},[S,o,s,n,i]),an(()=>(d.current=!0,()=>{d.current=!1}),[]);let h=Je(async()=>{await S()},[S]),w=Je(()=>{c([]),p(null),r(!1)},[]);return{quotes:u,loading:g,error:a,refresh:h,clear:w}}import{logger as et,WalletError as K}from"@naculus/connect-core";import{eip6963Connector as q}from"@naculus/connector-evm-injected";import{PassphraseGate as Ir}from"@naculus/connect-core";import{createWalletConnectConnector as Ur}from"@naculus/connector-walletconnect";var tt=null;function nt(e){let t=null,o=Ur({projectId:e.projectId,metadata:e.metadata}),s=null,n=null,l=null,i=null,C=e.passphrasePrompt&&e.enableEmbedded&&!e.embeddedConfig?.encryptionPassphrase?new Ir:null;e.enableEmbedded&&(n=import("@naculus/connector-embedded").then(r=>{let a={...e.embeddedConfig};C&&(a.encryptionPassphrase=C.request),e.enablePasskeys&&a.encryptionPassphrase&&!a.prfUnlock&&(a.prfUnlock={async derive(f){i&&await i;let d=l;return d?.hasCredential()?d.derivePrfKey(f):null}}),s=r.createPocketConnector(a),t?._setEmbeddedConnector(s)}).catch(r=>{et.warn("react/client","Embedded wallet connector not available:",r),s=null})),e.enablePasskeys&&(i=import("@naculus/connector-passkeys").then(r=>{l=r.createPasskeysConnector(),t?._setPasskeysConnector(l)}).catch(r=>{et.warn("react/client","Passkeys connector not available:",r),l=null}));let u=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}),u=a,typeof window<"u"&&"startDiscovery"in a&&a.startDiscovery(),t?._setSolanaConnector(u)}).catch(r=>{et.warn("react/client","Solana connector not available:",r),u=null})),typeof window<"u"&&q.startDiscovery();let g={connector:o,get embeddedConnector(){return s},getEmbeddedConnector:async()=>(n&&await n,s),get passkeysConnector(){return l},passphraseGate:C,solanaRpcUrl:e.solanaRpcUrl??null,get solanaConnector(){return u},connect:()=>o.connect(),connectInjected:async r=>q.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,!l)throw new Error("Passkeys connector not enabled. Set enablePasskeys: true in config.");return l.connect()},startPairing:()=>o.startPairing(),completePairing:()=>o.completePairing(),cancelPairing:()=>o.cancelPairing?.(),signMessage:async(r,a)=>{if(r.id?.startsWith("eip6963-"))return q.signMessage(r,a);if(r.walletType==="passkeys"&&l)return l.signMessage(r,a);if(r.walletType==="embedded"){if(!s)throw new K("wallet_unavailable","Embedded wallet connector not available.");return s.signMessage(r,a)}if(r.walletType==="solana"){if(c&&await c,u)return u.signMessage(r,a);throw new K("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 q.signTransaction(r,a);if(r.walletType==="embedded"){if(!s)throw new K("wallet_unavailable","Embedded wallet connector not available.");return s.signTransaction(r,a)}if(r.walletType==="solana"){if(c&&await c,u)return u.signTransaction(r,a);throw new K("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 q.sendTransaction(r,a);if(r.walletType==="passkeys"&&l)return l.sendTransaction(r,a);if(r.walletType==="embedded"){if(!s)throw new K("wallet_unavailable","Embedded wallet connector not available.");return s.sendTransaction(r,a)}if(r.walletType==="solana"){if(c&&await c,u)return u.sendTransaction(r,a);throw new K("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-")?q.onAccountsChanged?.(r,a)??p:r.walletType==="embedded"?s?.onAccountsChanged?.(r,a)??p:r.walletType==="passkeys"?p:r.walletType==="solana"?u?.onAccountsChanged?.(r,a)??p:o.onAccountsChanged?.(r,a)??p},onChainChanged:(r,a)=>{let p=()=>{};return r.id?.startsWith("eip6963-")?q.onChainChanged?.(r,a)??p:r.walletType==="passkeys"||r.walletType==="embedded"?p:r.walletType==="solana"?u?.onChainChanged?.(r,a)??p:o.onChainChanged?.(r,a)??p},getCapabilities:r=>r.id?.startsWith("eip6963-")?q.getCapabilities?.(r):r.walletType==="passkeys"?l?.getCapabilities?.(r):r.walletType==="solana"?u?.getCapabilities?.(r):r.walletType==="embedded"?s?.getCapabilities?.(r):o.getCapabilities?.(r),sendCalls:async(r,a,p,f)=>{if(r.id?.startsWith("eip6963-"))return q.sendCalls(r,a,p,f);if(r.walletType==="passkeys"&&l)return l.sendCalls(r,a,p,f);if(r.walletType==="solana"){if(c&&await c,u)return u.sendCalls(r,a,p,f);throw new K("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 K("method_not_allowed","Embedded wallet does not support sendCalls");return s.sendCalls(r,a,p,f)}if(!o.sendCalls)throw new K("method_not_allowed","sendCalls not supported by this connector");return o.sendCalls(r,a,p,f)},showCallsStatus:async(r,a)=>{if(r.id?.startsWith("eip6963-"))return q.showCallsStatus(r,a);if(r.walletType==="passkeys"||r.walletType==="embedded")throw new K("method_unsupported",`${r.walletType} wallets have no UI to display a call bundle.`);if(!o.showCallsStatus)throw new K("method_unsupported","This connector cannot display call status.");return o.showCallsStatus(r,a)},getCallsStatus:async(r,a)=>{if(r.id?.startsWith("eip6963-")&&q.getCallsStatus)return q.getCallsStatus(r,a);if(r.walletType==="passkeys"&&l?.getCallsStatus)return l.getCallsStatus(r,a);if(r.walletType==="embedded")throw new K("method_not_allowed","Embedded wallet does not support getCallsStatus");if(!o.getCallsStatus)throw new K("method_not_allowed","getCallsStatus not supported by this connector");return o.getCallsStatus(r,a)},reconnect:async r=>r.walletType==="eip6963"?q.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 q.disconnect(r);if(r.walletType==="embedded"&&s)return s.disconnect();if(r.walletType==="passkeys"&&l)return l.disconnect(r);if(r.walletType==="solana"){if(c&&await c,u)return u.disconnect(r);throw new K("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),l&&r.push(l),u&&r.push(u),r},_setEmbeddedConnector:r=>{s=r},_setPasskeysConnector:r=>{l=r},_setSolanaConnector:r=>{u=r}};return t=g,tt=g,g}function rt(){return tt}function Pr(){tt=null}import{isEvmAddress as fn,parseCaip10 as no}from"@naculus/connect-core";import{useMemo as ro}from"react";import{createConnectorManager as Vr,createSessionManager as $r,LocalStorageSessionStorage as Gr,logger as Z,WalletError as jr}from"@naculus/connect-core";import{eip6963Connector as Re}from"@naculus/connector-evm-injected";import{createContext as zr,useCallback as H,useContext as Qr,useEffect as ce,useMemo as ue,useReducer as Xr,useRef as dn}from"react";import{logger as Wr}from"@naculus/connect-core";import{issueNonce as Or,parseSiwxMessage as Nr}from"@naculus/siwx";function oe(e,t){let o=t.split(":",1)[0],n=(e.namespaces[o]?.accounts??[]).filter(l=>l.startsWith(`${o}:`)).map(l=>({namespace:o,caip10:l}))[0];if(n)return{...n,address:n.caip10.split(":").pop()??n.caip10}}function _r(e){return e.namespaces.eip155?.chains?.[0]??e.namespaces.solana?.chains?.[0]??e.namespaces.xrpl?.chains?.[0]??"eip155:1"}async function un(e){let{session:t,siwx:o,signMessage:s}=e;if(!o||!t)return{kind:"skipped"};try{let n=_r(t),l=oe(t,n);if(!l)throw new Error("No account found in session");let{address:i}=l,C=await o.createMessage({address:i,chainId:n}),u=Nr(C);if(!u?.nonce)throw new Error("SIWx message must contain a nonce");await Or(u.nonce);let c=await s(t,{message:C,address:i,chainId:n});return await o.handleSignComplete?.({message:C,signature:c}),{kind:"authenticated",address:i,chainId:n}}catch(n){let l=n instanceof Error?n:new Error("Wallet authentication failed");return Wr.error("appkit/core","SIWx authentication failed:",n),{kind:"failed",error:l,fatal:o.required!==!1}}}import{initialWeb3State as Yr,web3Reducer as Jr,withRetry as Zr,withTimeout as mn}from"@naculus/connect-appkit-core";import{resolveChain as Dr}from"@naculus/connect-appkit-core";import{CHAINS as be,DEFAULT_RPC_URLS as Mr,eip155Reference as Lr,getRpcUrl as Br}from"@naculus/connect-core";var Fr=[{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 Hr(e){let t=be[e];if(!t||!t.explorerUrl)return null;let o=t.caip2Id;return{caip2:o,name:t.name,rpcUrl:Br(o,Mr[o]??""),explorerUrl:t.explorerUrl,token:t.nativeCurrency.symbol}}function Kr(){if(!be)return[];let e=[],t=Object.keys(be).map(Number).sort((o,s)=>o-s);for(let o of t){let s=Hr(o);s&&e.push(s)}for(let o of Fr){let s=Lr(o.caip2);(s===null||!be[s])&&e.push(o)}return e}var pn=Kr();function qr(e,t){return Dr(e,t)??void 0}function ot(){return[...pn]}import{jsx as to}from"react/jsx-runtime";var st=zr(null);function eo({children:e,config:t,autoConnect:o=!0}){let[s,n]=Xr(Jr,Yr),l=ue(()=>t.chains??ot(),[t.chains]),i=t.connectionTimeout??3e4,C=t.maxRetries??2,u=ue(()=>new Gr(t.storageKey??"naculus_web3_session",t.encryptionKey),[t.storageKey,t.encryptionKey]),c=ue(()=>nt({projectId:t.projectId,metadata:t.metadata,enableEmbedded:t.enableEmbedded,embeddedConfig:t.embeddedConfig,enablePasskeys:t.enablePasskeys,enableSolana:t.enableSolana,solanaDefaultChain:t.solanaDefaultChain}),[t.projectId,t.metadata,t.enableEmbedded,t.embeddedConfig,t.enablePasskeys,t.enableSolana,t.solanaDefaultChain]),g=dn(null),r=dn(null),a=ue(()=>{let m=Vr();for(let N of[Re,...c.getAllConnectors()])m.register(N.id,N);let y={},k={};for(let N of l){let _=N.caip2;N.rpcUrl&&(y[_]=N.rpcUrl),N.token&&(k[_]={name:N.name,symbol:N.token,decimals:18})}let P=$r(m,{autoRefreshFeeOnSwitch:t.autoRefreshFeeOnSwitch??!0,defaultRpcUrls:y,defaultCurrencies:k,encryptionKey:t.encryptionKey});return g.current=P,P},[c,l,t.autoRefreshFeeOnSwitch,t.encryptionKey]);ce(()=>{let m=_=>{let{walletSession:J}=_.bundle;n({type:"SET_SESSION",payload:J});let Jt=[];Object.values(J.namespaces).forEach(xr=>{Jt.push(...xr.accounts)}),n({type:"SET_ACCOUNTS",payload:Jt}),n({type:"SET_CHAIN",payload:_.bundle.activeChainId}),n({type:"SET_STATUS",payload:"connected"})},y=()=>{n({type:"RESET"})},k=_=>{n({type:"SET_CHAIN",payload:_.newChainId})},P=_=>m(_),N=()=>{u.clear(),n({type:"RESET"})};return a.on("sessionConnected",m),a.on("sessionDisconnected",y),a.on("chainChanged",k),a.on("sessionScopeChanged",P),a.on("sessionRevoked",N),()=>{a.off("sessionConnected",m),a.off("sessionDisconnected",y),a.off("chainChanged",k),a.off("sessionScopeChanged",P),a.off("sessionRevoked",N)}},[a,u]),ce(()=>{let m=()=>{u.clear(),n({type:"RESET"})};c.connector.onSessionExpiry(m)},[c,u]);let p=H(()=>{for(let m of[Re,...c.getAllConnectors()])a.registerConnector(m)},[c,a]),f=H(async m=>{p();let y=[Re,...c.getAllConnectors()].find(P=>P.id===m.walletType||P.kind===m.walletType);y&&!m.connectorId&&(m.connectorId=y.id);let k=m.namespaces.eip155?.chains?.[0]??m.namespaces.solana?.chains?.[0]??m.namespaces.xrpl?.chains?.[0];k&&await a.attach(m,k)},[c,a,p]),d=H(m=>{if(n({type:"SET_SESSION",payload:m}),m){let y=[];Object.values(m.namespaces).forEach(_=>{y.push(..._.accounts)}),n({type:"SET_ACCOUNTS",payload:y});let k=m.namespaces.eip155?.chains?.[0],P=m.namespaces.solana?.chains?.[0],N=m.namespaces.xrpl?.chains?.[0];n({type:"SET_CHAIN",payload:k??P??N??null})}else n({type:"SET_ACCOUNTS",payload:[]}),n({type:"SET_CHAIN",payload:null})},[]);ce(()=>{let m=s.session,y=c;return!m||!y?.onAccountsChanged?void 0:y.onAccountsChanged(m,P=>{if(P.length===0){u.clear().finally(()=>n({type:"RESET"}));return}d(m),u.save(m)})},[s.session,c,u,d]),ce(()=>{let m=s.session,y=c;if(!(!m||!y?.onChainChanged))return y.onChainChanged(m,k=>{d(m),u.save(m);let P=a.syncExternalChain;if(!P)return;let N=P.call(a,k).catch(_=>{Z.warn("react/provider","External chain sync error:",_)});r.current=N,N.finally(()=>{r.current===N&&(r.current=null)})})},[s.session,c,u,d,a]);let S=H(async m=>{if(!t.siwx||!m)return!0;n({type:"SET_STATUS",payload:"authenticating"});let y=await un({session:m,siwx:t.siwx,signMessage:(k,P)=>c.signMessage(k,P)});return y.kind==="failed"&&y.fatal?(await u.clear(),n({type:"RESET"}),n({type:"SET_ERROR",payload:y.error}),!1):!0},[t.siwx,c,u]),h=H(async()=>{n({type:"SET_STATUS",payload:"connecting"}),n({type:"SET_ERROR",payload:null});try{let m=await mn(c.connect(),i,"Wallet connect");await u.save(m),d(m);try{await f(m)}catch(y){Z.warn("react/provider","SessionManager sync error:",y)}if(!await S(m))return;n({type:"SET_STATUS",payload:"connected"})}catch(m){let y=m instanceof Error?m.message:"Connection failed";n({type:"SET_ERROR",payload:m instanceof Error?m:new Error(y)}),n({type:"SET_STATUS",payload:"disconnected"})}},[c,u,d,i,S,f]),w=H(async()=>{n({type:"SET_STATUS",payload:"connecting"}),n({type:"SET_ERROR",payload:null});try{let m=await c.connectEmbedded();if(await u.save(m),d(m),await f(m),!await S(m))return;n({type:"SET_STATUS",payload:"connected"})}catch(m){let y=m instanceof Error?m.message:"Embedded wallet connection failed";n({type:"SET_ERROR",payload:m instanceof Error?m:new Error(y)}),n({type:"SET_STATUS",payload:"disconnected"})}},[c,u,d,S,f]),E=H(async()=>{n({type:"SET_STATUS",payload:"connecting"}),n({type:"SET_ERROR",payload:null});try{let m=await c.connectPasskeys();if(await u.save(m),d(m),await f(m),!await S(m))return;n({type:"SET_STATUS",payload:"connected"})}catch(m){let y=m instanceof Error?m.message:"Passkeys connection failed";n({type:"SET_ERROR",payload:m instanceof Error?m:new Error(y)}),n({type:"SET_STATUS",payload:"disconnected"})}},[c,u,d,S,f]),R=H(async()=>{if(!s.session){n({type:"RESET"});return}try{await c.disconnect(s.session)}catch(m){Z.error("react/provider","Disconnect error:",m)}try{let m=g.current;m&&await m.disconnect()}catch(m){Z.warn("react/provider","SessionManager disconnect error:",m)}await u.clear(),n({type:"RESET"})},[c,s.session,u]),A=H(async m=>{n({type:"SET_STATUS",payload:"connecting"}),n({type:"SET_ERROR",payload:null});try{let y=await mn(c.connectInjected(m),i,"Injected wallet connect");await u.save(y),d(y);try{await f(y)}catch(k){Z.warn("react/provider","SessionManager sync error:",k)}if(!await S(y))return;n({type:"SET_STATUS",payload:"connected"})}catch(y){let k=y instanceof Error?y.message:"Connection failed";n({type:"SET_ERROR",payload:y instanceof Error?y:new Error(k)}),n({type:"SET_STATUS",payload:"disconnected"})}},[c,u,d,i,S,f]),T=H(async()=>c.startPairing(),[c]),v=H(()=>{c.cancelPairing?.()},[c]),x=H(async()=>{let m=await c.completePairing();return await u.save(m),d(m),await f(m),await S(m)&&n({type:"SET_STATUS",payload:"connected"}),m},[c,u,d,S,f]),b=H(async m=>{let y=t.siwx;if(!y||y.required===!1)return!0;try{if(await y.hasValidSession?.())return!0}catch(k){Z.warn("react/provider","siwx.hasValidSession failed",k)}return S(m)},[t.siwx,S]),I=H(async()=>{let m=await u.load();if(!m){n({type:"SET_STATUS",payload:"disconnected"});return}n({type:"SET_STATUS",payload:"reconnecting"});try{let y=await Zr(()=>c.reconnect(m),{maxRetries:C,baseDelay:1e3,label:"reconnect"});d(y);try{let k=g.current;k&&(p(),await k.restoreFromPersistence())}catch(k){Z.warn("react/provider","SessionManager restore error:",k)}if(!await b(y))return;n({type:"SET_STATUS",payload:"connected"})}catch(y){Z.error("react/provider","Reconnect error:",y),await u.clear(),n({type:"SET_STATUS",payload:"disconnected"}),n({type:"SET_SESSION",payload:null})}},[c,u,d,C,p,b]),W=H(async m=>{r.current&&await r.current;let y=g.current;if(y?.getActiveBundle()){await y.switchChain(m),d(s.session);return}if(!s.session)throw new Error("No active session");try{s.session.walletType==="eip6963"||s.session.id?.startsWith("eip6963-")?await Re.switchChain(s.session,m):s.session.walletType==="embedded"&&c.embeddedConnector?await c.embeddedConnector.switchChain?.(s.session,m):s.session.walletType==="passkeys"&&c.passkeysConnector?await c.passkeysConnector.switchChain?.(s.session,m):s.session.walletType==="solana"&&c.solanaConnector?await c.solanaConnector.switchChain?.(s.session,m):await c.connector.switchChain(s.session,m),d(s.session)}catch(k){throw new jr("chain_unsupported","Failed to switch chain",k)}},[c,s.session,d]);ce(()=>{o&&I()},[o,I]);let L=H(()=>{n({type:"SET_ERROR",payload:null})},[]),F=ue(()=>({...s,connect:h,connectEmbedded:w,connectPasskeys:E,disconnect:R,reconnect:I,switchChain:W,startPairing:T,completePairing:x,cancelPairing:v,connectInjected:A,clearError:L,isConnected:s.status==="connected",chains:l,client:c,sessionManager:a}),[s,h,w,E,R,I,W,T,x,A,L,l,c,a]);return to(st.Provider,{value:F,children:e})}function U(){let e=Qr(st);if(!e)throw new Error("useWeb3 must be used within a Web3ConnectProvider");return e}function B(){let{accounts:e,isConnected:t}=U(),o=ro(()=>!t||e.length===0?null:e.map(n=>{let l=no(n);return l?{address:n,namespace:l.namespace,isEVM:l.namespace==="eip155"&&fn(l.address)}:{address:n,namespace:null,isEVM:fn(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}}import{chainNumber as oo,resolveChain as so,toViemChain as ao}from"@naculus/connect-appkit-core";import{useState as pe,useEffect as at,useCallback as io,useMemo as de,useRef as lo}from"react";import{createPublicClient as co,http as uo,formatEther as po}from"viem";import{getNativeTokenPriceUsd as mo}from"@naculus/connect-core";function fo(e){let{evmAccount:t,isConnected:o}=B(),{chainId:s,chains:n}=U(),[l,i]=pe(null),[C,u]=pe(!1),[c,g]=pe(null),[r,a]=pe(null),p=e?.refreshInterval,f=lo(null),d=de(()=>so(n,s),[s,n]),S=d?oo(d):null,h=de(()=>d?ao(d,S):null,[d,S]),w=de(()=>d?.token??null,[d]),[E,R]=pe(null);at(()=>{if(!h||!d?.rpcUrl){R(null);return}let x=co({transport:uo(d.rpcUrl),chain:h});return R(x),()=>{}},[d]);let A=io(async()=>{if(!t||!E){i(null);return}u(!0),g(null);try{let b=t.includes(":")?t.split(":").pop():t,[I,W]=await Promise.all([E.getBalance({address:b}),s?mo(s,d?.rpcUrl).catch(()=>null):Promise.resolve(null)]);i(I.toString()),a(W)}catch(x){g(x instanceof Error?x:new Error("Failed to fetch balance")),i(null),a(null)}finally{u(!1)}},[t,E,s,d?.rpcUrl]);at(()=>{o&&t&&A()},[o,t,A]),at(()=>(p&&p>0&&o&&t&&(f.current=setInterval(A,p)),()=>{f.current&&(clearInterval(f.current),f.current=null)}),[p,o,t,A]);let T=de(()=>{if(l===null)return null;try{return po(BigInt(l))}catch{return null}},[l]),v=de(()=>{if(r===null||T===null)return null;let x=parseFloat(T);if(isNaN(x))return null;let b=x*r;return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(b)},[r,T]);return{balance:l,formatted:T,symbol:w,usdPrice:r,usdValue:v,isLoading:C,error:c,refetch:A,chain:d}}import{atomicSupportFor as go,normalizeCapabilities as Co,selectChainCapabilities as ho}from"@naculus/connect-appkit-core";import{useCallback as yo,useEffect as So,useRef as Eo,useState as it}from"react";function O(e){return e??rt()}function lt(){let{client:e,session:t,chainId:o}=U(),[s,n]=it(null),[l,i]=it(!1),[C,u]=it(null),c=Eo(0),g=yo(async()=>{let r=++c.current,a=O(e);if(!a?.getCapabilities||!t){n(null),i(!1),u(null);return}i(!0),u(null);try{let p=await a.getCapabilities(t);if(r!==c.current)return;n(Co(p))}catch(p){if(r!==c.current)return;n(null),u(p instanceof Error?p:new Error("Capability query failed"))}finally{r===c.current&&i(!1)}},[e,t]);return So(()=>{g()},[g]),{capabilities:s,current:ho(s,o),atomic:go(s,o),isFetching:l,error:C,refetch:g}}import{useMemo as ct}from"react";import{chainsForNamespace as wo,describeChain as ko,resolveChain as xo}from"@naculus/connect-appkit-core";function V(){let{chainId:e,session:t,switchChain:o,chains:s}=U(),n=ct(()=>xo(s,e),[s,e]),l=ct(()=>t?ko(s,e):null,[s,e,t]),i=ct(()=>wo(s,e),[s,e]);return{chainId:e,currentChain:n,chainInfo:l,availableChains:i,chains:i,isEvm:e?.startsWith("eip155:")??!1,switchChain:o}}import{useCallback as vo,useState as gn}from"react";import{WalletError as Ao}from"@naculus/connect-core";function bo(){let{connect:e,status:t}=U(),[o,s]=gn(!1),[n,l]=gn(null);return{connect:vo(async()=>{s(!0),l(null);try{await e()}catch(C){let u=C instanceof Error?C.message:"Connection failed";l(C instanceof Ao?C:new Error(u))}finally{s(!1)}},[e]),isConnecting:o||t==="connecting",error:n}}import{bareEvmAddress as Po}from"@naculus/connect-appkit-core";import{delegateAccount as Wo,eip155Reference as Oo,REVOKE_DELEGATE as No,WalletError as hn}from"@naculus/connect-core";import{useCallback as Te,useEffect as yn,useRef as Sn,useState as pt}from"react";import{chainNumber as Ro,toViemChain as To}from"@naculus/connect-appkit-core";import{useMemo as ut}from"react";import{createPublicClient as Io,http as Cn,createWalletClient as Uo}from"viem";function $(){let{evmAccount:e,isConnected:t}=B(),{currentChain:o,chains:s}=V(),n=o?Ro(o):null,l=ut(()=>o?To(o,n):null,[o,n]),i=ut(()=>l?Io({transport:Cn(l.rpcUrls.default.http[0]),chain:l}):null,[o,l]),C=ut(()=>{if(!t||!e||!l)return null;let u=e.includes(":")?e.split(":").pop():e;return Uo({transport:Cn(l.rpcUrls.default.http[0]),chain:l,account:u})},[t,e,o,l]);return{publicClient:i,walletClient:C,chains:s}}function _o(e){let{evmAccount:t}=B(),{session:o,chainId:s,client:n}=U(),{publicClient:l}=$(),[i,C]=pt(null),[u,c]=pt(!1),[g,r]=pt(null),a=Sn(0),p=Sn(!1);yn(()=>()=>{a.current+=1},[]),yn(()=>{a.current+=1,C(null),c(!1),r(null)},[o,s,t]);let f=Te(async(w,E)=>{let R=x=>(r(x),null);if(p.current)return R(new Error("A delegation is already in progress"));let A=Po(t);if(!o||!A||!s)return R(new hn("wallet_unavailable","No connected EVM account"));if(!l||l.chain?.id!==Oo(s))return R(new hn("chain_mismatch",`No RPC client for ${s}; refusing to read the nonce elsewhere.`));let T=o.walletType==="embedded"?O(n)?.embeddedConnector??{}:{},v=++a.current;p.current=!0,c(!0),r(null),C(null);try{let x=await Wo({connector:T,session:o,account:A,chainId:s,delegate:w,allowlist:E,getTransactionCount:(b,I)=>l.getTransactionCount({address:b,blockTag:I})});return v!==a.current?null:(C(x),x)}catch(x){return v!==a.current?null:R(x instanceof Error?x:new Error("Failed to send delegation"))}finally{p.current=!1,v===a.current&&c(!1)}},[s,n,t,l,o]),d=Te(w=>f(w,e.allowlist),[f,e.allowlist]),S=Te(()=>f(No,[]),[f]),h=Te(()=>{a.current+=1,C(null),c(!1),r(null)},[]);return{delegate:d,revoke:S,result:i,isPending:u,error:g,reset:h}}import{readDelegation as Do,UNKNOWN_DELEGATION as dt}from"@naculus/connect-core";import{useCallback as Mo,useEffect as Lo,useRef as Bo,useState as mt}from"react";function me(){let{publicClient:e}=$(),{evmAccount:t}=B(),[o,s]=mt(dt),[n,l]=mt(!1),[i,C]=mt(null),u=Bo(0),c=t?.includes(":")?t.split(":").pop():t,g=Mo(async()=>{let r=++u.current;if(!e||!c){s(dt),l(!1),C(null);return}l(!0),C(null);try{let a=await e.getCode({address:c});if(r!==u.current)return;s(Do(a??"0x"))}catch(a){if(r!==u.current)return;s(dt),C(a instanceof Error?a:new Error("Code read failed"))}finally{r===u.current&&l(!1)}},[e,c]);return Lo(()=>{g()},[g]),{...o,isFetching:n,error:i,refetch:g}}import{bareEvmAddress as ts,createDelegationPolicyFlow as ns,isVerifiablePolicy as rs}from"@naculus/connect-appkit-core";import{useCallback as ge,useEffect as os,useMemo as ss,useState as Pe}from"react";import{recoverMessageAddress as as}from"viem";import{planExecution as qo,WalletError as Vo}from"@naculus/connect-core";import{useCallback as En,useState as gt}from"react";import{chooseExecutionStrategy as Ho,getAccountCapabilities as Ko,WalletError as ee}from"@naculus/connect-core";import{useCallback as Ue,useState as fe}from"react";import{WalletError as Fo}from"@naculus/connect-core";function Ie(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 Fo("tx_failed","Wallet did not return a valid 32-byte transaction hash")}function ft(){let{session:e,chainId:t,client:o}=U(),[s,n]=fe("idle"),[l,i]=fe(null),[C,u]=fe(null),[c,g]=fe(null),[r,a]=fe(null),p=Ue(async(h,w)=>{if(!e){n("failed");let E=new ee("wallet_unavailable","No active session");throw i(E),E}if(h.length===0){n("failed");let E=new ee("invalid_input","At least one call is required");throw i(E),E}n("awaiting_approval"),i(null),u(null);try{let E=O(o);if(!E)throw new ee("wallet_unavailable","Client not initialized");let R=w?.chainId??t??void 0,A=w?.strategy??Ho(await Ko(E,e,R),h.length);if(a(A),A==="atomic-batch"){let v=await E.sendCalls(e,h,R,{atomicRequired:!0,...w?.paymasterService?{paymasterService:w.paymasterService}:{}});return n("submitted"),u(v),v}let T="";for(let v=0;v<h.length;v++){let x=h[v];try{T=Ie(await E.sendTransaction(e,{transaction:{to:x.to,data:x.data,value:x.value},chainId:R}))}catch(b){throw new ee("tx_failed",`Call ${v+1} of ${h.length} failed after ${v} already landed (sent sequentially \u2014 this wallet cannot batch atomically): ${b instanceof Error?b.message:String(b)}`)}}return n("submitted"),u(T),T}catch(E){n("failed");let R=E instanceof Error?E.message:"sendCalls failed";throw i(E instanceof Error?E:new Error(R)),E}},[e,t,o]),f=Ue(async h=>{if(!e)throw new ee("wallet_unavailable","No active session");let w=h??C;if(!w)throw new ee("invalid_input","No bundle hash available");if(!h&&r==="sequential")throw new ee("invalid_input","Calls were sent sequentially, so there is no bundle to query. Track the returned transaction hash instead.");let E=O(o);if(!E)throw new ee("wallet_unavailable","Client not initialized");let R=await E.getCallsStatus(e,w);return g(R),R},[e,C,o,r]),d=Ue(async h=>{if(!e)return!1;let w=h??C;if(!w||!h&&r==="sequential")return!1;let E=O(o);if(!E?.showCallsStatus)return!1;try{return await E.showCallsStatus(e,w),!0}catch{return!1}},[e,C,o,r]),S=Ue(()=>{n("idle"),i(null),u(null),g(null),a(null)},[]);return{sendCalls:p,getCallsStatus:f,showCallsStatus:d,status:s,error:l,batchHash:C,callsStatus:c,execution:r,reset:S,isSending:s==="awaiting_approval"}}function Ct(e={}){let{current:t,atomic:o}=lt(),{delegated:s,delegate:n}=me(),{sendCalls:l}=ft(),[i,C]=gt(!1),[u,c]=gt(null),[g,r]=gt(null),a=e.atomicity??"preferred",p=e.sponsorship??"any",f=e.paymasterService,d=e.userOperation,S=e.userOperationSponsored??!1,h=!!(t?.raw?.paymasterService?.supported&&f),w=En((R,A=a)=>{let T=qo({atomicBatch:o==="supported",discovered:o!=="unknown",sponsoredTransactions:!1,...t?.maxBatchSize===void 0?{}:{maxBatchSize:t.maxBatchSize}},R,{atomicity:A,sponsorship:p}),v=p==="required"&&!S;if(T.strategy==="atomic-batch"&&!v)return{...T,reason:T.reason+(h?" 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.`:"",b=A!=="any"&&!T.atomic||p==="required";return d&&b&&!v?{strategy:"atomic-batch",atomic:!0,sponsored:S,reason:p==="required"&&!T.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"}:v?{strategy:"refuse",atomic:T.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}:T.strategy==="refuse"?{...T,reason:T.reason+x,route:null}:{...T,reason:T.reason+x,route:"sequential"}},[o,t,f,h,d,S,a,p,s,n]),E=En(async(R,A=a)=>{C(!0),c(null);try{let T=w(R.length,A);if(T.route===null)throw new Vo("method_not_allowed",T.reason);return r(T.route),T.route==="user-operation"?await d(R):await l(R,{strategy:T.route==="wallet-batch"?"atomic-batch":"sequential",...T.route==="wallet-batch"&&h?{paymasterService:f}:{}})}catch(T){let v=T instanceof Error?T:new Error("Execution failed");throw c(v),v}finally{C(!1)}},[w,l,d,a,f,h]);return{preview:w,execute:E,isExecuting:i,error:u,lastRoute:g,reset:()=>{c(null),r(null)}}}import{getSharedSessionKeyManager as $o,resetSharedSessionKeyManager as Go}from"@naculus/connect-appkit-core";import{WalletError as jo}from"@naculus/connect-core";import{useCallback as Q,useEffect as zo,useRef as Qo,useState as z}from"react";function se(e){return $o(e)}function ht(e){let{session:t}=U(),[o,s]=z([]),[n,l]=z(!1),[i,C]=z(null),u=Qo(!0),c=Q(()=>C(null),[]),g=se(e),r=g.isStorageAvailable(),a=Q(async()=>{if(!t){s([]);return}l(!0),C(null);try{let f=await g.listSessions();u.current&&s(f)}catch(f){u.current&&C(f instanceof Error?f:new Error("Failed to load session keys"))}finally{u.current&&l(!1)}},[t,g]);zo(()=>(u.current=!0,a(),()=>{u.current=!1}),[a]);let p=o.filter(f=>f.status==="active");return{sessions:o,activeSessions:p,loading:n,error:i,refresh:a,clearError:c,storageAvailable:r}}function Xo(e){let{session:t}=U(),[o,s]=z(null),[n,l]=z(!1),[i,C]=z(null),u=Q(()=>C(null),[]),c=se(e);return{createSessionKey:Q(async(r,a)=>{if(!t)throw new jo("wallet_unavailable","No active wallet session");l(!0),C(null);try{let p=a??void 0,f=await c.createSessionKey(r,p);return s(f),f}catch(p){let f=p instanceof Error?p:new Error("Failed to create session key");throw C(f),f}finally{l(!1)}},[t,c]),lastCreated:o,isCreating:n,error:i,clearError:u}}function Yo(e){let[t,o]=z(!1),[s,n]=z(null),l=Q(()=>n(null),[]),i=se(e);return{revokeSession:Q(async u=>{o(!0),n(null);try{await i.revokeSession(u)}catch(c){let g=c instanceof Error?c:new Error("Failed to revoke session key");throw n(g),g}finally{o(!1)}},[i]),isRevoking:t,error:s,clearError:l}}function Jo(e){let[t,o]=z(!1),[s,n]=z(null),l=Q(()=>n(null),[]),i=se(e),C=Q(async(c,g,r)=>{o(!0),n(null);try{return await i.signWithSessionKey(c,g,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]),u=Q(async(c,g)=>{o(!0),n(null);try{return await i.checkSessionScope(c,g)}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:C,checkScope:u,isBusy:t,error:s,clearError:l}}function Zo(){Go()}import{useState as wn,useCallback as es}from"react";import{WalletError as yt}from"@naculus/connect-core";function St(){let{session:e,chainId:t,client:o}=U(),[s,n]=wn(!1),[l,i]=wn(null);return{signMessage:es(async u=>{if(!e){let g=new yt("wallet_unavailable","No active session");throw i(g),g}let c=e.namespaces.eip155?.accounts[0]??Object.values(e.namespaces)[0]?.accounts[0];if(!c){let g=new yt("wallet_unavailable","No account found");throw i(g),g}n(!0),i(null);try{let g=O(o);if(!g)throw new yt("wallet_unavailable","Client not initialized");return await g.signMessage(e,{message:u,address:c,chainId:t??void 0})}catch(g){let r=g instanceof Error?g.message:"Signing failed",a=g instanceof Error?g:new Error(r);throw i(a),a}finally{n(!1)}},[e,t,o]),isSigning:s,error:l}}import{buildDelegationPolicyMessage as ls}from"@naculus/connect-appkit-core";function is(e={}){let{evmAccount:t}=B(),o=ts(t),s=me(),n=Ct(e.execution),{signMessage:l}=St(),i=ht(e.managerConfig),C=se(e.managerConfig),[u,c]=Pe(!1),[g,r]=Pe(null),[a,p]=Pe(()=>new Set),[f,d]=Pe(!1),S=e.origin??(typeof window<"u"?window.location.origin:"unknown"),h=!!e.managerConfig?.encryptionKey,w=e.execution?.sponsorship,{refresh:E,storageAvailable:R}=i,{preview:A}=n,{delegated:T,delegate:v}=s,x=ss(()=>ns({manager:C,origin:S,signer:()=>o,signMessage:l,verifySignature:async({message:y,signature:k,signerAddress:P})=>(await as({message:y,signature:k})).toLowerCase()===P.toLowerCase(),previewExecution:A,sponsorship:w,adapter:e.adapter,delegation:()=>({delegated:T,delegate:v}),encryptionKeyConfigured:h,storageAvailable:()=>R,refresh:E}),[C,S,o,l,A,w,e.adapter,T,v,h,R,E]);os(()=>{let y=!1,k=i.sessions.filter(rs);return k.length===0?(p(new Set),d(!1),()=>{y=!0}):(d(!0),Promise.all(k.map(async P=>[P.id,await x.verifyStoredPolicy(P)])).then(P=>{y||p(new Set(P.filter(([,N])=>N).map(([N])=>N)))}).catch(P=>{y||(p(new Set),r(P instanceof Error?P:new Error("Policy verification failed")))}).finally(()=>{y||d(!1)}),()=>{y=!0})},[i.sessions,x]);let b=ge(()=>{r(null),i.clearError()},[i]),I=ge(async(y,k)=>{c(!0),r(null);try{return await y()}catch(P){let N=P instanceof Error?P:new Error(k);throw r(N),N}finally{c(!1)}},[]),W=ge(y=>I(()=>x.createPolicy(y),"Policy creation failed"),[x,I]),L=ge(y=>I(()=>x.revokePolicy(y),"Policy revocation failed"),[x,I]),F=ge((y,k)=>I(()=>x.executePolicy(y,k),"Policy execution failed"),[x,I]),m=i.activeSessions.filter(y=>a.has(y.id));return{policies:i.sessions,activePolicies:m,storageAvailable:i.storageAvailable,loading:i.loading||f,isBusy:u,error:g??i.error,delegation:s,createPolicy:W,revokePolicy:L,previewPolicyExecution:x.previewPolicyExecution,signPolicyDigest:x.signPolicyDigest,executePolicy:F,refresh:i.refresh,clearError:b}}import{useCallback as cs,useRef as us,useState as kn}from"react";function ps(){let{disconnect:e,status:t}=U(),[o,s]=kn(!1),[n,l]=kn(null),i=us(!0);return{disconnect:cs(async()=>{if(t!=="disconnected"){s(!0),l(null);try{await e()}catch(u){if(!i.current)return;l(u instanceof Error?u:new Error("Disconnect failed"))}finally{i.current&&s(!1)}}},[e,t]),isDisconnecting:o,error:n,cleanup:()=>{i.current=!1}}}import{WalletError as Et}from"@naculus/connect-core";import{useCallback as X,useEffect as ds,useRef as We,useState as Oe}from"react";function te(e){let t=e.activeNamespace??"eip155",o=Array.isArray(e.accounts)?e.accounts.map(({namespace:s,address:n,derivationPath:l})=>({namespace:s,address:n,...l?{derivationPath:l}:{}})):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 ms(){let{connectEmbedded:e,client:t}=U(),[o,s]=Oe(null),n=We(null),l=We(4),i=We(!1),C=We(null),[u,c]=Oe(!1),[g,r]=Oe(!1),[a,p]=Oe(null),f=()=>p(null),d=X(()=>{let m=n.current;return n.current=null,m},[]),S=X(()=>{let m=O(t);if(!m?.embeddedConnector)throw new Et("wallet_unavailable","Embedded wallet not enabled.");return m.embeddedConnector},[t]),h=X(()=>{try{return S().getWallet()?.privateKey??null}catch{return null}},[S]),w=X(async()=>{let m=O(t);if(!m)throw new Et("wallet_unavailable","Embedded wallet not enabled.");let y=m.getEmbeddedConnector?await m.getEmbeddedConnector():m.embeddedConnector;if(!y)throw new Et("wallet_unavailable","Embedded wallet not enabled.");return y},[t]),E=X(()=>{try{return O(t)?.passphraseGate??null}catch{return null}},[t]),R=X(m=>{m?.code==="decryption_failed"&&E()?.forget("That passphrase did not open the wallet.")},[E]),A=X(async()=>{i.current=!1,p(null);try{let m=await w();if(!await m.load())return!1;let k=m.getWallet();return k?(n.current=null,c(!1),s(te(k)),!0):!1}catch(m){return i.current=!0,R(m),p(m instanceof Error?m:new Error("Failed to restore embedded wallet")),!1}},[R,w]);ds(()=>{let m=!1,y=null;return A().then(k=>{m||k||i.current||(y=setTimeout(()=>{m||A()},100))}),()=>{m=!0,y&&clearTimeout(y)}},[A]);let T=async()=>{r(!0),p(null);try{let m=await w(),y=await m.load(),k=m.getWallet();y&&k&&(s(te(k)),n.current=k.mnemonic||null,c(!k.mnemonic)),await e();let P=m.getWallet();P&&(s(te(P)),P.mnemonic&&!y&&(n.current=P.mnemonic,c(!0)))}catch(m){R(m),p(m instanceof Error?m:new Error("Embedded wallet connection failed"))}finally{r(!1)}},v=async()=>{r(!0),p(null);try{let m=await w();E()?.expect("create");let y=await m.generateWallet();return s(te(y)),n.current=y.mnemonic,c(!0),y}catch(m){return p(m instanceof Error?m:new Error("Failed to generate wallet")),null}finally{r(!1)}},x=async m=>{r(!0),p(null);try{let y=await w();E()?.expect("create");let k=await y.importFromMnemonic(m);return s(te(k)),n.current=null,c(!1),k}catch(y){return p(y instanceof Error?y:new Error("Failed to import wallet")),null}finally{r(!1)}},b=async m=>{r(!0),p(null);try{let y=await w();E()?.expect("create");let k=await y.importFromPrivateKey(m);return s(te(k)),n.current=null,c(!1),k}catch(y){return p(y instanceof Error?y:new Error("Failed to import wallet")),null}finally{r(!1)}},I=async()=>{r(!0),p(null);try{await(await w()).wipe(),s(null),n.current=null,c(!1)}catch(m){p(m instanceof Error?m:new Error("Failed to wipe wallet"))}finally{r(!1)}},W=X(m=>{let y=S();y.setActiveNamespace(m);let k=y.getWallet();s(k?te(k):null)},[S]),L=X(async()=>{let m=await w(),y=await m.backfillAccounts();if(y.length>0){let k=m.getWallet();s(k?te(k):null)}return y.map(({namespace:k,address:P,derivationPath:N})=>({namespace:k,address:P,...N?{derivationPath:N}:{}}))},[w]),F=()=>{n.current=null,c(!1)};return{connectEmbedded:T,restoreWallet:A,generateWallet:v,importFromMnemonic:x,importFromPrivateKey:b,wipe:I,wallet:o,hasWallet:o!==null,address:o?.address??null,accounts:o?.accounts??[],activeNamespace:o?.activeNamespace??null,setActiveNamespace:W,backfillAccounts:L,seedPhrase:n.current,getSeedPhrase:d,getPrivateKey:h,backupPending:u,confirmBackup:F,isBusy:g,error:a,clearError:f,storageSecurityLevel:(()=>{try{let m=S(),y=m.getStorageSecurityLevel?.()??4;return m.getWallet()?(l.current=y,y):o?l.current:y}catch{return o?l.current:4}})(),securityReport:(()=>{let m=null;try{m=S().getStorageSecurityReport?.()??null}catch{m=null}if(!m)return C.current=null,null;let y=JSON.stringify(m);return C.current?.json===y?C.current.value:(C.current={json:y,value:m},m)})()}}import{chainNumber as Es}from"@naculus/connect-appkit-core";import{useState as ws,useCallback as ks,useEffect as An,useRef as bn,useMemo as xs}from"react";import{WalletError as fs}from"@naculus/connect-core";import{useCallback as xn,useEffect as gs,useLayoutEffect as Cs,useMemo as hs,useRef as vn}from"react";import{tokenChainMismatch as ys}from"@naculus/connect-appkit-core";function Ss(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 ae(e){let{token:t,chainId:o}=e,s=t.address.toLowerCase(),n=Ss(e),l=hs(()=>({key:n}),[n]),i=vn(n),C=vn(!0);Cs(()=>{i.current=n},[n]),gs(()=>(C.current=!0,()=>{C.current=!1}),[]);let u=xn(()=>C.current&&i.current===n,[n]),c=xn(()=>{if(!u())throw new fs("session_inactive","Wallet or token context changed. Retry the operation with the current account and chain.");let g=ys({address:s,chainId:t.chainId},o);if(g)throw g},[u,s,t.chainId,o]);return{identity:l,isCurrent:u,assertCurrent:c}}import{ERC20_MIN_ABI as vs,formatUnits as As}from"@naculus/connect-core";function bs(e){let{publicClient:t}=$(),{currentChain:o}=V(),{identity:s,isCurrent:n,assertCurrent:l}=ae({token:e.token,chainId:o?Es(o)??void 0:void 0,owner:e.owner,spender:e.spender,publicClient:t}),[i,C]=ws(null),u=i?.identity===s?i.raw:null,c=i?.identity===s&&i.fetching,g=i?.identity===s?i.error:null,r=bn(null),a=bn(0),p=ks(async()=>{if(!n())return;let d=++a.current,S=()=>n()&&d===a.current;if(C({identity:s,raw:null,fetching:!!t,error:null}),!!t)try{l();let h=await t.readContract({address:e.token.address,abi:vs,functionName:"allowance",args:[e.owner,e.spender]});if(!S())return;C({identity:s,raw:h,fetching:!1,error:null})}catch(h){if(!S())return;C({identity:s,raw:null,fetching:!1,error:h instanceof Error?h:new Error("Failed to fetch allowance")})}},[t,e.token.address,e.token.chainId,e.owner,e.spender,s,n,l]);return An(()=>{p().catch(d=>console.warn("useERC20Allowance: initial fetch failed:",d))},[p]),An(()=>(e.refreshInterval&&e.refreshInterval>0&&(r.current=setInterval(p,e.refreshInterval)),()=>{r.current&&(clearInterval(r.current),r.current=null)}),[e.refreshInterval,p]),{allowance:xs(()=>{if(u===null)return null;let d=e.token.decimals;return d===void 0?null:As(u,d)},[u,e.token.decimals]),allowanceRaw:u,isFetching:c,error:g,refetch:p}}import{chainNumber as Rs,createDecimalsCache as Ts,encodeErc20Approve as Is,readDecimals as kt,writeDecimals as In}from"@naculus/connect-appkit-core";import{ERC20_MIN_ABI as Ne,formatUnits as Us,parseUnits as Un,WalletError as _e}from"@naculus/connect-core";import{useCallback as he,useRef as Pn,useState as Wn}from"react";import{WalletError as wt}from"@naculus/connect-core";import{useCallback as Rn,useState as Tn}from"react";function Ce(){let{session:e,chainId:t,client:o}=U(),[s,n]=Tn("idle"),[l,i]=Tn(null),C=Rn(async c=>{if(!e){n("failed");let r=new wt("wallet_unavailable","No active session");throw i(r),r}let g=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(!g){n("failed");let r=new wt("wallet_unavailable","No EVM account found");throw i(r),r}n("awaiting_approval"),i(null);try{let r={...c,from:c.from??g.split(":").pop()},a=O(o);if(!a)throw new wt("wallet_unavailable","Client not initialized");let p=await a.sendTransaction(e,{transaction:r,chainId:t??void 0}),f=Ie(p);return n("submitted"),f}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]),u=Rn(()=>{n("idle"),i(null)},[]);return{sendTransaction:C,status:s,error:l,reset:u,isSending:s==="awaiting_approval"}}function Ps(e){return e.includes(":")?e.split(":").pop():e}var Ws=2n**256n-1n;function Os(e){let{publicClient:t,walletClient:o}=$(),{evmAccount:s,isConnected:n}=B(),{currentChain:l}=V(),{session:i,client:C}=U(),{sendTransaction:u,isSending:c,error:g,reset:r}=Ce(),[a,p]=Wn(null),{identity:f,isCurrent:d,assertCurrent:S}=ae({token:e.token,chainId:l?Rs(l)??void 0:void 0,owner:s,spender:e.spender,connected:n,publicClient:t,walletClient:o,session:i,client:C}),[h,w]=Wn(null),E=h?.identity===f?h.raw:null,R=h?.identity===f&&h.fetching,A=Pn(Ts(e.token,e.token.decimals)),T=Pn(0),v=a??g,x=s?Ps(s):null,b=he(async()=>{if(!d())return null;let y=++T.current,k=()=>d()&&y===T.current;if(w({identity:f,raw:null,fetching:!!t&&!!x&&n}),p(null),!t||!x||!n)return null;try{S();let P=await t.readContract({address:e.token.address,abi:Ne,functionName:"allowance",args:[x,e.spender]});return k()?(w({identity:f,raw:P,fetching:!1}),P):null}catch(P){return k()&&(w({identity:f,raw:null,fetching:!1}),p(P instanceof Error?P:new Error("Failed to fetch allowance"))),null}},[t,x,e.token.address,e.token.chainId,e.spender,f,d,S,n]),I=(()=>{if(E===null)return null;let y=kt(A.current,e.token,e.token.decimals);return y===void 0?null:Us(E,y)})(),W=he(async y=>{if(p(null),r(),!n||!s){let k=new _e("wallet_unavailable","No connected account");throw p(k),k}if(!t){let k=new _e("wallet_unavailable","No public client");throw p(k),k}try{S();let k=Is(e.spender,y),P=O(C);if(i&&P){let _=await u({to:e.token.address,data:k,value:"0"});return b(),_}if(o){let{request:_}=await t.simulateContract({address:e.token.address,abi:Ne,functionName:"approve",args:[e.spender,y],account:x});S();let J=await o.writeContract(_);return b(),J}let N=await u({to:e.token.address,data:k,value:"0"});return b(),N}catch(k){let P=k instanceof Error?k:new Error("Approve failed");throw d()&&p(P),P}},[e,t,o,s,n,i,C,x,u,r,b,S,d]),L=he(async y=>{try{if(S(),!t)throw new _e("wallet_unavailable","No public client");let k=kt(A.current,e.token,e.token.decimals);k===void 0&&(k=await t.readContract({address:e.token.address,abi:Ne,functionName:"decimals"}),S(),In(A.current,e.token,k));let P=Un(y,k);return await W(P)}catch(k){throw d()&&p(k instanceof Error?k:new Error("Approve failed")),k}},[e.token,t,W,S,d]),F=he(async()=>W(Ws),[W]),m=he(async y=>{if(!d()||!n||!x||!t)return!1;try{S()}catch(_){return p(_ instanceof Error?_:new Error("Cannot check allowance")),!1}let k=E??await b();if(k===null)return!1;let P=kt(A.current,e.token,e.token.decimals);if(P===void 0){if(!t)throw new _e("wallet_unavailable","Cannot check allowance: no public client to read token decimals.");if(P=await t.readContract({address:e.token.address,abi:Ne,functionName:"decimals"}),!d())return!1;In(A.current,e.token,P)}let N=Un(y,P);return d()&&k>=N},[E,b,e.token.address,e.token.chainId,e.token.decimals,t,d,S,n,x]);return{approve:L,approveMax:F,allowance:I,allowanceRaw:E,hasAllowance:m,isApproving:c,isFetchingAllowance:R,error:v,refetchAllowance:b}}import{chainNumber as Ns,createDecimalsCache as _s,encodeErc20Transfer as Ds,readDecimals as Ms,writeDecimals as Ls}from"@naculus/connect-appkit-core";import{ERC20_MIN_ABI as On,parseUnits as Bs,WalletError as Nn}from"@naculus/connect-core";import{useCallback as Fs,useRef as Hs,useState as Ks}from"react";function qs(e){return e.includes(":")?e.split(":").pop():e}function Vs(e){let{publicClient:t,walletClient:o}=$(),{evmAccount:s,isConnected:n}=B(),{currentChain:l}=V(),{session:i,client:C}=U(),{sendTransaction:u,isSending:c,error:g,reset:r}=Ce(),[a,p]=Ks(null),{isCurrent:f,assertCurrent:d}=ae({token:e.token,chainId:l?Ns(l)??void 0:void 0,owner:s,connected:n,publicClient:t,walletClient:o,session:i,client:C}),S=Hs(_s(e.token,e.token.decimals)),h=a??g;return{sendTransfer:Fs(async(E,R)=>{if(p(null),r(),!n||!s){let A=new Nn("wallet_unavailable","No connected account");throw p(A),A}if(!t){let A=new Nn("wallet_unavailable","No public client available");throw p(A),A}try{d();let A=qs(s),T=Ms(S.current,e.token,e.token.decimals);T===void 0&&(T=await t.readContract({address:e.token.address,abi:On,functionName:"decimals"}),d(),Ls(S.current,e.token,T));let v=Bs(R,T),x=Ds(E,v),b=O(C);if(i&&b)return await u({to:e.token.address,data:x,value:"0"});if(o){let{request:W}=await t.simulateContract({address:e.token.address,abi:On,functionName:"transfer",args:[E,v],account:A});return d(),await o.writeContract(W)}return await u({to:e.token.address,data:x,value:"0"})}catch(A){let T=A instanceof Error?A:new Error("Transfer failed");throw f()&&p(T),T}},[e.token,t,o,s,n,i,C,u,r,d,f]),isSending:c,error:h}}import{chainNumber as zs,encodeErc20Transfer as Qs}from"@naculus/connect-appkit-core";import{parseUnits as Xs}from"@naculus/connect-core";import{useMemo as Ys}from"react";import{simulateTransactionPreview as $s}from"@naculus/connect-appkit-core";import{useCallback as _n,useEffect as Gs,useRef as js,useState as xt}from"react";function vt(e,t){U();let{evmAccount:o}=B(),{currentChain:s}=V(),{publicClient:n}=$(),[l,i]=xt(void 0),[C,u]=xt(!1),[c,g]=xt(null),r=js(void 0),a=_n(async()=>{e&&(u(!0),g(null));try{let f=await $s(e,{chainId:t,currentChain:s,publicClient:n,evmAccount:o});return i(f),f}catch(f){let d=f instanceof Error?f:new Error("Simulation failed");throw g(d),d}finally{e&&u(!1)}},[e,t,s,n,o]);Gs(()=>{if(e)return r.current&&clearTimeout(r.current),r.current=setTimeout(()=>{a().catch(()=>{})},300),()=>{r.current&&clearTimeout(r.current)}},[e,a]);let p=_n(()=>{i(void 0),g(null),u(!1)},[]);return{result:l,isSimulating:C,error:c,simulate:a,reset:p}}function Js(e){let{evmAccount:t,isConnected:o}=B(),{currentChain:s}=V(),n=e.token.chainId??(s?zs(s)??void 0:void 0),l=Ys(()=>{if(!(!o||!t))try{let C=e.token.decimals;if(C===void 0)return;let u=Xs(e.amount,C),c=Qs(e.to,u);return{to:e.token.address,data:c,value:"0"}}catch{return}},[e.token.address,e.token.decimals,e.to,e.amount,t,o]),i=vt(l,n);return{result:l?i.result:void 0,isSimulating:!!l&&i.isSimulating,error:l?i.error:null,reSimulate:i.simulate,reset:i.reset}}import{useState as At,useCallback as oa,useRef as bt}from"react";import{useState as De,useEffect as Zs,useCallback as Dn,useRef as ea}from"react";import{createContext as ta,useContext as na}from"react";var Mn=ta(null);function ye(){return na(Mn)}function ra(e,t,o){let s=ye(),n=o??s,[l,i]=De(null),[C,u]=De(!1),[c,g]=De(!1),[r,a]=De(null),p=ea(void 0),f=Dn(async()=>{if(!(!n||!e)){u(!0),a(null);try{await n.refreshTx(e,t);let h=n.getTxStatus(e,t);h&&i(h)}catch(h){a(h instanceof Error?h:new Error(String(h)))}finally{u(!1)}}},[n,e,t]),d=Dn(()=>{!n||!e||(n.stopWatching(e,t),g(!1))},[n,e,t]);Zs(()=>{if(!n||!e||!t){i(null),g(!1);return}p.current&&p.current!==e&&n.stopWatching(p.current),p.current=e;let h=!1;g(!0),u(!0),a(null);let w=n.getTxStatus(e,t);w&&(i(w),u(!1)),n.watchTx(e,t,{}).then(R=>{h||(i(R),u(!1))}).catch(R=>{h||(a(R instanceof Error?R:new Error(String(R))),u(!1))});let E=R=>{h||i({...R})};return n.on("statusChange",E),()=>{h=!0,g(!1),n.off("statusChange",E)}},[n,e,t]);let S=l?.status??"idle";return{entry:l,status:S,isLoading:C,isWatching:c,error:r,refresh:f,stopWatching:d}}function sa(e){let t=ye(),o=e??t,[s,n]=At(null),[l,i]=At(null),[C,u]=At(null),c=bt(null),g=bt(null),r=bt(null);o&&(g.current||(g.current=p=>{i(p),(!c.current||p.createdAt>=c.current.createdAt)&&(n(p),c.current=p)},o.on("confirmed",g.current)),r.current||(r.current=p=>{u(p),(!c.current||p.createdAt>=c.current.createdAt)&&(n(p),c.current=p)},o.on("failed",r.current)));let a=oa(()=>{n(null),i(null),u(null),c.current=null},[]);return{lastTx:s,lastConfirmedTx:l,lastFailedTx:C,clear:a}}import{useCallback as ca}from"react";import{useCallback as aa,useEffect as Ln,useMemo as ia,useRef as Bn,useState as Rt}from"react";import{getResolver as la}from"@naculus/connect-appkit-core";function Me({input:e,skip:t=!1,resolverConfig:o,scope:s,query:n}){let[l,i]=Rt(null),[C,u]=Rt(!1),[c,g]=Rt(null),r=Bn(0),a=Bn(!0);Ln(()=>(a.current=!0,()=>{a.current=!1}),[]);let p=ia(()=>la(o),[o]),f=aa(()=>{let d=e.trim();if(!d||t){r.current+=1,i(null),u(!1),g(null);return}let S=++r.current;u(!0),g(null),n(p,d,s).then(h=>{!a.current||S!==r.current||(i(h),u(!1))}).catch(h=>{!a.current||S!==r.current||(g(h instanceof Error?h:new Error(String(h))),i(null),u(!1))})},[e,t,s,p,n]);return Ln(()=>{f()},[f]),{data:l,isLoading:C,error:c,refetch:f}}function ua(e,t){let o=ca((s,n,l)=>s.lookupAddress(n,l),[]);return Me({input:e,skip:t?.skip,resolverConfig:t?.resolverConfig,scope:t?.chainId,query:o})}import{useState as Fn,useCallback as Y,useMemo as pa,useEffect as Hn,useRef as da}from"react";import{addInAppNotification as ma,channelsUpdate as fa,clearOneInAppNotification as ga,createNotificationSettingsStorage as Kn,DEFAULT_NOTIFICATION_SETTINGS as Ca,loadNotificationSettings as ha,mutedChainSettings as qn,saveNotificationSettings as ya,updateNotificationSettings as Sa}from"@naculus/connect-appkit-core";import{InAppChannel as Ea}from"@naculus/connect-core";function wa(e){let t=da(null);t.current||(t.current=e?.channel??new Ea);let o=t.current,[s,n]=Fn(()=>o.getHistory()),[l,i]=Fn(()=>Ca);Hn(()=>{let h=e?.storage??Kn();ha(h).then(w=>{w&&i(w)})},[]),Hn(()=>(o.onNotification=h=>{n(w=>[...w,h])},o.restore().then(()=>{n(o.getHistory())}),()=>{o.onNotification=void 0}),[]);let C=pa(()=>s.filter(h=>!h.read).length,[s]),u=Y(()=>{o.clear(),n([])},[o]),c=Y(h=>{ga(o,h).then(()=>{n(o.getHistory())})},[o]),g=Y(h=>{o.markAsRead(h),n(w=>w.map(E=>E.id===h?{...E,read:!0}:E))},[o]),r=Y(()=>{o.markAllAsRead(),n(h=>h.map(w=>({...w,read:!0})))},[o]),a=Y(h=>{ma(o,h)},[o]),p=Y(h=>{i(w=>{let E=Sa(w,h),R=e?.storage??Kn();return ya(R,E),E})},[e?.storage]),f=Y(h=>{p(fa(h))},[p]),d=Y(h=>{p(qn(l,h,!0))},[l.mutedChains,p]),S=Y(h=>{p(qn(l,h,!1))},[l.mutedChains,p]);return{notifications:s,unreadCount:C,addNotification:a,clear:u,clearOne:c,markAsRead:g,markAllAsRead:r,settings:l,updateSettings:p,setChannels:f,muteChain:d,unmuteChain:S}}import{useCallback as Tt,useSyncExternalStore as ka}from"react";var Vn=()=>null,xa=()=>()=>{};function va(){let{client:e}=U(),t=O(e)?.passphraseGate??null,o=ka(t?.subscribe??xa,t?.getSnapshot??Vn,Vn),s=Tt(i=>t?.submit(i),[t]),n=Tt(()=>t?.cancel(),[t]),l=Tt(i=>t?.forget(i),[t]);return{request:o,submit:s,cancel:n,forget:l,isUnlocked:t?.isUnlocked??!1,gate:t}}import{useCallback as Aa}from"react";function ba(e,t){let o=Aa((s,n)=>s.resolveName(n),[]);return Me({input:e,skip:t?.skip,resolverConfig:t?.resolverConfig,query:o})}import{assertHexSignature as It,bareEvmAddress as Ra,buildSmartAccountConfig as Ta,resolveUserOpChain as Ia}from"@naculus/connect-appkit-core";import{WalletError as ie}from"@naculus/connect-core";import{useCallback as $n,useEffect as Gn,useRef as jn,useState as Se}from"react";async function Ua(e,t,o,s,n){let l=O(t);if(!l)throw new ie("wallet_unavailable","Client not initialized");let i=[o,s];if(e.walletType==="eip6963"||e.id?.startsWith("eip6963-")){let{eip6963Connector:C}=await import("@naculus/connector-evm-injected"),u=C.getDiscoveredWallets().find(g=>g.id===e.walletId),c=u?await u.provider.request({method:"personal_sign",params:i}):await C.request({method:"personal_sign",params:i});return It(c)}if(e.walletType==="walletconnect")return It(await l.connector.request({method:"personal_sign",params:i}));if(e.walletType==="embedded"){let C=l.embeddedConnector;if(!C?.signHash)throw new ie("method_unsupported","This embedded wallet build cannot sign a raw digest. Upgrade @naculus/connector-embedded or pass an explicit signer.");return It(await C.signHash(e,o))}throw e.walletType==="passkeys"?new ie("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 ie("method_unsupported",`Raw UserOperation signing is not available for ${e.walletType} on ${n}. Pass a signer that signs the raw 32-byte hash.`)}function Pa(e){let{evmAccount:t}=B(),{session:o,chainId:s,client:n}=U(),[l,i]=Se(null),[C,u]=Se(null),[c,g]=Se(!1),[r,a]=Se(!1),[p,f]=Se(null),d=jn(0),S=jn(!1);Gn(()=>()=>{d.current+=1,S.current=!1},[]),Gn(()=>{d.current+=1,S.current=!1,i(null),u(null),g(!1),a(!1),f(null)},[n,s,t,e?.accountType,e?.bundlerUrl,e?.chainId,e?.entryPoint,e?.owner,e?.rpcUrl,e?.salt,e?.signerMode,o]);let h=$n(async(E,R)=>{let A=b=>(f(b),null);if(!e?.rpcUrl)return A(new Error("RPC URL not configured"));if(!e.bundlerUrl)return A(new Error("Bundler URL not configured"));if(!E.length)return A(new Error("At least one call is required"));if(S.current)return A(new Error("A UserOperation is already in progress"));let T=Ra(e.owner??t);if(!T)return A(new ie("wallet_unavailable","No EVM account found"));let v;try{v=Ia(e.chainId,s)}catch(b){return A(b)}if(!e.signer&&!o)return A(new ie("wallet_unavailable","No active session"));let x=++d.current;S.current=!0,g(!0),a(!0),f(null),i(null),u(null);try{let{SmartAccountManager:b}=await import("@naculus/connect-core"),I=e.signer??(m=>Ua(o,n,m,T,v)),W=new b({rpcUrl:e.rpcUrl,bundlerClient:{url:e.bundlerUrl},chainId:v,signer:I,signerMode:e.signer?e.signerMode??"eip191":"raw"}),L=Ta(T,v,e),F=await W.sendUserOperation(L,E,R);return x!==d.current?null:(a(!1),i(F.userOpHash),W.getUserOperationReceipt(F.userOpHash).then(m=>{x===d.current&&u(m)}).catch(()=>{}),F)}catch(b){if(x!==d.current)return null;let I=b instanceof Error?b:new Error("Failed to send UserOperation");return f(I),null}finally{S.current=!1,x===d.current&&(g(!1),a(!1))}},[n,s,t,e,o]),w=$n(()=>{d.current+=1,i(null),u(null),g(!1),a(!1),f(null)},[]);return{sendUserOp:h,userOpHash:l,receipt:C,isPending:c,isEstimating:r,error:p,reset:w}}import{useSyncExternalStore as Wa,useCallback as zn}from"react";function Oa(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 Ut=Object.freeze({session:null,chainSessions:[],activeChainId:null,isConnected:!1,connectorId:null}),Pt=new WeakMap;function Na(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 _a(e){if(!e)return Ut;let t=e.getActiveBundle(),o=Pt.get(e);if(!t)return o&&o.session===null?o:(Pt.set(e,Ut),Ut);let s=Array.from(t.chainSessions.values());if(o&&o.session===t.walletSession&&o.activeChainId===t.activeChainId&&Na(o.chainSessions,s))return o;let n={session:t.walletSession,chainSessions:s,activeChainId:t.activeChainId,isConnected:!0,connectorId:t.walletSession.walletType};return Pt.set(e,n),n}function Da(e){let t=U(),o=e??t.sessionManager??null,s=zn(l=>Oa(o,l),[o]),n=zn(()=>_a(o),[o]);return Wa(s,n)}import{defaultSiwxDomain as Ma,defaultSiwxUri as La}from"@naculus/connect-appkit-core";import{WalletError as Le}from"@naculus/connect-core";import{createSiwxMessage as Ba,generateNonce as Fa,getBlockchainName as Ha,issueNonce as Ka,nowISO as qa}from"@naculus/siwx";import{useCallback as Qn,useState as Xn}from"react";var Va=86400;function Wt(){let{session:e,chainId:t,client:o}=U(),[s,n]=Xn(!1),[l,i]=Xn(null),C=Qn(()=>i(null),[]);return{signIn:Qn(async c=>{if(!e)throw new Le("wallet_unavailable","No active session");let g=c?.chainId??t;if(!g)throw new Le("invalid_chain","No chain to sign for. Connect a wallet or pass options.chainId.");let r=oe(e,g);if(!r)throw new Le("wallet_unavailable","No account found");let a=O(o);if(!a)throw new Le("wallet_unavailable","Client not initialized");let{address:p}=r,f=typeof window>"u"?void 0:window.location,d=c?.domain??Ma(f),S=c?.uri??La(f);n(!0),i(null);try{let h=Fa();await Ka(h);let w=qa(),E=c?.expirySeconds??Va,R=new Date(Date.now()+E*1e3).toISOString(),A=Ba({domain:d,address:p,uri:S,version:1,chainId:g,nonce:h,issuedAt:w,expirationTime:R,statement:c?.statement,resources:c?.resources,requestId:c?.requestId}),T=await a.signMessage(e,{message:A,address:p,chainId:g??void 0}),v={message:{raw:A,domain:d,address:p,statement:c?.statement??null,uri:S,version:1,chainId:g,nonce:h,issuedAt:w,blockchain:Ha(g),expirationTime:R,notBefore:null,resources:c?.resources??[],requestId:c?.requestId??null},signature:T};return n(!1),v}catch(h){let w=h instanceof Error?h:new Error("SIWx sign-in failed");throw i(w),n(!1),w}},[e,t,o]),isSigningIn:s,error:l,clearError:C}}import{siwxResultToSession as Yn}from"@naculus/connect-appkit-core";import{logger as Ot}from"@naculus/connect-core";import{checkSessionExpired as Jn,createLocalStorageSiwxSessionStorage as $a}from"@naculus/siwx";import{useCallback as Be,useEffect as Zn,useRef as Ga,useState as Fe}from"react";function ja(e){let{storagePrefix:t="naculus_",autoRestore:o=!0,defaultExpirySeconds:s=86400}=e??{},[n,l]=Fe(null),[i,C]=Fe(o),[u,c]=Fe(!1),[g,r]=Fe(null),{session:a,chainId:p}=U(),f=Wt(),d=Ga($a(`${t}siwx_session`)),S=Be(()=>r(null),[]);Zn(()=>{if(!o){C(!1);return}let v=!1;return(async()=>{try{let b=await d.current.get();if(v)return;b?(Ot.info("react/useSIWxSession","Restored persisted SIWx session"),l(b),r(null)):l(null)}catch(x){Ot.warn("react/useSIWxSession","Failed to restore SIWx session:",x),l(null)}finally{v||C(!1)}})(),()=>{v=!0}},[o]),Zn(()=>{if(!n?.expiresAt)return;let v=new Date(n.expiresAt).getTime()-Date.now();if(v<=0){l(null);return}let x=setTimeout(()=>{l(b=>b&&b.id===n.id?null:b)},v);return()=>clearTimeout(x)},[n?.id,n?.expiresAt]);let h=Be(async v=>{c(!0),r(null);try{let x={expirySeconds:s,chainId:p??void 0,...v},b=await f.signIn(x),I=Yn(b);return await d.current.set(I),l(I),c(!1),I}catch(x){let b=x instanceof Error?x:new Error("SIWx sign-in failed");throw r(b),c(!1),b}},[f,p,s]),w=Be(async()=>{try{await d.current.remove()}catch(v){Ot.warn("react/useSIWxSession","Failed to clear session:",v)}l(null),r(null)},[]),E=Be(async()=>{if(!n)throw new Error("No active session to refresh");c(!0),r(null);try{let v=await f.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}),x={...Yn(v),id:n.id,refreshedAt:new Date().toISOString()};return await d.current.set(x),l(x),c(!1),x}catch(v){let x=v instanceof Error?v:new Error("Session refresh failed");throw r(x),c(!1),x}},[n,f,s]),R=n!==null&&!Jn(n),A=Jn(n),T=n?.expiresAt?Math.max(0,new Date(n.expiresAt).getTime()-Date.now()):null;return{session:R?n:null,isAuthenticated:R,isRestoring:i,isSigningIn:u,isExpired:A,timeUntilExpiry:T,signIn:h,signOut:w,refresh:E,error:g,clearError:S}}import{defaultSiwxDomain as za,defaultSiwxUri as Qa}from"@naculus/connect-appkit-core";import{WalletError as He}from"@naculus/connect-core";import{createSiwxMessage as Xa,generateNonce as Ya,getBlockchainName as Ja,issueNonce as Za,nowISO as ei}from"@naculus/siwx";import{useCallback as er,useState as Nt}from"react";function Ee(){let{session:e,chainId:t,client:o}=U(),[s,n]=Nt(!1),[l,i]=Nt(null),[C,u]=Nt(null),c=er(()=>u(null),[]);return{signIn:er(async r=>{if(!e)throw new He("wallet_unavailable","No active session");let a=r?.chainId??t;if(!a)throw new He("invalid_chain","No chain to sign for. Connect a wallet or pass options.chainId.");let p=oe(e,a);if(!p)throw new He("wallet_unavailable","No account found");let f=O(o);if(!f)throw new He("wallet_unavailable","Client not initialized");let{address:d}=p,S=typeof window>"u"?void 0:window.location,h=r?.domain??za(S),w=r?.uri??Qa(S);n(!0),u(null);try{let E=Ya();await Za(E);let R=ei(),A=Xa({domain:h,address:d,uri:w,version:1,chainId:a,nonce:E,issuedAt:R,statement:r?.statement,expirationTime:r?.expirySeconds?new Date(Date.now()+r.expirySeconds*1e3).toISOString():void 0,resources:r?.resources,requestId:r?.requestId}),T=await f.signMessage(e,{message:A,address:d,chainId:a??void 0}),v=r?.expirySeconds?new Date(Date.now()+r.expirySeconds*1e3).toISOString():null,x={message:{raw:A,domain:h,address:d,statement:r?.statement??null,uri:w,version:1,chainId:a,nonce:E,issuedAt:R,blockchain:Ja(a),expirationTime:v,notBefore:null,resources:r?.resources??[],requestId:r?.requestId??null},signature:T};return i(x),x}catch(E){let R=E instanceof Error?E:new Error("SIWx sign-in failed");throw u(R),R}finally{n(!1)}},[e,t,o]),isSigningIn:s,result:l,error:C,clearError:c}}import{WalletError as _t}from"@naculus/connect-core";import{useCallback as tr}from"react";function ti(){let{session:e,chainId:t}=U();return tr(o=>{if(!e)throw new _t("wallet_unavailable","No active session");let s=o??t;if(s&&!s.startsWith("eip155:"))throw new _t("namespace_mismatch",`Ethereum SIWx requires an eip155 chain, received ${s}`);let n=e.namespaces.eip155;if(!n||n.accounts.length===0)throw new _t("namespace_mismatch","No EVM (eip155) accounts found in session")},[e,t])}function ni(){let e=ti(),t=Ee();return{signIn:tr(async s=>(e(s?.chainId),t.signIn(s)),[e,t.signIn]),isSigningIn:t.isSigningIn,result:t.result,error:t.error,clearError:t.clearError}}import{resolveSimulationEndpoint as ri}from"@naculus/connect-appkit-core";import{SimulationManager as oi}from"@naculus/wallet-engine";import{useCallback as Dt,useRef as si,useState as Mt}from"react";function ai(e){let t=e?.rpcUrl,o=e?.chainId,s=si(null),n=Dt(()=>(s.current||(s.current=new oi({enabled:!0,rpcUrl:t,autoSimulate:!1})),s.current),[t]),[l,i]=Mt(null),[C,u]=Mt(!1),[c,g]=Mt(null),r=Dt(async(p,f,d,S,h)=>{u(!0),g(null);try{let w=n(),E=ri(h?.chainId,o,h?.rpcUrl,t),R=await w.simulateERC20Transfer(p,f,d,S,E.chainId,h?.decimals,E.rpcUrl);return i(R),R}catch(w){let E=w instanceof Error?w:new Error(String(w));throw g(E),E}finally{u(!1)}},[t,o,n]),a=Dt(()=>{i(null),g(null),u(!1)},[]);return{result:l,loading:C,error:c,simulate:r,reset:a}}import{isSiwxExpired as ii,isSiwxNotBeforeValid as li}from"@naculus/connect-appkit-core";import{LocalStorageAdapter as ci,logger as Ke}from"@naculus/connect-core";import{useCallback as Lt,useEffect as ui,useRef as pi,useState as qe}from"react";var Ve="siwx_auth";function di(e){return new ci(e)}function mi(e){let{storagePrefix:t="naculus_",autoRestore:o=!0}=e??{},[s,n]=qe(null),[l,i]=qe(o),[C,u]=qe(!1),[c,g]=qe(null),r=Ee(),a=pi(di(t)),p=Lt(()=>g(null),[]);ui(()=>{if(!o){i(!1);return}let S=!1;return(async()=>{try{let h=a.current,w=await h.get(Ve);if(S)return;w&&!ii(w,new Date)&&li(w,new Date)?(Ke.info("react/useSiwxAuthSession","Restored persisted SIWx auth session"),n(w),g(null)):w&&(Ke.info("react/useSiwxAuthSession","Persisted SIWx auth expired, clearing"),await h.remove(Ve))}catch(h){Ke.warn("react/useSiwxAuthSession","Failed to restore SIWx auth:",h)}finally{S||i(!1)}})(),()=>{S=!0}},[o]);let f=Lt(async S=>{u(!0),g(null);try{let h=await r.signIn(S);return await a.current.set(Ve,h),n(h),u(!1),h}catch(h){let w=h instanceof Error?h:new Error("SIWx sign-in failed");throw g(w),u(!1),w}},[r]),d=Lt(async()=>{try{await a.current.remove(Ve)}catch(S){Ke.warn("react/useSiwxAuthSession","Failed to clear SIWx auth:",S)}n(null),g(null)},[]);return{isSignedIn:s!==null,isRestoring:l,siwxResult:s,isSigningIn:C,error:c,signIn:f,signOut:d,clearError:p}}import{bareEvmAddress as fi,buildSmartAccountConfig as gi,resolveEvmChainId as nr}from"@naculus/connect-appkit-core";import{WalletError as sr}from"@naculus/connect-core";import{useCallback as ne,useEffect as rr,useRef as Bt,useState as we}from"react";function or(e){return new sr("wallet_unavailable",e)}function Ci(e){let{evmAccount:t}=B(),{session:o,chainId:s,client:n}=U(),[l,i]=we(null),[C,u]=we(!1),[c,g]=we(null),[r,a]=we(!1),[p,f]=we(null),d=Bt(null),S=Bt(0),h=Bt(!1);rr(()=>{if(d.current=null,!e?.rpcUrl)return;let b=!1;return import("@naculus/connect-core").then(({SmartAccountManager:I})=>{if(b)return;let W=nr(e.chainId,s);W&&(d.current=new I({rpcUrl:e.rpcUrl,chainId:W,bundlerClient:{url:e.bundlerUrl??""}}))}).catch(I=>{b||f(I instanceof Error?I:new Error("Failed to load account-abstraction module"))}),()=>{b=!0}},[s,e?.rpcUrl,e?.bundlerUrl,e?.chainId]),rr(()=>{S.current+=1,h.current=!1,i(null),u(!1),g(null),a(!1),f(null)},[t,s,e?.rpcUrl,e?.bundlerUrl,e?.chainId,e?.entryPoint,e?.accountType,e?.salt]);let w=ne(()=>{let b=fi(t);if(!b||!d.current)return null;let I=nr(e?.chainId,s);return I?gi(b,I,{accountType:e?.accountType,entryPoint:e?.entryPoint,salt:e?.salt}):null},[t,s,e?.accountType,e?.chainId,e?.entryPoint,e?.salt]),E=ne(b=>(f(b),null),[]),R=ne(()=>h.current?null:(h.current=!0,S.current),[]),A=ne(b=>{S.current===b&&(h.current=!1)},[]),T=ne(async()=>{let b=w();if(!b||!d.current)return E(new Error("Smart account not configured"));let I=R();if(I===null)return E(new Error("Smart account operation already in progress"));a(!0),f(null);try{let L=await d.current.createAccount(b);return S.current!==I?null:(i(L.address),u(L.isDeployed),g(L),L)}catch(W){if(S.current!==I)return null;let L=W instanceof Error?W:new Error("Failed to create smart account");return f(L),null}finally{S.current===I&&a(!1),A(I)}},[R,E,A,w]),v=ne(async()=>{let b=w();if(!b||!d.current)return E(new Error("Smart account not configured"));if(!o)return E(or("No active session"));let I=O(n);if(!I)return E(or("Client not initialized"));if(s&&s!==b.chainId)return E(new sr("chain_mismatch",`Connected chain ${s} does not match smart account chain ${b.chainId}.`));let W=R();if(W===null)return E(new Error("Smart account operation already in progress"));a(!0),f(null);try{let L=d.current,F=await L.createAccount(b);if(S.current!==W)return null;if(F.isDeployed)return i(F.address),u(!0),g(F),F.address;let m=await L.getDeployCallData(b),y=await I.sendTransaction(o,{transaction:{to:m.to,data:m.data,value:m.value.toString()},chainId:b.chainId});if(S.current!==W)return null;let k=await L.createAccount(b);return i(k.address),u(k.isDeployed),g(k),y}catch(L){if(S.current!==W)return null;let F=L instanceof Error?L:new Error("Failed to deploy smart account");return f(F),null}finally{S.current===W&&a(!1),A(W)}},[n,s,R,E,A,w,o]),x=ne(async()=>{let b=w();if(!b||!d.current)return null;let I=S.current;try{let W=await d.current.getAccountAddress(b);return S.current!==I?null:(i(W),W)}catch(W){return S.current!==I||f(W instanceof Error?W:new Error("Failed to get smart account address")),null}},[w]);return{address:l,isDeployed:C,accountInfo:c,isLoading:r,error:p,createWallet:T,deployWallet:v,getAddress:x}}import{useMemo as hi}from"react";function Ft(){let{accounts:e,isConnected:t}=U();return hi(()=>{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,l=s.length>=3?s.slice(0,-1).join(":"):null;return{address:n,caip10:o,chainId:l,isConnected:t}},[e,t])}import{useCallback as yi,useEffect as ar,useRef as Si,useState as Ht}from"react";import{getSolanaBalance as Ei}from"@naculus/connect-core";function wi(e={}){let{client:t}=U(),{address:o}=Ft(),s=e.address??o,n=e.rpcUrl??O(t)?.solanaRpcUrl??null,[l,i]=Ht(null),[C,u]=Ht(!1),[c,g]=Ht(null),r=Si(0),a=yi(async()=>{if(!s||!n){i(null);return}let p=++r.current;u(!0),g(null);try{let f=await Ei(n,s);if(p!==r.current)return;i(f)}catch(f){if(p!==r.current)return;i(null),g(f instanceof Error?f:new Error("Balance read failed"))}finally{p===r.current&&u(!1)}},[s,n]);return ar(()=>{a()},[a]),ar(()=>{if(!e.refreshInterval||e.refreshInterval<=0)return;let p=setInterval(()=>{a()},e.refreshInterval);return()=>clearInterval(p)},[e.refreshInterval,a]),{balance:l,isFetching:C,error:c,isConfigured:!!n,refetch:a}}import{readSolanaRoles as ki}from"@naculus/connect-appkit-core";import{useMemo as xi}from"react";function vi(){let{client:e,session:t,accounts:o}=U();return xi(()=>{let s=O(e)?.solanaConnector,{roles:n,absence:l}=ki(s,t);return{roles:n,absence:l,identity:n?.identity??null,signer:n?.signer??null,payer:n?.payer??null}},[e,t,o])}import{WalletError as ir}from"@naculus/connect-core";import{useCallback as Kt,useState as qt}from"react";import{getSignatureStatus as Ai}from"@naculus/connect-core";function bi(){let{client:e,session:t}=U(),[o,s]=qt(!1),[n,l]=qt(!1),[i,C]=qt(null),u=()=>{let a=O(e);if(!a||!t)throw new ir("wallet_unavailable","No connected wallet.");return a},c=Kt(async a=>{s(!0),C(null);try{return await u().signTransaction(t,{transaction:a})}catch(p){let f=p instanceof Error?p:new Error("Signing failed");throw C(f),f}finally{s(!1)}},[e,t]),g=Kt(async a=>{l(!0),C(null);try{return await u().sendTransaction(t,{transaction:a})}catch(p){let f=p instanceof Error?p:new Error("Send failed");throw C(f),f}finally{l(!1)}},[e,t]),r=Kt(async a=>{let p=O(e)?.solanaRpcUrl;if(!p)throw new ir("no_rpc","Set solanaRpcUrl on the client to read a signature's status.");return Ai(p,a)},[e]);return{signTransaction:c,sendTransaction:g,getStatus:r,isSigning:o,isSending:n,error:i,reset:()=>C(null)}}import{useCallback as lr,useState as cr}from"react";import{toChainSwitchError as Ri}from"@naculus/connect-appkit-core";function Ti(){let{switchChain:e,chainId:t}=U(),[o,s]=cr(!1),[n,l]=cr(null),i=lr(async u=>{s(!0),l(null);try{await e(u)}catch(c){let g=Ri(c);throw l(g),g}finally{s(!1)}},[e]),C=lr(()=>{l(null)},[]);return{switchChain:i,isSwitching:o,currentChainId:t,error:n,clearError:C}}import{chainNumber as Ii,resolveChain as Ui,toViemChain as Pi}from"@naculus/connect-appkit-core";import{useState as $e,useEffect as Vt,useCallback as ur,useMemo as $t,useRef as Wi}from"react";import{createPublicClient as Oi,http as Ni,formatUnits as _i}from"viem";function Di(e){let{evmAccount:t,isConnected:o}=B(),{chainId:s,chains:n}=U(),[l,i]=$e([]),[C,u]=$e(!1),[c,g]=$e(null),{tokens:r,refreshInterval:a}=e,p=Wi(null),f=$t(()=>r.map(v=>v.address.toLowerCase()+"|"+v.decimals+"|"+v.symbol).join(","),[r]),d=$t(()=>Ui(n,s),[s,n]),S=d?Ii(d):null,h=$t(()=>d?Pi(d,S):null,[d,S]),[w,E]=$e(null);Vt(()=>{if(!h||!d?.rpcUrl){E(null);return}let v=Oi({transport:Ni(d.rpcUrl),chain:h});E(v)},[d,h]);let R=[{name:"balanceOf",type:"function",stateMutability:"view",inputs:[{name:"owner",type:"address"}],outputs:[{name:"balance",type:"uint256"}]}],A=ur(async()=>{if(!t||!w||r.length===0){i([]);return}u(!0),g(null);try{let v=t.includes(":")?t.split(":").pop():t,b=(await Promise.allSettled(r.map(async I=>{try{let W=await w.readContract({address:I.address,abi:R,functionName:"balanceOf",args:[v]});return{address:I.address,symbol:I.symbol,decimals:I.decimals,name:I.name,balance:W.toString(),formatted:_i(W,I.decimals)}}catch{return{address:I.address,symbol:I.symbol,decimals:I.decimals,name:I.name,balance:null,formatted:null}}}))).map(I=>I.status==="fulfilled"?I.value:{address:"",symbol:"?",decimals:0,balance:null,formatted:null});i(b)}catch(v){g(v instanceof Error?v:new Error("Failed to fetch token balances"))}finally{u(!1)}},[t,w,f]);Vt(()=>{o&&t&&r.length>0&&A()},[o,t,f,A]),Vt(()=>(a&&a>0&&o&&t&&r.length>0&&(p.current=setInterval(A,a)),()=>{p.current&&(clearInterval(p.current),p.current=null)}),[a,o,t,f,A]);let T=ur(v=>l.find(x=>x.address.toLowerCase()===v.toLowerCase()),[l]);return{tokenBalances:l,isLoading:C,error:c,refetch:A,getTokenBalance:T,chain:d}}import{useState as Gt,useEffect as pr,useCallback as Mi,useRef as Li}from"react";function Bi(e,t,o){let s=ye(),n=o??s,[l,i]=Gt([]),[C,u]=Gt(!1),[c,g]=Gt(null),r=Li(0),a=Mi(async()=>{if(n){u(!0),g(null),r.current++;try{let f=await n.getTxHistory(e,t);i(f)}catch(f){g(f instanceof Error?f:new Error(String(f)))}finally{u(!1)}}},[n,e,t]);pr(()=>{a().catch(()=>{})},[a]),pr(()=>{if(!n)return;let f=()=>{a().catch(()=>{})};return n.on("statusChange",f),()=>{n.off("statusChange",f)}},[n,a]);let p={pending:l.filter(f=>f.status==="pending").length,confirmed:l.filter(f=>f.status==="confirmed").length,failed:l.filter(f=>f.status==="failed").length};return{entries:l,isLoading:C,error:c,refresh:a,summary:p}}import{fetchUserOperationReceipt as Fi,InvalidUserOperationReceiptError as Hi}from"@naculus/connect-appkit-core";import{useCallback as ke,useEffect as dr,useRef as le,useState as re}from"react";function Ki(e){let t=e?.bundlerUrl,o=e?.pollInterval??2e3,s=e?.maxRetries??30,[n,l]=re("idle"),[i,C]=re(null),[u,c]=re(e?.userOpHash??null),[g,r]=re(null),[a,p]=re(!1),[f,d]=re(0),S=le(0),[h,w]=re(0),E=le(null),R=le(null),A=le(0),T=le(0),v=le(null),x=ke(()=>{E.current&&(clearInterval(E.current),E.current=null),R.current&&(clearTimeout(R.current),R.current=null)},[]),b=ke(async(F,m)=>{if(!t||m!==A.current)return;let y=T.current+1;T.current=y,d(y);let k=new AbortController;v.current=k;let P=_=>{m===A.current&&(l("not_found"),p(!1),x(),r(_))},N=_=>{if(m===A.current){if(y<=s){R.current=setTimeout(()=>{b(F,m)},o);return}P(_)}};try{let _=await Fi(t,F,k.signal);if(m!==A.current)return;if(_){C(_),l(_.success?"confirmed":"failed"),p(!1),x();return}l("pending"),N(new Error("UserOperation not included after maximum retries"))}catch(_){if(m!==A.current||k.signal.aborted)return;let J=_ instanceof Error?_:new Error("Unknown bundler response failure");if(J instanceof Hi){P(J);return}N(new Error(`UserOperation status unavailable after ${y} attempt${y===1?"":"s"}: ${J.message}`))}finally{v.current===k&&(v.current=null)}},[t,o,s,x]),I=ke(F=>{A.current+=1;let m=A.current;if(v.current?.abort(),v.current=null,x(),c(F),C(null),r(null),T.current=0,d(0),w(0),S.current=Date.now(),!t){l("not_found"),p(!1),r(new Error("Bundler URL not configured"));return}l("pending"),p(!0),E.current=setInterval(()=>{w(Date.now()-S.current)},1e3),b(F,m)},[t,x,b]),W=ke(()=>{A.current+=1,v.current?.abort(),v.current=null,x(),p(!1)},[x]),L=ke(()=>{A.current+=1,v.current?.abort(),v.current=null,x(),c(null),l("idle"),C(null),r(null),p(!1),T.current=0,d(0),w(0)},[x]);return dr(()=>{e?.userOpHash&&e?.autoStart!==!1&&I(e.userOpHash)},[]),dr(()=>()=>{A.current+=1,v.current?.abort(),v.current=null,x()},[x]),{status:n,receipt:i,userOpHash:u,error:g,isPolling:a,elapsedMs:h,attempts:f,start:I,stop:W,reset:L}}import{validateDestination as ji}from"@naculus/connect-appkit-core";import{useMemo as zi}from"react";var qi={"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."},Vi={"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"},mr={en:qi,zh:Vi},jt="en";function $i(e){jt=e}function Gi(){return jt}function zt(e){return mr[jt][e]??mr.en[e]??e}function fr(e){let{isValid:t,level:o,issue:s}=ji(e);return{isValid:t,level:o,warning:s?zt(`address.${s}`):null}}function Qi({address:e}){return{validation:zi(()=>fr(e),[e])}}function Xi(){let{status:e,session:t,accounts:o,chainId:s,error:n,connect:l,disconnect:i,reconnect:C,switchChain:u}=U(),c=e==="connected",g=e==="connecting",r=e==="reconnecting",a=o[0]??null;return{status:e,session:t,accounts:o,chainId:s,error:n,isConnected:c,isConnecting:g,isReconnecting:r,isDisconnected:e==="disconnected",currentAccount:a,connect:l,disconnect:i,reconnect:C,switchChain:u}}import{useCallback as Xt,useMemo as hr}from"react";var gr={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."},xe="Something went wrong",ve="An unexpected error occurred. Please try again. If the problem persists, check your connection and wallet configuration.";function Ae(e){if(!e)return{title:xe,description:ve};let t=e;if(t.name==="WalletError"&&t.code){let o=t.code,s=gr[o]??xe,n=Cr[o]??t.message??ve;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:xe,description:o||ve}}return typeof e=="string"?{title:xe,description:e||ve}:{title:xe,description:ve}}function Qt(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 Yi(){let{error:e,clearError:t}=U(),o=hr(()=>e?Ae(e):null,[e]),s=hr(()=>e?Qt(e):!1,[e]),n=Xt(()=>{t()},[t]),l=Xt(C=>Ae(C),[]),i=Xt(C=>async()=>{try{return await C()}catch(u){let c=Ae(u);if(u instanceof Error){let g=u;try{g.title=c.title,g.friendlyMessage=c.description,g.code===void 0&&c.code!==void 0&&(g.code=c.code)}catch{}throw g}throw Object.assign(new Error(c.description,{cause:u}),{title:c.title,code:c.code,friendlyMessage:c.description})}},[]);return{error:e,friendlyError:o,clearError:n,isRetryable:s,formatError:l,wrapAsync:i}}import{useState as Ge,useEffect as Ji,useCallback as yr,useRef as Zi}from"react";import{TokenListManager as el}from"@naculus/connect-core";import{eip155ChainIdToNumber as Sr}from"@naculus/connect-appkit-core";function je(e,t){let o=Zi(null),[s,n]=Ge([]),[l,i]=Ge(t?.autoLoad!==!1),[C,u]=Ge(!1),[c,g]=Ge(null);if(!o.current){let p={};t?.sources&&(p.sources=t.sources),o.current=new el(p)}let r=yr(async()=>{let p=o.current;if(p){i(!0),g(null);try{await p.load();let f=e?Sr(e):void 0,d=p.getTokens(f!==void 0?{chainId:f}:void 0);n(d),u(!0)}catch(f){g(f instanceof Error?f:new Error(String(f)))}finally{i(!1)}}},[e]),a=yr(async()=>{let p=o.current;if(p){i(!0),g(null);try{await p.refresh();let f=e?Sr(e):void 0,d=p.getTokens(f!==void 0?{chainId:f}:void 0);n(d),u(!0)}catch(f){g(f instanceof Error?f:new Error(String(f)))}finally{i(!1)}}},[e]);return Ji(()=>{t?.autoLoad!==!1&&r()},[r,t?.autoLoad]),{tokens:s,isLoading:l,isLoaded:C,error:c,refetch:a}}import{useState as wr,useEffect as al,useRef as il}from"react";import{TokenListManager as ll}from"@naculus/connect-core";import{ETHEREUM_MAINNET_TOKENS as tl,POLYGON_TOKENS as nl,OPTIMISM_TOKENS as rl,ARBITRUM_TOKENS as ol,BASE_TOKENS as sl}from"@naculus/connect-core";function Er(){return[{name:"built-in",tokens:[...tl,...nl,...rl,...ol,...sl],enabled:!0},{name:"uniswap-default",url:"https://tokens.uniswap.org",enabled:!0,refreshInterval:1440*60*1e3}]}import{eip155ChainIdToNumber as cl}from"@naculus/connect-appkit-core";var ul=300,ze=null;function pl(){return ze||(ze=new ll({sources:Er()}),ze.load().catch(()=>{})),ze}function Qe(e,t){let[o,s]=wr({exact:[],fuzzy:[],hasMore:!1}),[n,l]=wr(!1),i=il(null),C=e.trim();return al(()=>{if(!C){s({exact:[],fuzzy:[],hasMore:!1}),l(!1);return}return i.current&&clearTimeout(i.current),l(!0),i.current=setTimeout(()=>{let u=pl(),c=t?cl(t):void 0,g=u.search(C,{chainId:c,limit:20});s(g),l(!1)},ul),()=>{i.current&&clearTimeout(i.current)}},[C,t]),{results:o,isSearching:n}}import Yt,{useCallback as dl}from"react";import{Fragment as ml,jsx as G,jsxs as j}from"react/jsx-runtime";function kr({chainId:e,onSelect:t,onClose:o,options:s}){let[n,l]=Yt.useState(""),{tokens:i,isLoading:C,error:u}=je(e),{results:c,isSearching:g}=Qe(n,n?e:void 0),r=s?.showRecommendations??!0,a=Yt.useMemo(()=>{if(n.trim()){let S=[...c.exact,...c.fuzzy].map(h=>h.token);return s?.filter?S.filter(s.filter):S}let d=i;return s?.filter?d.filter(s.filter):d},[n,c,i,s?.filter]),p=Yt.useMemo(()=>!r||n.trim()?[]:i.slice(0,6),[i,r,n]),f=dl(d=>{t(d),o()},[t,o]);return j("div",{style:{background:"hsl(var(--background))",borderRadius:"12px",padding:"16px",color:"hsl(var(--foreground))",minWidth:"320px",maxWidth:"400px",fontFamily:"system-ui, sans-serif"},children:[j("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px"},children:[G("h3",{style:{margin:0,fontSize:"16px",fontWeight:600},children:"Select Token"}),G("button",{onClick:o,style:{background:"none",border:"none",color:"hsl(var(--muted-foreground))",cursor:"pointer",fontSize:"18px",padding:"4px 8px"},children:"\u2715"})]}),G("input",{type:"text",placeholder:"Search token name or paste address",value:n,onChange:d=>l(d.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}),C&&!g&&G("div",{style:{textAlign:"center",padding:"20px",color:"hsl(var(--muted-foreground))"},children:"Loading tokens..."}),u&&j("div",{style:{textAlign:"center",padding:"12px",color:"hsl(var(--destructive))",fontSize:"13px"},children:["Error: ",u.message]}),r&&p.length>0&&!n.trim()&&j("div",{style:{marginBottom:"12px"},children:[G("div",{style:{fontSize:"11px",color:"hsl(var(--muted-foreground))",textTransform:"uppercase",letterSpacing:"0.5px",marginBottom:"8px"},children:"Popular"}),G("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap"},children:p.map(d=>j("button",{onClick:()=>f(d),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:[d.logoURI?G("img",{src:d.logoURI,alt:"",style:{width:"16px",height:"16px",borderRadius:"50%"},onError:S=>{S.target.style.display="none"}}):null,d.symbol]},`${d.chainId}:${d.address}`))})]}),n.trim()&&!C&&G("div",{style:{fontSize:"11px",color:"hsl(var(--muted-foreground))",marginBottom:"8px"},children:a.length>0?j(ml,{children:[c.exact.length," exact, ",c.fuzzy.length," fuzzy",c.hasMore?" (more available)":""]}):"No results found"}),G("div",{style:{maxHeight:"320px",overflowY:"auto",display:"flex",flexDirection:"column",gap:"2px"},children:a.map(d=>j("button",{onClick:()=>f(d),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:S=>{S.target.style.background="hsl(var(--card))"},onMouseLeave:S=>{S.target.style.background="transparent"},children:[G("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:d.logoURI?G("img",{src:d.logoURI,alt:d.symbol,style:{width:"100%",height:"100%"},onError:S=>{let h=S.target;h.style.display="none",h.parentElement.textContent=d.symbol.slice(0,2)}}):d.symbol.slice(0,2)}),j("div",{style:{flex:1,minWidth:0},children:[G("div",{style:{fontWeight:600,fontSize:"14px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d.symbol}),G("div",{style:{fontSize:"12px",color:"hsl(var(--muted-foreground))",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d.name})]}),j("div",{style:{fontSize:"11px",color:"#666",textAlign:"right",flexShrink:0},children:[j("div",{children:[d.decimals," decimals"]}),j("div",{children:["Chain ",d.chainId]})]})]},`${d.chainId}:${d.address}`))})]})}import{createComponent as D}from"@stencil/react-output-target/runtime";import M from"react";import{AppkitAccordion as fl,defineCustomElement as gl}from"@naculus/connect-appkit-wc/dist/components/appkit-accordion.js";import{AppkitAccountButton as Cl,defineCustomElement as hl}from"@naculus/connect-appkit-wc/dist/components/appkit-account-button.js";import{AppkitAlertDialog as yl,defineCustomElement as Sl}from"@naculus/connect-appkit-wc/dist/components/appkit-alert-dialog.js";import{AppkitAvatar as El,defineCustomElement as wl}from"@naculus/connect-appkit-wc/dist/components/appkit-avatar.js";import{AppkitBadge as kl,defineCustomElement as xl}from"@naculus/connect-appkit-wc/dist/components/appkit-badge.js";import{AppkitButton as vl,defineCustomElement as Al}from"@naculus/connect-appkit-wc/dist/components/appkit-button.js";import{AppkitCardContent as bl,defineCustomElement as Rl}from"@naculus/connect-appkit-wc/dist/components/appkit-card-content.js";import{AppkitCardDescription as Tl,defineCustomElement as Il}from"@naculus/connect-appkit-wc/dist/components/appkit-card-description.js";import{AppkitCardFooter as Ul,defineCustomElement as Pl}from"@naculus/connect-appkit-wc/dist/components/appkit-card-footer.js";import{AppkitCardHeader as Wl,defineCustomElement as Ol}from"@naculus/connect-appkit-wc/dist/components/appkit-card-header.js";import{AppkitCardTitle as Nl,defineCustomElement as _l}from"@naculus/connect-appkit-wc/dist/components/appkit-card-title.js";import{AppkitCard as Dl,defineCustomElement as Ml}from"@naculus/connect-appkit-wc/dist/components/appkit-card.js";import{AppkitCheckbox as Ll,defineCustomElement as Bl}from"@naculus/connect-appkit-wc/dist/components/appkit-checkbox.js";import{AppkitCollapsible as Fl,defineCustomElement as Hl}from"@naculus/connect-appkit-wc/dist/components/appkit-collapsible.js";import{AppkitConnectButton as Kl,defineCustomElement as ql}from"@naculus/connect-appkit-wc/dist/components/appkit-connect-button.js";import{AppkitDialog as Vl,defineCustomElement as $l}from"@naculus/connect-appkit-wc/dist/components/appkit-dialog.js";import{AppkitDropdownMenu as Gl,defineCustomElement as jl}from"@naculus/connect-appkit-wc/dist/components/appkit-dropdown-menu.js";import{AppkitInput as zl,defineCustomElement as Ql}from"@naculus/connect-appkit-wc/dist/components/appkit-input.js";import{AppkitPopover as Xl,defineCustomElement as Yl}from"@naculus/connect-appkit-wc/dist/components/appkit-popover.js";import{AppkitProgress as Jl,defineCustomElement as Zl}from"@naculus/connect-appkit-wc/dist/components/appkit-progress.js";import{AppkitScrollArea as ec,defineCustomElement as tc}from"@naculus/connect-appkit-wc/dist/components/appkit-scroll-area.js";import{AppkitSelect as nc,defineCustomElement as rc}from"@naculus/connect-appkit-wc/dist/components/appkit-select.js";import{AppkitSeparator as oc,defineCustomElement as sc}from"@naculus/connect-appkit-wc/dist/components/appkit-separator.js";import{AppkitSkeleton as ac,defineCustomElement as ic}from"@naculus/connect-appkit-wc/dist/components/appkit-skeleton.js";import{AppkitSwitch as lc,defineCustomElement as cc}from"@naculus/connect-appkit-wc/dist/components/appkit-switch.js";import{AppkitTabs as uc,defineCustomElement as pc}from"@naculus/connect-appkit-wc/dist/components/appkit-tabs.js";import{AppkitToggleGroup as dc,defineCustomElement as mc}from"@naculus/connect-appkit-wc/dist/components/appkit-toggle-group.js";import{AppkitTooltip as fc,defineCustomElement as gc}from"@naculus/connect-appkit-wc/dist/components/appkit-tooltip.js";var Cc=D({tagName:"appkit-accordion",elementClass:fl,react:M,events:{onAppkitToggle:"appkitToggle"},defineCustomElement:gl}),hc=D({tagName:"appkit-account-button",elementClass:Cl,react:M,events:{},defineCustomElement:hl}),yc=D({tagName:"appkit-alert-dialog",elementClass:yl,react:M,events:{onAppkitClose:"appkitClose",onAppkitOpenChange:"appkitOpenChange"},defineCustomElement:Sl}),Sc=D({tagName:"appkit-avatar",elementClass:El,react:M,events:{},defineCustomElement:wl}),Ec=D({tagName:"appkit-badge",elementClass:kl,react:M,events:{},defineCustomElement:xl}),wc=D({tagName:"appkit-button",elementClass:vl,react:M,events:{},defineCustomElement:Al}),kc=D({tagName:"appkit-card",elementClass:Dl,react:M,events:{},defineCustomElement:Ml}),xc=D({tagName:"appkit-card-content",elementClass:bl,react:M,events:{},defineCustomElement:Rl}),vc=D({tagName:"appkit-card-description",elementClass:Tl,react:M,events:{},defineCustomElement:Il}),Ac=D({tagName:"appkit-card-footer",elementClass:Ul,react:M,events:{},defineCustomElement:Pl}),bc=D({tagName:"appkit-card-header",elementClass:Wl,react:M,events:{},defineCustomElement:Ol}),Rc=D({tagName:"appkit-card-title",elementClass:Nl,react:M,events:{},defineCustomElement:_l}),Tc=D({tagName:"appkit-checkbox",elementClass:Ll,react:M,events:{onAppkitChange:"appkitChange"},defineCustomElement:Bl}),Ic=D({tagName:"appkit-collapsible",elementClass:Fl,react:M,events:{onAppkitToggle:"appkitToggle"},defineCustomElement:Hl}),Uc=D({tagName:"appkit-connect-button",elementClass:Kl,react:M,events:{onAppkitConnect:"appkitConnect",onAppkitDisconnect:"appkitDisconnect",onAppkitStartPairing:"appkitStartPairing",onAppkitRetry:"appkitRetry",onAppkitCancelPairing:"appkitCancelPairing",onAppkitMobileDeepLink:"appkitMobileDeepLink",onAppkitCopyAddress:"appkitCopyAddress"},defineCustomElement:ql}),Pc=D({tagName:"appkit-dialog",elementClass:Vl,react:M,events:{onAppkitClose:"appkitClose",onAppkitOpenChange:"appkitOpenChange"},defineCustomElement:$l}),Wc=D({tagName:"appkit-dropdown-menu",elementClass:Gl,react:M,events:{onAppkitSelect:"appkitSelect"},defineCustomElement:jl}),Oc=D({tagName:"appkit-input",elementClass:zl,react:M,events:{onAppkitChange:"appkitChange"},defineCustomElement:Ql}),Nc=D({tagName:"appkit-popover",elementClass:Xl,react:M,events:{onAppkitOpenChange:"appkitOpenChange"},defineCustomElement:Yl}),_c=D({tagName:"appkit-progress",elementClass:Jl,react:M,events:{},defineCustomElement:Zl}),Dc=D({tagName:"appkit-scroll-area",elementClass:ec,react:M,events:{},defineCustomElement:tc}),Mc=D({tagName:"appkit-select",elementClass:nc,react:M,events:{onAppkitChange:"appkitChange"},defineCustomElement:rc}),Lc=D({tagName:"appkit-separator",elementClass:oc,react:M,events:{},defineCustomElement:sc}),Bc=D({tagName:"appkit-skeleton",elementClass:ac,react:M,events:{},defineCustomElement:ic}),Fc=D({tagName:"appkit-switch",elementClass:lc,react:M,events:{onAppkitChange:"appkitChange"},defineCustomElement:cc}),Hc=D({tagName:"appkit-tabs",elementClass:uc,react:M,events:{onAppkitTabChange:"appkitTabChange"},defineCustomElement:pc}),Kc=D({tagName:"appkit-toggle-group",elementClass:dc,react:M,events:{onAppkitChange:"appkitChange"},defineCustomElement:mc}),qc=D({tagName:"appkit-tooltip",elementClass:fc,react:M,events:{},defineCustomElement:gc});export{Cc as AppkitAccordion,hc as AppkitAccountButton,yc as AppkitAlertDialog,Sc as AppkitAvatar,Ec as AppkitBadge,wc as AppkitButton,kc as AppkitCard,xc as AppkitCardContent,vc as AppkitCardDescription,Ac as AppkitCardFooter,bc as AppkitCardHeader,Rc as AppkitCardTitle,Tc as AppkitCheckbox,Ic as AppkitCollapsible,Uc as AppkitConnectButton,Pc as AppkitDialog,Wc as AppkitDropdownMenu,Oc as AppkitInput,Nc as AppkitPopover,_c as AppkitProgress,Dc as AppkitScrollArea,Mc as AppkitSelect,Lc as AppkitSeparator,Bc as AppkitSkeleton,Fc as AppkitSwitch,Hc as AppkitTabs,Kc as AppkitToggleGroup,qc as AppkitTooltip,pn as DEFAULT_EVM_CHAINS,UC as LAMPORTS_PER_SOL,PC as PassphraseCancelledError,WC as PassphraseGate,NC as SolanaRpcError,kr as TokenSelector,Mn as TxMonitorContext,Cr as WALLET_ERROR_DESCRIPTIONS,gr as WALLET_ERROR_TITLES,eo as Web3ConnectProvider,st as Web3Context,ls as buildDelegationPolicyMessage,Pr as clearClient,nt as createClient,bC as formatSol,qr as getChainById,rt as getClient,ot as getDefaultChains,RC as getLatestBlockhash,Gi as getLocale,TC as getSignatureStatus,IC as getSolanaBalance,Ae as getUserFriendlyError,Qt as isRetryableError,OC as parseSol,Zo as resetSessionKeyManager,$i as setLocale,zt as t,B as useAccount,fo as useBalance,lt as useCapabilities,V as useChain,nn as useCompareCosts,bo as useConnect,Xo as useCreateSessionKey,_o as useDelegate,me as useDelegation,is as useDelegationPolicy,ps as useDisconnect,bs as useERC20Allowance,Os as useERC20Approve,Vs as useERC20Transfer,Js as useERC20TransferSimulation,ms as useEmbeddedWallet,Ct as useExecuteCalls,sn as useExecuteRoute,sa as useLastTx,ua as useLookupAddress,wa as useNotification,va as usePassphraseGate,ba as useResolveName,Yo as useRevokeSession,cn as useRouteQuote,Wt as useSIWxLogin,ja as useSIWxSession,ft as useSendCalls,Ce as useSendTransaction,Pa as useSendUserOperation,Jo as useSendWithSession,Da as useSession,ht as useSessionKeys,ni as useSignInWithEthereum,Ee as useSignInWithX,St as useSignMessage,ai as useSimulateTransfer,mi as useSiwxAuthSession,Ci as useSmartAccount,Ft as useSolanaAccount,wi as useSolanaBalance,vi as useSolanaRoles,bi as useSolanaTransaction,Ti as useSwitchChain,Di as useTokenBalance,je as useTokenList,Qe as useTokenSearch,vt as useTransactionSimulation,Bi as useTxHistory,ra as useTxMonitor,Ki as useUserOpStatus,Qi as useValidateDestination,$ as useViemClient,Xi as useWallet,U as useWeb3,Yi as useWeb3ErrorHandler,fr as validateDestination};
|
|
1
|
+
import{formatSol as _h,getLatestBlockhash as Dh,getSignatureStatus as Mh,getSolanaBalance as Lh,LAMPORTS_PER_SOL as Bh,PassphraseCancelledError as Fh,PassphraseGate as Hh,parseSol as Kh,SolanaRpcError as qh}from"@naculus/connect-core";import{compareCostsKey as Rr}from"@naculus/connect-appkit-core";import{useCallback as tn,useEffect as nn,useRef as rn,useState as Xe}from"react";function on(e,t){let{operation:o,chains:s,options:n}=e,[l,i]=Xe([]),[g,u]=Xe(!1),[c,h]=Xe(null),r=rn(!0),a=rn(0),p=Rr(e),f=tn(async()=>{if(!s||s.length===0){i([]);return}if(!t)return;let y=++a.current;u(!0),h(null);try{let C=await t(o,s,n);r.current&&y===a.current&&i(C)}catch(C){r.current&&y===a.current&&(h(C instanceof Error?C:new Error(String(C))),i([]))}finally{r.current&&y===a.current&&u(!1)}},[p,t]);nn(()=>{f()},[f]),nn(()=>(r.current=!0,()=>{r.current=!1}),[]);let d=tn(async()=>{await f()},[f]);return{comparisons:l,loading:g,error:c,refresh:d}}import{toExecuteRouteError as Tr,validateRouteRecipient as Ir}from"@naculus/connect-appkit-core";import{useCallback as sn,useEffect as Ur,useRef as an,useState as Ye}from"react";function ln(e){let[t,o]=Ye(!1),[s,n]=Ye(null),[l,i]=Ye(null),g=an(!0),u=an(!1);Ur(()=>(g.current=!0,()=>{g.current=!1}),[]);let c=sn(async(r,a,p)=>{if(!e)return i({code:"no_executor",message:"No executeRoute function provided"}),n(null),null;let f=Ir(r,a);if(f)return i(f),n(null),null;if(u.current)return i({code:"execution_in_progress",message:"A route execution is already in progress"}),null;u.current=!0,o(!0),i(null),n(null);try{let d=await e(r,a,p);return g.current&&n(d),d}catch(d){return g.current&&i(Tr(d)),null}finally{u.current=!1,g.current&&o(!1)}},[e]),h=sn(()=>{n(null),i(null),o(!1)},[]);return{execute:c,executing:t,result:s,error:l,reset:h}}import{isQuotableInput as Pr}from"@naculus/connect-appkit-core";import{useCallback as Je,useEffect as cn,useRef as un,useState as Ze}from"react";function pn(e,t){let{fromChain:o,toChain:s,fromToken:n,toToken:l,amount:i,options:g}=e,[u,c]=Ze([]),[h,r]=Ze(!1),[a,p]=Ze(null),f=un(null),d=un(!0),y=Je(async()=>{if(!Pr({fromChain:o,toChain:s,fromToken:n,amount:i})){c([]);return}if(t){r(!0),p(null);try{let E=await t(o,s,n,i,g,l);d.current&&c(E)}catch(E){d.current&&(p(E instanceof Error?E:new Error(String(E))),c([]))}finally{d.current&&r(!1)}}},[o,s,n,l,i,g,t]);cn(()=>{if(f.current&&clearTimeout(f.current),!o||!s||!n||!i){c([]);return}return f.current=setTimeout(()=>{y()},300),()=>{f.current&&clearTimeout(f.current)}},[y,o,s,n,i]),cn(()=>(d.current=!0,()=>{d.current=!1}),[]);let C=Je(async()=>{await y()},[y]),w=Je(()=>{c([]),p(null),r(!1)},[]);return{quotes:u,loading:h,error:a,refresh:C,clear:w}}import{logger as et,WalletError as K}from"@naculus/connect-core";import{eip6963Connector as q}from"@naculus/connector-evm-injected";import{PassphraseGate as Wr}from"@naculus/connect-core";import{createWalletConnectConnector as Or}from"@naculus/connector-walletconnect";var tt=null;function nt(e){let t=null,o=Or({projectId:e.projectId,metadata:e.metadata}),s=null,n=null,l=null,i=null,g=e.passphrasePrompt&&e.enableEmbedded&&!e.embeddedConfig?.encryptionPassphrase?new Wr: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(f){i&&await i;let d=l;return d?.hasCredential()?d.derivePrfKey(f):null}}),s=r.createPocketConnector(a),t?._setEmbeddedConnector(s)}).catch(r=>{et.warn("react/client","Embedded wallet connector not available:",r),s=null})),e.enablePasskeys&&(i=import("@naculus/connector-passkeys").then(r=>{l=r.createPasskeysConnector(),t?._setPasskeysConnector(l)}).catch(r=>{et.warn("react/client","Passkeys connector not available:",r),l=null}));let u=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}),u=a,typeof window<"u"&&"startDiscovery"in a&&a.startDiscovery(),t?._setSolanaConnector(u)}).catch(r=>{et.warn("react/client","Solana connector not available:",r),u=null})),typeof window<"u"&&q.startDiscovery();let h={connector:o,get embeddedConnector(){return s},getEmbeddedConnector:async()=>(n&&await n,s),get passkeysConnector(){return l},passphraseGate:g,solanaRpcUrl:e.solanaRpcUrl??null,get solanaConnector(){return u},connect:()=>o.connect(),connectInjected:async r=>q.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,!l)throw new Error("Passkeys connector not enabled. Set enablePasskeys: true in config.");return l.connect()},startPairing:()=>o.startPairing(),completePairing:()=>o.completePairing(),cancelPairing:()=>o.cancelPairing?.(),signMessage:async(r,a)=>{if(r.id?.startsWith("eip6963-"))return q.signMessage(r,a);if(r.walletType==="passkeys"&&l)return l.signMessage(r,a);if(r.walletType==="embedded"){if(!s)throw new K("wallet_unavailable","Embedded wallet connector not available.");return s.signMessage(r,a)}if(r.walletType==="solana"){if(c&&await c,u)return u.signMessage(r,a);throw new K("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 q.signTransaction(r,a);if(r.walletType==="embedded"){if(!s)throw new K("wallet_unavailable","Embedded wallet connector not available.");return s.signTransaction(r,a)}if(r.walletType==="solana"){if(c&&await c,u)return u.signTransaction(r,a);throw new K("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 q.sendTransaction(r,a);if(r.walletType==="passkeys"&&l)return l.sendTransaction(r,a);if(r.walletType==="embedded"){if(!s)throw new K("wallet_unavailable","Embedded wallet connector not available.");return s.sendTransaction(r,a)}if(r.walletType==="solana"){if(c&&await c,u)return u.sendTransaction(r,a);throw new K("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-")?q.onAccountsChanged?.(r,a)??p:r.walletType==="embedded"?s?.onAccountsChanged?.(r,a)??p:r.walletType==="passkeys"?p:r.walletType==="solana"?u?.onAccountsChanged?.(r,a)??p:o.onAccountsChanged?.(r,a)??p},onChainChanged:(r,a)=>{let p=()=>{};return r.id?.startsWith("eip6963-")?q.onChainChanged?.(r,a)??p:r.walletType==="passkeys"||r.walletType==="embedded"?p:r.walletType==="solana"?u?.onChainChanged?.(r,a)??p:o.onChainChanged?.(r,a)??p},getCapabilities:r=>r.id?.startsWith("eip6963-")?q.getCapabilities?.(r):r.walletType==="passkeys"?l?.getCapabilities?.(r):r.walletType==="solana"?u?.getCapabilities?.(r):r.walletType==="embedded"?s?.getCapabilities?.(r):o.getCapabilities?.(r),sendCalls:async(r,a,p,f)=>{if(r.id?.startsWith("eip6963-"))return q.sendCalls(r,a,p,f);if(r.walletType==="passkeys"&&l)return l.sendCalls(r,a,p,f);if(r.walletType==="solana"){if(c&&await c,u)return u.sendCalls(r,a,p,f);throw new K("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 K("method_not_allowed","Embedded wallet does not support sendCalls");return s.sendCalls(r,a,p,f)}if(!o.sendCalls)throw new K("method_not_allowed","sendCalls not supported by this connector");return o.sendCalls(r,a,p,f)},showCallsStatus:async(r,a)=>{if(r.id?.startsWith("eip6963-"))return q.showCallsStatus(r,a);if(r.walletType==="passkeys"||r.walletType==="embedded")throw new K("method_unsupported",`${r.walletType} wallets have no UI to display a call bundle.`);if(!o.showCallsStatus)throw new K("method_unsupported","This connector cannot display call status.");return o.showCallsStatus(r,a)},getCallsStatus:async(r,a)=>{if(r.id?.startsWith("eip6963-")&&q.getCallsStatus)return q.getCallsStatus(r,a);if(r.walletType==="passkeys"&&l?.getCallsStatus)return l.getCallsStatus(r,a);if(r.walletType==="embedded")throw new K("method_not_allowed","Embedded wallet does not support getCallsStatus");if(!o.getCallsStatus)throw new K("method_not_allowed","getCallsStatus not supported by this connector");return o.getCallsStatus(r,a)},reconnect:async r=>r.walletType==="eip6963"?q.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 q.disconnect(r);if(r.walletType==="embedded"&&s)return s.disconnect();if(r.walletType==="passkeys"&&l)return l.disconnect(r);if(r.walletType==="solana"){if(c&&await c,u)return u.disconnect(r);throw new K("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),l&&r.push(l),u&&r.push(u),r},_setEmbeddedConnector:r=>{s=r},_setPasskeysConnector:r=>{l=r},_setSolanaConnector:r=>{u=r}};return t=h,tt=h,h}function rt(){return tt}function Nr(){tt=null}import{isEvmAddress as hn,parseCaip10 as so}from"@naculus/connect-core";import{useMemo as ao}from"react";import{createConnectorManager as jr,createSessionManager as zr,LocalStorageSessionStorage as Qr,logger as Z,WalletError as Xr}from"@naculus/connect-core";import{eip6963Connector as Re}from"@naculus/connector-evm-injected";import{createContext as Yr,useCallback as H,useContext as Jr,useEffect as ce,useMemo as ue,useReducer as Zr,useRef as fn}from"react";import{logger as _r}from"@naculus/connect-core";import{issueNonce as Dr,parseSiwxMessage as Mr}from"@naculus/siwx";function oe(e,t){let o=t.split(":",1)[0],n=(e.namespaces[o]?.accounts??[]).filter(l=>l.startsWith(`${o}:`)).map(l=>({namespace:o,caip10:l}))[0];if(n)return{...n,address:n.caip10.split(":").pop()??n.caip10}}function Lr(e){return e.namespaces.eip155?.chains?.[0]??e.namespaces.solana?.chains?.[0]??e.namespaces.xrpl?.chains?.[0]??"eip155:1"}async function dn(e){let{session:t,siwx:o,signMessage:s}=e;if(!o||!t)return{kind:"skipped"};try{let n=Lr(t),l=oe(t,n);if(!l)throw new Error("No account found in session");let{address:i}=l,g=await o.createMessage({address:i,chainId:n}),u=Mr(g);if(!u?.nonce)throw new Error("SIWx message must contain a nonce");await Dr(u.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 l=n instanceof Error?n:new Error("Wallet authentication failed");return _r.error("appkit/core","SIWx authentication failed:",n),{kind:"failed",error:l,fatal:o.required!==!1}}}import{initialWeb3State as eo,web3Reducer as to,withRetry as no,withTimeout as gn}from"@naculus/connect-appkit-core";import{resolveChain as Br}from"@naculus/connect-appkit-core";import{CHAINS as be,DEFAULT_RPC_URLS as Fr,eip155Reference as Hr,getRpcUrl as Kr}from"@naculus/connect-core";var qr=[{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 Vr(e){let t=be[e];if(!t||!t.explorerUrl)return null;let o=t.caip2Id;return{caip2:o,name:t.name,rpcUrl:Kr(o,Fr[o]??""),explorerUrl:t.explorerUrl,token:t.nativeCurrency.symbol}}function $r(){if(!be)return[];let e=[],t=Object.keys(be).map(Number).sort((o,s)=>o-s);for(let o of t){let s=Vr(o);s&&e.push(s)}for(let o of qr){let s=Hr(o.caip2);(s===null||!be[s])&&e.push(o)}return e}var mn=$r();function Gr(e,t){return Br(e,t)??void 0}function ot(){return[...mn]}import{jsx as oo}from"react/jsx-runtime";var st=Yr(null);function ro({children:e,config:t,autoConnect:o=!0}){let[s,n]=Zr(to,eo),l=ue(()=>t.chains??ot(),[t.chains]),i=t.connectionTimeout??3e4,g=t.maxRetries??2,u=ue(()=>new Qr(t.storageKey??"naculus_web3_session",t.encryptionKey),[t.storageKey,t.encryptionKey]),c=ue(()=>nt({projectId:t.projectId,metadata:t.metadata,enableEmbedded:t.enableEmbedded,embeddedConfig:t.embeddedConfig,enablePasskeys:t.enablePasskeys,enableSolana:t.enableSolana,solanaDefaultChain:t.solanaDefaultChain}),[t.projectId,t.metadata,t.enableEmbedded,t.embeddedConfig,t.enablePasskeys,t.enableSolana,t.solanaDefaultChain]),h=fn(null),r=fn(null),a=ue(()=>{let m=jr();for(let N of[Re,...c.getAllConnectors()])m.register(N.id,N);let S={},k={};for(let N of l){let _=N.caip2;N.rpcUrl&&(S[_]=N.rpcUrl),N.token&&(k[_]={name:N.name,symbol:N.token,decimals:18})}let P=zr(m,{autoRefreshFeeOnSwitch:t.autoRefreshFeeOnSwitch??!0,defaultRpcUrls:S,defaultCurrencies:k,encryptionKey:t.encryptionKey});return h.current=P,P},[c,l,t.autoRefreshFeeOnSwitch,t.encryptionKey]);ce(()=>{let m=_=>{let{walletSession:J}=_.bundle;n({type:"SET_SESSION",payload:J});let en=[];Object.values(J.namespaces).forEach(br=>{en.push(...br.accounts)}),n({type:"SET_ACCOUNTS",payload:en}),n({type:"SET_CHAIN",payload:_.bundle.activeChainId}),n({type:"SET_STATUS",payload:"connected"})},S=()=>{n({type:"RESET"})},k=_=>{n({type:"SET_CHAIN",payload:_.newChainId})},P=_=>m(_),N=()=>{u.clear(),n({type:"RESET"})};return a.on("sessionConnected",m),a.on("sessionDisconnected",S),a.on("chainChanged",k),a.on("sessionScopeChanged",P),a.on("sessionRevoked",N),()=>{a.off("sessionConnected",m),a.off("sessionDisconnected",S),a.off("chainChanged",k),a.off("sessionScopeChanged",P),a.off("sessionRevoked",N)}},[a,u]),ce(()=>{let m=()=>{u.clear(),n({type:"RESET"})};c.connector.onSessionExpiry(m)},[c,u]);let p=H(()=>{for(let m of[Re,...c.getAllConnectors()])a.registerConnector(m)},[c,a]),f=H(async m=>{p();let S=[Re,...c.getAllConnectors()].find(P=>P.id===m.walletType||P.kind===m.walletType);S&&!m.connectorId&&(m.connectorId=S.id);let k=m.namespaces.eip155?.chains?.[0]??m.namespaces.solana?.chains?.[0]??m.namespaces.xrpl?.chains?.[0];k&&await a.attach(m,k)},[c,a,p]),d=H(m=>{if(n({type:"SET_SESSION",payload:m}),m){let S=[];Object.values(m.namespaces).forEach(_=>{S.push(..._.accounts)}),n({type:"SET_ACCOUNTS",payload:S});let k=m.namespaces.eip155?.chains?.[0],P=m.namespaces.solana?.chains?.[0],N=m.namespaces.xrpl?.chains?.[0];n({type:"SET_CHAIN",payload:k??P??N??null})}else n({type:"SET_ACCOUNTS",payload:[]}),n({type:"SET_CHAIN",payload:null})},[]);ce(()=>{let m=s.session,S=c;return!m||!S?.onAccountsChanged?void 0:S.onAccountsChanged(m,P=>{if(P.length===0){u.clear().finally(()=>n({type:"RESET"}));return}d(m),u.save(m)})},[s.session,c,u,d]),ce(()=>{let m=s.session,S=c;if(!(!m||!S?.onChainChanged))return S.onChainChanged(m,k=>{d(m),u.save(m);let P=a.syncExternalChain;if(!P)return;let N=P.call(a,k).catch(_=>{Z.warn("react/provider","External chain sync error:",_)});r.current=N,N.finally(()=>{r.current===N&&(r.current=null)})})},[s.session,c,u,d,a]);let y=H(async m=>{if(!t.siwx||!m)return!0;n({type:"SET_STATUS",payload:"authenticating"});let S=await dn({session:m,siwx:t.siwx,signMessage:(k,P)=>c.signMessage(k,P)});return S.kind==="failed"&&S.fatal?(await u.clear(),n({type:"RESET"}),n({type:"SET_ERROR",payload:S.error}),!1):!0},[t.siwx,c,u]),C=H(async()=>{n({type:"SET_STATUS",payload:"connecting"}),n({type:"SET_ERROR",payload:null});try{let m=await gn(c.connect(),i,"Wallet connect");await u.save(m),d(m);try{await f(m)}catch(S){Z.warn("react/provider","SessionManager sync error:",S)}if(!await y(m))return;n({type:"SET_STATUS",payload:"connected"})}catch(m){let S=m instanceof Error?m.message:"Connection failed";n({type:"SET_ERROR",payload:m instanceof Error?m:new Error(S)}),n({type:"SET_STATUS",payload:"disconnected"})}},[c,u,d,i,y,f]),w=H(async()=>{n({type:"SET_STATUS",payload:"connecting"}),n({type:"SET_ERROR",payload:null});try{let m=await c.connectEmbedded();if(await u.save(m),d(m),await f(m),!await y(m))return;n({type:"SET_STATUS",payload:"connected"})}catch(m){let S=m instanceof Error?m.message:"Embedded wallet connection failed";n({type:"SET_ERROR",payload:m instanceof Error?m:new Error(S)}),n({type:"SET_STATUS",payload:"disconnected"})}},[c,u,d,y,f]),E=H(async()=>{n({type:"SET_STATUS",payload:"connecting"}),n({type:"SET_ERROR",payload:null});try{let m=await c.connectPasskeys();if(await u.save(m),d(m),await f(m),!await y(m))return;n({type:"SET_STATUS",payload:"connected"})}catch(m){let S=m instanceof Error?m.message:"Passkeys connection failed";n({type:"SET_ERROR",payload:m instanceof Error?m:new Error(S)}),n({type:"SET_STATUS",payload:"disconnected"})}},[c,u,d,y,f]),R=H(async()=>{if(!s.session){n({type:"RESET"});return}try{await c.disconnect(s.session)}catch(m){Z.error("react/provider","Disconnect error:",m)}try{let m=h.current;m&&await m.disconnect()}catch(m){Z.warn("react/provider","SessionManager disconnect error:",m)}await u.clear(),n({type:"RESET"})},[c,s.session,u]),A=H(async m=>{n({type:"SET_STATUS",payload:"connecting"}),n({type:"SET_ERROR",payload:null});try{let S=await gn(c.connectInjected(m),i,"Injected wallet connect");await u.save(S),d(S);try{await f(S)}catch(k){Z.warn("react/provider","SessionManager sync error:",k)}if(!await y(S))return;n({type:"SET_STATUS",payload:"connected"})}catch(S){let k=S instanceof Error?S.message:"Connection failed";n({type:"SET_ERROR",payload:S instanceof Error?S:new Error(k)}),n({type:"SET_STATUS",payload:"disconnected"})}},[c,u,d,i,y,f]),T=H(async()=>c.startPairing(),[c]),v=H(()=>{c.cancelPairing?.()},[c]),x=H(async()=>{let m=await c.completePairing();return await u.save(m),d(m),await f(m),await y(m)&&n({type:"SET_STATUS",payload:"connected"}),m},[c,u,d,y,f]),b=H(async m=>{let S=t.siwx;if(!S||S.required===!1)return!0;try{if(await S.hasValidSession?.())return!0}catch(k){Z.warn("react/provider","siwx.hasValidSession failed",k)}return y(m)},[t.siwx,y]),I=H(async()=>{let m=await u.load();if(!m){n({type:"SET_STATUS",payload:"disconnected"});return}n({type:"SET_STATUS",payload:"reconnecting"});try{let S=await no(()=>c.reconnect(m),{maxRetries:g,baseDelay:1e3,label:"reconnect"});d(S);try{let k=h.current;k&&(p(),await k.restoreFromPersistence())}catch(k){Z.warn("react/provider","SessionManager restore error:",k)}if(!await b(S))return;n({type:"SET_STATUS",payload:"connected"})}catch(S){Z.error("react/provider","Reconnect error:",S),await u.clear(),n({type:"SET_STATUS",payload:"disconnected"}),n({type:"SET_SESSION",payload:null})}},[c,u,d,g,p,b]),W=H(async m=>{r.current&&await r.current;let S=h.current;if(S?.getActiveBundle()){await S.switchChain(m),d(s.session);return}if(!s.session)throw new Error("No active session");try{s.session.walletType==="eip6963"||s.session.id?.startsWith("eip6963-")?await Re.switchChain(s.session,m):s.session.walletType==="embedded"&&c.embeddedConnector?await c.embeddedConnector.switchChain?.(s.session,m):s.session.walletType==="passkeys"&&c.passkeysConnector?await c.passkeysConnector.switchChain?.(s.session,m):s.session.walletType==="solana"&&c.solanaConnector?await c.solanaConnector.switchChain?.(s.session,m):await c.connector.switchChain(s.session,m),d(s.session)}catch(k){throw new Xr("chain_unsupported","Failed to switch chain",k)}},[c,s.session,d]);ce(()=>{o&&I()},[o,I]);let L=H(()=>{n({type:"SET_ERROR",payload:null})},[]),F=ue(()=>({...s,connect:C,connectEmbedded:w,connectPasskeys:E,disconnect:R,reconnect:I,switchChain:W,startPairing:T,completePairing:x,cancelPairing:v,connectInjected:A,clearError:L,isConnected:s.status==="connected",chains:l,client:c,sessionManager:a}),[s,C,w,E,R,I,W,T,x,A,L,l,c,a]);return oo(st.Provider,{value:F,children:e})}function U(){let e=Jr(st);if(!e)throw new Error("useWeb3 must be used within a Web3ConnectProvider");return e}function B(){let{accounts:e,isConnected:t}=U(),o=ao(()=>!t||e.length===0?null:e.map(n=>{let l=so(n);return l?{address:n,namespace:l.namespace,isEVM:l.namespace==="eip155"&&hn(l.address)}:{address:n,namespace:null,isEVM:hn(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}}import{chainNumber as io,resolveChain as lo,toViemChain as co}from"@naculus/connect-appkit-core";import{useState as pe,useEffect as at,useCallback as uo,useMemo as de,useRef as po}from"react";import{createPublicClient as mo,http as fo,formatEther as go}from"viem";import{getNativeTokenPriceUsd as ho}from"@naculus/connect-core";function Co(e){let{evmAccount:t,isConnected:o}=B(),{chainId:s,chains:n}=U(),[l,i]=pe(null),[g,u]=pe(!1),[c,h]=pe(null),[r,a]=pe(null),p=e?.refreshInterval,f=po(null),d=de(()=>lo(n,s),[s,n]),y=d?io(d):null,C=de(()=>d?co(d,y):null,[d,y]),w=de(()=>d?.token??null,[d]),[E,R]=pe(null);at(()=>{if(!C||!d?.rpcUrl){R(null);return}let x=mo({transport:fo(d.rpcUrl),chain:C});return R(x),()=>{}},[d]);let A=uo(async()=>{if(!t||!E){i(null);return}u(!0),h(null);try{let b=t.includes(":")?t.split(":").pop():t,[I,W]=await Promise.all([E.getBalance({address:b}),s?ho(s,d?.rpcUrl).catch(()=>null):Promise.resolve(null)]);i(I.toString()),a(W)}catch(x){h(x instanceof Error?x:new Error("Failed to fetch balance")),i(null),a(null)}finally{u(!1)}},[t,E,s,d?.rpcUrl]);at(()=>{o&&t&&A()},[o,t,A]),at(()=>(p&&p>0&&o&&t&&(f.current=setInterval(A,p)),()=>{f.current&&(clearInterval(f.current),f.current=null)}),[p,o,t,A]);let T=de(()=>{if(l===null)return null;try{return go(BigInt(l))}catch{return null}},[l]),v=de(()=>{if(r===null||T===null)return null;let x=parseFloat(T);if(isNaN(x))return null;let b=x*r;return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(b)},[r,T]);return{balance:l,formatted:T,symbol:w,usdPrice:r,usdValue:v,isLoading:g,error:c,refetch:A,chain:d}}import{atomicSupportFor as yo,normalizeCapabilities as So,selectChainCapabilities as Eo}from"@naculus/connect-appkit-core";import{useCallback as wo,useEffect as ko,useRef as xo,useState as it}from"react";function O(e){return e??rt()}function lt(){let{client:e,session:t,chainId:o}=U(),[s,n]=it(null),[l,i]=it(!1),[g,u]=it(null),c=xo(0),h=wo(async()=>{let r=++c.current,a=O(e);if(!a?.getCapabilities||!t){n(null),i(!1),u(null);return}i(!0),u(null);try{let p=await a.getCapabilities(t);if(r!==c.current)return;n(So(p))}catch(p){if(r!==c.current)return;n(null),u(p instanceof Error?p:new Error("Capability query failed"))}finally{r===c.current&&i(!1)}},[e,t]);return ko(()=>{h()},[h]),{capabilities:s,current:Eo(s,o),atomic:yo(s,o),isFetching:l,error:g,refetch:h}}import{useMemo as ct}from"react";import{chainsForNamespace as vo,describeChain as Ao,resolveChain as bo}from"@naculus/connect-appkit-core";function V(){let{chainId:e,session:t,switchChain:o,chains:s}=U(),n=ct(()=>bo(s,e),[s,e]),l=ct(()=>t?Ao(s,e):null,[s,e,t]),i=ct(()=>vo(s,e),[s,e]);return{chainId:e,currentChain:n,chainInfo:l,availableChains:i,chains:i,isEvm:e?.startsWith("eip155:")??!1,switchChain:o}}import{useCallback as Ro,useState as Cn}from"react";import{WalletError as To}from"@naculus/connect-core";function Io(){let{connect:e,status:t}=U(),[o,s]=Cn(!1),[n,l]=Cn(null);return{connect:Ro(async()=>{s(!0),l(null);try{await e()}catch(g){let u=g instanceof Error?g.message:"Connection failed";l(g instanceof To?g:new Error(u))}finally{s(!1)}},[e]),isConnecting:o||t==="connecting",error:n}}import{bareEvmAddress as No}from"@naculus/connect-appkit-core";import{delegateAccount as _o,eip155Reference as Do,REVOKE_DELEGATE as Mo,WalletError as Sn}from"@naculus/connect-core";import{useCallback as Te,useEffect as En,useRef as wn,useState as pt}from"react";import{chainNumber as Uo,toViemChain as Po}from"@naculus/connect-appkit-core";import{useMemo as ut}from"react";import{createPublicClient as Wo,http as yn,createWalletClient as Oo}from"viem";function $(){let{evmAccount:e,isConnected:t}=B(),{currentChain:o,chains:s}=V(),n=o?Uo(o):null,l=ut(()=>o?Po(o,n):null,[o,n]),i=ut(()=>l?Wo({transport:yn(l.rpcUrls.default.http[0]),chain:l}):null,[o,l]),g=ut(()=>{if(!t||!e||!l)return null;let u=e.includes(":")?e.split(":").pop():e;return Oo({transport:yn(l.rpcUrls.default.http[0]),chain:l,account:u})},[t,e,o,l]);return{publicClient:i,walletClient:g,chains:s}}function Lo(e){let{evmAccount:t}=B(),{session:o,chainId:s,client:n}=U(),{publicClient:l}=$(),[i,g]=pt(null),[u,c]=pt(!1),[h,r]=pt(null),a=wn(0),p=wn(!1);En(()=>()=>{a.current+=1},[]),En(()=>{a.current+=1,g(null),c(!1),r(null)},[o,s,t]);let f=Te(async(w,E)=>{let R=x=>(r(x),null);if(p.current)return R(new Error("A delegation is already in progress"));let A=No(t);if(!o||!A||!s)return R(new Sn("wallet_unavailable","No connected EVM account"));if(!l||l.chain?.id!==Do(s))return R(new Sn("chain_mismatch",`No RPC client for ${s}; refusing to read the nonce elsewhere.`));let T=o.walletType==="embedded"?O(n)?.embeddedConnector??{}:{},v=++a.current;p.current=!0,c(!0),r(null),g(null);try{let x=await _o({connector:T,session:o,account:A,chainId:s,delegate:w,allowlist:E,getTransactionCount:(b,I)=>l.getTransactionCount({address:b,blockTag:I})});return v!==a.current?null:(g(x),x)}catch(x){return v!==a.current?null:R(x instanceof Error?x:new Error("Failed to send delegation"))}finally{p.current=!1,v===a.current&&c(!1)}},[s,n,t,l,o]),d=Te(w=>f(w,e.allowlist),[f,e.allowlist]),y=Te(()=>f(Mo,[]),[f]),C=Te(()=>{a.current+=1,g(null),c(!1),r(null)},[]);return{delegate:d,revoke:y,result:i,isPending:u,error:h,reset:C}}import{describePayment as Bo}from"@naculus/connect-appkit-core";import{useCallback as kn,useEffect as Fo,useRef as dt,useState as mt}from"react";function Ho(e){let[t,o]=mt(0),[s,n]=mt(null),[l,i]=mt(null),g=dt(0),u=dt(0),c=dt(e);c.current=e,Fo(()=>()=>{g.current+=1,u.current+=1},[]);let h=kn(async(a,p)=>{let f=++g.current,d=u.current;o(y=>y+1),i(null);try{let y=await c.current(a,p),C=Bo(a,y);return C&&d===u.current&&n(C),y}catch(y){let C=y instanceof Error?y:new Error("Paid request failed");throw f===g.current&&i(C),C}finally{o(y=>y-1)}},[]),r=kn(()=>{g.current+=1,u.current+=1,n(null),i(null)},[]);return{payFetch:h,isPending:t>0,lastPayment:s,error:l,reset:r}}import{readDelegation as Ko,UNKNOWN_DELEGATION as ft}from"@naculus/connect-core";import{useCallback as qo,useEffect as Vo,useRef as $o,useState as gt}from"react";function me(){let{publicClient:e}=$(),{evmAccount:t}=B(),[o,s]=gt(ft),[n,l]=gt(!1),[i,g]=gt(null),u=$o(0),c=t?.includes(":")?t.split(":").pop():t,h=qo(async()=>{let r=++u.current;if(!e||!c){s(ft),l(!1),g(null);return}l(!0),g(null);try{let a=await e.getCode({address:c});if(r!==u.current)return;s(Ko(a??"0x"))}catch(a){if(r!==u.current)return;s(ft),g(a instanceof Error?a:new Error("Code read failed"))}finally{r===u.current&&l(!1)}},[e,c]);return Vo(()=>{h()},[h]),{...o,isFetching:n,error:i,refetch:h}}import{bareEvmAddress as is,createDelegationPolicyFlow as ls,isVerifiablePolicy as cs}from"@naculus/connect-appkit-core";import{useCallback as ge,useEffect as us,useMemo as ps,useState as Pe}from"react";import{recoverMessageAddress as ds}from"viem";import{planExecution as Qo,WalletError as Xo}from"@naculus/connect-core";import{useCallback as xn,useState as Ct}from"react";import{chooseExecutionStrategy as jo,getAccountCapabilities as zo,WalletError as ee}from"@naculus/connect-core";import{useCallback as Ue,useState as fe}from"react";import{WalletError as Go}from"@naculus/connect-core";function Ie(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 Go("tx_failed","Wallet did not return a valid 32-byte transaction hash")}function ht(){let{session:e,chainId:t,client:o}=U(),[s,n]=fe("idle"),[l,i]=fe(null),[g,u]=fe(null),[c,h]=fe(null),[r,a]=fe(null),p=Ue(async(C,w)=>{if(!e){n("failed");let E=new ee("wallet_unavailable","No active session");throw i(E),E}if(C.length===0){n("failed");let E=new ee("invalid_input","At least one call is required");throw i(E),E}n("awaiting_approval"),i(null),u(null);try{let E=O(o);if(!E)throw new ee("wallet_unavailable","Client not initialized");let R=w?.chainId??t??void 0,A=w?.strategy??jo(await zo(E,e,R),C.length);if(a(A),A==="atomic-batch"){let v=await E.sendCalls(e,C,R,{atomicRequired:!0,...w?.paymasterService?{paymasterService:w.paymasterService}:{}});return n("submitted"),u(v),v}let T="";for(let v=0;v<C.length;v++){let x=C[v];try{T=Ie(await E.sendTransaction(e,{transaction:{to:x.to,data:x.data,value:x.value},chainId:R}))}catch(b){throw new ee("tx_failed",`Call ${v+1} of ${C.length} failed after ${v} already landed (sent sequentially \u2014 this wallet cannot batch atomically): ${b instanceof Error?b.message:String(b)}`)}}return n("submitted"),u(T),T}catch(E){n("failed");let R=E instanceof Error?E.message:"sendCalls failed";throw i(E instanceof Error?E:new Error(R)),E}},[e,t,o]),f=Ue(async C=>{if(!e)throw new ee("wallet_unavailable","No active session");let w=C??g;if(!w)throw new ee("invalid_input","No bundle hash available");if(!C&&r==="sequential")throw new ee("invalid_input","Calls were sent sequentially, so there is no bundle to query. Track the returned transaction hash instead.");let E=O(o);if(!E)throw new ee("wallet_unavailable","Client not initialized");let R=await E.getCallsStatus(e,w);return h(R),R},[e,g,o,r]),d=Ue(async C=>{if(!e)return!1;let w=C??g;if(!w||!C&&r==="sequential")return!1;let E=O(o);if(!E?.showCallsStatus)return!1;try{return await E.showCallsStatus(e,w),!0}catch{return!1}},[e,g,o,r]),y=Ue(()=>{n("idle"),i(null),u(null),h(null),a(null)},[]);return{sendCalls:p,getCallsStatus:f,showCallsStatus:d,status:s,error:l,batchHash:g,callsStatus:c,execution:r,reset:y,isSending:s==="awaiting_approval"}}function yt(e={}){let{current:t,atomic:o}=lt(),{delegated:s,delegate:n}=me(),{sendCalls:l}=ht(),[i,g]=Ct(!1),[u,c]=Ct(null),[h,r]=Ct(null),a=e.atomicity??"preferred",p=e.sponsorship??"any",f=e.paymasterService,d=e.userOperation,y=e.userOperationSponsored??!1,C=!!(t?.raw?.paymasterService?.supported&&f),w=xn((R,A=a)=>{let T=Qo({atomicBatch:o==="supported",discovered:o!=="unknown",sponsoredTransactions:!1,...t?.maxBatchSize===void 0?{}:{maxBatchSize:t.maxBatchSize}},R,{atomicity:A,sponsorship:p}),v=p==="required"&&!y;if(T.strategy==="atomic-batch"&&!v)return{...T,reason:T.reason+(C?" 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.`:"",b=A!=="any"&&!T.atomic||p==="required";return d&&b&&!v?{strategy:"atomic-batch",atomic:!0,sponsored:y,reason:p==="required"&&!T.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"}:v?{strategy:"refuse",atomic:T.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}:T.strategy==="refuse"?{...T,reason:T.reason+x,route:null}:{...T,reason:T.reason+x,route:"sequential"}},[o,t,f,C,d,y,a,p,s,n]),E=xn(async(R,A=a)=>{g(!0),c(null);try{let T=w(R.length,A);if(T.route===null)throw new Xo("method_not_allowed",T.reason);return r(T.route),T.route==="user-operation"?await d(R):await l(R,{strategy:T.route==="wallet-batch"?"atomic-batch":"sequential",...T.route==="wallet-batch"&&C?{paymasterService:f}:{}})}catch(T){let v=T instanceof Error?T:new Error("Execution failed");throw c(v),v}finally{g(!1)}},[w,l,d,a,f,C]);return{preview:w,execute:E,isExecuting:i,error:u,lastRoute:h,reset:()=>{c(null),r(null)}}}import{getSharedSessionKeyManager as Yo,resetSharedSessionKeyManager as Jo}from"@naculus/connect-appkit-core";import{WalletError as Zo}from"@naculus/connect-core";import{useCallback as Q,useEffect as es,useRef as ts,useState as z}from"react";function se(e){return Yo(e)}function St(e){let{session:t}=U(),[o,s]=z([]),[n,l]=z(!1),[i,g]=z(null),u=ts(!0),c=Q(()=>g(null),[]),h=se(e),r=h.isStorageAvailable(),a=Q(async()=>{if(!t){s([]);return}l(!0),g(null);try{let f=await h.listSessions();u.current&&s(f)}catch(f){u.current&&g(f instanceof Error?f:new Error("Failed to load session keys"))}finally{u.current&&l(!1)}},[t,h]);es(()=>(u.current=!0,a(),()=>{u.current=!1}),[a]);let p=o.filter(f=>f.status==="active");return{sessions:o,activeSessions:p,loading:n,error:i,refresh:a,clearError:c,storageAvailable:r}}function ns(e){let{session:t}=U(),[o,s]=z(null),[n,l]=z(!1),[i,g]=z(null),u=Q(()=>g(null),[]),c=se(e);return{createSessionKey:Q(async(r,a)=>{if(!t)throw new Zo("wallet_unavailable","No active wallet session");l(!0),g(null);try{let p=a??void 0,f=await c.createSessionKey(r,p);return s(f),f}catch(p){let f=p instanceof Error?p:new Error("Failed to create session key");throw g(f),f}finally{l(!1)}},[t,c]),lastCreated:o,isCreating:n,error:i,clearError:u}}function rs(e){let[t,o]=z(!1),[s,n]=z(null),l=Q(()=>n(null),[]),i=se(e);return{revokeSession:Q(async u=>{o(!0),n(null);try{await i.revokeSession(u)}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:l}}function os(e){let[t,o]=z(!1),[s,n]=z(null),l=Q(()=>n(null),[]),i=se(e),g=Q(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]),u=Q(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:u,isBusy:t,error:s,clearError:l}}function ss(){Jo()}import{useState as vn,useCallback as as}from"react";import{WalletError as Et}from"@naculus/connect-core";function wt(){let{session:e,chainId:t,client:o}=U(),[s,n]=vn(!1),[l,i]=vn(null);return{signMessage:as(async u=>{if(!e){let h=new Et("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 Et("wallet_unavailable","No account found");throw i(h),h}n(!0),i(null);try{let h=O(o);if(!h)throw new Et("wallet_unavailable","Client not initialized");return await h.signMessage(e,{message:u,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:l}}import{buildDelegationPolicyMessage as fs}from"@naculus/connect-appkit-core";function ms(e={}){let{evmAccount:t}=B(),o=is(t),s=me(),n=yt(e.execution),{signMessage:l}=wt(),i=St(e.managerConfig),g=se(e.managerConfig),[u,c]=Pe(!1),[h,r]=Pe(null),[a,p]=Pe(()=>new Set),[f,d]=Pe(!1),y=e.origin??(typeof window<"u"?window.location.origin:"unknown"),C=!!e.managerConfig?.encryptionKey,w=e.execution?.sponsorship,{refresh:E,storageAvailable:R}=i,{preview:A}=n,{delegated:T,delegate:v}=s,x=ps(()=>ls({manager:g,origin:y,signer:()=>o,signMessage:l,verifySignature:async({message:S,signature:k,signerAddress:P})=>(await ds({message:S,signature:k})).toLowerCase()===P.toLowerCase(),previewExecution:A,sponsorship:w,adapter:e.adapter,signTypedData:e.signTypedData,chainId:()=>e.chainId??null,delegation:()=>({delegated:T,delegate:v}),encryptionKeyConfigured:C,storageAvailable:()=>R,refresh:E}),[g,y,o,l,A,w,e.adapter,e.signTypedData,e.chainId,T,v,C,R,E]);us(()=>{let S=!1,k=i.sessions.filter(cs);return k.length===0?(p(new Set),d(!1),()=>{S=!0}):(d(!0),Promise.all(k.map(async P=>[P.id,await x.verifyStoredPolicy(P)])).then(P=>{S||p(new Set(P.filter(([,N])=>N).map(([N])=>N)))}).catch(P=>{S||(p(new Set),r(P instanceof Error?P:new Error("Policy verification failed")))}).finally(()=>{S||d(!1)}),()=>{S=!0})},[i.sessions,x]);let b=ge(()=>{r(null),i.clearError()},[i]),I=ge(async(S,k)=>{c(!0),r(null);try{return await S()}catch(P){let N=P instanceof Error?P:new Error(k);throw r(N),N}finally{c(!1)}},[]),W=ge(S=>I(()=>x.createPolicy(S),"Policy creation failed"),[x,I]),L=ge(S=>I(()=>x.revokePolicy(S),"Policy revocation failed"),[x,I]),F=ge((S,k)=>I(()=>x.executePolicy(S,k),"Policy execution failed"),[x,I]),m=i.activeSessions.filter(S=>a.has(S.id));return{policies:i.sessions,activePolicies:m,storageAvailable:i.storageAvailable,loading:i.loading||f,isBusy:u,error:h??i.error,delegation:s,createPolicy:W,revokePolicy:L,previewPolicyExecution:x.previewPolicyExecution,signPolicyDigest:x.signPolicyDigest,executePolicy:F,refresh:i.refresh,clearError:b}}import{useCallback as gs,useRef as hs,useState as An}from"react";function Cs(){let{disconnect:e,status:t}=U(),[o,s]=An(!1),[n,l]=An(null),i=hs(!0);return{disconnect:gs(async()=>{if(t!=="disconnected"){s(!0),l(null);try{await e()}catch(u){if(!i.current)return;l(u instanceof Error?u:new Error("Disconnect failed"))}finally{i.current&&s(!1)}}},[e,t]),isDisconnecting:o,error:n,cleanup:()=>{i.current=!1}}}import{WalletError as kt}from"@naculus/connect-core";import{useCallback as X,useEffect as ys,useRef as We,useState as Oe}from"react";function te(e){let t=e.activeNamespace??"eip155",o=Array.isArray(e.accounts)?e.accounts.map(({namespace:s,address:n,derivationPath:l})=>({namespace:s,address:n,...l?{derivationPath:l}:{}})):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 Ss(){let{connectEmbedded:e,client:t}=U(),[o,s]=Oe(null),n=We(null),l=We(4),i=We(!1),g=We(null),[u,c]=Oe(!1),[h,r]=Oe(!1),[a,p]=Oe(null),f=()=>p(null),d=X(()=>{let m=n.current;return n.current=null,m},[]),y=X(()=>{let m=O(t);if(!m?.embeddedConnector)throw new kt("wallet_unavailable","Embedded wallet not enabled.");return m.embeddedConnector},[t]),C=X(()=>{try{return y().getWallet()?.privateKey??null}catch{return null}},[y]),w=X(async()=>{let m=O(t);if(!m)throw new kt("wallet_unavailable","Embedded wallet not enabled.");let S=m.getEmbeddedConnector?await m.getEmbeddedConnector():m.embeddedConnector;if(!S)throw new kt("wallet_unavailable","Embedded wallet not enabled.");return S},[t]),E=X(()=>{try{return O(t)?.passphraseGate??null}catch{return null}},[t]),R=X(m=>{m?.code==="decryption_failed"&&E()?.forget("That passphrase did not open the wallet.")},[E]),A=X(async()=>{i.current=!1,p(null);try{let m=await w();if(!await m.load())return!1;let k=m.getWallet();return k?(n.current=null,c(!1),s(te(k)),!0):!1}catch(m){return i.current=!0,R(m),p(m instanceof Error?m:new Error("Failed to restore embedded wallet")),!1}},[R,w]);ys(()=>{let m=!1,S=null;return A().then(k=>{m||k||i.current||(S=setTimeout(()=>{m||A()},100))}),()=>{m=!0,S&&clearTimeout(S)}},[A]);let T=async()=>{r(!0),p(null);try{let m=await w(),S=await m.load(),k=m.getWallet();S&&k&&(s(te(k)),n.current=k.mnemonic||null,c(!k.mnemonic)),await e();let P=m.getWallet();P&&(s(te(P)),P.mnemonic&&!S&&(n.current=P.mnemonic,c(!0)))}catch(m){R(m),p(m instanceof Error?m:new Error("Embedded wallet connection failed"))}finally{r(!1)}},v=async()=>{r(!0),p(null);try{let m=await w();E()?.expect("create");let S=await m.generateWallet();return s(te(S)),n.current=S.mnemonic,c(!0),S}catch(m){return p(m instanceof Error?m:new Error("Failed to generate wallet")),null}finally{r(!1)}},x=async m=>{r(!0),p(null);try{let S=await w();E()?.expect("create");let k=await S.importFromMnemonic(m);return s(te(k)),n.current=null,c(!1),k}catch(S){return p(S instanceof Error?S:new Error("Failed to import wallet")),null}finally{r(!1)}},b=async m=>{r(!0),p(null);try{let S=await w();E()?.expect("create");let k=await S.importFromPrivateKey(m);return s(te(k)),n.current=null,c(!1),k}catch(S){return p(S instanceof Error?S:new Error("Failed to import wallet")),null}finally{r(!1)}},I=async()=>{r(!0),p(null);try{await(await w()).wipe(),s(null),n.current=null,c(!1)}catch(m){p(m instanceof Error?m:new Error("Failed to wipe wallet"))}finally{r(!1)}},W=X(m=>{let S=y();S.setActiveNamespace(m);let k=S.getWallet();s(k?te(k):null)},[y]),L=X(async()=>{let m=await w(),S=await m.backfillAccounts();if(S.length>0){let k=m.getWallet();s(k?te(k):null)}return S.map(({namespace:k,address:P,derivationPath:N})=>({namespace:k,address:P,...N?{derivationPath:N}:{}}))},[w]),F=()=>{n.current=null,c(!1)};return{connectEmbedded:T,restoreWallet:A,generateWallet:v,importFromMnemonic:x,importFromPrivateKey:b,wipe:I,wallet:o,hasWallet:o!==null,address:o?.address??null,accounts:o?.accounts??[],activeNamespace:o?.activeNamespace??null,setActiveNamespace:W,backfillAccounts:L,seedPhrase:n.current,getSeedPhrase:d,getPrivateKey:C,backupPending:u,confirmBackup:F,isBusy:h,error:a,clearError:f,storageSecurityLevel:(()=>{try{let m=y(),S=m.getStorageSecurityLevel?.()??4;return m.getWallet()?(l.current=S,S):o?l.current:S}catch{return o?l.current:4}})(),securityReport:(()=>{let m=null;try{m=y().getStorageSecurityReport?.()??null}catch{m=null}if(!m)return g.current=null,null;let S=JSON.stringify(m);return g.current?.json===S?g.current.value:(g.current={json:S,value:m},m)})()}}import{chainNumber as bs}from"@naculus/connect-appkit-core";import{useState as Rs,useCallback as Ts,useEffect as Tn,useRef as In,useMemo as Is}from"react";import{WalletError as Es}from"@naculus/connect-core";import{useCallback as bn,useEffect as ws,useLayoutEffect as ks,useMemo as xs,useRef as Rn}from"react";import{tokenChainMismatch as vs}from"@naculus/connect-appkit-core";function As(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 ae(e){let{token:t,chainId:o}=e,s=t.address.toLowerCase(),n=As(e),l=xs(()=>({key:n}),[n]),i=Rn(n),g=Rn(!0);ks(()=>{i.current=n},[n]),ws(()=>(g.current=!0,()=>{g.current=!1}),[]);let u=bn(()=>g.current&&i.current===n,[n]),c=bn(()=>{if(!u())throw new Es("session_inactive","Wallet or token context changed. Retry the operation with the current account and chain.");let h=vs({address:s,chainId:t.chainId},o);if(h)throw h},[u,s,t.chainId,o]);return{identity:l,isCurrent:u,assertCurrent:c}}import{ERC20_MIN_ABI as Us,formatUnits as Ps}from"@naculus/connect-core";function Ws(e){let{publicClient:t}=$(),{currentChain:o}=V(),{identity:s,isCurrent:n,assertCurrent:l}=ae({token:e.token,chainId:o?bs(o)??void 0:void 0,owner:e.owner,spender:e.spender,publicClient:t}),[i,g]=Rs(null),u=i?.identity===s?i.raw:null,c=i?.identity===s&&i.fetching,h=i?.identity===s?i.error:null,r=In(null),a=In(0),p=Ts(async()=>{if(!n())return;let d=++a.current,y=()=>n()&&d===a.current;if(g({identity:s,raw:null,fetching:!!t,error:null}),!!t)try{l();let C=await t.readContract({address:e.token.address,abi:Us,functionName:"allowance",args:[e.owner,e.spender]});if(!y())return;g({identity:s,raw:C,fetching:!1,error:null})}catch(C){if(!y())return;g({identity:s,raw:null,fetching:!1,error:C instanceof Error?C:new Error("Failed to fetch allowance")})}},[t,e.token.address,e.token.chainId,e.owner,e.spender,s,n,l]);return Tn(()=>{p().catch(d=>console.warn("useERC20Allowance: initial fetch failed:",d))},[p]),Tn(()=>(e.refreshInterval&&e.refreshInterval>0&&(r.current=setInterval(p,e.refreshInterval)),()=>{r.current&&(clearInterval(r.current),r.current=null)}),[e.refreshInterval,p]),{allowance:Is(()=>{if(u===null)return null;let d=e.token.decimals;return d===void 0?null:Ps(u,d)},[u,e.token.decimals]),allowanceRaw:u,isFetching:c,error:h,refetch:p}}import{chainNumber as Os,createDecimalsCache as Ns,encodeErc20Approve as _s,readDecimals as vt,writeDecimals as Wn}from"@naculus/connect-appkit-core";import{ERC20_MIN_ABI as Ne,formatUnits as Ds,parseUnits as On,WalletError as _e}from"@naculus/connect-core";import{useCallback as Ce,useRef as Nn,useState as _n}from"react";import{WalletError as xt}from"@naculus/connect-core";import{useCallback as Un,useState as Pn}from"react";function he(){let{session:e,chainId:t,client:o}=U(),[s,n]=Pn("idle"),[l,i]=Pn(null),g=Un(async c=>{if(!e){n("failed");let r=new xt("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 xt("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(o);if(!a)throw new xt("wallet_unavailable","Client not initialized");let p=await a.sendTransaction(e,{transaction:r,chainId:t??void 0}),f=Ie(p);return n("submitted"),f}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]),u=Un(()=>{n("idle"),i(null)},[]);return{sendTransaction:g,status:s,error:l,reset:u,isSending:s==="awaiting_approval"}}function Ms(e){return e.includes(":")?e.split(":").pop():e}var Ls=2n**256n-1n;function Bs(e){let{publicClient:t,walletClient:o}=$(),{evmAccount:s,isConnected:n}=B(),{currentChain:l}=V(),{session:i,client:g}=U(),{sendTransaction:u,isSending:c,error:h,reset:r}=he(),[a,p]=_n(null),{identity:f,isCurrent:d,assertCurrent:y}=ae({token:e.token,chainId:l?Os(l)??void 0:void 0,owner:s,spender:e.spender,connected:n,publicClient:t,walletClient:o,session:i,client:g}),[C,w]=_n(null),E=C?.identity===f?C.raw:null,R=C?.identity===f&&C.fetching,A=Nn(Ns(e.token,e.token.decimals)),T=Nn(0),v=a??h,x=s?Ms(s):null,b=Ce(async()=>{if(!d())return null;let S=++T.current,k=()=>d()&&S===T.current;if(w({identity:f,raw:null,fetching:!!t&&!!x&&n}),p(null),!t||!x||!n)return null;try{y();let P=await t.readContract({address:e.token.address,abi:Ne,functionName:"allowance",args:[x,e.spender]});return k()?(w({identity:f,raw:P,fetching:!1}),P):null}catch(P){return k()&&(w({identity:f,raw:null,fetching:!1}),p(P instanceof Error?P:new Error("Failed to fetch allowance"))),null}},[t,x,e.token.address,e.token.chainId,e.spender,f,d,y,n]),I=(()=>{if(E===null)return null;let S=vt(A.current,e.token,e.token.decimals);return S===void 0?null:Ds(E,S)})(),W=Ce(async S=>{if(p(null),r(),!n||!s){let k=new _e("wallet_unavailable","No connected account");throw p(k),k}if(!t){let k=new _e("wallet_unavailable","No public client");throw p(k),k}try{y();let k=_s(e.spender,S),P=O(g);if(i&&P){let _=await u({to:e.token.address,data:k,value:"0"});return b(),_}if(o){let{request:_}=await t.simulateContract({address:e.token.address,abi:Ne,functionName:"approve",args:[e.spender,S],account:x});y();let J=await o.writeContract(_);return b(),J}let N=await u({to:e.token.address,data:k,value:"0"});return b(),N}catch(k){let P=k instanceof Error?k:new Error("Approve failed");throw d()&&p(P),P}},[e,t,o,s,n,i,g,x,u,r,b,y,d]),L=Ce(async S=>{try{if(y(),!t)throw new _e("wallet_unavailable","No public client");let k=vt(A.current,e.token,e.token.decimals);k===void 0&&(k=await t.readContract({address:e.token.address,abi:Ne,functionName:"decimals"}),y(),Wn(A.current,e.token,k));let P=On(S,k);return await W(P)}catch(k){throw d()&&p(k instanceof Error?k:new Error("Approve failed")),k}},[e.token,t,W,y,d]),F=Ce(async()=>W(Ls),[W]),m=Ce(async S=>{if(!d()||!n||!x||!t)return!1;try{y()}catch(_){return p(_ instanceof Error?_:new Error("Cannot check allowance")),!1}let k=E??await b();if(k===null)return!1;let P=vt(A.current,e.token,e.token.decimals);if(P===void 0){if(!t)throw new _e("wallet_unavailable","Cannot check allowance: no public client to read token decimals.");if(P=await t.readContract({address:e.token.address,abi:Ne,functionName:"decimals"}),!d())return!1;Wn(A.current,e.token,P)}let N=On(S,P);return d()&&k>=N},[E,b,e.token.address,e.token.chainId,e.token.decimals,t,d,y,n,x]);return{approve:L,approveMax:F,allowance:I,allowanceRaw:E,hasAllowance:m,isApproving:c,isFetchingAllowance:R,error:v,refetchAllowance:b}}import{chainNumber as Fs,createDecimalsCache as Hs,encodeErc20Transfer as Ks,readDecimals as qs,writeDecimals as Vs}from"@naculus/connect-appkit-core";import{ERC20_MIN_ABI as Dn,parseUnits as $s,WalletError as Mn}from"@naculus/connect-core";import{useCallback as Gs,useRef as js,useState as zs}from"react";function Qs(e){return e.includes(":")?e.split(":").pop():e}function Xs(e){let{publicClient:t,walletClient:o}=$(),{evmAccount:s,isConnected:n}=B(),{currentChain:l}=V(),{session:i,client:g}=U(),{sendTransaction:u,isSending:c,error:h,reset:r}=he(),[a,p]=zs(null),{isCurrent:f,assertCurrent:d}=ae({token:e.token,chainId:l?Fs(l)??void 0:void 0,owner:s,connected:n,publicClient:t,walletClient:o,session:i,client:g}),y=js(Hs(e.token,e.token.decimals)),C=a??h;return{sendTransfer:Gs(async(E,R)=>{if(p(null),r(),!n||!s){let A=new Mn("wallet_unavailable","No connected account");throw p(A),A}if(!t){let A=new Mn("wallet_unavailable","No public client available");throw p(A),A}try{d();let A=Qs(s),T=qs(y.current,e.token,e.token.decimals);T===void 0&&(T=await t.readContract({address:e.token.address,abi:Dn,functionName:"decimals"}),d(),Vs(y.current,e.token,T));let v=$s(R,T),x=Ks(E,v),b=O(g);if(i&&b)return await u({to:e.token.address,data:x,value:"0"});if(o){let{request:W}=await t.simulateContract({address:e.token.address,abi:Dn,functionName:"transfer",args:[E,v],account:A});return d(),await o.writeContract(W)}return await u({to:e.token.address,data:x,value:"0"})}catch(A){let T=A instanceof Error?A:new Error("Transfer failed");throw f()&&p(T),T}},[e.token,t,o,s,n,i,g,u,r,d,f]),isSending:c,error:C}}import{chainNumber as ea,encodeErc20Transfer as ta}from"@naculus/connect-appkit-core";import{parseUnits as na}from"@naculus/connect-core";import{useMemo as ra}from"react";import{simulateTransactionPreview as Ys}from"@naculus/connect-appkit-core";import{useCallback as Ln,useEffect as Js,useRef as Zs,useState as At}from"react";function bt(e,t){U();let{evmAccount:o}=B(),{currentChain:s}=V(),{publicClient:n}=$(),[l,i]=At(void 0),[g,u]=At(!1),[c,h]=At(null),r=Zs(void 0),a=Ln(async()=>{e&&(u(!0),h(null));try{let f=await Ys(e,{chainId:t,currentChain:s,publicClient:n,evmAccount:o});return i(f),f}catch(f){let d=f instanceof Error?f:new Error("Simulation failed");throw h(d),d}finally{e&&u(!1)}},[e,t,s,n,o]);Js(()=>{if(e)return r.current&&clearTimeout(r.current),r.current=setTimeout(()=>{a().catch(()=>{})},300),()=>{r.current&&clearTimeout(r.current)}},[e,a]);let p=Ln(()=>{i(void 0),h(null),u(!1)},[]);return{result:l,isSimulating:g,error:c,simulate:a,reset:p}}function oa(e){let{evmAccount:t,isConnected:o}=B(),{currentChain:s}=V(),n=e.token.chainId??(s?ea(s)??void 0:void 0),l=ra(()=>{if(!(!o||!t))try{let g=e.token.decimals;if(g===void 0)return;let u=na(e.amount,g),c=ta(e.to,u);return{to:e.token.address,data:c,value:"0"}}catch{return}},[e.token.address,e.token.decimals,e.to,e.amount,t,o]),i=bt(l,n);return{result:l?i.result:void 0,isSimulating:!!l&&i.isSimulating,error:l?i.error:null,reSimulate:i.simulate,reset:i.reset}}import{useState as Rt,useCallback as ua,useRef as Tt}from"react";import{useState as De,useEffect as sa,useCallback as Bn,useRef as aa}from"react";import{createContext as ia,useContext as la}from"react";var Fn=ia(null);function ye(){return la(Fn)}function ca(e,t,o){let s=ye(),n=o??s,[l,i]=De(null),[g,u]=De(!1),[c,h]=De(!1),[r,a]=De(null),p=aa(void 0),f=Bn(async()=>{if(!(!n||!e)){u(!0),a(null);try{await n.refreshTx(e,t);let C=n.getTxStatus(e,t);C&&i(C)}catch(C){a(C instanceof Error?C:new Error(String(C)))}finally{u(!1)}}},[n,e,t]),d=Bn(()=>{!n||!e||(n.stopWatching(e,t),h(!1))},[n,e,t]);sa(()=>{if(!n||!e||!t){i(null),h(!1);return}p.current&&p.current!==e&&n.stopWatching(p.current),p.current=e;let C=!1;h(!0),u(!0),a(null);let w=n.getTxStatus(e,t);w&&(i(w),u(!1)),n.watchTx(e,t,{}).then(R=>{C||(i(R),u(!1))}).catch(R=>{C||(a(R instanceof Error?R:new Error(String(R))),u(!1))});let E=R=>{C||i({...R})};return n.on("statusChange",E),()=>{C=!0,h(!1),n.off("statusChange",E)}},[n,e,t]);let y=l?.status??"idle";return{entry:l,status:y,isLoading:g,isWatching:c,error:r,refresh:f,stopWatching:d}}function pa(e){let t=ye(),o=e??t,[s,n]=Rt(null),[l,i]=Rt(null),[g,u]=Rt(null),c=Tt(null),h=Tt(null),r=Tt(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=>{u(p),(!c.current||p.createdAt>=c.current.createdAt)&&(n(p),c.current=p)},o.on("failed",r.current)));let a=ua(()=>{n(null),i(null),u(null),c.current=null},[]);return{lastTx:s,lastConfirmedTx:l,lastFailedTx:g,clear:a}}import{useCallback as ga}from"react";import{useCallback as da,useEffect as Hn,useMemo as ma,useRef as Kn,useState as It}from"react";import{getResolver as fa}from"@naculus/connect-appkit-core";function Me({input:e,skip:t=!1,resolverConfig:o,scope:s,query:n}){let[l,i]=It(null),[g,u]=It(!1),[c,h]=It(null),r=Kn(0),a=Kn(!0);Hn(()=>(a.current=!0,()=>{a.current=!1}),[]);let p=ma(()=>fa(o),[o]),f=da(()=>{let d=e.trim();if(!d||t){r.current+=1,i(null),u(!1),h(null);return}let y=++r.current;u(!0),h(null),n(p,d,s).then(C=>{!a.current||y!==r.current||(i(C),u(!1))}).catch(C=>{!a.current||y!==r.current||(h(C instanceof Error?C:new Error(String(C))),i(null),u(!1))})},[e,t,s,p,n]);return Hn(()=>{f()},[f]),{data:l,isLoading:g,error:c,refetch:f}}function ha(e,t){let o=ga((s,n,l)=>s.lookupAddress(n,l),[]);return Me({input:e,skip:t?.skip,resolverConfig:t?.resolverConfig,scope:t?.chainId,query:o})}import{useState as qn,useCallback as Y,useMemo as Ca,useEffect as Vn,useRef as ya}from"react";import{addInAppNotification as Sa,channelsUpdate as Ea,clearOneInAppNotification as wa,createNotificationSettingsStorage as $n,DEFAULT_NOTIFICATION_SETTINGS as ka,loadNotificationSettings as xa,mutedChainSettings as Gn,saveNotificationSettings as va,updateNotificationSettings as Aa}from"@naculus/connect-appkit-core";import{InAppChannel as ba}from"@naculus/connect-core";function Ra(e){let t=ya(null);t.current||(t.current=e?.channel??new ba);let o=t.current,[s,n]=qn(()=>o.getHistory()),[l,i]=qn(()=>ka);Vn(()=>{let C=e?.storage??$n();xa(C).then(w=>{w&&i(w)})},[]),Vn(()=>(o.onNotification=C=>{n(w=>[...w,C])},o.restore().then(()=>{n(o.getHistory())}),()=>{o.onNotification=void 0}),[]);let g=Ca(()=>s.filter(C=>!C.read).length,[s]),u=Y(()=>{o.clear(),n([])},[o]),c=Y(C=>{wa(o,C).then(()=>{n(o.getHistory())})},[o]),h=Y(C=>{o.markAsRead(C),n(w=>w.map(E=>E.id===C?{...E,read:!0}:E))},[o]),r=Y(()=>{o.markAllAsRead(),n(C=>C.map(w=>({...w,read:!0})))},[o]),a=Y(C=>{Sa(o,C)},[o]),p=Y(C=>{i(w=>{let E=Aa(w,C),R=e?.storage??$n();return va(R,E),E})},[e?.storage]),f=Y(C=>{p(Ea(C))},[p]),d=Y(C=>{p(Gn(l,C,!0))},[l.mutedChains,p]),y=Y(C=>{p(Gn(l,C,!1))},[l.mutedChains,p]);return{notifications:s,unreadCount:g,addNotification:a,clear:u,clearOne:c,markAsRead:h,markAllAsRead:r,settings:l,updateSettings:p,setChannels:f,muteChain:d,unmuteChain:y}}import{useCallback as Ut,useSyncExternalStore as Ta}from"react";var jn=()=>null,Ia=()=>()=>{};function Ua(){let{client:e}=U(),t=O(e)?.passphraseGate??null,o=Ta(t?.subscribe??Ia,t?.getSnapshot??jn,jn),s=Ut(i=>t?.submit(i),[t]),n=Ut(()=>t?.cancel(),[t]),l=Ut(i=>t?.forget(i),[t]);return{request:o,submit:s,cancel:n,forget:l,isUnlocked:t?.isUnlocked??!1,gate:t}}import{useCallback as Pa}from"react";function Wa(e,t){let o=Pa((s,n)=>s.resolveName(n),[]);return Me({input:e,skip:t?.skip,resolverConfig:t?.resolverConfig,query:o})}import{assertHexSignature as Pt,bareEvmAddress as Oa,buildSmartAccountConfig as Na,resolveUserOpChain as _a}from"@naculus/connect-appkit-core";import{WalletError as ie}from"@naculus/connect-core";import{useCallback as zn,useEffect as Qn,useRef as Xn,useState as Se}from"react";async function Da(e,t,o,s,n){let l=O(t);if(!l)throw new ie("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"),u=g.getDiscoveredWallets().find(h=>h.id===e.walletId),c=u?await u.provider.request({method:"personal_sign",params:i}):await g.request({method:"personal_sign",params:i});return Pt(c)}if(e.walletType==="walletconnect")return Pt(await l.connector.request({method:"personal_sign",params:i}));if(e.walletType==="embedded"){let g=l.embeddedConnector;if(!g?.signHash)throw new ie("method_unsupported","This embedded wallet build cannot sign a raw digest. Upgrade @naculus/connector-embedded or pass an explicit signer.");return Pt(await g.signHash(e,o))}throw e.walletType==="passkeys"?new ie("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 ie("method_unsupported",`Raw UserOperation signing is not available for ${e.walletType} on ${n}. Pass a signer that signs the raw 32-byte hash.`)}function Ma(e){let{evmAccount:t}=B(),{session:o,chainId:s,client:n}=U(),[l,i]=Se(null),[g,u]=Se(null),[c,h]=Se(!1),[r,a]=Se(!1),[p,f]=Se(null),d=Xn(0),y=Xn(!1);Qn(()=>()=>{d.current+=1,y.current=!1},[]),Qn(()=>{d.current+=1,y.current=!1,i(null),u(null),h(!1),a(!1),f(null)},[n,s,t,e?.accountType,e?.bundlerUrl,e?.chainId,e?.entryPoint,e?.owner,e?.rpcUrl,e?.salt,e?.signerMode,o]);let C=zn(async(E,R)=>{let A=b=>(f(b),null);if(!e?.rpcUrl)return A(new Error("RPC URL not configured"));if(!e.bundlerUrl)return A(new Error("Bundler URL not configured"));if(!E.length)return A(new Error("At least one call is required"));if(y.current)return A(new Error("A UserOperation is already in progress"));let T=Oa(e.owner??t);if(!T)return A(new ie("wallet_unavailable","No EVM account found"));let v;try{v=_a(e.chainId,s)}catch(b){return A(b)}if(!e.signer&&!o)return A(new ie("wallet_unavailable","No active session"));let x=++d.current;y.current=!0,h(!0),a(!0),f(null),i(null),u(null);try{let{SmartAccountManager:b}=await import("@naculus/connect-core"),I=e.signer??(m=>Da(o,n,m,T,v)),W=new b({rpcUrl:e.rpcUrl,bundlerClient:{url:e.bundlerUrl},chainId:v,signer:I,signerMode:e.signer?e.signerMode??"eip191":"raw"}),L=Na(T,v,e),F=await W.sendUserOperation(L,E,R);return x!==d.current?null:(a(!1),i(F.userOpHash),W.getUserOperationReceipt(F.userOpHash).then(m=>{x===d.current&&u(m)}).catch(()=>{}),F)}catch(b){if(x!==d.current)return null;let I=b instanceof Error?b:new Error("Failed to send UserOperation");return f(I),null}finally{y.current=!1,x===d.current&&(h(!1),a(!1))}},[n,s,t,e,o]),w=zn(()=>{d.current+=1,i(null),u(null),h(!1),a(!1),f(null)},[]);return{sendUserOp:C,userOpHash:l,receipt:g,isPending:c,isEstimating:r,error:p,reset:w}}import{useSyncExternalStore as La,useCallback as Yn}from"react";function Ba(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 Wt=Object.freeze({session:null,chainSessions:[],activeChainId:null,isConnected:!1,connectorId:null}),Ot=new WeakMap;function Fa(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 Ha(e){if(!e)return Wt;let t=e.getActiveBundle(),o=Ot.get(e);if(!t)return o&&o.session===null?o:(Ot.set(e,Wt),Wt);let s=Array.from(t.chainSessions.values());if(o&&o.session===t.walletSession&&o.activeChainId===t.activeChainId&&Fa(o.chainSessions,s))return o;let n={session:t.walletSession,chainSessions:s,activeChainId:t.activeChainId,isConnected:!0,connectorId:t.walletSession.walletType};return Ot.set(e,n),n}function Ka(e){let t=U(),o=e??t.sessionManager??null,s=Yn(l=>Ba(o,l),[o]),n=Yn(()=>Ha(o),[o]);return La(s,n)}import{defaultSiwxDomain as qa,defaultSiwxUri as Va}from"@naculus/connect-appkit-core";import{WalletError as Le}from"@naculus/connect-core";import{createSiwxMessage as $a,generateNonce as Ga,getBlockchainName as ja,issueNonce as za,nowISO as Qa}from"@naculus/siwx";import{useCallback as Jn,useState as Zn}from"react";var Xa=86400;function Nt(){let{session:e,chainId:t,client:o}=U(),[s,n]=Zn(!1),[l,i]=Zn(null),g=Jn(()=>i(null),[]);return{signIn:Jn(async c=>{if(!e)throw new Le("wallet_unavailable","No active session");let h=c?.chainId??t;if(!h)throw new Le("invalid_chain","No chain to sign for. Connect a wallet or pass options.chainId.");let r=oe(e,h);if(!r)throw new Le("wallet_unavailable","No account found");let a=O(o);if(!a)throw new Le("wallet_unavailable","Client not initialized");let{address:p}=r,f=typeof window>"u"?void 0:window.location,d=c?.domain??qa(f),y=c?.uri??Va(f);n(!0),i(null);try{let C=Ga();await za(C);let w=Qa(),E=c?.expirySeconds??Xa,R=new Date(Date.now()+E*1e3).toISOString(),A=$a({domain:d,address:p,uri:y,version:1,chainId:h,nonce:C,issuedAt:w,expirationTime:R,statement:c?.statement,resources:c?.resources,requestId:c?.requestId}),T=await a.signMessage(e,{message:A,address:p,chainId:h??void 0}),v={message:{raw:A,domain:d,address:p,statement:c?.statement??null,uri:y,version:1,chainId:h,nonce:C,issuedAt:w,blockchain:ja(h),expirationTime:R,notBefore:null,resources:c?.resources??[],requestId:c?.requestId??null},signature:T};return n(!1),v}catch(C){let w=C instanceof Error?C:new Error("SIWx sign-in failed");throw i(w),n(!1),w}},[e,t,o]),isSigningIn:s,error:l,clearError:g}}import{siwxResultToSession as er}from"@naculus/connect-appkit-core";import{logger as _t}from"@naculus/connect-core";import{checkSessionExpired as tr,createLocalStorageSiwxSessionStorage as Ya}from"@naculus/siwx";import{useCallback as Be,useEffect as nr,useRef as Ja,useState as Fe}from"react";function Za(e){let{storagePrefix:t="naculus_",autoRestore:o=!0,defaultExpirySeconds:s=86400}=e??{},[n,l]=Fe(null),[i,g]=Fe(o),[u,c]=Fe(!1),[h,r]=Fe(null),{session:a,chainId:p}=U(),f=Nt(),d=Ja(Ya(`${t}siwx_session`)),y=Be(()=>r(null),[]);nr(()=>{if(!o){g(!1);return}let v=!1;return(async()=>{try{let b=await d.current.get();if(v)return;b?(_t.info("react/useSIWxSession","Restored persisted SIWx session"),l(b),r(null)):l(null)}catch(x){_t.warn("react/useSIWxSession","Failed to restore SIWx session:",x),l(null)}finally{v||g(!1)}})(),()=>{v=!0}},[o]),nr(()=>{if(!n?.expiresAt)return;let v=new Date(n.expiresAt).getTime()-Date.now();if(v<=0){l(null);return}let x=setTimeout(()=>{l(b=>b&&b.id===n.id?null:b)},v);return()=>clearTimeout(x)},[n?.id,n?.expiresAt]);let C=Be(async v=>{c(!0),r(null);try{let x={expirySeconds:s,chainId:p??void 0,...v},b=await f.signIn(x),I=er(b);return await d.current.set(I),l(I),c(!1),I}catch(x){let b=x instanceof Error?x:new Error("SIWx sign-in failed");throw r(b),c(!1),b}},[f,p,s]),w=Be(async()=>{try{await d.current.remove()}catch(v){_t.warn("react/useSIWxSession","Failed to clear session:",v)}l(null),r(null)},[]),E=Be(async()=>{if(!n)throw new Error("No active session to refresh");c(!0),r(null);try{let v=await f.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}),x={...er(v),id:n.id,refreshedAt:new Date().toISOString()};return await d.current.set(x),l(x),c(!1),x}catch(v){let x=v instanceof Error?v:new Error("Session refresh failed");throw r(x),c(!1),x}},[n,f,s]),R=n!==null&&!tr(n),A=tr(n),T=n?.expiresAt?Math.max(0,new Date(n.expiresAt).getTime()-Date.now()):null;return{session:R?n:null,isAuthenticated:R,isRestoring:i,isSigningIn:u,isExpired:A,timeUntilExpiry:T,signIn:C,signOut:w,refresh:E,error:h,clearError:y}}import{defaultSiwxDomain as ei,defaultSiwxUri as ti}from"@naculus/connect-appkit-core";import{WalletError as He}from"@naculus/connect-core";import{createSiwxMessage as ni,generateNonce as ri,getBlockchainName as oi,issueNonce as si,nowISO as ai}from"@naculus/siwx";import{useCallback as rr,useState as Dt}from"react";function Ee(){let{session:e,chainId:t,client:o}=U(),[s,n]=Dt(!1),[l,i]=Dt(null),[g,u]=Dt(null),c=rr(()=>u(null),[]);return{signIn:rr(async r=>{if(!e)throw new He("wallet_unavailable","No active session");let a=r?.chainId??t;if(!a)throw new He("invalid_chain","No chain to sign for. Connect a wallet or pass options.chainId.");let p=oe(e,a);if(!p)throw new He("wallet_unavailable","No account found");let f=O(o);if(!f)throw new He("wallet_unavailable","Client not initialized");let{address:d}=p,y=typeof window>"u"?void 0:window.location,C=r?.domain??ei(y),w=r?.uri??ti(y);n(!0),u(null);try{let E=ri();await si(E);let R=ai(),A=ni({domain:C,address:d,uri:w,version:1,chainId:a,nonce:E,issuedAt:R,statement:r?.statement,expirationTime:r?.expirySeconds?new Date(Date.now()+r.expirySeconds*1e3).toISOString():void 0,resources:r?.resources,requestId:r?.requestId}),T=await f.signMessage(e,{message:A,address:d,chainId:a??void 0}),v=r?.expirySeconds?new Date(Date.now()+r.expirySeconds*1e3).toISOString():null,x={message:{raw:A,domain:C,address:d,statement:r?.statement??null,uri:w,version:1,chainId:a,nonce:E,issuedAt:R,blockchain:oi(a),expirationTime:v,notBefore:null,resources:r?.resources??[],requestId:r?.requestId??null},signature:T};return i(x),x}catch(E){let R=E instanceof Error?E:new Error("SIWx sign-in failed");throw u(R),R}finally{n(!1)}},[e,t,o]),isSigningIn:s,result:l,error:g,clearError:c}}import{WalletError as Mt}from"@naculus/connect-core";import{useCallback as or}from"react";function ii(){let{session:e,chainId:t}=U();return or(o=>{if(!e)throw new Mt("wallet_unavailable","No active session");let s=o??t;if(s&&!s.startsWith("eip155:"))throw new Mt("namespace_mismatch",`Ethereum SIWx requires an eip155 chain, received ${s}`);let n=e.namespaces.eip155;if(!n||n.accounts.length===0)throw new Mt("namespace_mismatch","No EVM (eip155) accounts found in session")},[e,t])}function li(){let e=ii(),t=Ee();return{signIn:or(async s=>(e(s?.chainId),t.signIn(s)),[e,t.signIn]),isSigningIn:t.isSigningIn,result:t.result,error:t.error,clearError:t.clearError}}import{resolveSimulationEndpoint as ci}from"@naculus/connect-appkit-core";import{SimulationManager as ui}from"@naculus/wallet-engine";import{useCallback as Lt,useRef as pi,useState as Bt}from"react";function di(e){let t=e?.rpcUrl,o=e?.chainId,s=pi(null),n=Lt(()=>(s.current||(s.current=new ui({enabled:!0,rpcUrl:t,autoSimulate:!1})),s.current),[t]),[l,i]=Bt(null),[g,u]=Bt(!1),[c,h]=Bt(null),r=Lt(async(p,f,d,y,C)=>{u(!0),h(null);try{let w=n(),E=ci(C?.chainId,o,C?.rpcUrl,t),R=await w.simulateERC20Transfer(p,f,d,y,E.chainId,C?.decimals,E.rpcUrl);return i(R),R}catch(w){let E=w instanceof Error?w:new Error(String(w));throw h(E),E}finally{u(!1)}},[t,o,n]),a=Lt(()=>{i(null),h(null),u(!1)},[]);return{result:l,loading:g,error:c,simulate:r,reset:a}}import{isSiwxExpired as mi,isSiwxNotBeforeValid as fi}from"@naculus/connect-appkit-core";import{LocalStorageAdapter as gi,logger as Ke}from"@naculus/connect-core";import{useCallback as Ft,useEffect as hi,useRef as Ci,useState as qe}from"react";var Ve="siwx_auth";function yi(e){return new gi(e)}function Si(e){let{storagePrefix:t="naculus_",autoRestore:o=!0}=e??{},[s,n]=qe(null),[l,i]=qe(o),[g,u]=qe(!1),[c,h]=qe(null),r=Ee(),a=Ci(yi(t)),p=Ft(()=>h(null),[]);hi(()=>{if(!o){i(!1);return}let y=!1;return(async()=>{try{let C=a.current,w=await C.get(Ve);if(y)return;w&&!mi(w,new Date)&&fi(w,new Date)?(Ke.info("react/useSiwxAuthSession","Restored persisted SIWx auth session"),n(w),h(null)):w&&(Ke.info("react/useSiwxAuthSession","Persisted SIWx auth expired, clearing"),await C.remove(Ve))}catch(C){Ke.warn("react/useSiwxAuthSession","Failed to restore SIWx auth:",C)}finally{y||i(!1)}})(),()=>{y=!0}},[o]);let f=Ft(async y=>{u(!0),h(null);try{let C=await r.signIn(y);return await a.current.set(Ve,C),n(C),u(!1),C}catch(C){let w=C instanceof Error?C:new Error("SIWx sign-in failed");throw h(w),u(!1),w}},[r]),d=Ft(async()=>{try{await a.current.remove(Ve)}catch(y){Ke.warn("react/useSiwxAuthSession","Failed to clear SIWx auth:",y)}n(null),h(null)},[]);return{isSignedIn:s!==null,isRestoring:l,siwxResult:s,isSigningIn:g,error:c,signIn:f,signOut:d,clearError:p}}import{bareEvmAddress as Ei,buildSmartAccountConfig as wi,resolveEvmChainId as sr}from"@naculus/connect-appkit-core";import{WalletError as lr}from"@naculus/connect-core";import{useCallback as ne,useEffect as ar,useRef as Ht,useState as we}from"react";function ir(e){return new lr("wallet_unavailable",e)}function ki(e){let{evmAccount:t}=B(),{session:o,chainId:s,client:n}=U(),[l,i]=we(null),[g,u]=we(!1),[c,h]=we(null),[r,a]=we(!1),[p,f]=we(null),d=Ht(null),y=Ht(0),C=Ht(!1);ar(()=>{if(d.current=null,!e?.rpcUrl)return;let b=!1;return import("@naculus/connect-core").then(({SmartAccountManager:I})=>{if(b)return;let W=sr(e.chainId,s);W&&(d.current=new I({rpcUrl:e.rpcUrl,chainId:W,bundlerClient:{url:e.bundlerUrl??""}}))}).catch(I=>{b||f(I instanceof Error?I:new Error("Failed to load account-abstraction module"))}),()=>{b=!0}},[s,e?.rpcUrl,e?.bundlerUrl,e?.chainId]),ar(()=>{y.current+=1,C.current=!1,i(null),u(!1),h(null),a(!1),f(null)},[t,s,e?.rpcUrl,e?.bundlerUrl,e?.chainId,e?.entryPoint,e?.accountType,e?.salt]);let w=ne(()=>{let b=Ei(t);if(!b||!d.current)return null;let I=sr(e?.chainId,s);return I?wi(b,I,{accountType:e?.accountType,entryPoint:e?.entryPoint,salt:e?.salt}):null},[t,s,e?.accountType,e?.chainId,e?.entryPoint,e?.salt]),E=ne(b=>(f(b),null),[]),R=ne(()=>C.current?null:(C.current=!0,y.current),[]),A=ne(b=>{y.current===b&&(C.current=!1)},[]),T=ne(async()=>{let b=w();if(!b||!d.current)return E(new Error("Smart account not configured"));let I=R();if(I===null)return E(new Error("Smart account operation already in progress"));a(!0),f(null);try{let L=await d.current.createAccount(b);return y.current!==I?null:(i(L.address),u(L.isDeployed),h(L),L)}catch(W){if(y.current!==I)return null;let L=W instanceof Error?W:new Error("Failed to create smart account");return f(L),null}finally{y.current===I&&a(!1),A(I)}},[R,E,A,w]),v=ne(async()=>{let b=w();if(!b||!d.current)return E(new Error("Smart account not configured"));if(!o)return E(ir("No active session"));let I=O(n);if(!I)return E(ir("Client not initialized"));if(s&&s!==b.chainId)return E(new lr("chain_mismatch",`Connected chain ${s} does not match smart account chain ${b.chainId}.`));let W=R();if(W===null)return E(new Error("Smart account operation already in progress"));a(!0),f(null);try{let L=d.current,F=await L.createAccount(b);if(y.current!==W)return null;if(F.isDeployed)return i(F.address),u(!0),h(F),F.address;let m=await L.getDeployCallData(b),S=await I.sendTransaction(o,{transaction:{to:m.to,data:m.data,value:m.value.toString()},chainId:b.chainId});if(y.current!==W)return null;let k=await L.createAccount(b);return i(k.address),u(k.isDeployed),h(k),S}catch(L){if(y.current!==W)return null;let F=L instanceof Error?L:new Error("Failed to deploy smart account");return f(F),null}finally{y.current===W&&a(!1),A(W)}},[n,s,R,E,A,w,o]),x=ne(async()=>{let b=w();if(!b||!d.current)return null;let I=y.current;try{let W=await d.current.getAccountAddress(b);return y.current!==I?null:(i(W),W)}catch(W){return y.current!==I||f(W instanceof Error?W:new Error("Failed to get smart account address")),null}},[w]);return{address:l,isDeployed:g,accountInfo:c,isLoading:r,error:p,createWallet:T,deployWallet:v,getAddress:x}}import{useMemo as xi}from"react";function Kt(){let{accounts:e,isConnected:t}=U();return xi(()=>{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,l=s.length>=3?s.slice(0,-1).join(":"):null;return{address:n,caip10:o,chainId:l,isConnected:t}},[e,t])}import{useCallback as vi,useEffect as cr,useRef as Ai,useState as qt}from"react";import{getSolanaBalance as bi}from"@naculus/connect-core";function Ri(e={}){let{client:t}=U(),{address:o}=Kt(),s=e.address??o,n=e.rpcUrl??O(t)?.solanaRpcUrl??null,[l,i]=qt(null),[g,u]=qt(!1),[c,h]=qt(null),r=Ai(0),a=vi(async()=>{if(!s||!n){i(null);return}let p=++r.current;u(!0),h(null);try{let f=await bi(n,s);if(p!==r.current)return;i(f)}catch(f){if(p!==r.current)return;i(null),h(f instanceof Error?f:new Error("Balance read failed"))}finally{p===r.current&&u(!1)}},[s,n]);return cr(()=>{a()},[a]),cr(()=>{if(!e.refreshInterval||e.refreshInterval<=0)return;let p=setInterval(()=>{a()},e.refreshInterval);return()=>clearInterval(p)},[e.refreshInterval,a]),{balance:l,isFetching:g,error:c,isConfigured:!!n,refetch:a}}import{readSolanaRoles as Ti}from"@naculus/connect-appkit-core";import{useMemo as Ii}from"react";function Ui(){let{client:e,session:t,accounts:o}=U();return Ii(()=>{let s=O(e)?.solanaConnector,{roles:n,absence:l}=Ti(s,t);return{roles:n,absence:l,identity:n?.identity??null,signer:n?.signer??null,payer:n?.payer??null}},[e,t,o])}import{WalletError as ur}from"@naculus/connect-core";import{useCallback as Vt,useState as $t}from"react";import{getSignatureStatus as Pi}from"@naculus/connect-core";function Wi(){let{client:e,session:t}=U(),[o,s]=$t(!1),[n,l]=$t(!1),[i,g]=$t(null),u=()=>{let a=O(e);if(!a||!t)throw new ur("wallet_unavailable","No connected wallet.");return a},c=Vt(async a=>{s(!0),g(null);try{return await u().signTransaction(t,{transaction:a})}catch(p){let f=p instanceof Error?p:new Error("Signing failed");throw g(f),f}finally{s(!1)}},[e,t]),h=Vt(async a=>{l(!0),g(null);try{return await u().sendTransaction(t,{transaction:a})}catch(p){let f=p instanceof Error?p:new Error("Send failed");throw g(f),f}finally{l(!1)}},[e,t]),r=Vt(async a=>{let p=O(e)?.solanaRpcUrl;if(!p)throw new ur("no_rpc","Set solanaRpcUrl on the client to read a signature's status.");return Pi(p,a)},[e]);return{signTransaction:c,sendTransaction:h,getStatus:r,isSigning:o,isSending:n,error:i,reset:()=>g(null)}}import{useCallback as pr,useState as dr}from"react";import{toChainSwitchError as Oi}from"@naculus/connect-appkit-core";function Ni(){let{switchChain:e,chainId:t}=U(),[o,s]=dr(!1),[n,l]=dr(null),i=pr(async u=>{s(!0),l(null);try{await e(u)}catch(c){let h=Oi(c);throw l(h),h}finally{s(!1)}},[e]),g=pr(()=>{l(null)},[]);return{switchChain:i,isSwitching:o,currentChainId:t,error:n,clearError:g}}import{chainNumber as _i,resolveChain as Di,toViemChain as Mi}from"@naculus/connect-appkit-core";import{useState as $e,useEffect as Gt,useCallback as mr,useMemo as jt,useRef as Li}from"react";import{createPublicClient as Bi,http as Fi,formatUnits as Hi}from"viem";function Ki(e){let{evmAccount:t,isConnected:o}=B(),{chainId:s,chains:n}=U(),[l,i]=$e([]),[g,u]=$e(!1),[c,h]=$e(null),{tokens:r,refreshInterval:a}=e,p=Li(null),f=jt(()=>r.map(v=>v.address.toLowerCase()+"|"+v.decimals+"|"+v.symbol).join(","),[r]),d=jt(()=>Di(n,s),[s,n]),y=d?_i(d):null,C=jt(()=>d?Mi(d,y):null,[d,y]),[w,E]=$e(null);Gt(()=>{if(!C||!d?.rpcUrl){E(null);return}let v=Bi({transport:Fi(d.rpcUrl),chain:C});E(v)},[d,C]);let R=[{name:"balanceOf",type:"function",stateMutability:"view",inputs:[{name:"owner",type:"address"}],outputs:[{name:"balance",type:"uint256"}]}],A=mr(async()=>{if(!t||!w||r.length===0){i([]);return}u(!0),h(null);try{let v=t.includes(":")?t.split(":").pop():t,b=(await Promise.allSettled(r.map(async I=>{try{let W=await w.readContract({address:I.address,abi:R,functionName:"balanceOf",args:[v]});return{address:I.address,symbol:I.symbol,decimals:I.decimals,name:I.name,balance:W.toString(),formatted:Hi(W,I.decimals)}}catch{return{address:I.address,symbol:I.symbol,decimals:I.decimals,name:I.name,balance:null,formatted:null}}}))).map(I=>I.status==="fulfilled"?I.value:{address:"",symbol:"?",decimals:0,balance:null,formatted:null});i(b)}catch(v){h(v instanceof Error?v:new Error("Failed to fetch token balances"))}finally{u(!1)}},[t,w,f]);Gt(()=>{o&&t&&r.length>0&&A()},[o,t,f,A]),Gt(()=>(a&&a>0&&o&&t&&r.length>0&&(p.current=setInterval(A,a)),()=>{p.current&&(clearInterval(p.current),p.current=null)}),[a,o,t,f,A]);let T=mr(v=>l.find(x=>x.address.toLowerCase()===v.toLowerCase()),[l]);return{tokenBalances:l,isLoading:g,error:c,refetch:A,getTokenBalance:T,chain:d}}import{useState as zt,useEffect as fr,useCallback as qi,useRef as Vi}from"react";function $i(e,t,o){let s=ye(),n=o??s,[l,i]=zt([]),[g,u]=zt(!1),[c,h]=zt(null),r=Vi(0),a=qi(async()=>{if(n){u(!0),h(null),r.current++;try{let f=await n.getTxHistory(e,t);i(f)}catch(f){h(f instanceof Error?f:new Error(String(f)))}finally{u(!1)}}},[n,e,t]);fr(()=>{a().catch(()=>{})},[a]),fr(()=>{if(!n)return;let f=()=>{a().catch(()=>{})};return n.on("statusChange",f),()=>{n.off("statusChange",f)}},[n,a]);let p={pending:l.filter(f=>f.status==="pending").length,confirmed:l.filter(f=>f.status==="confirmed").length,failed:l.filter(f=>f.status==="failed").length};return{entries:l,isLoading:g,error:c,refresh:a,summary:p}}import{fetchUserOperationReceipt as Gi,InvalidUserOperationReceiptError as ji}from"@naculus/connect-appkit-core";import{useCallback as ke,useEffect as gr,useRef as le,useState as re}from"react";function zi(e){let t=e?.bundlerUrl,o=e?.pollInterval??2e3,s=e?.maxRetries??30,[n,l]=re("idle"),[i,g]=re(null),[u,c]=re(e?.userOpHash??null),[h,r]=re(null),[a,p]=re(!1),[f,d]=re(0),y=le(0),[C,w]=re(0),E=le(null),R=le(null),A=le(0),T=le(0),v=le(null),x=ke(()=>{E.current&&(clearInterval(E.current),E.current=null),R.current&&(clearTimeout(R.current),R.current=null)},[]),b=ke(async(F,m)=>{if(!t||m!==A.current)return;let S=T.current+1;T.current=S,d(S);let k=new AbortController;v.current=k;let P=_=>{m===A.current&&(l("not_found"),p(!1),x(),r(_))},N=_=>{if(m===A.current){if(S<=s){R.current=setTimeout(()=>{b(F,m)},o);return}P(_)}};try{let _=await Gi(t,F,k.signal);if(m!==A.current)return;if(_){g(_),l(_.success?"confirmed":"failed"),p(!1),x();return}l("pending"),N(new Error("UserOperation not included after maximum retries"))}catch(_){if(m!==A.current||k.signal.aborted)return;let J=_ instanceof Error?_:new Error("Unknown bundler response failure");if(J instanceof ji){P(J);return}N(new Error(`UserOperation status unavailable after ${S} attempt${S===1?"":"s"}: ${J.message}`))}finally{v.current===k&&(v.current=null)}},[t,o,s,x]),I=ke(F=>{A.current+=1;let m=A.current;if(v.current?.abort(),v.current=null,x(),c(F),g(null),r(null),T.current=0,d(0),w(0),y.current=Date.now(),!t){l("not_found"),p(!1),r(new Error("Bundler URL not configured"));return}l("pending"),p(!0),E.current=setInterval(()=>{w(Date.now()-y.current)},1e3),b(F,m)},[t,x,b]),W=ke(()=>{A.current+=1,v.current?.abort(),v.current=null,x(),p(!1)},[x]),L=ke(()=>{A.current+=1,v.current?.abort(),v.current=null,x(),c(null),l("idle"),g(null),r(null),p(!1),T.current=0,d(0),w(0)},[x]);return gr(()=>{e?.userOpHash&&e?.autoStart!==!1&&I(e.userOpHash)},[]),gr(()=>()=>{A.current+=1,v.current?.abort(),v.current=null,x()},[x]),{status:n,receipt:i,userOpHash:u,error:h,isPolling:a,elapsedMs:C,attempts:f,start:I,stop:W,reset:L}}import{validateDestination as Zi}from"@naculus/connect-appkit-core";import{useMemo as el}from"react";var Qi={"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."},Xi={"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"},hr={en:Qi,zh:Xi},Qt="en";function Yi(e){Qt=e}function Ji(){return Qt}function Xt(e){return hr[Qt][e]??hr.en[e]??e}function Cr(e){let{isValid:t,level:o,issue:s}=Zi(e);return{isValid:t,level:o,warning:s?Xt(`address.${s}`):null}}function tl({address:e}){return{validation:el(()=>Cr(e),[e])}}function nl(){let{status:e,session:t,accounts:o,chainId:s,error:n,connect:l,disconnect:i,reconnect:g,switchChain:u}=U(),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:l,disconnect:i,reconnect:g,switchChain:u}}import{useCallback as Jt,useMemo as Er}from"react";var yr={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"},Sr={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."},xe="Something went wrong",ve="An unexpected error occurred. Please try again. If the problem persists, check your connection and wallet configuration.";function Ae(e){if(!e)return{title:xe,description:ve};let t=e;if(t.name==="WalletError"&&t.code){let o=t.code,s=yr[o]??xe,n=Sr[o]??t.message??ve;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:xe,description:o||ve}}return typeof e=="string"?{title:xe,description:e||ve}:{title:xe,description:ve}}function Yt(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 rl(){let{error:e,clearError:t}=U(),o=Er(()=>e?Ae(e):null,[e]),s=Er(()=>e?Yt(e):!1,[e]),n=Jt(()=>{t()},[t]),l=Jt(g=>Ae(g),[]),i=Jt(g=>async()=>{try{return await g()}catch(u){let c=Ae(u);if(u instanceof Error){let h=u;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:u}),{title:c.title,code:c.code,friendlyMessage:c.description})}},[]);return{error:e,friendlyError:o,clearError:n,isRetryable:s,formatError:l,wrapAsync:i}}import{useState as Ge,useEffect as ol,useCallback as wr,useRef as sl}from"react";import{TokenListManager as al}from"@naculus/connect-core";import{eip155ChainIdToNumber as kr}from"@naculus/connect-appkit-core";function je(e,t){let o=sl(null),[s,n]=Ge([]),[l,i]=Ge(t?.autoLoad!==!1),[g,u]=Ge(!1),[c,h]=Ge(null);if(!o.current){let p={};t?.sources&&(p.sources=t.sources),o.current=new al(p)}let r=wr(async()=>{let p=o.current;if(p){i(!0),h(null);try{await p.load();let f=e?kr(e):void 0,d=p.getTokens(f!==void 0?{chainId:f}:void 0);n(d),u(!0)}catch(f){h(f instanceof Error?f:new Error(String(f)))}finally{i(!1)}}},[e]),a=wr(async()=>{let p=o.current;if(p){i(!0),h(null);try{await p.refresh();let f=e?kr(e):void 0,d=p.getTokens(f!==void 0?{chainId:f}:void 0);n(d),u(!0)}catch(f){h(f instanceof Error?f:new Error(String(f)))}finally{i(!1)}}},[e]);return ol(()=>{t?.autoLoad!==!1&&r()},[r,t?.autoLoad]),{tokens:s,isLoading:l,isLoaded:g,error:c,refetch:a}}import{useState as vr,useEffect as dl,useRef as ml}from"react";import{TokenListManager as fl}from"@naculus/connect-core";import{ETHEREUM_MAINNET_TOKENS as il,POLYGON_TOKENS as ll,OPTIMISM_TOKENS as cl,ARBITRUM_TOKENS as ul,BASE_TOKENS as pl}from"@naculus/connect-core";function xr(){return[{name:"built-in",tokens:[...il,...ll,...cl,...ul,...pl],enabled:!0},{name:"uniswap-default",url:"https://tokens.uniswap.org",enabled:!0,refreshInterval:1440*60*1e3}]}import{eip155ChainIdToNumber as gl}from"@naculus/connect-appkit-core";var hl=300,ze=null;function Cl(){return ze||(ze=new fl({sources:xr()}),ze.load().catch(()=>{})),ze}function Qe(e,t){let[o,s]=vr({exact:[],fuzzy:[],hasMore:!1}),[n,l]=vr(!1),i=ml(null),g=e.trim();return dl(()=>{if(!g){s({exact:[],fuzzy:[],hasMore:!1}),l(!1);return}return i.current&&clearTimeout(i.current),l(!0),i.current=setTimeout(()=>{let u=Cl(),c=t?gl(t):void 0,h=u.search(g,{chainId:c,limit:20});s(h),l(!1)},hl),()=>{i.current&&clearTimeout(i.current)}},[g,t]),{results:o,isSearching:n}}import Zt,{useCallback as yl}from"react";import{Fragment as Sl,jsx as G,jsxs as j}from"react/jsx-runtime";function Ar({chainId:e,onSelect:t,onClose:o,options:s}){let[n,l]=Zt.useState(""),{tokens:i,isLoading:g,error:u}=je(e),{results:c,isSearching:h}=Qe(n,n?e:void 0),r=s?.showRecommendations??!0,a=Zt.useMemo(()=>{if(n.trim()){let y=[...c.exact,...c.fuzzy].map(C=>C.token);return s?.filter?y.filter(s.filter):y}let d=i;return s?.filter?d.filter(s.filter):d},[n,c,i,s?.filter]),p=Zt.useMemo(()=>!r||n.trim()?[]:i.slice(0,6),[i,r,n]),f=yl(d=>{t(d),o()},[t,o]);return j("div",{style:{background:"hsl(var(--background))",borderRadius:"12px",padding:"16px",color:"hsl(var(--foreground))",minWidth:"320px",maxWidth:"400px",fontFamily:"system-ui, sans-serif"},children:[j("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px"},children:[G("h3",{style:{margin:0,fontSize:"16px",fontWeight:600},children:"Select Token"}),G("button",{onClick:o,style:{background:"none",border:"none",color:"hsl(var(--muted-foreground))",cursor:"pointer",fontSize:"18px",padding:"4px 8px"},children:"\u2715"})]}),G("input",{type:"text",placeholder:"Search token name or paste address",value:n,onChange:d=>l(d.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&&G("div",{style:{textAlign:"center",padding:"20px",color:"hsl(var(--muted-foreground))"},children:"Loading tokens..."}),u&&j("div",{style:{textAlign:"center",padding:"12px",color:"hsl(var(--destructive))",fontSize:"13px"},children:["Error: ",u.message]}),r&&p.length>0&&!n.trim()&&j("div",{style:{marginBottom:"12px"},children:[G("div",{style:{fontSize:"11px",color:"hsl(var(--muted-foreground))",textTransform:"uppercase",letterSpacing:"0.5px",marginBottom:"8px"},children:"Popular"}),G("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap"},children:p.map(d=>j("button",{onClick:()=>f(d),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:[d.logoURI?G("img",{src:d.logoURI,alt:"",style:{width:"16px",height:"16px",borderRadius:"50%"},onError:y=>{y.target.style.display="none"}}):null,d.symbol]},`${d.chainId}:${d.address}`))})]}),n.trim()&&!g&&G("div",{style:{fontSize:"11px",color:"hsl(var(--muted-foreground))",marginBottom:"8px"},children:a.length>0?j(Sl,{children:[c.exact.length," exact, ",c.fuzzy.length," fuzzy",c.hasMore?" (more available)":""]}):"No results found"}),G("div",{style:{maxHeight:"320px",overflowY:"auto",display:"flex",flexDirection:"column",gap:"2px"},children:a.map(d=>j("button",{onClick:()=>f(d),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:[G("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:d.logoURI?G("img",{src:d.logoURI,alt:d.symbol,style:{width:"100%",height:"100%"},onError:y=>{let C=y.target;C.style.display="none",C.parentElement.textContent=d.symbol.slice(0,2)}}):d.symbol.slice(0,2)}),j("div",{style:{flex:1,minWidth:0},children:[G("div",{style:{fontWeight:600,fontSize:"14px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d.symbol}),G("div",{style:{fontSize:"12px",color:"hsl(var(--muted-foreground))",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d.name})]}),j("div",{style:{fontSize:"11px",color:"#666",textAlign:"right",flexShrink:0},children:[j("div",{children:[d.decimals," decimals"]}),j("div",{children:["Chain ",d.chainId]})]})]},`${d.chainId}:${d.address}`))})]})}import{createComponent as D}from"@stencil/react-output-target/runtime";import M from"react";import{AppkitAccordion as El,defineCustomElement as wl}from"@naculus/connect-appkit-wc/dist/components/appkit-accordion.js";import{AppkitAccountButton as kl,defineCustomElement as xl}from"@naculus/connect-appkit-wc/dist/components/appkit-account-button.js";import{AppkitAlertDialog as vl,defineCustomElement as Al}from"@naculus/connect-appkit-wc/dist/components/appkit-alert-dialog.js";import{AppkitAvatar as bl,defineCustomElement as Rl}from"@naculus/connect-appkit-wc/dist/components/appkit-avatar.js";import{AppkitBadge as Tl,defineCustomElement as Il}from"@naculus/connect-appkit-wc/dist/components/appkit-badge.js";import{AppkitButton as Ul,defineCustomElement as Pl}from"@naculus/connect-appkit-wc/dist/components/appkit-button.js";import{AppkitCardContent as Wl,defineCustomElement as Ol}from"@naculus/connect-appkit-wc/dist/components/appkit-card-content.js";import{AppkitCardDescription as Nl,defineCustomElement as _l}from"@naculus/connect-appkit-wc/dist/components/appkit-card-description.js";import{AppkitCardFooter as Dl,defineCustomElement as Ml}from"@naculus/connect-appkit-wc/dist/components/appkit-card-footer.js";import{AppkitCardHeader as Ll,defineCustomElement as Bl}from"@naculus/connect-appkit-wc/dist/components/appkit-card-header.js";import{AppkitCardTitle as Fl,defineCustomElement as Hl}from"@naculus/connect-appkit-wc/dist/components/appkit-card-title.js";import{AppkitCard as Kl,defineCustomElement as ql}from"@naculus/connect-appkit-wc/dist/components/appkit-card.js";import{AppkitCheckbox as Vl,defineCustomElement as $l}from"@naculus/connect-appkit-wc/dist/components/appkit-checkbox.js";import{AppkitCollapsible as Gl,defineCustomElement as jl}from"@naculus/connect-appkit-wc/dist/components/appkit-collapsible.js";import{AppkitConnectButton as zl,defineCustomElement as Ql}from"@naculus/connect-appkit-wc/dist/components/appkit-connect-button.js";import{AppkitDialog as Xl,defineCustomElement as Yl}from"@naculus/connect-appkit-wc/dist/components/appkit-dialog.js";import{AppkitDropdownMenu as Jl,defineCustomElement as Zl}from"@naculus/connect-appkit-wc/dist/components/appkit-dropdown-menu.js";import{AppkitInput as ec,defineCustomElement as tc}from"@naculus/connect-appkit-wc/dist/components/appkit-input.js";import{AppkitPopover as nc,defineCustomElement as rc}from"@naculus/connect-appkit-wc/dist/components/appkit-popover.js";import{AppkitProgress as oc,defineCustomElement as sc}from"@naculus/connect-appkit-wc/dist/components/appkit-progress.js";import{AppkitScrollArea as ac,defineCustomElement as ic}from"@naculus/connect-appkit-wc/dist/components/appkit-scroll-area.js";import{AppkitSelect as lc,defineCustomElement as cc}from"@naculus/connect-appkit-wc/dist/components/appkit-select.js";import{AppkitSeparator as uc,defineCustomElement as pc}from"@naculus/connect-appkit-wc/dist/components/appkit-separator.js";import{AppkitSkeleton as dc,defineCustomElement as mc}from"@naculus/connect-appkit-wc/dist/components/appkit-skeleton.js";import{AppkitSwitch as fc,defineCustomElement as gc}from"@naculus/connect-appkit-wc/dist/components/appkit-switch.js";import{AppkitTabs as hc,defineCustomElement as Cc}from"@naculus/connect-appkit-wc/dist/components/appkit-tabs.js";import{AppkitToggleGroup as yc,defineCustomElement as Sc}from"@naculus/connect-appkit-wc/dist/components/appkit-toggle-group.js";import{AppkitTooltip as Ec,defineCustomElement as wc}from"@naculus/connect-appkit-wc/dist/components/appkit-tooltip.js";var kc=D({tagName:"appkit-accordion",elementClass:El,react:M,events:{onAppkitToggle:"appkitToggle"},defineCustomElement:wl}),xc=D({tagName:"appkit-account-button",elementClass:kl,react:M,events:{},defineCustomElement:xl}),vc=D({tagName:"appkit-alert-dialog",elementClass:vl,react:M,events:{onAppkitClose:"appkitClose",onAppkitOpenChange:"appkitOpenChange"},defineCustomElement:Al}),Ac=D({tagName:"appkit-avatar",elementClass:bl,react:M,events:{},defineCustomElement:Rl}),bc=D({tagName:"appkit-badge",elementClass:Tl,react:M,events:{},defineCustomElement:Il}),Rc=D({tagName:"appkit-button",elementClass:Ul,react:M,events:{},defineCustomElement:Pl}),Tc=D({tagName:"appkit-card",elementClass:Kl,react:M,events:{},defineCustomElement:ql}),Ic=D({tagName:"appkit-card-content",elementClass:Wl,react:M,events:{},defineCustomElement:Ol}),Uc=D({tagName:"appkit-card-description",elementClass:Nl,react:M,events:{},defineCustomElement:_l}),Pc=D({tagName:"appkit-card-footer",elementClass:Dl,react:M,events:{},defineCustomElement:Ml}),Wc=D({tagName:"appkit-card-header",elementClass:Ll,react:M,events:{},defineCustomElement:Bl}),Oc=D({tagName:"appkit-card-title",elementClass:Fl,react:M,events:{},defineCustomElement:Hl}),Nc=D({tagName:"appkit-checkbox",elementClass:Vl,react:M,events:{onAppkitChange:"appkitChange"},defineCustomElement:$l}),_c=D({tagName:"appkit-collapsible",elementClass:Gl,react:M,events:{onAppkitToggle:"appkitToggle"},defineCustomElement:jl}),Dc=D({tagName:"appkit-connect-button",elementClass:zl,react:M,events:{onAppkitConnect:"appkitConnect",onAppkitDisconnect:"appkitDisconnect",onAppkitStartPairing:"appkitStartPairing",onAppkitRetry:"appkitRetry",onAppkitCancelPairing:"appkitCancelPairing",onAppkitMobileDeepLink:"appkitMobileDeepLink",onAppkitCopyAddress:"appkitCopyAddress"},defineCustomElement:Ql}),Mc=D({tagName:"appkit-dialog",elementClass:Xl,react:M,events:{onAppkitClose:"appkitClose",onAppkitOpenChange:"appkitOpenChange"},defineCustomElement:Yl}),Lc=D({tagName:"appkit-dropdown-menu",elementClass:Jl,react:M,events:{onAppkitSelect:"appkitSelect"},defineCustomElement:Zl}),Bc=D({tagName:"appkit-input",elementClass:ec,react:M,events:{onAppkitChange:"appkitChange"},defineCustomElement:tc}),Fc=D({tagName:"appkit-popover",elementClass:nc,react:M,events:{onAppkitOpenChange:"appkitOpenChange"},defineCustomElement:rc}),Hc=D({tagName:"appkit-progress",elementClass:oc,react:M,events:{},defineCustomElement:sc}),Kc=D({tagName:"appkit-scroll-area",elementClass:ac,react:M,events:{},defineCustomElement:ic}),qc=D({tagName:"appkit-select",elementClass:lc,react:M,events:{onAppkitChange:"appkitChange"},defineCustomElement:cc}),Vc=D({tagName:"appkit-separator",elementClass:uc,react:M,events:{},defineCustomElement:pc}),$c=D({tagName:"appkit-skeleton",elementClass:dc,react:M,events:{},defineCustomElement:mc}),Gc=D({tagName:"appkit-switch",elementClass:fc,react:M,events:{onAppkitChange:"appkitChange"},defineCustomElement:gc}),jc=D({tagName:"appkit-tabs",elementClass:hc,react:M,events:{onAppkitTabChange:"appkitTabChange"},defineCustomElement:Cc}),zc=D({tagName:"appkit-toggle-group",elementClass:yc,react:M,events:{onAppkitChange:"appkitChange"},defineCustomElement:Sc}),Qc=D({tagName:"appkit-tooltip",elementClass:Ec,react:M,events:{},defineCustomElement:wc});export{kc as AppkitAccordion,xc as AppkitAccountButton,vc as AppkitAlertDialog,Ac as AppkitAvatar,bc as AppkitBadge,Rc as AppkitButton,Tc as AppkitCard,Ic as AppkitCardContent,Uc as AppkitCardDescription,Pc as AppkitCardFooter,Wc as AppkitCardHeader,Oc as AppkitCardTitle,Nc as AppkitCheckbox,_c as AppkitCollapsible,Dc as AppkitConnectButton,Mc as AppkitDialog,Lc as AppkitDropdownMenu,Bc as AppkitInput,Fc as AppkitPopover,Hc as AppkitProgress,Kc as AppkitScrollArea,qc as AppkitSelect,Vc as AppkitSeparator,$c as AppkitSkeleton,Gc as AppkitSwitch,jc as AppkitTabs,zc as AppkitToggleGroup,Qc as AppkitTooltip,mn as DEFAULT_EVM_CHAINS,Bh as LAMPORTS_PER_SOL,Fh as PassphraseCancelledError,Hh as PassphraseGate,qh as SolanaRpcError,Ar as TokenSelector,Fn as TxMonitorContext,Sr as WALLET_ERROR_DESCRIPTIONS,yr as WALLET_ERROR_TITLES,ro as Web3ConnectProvider,st as Web3Context,fs as buildDelegationPolicyMessage,Nr as clearClient,nt as createClient,_h as formatSol,Gr as getChainById,rt as getClient,ot as getDefaultChains,Dh as getLatestBlockhash,Ji as getLocale,Mh as getSignatureStatus,Lh as getSolanaBalance,Ae as getUserFriendlyError,Yt as isRetryableError,Kh as parseSol,ss as resetSessionKeyManager,Yi as setLocale,Xt as t,B as useAccount,Co as useBalance,lt as useCapabilities,V as useChain,on as useCompareCosts,Io as useConnect,ns as useCreateSessionKey,Lo as useDelegate,me as useDelegation,ms as useDelegationPolicy,Cs as useDisconnect,Ws as useERC20Allowance,Bs as useERC20Approve,Xs as useERC20Transfer,oa as useERC20TransferSimulation,Ss as useEmbeddedWallet,yt as useExecuteCalls,ln as useExecuteRoute,pa as useLastTx,ha as useLookupAddress,Ra as useNotification,Ua as usePassphraseGate,Ho as usePaymentFetch,Wa as useResolveName,rs as useRevokeSession,pn as useRouteQuote,Nt as useSIWxLogin,Za as useSIWxSession,ht as useSendCalls,he as useSendTransaction,Ma as useSendUserOperation,os as useSendWithSession,Ka as useSession,St as useSessionKeys,li as useSignInWithEthereum,Ee as useSignInWithX,wt as useSignMessage,di as useSimulateTransfer,Si as useSiwxAuthSession,ki as useSmartAccount,Kt as useSolanaAccount,Ri as useSolanaBalance,Ui as useSolanaRoles,Wi as useSolanaTransaction,Ni as useSwitchChain,Ki as useTokenBalance,je as useTokenList,Qe as useTokenSearch,bt as useTransactionSimulation,$i as useTxHistory,ca as useTxMonitor,zi as useUserOpStatus,tl as useValidateDestination,$ as useViemClient,nl as useWallet,U as useWeb3,rl as useWeb3ErrorHandler,Cr as validateDestination};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|