From 6bfee1186516f38ddca08264982aba8ffa6c4115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CSushmoy?= Date: Fri, 6 Feb 2026 23:39:22 +0600 Subject: [PATCH] Handle normalized usernames for API fetches --- popup/src/lib/leetpush.api.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/popup/src/lib/leetpush.api.ts b/popup/src/lib/leetpush.api.ts index 4272a5b..e2c498e 100644 --- a/popup/src/lib/leetpush.api.ts +++ b/popup/src/lib/leetpush.api.ts @@ -25,7 +25,10 @@ export const fetchDailyProblem = async (): Promise => { * @returns The user stats **/ export const fetchUserStats = async (username: string): Promise => { - const response = await fetch(`${BASE_URL}/${username}`); + const normalizedUsername = username.trim(); + const response = await fetch( + `${BASE_URL}/${encodeURIComponent(normalizedUsername)}`, + ); if (response.status === 404) throw new Error("User not found"); else if (!response.ok) throw new Error("Failed to fetch user stats"); @@ -40,8 +43,12 @@ export const fetchUserStats = async (username: string): Promise => { export const fetchUserStreak = async ( username: string, ): Promise => { - const response = await fetch(`${BASE_URL}/userProfileCalendar/${username}`); + const normalizedUsername = username.trim(); + const response = await fetch( + `${BASE_URL}/userProfileCalendar/${encodeURIComponent(normalizedUsername)}`, + ); + if (response.status === 404) throw new Error("User not found"); if (!response.ok) throw new Error("Failed to fetch user streak"); return await response.json(); -}; +}; \ No newline at end of file