Closed aymericdelab closed 3 months 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 19, 2024 6:48am |
โฑ๏ธ Estimated effort to review [1-5] | 3 |
๐งช Relevant tests | No |
๐ Security concerns | No |
โก Key issues to review |
Possible Bug: The optimisticStaminaUpdate function in both useExplore.tsx and useTravel.tsx is called to update stamina optimistically. However, it's crucial to ensure that the stamina does not drop below zero or any predefined minimum value. This should be checked and handled to prevent negative stamina values. |
Error Handling: In the error handling section where overrides are removed, ensure that the catch blocks are adequately capturing and logging the specific errors for better debugging and maintenance. |
Category | Suggestion | Score |
Possible bug |
Prevent stamina from going negative by ensuring it does not drop below zero___ **Ensure that the stamina amount does not go below zero when subtracting the cost in theoptimisticStaminaUpdate function.**
[client/src/hooks/helpers/useExplore.tsx [73]](https://github.com/BibliothecaDAO/eternum/pull/955/files#diff-45821874b656c15cf5d9d6a603afd6d4858df5008f6353317b5a2d75482aa9a9R73-R73)
```diff
-amount: stamina.amount - cost,
+amount: Math.max(0, stamina.amount - cost),
```
Suggestion importance[1-10]: 10Why: This suggestion addresses a potential bug where stamina could become negative, which is a critical issue. Ensuring stamina does not drop below zero is essential for maintaining game logic integrity. | 10 |
Enhancement |
Add error handling around stamina updates to catch and log failures___ **Add error handling for theoptimisticStaminaUpdate function call to manage cases where the stamina update might fail.** [client/src/hooks/helpers/useExplore.tsx [126]](https://github.com/BibliothecaDAO/eternum/pull/955/files#diff-45821874b656c15cf5d9d6a603afd6d4858df5008f6353317b5a2d75482aa9a9R126-R126) ```diff -optimisticStaminaUpdate(overrideId, entityId, EternumGlobalConfig.stamina.exploreCost); +try { + optimisticStaminaUpdate(overrideId, entityId, EternumGlobalConfig.stamina.exploreCost); +} catch (error) { + console.error("Failed to update stamina optimistically", error); +} ``` Suggestion importance[1-10]: 8Why: Adding error handling improves the robustness of the code by catching and logging potential failures, which is important for debugging and maintaining application stability. | 8 |
Maintainability |
Use optional chaining and nullish coalescing to simplify accessing values___ **Refactor thegetStamina function to use optional chaining and nullish coalescing to simplify the code and improve readability.** [client/src/hooks/helpers/useStamina.tsx [40]](https://github.com/BibliothecaDAO/eternum/pull/955/files#diff-1462ae4521465368a66e185d64e149c741cf0439b84171e3946f3fa1046b8764R40-R40) ```diff -const armyEntity = getComponentValue(Army, armiesEntityIds.values().next().value); +const armyEntity = getComponentValue(Army, armiesEntityIds.values().next()?.value); ``` Suggestion importance[1-10]: 7Why: This suggestion improves code readability and maintainability by using modern JavaScript features. However, it does not address a critical issue. | 7 |
Possible issue |
Ensure
___
**Consider validating the | 6 |
PR Type
Enhancement
Description
optimisticStaminaUpdate
function intouseExplore
anduseTravel
hooks to handle stamina updates optimistically.getStamina
function inuseStamina
to usecurrentArmiesTick
directly.Position
andStamina
overrides if the operation fails.Changes walkthrough ๐
useExplore.tsx
Integrate optimistic stamina update in exploration logic.
client/src/hooks/helpers/useExplore.tsx
EternumGlobalConfig
anduseStamina
.optimisticStaminaUpdate
call inexploreHex
.Position
andStamina
overrides on error.useStamina.tsx
Add optimistic stamina update function.
client/src/hooks/helpers/useStamina.tsx
getStamina
function to usecurrentArmiesTick
.optimisticStaminaUpdate
function.useTravel.tsx
Integrate optimistic stamina update in travel logic.
client/src/hooks/helpers/useTravel.tsx
EternumGlobalConfig
anduseStamina
.optimisticStaminaUpdate
call intravelToHex
.Position
andStamina
overrides on error.