Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Suggestion on simplifying type guard #4912

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Loading