useInfo.ts raw

   1  import useSWR, { SWRConfiguration } from "swr";
   2  
   3  import React from "react";
   4  import { backendTypeConfigs } from "src/lib/backendType";
   5  import { InfoResponse } from "src/types";
   6  import { swrFetcher } from "src/utils/swr";
   7  
   8  const pollConfiguration: SWRConfiguration = {
   9    refreshInterval: 3000,
  10  };
  11  
  12  export function useInfo(poll = false) {
  13    const info = useSWR<InfoResponse>(
  14      "/api/info",
  15      swrFetcher,
  16      poll ? pollConfiguration : undefined
  17    );
  18  
  19    return React.useMemo(
  20      () => ({
  21        ...info,
  22        hasChannelManagement:
  23          info.data?.backendType &&
  24          backendTypeConfigs[info.data.backendType].hasChannelManagement,
  25        hasMnemonic:
  26          info.data?.backendType &&
  27          backendTypeConfigs[info.data.backendType].hasMnemonic,
  28        hasNodeBackup:
  29          info.data?.backendType &&
  30          backendTypeConfigs[info.data.backendType].hasNodeBackup,
  31      }),
  32      [info]
  33    );
  34  }
  35