Skip to content

fix: history length#271

Merged
antoncoding merged 4 commits intomasterfrom
fix/history-length
Dec 30, 2025
Merged

fix: history length#271
antoncoding merged 4 commits intomasterfrom
fix/history-length

Conversation

@antoncoding
Copy link
Copy Markdown
Owner

@antoncoding antoncoding commented Dec 30, 2025

Summary by CodeRabbit

  • Improvements

    • Faster, more reliable transaction loading with a clarified single-chain fetch path and improved pagination for bulk queries.
    • History list UI polished: consistent badge-style market identity, streamlined dropdown/filter behavior, and clearer placeholder text.
  • Breaking Changes

    • History table no longer accepts pre-fetched positions — it fetches positions/markets internally.
    • Transaction preview now requires a chain selection; transaction queries operate per single chain.

✏️ Tip: You can customize this high-level summary in your review settings.

@antoncoding antoncoding added the bug Something isn't working label Dec 30, 2025
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Dec 30, 2025

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

Project Deployment Review Updated (UTC)
monarch Ready Ready Preview, Comment Dec 30, 2025 1:57am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Dec 30, 2025

📝 Walkthrough

Walkthrough

Refactors transaction fetching to operate on a single chainId (not multi-chain). fetchUserTransactions now validates a single chain, prefers Morpho API for that chain with a Subgraph fallback, and removes multi-network parallel aggregation and client-side cross-chain pagination.

Changes

Cohort / File(s) Summary
Core query logic
src/hooks/queries/fetchUserTransactions.ts
Switched from multi-chain aggregation to single-chainId input. TransactionFilters now includes chainId: number (removed chainIds). Validates single chain via isSupportedChain; attempts Morpho API first (if supported) then falls back to Subgraph. Removed per-network parallel fetching, combined sorting, and client-side cross-chain pagination.
Query hook & pagination
src/hooks/queries/useUserTransactionsQuery.ts
Adds pagination-aware path that can paginate per-chain; when paginate=true it runs per-chain paging (supports chainIds or chainId) and concatenates/sorts results; non-paginate mode requires a single chainId and delegates to fetchUserTransactions. Query key now includes filters.chainId and filter types updated (HookTransactionFilters).
Morpho data source
src/data-sources/morpho-api/transactions.ts
Simplified chain filter to use single-element array [filters.chainId]. Minor typing change: Record<string, any>Record<string, unknown>. Removed SupportedNetworks import.
History UI: table & preview
src/features/history/components/history-table.tsx
src/features/history/components/transaction-history-preview.tsx
src/features/history/history-view.tsx
HistoryTable prop positions removed; component now fetches positions/markets internally (useUserPositions, useProcessedMarkets). TransactionHistoryPreview requires chainId prop. HistoryView stops passing positions into HistoryTable. UI adjustments: consistent Badge mode for MarketIdentity, filter text/placeholder tweaks, and loading state aggregation.
Position report hook usage
src/hooks/usePositionReport.ts
Updated call to fetchUserTransactions to pass a scalar chainId (selectedAsset.chainId) instead of an array of chainIds.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant UI as Client (hook/component)
  participant Q as fetchUserTransactions
  participant Check as isSupportedChain
  participant Morpho as Morpho API
  participant Subgraph as Subgraph

  UI->>Q: call(filters with chainId)
  Q->>Check: isSupportedChain(chainId)
  alt chain unsupported
    Check-->>Q: false
    Q-->>UI: error ("unsupported chain")
  else chain supported
    Check-->>Q: true
    Q->>Morpho: attempt fetch (if Morpho supported)
    alt Morpho supported & success
      Morpho-->>Q: transactions
      Q-->>UI: return transactions
    else Morpho fails or not supported
      Morpho-->>Q: error / not available
      Q->>Subgraph: fetch transactions (single-chain path)
      alt Subgraph success
        Subgraph-->>Q: transactions
        Q-->>UI: return transactions
      else Subgraph error
        Subgraph-->>Q: error
        Q-->>UI: return error (fallback path)
      end
    end
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • refactor: useQuery #266 — modifies src/hooks/queries/fetchUserTransactions.ts transaction-filter behavior (directly related change in chain handling).
  • feat: morpho api backup #149 — updates Morpho-first / Subgraph-fallback transaction fetching flow (overlaps core control flow changes).
  • feat: fix history too long #103 — changes related hooks/components that migrate transaction/position fetching into internal hooks and update component signatures (connected UI/hook surface changes).

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'fix: history length' is too vague and doesn't clearly describe what was actually fixed. The PR makes major architectural changes (single-chain transaction fetching, pagination logic, API refactoring) but the title gives no hint of this scope. Use a more descriptive title that explains the main change, such as 'refactor: support single-chain transaction fetching with pagination' or 'fix: implement per-chain transaction pagination in history view'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/history-length

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/hooks/queries/fetchUserTransactions.ts (1)

