diff --git a/app/components/Views/confirmations/SendFlow/Confirm/index.js b/app/components/Views/confirmations/SendFlow/Confirm/index.js index 4aae1abb75f..a8b8d3641a2 100644 --- a/app/components/Views/confirmations/SendFlow/Confirm/index.js +++ b/app/components/Views/confirmations/SendFlow/Confirm/index.js @@ -12,6 +12,7 @@ import { connect } from 'react-redux'; import { getSendFlowTitle } from '../../../../UI/Navbar'; import PropTypes from 'prop-types'; import Eth from '@metamask/ethjs-query'; +import { isEmpty } from 'lodash'; import { renderFromWei, renderFromTokenMinimalUnit, @@ -486,11 +487,25 @@ class Confirm extends PureComponent { const { TransactionController } = Engine.context; const transactionParams = this.prepareTransactionToSend(); - const { result, transactionMeta } = - await TransactionController.addTransaction(transactionParams, { - deviceConfirmedOn: WalletDevice.MM_MOBILE, - origin: TransactionTypes.MMM, - }); + let result, transactionMeta; + try { + ({ result, transactionMeta } = await TransactionController.addTransaction( + transactionParams, + { + deviceConfirmedOn: WalletDevice.MM_MOBILE, + origin: TransactionTypes.MMM, + }, + )); + } catch (error) { + Logger.error(error, 'error while adding transaction (Confirm)'); + navigation?.dangerouslyGetParent()?.pop(); + Alert.alert( + strings('transactions.transaction_error'), + error && error.message, + [{ text: 'OK' }], + ); + return; + } setTransactionId(transactionMeta.id); @@ -1305,6 +1320,7 @@ class Confirm extends PureComponent { EIP1559GasObject, EIP1559GasTransaction, legacyGasObject, + transactionMeta, } = this.state; const colors = this.context.colors || mockTheme.colors; const styles = createStyles(colors); @@ -1477,6 +1493,7 @@ class Confirm extends PureComponent { { ); }); }); + + it('should show error if transaction is not added', async () => { + jest.spyOn(Alert, 'alert'); + + Engine.context.TransactionController.addTransaction = jest + .fn() + .mockRejectedValue(new Error('Transaction not added')); + + render(Confirm); + + await flushPromises(); + + await waitFor(() => { + expect(Alert.alert).toHaveBeenCalledWith( + 'Transaction error', + 'Transaction not added', + expect.any(Array), + ); + }); + }); });