Skip to content

Commit

Permalink
replace isSnapId usage
Browse files Browse the repository at this point in the history
  • Loading branch information
hmalik88 committed Dec 25, 2024
1 parent 768716d commit 05e6441
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 32 deletions.
7 changes: 3 additions & 4 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,13 @@ import {
TransactionType,
} from '@metamask/transaction-controller';

///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
import {
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
getLocalizedSnapManifest,
stripSnapPrefix,
///: END:ONLY_INCLUDE_IF
isSnapId,
} from '@metamask/snaps-utils';
///: END:ONLY_INCLUDE_IF

import { Interface } from '@ethersproject/abi';
import { abiERC1155, abiERC721 } from '@metamask/metamask-eth-abis';
Expand Down Expand Up @@ -245,8 +246,6 @@ import {
} from '../../shared/lib/transactions-controller-utils';
import { getProviderConfig } from '../../shared/modules/selectors/networks';
import { endTrace, trace } from '../../shared/lib/trace';
// eslint-disable-next-line import/no-restricted-paths
import { isSnapId } from '../../ui/helpers/utils/snaps';
import { BridgeStatusAction } from '../../shared/types/bridge-status';
import { ENVIRONMENT } from '../../development/build/constants';
import fetchWithCache from '../../shared/lib/fetch-with-cache';
Expand Down
2 changes: 1 addition & 1 deletion ui/components/app/confirm/info/row/url.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useCallback, useState } from 'react';
import { isSnapId } from '@metamask/snaps-utils';
import {
Box,
Icon,
Expand All @@ -18,7 +19,6 @@ import {
} from '../../../../../helpers/constants/design-system';
import SnapAuthorshipPill from '../../../snaps/snap-authorship-pill';
import { SnapMetadataModal } from '../../../snaps/snap-metadata-modal';
import { isSnapId } from '../../../../../helpers/utils/snaps';

export type ConfirmInfoRowUrlProps = {
url: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { isSnapId } from '@metamask/snaps-utils';
import Button from '../../ui/button';
import { AvatarFavicon, IconSize } from '../../component-library';
import { stripHttpsSchemeWithoutPort } from '../../../helpers/utils/util';
import SiteOrigin from '../../ui/site-origin';
import { Size } from '../../../helpers/constants/design-system';
import { isSnapId } from '../../../helpers/utils/snaps';
import { SnapIcon } from '../snaps/snap-icon';

export default class ConnectedSitesList extends Component {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import React from 'react';
import PropTypes from 'prop-types';
import { useSelector } from 'react-redux';
import { getSnapPrefix, stripSnapPrefix } from '@metamask/snaps-utils';
import {
getSnapPrefix,
isSnapId,
stripSnapPrefix,
} from '@metamask/snaps-utils';
import {
getSnap,
getSnapRegistryData,
Expand Down Expand Up @@ -39,7 +43,6 @@ import { ShowMore } from '../show-more';
import SnapExternalPill from '../snap-version/snap-external-pill';
import { useSafeWebsite } from '../../../../hooks/snaps/useSafeWebsite';
import Tooltip from '../../../ui/tooltip';
import { isSnapId } from '../../../../helpers/utils/snaps';
import { SnapIcon } from '../snap-icon';

export const SnapMetadataModal = ({ snapId, isOpen, onClose }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useEffect, useRef, useState } from 'react';
import { useHistory } from 'react-router-dom';
import { useSelector } from 'react-redux';
import { isSnapId } from '@metamask/snaps-utils';
import { Content, Header, Page } from '../page';
import {
Box,
Expand All @@ -26,7 +27,6 @@ import {
REVIEW_PERMISSIONS,
} from '../../../../helpers/constants/routes';
import { getConnectedSitesListWithNetworkInfo } from '../../../../selectors';
import { isSnapId } from '../../../../helpers/utils/snaps';
import { ConnectionListItem } from './connection-list-item';

export const PermissionsPage = () => {
Expand Down
16 changes: 0 additions & 16 deletions ui/helpers/utils/snaps.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
import { SnapId } from '@metamask/snaps-sdk';
import { isProduction } from '../../../shared/modules/environment';

/**
* Check if the given value is a valid snap ID.
*
* NOTE: This function is a duplicate oF a yet to be released version in @metamask/snaps-utils.
*
* @param value - The value to check.
* @returns `true` if the value is a valid snap ID, and `false` otherwise.
*/
export function isSnapId(value: unknown): value is SnapId {
return (
(typeof value === 'string' || value instanceof String) &&
(value.startsWith('local:') || value.startsWith('npm:'))
);
}

/**
* Decode a snap ID fron a pathname.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { useSelector } from 'react-redux';

import { isSnapId } from '@metamask/snaps-utils';
import {
ConfirmInfoRowText,
ConfirmInfoRowUrl,
Expand All @@ -27,7 +28,6 @@ import {
TextColor,
TextVariant,
} from '../../../../../../helpers/constants/design-system';
import { isSnapId } from '../../../../../../helpers/utils/snaps';
import {
hexToText,
sanitizeString,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';

import { isSnapId } from '@metamask/snaps-utils';
import { ConfirmInfoAlertRow } from '../../../../../../components/app/confirm/info/row/alert-row/alert-row';
import {
ConfirmInfoRow,
Expand All @@ -14,7 +15,6 @@ import {
import { useConfirmContext } from '../../../../context/confirm';
import { ConfirmInfoRowTypedSignDataV1 } from '../../row/typed-sign-data-v1/typedSignDataV1';
import { ConfirmInfoSection } from '../../../../../../components/app/confirm/info/row/section';
import { isSnapId } from '../../../../../../helpers/utils/snaps';
import { SigningInWithRow } from '../shared/sign-in-with-row/sign-in-with-row';

const TypedSignV1Info: React.FC = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { isValidAddress } from 'ethereumjs-util';

import { isSnapId } from '@metamask/snaps-utils';
import { ConfirmInfoAlertRow } from '../../../../../../components/app/confirm/info/row/alert-row/alert-row';
import { parseTypedDataMessage } from '../../../../../../../shared/modules/transaction.utils';
import { RowAlertKey } from '../../../../../../components/app/confirm/info/row/constants';
Expand All @@ -21,7 +22,6 @@ import {
import { useConfirmContext } from '../../../../context/confirm';
import { useTypesSignSimulationEnabledInfo } from '../../../../hooks/useTypesSignSimulationEnabledInfo';
import { ConfirmInfoRowTypedSignData } from '../../row/typed-sign-data/typedSignData';
import { isSnapId } from '../../../../../../helpers/utils/snaps';
import { SigningInWithRow } from '../shared/sign-in-with-row/sign-in-with-row';
import { TypedSignV4Simulation } from './typed-sign-v4-simulation';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { Component } from 'react';
import { Switch, Route } from 'react-router-dom';
import { providerErrors, serializeError } from '@metamask/rpc-errors';
import { SubjectType } from '@metamask/permission-controller';
import { isSnapId } from '@metamask/snaps-utils';
// TODO: Remove restricted import
// eslint-disable-next-line import/no-restricted-paths
import { isEthAddress } from '../../../app/scripts/lib/multichain/address';
Expand All @@ -19,7 +20,6 @@ import {
// TODO: Remove restricted import
// eslint-disable-next-line import/no-restricted-paths
import { PermissionNames } from '../../../app/scripts/controllers/permissions';
import { isSnapId } from '../../helpers/utils/snaps';
import ChooseAccount from './choose-account';
import PermissionsRedirect from './redirect';
import SnapsConnect from './snaps/snaps-connect';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import PropTypes from 'prop-types';
import React, { useCallback, useState } from 'react';
import { useSelector } from 'react-redux';
import { isSnapId } from '@metamask/snaps-utils';
import { PageContainerFooter } from '../../../../components/ui/page-container';
import { useI18nContext } from '../../../../hooks/useI18nContext';
import SnapInstallWarning from '../../../../components/app/snaps/snap-install-warning';
Expand Down Expand Up @@ -34,7 +35,6 @@ import { useOriginMetadata } from '../../../../hooks/useOriginMetadata';
import { getSnapMetadata, getSnapsMetadata } from '../../../../selectors';
import { getSnapName } from '../../../../helpers/utils/util';
import PermissionConnectHeader from '../../../../components/app/permission-connect-header';
import { isSnapId } from '../../../../helpers/utils/snaps';

export default function SnapInstall({
request,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useCallback, useState } from 'react';
import { useSelector } from 'react-redux';
import PropTypes from 'prop-types';
import { isSnapId } from '@metamask/snaps-utils';
import { useI18nContext } from '../../../../hooks/useI18nContext';
import { Box, IconSize, Text } from '../../../../components/component-library';
import {
Expand All @@ -26,7 +27,6 @@ import {
getSnapMetadata,
} from '../../../../selectors';
import { useOriginMetadata } from '../../../../hooks/useOriginMetadata';
import { isSnapId } from '../../../../helpers/utils/snaps';
import { SnapIcon } from '../../../../components/app/snaps/snap-icon';

export default function SnapsConnect({
Expand Down
2 changes: 1 addition & 1 deletion ui/pages/snaps/snap-view/snap-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useDispatch, useSelector } from 'react-redux';
import PropTypes from 'prop-types';
import { useHistory } from 'react-router-dom';
import semver from 'semver';
import { isSnapId } from '@metamask/snaps-utils';
import { useI18nContext } from '../../../hooks/useI18nContext';
import {
BackgroundColor,
Expand Down Expand Up @@ -51,7 +52,6 @@ import { DelineatorType } from '../../../helpers/constants/snaps';
import SnapUpdateAlert from '../../../components/app/snaps/snap-update-alert';
import { CONNECT_ROUTE } from '../../../helpers/constants/routes';
import { ShowMore } from '../../../components/app/snaps/show-more';
import { isSnapId } from '../../../helpers/utils/snaps';
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
import { KeyringSnapRemovalResultStatus } from './constants';
///: END:ONLY_INCLUDE_IF
Expand Down

0 comments on commit 05e6441

Please sign in to comment.