118-123: Subgraph fallback ignores server-side pagination flag.

The Morpho API path respects useServerSidePagination (lines 85-96), but the subgraph fallback always uses skip: 0 regardless of the flag. This creates inconsistent behavior when the subgraph is used.

For consistency, consider applying the same pagination logic to subgraph requests.

📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eb3ea57 and 2a22bf5.

📒 Files selected for processing (2)
  • src/hooks/queries/fetchUserTransactions.ts
  • src/hooks/queries/useUserTransactionsQuery.ts
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2024-10-23T16:17:02.841Z
Learnt from: antoncoding
Repo: antoncoding/monarch PR: 77
File: src/graphql/queries.ts:168-193
Timestamp: 2024-10-23T16:17:02.841Z
Learning: In `src/graphql/queries.ts`, handling only `MarketTransferTransactionData` is intentional at this time.

Applied to files:

  • src/hooks/queries/fetchUserTransactions.ts
📚 Learning: 2025-12-09T10:06:39.848Z
Learnt from: antoncoding
Repo: antoncoding/monarch PR: 231
File: src/hooks/useDeployMorphoMarketV1Adapter.ts:3-3
Timestamp: 2025-12-09T10:06:39.848Z
Learning: In Wagmi v3, useConnection is the correct hook to obtain the connected wallet address, chainId, and connection status (isConnected). This replaces the useAccount hook from Wagmi v2. In your code under src/hooks, use: const { address, chainId, isConnected } = useConnection() from 'wagmi' to access the connected wallet information.

Applied to files:

  • src/hooks/queries/fetchUserTransactions.ts
  • src/hooks/queries/useUserTransactionsQuery.ts
🔇 Additional comments (5)
src/hooks/queries/useUserTransactionsQuery.ts (2)

50-50: Logic change looks reasonable.

Now respects filters.first when provided, falling back to pageSize if absent.


64-64: Server-side pagination flag set correctly.

The flag is appropriately enabled in pagination mode.

src/hooks/queries/fetchUserTransactions.ts (3)

17-22: Documentation added for the new flag.

The description clearly explains the intended behavior.


104-104: Using countTotal from Morpho response.

This propagates the server's total count, which is correct for single-network queries with server-side pagination. However, when combined with the multi-network issue flagged above, this count may be misleading.


176-180: Client-side pagination correctly skipped in server mode.

The conditional logic appropriately bypasses client-side slicing when server-side pagination is enabled.

Comment thread src/hooks/queries/fetchUserTransactions.ts Outdated
Copy link
Copy Markdown

@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

🧹 Nitpick comments (2)
src/features/history/components/transaction-history-preview.tsx (1)

157-158: Dead fallback code.

chainId is now required (non-optional), so the ?? allMarkets.find(...) fallback will never execute.

Suggested simplification
-              const chainIdForTx =
-                chainId ?? allMarkets.find((m) => m.uniqueKey === group.transactions[0].data.market.uniqueKey)?.morphoBlue.chain.id;
+              const chainIdForTx = chainId;
src/features/history/components/history-table.tsx (1)

85-86: Consider validating vaultAdapterChainId.

If chainId URL param is missing or non-numeric, Number(searchParams.get('chainId')) returns NaN or 0. The query won't run (guarded by Boolean(activeChainId)), but users get no feedback.

Optional: Add validation
-  const vaultAdapterChainId = isVaultAdapter ? Number(searchParams.get('chainId')) : null;
+  const vaultAdapterChainIdRaw = searchParams.get('chainId');
+  const vaultAdapterChainId = isVaultAdapter && vaultAdapterChainIdRaw 
+    ? Number(vaultAdapterChainIdRaw) 
+    : null;
+  const hasInvalidVaultChainId = isVaultAdapter && (!vaultAdapterChainId || Number.isNaN(vaultAdapterChainId));

Then show an error state when hasInvalidVaultChainId is true.

📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2a22bf5 and 59b7b38.

📒 Files selected for processing (7)
  • src/data-sources/morpho-api/transactions.ts
  • src/features/history/components/history-table.tsx
  • src/features/history/components/transaction-history-preview.tsx
  • src/features/history/history-view.tsx
  • src/hooks/queries/fetchUserTransactions.ts
  • src/hooks/queries/useUserTransactionsQuery.ts
  • src/hooks/usePositionReport.ts
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2024-10-23T16:17:02.841Z
Learnt from: antoncoding
Repo: antoncoding/monarch PR: 77
File: src/graphql/queries.ts:168-193
Timestamp: 2024-10-23T16:17:02.841Z
Learning: In `src/graphql/queries.ts`, handling only `MarketTransferTransactionData` is intentional at this time.

Applied to files:

  • src/data-sources/morpho-api/transactions.ts
  • src/hooks/queries/fetchUserTransactions.ts
  • src/hooks/usePositionReport.ts
  • src/hooks/queries/useUserTransactionsQuery.ts
  • src/features/history/components/history-table.tsx
