Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix mine balance max cap #2548

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion client/src/ui/components/resources/EntityResourceTable.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { configManager } from "@/dojo/setup";
import { useDojo } from "@/hooks/context/DojoContext";
import { useStructures } from "@/hooks/helpers/useStructures";
import useNextBlockTimestamp from "@/hooks/useNextBlockTimestamp";
import { getEntityIdFromKeys, gramToKg, multiplyByPrecision } from "@/ui/utils/utils";
import { BuildingType, CapacityConfigCategory, ID, RESOURCE_TIERS } from "@bibliothecadao/eternum";
import { BuildingType, CapacityConfigCategory, ID, RESOURCE_TIERS, StructureType } from "@bibliothecadao/eternum";
import { useComponentValue } from "@dojoengine/react";
import { useMemo } from "react";
import { ResourceChip } from "./ResourceChip";
Expand All @@ -18,7 +19,11 @@ export const EntityResourceTable = ({ entityId }: { entityId: ID | undefined })
getEntityIdFromKeys([BigInt(entityId || 0), BigInt(BuildingType.Storehouse)]),
)?.value || 0;

const { getStructureByEntityId } = useStructures();
const structure = getStructureByEntityId(entityId || 0);

const maxStorehouseCapacityKg = useMemo(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a comment explaining why Fragment Mines have infinite storage capacity for future maintainers. This special case might not be immediately obvious to someone new to the codebase.

Suggested change
const maxStorehouseCapacityKg = useMemo(() => {
const maxStorehouseCapacityKg = useMemo(() => {
// Fragment Mines have unlimited storage capacity since they are the primary resource generation structures

if (structure?.category === StructureType[StructureType.FragmentMine]) return Infinity;
const storehouseCapacityKg = gramToKg(configManager.getCapacityConfig(CapacityConfigCategory.Storehouse));
return multiplyByPrecision(quantity * storehouseCapacityKg + storehouseCapacityKg);
}, [quantity, entityId]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The useMemo dependency array should include structure since it's used in the calculation. Without it, changes to structure won't trigger a recalculation.

Suggested change
}, [quantity, entityId]);
}, [quantity, entityId, structure]);

Expand Down
Loading