@privy-io/react-auth
Version:
React client for the Privy Auth API
29 lines (28 loc) • 4.41 kB
JavaScript
import{jsx as e,jsxs as t}from"react/jsx-runtime";import{useState as r,useRef as o,useEffect as a}from"react";import{isMobile as i,isIOS as s}from"react-device-detect";import{styled as n}from"styled-components";import{C as l}from"./CopyToClipboard-DSTf_eKU.mjs";import{L as c}from"./useActiveWallet-CvP7iYvj.mjs";import{O as m}from"./OpenLink-DZHy38vr.mjs";import{Q as p}from"./QrCode-B84kEIjT.mjs";import{u as d,q as u}from"./context-DLtU3JQy.mjs";import{u as g}from"./internal-context-Z-fyxadS.mjs";import{a as h}from"./privy-context-DrMxzgOR.mjs";import{S as f}from"./ScreenLayout-D1p_ntex.mjs";import{F as v}from"./farcaster-DPlSjvF5.mjs";import"zustand";import"./use-export-wallet-_wu5ex5t.mjs";import"./useWallets-BzNCTucF.mjs";import"viem";import"@privy-io/js-sdk-core";import"eventemitter3";import"viem/utils";import"./events-context-CI0iqAXA.mjs";import"qrcode";import"tinycolor2";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";let y="#8a63d2";const k=({appName:r,loading:o,success:a,errorMessage:n,connectUri:d,onBack:u,onClose:g,onOpenFarcaster:h})=>/*#__PURE__*/e(f,i||o?s?{title:n?n.message:"Add a signer to Farcaster",subtitle:n?n.detail:`This will allow ${r} to add casts, likes, follows, and more on your behalf.`,icon:v,iconVariant:"loading",iconLoadingStatus:{success:a,fail:!!n},primaryCta:d&&h?{label:"Open Farcaster app",onClick:h}:void 0,onBack:u,onClose:g,watermark:!0}:{title:n?n.message:"Requesting signer from Farcaster",subtitle:n?n.detail:"This should only take a moment",icon:v,iconVariant:"loading",iconLoadingStatus:{success:a,fail:!!n},onBack:u,onClose:g,watermark:!0,children:d&&i&&/*#__PURE__*/e(x,{children:/*#__PURE__*/e(m,{text:"Take me to Farcaster",url:d,color:y})})}:{title:"Add a signer to Farcaster",subtitle:`This will allow ${r} to add casts, likes, follows, and more on your behalf.`,onBack:u,onClose:g,watermark:!0,children:/*#__PURE__*/t(w,{children:[/*#__PURE__*/e(j,{children:d?/*#__PURE__*/e(p,{url:d,size:275,squareLogoElement:v}):/*#__PURE__*/e(S,{children:/*#__PURE__*/e(c,{})})}),/*#__PURE__*/t(C,{children:[/*#__PURE__*/e(b,{children:"Or copy this link and paste it into a phone browser to open the Farcaster app."}),d&&/*#__PURE__*/e(l,{text:d,itemName:"link",color:y})]})]})});let x=n.div`
margin-top: 24px;
`,w=n.div`
display: flex;
flex-direction: column;
align-items: center;
gap: 24px;
`,j=n.div`
padding: 24px;
position: relative;
display: flex;
align-items: center;
justify-content: center;
min-height: 275px;
`,C=n.div`
display: flex;
flex-direction: column;
align-items: center;
gap: 16px;
`,b=n.div`
font-size: 0.875rem;
text-align: center;
color: var(--privy-color-foreground-2);
`,S=n.div`
position: relative;
width: 82px;
height: 82px;
`;const F={component:()=>{let{lastScreen:t,navigateBack:i,data:s}=h(),n=d(),{requestFarcasterSignerStatus:l,closePrivyModal:c}=g(),[m,p]=r(void 0),[f,v]=r(!1),[y,x]=r(!1),w=o([]),j=s?.farcasterSigner;a((()=>{let e=Date.now(),t=setInterval((async()=>{if(!j?.public_key)return clearInterval(t),void p({retryable:!0,message:"Connect failed",detail:"Something went wrong. Please try again."});"approved"===j.status&&(clearInterval(t),v(!1),x(!0),w.current.push(setTimeout((()=>c({shouldCallAuthOnSuccess:!1,isSuccess:!0})),u)));let r=await l(j?.public_key),o=Date.now()-e;"approved"===r.status?(clearInterval(t),v(!1),x(!0),w.current.push(setTimeout((()=>c({shouldCallAuthOnSuccess:!1,isSuccess:!0})),u))):o>3e5?(clearInterval(t),p({retryable:!0,message:"Connect failed",detail:"The request timed out. Try again."})):"revoked"===r.status&&(clearInterval(t),p({retryable:!0,message:"Request rejected",detail:"The request was rejected. Please try again."}))}),2e3);return()=>{clearInterval(t),w.current.forEach((e=>clearTimeout(e)))}}),[]);let C="pending_approval"===j?.status?j.signer_approval_url:void 0;/*#__PURE__*/return e(k,{appName:n.name,loading:f,success:y,errorMessage:m,connectUri:C,onBack:t?i:void 0,onClose:c,onOpenFarcaster:()=>{C&&(window.location.href=C)}})}};export{F as FarcasterSignerStatusScreen,k as FarcasterSignerStatusView,F as default};