import{jsx as e}from"react/jsx-runtime";import{useState as o,useEffect as r}from"react";import{u as t,g as s}from"./privy-context-Bi6vqCPc.mjs";import{u as i}from"./context-BKnOUECq.mjs";import{l as a,k as n}from"./errors-Dd6zfYtp.mjs";import{u as d}from"./internal-context-dfitw7Ot.mjs";import{u as c}from"./modal-context-DBwfUxD-.mjs";import{g as l}from"./get-entropy-details-for-user-BIWg0YxF.mjs";import{S as m,g as p}from"./SetWalletPasswordForm-DyC3u1As.mjs";import"@privy-io/are-addresses-equal";import"@privy-io/js-sdk-core";import"tinycolor2";import"ofetch";import"./user-D5cqJNp9.mjs";import"zustand";import"@heroicons/react/24/outline/ExclamationTriangleIcon";import"./Layouts-BlFm53ED.mjs";import"styled-components";import"./ModalHeader-DffkxvO4.mjs";import"./useActiveWallet-BEfvREjE.mjs";import"viem/utils";import"./wallet-connect-58EobR5U.mjs";import"./getPublicClient-D4yNgeGy.mjs";import"viem";import"viem/chains";import"eventemitter3";import"./events-context-BJ75xIIf.mjs";import"./index-BtwxknTg.mjs";import"react-device-detect";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"./shared-nyNh_dA7.mjs";import"@heroicons/react/24/outline/ArrowPathIcon";import"@heroicons/react/24/outline/EyeIcon";import"@heroicons/react/24/outline/EyeSlashIcon";import"./Checkbox-BhNoOKjX.mjs";import"@heroicons/react/24/outline/KeyIcon";import"@heroicons/react/24/solid/CheckCircleIcon";import"fast-password-entropy";import"secure-password-utilities";import"secure-password-utilities/wordlists";import"@heroicons/react/24/outline/ArrowDownTrayIcon";import"@heroicons/react/24/outline/ClipboardDocumentCheckIcon";import"@heroicons/react/24/outline/DocumentDuplicateIcon";import"@heroicons/react/24/solid/XCircleIcon";import"./ScreenHeader-CHmc4-Lu.mjs";const u={component:()=>{let[u,y]=o(null),[w,h]=o(!1),[v,g]=o(null),[f,j]=o(""),{authenticated:_,user:A}=t(),{client:I,walletProxy:M,refreshSessionAndUser:x,closePrivyModal:C,createAnalyticsEvent:R}=d(),{navigate:b,data:P,onUserCloseViaDialogOrKeybindRef:S}=c(),E=i(),{onSuccess:k,onFailure:N}=P.setWalletPassword,D=s(A),O="user-passcode"===u?.recoveryMethod,L="user-passcode"===D?.recoveryMethod;r((()=>{_||(b("LandingScreen"),N(new a("User must be authenticated before setting a password on a Privy wallet")))}),[_]);let T=()=>v?(N(v),void C({shouldCallAuthOnSuccess:!1})):O?(k(u),void C({shouldCallAuthOnSuccess:!1})):(N(new n("Exited before password was added to wallet")),void C({shouldCallAuthOnSuccess:!1}));S.current=T;/*#__PURE__*/return e(m,{appName:E?.name||"privy",config:{initiatedBy:"user",onCancel:T},error:v?"An error has occurred, please try again.":void 0,buttonLoading:w,buttonHideAnimations:!1,password:f,isResettingPassword:L,onPasswordGenerate:()=>j(p()),onPasswordChange:j,onSubmit:async()=>{O?(k(u),C({shouldCallAuthOnSuccess:!1})):(h(!0),g(null),await(async()=>{let e=await I.getAccessToken();if(e&&A&&D?.address&&f&&M)try{R({eventName:"embedded_wallet_set_recovery_started",payload:{walletAddress:D.address,existingRecoveryMethod:D.recoveryMethod,targetRecoveryMethod:"user-passcode",isResettingPassword:L}});let{entropyId:o,entropyIdVerifier:r}=l(A);if(!(await M.setRecovery({accessToken:e,entropyId:o,entropyIdVerifier:r,recoveryPassword:f,recoveryMethod:"user-passcode"})).entropyId)return g(new n("Error setting password on privy wallet")),void R({eventName:"embedded_wallet_set_recovery_failed",payload:{walletAddress:D.address,existingRecoveryMethod:D.recoveryMethod,targetRecoveryMethod:"user-passcode",isResettingPassword:L,reason:"error setting password"}});let t=await x(),i=s(t);if(!i)return g(new n("Error setting password on privy wallet")),void R({eventName:"embedded_wallet_set_recovery_failed",payload:{walletAddress:D.address,existingRecoveryMethod:D.recoveryMethod,targetRecoveryMethod:"user-passcode",isResettingPassword:L,reason:"wallet disconnected"}});y(i),R({eventName:"embedded_wallet_set_recovery_completed",payload:{walletAddress:D.address,existingRecoveryMethod:D.recoveryMethod,targetRecoveryMethod:"user-passcode",isResettingPassword:L}})}catch(e){console.warn(e),g(e instanceof Error?e:Error("Error setting password on privy wallet")),R({eventName:"embedded_wallet_set_password_failed",payload:{walletAddress:D.address,reason:e}})}})(),h(!1))},onClose:T})}};export{u as EmbeddedWalletPasswordUpdateScreen,u as default};
//# sourceMappingURL=EmbeddedWalletPasswordUpdateScreen-DlJH2cRY.mjs.map
