"use strict";var e=require("react/jsx-runtime"),r=require("react"),t=require("./privy-context-UTJouJ1x.js"),s=require("./context-rs-ygOK2.js"),o=require("./errors-CBapWvRs.js"),i=require("./internal-context-CdsQ3LEl.js"),a=require("./modal-context-BgeioxwT.js"),n=require("./get-entropy-details-for-user-D63rM5_a.js"),d=require("./SetWalletPasswordForm-B0uh0K47.js");require("@privy-io/are-addresses-equal"),require("@privy-io/js-sdk-core"),require("tinycolor2"),require("ofetch"),require("./user-D2oPA-vS.js"),require("zustand"),require("@heroicons/react/24/outline/ExclamationTriangleIcon"),require("./Layouts-D3TOcPhm.js"),require("styled-components"),require("./ModalHeader-Cpls13mi.js"),require("./useActiveWallet-dTc6deka.js"),require("viem/utils"),require("./wallet-connect-BuohfvHK.js"),require("./getPublicClient-CFd_sHBk.js"),require("viem"),require("viem/chains"),require("eventemitter3"),require("./events-context-Di6--rDg.js"),require("./index-Ub4KpwSY.js"),require("react-device-detect"),require("@heroicons/react/24/outline/ArrowLeftIcon"),require("@heroicons/react/24/outline/ArrowRightIcon"),require("@heroicons/react/24/outline/QuestionMarkCircleIcon"),require("@heroicons/react/24/outline/XMarkIcon"),require("./shared-h7omXu55.js"),require("@heroicons/react/24/outline/ArrowPathIcon"),require("@heroicons/react/24/outline/EyeIcon"),require("@heroicons/react/24/outline/EyeSlashIcon"),require("./Checkbox-DzxHC5tk.js"),require("@heroicons/react/24/outline/KeyIcon"),require("@heroicons/react/24/solid/CheckCircleIcon"),require("fast-password-entropy"),require("secure-password-utilities"),require("secure-password-utilities/wordlists"),require("@heroicons/react/24/outline/ArrowDownTrayIcon"),require("@heroicons/react/24/outline/ClipboardDocumentCheckIcon"),require("@heroicons/react/24/outline/DocumentDuplicateIcon"),require("@heroicons/react/24/solid/XCircleIcon"),require("./ScreenHeader-CgYJ5Fmg.js");const c={component:()=>{let[c,l]=r.useState(null),[u,y]=r.useState(!1),[v,w]=r.useState(null),[h,p]=r.useState(""),{authenticated:q,user:g}=t.usePrivyContext(),{client:m,walletProxy:P,refreshSessionAndUser:f,closePrivyModal:j,createAnalyticsEvent:A}=i.usePrivyInternal(),{navigate:E,data:I,onUserCloseViaDialogOrKeybindRef:M}=a.usePrivyModal(),_=s.useAppConfig(),{onSuccess:b,onFailure:x}=I.setWalletPassword,C=t.getPrivyPrimaryWallet(g),S="user-passcode"===c?.recoveryMethod,R="user-passcode"===C?.recoveryMethod;r.useEffect((()=>{q||(E("LandingScreen"),x(new o.PrivyUnauthenticatedError("User must be authenticated before setting a password on a Privy wallet")))}),[q]);let W=()=>v?(x(v),void j({shouldCallAuthOnSuccess:!1})):S?(b(c),void j({shouldCallAuthOnSuccess:!1})):(x(new o.PrivyEmbeddedWalletError("Exited before password was added to wallet")),void j({shouldCallAuthOnSuccess:!1}));M.current=W;/*#__PURE__*/return e.jsx(d.SetWalletPasswordForm,{appName:_?.name||"privy",config:{initiatedBy:"user",onCancel:W},error:v?"An error has occurred, please try again.":void 0,buttonLoading:u,buttonHideAnimations:!1,password:h,isResettingPassword:R,onPasswordGenerate:()=>p(d.generatePassphrase()),onPasswordChange:p,onSubmit:async()=>{S?(b(c),j({shouldCallAuthOnSuccess:!1})):(y(!0),w(null),await(async()=>{let e=await m.getAccessToken();if(e&&g&&C?.address&&h&&P)try{A({eventName:"embedded_wallet_set_recovery_started",payload:{walletAddress:C.address,existingRecoveryMethod:C.recoveryMethod,targetRecoveryMethod:"user-passcode",isResettingPassword:R}});let{entropyId:r,entropyIdVerifier:s}=n.getEntropyDetailsForUser(g);if(!(await P.setRecovery({accessToken:e,entropyId:r,entropyIdVerifier:s,recoveryPassword:h,recoveryMethod:"user-passcode"})).entropyId)return w(new o.PrivyEmbeddedWalletError("Error setting password on privy wallet")),void A({eventName:"embedded_wallet_set_recovery_failed",payload:{walletAddress:C.address,existingRecoveryMethod:C.recoveryMethod,targetRecoveryMethod:"user-passcode",isResettingPassword:R,reason:"error setting password"}});let i=await f(),a=t.getPrivyPrimaryWallet(i);if(!a)return w(new o.PrivyEmbeddedWalletError("Error setting password on privy wallet")),void A({eventName:"embedded_wallet_set_recovery_failed",payload:{walletAddress:C.address,existingRecoveryMethod:C.recoveryMethod,targetRecoveryMethod:"user-passcode",isResettingPassword:R,reason:"wallet disconnected"}});l(a),A({eventName:"embedded_wallet_set_recovery_completed",payload:{walletAddress:C.address,existingRecoveryMethod:C.recoveryMethod,targetRecoveryMethod:"user-passcode",isResettingPassword:R}})}catch(e){console.warn(e),w(e instanceof Error?e:Error("Error setting password on privy wallet")),A({eventName:"embedded_wallet_set_password_failed",payload:{walletAddress:C.address,reason:e}})}})(),y(!1))},onClose:W})}};exports.EmbeddedWalletPasswordUpdateScreen=c,exports.default=c;
//# sourceMappingURL=EmbeddedWalletPasswordUpdateScreen-B2rq5TBh.js.map
