@privy-io/react-auth
Version:
React client for the Privy Auth API
2 lines (1 loc) • 4.32 kB
JavaScript
import{jsx as e}from"react/jsx-runtime";import{useState as t,useEffect as o}from"react";import{isMobile as r}from"react-device-detect";import{C as i}from"./use-export-wallet-_wu5ex5t.mjs";import{q as n}from"./context-DLtU3JQy.mjs";import{z as a}from"./useActiveWallet-CvP7iYvj.mjs";import{u as s}from"./internal-context-Z-fyxadS.mjs";import{a as l}from"./privy-context-DrMxzgOR.mjs";import{S as c}from"./ScreenLayout-D1p_ntex.mjs";import{B as m}from"./index-YDEix4mU.mjs";import{getErrorDetails as p}from"./ConnectionStatusScreen-Dfv_mgId.mjs";import"./useWallets-BzNCTucF.mjs";import"viem";import"@privy-io/js-sdk-core";import"eventemitter3";import"viem/utils";import"tinycolor2";import"zustand";import"styled-components";import"./events-context-CI0iqAXA.mjs";import"ofetch";import"@privy-io/are-addresses-equal";import"./ModalHeader-BnVmXtvG.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-Cycy3IzT.mjs";import"./index-Dq_xe9dz.mjs";import"uuid";import"jose";import"@coinbase/wallet-sdk";import"@privy-io/ethereum";import"mipd";import"@privy-io/popup";import"./paths-3HW55qZg.mjs";import"./usePrivy-C_sY2Duk.mjs";import"@scure/base";import"@headlessui/react";import"@walletconnect/ethereum-provider";import"@privy-io/urls";import"./PrivyPluginContext-2QN2dVUw.mjs";import"./getEmbeddedConnectedWallet-JzK4iD-L.mjs";import"js-cookie";import"./frame-uzTmvtww.mjs";import"@privy-io/routes";import"x402/client";import"@privy-io/api-base";import"viem/accounts";import"./use-sign-with-user-signer-Do5Oi_rb.mjs";import"./Link-DJ5gq9Di.mjs";import"./useI18n-C4fmUAf3.mjs";import"./shouldProceedtoEmbeddedWalletCreationFlow-D2ZT5lW9.mjs";const u=({walletLogo:t,success:o,errorMessage:r,title:n,subtitle:a,onRetry:s,onUseDifferentWallet:l,onBack:m,numRetries:p,maxRetries:u})=>/*#__PURE__*/e(c,{title:n,subtitle:a,icon:t,iconVariant:"loading",iconLoadingStatus:{success:o,fail:!!r},primaryCta:r===i.ERROR_USER_EXISTS?{label:"Use a different wallet",onClick:l}:!o&&r?.retryable&&p<u?{label:"Retry",onClick:s,disabled:!r?.retryable||p>=u}:!o&&r&&p>=u?{label:"Use a different wallet",onClick:l}:void 0,onBack:m,watermark:!0}),d={component:()=>{let i,{navigateBack:c,navigate:d,lastScreen:w,currentScreen:f,data:y,setModalData:v}=l(),{walletConnectionStatus:j,closePrivyModal:g}=s(),[h,C]=t(void 0),[k,b]=t(0),x=a(j?.connector?.walletClientType||"unknown"),S="connected"===j?.status,R="switching_to_supported_chain"===j?.status;o((()=>{if(S){let e;if(y?.externalConnectWallet?.onCompleteNavigateTo){let t=y.externalConnectWallet.onCompleteNavigateTo,o=j.connectedWallet?.address;e=setTimeout((()=>{if(y.funding&&j.connector){let e=j.connector.wallets.find((e=>e.address===o));v({...y,funding:{...y.funding,connectedWallet:e}})}d(t({address:o,walletClientType:j.connector?.walletClientType,walletChainType:j.connector?.chainType}))}),n)}else e=setTimeout(g,n);return()=>clearTimeout(e)}}),[S]);o((()=>{var e;j?.connectError&&(e=j?.connectError,C(p(e)))}),[j]);let T=j?.connector?.connectorType||"injected",W=j?.connector?.walletClientType||"unknown",B=x?.metadata?.shortName||x?.name||j?.connector?.walletBranding.name||"Browser Extension",E=x?.image_url?.md||j?.connector?.walletBranding.icon||(t=>/*#__PURE__*/e(m,{...t})),M="Browser Extension"===B?B.toLowerCase():B;i=S?`Successfully connected with ${M}`:h?h.message:R?"Switching networks":`Waiting for ${M}`;let _="Don’t see your wallet? Check your other browser windows.";return S?_="You’re good to go!":k>=2&&h?_="Unable to connect wallet":h?_=h.detail:R?_="Switch your wallet to the requested network.":"metamask"===W&&r?_="Click to continue to open and connect MetaMask.":"metamask"===W?_="For the best experience, connect only one wallet at a time.":"wallet_connect_v2"===T?_="Open your mobile wallet app to continue":"coinbase_wallet"===T&&(_="Confirm in the Coinbase app/popup to continue."),/*#__PURE__*/e(u,{walletName:B,walletLogo:E,success:S,errorMessage:h,title:i,subtitle:_,onRetry:()=>{b(k+1),C(void 0),j?.connectRetry()},onUseDifferentWallet:c,onBack:f===w?void 0:c,numRetries:k,maxRetries:2})}};export{d as ConnectOnlyStatusScreen,u as ConnectOnlyStatusScreenView,d as default};