Skip to content

Commit f4eb7df

Browse files
committed
fix
1 parent eed3fbf commit f4eb7df

File tree

4 files changed

+39
-70
lines changed

4 files changed

+39
-70
lines changed

app/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const Home = () => {
1818
return (
1919
<main className='main-container'>
2020
<section className='home-grid'>
21-
<Suspense fallback={<ChartSectionFallback />}>
21+
<Suspense fallback={<CoinOverviewFallback />}>
2222
<CoinOverviewSection />
2323
</Suspense>
2424

@@ -38,7 +38,7 @@ const Home = () => {
3838

3939
export default Home;
4040

41-
const ChartSectionFallback = () => (
41+
const CoinOverviewFallback = () => (
4242
<div className='chart-section-container'>
4343
<div className='w-full h-full min-h-[420px] rounded-2xl bg-dark-500/60 p-6'>
4444
<div className='flex items-center gap-4 mb-6'>

components/CandlestickChart.tsx

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,20 @@ export default function CandlestickChart({
3434
const [loading, setLoading] = useState(false);
3535
const prevOhlcDataLength = useRef<number>(data?.length ?? 0);
3636

37-
console.log('=====liveOhlcv', liveOhlcv);
38-
3937
// Fetch OHLC data when period changes
4038
const fetchOHLCData = async (selectedPeriod: Period) => {
4139
setLoading(true);
4240
try {
4341
const config = PERIOD_CONFIG[selectedPeriod];
44-
console.log('==== Fetching OHLC:', {
45-
period: selectedPeriod,
46-
days: config.days,
47-
interval: config.interval,
48-
coinId,
49-
});
42+
5043
const newData = await getCoinOHLC(
5144
coinId,
5245
config.days,
5346
'usd',
5447
config.interval,
5548
'full'
5649
);
57-
console.log('==== OHLC Fetched:', {
58-
period: selectedPeriod,
59-
dataPoints: newData?.length,
60-
});
50+
6151
setOhlcData(newData ?? []);
6252
} catch (err) {
6353
console.error('Failed to fetch OHLC data:', err);
@@ -69,7 +59,6 @@ export default function CandlestickChart({
6959
const handlePeriodChange = (newPeriod: Period) => {
7060
if (newPeriod === period) return;
7161

72-
console.log('==== Period Change:', { from: period, to: newPeriod, mode });
7362
setPeriod(newPeriod);
7463
fetchOHLCData(newPeriod);
7564
};
@@ -104,18 +93,13 @@ export default function CandlestickChart({
10493
chartRef.current = null;
10594
candleSeriesRef.current = null;
10695
};
96+
// eslint-disable-next-line react-hooks/exhaustive-deps
10797
}, [height]);
10898

10999
// Update chart when data or liveOhlcv changes
110100
useEffect(() => {
111101
if (!candleSeriesRef.current) return;
112102

113-
console.log('==== Chart Update Effect Triggered:', {
114-
ohlcDataPoints: ohlcData.length,
115-
hasLiveOhlcv: !!liveOhlcv,
116-
liveOhlcv,
117-
});
118-
119103
// Convert timestamps from milliseconds to seconds
120104
const convertedToSeconds = ohlcData.map(
121105
(item) =>
@@ -129,7 +113,6 @@ export default function CandlestickChart({
129113
);
130114

131115
let merged: OHLCData[];
132-
let action = 'none';
133116

134117
if (liveOhlcv) {
135118
const liveTimestamp = liveOhlcv[0];
@@ -141,19 +124,10 @@ export default function CandlestickChart({
141124
if (lastHistoricalCandle && lastHistoricalCandle[0] === liveTimestamp) {
142125
// Update the last candle with live data
143126
merged = [...convertedToSeconds.slice(0, -1), liveOhlcv];
144-
action = 'updated';
145127
} else {
146128
// Append new live candle
147129
merged = [...convertedToSeconds, liveOhlcv];
148-
action = 'appended';
149130
}
150-
151-
console.log('==== Live OHLCV Merge:', {
152-
action,
153-
liveTimestamp,
154-
liveTime: new Date(liveTimestamp * 1000).toISOString(),
155-
lastHistoricalTimestamp: lastHistoricalCandle?.[0],
156-
});
157131
} else {
158132
merged = convertedToSeconds;
159133
}

hooks/useCoinGeckoWebSocket.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,7 @@ export function useCoinGeckoWebSocket({
6666
Number(msg.l ?? 0),
6767
Number(msg.c ?? 0),
6868
];
69-
70-
console.log('==== G3 OHLCV Update:', {
71-
timestamp,
72-
formattedTime: new Date(timestamp * 1000).toISOString(),
73-
open: msg.o,
74-
high: msg.h,
75-
low: msg.l,
76-
close: msg.c,
77-
candle: newCandle,
78-
});
79-
69+
8070
// Always update with the latest candle - chart will handle deduplication
8171
setOhlcv(newCandle);
8272
lastOhlcvTimestamp.current = timestamp;
@@ -155,7 +145,7 @@ export function useCoinGeckoWebSocket({
155145
subscribe('CGSimplePrice', { coin_id: [coinId], action: 'set_tokens' });
156146

157147
const wsPools = [poolId.replace('_', ':')];
158-
console.log("===wsPools", wsPools)
148+
159149

160150
if (wsPools.length) {
161151
subscribe('OnchainTrade', {

lib/coingecko.actions.ts

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,38 @@ const header = {
99
cache: 'no-store' as RequestCache,
1010
};
1111

12+
// Get detailed information about a specific coin by its ID
13+
export async function getCoinDetails(id: string) {
14+
const res = await fetch(`${baseUrl}/coins/${id}`, header);
15+
16+
if (!res.ok) throw new Error('Failed to fetch CoinGecko API data');
17+
return res.json();
18+
}
19+
20+
// Get OHLC (Open, High, Low, Close) data for a coin
21+
export async function getCoinOHLC(
22+
id: string,
23+
days: number | string,
24+
currency?: string,
25+
interval?: 'daily' | 'hourly',
26+
precision?: 'full' | string
27+
) {
28+
const currencyParam = currency || 'usd';
29+
const params = new URLSearchParams({
30+
vs_currency: currencyParam,
31+
days: days.toString(),
32+
});
33+
34+
if (interval) params.append('interval', interval);
35+
if (precision) params.append('precision', precision);
36+
37+
const res = await fetch(`${baseUrl}/coins/${id}/ohlc?${params}`, header);
38+
39+
if (!res.ok) throw new Error('Failed to fetch CoinGecko API data');
40+
return res.json();
41+
}
42+
43+
1244
export async function getCoinList(page: number = 1, perPage: number = 50) {
1345
const params = new URLSearchParams({
1446
vs_currency: 'usd',
@@ -38,34 +70,7 @@ export async function getCategories() {
3870
return data.slice(0, 10) || [];
3971
}
4072

41-
export async function getCoinDetails(id: string) {
42-
const res = await fetch(`${baseUrl}/coins/${id}`, header);
43-
44-
if (!res.ok) throw new Error('Failed to fetch CoinGecko API data');
45-
return res.json();
46-
}
47-
48-
export async function getCoinOHLC(
49-
id: string,
50-
days: number | string,
51-
currency?: string,
52-
interval?: 'daily' | 'hourly',
53-
precision?: 'full' | string
54-
) {
55-
const currencyParam = currency || 'usd';
56-
const params = new URLSearchParams({
57-
vs_currency: currencyParam,
58-
days: days.toString(),
59-
});
60-
61-
if (interval) params.append('interval', interval);
62-
if (precision) params.append('precision', precision);
63-
64-
const res = await fetch(`${baseUrl}/coins/${id}/ohlc?${params}`, header);
6573

66-
if (!res.ok) throw new Error('Failed to fetch CoinGecko API data');
67-
return res.json();
68-
}
6974

7075
export async function getTrendingCoins() {
7176
const res = await fetch(`${baseUrl}/search/trending`, header);

0 commit comments

Comments
 (0)