@privy-io/react-auth
Version:
React client for the Privy Auth API
8 lines (7 loc) • 4.78 kB
JavaScript
import{jsxs as e,jsx as o,Fragment as r}from"react/jsx-runtime";import t from"@heroicons/react/24/outline/LockClosedIcon";import i from"@heroicons/react/24/outline/PencilSquareIcon";import s from"@heroicons/react/24/outline/QuestionMarkCircleIcon";import{useState as c}from"react";import{styled as n}from"styled-components";import{a,u as l,g as p}from"./get-is-unified-wallet-Boa8DYrQ.mjs";import{M as d,B as u,P as m}from"./ModalHeader-D8-mhjp4.mjs";import{C as h}from"./ScreenHeader-CHmc4-Lu.mjs";import{u as y}from"./context-WTldtXS8.mjs";import{u as v}from"./internal-context-Z-fyxadS.mjs";import{w as g}from"./index-BBRkihRn.mjs";import{R as f,A as w,G as C,a as j}from"./styles-BsotlekN.mjs";import{U as k}from"./useActiveWallet-3RHPIBxJ.mjs";import"@privy-io/are-addresses-equal";import"@heroicons/react/24/outline/ArrowLeftIcon";import"@heroicons/react/24/outline/ArrowRightIcon";import"@heroicons/react/24/outline/XMarkIcon";import"@privy-io/js-sdk-core";import"tinycolor2";import"ofetch";import"uuid";import"jose";import"eventemitter3";import"./useWallets-CR0z5IIt.mjs";import"./use-export-wallet-CV4p7L0b.mjs";import"viem/utils";import"@coinbase/wallet-sdk";import"@privy-io/ethereum";import"mipd";import"react-device-detect";import"@privy-io/popup";import"./paths-3HW55qZg.mjs";import"./usePrivy-6nkpbErN.mjs";import"./events-context-CI0iqAXA.mjs";import"@scure/base";import"zustand";import"@headlessui/react";import"@walletconnect/ethereum-provider";import"@privy-io/urls";import"viem";import"./PrivyPluginContext-2QN2dVUw.mjs";import"./getEmbeddedConnectedWallet-JzK4iD-L.mjs";import"./getPublicClient-B4uPLKn-.mjs";import"js-cookie";import"./frame-uzTmvtww.mjs";import"@privy-io/routes";import"x402/client";import"@privy-io/api-base";import"viem/accounts";import"./use-sign-with-user-signer-Do5Oi_rb.mjs";let S=n.div`
width: 24px;
height: 24px;
display: flex;
justify-content: center;
align-items: center;
`,x={"google-drive":"Google Drive",icloud:"iCloud","user-passcode":"password",privy:"Privy","privy-v2":"Privy"},A=({onClose:t})=>/*#__PURE__*/e(j,{children:[/*#__PURE__*/o(h,{title:"Why do I need to secure my account?",icon:/*#__PURE__*/o(s,{width:48}),description:/*#__PURE__*/e(r,{children:[/*#__PURE__*/o("p",{children:"Your app uses cryptography to secure your account. App secrets are split and encrypted so only you can access them."}),/*#__PURE__*/o("p",{children:"To use this app on new devices, secure account secrets using a password, your Google or your Apple account. It’s important you don’t lose access to the method you choose."})]})}),/*#__PURE__*/o(m,{onClick:t,children:"Select backup method"})]});const P={component:()=>{let[s,n]=c(!1),{navigate:m,lastScreen:j,navigateBack:P,setModalData:b,data:I,onUserCloseViaDialogOrKeybindRef:M}=a(),{user:O}=l(),{embeddedWallets:W}=y(),{closePrivyModal:R}=v(),F=p(O),B=null===F,{isInAccountCreateFlow:D,isResettingPassword:E,shouldCreateEth:G,shouldCreateSol:U}=I.recoverySelection,q=F&&"privy"!==F.recoveryMethod,H=q?/*#__PURE__*/e("span",{children:["Your account is currently secured using"," ",/*#__PURE__*/o("strong",{children:x[F?.recoveryMethod||"user-passcode"]}),"."]}):"Select a method for logging in on new devices and recovering your account.";function L(e){b({recoveryOAuthStatus:{provider:e,action:B?"create-wallet":"set-recovery",isInAccountCreateFlow:D,shouldCreateEth:G,shouldCreateSol:U}}),m("RecoveryOAuthScreen")}function Y(){I?.setWalletPassword?.onFailure(Error("User exited set recovery flow")),R({shouldCallAuthOnSuccess:I?.setWalletPassword?.callAuthOnSuccessOnClose??!1})}return M.current=Y,/*#__PURE__*/e(r,{children:[/*#__PURE__*/o(d,{onClose:Y,backFn:s?()=>n(!1):j?P:void 0,infoFn:j||s?void 0:()=>n(!0)},"header"),s?/*#__PURE__*/o(A,{onClose:()=>n(!1)}):/*#__PURE__*/e(r,{children:[/*#__PURE__*/o(h,{title:q?"Update backup method":"Secure your account",icon:/*#__PURE__*/o(t,{width:48}),description:H}),/*#__PURE__*/o(f,{children:W.userOwnedRecoveryOptions.filter((e=>!["icloud","google-drive"].includes(F?.recoveryMethod||"")||e!==F?.recoveryMethod)).sort().map((r=>{switch(r){case"google-drive":/*#__PURE__*/return e(k,{onClick:()=>L("google-drive"),children:[/*#__PURE__*/o(S,{children:/*#__PURE__*/o(C,{style:{width:18}})}),"Back up to Google Drive"]},r);case"icloud":/*#__PURE__*/return e(k,{onClick:()=>L("icloud"),children:[/*#__PURE__*/o(S,{children:/*#__PURE__*/o(w,{style:{width:24}})}),"Back up to Apple iCloud"]},r);case"user-passcode":/*#__PURE__*/return e(k,{onClick:()=>{m(g({isCreatingWallet:B,skipSplashScreen:!0}))},children:[/*#__PURE__*/o(S,{children:/*#__PURE__*/o(i,{style:{width:18}})}),E?"Reset your":"Set a"," password"]},r);default:return null}}))})]}),/*#__PURE__*/o(u,{})]})}};export{P as RecoverySelectionScreen,P as default};