You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Possible Bug The method getUpdatedTroops in BattleManager class might throw an error if health.current is greater than health.lifetime. This scenario should be handled gracefully without throwing errors to avoid crashing the application.
Code Smell The method raidStructure in BattleManager class directly logs to the console which is not recommended. Consider using a logging framework or handling the error more gracefully.
UI Improvement The ArmyManagementCard component has a delete button that does not have a confirmation step directly in the UI flow, which might lead to accidental deletions. Consider adding a confirmation modal or an additional step to verify the user's intent.
Refactoring Needed The BattleActions component has a complex conditional rendering logic that makes the component difficult to read and maintain. Consider breaking down the component into smaller subcomponents or using a more declarative approach to handle the conditional rendering.
Ensure proper typing and usage of the battle variable within the useBattleManager function
Refactor the useBattleManager function to ensure that the battle variable is properly typed and used within the useMemo callback to avoid potential runtime errors.
Why: Adding a null check for 'army.health.current' is important to prevent potential null reference errors, which could cause runtime exceptions.
9
Add a null check for battle.last_updated to prevent runtime errors
Consider checking if battle is undefined before accessing its properties in getElapsedTime. This will prevent potential runtime errors when battle is undefined.
Why: This suggestion adds a null check for battle.last_updated, which is a good practice to prevent potential runtime errors when battle is undefined. It addresses a possible bug and improves code robustness.
8
Prevent underflows in time calculations by adding checks
Replace the direct subtraction in the getElapsedTime method with a safer calculation that checks for underflows, which can occur with large timestamp values.
Why: This suggestion addresses a potential bug by adding a check to prevent underflows in time calculations, improving the reliability of the getElapsedTime method.
8
Enhancement
Correct the typo and enhance readability in the function definition
Refactor the generateMockBatle function to correct the typo in the function name and improve the structure of the object returned to enhance readability.
Why: Correcting the typo in the function name is important for code clarity and maintainability. The suggestion also maintains the existing structure, ensuring no functionality is lost.
9
Adjust troop calculations to handle data inconsistencies gracefully
The function getUpdatedTroops should handle the case where currentHealth.current is greater than currentHealth.lifetime more gracefully by adjusting the troop count proportionally instead of throwing an error. This can help in scenarios where data inconsistencies might lead to application crashes.
Why: This suggestion improves the robustness of the code by preventing application crashes due to data inconsistencies. However, it changes the logic significantly, which might not be the intended behavior in all cases.
7
Robustness
Add error handling to asynchronous mock setups
Introduce error handling for asynchronous operations within the vi.mock setup to catch and handle potential rejections or exceptions, ensuring the mock setup does not fail silently.
Why: Adding error handling to asynchronous operations within the mock setup enhances the robustness of the tests by ensuring that any issues during the mock setup are caught and handled appropriately.
9
Possible issue
Add type assertion to ensure the 'battle' variable is of type 'BattleInfo'
Consider using a type assertion or a type guard to ensure that the battle variable is indeed of type BattleInfo before using it in the armyHasLost and battleIsFinished functions. This will prevent potential runtime errors if the battle variable does not conform to the expected type.
Why: Adding a type assertion for 'battle' ensures type safety and prevents potential runtime errors, which is crucial for maintaining robust code.
8
Ensure battleId is valid before using it in isRaidable
Use a more robust type check for battleId in isRaidable to ensure it's not just non-zero but also a valid ID. This can prevent logical errors when battleId is improperly set.
Why: This suggestion improves the robustness of the code by ensuring battleId is valid before using it. It prevents logical errors when battleId is improperly set, addressing a possible issue.
7
Best practice
Improve type safety by specifying more precise types for the list and get methods
Refactor the DojoAccount interface to use a more specific type than any for the list and get methods to improve type safety and code clarity.
Why: Improving type safety by specifying more precise types enhances code reliability and maintainability, which is a best practice.
8
Use BigInt for 'battle_id' to handle large numbers correctly
To ensure the correct handling of large numbers, consider using BigInt for all operations and comparisons involving battle_id to avoid potential precision loss in JavaScript numbers.
Why: Using BigInt for 'battle_id' ensures that large numbers are handled correctly, which is a good practice to avoid precision loss in JavaScript.
7
Ensure immutability by cloning the battle object before updates
Refactor the getUpdatedBattle function to ensure that the battle object is cloned before modification to avoid unintended side effects on the original battle object.
Why: Cloning the battle object before modification is a good practice to avoid unintended side effects. However, the suggestion does not provide a complete implementation, and the existing code does not show any direct modification of the battle object.
6
Maintainability
Improve the function name for clarity and maintainability
Consider using a more descriptive function name than getTroopHeathSimplified to improve code readability and maintainability. A name like calculateTroopHealth would be clearer in indicating the function's purpose.
Why: The suggestion improves code readability and maintainability by using a more descriptive function name, which is a good practice but not critical.
7
Refactor repeated army querying logic into a separate function
Refactor the repeated logic for querying armies by position into a separate function to improve code maintainability and reduce duplication.
Why: Refactoring repeated logic into a separate function improves code maintainability and reduces duplication, although it is not critical for functionality.
6
Simplify the isClaimable method by consolidating conditions
Refactor the isClaimable method to reduce complexity and improve readability by extracting conditions into well-named helper functions.
Why: This suggestion refactors the isClaimable method to reduce complexity and improve readability. While it enhances maintainability, the improvement is relatively minor.
5
Performance
Store durationSinceLastUpdate in a variable to avoid redundant calculations
Avoid recalculating durationSinceLastUpdate multiple times within the same method by storing it in a variable at the beginning of the method.
Why: This suggestion improves performance by avoiding redundant calculations of durationSinceLastUpdate. It simplifies the code and makes it more efficient.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Type
Tests, Enhancement
Description
BattleManager
class.ArmyManagementCard
component with new functionalities and improved UI.BattleManager
class with new methods for battle management.BattleActions
component to use newBattleManager
methods.StructureCard
component to integrate with new battle functionalities.EntityDetails
component to use new hooks and added tabs for entities and battles.StructureListItem
component with new battle-related functionalities.BattleView
component to use newBattleManager
methods.BattleSideView
component to integrate with new battle functionalities.Changes walkthrough 📝
1 files
BattleManager.test.ts
Add unit tests for BattleManager functionalities
client/src/dojo/modelManager/tests/BattleManager.test.ts
BattleManager
class.updates.
9 files
useArmies.tsx
Refactor army-related hooks and utilities
client/src/hooks/helpers/useArmies.tsx
Battle
component references.position.
ArmyManagementCard.tsx
Enhance ArmyManagementCard with delete functionality and UI
improvements
client/src/ui/components/military/ArmyManagementCard.tsx
ArmyManagementCard
component with new functionalities.BattleManager.ts
Extend BattleManager with new battle management methods
client/src/dojo/modelManager/BattleManager.ts
BattleManager
class with new methods for battle management.managing raids.
BattleActions.tsx
Refactor BattleActions to use new BattleManager methods
client/src/ui/modules/military/battle-view/BattleActions.tsx
BattleActions
component to use newBattleManager
methods.StructureCard.tsx
Update StructureCard with new battle functionalities
client/src/ui/components/hyperstructures/StructureCard.tsx
StructureCard
component to integrate with new battlefunctionalities.
EntityDetails.tsx
Refactor EntityDetails with new hooks and tabs
client/src/ui/modules/entity-details/EntityDetails.tsx
EntityDetails
component to use new hooks and utilities.StructureListItem.tsx
Enhance StructureListItem with battle functionalities
client/src/ui/components/worldmap/structures/StructureListItem.tsx
StructureListItem
component with new battle-relatedfunctionalities.
BattleView.tsx
Refactor BattleView to use new BattleManager methods
client/src/ui/modules/military/battle-view/BattleView.tsx
BattleView
component to use newBattleManager
methods.BattleSideView.tsx
Update BattleSideView with new battle functionalities
client/src/ui/modules/military/battle-view/BattleSideView.tsx
BattleSideView
component to integrate with new battlefunctionalities.
1 files
DepositResources.tsx
Fix resource deposit timing issue
client/src/ui/components/resources/DepositResources.tsx
51 files
useBattles.tsx
...
client/src/hooks/helpers/battles/useBattles.tsx
...
useStructures.tsx
...
client/src/hooks/helpers/useStructures.tsx
...
ArmyList.tsx
...
client/src/ui/components/military/ArmyList.tsx
...
BattleListItem.tsx
...
client/src/ui/components/battles/BattleListItem.tsx
...
__mock__.ts
...
client/src/dojo/modelManager/tests/mock.ts
...
ArmyChip.tsx
...
client/src/ui/components/military/ArmyChip.tsx
...
Battle.tsx
...
client/src/ui/modules/military/battle-view/Battle.tsx
...
SelectPreviewBuilding.tsx
...
client/src/ui/components/construction/SelectPreviewBuilding.tsx
...
BattleProgressBar.tsx
...
client/src/ui/modules/military/battle-view/BattleProgressBar.tsx
...
InventoryResources.tsx
...
client/src/ui/components/resources/InventoryResources.tsx
...
Battles.tsx
...
client/src/ui/components/models/buildings/worldmap/Battles.tsx
...
BattleDetails.tsx
...
client/src/ui/modules/military/battle-view/BattleDetails.tsx
...
Army.tsx
...
client/src/ui/components/worldmap/armies/Army.tsx
...
EnnemyArmies.tsx
...
client/src/ui/modules/entity-details/EnnemyArmies.tsx
...
Select.tsx
...
client/src/ui/elements/Select.tsx
...
ArmyInfoLabel.tsx
...
client/src/ui/components/worldmap/armies/ArmyInfoLabel.tsx
...
useEventHandlers.tsx
...
client/src/ui/components/worldmap/hexagon/useEventHandlers.tsx
...
TroopChip.tsx
...
client/src/ui/components/military/TroopChip.tsx
...
useEntities.tsx
...
client/src/hooks/helpers/useEntities.tsx
...
Entities.tsx
...
client/src/ui/modules/entity-details/Entities.tsx
...
LockedResources.tsx
...
client/src/ui/modules/military/battle-view/LockedResources.tsx
...
DojoContext.tsx
...
client/src/hooks/context/DojoContext.tsx
...
useTravelPath.tsx
...
client/src/ui/components/worldmap/hexagon/useTravelPath.tsx
...
Battles.tsx
...
client/src/ui/modules/entity-details/Battles.tsx
...
Entity.tsx
...
client/src/ui/components/entities/Entity.tsx
...
useResources.tsx
...
client/src/hooks/helpers/useResources.tsx
...
WorldStructuresMenu.tsx
...
client/src/ui/modules/world-structures/WorldStructuresMenu.tsx
...
ArmyHitBox.tsx
...
client/src/ui/components/worldmap/armies/ArmyHitBox.tsx
...
TradeHistoryEvent.tsx
...
client/src/ui/components/trading/TradeHistoryEvent.tsx
...
EntityList.tsx
...
client/src/ui/components/list/EntityList.tsx
...
ArmyViewCard.tsx
...
client/src/ui/components/military/ArmyViewCard.tsx
...
useGuilds.tsx
...
client/src/hooks/helpers/useGuilds.tsx
...
BattlesArmyTable.tsx
...
client/src/ui/components/military/BattlesArmyTable.tsx
...
StaminaResource.tsx
...
client/src/ui/elements/StaminaResource.tsx
...
Structures.tsx
...
client/src/ui/components/models/buildings/worldmap/Structures.tsx
...
BattleCard.tsx
...
client/src/ui/components/battles/BattleCard.tsx
...
RightNavigationModule.tsx
...
client/src/ui/modules/navigation/RightNavigationModule.tsx
...
Troops.tsx
...
client/src/ui/modules/military/battle-view/Troops.tsx
...
LeftNavigationModule.tsx
...
client/src/ui/modules/navigation/LeftNavigationModule.tsx
...
Armies.tsx
...
client/src/ui/components/worldmap/armies/Armies.tsx
...
HexLayers.tsx
...
client/src/ui/components/worldmap/hexagon/HexLayers.tsx
...
useBlockchainStore.tsx
...
client/src/hooks/store/useBlockchainStore.tsx
...
types.ts
...
client/src/hooks/store/types.ts
...
RealmListItem.tsx
...
client/src/ui/components/worldmap/realms/RealmListItem.tsx
...
global.ts
...
sdk/packages/eternum/src/constants/global.ts
...
EntitiesArmyTable.tsx
...
client/src/ui/components/military/EntitiesArmyTable.tsx
...
ArmyPanel.tsx
...
client/src/ui/components/military/ArmyPanel.tsx
...
index.ts
...
client/src/types/index.ts
...
contracts.cairo
...
contracts/src/systems/combat/contracts.cairo
...
system_models.json
...
contracts/scripts/system_models.json
...
package.json
...
client/package.json
...