Skip to content

Conversation

@citrusinesis
Copy link
Contributor

@citrusinesis citrusinesis commented Sep 22, 2025

Summary by CodeRabbit

  • New Features

    • Balance Sheet now reflects live on-chain data, showing dynamic SPOT/PERP positions with long/short indicators, color-coding, and percentages of total assets.
    • Displays USDC as “Available” or “To Be Allocated” to complete the portfolio view.
    • Provides sensible fallback data when live data isn’t available.
  • Improvements

    • More accurate portfolio totals and allocation percentages (sum to 100%).
    • Smoother loading/empty states for a clearer overview.

@vercel
Copy link

vercel bot commented Sep 22, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
crest-app Ready Ready Preview Comment Sep 22, 2025 3:51am

@coderabbitai
Copy link

coderabbitai bot commented Sep 22, 2025

Walkthrough

Replaces inline balance sheet constants with data from a new useBalanceSheet hook. Adds exports in hooks index. Introduces useBalanceSheet to read on-chain values via wagmi, compute percentages for SPOT/PERP/USDC, and return structured balanceData plus totals. Updates BalanceSheetSection to consume the hook-derived data.

Changes

Cohort / File(s) Change summary
Landing section uses hook-based data
packages/app/src/features/landing/sections/BalanceSheetSection.tsx
Removed local BALANCE_DATA constants; imported and used useBalanceSheet to obtain balanceData; updated chart cells and list rendering to reference hook data.
Hook exports wiring
packages/app/src/hooks/index.ts
Added public exports: useBalanceSheet and type BalanceData from ./useBalanceSheet; retained existing exports (e.g., WithdrawStatus).
New balance sheet hook
packages/app/src/hooks/useBalanceSheet.ts
Implemented useBalanceSheet using wagmi useReadContract calls to fetch total assets, positions, and core position value; computed normalized balanceData entries (SPOT/PERP/USDC) and exposed formatted totals and raw positions; exported interface BalanceData.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant BalanceSheetSection as BalanceSheetSection (UI)
  participant useBalanceSheet as useBalanceSheet (hook)
  participant wagmi as wagmi useReadContract
  participant Accountant as Crest.Accountant
  participant Manager as Crest.Manager

  User->>BalanceSheetSection: Open landing balance sheet
  BalanceSheetSection->>useBalanceSheet: invoke()
  rect #e8f5e9
    note right of useBalanceSheet: Fetch on-chain data
    useBalanceSheet->>wagmi: read getTotalAssets()
    wagmi->>Accountant: getTotalAssets
    Accountant-->>wagmi: totalAssets (bigint)
    wagmi-->>useBalanceSheet: totalAssets

    useBalanceSheet->>wagmi: read getPositions()
    wagmi->>Manager: getPositions
    Manager-->>wagmi: positions
    wagmi-->>useBalanceSheet: positions

    useBalanceSheet->>wagmi: read estimatePositionValue()
    wagmi->>Manager: estimatePositionValue
    Manager-->>wagmi: value (bigint)
    wagmi-->>useBalanceSheet: corePositionValue
  end

  note over useBalanceSheet: Format values, compute SPOT/PERP/USDC percentages
  useBalanceSheet-->>BalanceSheetSection: { balanceData, totals, positions }
  BalanceSheetSection-->>User: Render pie chart & list from balanceData
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I nibble numbers, chart the night,
SPOT and PERP in pastel light—
USDC crumbs tucked in a row,
A ledger burrowed soft below.
With hooks I hop from chain to sheet,
My balance pie is crisp and neat. 🥧🐇


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Free

📥 Commits

Reviewing files that changed from the base of the PR and between cb5d191 and 89031cb.

📒 Files selected for processing (3)
  • packages/app/src/features/landing/sections/BalanceSheetSection.tsx (3 hunks)
  • packages/app/src/hooks/index.ts (1 hunks)
  • packages/app/src/hooks/useBalanceSheet.ts (1 hunks)

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands and usage tips.

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