UNPKG

@privy-io/react-auth

Version:

React client for the Privy Auth API

2 lines (1 loc) 4.79 kB
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,a as c,h as l}from"./get-is-unified-wallet-gMDXpX6C.mjs";import{P as m}from"./Button-BCV6mjvS.mjs";import{S as d}from"./Layouts-Bmf8DxNP.mjs";import{P as p,a as u,I as h,H as y,S as v}from"./shared-D8TfUpfU.mjs";import{n as f}from"./index-NL2cPmJD.mjs";import{u as g,m as w}from"./internal-context-e-Eni5bG.mjs";import{S as j}from"./Screen-_0H_rCdH.mjs";import"viem";import"./context-DRLoVlsO.mjs";import"@privy-io/js-sdk-core";import"tinycolor2";import"./useActiveWallet-BeOB3HTh.mjs";import"zustand";import"react-device-detect";import"./prepareFundingModalData-BVTcQcmw.mjs";import"eventemitter3";import"./events-context-CI0iqAXA.mjs";import"viem/utils";import"./getPublicClient-A9RSftUZ.mjs";import"./useWallets-kObl6ZLS.mjs";import"@heroicons/react/24/outline/ArrowPathIcon";import"@heroicons/react/24/outline/EyeIcon";import"@heroicons/react/24/outline/EyeSlashIcon";import"uuid";import"jose";import"@coinbase/wallet-sdk";import"@privy-io/ethereum";import"mipd";import"@privy-io/popup";import"./paths-3HW55qZg.mjs";import"./usePrivy-BWtc2XF-.mjs";import"@scure/base";import"@headlessui/react";import"@walletconnect/ethereum-provider";import"@privy-io/urls";import"ofetch";import"js-cookie";import"./frame-CwE9r3cT.mjs";import"@privy-io/routes";import"x402/client";import"@privy-io/api-base";import"viem/accounts";import"./use-sign-with-user-signer-eEm9Olt_.mjs";import"./getEmbeddedConnectedWallet-CM6cDQCS.mjs";import"./ModalHeader-BTru6YQw.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"./index-CJMgUOnw.mjs";const b={component:()=>{let[s,a]=t(!0),{authenticated:m,user:b}=n(),{walletProxy:A,closePrivyModal:k,createAnalyticsEvent:P,client:S}=g(),{navigate:N,data:T,onUserCloseViaDialogOrKeybindRef:E}=c(),[M,W]=t(void 0),[_,H]=t(""),[R,U]=t(!1),{entropyId:B,entropyIdVerifier:D,onCompleteNavigateTo:F,onSuccess:O,onFailure:V}=T.recoverWallet,z=(e="User exited before their wallet could be recovered")=>{k({shouldCallAuthOnSuccess:!1}),V("string"==typeof e?new w(e):e)};E.current=z,i((()=>{if(!m)return z("User must be authenticated and have a Privy wallet before it can be recovered")}),[m]);/*#__PURE__*/return e(j,{children:[/*#__PURE__*/r(j.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:z}),/*#__PURE__*/r(j.Body,{children:/*#__PURE__*/r(C,{children:/*#__PURE__*/e("div",{children:[/*#__PURE__*/e(p,{children:[/*#__PURE__*/r(u,{type:s?"password":"text",onChange:e=>(e=>{e&&W(e)})(e.target.value),disabled:R,style:{paddingRight:"2.3rem"}}),/*#__PURE__*/r(h,{style:{right:"0.75rem"},children:s?/*#__PURE__*/r(y,{onClick:()=>a(!1)}):/*#__PURE__*/r(v,{onClick:()=>a(!0)})})]}),!!_&&/*#__PURE__*/r(x,{children:_})]})})}),/*#__PURE__*/e(j.Footer,{children:[/*#__PURE__*/r(j.HelpText,{children:/*#__PURE__*/e(d,{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(j.Actions,{children:/*#__PURE__*/r(I,{loading:R||!A,disabled:!M,onClick:async()=>{U(!0);let e=await S.getAccessToken(),r=l(b,B);if(!e||!r||null===M)return z("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(A?.recover({accessToken:e,entropyId:B,entropyIdVerifier:D,recoveryPassword:M})),H(""),F?N(F):k({shouldCallAuthOnSuccess:!1}),O?.(r),P({eventName:"embedded_wallet_recovery_completed",payload:{walletAddress:r.address}})}catch(e){f(e)?H("Invalid recovery password, please try again."):H("An error has occurred, please try again.")}finally{U(!1)}},$hideAnimations:!B&&R,children:"Recover your account"})}),/*#__PURE__*/r(j.Watermark,{})]})]})}};let C=/*#__PURE__*/s.div.withConfig({displayName:"Content",componentId:"sc-1247f710-0"})(["display:flex;flex-direction:column;gap:1.5rem;"]),x=/*#__PURE__*/s.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;"]),I=/*#__PURE__*/s(m).withConfig({displayName:"NoAnimationPrimaryButton",componentId:"sc-1247f710-2"})(["",""],(({$hideAnimations:e})=>e&&/*#__PURE__*/a(["&&{transition:none;}"])));export{b as PasswordRecoveryScreen,b as default};