forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReimbursementAccountUtils.ts
More file actions
50 lines (41 loc) · 1.84 KB
/
ReimbursementAccountUtils.ts
File metadata and controls
50 lines (41 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import type {ValueOf} from 'type-fest';
import CONST from '@src/CONST';
import type {ACHDataReimbursementAccount} from '@src/types/onyx/ReimbursementAccount';
type ReimbursementAccountStepToOpen = ValueOf<typeof REIMBURSEMENT_ACCOUNT_ROUTE_NAMES> | '';
const REIMBURSEMENT_ACCOUNT_ROUTE_NAMES = {
COMPANY: 'company',
PERSONAL_INFORMATION: 'personal-information',
BENEFICIAL_OWNERS: 'beneficial-owners',
CONTRACT: 'contract',
VALIDATE: 'validate',
ENABLE: 'enable',
NEW: 'new',
} as const;
/**
* Returns true if a VBBA exists in any state other than OPEN or LOCKED
*/
const hasInProgressUSDVBBA = (achData?: ACHDataReimbursementAccount): boolean => {
return !!achData?.bankAccountID && !!achData?.state && achData?.state !== CONST.BANK_ACCOUNT.STATE.OPEN && achData?.state !== CONST.BANK_ACCOUNT.STATE.LOCKED;
};
/** Returns true if user passed first step of flow for non USD VBBA */
const hasInProgressNonUSDVBBA = (achData?: ACHDataReimbursementAccount): boolean => {
return !!achData?.bankAccountID && !!achData?.created;
};
/**
* Returns achData.bankAccountID coerced to a number, defaulting to 0 when missing so VBBA API calls avoid NaN from undefined.
*/
function getBankAccountIDAsNumber(achData?: ACHDataReimbursementAccount): number {
return Number(achData?.bankAccountID ?? CONST.DEFAULT_NUMBER_ID);
}
/** Returns true if VBBA flow is in progress */
const hasInProgressVBBA = (achData?: ACHDataReimbursementAccount, isNonUSDWorkspace?: boolean, policyID?: string) => {
if (achData?.policyID !== policyID) {
return false;
}
if (isNonUSDWorkspace) {
return hasInProgressNonUSDVBBA(achData);
}
return hasInProgressUSDVBBA(achData);
};
export {getBankAccountIDAsNumber, hasInProgressUSDVBBA, hasInProgressVBBA, REIMBURSEMENT_ACCOUNT_ROUTE_NAMES};
export type {ReimbursementAccountStepToOpen};