Skip to content

Commit

Permalink
feat: getNetworkName
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Oct 13, 2023
1 parent 13ea194 commit 9032a48
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/getNetworkName.ts
Original file line number Diff line number Diff line change
@@ -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;
};

0 comments on commit 9032a48

Please sign in to comment.