diff --git a/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.component.js b/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.component.js index e7f99f6f3b36..18cefa0e724b 100644 --- a/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.component.js +++ b/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.component.js @@ -178,6 +178,7 @@ export default class ConfirmTransactionBase extends Component { smartTransactionsOptInStatus: PropTypes.bool, currentChainSupportsSmartTransactions: PropTypes.bool, selectedNetworkClientId: PropTypes.string, + isSmartTransactionsEnabled: PropTypes.bool, }; state = { @@ -825,6 +826,7 @@ export default class ConfirmTransactionBase extends Component { toAddress, showCustodianDeepLink, clearConfirmTransaction, + isSmartTransactionsEnabled, } = this.props; const { noteText } = this.state; @@ -836,6 +838,10 @@ export default class ConfirmTransactionBase extends Component { txData.metadata.note = noteText; } + if (isSmartTransactionsEnabled) { + txData.origin += '#smartTransaction'; + } + txData.metadata.custodianPublishesTransaction = custodianPublishesTransaction; txData.metadata.rpcUrl = rpcUrl; diff --git a/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.container.js b/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.container.js index 3734b231dad5..00cbdeefa01d 100644 --- a/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.container.js +++ b/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.container.js @@ -58,6 +58,9 @@ import { import { getCurrentChainSupportsSmartTransactions, getSmartTransactionsOptInStatus, + ///: BEGIN:ONLY_INCLUDE_IF(build-mmi) + getSmartTransactionsEnabled, + ///: END:ONLY_INCLUDE_IF } from '../../../../shared/modules/selectors'; import { getMostRecentOverviewPage } from '../../../ducks/history/history'; import { @@ -345,6 +348,7 @@ const mapStateToProps = (state, ownProps) => { isNotification, custodianPublishesTransaction, rpcUrl, + isSmartTransactionsEnabled: getSmartTransactionsEnabled(state), ///: END:ONLY_INCLUDE_IF }; }; diff --git a/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.test.js b/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.test.js index 5cf90c0da6cb..bc36b2667576 100644 --- a/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.test.js +++ b/ui/pages/confirmations/confirm-transaction-base/confirm-transaction-base.test.js @@ -45,9 +45,9 @@ setBackgroundConnection({ }), ), getGasFeeTimeEstimate: jest.fn(), - promisifiedBackground: jest.fn(), tryReverseResolveAddress: jest.fn(), getNextNonce: jest.fn(), + updateTransaction: jest.fn(), }); const mockTxParamsFromAddress = '0x123456789'; @@ -470,14 +470,12 @@ describe('Confirm Transaction Base', () => { const sendTransaction = jest .fn() .mockResolvedValue(state.confirmTransaction.txData); - const updateTransaction = jest.fn().mockResolvedValue(); const updateTransactionValue = jest.fn().mockResolvedValue(); const showCustodianDeepLink = jest.fn(); const setWaitForConfirmDeepLinkDialog = jest.fn(); const props = { sendTransaction, - updateTransaction, updateTransactionValue, showCustodianDeepLink, setWaitForConfirmDeepLinkDialog, @@ -497,12 +495,19 @@ describe('Confirm Transaction Base', () => { expect(sendTransaction).toHaveBeenCalled(); }); - it('handleMainSubmit calls sendTransaction correctly', async () => { + it('handleMMISubmit calls sendTransaction correctly and then showCustodianDeepLink', async () => { const state = { appState: { ...baseStore.appState, gasLoadingAnimationIsShowing: false, }, + confirmTransaction: { + ...baseStore.confirmTransaction, + txData: { + ...baseStore.confirmTransaction.txData, + custodyStatus: true, + }, + }, metamask: { ...baseStore.metamask, accounts: { @@ -516,7 +521,9 @@ describe('Confirm Transaction Base', () => { networksMetadata: { ...baseStore.metamask.networksMetadata, [NetworkType.mainnet]: { - EIPS: { 1559: true }, + EIPS: { + 1559: true, + }, status: NetworkStatus.Available, }, }, @@ -525,6 +532,47 @@ describe('Confirm Transaction Base', () => { gasPrice: '0x59682f00', }, noGasPrice: false, + keyrings: [ + { + type: 'Custody', + accounts: [mockTxParamsFromAddress], + }, + ], + custodyAccountDetails: { + [mockTxParamsFromAddress]: { + address: mockTxParamsFromAddress, + details: 'details', + custodyType: 'testCustody - Saturn', + custodianName: 'saturn-dev', + }, + }, + mmiConfiguration: { + custodians: [ + { + envName: 'saturn-dev', + displayName: 'Saturn Custody', + isNoteToTraderSupported: false, + }, + ], + }, + internalAccounts: { + accounts: { + 'cf8dace4-9439-4bd4-b3a8-88c821c8fcb3': { + address: mockTxParamsFromAddress, + id: 'cf8dace4-9439-4bd4-b3a8-88c821c8fcb3', + metadata: { + name: 'Custody Account A', + keyring: { + type: 'Custody', + }, + }, + options: {}, + methods: ETH_EOA_METHODS, + type: EthAccountType.Eoa, + }, + }, + selectedAccount: 'cf8dace4-9439-4bd4-b3a8-88c821c8fcb3', + }, }, send: { ...baseStore.send, @@ -546,12 +594,19 @@ describe('Confirm Transaction Base', () => { }, }; - const sendTransaction = jest.fn().mockResolvedValue(); + const sendTransaction = jest + .fn() + .mockResolvedValue(state.confirmTransaction.txData); + const showCustodianDeepLink = jest.fn(); + const setWaitForConfirmDeepLinkDialog = jest.fn(); const props = { sendTransaction, + showCustodianDeepLink, + setWaitForConfirmDeepLinkDialog, toAddress: mockPropsToAddress, toAccounts: [{ address: mockPropsToAddress }], + isMainBetaFlask: false, }; const { getByTestId } = await render({ props, state }); @@ -560,10 +615,12 @@ describe('Confirm Transaction Base', () => { await act(async () => { fireEvent.click(confirmButton); }); - expect(sendTransaction).toHaveBeenCalled(); + expect(setWaitForConfirmDeepLinkDialog).toHaveBeenCalled(); + await expect(sendTransaction).toHaveBeenCalled(); + expect(showCustodianDeepLink).toHaveBeenCalled(); }); - it('handleMMISubmit calls sendTransaction correctly and then showCustodianDeepLink', async () => { + it('should append #smartTransaction to txData.origin when smartTransactionsOptInStatus and currentChainSupportsSmartTransactions are true', async () => { const state = { appState: { ...baseStore.appState, @@ -574,6 +631,7 @@ describe('Confirm Transaction Base', () => { txData: { ...baseStore.confirmTransaction.txData, custodyStatus: true, + origin: 'metamask#smartTransaction', }, }, metamask: { @@ -600,6 +658,47 @@ describe('Confirm Transaction Base', () => { gasPrice: '0x59682f00', }, noGasPrice: false, + keyrings: [ + { + type: 'Custody', + accounts: [mockTxParamsFromAddress], + }, + ], + custodyAccountDetails: { + [mockTxParamsFromAddress]: { + address: mockTxParamsFromAddress, + details: 'details', + custodyType: 'testCustody - Saturn', + custodianName: 'saturn-dev', + }, + }, + mmiConfiguration: { + custodians: [ + { + envName: 'saturn-dev', + displayName: 'Saturn Custody', + isNoteToTraderSupported: false, + }, + ], + }, + internalAccounts: { + accounts: { + 'cf8dace4-9439-4bd4-b3a8-88c821c8fcb3': { + address: mockTxParamsFromAddress, + id: 'cf8dace4-9439-4bd4-b3a8-88c821c8fcb3', + metadata: { + name: 'Custody Account A', + keyring: { + type: 'Custody', + }, + }, + options: {}, + methods: ETH_EOA_METHODS, + type: EthAccountType.Eoa, + }, + }, + selectedAccount: 'cf8dace4-9439-4bd4-b3a8-88c821c8fcb3', + }, }, send: { ...baseStore.send, @@ -642,9 +741,12 @@ describe('Confirm Transaction Base', () => { await act(async () => { fireEvent.click(confirmButton); }); - expect(setWaitForConfirmDeepLinkDialog).toHaveBeenCalled(); - await expect(sendTransaction).toHaveBeenCalled(); - expect(showCustodianDeepLink).toHaveBeenCalled(); + + expect(sendTransaction).toHaveBeenCalledWith( + expect.objectContaining({ + origin: 'metamask#smartTransaction', + }), + ); }); describe('when rendering the recipient value', () => {