diff --git a/packages/snap/src/util/getEndpoint.ts b/packages/snap/src/util/getEndpoint.ts index 43a4967..a5e90ce 100644 --- a/packages/snap/src/util/getEndpoint.ts +++ b/packages/snap/src/util/getEndpoint.ts @@ -2,16 +2,26 @@ // SPDX-License-Identifier: Apache-2.0 import { createWsEndpoints } from '@polkadot/apps-config'; +import getChainName from './getChainName'; // eslint-disable-next-line jsdoc/require-jsdoc export default function getEndpoint( _genesisHash: string | undefined, ): string | undefined { + if (!_genesisHash) { + console.info('_genesisHash should not be undefined'); + return undefined; + } const allEndpoints = createWsEndpoints(() => ''); + const chainName = getChainName(_genesisHash); const endpoints = allEndpoints?.filter( - ({ genesisHash, value }) => - String(genesisHash) === _genesisHash && Boolean(value), + (e) => + e.value && + (String(e.info)?.toLowerCase() === chainName || + String(e.text) + ?.toLowerCase() + ?.includes(chainName || '')), ); return ( diff --git a/packages/snap/src/util/getLogo.ts b/packages/snap/src/util/getLogo.ts index 45be49a..26722d8 100644 --- a/packages/snap/src/util/getLogo.ts +++ b/packages/snap/src/util/getLogo.ts @@ -1,15 +1,19 @@ // Copyright 2019-2023 @polkadot/extension-polkagate authors & contributors // SPDX-License-Identifier: Apache-2.0 -/* eslint-disable jsdoc/require-jsdoc */ import { createWsEndpoints } from '@polkadot/apps-config'; +import getChainName from './getChainName'; const endpoints = createWsEndpoints(() => ''); +/** + * @param _genesisHash + * @description get logo of a chain based on its genesisHash + */ export default function getLogo(_genesisHash: string): string { - const endpoint = endpoints.find( - ({ genesisHash }) => _genesisHash === genesisHash, - ); + const chainName = getChainName(_genesisHash); + + const endpoint = endpoints.find((o) => o.info?.toLowerCase() === chainName); return endpoint?.ui?.logo as string; }