useSwaps.tsx raw

   1  import useSWR, { SWRConfiguration } from "swr";
   2  
   3  import { AutoSwapConfig, Swap, SwapInfo } from "src/types";
   4  import { swrFetcher } from "src/utils/swr";
   5  
   6  export function useAutoSwapsConfig() {
   7    return useSWR<AutoSwapConfig>("/api/autoswap", swrFetcher);
   8  }
   9  
  10  export function useSwapInfo(direction: "in" | "out") {
  11    return useSWR<SwapInfo>(`/api/swaps/${direction}/info`, swrFetcher);
  12  }
  13  
  14  const pollConfiguration: SWRConfiguration = {
  15    refreshInterval: 3000,
  16  };
  17  
  18  export function useSwap<T = Swap>(swapId: string | undefined, poll = false) {
  19    return useSWR<T>(
  20      swapId && `/api/swaps/${swapId}`,
  21      swrFetcher,
  22      poll ? pollConfiguration : undefined
  23    );
  24  }
  25