import{jsxs as e,jsx as r}from"react/jsx-runtime";import o from"@heroicons/react/24/outline/ShieldCheckIcon";import{useState as t,useEffect as i}from"react";import{styled as s,css as a}from"styled-components";import{u as n,f as m}from"./privy-context-Bi6vqCPc.mjs";import{P as c}from"./ModalHeader-DffkxvO4.mjs";import{S as l}from"./Layouts-BlFm53ED.mjs";import{P as p,a as d,I as u,H as h,S as y}from"./shared-nyNh_dA7.mjs";import{m as v}from"./index-C5jxD-zy.mjs";import{k as f}from"./errors-Dd6zfYtp.mjs";import{u as j}from"./internal-context-dfitw7Ot.mjs";import{u as w}from"./modal-context-DBwfUxD-.mjs";import{S as g}from"./Screen-D8KNyGVj.mjs";import"@privy-io/are-addresses-equal";import"./context-BKnOUECq.mjs";import"@privy-io/js-sdk-core";import"tinycolor2";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"zustand";import"react-device-detect";import"./get-entropy-details-for-user-BIWg0YxF.mjs";import"./user-D5cqJNp9.mjs";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"@heroicons/react/24/outline/ArrowPathIcon";import"@heroicons/react/24/outline/EyeIcon";import"@heroicons/react/24/outline/EyeSlashIcon";import"./toViemAccount-4iGGrW4w.mjs";import"jose";import"@coinbase/wallet-sdk";import"@walletconnect/ethereum-provider";import"./pkce-BinverJO.mjs";import"ofetch";import"./paths-BH8W4zMc.mjs";import"./PrivyPluginContext-DA-yS5vO.mjs";import"js-cookie";import"@privy-io/ethereum";import"viem/accounts";import"mipd";import"@scure/base";import"./usePrivy-BhL-ltvm.mjs";import"./use-unlink-wallet-oAguM2-k.mjs";import"@privy-io/popup";import"@headlessui/react";import"@privy-io/urls";import"./getEmbeddedConnectedWallet-Ba6LFHzY.mjs";import"./frame-DtizlaLu.mjs";import"@privy-io/routes";import"./use-deposit-address-BwThybOQ.mjs";import"x402/client";import"@privy-io/api-base";import"./use-sign-with-user-signer-CQI6hUH7.mjs";import"./index-Dq_xe9dz.mjs";const b={component:()=>{let[s,a]=t(!0),{authenticated:c,user:b}=n(),{walletProxy:C,closePrivyModal:I,createAnalyticsEvent:P,client:S}=j(),{navigate:T,data:W,onUserCloseViaDialogOrKeybindRef:_}=w(),[E,R]=t(void 0),[H,M]=t(""),[U,V]=t(!1),{entropyId:N,entropyIdVerifier:O,onCompleteNavigateTo:$,onSuccess:q,onFailure:z}=W.recoverWallet,F=(e="User exited before their wallet could be recovered")=>{I({shouldCallAuthOnSuccess:!1}),z("string"==typeof e?new f(e):e)};_.current=F,i((()=>{if(!c)return F("User must be authenticated and have a Privy wallet before it can be recovered")}),[c]);/*#__PURE__*/return e(g,{children:[/*#__PURE__*/r(g.Header,{icon:o,title:"Enter your password",subtitle:"Please provision your account on this new device. To continue, enter your recovery password.",showClose:!0,onClose:F}),/*#__PURE__*/r(g.Body,{children:/*#__PURE__*/r(x,{children:/*#__PURE__*/e("div",{children:[/*#__PURE__*/e(p,{children:[/*#__PURE__*/r(d,{type:s?"password":"text",onChange:e=>(e=>{e&&R(e)})(e.target.value),disabled:U,style:{paddingRight:"2.3rem"}}),/*#__PURE__*/r(u,{style:{right:"0.75rem"},children:s?/*#__PURE__*/r(h,{onClick:()=>a(!1)}):/*#__PURE__*/r(y,{onClick:()=>a(!0)})})]}),!!H&&/*#__PURE__*/r(k,{children:H})]})})}),/*#__PURE__*/e(g.Footer,{children:[/*#__PURE__*/r(g.HelpText,{children:/*#__PURE__*/e(l,{children:[/*#__PURE__*/r("h4",{children:"Why is this necessary?"}),/*#__PURE__*/r("p",{children:"You previously set a password for this wallet. This helps ensure only you can access it"})]})}),/*#__PURE__*/r(g.Actions,{children:/*#__PURE__*/r(A,{loading:U||!C,disabled:!E,onClick:async()=>{V(!0);let e=await S.getAccessToken(),r=m(b,N);if(!e||!r||null===E)return F("User must be authenticated and have a Privy wallet before it can be recovered");try{P({eventName:"embedded_wallet_recovery_started",payload:{walletAddress:r.address}}),await(C?.recover({accessToken:e,entropyId:N,entropyIdVerifier:O,recoveryPassword:E})),M(""),$?T($):I({shouldCallAuthOnSuccess:!1}),q?.(r),P({eventName:"embedded_wallet_recovery_completed",payload:{walletAddress:r.address}})}catch(e){v(e)?M("Invalid recovery password, please try again."):M("An error has occurred, please try again.")}finally{V(!1)}},$hideAnimations:!N&&U,children:"Recover your account"})}),/*#__PURE__*/r(g.Watermark,{})]})]})}};let x=s.div`
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
`,k=s.div`
  line-height: 20px;
  height: 20px;
  font-size: 13px;
  color: var(--privy-color-error);
  text-align: left;
  margin-top: 0.5rem;
`,A=s(c)`
  ${({$hideAnimations:e})=>e&&a`
      && {
        // Remove animations because the recoverWallet task on the iframe partially
        // blocks the renderer, so the animation stutters and doesn't look good
        transition: none;
      }
    `}
`;export{b as PasswordRecoveryScreen,b as default};
//# sourceMappingURL=PasswordRecoveryScreen-DNWCkbdN.mjs.map
