diff --git a/src/getNetworkName.ts b/src/getNetworkName.ts new file mode 100644 index 0000000..87cf4ab --- /dev/null +++ b/src/getNetworkName.ts @@ -0,0 +1,22 @@ +import networks from "./networks"; + +export const getNetworkName = (alias: string): string | null => { + const lowerCaseAlias = alias.toLowerCase(); + for (const networkKey in networks) { + const network = networks[networkKey as keyof typeof networks] as { + chain_aliases?: string[]; + }; + if ( + network.chain_aliases && + network.chain_aliases.some( + (networkAlias) => networkAlias.toLowerCase() === lowerCaseAlias + ) + ) { + return networkKey; + } + if (networkKey.toLowerCase() === lowerCaseAlias) { + return networkKey; + } + } + return null; +};