Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

refactor: migrate failover and request utils#554

Merged
cawabunga-bytes merged 1 commit into
betafrom
refactor/migrate-request
Jul 23, 2025
Merged

refactor: migrate failover and request utils#554
cawabunga-bytes merged 1 commit into
betafrom
refactor/migrate-request

Conversation

@jobotics

@jobotics jobotics commented Jul 22, 2025

Copy link
Copy Markdown
Collaborator

Depends on defuse-protocol/sdk-monorepo#41

Summary by CodeRabbit

  • Refactor

    • Updated internal dependencies to use shared utilities from an external package, improving maintainability and consistency.
  • Chores

    • Removed redundant internal utility files and related tests for HTTP requests, failover providers, and promise timeouts. No changes to user-facing features or behavior.

@jobotics
jobotics requested a review from cawabunga-bytes July 22, 2025 12:34
@coderabbitai

coderabbitai Bot commented Jul 22, 2025

Copy link
Copy Markdown

Walkthrough

This change removes local utility implementations for HTTP request handling, failover logic, and timeout management, and replaces their usage throughout the codebase with imports from the external @defuse-protocol/internal-utils package. Associated test files for the deleted utilities are also removed. No other logic or public API changes are introduced.

Changes

File(s) Change Summary
src/constants/nearClient.ts
src/queries/solverLiquidityQuerires.ts
src/sdk/hyperunit/apis.ts
src/sdk/hyperunit/types.ts
src/sdk/tokensUsdPricesHttpClient/apis.ts
src/sdk/tokensUsdPricesHttpClient/types.ts
Updated import sources for utility functions/types from local modules to @defuse-protocol/internal-utils.
src/utils/failover.ts
src/utils/promise/withTimeout.ts
src/utils/request.ts
Deleted utility files for failover provider creation, timeout wrapper, and HTTP request handling.
src/utils/failover.test.ts Deleted related unit test file for failover logic.

Estimated code review effort

2 (~15 minutes)

Poem

A bunny hops through fields of code,
Old helpers packed and off they go’d.
Now imports shine from a single source,
Utilities joined a common course.
With clutter gone and tests retired,
The rabbit’s code is newly wired!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (2)
src/queries/solverLiquidityQuerires.ts (1)

19-20: Remove the duplicate await.

A double-await is a no-op but adds noise and may mislead readers.

-  const response = await await request({
+  const response = await request({
src/sdk/hyperunit/apis.ts (1)

24-34: Consider surfacing non-2xx HTTP errors for better DX.

response.json() is invoked without checking response.ok. If @defuse-protocol/internal-utils/request no longer throws on non-2xx (unlike the old local helper), this will result in opaque runtime failures downstream.

   const response = await request({
     ...
   })

-  return response.json()
+  if (!response.ok) {
+    // propagate meaningful context to callers
+    throw new Error(
+      `generateHLAddress failed: ${response.status} ${response.statusText}`,
+    )
+  }
+  return response.json() as Promise<GeneratHLAddressResponse>
♻️ Duplicate comments (1)
src/sdk/hyperunit/types.ts (1)

3-6: See earlier note on RequestConfig duplication.

Same comment applies here; a shared source of truth would improve maintainability.

🧹 Nitpick comments (2)
src/queries/solverLiquidityQuerires.ts (1)

5-15: File name typo (*Querires*) propagates to importers.

The misspelling makes look-ups harder and may break editor tooling. Consider renaming to solverLiquidityQueries.ts.

src/sdk/tokensUsdPricesHttpClient/types.ts (1)

3-6: RequestConfig is duplicated across packages.

The same RequestConfig appears in multiple types.ts files. Consolidate it (e.g. export from @defuse-protocol/internal-utils) to avoid divergence.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 41e7079 and a727aed.

📒 Files selected for processing (10)
  • src/constants/nearClient.ts (1 hunks)
  • src/queries/solverLiquidityQuerires.ts (1 hunks)
  • src/sdk/hyperunit/apis.ts (1 hunks)
  • src/sdk/hyperunit/types.ts (1 hunks)
  • src/sdk/tokensUsdPricesHttpClient/apis.ts (1 hunks)
  • src/sdk/tokensUsdPricesHttpClient/types.ts (1 hunks)
  • src/utils/failover.test.ts (0 hunks)
  • src/utils/failover.ts (0 hunks)
  • src/utils/promise/withTimeout.ts (0 hunks)
  • src/utils/request.ts (0 hunks)
💤 Files with no reviewable changes (4)
  • src/utils/failover.test.ts
  • src/utils/promise/withTimeout.ts
  • src/utils/request.ts
  • src/utils/failover.ts
🔇 Additional comments (4)
src/queries/solverLiquidityQuerires.ts (1)

1-1: Import switch is correct.

Moving to the shared @defuse-protocol/internal-utils source is aligned with the refactor goals and keeps a single implementation of request.

src/constants/nearClient.ts (1)

1-16: LGTM – import aligns with new failover utility.

The switch cleans up local helpers and centralises fail-over logic.

src/sdk/tokensUsdPricesHttpClient/apis.ts (1)

8-15: Order of spreads enforces GET – intentional?

method: "GET" comes after spreading config?.fetchOptions, overriding any caller-supplied method. Confirm this is desired; otherwise reverse the order.

-    fetchOptions: {
-      ...config?.fetchOptions,
-      method: "GET",
-    },
+    fetchOptions: {
+      method: "GET",
+      ...config?.fetchOptions,
+    },
src/sdk/hyperunit/apis.ts (1)

1-1: Externalising request introduces version-coupling risk—pin dependency & align types.

Switching from a local helper to @defuse-protocol/internal-utils makes sdk transitively dependent on that package’s release cycle and type definitions.
Please verify:

  1. The package is already declared in package.json with an explicit, non-floating version to avoid accidental breaking upgrades.
  2. The exported signature of request is still Promise<Response> (or throws) so the subsequent response.json() call remains type-sound.

@cawabunga-bytes
cawabunga-bytes merged commit 9c6b917 into beta Jul 23, 2025
2 of 3 checks passed
@cawabunga-bytes
cawabunga-bytes deleted the refactor/migrate-request branch July 23, 2025 12:40
cawabunga-bytes added a commit that referenced this pull request Jul 23, 2025
* beta:
  refactor: migrate failover and request utils (#554)
  refactor: migrate publishIntent(s) function (#552)
  refactor: migrate logger from internal-utils (#551)
  refactor: migrate poaBridge utils (#550)
  refactor: use toError and NEP-141 storage utils from internal-utils (#548)
cawabunga-bytes added a commit that referenced this pull request Jul 23, 2025
* beta:
  refactor: migrate runtime and waitForIntentSettlement utils (#553)
  refactor: migrate failover and request utils (#554)
  refactor: migrate publishIntent(s) function (#552)
  refactor: migrate logger from internal-utils (#551)
  refactor: migrate poaBridge utils (#550)
  refactor: use toError and NEP-141 storage utils from internal-utils (#548)
@amdefuse

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.0.0-beta.204 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants