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

[DO NOT MERGE]Fix/wkspace settings lock after delete #8023

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/libs/actions/BankAccounts.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import _ from 'underscore';
import Onyx from 'react-native-onyx';
import lodashGet from 'lodash/get';
import CONST from '../../CONST';
import * as DeprecatedAPI from '../deprecatedAPI';
import * as Plaid from './Plaid';
Expand All @@ -8,6 +9,7 @@ import ONYXKEYS from '../../ONYXKEYS';
import * as PaymentMethods from './PaymentMethods';
import Growl from '../Growl';
import * as Localize from '../Localize';
import * as store from './ReimbursementAccount/store';

export {
setupWithdrawalAccount,
Expand Down Expand Up @@ -103,6 +105,14 @@ function addPersonalBankAccount(account, password, plaidLinkToken) {
* @param {Number} bankAccountID
*/
function deleteBankAccount(bankAccountID) {
const reimbursementBankAccountId = lodashGet(store.getReimbursementAccountInSetup(), 'bankAccountID');

// If the account is same, then delete function is called in `resetFreePlanBankAccount`, hence early returned
if (reimbursementBankAccountId === bankAccountID) {
ReimbursementAccount.resetFreePlanBankAccount();
return;
}

DeprecatedAPI.DeleteBankAccount({
bankAccountID,
}).then((response) => {
Expand Down
16 changes: 16 additions & 0 deletions src/libs/actions/PaymentMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Navigation from '../Navigation/Navigation';
import * as CardUtils from '../CardUtils';
import ROUTES from '../../ROUTES';
import NameValuePair from './NameValuePair';
import * as store from './ReimbursementAccount/store';

/**
* Deletes a debit card
Expand Down Expand Up @@ -59,6 +60,19 @@ function continueSetup() {
kycWallRef.current.continue();
}

/**
* Clears local reimbursement account if it doesn't exist in bankAccounts
* @param {Object[]} bankAccounts
*/
function cleanLocalReimbursementData(bankAccounts) {
const bankAccountID = lodashGet(store.getReimbursementAccountInSetup(), 'bankAccountID');

// We check if the bank account list doesn't have the reimbursementAccount
if (!_.find(bankAccounts, bankAccount => bankAccount.bankAccountID === bankAccountID)) {
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {achData: null, shouldShowResetModal: false});
}
}

/**
* Calls the API to get the user's bankAccountList, cardList, wallet, and payPalMe
*
Expand All @@ -77,6 +91,7 @@ function getPaymentMethods() {
// Convert bank accounts/cards from an array of objects, to a map with the bankAccountID as the key
const bankAccounts = _.object(_.map(lodashGet(response, 'bankAccountList', []), bankAccount => [bankAccount.bankAccountID, bankAccount]));
const debitCards = _.object(_.map(lodashGet(response, 'fundList', []), fund => [fund.fundID, fund]));
cleanLocalReimbursementData(bankAccounts);
Onyx.multiSet({
[ONYXKEYS.IS_LOADING_PAYMENT_METHODS]: false,
[ONYXKEYS.USER_WALLET]: lodashGet(response, 'userWallet', {}),
Expand Down Expand Up @@ -273,4 +288,5 @@ export {
saveWalletTransferAccountTypeAndID,
saveWalletTransferMethodType,
dismissWalletConfirmModal,
cleanLocalReimbursementData,
};