Skip to content

Commit 28102bc

Browse files
committed
fix: display Interacting with in transaction details section
1 parent fc1a3a8 commit 28102bc

File tree

8 files changed

+64
-142
lines changed

8 files changed

+64
-142
lines changed

shared/lib/transactions.utils.test.ts

-67
This file was deleted.

shared/lib/transactions.utils.ts

-20
This file was deleted.

ui/pages/confirmations/components/confirm/info/batch/transaction-account-details/transaction-account-details.test.tsx

+46-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import React from 'react';
2-
import { AuthorizationList } from '@metamask/transaction-controller';
2+
import {
3+
AuthorizationList,
4+
NestedTransactionMetadata,
5+
TransactionType,
6+
} from '@metamask/transaction-controller';
37
import { renderWithConfirmContextProvider } from '../../../../../../../../test/lib/confirmations/render-helpers';
48
import configureStore from '../../../../../../../store/store';
59
import { getMockConfirmStateForTransaction } from '../../../../../../../../test/data/confirmations/helper';
@@ -20,14 +24,17 @@ jest.mock(
2024

2125
function render({
2226
authorizationList,
27+
nestedTransactions,
2328
}: {
2429
authorizationList?: AuthorizationList;
30+
nestedTransactions?: NestedTransactionMetadata[];
2531
}) {
2632
const store = configureStore(
2733
getMockConfirmStateForTransaction(
2834
genUnapprovedContractInteractionConfirmation({
2935
address: FROM_MOCK,
3036
authorizationList,
37+
nestedTransactions,
3138
}),
3239
),
3340
);
@@ -44,12 +51,14 @@ describe('TransactionAccountDetails', () => {
4451
expect(getByText('0x12345...67890')).toBeInTheDocument();
4552
});
4653

47-
it('renders account type', () => {
48-
const { getByText } = render({
54+
it('renders type row', () => {
55+
const { getByText, queryByText } = render({
4956
authorizationList: [{ address: DELEGATION_MOCK }],
5057
});
5158

5259
expect(getByText('Smart account')).toBeInTheDocument();
60+
expect(getByText('Type')).toBeInTheDocument();
61+
expect(queryByText('Account type')).toBeNull();
5362
});
5463

5564
it('does not render if no authorization list', () => {
@@ -58,4 +67,38 @@ describe('TransactionAccountDetails', () => {
5867
expect(queryByText('0x12345...67890')).toBeNull();
5968
expect(queryByText('Smart account')).toBeNull();
6069
});
70+
71+
it('renders Account Type when transaction is a batch transaction', () => {
72+
const { getByText } = render({
73+
authorizationList: [{ address: DELEGATION_MOCK }],
74+
nestedTransactions: [{ to: FROM_MOCK }],
75+
});
76+
77+
expect(getByText('Account type')).toBeInTheDocument();
78+
});
79+
80+
describe('RecipientRow', () => {
81+
it('renders when transaction is a batch transaction', () => {
82+
const ADDRESS_2_MOCK = '0x1234567890123456789012345678901234567891';
83+
const { getByText, getByTestId } = render({
84+
authorizationList: [{ address: DELEGATION_MOCK }],
85+
nestedTransactions: [
86+
{
87+
to: FROM_MOCK,
88+
data: '0x1',
89+
type: TransactionType.contractInteraction,
90+
},
91+
{
92+
to: ADDRESS_2_MOCK,
93+
data: '0x2',
94+
type: TransactionType.contractInteraction,
95+
},
96+
] as NestedTransactionMetadata[],
97+
});
98+
expect(
99+
getByTestId('transaction-details-recipient-row'),
100+
).toBeInTheDocument();
101+
expect(getByText('Interacting with')).toBeInTheDocument();
102+
});
103+
});
61104
});

ui/pages/confirmations/components/confirm/info/batch/transaction-account-details/transaction-account-details.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ import {
1212
useIsUpgradeTransaction,
1313
} from '../../hooks/useIsUpgradeTransaction';
1414
import { useI18nContext } from '../../../../../../../hooks/useI18nContext';
15-
import { isBatchTransaction } from '../../../../../../../../shared/lib/transactions.utils';
1615
import { ConfirmInfoAlertRow } from '../../../../../../../components/app/confirm/info/row/alert-row/alert-row';
1716
import { RowAlertKey } from '../../../../../../../components/app/confirm/info/row/constants';
17+
import { RecipientRow } from '../../shared/transaction-details/transaction-details';
1818

1919
export function TransactionAccountDetails() {
2020
const t = useI18nContext();
2121
const { currentConfirmation } = useConfirmContext<TransactionMeta>();
2222
const isUpgrade = useIsUpgradeTransaction();
2323
const isDowngrade = useIsDowngradeTransaction();
2424
const { chainId, nestedTransactions, txParams, id } = currentConfirmation;
25-
const { from, to } = txParams;
26-
const isBatch = isBatchTransaction(from, nestedTransactions, to);
25+
const { from } = txParams;
26+
const isBatch = Boolean(nestedTransactions?.length);
2727

2828
if (!isUpgrade && !isDowngrade) {
2929
return null;
@@ -60,6 +60,7 @@ export function TransactionAccountDetails() {
6060
</ConfirmInfoRow>
6161
</>
6262
)}
63+
{isBatch && <RecipientRow />}
6364
</ConfirmInfoSection>
6465
);
6566
}

ui/pages/confirmations/components/confirm/info/shared/transaction-details/transaction-details.test.tsx

-37
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ import configureMockStore from 'redux-mock-store';
33
import thunk from 'redux-thunk';
44
import { Hex } from '@metamask/utils';
55
import { toHex } from '@metamask/controller-utils';
6-
import {
7-
NestedTransactionMetadata,
8-
TransactionType,
9-
} from '@metamask/transaction-controller';
106
import {
117
getMockConfirmState,
128
getMockConfirmStateForTransaction,
@@ -232,38 +228,5 @@ describe('<TransactionDetails />', () => {
232228
getByTestId('transaction-details-recipient-row'),
233229
).toBeInTheDocument();
234230
});
235-
236-
it('renders SmartContractWithLogo when transaction is a batch transaction', () => {
237-
const ADDRESS_MOCK = '0x88aa6343307ec9a652ccddda3646e62b2f1a5125';
238-
const ADDRESS_2_MOCK = '0x1234567890123456789012345678901234567891';
239-
const contractInteraction = genUnapprovedContractInteractionConfirmation({
240-
address: ADDRESS_MOCK,
241-
nestedTransactions: [
242-
{
243-
to: ADDRESS_MOCK,
244-
data: '0x1',
245-
type: TransactionType.contractInteraction,
246-
},
247-
{
248-
to: ADDRESS_2_MOCK,
249-
data: '0x2',
250-
type: TransactionType.contractInteraction,
251-
},
252-
] as NestedTransactionMetadata[],
253-
});
254-
const state = getMockConfirmStateForTransaction(contractInteraction, {
255-
metamask: {
256-
preferences: {
257-
showConfirmationAdvancedDetails: true,
258-
},
259-
},
260-
});
261-
const mockStore = configureMockStore(middleware)(state);
262-
const { getByText } = renderWithConfirmContextProvider(
263-
<TransactionDetails />,
264-
mockStore,
265-
);
266-
expect(getByText('Smart contract')).toBeInTheDocument();
267-
});
268231
});
269232
});

ui/pages/confirmations/components/confirm/info/shared/transaction-details/transaction-details.tsx

+10-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ export const OriginRow = () => {
6262
};
6363

6464
export const RecipientRow = ({ recipient }: { recipient?: Hex } = {}) => {
65+
console.log('RecipientRow >>>>');
66+
6567
const t = useI18nContext();
6668
const { currentConfirmation } = useConfirmContext<TransactionMeta>();
6769
const { from } = currentConfirmation?.txParams ?? {};
@@ -71,6 +73,7 @@ export const RecipientRow = ({ recipient }: { recipient?: Hex } = {}) => {
7173
Boolean(nestedTransactions?.length) &&
7274
to?.toLowerCase() === from.toLowerCase();
7375

76+
console.log('<>>>>>>>', to, from, isBatch);
7477
if (!to || !isValidAddress(to)) {
7578
return null;
7679
}
@@ -182,13 +185,19 @@ export const TransactionDetails = () => {
182185
if (currentConfirmation?.type === TransactionType.revokeDelegation) {
183186
return null;
184187
}
188+
const { nestedTransactions, txParams } = currentConfirmation ?? {};
189+
const { from, to } = txParams ?? {};
190+
191+
const isBatch =
192+
Boolean(nestedTransactions?.length) &&
193+
to?.toLowerCase() === from.toLowerCase();
185194

186195
return (
187196
<>
188197
<ConfirmInfoSection data-testid="transaction-details-section">
189198
<NetworkRow isShownWithAlertsOnly />
190199
<OriginRow />
191-
<RecipientRow />
200+
{!isBatch && <RecipientRow />}
192201
{showAdvancedDetails && <MethodDataRow />}
193202
<SigningInWithRow />
194203
</ConfirmInfoSection>

ui/pages/confirmations/hooks/alerts/transactions/useAccountTypeUpgrade.test.ts

-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
TransactionStatus,
44
TransactionType,
55
} from '@metamask/transaction-controller';
6-
import { isBatchTransaction } from '../../../../../../shared/lib/transactions.utils';
76
import { RowAlertKey } from '../../../../../components/app/confirm/info/row/constants';
87
import { Severity } from '../../../../../helpers/constants/design-system';
98
import { getMockConfirmStateForTransaction } from '../../../../../../test/data/confirmations/helper';
@@ -49,19 +48,15 @@ function runHook({
4948
}
5049

5150
describe('useAccountTypeUpgrade', () => {
52-
const isBatchTransactionMock = jest.mocked(isBatchTransaction);
53-
5451
beforeEach(() => {
5552
jest.resetAllMocks();
5653
});
5754

5855
it('returns an empty array when the transaction is not a batch transaction', () => {
59-
isBatchTransactionMock.mockReturnValue(false);
6056
expect(runHook()).toEqual([]);
6157
});
6258

6359
it('returns an alert when the transaction is a batch transaction', () => {
64-
isBatchTransactionMock.mockReturnValue(true);
6560
expect(
6661
runHook({
6762
currentConfirmation: {

ui/pages/confirmations/hooks/alerts/transactions/useAccountTypeUpgrade.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@ import { TransactionMeta } from '@metamask/transaction-controller';
33
import { useI18nContext } from '../../../../../hooks/useI18nContext';
44
import { useConfirmContext } from '../../../context/confirm';
55
import { Alert } from '../../../../../ducks/confirm-alerts/confirm-alerts';
6-
import { isBatchTransaction } from '../../../../../../shared/lib/transactions.utils';
76
import { RowAlertKey } from '../../../../../components/app/confirm/info/row/constants';
87
import { Severity } from '../../../../../helpers/constants/design-system';
98
import { AccountTypeMessage } from './AccountTypeMessage';
109

1110
export function useAccountTypeUpgrade(): Alert[] {
1211
const t = useI18nContext();
1312
const { currentConfirmation } = useConfirmContext<TransactionMeta>();
14-
const { nestedTransactions, txParams } = currentConfirmation ?? {};
15-
const { from, to } = txParams ?? {};
16-
console.log('currentConfirmation', from, nestedTransactions, to);
17-
const isBatch = isBatchTransaction(from, nestedTransactions, to);
18-
console.log('isBatch', isBatch);
13+
const { nestedTransactions } = currentConfirmation ?? {};
14+
15+
const isBatch = Boolean(nestedTransactions?.length);
16+
1917
return useMemo(() => {
2018
if (!isBatch) {
2119
return [];

0 commit comments

Comments
 (0)