-
Notifications
You must be signed in to change notification settings - Fork 160
[M2] feat(common-utils): add REACT_APP_BLOCK_EXPLORER_URL environment variable override #6774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
[M2] feat(common-utils): add REACT_APP_BLOCK_EXPLORER_URL environment variable override #6774
Conversation
|
@augustocollerone is attempting to deploy a commit to the cow Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughIntroduces an optional environment variable Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
|
I have read the CLA Document and I hereby sign the CLA |
There was a problem hiding this 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
🧹 Nitpick comments (1)
libs/common-utils/src/getExplorerLink.ts (1)
11-21: Well-documented environment variable.The JSDoc documentation clearly explains the override mechanism and provides a practical example.
Optional: Add trailing slash validation
While the documentation mentions the URL should not include a trailing slash, consider adding runtime validation to prevent potential issues with double slashes in generated URLs:
const BLOCK_EXPLORER_URL_OVERRIDE = process.env.REACT_APP_BLOCK_EXPLORER_URL?.replace(/\/$/, '')This would automatically strip any trailing slash if present.
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
apps/cowswap-frontend/.envapps/explorer/.env.examplelibs/common-utils/src/getExplorerLink.tslibs/common-utils/src/legacyAddressUtils.ts
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-12-03T19:23:35.789Z
Learnt from: kernelwhisperer
Repo: cowprotocol/cowswap PR: 6610
File: apps/cowswap-frontend/project.json:38-39
Timestamp: 2025-12-03T19:23:35.789Z
Learning: In the cowswap-frontend project configuration (apps/cowswap-frontend/project.json), the Vite dev server option `"host": true` is set to support Windows + WSL development environments, where binding to all network interfaces is required for the Windows host to access the dev server running in WSL.
Applied to files:
apps/cowswap-frontend/.env
🧬 Code graph analysis (2)
libs/common-utils/src/getExplorerLink.ts (2)
libs/common-const/src/chainInfo.ts (1)
CHAIN_INFO(74-141)libs/widget-lib/src/types.ts (1)
SupportedChainId(4-4)
libs/common-utils/src/legacyAddressUtils.ts (1)
libs/common-const/src/chainInfo.ts (1)
CHAIN_INFO(74-141)
🔇 Additional comments (4)
apps/explorer/.env.example (1)
25-33: LGTM! Clear and helpful documentation.The documentation clearly explains the block explorer override feature and provides a practical example for local development with Otterscan.
apps/cowswap-frontend/.env (1)
106-116: LGTM! Documentation is consistent across apps.The documentation matches the format and content in
apps/explorer/.env.example, ensuring consistency across the codebase.libs/common-utils/src/legacyAddressUtils.ts (1)
12-16: LGTM! Clear environment variable declaration.The constant is well-documented and clearly indicates its purpose for local development.
libs/common-utils/src/getExplorerLink.ts (1)
30-37: LGTM! Correct fallback priority order.The prefix resolution properly prioritizes the environment override, then the chain's default explorer, and finally the function parameter. This ensures known chains use their correct explorers while still allowing the override for local development.
| function getEtherscanUrl(chainId: SupportedChainId, data: string, type: BlockExplorerLinkType, base?: string): string { | ||
| const basePath = base || CHAIN_INFO[chainId]?.explorer | ||
| // Allow override via environment variable for local development (e.g., Otterscan) | ||
| const basePath = BLOCK_EXPLORER_URL_OVERRIDE || base || CHAIN_INFO[chainId]?.explorer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the fallback priority order.
The current fallback order OVERRIDE || base || CHAIN_INFO places the base parameter before the chain's default explorer, which is inconsistent with getExplorerLink.ts (line 37) and likely incorrect.
For known chains with entries in CHAIN_INFO, the chain's default explorer should take precedence over the generic base parameter. The base parameter should serve as a final fallback for unsupported chains, not override known chain explorers.
🔎 Proposed fix to align fallback priority
// Allow override via environment variable for local development (e.g., Otterscan)
- const basePath = BLOCK_EXPLORER_URL_OVERRIDE || base || CHAIN_INFO[chainId]?.explorer
+ const basePath = BLOCK_EXPLORER_URL_OVERRIDE || CHAIN_INFO[chainId]?.explorer || baseThis ensures:
- Environment override takes precedence (for local dev)
- Chain default is used for known chains
- Function parameter serves as final fallback for unknown chains
📝 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.
| function getEtherscanUrl(chainId: SupportedChainId, data: string, type: BlockExplorerLinkType, base?: string): string { | |
| const basePath = base || CHAIN_INFO[chainId]?.explorer | |
| // Allow override via environment variable for local development (e.g., Otterscan) | |
| const basePath = BLOCK_EXPLORER_URL_OVERRIDE || base || CHAIN_INFO[chainId]?.explorer | |
| function getEtherscanUrl(chainId: SupportedChainId, data: string, type: BlockExplorerLinkType, base?: string): string { | |
| // Allow override via environment variable for local development (e.g., Otterscan) | |
| const basePath = BLOCK_EXPLORER_URL_OVERRIDE || CHAIN_INFO[chainId]?.explorer || base |
🤖 Prompt for AI Agents
In libs/common-utils/src/legacyAddressUtils.ts around lines 77 to 79, the
fallback order for determining the explorer base is wrong: currently it uses
BLOCK_EXPLORER_URL_OVERRIDE || base || CHAIN_INFO[chainId]?.explorer but should
prefer the chain's configured explorer over the supplied base parameter. Change
the priority so it reads BLOCK_EXPLORER_URL_OVERRIDE ||
CHAIN_INFO[chainId]?.explorer || base, keeping the env override first, the chain
default second, and the function parameter as the final fallback.
Summary
This PR delivers part of Milestone 2: Frontend Integration of the CoW Grants Program RFP: CoW Protocol Playground Block Explorer Integration proposal by CoBuilders.
Adds environment variable support to override block explorer URLs in both CoW Swap and CoW Explorer frontends, enabling seamless integration with local block explorers like Otterscan.
Milestone 2 Deliverables
Frontend URL Override Support
REACT_APP_BLOCK_EXPLORER_URLenvironment variableImplementation
getExplorerLinkfunction to check env var firstgetEtherscanUrl/getBlockExplorerUrlfunctions to check env var first.envfilesSuccess Criteria
REACT_APP_BLOCK_EXPLORER_URL=http://localhost:8003redirects all explorer links to OtterscanChanges
Modified Files
libs/common-utils/src/getExplorerLink.tsBLOCK_EXPLORER_URL_OVERRIDEcheck before chain defaultlibs/common-utils/src/legacyAddressUtils.tsBLOCK_EXPLORER_URL_OVERRIDEcheck togetEtherscanUrlapps/cowswap-frontend/.envapps/explorer/.env.exampleHow It Works
Configuration
# In .env or build environment REACT_APP_BLOCK_EXPLORER_URL=http://localhost:8003When set, all block explorer links will use this URL:
http://localhost:8003/tx/{hash}http://localhost:8003/address/{address}http://localhost:8003/token/{address}http://localhost:8003/block/{number}Testing
Build with env var set:
Verify in browser:
localhost:8003instead of EtherscanVerify default behavior:
Related PRs
Milestones
Submitted by CoBuilders as part of the CoW Grants Program
Summary by CodeRabbit
Documentation
New Features
✏️ Tip: You can customize this high-level summary in your review settings.