UNPKG

@privy-io/react-auth

Version:

React client for the Privy Auth API

2 lines (1 loc) 4.62 kB
import{jsx as e}from"react/jsx-runtime";import{useState as t,useEffect as r}from"react";import{a as o,m as i,C as a}from"./index-CCyaupaz.mjs";import{u as s,q as n}from"./context-Bycd1SKV.mjs";import{u as m,b as l,k as c}from"./internal-context-e-Eni5bG.mjs";import{u as d,a as u}from"./get-is-unified-wallet-DvKS5IUO.mjs";import{s as p}from"./shouldProceedtoEmbeddedWalletCreationFlow-Djgu4xiS.mjs";import{S as g}from"./ScreenLayout-CddsD3Of.mjs";import{T as v}from"./telegram-B-JqnkqZ.mjs";import"@privy-io/js-sdk-core";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"tinycolor2";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 y=({success:t,errorMessage:r,onRetry:o})=>{let i=t?"Successfully connected with Telegram":r?r.message:"Verifying connection to Telegram";/*#__PURE__*/return e(g,{title:i,subtitle:t?"You're good to go!":r?r.detail:"Just a few moments more",icon:v,iconVariant:"loading",iconLoadingStatus:{success:t,fail:!!r},secondaryCta:r?.retryable&&o?{label:"Retry",onClick:o}:void 0,watermark:!0})},h={component:()=>{let{authenticated:g,logout:v,ready:h,user:f}=d(),{setModalData:A,navigate:b,resetNavigation:j,data:T}=u(),S=s(),{initLoginWithTelegram:C,loginWithTelegram:w,updateWallets:E,setReadyToTrue:R,closePrivyModal:W,createAnalyticsEvent:_,getAuthMeta:M}=m(),[k,L]=t(!1),[I,x]=t(void 0),D=o();async function U(){try{let e=await async function(){let e;if(!g){if(D.enabled&&"error"===D.status)throw new a(D.error,null,l.CAPTCHA_FAILURE);return D.enabled&&"success"!==D.status&&(D.execute(),e=await D.waitForResult()),e}}();await w({captchaToken:e}),L(!0),R(!0)}catch(e){if(e?.privyErrorCode===l.ALLOWLIST_REJECTED)return x(void 0),j(),void b("AllowlistRejectionScreen");if(e?.privyErrorCode===l.USER_LIMIT_REACHED)return console.error(new c(e).toString()),x(void 0),j(),void b("UserLimitReachedScreen");if(e?.privyErrorCode===l.USER_DOES_NOT_EXIST)return x(void 0),j(),void b("AccountNotFoundScreen");if(e?.privyErrorCode===l.ACCOUNT_TRANSFER_REQUIRED&&e.data?.data?.nonce)return x(void 0),j(),A({accountTransfer:{nonce:e.data?.data?.nonce,account:e.data?.data?.subject,telegramAuthResult:M()?.telegramAuthResult,telegramWebAppData:M()?.telegramWebAppData,displayName:e.data?.data?.account?.displayName,linkMethod:"telegram",embeddedWalletAddress:e.data?.data?.otherUser?.embeddedWalletAddress}}),void b("LinkConflictScreen");let{retryable:t,detail:r}=i(e);x({retryable:t,detail:r,message:"Authentication failed"})}}r((()=>{U()}),[]),r((()=>{if(!(h&&g&&k&&f))return;if(S?.legal.requireUsersAcceptTerms&&!f.hasAcceptedTerms){let e=setTimeout((()=>{b("AffirmativeConsentScreen")}),n);return()=>clearTimeout(e)}if(p(f,S.embeddedWallets)){let e=setTimeout((()=>{A({createWallet:{onSuccess:()=>{},onFailure:e=>{console.error(e),_({eventName:"embedded_wallet_creation_failure_logout",payload:{error:e,provider:"telegram",screen:"TelegramAuthScreen"}}),v()},callAuthOnSuccessOnClose:!0}}),b("EmbeddedWalletOnAccountCreateScreen")}),n);return()=>clearTimeout(e)}E();let e=setTimeout((()=>W({shouldCallAuthOnSuccess:!0,isSuccess:!0})),n);return()=>clearTimeout(e)}),[h,g,k,f]);/*#__PURE__*/return e(y,{success:k,errorMessage:I,onRetry:I?.retryable?async()=>{try{x(void 0),T?.telegramAuthModalData?.seamlessAuth||await C(void 0,T?.login?.disableSignup),await U()}catch(e){let{retryable:t,detail:r}=i(e);x({retryable:t,detail:r,message:"Authentication failed"})}}:void 0})},isCaptchaRequired:!0,isShownBeforeReady:!0};export{h as TelegramAuthScreen,y as TelegramAuthScreenView,h as default};