import{jsx as e}from"react/jsx-runtime";import{useContext as t,useState as i,useEffect as r,createContext as a}from"react";import{u as n,b as o}from"./privy-context-Bi6vqCPc.mjs";import{u as s}from"./context-BKnOUECq.mjs";import{P as l}from"./errors-Dd6zfYtp.mjs";import{a as c}from"./getEmbeddedConnectedWallet-Ba6LFHzY.mjs";import{u as m,g as d,a as p}from"./smart-wallets-DQwzlJfN.mjs";import{u as g,n as f}from"./internal-context-dfitw7Ot.mjs";import{u}from"./get-entropy-details-for-user-BIWg0YxF.mjs";import"@privy-io/are-addresses-equal";import"@privy-io/js-sdk-core";import"tinycolor2";import"ofetch";import"viem";import"./modal-context-DBwfUxD-.mjs";import"./PrivyPluginContext-DA-yS5vO.mjs";import"zustand";import"./getPublicClient-D4yNgeGy.mjs";import"viem/chains";import"permissionless";import"permissionless/accounts";import"permissionless/clients/pimlico";import"viem/account-abstraction";import"./user-D5cqJNp9.mjs";let h=/*#__PURE__*/a({client:void 0,getClientForChain:f});const C=({config:t,children:i})=>/*#__PURE__*/e(w,{config:t,children:/*#__PURE__*/e(W,{children:i})}),y=()=>{let{client:e,getClientForChain:i}=t(h);return{client:e,getClientForChain:i}};let w=({config:t,children:a})=>{let{appId:p}=g(),{chains:f,defaultChain:h,rpcConfig:C,smartWallets:y}=s(),{wallets:w}=u(),{user:W}=n(),[j,x]=i(),{wrapSmartAccountClientWithUIs:F}=m(),P=o(W),b=c(w,P?.address);r((()=>{(async()=>{if(!y?.enabled)return;let e=y.configuredNetworks.find((e=>e.chainId===`eip155:${h.id}`))?h:f.find((e=>y.configuredNetworks.map((e=>e.chainId)).includes(`eip155:${e.id}`)));if(!e)throw new l("Could not find smart wallets chain configurations for any Privy client configured chains. Please configure smart wallets for your chains in the Privy dashboard.");x(await d({chain:e,privyAppId:p,paymasterContext:t?.paymasterContext,rpcConfig:C,account:P,signer:await(b?.getEthereumProvider()),user:W,smartWalletsConfig:y}))})()}),[!!y?.enabled,!!W?.smartWallet,!!b,!!P]);/*#__PURE__*/return e(v.Provider,{value:{client:j,config:t,getClientForChain:async({id:e})=>{let i=await d({chain:f.find((t=>t.id===e)),privyAppId:p,paymasterContext:t?.paymasterContext,rpcConfig:C,account:P,signer:await(b?.getEthereumProvider()),user:W,smartWalletsConfig:y});if(!i)throw new l(`Failed to create smart wallet client for chain id: ${e}`);return F(i)}},children:a})},v=/*#__PURE__*/a({client:void 0,config:void 0,getClientForChain:f}),W=({children:i})=>{let{smartWallets:a}=s(),{client:o,config:l,getClientForChain:c}=(()=>{let{client:e,config:i,getClientForChain:r}=t(v);return{client:e,config:i,getClientForChain:r}})(),{wrapSmartAccountClient:m}=p({clientConfig:l,smartWalletsConfig:a}),{user:d}=n(),{generateSiweMessageForSmartWallet:f,linkSmartWallet:u,hideWalletUIs:C}=g();return r((()=>{(async()=>{if(o&&d&&!d?.smartWallet&&a?.enabled)try{let e=await f({address:o.account.address,chainId:`eip155:${o.chain.id}`});C.current=!0;let t=await o.signMessage({message:e});await u({signature:t,message:e,smartWalletType:a.smartWalletType,smartWalletVersion:a.smartWalletVersion})}catch(e){console.error("Error creating smart wallet:",e)}finally{C.current=!1}})()}),[!!o,!!d?.smartWallet,!!a?.enabled]),/*#__PURE__*/e(h.Provider,{value:{client:d?.smartWallet&&o?m(o):void 0,getClientForChain:c},children:i})};export{C as SmartWalletsProvider,y as useSmartWallets};
//# sourceMappingURL=smart-wallets.mjs.map
