@privy-io/react-auth
Version:
React client for the Privy Auth API
2 lines (1 loc) • 6.29 kB
JavaScript
import{jsx as o}from"react/jsx-runtime";import{useContext as e,useState as i,useEffect as r,createContext as t}from"react";import{f as n,l as c,u as a}from"./privy-provider-B9AIp9rV.mjs";import{u as l,P as s,n as m}from"./internal-context-D5bEplez.mjs";import{g as p}from"./getEmbeddedConnectedWallet-CSSBWE2p.mjs";import{u as h,g as d,a as u}from"./smart-wallets-BiMjWB9y.mjs";import"mipd";import"react-device-detect";import"viem/utils";import"@privy-io/js-sdk-core";import"viem";import"uuid";import"jose";import"eventemitter3";import"@coinbase/wallet-sdk";import"@marsidev/react-turnstile";import"styled-components";import"tinycolor2";import"@heroicons/react/24/outline/DevicePhoneMobileIcon";import"@heroicons/react/24/outline/FingerPrintIcon";import"@heroicons/react/24/outline/PhoneIcon";import"@heroicons/react/24/outline/ShieldCheckIcon";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/24/outline/ChevronDownIcon";import"@heroicons/react/24/outline/CalendarIcon";import"@heroicons/react/24/outline/ExclamationTriangleIcon";import"@headlessui/react";import"@walletconnect/ethereum-provider";import"zustand";import"fast-password-entropy";import"secure-password-utilities";import"secure-password-utilities/wordlists";import"@heroicons/react/24/outline/UserCircleIcon";import"@heroicons/react/24/outline/EnvelopeIcon";import"@heroicons/react/20/solid/CheckIcon";import"@heroicons/react/24/outline/WalletIcon";import"@heroicons/react/24/outline/CheckIcon";import"@heroicons/react/24/outline/Square2StackIcon";import"@heroicons/react/24/outline/ExclamationCircleIcon";import"@heroicons/react/24/outline/ArrowTopRightOnSquareIcon";import"@heroicons/react/24/solid/DocumentCheckIcon";import"@heroicons/react/24/solid/XCircleIcon";import"@heroicons/react/24/solid/CheckCircleIcon";import"qrcode";import"@heroicons/react/24/outline/ChevronRightIcon";import"@heroicons/react/24/outline/LockClosedIcon";import"@heroicons/react/24/outline/PencilSquareIcon";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/ClipboardDocumentCheckIcon";import"@heroicons/react/24/outline/DocumentDuplicateIcon";import"@heroicons/react/24/solid/LockClosedIcon";import"@heroicons/react/24/outline/CheckCircleIcon";import"@heroicons/react/24/outline/InformationCircleIcon";import"@heroicons/react/24/outline/CreditCardIcon";import"@heroicons/react/24/outline/QrCodeIcon";import"@heroicons/react/24/solid/ArrowsRightLeftIcon";import"@heroicons/react/24/outline/GlobeAltIcon";import"ofetch";import"@heroicons/react/24/outline";import"@heroicons/react/24/outline/ClipboardDocumentIcon";import"@heroicons/react/24/outline/CloudArrowUpIcon";import"@heroicons/react/24/outline/NoSymbolIcon";import"@heroicons/react/24/outline/ClockIcon";import"@heroicons/react/24/outline/TrashIcon";import"@heroicons/react/24/solid/CheckBadgeIcon";import"@heroicons/react/24/solid/IdentificationIcon";import"@heroicons/react/24/outline/MinusCircleIcon";import"@heroicons/react/24/outline/ArrowRightEndOnRectangleIcon";import"@heroicons/react/24/solid/ShieldCheckIcon";import"js-cookie";import"permissionless";import"permissionless/accounts";import"permissionless/clients/pimlico";import"viem/account-abstraction";let C=/*#__PURE__*/t({client:void 0,getClientForChain:m});const g=({config:e,children:i})=>/*#__PURE__*/o(v,{children:/*#__PURE__*/o(y,{config:e,children:/*#__PURE__*/o(W,{children:i})})}),I=()=>{let{client:o,getClientForChain:i}=e(C);return{client:o,getClientForChain:i}};let f=/*#__PURE__*/t({config:void 0}),w=()=>{let{config:o}=e(f);return{config:o}},v=({children:e})=>{let[t,n]=i(void 0),{client:c}=l();return r((()=>{!t&&c&&(async()=>{try{if(!c)return void console.warn("No client found");let o=await c.getSmartWalletsConfig();n(o)}catch(o){console.warn("Error generating smart wallet config: ",o)}})()}),[!!c]),/*#__PURE__*/o(f.Provider,{value:{config:t},children:e})},y=({config:e,children:t})=>{let{config:m}=w(),{appId:u}=l(),{chains:C,defaultChain:g,rpcConfig:I}=n(),{wallets:f}=c(),{user:v}=a(),[y,W]=i(),{wrapSmartAccountClientWithUIs:b}=h(),S=p(f);r((()=>{(async()=>{if(!m?.enabled)return;let o=m.configuredNetworks.find((o=>o.chainId===`eip155:${g.id}`))?g:C.find((o=>m.configuredNetworks.map((o=>o.chainId)).includes(`eip155:${o.id}`)));if(!o)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.");W(await d({chain:o,privyAppId:u,paymasterContext:e?.paymasterContext,rpcConfig:I,embeddedWallet:S,user:v,smartWalletsConfig:m}))})()}),[!!m?.enabled,!!v?.smartWallet,!!S]);/*#__PURE__*/return o(k.Provider,{value:{client:y,config:e,getClientForChain:async({id:o})=>{let i=p(f),r=await d({chain:C.find((e=>e.id===o)),privyAppId:u,paymasterContext:e?.paymasterContext,rpcConfig:I,embeddedWallet:i,user:v,smartWalletsConfig:m});if(!r)throw new s(`Failed to create smart wallet client for chain id: ${o}`);return b(r)}},children:t})},k=/*#__PURE__*/t({client:void 0,config:void 0,getClientForChain:m}),W=({children:i})=>{let{client:t,config:n,getClientForChain:c}=(()=>{let{client:o,config:i,getClientForChain:r}=e(k);return{client:o,config:i,getClientForChain:r}})(),{config:s}=w(),{wrapSmartAccountClient:m}=u({clientConfig:n,smartWalletsConfig:s}),{user:p}=a(),{generateSiweMessageForSmartWallet:h,linkSmartWallet:d,hideWalletUIs:g}=l();return r((()=>{(async()=>{if(t&&p&&!p?.smartWallet&&s?.enabled)try{let o=await h({address:t.account.address,chainId:`eip155:${t.chain.id}`});g.current=!0;let e=await t.signMessage({message:o});await d({signature:e,message:o,smartWalletType:s.smartWalletType})}catch(o){console.error("Error creating smart wallet:",o)}finally{g.current=!1}})()}),[!!t,!!p?.smartWallet,!!s?.enabled]),/*#__PURE__*/o(C.Provider,{value:{client:p?.smartWallet&&t?m(t):void 0,getClientForChain:c},children:i})};export{g as SmartWalletsProvider,I as useSmartWallets};