Skip to content

Conversation

@alfetopito
Copy link
Collaborator

@alfetopito alfetopito commented Jul 21, 2025

Summary

Use localStorage to set a custom backend endpoint

To Test

  1. Pick the url endpoints you'd like to use and set them with:
  2. localStorage.setItem('orderBookUrls', JSON.stringify({ "1":"https://YOUR_HOST", "100":"https://YOUR_HOST" }))
  3. Refresh the page
  4. Check the network page
  • Requests should be sent to the respective endpoints set above, for the chains specified
  1. To clear it:
  2. localStorage.removeItem('orderBookUrls')
  3. Refresh the page
  • Usual URLs should be used instead

Summary by CodeRabbit

  • New Features

    • Order book URLs can now be loaded from either environment variables or browser localStorage, offering more flexibility in configuration.
  • Bug Fixes

    • Fixed a syntax error in the example environment variable in the documentation to ensure correct JSON formatting.
  • Documentation

    • Updated the README with a corrected example for environment variable configuration.

@alfetopito alfetopito self-assigned this Jul 21, 2025
@vercel
Copy link

vercel bot commented Jul 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
cosmos ❌ Failed (Inspect) Jul 21, 2025 3:17pm
cowfi ✅ Ready (Inspect) Visit Preview Jul 21, 2025 3:17pm
explorer-dev ✅ Ready (Inspect) Visit Preview Jul 21, 2025 3:17pm
sdk-tools ✅ Ready (Inspect) Visit Preview Jul 21, 2025 3:17pm
swap-dev ✅ Ready (Inspect) Visit Preview Jul 21, 2025 3:17pm
widget-configurator ✅ Ready (Inspect) Visit Preview Jul 21, 2025 3:17pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 21, 2025

Walkthrough

The changes introduce support for loading order book URLs from both environment variables and browser localStorage in two frontend modules. The README is updated to fix a JSON syntax error in an environment variable example. No exported or public entity declarations are altered.

Changes

File(s) Change Summary
README.md Fixed a missing closing curly brace in the REACT_APP_ORDER_BOOK_URLS JSON string example.
apps/cowswap-frontend/src/cowSdk.ts, apps/explorer/src/cowSdk.ts Updated logic to load order book URLs from environment variables or localStorage, with fallback and comments added.

Estimated code review effort

2 (~15 minutes)

Poem

A curly brace once lost, now found,
Order book URLs can now abound!
From env or storage, they appear—
The source is flexible, the logic clear.
With every hop and every bound,
This rabbit’s code is safe and sound! 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

yarn install v1.22.22
[1/4] Resolving packages...
(node:12916) [DEP0169] DeprecationWarning: url.parse() behavior is not standardized and prone to errors that have security implications. Use the WHATWG URL API instead. CVEs are not issued for url.parse() vulnerabilities.
(Use node --trace-deprecation ... to show where the warning was created)
[2/4] Fetching packages...
error nx@21.0.3: The engine "node" is incompatible with this module. Expected version "^20.19.0 || ^22.12.0". Got "24.3.0"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

✨ 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.

@alfetopito
Copy link
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 21, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@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: 3

🧹 Nitpick comments (1)
apps/cowswap-frontend/src/cowSdk.ts (1)

16-16: Consider reducing console logging verbosity in production.

The console logging is helpful for development but may be too verbose for production environments. Consider using a debug flag or logging level.

Example approach:

-console.log('Order Book URLs:', prodBaseUrls, !!envBaseUrls, !!localStorageBaseUrls)
+if (process.env.NODE_ENV === 'development') {
+  console.log('Order Book URLs:', prodBaseUrls, !!envBaseUrls, !!localStorageBaseUrls)
+}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b142199 and e70794b.

📒 Files selected for processing (3)
  • README.md (1 hunks)
  • apps/cowswap-frontend/src/cowSdk.ts (1 hunks)
  • apps/explorer/src/cowSdk.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
apps/cowswap-frontend/src/cowSdk.ts (1)

Learnt from: shoom3301
PR: #5443
File: apps/cowswap-frontend/src/modules/swap/containers/ConfirmSwapModalSetup/index.tsx:71-71
Timestamp: 2025-02-20T15:59:33.749Z
Learning: The swap module in apps/cowswap-frontend/src/modules/swap/ is marked for deletion in PR #5444 as part of the swap widget unification effort.

🔇 Additional comments (2)
README.md (1)

201-201: LGTM! Documentation bug fix.

