UNPKG

@privy-io/react-auth

Version:

React client for the Privy Auth API

2 lines (1 loc) 4.93 kB
import{jsx as e,jsxs as t}from"react/jsx-runtime";import{useState as o,useRef as r,useEffect as a}from"react";import{isMobile as i,isIOS as n}from"react-device-detect";import{styled as s}from"styled-components";import{C as l}from"./CopyToClipboard-DatKc59_.mjs";import{L as c}from"./useActiveWallet-Bsy5GTCV.mjs";import{O as m}from"./OpenLink-BpeNYBKs.mjs";import{Q as p}from"./QrCode-DR5LogOp.mjs";import{u as d,q as u}from"./context-Bycd1SKV.mjs";import{u as f}from"./internal-context-e-Eni5bG.mjs";import{a as g}from"./get-is-unified-wallet-DvKS5IUO.mjs";import{S as h}from"./ScreenLayout-CddsD3Of.mjs";import{F as v}from"./farcaster-DPlSjvF5.mjs";import"./copy-Bx2Jwc5_.mjs";import"zustand";import"./prepareFundingModalData-CIgFwA7s.mjs";import"@privy-io/js-sdk-core";import"eventemitter3";import"./events-context-CI0iqAXA.mjs";import"viem";import"viem/utils";import"./getPublicClient-A9RSftUZ.mjs";import"./useWallets-D0lpBS44.mjs";import"qrcode";import"tinycolor2";import"ofetch";import"./Button-B8mqatRx.mjs";import"./Screen-BTyXgDrd.mjs";import"./ModalHeader-BLGC-7ev.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"./index-CJMgUOnw.mjs";let y="#8a63d2";const w=({appName:o,loading:r,success:a,errorMessage:s,connectUri:d,onBack:u,onClose:f,onOpenFarcaster:g})=>/*#__PURE__*/e(h,i||r?n?{title:s?s.message:"Add a signer to Farcaster",subtitle:s?s.detail:`This will allow ${o} to add casts, likes, follows, and more on your behalf.`,icon:v,iconVariant:"loading",iconLoadingStatus:{success:a,fail:!!s},primaryCta:d&&g?{label:"Open Farcaster app",onClick:g}:void 0,onBack:u,onClose:f,watermark:!0}:{title:s?s.message:"Requesting signer from Farcaster",subtitle:s?s.detail:"This should only take a moment",icon:v,iconVariant:"loading",iconLoadingStatus:{success:a,fail:!!s},onBack:u,onClose:f,watermark:!0,children:d&&i&&/*#__PURE__*/e(C,{children:/*#__PURE__*/e(m,{text:"Take me to Farcaster",url:d,color:y})})}:{title:"Add a signer to Farcaster",subtitle:`This will allow ${o} to add casts, likes, follows, and more on your behalf.`,onBack:u,onClose:f,watermark:!0,children:/*#__PURE__*/t(k,{children:[/*#__PURE__*/e(j,{children:d?/*#__PURE__*/e(p,{url:d,size:275,squareLogoElement:v}):/*#__PURE__*/e(b,{children:/*#__PURE__*/e(c,{})})}),/*#__PURE__*/t(x,{children:[/*#__PURE__*/e(I,{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 C=/*#__PURE__*/s.div.withConfig({displayName:"MobileLinkContainer",componentId:"sc-2da6f06e-0"})(["margin-top:24px;"]),k=/*#__PURE__*/s.div.withConfig({displayName:"ContentContainer",componentId:"sc-2da6f06e-1"})(["display:flex;flex-direction:column;align-items:center;gap:24px;"]),j=/*#__PURE__*/s.div.withConfig({displayName:"QrContainer",componentId:"sc-2da6f06e-2"})(["padding:24px;position:relative;display:flex;align-items:center;justify-content:center;min-height:275px;"]),x=/*#__PURE__*/s.div.withConfig({displayName:"InstructionsContainer",componentId:"sc-2da6f06e-3"})(["display:flex;flex-direction:column;align-items:center;gap:16px;"]),I=/*#__PURE__*/s.div.withConfig({displayName:"InstructionText",componentId:"sc-2da6f06e-4"})(["font-size:0.875rem;text-align:center;color:var(--privy-color-foreground-2);"]),b=/*#__PURE__*/s.div.withConfig({displayName:"LoaderWrapper",componentId:"sc-2da6f06e-5"})(["position:relative;width:82px;height:82px;"]);const S={component:()=>{let{lastScreen:t,navigateBack:i,data:n}=g(),s=d(),{requestFarcasterSignerStatus:l,closePrivyModal:c}=f(),[m,p]=o(void 0),[h,v]=o(!1),[y,C]=o(!1),k=r([]),j=n?.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),C(!0),k.current.push(setTimeout((()=>c({shouldCallAuthOnSuccess:!1,isSuccess:!0})),u)));let o=await l(j?.public_key),r=Date.now()-e;"approved"===o.status?(clearInterval(t),v(!1),C(!0),k.current.push(setTimeout((()=>c({shouldCallAuthOnSuccess:!1,isSuccess:!0})),u))):r>3e5?(clearInterval(t),p({retryable:!0,message:"Connect failed",detail:"The request timed out. Try again."})):"revoked"===o.status&&(clearInterval(t),p({retryable:!0,message:"Request rejected",detail:"The request was rejected. Please try again."}))}),2e3);return()=>{clearInterval(t),k.current.forEach((e=>clearTimeout(e)))}}),[]);let x="pending_approval"===j?.status?j.signer_approval_url:void 0;/*#__PURE__*/return e(w,{appName:s.name,loading:h,success:y,errorMessage:m,connectUri:x,onBack:t?i:void 0,onClose:c,onOpenFarcaster:()=>{x&&(window.location.href=x)}})}};export{S as FarcasterSignerStatusScreen,w as FarcasterSignerStatusView,S as default};