@privy-io/react-auth
Version:
React client for the Privy Auth API
2 lines (1 loc) • 7.1 kB
JavaScript
"use strict";var e=require("react/jsx-runtime"),r=require("@heroicons/react/24/outline/DevicePhoneMobileIcon"),n=require("@heroicons/react/24/outline/FingerPrintIcon"),t=require("@heroicons/react/24/outline/PhoneIcon"),i=require("@heroicons/react/24/outline/ShieldCheckIcon"),o=require("./ModalHeader-DB7Tbjwz.js"),s=require("./ScreenLayout-BeH-Q6N2.js"),a=require("./useActiveWallet-BOX8xCn9.js"),c=require("./PinInput-DSI6rjOn.js"),l=require("@heroicons/react/24/outline/CalendarIcon"),d=require("@heroicons/react/24/outline/ExclamationTriangleIcon"),u=require("./Button-Bm_Ft0Dw.js"),h=require("./StackedContainer-ByB6Mdu0.js"),x=require("./internal-context-NWsAL807.js"),j=require("react"),m=require("styled-components"),p=require("viem"),g=require("./useGetTokenPrice-BHq-guWz.js"),y=require("./useWallets-BLFNjTwC.js"),f=require("./index-NJrQkxJ7.js"),C=require("./getPublicClient-CGlodIp_.js"),I=require("./TransactionDetails-KB5Wyu1l.js"),k=require("./context-DFq1obBO.js");function T(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var M=/*#__PURE__*/T(r),S=/*#__PURE__*/T(n),P=/*#__PURE__*/T(t),q=/*#__PURE__*/T(i),v=/*#__PURE__*/T(l),B=/*#__PURE__*/T(d);const b=({pendingTransaction:r})=>{let{wallets:n}=y.useWallets(),{walletProxy:t,rpcConfig:i,chains:o,appId:s,nativeTokenSymbolForChainId:a}=x.usePrivyInternal(),[c,l]=j.useState(null),[d,u]=j.useState(r),{tokenPrice:h}=g.useGetTokenPrice(d.chainId),m=a(r.chainId)||"ETH",k=j.useMemo((()=>n.find((e=>"privy"===e.walletClientType))),[n]);return j.useEffect((()=>{(async function(){if(!t||!k)return d;let e=C.getPublicClient(d.chainId,o,i,{appId:s}),r=await f.prepareTransactionRequest(d,e,k.address);return l(p.toHex(BigInt(r.gas??0))),r})().then(u).catch(console.error)}),[t]),k?/*#__PURE__*/e.jsx(w,{children:/*#__PURE__*/e.jsx(I.TransactionDetails,{from:k.address,to:d.to,txn:d,gas:c??void 0,tokenPrice:h,tokenSymbol:m})}):null};let w=/*#__PURE__*/m.styled.div.withConfig({displayName:"TransactionInfoWrapper",componentId:"sc-8d9a2f57-0"})(["width:100%;padding:1rem 0;"]);exports.VerifyMethodSelectionScreen=({handleClose:r,user:n,onSelect:t})=>/*#__PURE__*/e.jsxs(s.ScreenLayout,{title:"Verify your identity",subtitle:"Choose a verification method",icon:q.default,iconVariant:"subtle",onClose:r,showClose:!0,watermark:!0,children:[/*#__PURE__*/e.jsxs(c.MethodList,{children:[n.mfaMethods.includes("totp")&&/*#__PURE__*/e.jsxs(a.LoginMethodButton,{onClick:()=>t("totp"),children:[/*#__PURE__*/e.jsx(a.LoginMethodIconWrapper,{children:/*#__PURE__*/e.jsx(M.default,{})}),"Authenticator app"]},"totp"),n.mfaMethods.includes("sms")&&/*#__PURE__*/e.jsxs(a.LoginMethodButton,{onClick:()=>t("sms"),children:[/*#__PURE__*/e.jsx(a.LoginMethodIconWrapper,{children:/*#__PURE__*/e.jsx(P.default,{})}),"SMS"]},"sms"),n.mfaMethods.includes("passkey")&&/*#__PURE__*/e.jsxs(a.LoginMethodButton,{onClick:()=>t("passkey"),children:[/*#__PURE__*/e.jsx(a.LoginMethodIconWrapper,{children:/*#__PURE__*/e.jsx(S.default,{})}),"Passkey"]},"passkey")]}),/*#__PURE__*/e.jsx(o.ModalFooter,{})]}),exports.VerifyWithPasskey=({hasBlockingError:r,error:n,onClose:t,onBack:i,handleSubmit:s,account:l,submitSuccess:d})=>{let{pendingTransaction:j}=x.usePrivyInternal();/*#__PURE__*/return e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(o.ModalHeader,{onClose:t},"header"),/*#__PURE__*/e.jsx(h.e,{children:/*#__PURE__*/e.jsxs("div",{children:[/*#__PURE__*/e.jsx(a.ConnectionLoader,{success:d,fail:!!n}),n?/*#__PURE__*/e.jsx(B.default,{style:{width:"38px",height:"38px"}}):/*#__PURE__*/e.jsx(c.FaceId,{style:{width:"38px",height:"38px"}})]})}),/*#__PURE__*/e.jsx(c.Title,{style:{marginTop:"1rem"},children:"Verifying with passkey"}),/*#__PURE__*/e.jsxs(c.List,{children:[/*#__PURE__*/e.jsxs(c.ListItem,{children:[/*#__PURE__*/e.jsx(c.ListItemIcon,{children:/*#__PURE__*/e.jsx(q.default,{})}),"Approve this action using your touch, face, PIN, or hardware key."]}),/*#__PURE__*/e.jsxs(c.ListItem,{children:[/*#__PURE__*/e.jsx(c.ListItemIcon,{children:/*#__PURE__*/e.jsx(v.default,{})}),"You last added a passkey on"," ",l?.firstVerifiedAt?.toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"}),"."]})]}),j&&/*#__PURE__*/e.jsx(c.Container,{children:/*#__PURE__*/e.jsx(b,{pendingTransaction:j})}),n&&/*#__PURE__*/e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(c.ErrorMessage,{style:{marginTop:"1.25rem"},children:n.message}),/*#__PURE__*/e.jsx(u.PrimaryButton,{disabled:r,onClick:s,style:{margin:"1.25rem auto 0"},children:"Try again"})]}),i&&/*#__PURE__*/e.jsx(c.PrimaryTextButton,{style:{marginTop:"1rem"},onClick:i,children:"Choose another method"}),/*#__PURE__*/e.jsx(o.ModalFooter,{})]})},exports.VerifyWithSmsOrTotpCode=({selectedMethod:r,submitSuccess:n,hasBlockingError:t,onClose:i,onBack:s,handleSubmitCode:a})=>{let l=k.useAppConfig(),{pendingTransaction:d}=x.usePrivyInternal();switch(r){case"sms":/*#__PURE__*/return e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(o.ModalHeader,{onClose:i},"header"),/*#__PURE__*/e.jsx(c.IconWrapper,{style:{marginBottom:"1.5rem"},children:/*#__PURE__*/e.jsx(P.default,{})}),/*#__PURE__*/e.jsx(c.Title,{children:"Enter verification code"}),/*#__PURE__*/e.jsxs(c.Container,{children:[/*#__PURE__*/e.jsx(c.NumericPinInput,{success:n,disabled:t,onChange:a}),/*#__PURE__*/e.jsxs(c.SubTitle,{children:["To continue, please enter the 6-digit code sent to your ",/*#__PURE__*/e.jsx("strong",{children:"mobile device"})]}),d&&/*#__PURE__*/e.jsx(b,{pendingTransaction:d})]}),s&&/*#__PURE__*/e.jsx(c.PrimaryTextButton,{theme:l?.appearance.palette.colorScheme,onClick:s,children:"Choose another method"}),/*#__PURE__*/e.jsx(u.SecondaryButton,{onClick:i,children:"Cancel"}),/*#__PURE__*/e.jsx(o.ModalFooter,{})]});case"totp":/*#__PURE__*/return e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(o.ModalHeader,{onClose:i},"header"),/*#__PURE__*/e.jsx(c.IconWrapper,{style:{marginBottom:"1.5rem"},children:/*#__PURE__*/e.jsx(M.default,{})}),/*#__PURE__*/e.jsx(c.Title,{children:"Enter verification code"}),/*#__PURE__*/e.jsxs(c.Container,{children:[/*#__PURE__*/e.jsx(c.NumericPinInput,{success:n,disabled:t,onChange:a}),/*#__PURE__*/e.jsxs(c.SubTitle,{children:["To continue, please enter the 6-digit code generated from your"," ",/*#__PURE__*/e.jsx("strong",{children:"authenticator app"})]}),d&&/*#__PURE__*/e.jsx(b,{pendingTransaction:d})]}),s&&/*#__PURE__*/e.jsx(c.PrimaryTextButton,{theme:l?.appearance.palette.colorScheme,onClick:s,children:"Choose another method"}),/*#__PURE__*/e.jsx(u.SecondaryButton,{onClick:i,children:"Cancel"}),/*#__PURE__*/e.jsx(o.ModalFooter,{})]});default:return null}},exports.toUIError=e=>f.errorIndicatesMaxMfaRetries(e)?{isBlocking:!0,error:Error("You have exceeded the maximum number of attempts. Please close this window and try again in 10 seconds.")}:f.errorIndicatesMfaVerificationFailed(e)?{isBlocking:!1,error:Error("The code you entered is not valid")}:f.errorIndicatesMfaTimeout(e)?{isBlocking:!0,error:Error("You have exceeded the time limit for code entry. Please try again in 30 seconds.")}:(console.error(e),{isBlocking:!1,error:Error("Something went wrong.")});