Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
spsjvc committed Oct 3, 2024
1 parent 7ea184d commit 6cb1b2a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/types/ParentChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { chains, nitroTestnodeL3 } from '../chains';
export type ParentChain = Exclude<(typeof chains)[number], { id: typeof nitroTestnodeL3.id }>;
export type ParentChainId = ParentChain['id'];

export function isValidParentChainId(
parentChainId: number | undefined,
): parentChainId is ParentChainId {
function isValidParentChainId(parentChainId: number | undefined): parentChainId is ParentChainId {
const ids = chains
// exclude nitro-testnode L3 from the list of parent chains
.filter((chain) => chain.id !== nitroTestnodeL3.id)
Expand Down
10 changes: 4 additions & 6 deletions src/utils/getParentChainFromId.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { extractChain } from 'viem';
import { ParentChain, isValidParentChainId } from '../types/ParentChain';

import { chains } from '../chains';
import { ParentChain, validateParentChain } from '../types/ParentChain';

export function getParentChainFromId(chainId: number): ParentChain {
// Just throws if the chainId is not valid
if (!isValidParentChainId(chainId)) {
throw new Error(`Parent chain not supported: ${chainId}`);
}
const parentChainId = validateParentChain(chainId);

return extractChain({
chains,
id: chainId,
id: parentChainId,
}) as ParentChain;
}

0 comments on commit 6cb1b2a

Please sign in to comment.