From bf7aa7a2c35fdb2b1332d3c18ea98570b97341bc Mon Sep 17 00:00:00 2001 From: Kami Date: Tue, 5 Dec 2023 04:31:35 +0330 Subject: [PATCH] Create getChainName.ts --- packages/snap/src/util/getChainName.ts | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 packages/snap/src/util/getChainName.ts diff --git a/packages/snap/src/util/getChainName.ts b/packages/snap/src/util/getChainName.ts new file mode 100644 index 0000000..97b2e4f --- /dev/null +++ b/packages/snap/src/util/getChainName.ts @@ -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(); +}