Skip to content

feat: Add 'Supply' Button to Position Page#77

Merged
antoncoding merged 4 commits intomasterfrom
feat/supply-positions
Oct 23, 2024
Merged

feat: Add 'Supply' Button to Position Page#77
antoncoding merged 4 commits intomasterfrom
feat/supply-positions

Conversation

@antoncoding
Copy link
Owner

@antoncoding antoncoding commented Oct 23, 2024

Improved Features, Enhanced and Simplified Components, Bug Fixes in State Management, URL Sync, Modal Logic, and Data Structures.

@vercel
Copy link
Contributor

vercel bot commented Oct 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
monarch ❌ Failed (Inspect) Oct 23, 2024 4:19pm

@coderabbitai
Copy link

coderabbitai bot commented Oct 23, 2024

Caution

Review failed

The head commit changed during the review from c8c870d to 9b30406.

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request includes updates to several components related to market and position management. Key changes involve modifying import paths, enhancing state management for modal visibility, and restructuring GraphQL queries. The Markets component now synchronizes state with URL parameters, while the Positions component distinguishes between supply and withdrawal modals. Additionally, new GraphQL fragments and queries are introduced to improve data retrieval for market positions, and type definitions are updated for clarity and maintainability.

Changes

File Path Change Summary
app/markets/components/markets.tsx Updated import path for SupplyModal. Enhanced state management for selected collaterals and loan assets, added URL synchronization, and modal handling.
app/positions/components/PositionsContent.tsx Added separate state for showSupplyModal and showWithdrawModal. Updated modal rendering logic and props for PositionsSummaryTable.
app/positions/components/PositionsSummaryTable.tsx Renamed PositionTableProps to PositionsSummaryTableProps. Updated modal visibility props and simplified refetch function signature.
app/positions/components/SuppliedMarketsDetail.tsx Updated modal visibility props and adjusted warning display logic. Added distinct buttons for supply and withdrawal actions.
src/graphql/queries.ts Introduced feedFieldsFragment, marketFragment, marketsQuery, and userPositionsQuery for structured data retrieval.
src/hooks/useMarkets.ts Imported marketsQuery and removed inline query definition. Updated fetchData for error handling and loading state management.
src/hooks/useUserPositions.ts Imported userPositionsQuery and removed inline query definition. Updated data structure to encapsulate warnings within market details.
src/utils/types.ts Simplified MarketPosition type by referencing a new Market type with expanded properties.

Possibly related PRs

🌟 In the world of code, where logic flows,
Modals now dance, as the state grows.
With fragments and queries, data's in sight,
Markets and positions, all shining bright!
So here's to the changes, both big and small,
A toast to the team, we’ve improved it all! 🎉


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.

@antoncoding antoncoding linked an issue Oct 23, 2024 that may be closed by this pull request
@antoncoding antoncoding changed the title feat: add supply button to position page feat: Add 'Supply' Button to Position Page Oct 23, 2024
Copy link

@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: 6

🧹 Outside diff range and nitpick comments (5)
src/utils/types.ts (1)

268-271: Add dailyApys documentation

Add JSDoc to explain APY calculation method and time window.

+  /** 
+   * Daily APY rates calculated over 24h period
+   * @property netSupplyApy - Net supply APY including rewards
+   * @property netBorrowApy - Net borrow APY including fees
+   */
   dailyApys: {
     netSupplyApy: number;
     netBorrowApy: number;
   };
app/positions/components/SuppliedMarketsDetail.tsx (1)

198-218: Consider extracting button styles

Both buttons share identical styles. Consider creating a shared style class or component.

+// Add to your CSS file or styled component
+.action-button {
+  @apply bg-hovered rounded-sm p-1 text-xs duration-300 ease-in-out hover:bg-orange-500;
+}

-className="bg-hovered rounded-sm p-1 text-xs duration-300 ease-in-out hover:bg-orange-500"
+className="action-button"
app/markets/components/markets.tsx (2)

Line range hint 64-65: Fix potential type safety issue with selectedMarket

The code assumes selectedMarket is defined when showing the modal, but the type allows undefined:

