import{o as e}from"./rolldown-runtime.js";import{n as t,t as n}from"./jsx-runtime.js";import{Ct as r,Mt as i,Vt as a,j as o,pn as s}from"./useActiveWallet-CEs8euQ3.js";import{k as c}from"./context-Cdw68BC2.js";import{B as l,V as u,j as d,l as f,z as p}from"./index-CKYEOQWW.js";import{x as m}from"./toViemAccount-BywVRwQG.js";import{t as h}from"./PrivyPluginContext-DA-yS5vO.js";import{t as g}from"./modal-context-DHfp-mFQ.js";import{t as _}from"./circle-x.js";import{t as v}from"./ScreenLayout-Dy-3vlz4.js";var y=n(),b=e(t(),1);o();var x=({errorMessage:e,onClose:t})=>(0,y.jsx)(v,e?{title:`Something went wrong`,subtitle:e,icon:_,iconVariant:`error`,primaryCta:{label:`Close`,onClick:t},watermark:!0}:{title:`Creating your wallet`,subtitle:`Please wait...`,iconVariant:`loading`,watermark:!1}),S={component:()=>{let{setModalData:e,navigate:t,data:n,onUserCloseViaDialogOrKeybindRef:o}=g(),_=c(),[v,S]=(0,b.useState)(``),{embeddedWallets:C}=c(),{authenticated:w,user:T}=i(),{closePrivyModal:E,walletProxy:D,client:O}=a(),{onSuccess:k,onFailure:A,callAuthOnSuccessOnClose:j,shouldCreateEth:M,shouldCreateSol:N}=n.createWallet,P=h(),F=T?P(d)?.shouldCreateWallet({user:T}):void 0,I=!!T&&p(T,_.embeddedWallets.ethereum.createOnLogin,F),L=!!T&&l(T,_.embeddedWallets.solana.createOnLogin,F),R=_.embeddedWallets.mode===`legacy-embedded-wallets-only`&&!0===_?.embeddedWallets.requireUserOwnedRecoveryOnCreate,[z,B]=(0,b.useState)(null),{create:V}=u(),H=M??I,U=N??L,W=new m((async()=>{let e=await O.getAccessToken();if(T&&e&&D)try{let e,n=await s(T.id,`ethereum`),r=await s(T.id,`solana`);if(H&&U)e=await V({chainType:`ethereum`,walletIndex:0,latestUser:T,idempotencyKey:n}),e=await V({chainType:`solana`,walletIndex:0,latestUser:e.user,idempotencyKey:r});else if(U)e=await V({chainType:`solana`,walletIndex:0,latestUser:T,idempotencyKey:r});else{if(!H)return void E({shouldCallAuthOnSuccess:j});e=await V({chainType:`ethereum`,walletIndex:0,latestUser:T,idempotencyKey:n})}B(e),t(`EmbeddedWalletCreatedScreen`)}catch(e){S(e.message)}}));return(0,b.useEffect)((()=>w&&T?R?(e({...n,createWallet:{...n.createWallet,shouldCreateEth:H,shouldCreateSol:U},recoverySelection:{...n?.recoverySelection,isInAccountCreateFlow:!0,shouldCreateEth:H,shouldCreateSol:U}}),t(f({walletAction:`create`,showAutomaticRecovery:!1,availableRecoveryMethods:C.userOwnedRecoveryOptions,legacySetWalletPasswordFlow:!1,isResettingPassword:!1}))):void W.execute():(t(`LandingScreen`),void A(Error(`User must be authenticated before creating a Privy wallet`)))),[R,w]),o.current=()=>null,(0,y.jsx)(x,{errorMessage:v||void 0,onClose:()=>{z?(k(z),E({shouldCallAuthOnSuccess:j})):(A(new r(`User wallet creation failed`)),E({shouldCallAuthOnSuccess:!1}))}})}};export{S as EmbeddedWalletOnAccountCreateScreen,S as default,x as EmbeddedWalletOnAccountCreateView};