UNPKG

@privy-io/react-auth

Version:

React client for the Privy Auth API

15 lines (13 loc) 3.9 kB
"use strict";var e=require("react/jsx-runtime"),r=require("@heroicons/react/24/outline/ExclamationTriangleIcon"),t=require("@heroicons/react/24/outline/LockClosedIcon"),o=require("react"),i=require("./privy-context-CrM9_s6G.js"),n=require("./ModalHeader-C5Wuo3-1.js"),l=require("styled-components"),s=require("./Subtitle-CR8zM7ZJ.js"),a=require("./Title-ifTy35V5.js"),c=require("./context-Cg3IEi80.js"),u=require("./internal-context-BJv4f_bO.js"),d=require("./useActiveWallet-BfMD5hzE.js");function y(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("@privy-io/are-addresses-equal"),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("@privy-io/js-sdk-core"),require("tinycolor2"),require("ofetch"),require("zustand"),require("react-device-detect"),require("./use-export-wallet-_EIyxyle.js"),require("./useWallets-dikDynAG.js"),require("viem"),require("eventemitter3"),require("viem/utils"),require("./events-context-Di6--rDg.js");var h=/*#__PURE__*/y(r),v=/*#__PURE__*/y(t);const f=l.styled.div` && { border-width: 4px; } display: flex; justify-content: center; align-items: center; padding: 1rem; aspect-ratio: 1; border-style: solid; border-color: ${e=>e.$color??"var(--privy-color-accent)"}; border-radius: 50%; `,j={component:()=>{let{user:r}=i.usePrivyContext(),{client:t,walletProxy:l,refreshSessionAndUser:y,closePrivyModal:j}=u.usePrivyInternal(),x=i.usePrivyModal(),{entropyId:m,entropyIdVerifier:q}=x.data?.recoverWallet,[g,p]=o.useState(!1),[w,S]=o.useState(null),[b,I]=o.useState(null);function T(){if(!g){if(b)return x.data?.setWalletPassword?.onFailure(b),void j();if(!w)return x.data?.setWalletPassword?.onFailure(Error("User exited set recovery flow")),void j()}}x.onUserCloseViaDialogOrKeybindRef.current=T;let W=!(!g&&!w);return b?/*#__PURE__*/e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(n.ModalHeader,{onClose:T},"header"),/*#__PURE__*/e.jsx(f,{$color:"var(--privy-color-error)",style:{alignSelf:"center"},children:/*#__PURE__*/e.jsx(h.default,{height:38,width:38,stroke:"var(--privy-color-error)"})}),/*#__PURE__*/e.jsx(a.Title,{style:{marginTop:"0.5rem"},children:"Something went wrong"}),/*#__PURE__*/e.jsx(d.Grow,{style:{minHeight:"2rem"}}),/*#__PURE__*/e.jsx(n.PrimaryButtonWithoutGray,{onClick:()=>I(null),children:"Try again"}),/*#__PURE__*/e.jsx(n.BlobbyFooter,{})]}):/*#__PURE__*/e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(n.ModalHeader,{onClose:T},"header"),/*#__PURE__*/e.jsx(v.default,{style:{width:"3rem",height:"3rem",alignSelf:"center"}}),/*#__PURE__*/e.jsx(a.Title,{style:{marginTop:"0.5rem"},children:"Automatically secure your account"}),/*#__PURE__*/e.jsx(s.Subtitle,{style:{marginTop:"1rem"},children:"When you log into a new device, you’ll only need to authenticate to access your account. Never get logged out if you forget your password."}),/*#__PURE__*/e.jsx(d.Grow,{style:{minHeight:"2rem"}}),/*#__PURE__*/e.jsx(n.PrimaryButtonWithoutGray,{loading:g,disabled:W,onClick:()=>async function(){p(!0);try{let e=await t.getAccessToken(),o=i.getPrivyWalletWithAddress(r,m);if(!e||!l||!o)return;if(!(await l.setRecovery({accessToken:e,entropyId:m,entropyIdVerifier:q,existingRecoveryMethod:o.recoveryMethod,recoveryMethod:"privy"})).entropyId)throw Error("Unable to set recovery on wallet");let n=await y();if(!n)throw Error("Unable to set recovery on wallet");let s=i.getPrivyWalletWithAddress(n,o.address);if(!s)throw Error("Unabled to set recovery on wallet");S(!!n),setTimeout((()=>{x.data?.setWalletPassword?.onSuccess(s),j()}),c.DEFAULT_SUCCESS_SCREEN_DURATION_MS)}catch(e){I(e)}finally{p(!1)}}(),children:w?"Success":"Confirm"}),/*#__PURE__*/e.jsx(n.BlobbyFooter,{})]})}};exports.SetAutomaticRecoveryScreen=j,exports.default=j;