Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
(Market): add svg sparkline variation + fix issue in countervalue ini…
Browse files Browse the repository at this point in the history
…tial setting
  • Loading branch information
LFBarreto committed Feb 14, 2022
1 parent ec7d4bf commit 6acf80e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
8 changes: 5 additions & 3 deletions src/market/MarketDataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ export const MarketDataProvider = ({
}, []);

useEffect(() => {
if (countervalue)
if (countervalue) {
const ticker = countervalue.ticker.toLowerCase();
api.supportedCounterCurrencies().then(
(supportedCounterCurrencies) =>
api.setSupportedCoinsList().then((coins) => {
Expand All @@ -233,13 +234,14 @@ export const MarketDataProvider = ({
});
dispatch({
type: ACTIONS.UPDATE_COUNTERVALUE,
payload: supportedCounterCurrencies.includes(countervalue.ticker)
? countervalue.ticker
payload: supportedCounterCurrencies.includes(ticker)
? ticker
: "usd",
});
}, handleError),
handleError
);
}
}, [api, countervalue, handleError]);

useEffect(() => {
Expand Down
18 changes: 9 additions & 9 deletions src/market/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ async function setSupportedCoinsList(): Promise<SupportedCoins> {

const matchSearch =
(search: string) =>
(currency: MarketCoin): boolean => {
if (!search) return false;
const match = `${currency.symbol}|${currency.name}`;
return match.toLowerCase().includes(search.toLowerCase());
};
(currency: MarketCoin): boolean => {
if (!search) return false;
const match = `${currency.symbol}|${currency.name}`;
return match.toLowerCase().includes(search.toLowerCase());
};

function distributedCopy(items: number[], n: number): number[] {
const elements = [items[0]];
Expand Down Expand Up @@ -83,6 +83,7 @@ function sparklineAsSvgData(points: number[]): SparklineSvgData {
})
.join(" "),
viewBox: `0 0 ${totalXSteps} ${sparklineYHeight + 3}`,
isPositive: points[0] <= points[points.length - 1],
};
}

Expand Down Expand Up @@ -121,8 +122,7 @@ async function listPaginated({

const url =
`${ROOT_PATH}/coins/markets?vs_currency=${counterCurrency}&order=${orderBy}_${order}&per_page=${limit}` +
`&sparkline=${
sparkline ? "true" : "false"
`&sparkline=${sparkline ? "true" : "false"
}&price_change_percentage=${range}` +
`${ids.length > 0 ? `&page=1&&ids=${ids.toString()}` : `&page=${page}`}`;

Expand Down Expand Up @@ -180,8 +180,8 @@ async function listPaginated({
atlDate: currency.atl_date,
sparklineIn7d: currency?.sparkline_in_7d?.price
? sparklineAsSvgData(
distributedCopy(currency.sparkline_in_7d.price, 6 * 7)
) // keep 6 points per day
distributedCopy(currency.sparkline_in_7d.price, 6 * 7)
) // keep 6 points per day
: null,
chartData: [],
})
Expand Down
1 change: 1 addition & 0 deletions src/market/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type MarketCurrencyChartDataRequestParams = {
export type SparklineSvgData = {
path: string;
viewBox: string;
isPositive: boolean;
};

export type CurrencyData = {
Expand Down

0 comments on commit 6acf80e

Please sign in to comment.