UNPKG

@privy-io/react-auth

Version:

React client for the Privy Auth API

15 lines (13 loc) 3.5 kB
import{jsxs as e,Fragment as r,jsx as o}from"react/jsx-runtime";import t from"@heroicons/react/24/outline/ExclamationTriangleIcon";import i from"@heroicons/react/24/outline/LockClosedIcon";import{useState as n}from"react";import{u as l,a,h as s}from"./get-is-unified-wallet-Boa8DYrQ.mjs";import{M as c,c as m,B as d}from"./ModalHeader-D8-mhjp4.mjs";import{styled as p}from"styled-components";import{S as u}from"./Subtitle-CV-2yKE4.mjs";import{T as y}from"./Title-BnzYV3Is.mjs";import{q as h}from"./context-WTldtXS8.mjs";import{u as f}from"./internal-context-Z-fyxadS.mjs";import{Y as v}from"./useActiveWallet-3RHPIBxJ.mjs";import"@privy-io/are-addresses-equal";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"@privy-io/js-sdk-core";import"tinycolor2";import"ofetch";import"zustand";import"react-device-detect";import"./use-export-wallet-CV4p7L0b.mjs";import"eventemitter3";import"viem/utils";import"./useWallets-CR0z5IIt.mjs";import"./events-context-CI0iqAXA.mjs";import"viem";import"./getPublicClient-B4uPLKn-.mjs";const g=p.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%; `,w={component:()=>{let{user:p}=l(),{client:w,walletProxy:j,refreshSessionAndUser:x,closePrivyModal:b}=f(),I=a(),{entropyId:T,entropyIdVerifier:k}=I.data?.recoverWallet,[C,M]=n(!1),[S,W]=n(null),[A,P]=n(null);function U(){if(!C){if(A)return I.data?.setWalletPassword?.onFailure(A),void b();if(!S)return I.data?.setWalletPassword?.onFailure(Error("User exited set recovery flow")),void b()}}I.onUserCloseViaDialogOrKeybindRef.current=U;let E=!(!C&&!S);/*#__PURE__*/return e(r,A?{children:[/*#__PURE__*/o(c,{onClose:U},"header"),/*#__PURE__*/o(g,{$color:"var(--privy-color-error)",style:{alignSelf:"center"},children:/*#__PURE__*/o(t,{height:38,width:38,stroke:"var(--privy-color-error)"})}),/*#__PURE__*/o(y,{style:{marginTop:"0.5rem"},children:"Something went wrong"}),/*#__PURE__*/o(v,{style:{minHeight:"2rem"}}),/*#__PURE__*/o(m,{onClick:()=>P(null),children:"Try again"}),/*#__PURE__*/o(d,{})]}:{children:[/*#__PURE__*/o(c,{onClose:U},"header"),/*#__PURE__*/o(i,{style:{width:"3rem",height:"3rem",alignSelf:"center"}}),/*#__PURE__*/o(y,{style:{marginTop:"0.5rem"},children:"Automatically secure your account"}),/*#__PURE__*/o(u,{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__*/o(v,{style:{minHeight:"2rem"}}),/*#__PURE__*/o(m,{loading:C,disabled:E,onClick:()=>async function(){M(!0);try{let e=await w.getAccessToken(),r=s(p,T);if(!e||!j||!r)return;if(!(await j.setRecovery({accessToken:e,entropyId:T,entropyIdVerifier:k,existingRecoveryMethod:r.recoveryMethod,recoveryMethod:"privy"})).entropyId)throw Error("Unable to set recovery on wallet");let o=await x();if(!o)throw Error("Unable to set recovery on wallet");let t=s(o,r.address);if(!t)throw Error("Unabled to set recovery on wallet");W(!!o),setTimeout((()=>{I.data?.setWalletPassword?.onSuccess(t),b()}),h)}catch(e){P(e)}finally{M(!1)}}(),children:S?"Success":"Confirm"}),/*#__PURE__*/o(d,{})]})}};export{w as SetAutomaticRecoveryScreen,w as default};