Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor DeleteFund #9609

Merged
merged 8 commits into from
Aug 11, 2022
Merged
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