Closed edisontim closed 5 days 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 | Jul 5, 2024 2:48pm |
β±οΈ Estimated effort to review: 4 π΅π΅π΅π΅βͺ |
π§ͺ No relevant tests |
π No security concerns identified |
β‘ Key issues to review **Possible Bug:** The `filterArmy` function in `useArmies.tsx` uses a logical OR to combine checks for army life and battle loss. This could unintentionally include armies that are dead but have a `protectee_id`. The logic might need revising to ensure it accurately filters armies based on the intended conditions. **Refactoring Needed:** The `useBattles.tsx` and `useArmies.tsx` files have significant changes with new functions and logic that could be split into smaller, more manageable functions. This would improve readability and maintainability. **Consistency Issue:** The renaming of hooks and functions (e.g., `useEntityArmies` to `useArmiesByEntityOwner`) should be consistently reflected across all files to avoid confusion and potential bugs. |
Category | Suggestion | Score |
Possible bug |
Add a null check for
___
**Consider adding a null check for | 9 |
Add null checks for variables before using them to prevent runtime errors___ **Consider checking for the existence ofownArmyBattleStarter and defenderArmyBattleStarter before using them to prevent runtime errors if they are undefined.** [client/src/ui/modules/military/battle-view/BattleView.tsx [46-51]](https://github.com/BibliothecaDAO/eternum/pull/1086/files#diff-9926efdce78d03bb2703f0b52f301b5125b0e15fc3676eeae4645d8f90e6146fR46-R51) ```diff -: [ownArmyBattleStarter!]; -: [defenderArmyBattleStarter!]; +: ownArmyBattleStarter ? [ownArmyBattleStarter] : []; +: defenderArmyBattleStarter ? [defenderArmyBattleStarter] : []; ``` Suggestion importance[1-10]: 9Why: Adding null checks for `ownArmyBattleStarter` and `defenderArmyBattleStarter` is crucial to prevent potential runtime errors if these variables are undefined. This is a significant improvement for code robustness. | 9 | |
Ensure
___
**Refactor the | 8 | |
Add checks to handle potential undefined returns from
___
**Ensure that the | 8 | |
Add a fallback value for
___
**Ensure that | 8 | |
Enhancement |
Use
___
**Consider using the | 9 |
Error handling |
Add error handling for
___
**Ensure that the | 8 |
Possible issue |
Add a null check for
___
**Replace the direct usage of | 8 |
Best practice |
Use
___
**Replace the | 7 |
Use nullish coalescing to handle potential undefined values more explicitly___ **Use nullish coalescing operator to provide default values forselectedArmy?.x and selectedArmy?.y to ensure that the coordinates are always valid numbers.**
[client/src/ui/modules/military/battle-view/BattleActions.tsx [110]](https://github.com/BibliothecaDAO/eternum/pull/1086/files#diff-a2b38e5f9c040c3591adb945a143c3fe234beb433a77a677a8d069ea47a6a462R110-R110)
```diff
-setBattleView({ battle: { x: selectedArmy?.x || 0, y: selectedArmy?.y || 0 }, target: undefined });
+setBattleView({ battle: { x: selectedArmy?.x ?? 0, y: selectedArmy?.y ?? 0 }, target: undefined });
```
Suggestion importance[1-10]: 7Why: Using the nullish coalescing operator (`??`) is a best practice for handling potential undefined values, making the code more explicit and safer. | 7 | |
Maintainability |
Simplify the calculation of
___
**Refactor the calculation of | 6 |
User description
PR Type
Bug fix, Enhancement
Description
useArmiesByEntityOwner
.Changes walkthrough π
1 files
BattleManager.ts
Minor formatting improvement.
client/src/dojo/modelManager/BattleManager.ts - Added a newline for better readability.
18 files
useArmies.tsx
Improved army filtering and renamed hook.
client/src/hooks/helpers/useArmies.tsx
getExtraBattleInformation
import.checkIfArmyLostAFinishedBattle
withfilterArmy
in multiplefunctions.
useEntityArmies
touseArmiesByEntityOwner
.useBattles.tsx
Enhanced battle information retrieval and filtering.
client/src/hooks/helpers/useBattles.tsx
getExtraBattleInformation
andBattleInfo
type.getExtraBattleInformation
.filterBattles
function.battleIsEmpty
function.useResources.tsx
Filter armies in resource arrivals.
client/src/hooks/helpers/useResources.tsx
filterArmy
andgetArmyByEntityId
imports.getAllArrivalsWithResources
to filter armies.useLeaderBoardStore.tsx
Refactor leaderboard points calculation.
client/src/hooks/store/useLeaderBoardStore.tsx
TOTAL_CONTRIBUTABLE_AMOUNT
calculation.playerPointsLeaderboards
parameter.useQuestStore.tsx
Update quest store to use new army hook.
client/src/hooks/store/useQuestStore.tsx - Replaced `useEntityArmies` with `useArmiesByEntityOwner`.
Entity.tsx
Add army existence check in entity component.
client/src/ui/components/entities/Entity.tsx
getArmyByEntityId
import.HyperstructurePanel.tsx
Simplify hyperstructure panel and leaderboard.
client/src/ui/components/hyperstructures/HyperstructurePanel.tsx
HYPERSTRUCTURE_TOTAL_COSTS_SCALED
.HyperstructureLeaderboard
component.HyperstructureResourceChip.tsx
Adjust max contributable amount and improve layout.
client/src/ui/components/hyperstructures/HyperstructureResourceChip.tsx
ArmyList.tsx
Update army list to use new army hook.
client/src/ui/components/military/ArmyList.tsx - Replaced `useEntityArmies` with `useArmiesByEntityOwner`.
BattlesArmyTable.tsx
Update battles army table to use new battle hook.
client/src/ui/components/military/BattlesArmyTable.tsx
useBattles
withusePlayerBattles
.BattleChip
to useBattleInfo
.EntitiesArmyTable.tsx
Simplify entities army table with new hook.
client/src/ui/components/military/EntitiesArmyTable.tsx
useEntityArmies
withuseArmiesByEntityOwner
.Battles.tsx
Remove redundant battle health check.
client/src/ui/components/models/buildings/worldmap/Battles.tsx - Removed redundant battle health check.
ResourceArrivals.tsx
Remove unused resource arrivals component.
client/src/ui/components/trading/ResourceArrivals.tsx
useResources
import andResourceArrivals
component.Army.tsx
Update BattleLabel to use battle entity ID.
client/src/ui/components/worldmap/armies/Army.tsx - Updated `BattleLabel` to use battle entity ID.
HexagonInformationPanel.tsx
Update hexagon information panel to use BattleInfo.
client/src/ui/components/worldmap/hexagon/HexagonInformationPanel.tsx - Updated `checkWhatToShow` to use `BattleInfo`.
LeftNavigationModule.tsx
Update left navigation module to use new army hook.
client/src/ui/modules/navigation/LeftNavigationModule.tsx - Replaced `useEntityArmies` with `useArmiesByEntityOwner`.
RightNavigationModule.tsx
Remove unused togglePopup import.
client/src/ui/modules/navigation/RightNavigationModule.tsx - Removed unused `togglePopup` import.
mint_resource.sh
Add function to mint all resources in script.
contracts/scripts/testing/mint_resource.sh
3 files
useHyperstructures.tsx
Fix resource cost calculation in hyperstructures.
client/src/hooks/helpers/useHyperstructures.tsx
getAllProgressesAndTotalPercentage
.BattleActions.tsx
Fix potential undefined value and adjust select width.
client/src/ui/modules/military/battle-view/BattleActions.tsx
setBattleView
.SelectContent
width.BattleView.tsx
Add non-null assertions for battle starter armies.
client/src/ui/modules/military/battle-view/BattleView.tsx - Added non-null assertions for battle starter armies.