diff --git a/app/util/smart-transactions/index.test.ts b/app/util/smart-transactions/index.test.ts index f10f3403108..2bad676e57c 100644 --- a/app/util/smart-transactions/index.test.ts +++ b/app/util/smart-transactions/index.test.ts @@ -283,37 +283,53 @@ describe('Smart Transactions utils', () => { }); describe('getShouldStartFlow', () => { it('returns true for Send transaction', () => { - const res = getShouldStartApprovalRequest(false, true, false, false); + const res = getShouldStartApprovalRequest(false, true, false, false, false); expect(res).toBe(true); }); + it('returns false for Send transaction when mobileReturnTxHashAsap is true', () => { + const res = getShouldStartApprovalRequest(false, true, false, false, true); + expect(res).toBe(false); + }); it('returns true for Dapp transaction', () => { - const res = getShouldStartApprovalRequest(true, false, false, false); + const res = getShouldStartApprovalRequest(true, false, false, false, false); expect(res).toBe(true); }); + it('returns false for Dapp transaction when mobileReturnTxHashAsap is true', () => { + const res = getShouldStartApprovalRequest(true, false, false, false, true); + expect(res).toBe(false); + }); it('returns true for Swap approve transaction', () => { - const res = getShouldStartApprovalRequest(false, false, true, false); + const res = getShouldStartApprovalRequest(false, false, true, false, false); expect(res).toBe(true); }); it('returns false for Swap transaction', () => { - const res = getShouldStartApprovalRequest(false, false, false, true); + const res = getShouldStartApprovalRequest(false, false, false, true, false); expect(res).toBe(false); }); }); describe('getShouldUpdateFlow', () => { it('returns true for Send transaction', () => { - const res = getShouldUpdateApprovalRequest(false, true, false); + const res = getShouldUpdateApprovalRequest(false, true, false, false); expect(res).toBe(true); }); + it('returns false for Send transaction when mobileReturnTxHashAsap is true', () => { + const res = getShouldUpdateApprovalRequest(false, true, false, true); + expect(res).toBe(false); + }); it('returns true for Dapp transaction', () => { - const res = getShouldUpdateApprovalRequest(true, false, false); + const res = getShouldUpdateApprovalRequest(true, false, false, false); expect(res).toBe(true); }); + it('returns false for Dapp transaction when mobileReturnTxHashAsap is true', () => { + const res = getShouldUpdateApprovalRequest(true, false, false, true); + expect(res).toBe(false); + }); it('returns true for Swap transaction', () => { - const res = getShouldUpdateApprovalRequest(false, false, true); + const res = getShouldUpdateApprovalRequest(false, false, true, false); expect(res).toBe(true); }); it('returns false for Swap approve transaction', () => { - const res = getShouldUpdateApprovalRequest(false, false, false); + const res = getShouldUpdateApprovalRequest(false, false, false, false); expect(res).toBe(false); }); }); diff --git a/app/util/smart-transactions/index.ts b/app/util/smart-transactions/index.ts index d831b4ec20f..4b190b5b2a0 100644 --- a/app/util/smart-transactions/index.ts +++ b/app/util/smart-transactions/index.ts @@ -69,14 +69,18 @@ export const getShouldStartApprovalRequest = ( isSend: boolean, isSwapApproveTx: boolean, hasPendingApprovalForSwapApproveTx: boolean, + mobileReturnTxHashAsap: boolean, ): boolean => - isDapp || isSend || isSwapApproveTx || !hasPendingApprovalForSwapApproveTx; + !mobileReturnTxHashAsap && + (isDapp || isSend || isSwapApproveTx || !hasPendingApprovalForSwapApproveTx); export const getShouldUpdateApprovalRequest = ( isDapp: boolean, isSend: boolean, isSwapTransaction: boolean, -): boolean => isDapp || isSend || isSwapTransaction; + mobileReturnTxHashAsap: boolean, +): boolean => + !mobileReturnTxHashAsap && (isDapp || isSend || isSwapTransaction); const waitForSmartTransactionConfirmationDone = ( controllerMessenger: ControllerMessenger, diff --git a/app/util/smart-transactions/smart-publish-hook.test.ts b/app/util/smart-transactions/smart-publish-hook.test.ts index a495cb5d247..3953ad17ee5 100644 --- a/app/util/smart-transactions/smart-publish-hook.test.ts +++ b/app/util/smart-transactions/smart-publish-hook.test.ts @@ -362,6 +362,69 @@ describe('submitSmartTransactionHook', () => { ); }); + it('submits a smart transaction without the smart transaction status page', async () => { + withRequest( + async ({ request, controllerMessenger, submitSignedTransactionsSpy }) => { + request.featureFlags.smartTransactions.mobileReturnTxHashAsap = true; + setImmediate(() => { + controllerMessenger.publish( + 'SmartTransactionsController:smartTransaction', + { + status: 'pending', + statusMetadata: { + minedHash: '', + }, + uuid: 'uuid', + } as SmartTransaction, + ); + + controllerMessenger.publish( + 'SmartTransactionsController:smartTransaction', + { + status: 'success', + statusMetadata: { + minedHash: transactionHash, + }, + uuid: 'uuid', + } as SmartTransaction, + ); + }); + const result = await submitSmartTransactionHook(request); + + expect(result).toEqual({ transactionHash }); + const { txParams, chainId } = request.transactionMeta; + + expect( + request.transactionController.approveTransactionsWithSameNonce, + ).toHaveBeenCalledWith( + [ + { + ...txParams, + maxFeePerGas: '0x2fd8a58d7', + maxPriorityFeePerGas: '0xaa0f8a94', + chainId, + value: undefined, + }, + ], + { hasNonce: true }, + ); + expect(submitSignedTransactionsSpy).toHaveBeenCalledWith({ + signedTransactions: [createSignedTransaction()], + signedCanceledTransactions: [], + txParams, + transactionMeta: request.transactionMeta, + }); + + expect( + request.approvalController.addAndShowApprovalRequest, + ).not.toHaveBeenCalled(); + expect( + request.approvalController.updateRequestState, + ).not.toHaveBeenCalled(); + }, + ); + }); + describe('MM Swaps', () => { it('starts an approval and does not end it if there is an swap tx that requires allowance', async () => { withRequest( diff --git a/app/util/smart-transactions/smart-publish-hook.ts b/app/util/smart-transactions/smart-publish-hook.ts index 2ed010b3d6f..16ecfa2bdf9 100644 --- a/app/util/smart-transactions/smart-publish-hook.ts +++ b/app/util/smart-transactions/smart-publish-hook.ts @@ -94,6 +94,7 @@ class SmartTransactionHook { #shouldStartApprovalRequest: boolean; #shouldUpdateApprovalRequest: boolean; + #mobileReturnTxHashAsap: boolean; constructor(request: SubmitSmartTransactionRequest) { const { @@ -116,6 +117,8 @@ class SmartTransactionHook { this.#chainId = transactionMeta.chainId; this.#txParams = transactionMeta.txParams; this.#controllerMessenger = controllerMessenger; + this.#mobileReturnTxHashAsap = + this.#featureFlags?.smartTransactions?.mobileReturnTxHashAsap ?? false; const { isDapp, @@ -143,11 +146,13 @@ class SmartTransactionHook { this.#isSend, this.#isSwapApproveTx, Boolean(approvalIdForPendingSwapApproveTx), + this.#mobileReturnTxHashAsap, ); this.#shouldUpdateApprovalRequest = getShouldUpdateApprovalRequest( this.#isDapp, this.#isSend, this.#isSwapTransaction, + this.#mobileReturnTxHashAsap, ); } @@ -221,9 +226,7 @@ class SmartTransactionHook { ); throw error; } finally { - const mobileReturnTxHashAsap = - this.#featureFlags?.smartTransactions?.mobileReturnTxHashAsap; - if (!mobileReturnTxHashAsap) { + if (!this.#mobileReturnTxHashAsap) { this.#cleanup(); } } @@ -266,10 +269,8 @@ class SmartTransactionHook { uuid: string, ) => { let transactionHash: string | undefined | null; - const mobileReturnTxHashAsap = - this.#featureFlags?.smartTransactions?.mobileReturnTxHashAsap; - if (mobileReturnTxHashAsap && submitTransactionResponse?.txHash) { + if (this.#mobileReturnTxHashAsap && submitTransactionResponse?.txHash) { transactionHash = submitTransactionResponse.txHash; } else { transactionHash = await this.#waitForTransactionHash({