UNPKG

@privy-io/react-auth

Version:

React client for the Privy Auth API

2 lines (1 loc) 4.29 kB
"use strict";var e=require("react/jsx-runtime"),r=require("lucide-react"),t=require("react"),i=require("@privy-io/js-sdk-core"),a=require("./context-D-ZJYjUg.js"),l=require("./index-C8lpxYDX.js"),s=require("./internal-context-BJv4f_bO.js"),o=require("./get-is-unified-wallet-UpdjHxOV.js"),u=require("./ScreenLayout-CMb-Fua0.js");require("tinycolor2"),require("uuid"),require("jose"),require("eventemitter3"),require("./useActiveWallet-Cn6zOXx5.js"),require("zustand"),require("styled-components"),require("react-device-detect"),require("./use-export-wallet-B5ujV5Nk.js"),require("viem/utils"),require("./useWallets-CKAypPZB.js"),require("./events-context-Di6--rDg.js"),require("viem"),require("./getPublicClient-BsmZyCGX.js"),require("@coinbase/wallet-sdk"),require("@privy-io/ethereum"),require("mipd"),require("@privy-io/popup"),require("./paths-DizMb-lU.js"),require("./usePrivy-cfS6o4tX.js"),require("@scure/base"),require("@headlessui/react"),require("@walletconnect/ethereum-provider"),require("@privy-io/urls"),require("./PrivyPluginContext-DsgaS6n9.js"),require("./getEmbeddedConnectedWallet-pJd-l936.js"),require("ofetch"),require("js-cookie"),require("./frame-Oz7volks.js"),require("@privy-io/routes"),require("x402/client"),require("@privy-io/api-base"),require("@privy-io/are-addresses-equal"),require("viem/accounts"),require("./use-sign-with-user-signer-Cu_6Bx7m.js"),require("./ModalHeader-BCPQgekO.js"),require("@heroicons/react/24/outline/ArrowLeftIcon"),require("@heroicons/react/24/outline/ArrowRightIcon"),require("@heroicons/react/24/outline/QuestionMarkCircleIcon"),require("@heroicons/react/24/outline/XMarkIcon"),require("./Screen-BfKedqka.js"),require("./index-ByFhjjzH.js");const n=({errorMessage:t,onClose:i})=>t?/*#__PURE__*/e.jsx(u.ScreenLayout,{title:"Something went wrong",subtitle:t,icon:r.XCircle,iconVariant:"error",primaryCta:{label:"Close",onClick:i},watermark:!0}):/*#__PURE__*/e.jsx(u.ScreenLayout,{title:"Creating your wallet",subtitle:"Please wait...",iconVariant:"loading",watermark:!1}),c={component:()=>{let{setModalData:r,navigate:u,data:c,onUserCloseViaDialogOrKeybindRef:d}=o.usePrivyModal(),q=a.useAppConfig(),[y,h]=t.useState(""),{embeddedWallets:m}=a.useAppConfig(),{authenticated:w,user:v}=o.usePrivyContext(),{closePrivyModal:p,walletProxy:C,client:g}=s.usePrivyInternal(),{onSuccess:b,onFailure:j,callAuthOnSuccessOnClose:S,shouldCreateEth:W,shouldCreateSol:x}=c.createWallet,f="legacy-embedded-wallets-only"===q.embeddedWallets.mode&&!0===q?.embeddedWallets.requireUserOwnedRecoveryOnCreate,[E,A]=t.useState(null),{create:O}=l.useCreateWalletWithoutFallback(),P=W??(!!v&&l.shouldCreateEmbeddedEthWallet(v,q.embeddedWallets.ethereum.createOnLogin)),I=x??(!!v&&l.shouldCreateEmbeddedSolWallet(v,q.embeddedWallets.solana.createOnLogin)),k=new l.RunEffectOnce((async()=>{let e=await g.getAccessToken();if(v&&e&&C)try{let e,r=await i.generateWalletIdempotencyKey(v.id,"ethereum"),t=await i.generateWalletIdempotencyKey(v.id,"solana");if(P&&I)e=await O({chainType:"ethereum",walletIndex:0,latestUser:v,idempotencyKey:r}),e=await O({chainType:"solana",walletIndex:0,latestUser:e.user,idempotencyKey:t});else if(I)e=await O({chainType:"solana",walletIndex:0,latestUser:v,idempotencyKey:t});else{if(!P)return void p({shouldCallAuthOnSuccess:S});e=await O({chainType:"ethereum",walletIndex:0,latestUser:v,idempotencyKey:r})}A(e),u("EmbeddedWalletCreatedScreen")}catch(e){h(e.message)}}));return t.useEffect((()=>w&&v?f?(r({...c,createWallet:{...c.createWallet,shouldCreateEth:P,shouldCreateSol:I},recoverySelection:{...c?.recoverySelection,isInAccountCreateFlow:!0,shouldCreateEth:P,shouldCreateSol:I}}),u(l.toEmbeddedWalletSetRecoveryScreen({walletAction:"create",showAutomaticRecovery:!1,availableRecoveryMethods:m.userOwnedRecoveryOptions,legacySetWalletPasswordFlow:!1,isResettingPassword:!1}))):void k.execute():(u("LandingScreen"),void j(Error("User must be authenticated before creating a Privy wallet")))),[f,w]),d.current=()=>null/*#__PURE__*/,e.jsx(n,{errorMessage:y||void 0,onClose:()=>{E?(b(E),p({shouldCallAuthOnSuccess:S})):(j(new s.PrivyEmbeddedWalletError("User wallet creation failed")),p({shouldCallAuthOnSuccess:!1}))}})}};exports.EmbeddedWalletOnAccountCreateScreen=c,exports.EmbeddedWalletOnAccountCreateView=n,exports.default=c;