BibliothecaDAO / eternum

onchain eternal game
https://alpha-eternum.realms.world
MIT License
36 stars 30 forks source link

Loaf market #993

Closed ponderingdemocritus closed 1 week ago

ponderingdemocritus commented 1 week ago

PR Type

enhancement, bug fix


Description


Changes walkthrough πŸ“

Relevant files
Bug fix
useTrade.tsx
Add optional chaining to prevent runtime errors                   

client/src/hooks/helpers/useTrade.tsx
  • Added optional chaining to takerGets[0]?.resourceId to prevent
    potential runtime errors.
  • +3/-3     
    Enhancement
    ResourceWeight.tsx
    Reorder table rows and update styling                                       

    client/src/ui/components/resources/ResourceWeight.tsx
  • Reordered table rows for better UX.
  • Updated class names for styling consistency.
  • +11/-13 
    MarketOrderPanel.tsx
    Adjust resource icon placement and fix bid calculation     

    client/src/ui/components/trading/MarketOrderPanel.tsx
  • Adjusted resource icon placement for better UX.
  • Corrected bid calculation logic.
  • +4/-3     
    TransferBetweenEntities.tsx
    Enhance transfer details and improve layout                           

    client/src/ui/components/trading/TransferBetweenEntities.tsx
  • Added entity name display for transfer details.
  • Updated state management for selected entities.
  • Improved layout and styling for resource selection and transfer
    confirmation.
  • +74/-42 
    ListSelect.tsx
    Update styling and remove unused SVG                                         

    client/src/ui/elements/ListSelect.tsx
  • Updated styling for list select component.
  • Removed unused SVG element.
  • +7/-15   
    NumberInput.tsx
    Update border styling for number input                                     

    client/src/ui/elements/NumberInput.tsx - Updated border styling for number input component.
    +2/-2     

    πŸ’‘ PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    vercel[bot] commented 1 week 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 24, 2024 6:06am
    github-actions[bot] commented 1 week ago

    PR Reviewer Guide πŸ”

    ⏱️ Estimated effort to review [1-5] 4
    πŸ§ͺ Relevant tests No
    πŸ”’ Security concerns No
    ⚑ Key issues to review Possible Bug:
    In useTrade.tsx, the change in the calculation logic for perLords might introduce a bug if not properly tested. The order of arguments in calculateRatio function has been swapped, which could potentially lead to incorrect calculations if not handled correctly.
    Code Clarity:
    In ResourceWeight.tsx, the renaming of table headers and data might cause confusion or misalignment with other parts of the application that depend on these names. It's important to ensure that all references to these names are updated accordingly.
    Redundancy:
    In MarketOrderPanel.tsx, the ResourceIcon component is rendered twice consecutively with different props which might be an error or unnecessary duplication.
    Data Handling:
    In TransferBetweenEntities.tsx, the introduction of SelectedEntity interface and changes in state management for entity selection could lead to unexpected behavior if the new data structure is not integrated properly throughout the application.
    github-actions[bot] commented 1 week ago

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Add a check to prevent division by zero, ensuring the application's stability ___ **Replace the direct division of lords / resource with a safer check to ensure resource is
    not zero, preventing division by zero errors.** [client/src/ui/components/trading/MarketOrderPanel.tsx [343]](https://github.com/BibliothecaDAO/eternum/pull/993/files#diff-00bad72a59745d3d904730035fcdeaddda30f53c9212d94f35f277ef202bd0bdR343-R343) ```diff -return (lords / resource).toFixed(2); +return resource !== 0 ? (lords / resource).toFixed(2) : '0.00'; ```
    Suggestion importance[1-10]: 10 Why: This suggestion prevents a critical issue of division by zero, which could cause runtime errors and application instability. It is a significant improvement for ensuring the application's reliability.
    10
    Add a null check for the array before accessing its elements to prevent runtime errors ___ **Consider adding a null check for takerGets before accessing its first element to avoid
    potential runtime errors if takerGets is undefined or empty.** [client/src/hooks/helpers/useTrade.tsx [91]](https://github.com/BibliothecaDAO/eternum/pull/993/files#diff-e42008cf5c4b4bd687484849a10da2429f055707a9335a9c28ac67da60a45f34R91-R91) ```diff -takerGets[0]?.resourceId == ResourcesIds.Lords +takerGets && takerGets[0]?.resourceId == ResourcesIds.Lords ```
    Suggestion importance[1-10]: 9 Why: This suggestion addresses a potential runtime error by adding a null check for `takerGets` before accessing its first element. This is crucial for preventing crashes if `takerGets` is undefined or empty.
    9
    Implement null checks before accessing object properties to prevent errors ___ **Use null checks for selectedEntityIdFrom and selectedEntityIdTo before using their
    properties to avoid potential null reference errors.** [client/src/ui/components/trading/TransferBetweenEntities.tsx [84-85]](https://github.com/BibliothecaDAO/eternum/pull/993/files#diff-5ce2f1e45fead506c5de11a56a5f1927ff1efbe1645641f5cf0fcb88094d64baR84-R85) ```diff -owner_entity_id: selectedEntityIdFrom?.entityId!, -recipient_entity_id: selectedEntityIdTo?.entityId!, +owner_entity_id: selectedEntityIdFrom ? selectedEntityIdFrom.entityId : undefined, +recipient_entity_id: selectedEntityIdTo ? selectedEntityIdTo.entityId : undefined, ```
    Suggestion importance[1-10]: 9 Why: This suggestion adds necessary null checks before accessing properties of `selectedEntityIdFrom` and `selectedEntityIdTo`, which helps prevent potential null reference errors and improves code safety.
    9
    Use optional chaining to handle potential undefined values safely ___ **Ensure consistent use of optional chaining for travelTime to prevent potential undefined
    errors, similar to other usages in the code.** [client/src/ui/components/resources/ResourceWeight.tsx [52]](https://github.com/BibliothecaDAO/eternum/pull/993/files#diff-cb1944e8fb6258c30583665a6237d4196296b5fe8e4fd798889097796753e0cfR52-R52) ```diff -{`${travelTime!} hrs`} +{`${travelTime ? `${travelTime} hrs` : 'N/A'}`} ```
    Suggestion importance[1-10]: 8 Why: This suggestion ensures consistent use of optional chaining for `travelTime`, which helps prevent potential undefined errors and improves code robustness.
    8
    Possible issue
    Remove redundant z-index from the CSS class list to avoid confusion and ensure correct styling ___ **The z-index of Listbox.Options is set to both z-50 and z-100 which is likely a mistake as
    only one z-index value can be applied at a time. Consider removing the redundant z-index
    to avoid confusion and ensure the CSS behaves as expected.** [client/src/ui/elements/ListSelect.tsx [76]](https://github.com/BibliothecaDAO/eternum/pull/993/files#diff-f5c0bdecb0ad9b6ec67a48dba52979ef620c3d90a6e55d9b38f569cf41730f57R76-R76) ```diff -"z-50 mt-3 w-full rounded-md py-1 h-72 overflow-scroll z-100 border border-gold/10" +"z-50 mt-3 w-full rounded-md py-1 h-72 overflow-scroll border border-gold/10" ```
    Suggestion importance[1-10]: 9 Why: The suggestion correctly identifies a redundancy in the CSS class list that could lead to confusion or unexpected behavior. Removing the redundant z-index improves code clarity and maintainability.
    9
    Verify and adjust the border color opacity to ensure it meets the design requirements ___ **The border color opacity has been changed from border-gold to border-gold/10. If this
    change was intended to reduce the visibility of the border, it's fine. However, if the
    change was accidental, consider reverting it to maintain the original appearance.** [client/src/ui/elements/NumberInput.tsx [21]](https://github.com/BibliothecaDAO/eternum/pull/993/files#diff-dcfea276430231a9d63af9a1ab38e9d6164a68bd71147a665e7f7c1c3f591a55R21-R21) ```diff -className="flex items-center justify-center h-full px-1 border-r cursor-pointer border-gold/10 hover:bg-gold/30 " +className="flex items-center justify-center h-full px-1 border-r cursor-pointer border-gold hover:bg-gold/30 " ```
    Suggestion importance[1-10]: 7 Why: The suggestion is valid as it prompts verification of a potentially unintended change in border color opacity, which could affect the visual design. However, it is a minor issue.
    7
    Maintainability
    Remove or properly handle the commented-out SVG to clean up the code ___ **The SVG element is commented out but still partially present in the code. If the SVG is
    not needed, consider removing the entire SVG block to clean up the code. If it is
    temporarily disabled, ensure that it is properly documented or handled.** [client/src/ui/elements/ListSelect.tsx [60-72]](https://github.com/BibliothecaDAO/eternum/pull/993/files#diff-f5c0bdecb0ad9b6ec67a48dba52979ef620c3d90a6e55d9b38f569cf41730f57R60-R72) ```diff -{/* */} +{/* SVG removed or properly handled */} ```
    Suggestion importance[1-10]: 8 Why: The suggestion addresses a maintainability issue by recommending the removal or proper handling of commented-out code, which helps keep the codebase clean and understandable.
    8
    Enhancement
    Explicitly set a default background color for inactive states in conditional styling ___ **The conditional styling for active items in Listbox.Option uses an empty string for
    inactive states, which might lead to unintended CSS results. Consider explicitly setting a
    default background color for better clarity and maintainability.** [client/src/ui/elements/ListSelect.tsx [85]](https://github.com/BibliothecaDAO/eternum/pull/993/files#diff-f5c0bdecb0ad9b6ec67a48dba52979ef620c3d90a6e55d9b38f569cf41730f57R85-R85) ```diff -active ? "bg-gold/10 text-white/90" : "" +active ? "bg-gold/10 text-white/90" : "bg-transparent" ```
    Suggestion importance[1-10]: 8 Why: The suggestion improves code clarity and maintainability by ensuring that inactive states have a defined background color, preventing potential unintended CSS results.
    8