Skip to content

Commit

Permalink
Merge branch 'main' into temp/message-manager-transition
Browse files Browse the repository at this point in the history
  • Loading branch information
OGPoyraz authored Jan 6, 2025
2 parents 49d2bb7 + 4ee7e3f commit 4174afe
Show file tree
Hide file tree
Showing 19 changed files with 43 additions and 53 deletions.
5 changes: 5 additions & 0 deletions app/scripts/constants/sentry-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export const SENTRY_BACKGROUND_STATE = {
},
AuthenticationController: {
isSignedIn: false,
sessionData: {
profile: true,
accessToken: false,
expiresIn: true,
},
},
NetworkOrderController: {
orderedNetworkList: [],
Expand Down
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
7 changes: 7 additions & 0 deletions test/e2e/tests/metrics/errors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,13 @@ describe('Sentry errors', function () {
// the "resetState" method
swapsFeatureFlags: true,
},
// Part of the AuthenticationController store, but initialized as undefined
// Only populated once the client is authenticated
sessionData: {
accessToken: false,
expiresIn: true,
profile: true,
},
// This can get erased due to a bug in the app state controller's
// preferences state change handler
timeoutMinutes: true,
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
Expand Up @@ -87,6 +87,7 @@ export const SnapUIFooterButton: FunctionComponent<
alignItems: AlignItems.center,
flexDirection: FlexDirection.Row,
}}
data-theme={null}
>
{isSnapAction && !hideSnapBranding && !loading && (
<SnapIcon snapId={snapId} avatarSize={IconSize.Sm} marginRight={2} />
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
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import configureMockStore from 'redux-mock-store';
import { TransactionType } from '@metamask/transaction-controller';

import { isSnapId } from '@metamask/snaps-utils';
import {
getMockConfirmState,
getMockPersonalSignConfirmState,
Expand All @@ -13,7 +14,6 @@ import {
signatureRequestSIWE,
unapprovedPersonalSignMsg,
} from '../../../../../../../test/data/confirmations/personal_sign';
import * as snapUtils from '../../../../../../helpers/utils/snaps';
import { SignatureRequestType } from '../../../../types/confirm';
import * as utils from '../../../../utils';
import PersonalSignInfo from './personal-sign';
Expand Down Expand Up @@ -43,13 +43,10 @@ jest.mock('../../../../../../../node_modules/@metamask/snaps-utils', () => {
...originalUtils,
stripSnapPrefix: jest.fn().mockReturnValue('@metamask/examplesnap'),
getSnapPrefix: jest.fn().mockReturnValue('npm:'),
isSnapId: jest.fn(),
};
});

jest.mock('../../../../../../helpers/utils/snaps', () => ({
isSnapId: jest.fn(),
}));

describe('PersonalSignInfo', () => {
it('renders correctly for personal sign request', () => {
const state = getMockPersonalSignConfirmState();
Expand Down Expand Up @@ -149,7 +146,7 @@ describe('PersonalSignInfo', () => {
getMockPersonalSignConfirmStateForRequest(signatureRequestSIWE);

(utils.isSIWESignatureRequest as jest.Mock).mockReturnValue(false);
(snapUtils.isSnapId as unknown as jest.Mock).mockReturnValue(true);
(isSnapId as unknown as jest.Mock).mockReturnValue(true);

const mockStore = configureMockStore([])(state);
const { queryByText, getByText } = renderWithConfirmContextProvider(
Expand All @@ -171,7 +168,7 @@ describe('PersonalSignInfo', () => {
const state =
getMockPersonalSignConfirmStateForRequest(signatureRequestSIWE);
(utils.isSIWESignatureRequest as jest.Mock).mockReturnValue(false);
(snapUtils.isSnapId as unknown as jest.Mock).mockReturnValue(true);
(isSnapId as unknown as jest.Mock).mockReturnValue(true);

const mockStore = configureMockStore([])(state);
const { getByText, queryByText } = renderWithConfirmContextProvider(
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
Expand Up @@ -2,10 +2,10 @@ import React from 'react';
import configureMockStore from 'redux-mock-store';
import { TransactionType } from '@metamask/transaction-controller';

import { isSnapId } from '@metamask/snaps-utils';
import { renderWithConfirmContextProvider } from '../../../../../../../test/lib/confirmations/render-helpers';
import { getMockTypedSignConfirmStateForRequest } from '../../../../../../../test/data/confirmations/helper';
import { unapprovedTypedSignMsgV1 } from '../../../../../../../test/data/confirmations/typed_sign';
import * as snapUtils from '../../../../../../helpers/utils/snaps';
import TypedSignInfoV1 from './typed-sign-v1';

jest.mock(
Expand All @@ -25,13 +25,10 @@ jest.mock('../../../../../../../node_modules/@metamask/snaps-utils', () => {
...originalUtils,
stripSnapPrefix: jest.fn().mockReturnValue('@metamask/examplesnap'),
getSnapPrefix: jest.fn().mockReturnValue('npm:'),
isSnapId: jest.fn(),
};
});

jest.mock('../../../../../../helpers/utils/snaps', () => ({
isSnapId: jest.fn(),
}));

describe('TypedSignInfo', () => {
it('correctly renders typed sign data request', () => {
const mockState = getMockTypedSignConfirmStateForRequest(
Expand Down Expand Up @@ -65,7 +62,7 @@ describe('TypedSignInfo', () => {
type: TransactionType.signTypedData,
chainId: '0x5',
});
(snapUtils.isSnapId as unknown as jest.Mock).mockReturnValue(true);
(isSnapId as unknown as jest.Mock).mockReturnValue(true);
const mockStore = configureMockStore([])(mockState);
const { queryByText } = renderWithConfirmContextProvider(
<TypedSignInfoV1 />,
Expand All @@ -88,7 +85,7 @@ describe('TypedSignInfo', () => {
type: TransactionType.signTypedData,
chainId: '0x5',
});
(snapUtils.isSnapId as unknown as jest.Mock).mockReturnValue(false);
(isSnapId as unknown as jest.Mock).mockReturnValue(false);
const mockStore = configureMockStore([])(mockState);
const { queryByText } = renderWithConfirmContextProvider(
<TypedSignInfoV1 />,
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
Expand Up @@ -5,6 +5,7 @@ import {
TransactionType,
} from '@metamask/transaction-controller';

import { isSnapId } from '@metamask/snaps-utils';
import {
getMockConfirmStateForTransaction,
getMockTypedSignConfirmState,
Expand All @@ -17,7 +18,6 @@ import {
unapprovedTypedSignMsgV4,
} from '../../../../../../../test/data/confirmations/typed_sign';
import { renderWithConfirmContextProvider } from '../../../../../../../test/lib/confirmations/render-helpers';
import * as snapUtils from '../../../../../../helpers/utils/snaps';
import TypedSignInfo from './typed-sign';

jest.mock(
Expand All @@ -44,13 +44,10 @@ jest.mock('../../../../../../../node_modules/@metamask/snaps-utils', () => {
...originalUtils,
stripSnapPrefix: jest.fn().mockReturnValue('@metamask/examplesnap'),
getSnapPrefix: jest.fn().mockReturnValue('npm:'),
isSnapId: jest.fn(),
};
});

jest.mock('../../../../../../helpers/utils/snaps', () => ({
isSnapId: jest.fn(),
}));

describe('TypedSignInfo', () => {
it('renders origin for typed sign data request', () => {
const state = getMockTypedSignConfirmState();
Expand Down Expand Up @@ -153,7 +150,7 @@ describe('TypedSignInfo', () => {
type: TransactionType.signTypedData,
chainId: '0x5',
});
(snapUtils.isSnapId as unknown as jest.Mock).mockReturnValue(true);
(isSnapId as unknown as jest.Mock).mockReturnValue(true);
const mockStore = configureMockStore([])(mockState);
const { queryByText } = renderWithConfirmContextProvider(
<TypedSignInfo />,
Expand All @@ -177,7 +174,7 @@ describe('TypedSignInfo', () => {
type: TransactionType.signTypedData,
chainId: '0x5',
});
(snapUtils.isSnapId as unknown as jest.Mock).mockReturnValue(false);
(isSnapId as unknown as jest.Mock).mockReturnValue(false);
const mockStore = configureMockStore([])(mockState);
const { queryByText } = renderWithConfirmContextProvider(
<TypedSignInfo />,
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 4174afe

Please sign in to comment.