UNPKG

@privy-io/react-auth

Version:

React client for the Privy Auth API

2 lines (1 loc) 3.8 kB
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{u as a}from"./context-BOoFAPna.mjs";import{s as i,k as s,E as l,R as n}from"./index-CUao1WyN.mjs";import{u as m,m as c}from"./internal-context-e-Eni5bG.mjs";import{u as d}from"./use-create-wallet-without-fallback-4kJuPNnl.mjs";import{a as u,u as p}from"./get-is-unified-wallet-Ca5aEojK.mjs";import{S as h}from"./ScreenLayout-t3qtbQ3-.mjs";import"@privy-io/js-sdk-core";import"tinycolor2";import"uuid";import"jose";import"eventemitter3";import"./useActiveWallet-BdFIc7_K.mjs";import"zustand";import"styled-components";import"react-device-detect";import"./prepareFundingModalData-CzDMa8gy.mjs";import"./events-context-CI0iqAXA.mjs";import"viem";import"viem/utils";import"./getPublicClient-A9RSftUZ.mjs";import"./useWallets-3r4yfFNg.mjs";import"@coinbase/wallet-sdk";import"@privy-io/ethereum";import"mipd";import"@privy-io/popup";import"./paths-3HW55qZg.mjs";import"./usePrivy-CeQ3C1KS.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"./Button-CrJpeX0e.mjs";import"./Screen-CpIMiJNF.mjs";import"./ModalHeader-YP9pLMEP.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 w=({errorMessage:r,onClose:o})=>/*#__PURE__*/e(h,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}),y={component:()=>{let{setModalData:t,navigate:h,data:y,onUserCloseViaDialogOrKeybindRef:v}=u(),g=a(),[j,C]=r(""),{embeddedWallets:f}=a(),{authenticated:b,user:S}=p(),{closePrivyModal:x,walletProxy:W,client:O}=m(),{onSuccess:k,onFailure:A,callAuthOnSuccessOnClose:I,shouldCreateEth:M,shouldCreateSol:P}=y.createWallet,R="legacy-embedded-wallets-only"===g.embeddedWallets.mode&&!0===g?.embeddedWallets.requireUserOwnedRecoveryOnCreate,[U,E]=r(null),{create:L}=d(),T=M??(!!S&&i(S,g.embeddedWallets.ethereum.createOnLogin)),D=P??(!!S&&s(S,g.embeddedWallets.solana.createOnLogin)),F=new n((async()=>{let e=await O.getAccessToken();if(S&&e&&W)try{let e;if(T&&D)e=await L({chainType:"ethereum",walletIndex:0,latestUser:S}),e=await L({chainType:"solana",walletIndex:0,latestUser:e.user});else if(D)e=await L({chainType:"solana",walletIndex:0,latestUser:S});else{if(!T)return void x({shouldCallAuthOnSuccess:I});e=await L({chainType:"ethereum",walletIndex:0,latestUser:S})}E(e),h("EmbeddedWalletCreatedScreen")}catch(e){C(e.message)}}));return o((()=>b&&S?R?(t({...y,createWallet:{...y.createWallet,shouldCreateEth:T,shouldCreateSol:D},recoverySelection:{...y?.recoverySelection,isInAccountCreateFlow:!0,shouldCreateEth:T,shouldCreateSol:D}}),h(l({walletAction:"create",showAutomaticRecovery:!1,availableRecoveryMethods:f.userOwnedRecoveryOptions,legacySetWalletPasswordFlow:!1,isResettingPassword:!1}))):void F.execute():(h("LandingScreen"),void A(Error("User must be authenticated before creating a Privy wallet")))),[R,b]),v.current=()=>null/*#__PURE__*/,e(w,{errorMessage:j||void 0,onClose:()=>{U?(k(U),x({shouldCallAuthOnSuccess:I})):(A(new c("User wallet creation failed")),x({shouldCallAuthOnSuccess:!1}))}})}};export{y as EmbeddedWalletOnAccountCreateScreen,w as EmbeddedWalletOnAccountCreateView,y as default};