Closed aymericdelab closed 1 week ago
The latest updates on your projects. Learn more about Vercel for Git βοΈ
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
eternum | β Ready (Inspect) | Visit Preview | π¬ Add feedback | Jun 24, 2024 11:44am |
β±οΈ Estimated effort to review [1-5] | 3 |
π§ͺ Relevant tests | No |
π Security concerns | No |
β‘ Key issues to review |
Possible Bug: The getEntityOwner function in useRealm.tsx assumes that entityOwner?.entity_owner_id will always be non-null when called. This could potentially lead to runtime errors if entityOwner is null. Consider adding null checks or default values. |
Performance Concern: The canExplore function in utils.tsx performs multiple searches on the food array to find specific resources. This could be optimized by using a map or reducing the array to an object keyed by resourceId for faster lookups. |
Category | Suggestion | Score |
Possible bug |
Add a null check for
___
**Add a null check for | 9 |
Maintainability |
Refactor resource checks to use a loop for better scalability and maintainability___ **Refactor thecanExplore function to use a loop for checking resource requirements, which will make the function more maintainable and scalable if more resources are added in the future.** [client/src/ui/components/worldmap/hexagon/utils.tsx [50-57]](https://github.com/BibliothecaDAO/eternum/pull/1000/files#diff-770c44daa009ae4d3637fe48f885dfddf3ed664920aca4d4367177be3a83bcb0R50-R57) ```diff -const fish = food.find((resource) => resource.resourceId === ResourcesIds.Fish); -if ((fish?.amount || 0) < EternumGlobalConfig.exploration.fishBurn) { - return false; -} -const wheat = food.find((resource) => resource.resourceId === ResourcesIds.Wheat); -if ((wheat?.amount || 0) < EternumGlobalConfig.exploration.wheatBurn) { - return false; +const requiredResources = [ResourcesIds.Fish, ResourcesIds.Wheat]; +for (const resourceId of requiredResources) { + const resource = food.find((r) => r.resourceId === resourceId); + const requiredAmount = EternumGlobalConfig.exploration[resourceId.toLowerCase() + 'Burn']; + if ((resource?.amount || 0) < requiredAmount) { + return false; + } } ``` Suggestion importance[1-10]: 8Why: This refactor improves maintainability and scalability, which is beneficial for future code changes. | 8 |
Enhancement |
Simplify the return statement by destructuring directly___ **Consider destructuringentity_owner_id directly in the return statement of getEntityOwner to simplify the function and improve readability.** [client/src/hooks/helpers/useRealm.tsx [26-27]](https://github.com/BibliothecaDAO/eternum/pull/1000/files#diff-7a3368b90ccd171419e1dd68aafbbf5d20b6e3a231a12d711de4ff05ba9bed0cR26-R27) ```diff -const entityOwner = getComponentValue(EntityOwner, getEntityIdFromKeys([entityId])); -return entityOwner?.entity_owner_id; +return getComponentValue(EntityOwner, getEntityIdFromKeys([entityId]))?.entity_owner_id; ``` Suggestion importance[1-10]: 7Why: This suggestion improves readability by simplifying the return statement, but it is not crucial for functionality. | 7 |
Best practice |
Extract repeated logic for fetching
___
**Extract the repeated logic of fetching | 6 |
1000th PR π
User description
fixes #994
PR Type
enhancement, bug fix
Description
getEntityOwner
function inuseRealm
to retrieve the owner of an entity.useResourceBalance
to ensurecurrentDefaultTick
is always up-to-date and removed redundantuseEffect
dependencies.canExplore
function inuseTravelPath
to check if exploration is feasible based on stamina and food resources.canExplore
function inutils
to validate exploration requirements including stamina and food resources.Changes walkthrough π
useRealm.tsx
Add function to retrieve entity owner.
client/src/hooks/helpers/useRealm.tsx
getEntityOwner
function to retrieve the owner of an entity.EntityOwner
in the setup components.useResources.tsx
Refactor resource balance functions for state consistency.
client/src/hooks/helpers/useResources.tsx
currentDefaultTick
inside functions to ensure up-to-date state.useEffect
dependencies.useTravelPath.tsx
Integrate exploration feasibility check in travel path.
client/src/ui/components/worldmap/hexagon/useTravelPath.tsx
canExplore
function to check exploration feasibility.utils.tsx
Add function to validate exploration requirements.
client/src/ui/components/worldmap/hexagon/utils.tsx
canExplore
function to validate stamina and food resources.