Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Deploying x402-exec with
|
| Latest commit: |
3b326e8
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://8de837cf.x402-exec.pages.dev |
| Branch Preview URL: | https://refactor-network-ids.x402-exec.pages.dev |
There was a problem hiding this comment.
Pull request overview
This PR refactors network identifier handling by renaming functions and variables to better reflect their purpose as "aliases" for v1 compatibility rather than canonical "names". The changes improve code clarity by explicitly distinguishing between CAIP-2 identifiers (the canonical v2 format) and human-readable aliases (v1 legacy names).
Key Changes:
- Renamed
getNetworkName→getNetworkAliasto clarify that these are v1 compatibility aliases, not canonical names - Renamed
getSupportedNetworkNames→getSupportedNetworkAliasesfor consistency - Renamed
getSupportedNetworksV2→getSupportedNetworkIdsto better describe CAIP-2 identifiers - Updated network configuration keys from human-readable names to CAIP-2 format internally
- Removed
legacy-compat.tsfile containing unused legacy compatibility shims
Reviewed changes
Copilot reviewed 19 out of 21 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
typescript/packages/facilitator-sdk/test/settlement.test.ts |
Updated mock function name from getNetworkName to getNetworkAlias |
typescript/packages/facilitator-sdk/test/integration.test.ts |
Updated mock function name from getNetworkName to getNetworkAlias |
typescript/packages/facilitator-sdk/test/facilitator.test.ts |
Updated mock function name from getNetworkName to getNetworkAlias |
typescript/packages/facilitator-sdk/src/types.d.ts |
Updated type declaration for renamed function |
typescript/packages/facilitator-sdk/src/settlement.ts |
Updated function imports and variable names to use "alias" terminology |
typescript/packages/extensions/src/utils.ts |
Updated function import and variable names for network alias handling |
typescript/packages/extensions/src/networks.ts |
Refactored to use CAIP-2 as internal keys with normalization function; renamed exports to use "alias" terminology |
typescript/packages/extensions/src/network-utils.ts |
Renamed constants and functions to use "alias" terminology; moved NETWORK_ALIASES_V1_TO_V2 definition earlier as primary mapping |
typescript/packages/extensions/src/network-utils.test.ts |
Updated test to use toCanonicalNetworkKey instead of removed getNetworkId |
typescript/packages/extensions/src/network-alignment.test.ts |
Updated function calls from getSupportedNetworksV2 to getSupportedNetworkIds |
typescript/packages/extensions/src/legacy-compat.ts |
Removed entire file containing unused legacy compatibility shims |
typescript/packages/extensions/src/index.ts |
Updated exports to reflect renamed functions and removed legacy compatibility exports |
typescript/packages/extensions/src/hooks/transfer.ts |
Updated documentation and function signature to accept both CAIP-2 and human-readable names |
typescript/packages/extensions/src/hooks/demo.ts |
Updated documentation and function signatures to accept both identifier formats |
typescript/packages/extensions/src/chains.ts |
Refactored to normalize network identifiers internally using NETWORK_ALIASES_V1_TO_V2 |
facilitator/test/unit/token-validation.test.ts |
Updated error message expectation from "Unsupported network" to "Unknown network" |
facilitator/src/types.d.ts |
Updated type declaration for renamed function |
facilitator/src/network-utils.ts |
Updated function import and usage from getNetworkName to getNetworkAlias |
examples/showcase/server/src/index.ts |
Updated function calls from getSupportedNetworksV2 to getSupportedNetworkIds |
examples/showcase/client/src/wagmi.config.ts |
Updated function call from getSupportedNetworkNames to getSupportedNetworkAliases |
examples/showcase/client/src/config.ts |
Updated function call from getSupportedNetworkNames to getSupportedNetworkAliases |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| function normalizeToCAIP2(network: string | Network): Network { | ||
| // Already CAIP-2 format | ||
| if (network.startsWith('eip155:')) { | ||
| return network as Network; | ||
| } | ||
| // Convert from human-readable name using alias mapping | ||
| const caip2 = NETWORK_ALIASES_V1_TO_V2[network]; | ||
| if (!caip2) { | ||
| throw new Error( | ||
| `Unknown network: ${network}. ` + | ||
| `Supported networks: ${Object.keys(NETWORK_ALIASES_V1_TO_V2).join(", ")}` | ||
| ); | ||
| } | ||
| return caip2; | ||
| } |
There was a problem hiding this comment.
The normalizeToCAIP2 function accepts any string starting with 'eip155:' without validating whether it's actually a supported network. This could lead to undefined behavior when an unsupported CAIP-2 identifier is passed. Consider validating that the CAIP-2 identifier exists in NETWORK_ALIASES_V1_TO_V2 values or the networks configuration.
| export function getChain(network: string | Network): Chain { | ||
| let chainId: number; | ||
|
|
||
| // If already CAIP-2 format, extract chainId directly | ||
| if (network.startsWith('eip155:')) { | ||
| chainId = parseInt(network.split(":")[1]); | ||
| } else { | ||
| // Convert name to CAIP-2, then extract chainId | ||
| const caip2 = NETWORK_ALIASES_V1_TO_V2[network]; | ||
| if (!caip2) { | ||
| throw new Error( | ||
| `Unknown network: ${network}. ` + | ||
| `Supported networks: ${Object.keys(NETWORK_ALIASES_V1_TO_V2).join(", ")}` | ||
| ); | ||
| } | ||
| chainId = parseInt(caip2.split(":")[1]); | ||
| } |
There was a problem hiding this comment.
The getChain function accepts any CAIP-2 identifier starting with 'eip155:' without validating whether it's a supported network in NETWORK_ALIASES_V1_TO_V2. This means unsupported chain IDs could pass through if they exist in viem's chain list but aren't configured in the application. Consider validating the CAIP-2 identifier against NETWORK_ALIASES before extracting the chain ID to ensure consistency with the supported networks configuration.
No description provided.