From 6d11b05aa2adda197d807ac9b7f4595923258e17 Mon Sep 17 00:00:00 2001 From: Augusto Collerone Date: Fri, 26 Dec 2025 16:19:37 -0300 Subject: [PATCH 1/4] feat(common-utils): add REACT_APP_BLOCK_EXPLORER_URL env var override --- apps/cowswap-frontend/.env | 11 +++++++++++ apps/explorer/.env.example | 9 +++++++++ libs/common-utils/src/getExplorerLink.ts | 15 ++++++++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/apps/cowswap-frontend/.env b/apps/cowswap-frontend/.env index 1773c7002db..6e3cb389745 100644 --- a/apps/cowswap-frontend/.env +++ b/apps/cowswap-frontend/.env @@ -103,6 +103,17 @@ INTEGRATION_TESTS_INFURA_KEY= #REACT_APP_EXPLORER_URL_PROD= #REACT_APP_EXPLORER_URL_BARN= +####################################### +# Block Explorer Override +####################################### +# Override the default block explorer URL (e.g., Etherscan, Gnosisscan). +# Useful for local development with tools like Otterscan. +# When set, all block explorer links will use this URL instead of the chain's default. +# The URL should not include a trailing slash. +# +# Example for local Otterscan: +#REACT_APP_BLOCK_EXPLORER_URL=http://localhost:8003 + diff --git a/apps/explorer/.env.example b/apps/explorer/.env.example index 8bd1ce4ad67..c7d3883adc5 100644 --- a/apps/explorer/.env.example +++ b/apps/explorer/.env.example @@ -22,3 +22,12 @@ THEGRAPH_API_KEY= # REACT_APP_DOMAIN_REGEX_DEVELOPMENT="^(dev\.explorer\.cow\.fi|explorer-develop\.vercel\.app)" # REACT_APP_DOMAIN_REGEX_STAGING="^(staging\.explorer\.cow\.fi|explorer-staging\.vercel\.app)" # REACT_APP_DOMAIN_REGEX_PRODUCTION="^(explorer\.cow\.fi|explorer-prod\.vercel\.app)$" + +# Block Explorer Override +# Override the default block explorer URL (e.g., Etherscan, Gnosisscan). +# Useful for local development with tools like Otterscan. +# When set, all block explorer links will use this URL instead of the chain's default. +# The URL should not include a trailing slash. +# +# Example for local Otterscan: +#REACT_APP_BLOCK_EXPLORER_URL=http://localhost:8003 diff --git a/libs/common-utils/src/getExplorerLink.ts b/libs/common-utils/src/getExplorerLink.ts index f86bc29b54f..4b8ab268cd8 100644 --- a/libs/common-utils/src/getExplorerLink.ts +++ b/libs/common-utils/src/getExplorerLink.ts @@ -8,6 +8,18 @@ export enum ExplorerDataType { BLOCK = 'block', } +/** + * Environment variable to override the block explorer URL. + * Useful for local development with tools like Otterscan. + * + * When set, this URL will be used instead of the chain's default block explorer (e.g., Etherscan). + * The URL should not include a trailing slash. + * + * @example + * REACT_APP_BLOCK_EXPLORER_URL=http://localhost:8003 + */ +const BLOCK_EXPLORER_URL_OVERRIDE = process.env.REACT_APP_BLOCK_EXPLORER_URL + /** * Return the explorer link for the given data and data type * @param chainId the ID of the chain for which to return the data @@ -21,7 +33,8 @@ export function getExplorerLink( type: ExplorerDataType, defaultPrefix = 'https://etherscan.io', ): string { - const prefix = CHAIN_INFO[chainId as SupportedChainId]?.explorer ?? defaultPrefix + // Allow override via environment variable for local development (e.g., Otterscan) + const prefix = BLOCK_EXPLORER_URL_OVERRIDE || CHAIN_INFO[chainId as SupportedChainId]?.explorer || defaultPrefix switch (type) { case ExplorerDataType.TRANSACTION: From 5f2b13d822fbe8f9a98951f5b055e6f83dc3e045 Mon Sep 17 00:00:00 2001 From: Augusto Collerone Date: Fri, 26 Dec 2025 16:43:54 -0300 Subject: [PATCH 2/4] chore(common-utils): add debug logging for block explorer URL override --- libs/common-utils/src/getExplorerLink.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libs/common-utils/src/getExplorerLink.ts b/libs/common-utils/src/getExplorerLink.ts index 4b8ab268cd8..a44315133e1 100644 --- a/libs/common-utils/src/getExplorerLink.ts +++ b/libs/common-utils/src/getExplorerLink.ts @@ -20,6 +20,9 @@ export enum ExplorerDataType { */ const BLOCK_EXPLORER_URL_OVERRIDE = process.env.REACT_APP_BLOCK_EXPLORER_URL +// Debug logging for block explorer URL override +console.log('[getExplorerLink] BLOCK_EXPLORER_URL_OVERRIDE:', BLOCK_EXPLORER_URL_OVERRIDE) + /** * Return the explorer link for the given data and data type * @param chainId the ID of the chain for which to return the data @@ -36,6 +39,16 @@ export function getExplorerLink( // Allow override via environment variable for local development (e.g., Otterscan) const prefix = BLOCK_EXPLORER_URL_OVERRIDE || CHAIN_INFO[chainId as SupportedChainId]?.explorer || defaultPrefix + // Debug logging for each call + console.log('[getExplorerLink] called with:', { + chainId, + type, + override: BLOCK_EXPLORER_URL_OVERRIDE, + chainExplorer: CHAIN_INFO[chainId as SupportedChainId]?.explorer, + defaultPrefix, + selectedPrefix: prefix, + }) + switch (type) { case ExplorerDataType.TRANSACTION: return `${prefix}/tx/${data}` From f0d3263691d4788fe86fd466088c8863418c4e55 Mon Sep 17 00:00:00 2001 From: Augusto Collerone Date: Fri, 26 Dec 2025 17:06:56 -0300 Subject: [PATCH 3/4] fix(common-utils): add BLOCK_EXPLORER_URL override to legacyAddressUtils --- libs/common-utils/src/legacyAddressUtils.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libs/common-utils/src/legacyAddressUtils.ts b/libs/common-utils/src/legacyAddressUtils.ts index 2441bd08088..f8acbe23291 100644 --- a/libs/common-utils/src/legacyAddressUtils.ts +++ b/libs/common-utils/src/legacyAddressUtils.ts @@ -9,6 +9,15 @@ import { t } from '@lingui/core/macro' import { getExplorerOrderLink } from './explorer' +/** + * Environment variable to override the block explorer URL. + * Useful for local development with tools like Otterscan. + */ +const BLOCK_EXPLORER_URL_OVERRIDE = process.env.REACT_APP_BLOCK_EXPLORER_URL + +// Debug logging for block explorer URL override +console.log('[legacyAddressUtils] BLOCK_EXPLORER_URL_OVERRIDE:', BLOCK_EXPLORER_URL_OVERRIDE) + // returns the checksummed address if the address is valid, otherwise returns false export function isAddress(value: string | undefined | null): string | false { try { @@ -69,7 +78,8 @@ export type BlockExplorerLinkType = // eslint-disable-next-line complexity 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 if (!basePath) return '' From a8b3175a89e9a1caeff8b6174bcf2c6b71ff957c Mon Sep 17 00:00:00 2001 From: Augusto Collerone Date: Fri, 26 Dec 2025 17:26:15 -0300 Subject: [PATCH 4/4] chore(common-utils): remove debug console logs --- libs/common-utils/src/getExplorerLink.ts | 13 ------------- libs/common-utils/src/legacyAddressUtils.ts | 3 --- 2 files changed, 16 deletions(-) diff --git a/libs/common-utils/src/getExplorerLink.ts b/libs/common-utils/src/getExplorerLink.ts index a44315133e1..4b8ab268cd8 100644 --- a/libs/common-utils/src/getExplorerLink.ts +++ b/libs/common-utils/src/getExplorerLink.ts @@ -20,9 +20,6 @@ export enum ExplorerDataType { */ const BLOCK_EXPLORER_URL_OVERRIDE = process.env.REACT_APP_BLOCK_EXPLORER_URL -// Debug logging for block explorer URL override -console.log('[getExplorerLink] BLOCK_EXPLORER_URL_OVERRIDE:', BLOCK_EXPLORER_URL_OVERRIDE) - /** * Return the explorer link for the given data and data type * @param chainId the ID of the chain for which to return the data @@ -39,16 +36,6 @@ export function getExplorerLink( // Allow override via environment variable for local development (e.g., Otterscan) const prefix = BLOCK_EXPLORER_URL_OVERRIDE || CHAIN_INFO[chainId as SupportedChainId]?.explorer || defaultPrefix - // Debug logging for each call - console.log('[getExplorerLink] called with:', { - chainId, - type, - override: BLOCK_EXPLORER_URL_OVERRIDE, - chainExplorer: CHAIN_INFO[chainId as SupportedChainId]?.explorer, - defaultPrefix, - selectedPrefix: prefix, - }) - switch (type) { case ExplorerDataType.TRANSACTION: return `${prefix}/tx/${data}` diff --git a/libs/common-utils/src/legacyAddressUtils.ts b/libs/common-utils/src/legacyAddressUtils.ts index f8acbe23291..c2691f07b86 100644 --- a/libs/common-utils/src/legacyAddressUtils.ts +++ b/libs/common-utils/src/legacyAddressUtils.ts @@ -15,9 +15,6 @@ import { getExplorerOrderLink } from './explorer' */ const BLOCK_EXPLORER_URL_OVERRIDE = process.env.REACT_APP_BLOCK_EXPLORER_URL -// Debug logging for block explorer URL override -console.log('[legacyAddressUtils] BLOCK_EXPLORER_URL_OVERRIDE:', BLOCK_EXPLORER_URL_OVERRIDE) - // returns the checksummed address if the address is valid, otherwise returns false export function isAddress(value: string | undefined | null): string | false { try {