Repository: sunflower-farmers/sunflower-farmers
File: src/features/world/ui/megastore/chapter_store_components/ItemsList.tsx (TypeScript)

Code before:
  const chapterTicket = getChapterTicket(now);
  const chapterArtefact = getChapterArtefact(now);

  //For Discount
  const [
    {
      context: { state },
    },
  ] = useActor(gameService);

  const getBalanceOfItem = (item: ChapterStoreItem): number => {
    // Handling all types or specific ones if provided
    if (type === "wearables" || (!type && "wearable" in item)) {
      return (
        state.farmActivity[
          `${(item as ChapterStoreWearable).wearable as ChapterTierItemName} Bought`
        ] ?? 0
      );
    } else if (type === "collectibles" || (!type && "collectible" in item)) {
      return (
        state.farmActivity[
          `${(item as ChapterStoreCollectible).collectible as ChapterTierItemName} Bought`
        ] ?? 0
      );
    } else if (type === "keys" || (!type && "key" in item)) {
      return (
        state.farmActivity[
          `${(item as ChapterStoreCollectible).collectible as ChapterTierItemName} Bought`
        ] ?? 0
      );
    }

    return 0;
  };

  const getItemName = (item: ChapterStoreItem): string => {
    if (type === "wearables" || (!type && "wearable" in item)) {
      return (item as ChapterStoreWearable).wearable as BumpkinItem;
    } else if (type === "collectibles" || (!type && "collectible" in item)) {
      return (item as ChapterStoreCollectible).collectible as InventoryItemName;
    } else if (type === "keys" || (!type && "key" in item)) {
      return (item as ChapterStoreCollectible).collectible as InventoryItemName;
    }

    return "";
  };

  const filteredItems = type
    ? items.filter((item) => {
        // Filter by type if provided
        if (type === "wearables" && "wearable" in item) return true;

Review comment (suggestion):
```suggestion
      const result = state.farmActivity[`${collectibleName} Bought`] ?? 0;
```

Code after:
  const now = useNow();
  const chapterTicket = getChapterTicket(now);
  const chapterArtefact = getChapterArtefact(now);

  //For Discount
  const [
    {
      context: { state },
    },
  ] = useActor(gameService);

  const getBalanceOfItem = (item: ChapterStoreItem): number => {
    // Handling all types or specific ones if provided
    if (type === "wearables" || (!type && "wearable" in item)) {
      return (
        state.farmActivity[
          `${(item as ChapterStoreWearable).wearable as ChapterTierItemName} Bought`
        ] ?? 0
      );
    } else if (type === "collectibles" || (!type && "collectible" in item)) {
      const collectibleName = (item as ChapterStoreCollectible).collectible;
      const activityName = `${collectibleName} Bought` as const;
      const result =
        (state.farmActivity[activityName as keyof typeof state.farmActivity] as
          | number
          | undefined) ?? 0;
      return result;
    } else if (type === "keys" || (!type && "key" in item)) {
      return (
        state.farmActivity[
          `${(item as ChapterStoreCollectible).collectible as ChapterTierItemName} Bought`
        ] ?? 0
      );
    }

    return 0;
  };

  const getItemName = (item: ChapterStoreItem): string => {
    if (type === "wearables" || (!type && "wearable" in item)) {
      return (item as ChapterStoreWearable).wearable as BumpkinItem;
    } else if (type === "collectibles" || (!type && "collectible" in item)) {
      return (item as ChapterStoreCollectible).collectible as InventoryItemName;
    } else if (type === "keys" || (!type && "key" in item)) {
      return (item as ChapterStoreCollectible).collectible as InventoryItemName;
    }

    return "";
  };

  const filteredItems = type