Skip to content

Commit

Permalink
Create getChainName.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-1979 committed Dec 5, 2023
1 parent c4c8b7b commit bf7aa7a
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/snap/src/util/getChainName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2019-2023 @polkadot/extension-polkagate authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { getChain } from '../chains';

export const sanitizeChainName = (chainName: string | undefined) =>
chainName
?.replace(' Relay Chain', '')
?.replace(' Network', '')
?.replace(' chain', '')
?.replace(' Chain', '')
?.replace(' Finance', '')
?.replace(/\s/g, '');

// eslint-disable-next-line jsdoc/require-jsdoc
export default function getChainName(
_genesisHash: string | undefined,
): string | undefined {
if (!_genesisHash) {
console.info('_genesisHash should not be undefined');
return undefined;
}
const chainName =
getChain(_genesisHash)?.displayName || getChain(_genesisHash)?.network;

console.info('chainName is:', chainName);

return sanitizeChainName(chainName)?.toLowerCase();
}

0 comments on commit bf7aa7a

Please sign in to comment.