Skip to content

Commit d7584ca

Browse files
authored
Merge branch 'main' into feat-INFRA-2575-yarn-issues
2 parents 6572fbf + e43f610 commit d7584ca

File tree

11 files changed

+1196
-38
lines changed

11 files changed

+1196
-38
lines changed

app/_locales/en/messages.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/_locales/en_GB/messages.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/components/app/confirm/info/row/alert-row/alert-row.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export type ConfirmInfoAlertRowProps = ConfirmInfoRowProps & {
2121
isShownWithAlertsOnly?: boolean;
2222
};
2323

24-
function getAlertTextColors(
24+
export function getAlertTextColors(
2525
variant?: ConfirmInfoRowVariant | Severity,
2626
): TextColor {
2727
switch (variant) {

ui/components/app/confirm/info/row/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export enum RowAlertKey {
99
Resimulation = 'resimulation',
1010
Speed = 'speed',
1111
InteractingWith = 'interactingWith',
12+
EstimatedChangesStatic = 'estimatedChangesStatic',
1213
}
1314

1415
export enum AlertActionKey {

ui/pages/confirmations/components/simulation-details/balance-change-list.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Box } from '../../../../components/component-library';
33
import {
44
Display,
55
FlexDirection,
6+
TextColor,
67
} from '../../../../helpers/constants/design-system';
78
import { BalanceChangeRow } from './balance-change-row';
89
import { BalanceChange } from './types';
@@ -17,13 +18,15 @@ import { sortBalanceChanges } from './sortBalanceChanges';
1718
* @param props.heading
1819
* @param props.balanceChanges
1920
* @param props.testId
21+
* @param props.labelColor
2022
* @returns
2123
*/
2224
export const BalanceChangeList: React.FC<{
2325
heading: string;
2426
balanceChanges: BalanceChange[];
2527
testId?: string;
26-
}> = ({ heading, balanceChanges, testId }) => {
28+
labelColor?: TextColor;
29+
}> = ({ heading, balanceChanges, testId, labelColor }) => {
2730
const sortedBalanceChanges = useMemo(() => {
2831
return sortBalanceChanges(balanceChanges);
2932
}, [balanceChanges]);
@@ -57,6 +60,7 @@ export const BalanceChangeList: React.FC<{
5760
label={index === 0 ? heading : undefined}
5861
balanceChange={balanceChange}
5962
showFiat={!showFiatTotal && !balanceChange.isUnlimitedApproval}
63+
labelColor={labelColor}
6064
/>
6165
))}
6266
</Box>

ui/pages/confirmations/components/simulation-details/balance-change-row.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
FlexDirection,
66
FlexWrap,
77
IconColor,
8+
TextColor,
89
TextVariant,
910
} from '../../../../helpers/constants/design-system';
1011
import {
@@ -27,12 +28,14 @@ import { IndividualFiatDisplay } from './fiat-display';
2728
* @param props.label
2829
* @param props.showFiat
2930
* @param props.balanceChange
31+
* @param props.labelColor
3032
*/
3133
export const BalanceChangeRow: React.FC<{
3234
label?: string;
3335
showFiat?: boolean;
3436
balanceChange: BalanceChange;
35-
}> = ({ label, showFiat, balanceChange }) => {
37+
labelColor?: TextColor;
38+
}> = ({ label, showFiat, balanceChange, labelColor }) => {
3639
const t = useI18nContext();
3740

3841
const {
@@ -55,7 +58,11 @@ export const BalanceChangeRow: React.FC<{
5558
flexWrap={FlexWrap.Wrap}
5659
>
5760
{label && (
58-
<Text style={{ whiteSpace: 'nowrap' }} variant={TextVariant.bodyMd}>
61+
<Text
62+
style={{ whiteSpace: 'nowrap' }}
63+
color={labelColor}
64+
variant={TextVariant.bodyMd}
65+
>
5966
{label}
6067
</Text>
6168
)}

ui/pages/confirmations/components/simulation-details/simulation-details.test.tsx

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
import configureStore from 'redux-mock-store';
2-
import React from 'react';
3-
import { screen } from '@testing-library/react';
41
import {
52
SimulationData,
63
SimulationErrorCode,
74
TransactionMeta,
85
} from '@metamask/transaction-controller';
6+
import { screen } from '@testing-library/react';
97
import { BigNumber } from 'bignumber.js';
10-
import { renderWithProvider } from '../../../../../test/lib/render-helpers';
11-
import mockState from '../../../../../test/data/mock-state.json';
8+
import React from 'react';
9+
import configureStore from 'redux-mock-store';
1210
import { TokenStandard } from '../../../../../shared/constants/transaction';
13-
import { SimulationDetails, StaticRow } from './simulation-details';
14-
import { useBalanceChanges } from './useBalanceChanges';
11+
import mockState from '../../../../../test/data/mock-state.json';
12+
import { renderWithProvider } from '../../../../../test/lib/render-helpers';
13+
import { AlertMetricsProvider } from '../../../../components/app/alert-system/contexts/alertMetricsContext';
1514
import { BalanceChangeList } from './balance-change-list';
15+
import { SimulationDetails, StaticRow } from './simulation-details';
1616
import { BalanceChange } from './types';
17+
import { useBalanceChanges } from './useBalanceChanges';
1718

1819
const store = configureStore()(mockState);
1920

@@ -31,6 +32,7 @@ jest.mock(
3132
'../../../../components/app/confirm/info/row/alert-row/alert-row',
3233
() => ({
3334
ConfirmInfoAlertRow: jest.fn(({ label }) => <>{label}</>),
35+
getAlertTextColors: jest.fn(() => 'textDefault'),
3436
}),
3537
);
3638

@@ -46,17 +48,30 @@ const renderSimulationDetails = (
4648
simulationData?: Partial<SimulationData>,
4749
metricsOnly?: boolean,
4850
staticRows?: StaticRow[],
49-
) =>
50-
renderWithProvider(
51-
<SimulationDetails
52-
transaction={
53-
{ id: 'testTransactionId', simulationData } as TransactionMeta
54-
}
55-
metricsOnly={metricsOnly}
56-
staticRows={staticRows}
57-
/>,
51+
) => {
52+
const trackAlertActionClicked = jest.fn();
53+
const trackAlertRender = jest.fn();
54+
const trackInlineAlertClicked = jest.fn();
55+
56+
return renderWithProvider(
57+
<AlertMetricsProvider
58+
metrics={{
59+
trackAlertActionClicked,
60+
trackAlertRender,
61+
trackInlineAlertClicked,
62+
}}
63+
>
64+
<SimulationDetails
65+
transaction={
66+
{ id: 'testTransactionId', simulationData } as TransactionMeta
67+
}
68+
metricsOnly={metricsOnly}
69+
staticRows={staticRows}
70+
/>
71+
</AlertMetricsProvider>,
5872
store,
5973
);
74+
};
6075

6176
describe('SimulationDetails', () => {
6277
beforeEach(() => {

ui/pages/confirmations/components/simulation-details/simulation-details.tsx

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@ import {
33
SimulationErrorCode,
44
TransactionMeta,
55
} from '@metamask/transaction-controller';
6-
import React from 'react';
7-
import { ConfirmInfoAlertRow } from '../../../../components/app/confirm/info/row/alert-row/alert-row';
6+
import React, { useState } from 'react';
7+
import { useAlertMetrics } from '../../../../components/app/alert-system/contexts/alertMetricsContext';
8+
import InlineAlert from '../../../../components/app/alert-system/inline-alert';
9+
import { MultipleAlertModal } from '../../../../components/app/alert-system/multiple-alert-modal';
10+
import {
11+
ConfirmInfoAlertRow,
12+
getAlertTextColors,
13+
} from '../../../../components/app/confirm/info/row/alert-row/alert-row';
814
import { RowAlertKey } from '../../../../components/app/confirm/info/row/constants';
915
import { ConfirmInfoSection } from '../../../../components/app/confirm/info/row/section';
1016
import {
@@ -27,11 +33,12 @@ import {
2733
TextColor,
2834
TextVariant,
2935
} from '../../../../helpers/constants/design-system';
36+
import useAlerts from '../../../../hooks/useAlerts';
3037
import { useI18nContext } from '../../../../hooks/useI18nContext';
3138
import { BalanceChangeList } from './balance-change-list';
39+
import { BalanceChange } from './types';
3240
import { useBalanceChanges } from './useBalanceChanges';
3341
import { useSimulationMetrics } from './useSimulationMetrics';
34-
import { BalanceChange } from './types';
3542

3643
export type StaticRow = {
3744
label: string;
@@ -250,6 +257,49 @@ const SimulationDetailsLayout: React.FC<{
250257
</Box>
251258
);
252259

260+
const BalanceChangesAlert = ({ transactionId }: { transactionId: string }) => {
261+
const { getFieldAlerts } = useAlerts(transactionId);
262+
const fieldAlerts = getFieldAlerts(RowAlertKey.EstimatedChangesStatic);
263+
const selectedAlertSeverity = fieldAlerts[0]?.severity;
264+
const selectedAlertKey = fieldAlerts[0]?.key;
265+
266+
const { trackInlineAlertClicked } = useAlertMetrics();
267+
268+
const [alertModalVisible, setAlertModalVisible] = useState<boolean>(false);
269+
270+
const handleModalClose = () => {
271+
setAlertModalVisible(false);
272+
};
273+
274+
const handleInlineAlertClick = () => {
275+
setAlertModalVisible(true);
276+
trackInlineAlertClicked(selectedAlertKey);
277+
};
278+
279+
return (
280+
<>
281+
{fieldAlerts.length > 0 && (
282+
<Box marginLeft={1}>
283+
<InlineAlert
284+
onClick={handleInlineAlertClick}
285+
severity={selectedAlertSeverity}
286+
/>
287+
</Box>
288+
)}
289+
{alertModalVisible && (
290+
<MultipleAlertModal
291+
alertKey={selectedAlertKey}
292+
ownerId={transactionId}
293+
onFinalAcknowledgeClick={handleModalClose}
294+
onClose={handleModalClose}
295+
showCloseIcon={false}
296+
skipAlertNavigation={true}
297+
/>
298+
)}
299+
</>
300+
);
301+
};
302+
253303
/**
254304
* Preview of a transaction's effects using simulation data.
255305
*
@@ -285,6 +335,10 @@ export const SimulationDetails: React.FC<SimulationDetailsProps> = ({
285335
transactionId,
286336
});
287337

338+
const { getFieldAlerts } = useAlerts(transactionId);
339+
const fieldAlerts = getFieldAlerts(RowAlertKey.EstimatedChangesStatic);
340+
const selectedAlertSeverity = fieldAlerts[0]?.severity;
341+
288342
if (metricsOnly) {
289343
return null;
290344
}
@@ -351,11 +405,15 @@ export const SimulationDetails: React.FC<SimulationDetailsProps> = ({
351405
>
352406
<Box display={Display.Flex} flexDirection={FlexDirection.Column} gap={3}>
353407
{staticRows.map((staticRow, index) => (
354-
<BalanceChangeList
355-
key={index}
356-
heading={staticRow.label}
357-
balanceChanges={staticRow.balanceChanges}
358-
/>
408+
<>
409+
<BalanceChangeList
410+
key={index}
411+
heading={staticRow.label}
412+
balanceChanges={staticRow.balanceChanges}
413+
labelColor={getAlertTextColors(selectedAlertSeverity)}
414+
/>
415+
<BalanceChangesAlert transactionId={transactionId} />
416+
</>
359417
))}
360418
<BalanceChangeList
361419
heading={t('simulationDetailsOutgoingHeading')}

0 commit comments

Comments
 (0)