import{jsx as e}from"react/jsx-runtime";import{XCircle as t}from"lucide-react";import{useMemo as r,useState as o,useEffect as i}from"react";import{e as a,b as n}from"./index-C5jxD-zy.mjs";import{u as s}from"./internal-context-dfitw7Ot.mjs";import{u as m}from"./modal-context-DBwfUxD-.mjs";import{u as c}from"./privy-context-Bi6vqCPc.mjs";import{S as l}from"./ScreenLayout-Caq5mGD8.mjs";import"@privy-io/js-sdk-core";import"./toViemAccount-4iGGrW4w.mjs";import"jose";import"eventemitter3";import"./index-BtwxknTg.mjs";import"zustand";import"./context-BKnOUECq.mjs";import"tinycolor2";import"viem";import"viem/utils";import"./errors-Dd6zfYtp.mjs";import"ofetch";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"./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"./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 p=({connectionFailed:r,onClose:o})=>/*#__PURE__*/e(l,r?{title:"Something went wrong",subtitle:"We're on it. Please try again later.",icon:t,iconVariant:"error",primaryCta:{label:"Close",onClick:o},watermark:!0}:{title:"Connecting to your wallet",subtitle:"Please wait...",iconVariant:"loading",showClose:!0,onClose:o,watermark:!1}),d={component:()=>{let{authenticated:t,user:l}=c(),{client:d,closePrivyModal:u,createAnalyticsEvent:y,walletProxy:v}=s(),{navigate:h,data:f,setModalData:w,onUserCloseViaDialogOrKeybindRef:j}=m(),b=r((()=>Date.now()),[]),[g,C]=o(!1),{onCompleteNavigateTo:k,onFailure:A,shouldForceMFA:I,entropyId:x,entropyIdVerifier:P,recoveryMethod:S,connectingWalletAddress:T,isUnifiedWallet:V=!1}=f?.connectWallet??{},F=e=>{g||(C(!0),A("string"==typeof e?Error(e):e))};i((()=>{let e;return t?v?((async()=>{let t=await d.getAccessToken();if(!t)return F("User must be authenticated and have a Privy wallet before it can be connected");try{if(!V){if(!x||!P)return F("For on-device first-class chain wallets, entropyId and entropyIdVerifier are required");await v.connect({accessToken:t,entropyId:x,entropyIdVerifier:P})}I&&await v.verifyMfa({accessToken:t});let r=(Date.now()-b)/1e3;"EmbeddedWalletKeyExportScreen"===k&&r<1?e=setTimeout((()=>{h(k,!1)}),1e3*(1-r)):h(k,!1)}catch(e){if(a(e)&&"privy"===S){let e=await d.getAccessToken();if(!e)return F("User must be authenticated and have a Privy wallet before it can be recovered");try{y({eventName:"embedded_wallet_pinless_recovery_started",payload:{walletAddress:T}});let t=await(v?.recover({accessToken:e,entropyId:x,entropyIdVerifier:P}));t?.entropyId||F(Error("Unable to recover wallet")),k?h(k):u({shouldCallAuthOnSuccess:!1}),y({eventName:"embedded_wallet_recovery_completed",payload:{walletAddress:T}}),h(k)}catch(e){F("An error has occurred, please try again.")}}else a(e)&&"privy"!==S&&"privy-v2"!==S?(w({...f,recoverWallet:{entropyId:x,entropyIdVerifier:P,onCompleteNavigateTo:k,onFailure:A},recoveryOAuthStatus:{provider:S,action:"recover",isInAccountCreateFlow:!1,shouldCreateEth:!1,shouldCreateSol:!1}}),h(n(S))):F(e)}})(),()=>clearTimeout(e)):void 0:F("User must be authenticated and have a Privy wallet before it can be connected")}),[t,l,v]);let M=()=>{F("User exited before wallet could be connected"),u({shouldCallAuthOnSuccess:!1})};return j.current=M,/*#__PURE__*/e(p,{connectionFailed:g,onClose:M})}};export{d as EmbeddedWalletConnectingScreen,p as EmbeddedWalletConnectingView,d as default};
//# sourceMappingURL=EmbeddedWalletConnectingScreen-BqN3P_gu.mjs.map
