Skip to content

Commit 1e5ecf4

Browse files
committed
fix: removed debug logs
1 parent 05df158 commit 1e5ecf4

3 files changed

Lines changed: 5 additions & 304 deletions

File tree

apps/game-client/src/api/characters.api.ts

Lines changed: 0 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const MARGONEM_CHARACTER_LIST_URL =
66
"https://public-api.margonem.pl/account/charlist";
77
const MARGONEM_CHARACTER_LIST_EN_URL =
88
"https://public-api.margonem.com/account/charlist";
9-
const CHARACTER_LIST_LOG_PREFIX = "[CharacterList]";
109

1110
export type MargonemCharacter = {
1211
clan?: number;
@@ -211,52 +210,6 @@ export const normalizeCharacterList = (
211210
);
212211
};
213212

214-
const logCharacterListDebug = (
215-
message: string,
216-
details?: Record<string, unknown>,
217-
) => {
218-
if (details) {
219-
console.log(`${CHARACTER_LIST_LOG_PREFIX} ${message}`, details);
220-
return;
221-
}
222-
223-
console.log(`${CHARACTER_LIST_LOG_PREFIX} ${message}`);
224-
};
225-
226-
const summarizeCharacterEntry = (character: unknown) => {
227-
if (typeof character !== "object" || character === null) {
228-
return {
229-
entryType: typeof character,
230-
isNull: character === null,
231-
};
232-
}
233-
234-
const characterData = character as Record<string, unknown>;
235-
236-
return {
237-
keys: Object.keys(characterData),
238-
idType: typeof characterData.id,
239-
iconType: typeof characterData.icon,
240-
lvlType: typeof characterData.lvl,
241-
nickType: typeof characterData.nick,
242-
profType: typeof characterData.prof,
243-
worldType: typeof characterData.world,
244-
idPreview: characterData.id,
245-
lvlPreview: characterData.lvl,
246-
nickPreview: characterData.nick,
247-
profPreview: characterData.prof,
248-
worldPreview: characterData.world,
249-
};
250-
};
251-
252-
const getCharacterWorldCounts = (characters: MargonemCharacter[]) => {
253-
return characters.reduce<Record<string, number>>((worldCounts, character) => {
254-
// @ts-expect-error `normalizeCharacterList` guarantees `world` is a string here.
255-
worldCounts[character.world] = (worldCounts[character.world] ?? 0) + 1;
256-
return worldCounts;
257-
}, {});
258-
};
259-
260213
const filterCharactersByWorld = (
261214
characters: MargonemCharacter[],
262215
world: string | undefined,
@@ -283,28 +236,12 @@ export async function fetchCharacterList({
283236
const margonemEntry = window.localStorage?.getItem("Margonem");
284237
const accountIdKey = String(accountId);
285238

286-
logCharacterListDebug("Fetching character list", {
287-
accountId,
288-
world,
289-
languageVersion,
290-
hasMargonemEntry: Boolean(margonemEntry),
291-
});
292-
293239
let parsed: unknown = null;
294240

295241
if (margonemEntry) {
296242
try {
297243
parsed = JSON.parse(margonemEntry);
298244
} catch (error) {
299-
console.warn(
300-
`${CHARACTER_LIST_LOG_PREFIX} Failed to parse Margonem cache`,
301-
{
302-
accountId,
303-
world,
304-
margonemEntryLength: margonemEntry.length,
305-
error,
306-
},
307-
);
308245
throw error;
309246
}
310247
}
@@ -321,78 +258,17 @@ export async function fetchCharacterList({
321258
const cached = accountId ? normalizeCharacterList(rawCachedCharacters) : [];
322259
const filteredCached = filterCharactersByWorld(cached, world);
323260

324-
logCharacterListDebug("Resolved cached character list", {
325-
accountId,
326-
world,
327-
hasCharlist: Boolean(charlist),
328-
rawCachedType:
329-
rawCachedCharacters === null ? "missing" : typeof rawCachedCharacters,
330-
rawCachedCount: Array.isArray(rawCachedCharacters)
331-
? rawCachedCharacters.length
332-
: null,
333-
normalizedCachedCount: cached.length,
334-
filteredCachedCount: filteredCached.length,
335-
cachedWorldCounts: getCharacterWorldCounts(cached),
336-
});
337-
338-
if (
339-
Array.isArray(rawCachedCharacters) &&
340-
rawCachedCharacters.length > 0 &&
341-
cached.length === 0
342-
) {
343-
console.warn(
344-
`${CHARACTER_LIST_LOG_PREFIX} Cached character entries were rejected by normalization`,
345-
{
346-
accountId,
347-
world,
348-
firstCachedEntrySummary: summarizeCharacterEntry(
349-
rawCachedCharacters[0],
350-
),
351-
},
352-
);
353-
}
354-
355261
if (filteredCached.length > 0) {
356-
logCharacterListDebug("Returning cached character list", {
357-
accountId,
358-
world,
359-
filteredCachedCount: filteredCached.length,
360-
});
361-
362262
return filteredCached;
363263
}
364264

365-
if (cached.length > 0) {
366-
logCharacterListDebug(
367-
"Cached character list does not contain entries for current world, falling back to public API",
368-
{
369-
accountId,
370-
world,
371-
normalizedCachedCount: cached.length,
372-
filteredCachedCount: filteredCached.length,
373-
},
374-
);
375-
}
376-
377265
const hs3 = window.getCookie?.("hs3");
378266
const url =
379267
languageVersion === LanguageVersion.PL
380268
? MARGONEM_CHARACTER_LIST_URL
381269
: MARGONEM_CHARACTER_LIST_EN_URL;
382270

383-
logCharacterListDebug("Cache miss, falling back to public API", {
384-
accountId,
385-
world,
386-
url,
387-
hasHs3: Boolean(hs3),
388-
});
389-
390271
if (!hs3) {
391-
console.warn(`${CHARACTER_LIST_LOG_PREFIX} Missing authentication cookie`, {
392-
accountId,
393-
world,
394-
url,
395-
});
396272
throw new Error("Missing required authentication cookie");
397273
}
398274

@@ -406,39 +282,7 @@ export async function fetchCharacterList({
406282
world,
407283
);
408284

409-
logCharacterListDebug("Received public API character list", {
410-
accountId,
411-
world,
412-
rawApiCount: Array.isArray(response.data) ? response.data.length : null,
413-
normalizedApiCount: normalizedCharacters.length,
414-
filteredApiCount: filteredCharacters.length,
415-
apiWorldCounts: getCharacterWorldCounts(normalizedCharacters),
416-
});
417-
418-
if (
419-
Array.isArray(response.data) &&
420-
response.data.length > 0 &&
421-
normalizedCharacters.length === 0
422-
) {
423-
console.warn(
424-
`${CHARACTER_LIST_LOG_PREFIX} API character entries were rejected by normalization`,
425-
{
426-
accountId,
427-
world,
428-
firstApiEntrySummary: summarizeCharacterEntry(response.data[0]),
429-
},
430-
);
431-
}
432-
433285
if (!response.data || response.data.length === 0) {
434-
console.warn(
435-
`${CHARACTER_LIST_LOG_PREFIX} Empty character list received from API`,
436-
{
437-
accountId,
438-
world,
439-
url,
440-
},
441-
);
442286
throw new Error("Empty character list received from API");
443287
}
444288

apps/game-client/src/features/settings/components/catching/catching-settings.tsx

Lines changed: 5 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,10 @@ import { toast } from "sonner";
2323
import { useEffect, useRef, useState } from "react";
2424
import { useTranslation } from "react-i18next";
2525

26-
const CATCHING_SETTINGS_LOG_PREFIX = "[CatchingSettings]";
27-
2826
export const CatchingSettings = () => {
2927
const queryClient = useQueryClient();
3028
const accountId = String(Game.hero.account);
31-
const {
32-
data: characterList,
33-
error: characterListError,
34-
isError: isCharacterListError,
35-
isFetching: isCharacterListFetching,
36-
isPending: isCharacterListPending,
37-
} = useCharacterList();
29+
const { data: characterList } = useCharacterList();
3830
const { data: lootlogCharactersConfig } = useLootlogCharactersConfig();
3931
const initialCharacterId = String(Game.hero.id);
4032
const [selectedCharacterId, setSelectedCharacterId] =
@@ -46,87 +38,15 @@ export const CatchingSettings = () => {
4638
const { t } = useTranslation();
4739

4840
useEffect(() => {
49-
console.log(`${CATCHING_SETTINGS_LOG_PREFIX} Input state updated`, {
50-
accountId,
51-
initialCharacterId,
52-
selectedCharacterId,
53-
characterListState:
54-
characterList === undefined
55-
? "unavailable"
56-
: characterList.length === 0
57-
? "empty"
58-
: "populated",
59-
characterListCount: characterList?.length ?? null,
60-
characterListSummary:
61-
characterList?.map((character) => ({
62-
id: String(character.id),
63-
world: character.world,
64-
})) ?? [],
65-
isCharacterListPending,
66-
isCharacterListFetching,
67-
isCharacterListError,
68-
characterListError:
69-
characterListError instanceof Error ? characterListError.message : null,
70-
lootlogConfigCharacterIds: lootlogCharactersConfig
71-
? Object.keys(lootlogCharactersConfig)
72-
: [],
73-
});
74-
}, [
75-
accountId,
76-
characterList,
77-
characterListError,
78-
initialCharacterId,
79-
isCharacterListError,
80-
isCharacterListFetching,
81-
isCharacterListPending,
82-
lootlogCharactersConfig,
83-
selectedCharacterId,
84-
]);
85-
86-
useEffect(() => {
87-
if (!characterList) {
88-
console.log(
89-
`${CATCHING_SETTINGS_LOG_PREFIX} Skipping selected character sync because character list is unavailable`,
90-
{
91-
accountId,
92-
selectedCharacterId,
93-
},
94-
);
95-
return;
96-
}
97-
98-
if (characterList.length === 0) {
99-
console.log(
100-
`${CATCHING_SETTINGS_LOG_PREFIX} Skipping selected character sync because character list is empty`,
101-
{
102-
accountId,
103-
selectedCharacterId,
104-
},
105-
);
106-
return;
107-
}
41+
if (!characterList || characterList.length === 0) return;
10842

10943
const characterExists = characterList.some(
11044
(character) => String(character.id) === selectedCharacterId,
11145
);
11246
if (characterExists) return;
11347

114-
const fallbackCharacterId = String(characterList[0].id);
115-
116-
console.log(
117-
`${CATCHING_SETTINGS_LOG_PREFIX} Selected character missing from available characters, applying fallback`,
118-
{
119-
accountId,
120-
selectedCharacterId,
121-
fallbackCharacterId,
122-
availableCharacterIds: characterList.map((character) =>
123-
String(character.id),
124-
),
125-
},
126-
);
127-
128-
setSelectedCharacterId(fallbackCharacterId);
129-
}, [accountId, characterList, selectedCharacterId]);
48+
setSelectedCharacterId(String(characterList[0].id));
49+
}, [characterList, selectedCharacterId]);
13050

13151
const applyToAllMutation = useMutation({
13252
mutationKey: ["apply-catching-config-to-all-characters", accountId],
@@ -276,28 +196,7 @@ export const CatchingSettings = () => {
276196
});
277197

278198
const handleApplyToAllCharacters = () => {
279-
if (!characterList) {
280-
console.log(
281-
`${CATCHING_SETTINGS_LOG_PREFIX} Skipping apply-to-all because character list is unavailable`,
282-
{
283-
accountId,
284-
selectedCharacterId,
285-
},
286-
);
287-
return;
288-
}
289-
290-
if (characterList.length <= 1) {
291-
console.log(
292-
`${CATCHING_SETTINGS_LOG_PREFIX} Skipping apply-to-all because there are not enough characters`,
293-
{
294-
accountId,
295-
selectedCharacterId,
296-
characterCount: characterList.length,
297-
},
298-
);
299-
return;
300-
}
199+
if (!characterList || characterList.length <= 1) return;
301200

302201
const targetCharacterIds = characterList.map((character) =>
303202
String(character.id),
@@ -308,17 +207,6 @@ export const CatchingSettings = () => {
308207
lootlogCharactersConfig?.[selectedCharacterId]?.catchingGuildIds ??
309208
[];
310209

311-
console.log(
312-
`${CATCHING_SETTINGS_LOG_PREFIX} Applying config to all characters`,
313-
{
314-
accountId,
315-
selectedCharacterId,
316-
activeSelectionCount: activeCharacterSelection.length,
317-
targetCharacterCount: targetCharacterIds.length,
318-
targetCharacterIds,
319-
},
320-
);
321-
322210
applyToAllMutation.mutate({
323211
catchingGuildIds: activeCharacterSelection,
324212
targetCharacterIds,

0 commit comments

Comments
 (0)