@privy-io/react-auth
Version:
React client for the Privy Auth API
2 lines (1 loc) • 3.97 kB
JavaScript
import{jsx as e}from"react/jsx-runtime";import{XCircle as t}from"lucide-react";import{useState as r,useEffect as o}from"react";import{generateWalletIdempotencyKey as a}from"@privy-io/js-sdk-core";import{u as i}from"./context-DLtU3JQy.mjs";import{F as s,s as l,k as n,v as m,G as c,R as d}from"./index-YDEix4mU.mjs";import{u as p,m as u}from"./internal-context-Z-fyxadS.mjs";import{a as h,u as y}from"./privy-context-DrMxzgOR.mjs";import{u as w}from"./PrivyPluginContext-2QN2dVUw.mjs";import{S as v}from"./ScreenLayout-D1p_ntex.mjs";import"tinycolor2";import"uuid";import"jose";import"eventemitter3";import"./useActiveWallet-CvP7iYvj.mjs";import"zustand";import"styled-components";import"react-device-detect";import"./use-export-wallet-_wu5ex5t.mjs";import"./useWallets-BzNCTucF.mjs";import"viem";import"viem/utils";import"./events-context-CI0iqAXA.mjs";import"@coinbase/wallet-sdk";import"@privy-io/ethereum";import"mipd";import"@privy-io/popup";import"./paths-3HW55qZg.mjs";import"./usePrivy-C_sY2Duk.mjs";import"@scure/base";import"@headlessui/react";import"@walletconnect/ethereum-provider";import"@privy-io/urls";import"./getEmbeddedConnectedWallet-JzK4iD-L.mjs";import"ofetch";import"js-cookie";import"./frame-uzTmvtww.mjs";import"@privy-io/routes";import"x402/client";import"@privy-io/api-base";import"@privy-io/are-addresses-equal";import"viem/accounts";import"./use-sign-with-user-signer-Do5Oi_rb.mjs";import"./ModalHeader-BnVmXtvG.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"./Screen-Cycy3IzT.mjs";import"./index-Dq_xe9dz.mjs";const C=({errorMessage:r,onClose:o})=>/*#__PURE__*/e(v,r?{title:"Something went wrong",subtitle:r,icon:t,iconVariant:"error",primaryCta:{label:"Close",onClick:o},watermark:!0}:{title:"Creating your wallet",subtitle:"Please wait...",iconVariant:"loading",watermark:!1}),j={component:()=>{let{setModalData:t,navigate:v,data:j,onUserCloseViaDialogOrKeybindRef:f}=h(),g=i(),[b,x]=r(""),{embeddedWallets:S}=i(),{authenticated:W,user:O}=y(),{closePrivyModal:A,walletProxy:k,client:I}=p(),{onSuccess:P,onFailure:M,callAuthOnSuccessOnClose:R,shouldCreateEth:U,shouldCreateSol:E}=j.createWallet,L=w(),F=O?L(s)?.shouldCreateWallet({user:O}):void 0,K=!!O&&l(O,g.embeddedWallets.ethereum.createOnLogin,F),T=!!O&&n(O,g.embeddedWallets.solana.createOnLogin,F),V="legacy-embedded-wallets-only"===g.embeddedWallets.mode&&!0===g?.embeddedWallets.requireUserOwnedRecoveryOnCreate,[q,D]=r(null),{create:G}=m(),z=U??K,H=E??T,Q=new d((async()=>{let e=await I.getAccessToken();if(O&&e&&k)try{let e,t=await a(O.id,"ethereum"),r=await a(O.id,"solana");if(z&&H)e=await G({chainType:"ethereum",walletIndex:0,latestUser:O,idempotencyKey:t}),e=await G({chainType:"solana",walletIndex:0,latestUser:e.user,idempotencyKey:r});else if(H)e=await G({chainType:"solana",walletIndex:0,latestUser:O,idempotencyKey:r});else{if(!z)return void A({shouldCallAuthOnSuccess:R});e=await G({chainType:"ethereum",walletIndex:0,latestUser:O,idempotencyKey:t})}D(e),v("EmbeddedWalletCreatedScreen")}catch(e){x(e.message)}}));return o((()=>W&&O?V?(t({...j,createWallet:{...j.createWallet,shouldCreateEth:z,shouldCreateSol:H},recoverySelection:{...j?.recoverySelection,isInAccountCreateFlow:!0,shouldCreateEth:z,shouldCreateSol:H}}),v(c({walletAction:"create",showAutomaticRecovery:!1,availableRecoveryMethods:S.userOwnedRecoveryOptions,legacySetWalletPasswordFlow:!1,isResettingPassword:!1}))):void Q.execute():(v("LandingScreen"),void M(Error("User must be authenticated before creating a Privy wallet")))),[V,W]),f.current=()=>null/*#__PURE__*/,e(C,{errorMessage:b||void 0,onClose:()=>{q?(P(q),A({shouldCallAuthOnSuccess:R})):(M(new u("User wallet creation failed")),A({shouldCallAuthOnSuccess:!1}))}})}};export{j as EmbeddedWalletOnAccountCreateScreen,C as EmbeddedWalletOnAccountCreateView,j as default};