import{jsx as e}from"react/jsx-runtime";import{useState as t,useEffect as o,useMemo as r}from"react";import{u as i,r as a}from"./context-BKnOUECq.mjs";import{R as s}from"./toViemAccount-4iGGrW4w.mjs";import{P as n,c as m,a as p}from"./errors-Dd6zfYtp.mjs";import{u as c}from"./internal-context-dfitw7Ot.mjs";import{u as l}from"./modal-context-DBwfUxD-.mjs";import{f as d}from"./useActiveWallet-BEfvREjE.mjs";import{s as u}from"./shouldProceedtoEmbeddedWalletCreationFlow-SyjOJUom.mjs";import{S as f}from"./ScreenLayout-Caq5mGD8.mjs";import"@privy-io/js-sdk-core";import"tinycolor2";import"jose";import"./privy-context-Bi6vqCPc.mjs";import"@privy-io/are-addresses-equal";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"styled-components";import"./events-context-BJ75xIIf.mjs";import"./get-entropy-details-for-user-BIWg0YxF.mjs";import"./user-D5cqJNp9.mjs";import"./index-C5jxD-zy.mjs";import"mipd";import"@scure/base";import"./usePrivy-BhL-ltvm.mjs";import"./use-unlink-wallet-oAguM2-k.mjs";import"@privy-io/popup";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"./use-sign-with-user-signer-CQI6hUH7.mjs";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 h=({providerApp:t,success:o,error:i,onClose:a})=>{let{title:s,subtitle:n}=r((()=>o?{title:`Successfully connected with ${t.name}`,subtitle:"You're good to go!"}:i?{title:"Authentication failed",subtitle:i.message}:{title:`Connecting to ${t.name}`,subtitle:`Please check the pop-up from ${t.name} to continue`}),[o,i,t.name]);/*#__PURE__*/return e(f,{title:s,subtitle:n,icon:t.logoUrl,iconVariant:"loading",iconLoadingStatus:{success:o,fail:!!i},onBack:a,watermark:!0})},j={component:()=>{let r=i(),{data:f,navigate:j,setModalData:v,onUserCloseViaDialogOrKeybindRef:y}=l(),{crossAppAuthFlow:g,updateWallets:A,closePrivyModal:S,createAnalyticsEvent:b}=c(),{logout:w}=d(),[C,I]=t({}),k=f?.crossAppAuth,x=new n(`There was an issue connecting your ${k?.name} account. Please try again.`),T=new s((async e=>{if(k?.popup)try{let t=await g({appId:e,popup:k.popup,action:k.action,disableSignup:k.disableSignup});I({data:t})}catch(e){if(e instanceof n)I({error:e});else if(e instanceof m){if(e.privyErrorCode===p.ACCOUNT_TRANSFER_REQUIRED&&e.data?.data?.nonce)return v({accountTransfer:{nonce:e.data?.data?.nonce,account:e.data?.data?.subject,displayName:e.data?.data?.account?.displayName,linkMethod:`privy:${k.appId}`,embeddedWalletAddress:e.data?.data?.otherUser?.embeddedWalletAddress,oAuthUserInfo:e.data?.data?.otherUser?.oAuthUserInfo}}),void j("LinkConflictScreen");k.popup&&k.popup.close(),I({error:x})}else I({error:x})}else I({error:x})})),U=()=>{C.data&&(A(),k?.onSuccess(C.data),S({shouldCallAuthOnSuccess:!0,isSuccess:!0})),k?.onError(C.error??new n("User canceled flow")),S({shouldCallAuthOnSuccess:!1,isSuccess:!1})};return y.current=U,o((()=>{k?.appId?.length&&T.execute(k.appId)}),[k?.appId]),o((()=>{if(!C.data)return;let e=C.data;if(r.legal.requireUsersAcceptTerms&&!e.hasAcceptedTerms){let e=setTimeout((()=>{j("AffirmativeConsentScreen")}),a);return()=>clearTimeout(e)}if(u(e,r.embeddedWallets)){let e=setTimeout((()=>{v({createWallet:{onSuccess:()=>{},onFailure:e=>{console.error(e),b({eventName:"embedded_wallet_creation_failure_logout",payload:{error:e,provider:`privy:${k?.appId}`,screen:"CrossAppAuthScreen"}}),w()},callAuthOnSuccessOnClose:!0}}),j("EmbeddedWalletOnAccountCreateScreen")}),a);return()=>clearTimeout(e)}let t=setTimeout(U,a);return()=>clearTimeout(t)}),[C.data]),k?.appId?/*#__PURE__*/e(h,{providerApp:{id:k?.appId,logoUrl:k?.logoUrl,name:k?.name},success:!!C.data,error:C.error,onClose:U}):(console.warn("Missing data for Screen"),null)},isShownBeforeReady:!0};export{j as CrossAppAuthScreen,h as CrossAppAuthScreenView,j as default};
//# sourceMappingURL=CrossAppAuthScreen-DRIIYkjj.mjs.map
