@privy-io/react-auth
Version:
React client for the Privy Auth API
5 lines (4 loc) • 5.71 kB
JavaScript
import{jsxs as e,jsx as r,Fragment as o}from"react/jsx-runtime";import n from"@heroicons/react/24/outline/DevicePhoneMobileIcon";import i from"@heroicons/react/24/outline/FingerPrintIcon";import t from"@heroicons/react/24/outline/PhoneIcon";import a from"@heroicons/react/24/outline/ShieldCheckIcon";import{b as s,M as c,P as l,S as d}from"./ModalHeader-BnVmXtvG.mjs";import{S as h}from"./ScreenLayout-D1p_ntex.mjs";import{A as m,C as p,N as u}from"./useActiveWallet-CvP7iYvj.mjs";import{M as g,F as f,T as y,L as C,b as k,c as T,C as S,E as b,P as v,I,N as w,S as j}from"./PinInput-3SLvbnQa.mjs";import P from"@heroicons/react/24/outline/CalendarIcon";import x from"@heroicons/react/24/outline/ExclamationTriangleIcon";import{e as B}from"./StackedContainer-B2vaEl56.mjs";import{u as E}from"./internal-context-Z-fyxadS.mjs";import{useState as M,useMemo as A,useEffect as V}from"react";import{styled as L}from"styled-components";import{toHex as N}from"viem";import{u as D}from"./useGetTokenPrice-LPJMl6JV.mjs";import{u as F,a as Y}from"./useWallets-BzNCTucF.mjs";import{p as H,j as W,g as G,h as O}from"./index-YDEix4mU.mjs";import{T as Q}from"./TransactionDetails-DqFIa7IO.mjs";import{u as q}from"./context-DLtU3JQy.mjs";const z=({handleClose:o,mfaMethods:c,onSelect:l})=>/*#__PURE__*/e(h,{title:"Verify your identity",subtitle:"Choose a verification method",icon:a,iconVariant:"subtle",onClose:o,showClose:!0,watermark:!0,children:[/*#__PURE__*/e(g,{children:[c.includes("totp")&&/*#__PURE__*/e(m,{onClick:()=>l("totp"),children:[/*#__PURE__*/r(p,{children:/*#__PURE__*/r(n,{})}),"Authenticator app"]},"totp"),c.includes("sms")&&/*#__PURE__*/e(m,{onClick:()=>l("sms"),children:[/*#__PURE__*/r(p,{children:/*#__PURE__*/r(t,{})}),"SMS"]},"sms"),c.includes("passkey")&&/*#__PURE__*/e(m,{onClick:()=>l("passkey"),children:[/*#__PURE__*/r(p,{children:/*#__PURE__*/r(i,{})}),"Passkey"]},"passkey")]}),/*#__PURE__*/r(s,{})]}),J=({pendingTransaction:e})=>{let{wallets:o}=F(),{walletProxy:n,rpcConfig:i,chains:t,appId:a,nativeTokenSymbolForChainId:s}=E(),[c,l]=M(null),[d,h]=M(e),{tokenPrice:m}=D(d.chainId),p=s(e.chainId)||"ETH",u=A((()=>o.find((e=>"privy"===e.walletClientType))),[o]);return V((()=>{(async function(){if(!n||!u)return d;let e=Y(d.chainId,t,i,{appId:a}),r=await H(d,e,u.address);return l(N(BigInt(r.gas??0))),r})().then(h).catch(console.error)}),[n]),u?/*#__PURE__*/r(K,{children:/*#__PURE__*/r(Q,{from:u.address,to:d.to,txn:d,gas:c??void 0,tokenPrice:m,tokenSymbol:p})}):null};let K=L.div`
width: 100%;
padding: 1rem 0;
`;const R=({hasBlockingError:n,error:i,onClose:t,onBack:d,handleSubmit:h,account:m,submitSuccess:p})=>{let{pendingTransaction:g}=E();/*#__PURE__*/return e(o,{children:[/*#__PURE__*/r(c,{onClose:t},"header"),/*#__PURE__*/r(B,{children:/*#__PURE__*/e("div",{children:[/*#__PURE__*/r(u,{success:p,fail:!!i}),/*#__PURE__*/r(i?x:f,{style:{width:"38px",height:"38px"}})]})}),/*#__PURE__*/r(y,{style:{marginTop:"1rem"},children:"Verifying with passkey"}),/*#__PURE__*/e(C,{children:[/*#__PURE__*/e(k,{children:[/*#__PURE__*/r(T,{children:/*#__PURE__*/r(a,{})}),"Approve this action using your touch, face, PIN, or hardware key."]}),/*#__PURE__*/e(k,{children:[/*#__PURE__*/r(T,{children:/*#__PURE__*/r(P,{})}),"You last added a passkey on"," ",m?.firstVerifiedAt?.toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"}),"."]})]}),g&&/*#__PURE__*/r(S,{children:/*#__PURE__*/r(J,{pendingTransaction:g})}),i&&/*#__PURE__*/e(o,{children:[/*#__PURE__*/r(b,{style:{marginTop:"1.25rem"},children:i.message}),/*#__PURE__*/r(l,{disabled:n,onClick:h,style:{margin:"1.25rem auto 0"},children:"Try again"})]}),d&&/*#__PURE__*/r(v,{style:{marginTop:"1rem"},onClick:d,children:"Choose another method"}),/*#__PURE__*/r(s,{})]})},U=({selectedMethod:i,submitSuccess:a,hasBlockingError:l,onClose:h,onBack:m,handleSubmitCode:p})=>{let u=q(),{pendingTransaction:g}=E();switch(i){case"sms":/*#__PURE__*/return e(o,{children:[/*#__PURE__*/r(c,{onClose:h},"header"),/*#__PURE__*/r(I,{style:{marginBottom:"1.5rem"},children:/*#__PURE__*/r(t,{})}),/*#__PURE__*/r(y,{children:"Enter verification code"}),/*#__PURE__*/e(S,{children:[/*#__PURE__*/r(w,{success:a,disabled:l,onChange:p}),/*#__PURE__*/e(j,{children:["To continue, please enter the 6-digit code sent to your ",/*#__PURE__*/r("strong",{children:"mobile device"})]}),g&&/*#__PURE__*/r(J,{pendingTransaction:g})]}),m&&/*#__PURE__*/r(v,{theme:u?.appearance.palette.colorScheme,onClick:m,children:"Choose another method"}),/*#__PURE__*/r(d,{onClick:h,children:"Cancel"}),/*#__PURE__*/r(s,{})]});case"totp":/*#__PURE__*/return e(o,{children:[/*#__PURE__*/r(c,{onClose:h},"header"),/*#__PURE__*/r(I,{style:{marginBottom:"1.5rem"},children:/*#__PURE__*/r(n,{})}),/*#__PURE__*/r(y,{children:"Enter verification code"}),/*#__PURE__*/e(S,{children:[/*#__PURE__*/r(w,{success:a,disabled:l,onChange:p}),/*#__PURE__*/e(j,{children:["To continue, please enter the 6-digit code generated from your"," ",/*#__PURE__*/r("strong",{children:"authenticator app"})]}),g&&/*#__PURE__*/r(J,{pendingTransaction:g})]}),m&&/*#__PURE__*/r(v,{theme:u?.appearance.palette.colorScheme,onClick:m,children:"Choose another method"}),/*#__PURE__*/r(d,{onClick:h,children:"Cancel"}),/*#__PURE__*/r(s,{})]});default:return null}},X=e=>W(e)?{isBlocking:!0,error:Error("You have exceeded the maximum number of attempts. Please close this window and try again in 10 seconds.")}:G(e)?{isBlocking:!1,error:Error("The code you entered is not valid")}:O(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.")});export{R as V,U as a,z as b,X as t};