Showing AI reviews for website
Project AI Score ?
71%
Quality Avg ?
72%
Security Avg ?
74%
Reviews ?
123

Review Result ?

solutionbowl/website · 9bd43ede
This commit adds functionality for updating the user's wallet balance across multiple components and contexts, enhancing real-time balance tracking via sockets. It includes thoughtful fallbacks and localStorage updates to maintain user state consistency. Debug logging is used extensively to trace balance changes and socket events.
Quality ?
80%
Security ?
70%
Business Value ?
90%
Maintainability ?
75%
Issues & Suggested Fixes ?
1AI detects the issue
2Shows file, line, or evidence
3Suggests the fix to apply
Commented Out Debugging Code
Where src/components/racing/HorseRow.tsx:263-271
Issue / Evidence commented-out debugging code
Suggested Fix remove or replace with conditional debug logging to reduce clutter and improve maintainability
Console.log Statements
Where src/contexts/AuthContext.tsx:223-234
Issue / Evidence console.log statements
Suggested Fix replace with a proper logging framework or remove in production to avoid sensitive data exposure
Debug Console Logs And Warnings
Where src/hooks/useLoginSoket.ts:45,216-231
Issue / Evidence debug console logs and warnings
Suggested Fix consider controlling logging level or removing these in production builds for security and performance
Json.parse Usage On Localstorage Item Retr...
Where src/contexts/AuthContext.tsx:225-227
Issue / Evidence JSON.parse usage on localStorage item retrieval
Suggested Fix add try-catch to handle possible malformed data to reduce bug risk
Very Short And Generic
Where commit message
Issue / Evidence very short and generic
Suggested Fix enhance commit message to describe why wallet balance update was added and what problem it solves for better traceability
Code Change Preview · src/components/layout/Header.tsx ?
Removed / Before Commit
- diff --git a/src/components/layout/Header.tsx b/src/components/layout/Header.tsx
- index 51e7303..bcc6eb1 100644
- const colors = useThemeColors();
- const { user, isAuthenticated } = useAuth();
- 
-   const balance = Number(user?.walletBalance ?? 0);
- const balanceDisplay = balance.toLocaleString("en-IN");
- const auth = useAuthModal();
- 
- >
- <i className="fa-solid fa-wallet"></i>
- </div>
-                 </div>
- 
- <button
- onClick={onProfileClick}
Added / After Commit
+ diff --git a/src/components/layout/Header.tsx b/src/components/layout/Header.tsx
+ index 51e7303..bcc6eb1 100644
+ const colors = useThemeColors();
+ const { user, isAuthenticated } = useAuth();
+ 
+   const balance = Number(user?.walletBalance ?? user?.wallet?.balance ?? user?.balance ?? 0);
+ const balanceDisplay = balance.toLocaleString("en-IN");
+ const auth = useAuthModal();
+ 
+ >
+ <i className="fa-solid fa-wallet"></i>
+ </div>
+                 </div>        
+ 
+ <button
+ onClick={onProfileClick}
Removed / Before Commit
- diff --git a/src/components/racing/HorseRow.tsx b/src/components/racing/HorseRow.tsx
- index 99a8d5c..54d199d 100644
- 
- 
- 
-   if (runner.exposure !== undefined || runner.exposureProfit !== undefined) {
-     console.log(`🐴 Runner ${horseData.name}:`, {
-       exposure: runner.exposure,
-       exposureProfit: runner.exposureProfit,
-       hasExposure,
-       profitLoss,
-       marketName
-     })
-   }
- 
- 
- const isWithdrawn = runner.withdrawn === true
Added / After Commit
+ diff --git a/src/components/racing/HorseRow.tsx b/src/components/racing/HorseRow.tsx
+ index 99a8d5c..54d199d 100644
+ 
+ 
+ 
+   // if (runner.exposure !== undefined || runner.exposureProfit !== undefined) {
+   //   console.log(`🐴 Runner ${horseData.name}:`, {
+   //     exposure: runner.exposure,
+   //     exposureProfit: runner.exposureProfit,
+   //     hasExposure,
+   //     profitLoss,
+   //     marketName
+   //   })
+   // }
+ 
+ 
+ const isWithdrawn = runner.withdrawn === true
Removed / Before Commit
- diff --git a/src/contexts/AuthContext.tsx b/src/contexts/AuthContext.tsx
- index 0cc0159..7e1da08 100644
- };
- 
- const getBalanceFromSocketPayload = (data: any): number | null => {
- const rawBalance =
- data?.walletBalance ??
- data?.data?.walletBalance ??
- data?.user?.walletBalance ??
- data?.data?.user?.walletBalance ??
- data?.balance ??
-     data?.data?.balance;
- 
- const walletBalance = Number(rawBalance);
- 
- return Number.isFinite(walletBalance) ? walletBalance : null;
- };
- 
Added / After Commit
+ diff --git a/src/contexts/AuthContext.tsx b/src/contexts/AuthContext.tsx
+ index 0cc0159..7e1da08 100644
+ };
+ 
+ const getBalanceFromSocketPayload = (data: any): number | null => {
+   // Direct format: { userId: "...", walletBalance: 9500 }
+ const rawBalance =
+ data?.walletBalance ??
+ data?.data?.walletBalance ??
+ data?.user?.walletBalance ??
+ data?.data?.user?.walletBalance ??
+ data?.balance ??
+     data?.data?.balance ??
+     data?.wallet?.balance ??
+     data?.data?.wallet?.balance;
+ 
+ const walletBalance = Number(rawBalance);
+ return Number.isFinite(walletBalance) ? walletBalance : null;
Removed / Before Commit
- diff --git a/src/hooks/useLoginSoket.ts b/src/hooks/useLoginSoket.ts
- index 4a4e8ec..83c9c99 100644
- onForceLogout?: (data?: unknown) => void;
- 
- onBalanceUpdate?: (data: {
- walletBalance: number;
- }) => void;
- 
- return Number.isFinite(walletBalance) ? walletBalance : null;
- };
- 
- export const useLoginSocket = ({
- userId,
- token,
- "Login socket already connected"
- );
- 
- return;
Added / After Commit
+ diff --git a/src/hooks/useLoginSoket.ts b/src/hooks/useLoginSoket.ts
+ index 4a4e8ec..83c9c99 100644
+ onForceLogout?: (data?: unknown) => void;
+ 
+ onBalanceUpdate?: (data: {
+     userId?: string;
+ walletBalance: number;
+ }) => void;
+ 
+ return Number.isFinite(walletBalance) ? walletBalance : null;
+ };
+ 
+ const joinBalanceRoom = (socket: Socket, userId: string) => {
+   socket.emit("join", { userId });
+   console.log("Joined balance socket room:", { userId });
+ };
+ 
+ export const useLoginSocket = ({
Removed / Before Commit
- diff --git a/src/pages/HorseRacingDetails.tsx b/src/pages/HorseRacingDetails.tsx
- index 02c4db0..1a7a731 100644
- const STANDALONE_FANCY_TYPES = new Set(["OBJECTION", "ODDS & EVENS", "PHOTO"])
- const MARKET_TYPE_DISPLAY_ORDER = [
- "WIN",
-   "2PLACE",
-   "3PLACE",
-   "4PLACE",
- "FANCY",
- "OBJECTION",
- "ODDS & EVENS",
Added / After Commit
+ diff --git a/src/pages/HorseRacingDetails.tsx b/src/pages/HorseRacingDetails.tsx
+ index 02c4db0..1a7a731 100644
+ const STANDALONE_FANCY_TYPES = new Set(["OBJECTION", "ODDS & EVENS", "PHOTO"])
+ const MARKET_TYPE_DISPLAY_ORDER = [
+ "WIN",
+   "2PLACES",
+   "3PLACES",
+   "4PLACES",
+ "FANCY",
+ "OBJECTION",
+ "ODDS & EVENS",