@privy-io/react-auth
Version:
React client for the Privy Auth API
2 lines (1 loc) • 5.69 kB
JavaScript
import{jsx as e}from"react/jsx-runtime";import{useContext as o,useState as t,useEffect as r,createContext as i}from"react";import{u as n,b as c}from"./privy-context-V2csHgUI.mjs";import{ar as a,ae as l}from"./SignRequestScreen-NOqdMm22.mjs";import{P as s}from"./paths-B891YjWw.mjs";import{g as m}from"./getEmbeddedConnectedWallet-CSSBWE2p.mjs";import{u as p,g as h,a as u}from"./smart-wallets-DXnL6fHN.mjs";import{u as d,n as g}from"./internal-context-LlMdpfkb.mjs";import"viem";import"@heroicons/react/24/outline/CheckCircleIcon";import"@privy-io/js-sdk-core";import"@heroicons/react/24/outline/InformationCircleIcon";import"styled-components";import"@heroicons/react/24/outline/CreditCardIcon";import"@heroicons/react/24/outline/QrCodeIcon";import"@heroicons/react/24/solid/ArrowsRightLeftIcon";import"viem/utils";import"@heroicons/react/24/outline/ExclamationCircleIcon";import"@heroicons/react/24/outline/WalletIcon";import"@heroicons/react/24/outline/GlobeAltIcon";import"@headlessui/react";import"@heroicons/react/24/outline/ChevronDownIcon";import"@heroicons/react/24/solid/CheckCircleIcon";import"ofetch";import"@heroicons/react/24/outline";import"@heroicons/react/24/outline/ClipboardDocumentCheckIcon";import"@heroicons/react/24/outline/ClipboardDocumentIcon";import"@privy-io/ethereum";import"lucide-react";import"@heroicons/react/24/outline/ExclamationTriangleIcon";import"@scure/base";import"tinycolor2";import"@heroicons/react/24/outline/UserCircleIcon";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/Square2StackIcon";import"fast-password-entropy";import"secure-password-utilities";import"secure-password-utilities/wordlists";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"@tanstack/react-virtual";import"@heroicons/react/24/outline/CheckIcon";import"qrcode";import"eventemitter3";import"zustand";import"@walletconnect/ethereum-provider";import"@heroicons/react/24/outline/FingerPrintIcon";import"permissionless";import"permissionless/accounts";import"permissionless/clients/pimlico";import"viem/account-abstraction";let f=/*#__PURE__*/i({client:void 0,getClientForChain:g});const C=({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(f);return{client:e,getClientForChain:t}};let w=/*#__PURE__*/i({config:void 0}),v=()=>{let{config:e}=o(w);return{config:e}},y=({children:o})=>{let[i,n]=t(void 0),{client:c}=d();return r((()=>{!i&&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:i},children:o})},W=({config:o,children:i})=>{let{config:u}=v(),{appId:g}=d(),{chains:f,defaultChain:C,rpcConfig:I}=a(),{wallets:w}=l(),{user:y}=n(),[W,b]=t(),{wrapSmartAccountClientWithUIs:P}=p(),S=c(y),F=m(w);r((()=>{(async()=>{if(!u?.enabled)return;let e=u.configuredNetworks.find((e=>e.chainId===`eip155:${C.id}`))?C:f.find((e=>u.configuredNetworks.map((e=>e.chainId)).includes(`eip155:${e.id}`)));if(!e)throw new s("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 h({chain:e,privyAppId:g,paymasterContext:o?.paymasterContext,rpcConfig:I,account:S,signer:await(F?.getEthereumProvider()),user:y,smartWalletsConfig:u}))})()}),[!!u?.enabled,!!y?.smartWallet,!!F,!!S]);/*#__PURE__*/return e(k.Provider,{value:{client:W,config:o,getClientForChain:async({id:e})=>{let t=await h({chain:f.find((o=>o.id===e)),privyAppId:g,paymasterContext:o?.paymasterContext,rpcConfig:I,account:S,signer:await(F?.getEthereumProvider()),user:y,smartWalletsConfig:u});if(!t)throw new s(`Failed to create smart wallet client for chain id: ${e}`);return P(t)}},children:i})},k=/*#__PURE__*/i({client:void 0,config:void 0,getClientForChain:g}),b=({children:t})=>{let{client:i,config:c,getClientForChain:a}=(()=>{let{client:e,config:t,getClientForChain:r}=o(k);return{client:e,config:t,getClientForChain:r}})(),{config:l}=v(),{wrapSmartAccountClient:s}=u({clientConfig:c,smartWalletsConfig:l}),{user:m}=n(),{generateSiweMessageForSmartWallet:p,linkSmartWallet:h,hideWalletUIs:g}=d();return r((()=>{(async()=>{if(i&&m&&!m?.smartWallet&&l?.enabled)try{let e=await p({address:i.account.address,chainId:`eip155:${i.chain.id}`});g.current=!0;let o=await i.signMessage({message:e});await h({signature:o,message:e,smartWalletType:l.smartWalletType,smartWalletVersion:l.smartWalletVersion})}catch(e){console.error("Error creating smart wallet:",e)}finally{g.current=!1}})()}),[!!i,!!m?.smartWallet,!!l?.enabled]),/*#__PURE__*/e(f.Provider,{value:{client:m?.smartWallet&&i?s(i):void 0,getClientForChain:a},children:t})};export{C as SmartWalletsProvider,I as useSmartWallets};