fix: Update miningStats and topMiners loading logic to handle single object responses and ensure correct state setting

This commit is contained in:
MayaTheShy
2026-02-20 01:31:49 -05:00
parent bd68a79cd5
commit 558fb92c41

View File

@@ -30,6 +30,7 @@ const StatsPanel = ({ selectedTurtle, apiUrl }) => {
const response = await fetch(url);
if (response.ok) {
const data = await response.json();
// Response is either a single object (per turtle) or an array (all turtles)
setMiningStats(Array.isArray(data) ? data : [data]);
}
} catch (error) {
@@ -44,7 +45,8 @@ const StatsPanel = ({ selectedTurtle, apiUrl }) => {
const response = await fetch(`${apiUrl}/api/stats/top-miners?limit=10`);
if (response.ok) {
const data = await response.json();
setTopMiners(data);
// Response is now a flat array of {turtleId, totalBlocks, uniqueTypes}
setTopMiners(Array.isArray(data) ? data : (data.topMiners || []));
}
} catch (error) {
console.error('Failed to load top miners:', error);