UNPKG

@privy-io/react-auth

Version:

React client for the Privy Auth API

3 lines (2 loc) 5.27 kB
"use strict";var e=require("react/jsx-runtime"),r=require("react"),t=require("react-device-detect"),a=require("styled-components"),i=require("./CopyToClipboard-fd8Z3kQX.js"),s=require("./useActiveWallet-BOX8xCn9.js"),n=require("./OpenLink-BpCUf9iR.js"),o=require("./QrCode-DsQD8cG6.js"),l=require("./context-DFq1obBO.js"),c=require("./internal-context-NWsAL807.js"),u=require("./get-is-unified-wallet-D4ouXJpi.js"),d=require("./ScreenLayout-BeH-Q6N2.js"),p=require("./farcaster-CWHXGAib.js");require("./copy-BiZ7dtqy.js"),require("zustand"),require("./prepareFundingModalData-Cnd6rhhJ.js"),require("@privy-io/js-sdk-core"),require("eventemitter3"),require("./events-context-Di6--rDg.js"),require("viem"),require("viem/utils"),require("./getPublicClient-CGlodIp_.js"),require("./useWallets-BLFNjTwC.js"),require("qrcode"),require("tinycolor2"),require("ofetch"),require("./Button-Bm_Ft0Dw.js"),require("./Screen-D9Tvi297.js"),require("./ModalHeader-DB7Tbjwz.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("./index-CRFXS9pP.js");let g="#8a63d2";const m=({appName:r,loading:a,success:l,errorMessage:c,connectUri:u,onBack:m,onClose:C,onOpenFarcaster:j})=>t.isMobile||a?t.isIOS?/*#__PURE__*/e.jsx(d.ScreenLayout,{title:c?c.message:"Add a signer to Farcaster",subtitle:c?c.detail:`This will allow ${r} to add casts, likes, follows, and more on your behalf.`,icon:p.Farcaster,iconVariant:"loading",iconLoadingStatus:{success:l,fail:!!c},primaryCta:u&&j?{label:"Open Farcaster app",onClick:j}:void 0,onBack:m,onClose:C,watermark:!0}):/*#__PURE__*/e.jsx(d.ScreenLayout,{title:c?c.message:"Requesting signer from Farcaster",subtitle:c?c.detail:"This should only take a moment",icon:p.Farcaster,iconVariant:"loading",iconLoadingStatus:{success:l,fail:!!c},onBack:m,onClose:C,watermark:!0,children:u&&t.isMobile&&/*#__PURE__*/e.jsx(h,{children:/*#__PURE__*/e.jsx(n.OpenLinkButton,{text:"Take me to Farcaster",url:u,color:g})})}): /*#__PURE__*/e.jsx(d.ScreenLayout,{title:"Add a signer to Farcaster",subtitle:`This will allow ${r} to add casts, likes, follows, and more on your behalf.`,onBack:m,onClose:C,watermark:!0,children:/*#__PURE__*/e.jsxs(y,{children:[/*#__PURE__*/e.jsx(f,{children:u?/*#__PURE__*/e.jsx(o.QrCode,{url:u,size:275,squareLogoElement:p.Farcaster}):/*#__PURE__*/e.jsx(x,{children:/*#__PURE__*/e.jsx(s.Loader,{})})}),/*#__PURE__*/e.jsxs(q,{children:[/*#__PURE__*/e.jsx(v,{children:"Or copy this link and paste it into a phone browser to open the Farcaster app."}),u&&/*#__PURE__*/e.jsx(i.CopytoClipboardButton,{text:u,itemName:"link",color:g})]})]})});let h=/*#__PURE__*/a.styled.div.withConfig({displayName:"MobileLinkContainer",componentId:"sc-2da6f06e-0"})(["margin-top:24px;"]),y=/*#__PURE__*/a.styled.div.withConfig({displayName:"ContentContainer",componentId:"sc-2da6f06e-1"})(["display:flex;flex-direction:column;align-items:center;gap:24px;"]),f=/*#__PURE__*/a.styled.div.withConfig({displayName:"QrContainer",componentId:"sc-2da6f06e-2"})(["padding:24px;position:relative;display:flex;align-items:center;justify-content:center;min-height:275px;"]),q=/*#__PURE__*/a.styled.div.withConfig({displayName:"InstructionsContainer",componentId:"sc-2da6f06e-3"})(["display:flex;flex-direction:column;align-items:center;gap:16px;"]),v=/*#__PURE__*/a.styled.div.withConfig({displayName:"InstructionText",componentId:"sc-2da6f06e-4"})(["font-size:0.875rem;text-align:center;color:var(--privy-color-foreground-2);"]),x=/*#__PURE__*/a.styled.div.withConfig({displayName:"LoaderWrapper",componentId:"sc-2da6f06e-5"})(["position:relative;width:82px;height:82px;"]);const C={component:()=>{let{lastScreen:t,navigateBack:a,data:i}=u.usePrivyModal(),s=l.useAppConfig(),{requestFarcasterSignerStatus:n,closePrivyModal:o}=c.usePrivyInternal(),[d,p]=r.useState(void 0),[g,h]=r.useState(!1),[y,f]=r.useState(!1),q=r.useRef([]),v=i?.farcasterSigner;r.useEffect((()=>{let e=Date.now(),r=setInterval((async()=>{if(!v?.public_key)return clearInterval(r),void p({retryable:!0,message:"Connect failed",detail:"Something went wrong. Please try again."});"approved"===v.status&&(clearInterval(r),h(!1),f(!0),q.current.push(setTimeout((()=>o({shouldCallAuthOnSuccess:!1,isSuccess:!0})),l.DEFAULT_SUCCESS_SCREEN_DURATION_MS)));let t=await n(v?.public_key),a=Date.now()-e;"approved"===t.status?(clearInterval(r),h(!1),f(!0),q.current.push(setTimeout((()=>o({shouldCallAuthOnSuccess:!1,isSuccess:!0})),l.DEFAULT_SUCCESS_SCREEN_DURATION_MS))):a>3e5?(clearInterval(r),p({retryable:!0,message:"Connect failed",detail:"The request timed out. Try again."})):"revoked"===t.status&&(clearInterval(r),p({retryable:!0,message:"Request rejected",detail:"The request was rejected. Please try again."}))}),2e3);return()=>{clearInterval(r),q.current.forEach((e=>clearTimeout(e)))}}),[]);let x="pending_approval"===v?.status?v.signer_approval_url:void 0;/*#__PURE__*/return e.jsx(m,{appName:s.name,loading:g,success:y,errorMessage:d,connectUri:x,onBack:t?a:void 0,onClose:o,onOpenFarcaster:()=>{x&&(window.location.href=x)}})}};exports.FarcasterSignerStatusScreen=C,exports.FarcasterSignerStatusView=m,exports.default=C;