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

[client] show all my trades in history #2046

Merged
merged 1 commit into from
Nov 7, 2024
Merged

[client] show all my trades in history #2046

merged 1 commit into from
Nov 7, 2024

Conversation

aymericdelab
Copy link
Collaborator

@aymericdelab aymericdelab commented Nov 7, 2024

Fixes #2041

Summary by CodeRabbit

  • New Features

    • Enhanced the MarketTradingHistory component to accurately reflect trades involving the current user as both maker and taker.
  • Bug Fixes

    • Simplified rendering logic in the TradeHistoryEvent component by removing the conditional display of the Crown icon next to the taker name.

Copy link

vercel bot commented Nov 7, 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 Nov 7, 2024 3:10pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
eternum-landing ⬜️ Ignored (Inspect) Visit Preview Nov 7, 2024 3:10pm

Copy link
Contributor

mentatbot bot commented Nov 7, 2024

You are out of MentatBot reviews. Your usage will refresh November 11 at 08:00 AM.

Copy link
Contributor

coderabbitai bot commented Nov 7, 2024

Walkthrough

The pull request modifies the MarketTradingHistory and TradeHistoryEvent components. In MarketTradingHistory, logic is added to handle the makerOwner in the AcceptOrder event, allowing the component to identify trades involving the current user as either the maker or taker. In TradeHistoryEvent, the conditional rendering of the Crown icon next to the taker name is removed, simplifying the display. These changes enhance the accuracy of trade representation without altering the overall structure of the components.

Changes

File Path Change Summary
client/src/ui/components/trading/MarketTradingHistory.tsx Added logic to handle makerOwner in AcceptOrder event processing, modifying the isYours property to check both makerOwner and takerOwner.
client/src/ui/components/trading/TradeHistoryEvent.tsx Removed conditional rendering of the Crown icon next to the taker name, simplifying the display logic.

Assessment against linked issues

Objective Addressed Explanation
Show all trades in history (2041)

🐇 In the trading den, where bunnies play,
All my trades now come out to stay.
With makers and takers, I hop with glee,
My history's clear, just wait and see!
No crowns to distract, just trades so bright,
A joyful leap in the trading night! 🌙


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

github-actions bot commented Nov 7, 2024

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

🧹 Outside diff range and nitpick comments (4)
client/src/ui/components/trading/TradeHistoryEvent.tsx (2)

37-37: LGTM! Crown icon removal aligns with showing all trades.

The removal of the Crown icon is appropriate since trades will now be shown for both maker and taker roles.

Consider improving the trade direction display to be more explicit about the user's role. For example:

-      <div className={`text-sm my-auto flex flex-row items-center justify-start`}>{taker}</div>
+      <div className={`text-sm my-auto flex flex-row items-center justify-start`}>
+        {`${taker} ${trade.event.isYours ? '(You)' : ''}`}
+      </div>

Line range hint 38-45: Consider clarifying trade direction based on user's role.

The trade description always shows "bought" from taker's perspective, which might be confusing when viewing trades where the user was the maker.

Consider adjusting the trade description to be clearer:

       <div className="text-sm my-auto flex flex-row">
-        <div>{"bought"}</div>
+        <div>{trade.event.isYours ? (trade.event.takerId === currentUser ? "bought" : "sold") : "bought"}</div>
         <ResourceIcon resource={ResourcesIds[Number(trade.event.resourceTaken.resourceId)]} size={"sm"} />
         <div>{`${currencyIntlFormat(divideByPrecision(trade.event.resourceTaken.amount), 2)} for ${currencyIntlFormat(
           divideByPrecision(trade.event.resourceGiven.amount),
           2,
         )}`}</div>
         <ResourceIcon resource={ResourcesIds[Number(trade.event.resourceGiven.resourceId)]} size={"sm"} />
       </div>
client/src/ui/components/trading/MarketTradingHistory.tsx (2)

64-64: LGTM! Trade ownership check now includes both maker and taker roles.

The condition correctly identifies trades where the user is either the maker or taker, addressing the original issue of showing trades from only one side.

Consider extracting the ownership check into a more readable form:

-isYours: takerOwner.address === BigInt(address) || makerOwner.address === BigInt(address),
+isYours: [takerOwner.address, makerOwner.address].includes(BigInt(address)),

Line range hint 7-7: Consider pagination for improved scalability.

Now that the trade history includes both maker and taker trades, users might see up to twice as many trades. While the current MAX_TRADES limit of 100 helps manage performance, consider implementing pagination for better scalability and user experience.

Would you like me to propose a pagination implementation that maintains the current filtering capabilities?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2e7c57e and 87aa83e.

📒 Files selected for processing (2)
  • client/src/ui/components/trading/MarketTradingHistory.tsx (2 hunks)
  • client/src/ui/components/trading/TradeHistoryEvent.tsx (1 hunks)
🔇 Additional comments (2)
client/src/ui/components/trading/TradeHistoryEvent.tsx (1)

Line range hint 1-67: Verify the trade event interface implementation.

Let's check how the isYours property is implemented in MarketTradingHistory to ensure it correctly identifies both maker and taker roles.

client/src/ui/components/trading/MarketTradingHistory.tsx (1)

51-53: LGTM! Maker owner retrieval is properly implemented.

The addition of maker owner retrieval and validation follows the same pattern as the taker owner, ensuring consistent handling of both sides of trades.

Let's verify that the maker_id is always available in AcceptOrder events:

✅ Verification successful

Maker ID retrieval is properly implemented and verified

Based on the code analysis:

  1. The maker_id is a required field in the AcceptOrder props interface (from sdk/packages/eternum/src/types/provider.ts)
  2. The component properly retrieves both maker and taker owners using consistent patterns
  3. The implementation correctly handles the PR objective of showing both sides of trades
  4. The early return prevents undefined behavior when maker owner is not found

The verification confirms that:

  • The AcceptOrder event structure includes maker_id as shown in the SDK types
  • The component properly handles maker_id retrieval and validation
  • The implementation follows the same pattern as taker_id handling
  • The changes successfully fulfill the requirement to show all trades in history
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for AcceptOrder event definitions to confirm maker_id is a required field
ast-grep --pattern 'struct AcceptOrder {
  $$$
  maker_id: $_
  $$$
}'

Length of output: 72


Script:

#!/bin/bash
# Let's try different approaches to find AcceptOrder event structure
# 1. Search for AcceptOrder in typescript/solidity files
rg -t ts -t sol "AcceptOrder" -A 5 -B 5

# 2. Search for maker_id usage in the context of events
rg "maker_id.*event" -t ts

# 3. Look for the specific file where events are defined
fd "events?.ts" --type f

Length of output: 223


Script:

#!/bin/bash
# Let's check the content of the identified files and their imports
cat client/src/hooks/helpers/useBattleEvents.tsx
cat client/src/ui/components/trading/TradeHistoryEvent.tsx

# Also search for any type definitions related to AcceptOrder
rg -t ts "type.*AcceptOrder" -A 3
rg -t ts "interface.*AcceptOrder" -A 3

Length of output: 6426


Script:

#!/bin/bash
# Let's check the MarketTradingHistory.tsx file to understand the full context
cat client/src/ui/components/trading/MarketTradingHistory.tsx

# Also check for any event type definitions in the codebase
rg -t ts "AcceptOrder.*event" -B 3 -A 3

Length of output: 5317

@edisontim edisontim merged commit 93c3146 into next Nov 7, 2024
8 checks passed
@edisontim edisontim deleted the raschel/issue2041 branch November 7, 2024 15:23
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.

[client] show all my trades in history
2 participants