@privy-io/react-auth
Version:
React client for the Privy Auth API
2 lines (1 loc) • 4.33 kB
JavaScript
import{jsx as e}from"react/jsx-runtime";import{useState as o,useEffect as r}from"react";import{u as t,a as s,g as a}from"./get-is-unified-wallet-DvKS5IUO.mjs";import{u as i}from"./context-Bycd1SKV.mjs";import{u as n,o as d,m as c}from"./internal-context-e-Eni5bG.mjs";import{g as l}from"./useWallets-D0lpBS44.mjs";import{S as m,g as p}from"./SetWalletPasswordForm-DvgKP4Ez.mjs";import"viem";import"@privy-io/js-sdk-core";import"tinycolor2";import"ofetch";import"@heroicons/react/24/outline/ExclamationTriangleIcon";import"./Layouts-Bmf8DxNP.mjs";import"styled-components";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"./shared-rucIJmk0.mjs";import"@heroicons/react/24/outline/ArrowPathIcon";import"@heroicons/react/24/outline/EyeIcon";import"@heroicons/react/24/outline/EyeSlashIcon";import"./Button-B8mqatRx.mjs";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"./Checkbox-NmGCZeKL.mjs";import"@heroicons/react/24/outline/KeyIcon";import"@heroicons/react/24/solid/CheckCircleIcon";import"fast-password-entropy";import"secure-password-utilities";import"secure-password-utilities/wordlists";import"@heroicons/react/24/outline/ArrowDownTrayIcon";import"@heroicons/react/24/outline/ClipboardDocumentCheckIcon";import"@heroicons/react/24/outline/DocumentDuplicateIcon";import"@heroicons/react/24/solid/XCircleIcon";import"./ScreenHeader-Biz1wq02.mjs";const u={component:()=>{let[u,w]=o(null),[y,h]=o(!1),[v,g]=o(null),[f,M]=o(""),{authenticated:_,user:A}=t(),{client:I,walletProxy:j,refreshSessionAndUser:b,closePrivyModal:C,createAnalyticsEvent:R}=n(),{navigate:P,data:x,onUserCloseViaDialogOrKeybindRef:S}=s(),E=i(),{onSuccess:k,onFailure:D}=x.setWalletPassword,N=a(A),O="user-passcode"===u?.recoveryMethod,L="user-passcode"===N?.recoveryMethod;r((()=>{_||(P("LandingScreen"),D(new d("User must be authenticated before setting a password on a Privy wallet")))}),[_]);let T=()=>v?(D(v),void C({shouldCallAuthOnSuccess:!1})):O?(k(u),void C({shouldCallAuthOnSuccess:!1})):(D(new c("Exited before password was added to wallet")),void C({shouldCallAuthOnSuccess:!1}));S.current=T;/*#__PURE__*/return e(m,{appName:E?.name||"privy",config:{initiatedBy:"user",onCancel:T},error:v?"An error has occurred, please try again.":void 0,buttonLoading:y,buttonHideAnimations:!1,password:f,isResettingPassword:L,onPasswordGenerate:()=>M(p()),onPasswordChange:M,onSubmit:async()=>{O?(k(u),C({shouldCallAuthOnSuccess:!1})):(h(!0),g(null),await(async()=>{let e=await I.getAccessToken();if(e&&A&&N?.address&&f&&j)try{R({eventName:"embedded_wallet_set_recovery_started",payload:{walletAddress:N.address,existingRecoveryMethod:N.recoveryMethod,targetRecoveryMethod:"user-passcode",isResettingPassword:L}});let{entropyId:o,entropyIdVerifier:r}=l(A);if(!(await j.setRecovery({accessToken:e,entropyId:o,entropyIdVerifier:r,recoveryPassword:f,recoveryMethod:"user-passcode"})).entropyId)return g(new c("Error setting password on privy wallet")),void R({eventName:"embedded_wallet_set_recovery_failed",payload:{walletAddress:N.address,existingRecoveryMethod:N.recoveryMethod,targetRecoveryMethod:"user-passcode",isResettingPassword:L,reason:"error setting password"}});let t=await b(),s=a(t);if(!s)return g(new c("Error setting password on privy wallet")),void R({eventName:"embedded_wallet_set_recovery_failed",payload:{walletAddress:N.address,existingRecoveryMethod:N.recoveryMethod,targetRecoveryMethod:"user-passcode",isResettingPassword:L,reason:"wallet disconnected"}});w(s),R({eventName:"embedded_wallet_set_recovery_completed",payload:{walletAddress:N.address,existingRecoveryMethod:N.recoveryMethod,targetRecoveryMethod:"user-passcode",isResettingPassword:L}})}catch(e){console.warn(e),g(e instanceof Error?e:Error("Error setting password on privy wallet")),R({eventName:"embedded_wallet_set_password_failed",payload:{walletAddress:N.address,reason:e}})}})(),h(!1))},onClose:T})}};export{u as EmbeddedWalletPasswordUpdateScreen,u as default};