useBitcoinRate.ts raw

   1  import useSWR from "swr";
   2  
   3  import { BitcoinRate } from "src/types";
   4  import { swrFetcher } from "src/utils/swr";
   5  
   6  export function useBitcoinRate(currency?: string) {
   7    const shouldFetch = currency && currency !== "SATS";
   8  
   9    return useSWR<BitcoinRate>(
  10      shouldFetch ? `/api/alby/rates/${encodeURIComponent(currency)}` : null,
  11      swrFetcher
  12    );
  13  }
  14