"use strict";var e=require("react/jsx-runtime"),r=require("lucide-react"),t=require("react"),i=require("./index-BoiKFBqR.js"),o=require("./internal-context-CdsQ3LEl.js"),n=require("./modal-context-BgeioxwT.js"),a=require("./privy-context-UTJouJ1x.js"),s=require("./ScreenLayout-DaFW0I3a.js");require("@privy-io/js-sdk-core"),require("./toViemAccount-CopJpCYv.js"),require("jose"),require("eventemitter3"),require("./index-Ub4KpwSY.js"),require("zustand"),require("./context-rs-ygOK2.js"),require("tinycolor2"),require("viem"),require("viem/utils"),require("./errors-CBapWvRs.js"),require("ofetch"),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("./paths-DizMb-lU.js"),require("./PrivyPluginContext-DsLtVhZA.js"),require("js-cookie"),require("@privy-io/ethereum"),require("viem/accounts"),require("mipd"),require("@scure/base"),require("./usePrivy-Dt4_yE6Q.js"),require("./use-unlink-wallet-DAxmY7kq.js"),require("./get-entropy-details-for-user-D63rM5_a.js"),require("./user-D2oPA-vS.js"),require("@privy-io/popup"),require("./events-context-Di6--rDg.js"),require("styled-components"),require("./useActiveWallet-dTc6deka.js"),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("@privy-io/are-addresses-equal"),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 c=({connectionFailed:t,onClose:i})=>t?/*#__PURE__*/e.jsx(s.ScreenLayout,{title:"Something went wrong",subtitle:"We're on it. Please try again later.",icon:r.XCircle,iconVariant:"error",primaryCta:{label:"Close",onClick:i},watermark:!0}):/*#__PURE__*/e.jsx(s.ScreenLayout,{title:"Connecting to your wallet",subtitle:"Please wait...",iconVariant:"loading",showClose:!0,onClose:i,watermark:!1}),u={component:()=>{let{authenticated:r,user:s}=a.usePrivyContext(),{client:u,closePrivyModal:l,createAnalyticsEvent:d,walletProxy:q}=o.usePrivyInternal(),{navigate:y,data:v,setModalData:p,onUserCloseViaDialogOrKeybindRef:m}=n.usePrivyModal(),h=t.useMemo((()=>Date.now()),[]),[j,w]=t.useState(!1),{onCompleteNavigateTo:b,onFailure:f,shouldForceMFA:g,entropyId:C,entropyIdVerifier:x,recoveryMethod:I,connectingWalletAddress:k,isUnifiedWallet:A=!1}=v?.connectWallet??{},P=e=>{j||(w(!0),f("string"==typeof e?Error(e):e))};t.useEffect((()=>{let e;return r?q?((async()=>{let r=await u.getAccessToken();if(!r)return P("User must be authenticated and have a Privy wallet before it can be connected");try{if(!A){if(!C||!x)return P("For on-device first-class chain wallets, entropyId and entropyIdVerifier are required");await q.connect({accessToken:r,entropyId:C,entropyIdVerifier:x})}g&&await q.verifyMfa({accessToken:r});let t=(Date.now()-h)/1e3;"EmbeddedWalletKeyExportScreen"===b&&t<1?e=setTimeout((()=>{y(b,!1)}),1e3*(1-t)):y(b,!1)}catch(e){if(i.errorIndicatesRecoveryIsNeeded(e)&&"privy"===I){let e=await u.getAccessToken();if(!e)return P("User must be authenticated and have a Privy wallet before it can be recovered");try{d({eventName:"embedded_wallet_pinless_recovery_started",payload:{walletAddress:k}});let r=await(q?.recover({accessToken:e,entropyId:C,entropyIdVerifier:x}));r?.entropyId||P(Error("Unable to recover wallet")),b?y(b):l({shouldCallAuthOnSuccess:!1}),d({eventName:"embedded_wallet_recovery_completed",payload:{walletAddress:k}}),y(b)}catch(e){P("An error has occurred, please try again.")}}else i.errorIndicatesRecoveryIsNeeded(e)&&"privy"!==I&&"privy-v2"!==I?(p({...v,recoverWallet:{entropyId:C,entropyIdVerifier:x,onCompleteNavigateTo:b,onFailure:f},recoveryOAuthStatus:{provider:I,action:"recover",isInAccountCreateFlow:!1,shouldCreateEth:!1,shouldCreateSol:!1}}),y(i.embeddedWalletRecoveryScreen(I))):P(e)}})(),()=>clearTimeout(e)):void 0:P("User must be authenticated and have a Privy wallet before it can be connected")}),[r,s,q]);let S=()=>{P("User exited before wallet could be connected"),l({shouldCallAuthOnSuccess:!1})};return m.current=S,/*#__PURE__*/e.jsx(c,{connectionFailed:j,onClose:S})}};exports.EmbeddedWalletConnectingScreen=u,exports.EmbeddedWalletConnectingView=c,exports.default=u;
//# sourceMappingURL=EmbeddedWalletConnectingScreen-QNjEoBR3.js.map
