@privy-io/react-auth
Version:
React client for the Privy Auth API
21 lines (20 loc) • 5.29 kB
JavaScript
"use strict";var e=require("react/jsx-runtime"),r=require("@heroicons/react/24/outline/ShieldCheckIcon"),i=require("react"),t=require("styled-components"),s=require("./get-is-unified-wallet-UpdjHxOV.js"),o=require("./ModalHeader-BCPQgekO.js"),n=require("./Layouts-D3TOcPhm.js"),a=require("./shared-e1wjsjhc.js"),l=require("./index-C8lpxYDX.js"),c=require("./internal-context-BJv4f_bO.js"),u=require("./Screen-BfKedqka.js");function d(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("@privy-io/are-addresses-equal"),require("./context-D-ZJYjUg.js"),require("@privy-io/js-sdk-core"),require("tinycolor2"),require("./useActiveWallet-Cn6zOXx5.js"),require("zustand"),require("react-device-detect"),require("./use-export-wallet-B5ujV5Nk.js"),require("eventemitter3"),require("viem/utils"),require("./useWallets-CKAypPZB.js"),require("./events-context-Di6--rDg.js"),require("viem"),require("./getPublicClient-BsmZyCGX.js"),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("@heroicons/react/24/outline/ArrowPathIcon"),require("@heroicons/react/24/outline/EyeIcon"),require("@heroicons/react/24/outline/EyeSlashIcon"),require("uuid"),require("jose"),require("@coinbase/wallet-sdk"),require("@privy-io/ethereum"),require("mipd"),require("@privy-io/popup"),require("./paths-DizMb-lU.js"),require("./usePrivy-cfS6o4tX.js"),require("@scure/base"),require("@headlessui/react"),require("@walletconnect/ethereum-provider"),require("@privy-io/urls"),require("./PrivyPluginContext-DsgaS6n9.js"),require("./getEmbeddedConnectedWallet-pJd-l936.js"),require("ofetch"),require("js-cookie"),require("./frame-Oz7volks.js"),require("@privy-io/routes"),require("x402/client"),require("@privy-io/api-base"),require("viem/accounts"),require("./use-sign-with-user-signer-Cu_6Bx7m.js"),require("./index-ByFhjjzH.js");var h=/*#__PURE__*/d(r);const y={component:()=>{let[r,t]=i.useState(!0),{authenticated:o,user:d}=s.usePrivyContext(),{walletProxy:y,closePrivyModal:j,createAnalyticsEvent:x,client:m}=c.usePrivyInternal(),{navigate:w,data:f,onUserCloseViaDialogOrKeybindRef:g}=s.usePrivyModal(),[b,I]=i.useState(void 0),[P,S]=i.useState(""),[C,k]=i.useState(!1),{entropyId:A,entropyIdVerifier:W,onCompleteNavigateTo:E,onSuccess:R,onFailure:T}=f.recoverWallet,_=(e="User exited before their wallet could be recovered")=>{j({shouldCallAuthOnSuccess:!1}),T("string"==typeof e?new c.PrivyEmbeddedWalletError(e):e)};g.current=_,i.useEffect((()=>{if(!o)return _("User must be authenticated and have a Privy wallet before it can be recovered")}),[o]);/*#__PURE__*/return e.jsxs(u.Screen,{children:[/*#__PURE__*/e.jsx(u.Screen.Header,{icon:h.default,title:"Enter your password",subtitle:"Please provision your account on this new device. To continue, enter your recovery password.",showClose:!0,onClose:_}),/*#__PURE__*/e.jsx(u.Screen.Body,{children:/*#__PURE__*/e.jsx(v,{children:/*#__PURE__*/e.jsxs("div",{children:[/*#__PURE__*/e.jsxs(a.PasswordContainer,{children:[/*#__PURE__*/e.jsx(a.PasswordInput,{type:r?"password":"text",onChange:e=>(e=>{e&&I(e)})(e.target.value),disabled:C,style:{paddingRight:"2.3rem"}}),/*#__PURE__*/e.jsx(a.InputRightIcons,{style:{right:"0.75rem"},children:r?/*#__PURE__*/e.jsx(a.HiddenIcon,{onClick:()=>t(!1)}):/*#__PURE__*/e.jsx(a.ShownIcon,{onClick:()=>t(!0)})})]}),!!P&&/*#__PURE__*/e.jsx(q,{children:P})]})})}),/*#__PURE__*/e.jsxs(u.Screen.Footer,{children:[/*#__PURE__*/e.jsx(u.Screen.HelpText,{children:/*#__PURE__*/e.jsxs(n.StyledCalloutSection,{children:[/*#__PURE__*/e.jsx("h4",{children:"Why is this necessary?"}),/*#__PURE__*/e.jsx("p",{children:"You previously set a password for this wallet. This helps ensure only you can access it"})]})}),/*#__PURE__*/e.jsx(u.Screen.Actions,{children:/*#__PURE__*/e.jsx(p,{loading:C||!y,disabled:!b,onClick:async()=>{k(!0);let e=await m.getAccessToken(),r=s.getPrivyWalletWithAddress(d,A);if(!e||!r||null===b)return _("User must be authenticated and have a Privy wallet before it can be recovered");try{x({eventName:"embedded_wallet_recovery_started",payload:{walletAddress:r.address}}),await(y?.recover({accessToken:e,entropyId:A,entropyIdVerifier:W,recoveryPassword:b})),S(""),E?w(E):j({shouldCallAuthOnSuccess:!1}),R?.(r),x({eventName:"embedded_wallet_recovery_completed",payload:{walletAddress:r.address}})}catch(e){l.errorIndicatesInvalidRecoveryPassword(e)?S("Invalid recovery password, please try again."):S("An error has occurred, please try again.")}finally{k(!1)}},$hideAnimations:!A&&C,children:"Recover your account"})}),/*#__PURE__*/e.jsx(u.Screen.Watermark,{})]})]})}};let v=t.styled.div`
display: flex;
flex-direction: column;
gap: 1.5rem;
`,q=t.styled.div`
line-height: 20px;
height: 20px;
font-size: 13px;
color: var(--privy-color-error);
text-align: left;
margin-top: 0.5rem;
`,p=t.styled(o.PrimaryButton)`
${({$hideAnimations:e})=>e&&t.css`
&& {
// Remove animations because the recoverWallet task on the iframe partially
// blocks the renderer, so the animation stutters and doesn't look good
transition: none;
}
`}
`;exports.PasswordRecoveryScreen=y,exports.default=y;