From 104d34db7aa348076ed1a450682ed5db86d0884d Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Mon, 18 Sep 2023 14:09:23 +0200 Subject: [PATCH 1/7] Migrated src/libs/modules --- src/libs/models/BankAccount.js | 254 -------------------------------- src/libs/models/BankAccount.ts | 262 +++++++++++++++++++++++++++++++++ 2 files changed, 262 insertions(+), 254 deletions(-) delete mode 100644 src/libs/models/BankAccount.js create mode 100644 src/libs/models/BankAccount.ts diff --git a/src/libs/models/BankAccount.js b/src/libs/models/BankAccount.js deleted file mode 100644 index c0dee2a672ff..000000000000 --- a/src/libs/models/BankAccount.js +++ /dev/null @@ -1,254 +0,0 @@ -import _ from 'underscore'; -import Str from 'expensify-common/lib/str'; -import lodashGet from 'lodash/get'; -import lodashHas from 'lodash/has'; -import CONST from '../../CONST'; - -class BankAccount { - static STATE = { - PENDING: 'PENDING', - OPEN: 'OPEN', - DELETED: 'DELETED', - LOCKED: 'LOCKED', - SETUP: 'SETUP', - VERIFYING: 'VERIFYING', - }; - - constructor(accountJSON) { - this.json = accountJSON; - } - - /** - * Return the ID of the reimbursement account - * - * @returns {Number} - */ - getID() { - return this.json.methodID; - } - - /** - * Return the account number, which has been obfuscated by the back end - * example "XXXXXX3956" - * - * @returns {String} - */ - getMaskedAccountNumber() { - return this.json.accountData.accountNumber; - } - - /** - * Used as the display name for the account... - * @returns {String} - */ - getAddressName() { - return this.json.accountData.addressName; - } - - /** - * @returns {String} - */ - getProcessor() { - return this.json.accountData.processor; - } - - /** - * @returns {String} - */ - getRoutingNumber() { - return this.json.accountData.routingNumber; - } - - /** - * Get all user emails that have access to this bank account - * @return {String[]} - */ - getSharees() { - return this.json.accountData.sharees; - } - - /** - * @returns {String} - * @private - */ - getState() { - return this.json.accountData.state; - } - - /** - * @returns {Boolean} - */ - isOpen() { - return this.getState() === BankAccount.STATE.OPEN; - } - - /** - * @deprecated Use !isPending instead. - * @returns {Boolean} - */ - isVerified() { - return !this.isPending(); - } - - /** - * If the user still needs to enter the 3 micro deposit amounts. - * @returns {Boolean} - */ - isPending() { - return this.getState() === BankAccount.STATE.PENDING; - } - - /** - * If success team is currently verifying the bank account data provided by the user. - * @returns {Boolean} - */ - isVerifying() { - return this.getState() === BankAccount.STATE.VERIFYING; - } - - /** - * If the user didn't finish entering all their info. - * @returns {Boolean} - */ - isInSetup() { - return this.getState() === BankAccount.STATE.SETUP; - } - - /** - * @returns {Boolean} - */ - isLocked() { - return this.getState() === BankAccount.STATE.LOCKED; - } - - /** - * Is it the account to use by default to receive money? - * - * @returns {Boolean} - */ - isDefaultCredit() { - return this.json.accountData.defaultCredit === true; - } - - /** - * Can we use this account to pay other people? - * - * @returns {Boolean} - */ - isWithdrawal() { - return this.json.accountData.allowDebit === true; - } - - /** - * Return the client ID of this bank account - * - * @NOTE WARNING KEEP IN SYNC WITH THE PHP - * @returns {String} - */ - getClientID() { - // eslint-disable-next-line max-len - return `${Str.makeID(this.getMaskedAccountNumber())}${Str.makeID(this.getAddressName())}${Str.makeID(this.getRoutingNumber())}${this.getType()}`; - } - - /** - * @returns {String} - * @private - */ - getType() { - return this.isWithdrawal() ? 'withdrawal' : 'direct-deposit'; - } - - /** - * Return the internal json data structure used by auth - * @returns {Object} - */ - getJSON() { - return this.json; - } - - /** - * Return whether or not this bank account has been risk checked - * @returns {Boolean} - */ - isRiskChecked() { - return Boolean(this.json.accountData.riskChecked); - } - - /** - * Return when the 3 micro amounts for validation were supposed to reach the bank account. - * @returns {String} - */ - getValidateCodeExpectedDate() { - return this.json.validateCodeExpectedDate || ''; - } - - /** - * In which country is the bank account? - * @returns {string} - */ - getCountry() { - return lodashGet(this.json, ['accountData', 'additionalData', 'country'], CONST.COUNTRY.US); - } - - /** - * In which currency is the bank account? - * @returns {String} - */ - getCurrency() { - return lodashGet(this.json, ['accountData', 'additionalData', 'currency'], 'USD'); - } - - /** - * In which bank is the bank account? - * @returns {String} - */ - getBankName() { - return lodashGet(this.json, ['accountData', 'additionalData', 'bankName'], ''); - } - - /** - * Did we get bank account details for local transfer or international wire? - * @returns {Boolean} - */ - hasInternationalWireDetails() { - return lodashGet(this.json, ['accountData', 'additionalData', 'fieldsType'], 'local') === 'international'; - } - - /** - * Get the additional data of a bankAccount - * @returns {Object} - */ - getAdditionalData() { - return this.json.accountData.additionalData || {}; - } - - /** - * Return a map needed to setup a withdrawal account - * @returns {Object} - */ - toACHData() { - return _.extend( - { - 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(), - ); - } - - /** - * Check if user hasn't upgraded their bank account yet. - * @return {Boolean} - */ - needsToUpgrade() { - return !this.isInSetup() && !lodashHas(this.json, ['accountData', 'additionalData', 'beneficialOwners']); - } -} - -export default BankAccount; diff --git a/src/libs/models/BankAccount.ts b/src/libs/models/BankAccount.ts new file mode 100644 index 000000000000..6c563e6583bb --- /dev/null +++ b/src/libs/models/BankAccount.ts @@ -0,0 +1,262 @@ +import Str from 'expensify-common/lib/str'; +import CONST from '../../CONST'; +import { ValueOf } from "type-fest"; + +const BANK_ACCOUNT_STATES = { + PENDING: 'PENDING', + OPEN: 'OPEN', + DELETED: 'DELETED', + LOCKED: 'LOCKED', + SETUP: 'SETUP', + VERIFYING: 'VERIFYING', +}; + +type State = ValueOf; + +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; + } +}; + +type ACHData = { + routingNumber: string, + accountNumber: string, + addressName: string, + isSavings: boolean, + bankAccountID: number, + state: State, + validateCodeExpectedDate: string, + needsToUpgrade: boolean, +}; + +class BankAccount { + private readonly json: BankAccountJSON; + constructor(accountJSON: BankAccountJSON) { + this.json = accountJSON; + } + + /** + * @returns - the ID of the reimbursement account + */ + getID() { + return this.json.methodID; + } + + /** + * @returns - account number obfuscated by the backend. + * @example "XXXXXX3956" + */ + getMaskedAccountNumber() { + return this.json.accountData.accountNumber; + } + + /** + * @returns - the display name for the account. + */ + getAddressName() { + return this.json.accountData.addressName; + } + + /** + * @returns - processor of the bank account. + */ + getProcessor() { + return this.json.accountData.processor; + } + + /** + * @returns - routing number of the bank account. + */ + getRoutingNumber() { + return this.json.accountData.routingNumber; + } + + /** + * @return - all user emails that have access to this bank account. + */ + getSharees() { + return this.json.accountData.sharees; + } + + /** + * @returns - current state of the bank account. + * @private + */ + private getState(): State { + return this.json.accountData.state; + } + + /** + * @returns - if the bank account is open. + */ + isOpen() { + return this.getState() === BANK_ACCOUNT_STATES.OPEN; + } + + /** + * @deprecated Use !isPending instead. + * @returns - if the bank account is verified. + */ + isVerified() { + return !this.isPending(); + } + + /** + * @returns - if he user still needs to enter the 3 micro deposit amounts. + */ + isPending() { + return this.getState() === BANK_ACCOUNT_STATES.PENDING; + } + + /** + * @returns - if success team is currently verifying the bank account data provided by the user. + */ + isVerifying() { + return this.getState() === BANK_ACCOUNT_STATES.VERIFYING; + } + + /** + * @returns - if the user didn't finish entering all their info. + */ + isInSetup() { + return this.getState() === BANK_ACCOUNT_STATES.SETUP; + } + + /** + * @returns - if the bank account is locked. + */ + isLocked() { + return this.getState() === BANK_ACCOUNT_STATES.LOCKED; + } + + /** + * @returns - if the account is the default credit account. + */ + isDefaultCredit() { + return this.json.accountData.defaultCredit; + } + + /** + * @returns - if the account can be used for paying other people. + */ + isWithdrawal() { + return this.json.accountData.allowDebit; + } + + /** + * @NOTE WARNING KEEP IN SYNC WITH THE PHP + * @returns - client ID of the bank account. + */ + getClientID() { + // eslint-disable-next-line max-len + return `${Str.makeID(this.getMaskedAccountNumber())}${Str.makeID(this.getAddressName())}${Str.makeID(this.getRoutingNumber())}${this.getType()}`; + } + + /** + * @returns - type of the bank account. + * @private + */ + private getType(): BankAccountType { + return this.isWithdrawal() ? 'withdrawal' : 'direct-deposit'; + } + + /** + * @returns - Return the internal json data structure used by auth. + */ + getJSON() { + return this.json; + } + + /** + * @returns - Whether or not this bank account has been risk checked + */ + isRiskChecked() { + return this.json.accountData.riskChecked; + } + + /** + * @returns - date when the 3 micro amounts for validation were supposed to reach the bank account. + */ + getValidateCodeExpectedDate() { + return this.json.validateCodeExpectedDate || ''; + } + + /** + * @returns - country of the bank account. + */ + getCountry() { + return this.json.accountData?.additionalData?.country as string || CONST.COUNTRY.US; + } + + /** + * @returns - currency of the bank account. + */ + getCurrency() { + return this.json.accountData?.additionalData?.currency as string || "USD"; + } + + /** + * @returns - bank name of the bank account. + */ + getBankName() { + return this.json.accountData?.additionalData?.bankName as string || ""; + } + + /** + * @returns - Information if did we get bank account details for local transfer or international wire. + */ + hasInternationalWireDetails() { + return this.json.accountData?.additionalData?.fieldsType as string === 'international'; + } + + /** + * @returns {Unknown} Additional data of a bankAccount. + */ + getAdditionalData() { + 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(), + ); + } + + /** + * @returns - Information if user hasn't upgraded their bank account yet. + */ + needsToUpgrade() { + return !this.isInSetup() && !(typeof this.json?.accountData?.additionalData?.beneficialOwners !== 'undefined'); + } +} + +export default BankAccount; From 12c860c94a8457e68f673ac3594e54a9df643184 Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Mon, 18 Sep 2023 14:18:23 +0200 Subject: [PATCH 2/7] Fixed regression issue --- src/libs/models/BankAccount.ts | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/libs/models/BankAccount.ts b/src/libs/models/BankAccount.ts index 6c563e6583bb..73453f5382a6 100644 --- a/src/libs/models/BankAccount.ts +++ b/src/libs/models/BankAccount.ts @@ -2,16 +2,7 @@ import Str from 'expensify-common/lib/str'; import CONST from '../../CONST'; import { ValueOf } from "type-fest"; -const BANK_ACCOUNT_STATES = { - PENDING: 'PENDING', - OPEN: 'OPEN', - DELETED: 'DELETED', - LOCKED: 'LOCKED', - SETUP: 'SETUP', - VERIFYING: 'VERIFYING', -}; - -type State = ValueOf; +type State = ValueOf; type BankAccountType = "withdrawal" | "direct-deposit"; @@ -46,6 +37,14 @@ type ACHData = { }; class BankAccount { + public static readonly STATE = { + PENDING: 'PENDING', + OPEN: 'OPEN', + DELETED: 'DELETED', + LOCKED: 'LOCKED', + SETUP: 'SETUP', + VERIFYING: 'VERIFYING', + }; private readonly json: BankAccountJSON; constructor(accountJSON: BankAccountJSON) { this.json = accountJSON; @@ -106,7 +105,7 @@ class BankAccount { * @returns - if the bank account is open. */ isOpen() { - return this.getState() === BANK_ACCOUNT_STATES.OPEN; + return this.getState() === BankAccount.STATE.OPEN; } /** @@ -121,28 +120,28 @@ class BankAccount { * @returns - if he user still needs to enter the 3 micro deposit amounts. */ isPending() { - return this.getState() === BANK_ACCOUNT_STATES.PENDING; + return this.getState() === BankAccount.STATE.PENDING; } /** * @returns - if success team is currently verifying the bank account data provided by the user. */ isVerifying() { - return this.getState() === BANK_ACCOUNT_STATES.VERIFYING; + return this.getState() === BankAccount.STATE.VERIFYING; } /** * @returns - if the user didn't finish entering all their info. */ isInSetup() { - return this.getState() === BANK_ACCOUNT_STATES.SETUP; + return this.getState() === BankAccount.STATE.SETUP; } /** * @returns - if the bank account is locked. */ isLocked() { - return this.getState() === BANK_ACCOUNT_STATES.LOCKED; + return this.getState() === BankAccount.STATE.LOCKED; } /** From a52ade1142fddf0213c497ba708a49f37e961bec Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Mon, 18 Sep 2023 16:11:51 +0200 Subject: [PATCH 3/7] Implemented requested changes. --- src/libs/models/BankAccount.ts | 118 ++++++++++++++------------------- src/types/onyx/BankAccount.ts | 5 +- 2 files changed, 53 insertions(+), 70 deletions(-) diff --git a/src/libs/models/BankAccount.ts b/src/libs/models/BankAccount.ts index 73453f5382a6..c1557cdef324 100644 --- a/src/libs/models/BankAccount.ts +++ b/src/libs/models/BankAccount.ts @@ -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; 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; - } -}; - type ACHData = { routingNumber: string, accountNumber: string, @@ -53,7 +35,7 @@ class BankAccount { /** * @returns - the ID of the reimbursement account */ - getID() { + getID(): number | undefined { return this.json.methodID; } @@ -61,50 +43,50 @@ class BankAccount { * @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; } @@ -112,50 +94,50 @@ class BankAccount { * @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; } /** @@ -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()}`; } /** @@ -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 { 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 { + 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; } } diff --git a/src/types/onyx/BankAccount.ts b/src/types/onyx/BankAccount.ts index ccaaa7ebab78..5f29fb9c90b0 100644 --- a/src/types/onyx/BankAccount.ts +++ b/src/types/onyx/BankAccount.ts @@ -1,4 +1,4 @@ -type AdditionalData = { +export type AdditionalData = { isP2PDebitCard?: boolean; beneficialOwners?: string[]; currency?: string; @@ -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-{}' where is the bankAccountID */ key?: string; From b0f2d577a1034e93c28f9140a4e3fd07bce1aa7a Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Wed, 20 Sep 2023 10:29:03 +0200 Subject: [PATCH 4/7] Resolved all requested changes. --- src/libs/models/BankAccount.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/models/BankAccount.ts b/src/libs/models/BankAccount.ts index c1557cdef324..90ce49945840 100644 --- a/src/libs/models/BankAccount.ts +++ b/src/libs/models/BankAccount.ts @@ -19,7 +19,7 @@ type ACHData = { }; class BankAccount { - public static readonly STATE = { + static readonly STATE = { PENDING: 'PENDING', OPEN: 'OPEN', DELETED: 'DELETED', @@ -182,28 +182,28 @@ class BankAccount { * @returns - country of the bank account. */ getCountry(): string { - return this.json.accountData?.additionalData?.country as string || CONST.COUNTRY.US; + return this.json.accountData?.additionalData?.country ?? CONST.COUNTRY.US; } /** * @returns - currency of the bank account. */ getCurrency(): string { - return this.json.accountData?.additionalData?.currency as string || "USD"; + return this.json.accountData?.additionalData?.currency ?? "USD"; } /** * @returns - bank name of the bank account. */ getBankName(): string { - return this.json.accountData?.additionalData?.bankName as string || ""; + return this.json.accountData?.additionalData?.bankName ?? ""; } /** * @returns - Information if did we get bank account details for local transfer or international wire. */ hasInternationalWireDetails(): boolean { - return this.json.accountData?.additionalData?.fieldsType as string === 'international'; + return this.json.accountData?.additionalData?.fieldsType === 'international'; } /** From 0589037288215ea7022524035ee40d50cbb198bb Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Thu, 5 Oct 2023 09:57:45 +0200 Subject: [PATCH 5/7] Fixed conflicts and linter issues. --- src/libs/models/BankAccount.ts | 34 ++++++++++++++++++---------------- src/types/onyx/BankAccount.ts | 2 +- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/libs/models/BankAccount.ts b/src/libs/models/BankAccount.ts index 90ce49945840..f7f4a925a7e4 100644 --- a/src/libs/models/BankAccount.ts +++ b/src/libs/models/BankAccount.ts @@ -1,21 +1,21 @@ import Str from 'expensify-common/lib/str'; +import {ValueOf} from 'type-fest'; import CONST from '../../CONST'; -import { ValueOf } from "type-fest"; -import BankAccountJSON, {AdditionalData} from "../../types/onyx/BankAccount"; +import BankAccountJSON, {AdditionalData} from '../../types/onyx/BankAccount'; type State = ValueOf; -type BankAccountType = "withdrawal" | "direct-deposit"; +type BankAccountType = 'withdrawal' | 'direct-deposit'; type ACHData = { - routingNumber: string, - accountNumber: string, - addressName: string, - isSavings: boolean, - bankAccountID: number, - state: State, - validateCodeExpectedDate: string, - needsToUpgrade: boolean, + routingNumber: string; + accountNumber: string; + addressName: string; + isSavings: boolean; + bankAccountID: number; + state: State; + validateCodeExpectedDate: string; + needsToUpgrade: boolean; }; class BankAccount { @@ -27,7 +27,9 @@ class BankAccount { SETUP: 'SETUP', VERIFYING: 'VERIFYING', }; + private readonly json: BankAccountJSON; + constructor(accountJSON: BankAccountJSON) { this.json = accountJSON; } @@ -146,7 +148,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()}`; } /** @@ -175,7 +177,7 @@ class BankAccount { * @returns - date when the 3 micro amounts for validation were supposed to reach the bank account. */ getValidateCodeExpectedDate(): string { - return this.json.validateCodeExpectedDate || ''; + return this.json.validateCodeExpectedDate ?? ''; } /** @@ -189,14 +191,14 @@ class BankAccount { * @returns - currency of the bank account. */ getCurrency(): string { - return this.json.accountData?.additionalData?.currency ?? "USD"; + return this.json.accountData?.additionalData?.currency ?? 'USD'; } /** * @returns - bank name of the bank account. */ getBankName(): string { - return this.json.accountData?.additionalData?.bankName ?? ""; + return this.json.accountData?.additionalData?.bankName ?? ''; } /** @@ -210,7 +212,7 @@ class BankAccount { * @returns - Additional data of a bankAccount. */ getAdditionalData(): Partial { - return this.json.accountData?.additionalData || {}; + return this.json.accountData?.additionalData ?? {}; } /** diff --git a/src/types/onyx/BankAccount.ts b/src/types/onyx/BankAccount.ts index cf37bf7af389..7542a34d90e0 100644 --- a/src/types/onyx/BankAccount.ts +++ b/src/types/onyx/BankAccount.ts @@ -75,4 +75,4 @@ type BankAccount = { }; export default BankAccount; -export type { AdditionalData }; +export type {AdditionalData}; From b99bb3842cb2c22854d23d6867ab645795ea40cf Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Fri, 20 Oct 2023 22:52:02 +0200 Subject: [PATCH 6/7] Solved conflicts. --- src/libs/models/BankAccount.ts | 150 +++++++++++++++------------------ src/types/onyx/BankAccount.ts | 14 ++- 2 files changed, 83 insertions(+), 81 deletions(-) diff --git a/src/libs/models/BankAccount.ts b/src/libs/models/BankAccount.ts index f7f4a925a7e4..7096f4bf3f8a 100644 --- a/src/libs/models/BankAccount.ts +++ b/src/libs/models/BankAccount.ts @@ -1,12 +1,11 @@ import Str from 'expensify-common/lib/str'; import {ValueOf} from 'type-fest'; import CONST from '../../CONST'; + import BankAccountJSON, {AdditionalData} from '../../types/onyx/BankAccount'; type State = ValueOf; -type BankAccountType = 'withdrawal' | 'direct-deposit'; - type ACHData = { routingNumber: string; accountNumber: string; @@ -19,7 +18,9 @@ type ACHData = { }; class BankAccount { - static readonly STATE = { + json: BankAccountJSON; + + static STATE = { PENDING: 'PENDING', OPEN: 'OPEN', DELETED: 'DELETED', @@ -28,215 +29,204 @@ class BankAccount { VERIFYING: 'VERIFYING', }; - private readonly json: BankAccountJSON; - constructor(accountJSON: BankAccountJSON) { this.json = accountJSON; } /** - * @returns - the ID of the reimbursement account + * Return the ID of the reimbursement account */ - getID(): number | undefined { + getID() { return this.json.methodID; } /** - * @returns - account number obfuscated by the backend. - * @example "XXXXXX3956" + * Return the account number, which has been obfuscated by the back end + * example "XXXXXX3956" */ - getMaskedAccountNumber(): string | undefined { + getMaskedAccountNumber() { return this.json.accountData?.accountNumber; } /** - * @returns - the display name for the account. + * Used as the display name for the account... */ - getAddressName(): string | undefined { + getAddressName() { return this.json.accountData?.addressName; } - /** - * @returns - processor of the bank account. - */ - getProcessor(): string | undefined { + getProcessor() { return this.json.accountData?.processor; } - /** - * @returns - routing number of the bank account. - */ - getRoutingNumber(): string | undefined { + getRoutingNumber() { return this.json.accountData?.routingNumber; } /** - * @return - all user emails that have access to this bank account. + * Get all user emails that have access to this bank account */ - getSharees(): string[] | undefined { + getSharees() { return this.json.accountData?.sharees; } - /** - * @returns - current state of the bank account. - * @private - */ - private getState(): State | undefined { + getState() { return this.json.accountData?.state; } - /** - * @returns - if the bank account is open. - */ - isOpen(): boolean { + isOpen() { return this.getState() === BankAccount.STATE.OPEN; } /** * @deprecated Use !isPending instead. - * @returns - if the bank account is verified. */ - isVerified(): boolean { + isVerified() { return !this.isPending(); } /** - * @returns - if he user still needs to enter the 3 micro deposit amounts. + * If the user still needs to enter the 3 micro deposit amounts. */ - isPending(): boolean { + isPending() { return this.getState() === BankAccount.STATE.PENDING; } /** - * @returns - if success team is currently verifying the bank account data provided by the user. + * If success team is currently verifying the bank account data provided by the user. */ - isVerifying(): boolean { + isVerifying() { return this.getState() === BankAccount.STATE.VERIFYING; } /** - * @returns - if the user didn't finish entering all their info. + * If the user didn't finish entering all their info. */ - isInSetup(): boolean { + isInSetup() { return this.getState() === BankAccount.STATE.SETUP; } - /** - * @returns - if the bank account is locked. - */ - isLocked(): boolean { + isLocked() { return this.getState() === BankAccount.STATE.LOCKED; } /** - * @returns - if the account is the default credit account. + * Is it the account to use by default to receive money? */ - isDefaultCredit(): boolean | undefined { - return this.json.accountData?.defaultCredit; + isDefaultCredit() { + return this.json.accountData?.defaultCredit === true; } /** - * @returns - if the account can be used for paying other people. + * Can we use this account to pay other people? */ - isWithdrawal(): boolean | undefined { - return this.json.accountData?.allowDebit; + isWithdrawal() { + return this.json.accountData?.allowDebit === true; + } + + getType() { + return this.json.accountData?.type; } /** + * Return the client ID of this bank account + * * @NOTE WARNING KEEP IN SYNC WITH THE PHP - * @returns - client ID of the bank account. */ 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.getTransactionType()}`; } - /** - * @returns - type of the bank account. - * @private - */ - private getType(): BankAccountType { + private getTransactionType() { return this.isWithdrawal() ? 'withdrawal' : 'direct-deposit'; } /** - * @returns - Return the internal json data structure used by auth. + * Return the internal json data structure used by auth */ - getJSON(): BankAccountJSON { + getJSON() { return this.json; } /** - * @returns - Whether or not this bank account has been risk checked + * Return whether this bank account has been risk checked */ - isRiskChecked(): boolean | undefined { - return this.json.accountData?.riskChecked; + isRiskChecked() { + return Boolean(this.json.accountData?.riskChecked); } /** - * @returns - date when the 3 micro amounts for validation were supposed to reach the bank account. + * Return when the 3 micro amounts for validation were supposed to reach the bank account. */ - getValidateCodeExpectedDate(): string { + getValidateCodeExpectedDate() { return this.json.validateCodeExpectedDate ?? ''; } /** - * @returns - country of the bank account. + * In which country is the bank account? */ - getCountry(): string { + getCountry() { return this.json.accountData?.additionalData?.country ?? CONST.COUNTRY.US; } /** - * @returns - currency of the bank account. + * In which currency is the bank account? */ - getCurrency(): string { + getCurrency() { return this.json.accountData?.additionalData?.currency ?? 'USD'; } /** - * @returns - bank name of the bank account. + * In which bank is the bank account? */ - getBankName(): string { + getBankName() { return this.json.accountData?.additionalData?.bankName ?? ''; } /** - * @returns - Information if did we get bank account details for local transfer or international wire. + * Did we get bank account details for local transfer or international wire? */ - hasInternationalWireDetails(): boolean { - return this.json.accountData?.additionalData?.fieldsType === 'international'; + hasInternationalWireDetails() { + return (this.json.accountData?.additionalData?.fieldsType ?? 'local') === 'international'; } /** - * @returns - Additional data of a bankAccount. + * Get the additional data of a bankAccount */ getAdditionalData(): Partial { return this.json.accountData?.additionalData ?? {}; } /** - * @returns - A map needed to set up a withdrawal account. + * Get the pending action of the bank account + */ + getPendingAction() { + return this.json.pendingAction ?? ''; + } + + /** + * Return a map needed to set up a withdrawal account */ - toACHData(): Partial { + toACHData(): Partial { return { routingNumber: this.getRoutingNumber(), accountNumber: this.getMaskedAccountNumber(), addressName: this.getAddressName(), - isSavings: this.json.accountData?.isSavings, + isSavings: this.json.isSavings, bankAccountID: this.getID(), state: this.getState(), validateCodeExpectedDate: this.getValidateCodeExpectedDate(), needsToUpgrade: this.needsToUpgrade(), ...this.getAdditionalData(), - }; + } as ACHData; } /** - * @returns - Information if user hasn't upgraded their bank account yet. + * Check if user hasn't upgraded their bank account yet. */ - needsToUpgrade(): boolean { - return !this.isInSetup() && !this.json?.accountData?.additionalData?.beneficialOwners; + needsToUpgrade() { + return !this.isInSetup() && this.json.accountData?.additionalData?.beneficialOwners === undefined; } } diff --git a/src/types/onyx/BankAccount.ts b/src/types/onyx/BankAccount.ts index ff61cab805f1..70a2a0495b35 100644 --- a/src/types/onyx/BankAccount.ts +++ b/src/types/onyx/BankAccount.ts @@ -2,6 +2,15 @@ import CONST from '../../CONST'; import AccountData from './AccountData'; import * as OnyxCommon from './OnyxCommon'; +type AdditionalData = { + isP2PDebitCard?: boolean; + beneficialOwners?: string[]; + currency?: string; + bankName?: string; + fieldsType?: string; + country?: string; +}; + type BankAccount = { /** The bank account type */ accountType?: typeof CONST.PAYMENT_METHODS.BANK_ACCOUNT; @@ -11,6 +20,9 @@ type BankAccount = { isDefault?: boolean; + /* Determines if the bank account is a savings account */ + isSavings?: boolean; + /** Date when the 3 micro amounts for validation were supposed to reach the bank account. */ validateCodeExpectedDate?: string; @@ -34,4 +46,4 @@ type BankAccount = { }; export default BankAccount; -export type {AdditionalData, AccountData}; +export type {AccountData, AdditionalData}; From 91b3bb021d26e7cf44a933c8187a0b8cbdb37e50 Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Mon, 20 Nov 2023 13:13:06 +0100 Subject: [PATCH 7/7] Linter issues fixed. --- src/libs/models/BankAccount.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/models/BankAccount.ts b/src/libs/models/BankAccount.ts index 752bb25dc345..6fd77b161aa9 100644 --- a/src/libs/models/BankAccount.ts +++ b/src/libs/models/BankAccount.ts @@ -1,8 +1,7 @@ import Str from 'expensify-common/lib/str'; import {ValueOf} from 'type-fest'; import CONST from '@src/CONST'; - -import BankAccountJSON, {AdditionalData} from '../../types/onyx/BankAccount'; +import BankAccountJSON, {AdditionalData} from '@src/types/onyx/BankAccount'; type State = ValueOf;