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
Refactoring Complexity The refactoring in useArmies.tsx significantly increases the complexity of the code. Consider simplifying the logic or breaking down the functions further to improve maintainability.
New Functionality New functions and types such as getBattle and BattleInfo have been added. Ensure that these changes are well-documented and covered by unit tests to maintain code quality and understandability.
UI Component Changes Changes in ArmyManagementCard.tsx involve significant modifications to the UI logic and state management. It's crucial to ensure that these changes do not introduce regressions or affect the user experience negatively.
Prevent division by zero by validating precision values before division
Avoid potential division by zero errors by checking if EternumGlobalConfig.resources.resourcePrecision and EternumGlobalConfig.troop.healthPrecision are not zero before performing the division.
-BigInt(EternumGlobalConfig.resources.resourcePrecision) * EternumGlobalConfig.troop.healthPrecision+const precisionProduct = BigInt(EternumGlobalConfig.resources.resourcePrecision) * EternumGlobalConfig.troop.healthPrecision;+if (precisionProduct === 0n) throw new Error("Precision values should not be zero.");+healthClone.current = BigInt(healthClone.current) / precisionProduct;+healthClone.lifetime = BigInt(healthClone.lifetime) / precisionProduct;
Suggestion importance[1-10]: 10
Why: This suggestion prevents a critical error (division by zero) by validating precision values, which is essential for ensuring the correctness and stability of the code.
10
Add a check to prevent division by zero in troop count calculations
Ensure that the getUpdatedArmy function handles the case where battle_army_lifetime.troops.knight_count is zero to avoid division by zero errors.
Why: This suggestion prevents a possible division by zero error, which is a significant bug that could cause runtime exceptions.
9
Add a check for undefined army object to prevent runtime errors
Consider checking for undefined values in the army object before accessing its properties in the checkIfArmyLostAFinishedBattle function. This will prevent potential runtime errors if an undefined army object is passed to the function.
Why: This suggestion addresses a potential runtime error by adding a check for an undefined army object, which is a crucial improvement for code robustness.
9
Add null checks to prevent runtime errors when accessing potentially null objects
Consider adding null checks or optional chaining when accessing properties of objects that might potentially be null or undefined. This is particularly important for the realm and structure objects in the playerStructures function, as they are being accessed directly which could lead to runtime errors if they are null.
Why: Adding null checks is crucial to prevent potential runtime errors when accessing properties of objects that might be null or undefined. This suggestion addresses a possible bug and improves the robustness of the code.
9
Improve the safety of BigInt to number conversion to prevent potential data loss
Replace the direct usage of Number for converting BigInt to number with a safer method that checks for potential overflow or precision issues. This is crucial because using Number directly can lead to precision loss for very large BigInt values.
Why: This suggestion addresses a potential bug by ensuring safer conversion from BigInt to number, which is crucial for preventing precision loss in large values.
8
Add null checks to function inputs to prevent runtime errors
Ensure that the protectorStillInBattle function handles cases where the input parameters are null or undefined to prevent runtime errors.
-const isInBattle = testedModule.protectorStillInBattle({} as any, {} as any, {} as any);+const isInBattle = testedModule.protectorStillInBattle({} as any ?? {}, {} as any ?? {}, {} as any ?? {});
Suggestion importance[1-10]: 5
Why: Adding null checks can prevent potential runtime errors, but the suggested implementation using the nullish coalescing operator is not the most appropriate for this context.
5
Enhancement
Add error handling for undefined return values in getBattle to enhance robustness
Consider adding error handling or a fallback mechanism in getBattle method when getComponentValue returns undefined, to ensure the method's robustness.
-return getComponentValue(this.battleModel, getEntityIdFromKeys([this.battleId]));+const battleComponent = getComponentValue(this.battleModel, getEntityIdFromKeys([this.battleId]));+if (!battleComponent) {+ // Handle the undefined case or throw an error+ throw new Error("Battle component not found for the given battle ID.");+}+return battleComponent;
Suggestion importance[1-10]: 8
Why: Adding error handling increases the robustness of the method, preventing potential issues when getComponentValue returns undefined.
8
Ensure consistent army positioning by replacing random offset calculation with a deterministic approach
Replace the usage of Math.random() for offset calculation with a deterministic function based on armyEntityId to ensure consistent positioning across different renders or sessions.
Why: Replacing Math.random() with a deterministic function ensures consistent positioning, which is important for predictable behavior across different renders or sessions.
8
Use destructuring to enhance code readability and maintainability
To improve code readability and maintainability, consider using destructuring for the account object in the useEntitiesUtils function. This approach can make the code cleaner and easier to understand.
Why: While using destructuring can enhance code readability, the existing code is already clear. This suggestion is a minor enhancement and does not address any critical issues.
5
Best practice
Improve type safety by using a more robust type checking mechanism
Replace the direct type assertion with a more robust type checking mechanism to ensure the correct type is being passed to the Set constructor. This will prevent potential runtime errors if the type of the entity is not as expected.
-const protectors = new Set(["0x0" as Entity]);+const protectors = new Set<Entity>(["0x0"].map(e => e as Entity));
Suggestion importance[1-10]: 8
Why: This suggestion improves type safety by ensuring that the elements being added to the Set are of the correct type, which can prevent potential runtime errors.
8
Add error handling for undefined entityName to enhance function robustness
It's a good practice to handle cases where entityName might be undefined in the getEntityName function. This can prevent potential runtime errors and make the function more robust.
Why: Handling cases where entityName might be undefined is important for preventing runtime errors and improving the robustness of the function. This suggestion addresses a best practice.
8
Enhance type safety by using a more specific type guard in the filter method
Use a more specific type guard in the .filter method to ensure only valid ArmyInfo objects are processed, enhancing type safety and clarity.
-.filter((army): army is ArmyInfo => army !== undefined);+.filter((army): army is ArmyInfo => army !== undefined && army.hasOwnProperty('name') && army.hasOwnProperty('health'));
Suggestion importance[1-10]: 7
Why: Using a more specific type guard improves type safety and clarity, which is beneficial for maintainability and reducing potential bugs.
7
Improve type safety by using explicit type casting or type guards
Use explicit type casting or type guards instead of using as any to ensure type safety and maintainability of the code.
-const isInBattle = testedModule.protectorStillInBattle({} as any, {} as any, {} as any);+const isInBattle = testedModule.protectorStillInBattle({} as SpecificType, {} as SpecificType, {} as SpecificType);
Suggestion importance[1-10]: 6
Why: Using explicit type casting or type guards enhances type safety and maintainability, but the suggestion lacks specificity regarding the exact types to be used.
6
Maintainability
Refactor the method to calculate total troop health to be more scalable and maintainable
Refactor getTroopFullHealth to use a loop or a more scalable method to handle an arbitrary number of troop types, which will improve maintainability and scalability of the code.
Why: Refactoring the repeated mocking to a utility function or setup step reduces redundancy and improves the maintainability of the tests, making the code cleaner and easier to manage.
7
Possible issue
Validate address before usage to ensure data integrity and prevent bugs
To avoid potential bugs and ensure the data integrity, consider validating the address before using it to fetch addressName in the getAddressNameFromEntity function.
Why: Validating the address before usage is a good practice to ensure data integrity and prevent potential bugs. This suggestion addresses a possible issue but is not critical.
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.
User description
beginning of changes to UI to adapt to contract changes:
Army panel and entity details design changes
PR Type
Enhancement, Tests
Description
.no-scrollbar
to hide scrollbars across different browsers.useBattlesUtils
functions.Changes walkthrough 📝
14 files
tailwind.config.js
Add utility class to hide scrollbars
client/tailwind.config.js
.no-scrollbar
to hide scrollbars acrossdifferent browsers.
useArmies.tsx
Refactor army-related hooks and types
client/src/hooks/helpers/useArmies.tsx
ArmyInfo
type to useComponentValue
.formatArmies
function to handle undefined values andstructured cloning.
useArmies
touseMovableArmies
.type safety.
useBattles.tsx
Refactor battle-related hooks and add utility functions
client/src/hooks/helpers/battles/useBattles.tsx
getBattle
function to fetch and process battle data.getExtraBattleInformation
to usegetBattle
.useBattles
touseAllBattles
.safety.
ArmyManagementCard.tsx
Update ArmyManagementCard component and add map navigation icon
client/src/ui/components/military/ArmyManagementCard.tsx
entity
prop toarmy
.army
instead ofentity
.ViewOnMapIcon
component for map navigation.BattleManager.ts
Refactor BattleManager for improved type safety and functionality
client/src/dojo/modelManager/BattleManager.ts
BattleManager
class to improve type safety.useStructures.tsx
Refactor structure-related hooks for improved type safety
client/src/hooks/helpers/useStructures.tsx
useStructuresPosition
andgetStructureAtPosition
to handleundefined values.
EntityDetails.tsx
Add components for displaying entity details
client/src/ui/modules/entity-details/EntityDetails.tsx
selected entity.
useEntities.tsx
Refactor entity-related hooks and add utility functions
client/src/hooks/helpers/useEntities.tsx
useEntities
anduseEntitiesUtils
hooks.ArmyChip.tsx
Update ArmyChip component with new army data structure and buttons
client/src/ui/components/military/ArmyChip.tsx
ArmyChip
component to use new army data structure.Battle.tsx
Update EnemyArmies component with new army data structure
client/src/ui/components/military/Battle.tsx
EnemyArmies
component to use new army data structure.Entity.tsx
Update Entity component with new hooks and utility functions
client/src/ui/components/entities/Entity.tsx
Entity
component to use new hooks and utility functions.BattleActions.tsx
Update BattleActions component with new data structures
client/src/ui/modules/military/battle-view/BattleActions.tsx
BattleActions
component to use new army and battle datastructures.
ArmyInfoLabel.tsx
Update ArmyInfoLabel component with new army data structure
client/src/ui/components/worldmap/armies/ArmyInfoLabel.tsx
ArmyInfoLabel
component to use new army data structure.Army.tsx
Update Army and ArmySelectionOverlay components with new data
structure
client/src/ui/components/worldmap/armies/Army.tsx
Army
andArmySelectionOverlay
components to use new army datastructure.
1 files
useBattlesUtils.test.tsx
Add tests for useBattlesUtils functions
client/src/hooks/helpers/battles/test/useBattlesUtils.test.tsx
useBattlesUtils
functions.71 files
__mock__.tsx
...
client/src/hooks/helpers/battles/test/mock.tsx
...
Military.tsx
...
client/src/ui/modules/military/Military.tsx
...
BattleProgressBar.tsx
...
client/src/ui/modules/military/battle-view/BattleProgressBar.tsx
...
BattleView.tsx
...
client/src/ui/modules/military/battle-view/BattleView.tsx
...
Battle.tsx
...
client/src/ui/modules/military/battle-view/Battle.tsx
...
useHyperstructures.tsx
...
client/src/hooks/helpers/useHyperstructures.tsx
...
TroopChip.tsx
...
client/src/ui/components/military/TroopChip.tsx
...
useGuilds.tsx
...
client/src/hooks/helpers/useGuilds.tsx
...
TopMiddleNavigation.tsx
...
client/src/ui/modules/navigation/TopMiddleNavigation.tsx
...
useTrade.tsx
...
client/src/hooks/helpers/useTrade.tsx
...
useStamina.tsx
...
client/src/hooks/helpers/useStamina.tsx
...
Battles.tsx
...
client/src/ui/components/models/buildings/worldmap/Battles.tsx
...
StructureCard.tsx
...
client/src/ui/components/hyperstructures/StructureCard.tsx
...
GroundGrid.tsx
...
client/src/ui/components/construction/GroundGrid.tsx
...
ShardsMines.tsx
...
client/src/ui/components/models/buildings/worldmap/ShardsMines.tsx
...
useHexPosition.tsx
...
client/src/hooks/helpers/useHexPosition.tsx
...
useTravel.tsx
...
client/src/hooks/helpers/useTravel.tsx
...
ArmyViewCard.tsx
...
client/src/ui/components/military/ArmyViewCard.tsx
...
MarketManager.ts
...
client/src/dojo/modelManager/MarketManager.ts
...
RealmListItem.tsx
...
client/src/ui/components/worldmap/realms/RealmListItem.tsx
...
InstancedCastles.tsx
...
client/src/ui/components/models/buildings/worldmap/InstancedCastles.tsx
...
TradeHistoryEvent.tsx
...
client/src/ui/components/trading/TradeHistoryEvent.tsx
...
Armies.tsx
...
client/src/ui/components/worldmap/armies/Armies.tsx
...
LeftNavigationModule.tsx
...
client/src/ui/modules/navigation/LeftNavigationModule.tsx
...
useResources.tsx
...
client/src/hooks/helpers/useResources.tsx
...
HexceptionViewScene.tsx
...
client/src/ui/modules/scenes/HexceptionViewScene.tsx
...
useBuildings.tsx
...
client/src/hooks/helpers/useBuildings.tsx
...
ArmyHitBox.tsx
...
client/src/ui/components/worldmap/armies/ArmyHitBox.tsx
...
useUISound.tsx
...
client/src/hooks/useUISound.tsx
...
utils.tsx
...
client/src/ui/components/worldmap/armies/utils.tsx
...
useRoads.tsx
...
client/src/hooks/helpers/useRoads.tsx
...
useBanks.tsx
...
client/src/hooks/helpers/useBanks.tsx
...
RightNavigationModule.tsx
...
client/src/ui/modules/navigation/RightNavigationModule.tsx
...
WorldStructuresMenu.tsx
...
client/src/ui/modules/world-structures/WorldStructuresMenu.tsx
...
BattleDetails.tsx
...
client/src/ui/modules/military/battle-view/BattleDetails.tsx
...
StructureListItem.tsx
...
client/src/ui/components/worldmap/structures/StructureListItem.tsx
...
useBlockchainStore.tsx
...
client/src/hooks/store/useBlockchainStore.tsx
...
HexGrid.tsx
...
client/src/ui/components/models/biomes/HexGrid.tsx
...
GrasslandBiome.tsx
...
client/src/ui/components/models/biomes/GrasslandBiome.tsx
...
DeepOceanBiome.tsx
...
client/src/ui/components/models/biomes/DeepOceanBiome.tsx
...
DesertBiome.tsx
...
client/src/ui/components/models/biomes/DesertBiome.tsx
...
OceanBiome.tsx
...
client/src/ui/components/models/biomes/OceanBiome.tsx
...
useRealm.tsx
...
client/src/hooks/helpers/useRealm.tsx
...
useQuestStore.tsx
...
client/src/hooks/store/useQuestStore.tsx
...
vitest.config.ts
...
client/vitest.config.ts
...
DeciduousForestBiome.tsx
...
client/src/ui/components/models/biomes/DeciduousForestBiome.tsx
...
SubtropicalDesertBiome.tsx
...
client/src/ui/components/models/biomes/SubtropicalDesertBiome.tsx
...
TemperateDesertBiome.tsx
...
client/src/ui/components/models/biomes/TemperateDesertBiome.tsx
...
TemperateRainforestBiome.tsx
...
client/src/ui/components/models/biomes/TemperateRainforestBiome.tsx
...
TropicalSeasonalForestBiome.tsx
...
client/src/ui/components/models/biomes/TropicalSeasonalForestBiome.tsx
...
_mapStore.tsx
...
client/src/hooks/store/_mapStore.tsx
...
ScorchedBiome.tsx
...
client/src/ui/components/models/biomes/ScorchedBiome.tsx
...
SnowBiome.tsx
...
client/src/ui/components/models/biomes/SnowBiome.tsx
...
TropicalRainforestBiome.tsx
...
client/src/ui/components/models/biomes/TropicalRainforestBiome.tsx
...
BeachBiome.tsx
...
client/src/ui/components/models/biomes/BeachBiome.tsx
...
ShrublandBiome.tsx
...
client/src/ui/components/models/biomes/ShrublandBiome.tsx
...
TaigaBiome.tsx
...
client/src/ui/components/models/biomes/TaigaBiome.tsx
...
TundraBiome.tsx
...
client/src/ui/components/models/biomes/TundraBiome.tsx
...
ExistingBuildings.tsx
...
client/src/ui/components/construction/ExistingBuildings.tsx
...
BattleLabel.tsx
...
client/src/ui/components/worldmap/armies/BattleLabel.tsx
...
useCaravans.tsx
...
client/src/hooks/helpers/useCaravans.tsx
...
global.ts
...
sdk/packages/eternum/src/constants/global.ts
...
ArmyPanel.tsx
...
client/src/ui/components/military/ArmyPanel.tsx
...
BattlesArmyTable.tsx
...
client/src/ui/components/military/BattlesArmyTable.tsx
...
DepositResources.tsx
...
client/src/ui/components/resources/DepositResources.tsx
...
createClientComponents.ts
...
client/src/dojo/createClientComponents.ts
...
pnpm-lock.yaml
...
pnpm-lock.yaml
...
tests.cairo
...
contracts/src/systems/combat/tests.cairo
...
package.json
...
client/package.json
...
test-contracts.yml
...
.github/workflows/test-contracts.yml
...
test-client.yml
...
.github/workflows/test-client.yml
...