From 9032a48d261621ea3e39c49774e87765a021df90 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Fri, 13 Oct 2023 12:03:08 +0400 Subject: [PATCH] feat: getNetworkName --- src/getNetworkName.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/getNetworkName.ts 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; +};