Skip to content

feat/arbitrum-optimism-bnb-implementation#265

Merged
RanaBug merged 9 commits intostagingfrom
feat/arbitrum-optimism-bnb-implementation
Mar 26, 2025
Merged

feat/arbitrum-optimism-bnb-implementation#265
RanaBug merged 9 commits intostagingfrom
feat/arbitrum-optimism-bnb-implementation

Conversation

@RanaBug
Copy link
Collaborator

@RanaBug RanaBug commented Mar 24, 2025

Description

  • Add compatibility with Arbitrum, Optimism and BNB chains

How Has This Been Tested?

  • Existing Unit Tests and Manual Testing

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Summary by CodeRabbit

  • New Features

    • Expanded support for additional blockchain networks including Arbitrum, Binance Smart Chain, and Optimism.
    • Introduced new token listings for the added networks, enhancing token discovery and management.
    • Updated wallet connection capabilities to integrate with the new blockchain networks.
  • Refactor

    • Improved display logic to ensure consistent and accurate network naming across the application.
    • Consolidated network mappings and configurations for smoother blockchain integration.

@RanaBug RanaBug requested a review from IAmKio March 24, 2025 13:10
@RanaBug RanaBug self-assigned this Mar 24, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 24, 2025

Walkthrough

This update enhances multi-chain support across the application. It replaces hardcoded chain name conditions with a new utility function, chainNameDataCompatibility, and introduces its reverse mapping counterpart. The changes expand token lists, network configurations, and type definitions to include additional chains (Arbitrum, BNB Smart Chain, and Optimism) across both UI components and backend services, along with requisite adjustments in tests and mocks.

Changes

File(s) Change Summary
src/apps/deposit/components/Asset/Asset.tsx
src/apps/the-exchange/components/TokenListItem/TokenListItem.tsx
src/apps/token-atlas/components/TokenResultCard/TokenResultCard.tsx
Replaced inline conditional logic for displaying chain names with a call to chainNameDataCompatibility for dynamic chain name mapping.
src/services/tokensData.ts Added new functions: chainNameDataCompatibility and chainNameFromViemToMobula; updated mapping functions (chainIdToChainNameTokensData and chainNameToChainIdTokensData) to include additional blockchain network cases.
src/apps/deposit/components/AssetsList/AssetsList.tsx
src/apps/deposit/index.tsx
src/apps/deposit/types/types.tsx
src/apps/deposit/utils/blockchain.tsx
src/services/walletConnect.ts
src/utils/blockchain.ts
src/providers/__tests__/AssetsProvider.test.tsx
Extended multi-chain support by updating imports, network configurations, type definitions, blockchain mappings, and tests to incorporate Arbitrum, BNB (BSC), and Optimism.
src/apps/deposit/utils/tokens/arbitrum-tokens.json
src/apps/deposit/utils/tokens/bnb-tokens.json
src/apps/deposit/utils/tokens/optimism-tokens.json
Introduced new JSON token lists with metadata for the Arbitrum, BNB, and Optimism networks.
src/apps/the-exchange/components/CardsSwap/test/CardSwap.test.tsx
src/apps/the-exchange/components/DropdownTokensList/test/DropdownTokensList.test.tsx
Updated Jest mocks by introducing a mocked version of chainNameDataCompatibility to standardize chain name translation in tests.

Sequence Diagram(s)

sequenceDiagram
    participant Component as UI Component
    participant DataSvc as tokensData Service
    participant Mapping as Chain Name Mapping

    Component->>DataSvc: Call chainNameDataCompatibility(chainName)
    DataSvc->>Mapping: Map the provided chain name
    Mapping-->>DataSvc: Return standardized chain name
    DataSvc-->>Component: Return compatible chain name
    Component->>UI: Render the updated chain name
Loading

Possibly related PRs

Suggested reviewers

  • IAmKio

Poem

I'm a hopping rabbit in a code-filled glade,
Where chain names dance and networks are laid.
With chainNameDataCompatibility lighting the way,
New tokens and chains join in the play.
Hoppity-hop, the changes sing bright—
CodeRabbit cheers with delight!
🐰🌟


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 12c0ca7 and 3d741a2.

