UNPKG

@privy-io/react-auth

Version:

React client for the Privy Auth API

2 lines (1 loc) 1.59 kB
"use strict";var r=require("./privy-context-CrM9_s6G.js"),e=require("viem"),t=require("./internal-context-BJv4f_bO.js"),i=require("react");const l=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")},n=(r,e,i)=>{let l,n=r.id,o=Number(r.id);if(r.rpcUrls.privyWalletOverride&&r.rpcUrls.privyWalletOverride.http[0])l=r.rpcUrls.privyWalletOverride.http[0];else if(e.rpcUrls&&e.rpcUrls[o])l=e.rpcUrls[o];else if(r.rpcUrls.privy?.http[0]){let e=new URL(r.rpcUrls.privy.http[0]);e.searchParams.append("privyAppId",i),l=e.toString()}else l=r.rpcUrls.public?.http[0]?r.rpcUrls.public.http[0]:r.rpcUrls.default?.http[0];if(!l)throw new t.PrivyConnectorError(`No RPC url found for ${n}`);return l},o=/*#__PURE__*/i.createContext(null);exports.UseWalletsContext=o,exports.getEntropyDetailsForUser=(e,t)=>{if(t?.imported)return l(t);let i=r.getPrivyPrimaryWallet(e);if(!i)throw Error("Failed to find primary wallet");return l(i)},exports.getJsonRpcEndpointFromChain=n,exports.getPublicClient=(r,i,l,o)=>{let p=Number(r),s=i.find((r=>r.id===p));if(!s)throw new t.PrivyConnectorError(`Unsupported chainId ${r}`,4901);return e.createPublicClient({transport:e.http(n(s,l,o.appId)),chain:s})},exports.toEntropyDetailsFromAccount=l,exports.useWallets=function(){let r=i.useContext(o);return null===r?(console.warn("`useWallets` was called outside the PrivyProvider component"),{wallets:[],ready:!1}):r};