The missing closing curly brace in the JSON example has been corrected, ensuring the environment variable example is syntactically valid and consistent with the parsing logic in the codebase.

apps/cowswap-frontend/src/cowSdk.ts (1)

7-10: Excellent developer guidance!

The comments providing clear instructions for manually setting and clearing localStorage URLs are very helpful for developers and testers.

Comment on lines +5 to +14
const envBaseUrls = process.env.REACT_APP_ORDER_BOOK_URLS && JSON.parse(process.env.REACT_APP_ORDER_BOOK_URLS)

// To manually set the order book URLs in localStorage, you can use the following command in the browser console:
// localStorage.setItem('orderBookUrls', JSON.stringify({ "1":"https://YOUR_HOST", "100":"https://YOUR_HOST" }))
// To clear it, simply run:
// localStorage.removeItem('orderBookUrls')
const localStorageBaseUrls =
localStorage.getItem('orderBookUrls') && JSON.parse(localStorage.getItem('orderBookUrls') || '{}')

const prodBaseUrls = envBaseUrls || localStorageBaseUrls || undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling for JSON parsing operations.

Similar to the explorer implementation, this code lacks error handling for malformed JSON, which could cause application crashes.

Apply this diff to add proper error handling:

-const envBaseUrls = process.env.REACT_APP_ORDER_BOOK_URLS && JSON.parse(process.env.REACT_APP_ORDER_BOOK_URLS)
+const envBaseUrls = (() => {
+  try {
+    return process.env.REACT_APP_ORDER_BOOK_URLS && JSON.parse(process.env.REACT_APP_ORDER_BOOK_URLS)
+  } catch (error) {
+    console.warn('Failed to parse REACT_APP_ORDER_BOOK_URLS:', error)
+    return undefined
+  }
+})()

-const localStorageBaseUrls =
-  localStorage.getItem('orderBookUrls') && JSON.parse(localStorage.getItem('orderBookUrls') || '{}')
+const localStorageBaseUrls = (() => {
+  try {
+    const stored = localStorage.getItem('orderBookUrls')
+    return stored && JSON.parse(stored)
+  } catch (error) {
+    console.warn('Failed to parse orderBookUrls from localStorage:', error)
+    return undefined
+  }
+})()
📝 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 envBaseUrls = process.env.REACT_APP_ORDER_BOOK_URLS && JSON.parse(process.env.REACT_APP_ORDER_BOOK_URLS)
// To manually set the order book URLs in localStorage, you can use the following command in the browser console:
// localStorage.setItem('orderBookUrls', JSON.stringify({ "1":"https://YOUR_HOST", "100":"https://YOUR_HOST" }))
// To clear it, simply run:
// localStorage.removeItem('orderBookUrls')
const localStorageBaseUrls =
localStorage.getItem('orderBookUrls') && JSON.parse(localStorage.getItem('orderBookUrls') || '{}')
const prodBaseUrls = envBaseUrls || localStorageBaseUrls || undefined
const envBaseUrls = (() => {
try {
return process.env.REACT_APP_ORDER_BOOK_URLS && JSON.parse(process.env.REACT_APP_ORDER_BOOK_URLS)
} catch (error) {
console.warn('Failed to parse REACT_APP_ORDER_BOOK_URLS:', error)
return undefined
}
})()
// To manually set the order book URLs in localStorage, you can use the following command in the browser console:
// localStorage.setItem('orderBookUrls', JSON.stringify({ "1":"https://YOUR_HOST", "100":"https://YOUR_HOST" }))
// To clear it, simply run:
// localStorage.removeItem('orderBookUrls')
const localStorageBaseUrls = (() => {
try {
const stored = localStorage.getItem('orderBookUrls')
return stored && JSON.parse(stored)
} catch (error) {
console.warn('Failed to parse orderBookUrls from localStorage:', error)
return undefined
}
})()
const prodBaseUrls = envBaseUrls || localStorageBaseUrls || undefined
🤖 Prompt for AI Agents
In apps/cowswap-frontend/src/cowSdk.ts around lines 5 to 14, the JSON.parse
calls for environment and localStorage values lack error handling, risking
crashes on malformed JSON. Wrap each JSON.parse call in try-catch blocks to
safely handle parsing errors, and fallback to undefined or an empty object if
parsing fails, ensuring the app remains stable.

const prodBaseUrls = process.env.REACT_APP_ORDER_BOOK_URLS
? JSON.parse(process.env.REACT_APP_ORDER_BOOK_URLS)
: undefined
// TODO: why is this duplicated? Can this be shared with the instance from CoW Swap?
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Address the code duplication concern.

