"use strict";var e=require("react/jsx-runtime"),r=require("react"),t=require("./context-rs-ygOK2.js"),i=require("./toViemAccount-CopJpCYv.js"),o=require("./errors-CBapWvRs.js"),s=require("./internal-context-CdsQ3LEl.js"),a=require("./modal-context-BgeioxwT.js"),u=require("./useActiveWallet-dTc6deka.js"),n=require("./shouldProceedtoEmbeddedWalletCreationFlow-DTSTIV1u.js"),c=require("./ScreenLayout-DaFW0I3a.js");require("@privy-io/js-sdk-core"),require("tinycolor2"),require("jose"),require("./privy-context-UTJouJ1x.js"),require("@privy-io/are-addresses-equal"),require("eventemitter3"),require("./index-Ub4KpwSY.js"),require("zustand"),require("viem"),require("viem/utils"),require("./wallet-connect-BuohfvHK.js"),require("./getPublicClient-CFd_sHBk.js"),require("viem/chains"),require("react-device-detect"),require("@coinbase/wallet-sdk"),require("@walletconnect/ethereum-provider"),require("./pkce-CmuJlEgn.js"),require("ofetch"),require("./paths-DizMb-lU.js"),require("./PrivyPluginContext-DsLtVhZA.js"),require("js-cookie"),require("@privy-io/ethereum"),require("viem/accounts"),require("styled-components"),require("./events-context-Di6--rDg.js"),require("./get-entropy-details-for-user-D63rM5_a.js"),require("./user-D2oPA-vS.js"),require("./index-BoiKFBqR.js"),require("mipd"),require("@scure/base"),require("./usePrivy-Dt4_yE6Q.js"),require("./use-unlink-wallet-DAxmY7kq.js"),require("@privy-io/popup"),require("@headlessui/react"),require("@privy-io/urls"),require("./getEmbeddedConnectedWallet-D6YL2FS9.js"),require("./frame-BHa-PKpX.js"),require("@privy-io/routes"),require("./use-deposit-address-CVyd0fqP.js"),require("x402/client"),require("@privy-io/api-base"),require("./use-sign-with-user-signer-BhoaqeNG.js"),require("./ModalHeader-Cpls13mi.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-8NusMFtu.js"),require("./index-ByFhjjzH.js");const l=({providerApp:t,success:i,error:o,onClose:s})=>{let{title:a,subtitle:u}=r.useMemo((()=>i?{title:`Successfully connected with ${t.name}`,subtitle:"You're good to go!"}:o?{title:"Authentication failed",subtitle:o.message}:{title:`Connecting to ${t.name}`,subtitle:`Please check the pop-up from ${t.name} to continue`}),[i,o,t.name]);/*#__PURE__*/return e.jsx(c.ScreenLayout,{title:a,subtitle:u,icon:t.logoUrl,iconVariant:"loading",iconLoadingStatus:{success:i,fail:!!o},onBack:s,watermark:!0})},d={component:()=>{let c=t.useAppConfig(),{data:d,navigate:p,setModalData:q,onUserCloseViaDialogOrKeybindRef:m}=a.usePrivyModal(),{crossAppAuthFlow:S,updateWallets:h,closePrivyModal:v,createAnalyticsEvent:A}=s.usePrivyInternal(),{logout:f}=u.useLogout(),[y,j]=r.useState({}),C=d?.crossAppAuth,g=new o.PrivyClientError(`There was an issue connecting your ${C?.name} account. Please try again.`),E=new i.RunEffectOnce((async e=>{if(C?.popup)try{let r=await S({appId:e,popup:C.popup,action:C.action,disableSignup:C.disableSignup});j({data:r})}catch(e){if(e instanceof o.PrivyClientError)j({error:e});else if(e instanceof o.PrivyApiError){if(e.privyErrorCode===o.PrivyErrorCode.ACCOUNT_TRANSFER_REQUIRED&&e.data?.data?.nonce)return q({accountTransfer:{nonce:e.data?.data?.nonce,account:e.data?.data?.subject,displayName:e.data?.data?.account?.displayName,linkMethod:`privy:${C.appId}`,embeddedWalletAddress:e.data?.data?.otherUser?.embeddedWalletAddress,oAuthUserInfo:e.data?.data?.otherUser?.oAuthUserInfo}}),void p("LinkConflictScreen");C.popup&&C.popup.close(),j({error:g})}else j({error:g})}else j({error:g})})),b=()=>{y.data&&(h(),C?.onSuccess(y.data),v({shouldCallAuthOnSuccess:!0,isSuccess:!0})),C?.onError(y.error??new o.PrivyClientError("User canceled flow")),v({shouldCallAuthOnSuccess:!1,isSuccess:!1})};return m.current=b,r.useEffect((()=>{C?.appId?.length&&E.execute(C.appId)}),[C?.appId]),r.useEffect((()=>{if(!y.data)return;let e=y.data;if(c.legal.requireUsersAcceptTerms&&!e.hasAcceptedTerms){let e=setTimeout((()=>{p("AffirmativeConsentScreen")}),t.DEFAULT_SUCCESS_SCREEN_DURATION_MS);return()=>clearTimeout(e)}if(n.shouldProceedtoEmbeddedWalletCreationFlow(e,c.embeddedWallets)){let e=setTimeout((()=>{q({createWallet:{onSuccess:()=>{},onFailure:e=>{console.error(e),A({eventName:"embedded_wallet_creation_failure_logout",payload:{error:e,provider:`privy:${C?.appId}`,screen:"CrossAppAuthScreen"}}),f()},callAuthOnSuccessOnClose:!0}}),p("EmbeddedWalletOnAccountCreateScreen")}),t.DEFAULT_SUCCESS_SCREEN_DURATION_MS);return()=>clearTimeout(e)}let r=setTimeout(b,t.DEFAULT_SUCCESS_SCREEN_DURATION_MS);return()=>clearTimeout(r)}),[y.data]),C?.appId?/*#__PURE__*/e.jsx(l,{providerApp:{id:C?.appId,logoUrl:C?.logoUrl,name:C?.name},success:!!y.data,error:y.error,onClose:b}):(console.warn("Missing data for Screen"),null)},isShownBeforeReady:!0};exports.CrossAppAuthScreen=d,exports.CrossAppAuthScreenView=l,exports.default=d;
//# sourceMappingURL=CrossAppAuthScreen-OVpK_D7e.js.map
