Skip to content

Commit 793a7cc

Browse files
authored
Merge pull request Expensify#67519 from allgandalf/fixresetNonUSDBankAccount
Remove Onyx.connect() for the key: ONYXKEYS.COLLECTION.POLICY in src/libs/actions/ReimbursementAccount/resetNonUSDBankAccount.ts
2 parents 84f878c + 6b9184a commit 793a7cc

3 files changed

Lines changed: 8 additions & 16 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"test:debug": "TZ=utc NODE_OPTIONS='--inspect-brk --experimental-vm-modules' jest --runInBand",
4747
"perf-test": "NODE_OPTIONS=--experimental-vm-modules npx reassure",
4848
"typecheck": "NODE_OPTIONS=--max_old_space_size=8192 tsc",
49-
"lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=245 --cache --cache-location=node_modules/.cache/eslint",
49+
"lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=244 --cache --cache-location=node_modules/.cache/eslint",
5050
"lint-changed": "NODE_OPTIONS=--max_old_space_size=8192 ./scripts/lintChanged.sh",
5151
"lint-watch": "npx eslint-watch --watch --changed",
5252
"shellcheck": "./scripts/shellCheck.sh",

src/libs/actions/ReimbursementAccount/resetNonUSDBankAccount.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
11
import Onyx from 'react-native-onyx';
2-
import type {OnyxCollection} from 'react-native-onyx';
2+
import type {OnyxEntry} from 'react-native-onyx';
33
import * as API from '@libs/API';
44
import {WRITE_COMMANDS} from '@libs/API/types';
55
import CONST from '@src/CONST';
66
import ONYXKEYS from '@src/ONYXKEYS';
7-
import type * as OnyxTypes from '@src/types/onyx';
7+
import type {ACHAccount} from '@src/types/onyx/Policy';
88

9-
let allPolicies: OnyxCollection<OnyxTypes.Policy>;
10-
Onyx.connect({
11-
key: ONYXKEYS.COLLECTION.POLICY,
12-
waitForCollectionCallback: true,
13-
callback: (value) => (allPolicies = value),
14-
});
15-
16-
function resetNonUSDBankAccount(policyID: string | undefined) {
9+
function resetNonUSDBankAccount(policyID: string | undefined, achAccount: OnyxEntry<ACHAccount>) {
1710
if (!policyID) {
18-
throw new Error('Missing Policy ID when attempting to reset');
11+
throw new Error('Missing policy when attempting to reset');
1912
}
2013

21-
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`] ?? ({} as OnyxTypes.Policy);
22-
2314
API.write(
2415
WRITE_COMMANDS.RESET_BANK_ACCOUNT_SETUP,
2516
{policyID},
@@ -65,7 +56,7 @@ function resetNonUSDBankAccount(policyID: string | undefined) {
6556
onyxMethod: Onyx.METHOD.MERGE,
6657
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
6758
value: {
68-
achAccount: policy?.achAccount,
59+
achAccount,
6960
},
7061
},
7162
],

src/pages/workspace/WorkspaceResetBankAccountModal.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ function WorkspaceResetBankAccountModal({
4242
const {translate} = useLocalize();
4343
const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false});
4444
const policyID = reimbursementAccount?.achData?.policyID;
45+
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {canBeMissing: true});
4546
const achData = reimbursementAccount?.achData;
4647
const isInOpenState = achData?.state === BankAccount.STATE.OPEN;
4748
const bankAccountID = achData?.bankAccountID;
@@ -54,7 +55,7 @@ function WorkspaceResetBankAccountModal({
5455

5556
const handleConfirm = () => {
5657
if (isNonUSDWorkspace) {
57-
resetNonUSDBankAccount(policyID);
58+
resetNonUSDBankAccount(policyID, policy?.achAccount);
5859

5960
if (setShouldShowConnectedVerifiedBankAccount) {
6061
setShouldShowConnectedVerifiedBankAccount(false);

0 commit comments

Comments
 (0)