Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: Adding info alert when new confirmation is from different origin or network #30550

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions app/_locales/de/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions app/_locales/el/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions app/_locales/en_GB/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions app/_locales/es/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions app/_locales/fr/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions app/_locales/hi/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions app/_locales/id/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions app/_locales/ja/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions app/_locales/ko/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions app/_locales/pt/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions app/_locales/ru/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions app/_locales/tl/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions app/_locales/tr/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions app/_locales/vi/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions app/_locales/zh_CN/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions shared/types/confirm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export type LastInteractedConfirmationInfo = {
id: string;
timestamp: number;
chainId: string;
origin: string;
};
1 change: 1 addition & 0 deletions ui/components/app/confirm/info/row/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export enum RowAlertKey {
EstimatedFee = 'estimatedFee',
SigningInWith = 'signingInWith',
RequestFrom = 'requestFrom',
Network = 'Network',
Resimulation = 'resimulation',
Speed = 'speed',
To = 'to',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import React from 'react';
import { CHAIN_IDS } from '@metamask/transaction-controller';

import {
getMockConfirmStateForTransaction,
getMockContractInteractionConfirmState,
} from '../../../../../../../../test/data/confirmations/helper';
import { genUnapprovedContractInteractionConfirmation } from '../../../../../../../../test/data/confirmations/contract-interaction';
import { renderWithConfirmContextProvider } from '../../../../../../../../test/lib/confirmations/render-helpers';
import { RowAlertKey } from '../../../../../../../components/app/confirm/info/row/constants';
import { Severity } from '../../../../../../../helpers/constants/design-system';
import { NetworkRow } from './network-row';

jest.mock(
'../../../../../../../components/app/alert-system/contexts/alertMetricsContext',
() => ({
useAlertMetrics: jest.fn(() => ({
trackAlertMetrics: jest.fn(),
})),
}),
);

describe('NetworkRow', () => {
const middleware = [thunk];

it('does display network information of current confirmation', () => {
const state = getMockContractInteractionConfirmState();
const mockStore = configureMockStore(middleware)(state);
const { getByText } = renderWithConfirmContextProvider(
<NetworkRow />,
mockStore,
);
expect(getByText('Network')).toBeInTheDocument();
expect(getByText('Goerli')).toBeInTheDocument();
});

it('does not display network if isShownWithAlertsOnly is true and there is no field alert', () => {
const state = getMockContractInteractionConfirmState();
const mockStore = configureMockStore(middleware)(state);
const { queryByText } = renderWithConfirmContextProvider(
<NetworkRow isShownWithAlertsOnly />,
mockStore,
);
expect(queryByText('Network')).not.toBeInTheDocument();
});

it('does display network if isShownWithAlertsOnly is true and field alert is present', () => {
const contractInteraction = genUnapprovedContractInteractionConfirmation({
chainId: CHAIN_IDS.GOERLI,
});
const state = {
...getMockConfirmStateForTransaction(contractInteraction),
confirmAlerts: {
alerts: {
[contractInteraction.id]: [
{
key: 'networkSwitchInfo',
field: RowAlertKey.Network,
severity: Severity.Info,
message: 'dummy message',
reason: 'dummy reason',
},
],
},
confirmed: {},
},
};

const mockStore = configureMockStore(middleware)(state);
const { getByText } = renderWithConfirmContextProvider(
<NetworkRow isShownWithAlertsOnly />,
mockStore,
);
expect(getByText('Network')).toBeInTheDocument();
expect(getByText('Goerli')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React from 'react';
import { useSelector } from 'react-redux';

import { CHAIN_ID_TO_NETWORK_IMAGE_URL_MAP } from '../../../../../../../../shared/constants/network';
import { getNetworkConfigurationsByChainId } from '../../../../../../../../shared/modules/selectors/networks';
import { useI18nContext } from '../../../../../../../hooks/useI18nContext';
import { ConfirmInfoRow } from '../../../../../../../components/app/confirm/info/row';

Check failure on line 7 in ui/pages/confirmations/components/confirm/info/shared/network-row/network-row.tsx

View workflow job for this annotation

GitHub Actions / Test lint / Test lint

'ConfirmInfoRow' is defined but never used
import {
AvatarNetwork,
AvatarNetworkSize,
Box,
Text,
} from '../../../../../../../components/component-library';
import {
AlignItems,
BlockSize,
BorderColor,
Display,
FlexWrap,
TextColor,
TextVariant,
} from '../../../../../../../helpers/constants/design-system';
import { ConfirmInfoAlertRow } from '../../../../../../../components/app/confirm/info/row/alert-row/alert-row';
import { RowAlertKey } from '../../../../../../../components/app/confirm/info/row/constants';
import { useConfirmContext } from '../../../../../context/confirm';

export const NetworkRow = ({
isShownWithAlertsOnly = false,
}: {
isShownWithAlertsOnly?: boolean;
}) => {
{

Check failure on line 32 in ui/pages/confirmations/components/confirm/info/shared/network-row/network-row.tsx

View workflow job for this annotation

GitHub Actions / Test lint / Test lint

Nested block is redundant
const t = useI18nContext();
const { currentConfirmation } = useConfirmContext() ?? {};
const chainId = (currentConfirmation?.chainId as `0x${string}`) ?? '';
const networkConfigurations = useSelector(
getNetworkConfigurationsByChainId,
);
const networkName = chainId ? networkConfigurations[chainId]?.name : '';

return (
<ConfirmInfoAlertRow
alertKey={RowAlertKey.Network}
ownerId={currentConfirmation.id}
label={t('transactionFlowNetwork')}
isShownWithAlertsOnly={isShownWithAlertsOnly}
>
<Box
display={Display.Flex}
alignItems={AlignItems.center}
flexWrap={FlexWrap.Wrap}
gap={2}
minWidth={BlockSize.Zero}
>
<AvatarNetwork
borderColor={BorderColor.backgroundDefault}
size={AvatarNetworkSize.Xs}
src={
CHAIN_ID_TO_NETWORK_IMAGE_URL_MAP[
chainId as keyof typeof CHAIN_ID_TO_NETWORK_IMAGE_URL_MAP
]
}
name={networkName}
/>
<Text variant={TextVariant.bodyMd} color={TextColor.textDefault}>
{networkName}
</Text>
</Box>
</ConfirmInfoAlertRow>
);
}
};
Loading
Loading