Closed edisontim closed 3 weeks 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 18, 2024 9:26am |
โฑ๏ธ Estimated effort to review [1-5] | 4 |
๐งช Relevant tests | No |
๐ Security concerns | No |
โก Key issues to review |
Possible Bug: The BattleActions.tsx file introduces a new enumeration for loading states, which is a good improvement for readability and maintainability. However, there's a potential issue with the condition checks for disabling buttons. The conditions are based on the loading state being Loading.None , which might not be sufficient if other asynchronous operations affect the UI state. Consider adding additional checks or a more comprehensive state management approach to handle multiple loading conditions simultaneously. |
Refactoring Needed: In BattleView.tsx , the logic for rendering different components based on the battle state is complex and could be simplified. The use of multiple nested ternary operators and extensive conditions makes it hard to read and maintain. Consider breaking down the component into smaller sub-components or using a state management library to handle the complex state transitions more cleanly. | |
Data Handling: The conversion of army IDs to BigInt directly in the UI components (e.g., in BattleLabel.tsx and StructureCard.tsx ) could lead to potential type errors or inconsistencies. It would be safer to handle these conversions in the data-fetching or context layer to ensure that all components receive data in the correct format. |
Category | Suggestion | Score |
Security |
Add validation for owner data before updating to ensure data integrity___ **Add validation to check if thestructure_army_owner and structure_owner are valid before updating their addresses to prevent unauthorized access or errors.** [contracts/src/systems/combat/contracts.cairo [787-801]](https://github.com/BibliothecaDAO/eternum/pull/952/files#diff-4bdcda25a764215afd907449c2bb112a726bf3281fc1a7e6b9f7f0d4351ddb52R787-R801) ```diff let mut structure_army_owner: Owner = get!(world, structure_army_id, Owner); -structure_army_owner.address = starknet::get_caller_address(); -set!(world, (structure_army_owner)); let mut structure_owner: Owner = get!(world, structure_id, Owner); -structure_owner.address = starknet::get_caller_address(); -set!(world, (structure_owner)); +if structure_army_owner.is_valid() && structure_owner.is_valid() { + structure_army_owner.address = starknet::get_caller_address(); + structure_owner.address = starknet::get_caller_address(); + set!(world, (structure_army_owner)); + set!(world, (structure_owner)); +} else { + throw!("Invalid owner data"); +} ``` Suggestion importance[1-10]: 10Why: Adding validation checks before updating owner data is essential for preventing unauthorized access and ensuring data integrity, which is a critical security measure. | 10 |
Possible issue |
Add error handling to the asynchronous operation in the
___
**Consider adding error handling for the asynchronous operations within the | 9 |
Add error handling for transaction execution in the
___
**Consider handling exceptions for the | 9 | |
Verify compatibility of lockfile version upgrade to prevent potential issues___ **Ensure that the version updates are necessary and beneficial. The update fromlockfileVersion: '6.0' to lockfileVersion: '9.0' might introduce compatibility issues with older versions of the tooling or with other team members' environments. Verify compatibility before upgrading.** [pnpm-lock.yaml [1]](https://github.com/BibliothecaDAO/eternum/pull/952/files#diff-32824c984905bb02bc7ffcef96a77addd1f1602cff71a11fbbfdd7f53ee026bbR1-R1) ```diff -lockfileVersion: '9.0' +lockfileVersion: '6.0' ``` Suggestion importance[1-10]: 7Why: Verifying compatibility before upgrading the lockfile version is important to prevent potential issues, but the suggestion to revert might not always be necessary if compatibility is confirmed. | 7 | |
Possible bug |
Add a check for undefined
___
**Consider adding a check for | 9 |
Ensure atomic updates for
___
**Ensure that the | 8 | |
Enhancement |
Ensure type consistency in the
___
**Update the | 8 |
Use more descriptive enum names to clarify their purpose___ **Use a more descriptive variable name thanLoading for the enum to clarify its purpose related to UI state management.** [client/src/ui/modules/military/battle-view/BattleActions.tsx [14-20]](https://github.com/BibliothecaDAO/eternum/pull/952/files#diff-a2b38e5f9c040c3591adb945a143c3fe234beb433a77a677a8d069ea47a6a462R14-R20) ```diff -enum Loading { +enum BattleLoadingState { None, - Claim, - Raid, - Start, - Leave, + Claiming, + Raiding, + Starting, + Leaving, } ``` Suggestion importance[1-10]: 6Why: Using more descriptive enum names improves code readability and clarity, but it is a minor enhancement. | 6 | |
Maintainability |
Simplify the version specification to avoid potential conflicts and duplication___ **Consider using a consistent versioning approach for dependencies. The version8.1.0(@swc/core@1.5.28)(postcss@8.4.38)(typescript@5.4.4) for tsup includes specific versions of dependencies which might not be necessary if they are already managed elsewhere in the project. This can lead to version conflicts or duplication in dependency management.** [pnpm-lock.yaml [13]](https://github.com/BibliothecaDAO/eternum/pull/952/files#diff-32824c984905bb02bc7ffcef96a77addd1f1602cff71a11fbbfdd7f53ee026bbR13-R13) ```diff -version: 8.1.0(@swc/core@1.5.28)(postcss@8.4.38)(typescript@5.4.4) +version: 8.1.0 ``` Suggestion importance[1-10]: 8Why: Simplifying the version specification can prevent potential conflicts and duplication, improving maintainability. | 8 |
Simplify nested dependency declarations in version strings___ **Consider the impact of deeply nested dependencies in version strings, such asversion: 1.4.1(rollup@4.18.0)(vite@5.2.13(@types/node@20.14.2)) . This might complicate updates and obscure the source of issues. Simplifying these declarations can aid in maintainability and clarity.** [pnpm-lock.yaml [163]](https://github.com/BibliothecaDAO/eternum/pull/952/files#diff-32824c984905bb02bc7ffcef96a77addd1f1602cff71a11fbbfdd7f53ee026bbR163-R163) ```diff -version: 1.4.1(rollup@4.18.0)(vite@5.2.13(@types/node@20.14.2)) +version: 1.4.1 ``` Suggestion importance[1-10]: 8Why: Simplifying nested dependency declarations can improve maintainability and clarity, making it easier to manage and debug issues. | 8 | |
Refactor repeated code into a function to reduce duplication and improve maintainability___ **Refactor the repeatedsetLoading and setBattleView calls in each handler function to a separate function to reduce code duplication and improve maintainability.** [client/src/ui/modules/military/battle-view/BattleActions.tsx [56-64]](https://github.com/BibliothecaDAO/eternum/pull/952/files#diff-a2b38e5f9c040c3591adb945a143c3fe234beb433a77a677a8d069ea47a6a462R56-R64) ```diff -setLoading(Loading.Raid); -await battle_pillage({ +async function handleAction(action, loadingState) { + setLoading(loadingState); + await action(); + setLoading(Loading.None); + setBattleView(null); +} +handleAction(() => battle_pillage({ signer: account, army_id: attacker.entity_id, structure_id: structure!.entity_id, -}); -setLoading(Loading.None); -setBattleView(null); +}), Loading.Raid); ``` Suggestion importance[1-10]: 7Why: Refactoring repeated code into a separate function reduces duplication and enhances maintainability, although it is not critical, it improves code quality. | 7 | |
Split
___
**Refactor the | 7 | |
Improve readability and maintainability of the
___
**Refactor the | 6 | |
Best practice |
Replace non-null assertions with conditional checks to enhance code safety___ **Replace the non-null assertion operator (!) with conditional checks to ensure thatownArmy and defender are not undefined before accessing their properties. This will enhance code safety and prevent runtime errors.** [client/src/ui/modules/military/battle-view/BattleActions.tsx [77-81]](https://github.com/BibliothecaDAO/eternum/pull/952/files#diff-a2b38e5f9c040c3591adb945a143c3fe234beb433a77a677a8d069ea47a6a462R77-R81) ```diff -await battle_start({ - signer: account, - attacking_army_id: ownArmy!.entity_id, - defending_army_id: defender!.entity_id, -}); +if (ownArmy && defender) { + await battle_start({ + signer: account, + attacking_army_id: ownArmy.entity_id, + defending_army_id: defender.entity_id, + }); +} ``` Suggestion importance[1-10]: 8Why: Replacing non-null assertions with conditional checks improves code safety and prevents potential runtime errors, which is a best practice. | 8 |
Reduce specificity in version declarations to improve manageability___ **Review the necessity of adding specific sub-dependency versions directly in the versionfield. For example, version: 0.7.0-alpha.2(starknet@6.7.0(encoding@0.1.13))(typescript@5.4.4) might be overly specific and could be managed better through a centralized dependency management strategy.** [pnpm-lock.yaml [22]](https://github.com/BibliothecaDAO/eternum/pull/952/files#diff-32824c984905bb02bc7ffcef96a77addd1f1602cff71a11fbbfdd7f53ee026bbR22-R22) ```diff -version: 0.7.0-alpha.2(starknet@6.7.0(encoding@0.1.13))(typescript@5.4.4) +version: 0.7.0-alpha.2 ``` Suggestion importance[1-10]: 8Why: Reducing specificity in version declarations can improve manageability and prevent potential conflicts, making it a good practice. | 8 | |
Performance |
Refactor the destructuring in
___
**Refactor the | 7 |
User description
PR Type
Enhancement, Bug fix
Description
Changes walkthrough ๐
14 files
BattleActions.tsx
Enhance battle action handlers with loading states
client/src/ui/modules/military/battle-view/BattleActions.tsx
Loading
enum to manage different loading states.Loading
enum.BattleView.tsx
Refactor BattleView to handle different battle states
client/src/ui/modules/military/battle-view/BattleView.tsx
NoOngoingBattle
withBattleStarter
andBattleFinisher
.useArmyByArmyEntityId
hook.BattleFinisher.tsx
Add BattleFinisher component for battle completion
client/src/ui/modules/military/battle-view/BattleFinisher.tsx
BattleFinisher
component to handle battle completion UI.BattleActions
andBattleProgressBar
.BattleLabel.tsx
Handle empty battle sides in BattleLabel
client/src/ui/components/worldmap/armies/BattleLabel.tsx
battle_leave
system call.useUIStore.tsx
Simplify setBattleView function signature
client/src/hooks/store/useUIStore.tsx - Simplified `setBattleView` function signature.
useStructures.tsx
Refactor Structure type for clarity
client/src/hooks/helpers/useStructures.tsx - Refactored `Structure` type to improve clarity.
Battle.tsx
Simplify EnnemyArmies component props
client/src/ui/components/military/Battle.tsx - Simplified `EnnemyArmies` component props.
index.ts
Add battle_claim_and_leave method to EternumProvider
sdk/packages/eternum/src/provider/index.ts - Added `battle_claim_and_leave` method to `EternumProvider`.
BattleStarter.tsx
Rename and enhance BattleStarter component
client/src/ui/modules/military/battle-view/BattleStarter.tsx
NoOngoingBattle
toBattleStarter
.useArmies.tsx
Add useArmyByArmyEntityId hook
client/src/hooks/helpers/useArmies.tsx - Added `useArmyByArmyEntityId` hook.
createSystemCalls.ts
Add new battle-related system calls
client/src/dojo/createSystemCalls.ts
battle_leave_and_claim
,battle_claim
, andbattle_pillage
systemcalls.
StructureCard.tsx
Update StructureCard to use BigInt for entity IDs
client/src/ui/components/hyperstructures/StructureCard.tsx
setBattleView
to useBigInt
for entity IDs.MergeTroopsPanel
.provider.ts
Add BattleClaimAndLeaveProps interface
sdk/packages/eternum/src/types/provider.ts - Added `BattleClaimAndLeaveProps` interface.
HexagonInformationPanel.tsx
Add non-null assertion for ownArmySelected
client/src/ui/components/worldmap/hexagon/HexagonInformationPanel.tsx - Added non-null assertion for `ownArmySelected`.
1 files
WorldHexagon.tsx
Adjust import order in WorldHexagon
client/src/ui/components/worldmap/hexagon/WorldHexagon.tsx - Adjusted import order for consistency.