Skip to content

Commit

Permalink
chore: Suggestion on simplifying type guard (#4912)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gudahtt authored Nov 8, 2024
1 parent 43cddcc commit 693ee5c
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions packages/multichain/src/scope/supported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
KnownWalletNamespaceRpcMethods,
KnownWalletRpcMethods,
} from './constants';
import type { NonWalletKnownCaipNamespace, ExternalScopeString } from './types';
import type { ExternalScopeString } from './types';
import { parseScopeString } from './types';

/**
Expand Down Expand Up @@ -112,11 +112,15 @@ export const isSupportedNotification = (
): boolean => {
const { namespace } = parseScopeString(scopeString);

if (!namespace || !isNonWalletKnownCaipNamespace(namespace)) {
if (
!namespace ||
!isKnownCaipNamespace(namespace) ||
namespace === KnownCaipNamespace.Wallet
) {
return false;
}

return (KnownNotifications[namespace] || []).includes(notification);
return KnownNotifications[namespace].includes(notification);
};

/**
Expand All @@ -134,19 +138,3 @@ function isKnownCaipNamespace(

return knownNamespaces.includes(namespace);
}

/**
* Checks whether the given namespace is a known non-wallet CAIP namespace.
*
* @param namespace - The namespace to check
* @returns Whether the given namespace is a known non-wallet CAIP namespace.
*/
function isNonWalletKnownCaipNamespace(
namespace: string,
): namespace is NonWalletKnownCaipNamespace {
const knownNamespaces = Object.keys(KnownCaipNamespace)
.filter((key) => key !== KnownCaipNamespace.Wallet)
.map((key) => key.toLowerCase());

return knownNamespaces.includes(namespace);
}

0 comments on commit 693ee5c

Please sign in to comment.