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