Skip to content
This repository was archived by the owner on Jul 6, 2026. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions src/components/TournamentCenter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react';
import React, { useState, useEffect, useMemo } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import {
Trophy,
Expand Down Expand Up @@ -29,7 +29,10 @@ const TournamentCenter: React.FC = () => {
const [showJoinModal, setShowJoinModal] = useState(false);
const [selectedHorse, setSelectedHorse] = useState<string | null>(null);

const playerHorses = horses.filter(h => h.owner === player?.walletAddress);
const playerHorses = useMemo(() =>
horses.filter(h => h.owner === player?.walletAddress),
[horses, player?.walletAddress]
);

// Generate mock tournaments for demonstration
useEffect(() => {
Expand Down Expand Up @@ -214,14 +217,22 @@ const TournamentCenter: React.FC = () => {
}
};

const filteredTournaments = tournaments.filter(t => {
switch (currentTab) {
case 'active': return t.status === 'Active';
case 'upcoming': return t.status === 'Registration';
case 'history': return t.status === 'Completed';
default: return true;
}
});
const filteredTournaments = useMemo(() =>
tournaments.filter(t => {
switch (currentTab) {
case 'active': return t.status === 'Active';
case 'upcoming': return t.status === 'Registration';
case 'history': return t.status === 'Completed';
default: return true;
}
}),
[tournaments, currentTab]
);

const tournamentWins = useMemo(() =>
player?.stats.achievements.filter(a => a.name.includes('Tournament')).length || 0,
[player?.stats.achievements]
Comment on lines +232 to +234

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Use safer optional chaining and align the dependency array to avoid potential runtime errors.

player?.stats.achievements can still throw if stats is undefined/null: player?.stats may be undefined, and then accessing .achievements will fail. This affects both the memo body and the dependency array. Consider:

const tournamentWins = useMemo(
  () => player?.stats?.achievements?.filter(a => a.name.includes('Tournament')).length ?? 0,
  [player?.stats?.achievements]
);

This handles partially populated player objects and keeps the dependency array consistent with the computed value.

);

return (
<div className="max-w-7xl mx-auto p-6 space-y-6">
Expand All @@ -242,7 +253,7 @@ const TournamentCenter: React.FC = () => {
<div className="text-center">
<p className="text-sm text-gray-600">Tournament Wins</p>
<p className="text-2xl font-bold text-purple-600">
{player?.stats.achievements.filter(a => a.name.includes('Tournament')).length || 0}
{tournamentWins}
</p>
</div>
<div className="text-center">
Expand Down
Loading