@privy-io/react-auth
Version:
React client for the Privy Auth API
5 lines (4 loc) • 6.91 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-C5Wuo3-1.js"),s=require("./ScreenLayout-C4QHZMbl.js"),a=require("./useActiveWallet-BfMD5hzE.js"),c=require("./PinInput-B12fA7pp.js"),l=require("@heroicons/react/24/outline/CalendarIcon"),d=require("@heroicons/react/24/outline/ExclamationTriangleIcon"),u=require("./StackedContainer-CM36po_U.js"),h=require("./internal-context-BJv4f_bO.js"),x=require("react"),j=require("styled-components"),m=require("viem"),p=require("./useGetTokenPrice-CSWuvKuF.js"),g=require("./useWallets-dikDynAG.js"),y=require("./index-DchMyzt9.js"),f=require("./TransactionDetails-BisPbyIV.js"),C=require("./context-Cg3IEi80.js");function I(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var k=/*#__PURE__*/I(r),T=/*#__PURE__*/I(n),M=/*#__PURE__*/I(t),S=/*#__PURE__*/I(i),P=/*#__PURE__*/I(l),q=/*#__PURE__*/I(d);const v=({pendingTransaction:r})=>{let{wallets:n}=g.useWallets(),{walletProxy:t,rpcConfig:i,chains:o,appId:s,nativeTokenSymbolForChainId:a}=h.usePrivyInternal(),[c,l]=x.useState(null),[d,u]=x.useState(r),{tokenPrice:j}=p.useGetTokenPrice(d.chainId),C=a(r.chainId)||"ETH",I=x.useMemo((()=>n.find((e=>"privy"===e.walletClientType))),[n]);return x.useEffect((()=>{(async function(){if(!t||!I)return d;let e=g.getPublicClient(d.chainId,o,i,{appId:s}),r=await y.prepareTransactionRequest(d,e,I.address);return l(m.toHex(BigInt(r.gas??0))),r})().then(u).catch(console.error)}),[t]),I?/*#__PURE__*/e.jsx(B,{children:/*#__PURE__*/e.jsx(f.TransactionDetails,{from:I.address,to:d.to,txn:d,gas:c??void 0,tokenPrice:j,tokenSymbol:C})}):null};let B=j.styled.div`
width: 100%;
padding: 1rem 0;
`;exports.VerifyMethodSelectionScreen=({handleClose:r,mfaMethods:n,onSelect:t})=>/*#__PURE__*/e.jsxs(s.ScreenLayout,{title:"Verify your identity",subtitle:"Choose a verification method",icon:S.default,iconVariant:"subtle",onClose:r,showClose:!0,watermark:!0,children:[/*#__PURE__*/e.jsxs(c.MethodList,{children:[n.includes("totp")&&/*#__PURE__*/e.jsxs(a.LoginMethodButton,{onClick:()=>t("totp"),children:[/*#__PURE__*/e.jsx(a.LoginMethodIconWrapper,{children:/*#__PURE__*/e.jsx(k.default,{})}),"Authenticator app"]},"totp"),n.includes("sms")&&/*#__PURE__*/e.jsxs(a.LoginMethodButton,{onClick:()=>t("sms"),children:[/*#__PURE__*/e.jsx(a.LoginMethodIconWrapper,{children:/*#__PURE__*/e.jsx(M.default,{})}),"SMS"]},"sms"),n.includes("passkey")&&/*#__PURE__*/e.jsxs(a.LoginMethodButton,{onClick:()=>t("passkey"),children:[/*#__PURE__*/e.jsx(a.LoginMethodIconWrapper,{children:/*#__PURE__*/e.jsx(T.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:x}=h.usePrivyInternal();/*#__PURE__*/return e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(o.ModalHeader,{onClose:t},"header"),/*#__PURE__*/e.jsx(u.e,{children:/*#__PURE__*/e.jsxs("div",{children:[/*#__PURE__*/e.jsx(a.ConnectionLoader,{success:d,fail:!!n}),n?/*#__PURE__*/e.jsx(q.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(S.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(P.default,{})}),"You last added a passkey on"," ",l?.firstVerifiedAt?.toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"}),"."]})]}),x&&/*#__PURE__*/e.jsx(c.Container,{children:/*#__PURE__*/e.jsx(v,{pendingTransaction:x})}),n&&/*#__PURE__*/e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(c.ErrorMessage,{style:{marginTop:"1.25rem"},children:n.message}),/*#__PURE__*/e.jsx(o.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=C.useAppConfig(),{pendingTransaction:d}=h.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(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 sent to your ",/*#__PURE__*/e.jsx("strong",{children:"mobile device"})]}),d&&/*#__PURE__*/e.jsx(v,{pendingTransaction:d})]}),s&&/*#__PURE__*/e.jsx(c.PrimaryTextButton,{theme:l?.appearance.palette.colorScheme,onClick:s,children:"Choose another method"}),/*#__PURE__*/e.jsx(o.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(k.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(v,{pendingTransaction:d})]}),s&&/*#__PURE__*/e.jsx(c.PrimaryTextButton,{theme:l?.appearance.palette.colorScheme,onClick:s,children:"Choose another method"}),/*#__PURE__*/e.jsx(o.SecondaryButton,{onClick:i,children:"Cancel"}),/*#__PURE__*/e.jsx(o.ModalFooter,{})]});default:return null}},exports.toUIError=e=>y.errorIndicatesMaxMfaRetries(e)?{isBlocking:!0,error:Error("You have exceeded the maximum number of attempts. Please close this window and try again in 10 seconds.")}:y.errorIndicatesMfaVerificationFailed(e)?{isBlocking:!1,error:Error("The code you entered is not valid")}:y.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.")});