@privy-io/react-auth
Version:
React client for the Privy Auth API
30 lines (29 loc) • 4.8 kB
JavaScript
"use strict";var e=require("react/jsx-runtime"),r=require("react"),t=require("react-device-detect"),a=require("styled-components"),i=require("./CopyToClipboard-CC0DCGEH.js"),s=require("./useActiveWallet-Cn6zOXx5.js"),o=require("./OpenLink-L5LZ-pEm.js"),n=require("./QrCode-CE12LRBB.js"),l=require("./context-D-ZJYjUg.js"),c=require("./internal-context-BJv4f_bO.js"),u=require("./get-is-unified-wallet-UpdjHxOV.js"),d=require("./ScreenLayout-CMb-Fua0.js"),p=require("./farcaster-CWHXGAib.js");require("zustand"),require("./use-export-wallet-B5ujV5Nk.js"),require("@privy-io/js-sdk-core"),require("eventemitter3"),require("viem/utils"),require("./useWallets-CKAypPZB.js"),require("./events-context-Di6--rDg.js"),require("viem"),require("./getPublicClient-BsmZyCGX.js"),require("qrcode"),require("tinycolor2"),require("ofetch"),require("@privy-io/are-addresses-equal"),require("./ModalHeader-BCPQgekO.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("./Screen-BfKedqka.js"),require("./index-ByFhjjzH.js");let g="#8a63d2";const q=({appName:r,loading:a,success:l,errorMessage:c,connectUri:u,onBack:q,onClose:S,onOpenFarcaster:f})=>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&&f?{label:"Open Farcaster app",onClick:f}:void 0,onBack:q,onClose:S,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:q,onClose:S,watermark:!0,children:u&&t.isMobile&&/*#__PURE__*/e.jsx(m,{children:/*#__PURE__*/e.jsx(o.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:q,onClose:S,watermark:!0,children:/*#__PURE__*/e.jsxs(v,{children:[/*#__PURE__*/e.jsx(h,{children:u?/*#__PURE__*/e.jsx(n.QrCode,{url:u,size:275,squareLogoElement:p.Farcaster}):/*#__PURE__*/e.jsx(j,{children:/*#__PURE__*/e.jsx(s.Loader,{})})}),/*#__PURE__*/e.jsxs(x,{children:[/*#__PURE__*/e.jsx(y,{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 m=a.styled.div`
margin-top: 24px;
`,v=a.styled.div`
display: flex;
flex-direction: column;
align-items: center;
gap: 24px;
`,h=a.styled.div`
padding: 24px;
position: relative;
display: flex;
align-items: center;
justify-content: center;
min-height: 275px;
`,x=a.styled.div`
display: flex;
flex-direction: column;
align-items: center;
gap: 16px;
`,y=a.styled.div`
font-size: 0.875rem;
text-align: center;
color: var(--privy-color-foreground-2);
`,j=a.styled.div`
position: relative;
width: 82px;
height: 82px;
`;const S={component:()=>{let{lastScreen:t,navigateBack:a,data:i}=u.usePrivyModal(),s=l.useAppConfig(),{requestFarcasterSignerStatus:o,closePrivyModal:n}=c.usePrivyInternal(),[d,p]=r.useState(void 0),[g,m]=r.useState(!1),[v,h]=r.useState(!1),x=r.useRef([]),y=i?.farcasterSigner;r.useEffect((()=>{let e=Date.now(),r=setInterval((async()=>{if(!y?.public_key)return clearInterval(r),void p({retryable:!0,message:"Connect failed",detail:"Something went wrong. Please try again."});"approved"===y.status&&(clearInterval(r),m(!1),h(!0),x.current.push(setTimeout((()=>n({shouldCallAuthOnSuccess:!1,isSuccess:!0})),l.DEFAULT_SUCCESS_SCREEN_DURATION_MS)));let t=await o(y?.public_key),a=Date.now()-e;"approved"===t.status?(clearInterval(r),m(!1),h(!0),x.current.push(setTimeout((()=>n({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),x.current.forEach((e=>clearTimeout(e)))}}),[]);let j="pending_approval"===y?.status?y.signer_approval_url:void 0;/*#__PURE__*/return e.jsx(q,{appName:s.name,loading:g,success:v,errorMessage:d,connectUri:j,onBack:t?a:void 0,onClose:n,onOpenFarcaster:()=>{j&&(window.location.href=j)}})}};exports.FarcasterSignerStatusScreen=S,exports.FarcasterSignerStatusView=q,exports.default=S;