fix: Update miningStats and topMiners loading logic to handle single object responses and ensure correct state setting
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user