From 1369b429395da1337d8ae1b443784f770c241f8b Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Bajpai Date: Sun, 2 Aug 2026 17:30:44 +0530 Subject: [PATCH] fix: code quality and safety improvements --- frontend/js/user/badges.js | 2 +- scripts/fetch-user-info.js | 29 +---------------------------- 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/frontend/js/user/badges.js b/frontend/js/user/badges.js index 648d3b6a..c541a701 100644 --- a/frontend/js/user/badges.js +++ b/frontend/js/user/badges.js @@ -95,7 +95,7 @@ export async function loadBadges(data) { ranks.overall.rank !== "--" ) { const overallRank = parseInt(ranks.overall.rank, 10); - if (!isNaN(overallRank) && overallRank <= 10) { + if (!Number.isNaN(overallRank) && overallRank <= 10) { earnedSet.add("TOP_BRASS"); } } diff --git a/scripts/fetch-user-info.js b/scripts/fetch-user-info.js index a913a118..b46b95ea 100644 --- a/scripts/fetch-user-info.js +++ b/scripts/fetch-user-info.js @@ -73,31 +73,4 @@ async function fetchUserInfo(username) { // 2. Fetch live profile ranking from the wrapper API const livePromise = fetchWithTimeout(liveApiUrl).then(async (res) => { - if (res.ok) { - const apiData = await res.json(); - ranking = apiData.ranking || 0; - contest = apiData.contest || null; - } else { - throw new Error(`LeetCode API wrapper returned status ${res.status}`); - } - }); - - // Wait for the live API task to complete - await livePromise; - - // Ensure history is sorted chronologically - // Guard against a corrupted history file (e.g. non-array `history` field) - history = Array.isArray(history) ? history : []; - history.sort((a, b) => new Date(a.date) - new Date(b.date)); - - return { - username, - streak, - ranking, - leaderboardRanks, - contest, - history, - }; -} - -module.exports = fetchUserInfo; + .catch(err => console.error(err)) \ No newline at end of file