@privy-io/react-auth
Version:
React client for the Privy Auth API
2 lines (1 loc) • 1.42 kB
JavaScript
import{g as r}from"./privy-context-DrMxzgOR.mjs";import{createPublicClient as e,http as t}from"viem";import{P as i}from"./internal-context-Z-fyxadS.mjs";import{useContext as p,createContext as l}from"react";const s=r=>{if("ethereum"===r.chainType)return{entropyId:r.address,entropyIdVerifier:"ethereum-address-verifier"};if("solana"===r.chainType)return{entropyId:r.address,entropyIdVerifier:"solana-address-verifier"};throw Error("Failed to get account entropy details")},a=(e,t)=>{if(t?.imported)return s(t);let i=r(e);if(!i)throw Error("Failed to find primary wallet");return s(i)},n=(r,p,l,s)=>{let a=Number(r),n=p.find((r=>r.id===a));if(!n)throw new i(`Unsupported chainId ${r}`,4901);return e({transport:t(o(n,l,s.appId)),chain:n})},o=(r,e,t)=>{let p,l=r.id,s=Number(r.id);if(r.rpcUrls.privyWalletOverride&&r.rpcUrls.privyWalletOverride.http[0])p=r.rpcUrls.privyWalletOverride.http[0];else if(e.rpcUrls&&e.rpcUrls[s])p=e.rpcUrls[s];else if(r.rpcUrls.privy?.http[0]){let e=new URL(r.rpcUrls.privy.http[0]);e.searchParams.append("privyAppId",t),p=e.toString()}else p=r.rpcUrls.public?.http[0]?r.rpcUrls.public.http[0]:r.rpcUrls.default?.http[0];if(!p)throw new i(`No RPC url found for ${l}`);return p},d=/*#__PURE__*/l(null);function c(){let r=p(d);return null===r?(console.warn("`useWallets` was called outside the PrivyProvider component"),{wallets:[],ready:!1}):r}export{d as U,n as a,o as b,a as g,s as t,c as u};