8000 feat: add `Avalanche` and `Polygon` native token images to Explorer by cowdan · Pull Request #5813 · cowprotocol/cowswap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add Avalanche and Polygon native token images to E 8000 xplorer #5813

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

Merged
merged 13 commits into from
Jun 16, 2025

Conversation

cowdan
Copy link
Contributor
@cowdan cowdan commented Jun 12, 2025

Summary

  • Add Avalanche and Polygon native token images to Explorer
  • Change Avalanche and Polygon start date
  • Fix wrapping/unwrapping Avalanche and Polygon native tokens message

Fixes

  • Wrong token symbols(names) for (wrapped)native and token
  • Update FAQ on CoW Swap and CoW Protocol pages in cow.fi
  • Total surplus tooltip: change May to June
  • Typo in polygonscan (and SnowTrace for Avalanche)

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Added support for displaying token images for Avalanche (AVAX) and Polygon (POL) networks.
  • Chores
    • Centralized network-to-token image mappings for better maintainability.
    • Updated surplus calculation start dates for Polygon and Avalanche to June 2025.
    • Standardized currency symbol mappings across supported chains for consistency.
    • Expanded the list of supported blockchain networks in FAQs to include Polygon and Avalanche.
    • Updated CoW SDK dependency to the latest release candidate version.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Copy link
vercel bot commented Jun 12, 2025

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

Name Status Preview Updated (UTC)
cowfi 🛑 Canceled (Inspect) Jun 16, 2025 10:43am
explorer-dev ✅ Ready (Inspect) Visit Preview Jun 16, 2025 10:43am
swap-dev ✅ Ready (Inspect) Visit Preview Jun 16, 2025 10:43am
3 Skipped Deployments
Name Status Preview Updated (UTC)
cosmos ⬜️ Ignored (Inspect) Visit Preview Jun 16, 2025 10:43am
sdk-tools ⬜️ Ignored (Inspect) Visit Preview Jun 16, 2025 10:43am
widget-configurator ⬜️ Ignored (Inspect) Visit Preview Jun 16, 2025 10:43am

Copy link
Contributor
coderabbitai bot commented Jun 12, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes expand support for Avalanche and Polygon tokens by updating regex patterns and centralizing network-to-image mappings. Surplus start dates for Polygon and Avalanche were updated from May to June 2025. Currency symbol retrieval was refactored to use a mapping object for multiple chains, replacing conditional logic. FAQ data was updated to include Polygon and Avalanche in supported chains. The CoW SDK dependency version was bumped.

Changes

File(s) Change Summary
apps/explorer/src/components/common/TokenImg.tsx Expanded regex to include "avax" and "pol" token icons.
apps/explorer/src/utils/miscellaneous.ts Replaced conditional in getImageAddress with a centralized NetworkImageAddressMap supporting multiple chains.
apps/cowswap-frontend/src/modules/account/containers/AccountDetails/SurplusCard.tsx Updated surplus start dates for Polygon and Avalanche from May 2025 to June 2025.
libs/common-const/src/gnosis_chain/hack.ts Refactored getChainCurrencySymbols to use a mapping object for chain currency symbols, adding multiple chains.
apps/cow-fi/data/cow-protocol/const.tsx Updated FAQ to include Polygon and Avalanche in supported chains.
apps/cow-fi/data/cow-swap/const.tsx Updated FAQ to add Base, Polygon, and Avalanche to CoW Swap supported networks.
package.json Updated @cowprotocol/cow-sdk dependency version from 6.0.0-RC.60 to 6.0.0-RC.61.

Suggested reviewers

  • elena-zh

Poem

🐇 Hopping through chains with a twitch of my nose,
Avax and Pol join where the wild token grows.
Dates march to June, fresh starts in the air,
Symbols aligned with a map’s loving care.
Regex expanded, logic refined,
In blockchain meadows, new paths I find!
🌿🥕✨


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.

const TOKEN_ICON_FILENAME_REGEX = /(0x\w{40}|eth|xdai)/
const TOKEN_ICON_FILENAME_REGEX = /(0x\w{40}|eth|xdai|avax|pol)/

console.log(tokensIconsRequire)
Copy link
Collaborator

Choose a reason for hiding this comment

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

console.log

