@privy-io/react-auth
Version:
React client for the Privy Auth API
2 lines (1 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-D4ouXJpi.js"),o=require("./Button-Bm_Ft0Dw.js"),n=require("./Layouts-dRL0OSpp.js"),a=require("./shared-CCAyvw5i.js"),c=require("./index-NJrQkxJ7.js"),l=require("./internal-context-NWsAL807.js"),u=require("./Screen-D9Tvi297.js");function d(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("viem"),require("./context-DFq1obBO.js"),require("@privy-io/js-sdk-core"),require("tinycolor2"),require("./useActiveWallet-BOX8xCn9.js"),require("zustand"),require("react-device-detect"),require("./prepareFundingModalData-Cnd6rhhJ.js"),require("eventemitter3"),require("./events-context-Di6--rDg.js"),require("viem/utils"),require("./getPublicClient-CGlodIp_.js"),require("./useWallets-BLFNjTwC.js"),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-CcfSRv1R.js"),require("@scure/base"),require("@headlessui/react"),require("@walletconnect/ethereum-provider"),require("@privy-io/urls"),require("ofetch"),require("js-cookie"),require("./frame-B14fp9oC.js"),require("@privy-io/routes"),require("x402/client"),require("@privy-io/api-base"),require("viem/accounts"),require("./use-sign-with-user-signer-BcAsQTGF.js"),require("./getEmbeddedConnectedWallet-6TsVZJkD.js"),require("./ModalHeader-DB7Tbjwz.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("./index-CRFXS9pP.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:m,client:x}=l.usePrivyInternal(),{navigate:w,data:f,onUserCloseViaDialogOrKeybindRef:g}=s.usePrivyModal(),[I,b]=i.useState(void 0),[C,S]=i.useState(""),[P,A]=i.useState(!1),{entropyId:k,entropyIdVerifier:E,onCompleteNavigateTo:W,onSuccess:M,onFailure:N}=f.recoverWallet,R=(e="User exited before their wallet could be recovered")=>{j({shouldCallAuthOnSuccess:!1}),N("string"==typeof e?new l.PrivyEmbeddedWalletError(e):e)};g.current=R,i.useEffect((()=>{if(!o)return R("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:R}),/*#__PURE__*/e.jsx(u.Screen.Body,{children:/*#__PURE__*/e.jsx(p,{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&&b(e)})(e.target.value),disabled:P,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)})})]}),!!C&&/*#__PURE__*/e.jsx(v,{children:C})]})})}),/*#__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(q,{loading:P||!y,disabled:!I,onClick:async()=>{A(!0);let e=await x.getAccessToken(),r=s.getPrivyWalletWithAddress(d,k);if(!e||!r||null===I)return R("User must be authenticated and have a Privy wallet before it can be recovered");try{m({eventName:"embedded_wallet_recovery_started",payload:{walletAddress:r.address}}),await(y?.recover({accessToken:e,entropyId:k,entropyIdVerifier:E,recoveryPassword:I})),S(""),W?w(W):j({shouldCallAuthOnSuccess:!1}),M?.(r),m({eventName:"embedded_wallet_recovery_completed",payload:{walletAddress:r.address}})}catch(e){c.errorIndicatesInvalidRecoveryPassword(e)?S("Invalid recovery password, please try again."):S("An error has occurred, please try again.")}finally{A(!1)}},$hideAnimations:!k&&P,children:"Recover your account"})}),/*#__PURE__*/e.jsx(u.Screen.Watermark,{})]})]})}};let p=/*#__PURE__*/t.styled.div.withConfig({displayName:"Content",componentId:"sc-1247f710-0"})(["display:flex;flex-direction:column;gap:1.5rem;"]),v=/*#__PURE__*/t.styled.div.withConfig({displayName:"ErrorMessage",componentId:"sc-1247f710-1"})(["line-height:20px;height:20px;font-size:13px;color:var(--privy-color-error);text-align:left;margin-top:0.5rem;"]),q=/*#__PURE__*/t.styled(o.PrimaryButton).withConfig({displayName:"NoAnimationPrimaryButton",componentId:"sc-1247f710-2"})(["",""],(({$hideAnimations:e})=>e&&/*#__PURE__*/t.css(["&&{transition:none;}"])));exports.PasswordRecoveryScreen=y,exports.default=y;