refactor: position page initial loading#126
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughThe changes update the loading state handling in the Positions components and refactor earnings calculations. The UI now distinguishes between positions and earnings loading states. Several hooks no longer use a custom hook ( Changes
Sequence Diagram(s)sequenceDiagram
participant C as Component (e.g., useUserPosition)
participant U as Utils (fetchPositionSnapshot)
participant A as API (Position Snapshot API)
C->>U: Call fetchPositionSnapshot(marketId, userAddress, chainId, blockNumber)
U->>A: Send GET request for snapshot data
A-->>U: Return snapshot response
U-->>C: Return processed position snapshot (or null)
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/hooks/useUserPositionsSummaryData.ts (1)
113-148: Sequential updates may affect performance
Processing positions in a for-loop is more granular but might slow down overall loading. Consider parallel computation if real-time partial updates are not critical.src/utils/positions.ts (1)
223-312: Grouping by loan assets
Combines positions properly. Might consider using BigInt consistently for supply comparisons.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
app/positions/components/PositionsContent.tsx(3 hunks)app/positions/components/PositionsSummaryTable.tsx(6 hunks)src/hooks/usePositionReport.ts(1 hunks)src/hooks/usePositionSnapshot.ts(0 hunks)src/hooks/useUserPosition.ts(1 hunks)src/hooks/useUserPositions.ts(1 hunks)src/hooks/useUserPositionsSummaryData.ts(5 hunks)src/utils/positions.ts(1 hunks)
💤 Files with no reviewable changes (1)
- src/hooks/usePositionSnapshot.ts
🧰 Additional context used
🧬 Code Definitions (2)
src/hooks/useUserPositionsSummaryData.ts (1)
src/utils/positions.ts (1) (1)
initializePositionsWithEmptyEarnings(356-368)
app/positions/components/PositionsSummaryTable.tsx (2)
src/utils/positions.ts (3) (3)
groupPositionsByLoanAsset(230-312)processCollaterals(320-348)getGroupedEarnings(205-221)src/utils/balance.ts (1) (1)
formatBalance(21-23)
🔇 Additional comments (29)
app/positions/components/PositionsContent.tsx (3)
46-47: Good separation of loading statesSplitting the loading state into position-specific and earnings-specific states provides better granularity for UI feedback.
147-147: Updated conditional rendering with specific loading stateCorrectly updated the conditional rendering to use the more specific
isPositionsLoadingstate.
176-176: Added earnings loading state to child componentProperly passed the new earnings loading state to the table component.
src/hooks/useUserPositions.ts (1)
7-7: Direct import of utility functionRemoving the hook dependency in favor of a direct utility import simplifies the code structure.
src/hooks/usePositionReport.ts (1)
7-7: Simplified import patternReplaced hook usage with direct function import, keeping consistent with the refactoring pattern.
src/hooks/useUserPosition.ts (1)
5-5: Direct utility function importConsistent with changes in other files - replaced hook with direct function import.
src/hooks/useUserPositionsSummaryData.ts (5)
4-7: Rebranded function usage is consistent
The aliasing ofcalculateEarningsFromPeriodtocalculateEarningsand usage ofinitializePositionsWithEmptyEarningslooks coherent and aligns with the rest of the code references.
42-46: Clear separation of loading states
Splitting position loading from earnings loading clarifies progress indicators and is easy to follow.
96-102: Immediate initialization for smoother UI
Initializing empty earnings allows the interface to show placeholders without blocking, which improves user experience.
104-105: Concise comment
The note "Calculate real earnings in the background" is self-explanatory and helpful.
161-162: Return statements look clean
ExportingisPositionsLoadingandisEarningsLoadingclarifies the hook’s API.app/positions/components/PositionsSummaryTable.tsx (7)
9-9: Loader import is straightforward
UsingPulseLoaderfor indicating progress is fine.
17-22: Relevant imports
Bringing inEarningsPeriod, grouping, and processing functions is aligned with the updated logic.
45-45: Optional loading indicator
isLoadingEarnings?is a convenient flag to control UI feedback.
83-85: Grouping approach
groupPositionsByLoanAssetusage is direct and keeps the table logic tidy.
87-89: Collateral post-processing
processCollateralsis neatly applied to shape the data for display.
192-192: Centralized earnings retrieval
CallinggetGroupedEarningshere is concise and consistent.
231-235: Loader fallback
DisplayingPulseLoaderwhenisLoadingEarningsis true ensures immediate feedback for the user.src/utils/positions.ts (11)
1-3: General imports
No issues with importingAddressorformatBalance.
5-12: Types import
Bringing type definitions is consistent.
14-20: PositionSnapshot type
Straightforward structure, no concerns.
22-30: PositionResponse type
Fits well with the fetch logic.
32-83: Snapshot fetching
Basic error handling is in place. Consider handling timeouts or network errors more thoroughly if needed.
85-159: Earnings calculation
calculateEarningsFromPeriodleverages snapshots well. BigInt usage is valid.
161-169: Defined enum
EarningsPeriodis clear and easy to extend.
171-196: Simple period retrieval
getEarningsForPeriodis straightforward.
198-221: getGroupedEarnings
Aggregates position earnings elegantly.
314-348: Collateral processing
Sorting and consolidating the “others” category is tidy.
350-368: Initialization with empty earnings
Makes sense for immediate zero-state display.
Summary by CodeRabbit
New Features
Refactor