Support both chain slug and chain id in multichain page parameters#3338
Support both chain slug and chain id in multichain page parameters#3338
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. To trigger a review, include ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
There was a problem hiding this comment.
Pull request overview
Adds multichain routing support so chain identifiers in path/query can be resolved by either chain slug or chain id, improving link stability when slugs change.
Changes:
- Introduces a shared resolver (
getChainIdFromSlugOrId) and updates multichain context + SSR chain resolution to accept slug-or-id. - Renames multichain route param from
chain_slugtochain_slug_or_idacross routes, navigation highlighting, Mixpanel page typing, and metadata template maps. - Updates multichain page entry points and search redirects to generate/use the new route param.
Reviewed changes
Copilot reviewed 25 out of 29 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| ui/token/TokenDetails.tsx | Updates token tab navigation to push multichain token route using chain_slug_or_id. |
| ui/multichain/tx/MultichainTx.tsx | Resolves chain by slug or id from chain_slug_or_id param before providing chain context. |
| ui/multichain/tokenInstance/MultichainTokenInstance.tsx | Resolves chain by slug or id from chain_slug_or_id param for NFT instance page. |
| ui/multichain/token/MultichainToken.tsx | Resolves chain by slug or id from chain_slug_or_id param for token page. |
| ui/multichain/searchResults/useSearchRedirect.tsx | Updates redirects to use /chain/[chain_slug_or_id]/... routes and query key. |
| ui/multichain/block/MultichainBlock.tsx | Resolves chain by slug or id from chain_slug_or_id param for block page. |
| pages/chain/[chain_slug_or_id]/visualize/sol2uml.tsx | Adds multichain Sol2UML route entry point. |
| pages/chain/[chain_slug_or_id]/tx/[hash]/index.tsx | Updates multichain tx page wrapper to use the new param name in pathname. |
| pages/chain/[chain_slug_or_id]/token/[hash]/instance/[id].tsx | Adds multichain token instance route wrapper under new param name. |
| pages/chain/[chain_slug_or_id]/token/[hash]/index.tsx | Adds multichain token route wrapper under new param name. |
| pages/chain/[chain_slug_or_id]/op/[hash].tsx | Updates multichain user-op page wrapper pathname. |
| pages/chain/[chain_slug_or_id]/csv-export/index.tsx | Updates multichain CSV export page wrapper pathname. |
| pages/chain/[chain_slug_or_id]/block/countdown/index.tsx | Updates multichain block countdown index wrapper pathname. |
| pages/chain/[chain_slug_or_id]/block/countdown/[height].tsx | Updates multichain block countdown wrapper pathname. |
| pages/chain/[chain_slug_or_id]/block/[height_or_hash].tsx | Updates multichain block page wrapper pathname. |
| pages/chain/[chain_slug_or_id]/advanced-filter/index.tsx | Updates multichain advanced filter wrapper pathname. |
| pages/chain/[chain_slug_or_id]/accounts/label/[slug].tsx | Updates multichain accounts-by-label wrapper pathname. |
| nextjs/routes.ts | Updates route helper to generate multichain-prefixed paths using chain_slug_or_id. |
| nextjs/nextjs-routes.d.ts | Regenerates route typings to replace chain_slug with chain_slug_or_id. |
| nextjs/getServerSideProps/utils.ts | Updates SSR multichain factory to resolve chain by slug or id from params. |
| lib/multichain/getChainValueFromQuery.ts | Updates query-to-chain resolution to use chain_slug_or_id and match by slug or id. |
| lib/multichain/getChainIdFromSlugOrId.ts | New shared helper to resolve chain id from slug-or-id input. |
| lib/multichain/getChainIdFromSlug.ts | Removes old slug-only resolver. |
| lib/mixpanel/getPageType.ts | Updates multichain route keys for Mixpanel page typing. |
| lib/metadata/templates/title.ts | Updates metadata title template keys to new multichain route param name. |
| lib/metadata/templates/description.ts | Updates metadata description template keys to new multichain route param name. |
| lib/metadata/getPageOgType.ts | Updates OG page type map keys to new multichain route param name. |
| lib/hooks/useNavItems.tsx | Updates nav active-route checks for multichain pathnames. |
| lib/contexts/multichain.tsx | Updates context initialization to resolve chain id from chain_slug_or_id via new helper. |
Comments suppressed due to low confidence (1)
lib/multichain/getChainValueFromQuery.ts:30
- The new slug-or-id resolution behavior here is untested. Adding unit tests for
getChainValueFromQuery(coveringchain_id,chain_slug_or_idas slug,chain_slug_or_idas id, and invalid values/precedence) would help prevent regressions in multichain routing/query handling.
const chainId = getQueryParamString(query.chain_id);
const chainSlugOrId = getQueryParamString(query.chain_slug_or_id);
if (chainId) {
if (config.chains.some((chain) => chain.id === chainId)) {
return chainId;
}
}
if (chainSlugOrId) {
const chain = config.chains.find((chain) => chain.slug === chainSlugOrId || chain.id === chainSlugOrId);
if (chain) {
return chain.id;
}
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description and Related Issue(s)
Resolves #3320
In multichain explorer mode, path segments and query parameters that identify a chain can use either the chain slug or the chain id, so links stay stable when slugs or display names change and stay aligned with backends that key on chain id.
Proposed Changes
getChainIdFromSlugOrId(replacing slug-only resolution) so a single path/query value is matched against configured chains by slug or id.getChainValueFromQuerysochain_slug_or_id(and related flow) resolves when the value is either a slug or an id.Multichain*page entry points, search redirect, token details, navigation, server-side props, and metadata/mixpanel page typing to use the shared resolution consistently.Breaking or Incompatible Changes
None intended. Existing slug-based URLs should behave as before; additional acceptance of chain id is additive.
Additional Information
Checklist for PR author