@privy-io/react-auth
Version:
React client for the Privy Auth API
2 lines (1 loc) • 5.76 kB
JavaScript
import{jsx as e}from"react/jsx-runtime";import{useContext as o,createContext as t,useState as r,useEffect as i}from"react";import{$ as n,ab as c,b5 as a}from"./EmbeddedWalletConnectingScreen-D50stmJi.mjs";import{k as l}from"./events-context-ClaboIDc.mjs";import{aa as s,P as m,ad as p}from"./internal-context-eGSwROSk.mjs";import{a as h}from"./getEmbeddedConnectedWallet-CM6cDQCS.mjs";import{u,g as d,a as g}from"./smart-wallets-BXT3GZwg.mjs";import"lucide-react";import"viem";import"fast-password-entropy";import"secure-password-utilities";import"secure-password-utilities/wordlists";import"@heroicons/react/24/outline/UserCircleIcon";import"styled-components";import"@heroicons/react/24/outline/ArrowLeftIcon";import"@heroicons/react/24/outline/ArrowRightIcon";import"@heroicons/react/24/outline/QuestionMarkCircleIcon";import"@heroicons/react/24/outline/XMarkIcon";import"@heroicons/react/20/solid/CheckIcon";import"@heroicons/react/24/outline/EnvelopeIcon";import"@heroicons/react/24/outline/PhoneIcon";import"react-device-detect";import"@heroicons/react/24/outline/ExclamationTriangleIcon";import"@heroicons/react/24/outline/WalletIcon";import"@heroicons/react/24/outline/ExclamationCircleIcon";import"@heroicons/react/24/outline/Square2StackIcon";import"@privy-io/js-sdk-core";import"zustand";import"@heroicons/react/24/outline";import"@tanstack/react-virtual";import"@heroicons/react/24/outline/CheckIcon";import"qrcode";import"viem/utils";import"eventemitter3";import"@scure/base";import"@walletconnect/ethereum-provider";import"@heroicons/react/24/outline/CreditCardIcon";import"@heroicons/react/24/outline/QrCodeIcon";import"@heroicons/react/24/solid/ArrowsRightLeftIcon";import"@heroicons/react/24/outline/InformationCircleIcon";import"@heroicons/react/24/outline/ClipboardDocumentCheckIcon";import"@heroicons/react/24/outline/ClipboardDocumentIcon";import"@heroicons/react/24/outline/ChevronDownIcon";import"@privy-io/ethereum";import"@heroicons/react/24/outline/CheckCircleIcon";import"@heroicons/react/24/outline/GlobeAltIcon";import"@headlessui/react";import"@privy-io/popup";import"@heroicons/react/24/solid/CheckCircleIcon";import"ofetch";import"@heroicons/react/24/outline/FingerPrintIcon";import"@heroicons/react/24/outline/LockClosedIcon";import"@heroicons/react/24/outline/PencilSquareIcon";import"jose";import"@heroicons/react/24/outline/ArrowPathIcon";import"@heroicons/react/24/outline/EyeIcon";import"@heroicons/react/24/outline/EyeSlashIcon";import"@heroicons/react/24/outline/KeyIcon";import"@heroicons/react/24/outline/ArrowDownTrayIcon";import"@heroicons/react/24/outline/DocumentDuplicateIcon";import"@heroicons/react/24/solid/XCircleIcon";import"@heroicons/react/24/outline/ShieldCheckIcon";import"@privy-io/urls";import"tinycolor2";import"./SignRequestScreen-D9o7VhNz.mjs";import"permissionless";import"permissionless/accounts";import"permissionless/clients/pimlico";import"viem/account-abstraction";let C=/*#__PURE__*/t({client:void 0,getClientForChain:p});const f=({config:o,children:t})=>/*#__PURE__*/e(y,{children:/*#__PURE__*/e(W,{config:o,children:/*#__PURE__*/e(b,{children:t})})}),I=()=>{let{client:e,getClientForChain:t}=o(C);return{client:e,getClientForChain:t}};let w=/*#__PURE__*/t({config:void 0}),v=()=>{let{config:e}=o(w);return{config:e}},y=({children:o})=>{let[t,n]=r(void 0),{client:c}=s();return i((()=>{!t&&c&&(async()=>{try{if(!c)return void console.warn("No client found");let e=await c.getSmartWalletsConfig();n(e)}catch(e){console.warn("Error generating smart wallet config: ",e)}})()}),[!!c]),/*#__PURE__*/e(w.Provider,{value:{config:t},children:o})},W=({config:o,children:t})=>{let{config:p}=v(),{appId:g}=s(),{chains:C,defaultChain:f,rpcConfig:I}=l(),{wallets:w}=n(),{user:y}=c(),[W,b]=r(),{wrapSmartAccountClientWithUIs:S}=u(),P=a(y),F=h(w,P?.address);i((()=>{(async()=>{if(!p?.enabled)return;let e=p.configuredNetworks.find((e=>e.chainId===`eip155:${f.id}`))?f:C.find((e=>p.configuredNetworks.map((e=>e.chainId)).includes(`eip155:${e.id}`)));if(!e)throw new m("Could not find smart wallets chain configurations for any Privy client configured chains. Please configure smart wallets for your chains in the Privy dashboard.");b(await d({chain:e,privyAppId:g,paymasterContext:o?.paymasterContext,rpcConfig:I,account:P,signer:await(F?.getEthereumProvider()),user:y,smartWalletsConfig:p}))})()}),[!!p?.enabled,!!y?.smartWallet,!!F,!!P]);/*#__PURE__*/return e(k.Provider,{value:{client:W,config:o,getClientForChain:async({id:e})=>{let t=await d({chain:C.find((o=>o.id===e)),privyAppId:g,paymasterContext:o?.paymasterContext,rpcConfig:I,account:P,signer:await(F?.getEthereumProvider()),user:y,smartWalletsConfig:p});if(!t)throw new m(`Failed to create smart wallet client for chain id: ${e}`);return S(t)}},children:t})},k=/*#__PURE__*/t({client:void 0,config:void 0,getClientForChain:p}),b=({children:t})=>{let{client:r,config:n,getClientForChain:a}=(()=>{let{client:e,config:t,getClientForChain:r}=o(k);return{client:e,config:t,getClientForChain:r}})(),{config:l}=v(),{wrapSmartAccountClient:m}=g({clientConfig:n,smartWalletsConfig:l}),{user:p}=c(),{generateSiweMessageForSmartWallet:h,linkSmartWallet:u,hideWalletUIs:d}=s();return i((()=>{(async()=>{if(r&&p&&!p?.smartWallet&&l?.enabled)try{let e=await h({address:r.account.address,chainId:`eip155:${r.chain.id}`});d.current=!0;let o=await r.signMessage({message:e});await u({signature:o,message:e,smartWalletType:l.smartWalletType,smartWalletVersion:l.smartWalletVersion})}catch(e){console.error("Error creating smart wallet:",e)}finally{d.current=!1}})()}),[!!r,!!p?.smartWallet,!!l?.enabled]),/*#__PURE__*/e(C.Provider,{value:{client:p?.smartWallet&&r?m(r):void 0,getClientForChain:a},children:t})};export{f as SmartWalletsProvider,I as useSmartWallets};