Skip to content
This repository was archived by the owner on Mar 9, 2026. It is now read-only.

Commit e135402

Browse files
author
von-steinkirch
committed
clean up slider price
1 parent 42e4e20 commit e135402

1 file changed

Lines changed: 8 additions & 20 deletions

File tree

src/components/SliderPrice.tsx

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,24 @@ interface CryptoPrice {
1111
change: number;
1212
}
1313

14-
interface CoinGeckoPriceData {
14+
interface PriceData {
1515
usd: number;
1616
usd_24h_change: number;
1717
}
1818

1919
const formatPrice = (price: number): string => {
20-
// For prices less than 1, show up to 6 decimal places
2120
if (price < 1) {
2221
return `$${price.toLocaleString(undefined, {
2322
minimumFractionDigits: 2,
2423
maximumFractionDigits: 6,
2524
})}`;
2625
}
27-
// For prices between 1 and 100, show 2 decimal places
2826
if (price < 100) {
2927
return `$${price.toLocaleString(undefined, {
3028
minimumFractionDigits: 2,
3129
maximumFractionDigits: 2,
3230
})}`;
3331
}
34-
// For prices 100 and above, show 0 decimal places
3532
return `$${price.toLocaleString(undefined, {
3633
minimumFractionDigits: 0,
3734
maximumFractionDigits: 0,
@@ -92,29 +89,20 @@ export const SliderPrice: React.FC = () => {
9289
const fetchPrices = async () => {
9390
try {
9491
setIsLoading(true);
95-
const queryParams = new URLSearchParams({
96-
ids: PRICE_SLIDER_CONFIG.API.PARAMS.ids,
97-
vs_currencies: PRICE_SLIDER_CONFIG.API.PARAMS.vs_currencies,
98-
include_24hr_change:
99-
PRICE_SLIDER_CONFIG.API.PARAMS.include_24hr_change.toString(),
100-
});
101-
102-
const response = await fetch(
103-
`${PRICE_SLIDER_CONFIG.API.URL}?${queryParams}`,
104-
{
105-
headers: {
106-
Accept: "application/json",
107-
},
92+
const response = await fetch(PRICE_SLIDER_CONFIG.API.URL, {
93+
headers: {
94+
Accept: "application/json",
10895
},
109-
);
96+
});
11097

11198
if (!response.ok) {
112-
throw new Error(`HTTP error! status: ${response.status}`);
99+
console.error(sliderPriceI18n.en.errors.fetchFailed, `HTTP ${response.status}`);
100+
return;
113101
}
114102

115103
const data = await response.json();
116104
const formattedPrices = Object.entries(
117-
data as Record<string, CoinGeckoPriceData>,
105+
data as Record<string, PriceData>,
118106
).map(([id, price]) => ({
119107
symbol: id.toUpperCase(),
120108
price: price.usd,

0 commit comments

Comments
 (0)