Skip to content

chore/tc-endpoints#628

Merged
ThomasRalee merged 2 commits intodevfrom
chore/tc-endpoints
Mar 23, 2026
Merged

chore/tc-endpoints#628
ThomasRalee merged 2 commits intodevfrom
chore/tc-endpoints

Conversation

@Frederick-88
Copy link
Copy Markdown
Collaborator

@Frederick-88 Frederick-88 commented Mar 23, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Order history now excludes booked orders from results, improving accuracy of displayed history.
  • Refactor

    • Improved type safety for derivative orders, trades, and positions to reduce data inconsistencies.
    • Standardized response ordering (pagination/summary fields appear earlier) for more consistent API responses.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b5d8e69a-49c3-497c-a983-7a167265937c

📥 Commits

Reviewing files that changed from the base of the PR and between 644dfb7 and c6906f2.

📒 Files selected for processing (1)
  • packages/sdk-ts/src/client/indexer/types/tc-derivatives.ts

📝 Walkthrough

Walkthrough

Replaced several untyped string fields with enum types in TC derivatives DTOs, added explicit casts in transformer methods, filtered out OrderState.Booked in orders history, reordered some returned fields, and adjusted one destructuring order in fetchOrdersHistory. No exported APIs/signatures changed.

Changes

Cohort / File(s) Summary
Type Definitions
packages/sdk-ts/src/client/indexer/types/tc-derivatives.ts
Replaced string-typed status/direction fields with enums: TradeDirection, OrderState, OrderSide, TradeExecutionSide, TradeExecutionType across DTOs (position deltas, order/history/trade/position/limit order types).
Transformers
packages/sdk-ts/src/client/indexer/transformers/IndexerGrpcTcDerivativesTransformer.ts
Added enum imports and explicit casts for direction/state/execution fields in mapping functions; ordersHistoryResponseToOrdersHistory filters out entries with OrderState.Booked; return objects reordered to surface next/total earlier.
API Client
packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcTcDerivativesApi.ts
Reordered destructuring of params in fetchOrdersHistory (token moved first). No other request/response logic changed.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I nibble at types, swapping strings for names,

Enums in my burrow now tidy the games.
I skip the booked orders with a polite little hop,
Rearranged the fields, then I fluffed every prop—
A rabbit-approved patch, and then off I zoom!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'chore/tc-endpoints' is vague and does not clearly describe the specific changes made in the pull request. Use a more descriptive title that explains the main change, such as 'Type enums for TC derivatives API responses' or 'Add explicit type casting for TC derivatives fields'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/tc-endpoints

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@packages/sdk-ts/src/client/indexer/transformers/IndexerGrpcTcDerivativesTransformer.ts`:
- Around line 156-164: filteredOrderHistory can be undefined if response.orders
is undefined, causing a TypeError when calling .map; change the logic so you
default to an empty array before filtering or mapping (e.g., set
filteredOrderHistory = response.orders?.filter(...) ?? [] or use
(filteredOrderHistory ?? []).map(...)) and then pass that safe array into
IndexerGrpcTcDerivativesTransformer.grpcOrderHistoryToOrderHistory to avoid
runtime errors.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6877b2a0-5ebe-4f75-9b7d-253a7c225f1e

📥 Commits

Reviewing files that changed from the base of the PR and between acab92c and 644dfb7.

📒 Files selected for processing (3)
  • packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcTcDerivativesApi.ts
  • packages/sdk-ts/src/client/indexer/transformers/IndexerGrpcTcDerivativesTransformer.ts
  • packages/sdk-ts/src/client/indexer/types/tc-derivatives.ts

Comment on lines +156 to 164
const filteredOrderHistory = response.orders?.filter(
(order) => order.state !== OrderState.Booked,
)

return {
orders: response.orders.map(
next: response.next,
orders: filteredOrderHistory.map(
IndexerGrpcTcDerivativesTransformer.grpcOrderHistoryToOrderHistory,
),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Potential runtime error: calling .map() on possibly undefined value.

If response.orders is undefined, the optional chaining on line 156 will return undefined, and calling .map() on line 162 will throw a TypeError.

🐛 Proposed fix using nullish coalescing
     const filteredOrderHistory = response.orders?.filter(
       (order) => order.state !== OrderState.Booked,
-    )
+    ) ?? []

     return {
       next: response.next,
       orders: filteredOrderHistory.map(
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const filteredOrderHistory = response.orders?.filter(
(order) => order.state !== OrderState.Booked,
)
return {
orders: response.orders.map(
next: response.next,
orders: filteredOrderHistory.map(
IndexerGrpcTcDerivativesTransformer.grpcOrderHistoryToOrderHistory,
),
const filteredOrderHistory = response.orders?.filter(
(order) => order.state !== OrderState.Booked,
) ?? []
return {
next: response.next,
orders: filteredOrderHistory.map(
IndexerGrpcTcDerivativesTransformer.grpcOrderHistoryToOrderHistory,
),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/sdk-ts/src/client/indexer/transformers/IndexerGrpcTcDerivativesTransformer.ts`
around lines 156 - 164, filteredOrderHistory can be undefined if response.orders
is undefined, causing a TypeError when calling .map; change the logic so you
default to an empty array before filtering or mapping (e.g., set
filteredOrderHistory = response.orders?.filter(...) ?? [] or use
(filteredOrderHistory ?? []).map(...)) and then pass that safe array into
IndexerGrpcTcDerivativesTransformer.grpcOrderHistoryToOrderHistory to avoid
runtime errors.

@ThomasRalee ThomasRalee merged commit bd3fc45 into dev Mar 23, 2026
5 checks passed
@ThomasRalee ThomasRalee deleted the chore/tc-endpoints branch March 23, 2026 13:56
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