Skip to content

Commit ff34c51

Browse files
committed
test(predict): cover predictWithdraw summary lines and dedupe selector
1 parent 7aff1c7 commit ff34c51

3 files changed

Lines changed: 117 additions & 4 deletions

File tree

app/components/Views/confirmations/components/activity/transaction-details-summary/receive-summary-line.test.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { selectBridgeHistoryForAccount } from '../../../../../../selectors/bridg
1313
import { useBridgeTxHistoryData } from '../../../../../../util/bridge/hooks/useBridgeTxHistoryData';
1414
import { useTokenAmount } from '../../../hooks/useTokenAmount';
1515
import { useTransactionDetails } from '../../../hooks/activity/useTransactionDetails';
16+
import { useTokenWithBalance } from '../../../hooks/tokens/useTokenWithBalance';
1617
import { ReceiveSummaryLine } from './receive-summary-line';
1718

1819
jest.mock('../../../../../UI/Bridge/hooks/useMultichainBlockExplorerTxUrl');
@@ -21,6 +22,7 @@ jest.mock('../../../../../../selectors/bridgeStatusController');
2122
jest.mock('../../../../../../util/bridge/hooks/useBridgeTxHistoryData');
2223
jest.mock('../../../hooks/useTokenAmount');
2324
jest.mock('../../../hooks/activity/useTransactionDetails');
25+
jest.mock('../../../hooks/tokens/useTokenWithBalance');
2426

2527
jest.mock('@react-navigation/native', () => ({
2628
...jest.requireActual('@react-navigation/native'),
@@ -161,4 +163,36 @@ describe('ReceiveSummaryLine', () => {
161163
),
162164
).toBeDefined();
163165
});
166+
167+
it('renders predict withdraw title using source token symbol and source network', () => {
168+
useNetworkNameMock.mockImplementation((chainId?: Hex) =>
169+
chainId === '0x1' ? 'Ethereum' : 'Polygon',
170+
);
171+
jest
172+
.mocked(useTokenWithBalance)
173+
.mockReturnValue({ symbol: 'USDC' } as ReturnType<
174+
typeof useTokenWithBalance
175+
>);
176+
177+
const { getByText } = render({
178+
id: 'tx-id',
179+
chainId: '0x89' as Hex,
180+
hash: '0x123',
181+
submittedTime: 1755719285723,
182+
type: TransactionType.predictWithdraw,
183+
metamaskPay: {
184+
chainId: '0x1' as Hex,
185+
tokenAddress: '0xabc' as Hex,
186+
},
187+
} as Partial<TransactionMeta>);
188+
189+
expect(
190+
getByText(
191+
strings('transaction_details.summary_title.bridge_receive', {
192+
targetSymbol: 'USDC',
193+
targetChain: 'Ethereum',
194+
}),
195+
),
196+
).toBeDefined();
197+
});
164198
});

app/components/Views/confirmations/components/activity/transaction-details-summary/source-hash-summary-line.test.tsx

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import React from 'react';
22
import { fireEvent } from '@testing-library/react-native';
3-
import { TransactionMeta } from '@metamask/transaction-controller';
3+
import {
4+
TransactionMeta,
5+
TransactionType,
6+
} from '@metamask/transaction-controller';
47
import { Hex } from '@metamask/utils';
58
import renderWithProvider from '../../../../../../util/test/renderWithProvider';
69
import { strings } from '../../../../../../../locales/i18n';
@@ -31,19 +34,19 @@ jest.mock('@react-navigation/native', () => ({
3134
}),
3235
}));
3336

34-
function render() {
37+
function render(parentTransaction?: Partial<TransactionMeta>) {
3538
return renderWithProvider(
3639
<SourceHashSummaryLine
3740
parentTransaction={
38-
{
41+
(parentTransaction ?? {
3942
id: 'parent-id',
4043
chainId: '0x1',
4144
submittedTime: 1755719285723,
4245
metamaskPay: {
4346
tokenAddress: '0x123',
4447
chainId: '0x1',
4548
},
46-
} as unknown as TransactionMeta
49+
}) as unknown as TransactionMeta
4750
}
4851
sourceHash={'0xabc' as Hex}
4952
/>,
@@ -118,4 +121,30 @@ describe('SourceHashSummaryLine', () => {
118121
},
119122
});
120123
});
124+
125+
it('renders predict-withdraw title with pUSD and target network', () => {
126+
useNetworkNameMock.mockImplementation((chainId?: Hex) =>
127+
chainId === '0x89' ? 'Polygon' : 'Ethereum',
128+
);
129+
130+
const { getByText } = render({
131+
id: 'parent-id',
132+
chainId: '0x89' as Hex,
133+
submittedTime: 1755719285723,
134+
type: TransactionType.predictWithdraw,
135+
metamaskPay: {
136+
tokenAddress: '0x123' as Hex,
137+
chainId: '0x1' as Hex,
138+
},
139+
} as Partial<TransactionMeta>);
140+
141+
expect(
142+
getByText(
143+
strings('transaction_details.summary_title.predict_withdraw', {
144+
sourceSymbol: 'pUSD',
145+
sourceChain: 'Polygon',
146+
}),
147+
),
148+
).toBeDefined();
149+
});
121150
});

app/selectors/transactionController.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,56 @@ describe('TransactionController Selectors', () => {
233233
expect.objectContaining({ id: 'parent' }),
234234
]);
235235
});
236+
237+
it('keeps nonce-less transactions that share an actionId', () => {
238+
const activeEvmAddress = '0x0000000000000000000000000000000000000001';
239+
const state = {
240+
engine: {
241+
backgroundState: {
242+
AccountsController: {
243+
internalAccounts: {
244+
selectedAccount: 'account-1',
245+
accounts: {
246+
'account-1': {
247+
id: 'account-1',
248+
address: activeEvmAddress,
249+
type: 'eip155:eoa',
250+
},
251+
},
252+
},
253+
},
254+
TransactionController: {
255+
transactions: [
256+
{
257+
id: 'tx-a',
258+
chainId: '0x1',
259+
time: 100,
260+
txParams: {
261+
from: activeEvmAddress,
262+
actionId: 'shared-action',
263+
},
264+
},
265+
{
266+
id: 'tx-b',
267+
chainId: '0x1',
268+
time: 200,
269+
txParams: {
270+
from: activeEvmAddress,
271+
actionId: 'shared-action',
272+
},
273+
},
274+
],
275+
},
276+
},
277+
},
278+
pendingSmartTransactionsForGroup: [],
279+
} as unknown as RootState;
280+
281+
const ids = selectLocalTransactions(state).map((t) => t.id);
282+
283+
expect(ids).toContain('tx-a');
284+
expect(ids).toContain('tx-b');
285+
});
236286
});
237287

238288
describe('selectTransactionMetadataById', () => {

0 commit comments

Comments
 (0)