From 119b0d4c1b59309fcf60f1c6f4134c1f6573eb62 Mon Sep 17 00:00:00 2001
From: Jyoti Puri
Date: Thu, 22 Aug 2024 18:44:06 +0530
Subject: [PATCH 01/17] Adding context to get current confirmation
---
test/data/confirmations/helper.ts | 91 +++++++++++++++++++
test/lib/confirmations/render-helpers.tsx | 31 +++++++
ui/pages/confirmations/confirm/confirm.tsx | 55 +++++------
.../confirmations/context/confirm/index.tsx | 34 +++++++
4 files changed, 185 insertions(+), 26 deletions(-)
create mode 100644 test/data/confirmations/helper.ts
create mode 100644 test/lib/confirmations/render-helpers.tsx
create mode 100644 ui/pages/confirmations/context/confirm/index.tsx
diff --git a/test/data/confirmations/helper.ts b/test/data/confirmations/helper.ts
new file mode 100644
index 000000000000..8596060bf53e
--- /dev/null
+++ b/test/data/confirmations/helper.ts
@@ -0,0 +1,91 @@
+import { ApprovalType } from '@metamask/controller-utils';
+import {
+ TransactionStatus,
+ TransactionType,
+} from '@metamask/transaction-controller';
+
+import mockState from '../mock-state.json';
+
+type RootState = { metamask: Record } & Record<
+ string,
+ unknown
+>;
+
+export const getExampleMockSignatureConfirmState = (
+ args: RootState = { metamask: {} },
+) => ({
+ ...mockState,
+ ...args,
+ metamask: {
+ ...mockState.metamask,
+ preferences: {
+ redesignedTransactionsEnabled: true,
+ redesignedConfirmationsEnabled: true,
+ isRedesignedConfirmationsDeveloperEnabled: true,
+ },
+ pendingApprovals: {
+ '123': {
+ id: '123',
+ type: ApprovalType.EthSignTypedData,
+ },
+ },
+ unapprovedTypedMessages: {
+ '123': {
+ id: '123',
+ chainId: mockState.metamask.providerConfig.chainId,
+ type: TransactionType.signTypedData,
+ status: TransactionStatus.unapproved,
+ txParams: { from: Object.keys(mockState.metamask.identities)[0] },
+ msgParams: {
+ signatureMethod: 'eth_signTypedData_v4'
+ }
+ },
+ },
+ ...args.metamask,
+ },
+});
+
+export const getExampleMockContractInteractionConfirmState = (
+ args: RootState = { metamask: {} },
+) => ({
+ ...mockState,
+ ...args,
+ metamask: {
+ ...mockState.metamask,
+ preferences: {
+ redesignedTransactionsEnabled: true,
+ redesignedConfirmationsEnabled: true,
+ isRedesignedConfirmationsDeveloperEnabled: true,
+ },
+ pendingApprovals: {
+ '123': {
+ id: '123',
+ type: ApprovalType.Transaction,
+ },
+ },
+ transactions: [
+ {
+ id: '123',
+ type: TransactionType.contractInteraction,
+ chainId: mockState.metamask.providerConfig.chainId,
+ status: TransactionStatus.unapproved,
+ txParams: { from: Object.keys(mockState.metamask.identities)[0] },
+ },
+ ],
+ ...args.metamask,
+ },
+});
+
+export const getMockConfirmState = (args: RootState = { metamask: {} }) => ({
+ ...mockState,
+ ...args,
+ metamask: {
+ ...mockState.metamask,
+ preferences: {
+ redesignedTransactionsEnabled: true,
+ redesignedConfirmationsEnabled: true,
+ isRedesignedConfirmationsDeveloperEnabled: true,
+ },
+ ...args.metamask,
+ },
+});
diff --git a/test/lib/confirmations/render-helpers.tsx b/test/lib/confirmations/render-helpers.tsx
new file mode 100644
index 000000000000..c123b3117ff8
--- /dev/null
+++ b/test/lib/confirmations/render-helpers.tsx
@@ -0,0 +1,31 @@
+import React, { ReactElement } from 'react';
+
+import { ConfirmContextProvider } from '../../../ui/pages/confirmations/context/confirm';
+import { renderHookWithProvider, renderWithProvider } from '../render-helpers';
+
+export function renderWithConfirmContextProvider(
+ component: ReactElement,
+ store: unknown,
+ pathname = '/',
+) {
+ return renderWithProvider(
+ {component},
+ store,
+ pathname,
+ );
+}
+
+export function renderHookWithConfirmContextProvider(
+ hook: () => unknown,
+ state: Record,
+ pathname = '/',
+ Container?: ReactElement,
+) {
+ const contextContainer = Container ? (
+ {Container}
+ ) : (
+ ConfirmContextProvider
+ );
+
+ return renderHookWithProvider(hook, state, pathname, contextContainer);
+}
diff --git a/ui/pages/confirmations/confirm/confirm.tsx b/ui/pages/confirmations/confirm/confirm.tsx
index 10907aeaa88c..8f98cef1e9a7 100644
--- a/ui/pages/confirmations/confirm/confirm.tsx
+++ b/ui/pages/confirmations/confirm/confirm.tsx
@@ -20,6 +20,7 @@ import EditGasFeePopover from '../components/edit-gas-fee-popover';
import { NetworkChangeToast } from '../components/confirm/network-change-toast';
import setCurrentConfirmation from '../hooks/setCurrentConfirmation';
import syncConfirmPath from '../hooks/syncConfirmPath';
+import { ConfirmContextProvider } from '../context/confirm';
const EIP1559TransactionGasModal = () => {
return (
@@ -35,32 +36,34 @@ const Confirm = () => {
syncConfirmPath();
return (
-
- {/* This context should be removed once we implement the new edit gas fees popovers */}
-
-
-
-
-
-
-
- {
- ///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
-
- ///: END:ONLY_INCLUDE_IF
- }
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+ {/* This context should be removed once we implement the new edit gas fees popovers */}
+
+
+
+
+
+
+
+ {
+ ///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
+
+ ///: END:ONLY_INCLUDE_IF
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
);
};
diff --git a/ui/pages/confirmations/context/confirm/index.tsx b/ui/pages/confirmations/context/confirm/index.tsx
new file mode 100644
index 000000000000..677ce49f272f
--- /dev/null
+++ b/ui/pages/confirmations/context/confirm/index.tsx
@@ -0,0 +1,34 @@
+import React, { ReactElement, createContext, useContext } from 'react';
+
+import useCurrentConfirmation from '../../hooks/useCurrentConfirmation';
+import { Confirmation } from '../../types/confirm';
+
+type ConfirmContextType = {
+ currentConfirmation: Confirmation;
+};
+
+export const ConfirmContext = createContext(
+ undefined,
+);
+
+export const ConfirmContextProvider: React.FC<{
+ children: ReactElement;
+}> = ({ children }) => {
+ const { currentConfirmation } = useCurrentConfirmation();
+
+ return (
+
+ {children}
+
+ );
+};
+
+export const useConfirmContext = () => {
+ const context = useContext(ConfirmContext);
+ if (!context) {
+ throw new Error(
+ 'useConfirmContext must be used within an ConfirmContextProvider',
+ );
+ }
+ return context;
+};
From 52c98911249394810085390f2a69bde1e7bc6486 Mon Sep 17 00:00:00 2001
From: Jyoti Puri
Date: Thu, 22 Aug 2024 18:44:06 +0530
Subject: [PATCH 02/17] Adding context to get current confirmation
---
.../blockaid-loading-indicator.test.tsx | 7 +-
.../blockaid-loading-indicator.tsx | 10 +-
.../header/__snapshots__/header.test.tsx.snap | 24 +-
.../confirm/header/header-info.test.tsx | 45 ++--
.../components/confirm/header/header-info.tsx | 9 +-
.../components/confirm/header/header.test.tsx | 49 ++---
.../__snapshots__/confirm.test.tsx.snap | 208 ++----------------
.../hooks/alerts/useBlockaidAlerts.test.ts | 95 ++++----
.../hooks/alerts/useBlockaidAlerts.ts | 29 ++-
.../hooks/useConfirmationAlerts.test.ts | 7 +-
.../hooks/useConfirmationNetworkInfo.test.ts | 92 +++++---
.../hooks/useConfirmationNetworkInfo.ts | 8 +-
.../useConfirmationRecipientInfo.test.ts | 24 +-
.../hooks/useConfirmationRecipientInfo.ts | 12 +-
...rentSignatureSecurityAlertResponse.test.ts | 53 +++++
...seCurrentSignatureSecurityAlertResponse.ts | 40 ++++
.../confirmations/selectors/confirm.test.ts | 37 +---
ui/pages/confirmations/selectors/confirm.ts | 27 +--
18 files changed, 317 insertions(+), 459 deletions(-)
create mode 100644 ui/pages/confirmations/hooks/useCurrentSignatureSecurityAlertResponse.test.ts
create mode 100644 ui/pages/confirmations/hooks/useCurrentSignatureSecurityAlertResponse.ts
diff --git a/ui/pages/confirmations/components/confirm/blockaid-loading-indicator/blockaid-loading-indicator.test.tsx b/ui/pages/confirmations/components/confirm/blockaid-loading-indicator/blockaid-loading-indicator.test.tsx
index d370b263427c..8589e38bf8ff 100644
--- a/ui/pages/confirmations/components/confirm/blockaid-loading-indicator/blockaid-loading-indicator.test.tsx
+++ b/ui/pages/confirmations/components/confirm/blockaid-loading-indicator/blockaid-loading-indicator.test.tsx
@@ -7,7 +7,7 @@ import {
import mockState from '../../../../../../test/data/mock-state.json';
import { BlockaidResultType } from '../../../../../../shared/constants/security-provider';
-import { renderWithProvider } from '../../../../../../test/lib/render-helpers';
+import { renderWithConfirmContextProvider } from '../../../../../../test/lib/confirmations/render-helpers';
import { SecurityAlertResponse } from '../../../types/confirm';
import BlockaidLoadingIndicator from './blockaid-loading-indicator';
@@ -55,7 +55,10 @@ const render = (
};
const defaultStore = configureStore()(mockExpectedState);
- return renderWithProvider(, defaultStore);
+ return renderWithConfirmContextProvider(
+ ,
+ defaultStore,
+ );
};
describe('BlockaidLoadingIndicator', () => {
diff --git a/ui/pages/confirmations/components/confirm/blockaid-loading-indicator/blockaid-loading-indicator.tsx b/ui/pages/confirmations/components/confirm/blockaid-loading-indicator/blockaid-loading-indicator.tsx
index 49f9c8b199cd..add69251a2a8 100644
--- a/ui/pages/confirmations/components/confirm/blockaid-loading-indicator/blockaid-loading-indicator.tsx
+++ b/ui/pages/confirmations/components/confirm/blockaid-loading-indicator/blockaid-loading-indicator.tsx
@@ -1,16 +1,12 @@
import React from 'react';
-import { useSelector } from 'react-redux';
-
import Preloader from '../../../../../components/ui/icon/preloader';
import { BlockaidResultType } from '../../../../../../shared/constants/security-provider';
import { Box } from '../../../../../components/component-library';
-
-import { currentSignatureRequestSecurityResponseSelector } from '../../../selectors';
+import useCurrentSignatureSecurityAlertResponse from '../../../hooks/useCurrentSignatureSecurityAlertResponse';
const BlockaidLoadingIndicator = () => {
- const signatureSecurityAlertResponse = useSelector(
- currentSignatureRequestSecurityResponseSelector,
- );
+ const signatureSecurityAlertResponse =
+ useCurrentSignatureSecurityAlertResponse();
if (
signatureSecurityAlertResponse?.result_type !== BlockaidResultType.Loading
diff --git a/ui/pages/confirmations/components/confirm/header/__snapshots__/header.test.tsx.snap b/ui/pages/confirmations/components/confirm/header/__snapshots__/header.test.tsx.snap
index 2d1ac826aa65..afc71c0f6917 100644
--- a/ui/pages/confirmations/components/confirm/header/__snapshots__/header.test.tsx.snap
+++ b/ui/pages/confirmations/components/confirm/header/__snapshots__/header.test.tsx.snap
@@ -20,7 +20,7 @@ exports[`Header should match snapshot with signature confirmation 1`] = `
style="height: 32px; width: 32px; border-radius: 16px;"
>
+ >
+ Chain 5
+
{
const store = configureStore(mockStore);
- return renderWithProvider(
, store);
+ return renderWithConfirmContextProvider(
, store);
};
describe('Header', () => {
@@ -95,7 +76,7 @@ describe('Header', () => {
cases.forEach(({ description, store, expectedEvent }) => {
it(`sends "${MetaMetricsEventName.AccountDetailsOpened}" metametric ${description}`, () => {
const mockTrackEvent = jest.fn();
- const { getByLabelText } = renderWithProvider(
+ const { getByLabelText } = renderWithConfirmContextProvider(
,
diff --git a/ui/pages/confirmations/components/confirm/header/header-info.tsx b/ui/pages/confirmations/components/confirm/header/header-info.tsx
index b4aeb4e255ad..ec286413a70e 100644
--- a/ui/pages/confirmations/components/confirm/header/header-info.tsx
+++ b/ui/pages/confirmations/components/confirm/header/header-info.tsx
@@ -39,10 +39,7 @@ import {
TextVariant,
} from '../../../../../helpers/constants/design-system';
import { useI18nContext } from '../../../../../hooks/useI18nContext';
-import {
- currentConfirmationSelector,
- getUseBlockie,
-} from '../../../../../selectors';
+import { getUseBlockie } from '../../../../../selectors';
import { setConfirmationAdvancedDetailsOpen } from '../../../../../store/actions';
import { useBalance } from '../../../hooks/useBalance';
import useConfirmationRecipientInfo from '../../../hooks/useConfirmationRecipientInfo';
@@ -50,6 +47,7 @@ import { selectConfirmationAdvancedDetailsOpen } from '../../../selectors/prefer
import { SignatureRequestType } from '../../../types/confirm';
import { REDESIGN_TRANSACTION_TYPES } from '../../../utils';
import { isSignatureTransactionType } from '../../../utils/confirm';
+import { useConfirmContext } from '../../../context/confirm';
const HeaderInfo = () => {
const dispatch = useDispatch();
@@ -66,7 +64,8 @@ const HeaderInfo = () => {
dispatch(setConfirmationAdvancedDetailsOpen(value));
};
- const currentConfirmation = useSelector(currentConfirmationSelector);
+ const { currentConfirmation } = useConfirmContext();
+
const { senderAddress: fromAddress, senderName: fromName } =
useConfirmationRecipientInfo();
diff --git a/ui/pages/confirmations/components/confirm/header/header.test.tsx b/ui/pages/confirmations/components/confirm/header/header.test.tsx
index a4cb88c78e4c..13475fa42ab0 100644
--- a/ui/pages/confirmations/components/confirm/header/header.test.tsx
+++ b/ui/pages/confirmations/components/confirm/header/header.test.tsx
@@ -1,52 +1,33 @@
import { fireEvent, waitFor } from '@testing-library/react';
import React from 'react';
+import { DefaultRootState } from 'react-redux';
+
import {
- DEPOSIT_METHOD_DATA,
- genUnapprovedContractInteractionConfirmation,
-} from '../../../../../../test/data/confirmations/contract-interaction';
-import { unapprovedPersonalSignMsg } from '../../../../../../test/data/confirmations/personal_sign';
-import mockState from '../../../../../../test/data/mock-state.json';
-import { renderWithProvider } from '../../../../../../test/jest';
+ getExampleMockContractInteractionConfirmState,
+ getExampleMockSignatureConfirmState,
+} from '../../../../../../test/data/confirmations/helper';
+import { renderWithConfirmContextProvider } from '../../../../../../test/lib/confirmations/render-helpers';
import configureStore from '../../../../../store/store';
import Header from './header';
-const render = (storeOverrides = {}) => {
- const store = configureStore({
- metamask: {
- ...mockState.metamask,
- useNonceField: true,
- },
- confirm: {
- currentConfirmation: {
- msgParams: {
- from: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
- },
- },
- },
- ...storeOverrides,
- });
+const render = (
+ state: DefaultRootState = getExampleMockSignatureConfirmState(),
+) => {
+ const store = configureStore(state);
- return renderWithProvider(
, store);
+ return renderWithConfirmContextProvider(
, store);
};
describe('Header', () => {
it('should match snapshot with signature confirmation', () => {
- const { container } = render({
- confirm: { currentConfirmation: unapprovedPersonalSignMsg },
- });
-
+ const { container } = render(getExampleMockSignatureConfirmState());
expect(container).toMatchSnapshot();
});
it('should match snapshot with transaction confirmation', () => {
- const { container } = render({
- confirm: {
- currentConfirmation: genUnapprovedContractInteractionConfirmation({
- address: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
- txData: DEPOSIT_METHOD_DATA,
- }),
- },
- });
+ const { container } = render(
+ getExampleMockContractInteractionConfirmState(),
+ );
expect(container).toMatchSnapshot();
});
diff --git a/ui/pages/confirmations/confirm/__snapshots__/confirm.test.tsx.snap b/ui/pages/confirmations/confirm/__snapshots__/confirm.test.tsx.snap
index 2b394a6786b4..c74a3d30790a 100644
--- a/ui/pages/confirmations/confirm/__snapshots__/confirm.test.tsx.snap
+++ b/ui/pages/confirmations/confirm/__snapshots__/confirm.test.tsx.snap
@@ -19,53 +19,13 @@ exports[`Confirm matches snapshot for signature - personal sign type 1`] = `
class="mm-box mm-box--margin-top-2 mm-box--display-flex"
>
+ class="identicon__image-border"
+ style="height: 32px; width: 32px; border-radius: 16px;"
+ />
- C
+ ?
- Chain 5
-
+ />
+ class="identicon__image-border"
+ style="height: 32px; width: 32px; border-radius: 16px;"
+ />
- C
+ ?
- Chain 5
-
+ />
+ class="identicon__image-border"
+ style="height: 32px; width: 32px; border-radius: 16px;"
+ />
- C
+ ?
- Chain 5
-
+ />
+ class="identicon__image-border"
+ style="height: 32px; width: 32px; border-radius: 16px;"
+ />
- C
+ ?
- Chain 5
-
+ />
) =>
+ getMockConfirmState({
+ metamask: {
+ unapprovedPersonalMsgs: {
+ '1': { ...currentConfirmationMock, msgParams: {} },
},
+ pendingApprovals: {
+ '1': {
+ ...currentConfirmationMock,
+ origin: 'origin',
+ requestData: {},
+ requestState: null,
+ expectsResult: false,
+ },
+ },
+ signatureSecurityAlertResponses: {
+ 'test-id-mock': mockSecurityAlertResponse,
+ },
+ ...args,
},
- preferences: { redesignedConfirmationsEnabled: true },
- signatureSecurityAlertResponses: {
- 'test-id-mock': mockSecurityAlertResponse,
- },
- },
- confirm: { currentConfirmation: currentConfirmationMock },
-};
+ });
const EXPECTED_ALERT = {
key: mockSecurityAlertResponse.securityAlertId,
@@ -58,8 +62,8 @@ const EXPECTED_ALERT = {
};
describe('useBlockaidAlerts', () => {
- it('returns an empty array when there is no current confirmation', () => {
- const { result } = renderHookWithProvider(
+ it('returns an empty array when there is no confirmation', () => {
+ const { result } = renderHookWithConfirmContextProvider(
() => useBlockaidAlert(),
mockState,
);
@@ -67,15 +71,15 @@ describe('useBlockaidAlerts', () => {
});
it('returns alerts when there is a valid PersonalSign confirmation with a security alert response', () => {
- const { result } = renderHookWithProvider(() => useBlockaidAlert(), {
- ...mockExpectedState,
- metamask: {
- ...mockExpectedState.metamask,
- signatureSecurityAlertResponses: {
- 'test-id-mock': mockSecurityAlertResponse,
- },
+ const mockCurrentState = getMockCurrentState({
+ signatureSecurityAlertResponses: {
+ 'test-id-mock': mockSecurityAlertResponse,
},
});
+ const { result } = renderHookWithConfirmContextProvider(
+ () => useBlockaidAlert(),
+ mockCurrentState,
+ );
expect(result.current).toHaveLength(1);
expect(result.current[0].reportUrl).toBeDefined();
@@ -84,18 +88,29 @@ describe('useBlockaidAlerts', () => {
});
it('returns alerts if confirmation is contract interaction with security alert response', () => {
- const { result } = renderHookWithProvider(() => useBlockaidAlert(), {
- ...mockExpectedState,
- metamask: {
- ...mockState.metamask,
- transactions: [
- {
- securityAlertResponse: mockSecurityAlertResponse,
- },
- ],
+ const mockCurrentState = getMockCurrentState({
+ pendingApprovals: {
+ '1': {
+ id: '1',
+ type: ApprovalType.Transaction,
+ },
},
+ transactions: [
+ {
+ id: '1',
+ type: TransactionType.contractInteraction,
+ chainId: '0x5',
+ securityAlertResponse: mockSecurityAlertResponse,
+ status: TransactionStatus.unapproved,
+ },
+ ],
});
+ const { result } = renderHookWithConfirmContextProvider(
+ () => useBlockaidAlert(),
+ mockCurrentState,
+ );
+
expect(result.current).toHaveLength(1);
expect(result.current[0].reportUrl).toBeDefined();
delete result.current[0].reportUrl;
diff --git a/ui/pages/confirmations/hooks/alerts/useBlockaidAlerts.ts b/ui/pages/confirmations/hooks/alerts/useBlockaidAlerts.ts
index 525e70f9f363..6c3d88291e66 100644
--- a/ui/pages/confirmations/hooks/alerts/useBlockaidAlerts.ts
+++ b/ui/pages/confirmations/hooks/alerts/useBlockaidAlerts.ts
@@ -21,11 +21,12 @@ import {
SIGNATURE_TRANSACTION_TYPES,
} from '../../utils';
import {
- currentConfirmationSelector,
- currentSignatureRequestSecurityResponseSelector,
-} from '../../selectors';
-import { SecurityAlertResponse } from '../../types/confirm';
+ SecurityAlertResponse,
+ SignatureRequestType,
+} from '../../types/confirm';
+import { useConfirmContext } from '../../context/confirm';
import { normalizeProviderAlert } from './utils';
+import useCurrentSignatureSecurityAlertResponse from '../useCurrentSignatureSecurityAlertResponse';
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
const zlib = require('zlib');
@@ -49,22 +50,17 @@ type SecurityAlertResponsesState = {
const useBlockaidAlerts = (): Alert[] => {
const t = useI18nContext();
-
- const currentConfirmation = useSelector(
- currentConfirmationSelector,
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- ) as Record
;
-
+ const { currentConfirmation } = useConfirmContext();
const selectorChainId = useSelector(getCurrentChainId);
- const securityAlertId = currentConfirmation?.securityAlertResponse
- ?.securityAlertId as string;
+ const securityAlertId = (
+ currentConfirmation?.securityAlertResponse as SecurityAlertResponse
+ )?.securityAlertId as string;
const transactionType = currentConfirmation?.type as TransactionType;
- const signatureSecurityAlertResponse = useSelector(
- currentSignatureRequestSecurityResponseSelector,
- );
+ const signatureSecurityAlertResponse =
+ useCurrentSignatureSecurityAlertResponse();
const transactionSecurityAlertResponse = useSelector(
(state: SecurityAlertResponsesState) =>
@@ -95,7 +91,8 @@ const useBlockaidAlerts = (): Alert[] => {
reason,
result_type: resultType,
} = securityAlertResponse as SecurityAlertResponse;
- const { chainId, msgParams, origin, type, txParams } = currentConfirmation;
+ const { chainId, msgParams, origin, type, txParams } =
+ currentConfirmation as SignatureRequestType & TransactionMeta;
const isFailedResultType = resultType === BlockaidResultType.Errored;
diff --git a/ui/pages/confirmations/hooks/useConfirmationAlerts.test.ts b/ui/pages/confirmations/hooks/useConfirmationAlerts.test.ts
index 2d7e2abc7e0d..4b2545b19cda 100644
--- a/ui/pages/confirmations/hooks/useConfirmationAlerts.test.ts
+++ b/ui/pages/confirmations/hooks/useConfirmationAlerts.test.ts
@@ -1,10 +1,13 @@
-import { renderHookWithProvider } from '../../../../test/lib/render-helpers';
+import { renderHookWithConfirmContextProvider } from '../../../../test/lib/confirmations/render-helpers';
import mockState from '../../../../test/data/mock-state.json';
import useConfirmationAlerts from './useConfirmationAlerts';
describe('useConfirmationAlerts', () => {
it('returns empty array if no alerts', () => {
- const { result } = renderHookWithProvider(useConfirmationAlerts, mockState);
+ const { result } = renderHookWithConfirmContextProvider(
+ useConfirmationAlerts,
+ mockState,
+ );
expect(result.current).toEqual([]);
});
});
diff --git a/ui/pages/confirmations/hooks/useConfirmationNetworkInfo.test.ts b/ui/pages/confirmations/hooks/useConfirmationNetworkInfo.test.ts
index 741e30394ec0..94e392f4615f 100644
--- a/ui/pages/confirmations/hooks/useConfirmationNetworkInfo.test.ts
+++ b/ui/pages/confirmations/hooks/useConfirmationNetworkInfo.test.ts
@@ -1,5 +1,12 @@
+import { ApprovalType } from '@metamask/controller-utils';
+import { TransactionType } from '@metamask/transaction-controller';
+
import mockState from '../../../../test/data/mock-state.json';
-import { renderHookWithProvider } from '../../../../test/lib/render-helpers';
+import {
+ getExampleMockSignatureConfirmState,
+ getMockConfirmState,
+} from '../../../../test/data/confirmations/helper';
+import { renderHookWithConfirmContextProvider } from '../../../../test/lib/confirmations/render-helpers';
import useConfirmationNetworkInfo from './useConfirmationNetworkInfo';
describe('useConfirmationNetworkInfo', () => {
@@ -10,18 +17,26 @@ describe('useConfirmationNetworkInfo', () => {
ticker: 'ETH',
type: 'mainnet',
};
- const { result } = renderHookWithProvider(
+ const { result } = renderHookWithConfirmContextProvider(
() => useConfirmationNetworkInfo(),
- {
- ...mockState,
+ getMockConfirmState({
metamask: {
- ...mockState.metamask,
providerConfig,
+ pendingApprovals: {
+ 123: {
+ id: 123,
+ type: ApprovalType.EthSignTypedData,
+ },
+ },
+ unapprovedTypedMessages: {
+ 123: {
+ id: 123,
+ chainId: '0x1',
+ type: TransactionType.signTypedData,
+ },
+ },
},
- confirm: {
- currentConfirmation: { id: '1', chainId: '0x1' },
- },
- },
+ }),
);
expect(result.current.networkDisplayName).toBe('Ethereum Mainnet');
@@ -29,12 +44,10 @@ describe('useConfirmationNetworkInfo', () => {
});
it('returns display name and image for custom network', () => {
- const { result } = renderHookWithProvider(
+ const { result } = renderHookWithConfirmContextProvider(
() => useConfirmationNetworkInfo(),
- {
- ...mockState,
+ getExampleMockSignatureConfirmState({
metamask: {
- ...mockState.metamask,
providerConfig: {
chainId: '0x7',
type: 'rpc',
@@ -53,11 +66,21 @@ describe('useConfirmationNetworkInfo', () => {
},
},
},
+ pendingApprovals: {
+ 123: {
+ id: 123,
+ type: ApprovalType.EthSignTypedData,
+ },
+ },
+ unapprovedTypedMessages: {
+ 123: {
+ id: 123,
+ chainId: '0x7',
+ type: TransactionType.signTypedData,
+ },
+ },
},
- confirm: {
- currentConfirmation: { id: '1', msgParams: {} },
- },
- },
+ }),
);
expect(result.current.networkDisplayName).toBe('Custom Mainnet RPC');
@@ -65,20 +88,15 @@ describe('useConfirmationNetworkInfo', () => {
});
it('should return empty strings if no matching network is found', () => {
- const { result } = renderHookWithProvider(
+ const { result } = renderHookWithConfirmContextProvider(
() => useConfirmationNetworkInfo(),
- {
- ...mockState,
+ getExampleMockSignatureConfirmState({
metamask: {
- ...mockState.metamask,
providerConfig: {
chainId: '0x7',
},
},
- confirm: {
- currentConfirmation: { id: '1', msgParams: {} },
- },
- },
+ }),
);
expect(result.current.networkDisplayName).toBe('');
@@ -104,22 +122,30 @@ describe('useConfirmationNetworkInfo', () => {
ticker: 'ETH',
type: 'rpc',
};
- const { result } = renderHookWithProvider(
+ const { result } = renderHookWithConfirmContextProvider(
() => useConfirmationNetworkInfo(),
- {
- ...mockState,
+ getMockConfirmState({
metamask: {
- ...mockState.metamask,
providerConfig,
networkConfigurations: {
...mockState.metamask.networkConfigurations,
[customNetwork.id]: customNetwork,
},
+ pendingApprovals: {
+ 123: {
+ id: 123,
+ type: ApprovalType.EthSignTypedData,
+ },
+ },
+ unapprovedTypedMessages: {
+ 123: {
+ id: 123,
+ chainId: '0x1',
+ type: TransactionType.signTypedData,
+ },
+ },
},
- confirm: {
- currentConfirmation: { id: '1', chainId: '0x1' },
- },
- },
+ }),
);
expect(result.current.networkDisplayName).toBe('Flashbots Protect');
diff --git a/ui/pages/confirmations/hooks/useConfirmationNetworkInfo.ts b/ui/pages/confirmations/hooks/useConfirmationNetworkInfo.ts
index 64fbd815d645..1fab535733a1 100644
--- a/ui/pages/confirmations/hooks/useConfirmationNetworkInfo.ts
+++ b/ui/pages/confirmations/hooks/useConfirmationNetworkInfo.ts
@@ -5,19 +5,17 @@ import {
NETWORK_TYPES,
} from '../../../../shared/constants/network';
-import {
- currentConfirmationSelector,
- getAllNetworks,
-} from '../../../selectors';
+import { getAllNetworks } from '../../../selectors';
import { getProviderConfig } from '../../../ducks/metamask/metamask';
import { useI18nContext } from '../../../hooks/useI18nContext';
+import { useConfirmContext } from '../context/confirm';
type KeyOfNetworkName = keyof typeof NETWORK_TO_NAME_MAP;
function useConfirmationNetworkInfo() {
const t = useI18nContext();
- const currentConfirmation = useSelector(currentConfirmationSelector);
+ const { currentConfirmation } = useConfirmContext();
const allNetworks = useSelector(getAllNetworks);
const providerConfig = useSelector(getProviderConfig);
diff --git a/ui/pages/confirmations/hooks/useConfirmationRecipientInfo.test.ts b/ui/pages/confirmations/hooks/useConfirmationRecipientInfo.test.ts
index 9f945230af0c..bb560419509e 100644
--- a/ui/pages/confirmations/hooks/useConfirmationRecipientInfo.test.ts
+++ b/ui/pages/confirmations/hooks/useConfirmationRecipientInfo.test.ts
@@ -1,5 +1,8 @@
-import mockState from '../../../../test/data/mock-state.json';
-import { renderHookWithProvider } from '../../../../test/lib/render-helpers';
+import {
+ getExampleMockSignatureConfirmState,
+ getMockConfirmState,
+} from '../../../../test/data/confirmations/helper';
+import { renderHookWithConfirmContextProvider } from '../../../../test/lib/confirmations/render-helpers';
import { getInternalAccountByAddress } from '../../../selectors';
import useConfirmationRecipientInfo from './useConfirmationRecipientInfo';
@@ -8,17 +11,10 @@ const SenderAddress = '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc';
describe('useConfirmationRecipientInfo', () => {
describe('when the current confirmation is a signature', () => {
it('returns the account name of the from address as the recipient name', () => {
- const { result } = renderHookWithProvider(
+ const mockState = getExampleMockSignatureConfirmState();
+ const { result } = renderHookWithConfirmContextProvider(
() => useConfirmationRecipientInfo(),
- {
- ...mockState,
- confirm: {
- currentConfirmation: {
- id: '1',
- msgParams: { from: SenderAddress },
- },
- },
- },
+ mockState,
);
const expectedAccount = getInternalAccountByAddress(
@@ -32,9 +28,9 @@ describe('useConfirmationRecipientInfo', () => {
});
it('returns empty strings if there if current confirmation is not defined', () => {
- const { result } = renderHookWithProvider(
+ const { result } = renderHookWithConfirmContextProvider(
() => useConfirmationRecipientInfo(),
- mockState,
+ getMockConfirmState(),
);
expect(result.current.senderAddress).toBe('');
diff --git a/ui/pages/confirmations/hooks/useConfirmationRecipientInfo.ts b/ui/pages/confirmations/hooks/useConfirmationRecipientInfo.ts
index 2db770f76843..61ffac7f8eb5 100644
--- a/ui/pages/confirmations/hooks/useConfirmationRecipientInfo.ts
+++ b/ui/pages/confirmations/hooks/useConfirmationRecipientInfo.ts
@@ -1,17 +1,11 @@
import { useSelector } from 'react-redux';
import { getAccountByAddress } from '../../../helpers/utils/util';
-import {
- accountsWithSendEtherInfoSelector,
- currentConfirmationSelector,
-} from '../../../selectors';
+import { accountsWithSendEtherInfoSelector } from '../../../selectors';
import { getConfirmationSender } from '../components/confirm/utils';
-import { Confirmation } from '../types/confirm';
+import { useConfirmContext } from '../context/confirm';
function useConfirmationRecipientInfo() {
- const currentConfirmation = useSelector(
- currentConfirmationSelector,
- ) as Confirmation;
-
+ const { currentConfirmation } = useConfirmContext();
const allAccounts = useSelector(accountsWithSendEtherInfoSelector);
let senderAddress, senderName;
diff --git a/ui/pages/confirmations/hooks/useCurrentSignatureSecurityAlertResponse.test.ts b/ui/pages/confirmations/hooks/useCurrentSignatureSecurityAlertResponse.test.ts
new file mode 100644
index 000000000000..eefc84eefd2e
--- /dev/null
+++ b/ui/pages/confirmations/hooks/useCurrentSignatureSecurityAlertResponse.test.ts
@@ -0,0 +1,53 @@
+import { ApprovalType } from '@metamask/controller-utils';
+
+import { renderHookWithConfirmContextProvider } from '../../../../test/lib/confirmations/render-helpers';
+import { getMockConfirmState } from '../../../../test/data/confirmations/helper';
+import { BlockaidResultType } from '../../../../shared/constants/security-provider';
+import { SecurityAlertResponse } from '../types/confirm';
+import useCurrentSignatureSecurityAlertResponse from './useCurrentSignatureSecurityAlertResponse';
+
+const mockSecurityAlertResponse: SecurityAlertResponse = {
+ securityAlertId: 'test-id-mock',
+ reason: 'test-reason',
+ result_type: BlockaidResultType.Malicious,
+ features: ['Feature 1', 'Feature 2'],
+};
+
+const currentConfirmationMock = {
+ id: '1',
+ status: 'unapproved',
+ time: new Date().getTime(),
+ type: ApprovalType.PersonalSign,
+ securityAlertResponse: mockSecurityAlertResponse,
+};
+
+const getMockCurrentState = () =>
+ getMockConfirmState({
+ metamask: {
+ unapprovedPersonalMsgs: {
+ '1': { ...currentConfirmationMock, msgParams: {} },
+ },
+ pendingApprovals: {
+ '1': {
+ ...currentConfirmationMock,
+ origin: 'origin',
+ requestData: {},
+ requestState: null,
+ expectsResult: false,
+ },
+ },
+ signatureSecurityAlertResponses: {
+ 'test-id-mock': mockSecurityAlertResponse,
+ },
+ },
+ });
+
+describe('useCurrentSignatureSecurityAlertResponse', () => {
+ it('returns security alert response for current signature request', () => {
+ const { result } = renderHookWithConfirmContextProvider(
+ () => useCurrentSignatureSecurityAlertResponse(),
+ getMockCurrentState(),
+ );
+ expect(result.current).toEqual(mockSecurityAlertResponse);
+ });
+});
diff --git a/ui/pages/confirmations/hooks/useCurrentSignatureSecurityAlertResponse.ts b/ui/pages/confirmations/hooks/useCurrentSignatureSecurityAlertResponse.ts
new file mode 100644
index 000000000000..f17e6618e280
--- /dev/null
+++ b/ui/pages/confirmations/hooks/useCurrentSignatureSecurityAlertResponse.ts
@@ -0,0 +1,40 @@
+import { useSelector } from 'react-redux';
+import { TransactionMeta } from '@metamask/transaction-controller';
+
+import { SecurityAlertResponse } from '../types/confirm';
+import { useConfirmContext } from '../context/confirm';
+
+type SecurityAlertResponsesState = {
+ metamask: {
+ signatureSecurityAlertResponses: Record;
+ transactions: TransactionMeta[];
+ };
+};
+
+const useCurrentSignatureSecurityAlertResponse = ():
+ | SecurityAlertResponse
+ | undefined => {
+ const { currentConfirmation } = useConfirmContext();
+
+ const securityAlertId = (
+ currentConfirmation?.securityAlertResponse as SecurityAlertResponse
+ )?.securityAlertId as string;
+
+ const signatureSecurityAlertResponse = useSelector(
+ (state: SecurityAlertResponsesState) => {
+ const signatureSecurityAlertId = (
+ currentConfirmation?.securityAlertResponse as SecurityAlertResponse
+ )?.securityAlertId;
+ if (securityAlertId === undefined) {
+ return undefined;
+ }
+ return state.metamask.signatureSecurityAlertResponses?.[
+ signatureSecurityAlertId as string
+ ];
+ },
+ );
+
+ return signatureSecurityAlertResponse;
+};
+
+export default useCurrentSignatureSecurityAlertResponse;
diff --git a/ui/pages/confirmations/selectors/confirm.test.ts b/ui/pages/confirmations/selectors/confirm.test.ts
index e3f95e24265a..a0c1a76d3347 100644
--- a/ui/pages/confirmations/selectors/confirm.test.ts
+++ b/ui/pages/confirmations/selectors/confirm.test.ts
@@ -1,25 +1,14 @@
import { ApprovalType } from '@metamask/controller-utils';
import { TransactionType } from '@metamask/transaction-controller';
-import {
- BlockaidReason,
- BlockaidResultType,
-} from '../../../../shared/constants/security-provider';
-import { ConfirmMetamaskState, SecurityAlertResponse } from '../types/confirm';
+import { ConfirmMetamaskState } from '../types/confirm';
import {
currentConfirmationSelector,
- currentSignatureRequestSecurityResponseSelector,
getIsRedesignedConfirmationsDeveloperEnabled,
latestPendingConfirmationSelector,
pendingConfirmationsSelector,
} from './confirm';
-const SECURITY_ALERT_RESPONSE_MOCK: SecurityAlertResponse = {
- securityAlertId: '1',
- result_type: BlockaidResultType.Malicious,
- reason: BlockaidReason.permitFarming,
-};
-
describe('confirm selectors', () => {
const mockedState: ConfirmMetamaskState = {
confirm: {
@@ -89,30 +78,6 @@ describe('confirm selectors', () => {
});
});
- describe('currentSignatureRequestSecurityResponseSelector', () => {
- it('should return SecurityAlertResponse for current signature', () => {
- const sigMockState: ConfirmMetamaskState = {
- confirm: {
- currentConfirmation: {
- id: '1',
- type: TransactionType.personalSign,
- securityAlertResponse: SECURITY_ALERT_RESPONSE_MOCK,
- },
- },
- metamask: {
- pendingApprovals: {},
- approvalFlows: [],
- signatureSecurityAlertResponses: { 1: SECURITY_ALERT_RESPONSE_MOCK },
- },
- };
-
- const result =
- currentSignatureRequestSecurityResponseSelector(sigMockState);
-
- expect(result).toStrictEqual(SECURITY_ALERT_RESPONSE_MOCK);
- });
- });
-
describe('#getIsRedesignedConfirmationsDeveloperEnabled', () => {
it('returns true if redesigned confirmations developer setting is enabled', () => {
const mockState = {
diff --git a/ui/pages/confirmations/selectors/confirm.ts b/ui/pages/confirmations/selectors/confirm.ts
index 5b9d9968ee73..cb0c7f50a591 100644
--- a/ui/pages/confirmations/selectors/confirm.ts
+++ b/ui/pages/confirmations/selectors/confirm.ts
@@ -2,13 +2,8 @@ import { ApprovalType } from '@metamask/controller-utils';
import { createSelector } from 'reselect';
import { getPendingApprovals } from '../../../selectors/approvals';
-import {
- ConfirmMetamaskState,
- Confirmation,
- SecurityAlertResponse,
-} from '../types/confirm';
+import { ConfirmMetamaskState } from '../types/confirm';
import { createDeepEqualSelector } from '../../../selectors/util';
-import { isSignatureTransactionType } from '../utils';
import { getPreferences } from '../../../selectors/selectors';
const ConfirmationApprovalTypes = [
@@ -49,26 +44,6 @@ export const confirmSelector = (state: ConfirmMetamaskState) => state.confirm;
export const currentConfirmationSelector = (state: ConfirmMetamaskState) =>
state.confirm.currentConfirmation;
-export const currentSignatureRequestSecurityResponseSelector = (
- state: ConfirmMetamaskState,
-) => {
- const currentConfirmation: Confirmation | undefined =
- currentConfirmationSelector(state);
-
- if (
- !currentConfirmation ||
- !isSignatureTransactionType(currentConfirmation)
- ) {
- return undefined;
- }
-
- const securityAlertId = (
- currentConfirmation?.securityAlertResponse as SecurityAlertResponse
- )?.securityAlertId as string;
-
- return state.metamask.signatureSecurityAlertResponses?.[securityAlertId];
-};
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function getIsRedesignedConfirmationsDeveloperEnabled(state: any) {
return getPreferences(state).isRedesignedConfirmationsDeveloperEnabled;
From eb5c1adc92e0999176e5ae1046d8c3a1ffb3398e Mon Sep 17 00:00:00 2001
From: Jyoti Puri
Date: Thu, 22 Aug 2024 21:59:27 +0530
Subject: [PATCH 03/17] update
---
.../blockaid-loading-indicator/blockaid-loading-indicator.tsx | 1 +
.../confirmations/components/confirm/header/header.test.tsx | 4 ++--
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/ui/pages/confirmations/components/confirm/blockaid-loading-indicator/blockaid-loading-indicator.tsx b/ui/pages/confirmations/components/confirm/blockaid-loading-indicator/blockaid-loading-indicator.tsx
index add69251a2a8..6459855599b3 100644
--- a/ui/pages/confirmations/components/confirm/blockaid-loading-indicator/blockaid-loading-indicator.tsx
+++ b/ui/pages/confirmations/components/confirm/blockaid-loading-indicator/blockaid-loading-indicator.tsx
@@ -1,4 +1,5 @@
import React from 'react';
+
import Preloader from '../../../../../components/ui/icon/preloader';
import { BlockaidResultType } from '../../../../../../shared/constants/security-provider';
import { Box } from '../../../../../components/component-library';
diff --git a/ui/pages/confirmations/components/confirm/header/header.test.tsx b/ui/pages/confirmations/components/confirm/header/header.test.tsx
index 13475fa42ab0..ce3eb0b84d12 100644
--- a/ui/pages/confirmations/components/confirm/header/header.test.tsx
+++ b/ui/pages/confirmations/components/confirm/header/header.test.tsx
@@ -14,13 +14,13 @@ const render = (
state: DefaultRootState = getExampleMockSignatureConfirmState(),
) => {
const store = configureStore(state);
-
return renderWithConfirmContextProvider(, store);
};
describe('Header', () => {
it('should match snapshot with signature confirmation', () => {
- const { container } = render(getExampleMockSignatureConfirmState());
+ const { container } = render();
+
expect(container).toMatchSnapshot();
});
From 392aab8a7dd168554d19d440d9d2b5f81465aa17 Mon Sep 17 00:00:00 2001
From: Jyoti Puri
Date: Thu, 22 Aug 2024 22:00:02 +0530
Subject: [PATCH 04/17] update
---
test/data/confirmations/helper.ts | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/test/data/confirmations/helper.ts b/test/data/confirmations/helper.ts
index 8596060bf53e..a1ad1f299c62 100644
--- a/test/data/confirmations/helper.ts
+++ b/test/data/confirmations/helper.ts
@@ -37,8 +37,8 @@ export const getExampleMockSignatureConfirmState = (
status: TransactionStatus.unapproved,
txParams: { from: Object.keys(mockState.metamask.identities)[0] },
msgParams: {
- signatureMethod: 'eth_signTypedData_v4'
- }
+ signatureMethod: 'eth_signTypedData_v4',
+ },
},
},
...args.metamask,
From 61fd4be0e817d0297070bcbd19c8e8944407a9d3 Mon Sep 17 00:00:00 2001
From: Jyoti Puri
Date: Thu, 22 Aug 2024 22:58:55 +0530
Subject: [PATCH 05/17] update
---
.../confirm/header/header.stories.tsx | 24 ++++++++-----------
.../hooks/alerts/useBlockaidAlerts.ts | 2 +-
2 files changed, 11 insertions(+), 15 deletions(-)
diff --git a/ui/pages/confirmations/components/confirm/header/header.stories.tsx b/ui/pages/confirmations/components/confirm/header/header.stories.tsx
index 31b383b4139b..69f1e9878605 100644
--- a/ui/pages/confirmations/components/confirm/header/header.stories.tsx
+++ b/ui/pages/confirmations/components/confirm/header/header.stories.tsx
@@ -1,28 +1,24 @@
import React from 'react';
import { Provider } from 'react-redux';
-import mockState from '../../../../../../test/data/mock-state.json';
+import { getExampleMockSignatureConfirmState } from '../../../../../../test/data/confirmations/helper';
import configureStore from '../../../../../store/store';
import Header from './header';
+import { ConfirmContextProvider } from '../../../context/confirm';
-const store = configureStore({
- metamask: {
- ...mockState.metamask,
- },
- confirm: {
- currentConfirmation: {
- msgParams: {
- from: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
- },
- },
- },
-});
+const store = configureStore(getExampleMockSignatureConfirmState);
const Story = {
title: 'Confirmations/Components/Confirm/Header',
component: Header,
- decorators: [(story: any) => {story()}],
+ decorators: [
+ (story: any) => (
+
+ {story()}
+
+ ),
+ ],
};
export default Story;
diff --git a/ui/pages/confirmations/hooks/alerts/useBlockaidAlerts.ts b/ui/pages/confirmations/hooks/alerts/useBlockaidAlerts.ts
index 6c3d88291e66..886e1bd204d4 100644
--- a/ui/pages/confirmations/hooks/alerts/useBlockaidAlerts.ts
+++ b/ui/pages/confirmations/hooks/alerts/useBlockaidAlerts.ts
@@ -25,8 +25,8 @@ import {
SignatureRequestType,
} from '../../types/confirm';
import { useConfirmContext } from '../../context/confirm';
-import { normalizeProviderAlert } from './utils';
import useCurrentSignatureSecurityAlertResponse from '../useCurrentSignatureSecurityAlertResponse';
+import { normalizeProviderAlert } from './utils';
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
const zlib = require('zlib');
From 44d48884e057ee6ea1926f0cddb7378179cc5977 Mon Sep 17 00:00:00 2001
From: Jyoti Puri
Date: Thu, 22 Aug 2024 23:14:58 +0530
Subject: [PATCH 06/17] update
---
.../confirmations/components/confirm/header/header.stories.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ui/pages/confirmations/components/confirm/header/header.stories.tsx b/ui/pages/confirmations/components/confirm/header/header.stories.tsx
index 69f1e9878605..af7c6e1aca5a 100644
--- a/ui/pages/confirmations/components/confirm/header/header.stories.tsx
+++ b/ui/pages/confirmations/components/confirm/header/header.stories.tsx
@@ -7,7 +7,7 @@ import configureStore from '../../../../../store/store';
import Header from './header';
import { ConfirmContextProvider } from '../../../context/confirm';
-const store = configureStore(getExampleMockSignatureConfirmState);
+const store = configureStore(getExampleMockSignatureConfirmState());
const Story = {
title: 'Confirmations/Components/Confirm/Header',
From c6b35fb9a71e97762950d7b021cfa304546e26bf Mon Sep 17 00:00:00 2001
From: Jyoti Puri
Date: Thu, 22 Aug 2024 23:17:15 +0530
Subject: [PATCH 07/17] update
---
ui/pages/confirmations/selectors/confirm.ts | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/ui/pages/confirmations/selectors/confirm.ts b/ui/pages/confirmations/selectors/confirm.ts
index cb0c7f50a591..cc039622263c 100644
--- a/ui/pages/confirmations/selectors/confirm.ts
+++ b/ui/pages/confirmations/selectors/confirm.ts
@@ -41,6 +41,10 @@ export const latestPendingConfirmationSelector = createDeepEqualSelector(
export const confirmSelector = (state: ConfirmMetamaskState) => state.confirm;
+/**
+ * @param state
+ * @deprecated get current confirmation using new hook useConfirmContext().
+ */
export const currentConfirmationSelector = (state: ConfirmMetamaskState) =>
state.confirm.currentConfirmation;
From d06c81281ce086428c558303e7b36cfb549abe51 Mon Sep 17 00:00:00 2001
From: Jyoti Puri
Date: Fri, 23 Aug 2024 14:33:02 +0530
Subject: [PATCH 08/17] update
---
test/data/confirmations/helper.ts | 8 ++++----
test/data/confirmations/personal_sign.ts | 1 +
test/data/confirmations/typed_sign.ts | 1 +
.../components/confirm/header/header-info.test.tsx | 8 ++++----
.../components/confirm/header/header.stories.tsx | 4 ++--
.../components/confirm/header/header.test.tsx | 8 ++++----
.../hooks/useConfirmationNetworkInfo.test.ts | 6 +++---
.../hooks/useConfirmationRecipientInfo.test.ts | 4 ++--
8 files changed, 21 insertions(+), 19 deletions(-)
diff --git a/test/data/confirmations/helper.ts b/test/data/confirmations/helper.ts
index a1ad1f299c62..e47bb96762cb 100644
--- a/test/data/confirmations/helper.ts
+++ b/test/data/confirmations/helper.ts
@@ -11,7 +11,7 @@ type RootState = { metamask: Record } & Record<
unknown
>;
-export const getExampleMockSignatureConfirmState = (
+export const getMockTypedSignConfirmState = (
args: RootState = { metamask: {} },
) => ({
...mockState,
@@ -37,15 +37,15 @@ export const getExampleMockSignatureConfirmState = (
status: TransactionStatus.unapproved,
txParams: { from: Object.keys(mockState.metamask.identities)[0] },
msgParams: {
- signatureMethod: 'eth_signTypedData_v4',
- },
+ signatureMethod: 'eth_signTypedData_v4'
+ }
},
},
...args.metamask,
},
});
-export const getExampleMockContractInteractionConfirmState = (
+export const getMockContractInteractionConfirmState = (
args: RootState = { metamask: {} },
) => ({
...mockState,
diff --git a/test/data/confirmations/personal_sign.ts b/test/data/confirmations/personal_sign.ts
index 6ac82dfe57bb..825538c47b09 100644
--- a/test/data/confirmations/personal_sign.ts
+++ b/test/data/confirmations/personal_sign.ts
@@ -9,6 +9,7 @@ export const unapprovedPersonalSignMsg = {
time: new Date().getTime(),
type: 'personal_sign',
securityProviderResponse: null,
+ chainid: '0x5',
msgParams: {
from: PERSONAL_SIGN_SENDER_ADDRESS,
data: '0x4578616d706c652060706572736f6e616c5f7369676e60206d657373616765',
diff --git a/test/data/confirmations/typed_sign.ts b/test/data/confirmations/typed_sign.ts
index 0a05a6716432..fa0a8b44f417 100644
--- a/test/data/confirmations/typed_sign.ts
+++ b/test/data/confirmations/typed_sign.ts
@@ -127,6 +127,7 @@ export const unapprovedTypedSignMsgV4 = {
id: '0050d5b0-c023-11ee-a0cb-3390a510a0ab',
status: 'unapproved',
time: new Date().getTime(),
+ chainid: '0x5',
type: 'eth_signTypedData',
securityProviderResponse: null,
msgParams: {
diff --git a/ui/pages/confirmations/components/confirm/header/header-info.test.tsx b/ui/pages/confirmations/components/confirm/header/header-info.test.tsx
index cd72810cf2f0..ac8670c4bd33 100644
--- a/ui/pages/confirmations/components/confirm/header/header-info.test.tsx
+++ b/ui/pages/confirmations/components/confirm/header/header-info.test.tsx
@@ -8,15 +8,15 @@ import {
MetaMetricsEventName,
} from '../../../../../../shared/constants/metametrics';
import {
- getExampleMockContractInteractionConfirmState,
- getExampleMockSignatureConfirmState,
+ getMockContractInteractionConfirmState,
+ getMockTypedSignConfirmState,
} from '../../../../../../test/data/confirmations/helper';
import { renderWithConfirmContextProvider } from '../../../../../../test/lib/confirmations/render-helpers';
import { MetaMetricsContext } from '../../../../../contexts/metametrics';
import configureStore from '../../../../../store/store';
import HeaderInfo from './header-info';
-const mockStore = getExampleMockSignatureConfirmState();
+const mockStore = getMockTypedSignConfirmState();
const cases = [
{
@@ -34,7 +34,7 @@ const cases = [
},
{
description: 'for a transaction',
- store: getExampleMockContractInteractionConfirmState(),
+ store: getMockContractInteractionConfirmState(),
expectedEvent: {
category: MetaMetricsEventCategory.Confirmations,
event: MetaMetricsEventName.AccountDetailsOpened,
diff --git a/ui/pages/confirmations/components/confirm/header/header.stories.tsx b/ui/pages/confirmations/components/confirm/header/header.stories.tsx
index af7c6e1aca5a..286938a67a13 100644
--- a/ui/pages/confirmations/components/confirm/header/header.stories.tsx
+++ b/ui/pages/confirmations/components/confirm/header/header.stories.tsx
@@ -1,13 +1,13 @@
import React from 'react';
import { Provider } from 'react-redux';
-import { getExampleMockSignatureConfirmState } from '../../../../../../test/data/confirmations/helper';
+import { getMockTypedSignConfirmState } from '../../../../../../test/data/confirmations/helper';
import configureStore from '../../../../../store/store';
import Header from './header';
import { ConfirmContextProvider } from '../../../context/confirm';
-const store = configureStore(getExampleMockSignatureConfirmState());
+const store = configureStore(getMockTypedSignConfirmState());
const Story = {
title: 'Confirmations/Components/Confirm/Header',
diff --git a/ui/pages/confirmations/components/confirm/header/header.test.tsx b/ui/pages/confirmations/components/confirm/header/header.test.tsx
index ce3eb0b84d12..7d73f5216844 100644
--- a/ui/pages/confirmations/components/confirm/header/header.test.tsx
+++ b/ui/pages/confirmations/components/confirm/header/header.test.tsx
@@ -3,15 +3,15 @@ import React from 'react';
import { DefaultRootState } from 'react-redux';
import {
- getExampleMockContractInteractionConfirmState,
- getExampleMockSignatureConfirmState,
+ getMockContractInteractionConfirmState,
+ getMockTypedSignConfirmState,
} from '../../../../../../test/data/confirmations/helper';
import { renderWithConfirmContextProvider } from '../../../../../../test/lib/confirmations/render-helpers';
import configureStore from '../../../../../store/store';
import Header from './header';
const render = (
- state: DefaultRootState = getExampleMockSignatureConfirmState(),
+ state: DefaultRootState = getMockTypedSignConfirmState(),
) => {
const store = configureStore(state);
return renderWithConfirmContextProvider(, store);
@@ -26,7 +26,7 @@ describe('Header', () => {
it('should match snapshot with transaction confirmation', () => {
const { container } = render(
- getExampleMockContractInteractionConfirmState(),
+ getMockContractInteractionConfirmState(),
);
expect(container).toMatchSnapshot();
diff --git a/ui/pages/confirmations/hooks/useConfirmationNetworkInfo.test.ts b/ui/pages/confirmations/hooks/useConfirmationNetworkInfo.test.ts
index 94e392f4615f..f30f27190b6f 100644
--- a/ui/pages/confirmations/hooks/useConfirmationNetworkInfo.test.ts
+++ b/ui/pages/confirmations/hooks/useConfirmationNetworkInfo.test.ts
@@ -3,7 +3,7 @@ import { TransactionType } from '@metamask/transaction-controller';
import mockState from '../../../../test/data/mock-state.json';
import {
- getExampleMockSignatureConfirmState,
+ getMockTypedSignConfirmState,
getMockConfirmState,
} from '../../../../test/data/confirmations/helper';
import { renderHookWithConfirmContextProvider } from '../../../../test/lib/confirmations/render-helpers';
@@ -46,7 +46,7 @@ describe('useConfirmationNetworkInfo', () => {
it('returns display name and image for custom network', () => {
const { result } = renderHookWithConfirmContextProvider(
() => useConfirmationNetworkInfo(),
- getExampleMockSignatureConfirmState({
+ getMockTypedSignConfirmState({
metamask: {
providerConfig: {
chainId: '0x7',
@@ -90,7 +90,7 @@ describe('useConfirmationNetworkInfo', () => {
it('should return empty strings if no matching network is found', () => {
const { result } = renderHookWithConfirmContextProvider(
() => useConfirmationNetworkInfo(),
- getExampleMockSignatureConfirmState({
+ getMockTypedSignConfirmState({
metamask: {
providerConfig: {
chainId: '0x7',
diff --git a/ui/pages/confirmations/hooks/useConfirmationRecipientInfo.test.ts b/ui/pages/confirmations/hooks/useConfirmationRecipientInfo.test.ts
index bb560419509e..4d9d4eb1b314 100644
--- a/ui/pages/confirmations/hooks/useConfirmationRecipientInfo.test.ts
+++ b/ui/pages/confirmations/hooks/useConfirmationRecipientInfo.test.ts
@@ -1,5 +1,5 @@
import {
- getExampleMockSignatureConfirmState,
+ getMockTypedSignConfirmState,
getMockConfirmState,
} from '../../../../test/data/confirmations/helper';
import { renderHookWithConfirmContextProvider } from '../../../../test/lib/confirmations/render-helpers';
@@ -11,7 +11,7 @@ const SenderAddress = '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc';
describe('useConfirmationRecipientInfo', () => {
describe('when the current confirmation is a signature', () => {
it('returns the account name of the from address as the recipient name', () => {
- const mockState = getExampleMockSignatureConfirmState();
+ const mockState = getMockTypedSignConfirmState();
const { result } = renderHookWithConfirmContextProvider(
() => useConfirmationRecipientInfo(),
mockState,
From aea945a2dad73c19811036c3e8d5fddb7beca2dd Mon Sep 17 00:00:00 2001
From: Jyoti Puri
Date: Mon, 26 Aug 2024 10:33:19 +0530
Subject: [PATCH 09/17] update
---
.../hooks/useCurrentSignatureSecurityAlertResponse.ts | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/ui/pages/confirmations/hooks/useCurrentSignatureSecurityAlertResponse.ts b/ui/pages/confirmations/hooks/useCurrentSignatureSecurityAlertResponse.ts
index f17e6618e280..dd534b564a27 100644
--- a/ui/pages/confirmations/hooks/useCurrentSignatureSecurityAlertResponse.ts
+++ b/ui/pages/confirmations/hooks/useCurrentSignatureSecurityAlertResponse.ts
@@ -22,14 +22,11 @@ const useCurrentSignatureSecurityAlertResponse = ():
const signatureSecurityAlertResponse = useSelector(
(state: SecurityAlertResponsesState) => {
- const signatureSecurityAlertId = (
- currentConfirmation?.securityAlertResponse as SecurityAlertResponse
- )?.securityAlertId;
if (securityAlertId === undefined) {
return undefined;
}
return state.metamask.signatureSecurityAlertResponses?.[
- signatureSecurityAlertId as string
+ securityAlertId as string
];
},
);
From ca38007b38d5bbf9bba19ecaa42195bef4110f57 Mon Sep 17 00:00:00 2001
From: Jyoti Puri
Date: Mon, 26 Aug 2024 10:35:14 +0530
Subject: [PATCH 10/17] update
---
test/data/confirmations/helper.ts | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/test/data/confirmations/helper.ts b/test/data/confirmations/helper.ts
index a1ad1f299c62..e2d0a79f95ae 100644
--- a/test/data/confirmations/helper.ts
+++ b/test/data/confirmations/helper.ts
@@ -32,7 +32,9 @@ export const getExampleMockSignatureConfirmState = (
unapprovedTypedMessages: {
'123': {
id: '123',
- chainId: mockState.metamask.providerConfig.chainId,
+ chainId:
+ mockState.metamask.networkConfigurations.testNetworkConfigurationId
+ .chainId,
type: TransactionType.signTypedData,
status: TransactionStatus.unapproved,
txParams: { from: Object.keys(mockState.metamask.identities)[0] },
@@ -67,7 +69,9 @@ export const getExampleMockContractInteractionConfirmState = (
{
id: '123',
type: TransactionType.contractInteraction,
- chainId: mockState.metamask.providerConfig.chainId,
+ chainId:
+ mockState.metamask.networkConfigurations.testNetworkConfigurationId
+ .chainId,
status: TransactionStatus.unapproved,
txParams: { from: Object.keys(mockState.metamask.identities)[0] },
},
From 7b24f9f36a7900ef569d9b7f138bc6d2ee201d60 Mon Sep 17 00:00:00 2001
From: Jyoti Puri
Date: Mon, 26 Aug 2024 10:58:01 +0530
Subject: [PATCH 11/17] update
---
test/data/confirmations/helper.ts | 12 ++++--------
.../components/confirm/header/header.test.tsx | 8 ++------
2 files changed, 6 insertions(+), 14 deletions(-)
diff --git a/test/data/confirmations/helper.ts b/test/data/confirmations/helper.ts
index fd5059afd243..4144764d3cdf 100644
--- a/test/data/confirmations/helper.ts
+++ b/test/data/confirmations/helper.ts
@@ -32,15 +32,13 @@ export const getMockTypedSignConfirmState = (
unapprovedTypedMessages: {
'123': {
id: '123',
- chainId:
- mockState.metamask.networkConfigurations.testNetworkConfigurationId
- .chainId,
+ chainId: mockState.metamask.networkConfigurations.goerli.chainId,
type: TransactionType.signTypedData,
status: TransactionStatus.unapproved,
txParams: { from: Object.keys(mockState.metamask.identities)[0] },
msgParams: {
- signatureMethod: 'eth_signTypedData_v4'
- }
+ signatureMethod: 'eth_signTypedData_v4',
+ },
},
},
...args.metamask,
@@ -69,9 +67,7 @@ export const getMockContractInteractionConfirmState = (
{
id: '123',
type: TransactionType.contractInteraction,
- chainId:
- mockState.metamask.networkConfigurations.testNetworkConfigurationId
- .chainId,
+ chainId: mockState.metamask.networkConfigurations.goerli.chainId,
status: TransactionStatus.unapproved,
txParams: { from: Object.keys(mockState.metamask.identities)[0] },
},
diff --git a/ui/pages/confirmations/components/confirm/header/header.test.tsx b/ui/pages/confirmations/components/confirm/header/header.test.tsx
index 7d73f5216844..508089d7ed8d 100644
--- a/ui/pages/confirmations/components/confirm/header/header.test.tsx
+++ b/ui/pages/confirmations/components/confirm/header/header.test.tsx
@@ -10,9 +10,7 @@ import { renderWithConfirmContextProvider } from '../../../../../../test/lib/con
import configureStore from '../../../../../store/store';
import Header from './header';
-const render = (
- state: DefaultRootState = getMockTypedSignConfirmState(),
-) => {
+const render = (state: DefaultRootState = getMockTypedSignConfirmState()) => {
const store = configureStore(state);
return renderWithConfirmContextProvider(, store);
};
@@ -25,9 +23,7 @@ describe('Header', () => {
});
it('should match snapshot with transaction confirmation', () => {
- const { container } = render(
- getMockContractInteractionConfirmState(),
- );
+ const { container } = render(getMockContractInteractionConfirmState());
expect(container).toMatchSnapshot();
});
From c6280c23f2bbfc195d093a8a8a7d8a5fa072957e Mon Sep 17 00:00:00 2001
From: Jyoti Puri
Date: Sat, 24 Aug 2024 20:29:34 +0530
Subject: [PATCH 12/17] Refactoring confirmation code to use
currentConfirmation from confirmContext
---
app/scripts/metamask-controller.test.js | 2 +-
.../confirmations/contract-interaction.ts | 268 +++++++++---------
test/data/confirmations/helper.ts | 87 +++---
test/data/confirmations/personal_sign.ts | 2 +-
test/data/confirmations/typed_sign.ts | 6 +-
.../header/__snapshots__/header.test.tsx.snap | 18 +-
.../approve-details.stories.tsx | 28 +-
.../approve-details/approve-details.test.tsx | 8 +-
.../confirm/info/approve/approve.stories.tsx | 18 +-
.../confirm/info/approve/approve.test.tsx | 22 +-
.../hooks/useDecodedTransactionData.test.ts | 53 ++--
.../info/hooks/useDecodedTransactionData.ts | 10 +-
.../advanced-details.stories.tsx | 28 +-
.../advanced-details.test.tsx | 12 +-
.../transaction-data.stories.tsx | 41 ++-
.../transaction-data.test.tsx | 32 ++-
.../transaction-data/transaction-data.tsx | 9 +-
.../nav/__snapshots__/nav.test.tsx.snap | 5 +-
.../components/confirm/nav/nav.stories.tsx | 19 +-
.../components/confirm/nav/nav.test.tsx | 110 +++----
.../components/confirm/nav/nav.tsx | 8 +-
.../pluggable-section.test.tsx | 17 +-
.../pluggable-section/pluggable-section.tsx | 5 +-
.../scroll-to-bottom.stories.tsx | 5 +-
.../scroll-to-bottom.test.tsx | 30 +-
.../scroll-to-bottom/scroll-to-bottom.tsx | 4 +-
.../signature-message/signature-message.tsx | 9 +-
.../__snapshots__/confirm.test.tsx.snap | 16 +-
28 files changed, 441 insertions(+), 431 deletions(-)
diff --git a/app/scripts/metamask-controller.test.js b/app/scripts/metamask-controller.test.js
index 387ecd1696a7..b64530444cdf 100644
--- a/app/scripts/metamask-controller.test.js
+++ b/app/scripts/metamask-controller.test.js
@@ -1311,7 +1311,7 @@ describe('MetaMaskController', () => {
);
expect(loggerMiddlewareMock.requests[0]).toHaveProperty(
'networkClientId',
- 'networkConfigurationId1',
+ 'mainnet',
);
resolve();
});
diff --git a/test/data/confirmations/contract-interaction.ts b/test/data/confirmations/contract-interaction.ts
index 935a95f849db..f6ad5a8633ea 100644
--- a/test/data/confirmations/contract-interaction.ts
+++ b/test/data/confirmations/contract-interaction.ts
@@ -3,7 +3,10 @@ import {
TransactionType,
} from '@metamask/transaction-controller';
import { Hex } from '@metamask/utils';
-import { Confirmation } from '../../../ui/pages/confirmations/types/confirm';
+import {
+ Confirmation,
+ SignatureRequestType,
+} from '../../../ui/pages/confirmations/types/confirm';
export const PAYMASTER_AND_DATA =
'0x9d6ac51b972544251fcc0f2902e633e3f9bd3f2900000000000000000000000000000000000000000000000000000000666bfd410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003498a76eb88b702e5e52b00fbc16a36baf89ebe3e0dd23170949cffc0a623011383cced660ff67930308c22e5aa746a2d586629ddbd87046a146225bf80e9d6f1b';
@@ -13,153 +16,160 @@ export const CONTRACT_INTERACTION_SENDER_ADDRESS =
export const DEPOSIT_METHOD_DATA = '0xd0e30db0';
+export const CHAIN_ID = '0xaa36a7';
+
export const genUnapprovedContractInteractionConfirmation = ({
address = CONTRACT_INTERACTION_SENDER_ADDRESS,
txData = DEPOSIT_METHOD_DATA,
+ chainId = CHAIN_ID,
}: {
address?: Hex;
txData?: Hex;
-} = {}): Confirmation => ({
- actionId: String(400855682),
- chainId: '0xaa36a7',
- dappSuggestedGasFees: {
- gas: '0xab77',
- },
- defaultGasEstimates: {
- estimateType: 'medium',
- gas: '0xab77',
- maxFeePerGas: '0xaa350353',
- maxPriorityFeePerGas: '0x59682f00',
- },
- gasFeeEstimatesLoaded: true,
- history: [
- {
- actionId: String(400855682),
- chainId: '0xaa36a7',
- dappSuggestedGasFees: {
- gas: '0xab77',
- },
- defaultGasEstimates: {
- estimateType: 'medium',
- gas: '0xab77',
- maxFeePerGas: '0xaa350353',
- maxPriorityFeePerGas: '0x59682f00',
- },
- id: '1d7c08c0-fe54-11ee-9243-91b1e533746a',
- origin: 'https://metamask.github.io',
- securityAlertResponse: {
- reason: 'loading',
- result_type: 'validation_in_progress',
- },
- sendFlowHistory: [],
- status: TransactionStatus.unapproved,
- time: 1713534772044,
- txParams: {
- data: txData,
- from: address,
- gas: '0xab77',
- maxFeePerGas: '0xaa350353',
- maxPriorityFeePerGas: '0x59682f00',
- to: '0x88aa6343307ec9a652ccddda3646e62b2f1a5125',
- value: '0x3782dace9d900000',
- },
- type: TransactionType.contractInteraction,
- userEditedGasLimit: false,
- userFeeLevel: 'medium',
- verifiedOnBlockchain: false,
+ chainId?: string;
+} = {}): Confirmation =>
+ ({
+ actionId: String(400855682),
+ chainId,
+ dappSuggestedGasFees: {
+ gas: '0xab77',
},
- [
+ defaultGasEstimates: {
+ estimateType: 'medium',
+ gas: '0xab77',
+ maxFeePerGas: '0xaa350353',
+ maxPriorityFeePerGas: '0x59682f00',
+ },
+ gasFeeEstimatesLoaded: true,
+ history: [
{
- note: 'TransactionController#updateSimulationData - Update simulation data',
- op: 'add',
- path: '/simulationData',
- timestamp: 1713534772417,
- value: {
- nativeBalanceChange: {
- difference: '0x3782dace9d900000',
- isDecrease: true,
- newBalance: '0xcc0ea4fb7ffa87d',
- previousBalance: '0x4443c51e558fa87d',
- },
- tokenBalanceChanges: [],
+ actionId: String(400855682),
+ chainId,
+ dappSuggestedGasFees: {
+ gas: '0xab77',
},
+ defaultGasEstimates: {
+ estimateType: 'medium',
+ gas: '0xab77',
+ maxFeePerGas: '0xaa350353',
+ maxPriorityFeePerGas: '0x59682f00',
+ },
+ id: '1d7c08c0-fe54-11ee-9243-91b1e533746a',
+ origin: 'https://metamask.github.io',
+ securityAlertResponse: {
+ reason: 'loading',
+ result_type: 'validation_in_progress',
+ },
+ sendFlowHistory: [],
+ status: TransactionStatus.unapproved,
+ time: 1713534772044,
+ txParams: {
+ data: txData,
+ from: address,
+ gas: '0xab77',
+ maxFeePerGas: '0xaa350353',
+ maxPriorityFeePerGas: '0x59682f00',
+ to: '0x88aa6343307ec9a652ccddda3646e62b2f1a5125',
+ value: '0x3782dace9d900000',
+ },
+ type: TransactionType.contractInteraction,
+ userEditedGasLimit: false,
+ userFeeLevel: 'medium',
+ verifiedOnBlockchain: false,
},
- {
- op: 'add',
- path: '/gasFeeEstimatesLoaded',
- value: true,
- },
+ [
+ {
+ note: 'TransactionController#updateSimulationData - Update simulation data',
+ op: 'add',
+ path: '/simulationData',
+ timestamp: 1713534772417,
+ value: {
+ nativeBalanceChange: {
+ difference: '0x3782dace9d900000',
+ isDecrease: true,
+ newBalance: '0xcc0ea4fb7ffa87d',
+ previousBalance: '0x4443c51e558fa87d',
+ },
+ tokenBalanceChanges: [],
+ },
+ },
+ {
+ op: 'add',
+ path: '/gasFeeEstimatesLoaded',
+ value: true,
+ },
+ ],
+ [
+ {
+ note: 'TransactionController:updatesecurityAlertResponse - securityAlertResponse updated',
+ op: 'replace',
+ path: '/securityAlertResponse/result_type',
+ timestamp: 1713534773213,
+ value: 'Benign',
+ },
+ {
+ op: 'replace',
+ path: '/securityAlertResponse/reason',
+ value: '',
+ },
+ {
+ op: 'add',
+ path: '/securityAlertResponse/description',
+ value: '',
+ },
+ {
+ op: 'add',
+ path: '/securityAlertResponse/features',
+ value: [],
+ },
+ {
+ op: 'add',
+ path: '/securityAlertResponse/block',
+ value: 5732063,
+ },
+ ],
],
- [
- {
- note: 'TransactionController:updatesecurityAlertResponse - securityAlertResponse updated',
- op: 'replace',
- path: '/securityAlertResponse/result_type',
- timestamp: 1713534773213,
- value: 'Benign',
- },
- {
- op: 'replace',
- path: '/securityAlertResponse/reason',
- value: '',
- },
- {
- op: 'add',
- path: '/securityAlertResponse/description',
- value: '',
- },
- {
- op: 'add',
- path: '/securityAlertResponse/features',
- value: [],
- },
- {
- op: 'add',
- path: '/securityAlertResponse/block',
- value: 5732063,
+ id: '1d7c08c0-fe54-11ee-9243-91b1e533746a',
+ origin: 'https://metamask.github.io',
+ securityAlertResponse: {
+ features: [],
+ reason: '',
+ result_type: 'Benign',
+ },
+ sendFlowHistory: [],
+ simulationData: {
+ nativeBalanceChange: {
+ difference: '0x3782dace9d900000',
+ isDecrease: true,
+ newBalance: '0xcc0ea4fb7ffa87d',
+ previousBalance: '0x4443c51e558fa87d',
},
- ],
- ],
- id: '1d7c08c0-fe54-11ee-9243-91b1e533746a',
- origin: 'https://metamask.github.io',
- securityAlertResponse: {
- features: [],
- reason: '',
- result_type: 'Benign',
- },
- sendFlowHistory: [],
- simulationData: {
- nativeBalanceChange: {
- difference: '0x3782dace9d900000',
- isDecrease: true,
- newBalance: '0xcc0ea4fb7ffa87d',
- previousBalance: '0x4443c51e558fa87d',
+ tokenBalanceChanges: [],
},
- tokenBalanceChanges: [],
- },
- status: TransactionStatus.unapproved,
- time: 1713534772044,
- txParams: {
- data: txData,
- from: address,
- gas: '0xab77',
- maxFeePerGas: '0xaa350353',
- maxPriorityFeePerGas: '0x59682f00',
- to: '0x88aa6343307ec9a652ccddda3646e62b2f1a5125',
- value: '0x3782dace9d900000',
- },
- type: TransactionType.contractInteraction,
- userEditedGasLimit: false,
- userFeeLevel: 'medium',
- verifiedOnBlockchain: false,
-});
+ status: TransactionStatus.unapproved,
+ time: 1713534772044,
+ txParams: {
+ data: txData,
+ from: address,
+ gas: '0xab77',
+ maxFeePerGas: '0xaa350353',
+ maxPriorityFeePerGas: '0x59682f00',
+ to: '0x88aa6343307ec9a652ccddda3646e62b2f1a5125',
+ value: '0x3782dace9d900000',
+ },
+ type: TransactionType.contractInteraction,
+ userEditedGasLimit: false,
+ userFeeLevel: 'medium',
+ verifiedOnBlockchain: false,
+ } as SignatureRequestType);
export const genUnapprovedApproveConfirmation = ({
address = CONTRACT_INTERACTION_SENDER_ADDRESS,
+ chainId = CHAIN_ID,
}: {
address?: Hex;
+ chainId?: string;
} = {}) => ({
- ...genUnapprovedContractInteractionConfirmation(),
+ ...genUnapprovedContractInteractionConfirmation({ chainId }),
txParams: {
from: address,
data: '0x095ea7b30000000000000000000000002e0d7e8c45221fca00d74a3609a0f7097035d09b0000000000000000000000000000000000000000000000000000000000000001',
diff --git a/test/data/confirmations/helper.ts b/test/data/confirmations/helper.ts
index 4144764d3cdf..aab810fb0415 100644
--- a/test/data/confirmations/helper.ts
+++ b/test/data/confirmations/helper.ts
@@ -1,10 +1,13 @@
import { ApprovalType } from '@metamask/controller-utils';
-import {
- TransactionStatus,
- TransactionType,
-} from '@metamask/transaction-controller';
+import { Confirmation } from '../../../ui/pages/confirmations/types/confirm';
import mockState from '../mock-state.json';
+import {
+ genUnapprovedApproveConfirmation,
+ genUnapprovedContractInteractionConfirmation,
+} from './contract-interaction';
+import { unapprovedPersonalSignMsg } from './personal_sign';
+import { unapprovedTypedSignMsgV4 } from './typed_sign';
type RootState = { metamask: Record } & Record<
string,
@@ -18,61 +21,48 @@ export const getMockTypedSignConfirmState = (
...args,
metamask: {
...mockState.metamask,
+ ...args.metamask,
preferences: {
+ ...mockState.metamask.preferences,
redesignedTransactionsEnabled: true,
redesignedConfirmationsEnabled: true,
isRedesignedConfirmationsDeveloperEnabled: true,
},
pendingApprovals: {
- '123': {
- id: '123',
+ [unapprovedTypedSignMsgV4.id]: {
+ id: unapprovedTypedSignMsgV4.id,
type: ApprovalType.EthSignTypedData,
},
},
unapprovedTypedMessages: {
- '123': {
- id: '123',
- chainId: mockState.metamask.networkConfigurations.goerli.chainId,
- type: TransactionType.signTypedData,
- status: TransactionStatus.unapproved,
- txParams: { from: Object.keys(mockState.metamask.identities)[0] },
- msgParams: {
- signatureMethod: 'eth_signTypedData_v4',
- },
- },
+ [unapprovedTypedSignMsgV4.id]: unapprovedTypedSignMsgV4,
},
- ...args.metamask,
},
});
-export const getMockContractInteractionConfirmState = (
+export const getMockPersonalSignConfirmState = (
args: RootState = { metamask: {} },
) => ({
...mockState,
...args,
metamask: {
...mockState.metamask,
+ ...args.metamask,
preferences: {
+ ...mockState.metamask.preferences,
redesignedTransactionsEnabled: true,
redesignedConfirmationsEnabled: true,
isRedesignedConfirmationsDeveloperEnabled: true,
},
pendingApprovals: {
- '123': {
- id: '123',
- type: ApprovalType.Transaction,
+ [unapprovedPersonalSignMsg.id]: {
+ id: unapprovedPersonalSignMsg.id,
+ type: ApprovalType.PersonalSign,
},
},
- transactions: [
- {
- id: '123',
- type: TransactionType.contractInteraction,
- chainId: mockState.metamask.networkConfigurations.goerli.chainId,
- status: TransactionStatus.unapproved,
- txParams: { from: Object.keys(mockState.metamask.identities)[0] },
- },
- ],
- ...args.metamask,
+ unapprovedPersonalMsgs: {
+ [unapprovedPersonalSignMsg.id]: unapprovedPersonalSignMsg,
+ },
},
});
@@ -81,11 +71,44 @@ export const getMockConfirmState = (args: RootState = { metamask: {} }) => ({
...args,
metamask: {
...mockState.metamask,
+ ...args.metamask,
preferences: {
+ ...mockState.metamask.preferences,
redesignedTransactionsEnabled: true,
redesignedConfirmationsEnabled: true,
isRedesignedConfirmationsDeveloperEnabled: true,
},
- ...args.metamask,
},
});
+
+export const getMockConfirmStateForTransaction = (
+ transaction: Confirmation,
+ args: RootState = { metamask: {} },
+) =>
+ getMockConfirmState({
+ ...args,
+ metamask: {
+ ...args.metamask,
+ pendingApprovals: {
+ [transaction.id]: {
+ id: transaction.id,
+ type: ApprovalType.Transaction,
+ },
+ },
+ transactions: [transaction],
+ },
+ confirm: {
+ currentConfirmation: transaction,
+ },
+ });
+
+export const getMockContractInteractionConfirmState = () => {
+ const contractInteraction = genUnapprovedContractInteractionConfirmation({
+ chainId: mockState.metamask.networkConfigurations.goerli.chainId,
+ });
+ return getMockConfirmStateForTransaction(contractInteraction);
+};
+
+export const getMockApproveConfirmState = () => {
+ return getMockConfirmStateForTransaction(genUnapprovedApproveConfirmation());
+};
diff --git a/test/data/confirmations/personal_sign.ts b/test/data/confirmations/personal_sign.ts
index 825538c47b09..b0f135efa53d 100644
--- a/test/data/confirmations/personal_sign.ts
+++ b/test/data/confirmations/personal_sign.ts
@@ -1,7 +1,7 @@
import { SignatureRequestType } from '../../../ui/pages/confirmations/types/confirm';
export const PERSONAL_SIGN_SENDER_ADDRESS =
- '0x8eeee1781fd885ff5ddef7789486676961873d12';
+ '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc';
export const unapprovedPersonalSignMsg = {
id: '0050d5b0-c023-11ee-a0cb-3390a510a0ab',
diff --git a/test/data/confirmations/typed_sign.ts b/test/data/confirmations/typed_sign.ts
index fa0a8b44f417..86067ef1f117 100644
--- a/test/data/confirmations/typed_sign.ts
+++ b/test/data/confirmations/typed_sign.ts
@@ -1,3 +1,4 @@
+import { MESSAGE_TYPE } from '../../../shared/constants/app';
import { SignatureRequestType } from '../../../ui/pages/confirmations/types/confirm';
export const unapprovedTypedSignMsgV1 = {
@@ -131,9 +132,10 @@ export const unapprovedTypedSignMsgV4 = {
type: 'eth_signTypedData',
securityProviderResponse: null,
msgParams: {
- from: '0x8eeee1781fd885ff5ddef7789486676961873d12',
+ from: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
data: JSON.stringify(rawMessageV4),
origin: 'https://metamask.github.io',
+ signatureMethod: MESSAGE_TYPE.ETH_SIGN_TYPED_DATA_V4,
},
} as SignatureRequestType;
@@ -148,7 +150,7 @@ export const orderSignatureMsg = {
time: 1722011224974,
type: 'eth_signTypedData',
msgParams: {
- data: '{"types":{"Order":[{"type":"uint8","name":"direction"},{"type":"address","name":"maker"},{"type":"address","name":"taker"},{"type":"uint256","name":"expiry"},{"type":"uint256","name":"nonce"},{"type":"address","name":"erc20Token"},{"type":"uint256","name":"erc20TokenAmount"},{"type":"Fee[]","name":"fees"},{"type":"address","name":"erc721Token"},{"type":"uint256","name":"erc721TokenId"},{"type":"Property[]","name":"erc721TokenProperties"}],"Fee":[{"type":"address","name":"recipient"},{"type":"uint256","name":"amount"},{"type":"bytes","name":"feeData"}],"Property":[{"type":"address","name":"propertyValidator"},{"type":"bytes","name":"propertyData"}],"EIP712Domain":[{"name":"name","type":"string"},{"name":"version","type":"string"},{"name":"chainId","type":"uint256"},{"name":"verifyingContract","type":"address"}]},"domain":{"name":"ZeroEx","version":"1.0.0","chainId":"0x1","verifyingContract":"0xdef1c0ded9bec7f1a1670819833240f027b25eff"},"primaryType":"Order","message":{"direction":"0","maker":"0x8eeee1781fd885ff5ddef7789486676961873d12","taker":"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826","expiry":"2524604400","nonce":"100131415900000000000000000000000000000083840314483690155566137712510085002484","erc20Token":"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2","erc20TokenAmount":"42000000000000","fees":[],"erc721Token":"0x8a90CAb2b38dba80c64b7734e58Ee1dB38B8992e","erc721TokenId":"2516","erc721TokenProperties":[]}}',
+ data: '{"types":{"Order":[{"type":"uint8","name":"direction"},{"type":"address","name":"maker"},{"type":"address","name":"taker"},{"type":"uint256","name":"expiry"},{"type":"uint256","name":"nonce"},{"type":"address","name":"erc20Token"},{"type":"uint256","name":"erc20TokenAmount"},{"type":"Fee[]","name":"fees"},{"type":"address","name":"erc721Token"},{"type":"uint256","name":"erc721TokenId"},{"type":"Property[]","name":"erc721TokenProperties"}],"Fee":[{"type":"address","name":"recipient"},{"type":"uint256","name":"amount"},{"type":"bytes","name":"feeData"}],"Property":[{"type":"address","name":"propertyValidator"},{"type":"bytes","name":"propertyData"}],"EIP712Domain":[{"name":"name","type":"string"},{"name":"version","type":"string"},{"name":"chainId","type":"uint256"},{"name":"verifyingContract","type":"address"}]},"domain":{"name":"ZeroEx","version":"1.0.0","chainId":"0x1","verifyingContract":"0xdef1c0ded9bec7f1a1670819833240f027b25eff"},"primaryType":"Order","message":{"direction":"0","maker":"0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc","taker":"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826","expiry":"2524604400","nonce":"100131415900000000000000000000000000000083840314483690155566137712510085002484","erc20Token":"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2","erc20TokenAmount":"42000000000000","fees":[],"erc721Token":"0x8a90CAb2b38dba80c64b7734e58Ee1dB38B8992e","erc721TokenId":"2516","erc721TokenProperties":[]}}',
from: '0x935e73edb9ff52e23bac7f7e043a1ecd06d05477',
version: 'V4',
signatureMethod: 'eth_signTypedData_v4',
diff --git a/ui/pages/confirmations/components/confirm/header/__snapshots__/header.test.tsx.snap b/ui/pages/confirmations/components/confirm/header/__snapshots__/header.test.tsx.snap
index afc71c0f6917..313746c4f504 100644
--- a/ui/pages/confirmations/components/confirm/header/__snapshots__/header.test.tsx.snap
+++ b/ui/pages/confirmations/components/confirm/header/__snapshots__/header.test.tsx.snap
@@ -133,7 +133,7 @@ exports[`Header should match snapshot with transaction confirmation 1`] = `
style="height: 32px; width: 32px; border-radius: 16px;"
>
);
@@ -70,18 +72,15 @@ export default {
decorators: [(story: () => Meta) => story()],
};
-export const UniswapStory = () =>
- Template({ to: CONTRACT_ADDRESS_UNISWAP });
+export const UniswapStory = () => Template({ to: CONTRACT_ADDRESS_UNISWAP });
UniswapStory.storyName = 'Uniswap';
-export const SourcifyStory = () =>
- Template({ to: CONTRACT_ADDRESS_SOURCIFY });
+export const SourcifyStory = () => Template({ to: CONTRACT_ADDRESS_SOURCIFY });
SourcifyStory.storyName = 'Sourcify';
-export const FourByteStory = () =>
- Template({ to: CONTRACT_ADDRESS_FOUR_BYTE });
+export const FourByteStory = () => Template({ to: CONTRACT_ADDRESS_FOUR_BYTE });
FourByteStory.storyName = 'Four Byte';
diff --git a/ui/pages/confirmations/components/confirm/info/shared/transaction-data/transaction-data.test.tsx b/ui/pages/confirmations/components/confirm/info/shared/transaction-data/transaction-data.test.tsx
index 704d16eae7f8..5a793508c744 100644
--- a/ui/pages/confirmations/components/confirm/info/shared/transaction-data/transaction-data.test.tsx
+++ b/ui/pages/confirmations/components/confirm/info/shared/transaction-data/transaction-data.test.tsx
@@ -1,14 +1,20 @@
import React from 'react';
import configureMockStore from 'redux-mock-store';
+import {
+ TransactionStatus,
+ TransactionType,
+} from '@metamask/transaction-controller';
import { act } from '@testing-library/react';
-import mockState from '../../../../../../../../test/data/mock-state.json';
-import { renderWithProvider } from '../../../../../../../../test/lib/render-helpers';
+
+import { getMockConfirmStateForTransaction } from '../../../../../../../../test/data/confirmations/helper';
+import { renderWithConfirmContextProvider } from '../../../../../../../../test/lib/confirmations/render-helpers';
import { decodeTransactionData } from '../../../../../../../store/actions';
import {
TRANSACTION_DECODE_FOUR_BYTE,
TRANSACTION_DECODE_NESTED,
TRANSACTION_DECODE_UNISWAP,
} from '../../../../../../../../test/data/confirmations/transaction-decode';
+import { Confirmation } from '../../../../../types/confirm';
import { TransactionData } from './transaction-data';
const DATA_MOCK = '0x123456';
@@ -19,19 +25,21 @@ jest.mock('../../../../../../../store/actions', () => ({
}));
async function renderTransactionData(transactionData: string) {
- const state = {
- ...mockState,
- confirm: {
- currentConfirmation: {
- txParams: {
- data: transactionData,
- },
- },
+ const state = getMockConfirmStateForTransaction({
+ id: '123',
+ chainId: '0x5',
+ type: TransactionType.contractInteraction,
+ status: TransactionStatus.unapproved,
+ txParams: {
+ data: transactionData,
},
- };
+ } as Confirmation);
const mockStore = configureMockStore()(state);
- const { container } = renderWithProvider(, mockStore);
+ const { container } = renderWithConfirmContextProvider(
+ ,
+ mockStore,
+ );
await act(() => {
// Ignore
diff --git a/ui/pages/confirmations/components/confirm/info/shared/transaction-data/transaction-data.tsx b/ui/pages/confirmations/components/confirm/info/shared/transaction-data/transaction-data.tsx
index dd020b389482..fb6018c86c56 100644
--- a/ui/pages/confirmations/components/confirm/info/shared/transaction-data/transaction-data.tsx
+++ b/ui/pages/confirmations/components/confirm/info/shared/transaction-data/transaction-data.tsx
@@ -1,11 +1,9 @@
import React from 'react';
-import { useSelector } from 'react-redux';
import { TransactionMeta } from '@metamask/transaction-controller';
import { hexStripZeros } from '@ethersproject/bytes';
import _ from 'lodash';
import { Hex } from '@metamask/utils';
import { useDecodedTransactionData } from '../../hooks/useDecodedTransactionData';
-import { currentConfirmationSelector } from '../../../../../selectors';
import { ConfirmInfoSection } from '../../../../../../../components/app/confirm/info/row/section';
import {
ConfirmInfoRow,
@@ -28,11 +26,12 @@ import {
DecodedTransactionDataSource,
} from '../../../../../../../../shared/types/transaction-decode';
import { UniswapPathPool } from '../../../../../../../../app/scripts/lib/transaction/decode/uniswap';
+import { useConfirmContext } from '../../../../../context/confirm';
export const TransactionData = () => {
- const currentConfirmation = useSelector(currentConfirmationSelector) as
- | TransactionMeta
- | undefined;
+ const { currentConfirmation } = useConfirmContext() as unknown as {
+ currentConfirmation: TransactionMeta | undefined;
+ };
const transactionData = currentConfirmation?.txParams?.data as Hex;
const decodeResponse = useDecodedTransactionData();
diff --git a/ui/pages/confirmations/components/confirm/nav/__snapshots__/nav.test.tsx.snap b/ui/pages/confirmations/components/confirm/nav/__snapshots__/nav.test.tsx.snap
index 15d081f80047..48cafff5e80a 100644
--- a/ui/pages/confirmations/components/confirm/nav/__snapshots__/nav.test.tsx.snap
+++ b/ui/pages/confirmations/components/confirm/nav/__snapshots__/nav.test.tsx.snap
@@ -11,8 +11,9 @@ exports[`ConfirmNav should match snapshot 1`] = `
>
`;
-
-exports[` renders component for approve request 2`] = `
-
-
-
-
-
-
-
- metamask.github.io
-
-
-
-
-
-
-
-
-
- 0.004 ETH
-
-
- $2.20
-
-
-
-
-
-
-
-
-
-
-
-
- 🦊 Market
-
-
-
- ~
- 0 sec
-
-
-
-
-
-
-
-`;
-
-exports[` renders component for approve request 3`] = `
-
-
-
-
-
-
- metamask.github.io
-
-
-
-
-
-
-
-
-
- 0.004 ETH
-
-
- $2.20
-
-
-
-
-
-
-
-
-
-
-
-
- 🦊 Market
-
-
-
- ~
- 0 sec
-
-
-
-
-
-
-
-`;
-
-exports[` renders component for approve request 4`] = ``;
diff --git a/ui/pages/confirmations/components/confirm/info/approve/approve.test.tsx b/ui/pages/confirmations/components/confirm/info/approve/approve.test.tsx
index f771a7ac4ac8..a14a5329979b 100644
--- a/ui/pages/confirmations/components/confirm/info/approve/approve.test.tsx
+++ b/ui/pages/confirmations/components/confirm/info/approve/approve.test.tsx
@@ -37,9 +37,7 @@ describe('', () => {
mockStore,
);
- await waitFor(() => {
- expect(container).toMatchSnapshot();
- });
+ expect(container).toMatchSnapshot();
});
it('does not render if required data is not present in the transaction', () => {
From 17a2c6394abda041c09f4685cf339647bb68948b Mon Sep 17 00:00:00 2001
From: Jyoti Puri
Date: Mon, 2 Sep 2024 18:23:37 +0530
Subject: [PATCH 17/17] update
---
.../components/confirm/info/approve/approve.test.tsx | 1 -
1 file changed, 1 deletion(-)
diff --git a/ui/pages/confirmations/components/confirm/info/approve/approve.test.tsx b/ui/pages/confirmations/components/confirm/info/approve/approve.test.tsx
index a14a5329979b..75026ecea138 100644
--- a/ui/pages/confirmations/components/confirm/info/approve/approve.test.tsx
+++ b/ui/pages/confirmations/components/confirm/info/approve/approve.test.tsx
@@ -1,4 +1,3 @@
-import { waitFor } from '@testing-library/react';
import React from 'react';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';