-const [selectedMarket, setSelectedMarket] = useState<Market | undefined>(undefined);
+const [selectedMarket, setSelectedMarket] = useState<Market | null>(null);

-{showSupplyModal && (
+{showSupplyModal && selectedMarket && (
   <SupplyModal
-    market={selectedMarket as Market}
+    market={selectedMarket}
     onClose={() => setShowSupplyModal(false)}
   />
 )}

Also applies to: 171-176


Line range hint 170-270: Add ARIA labels for better accessibility

Interactive elements need proper ARIA labels:

-<div className="container h-full gap-8" style={{ padding: '0 5%' }}>
+<div className="container h-full gap-8" style={{ padding: '0 5%' }} role="main">
-<h1 className="py-8 font-zen"> Markets </h1>
+<h1 className="py-8 font-zen" id="markets-heading"> Markets </h1>
src/graphql/queries.ts (1)

83-83: Reconsider the inclusion of __typename.

Remove __typename if it's not needed.

Also applies to: 140-140

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 22ebffa and 6460c44.

📒 Files selected for processing (8)
  • app/markets/components/markets.tsx (1 hunks)
  • app/positions/components/PositionsContent.tsx (3 hunks)
  • app/positions/components/PositionsSummaryTable.tsx (5 hunks)
  • app/positions/components/SuppliedMarketsDetail.tsx (4 hunks)
  • src/graphql/queries.ts (1 hunks)
  • src/hooks/useMarkets.ts (2 hunks)
  • src/hooks/useUserPositions.ts (4 hunks)
  • src/utils/types.ts (2 hunks)
🧰 Additional context used
🔇 Additional comments (20)
src/hooks/useUserPositions.ts (3)

4-4: LGTM! Good separation of concerns.

Moving the GraphQL query to a dedicated file improves maintainability.


80-85: Verify consumers of position data.

Market warnings moved to market.warningsWithDetail. Check if UI components handle this change.

#!/bin/bash
# Find components using position data
rg "warningsWithDetail" --type tsx

34-34: Verify query consistency across networks.

The same query is used for both networks. Let's verify the query definition.

Also applies to: 47-47

✅ Verification successful

The previous command had issues with file type recognition. Let's try a broader search to find both the query usage and its definition. The second command looks for GraphQL queries containing "position" in template literals.


Query is properly imported and used consistently

The query is imported from @/graphql/queries and used identically for both Mainnet and Base networks. The query definition in queries.ts fetches user market positions with the correct parameters (address and chainId).

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Find and display the query definition
rg -l "userPositionsQuery" --type ts

Length of output: 137


Script:

#!/bin/bash
# Let's try a more comprehensive search for the query
rg "userPositionsQuery" -A 5

# Also search for potential query definition
rg "gql`.*position.*`" --multiline

Length of output: 1723

app/positions/components/PositionsContent.tsx (3)

18-19: LGTM!

Clean separation of modal states improves code clarity.


54-73: LGTM!

Modal implementations are consistent and handle cleanup properly.


83-84: LGTM!

Props naming clearly reflects their purpose.

src/hooks/useMarkets.ts (1)

5-5: LGTM!

Moving the query to a separate file improves code organization.

src/utils/types.ts (2)

Line range hint 1-285: Types look good

Clean structure with logical grouping and consistent naming.


8-8: Check all MarketPosition usages

Type change from inline object to Market reference could break existing code.

✅ Verification successful

Based on the search results, I can see that the change from inline object to Market reference is being used consistently throughout the codebase. The market property is accessed in a type-safe manner across all files, with proper access to nested properties like:

  • market.loanAsset
  • market.collateralAsset
  • market.morphoBlue
  • market.uniqueKey
  • market.state
  • market.warningsWithDetail
  • etc.

No issues with Market type usage

The type change is properly integrated across all components and doesn't break existing code.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Find all files using MarketPosition type
rg -l "MarketPosition" 

# Find potential usage of old market property structure
rg "market\." -A 3 -B 3

Length of output: 64137

app/positions/components/SuppliedMarketsDetail.tsx (2)

14-15: Props update looks good

Clear prop names that match their purpose.


120-120: Warning handling update looks good

Consistent use of market-level warnings throughout the component.

Also applies to: 127-129

app/markets/components/markets.tsx (2)

Line range hint 149-164: LGTM! Clean filtering implementation

Good separation of concerns with filtering logic in utils.


Line range hint 134-148: Verify URL update behavior

Check if multiple rapid filter changes create separate history entries:

✅ Verification successful

Let me check for more context about the URL parameter handling.


Let me check one more thing about the router implementation.


URL updates look good, no history entry issues

The code uses a single router.push with scroll: false and maintains previous params state. No conflicting router calls or complex state updates found. The URL updates are straightforward and won't create unnecessary history entries.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Look for other router.push calls that might conflict
rg "router.push.*scroll.*false" -A 2

Length of output: 251


Script:

#!/bin/bash
# Look for URL parameter handling patterns
ast-grep --pattern 'const params = new URLSearchParams'

# Check for any debouncing or batching of URL updates
rg "useEffect.*params" -A 5

Length of output: 182


Script:

#!/bin/bash
# Check for router usage and any debouncing logic
rg "router\s*=\s*useRouter" -A 10
rg "useCallback.*router" -A 10

Length of output: 881

app/positions/components/PositionsSummaryTable.tsx (5)

19-24: LGTM: Clean type definitions and props structure.

The new props structure cleanly separates supply and withdraw modal controls.

Also applies to: 30-35


72-73: LGTM: Safe warning handling.

Good use of optional chaining to prevent undefined errors.


288-289: LGTM: Consistent modal props.

Modal controls are properly passed down to child components.


269-280: Verify CSS class usage.

Check if bg-hovered class is defined in your CSS system.

#!/bin/bash
# Search for bg-hovered class definition
rg 'bg-hovered'

80-80: Verify APY calculation change.

Changed from dailyApys.netSupplyApy to state.supplyApy. Please confirm this is intentional.

✅ Verification successful

Let me analyze the APY calculation changes with one more verification to understand the data flow.

This will help us understand if these are two different APY calculations or if one is derived from the other.


Let me try one more search with a simpler pattern to understand the APY types.


APY calculation change is intentional and correct

The change from dailyApys.netSupplyApy to state.supplyApy in weighted APY calculation is valid because:

  • state.supplyApy represents the base supply APY
  • dailyApys.netSupplyApy includes additional calculations for net returns
  • For weight calculations, using the base supplyApy is more appropriate
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other APY calculations to ensure consistency
rg -A 2 'supplyApy|netSupplyApy'

Length of output: 4048


Script:

#!/bin/bash
# Check the market state and daily APY types/interfaces
ast-grep --pattern 'interface $_ {
  $$$
  state: {
    $$$
    supplyApy: $_
    $$$
  }
  $$$
  dailyApys: {
    $$$
    netSupplyApy: $_
    $$$
  }
  $$$
}'

Length of output: 162


Script:

#!/bin/bash
# Look for interface or type definitions containing APY fields
ast-grep --pattern 'interface Market {
  $$$
}'

ast-grep --pattern 'type Market = {
  $$$
}'

Length of output: 3140

src/graphql/queries.ts (2)

150-150: Confirm if $chainId should be optional.

Check if making $chainId optional is intentional in the query.


159-159: Good use of the MarketFields fragment.

Reusing the fragment promotes consistency.

@antoncoding antoncoding merged commit 90e68bd into master Oct 23, 2024
@antoncoding antoncoding deleted the feat/supply-positions branch October 23, 2024 16:19
This was referenced Oct 24, 2024
This was referenced Dec 6, 2024
@coderabbitai coderabbitai bot mentioned this pull request Dec 17, 2024
@coderabbitai coderabbitai bot mentioned this pull request Jan 9, 2025
@coderabbitai coderabbitai bot mentioned this pull request Apr 27, 2025
@coderabbitai coderabbitai bot mentioned this pull request Aug 19, 2025
@coderabbitai coderabbitai bot mentioned this pull request Oct 13, 2025
@coderabbitai coderabbitai bot mentioned this pull request Nov 30, 2025
@coderabbitai coderabbitai bot mentioned this pull request Dec 8, 2025
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.

feat: Add a 'Supply' button next to 'Withdraw'

1 participant