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,ht as o,j as s,jt as c}from"./useActiveWallet-CEs8euQ3.js";import{k as l}from"./context-Cdw68BC2.js";import{r as u}from"./get-entropy-details-for-user-Bq7nAeEf.js";import{t as d}from"./modal-context-DHfp-mFQ.js";import{n as f,r as p,t as m}from"./SetWalletPasswordForm-C1lINjEc.js";var h=n(),g=e(t(),1);s(),p();var _={component:()=>{let[e,t]=(0,g.useState)(null),[n,s]=(0,g.useState)(!1),[p,_]=(0,g.useState)(null),[v,y]=(0,g.useState)(``),{authenticated:b,user:x}=i(),{client:S,walletProxy:C,refreshSessionAndUser:w,closePrivyModal:T,createAnalyticsEvent:E}=a(),{navigate:D,data:O,onUserCloseViaDialogOrKeybindRef:k}=d(),A=l(),{onSuccess:j,onFailure:M}=O.setWalletPassword,N=c(x),P=e?.recoveryMethod===`user-passcode`,F=N?.recoveryMethod===`user-passcode`;(0,g.useEffect)((()=>{b||(D(`LandingScreen`),M(new o(`User must be authenticated before setting a password on a Privy wallet`)))}),[b]);let I=()=>p?(M(p),void T({shouldCallAuthOnSuccess:!1})):P?(j(e),void T({shouldCallAuthOnSuccess:!1})):(M(new r(`Exited before password was added to wallet`)),void T({shouldCallAuthOnSuccess:!1}));return k.current=I,(0,h.jsx)(f,{appName:A?.name||`privy`,config:{initiatedBy:`user`,onCancel:I},error:p?`An error has occurred, please try again.`:void 0,buttonLoading:n,buttonHideAnimations:!1,password:v,isResettingPassword:F,onPasswordGenerate:()=>y(m()),onPasswordChange:y,onSubmit:async()=>{P?(j(e),T({shouldCallAuthOnSuccess:!1})):(s(!0),_(null),await(async()=>{let e=await S.getAccessToken();if(e&&x&&N?.address&&v&&C)try{E({eventName:`embedded_wallet_set_recovery_started`,payload:{walletAddress:N.address,existingRecoveryMethod:N.recoveryMethod,targetRecoveryMethod:`user-passcode`,isResettingPassword:F}});let{entropyId:n,entropyIdVerifier:i}=u(x);if(!(await C.setRecovery({accessToken:e,entropyId:n,entropyIdVerifier:i,recoveryPassword:v,recoveryMethod:`user-passcode`})).entropyId)return _(new r(`Error setting password on privy wallet`)),void E({eventName:`embedded_wallet_set_recovery_failed`,payload:{walletAddress:N.address,existingRecoveryMethod:N.recoveryMethod,targetRecoveryMethod:`user-passcode`,isResettingPassword:F,reason:`error setting password`}});let a=await w(),o=c(a);if(!o)return _(new r(`Error setting password on privy wallet`)),void E({eventName:`embedded_wallet_set_recovery_failed`,payload:{walletAddress:N.address,existingRecoveryMethod:N.recoveryMethod,targetRecoveryMethod:`user-passcode`,isResettingPassword:F,reason:`wallet disconnected`}});t(o),E({eventName:`embedded_wallet_set_recovery_completed`,payload:{walletAddress:N.address,existingRecoveryMethod:N.recoveryMethod,targetRecoveryMethod:`user-passcode`,isResettingPassword:F}})}catch(e){console.warn(e),_(e instanceof Error?e:Error(`Error setting password on privy wallet`)),E({eventName:`embedded_wallet_set_password_failed`,payload:{walletAddress:N.address,reason:e}})}})(),s(!1))},onClose:I})}};export{_ as EmbeddedWalletPasswordUpdateScreen,_ as default};