UNPKG

@privy-io/react-auth

Version:

React client for the Privy Auth API

2 lines (1 loc) 1.03 kB
import{useState as r,useEffect as e}from"react";import{addToDefaultChains as o}from"@privy-io/js-sdk-core";import{s as i}from"./context-WTldtXS8.mjs";import{u as n}from"./internal-context-Z-fyxadS.mjs";import{u as t}from"./useGetSolPrice-DwwjjGbd.mjs";function c(c){let{tokenPrice:a,isTokenPriceLoading:s,tokenPriceError:P}=(t=>{let{showFiatPrices:c,getUsdTokenPrice:a,chains:s}=n(),[P,l]=r(!0),[d,k]=r(void 0),[m,f]=r(void 0);return e((()=>{t||=i;let r=o(s).find((r=>r.id===Number(t)));(async()=>{if(c){if(!r)return l(!1),void k(Error(`Unable to fetch token price on chain id ${t}`));try{l(!0);let e=await a(r);e?f(e):k(Error(`Unable to fetch token price on chain id ${r.id}`))}catch(r){k(r)}finally{l(!1)}}else l(!1)})()}),[t]),{tokenPrice:m,isTokenPriceLoading:P,tokenPriceError:d}})("solana"===c?-1:c),{solPrice:l,isSolPriceLoading:d,solPriceError:k}=t({enabled:"solana"===c});return"solana"===c?{tokenPrice:l,isTokenPriceLoading:d,tokenPriceError:k}:{tokenPrice:a,isTokenPriceLoading:s,tokenPriceError:P}}export{c as u};