import{jsx as e}from"react/jsx-runtime";import{XCircle as t}from"lucide-react";import{useState as r,useEffect as o}from"react";import{generateWalletIdempotencyKey as i}from"@privy-io/js-sdk-core";import{u as a}from"./context-BKnOUECq.mjs";import{R as s}from"./toViemAccount-4iGGrW4w.mjs";import{k as l}from"./errors-Dd6zfYtp.mjs";import{u as m}from"./internal-context-dfitw7Ot.mjs";import{W as n,s as c,g as p,n as d,v as u}from"./index-C5jxD-zy.mjs";import{u as h}from"./modal-context-DBwfUxD-.mjs";import{u as y}from"./privy-context-Bi6vqCPc.mjs";import{u as w}from"./PrivyPluginContext-DA-yS5vO.mjs";import{S as v}from"./ScreenLayout-Caq5mGD8.mjs";import"tinycolor2";import"jose";import"eventemitter3";import"./index-BtwxknTg.mjs";import"zustand";import"viem";import"viem/utils";import"./wallet-connect-58EobR5U.mjs";import"./getPublicClient-D4yNgeGy.mjs";import"viem/chains";import"react-device-detect";import"@coinbase/wallet-sdk";import"@walletconnect/ethereum-provider";import"./pkce-BinverJO.mjs";import"ofetch";import"./paths-BH8W4zMc.mjs";import"js-cookie";import"@privy-io/ethereum";import"viem/accounts";import"mipd";import"@scure/base";import"./usePrivy-BhL-ltvm.mjs";import"./use-unlink-wallet-oAguM2-k.mjs";import"./get-entropy-details-for-user-BIWg0YxF.mjs";import"./user-D5cqJNp9.mjs";import"@privy-io/popup";import"./events-context-BJ75xIIf.mjs";import"styled-components";import"./useActiveWallet-BEfvREjE.mjs";import"@headlessui/react";import"@privy-io/urls";import"./getEmbeddedConnectedWallet-Ba6LFHzY.mjs";import"./frame-DtizlaLu.mjs";import"@privy-io/routes";import"./use-deposit-address-BwThybOQ.mjs";import"x402/client";import"@privy-io/api-base";import"@privy-io/are-addresses-equal";import"./use-sign-with-user-signer-CQI6hUH7.mjs";import"./ModalHeader-DffkxvO4.mjs";import"@heroicons/react/24/outline/ArrowLeftIcon";import"@heroicons/react/24/outline/ArrowRightIcon";import"@heroicons/react/24/outline/QuestionMarkCircleIcon";import"@heroicons/react/24/outline/XMarkIcon";import"./Screen-D8KNyGVj.mjs";import"./index-Dq_xe9dz.mjs";const j=({errorMessage:r,onClose:o})=>/*#__PURE__*/e(v,r?{title:"Something went wrong",subtitle:r,icon:t,iconVariant:"error",primaryCta:{label:"Close",onClick:o},watermark:!0}:{title:"Creating your wallet",subtitle:"Please wait...",iconVariant:"loading",watermark:!1}),f={component:()=>{let{setModalData:t,navigate:v,data:f,onUserCloseViaDialogOrKeybindRef:g}=h(),C=a(),[b,x]=r(""),{embeddedWallets:S}=a(),{authenticated:W,user:k}=y(),{closePrivyModal:A,walletProxy:O,client:P}=m(),{onSuccess:I,onFailure:M,callAuthOnSuccessOnClose:R,shouldCreateEth:U,shouldCreateSol:E}=f.createWallet,T=w(),K=k?T(n)?.shouldCreateWallet({user:k}):void 0,L=!!k&&c(k,C.embeddedWallets.ethereum.createOnLogin,K),V=!!k&&p(k,C.embeddedWallets.solana.createOnLogin,K),q="legacy-embedded-wallets-only"===C.embeddedWallets.mode&&!0===C?.embeddedWallets.requireUserOwnedRecoveryOnCreate,[F,D]=r(null),{create:z}=d(),H=U??L,Q=E??V,X=new s((async()=>{let e=await P.getAccessToken();if(k&&e&&O)try{let e,t=await i(k.id,"ethereum"),r=await i(k.id,"solana");if(H&&Q)e=await z({chainType:"ethereum",walletIndex:0,latestUser:k,idempotencyKey:t}),e=await z({chainType:"solana",walletIndex:0,latestUser:e.user,idempotencyKey:r});else if(Q)e=await z({chainType:"solana",walletIndex:0,latestUser:k,idempotencyKey:r});else{if(!H)return void A({shouldCallAuthOnSuccess:R});e=await z({chainType:"ethereum",walletIndex:0,latestUser:k,idempotencyKey:t})}D(e),v("EmbeddedWalletCreatedScreen")}catch(e){x(e.message)}}));return o((()=>W&&k?q?(t({...f,createWallet:{...f.createWallet,shouldCreateEth:H,shouldCreateSol:Q},recoverySelection:{...f?.recoverySelection,isInAccountCreateFlow:!0,shouldCreateEth:H,shouldCreateSol:Q}}),v(u({walletAction:"create",showAutomaticRecovery:!1,availableRecoveryMethods:S.userOwnedRecoveryOptions,legacySetWalletPasswordFlow:!1,isResettingPassword:!1}))):void X.execute():(v("LandingScreen"),void M(Error("User must be authenticated before creating a Privy wallet")))),[q,W]),g.current=()=>null/*#__PURE__*/,e(j,{errorMessage:b||void 0,onClose:()=>{F?(I(F),A({shouldCallAuthOnSuccess:R})):(M(new l("User wallet creation failed")),A({shouldCallAuthOnSuccess:!1}))}})}};export{f as EmbeddedWalletOnAccountCreateScreen,j as EmbeddedWalletOnAccountCreateView,f as default};
//# sourceMappingURL=EmbeddedWalletOnAccountCreateScreen-D43fjXAr.mjs.map
