diff --git a/src/languages/en.js b/src/languages/en.js index 008c81006115..01ac64feee79 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -392,7 +392,6 @@ export default { setDefaultSuccess: 'Default payment method set!', deleteAccount: 'Delete Account', deleteConfirmation: 'Are you sure that you want to delete this account?', - deleteBankAccountSuccess: 'Bank account successfully deleted', deletePayPalSuccess: 'PayPal.me successfully deleted', error: { notOwnerOfBankAccount: 'There was an error setting this bank account as your default payment method.', diff --git a/src/languages/es.js b/src/languages/es.js index 778127f86485..64a045854051 100644 --- a/src/languages/es.js +++ b/src/languages/es.js @@ -392,7 +392,6 @@ export default { setDefaultSuccess: 'Método de pago configurado', deleteAccount: 'Eliminar cuenta', deleteConfirmation: '¿Estás seguro de que quieres eliminar esta cuenta?', - deleteBankAccountSuccess: 'Cuenta bancaria eliminada correctamente', deletePayPalSuccess: 'PayPal.me eliminada correctamente', error: { notOwnerOfBankAccount: 'Ha ocurrido un error al establecer esta cuenta bancaria como tu método de pago predeterminado.', diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index 8fb86b3c25dd..26966eb7f730 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -1,13 +1,8 @@ -import lodashGet from 'lodash/get'; import Onyx from 'react-native-onyx'; import CONST from '../../CONST'; -import * as DeprecatedAPI from '../deprecatedAPI'; import * as API from '../API'; -import * as ReimbursementAccount from './ReimbursementAccount'; import ONYXKEYS from '../../ONYXKEYS'; -import Growl from '../Growl'; import * as Localize from '../Localize'; -import * as store from './ReimbursementAccount/store'; export { setupWithdrawalAccount, @@ -104,36 +99,23 @@ function addPersonalBankAccount(account, password) { API.write(commandName, parameters, onyxData); } -/** - * Deletes a bank account - * - * @param {Number} bankAccountID - */ -function deleteBankAccount(bankAccountID) { - const reimbursementBankAccountId = lodashGet(store.getReimbursementAccountInSetup(), 'bankAccountID'); - - // Early return as DeleteBankAccount API is called inside `resetFreePlanBankAccount` - if (reimbursementBankAccountId === bankAccountID) { - ReimbursementAccount.resetFreePlanBankAccount(); - return; - } - DeprecatedAPI.DeleteBankAccount({ +function deletePaymentBankAccount(bankAccountID) { + API.write('DeletePaymentBankAccount', { bankAccountID, - }).then((response) => { - if (response.jsonCode === 200) { - ReimbursementAccount.deleteFromBankAccountList(bankAccountID); - Growl.show(Localize.translateLocal('paymentsPage.deleteBankAccountSuccess'), CONST.GROWL.SUCCESS, 3000); - } else { - Growl.show(Localize.translateLocal('common.genericErrorMessage'), CONST.GROWL.ERROR, 3000); - } - }).catch(() => { - Growl.show(Localize.translateLocal('common.genericErrorMessage'), CONST.GROWL.ERROR, 3000); + }, { + optimisticData: [ + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: `${ONYXKEYS.BANK_ACCOUNT_LIST}`, + value: {[bankAccountID]: {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}}, + }, + ], }); } export { addPersonalBankAccount, - deleteBankAccount, + deletePaymentBankAccount, clearPersonalBankAccount, clearPlaid, }; diff --git a/src/libs/deprecatedAPI.js b/src/libs/deprecatedAPI.js index eff8088a6744..de9a7e2c0b61 100644 --- a/src/libs/deprecatedAPI.js +++ b/src/libs/deprecatedAPI.js @@ -483,18 +483,6 @@ function BankAccount_SetupWithdrawal(parameters) { ); } -/** - * @param {Object} parameters - * @param {Number} parameters.bankAccountID - * @param {String} parameters.ownerEmail - * @returns {Promise} - */ -function DeleteBankAccount(parameters) { - const commandName = 'DeleteBankAccount'; - requireParameters(['bankAccountID'], parameters, commandName); - return Network.post(commandName, parameters); -} - /** * @param {Object} parameters * @param {Number} [parameters.latitude] @@ -670,7 +658,6 @@ export { CreatePolicyRoom, RenameReport, DeleteLogin, - DeleteBankAccount, Get, GetStatementPDF, GetIOUReport, diff --git a/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js b/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js index d127abbfa705..1d0dadc698de 100644 --- a/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js +++ b/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js @@ -246,7 +246,7 @@ class BasePaymentsPage extends React.Component { if (this.state.selectedPaymentMethodType === CONST.PAYMENT_METHODS.PAYPAL) { PaymentMethods.deletePayPalMe(); } else if (this.state.selectedPaymentMethodType === CONST.PAYMENT_METHODS.BANK_ACCOUNT) { - BankAccounts.deleteBankAccount(this.state.selectedPaymentMethod.bankAccountID); + BankAccounts.deletePaymentBankAccount(this.state.selectedPaymentMethod.bankAccountID); } else if (this.state.selectedPaymentMethodType === CONST.PAYMENT_METHODS.DEBIT_CARD) { PaymentMethods.deletePaymentCard(this.state.selectedPaymentMethod.fundID); }