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-DvKS5IUO.mjs";import{P as m}from"./Button-B8mqatRx.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-rucIJmk0.mjs";import{n as f}from"./index-CCyaupaz.mjs";import{u as g,m as w}from"./internal-context-e-Eni5bG.mjs";import{S as j}from"./Screen-BTyXgDrd.mjs";import"viem";import"./context-Bycd1SKV.mjs";import"@privy-io/js-sdk-core";import"tinycolor2";import"./useActiveWallet-Bsy5GTCV.mjs";import"zustand";import"react-device-detect";import"./prepareFundingModalData-CIgFwA7s.mjs";import"eventemitter3";import"./events-context-CI0iqAXA.mjs";import"viem/utils";import"./getPublicClient-A9RSftUZ.mjs";import"./useWallets-D0lpBS44.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-BaiIHGte.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-BLGC-7ev.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:E,onUserCloseViaDialogOrKeybindRef:M}=c(),[T,W]=t(void 0),[_,B]=t(""),[H,R]=t(!1),{entropyId:U,entropyIdVerifier:F,onCompleteNavigateTo:O,onSuccess:V,onFailure:z}=E.recoverWallet,D=(e="User exited before their wallet could be recovered")=>{k({shouldCallAuthOnSuccess:!1}),z("string"==typeof e?new w(e):e)};M.current=D,i((()=>{if(!m)return D("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:D}),/*#__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:H,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:H||!A,disabled:!T,onClick:async()=>{R(!0);let e=await S.getAccessToken(),r=l(b,U);if(!e||!r||null===T)return D("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:U,entropyIdVerifier:F,recoveryPassword:T})),B(""),O?N(O):k({shouldCallAuthOnSuccess:!1}),V?.(r),P({eventName:"embedded_wallet_recovery_completed",payload:{walletAddress:r.address}})}catch(e){f(e)?B("Invalid recovery password, please try again."):B("An error has occurred, please try again.")}finally{R(!1)}},$hideAnimations:!U&&H,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};