Skip to content

Commit

Permalink
Implemented requested changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
fvlvte committed Sep 18, 2023
1 parent 12c860c commit a52ade1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 70 deletions.
118 changes: 49 additions & 69 deletions src/libs/models/BankAccount.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
import Str from 'expensify-common/lib/str';
import CONST from '../../CONST';
import { ValueOf } from "type-fest";
import BankAccountJSON, {AdditionalData} from "../../types/onyx/BankAccount";

type State = ValueOf<typeof BankAccount.STATE>;

type BankAccountType = "withdrawal" | "direct-deposit";

type BankAccountJSON = {
methodID: number;
validateCodeExpectedDate: string;
isSavings: boolean;
accountData: {
accountNumber: string;
addressName: string;
processor: string;
routingNumber: string;
sharees: string[];
state: State;
country: string;
defaultCredit: boolean;
allowDebit: boolean;
riskChecked: boolean;
additionalData: Record<string, unknown>;
}
};

type ACHData = {
routingNumber: string,
accountNumber: string,
Expand Down Expand Up @@ -53,109 +35,109 @@ class BankAccount {
/**
* @returns - the ID of the reimbursement account
*/
getID() {
getID(): number | undefined {
return this.json.methodID;
}

/**
* @returns - account number obfuscated by the backend.
* @example "XXXXXX3956"
*/
getMaskedAccountNumber() {
return this.json.accountData.accountNumber;
getMaskedAccountNumber(): string | undefined {
return this.json.accountData?.accountNumber;
}

/**
* @returns - the display name for the account.
*/
getAddressName() {
return this.json.accountData.addressName;
getAddressName(): string | undefined {
return this.json.accountData?.addressName;
}

/**
* @returns - processor of the bank account.
*/
getProcessor() {
return this.json.accountData.processor;
getProcessor(): string | undefined {
return this.json.accountData?.processor;
}

/**
* @returns - routing number of the bank account.
*/
getRoutingNumber() {
return this.json.accountData.routingNumber;
getRoutingNumber(): string | undefined {
return this.json.accountData?.routingNumber;
}

/**
* @return - all user emails that have access to this bank account.
*/
getSharees() {
return this.json.accountData.sharees;
getSharees(): string[] | undefined {
return this.json.accountData?.sharees;
}

/**
* @returns - current state of the bank account.
* @private
*/
private getState(): State {
return this.json.accountData.state;
private getState(): State | undefined {
return this.json.accountData?.state;
}

/**
* @returns - if the bank account is open.
*/
isOpen() {
isOpen(): boolean {
return this.getState() === BankAccount.STATE.OPEN;
}

/**
* @deprecated Use !isPending instead.
* @returns - if the bank account is verified.
*/
isVerified() {
isVerified(): boolean {
return !this.isPending();
}

/**
* @returns - if he user still needs to enter the 3 micro deposit amounts.
*/
isPending() {
isPending(): boolean {
return this.getState() === BankAccount.STATE.PENDING;
}

/**
* @returns - if success team is currently verifying the bank account data provided by the user.
*/
isVerifying() {
isVerifying(): boolean {
return this.getState() === BankAccount.STATE.VERIFYING;
}

/**
* @returns - if the user didn't finish entering all their info.
*/
isInSetup() {
isInSetup(): boolean {
return this.getState() === BankAccount.STATE.SETUP;
}

/**
* @returns - if the bank account is locked.
*/
isLocked() {
isLocked(): boolean {
return this.getState() === BankAccount.STATE.LOCKED;
}

/**
* @returns - if the account is the default credit account.
*/
isDefaultCredit() {
return this.json.accountData.defaultCredit;
isDefaultCredit(): boolean | undefined {
return this.json.accountData?.defaultCredit;
}

/**
* @returns - if the account can be used for paying other people.
*/
isWithdrawal() {
return this.json.accountData.allowDebit;
isWithdrawal(): boolean | undefined {
return this.json.accountData?.allowDebit;
}

/**
Expand All @@ -164,7 +146,7 @@ class BankAccount {
*/
getClientID() {
// eslint-disable-next-line max-len
return `${Str.makeID(this.getMaskedAccountNumber())}${Str.makeID(this.getAddressName())}${Str.makeID(this.getRoutingNumber())}${this.getType()}`;
return `${Str.makeID(this.getMaskedAccountNumber() || "")}${Str.makeID(this.getAddressName() || "")}${Str.makeID(this.getRoutingNumber() || "")}${this.getType()}`;
}

/**
Expand All @@ -178,83 +160,81 @@ class BankAccount {
/**
* @returns - Return the internal json data structure used by auth.
*/
getJSON() {
getJSON(): BankAccountJSON {
return this.json;
}

/**
* @returns - Whether or not this bank account has been risk checked
*/
isRiskChecked() {
return this.json.accountData.riskChecked;
isRiskChecked(): boolean | undefined {
return this.json.accountData?.riskChecked;
}

/**
* @returns - date when the 3 micro amounts for validation were supposed to reach the bank account.
*/
getValidateCodeExpectedDate() {
getValidateCodeExpectedDate(): string {
return this.json.validateCodeExpectedDate || '';
}

/**
* @returns - country of the bank account.
*/
getCountry() {
getCountry(): string {
return this.json.accountData?.additionalData?.country as string || CONST.COUNTRY.US;
}

/**
* @returns - currency of the bank account.
*/
getCurrency() {
getCurrency(): string {
return this.json.accountData?.additionalData?.currency as string || "USD";
}

/**
* @returns - bank name of the bank account.
*/
getBankName() {
getBankName(): string {
return this.json.accountData?.additionalData?.bankName as string || "";
}

/**
* @returns - Information if did we get bank account details for local transfer or international wire.
*/
hasInternationalWireDetails() {
hasInternationalWireDetails(): boolean {
return this.json.accountData?.additionalData?.fieldsType as string === 'international';
}

/**
* @returns {Unknown} Additional data of a bankAccount.
* @returns - Additional data of a bankAccount.
*/
getAdditionalData() {
getAdditionalData(): Partial<AdditionalData> {
return this.json.accountData?.additionalData || {};
}

/**
* @returns - A map needed to set up a withdrawal account.
*/
toACHData(): ACHData {
return Object.assign(
{
routingNumber: this.getRoutingNumber(),
accountNumber: this.getMaskedAccountNumber(),
addressName: this.getAddressName(),
isSavings: this.json.isSavings,
bankAccountID: this.getID(),
state: this.getState(),
validateCodeExpectedDate: this.getValidateCodeExpectedDate(),
needsToUpgrade: this.needsToUpgrade(),
},
this.getAdditionalData(),
);
toACHData(): Partial<ACHData & AdditionalData> {
return {
routingNumber: this.getRoutingNumber(),
accountNumber: this.getMaskedAccountNumber(),
addressName: this.getAddressName(),
isSavings: this.json.accountData?.isSavings,
bankAccountID: this.getID(),
state: this.getState(),
validateCodeExpectedDate: this.getValidateCodeExpectedDate(),
needsToUpgrade: this.needsToUpgrade(),
...this.getAdditionalData(),
};
}

/**
* @returns - Information if user hasn't upgraded their bank account yet.
*/
needsToUpgrade() {
return !this.isInSetup() && !(typeof this.json?.accountData?.additionalData?.beneficialOwners !== 'undefined');
needsToUpgrade(): boolean {
return !this.isInSetup() && !this.json?.accountData?.additionalData?.beneficialOwners;
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/types/onyx/BankAccount.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type AdditionalData = {
export type AdditionalData = {
isP2PDebitCard?: boolean;
beneficialOwners?: string[];
currency?: string;
Expand Down Expand Up @@ -56,6 +56,9 @@ type BankAccount = {

isDefault?: boolean;

/** Date when the 3 micro amounts for validation were supposed to reach the bank account. */
validateCodeExpectedDate?: string;

/** string like 'bankAccount-{<bankAccountID>}' where <bankAccountID> is the bankAccountID */
key?: string;

Expand Down

0 comments on commit a52ade1

Please sign in to comment.