"use strict";var e=require("react/jsx-runtime"),t=require("react"),r=require("./privy-context-UTJouJ1x.js"),i=require("./context-rs-ygOK2.js"),n=require("./errors-CBapWvRs.js"),a=require("./getEmbeddedConnectedWallet-D6YL2FS9.js"),l=require("./smart-wallets-B8ZWRkMm.js"),s=require("./internal-context-CdsQ3LEl.js"),o=require("./get-entropy-details-for-user-D63rM5_a.js");require("@privy-io/are-addresses-equal"),require("@privy-io/js-sdk-core"),require("tinycolor2"),require("ofetch"),require("viem"),require("./modal-context-BgeioxwT.js"),require("./PrivyPluginContext-DsLtVhZA.js"),require("zustand"),require("./getPublicClient-CFd_sHBk.js"),require("viem/chains"),require("permissionless"),require("permissionless/accounts"),require("permissionless/clients/pimlico"),require("viem/account-abstraction"),require("./user-D2oPA-vS.js");let c=/*#__PURE__*/t.createContext({client:void 0,getClientForChain:s.notImplemented});let u=({config:c,children:u})=>{let{appId:m}=s.usePrivyInternal(),{chains:g,defaultChain:C,rpcConfig:p,smartWallets:f}=i.useAppConfig(),{wallets:h}=o.useWallets(),{user:W}=r.usePrivyContext(),[v,y]=t.useState(),{wrapSmartAccountClientWithUIs:q}=l.useSmartWalletsUIWrapper(),w=r.getPrivyEthereumWallet(W),x=a.getEmbeddedConnectedWalletWithAddress(h,w?.address);t.useEffect((()=>{(async()=>{if(!f?.enabled)return;let e=f.configuredNetworks.find((e=>e.chainId===`eip155:${C.id}`))?C:g.find((e=>f.configuredNetworks.map((e=>e.chainId)).includes(`eip155:${e.id}`)));if(!e)throw new n.PrivyClientError("Could not find smart wallets chain configurations for any Privy client configured chains. Please configure smart wallets for your chains in the Privy dashboard.");y(await l.getSmartWalletClient({chain:e,privyAppId:m,paymasterContext:c?.paymasterContext,rpcConfig:p,account:w,signer:await(x?.getEthereumProvider()),user:W,smartWalletsConfig:f}))})()}),[!!f?.enabled,!!W?.smartWallet,!!x,!!w]);/*#__PURE__*/return e.jsx(d.Provider,{value:{client:v,config:c,getClientForChain:async({id:e})=>{let t=await l.getSmartWalletClient({chain:g.find((t=>t.id===e)),privyAppId:m,paymasterContext:c?.paymasterContext,rpcConfig:p,account:w,signer:await(x?.getEthereumProvider()),user:W,smartWalletsConfig:f});if(!t)throw new n.PrivyClientError(`Failed to create smart wallet client for chain id: ${e}`);return q(t)}},children:u})},d=/*#__PURE__*/t.createContext({client:void 0,config:void 0,getClientForChain:s.notImplemented}),m=({children:n})=>{let{smartWallets:a}=i.useAppConfig(),{client:o,config:u,getClientForChain:m}=(()=>{let{client:e,config:r,getClientForChain:i}=t.useContext(d);return{client:e,config:r,getClientForChain:i}})(),{wrapSmartAccountClient:g}=l.useSmartWalletsWrapper({clientConfig:u,smartWalletsConfig:a}),{user:C}=r.usePrivyContext(),{generateSiweMessageForSmartWallet:p,linkSmartWallet:f,hideWalletUIs:h}=s.usePrivyInternal();return t.useEffect((()=>{(async()=>{if(o&&C&&!C?.smartWallet&&a?.enabled)try{let e=await p({address:o.account.address,chainId:`eip155:${o.chain.id}`});h.current=!0;let t=await o.signMessage({message:e});await f({signature:t,message:e,smartWalletType:a.smartWalletType,smartWalletVersion:a.smartWalletVersion})}catch(e){console.error("Error creating smart wallet:",e)}finally{h.current=!1}})()}),[!!o,!!C?.smartWallet,!!a?.enabled]),/*#__PURE__*/e.jsx(c.Provider,{value:{client:C?.smartWallet&&o?g(o):void 0,getClientForChain:m},children:n})};exports.SmartWalletsProvider=({config:t,children:r})=>/*#__PURE__*/e.jsx(u,{config:t,children:/*#__PURE__*/e.jsx(m,{children:r})}),exports.useSmartWallets=()=>{let{client:e,getClientForChain:r}=t.useContext(c);return{client:e,getClientForChain:r}};
//# sourceMappingURL=smart-wallets.js.map
