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

add stats resources bridged on empire #2618

Merged
merged 3 commits into from
Dec 28, 2024
Merged

add stats resources bridged on empire #2618

merged 3 commits into from
Dec 28, 2024

Conversation

aymericdelab
Copy link
Collaborator

@aymericdelab aymericdelab commented Dec 28, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a new Bridged Resources component to display and manage resource information
    • Implemented sorting functionality for resources by total supply and balance
    • Integrated copy-to-clipboard feature for contract addresses
  • Improvements

    • Enhanced resource data fetching with error handling
    • Updated resource addresses utility to improve module accessibility
  • UI Changes

    • Integrated Bridged Resources component into the main application grid layout

Copy link

vercel bot commented Dec 28, 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 28, 2024 1:05pm
eternum-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 28, 2024 1:05pm
eternum-landing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 28, 2024 1:05pm

Copy link
Contributor

coderabbitai bot commented Dec 28, 2024

Walkthrough

The pull request introduces a new BridgedResources component to manage and display bridged resources in a React application. The changes include creating a new component in the bridged-resources.tsx file, modifying the utils.ts file to export the ResourceAddresses interface, and updating the index.lazy.tsx route to incorporate the new component into the application's grid layout. The implementation focuses on resource data fetching, sorting, and displaying individual resource details with error handling and user interaction capabilities.

Changes

File Change Summary
landing/src/components/modules/bridged-resources.tsx - Added BridgedResources component
- Added BridgeResource subcomponent
- Implemented sorting and data fetching functionality
landing/src/components/ui/utils/utils.ts - Changed ResourceAddresses interface to be publicly exported
landing/src/routes/index.lazy.tsx - Imported BridgedResources component
- Added new item to AnimatedGrid with BridgedResources

Sequence Diagram

sequenceDiagram
    participant User
    participant BridgedResources
    participant getSeasonAddresses
    participant SmartContract
    
    User->>BridgedResources: Render component
    BridgedResources->>getSeasonAddresses: Fetch resource addresses
    getSeasonAddresses-->>BridgedResources: Return addresses
    BridgedResources->>SmartContract: Fetch total supply and balance
    SmartContract-->>BridgedResources: Return resource data
    BridgedResources->>BridgedResources: Sort and display resources
Loading

Poem

🐰 Bridged Resources, a tale of might,
Sorting data with algorithmic delight!
Addresses fetched, balances clear,
A rabbit's code brings resources near.
Dancing through contracts with graceful ease,
Our UI now sparkles and aims to please! 🌟

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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: 1

🧹 Nitpick comments (6)
landing/src/components/modules/bridged-resources.tsx (6)

14-19: Potential data mismatch if resourceData remains empty.

The state initialization and usage are fine. However, consider a fallback UI or a clear message when resourceData is not yet populated, to provide user feedback while awaiting the data fetch.


24-26: Handle fetch failures gracefully.

If getSeasonAddresses() fails, consider logging the error via a user-facing alert or toast, not just the console. This helps the user understand why data may not load.


53-60: Toggle sort directions more explicitly.

Your toggle logic is correct. Alternatively, you might consider extracting your toggle logic into a small, reusable helper, which can simplify code if you plan to add more sort keys or complexities later.


63-104: Provide loading or empty states.

Rendering sortedResources.map(...) is correct. In case sortedResources is empty, consider providing a loading or empty state UI within the .divide-y container. This prevents a blank view from confusing users while data loads or if none is available.


107-117: Exporting subcomponent.

The BridgeResource subcomponent is well-scoped. If it’s only relevant to BridgedResources, consider either keeping it as an inline component or rename it to reflect it is a child within that module (e.g., BridgedResourceItem) to limit confusion.


172-176: Clipboard success feedback is good.

Your approach to setting a small timeout for the “copied” state is good UX. For maximum accessibility, consider also adding an ARIA alert or a short text message that a screen reader can announce.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2185bcb and 56b78df.

📒 Files selected for processing (3)
  • landing/src/components/modules/bridged-resources.tsx (1 hunks)
  • landing/src/components/ui/utils/utils.ts (1 hunks)
  • landing/src/routes/index.lazy.tsx (2 hunks)
🔇 Additional comments (6)
landing/src/routes/index.lazy.tsx (1)

131-138: Render new bridged resources in grid layout.

The addition of <BridgedResources /> to the AnimatedGrid items array is clear and straightforward. Ensure that there is proper loading state handling or fallback UI, if <BridgedResources /> requires a lengthy data fetch before rendering. Other than that, this integration looks good.

landing/src/components/modules/bridged-resources.tsx (4)

1-9: Validate dependencies and naming consistency.

These initial imports look consistent and meaningful. Make sure that all external hooks (useDojo, useAccount) are available at runtime and that "BridgedResources" naming is uniform across the codebase to avoid confusion.


28-38: Ensure updateResourceData concurrency safety.

Since you rely on the previous state with setResourceData, concurrency issues are unlikely in React’s standard model, but confirm no race conditions exist if multiple resources update simultaneously.


40-51: Double-check sorting logic.

The sorting approach is clear. However, confirm that mismatched resource data indices never cause sorting anomalies (e.g., if sortedResources adds new entries while resourceData is still partially filled). If that scenario is possible, you may need a synchronization step before sorting.


179-230: Visual consistency of resource item layout.

The markup is consistent. If you foresee expansions or additional functionality (e.g., bridging/unbridging resources), keep this layout flexible by using more modular subcomponents. Otherwise, it looks good.

landing/src/components/ui/utils/utils.ts (1)

439-439: Public interface for shared resource usage.

Exporting ResourceAddresses is a good move for reusability. Confirm that no naming conflict arises with similarly named types in other parts of the codebase.

Comment on lines +118 to +161
const {
network: { provider },
} = useDojo();
const { account } = useAccount();

const [amountBridged, setAmountBridged] = useState(0n);
const [playerBalance, setPlayerBalance] = useState(0n);
const [copied, setCopied] = useState(false);

useEffect(() => {
const fetchData = async () => {
try {
// Get total supply
const totalSupplyResult = await provider.provider.callContract({
contractAddress: contractAddress,
entrypoint: "total_supply",
});
const totalSupply = BigInt(totalSupplyResult[0]);
setAmountBridged(totalSupply);

// Get player balance
let balance = 0n;
if (account?.address) {
const balanceResult = await provider.provider.callContract({
contractAddress: contractAddress,
entrypoint: "balance_of",
calldata: [account.address],
});
balance = BigInt(balanceResult[0]);
setPlayerBalance(balance);
}

onDataUpdate(contractAddress, totalSupply, balance);
} catch (error) {
console.error("Error fetching data:", error);
setAmountBridged(0n);
setPlayerBalance(0n);
onDataUpdate(contractAddress, 0n, 0n);
}
};

fetchData();
}, [provider, contractAddress, account?.address, onDataUpdate]);

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Account for Stargate or RPC issues in data fetch.

The callContract logic is correct. For better user experience, consider concurrency handling (e.g., if multiple resources are fetched simultaneously) or repeated calls if the provider becomes momentarily unreachable. If the fetching process is large-scale, you may need batching for performance optimization.

@bob0005 bob0005 merged commit 0e289fe into next Dec 28, 2024
23 of 29 checks passed
@bob0005 bob0005 deleted the add-resources branch December 28, 2024 13:22
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.

2 participants