Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/donkeys empty balance #2611

Merged
merged 6 commits into from
Dec 27, 2024
Merged

Fix/donkeys empty balance #2611

merged 6 commits into from
Dec 27, 2024

Conversation

bob0005
Copy link
Collaborator

@bob0005 bob0005 commented Dec 27, 2024

Summary by CodeRabbit

  • New Features
    • Enhanced filtering for donkey information to include only those with positive resource balances.
  • Improvements
    • Increased the interval for automatic data refetching related to donkey entities.
    • Streamlined logic for updating resource selections in the BridgeOutStep2 component.

bob0005 and others added 6 commits December 26, 2024 23:12
* Fix missing arrival when sending lords & donkeys (#2594)

* contracts: fix share points check

* contracts: fix share points check

* Add resource filter for contributions (#2596)

* Add resource filter for contributions

* Change % for specific resource contribution

* Fix missing donkeys in bridge step 2 (#2598)

* Fix missing donkeys in bridge step 2

* fix rerenders

* Remove filter

* Fix registration delay (#2602)

* Fix registration delay

* styling

* Open popup on load

* Add burned donkeys back (#2601)

---------

Co-authored-by: Credence <[email protected]>
Co-authored-by: Loaf <[email protected]>
* Fix missing arrival when sending lords & donkeys (#2594)

* contracts: fix share points check

* contracts: fix share points check

* Add resource filter for contributions (#2596)

* Add resource filter for contributions

* Change % for specific resource contribution

* Fix missing donkeys in bridge step 2 (#2598)

* Fix missing donkeys in bridge step 2

* fix rerenders

* Remove filter

* Fix registration delay (#2602)

* Fix registration delay

* styling

* Open popup on load

* Add burned donkeys back (#2601)

* im (#2604)

---------

Co-authored-by: Credence <[email protected]>
Co-authored-by: Loaf <[email protected]>
Copy link

vercel bot commented Dec 27, 2024

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 Dec 27, 2024 3:11pm
eternum-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 27, 2024 3:11pm
eternum-landing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 27, 2024 3:11pm

Copy link
Contributor

coderabbitai bot commented Dec 27, 2024

Walkthrough

The pull request introduces modifications to two files: bridge-out-step-2.tsx and useDonkeyArrivals.tsx. The changes primarily focus on refactoring the resource selection logic for donkeys and adjusting the data fetching strategy. The updateResourcesFromSelectedDonkeys function in the bridge component has been simplified by removing memoization, while the donkey arrivals hook has been updated to extend the refetch interval and filter donkey information based on resource balances.

Changes

File Change Summary
landing/src/components/modules/bridge-out-step-2.tsx Removed useMemo from updateResourcesFromSelectedDonkeys function, simplifying its definition and dependency management
landing/src/hooks/helpers/useDonkeyArrivals.tsx - Increased refetch interval from 10,000ms to 100,000ms
- Removed staleTime from donkey queries
- Added filter to only include donkeys with positive resource balances

Sequence Diagram

sequenceDiagram
    participant UI as Bridge Out UI
    participant Hook as useDonkeyArrivals
    participant Query as Donkey Queries

    UI->>Hook: Request donkey information
    Hook->>Query: Fetch donkey data
    Query-->>Hook: Return donkey data
    Hook->>Hook: Filter donkeys with positive balances
    Hook-->>UI: Provide filtered donkey info
Loading

Poem

🐰 Donkeys and resources dance,
Refactored code takes a new stance,
Memoization fades away,
Queries slow, but data's play,
A rabbit's code, both swift and bright! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Failed to generate code suggestions for PR

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
landing/src/hooks/helpers/useDonkeyArrivals.tsx (1)

Line range hint 97-104: Optimize the accumulator to avoid performance overhead from the spread operator.
Using the spread syntax within a reduce accumulator can incur O(n^2) complexity. Consider mutating the accumulator object directly or using other approaches (e.g., pushing or assigning values) to avoid repetitive copying.

- allResources.reduce(
-   (acc, r) => ({
-     ...acc,
-     [r.resourceId]: (acc[r.resourceId] || 0) + r.amount / RESOURCE_PRECISION,
-   }),
-   {},
- )
+ allResources.reduce((acc, r) => {
+   acc[r.resourceId] = (acc[r.resourceId] || 0) + r.amount / RESOURCE_PRECISION;
+   return acc;
+ }, {})
landing/src/components/modules/bridge-out-step-2.tsx (1)

89-105: Refactor from memoized to standard function.
Removing the memoization can simplify the code and keep logic consistent. However, if performance was a concern with frequent re-renders, it may be worth considering an alternative optimization strategy (e.g., useCallback) if the function is computationally heavy or triggered frequently.

🧰 Tools
🪛 Biome (1.9.4)

[error] 99-99: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c9c9e41 and b479670.

📒 Files selected for processing (2)
  • landing/src/components/modules/bridge-out-step-2.tsx (2 hunks)
  • landing/src/hooks/helpers/useDonkeyArrivals.tsx (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
landing/src/components/modules/bridge-out-step-2.tsx

[error] 99-99: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)

🔇 Additional comments (3)
landing/src/hooks/helpers/useDonkeyArrivals.tsx (2)

37-37: Consider the increased refetch interval carefully.
Increasing the refetchInterval to 100,000 ms (from the previous 10,000 ms) will decrease the frequency of updates, potentially delaying the latest donkey information. Ensure that this aligns with the desired user experience.


112-114: Confirm filtering logic for resource balances.
Filtering out donkey entries with zero balances is logical. Ensure that any donkey intended to be displayed, even if it lacks resources, is handled as desired outside this function. If zero-balance donkeys need display for user awareness, consider including them or surfacing a reason for their omission.

landing/src/components/modules/bridge-out-step-2.tsx (1)

115-115: Consider re-adding dependencies if needed.
Not re-running this effect when selectedDonkeys changes could allow for stale data in scenarios where donkey arrivals or states change. Verify whether this new behavior accurately reflects your intended logic.

@aymericdelab aymericdelab merged commit 2185bcb into next Dec 27, 2024
23 of 29 checks passed
@aymericdelab aymericdelab deleted the fix/donkeys-empty-balance branch December 27, 2024 22:31
aymericdelab added a commit that referenced this pull request Dec 28, 2024
* Fix/donkeys empty balance (#2611)

* Merge into main (#2603)

* Fix missing arrival when sending lords & donkeys (#2594)

* contracts: fix share points check

* contracts: fix share points check

* Add resource filter for contributions (#2596)

* Add resource filter for contributions

* Change % for specific resource contribution

* Fix missing donkeys in bridge step 2 (#2598)

* Fix missing donkeys in bridge step 2

* fix rerenders

* Remove filter

* Fix registration delay (#2602)

* Fix registration delay

* styling

* Open popup on load

* Add burned donkeys back (#2601)

---------

Co-authored-by: Credence <[email protected]>
Co-authored-by: Loaf <[email protected]>

* merge into main (#2605)

* Fix missing arrival when sending lords & donkeys (#2594)

* contracts: fix share points check

* contracts: fix share points check

* Add resource filter for contributions (#2596)

* Add resource filter for contributions

* Change % for specific resource contribution

* Fix missing donkeys in bridge step 2 (#2598)

* Fix missing donkeys in bridge step 2

* fix rerenders

* Remove filter

* Fix registration delay (#2602)

* Fix registration delay

* styling

* Open popup on load

* Add burned donkeys back (#2601)

* im (#2604)

---------

Co-authored-by: Credence <[email protected]>
Co-authored-by: Loaf <[email protected]>

* Fix build (#2610)

* filter out donkeys w/ empty balance

---------

Co-authored-by: Credence <[email protected]>
Co-authored-by: Loaf <[email protected]>

* add stats resources bridged on empire (#2618)

* add resourcers bridged

* change logo

* remove looping gql calls (#2620)

* remove looping gql calls

* batch queries

---------

Co-authored-by: Credence <[email protected]>
Co-authored-by: Loaf <[email protected]>
Co-authored-by: raschel <[email protected]>
aymericdelab added a commit that referenced this pull request Jan 6, 2025
* Fix/donkeys empty balance (#2611)

* Merge into main (#2603)

* Fix missing arrival when sending lords & donkeys (#2594)

* contracts: fix share points check

* contracts: fix share points check

* Add resource filter for contributions (#2596)

* Add resource filter for contributions

* Change % for specific resource contribution

* Fix missing donkeys in bridge step 2 (#2598)

* Fix missing donkeys in bridge step 2

* fix rerenders

* Remove filter

* Fix registration delay (#2602)

* Fix registration delay

* styling

* Open popup on load

* Add burned donkeys back (#2601)

---------




* merge into main (#2605)

* Fix missing arrival when sending lords & donkeys (#2594)

* contracts: fix share points check

* contracts: fix share points check

* Add resource filter for contributions (#2596)

* Add resource filter for contributions

* Change % for specific resource contribution

* Fix missing donkeys in bridge step 2 (#2598)

* Fix missing donkeys in bridge step 2

* fix rerenders

* Remove filter

* Fix registration delay (#2602)

* Fix registration delay

* styling

* Open popup on load

* Add burned donkeys back (#2601)

* im (#2604)

---------




* Fix build (#2610)

* filter out donkeys w/ empty balance

---------




* add stats resources bridged on empire (#2618)

* add resourcers bridged

* change logo

* remove looping gql calls (#2620)

* remove looping gql calls

* batch queries

---------

Co-authored-by: Loaf <[email protected]>
Co-authored-by: Bob <[email protected]>
Co-authored-by: Credence <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants