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}from"./useActiveWallet-CEs8euQ3.js";import{k as s}from"./context-Cdw68BC2.js";import{V as c}from"./index-CKYEOQWW.js";import{x as l}from"./toViemAccount-BywVRwQG.js";import{t as u}from"./modal-context-DHfp-mFQ.js";import{n as d,r as f,t as p}from"./SetWalletPasswordForm-C1lINjEc.js";var m=n(),h=e(t(),1);o(),f();var g={component:()=>{let{navigate:e,data:t,onUserCloseViaDialogOrKeybindRef:n}=u(),o=s(),[f,g]=(0,h.useState)(``),[_,v]=(0,h.useState)(!1),[y,b]=(0,h.useState)(),[x,S]=(0,h.useState)(null),{create:C}=c(),{authenticated:w,user:T}=i(),{closePrivyModal:E,isNewUserThisSession:D,initializeWalletProxy:O}=a(),{onSuccess:k,onFailure:A,callAuthOnSuccessOnClose:j,shouldCreateEth:M,shouldCreateSol:N}=t.createWallet,[P,F]=(0,h.useState)(null),I=new l((async()=>{try{let t;if(M&&N)t=await C({recoveryMethod:`user-passcode`,recoveryPassword:y,chainType:`ethereum`,walletIndex:0,latestUser:T}),t=await C({chainType:`solana`,walletIndex:0,latestUser:t.user});else if(N)t=await C({recoveryMethod:`user-passcode`,recoveryPassword:y,chainType:`solana`,walletIndex:0,latestUser:T});else{if(!M)throw Error(`Invalid args to create wallet`);t=await C({recoveryMethod:`user-passcode`,recoveryPassword:y,chainType:`ethereum`,walletIndex:0,latestUser:T})}F(t),D?e(`EmbeddedWalletCreatedScreen`):(k(t),E({shouldCallAuthOnSuccess:j}))}catch(e){g(e.message)}}));return(0,h.useEffect)((()=>{x||O(3e4).then((e=>S(e)))}),[x]),(0,h.useEffect)((()=>{if(!w||!T)return e(`LandingScreen`),void A(Error(`User must be authenticated before creating a Privy wallet`))}),[w]),n.current=()=>null,(0,m.jsx)(d,{config:{initiatedBy:`automatic`},appName:o?.name||`privy`,loading:!x,buttonLoading:_,buttonHideAnimations:!P&&_,isResettingPassword:!1,error:f,password:y||``,onClose:()=>{P&&P.account.recoveryMethod!==`user-passcode`?(A(new r(`User created a wallet but failed to set a password for it`)),E({shouldCallAuthOnSuccess:!1})):P?(k(P),E({shouldCallAuthOnSuccess:j})):(A(new r(`User wallet creation failed`)),E({shouldCallAuthOnSuccess:!1}))},onPasswordChange:b,onPasswordGenerate:()=>b(p()),onSubmit:async()=>(v(!0),I.execute().then((()=>new Promise((e=>setTimeout(e,250))))).finally((()=>v(!1))))})}};export{g as EmbeddedWalletPasswordCreateScreen,g as default};