"use strict";var e=require("react/jsx-runtime"),r=require("lucide-react"),t=require("react"),i=require("@privy-io/js-sdk-core"),a=require("./context-rs-ygOK2.js"),l=require("./toViemAccount-CopJpCYv.js"),s=require("./errors-CBapWvRs.js"),o=require("./internal-context-CdsQ3LEl.js"),u=require("./index-BoiKFBqR.js"),n=require("./modal-context-BgeioxwT.js"),c=require("./privy-context-UTJouJ1x.js"),d=require("./PrivyPluginContext-DsLtVhZA.js"),q=require("./ScreenLayout-DaFW0I3a.js");require("tinycolor2"),require("jose"),require("eventemitter3"),require("./index-Ub4KpwSY.js"),require("zustand"),require("viem"),require("viem/utils"),require("./wallet-connect-BuohfvHK.js"),require("./getPublicClient-CFd_sHBk.js"),require("viem/chains"),require("react-device-detect"),require("@coinbase/wallet-sdk"),require("@walletconnect/ethereum-provider"),require("./pkce-CmuJlEgn.js"),require("ofetch"),require("./paths-DizMb-lU.js"),require("js-cookie"),require("@privy-io/ethereum"),require("viem/accounts"),require("mipd"),require("@scure/base"),require("./usePrivy-Dt4_yE6Q.js"),require("./use-unlink-wallet-DAxmY7kq.js"),require("./get-entropy-details-for-user-D63rM5_a.js"),require("./user-D2oPA-vS.js"),require("@privy-io/popup"),require("./events-context-Di6--rDg.js"),require("styled-components"),require("./useActiveWallet-dTc6deka.js"),require("@headlessui/react"),require("@privy-io/urls"),require("./getEmbeddedConnectedWallet-D6YL2FS9.js"),require("./frame-BHa-PKpX.js"),require("@privy-io/routes"),require("./use-deposit-address-CVyd0fqP.js"),require("x402/client"),require("@privy-io/api-base"),require("@privy-io/are-addresses-equal"),require("./use-sign-with-user-signer-BhoaqeNG.js"),require("./ModalHeader-Cpls13mi.js"),require("@heroicons/react/24/outline/ArrowLeftIcon"),require("@heroicons/react/24/outline/ArrowRightIcon"),require("@heroicons/react/24/outline/QuestionMarkCircleIcon"),require("@heroicons/react/24/outline/XMarkIcon"),require("./Screen-8NusMFtu.js"),require("./index-ByFhjjzH.js");const y=({errorMessage:t,onClose:i})=>t?/*#__PURE__*/e.jsx(q.ScreenLayout,{title:"Something went wrong",subtitle:t,icon:r.XCircle,iconVariant:"error",primaryCta:{label:"Close",onClick:i},watermark:!0}):/*#__PURE__*/e.jsx(q.ScreenLayout,{title:"Creating your wallet",subtitle:"Please wait...",iconVariant:"loading",watermark:!1}),h={component:()=>{let{setModalData:r,navigate:q,data:h,onUserCloseViaDialogOrKeybindRef:m}=n.usePrivyModal(),p=a.useAppConfig(),[v,w]=t.useState(""),{embeddedWallets:j}=a.useAppConfig(),{authenticated:C,user:g}=c.usePrivyContext(),{closePrivyModal:b,walletProxy:S,client:x}=o.usePrivyInternal(),{onSuccess:W,onFailure:f,callAuthOnSuccessOnClose:A,shouldCreateEth:E,shouldCreateSol:O}=h.createWallet,I=d.usePlugins(),P=g?I(u.WALLET_CREATION_ON_LOGIN_PLUGIN_ID)?.shouldCreateWallet({user:g}):void 0,k=!!g&&u.shouldCreateEmbeddedEthWallet(g,p.embeddedWallets.ethereum.createOnLogin,P),L=!!g&&u.shouldCreateEmbeddedSolWallet(g,p.embeddedWallets.solana.createOnLogin,P),R="legacy-embedded-wallets-only"===p.embeddedWallets.mode&&!0===p?.embeddedWallets.requireUserOwnedRecoveryOnCreate,[M,U]=t.useState(null),{create:T}=u.useCreateWalletWithoutFallback(),K=E??k,V=O??L,_=new l.RunEffectOnce((async()=>{let e=await x.getAccessToken();if(g&&e&&S)try{let e,r=await i.generateWalletIdempotencyKey(g.id,"ethereum"),t=await i.generateWalletIdempotencyKey(g.id,"solana");if(K&&V)e=await T({chainType:"ethereum",walletIndex:0,latestUser:g,idempotencyKey:r}),e=await T({chainType:"solana",walletIndex:0,latestUser:e.user,idempotencyKey:t});else if(V)e=await T({chainType:"solana",walletIndex:0,latestUser:g,idempotencyKey:t});else{if(!K)return void b({shouldCallAuthOnSuccess:A});e=await T({chainType:"ethereum",walletIndex:0,latestUser:g,idempotencyKey:r})}U(e),q("EmbeddedWalletCreatedScreen")}catch(e){w(e.message)}}));return t.useEffect((()=>C&&g?R?(r({...h,createWallet:{...h.createWallet,shouldCreateEth:K,shouldCreateSol:V},recoverySelection:{...h?.recoverySelection,isInAccountCreateFlow:!0,shouldCreateEth:K,shouldCreateSol:V}}),q(u.toEmbeddedWalletSetRecoveryScreen({walletAction:"create",showAutomaticRecovery:!1,availableRecoveryMethods:j.userOwnedRecoveryOptions,legacySetWalletPasswordFlow:!1,isResettingPassword:!1}))):void _.execute():(q("LandingScreen"),void f(Error("User must be authenticated before creating a Privy wallet")))),[R,C]),m.current=()=>null/*#__PURE__*/,e.jsx(y,{errorMessage:v||void 0,onClose:()=>{M?(W(M),b({shouldCallAuthOnSuccess:A})):(f(new s.PrivyEmbeddedWalletError("User wallet creation failed")),b({shouldCallAuthOnSuccess:!1}))}})}};exports.EmbeddedWalletOnAccountCreateScreen=h,exports.EmbeddedWalletOnAccountCreateView=y,exports.default=h;
//# sourceMappingURL=EmbeddedWalletOnAccountCreateScreen-BuyuzE2k.js.map