⛔ Files ignored due to path filters (2)
  • src/apps/pillarx-app/components/MediaGridCollection/tests/__snapshots__/DisplayCollectionImage.test.tsx.snap is excluded by !**/*.snap
  • src/apps/pillarx-app/components/PointsTile/test/__snapshots__/PointsTile.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (7)
  • src/apps/deposit/types/types.tsx (1 hunks)
  • src/apps/deposit/utils/blockchain.tsx (4 hunks)
  • src/apps/the-exchange/components/CardsSwap/test/CardSwap.test.tsx (1 hunks)
  • src/apps/the-exchange/components/DropdownTokensList/test/DropdownTokensList.test.tsx (1 hunks)
  • src/apps/the-exchange/components/SelectDropdown/test/SelectDropdown.test.tsx (3 hunks)
  • src/services/tokensData.ts (4 hunks)
  • src/utils/blockchain.ts (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/apps/the-exchange/components/DropdownTokensList/test/DropdownTokensList.test.tsx
  • src/apps/deposit/types/types.tsx
  • src/apps/the-exchange/components/SelectDropdown/test/SelectDropdown.test.tsx
  • src/apps/deposit/utils/blockchain.tsx
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: unit-tests
  • GitHub Check: build
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (13)
src/apps/the-exchange/components/CardsSwap/test/CardSwap.test.tsx (1)

74-85: LGTM! Good test coverage for the new function.

The mock implementation of chainNameDataCompatibility properly matches the actual implementation and provides the expected behavior for the test suite.

src/services/tokensData.ts (5)

42-62: LGTM! Well-implemented chain name standardization.

The chainNameDataCompatibility function provides a clear way to standardize blockchain names across the application, which helps maintain consistency in the UI.


64-82: LGTM! Good implementation of the reverse mapping function.

The chainNameFromViemToMobula function properly handles the reverse mapping from standardized chain names to Mobula's naming conventions, which is essential for compatibility with the Mobula API.


94-96: LGTM! Good refactoring to use the new function.

Replacing the hardcoded condition with the chainNameFromViemToMobula function makes the code more maintainable and consistent.


224-230: LGTM! Proper chain ID mapping for the new chains.

The function correctly maps the new chains to their respective IDs, which is essential for proper token data retrieval.


248-254: LGTM! Proper chain name mapping for the new chains.

The function correctly maps the new chain IDs to their respective names, which ensures consistency throughout the application.

src/utils/blockchain.ts (7)

7-14: LGTM! Proper imports for the new chains.

The imports for arbitrum and optimism from viem/chains are correctly added.


19-27: LGTM! Correct imports for the chain logos.

The logo imports for Arbitrum and Optimism are properly added, which will be used to display the chain logos in the UI.


108-121: LGTM! Proper native asset configuration for Optimism and Arbitrum.

The implementation correctly sets ETH as the native asset for both Optimism and Arbitrum, which is accurate as transactions on these networks are paid with ETH, not their governance tokens.


139-148: LGTM! Updated supported chains list.

The supportedChains array is properly updated to include BNB Smart Chain, Optimism, and Arbitrum.


179-186: LGTM! Proper logo mapping for the new chains.

The function correctly returns the imported logos for Optimism and Arbitrum based on their chain IDs.


249-255: LGTM! Proper chain name mapping for the new chains.

The function correctly returns the chain names for BNB Smart Chain, Optimism, and Arbitrum based on their chain IDs.


277-289: LGTM! Updated compatible chains list.

The CompatibleChains array is properly updated to include entries for BNB Smart Chain, Optimism, and Arbitrum with their respective chain IDs and names.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 24, 2025

Deploying x with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3d741a2
Status: ✅  Deploy successful!
Preview URL: https://0a1feb0c.x-e62.pages.dev
Branch Preview URL: https://feat-arbitrum-optimism-bnb-i.x-e62.pages.dev

View logs

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

🔭 Outside diff range comments (1)
src/apps/deposit/components/AssetsList/AssetsList.tsx (1)

75-75: 💡 Verification agent

🧩 Analysis chain

Verify chainName handling for new chains.

The chainName variable is derived from getNetworkViem(chainId).name.toLowerCase(). Ensure this function properly handles the new chains (BNB Smart Chain, Optimism, and Arbitrum) in the blockchain.tsx utility file.


🏁 Script executed:

#!/bin/bash
# Check if the getNetworkViem function properly handles new chains
rg -A 10 "getNetworkViem" src/apps/deposit/utils/blockchain.tsx

Length of output: 2762


Action Required: Update Network Handling for New Chains

It appears that the getNetworkViem function currently returns chains for IDs 1, 137, 100, 8453, and has a provision for chain ID 56 (BNB Smart Chain). However, explicit cases for Optimism (chainId 10) and Arbitrum (chainId 42161) are missing. Please update the switch-case in src/apps/deposit/utils/blockchain.tsx to include these new chains and ensure that their returned chain objects have name properties matching the keys in chainMapping (using lowercase). This will ensure that chainName handling is consistent and that the system properly supports Optimism and Arbitrum.

🧹 Nitpick comments (1)
src/apps/deposit/utils/tokens/optimism-tokens.json (1)

1-372: Well-structured token list for Optimism network.

The Optimism token list is comprehensive and follows a standard format, including essential metadata for each token such as contract addresses, symbols, and logo URIs. This will support the application's token display and selection functionality on the Optimism network.

One minor issue to note:

In the Optimism token (OP) entry at line 368, the decimals property is defined as a string "18" while all other tokens use a number format. Consider standardizing this to be consistent with the other tokens:

-      "decimals": "18",
+      "decimals": 18,
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0133289 and 5dc35f5.

⛔ Files ignored due to path filters (4)
  • src/apps/pillarx-app/components/MediaGridCollection/tests/__snapshots__/DisplayCollectionImage.test.tsx.snap is excluded by !**/*.snap
  • src/apps/pillarx-app/components/PointsTile/test/__snapshots__/PointsTile.test.tsx.snap is excluded by !**/*.snap
  • src/assets/images/logo-arbitrum.png is excluded by !**/*.png
  • src/assets/images/logo-optimism.png is excluded by !**/*.png
📒 Files selected for processing (16)
  • src/apps/deposit/components/Asset/Asset.tsx (2 hunks)
  • src/apps/deposit/components/AssetsList/AssetsList.tsx (2 hunks)
  • src/apps/deposit/index.tsx (2 hunks)
  • src/apps/deposit/types/types.tsx (1 hunks)
  • src/apps/deposit/utils/blockchain.tsx (6 hunks)
  • src/apps/deposit/utils/tokens/arbitrum-tokens.json (1 hunks)
  • src/apps/deposit/utils/tokens/bnb-tokens.json (1 hunks)
  • src/apps/deposit/utils/tokens/optimism-tokens.json (1 hunks)
  • src/apps/the-exchange/components/CardsSwap/test/CardSwap.test.tsx (1 hunks)
  • src/apps/the-exchange/components/DropdownTokensList/test/DropdownTokensList.test.tsx (1 hunks)
  • src/apps/the-exchange/components/TokenListItem/TokenListItem.tsx (2 hunks)
  • src/apps/token-atlas/components/TokenResultCard/TokenResultCard.tsx (2 hunks)
  • src/providers/__tests__/AssetsProvider.test.tsx (2 hunks)
  • src/services/tokensData.ts (3 hunks)
  • src/services/walletConnect.ts (2 hunks)
  • src/utils/blockchain.ts (7 hunks)
🧰 Additional context used
🧬 Code Definitions (5)
src/apps/deposit/components/Asset/Asset.tsx (1)
src/services/tokensData.ts (1)
  • chainNameDataCompatibility (42-62)
src/apps/token-atlas/components/TokenResultCard/TokenResultCard.tsx (1)
src/services/tokensData.ts (1)
  • chainNameDataCompatibility (42-62)
src/apps/the-exchange/components/TokenListItem/TokenListItem.tsx (1)
src/services/tokensData.ts (1)
  • chainNameDataCompatibility (42-62)
src/providers/__tests__/AssetsProvider.test.tsx (1)
src/utils/blockchain.ts (1)
  • getNativeAssetForChainId (66-138)
src/services/tokensData.ts (1)
src/utils/blockchain.ts (1)
  • CompatibleChains (261-290)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (36)
src/apps/deposit/types/types.tsx (1)

21-28: Good addition of new network types supporting the PR objectives!

The expansion of the Network type to include 'bnb smart chain', 'op mainnet', and 'arbitrum one' properly implements the core objective of adding support for these new blockchain networks. The naming convention follows the existing pattern of using lowercase and space-separated names, maintaining consistency.

src/apps/token-atlas/components/TokenResultCard/TokenResultCard.tsx (2)

1-2: Good addition of the utility import!

Adding the import for the chainNameDataCompatibility utility function is a good practice. This centralizes chain name handling across the codebase.


59-59: Excellent refactoring to use utility function!

Replacing hardcoded chain name checks with the chainNameDataCompatibility utility function is a good improvement. This improves maintainability and allows for standardized chain name display across the application.

src/apps/deposit/components/Asset/Asset.tsx (2)

3-4: Good addition of the utility import!

Adding the import for the chainNameDataCompatibility utility function is aligned with the codebase-wide refactoring for chain name handling.


65-65: Excellent refactoring to use utility function!

Replacing hardcoded chain name checks with the chainNameDataCompatibility utility function enhances consistency in how chain names are displayed across the application.

src/apps/deposit/utils/tokens/arbitrum-tokens.json (1)

1-292: Well-structured token list for Arbitrum network!

The token list is well-formatted and includes essential details for each token (address, chainId, decimals, name, symbol, logoURI). The chainId 42161 is correctly used for Arbitrum One. This file provides good support for the new blockchain integration.

Two minor points to note:

  1. The logos are sourced from different domains (arbiscan.io, raw.githubusercontent.com) - this is fine but worth noting for future maintenance
  2. Some tokens have placeholder logos ("empty-token.png") which might be improved in the future
src/services/walletConnect.ts (2)

331-333: New blockchain chains added to WalletConnect configuration.

The addition of BNB Smart Chain, Optimism, and Arbitrum to the supported chains array expands the wallet's connectivity options, allowing users to interact with dApps on these networks.


354-356: Correctly added corresponding account identifiers for the new chains.

These entries create the necessary account identifiers by combining each chain ID with the user's wallet address, following the EIP-155 standard format required by WalletConnect.

src/apps/the-exchange/components/CardsSwap/test/CardSwap.test.tsx (1)

74-85: Test mock updated for chain name compatibility.

The mock implementation of chainNameDataCompatibility ensures test coverage for the standardization of chain names, including the newly added chains (Arbitrum and Optimism). This maintains test integrity with the new functionality.

src/apps/the-exchange/components/TokenListItem/TokenListItem.tsx (2)

1-2: Added import for chainNameDataCompatibility utility.

The import of the utility function from tokensData service is appropriate and follows the project's import conventions.


50-50: Replaced hardcoded chain name handling with utility function.

Using the chainNameDataCompatibility function here improves maintainability by centralizing chain name standardization logic rather than having conditional checks scattered across components.

src/apps/the-exchange/components/DropdownTokensList/test/DropdownTokensList.test.tsx (1)

95-106: LGTM: Adding chainNameDataCompatibility mock implements the new chain name mappings.

The mock implementation properly maps alternative chain names to their standardized formats for Arbitrum, Optimism, and BNB Smart Chain, consistent with the PR's objective to add support for these networks.

src/apps/deposit/utils/tokens/bnb-tokens.json (1)

1-452: LGTM: Comprehensive BNB Smart Chain token list follows the established pattern.

This new token list includes essential tokens for the BNB Smart Chain with the correct chain ID (56) and follows the same structure as existing token lists. The inclusion of popular tokens like BNB, ETH, USDT, and USDC will provide a good user experience.

src/apps/deposit/index.tsx (2)

3-11: LGTM: Network imports now include the new chains.

Properly imported the new blockchain networks (arbitrum, bsc, and optimism) alongside existing networks.


52-52: LGTM: Networks configuration updated to include the new chains.

The networks array now correctly includes bsc, optimism, and arbitrum, enabling the application to support these chains.

src/apps/deposit/components/AssetsList/AssetsList.tsx (2)

29-35: LGTM: Added imports for new token lists.

Properly imported token lists for Arbitrum, BNB Smart Chain, and Optimism.


46-48: LGTM: Updated tokenLists with chain IDs for new networks.

Added correct chain ID mappings for BNB Smart Chain (56), Optimism (10), and Arbitrum (42161) to their respective token lists.

src/providers/__tests__/AssetsProvider.test.tsx (2)

4-12: Well-structured import of additional chains.

The updated import cleanly integrates the additional chains (arbitrum, bsc, optimism) alongside existing ones, maintaining alphabetical ordering and proper code organization.


63-65: Correctly updated assets test to include new chains.

The test case has been appropriately extended to verify that AssetsProvider properly initializes assets for the newly supported chains (BSC, Optimism, Arbitrum), ensuring comprehensive test coverage.

src/services/tokensData.ts (5)

42-62: Good implementation of blockchain name compatibility function.

The chainNameDataCompatibility function provides a clean, consistent approach for standardizing chain names across the application. This centralized conversion logic will improve maintainability.


64-82: Well-structured reverse mapping function for chain names.

The chainNameFromViemToMobula function provides the necessary reverse mapping functionality, creating a bidirectional conversion system that ensures consistency when interfacing with external services.


86-86: Good refactoring of chain name conversion logic.

Replacing the conditional check with a call to the new utility function eliminates duplicated logic and improves maintainability.


166-171: Complete implementation of chain ID to name mapping.

The updated function now properly handles all the new chains (BSC, Optimism, Arbitrum) with their corresponding IDs, ensuring consistent chain identification throughout the application.


189-194: Properly implemented chain name to ID mapping.

The updated function correctly maps the new chain names to their respective IDs, completing the bidirectional conversion system needed for cross-chain functionality.

src/apps/deposit/utils/blockchain.tsx (6)

19-27: Clean import of additional blockchain chains.

The imports have been updated to include the new chains (arbitrum, bsc, optimism) while maintaining alphabetical ordering for better code readability.


42-44: RPC URLs properly configured for new chains.

The chainMapping object has been correctly extended with RPC endpoints for the new chains, enabling network interactions with BNB Smart Chain, Optimism, and Arbitrum.


55-57: Appropriate native token configurations for new chains.

The allNativeTokens object now includes proper configuration for the native tokens of the newly supported chains, which is essential for correct token handling.


70-75: Chain object mapping implemented for new chain IDs.

The getNetworkViem function now correctly returns the appropriate chain objects for the new chain IDs (56 for BSC, 10 for Optimism, 42161 for Arbitrum).


91-96: Chain ID resolution properly implemented for new chains.

The getChainId function now correctly maps the string identifiers for the new chains to their respective numeric IDs.


112-117: Chain name resolution expanded for new chain IDs.

The getChainName function has been extended to handle the new chain IDs, ensuring consistent name resolution throughout the application.

src/utils/blockchain.ts (6)

8-17: Appropriate import of additional blockchain networks.

The imports have been expanded to include arbitrum and optimism alongside the existing chains, ensuring compatibility with the added networks.


20-28: Logo imports added for new networks.

The logo imports for Arbitrum and Optimism have been correctly added to support UI components that display chain logos.


140-149: Comprehensive update to supported chains list.

The supportedChains array now includes bsc, optimism, and arbitrum, enabling functionality across all these networks throughout the application.


180-187: Logo retrieval function updated for new chains.

The getLogoForChainId function now correctly returns the appropriate logos for Optimism and Arbitrum networks.


250-255: Chain name mapping correctly implemented.

The getChainName function has been properly extended to return the appropriate names for the new chains based on their IDs.


278-289: Compatible chains list comprehensively updated.

The CompatibleChains array has been expanded to include BSC, Optimism, and Arbitrum with their correct chain IDs and names.

Copy link
Collaborator

@IAmKio IAmKio left a comment

Choose a reason for hiding this comment

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

This LGTM but after looking through the PR, i'm quite sure someone will complain if we leave it as OP Mainnet - we may need to change this to Optimism

@github-actions github-actions bot temporarily deployed to Preview (feat/arbitrum-optimism-bnb-implementation) March 25, 2025 10:20 Inactive
@github-actions github-actions bot temporarily deployed to Preview (feat/arbitrum-optimism-bnb-implementation) March 26, 2025 13:34 Inactive
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 (2)
src/services/tokensData.ts (2)

42-62: Well-implemented chain name compatibility function.

The chainNameDataCompatibility function provides a clean solution for standardizing chain names across the application. It properly handles the translation from various chain name formats to their standardized versions.

Though the implementation works correctly, consider refactoring the multiple if-statements to use a mapping object for better maintainability:

-export const chainNameDataCompatibility = (chainName: string) => {
-  const chain = chainName.toLowerCase();
-
-  if (chain === 'xdai') {
-    return 'Gnosis';
-  }
-
-  if (chain === 'bnb smart chain (bep20)') {
-    return 'BNB Smart Chain';
-  }
-
-  if (chain === 'optimistic') {
-    return 'OP Mainnet';
-  }
-
-  if (chain === 'arbitrum') {
-    return 'Arbitrum One';
-  }
-
-  return chainName;
-};
+export const chainNameDataCompatibility = (chainName: string) => {
+  const chain = chainName.toLowerCase();
+  const chainMapping: Record<string, string> = {
+    'xdai': 'Gnosis',
+    'bnb smart chain (bep20)': 'BNB Smart Chain',
+    'optimistic': 'OP Mainnet',
+    'arbitrum': 'Arbitrum One',
+  };
+  
+  return chainMapping[chain] || chainName;
+};

64-82: Well-implemented reverse mapping function.

The chainNameFromViemToMobula function correctly implements the reverse operation of chainNameDataCompatibility, ensuring bidirectional conversion between different chain name formats.

Similar to the previous function, consider refactoring to use a mapping object for better maintainability:

-export const chainNameFromViemToMobula = (chainName: string) => {
-  if (chainName === 'Gnosis') {
-    return 'XDAI';
-  }
-
-  if (chainName === 'BNB Smart Chain') {
-    return 'BNB Smart Chain (BEP20)';
-  }
-
-  if (chainName === 'OP Mainnet') {
-    return 'Optimistic';
-  }
-
-  if (chainName === 'Arbitrum One') {
-    return 'Arbitrum';
-  }
-
-  return chainName;
-};
+export const chainNameFromViemToMobula = (chainName: string) => {
+  const chainMapping: Record<string, string> = {
+    'Gnosis': 'XDAI',
+    'BNB Smart Chain': 'BNB Smart Chain (BEP20)',
+    'OP Mainnet': 'Optimistic',
+    'Arbitrum One': 'Arbitrum',
+  };
+  
+  return chainMapping[chainName] || chainName;
+};
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 585d87d and 857c75a.

📒 Files selected for processing (4)
  • src/apps/deposit/utils/blockchain.tsx (6 hunks)
  • src/apps/the-exchange/components/SelectDropdown/SelectDropdown.tsx (2 hunks)
  • src/services/tokensData.ts (3 hunks)
  • src/utils/blockchain.ts (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/utils/blockchain.ts
🧰 Additional context used
🧬 Code Definitions (1)
src/services/tokensData.ts (1)
src/utils/blockchain.ts (1)
  • CompatibleChains (261-290)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: unit-tests
  • GitHub Check: build
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (11)
src/apps/the-exchange/components/SelectDropdown/SelectDropdown.tsx (2)

13-13: Properly integrated new utility function.

Adding the chainNameDataCompatibility import to standardize chain name display is a good improvement for ensuring consistent representation of chain names across the application.


111-113: Chain name standardization properly implemented.

The implementation correctly applies the new chainNameDataCompatibility function to both swapChain?.chainName and receiveChain?.chainName, ensuring consistent display of chain names including the newly supported Arbitrum, Optimism, and BNB chains.

src/services/tokensData.ts (3)

86-86: Improved flexibility in token data loading.

Using the chainNameFromViemToMobula function instead of a hardcoded conditional check improves flexibility and maintainability, making the code more adaptable to future chain additions.


190-195: Successfully added new chain mappings.

The addition of mappings for BNB Smart Chain (56), Optimistic (10), and Arbitrum (42161) correctly expands the application's compatibility with these chains.


213-218: Successfully added reverse chain mappings.

The addition of reverse mappings for the new chains completes the bidirectional mapping between chain names and IDs, ensuring consistency throughout the application.

src/apps/deposit/utils/blockchain.tsx (6)

19-27: Properly expanded chain imports.

The imports now correctly include the new chain configurations for arbitrum, bsc, and optimism from the viem/chains library, which is necessary for supporting these networks.


55-57: Correctly defined native tokens for new chains.

The native token information for each new chain has been properly defined, with BNB for BNB Smart Chain and ETH for both Optimism and Arbitrum, which is accurate.


70-75: Added proper chain object mappings.

The getNetworkViem function has been correctly updated to return the appropriate chain objects for the new chain IDs (56 for bsc, 10 for optimism, 42161 for arbitrum), ensuring compatibility with the viem library.


91-96: Added chain ID mappings for new chains.

The getChainId function has been properly updated to handle the new chain names and return their corresponding chain IDs, maintaining consistency with industry standards.


112-117: Added chain name mappings for new chains.

The getChainName function has been correctly updated to return the appropriate chain names for the new chain IDs, completing the bidirectional mapping necessary for the application to work with these chains.


42-44:

Details

✅ Verification successful

Added RPC URLs for new chains.

The RPC endpoints for the new chains have been properly defined. However, it's important to verify the reliability of these endpoints, as they are critical for the application's functionality.

I recommend verifying that these RPC endpoints are reliable and stable, as they will be used for all interactions with these blockchains:


🏁 Script executed:

#!/bin/bash
# Test the RPC endpoints for the new chains

echo "Testing BNB Smart Chain RPC..."
curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' https://bsc.drpc.org | jq

echo "Testing Optimism RPC..."
curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' https://optimism-rpc.publicnode.com | jq

echo "Testing Arbitrum RPC..."
curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' https://arbitrum.drpc.org | jq

Length of output: 841


RPC Endpoints Verified

The RPC endpoints for BNB Smart Chain, Optimism mainnet, and Arbitrum One have been successfully tested. Each endpoint returned a valid block number in response to an eth_blockNumber request, confirming their reliability for blockchain interactions.

  • BNB Smart Chain: Returned block number 0x2d971c8
  • Optimism mainnet: Returned block number 0x7f814ef
  • Arbitrum One: Returned block number 0x130ef9d3

No further changes are required.

@github-actions github-actions bot temporarily deployed to Preview (feat/arbitrum-optimism-bnb-implementation) March 26, 2025 14:10 Inactive
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 (1)
src/apps/the-exchange/components/SelectDropdown/test/SelectDropdown.test.tsx (1)

55-69: Mock implementation for chainNameDataCompatibility looks good, but missing test coverage for new chains.

The mock implementation follows best practices with type safety (using as const) and a clean fallback mechanism. It properly supports the Arbitrum, Optimism, and BNB chains mentioned in the PR objectives.

However, while the mock is set up correctly, I don't see test cases that verify the behavior with these newly added chains. Consider adding specific tests that assert the correct mapping for Arbitrum, Optimism, BNB Smart Chain, and XDAI.

// Add a test case to verify chain name mapping after line 232
+ it('correctly maps chain names using chainNameDataCompatibility', () => {
+   const { chainNameDataCompatibility } = require('../../../../../services/tokensData');
+   expect(chainNameDataCompatibility('XDAI')).toBe('Gnosis');
+   expect(chainNameDataCompatibility('BNB Smart Chain (BEP20)')).toBe('BNB Smart Chain');
+   expect(chainNameDataCompatibility('Optimistic')).toBe('OP Mainnet');
+   expect(chainNameDataCompatibility('Arbitrum')).toBe('Arbitrum One');
+   expect(chainNameDataCompatibility('Ethereum')).toBe('Ethereum');
+ });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 857c75a and 01a7b8e.

⛔ Files ignored due to path filters (2)
  • src/apps/pillarx-app/components/MediaGridCollection/tests/__snapshots__/DisplayCollectionImage.test.tsx.snap is excluded by !**/*.snap
  • src/apps/pillarx-app/components/PointsTile/test/__snapshots__/PointsTile.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • src/apps/the-exchange/components/SelectDropdown/test/SelectDropdown.test.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: unit-tests
  • GitHub Check: build
  • GitHub Check: Cloudflare Pages

@github-actions github-actions bot temporarily deployed to Preview (feat/arbitrum-optimism-bnb-implementation) March 26, 2025 15:24 Inactive
@github-actions github-actions bot temporarily deployed to Preview (feat/arbitrum-optimism-bnb-implementation) March 26, 2025 17:22 Inactive
Copy link
Collaborator

@IAmKio IAmKio left a comment

Choose a reason for hiding this comment

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

LGTM

@github-actions github-actions bot temporarily deployed to Preview (feat/arbitrum-optimism-bnb-implementation) March 26, 2025 17:36 Inactive
@RanaBug RanaBug merged commit ebf7db0 into staging Mar 26, 2025
7 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Sep 8, 2025
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants