@privy-io/react-auth
Version:
React client for the Privy Auth API
2 lines (1 loc) • 1.03 kB
JavaScript
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-Bycd1SKV.mjs";import{u as n}from"./internal-context-e-Eni5bG.mjs";import{u as t}from"./useGetSolPrice-Cfm8o9C5.mjs";function c(c){let{tokenPrice:a,isTokenPriceLoading:s,tokenPriceError:l}=(t=>{let{showFiatPrices:c,getUsdTokenPrice:a,chains:s}=n(),[l,P]=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 P(!1),void k(Error(`Unable to fetch token price on chain id ${t}`));try{P(!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{P(!1)}}else P(!1)})()}),[t]),{tokenPrice:m,isTokenPriceLoading:l,tokenPriceError:d}})("solana"===c?-1:c),{solPrice:P,isSolPriceLoading:d,solPriceError:k}=t({enabled:"solana"===c});return"solana"===c?{tokenPrice:P,isTokenPriceLoading:d,tokenPriceError:k}:{tokenPrice:a,isTokenPriceLoading:s,tokenPriceError:l}}export{c as u};