@privy-io/react-auth
Version:
React client for the Privy Auth API
2 lines (1 loc) • 4.21 kB
JavaScript
import{jsx as e}from"react/jsx-runtime";import{useState as t,useEffect as o}from"react";import{u as r}from"./context-DRLoVlsO.mjs";import{R as i}from"./index-NL2cPmJD.mjs";import{u as s,m as a}from"./internal-context-e-Eni5bG.mjs";import{u as n}from"./use-create-wallet-without-fallback-C0dI_RFZ.mjs";import{a as c,u as l}from"./get-is-unified-wallet-gMDXpX6C.mjs";import{S as m,g as p}from"./SetWalletPasswordForm-vaG_68V0.mjs";import"@privy-io/js-sdk-core";import"tinycolor2";import"uuid";import"jose";import"eventemitter3";import"./useActiveWallet-BeOB3HTh.mjs";import"zustand";import"styled-components";import"react-device-detect";import"./prepareFundingModalData-BVTcQcmw.mjs";import"./events-context-CI0iqAXA.mjs";import"viem";import"viem/utils";import"./getPublicClient-A9RSftUZ.mjs";import"./useWallets-kObl6ZLS.mjs";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"@heroicons/react/24/outline/ExclamationTriangleIcon";import"./Layouts-Bmf8DxNP.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"./shared-D8TfUpfU.mjs";import"@heroicons/react/24/outline/ArrowPathIcon";import"@heroicons/react/24/outline/EyeIcon";import"@heroicons/react/24/outline/EyeSlashIcon";import"./Button-BCV6mjvS.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{navigate:u,data:d,onUserCloseViaDialogOrKeybindRef:h}=c(),w=r(),[y,v]=t(""),[j,f]=t(!1),[g,C]=t(),[I,b]=t(null),{create:x}=n(),{authenticated:S,user:P}=l(),{closePrivyModal:A,isNewUserThisSession:k,initializeWalletProxy:M}=s(),{onSuccess:T,onFailure:U,callAuthOnSuccessOnClose:E,shouldCreateEth:O,shouldCreateSol:W}=d.createWallet,[D,L]=t(null),R=new i((async()=>{try{let e;if(O&&W)e=await x({recoveryMethod:"user-passcode",recoveryPassword:g,chainType:"ethereum",walletIndex:0,latestUser:P}),e=await x({chainType:"solana",walletIndex:0,latestUser:e.user});else if(W)e=await x({recoveryMethod:"user-passcode",recoveryPassword:g,chainType:"solana",walletIndex:0,latestUser:P});else{if(!O)throw Error("Invalid args to create wallet");e=await x({recoveryMethod:"user-passcode",recoveryPassword:g,chainType:"ethereum",walletIndex:0,latestUser:P})}L(e),k?u("EmbeddedWalletCreatedScreen"):(T(e),A({shouldCallAuthOnSuccess:E}))}catch(e){v(e.message)}}));o((()=>{I||M(3e4).then((e=>b(e)))}),[I]),o((()=>{if(!S||!P)return u("LandingScreen"),void U(Error("User must be authenticated before creating a Privy wallet"))}),[S]),h.current=()=>null;/*#__PURE__*/return e(m,{config:{initiatedBy:"automatic"},appName:w?.name||"privy",loading:!I,buttonLoading:j,buttonHideAnimations:!D&&j,isResettingPassword:!1,error:y,password:g||"",onClose:()=>{D&&"user-passcode"!==D.account.recoveryMethod?(U(new a("User created a wallet but failed to set a password for it")),A({shouldCallAuthOnSuccess:!1})):D?(T(D),A({shouldCallAuthOnSuccess:E})):(U(new a("User wallet creation failed")),A({shouldCallAuthOnSuccess:!1}))},onPasswordChange:C,onPasswordGenerate:()=>C(p()),onSubmit:async()=>(f(!0),R.execute().then((()=>new Promise((e=>setTimeout(e,250))))).finally((()=>f(!1))))})}};export{u as EmbeddedWalletPasswordCreateScreen,u as default};