Skip to content

Commit f01fb75

Browse files
fix: cp-7.60.0 block metamask pay if submitted transaction (#22904)
## **Description** Show an alert if doing a Perps or Predict deposit and there is an existing submitted transaction on the same chain and account. ## **Changelog** CHANGELOG entry: null ## **Related issues** Fixes: #22762 ## **Manual testing steps** ## **Screenshots/Recordings** ### **Before** ### **After** ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Alerts now trigger for Perps/Predict deposits when an existing transaction is in submitted status on the same chain/account; tests updated/added. > > - **Alerts**: > - Update `useSignedOrSubmittedAlert` to include `TransactionStatus.submitted` as a blocking status when the current transaction is a Pay type (`perpsDeposit`, `predictDeposit`). > - **Tests**: > - Add cases verifying alerts show when an existing transaction is `submitted` and current type is any in `PAY_TYPES`. > - Ensure existing behavior for signed/approved, chain/account checks, and Pay-type messaging remains validated. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 968d285. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 860d110 commit f01fb75

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

app/components/Views/confirmations/hooks/alerts/useSignedOrSubmittedAlert.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,46 @@ describe('useSignedOrSubmittedAlert', () => {
208208
]);
209209
},
210210
);
211+
212+
it.each(PAY_TYPES)(
213+
'returns alert if existing transaction is submitted and current type is %s',
214+
(type) => {
215+
mockUseTransactionMetadataRequest.mockReturnValue({
216+
...TRANSACTION_META_MOCK,
217+
id: '2',
218+
status: TransactionStatus.confirmed,
219+
type,
220+
} as TransactionMeta);
221+
222+
const existingTransaction = {
223+
...TRANSACTION_META_MOCK,
224+
status: TransactionStatus.submitted,
225+
};
226+
227+
const { result } = renderHookWithProvider(
228+
() => useSignedOrSubmittedAlert(),
229+
{
230+
state: {
231+
engine: {
232+
backgroundState: {
233+
TransactionController: {
234+
transactions: [existingTransaction],
235+
},
236+
},
237+
},
238+
},
239+
},
240+
);
241+
242+
expect(result.current).toStrictEqual([
243+
{
244+
isBlocking: true,
245+
key: AlertKeys.SignedOrSubmitted,
246+
message: strings('alert_system.signed_or_submitted.message'),
247+
title: strings('alert_system.signed_or_submitted.title'),
248+
severity: Severity.Danger,
249+
},
250+
]);
251+
},
252+
);
211253
});

app/components/Views/confirmations/hooks/alerts/useSignedOrSubmittedAlert.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,20 @@ export const useSignedOrSubmittedAlert = () => {
2525
const { chainId, id: transactionId, txParams } = transactionMetadata || {};
2626
const { from } = txParams ?? {};
2727

28-
const existingTransaction = transactions.find(
29-
(transaction) =>
30-
BLOCK_STATUS.includes(transaction.status) &&
28+
const existingTransaction = transactions.find((transaction) => {
29+
const blockStatuses = [...BLOCK_STATUS];
30+
31+
if (hasTransactionType(transactionMetadata, PAY_TYPES)) {
32+
blockStatuses.push(TransactionStatus.submitted);
33+
}
34+
35+
return (
36+
blockStatuses.includes(transaction.status) &&
3137
transaction.id !== transactionId &&
3238
transaction.chainId === chainId &&
33-
transaction.txParams.from.toLowerCase() === from?.toLowerCase(),
34-
);
39+
transaction.txParams.from.toLowerCase() === from?.toLowerCase()
40+
);
41+
});
3542

3643
const isTransactionPay = PAY_TYPES.some(
3744
(payType) =>

0 commit comments

Comments
 (0)