Skip to content

Commit

Permalink
fix undefined genesisHash issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-1979 committed Dec 5, 2023
1 parent bf7aa7a commit e12cdc7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
14 changes: 12 additions & 2 deletions packages/snap/src/util/getEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
12 changes: 8 additions & 4 deletions packages/snap/src/util/getLogo.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit e12cdc7

Please sign in to comment.