import{jsx as e}from"react/jsx-runtime";import{useState as t,useEffect as r}from"react";import{a as o,l as i,C as a}from"./index-C5jxD-zy.mjs";import{u as s,r as m}from"./context-BKnOUECq.mjs";import{a as n,j as l}from"./errors-Dd6zfYtp.mjs";import{u as c}from"./internal-context-dfitw7Ot.mjs";import{u as d}from"./modal-context-DBwfUxD-.mjs";import{u}from"./privy-context-Bi6vqCPc.mjs";import{s as p}from"./shouldProceedtoEmbeddedWalletCreationFlow-SyjOJUom.mjs";import{S as v}from"./ScreenLayout-Caq5mGD8.mjs";import{T as y}from"./telegram-B-JqnkqZ.mjs";import"@privy-io/js-sdk-core";import"./toViemAccount-4iGGrW4w.mjs";import"jose";import"eventemitter3";import"./index-BtwxknTg.mjs";import"zustand";import"viem";import"viem/utils";import"./wallet-connect-58EobR5U.mjs";import"./getPublicClient-D4yNgeGy.mjs";import"viem/chains";import"react-device-detect";import"@coinbase/wallet-sdk";import"@walletconnect/ethereum-provider";import"./pkce-BinverJO.mjs";import"ofetch";import"./paths-BH8W4zMc.mjs";import"./PrivyPluginContext-DA-yS5vO.mjs";import"js-cookie";import"@privy-io/ethereum";import"viem/accounts";import"mipd";import"@scure/base";import"./usePrivy-BhL-ltvm.mjs";import"./use-unlink-wallet-oAguM2-k.mjs";import"./get-entropy-details-for-user-BIWg0YxF.mjs";import"./user-D5cqJNp9.mjs";import"@privy-io/popup";import"./events-context-BJ75xIIf.mjs";import"styled-components";import"./useActiveWallet-BEfvREjE.mjs";import"@headlessui/react";import"@privy-io/urls";import"./getEmbeddedConnectedWallet-Ba6LFHzY.mjs";import"./frame-DtizlaLu.mjs";import"@privy-io/routes";import"./use-deposit-address-BwThybOQ.mjs";import"x402/client";import"@privy-io/api-base";import"@privy-io/are-addresses-equal";import"./use-sign-with-user-signer-CQI6hUH7.mjs";import"tinycolor2";import"./ModalHeader-DffkxvO4.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-D8KNyGVj.mjs";import"./index-Dq_xe9dz.mjs";const g=({success:t,errorMessage:r,onRetry:o})=>{let i=t?"Successfully connected with Telegram":r?r.message:"Verifying connection to Telegram";/*#__PURE__*/return e(v,{title:i,subtitle:t?"You're good to go!":r?r.detail:"Just a few moments more",icon:y,iconVariant:"loading",iconLoadingStatus:{success:t,fail:!!r},secondaryCta:r?.retryable&&o?{label:"Retry",onClick:o}:void 0,watermark:!0})},f={component:()=>{let{authenticated:v,logout:y,ready:f,user:h}=u(),{setModalData:j,navigate:A,resetNavigation:T,data:b}=d(),S=s(),{initLoginWithTelegram:C,loginWithTelegram:w,updateWallets:E,setReadyToTrue:R,closePrivyModal:W,createAnalyticsEvent:k,getAuthMeta:x}=c(),[_,L]=t(!1),[M,I]=t(void 0),D=o();async function N(){try{let e=await async function(){let e;if(!v){if(D.enabled&&"error"===D.status)throw new a(D.error,null,n.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===n.ALLOWLIST_REJECTED)return I(void 0),T(),void A("AllowlistRejectionScreen");if(e?.privyErrorCode===n.USER_LIMIT_REACHED)return console.error(new l(e).toString()),I(void 0),T(),void A("UserLimitReachedScreen");if(e?.privyErrorCode===n.USER_DOES_NOT_EXIST)return I(void 0),T(),void A("AccountNotFoundScreen");if(e?.privyErrorCode===n.ACCOUNT_TRANSFER_REQUIRED&&e.data?.data?.nonce)return I(void 0),T(),j({accountTransfer:{nonce:e.data?.data?.nonce,account:e.data?.data?.subject,telegramAuthResult:x()?.telegramAuthResult,telegramWebAppData:x()?.telegramWebAppData,displayName:e.data?.data?.account?.displayName,linkMethod:"telegram",embeddedWalletAddress:e.data?.data?.otherUser?.embeddedWalletAddress}}),void A("LinkConflictScreen");let{retryable:t,detail:r}=i(e);I({retryable:t,detail:r,message:"Authentication failed"})}}r((()=>{N()}),[]),r((()=>{if(!(f&&v&&_&&h))return;if(S?.legal.requireUsersAcceptTerms&&!h.hasAcceptedTerms){let e=setTimeout((()=>{A("AffirmativeConsentScreen")}),m);return()=>clearTimeout(e)}if(p(h,S.embeddedWallets)){let e=setTimeout((()=>{j({createWallet:{onSuccess:()=>{},onFailure:e=>{console.error(e),k({eventName:"embedded_wallet_creation_failure_logout",payload:{error:e,provider:"telegram",screen:"TelegramAuthScreen"}}),y()},callAuthOnSuccessOnClose:!0}}),A("EmbeddedWalletOnAccountCreateScreen")}),m);return()=>clearTimeout(e)}E();let e=setTimeout((()=>W({shouldCallAuthOnSuccess:!0,isSuccess:!0})),m);return()=>clearTimeout(e)}),[f,v,_,h]);/*#__PURE__*/return e(g,{success:_,errorMessage:M,onRetry:M?.retryable?async()=>{try{I(void 0),b?.telegramAuthModalData?.seamlessAuth||await C(void 0,b?.login?.disableSignup),await N()}catch(e){let{retryable:t,detail:r}=i(e);I({retryable:t,detail:r,message:"Authentication failed"})}}:void 0})},isCaptchaRequired:!0,isShownBeforeReady:!0};export{f as TelegramAuthScreen,g as TelegramAuthScreenView,f as default};
//# sourceMappingURL=TelegramAuthScreen-iuUnqZ3C.mjs.map