The TODO comment correctly identifies code duplication with the cowswap-frontend implementation. Consider extracting this logic into a shared utility function to maintain consistency and reduce maintenance overhead.

Example approach:

// In a shared utilities file
export function getOrderBookUrls() {
  const envBaseUrls = process.env.REACT_APP_ORDER_BOOK_URLS && JSON.parse(process.env.REACT_APP_ORDER_BOOK_URLS)
  const localStorageBaseUrls = 
    localStorage.getItem('orderBookUrls') && JSON.parse(localStorage.getItem('orderBookUrls') || '{}')
  return envBaseUrls || localStorageBaseUrls || undefined
}
🤖 Prompt for AI Agents
In apps/explorer/src/cowSdk.ts at line 6, there is duplicated logic for
obtaining order book URLs that also exists in the cowswap-frontend codebase. To
fix this, extract this logic into a shared utility function in a common
utilities file that both projects can import. This function should handle
reading from environment variables and local storage as needed, returning the
URLs or undefined. Replace the duplicated code in cowSdk.ts with a call to this
shared utility to ensure consistency and reduce maintenance overhead.

Comment on lines +8 to +12
const envBaseUrls = process.env.REACT_APP_ORDER_BOOK_URLS && JSON.parse(process.env.REACT_APP_ORDER_BOOK_URLS)
const localStorageBaseUrls =
localStorage.getItem('orderBookUrls') && JSON.parse(localStorage.getItem('orderBookUrls') || '{}')

const prodBaseUrls = envBaseUrls || localStorageBaseUrls || undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling for JSON parsing operations.

The current implementation lacks error handling for malformed JSON in both environment variables and localStorage. This could cause the application to crash if invalid JSON is provided.

Apply this diff to add proper error handling:

-const envBaseUrls = process.env.REACT_APP_ORDER_BOOK_URLS && JSON.parse(process.env.REACT_APP_ORDER_BOOK_URLS)
-const localStorageBaseUrls =
-  localStorage.getItem('orderBookUrls') && JSON.parse(localStorage.getItem('orderBookUrls') || '{}')
+const envBaseUrls = (() => {
+  try {
+    return process.env.REACT_APP_ORDER_BOOK_URLS && JSON.parse(process.env.REACT_APP_ORDER_BOOK_URLS)
+  } catch (error) {
+    console.warn('Failed to parse REACT_APP_ORDER_BOOK_URLS:', error)
+    return undefined
+  }
+})()
+
+const localStorageBaseUrls = (() => {
+  try {
+    const stored = localStorage.getItem('orderBookUrls')
+    return stored && JSON.parse(stored)
+  } catch (error) {
+    console.warn('Failed to parse orderBookUrls from localStorage:', error)
+    return undefined
+  }
+})()
📝 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 envBaseUrls = process.env.REACT_APP_ORDER_BOOK_URLS && JSON.parse(process.env.REACT_APP_ORDER_BOOK_URLS)
const localStorageBaseUrls =
localStorage.getItem('orderBookUrls') && JSON.parse(localStorage.getItem('orderBookUrls') || '{}')
const prodBaseUrls = envBaseUrls || localStorageBaseUrls || undefined
const envBaseUrls = (() => {
try {
return process.env.REACT_APP_ORDER_BOOK_URLS && JSON.parse(process.env.REACT_APP_ORDER_BOOK_URLS)
} catch (error) {
console.warn('Failed to parse REACT_APP_ORDER_BOOK_URLS:', error)
return undefined
}
})()
const localStorageBaseUrls = (() => {
try {
const stored = localStorage.getItem('orderBookUrls')
return stored && JSON.parse(stored)
} catch (error) {
console.warn('Failed to parse orderBookUrls from localStorage:', error)
return undefined
}
})()
const prodBaseUrls = envBaseUrls || localStorageBaseUrls || undefined
🤖 Prompt for AI Agents
In apps/explorer/src/cowSdk.ts around lines 8 to 12, the JSON.parse calls for
environment variables and localStorage lack error handling, risking crashes on
malformed JSON. Wrap each JSON.parse operation in try-catch blocks to safely
handle parsing errors. If parsing fails, log the error and fallback to undefined
or an empty object as appropriate to prevent the application from crashing.

@alfetopito
Copy link
Collaborator Author

@MartinquaXD let me know whether this is useful

@shoom3301 shoom3301 closed this Nov 25, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Nov 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants