UNPKG

@ledgerhq/live-common

Version:
25 lines 1.18 kB
import { useQueries } from "@tanstack/react-query"; import { fetchCurrency } from "../api"; import { QUERY_KEY } from "../utils/queryKeys"; import { REFETCH_TIME_ONE_MINUTE, BASIC_REFETCH } from "../utils/timers"; import { format } from "../utils/currencyFormatter"; import { listCryptoCurrencies } from "@ledgerhq/cryptoassets/currencies"; const cryptoCurrenciesList = [...listCryptoCurrencies()]; export const useLargeMoverCurrencies = ({ ids, counterCurrency, }) => { const currencyQueries = useQueries({ queries: ids.map(id => ({ queryKey: [QUERY_KEY.CurrencyDataRaw, id, counterCurrency], queryFn: () => fetchCurrency({ id, counterCurrency }), refetchInterval: REFETCH_TIME_ONE_MINUTE * BASIC_REFETCH, staleTime: REFETCH_TIME_ONE_MINUTE * BASIC_REFETCH, select: (data) => format(data, cryptoCurrenciesList), })), }); return ids.map((id, index) => ({ id, data: currencyQueries[index]?.data, isLoading: currencyQueries[index]?.isLoading || false, isError: currencyQueries[index]?.isError || false, })); }; //# sourceMappingURL=useLargeMoverCurrencies.js.map