Skip to content

Commit

Permalink
Merge pull request #9609 from Expensify/jack-refactorDeleteDebitCard
Browse files Browse the repository at this point in the history
Refactor DeleteFund
  • Loading branch information
Justice Arthur authored Aug 11, 2022
2 parents 72dcbe4 + 0cede96 commit 37eacaf
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 38 deletions.
1 change: 0 additions & 1 deletion src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ export default {
deleteAccount: 'Delete Account',
deleteConfirmation: 'Are you sure that you want to delete this account?',
deleteBankAccountSuccess: 'Bank account successfully deleted',
deleteDebitCardSuccess: 'Debit Card successfully deleted',
deletePayPalSuccess: 'PayPal.me successfully deleted',
error: {
notOwnerOfBankAccount: 'There was an error setting this bank account as your default payment method.',
Expand Down
1 change: 0 additions & 1 deletion src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ export default {
deleteAccount: 'Eliminar cuenta',
deleteConfirmation: '¿Estás seguro de que quieres eliminar esta cuenta?',
deleteBankAccountSuccess: 'Cuenta bancaria eliminada correctamente',
deleteDebitCardSuccess: 'Tarjeta de débito 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.',
Expand Down
38 changes: 15 additions & 23 deletions src/libs/actions/PaymentMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,6 @@ import * as User from './User';
import * as store from './ReimbursementAccount/store';
import ROUTES from '../../ROUTES';

/**
* Deletes a debit card
*
* @param {Number} fundID
*
* @returns {Promise}
*/
function deleteDebitCard(fundID) {
return DeprecatedAPI.DeleteFund({fundID})
.then((response) => {
if (response.jsonCode === 200) {
Growl.show(Localize.translateLocal('paymentsPage.deleteDebitCardSuccess'), CONST.GROWL.SUCCESS, 3000);
Onyx.merge(ONYXKEYS.CARD_LIST, {[fundID]: null});
} else {
Growl.show(Localize.translateLocal('common.genericErrorMessage'), CONST.GROWL.ERROR, 3000);
}
})
.catch(() => {
Growl.show(Localize.translateLocal('common.genericErrorMessage'), CONST.GROWL.ERROR, 3000);
});
}

function deletePayPalMe() {
User.deletePaypalMeAddress();
Growl.show(Localize.translateLocal('paymentsPage.deletePayPalSuccess'), CONST.GROWL.SUCCESS, 3000);
Expand Down Expand Up @@ -311,9 +289,23 @@ function dismissSuccessfulTransferBalancePage() {
Navigation.navigate(ROUTES.SETTINGS_PAYMENTS);
}

function deletePaymentCard(fundID) {
API.write('DeletePaymentCard', {
fundID,
}, {
optimisticData: [
{
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: `${ONYXKEYS.CARD_LIST}`,
value: {[fundID]: {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}},
},
],
});
}

export {
deleteDebitCard,
deletePayPalMe,
deletePaymentCard,
getPaymentMethods,
openPaymentsPage,
makeDefaultPaymentMethod,
Expand Down
12 changes: 0 additions & 12 deletions src/libs/deprecatedAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,6 @@ function CreateLogin(parameters) {
return Network.post(commandName, parameters);
}

/**
* @param {Object} parameters
* @param {Number} parameters.fundID
* @returns {Promise}
*/
function DeleteFund(parameters) {
const commandName = 'DeleteFund';
requireParameters(['fundID'], parameters, commandName);
return Network.post(commandName, parameters);
}

/**
* @param {Object} parameters
* @param {String} parameters.partnerUserID
Expand Down Expand Up @@ -690,7 +679,6 @@ export {
CreateLogin,
CreatePolicyRoom,
RenameReport,
DeleteFund,
DeleteLogin,
DeleteBankAccount,
Get,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class BasePaymentsPage extends React.Component {
} else if (this.state.selectedPaymentMethodType === CONST.PAYMENT_METHODS.BANK_ACCOUNT) {
BankAccounts.deleteBankAccount(this.state.selectedPaymentMethod.bankAccountID);
} else if (this.state.selectedPaymentMethodType === CONST.PAYMENT_METHODS.DEBIT_CARD) {
PaymentMethods.deleteDebitCard(this.state.selectedPaymentMethod.fundID);
PaymentMethods.deletePaymentCard(this.state.selectedPaymentMethod.fundID);
}
}

Expand Down

0 comments on commit 37eacaf

Please sign in to comment.