📚 Learning: 2025-12-09T10:06:39.848Z
Learnt from: antoncoding
Repo: antoncoding/monarch PR: 231
File: src/hooks/useDeployMorphoMarketV1Adapter.ts:3-3
Timestamp: 2025-12-09T10:06:39.848Z
Learning: In Wagmi v3, useConnection is the correct hook to obtain the connected wallet address, chainId, and connection status (isConnected). This replaces the useAccount hook from Wagmi v2. In your code under src/hooks, use: const { address, chainId, isConnected } = useConnection() from 'wagmi' to access the connected wallet information.

Applied to files:

  • src/hooks/queries/fetchUserTransactions.ts
  • src/hooks/usePositionReport.ts
  • src/hooks/queries/useUserTransactionsQuery.ts
📚 Learning: 2024-11-25T09:39:42.148Z
Learnt from: antoncoding
Repo: antoncoding/monarch PR: 87
File: app/home/HomePage.tsx:17-39
Timestamp: 2024-11-25T09:39:42.148Z
Learning: In `app/home/HomePage.tsx`, the `useEffect` hook depends on `[showCustomized]` because changing `showCustomized` triggers updates to the yield and risk terms.

Applied to files:

  • src/features/history/components/history-table.tsx
📚 Learning: 2024-10-12T09:23:16.495Z
Learnt from: antoncoding
Repo: antoncoding/monarch PR: 63
File: app/markets/components/MarketRowDetail.tsx:49-52
Timestamp: 2024-10-12T09:23:16.495Z
Learning: When rendering oracle feeds in `ExpandedMarketDetail` (`app/markets/components/MarketRowDetail.tsx`), prefer explicit rendering over iterating keys when dealing with a small number of feeds.

Applied to files:

  • src/features/history/components/history-table.tsx
🧬 Code graph analysis (3)
src/hooks/queries/fetchUserTransactions.ts (4)
src/utils/networks.ts (1)
  • isSupportedChain (179-181)
src/config/dataSources.ts (1)
  • supportsMorphoApi (6-20)
src/data-sources/morpho-api/transactions.ts (1)
  • fetchMorphoTransactions (13-61)
src/data-sources/subgraph/transactions.ts (1)
  • fetchSubgraphTransactions (129-217)
src/hooks/queries/useUserTransactionsQuery.ts (3)
src/hooks/queries/fetchUserTransactions.ts (2)
  • TransactionFilters (11-21)
  • fetchUserTransactions (39-89)
src/utils/networks.ts (1)
  • ALL_SUPPORTED_NETWORKS (38-46)
src/utils/types.ts (1)
  • UserTransaction (37-49)
src/features/history/components/history-table.tsx (3)
src/hooks/useProcessedMarkets.ts (1)
  • useProcessedMarkets (27-91)
src/features/positions-report/components/asset-selector.tsx (1)
  • AssetKey (8-13)
src/hooks/queries/useUserTransactionsQuery.ts (1)
  • useUserTransactionsQuery (38-125)
🔇 Additional comments (10)
src/hooks/usePositionReport.ts (1)

85-93: LGTM!

Clean alignment with the new single-chain fetchUserTransactions API. The selectedAsset null check at line 49 ensures chainId is always defined here.

src/features/history/history-view.tsx (1)

19-22: LGTM!

Cleaner API. HistoryTable now owns its data fetching internally.

src/data-sources/morpho-api/transactions.ts (1)

15-18: LGTM!

Type narrowing from any to unknown is a nice improvement. Single chainId wrapped in array correctly matches the GraphQL chainId_in filter format.

src/features/history/components/transaction-history-preview.tsx (1)

21-21: LGTM!

Making chainId required aligns with the single-chain fetch model.

src/hooks/queries/useUserTransactionsQuery.ts (2)

58-107: LGTM!

Paginate mode now correctly fetches all pages per chain client-side before merging. This addresses the previous concern about server-side pagination breaking with multiple networks.


109-119: LGTM!

Clear enforcement of single-chain requirement for non-paginated queries with a helpful error message.

src/hooks/queries/fetchUserTransactions.ts (1)

39-89: LGTM!

Clean single-chain implementation with proper Morpho API → Subgraph fallback. Error handling is solid.

src/features/history/components/history-table.tsx (3)

73-76: LGTM!

Clean ownership shift - component now fetches its own position and market data.


107-127: LGTM!

Query setup is correct. The Boolean(activeChainId) guard in enabled prevents queries when chainId is invalid.


203-228: LGTM!

Clean URL parameter initialization with proper fallback to first available asset.

@antoncoding antoncoding merged commit bc7963c into master Dec 30, 2025
4 checks passed
@antoncoding antoncoding deleted the fix/history-length branch December 30, 2025 01:58
@coderabbitai coderabbitai Bot mentioned this pull request Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant