@privy-io/react-auth
Version:
React client for the Privy Auth API
2 lines (1 loc) • 3.8 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{u as a}from"./context-Bycd1SKV.mjs";import{s as i,k as s,E as l,R as n}from"./index-CCyaupaz.mjs";import{u as m,m as c}from"./internal-context-e-Eni5bG.mjs";import{u as d}from"./use-create-wallet-without-fallback-cSYr4rn8.mjs";import{a as u,u as p}from"./get-is-unified-wallet-DvKS5IUO.mjs";import{S as h}from"./ScreenLayout-CddsD3Of.mjs";import"@privy-io/js-sdk-core";import"tinycolor2";import"uuid";import"jose";import"eventemitter3";import"./useActiveWallet-Bsy5GTCV.mjs";import"zustand";import"styled-components";import"react-device-detect";import"./prepareFundingModalData-CIgFwA7s.mjs";import"./events-context-CI0iqAXA.mjs";import"viem";import"viem/utils";import"./getPublicClient-A9RSftUZ.mjs";import"./useWallets-D0lpBS44.mjs";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"./Button-B8mqatRx.mjs";import"./Screen-BTyXgDrd.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 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)),F=P??(!!S&&s(S,g.embeddedWallets.solana.createOnLogin)),D=new n((async()=>{let e=await O.getAccessToken();if(S&&e&&W)try{let e;if(T&&F)e=await L({chainType:"ethereum",walletIndex:0,latestUser:S}),e=await L({chainType:"solana",walletIndex:0,latestUser:e.user});else if(F)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:F},recoverySelection:{...y?.recoverySelection,isInAccountCreateFlow:!0,shouldCreateEth:T,shouldCreateSol:F}}),h(l({walletAction:"create",showAutomaticRecovery:!1,availableRecoveryMethods:f.userOwnedRecoveryOptions,legacySetWalletPasswordFlow:!1,isResettingPassword:!1}))):void D.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};