@@ -75,7 +75,16 @@ export function getImageAddress(address: string, network: Network): string {
// Well, this address here is the path on `src/assets/tokens/`
// So these special values will use the local images,
// because they are native tokens and don't really have an address
return network === Network.GNOSIS_CHAIN ? 'xdai' : 'eth'
switch (network) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick, it's better to use Record<Network, string> instead of switch/case. It will protect you from ocassional mistakes

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: 0

🧹 Nitpick comments (3)
apps/explorer/src/utils/miscellaneous.ts (1)

78-87: Prefer a constant map over an inline switch for scalability

Hard-coding network ↔︎ image strings in a switch works, but every future network addition will touch this function again.
A single constant map keeps the function O(1) and avoids code churn:

-    switch (network) {
-      case Network.GNOSIS_CHAIN:
-        return 'xdai'
-      case Network.AVALANCHE:
-        return 'avax'
-      case Network.POLYGON:
-        return 'pol'
-      default:
-        return 'eth'
-    }
+    const NATIVE_ICON_BY_NETWORK: Record<Network, string> = {
+      [Network.GNOSIS_CHAIN]: 'xdai',
+      [Network.AVALANCHE]: 'avax',
+      [Network.POLYGON]: 'pol',
+    } as const
+
+    return NATIVE_ICON_BY_NETWORK[network] ?? 'eth'

Benefits:
• Single-source of truth (also reusable from TokenImg.tsx)
• Type-checked keys → compile-time safety when a new enum member is introduced
• Cleaner diff for future PRs.

apps/explorer/src/components/common/TokenImg.tsx (2)

43-44: Keep regex patterns in sync with getImageAddress

Good catch adding avax & pol. Once the mapping in miscellaneous.ts is refactored into a constant (see previous comment), consider importing that same constant here to avoid future drift between the regex and the mapping.


45-46: Remove unconditional console.log before shipping

Dumping the entire tokensIconsRequire object (~hundreds of base-64 URLs) to the console will bloat production logs and slightly impact bundle size. Gate it behind a dev check or drop it entirely:

-console.log(tokensIconsRequire)
+if (process.env.NODE_ENV === 'development') {
+  // eslint-disable-next-line no-console
+  console.debug('Token icons loaded:', tokensIconsRequire)
+}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7786c99 and 4aa1254.

⛔ Files ignored due to path filters (2)
  • apps/explorer/src/assets/img/tokens/avax.png is excluded by !**/*.png
  • apps/explorer/src/assets/img/tokens/pol.png is excluded by !**/*.png
📒 Files selected for processing (2)
  • apps/explorer/src/components/common/TokenImg.tsx (1 hunks)
  • apps/explorer/src/utils/miscellaneous.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Cypress
  • GitHub Check: Setup

@cowdan cowdan requested a review from shoom3301 June 12, 2025 10:46
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: 2

🧹 Nitpick comments (1)
libs/common-const/src/gnosis_chain/hack.ts (1)

9-17: Optional: use satisfies / as const for compile-time exhaustiveness

TypeScript 4.9+ can guarantee every SupportedChainId key is present:

-const ChainCurrencySymbolsMap: Record<SupportedChainId, { native: string; wrapped: string }> = {
+const ChainCurrencySymbolsMap = {-} 
+} as const satisfies Record<SupportedChainId, { native: string; wrapped: string }>

This prevents accidental omission when new chains are added.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4aa1254 and 759a9e4.

📒 Files selected for processing (4)
  • apps/cowswap-frontend/src/modules/account/containers/AccountDetails/SurplusCard.tsx (1 hunks)
  • apps/explorer/src/components/common/TokenImg.tsx (1 hunks)
  • apps/explorer/src/utils/miscellaneous.ts (1 hunks)
  • libs/common-const/src/gnosis_chain/hack.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • apps/cowswap-frontend/src/modules/account/containers/AccountDetails/SurplusCard.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/explorer/src/components/common/TokenImg.tsx
  • apps/explorer/src/utils/miscellaneous.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
libs/common-const/src/gnosis_chain/hack.ts (2)
libs/widget-lib/src/types.ts (1)
  • SupportedChainId (4-4)
libs/common-const/src/tokens.ts (1)
  • XDAI_SYMBOL (99-99)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Cypress
  • GitHub Check: Setup

Comment on lines +19 to +22
export function getChainCurrencySymbols(chainId?: SupportedChainId): { native: string; wrapped: string } {
if (!chainId) return ChainCurrencySymbolsMap[SupportedChainId.MAINNET]

return CURRENCY_SYMBOLS_ETH
return ChainCurrencySymbolsMap[chainId]
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

Unsafe return type – function may yield undefined for unknown chainId

Record<SupportedChainId, …> is not exhaustive at runtime: callers can pass any number.
ChainCurrencySymbolsMap[chainId] will return undefined, violating the declared return type { native: string; wrapped: string } and crashing on property access.

 export function getChainCurrencySymbols(chainId?: SupportedChainId): { native: string; wrapped: string } {
-  if (!chainId) return ChainCurrencySymbolsMap[SupportedChainId.MAINNET]
-
-  return ChainCurrencySymbolsMap[chainId]
+  const symbols = ChainCurrencySymbolsMap[chainId ?? SupportedChainId.MAINNET]
+  if (!symbols) {
+    // Fallback or throw – choose whichever matches product requirements
+    return CURRENCY_SYMBOLS_ETH
+    // throw new Error(`Unsupported chainId ${chainId}`)
+  }
+  return symbols
 }

Add an exhaustive test to ensure unknown IDs fall back or throw as intended.

📝 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
export function getChainCurrencySymbols(chainId?: SupportedChainId): { native: string; wrapped: string } {
if ( 8000 !chainId) return ChainCurrencySymbolsMap[SupportedChainId.MAINNET]
return CURRENCY_SYMBOLS_ETH
return ChainCurrencySymbolsMap[chainId]
export function getChainCurrencySymbols(chainId?: SupportedChainId): { native: string; wrapped: string } {
const symbols = ChainCurrencySymbolsMap[chainId ?? SupportedChainId.MAINNET]
if (!symbols) {
// Fallback or throw – choose whichever matches product requirements
return CURRENCY_SYMBOLS_ETH
// throw new Error(`Unsupported chainId ${chainId}`)
}
return symbols
}
🤖 Prompt for AI Agents
In libs/common-const/src/gnosis_chain/hack.ts around lines 19 to 22, the
function getChainCurrencySymbols may return undefined if an unknown chainId is
passed, violating the declared return type. To fix this, add a runtime check to
verify if chainId exists in ChainCurrencySymbolsMap; if not, either throw an
error or return a default fallback value like the MAINNET symbols. Also, add a
test case to cover unknown chainId inputs to ensure the function handles them
safely.

@elena-zh
Copy link
Contributor

Hey @cowdan , thank you!
However:

  1. the build is cancelled, could you please fix it?
  2. could you please provide a bit more info which tasks in particular I should review? or add some steps to reproduce?

Thanks

@cowdan
Copy link
Contributor Author
cowdan commented Jun 12, 2025

Hey @cowdan , thank you! However:

  1. the build is cancelled, could you please fix it?
  2. could you please provide a bit more info which tasks in particular I should review? or add some steps to reproduce?

Thanks

Hey @elena-zh,

  1. the build should be ok now
  2. updated description

@elena-zh
Copy link
Contributor

Thanks, @cowdan , the build is still 'cancelled'
image
Let me know please if I can use this link for tests
image

Copy link
socket-security bot commented Jun 12, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​cowprotocol/​cow-sdk@​6.0.0-RC.60 ⏵ 6.0.0-RC.61821009999 +1100

View full report

Copy link
Contributor
@elena-zh elena-zh left a comment

Choose a reason for hiding this comment

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

Hey @cowdan , thank you!
So, eveything lools good:

  • Polyscan and Snowtrace naming
  • native and wrapped native tokens names
  • tooltip details
  • and chains info on cow.fi.

However, I have 1 concern: if we merge this PR with changes on Cow.fi before the networks launch, it might be possible that users will see it before the announcement.
WDYT about commenting this change for now and enabling it after the new networks launch?

Thanks

@fairlighteth
Copy link
Contributor

In relation to @elena-zh 's comment, should we make use of useAvailableChains() to only show enabled chains by our feature flags? We need to think how to handle this for the cowfi app (for the FAQ item).

@cowdan cowdan requested a review from elena-zh June 16, 2025 09:24
@cowdan
Copy link
Contributor Author
cowdan commented Jun 16, 2025

However, I have 1 concern: if we merge this PR with changes on Cow.fi before the networks launch, it might be possible that users will see it before the announcement. WDYT about commenting this change for now and enabling it after the new networks launch?

Hey @elena-zh, as discussed, that commit has been reverted

@cowdan
Copy link
Contributor Author
cowdan commented Jun 16, 2025

In relation to @elena-zh 's comment, should we make use of useAvailableChains() to only show enabled chains by our feature flags? We need to think how to handle this for the cowfi app (for the FAQ item).

I've tried that but having to manage different versions according to which flag is enabled is not worth IMO

Copy link
Contributor
@elena-zh elena-zh left a comment

Choose a reason for hiding this comment

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

Thanks

@cowdan cowdan merged commit 2c83e45 into develop Jun 16, 2025
14 of 15 checks passed
@cowdan cowdan deleted the fix/explorer-new-networks branch June 16, 2025 15:38
@github-actions github-actions bot locked and limited conversation to collaborators Jun 16, 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.

5 participants
0