Skip to content

Commit

Permalink
Move logic outside Fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
mcayuelas-ledger committed Mar 22, 2024
1 parent d400c74 commit 015a7d5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 3 additions & 4 deletions libs/ledger-live-common/src/market/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import {
RawCurrencyData,
MarketPerformersParams,
MarketItemResponse,
MarketItemPerformer,
SupportedCoins,
} from "../types";
import { rangeDataTable } from "../utils/rangeDataTable";
import { currencyFormatter, formatPerformer } from "../utils/currencyFormatter";
import { currencyFormatter } from "../utils/currencyFormatter";
import URL from "url";
import { getRange } from "../utils/rangeFormatter";

Expand Down Expand Up @@ -285,7 +284,7 @@ export async function fetchMarketPerformers({
top = 50,
sort,
supported,
}: MarketPerformersParams): Promise<MarketItemPerformer[]> {
}: MarketPerformersParams): Promise<MarketItemResponse[]> {
const sortParam = `${sort === "asc" ? "positive" : "negative"}-price-change-${getRange(range)}`;

const url = URL.format({
Expand All @@ -301,7 +300,7 @@ export async function fetchMarketPerformers({

const { data } = await network({ method: "GET", url });

return data.map((currency: MarketItemResponse) => formatPerformer(currency));
return data;
}

export default {
Expand Down
4 changes: 3 additions & 1 deletion libs/ledger-live-common/src/market/v2/useMarketPerformers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { fetchMarketPerformers } from "../api/api";
import { MarketPerformersParams } from "../types";
import { MarketItemResponse, MarketPerformersParams } from "../types";
import { QUERY_KEY } from "./queryKeys";
import { useQuery } from "@tanstack/react-query";
import { formatPerformer } from "../utils/currencyFormatter";

export function useMarketPerformers({
counterCurrency,
Expand All @@ -16,6 +17,7 @@ export function useMarketPerformers({
queryKey: [QUERY_KEY.MarketPerformers, counterCurrency, range, sort],
queryFn: () => fetchMarketPerformers({ counterCurrency, range, limit, top, sort, supported }),
refetchInterval: 60 * 1000 * Number(refreshRate),
select: data => data.map((currency: MarketItemResponse) => formatPerformer(currency)),
});

return {
Expand Down

0 comments on commit 015a7d5

Please sign in to comment.