From d0460ae7c0d851b5f0eb6146921ffc49027d8f64 Mon Sep 17 00:00:00 2001 From: Viktoryia Kliushun Date: Wed, 27 Sep 2023 14:14:21 +0200 Subject: [PATCH 1/9] [TS migration] Migrate 'BankAccounts.js' lib --- .../{BankAccounts.js => BankAccounts.ts} | 116 ++++-------------- src/types/onyx/BankAccount.ts | 1 + src/types/onyx/PersonalBankAccount.ts | 3 + src/types/onyx/PlaidBankAccount.ts | 3 + src/types/onyx/ReimbursementAccountDraft.ts | 33 ++++- src/types/onyx/Request.ts | 3 +- 6 files changed, 67 insertions(+), 92 deletions(-) rename src/libs/actions/{BankAccounts.js => BankAccounts.ts} (74%) diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.ts similarity index 74% rename from src/libs/actions/BankAccounts.js rename to src/libs/actions/BankAccounts.ts index b1cb09a8a5e2..a60123ac95c2 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.ts @@ -7,6 +7,9 @@ import * as PlaidDataProps from '../../pages/ReimbursementAccount/plaidDataPropT import Navigation from '../Navigation/Navigation'; import ROUTES from '../../ROUTES'; import * as ReimbursementAccount from './ReimbursementAccount'; +import PlaidBankAccount from '../../types/onyx/PlaidBankAccount'; +import {ACHContractStepProps, BankAccountStepProps, CompanyStepProps, OnfidoData, ReimbursementAccountProps, RequestorStepProps} from '../../types/onyx/ReimbursementAccountDraft'; +import {Request} from '../../types/onyx'; export { goToWithdrawalAccountSetupStep, @@ -23,7 +26,9 @@ export { export {openPlaidBankAccountSelector, openPlaidBankLogin} from './Plaid'; export {openOnfidoFlow, answerQuestionsForWallet, verifyIdentity, acceptWalletTerms} from './Wallet'; -function clearPlaid() { +type BankAccountCompanyInformation = BankAccountStepProps & CompanyStepProps & ReimbursementAccountProps; + +function clearPlaid(): Promise { Onyx.set(ONYXKEYS.PLAID_LINK_TOKEN, ''); return Onyx.set(ONYXKEYS.PLAID_DATA, PlaidDataProps.plaidDataDefaultProps); @@ -35,14 +40,13 @@ function openPlaidView() { /** * Open the personal bank account setup flow, with an optional exitReportID to redirect to once the flow is finished. - * @param {String} exitReportID */ -function openPersonalBankAccountSetupView(exitReportID) { +function openPersonalBankAccountSetupView(exitReportID: string) { clearPlaid().then(() => { if (exitReportID) { Onyx.merge(ONYXKEYS.PERSONAL_BANK_ACCOUNT, {exitReportID}); } - Navigation.navigate(ROUTES.SETTINGS_ADD_BANK_ACCOUNT); + Navigation.navigate(ROUTES.SETTINGS_ADD_BANK_ACCOUNT, ''); }); } @@ -57,10 +61,8 @@ function clearOnfidoToken() { /** * Helper method to build the Onyx data required during setup of a Verified Business Bank Account - * - * @returns {Object} */ -function getVBBADataForOnyx() { +function getVBBADataForOnyx(): Request { return { optimisticData: [ { @@ -68,7 +70,7 @@ function getVBBADataForOnyx() { key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, value: { isLoading: true, - errors: null, + errors: undefined, }, }, ], @@ -78,7 +80,7 @@ function getVBBADataForOnyx() { key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, value: { isLoading: false, - errors: null, + errors: undefined, }, }, ], @@ -97,11 +99,8 @@ function getVBBADataForOnyx() { /** * Submit Bank Account step with Plaid data so php can perform some checks. - * - * @param {Number} bankAccountID - * @param {Object} selectedPlaidBankAccount */ -function connectBankAccountWithPlaid(bankAccountID, selectedPlaidBankAccount) { +function connectBankAccountWithPlaid(bankAccountID: number, selectedPlaidBankAccount: PlaidBankAccount) { const commandName = 'ConnectBankAccountWithPlaid'; const parameters = { @@ -119,10 +118,9 @@ function connectBankAccountWithPlaid(bankAccountID, selectedPlaidBankAccount) { /** * Adds a bank account via Plaid * - * @param {Object} account * @TODO offline pattern for this command will have to be added later once the pattern B design doc is complete */ -function addPersonalBankAccount(account) { +function addPersonalBankAccount(account: PlaidBankAccount) { const commandName = 'AddPersonalBankAccount'; const parameters = { @@ -174,7 +172,7 @@ function addPersonalBankAccount(account) { API.write(commandName, parameters, onyxData); } -function deletePaymentBankAccount(bankAccountID) { +function deletePaymentBankAccount(bankAccountID: number) { API.write( 'DeletePaymentBankAccount', { @@ -206,30 +204,12 @@ function deletePaymentBankAccount(bankAccountID) { * Update the user's personal information on the bank account in database. * * This action is called by the requestor step in the Verified Bank Account flow - * - * @param {Object} params - * - * @param {String} [params.dob] - * @param {String} [params.firstName] - * @param {String} [params.lastName] - * @param {String} [params.requestorAddressStreet] - * @param {String} [params.requestorAddressCity] - * @param {String} [params.requestorAddressState] - * @param {String} [params.requestorAddressZipCode] - * @param {String} [params.ssnLast4] - * @param {String} [params.isControllingOfficer] - * @param {Object} [params.onfidoData] - * @param {Boolean} [params.isOnfidoSetupComplete] */ -function updatePersonalInformationForBankAccount(params) { +function updatePersonalInformationForBankAccount(params: RequestorStepProps) { API.write('UpdatePersonalInformationForBankAccount', params, getVBBADataForOnyx()); } -/** - * @param {Number} bankAccountID - * @param {String} validateCode - */ -function validateBankAccount(bankAccountID, validateCode) { +function validateBankAccount(bankAccountID: number, validateCode: string) { API.write( 'ValidateBankAccountWithTransactions', { @@ -269,7 +249,7 @@ function validateBankAccount(bankAccountID, validateCode) { ); } -function openReimbursementAccountPage(stepToOpen, subStep, localCurrentStep) { +function openReimbursementAccountPage(stepToOpen: string, subStep: string, localCurrentStep: string) { const onyxData = { optimisticData: [ { @@ -311,63 +291,23 @@ function openReimbursementAccountPage(stepToOpen, subStep, localCurrentStep) { /** * Updates the bank account in the database with the company step data - * - * @param {Object} bankAccount - * @param {Number} [bankAccount.bankAccountID] - * - * Fields from BankAccount step - * @param {String} [bankAccount.routingNumber] - * @param {String} [bankAccount.accountNumber] - * @param {String} [bankAccount.bankName] - * @param {String} [bankAccount.plaidAccountID] - * @param {String} [bankAccount.plaidAccessToken] - * @param {Boolean} [bankAccount.isSavings] - * - * Fields from Company step - * @param {String} [bankAccount.companyName] - * @param {String} [bankAccount.addressStreet] - * @param {String} [bankAccount.addressCity] - * @param {String} [bankAccount.addressState] - * @param {String} [bankAccount.addressZipCode] - * @param {String} [bankAccount.companyPhone] - * @param {String} [bankAccount.website] - * @param {String} [bankAccount.companyTaxID] - * @param {String} [bankAccount.incorporationType] - * @param {String} [bankAccount.incorporationState] - * @param {String} [bankAccount.incorporationDate] - * @param {Boolean} [bankAccount.hasNoConnectionToCannabis] - * @param {String} policyID */ -function updateCompanyInformationForBankAccount(bankAccount, policyID) { +function updateCompanyInformationForBankAccount(bankAccount: BankAccountCompanyInformation, policyID: string) { API.write('UpdateCompanyInformationForBankAccount', {...bankAccount, policyID}, getVBBADataForOnyx()); } /** * Add beneficial owners for the bank account, accept the ACH terms and conditions and verify the accuracy of the information provided - * - * @param {Object} params - * - * // ACH Contract Step - * @param {Boolean} [params.ownsMoreThan25Percent] - * @param {Boolean} [params.hasOtherBeneficialOwners] - * @param {Boolean} [params.acceptTermsAndConditions] - * @param {Boolean} [params.certifyTrueInformation] - * @param {String} [params.beneficialOwners] */ -function updateBeneficialOwnersForBankAccount(params) { +function updateBeneficialOwnersForBankAccount(params: ACHContractStepProps) { API.write('UpdateBeneficialOwnersForBankAccount', {...params}, getVBBADataForOnyx()); } /** * Create the bank account with manually entered data. * - * @param {number} [bankAccountID] - * @param {String} [accountNumber] - * @param {String} [routingNumber] - * @param {String} [plaidMask] - * */ -function connectBankAccountManually(bankAccountID, accountNumber, routingNumber, plaidMask) { +function connectBankAccountManually(bankAccountID: number, accountNumber: string, routingNumber: string, plaidMask: string) { API.write( 'ConnectBankAccountManually', { @@ -382,11 +322,8 @@ function connectBankAccountManually(bankAccountID, accountNumber, routingNumber, /** * Verify the user's identity via Onfido - * - * @param {Number} bankAccountID - * @param {Object} onfidoData */ -function verifyIdentityForBankAccount(bankAccountID, onfidoData) { +function verifyIdentityForBankAccount(bankAccountID: number, onfidoData: OnfidoData) { API.write( 'VerifyIdentityForBankAccount', { @@ -398,24 +335,23 @@ function verifyIdentityForBankAccount(bankAccountID, onfidoData) { } function openWorkspaceView() { - API.read('OpenWorkspaceView'); + API.read('OpenWorkspaceView', {}, {}); } -function handlePlaidError(bankAccountID, error, error_description, plaidRequestID) { +function handlePlaidError(bankAccountID: number, error: string, errorDescription: string, plaidRequestID: string) { API.write('BankAccount_HandlePlaidError', { bankAccountID, error, - error_description, + // eslint-disable-next-line @typescript-eslint/naming-convention + error_description: errorDescription, plaidRequestID, }); } /** * Set the reimbursement account loading so that it happens right away, instead of when the API command is processed. - * - * @param {Boolean} isLoading */ -function setReimbursementAccountLoading(isLoading) { +function setReimbursementAccountLoading(isLoading: boolean) { Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {isLoading}); } diff --git a/src/types/onyx/BankAccount.ts b/src/types/onyx/BankAccount.ts index ccaaa7ebab78..bc54662d9817 100644 --- a/src/types/onyx/BankAccount.ts +++ b/src/types/onyx/BankAccount.ts @@ -70,3 +70,4 @@ type BankAccount = { }; export default BankAccount; +export type {AccountData}; diff --git a/src/types/onyx/PersonalBankAccount.ts b/src/types/onyx/PersonalBankAccount.ts index 06f505a04196..04897ca24d25 100644 --- a/src/types/onyx/PersonalBankAccount.ts +++ b/src/types/onyx/PersonalBankAccount.ts @@ -10,6 +10,9 @@ type PersonalBankAccount = { /** The account ID of the selected bank account from Plaid */ plaidAccountID?: string; + + /** Any reportID we should redirect to at the end of the flow */ + exitReportID?: string; }; export default PersonalBankAccount; diff --git a/src/types/onyx/PlaidBankAccount.ts b/src/types/onyx/PlaidBankAccount.ts index d89e8ac3082d..c7cd7b5d83e4 100644 --- a/src/types/onyx/PlaidBankAccount.ts +++ b/src/types/onyx/PlaidBankAccount.ts @@ -19,6 +19,9 @@ type PlaidBankAccount = { /** Plaid access token, used to then retrieve Assets and Balances */ plaidAccessToken: string; + + /** Name of the bank */ + bankName?: string; }; export default PlaidBankAccount; diff --git a/src/types/onyx/ReimbursementAccountDraft.ts b/src/types/onyx/ReimbursementAccountDraft.ts index d55c2b5b3567..cab1283943bc 100644 --- a/src/types/onyx/ReimbursementAccountDraft.ts +++ b/src/types/onyx/ReimbursementAccountDraft.ts @@ -1,10 +1,19 @@ -type ReimbursementAccountDraft = { +type OnfidoData = Record; + +type BankAccountStepProps = { accountNumber?: string; routingNumber?: string; acceptTerms?: boolean; plaidAccountID?: string; plaidMask?: string; +}; + +type CompanyStepProps = { companyName?: string; + addressStreet?: string; + addressCity?: string; + addressState?: string; + addressZipCode?: string; companyPhone?: string; website?: string; companyTaxID?: string; @@ -12,13 +21,32 @@ type ReimbursementAccountDraft = { incorporationDate?: string | Date; incorporationState?: string; hasNoConnectionToCannabis?: boolean; +}; + +type RequestorStepProps = { + firstName?: string; + lastName?: string; + requestorAddressStreet?: string; + requestorAddressCity?: string; + requestorAddressState?: string; + requestorAddressZipCode?: string; + dob?: string | Date; + ssnLast4?: string; isControllingOfficer?: boolean; isOnfidoSetupComplete?: boolean; + onfidoData?: OnfidoData; +}; + +type ACHContractStepProps = { ownsMoreThan25Percent?: boolean; hasOtherBeneficialOwners?: boolean; acceptTermsAndConditions?: boolean; certifyTrueInformation?: boolean; beneficialOwners?: string[]; +}; + +type ReimbursementAccountProps = { + bankAccountID?: number; isSavings?: boolean; bankName?: string; plaidAccessToken?: string; @@ -27,4 +55,7 @@ type ReimbursementAccountDraft = { amount3?: string; }; +type ReimbursementAccountDraft = BankAccountStepProps & CompanyStepProps & RequestorStepProps & ACHContractStepProps & ReimbursementAccountProps; + export default ReimbursementAccountDraft; +export type {ACHContractStepProps, RequestorStepProps, OnfidoData, BankAccountStepProps, CompanyStepProps, ReimbursementAccountProps}; diff --git a/src/types/onyx/Request.ts b/src/types/onyx/Request.ts index 94f14af0ddb3..d933a5ee4f1e 100644 --- a/src/types/onyx/Request.ts +++ b/src/types/onyx/Request.ts @@ -1,12 +1,13 @@ import {OnyxUpdate} from 'react-native-onyx'; type Request = { - command: string; + command?: string; data?: Record; type?: string; shouldUseSecure?: boolean; successData?: OnyxUpdate[]; failureData?: OnyxUpdate[]; + optimisticData?: OnyxUpdate[]; }; export default Request; From f54ac0835e26fc01b4fedff5db077aa4bc871dc0 Mon Sep 17 00:00:00 2001 From: Viktoryia Kliushun Date: Wed, 27 Sep 2023 16:15:08 +0200 Subject: [PATCH 2/9] Add OnyxData type --- src/libs/actions/BankAccounts.ts | 4 ++-- src/types/onyx/Request.ts | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/libs/actions/BankAccounts.ts b/src/libs/actions/BankAccounts.ts index a60123ac95c2..703cdce6195c 100644 --- a/src/libs/actions/BankAccounts.ts +++ b/src/libs/actions/BankAccounts.ts @@ -9,7 +9,7 @@ import ROUTES from '../../ROUTES'; import * as ReimbursementAccount from './ReimbursementAccount'; import PlaidBankAccount from '../../types/onyx/PlaidBankAccount'; import {ACHContractStepProps, BankAccountStepProps, CompanyStepProps, OnfidoData, ReimbursementAccountProps, RequestorStepProps} from '../../types/onyx/ReimbursementAccountDraft'; -import {Request} from '../../types/onyx'; +import {OnyxData} from '../../types/onyx/Request'; export { goToWithdrawalAccountSetupStep, @@ -62,7 +62,7 @@ function clearOnfidoToken() { /** * Helper method to build the Onyx data required during setup of a Verified Business Bank Account */ -function getVBBADataForOnyx(): Request { +function getVBBADataForOnyx(): OnyxData { return { optimisticData: [ { diff --git a/src/types/onyx/Request.ts b/src/types/onyx/Request.ts index d933a5ee4f1e..a3032401b346 100644 --- a/src/types/onyx/Request.ts +++ b/src/types/onyx/Request.ts @@ -1,13 +1,19 @@ import {OnyxUpdate} from 'react-native-onyx'; -type Request = { - command?: string; - data?: Record; - type?: string; - shouldUseSecure?: boolean; +type OnyxData = { successData?: OnyxUpdate[]; failureData?: OnyxUpdate[]; optimisticData?: OnyxUpdate[]; }; +type RequestData = { + command: string; + data?: Record; + type?: string; + shouldUseSecure?: boolean; +}; + +type Request = RequestData & OnyxData; + export default Request; +export type {OnyxData}; From 0a325e1df98178c0260b4b5b6e7f45551b02250e Mon Sep 17 00:00:00 2001 From: Viktoryia Kliushun Date: Fri, 29 Sep 2023 12:35:59 +0200 Subject: [PATCH 3/9] Add types for API calls params --- src/libs/actions/BankAccounts.ts | 222 +++++++++++++++++++------------ 1 file changed, 136 insertions(+), 86 deletions(-) diff --git a/src/libs/actions/BankAccounts.ts b/src/libs/actions/BankAccounts.ts index 703cdce6195c..1d25de8aff06 100644 --- a/src/libs/actions/BankAccounts.ts +++ b/src/libs/actions/BankAccounts.ts @@ -103,7 +103,16 @@ function getVBBADataForOnyx(): OnyxData { function connectBankAccountWithPlaid(bankAccountID: number, selectedPlaidBankAccount: PlaidBankAccount) { const commandName = 'ConnectBankAccountWithPlaid'; - const parameters = { + type ConnectBankAccountWithPlaidParams = { + bankAccountID: number; + routingNumber: string; + accountNumber: string; + bank?: string; + plaidAccountID: string; + plaidAccessToken: string; + }; + + const parameters: ConnectBankAccountWithPlaidParams = { bankAccountID, routingNumber: selectedPlaidBankAccount.routingNumber, accountNumber: selectedPlaidBankAccount.accountNumber, @@ -123,7 +132,18 @@ function connectBankAccountWithPlaid(bankAccountID: number, selectedPlaidBankAcc function addPersonalBankAccount(account: PlaidBankAccount) { const commandName = 'AddPersonalBankAccount'; - const parameters = { + type AddPersonalBankAccountParams = { + addressName: string; + routingNumber: string; + accountNumber: string; + isSavings: boolean; + setupType: string; + bank?: string; + plaidAccountID: string; + plaidAccessToken: string; + }; + + const parameters: AddPersonalBankAccountParams = { addressName: account.addressName, routingNumber: account.routingNumber, accountNumber: account.accountNumber, @@ -173,31 +193,29 @@ function addPersonalBankAccount(account: PlaidBankAccount) { } function deletePaymentBankAccount(bankAccountID: number) { - API.write( - 'DeletePaymentBankAccount', - { - bankAccountID, - }, - { - optimisticData: [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.BANK_ACCOUNT_LIST}`, - value: {[bankAccountID]: {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}}, - }, - ], - - // Sometimes pusher updates aren't received when we close the App while still offline, - // so we are setting the bankAccount to null here to ensure that it gets cleared out once we come back online. - successData: [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.BANK_ACCOUNT_LIST}`, - value: {[bankAccountID]: null}, - }, - ], - }, - ); + type DeletePaymentBankAccountParams = {bankAccountID: number}; + + const parameters: DeletePaymentBankAccountParams = {bankAccountID}; + + API.write('DeletePaymentBankAccount', parameters, { + optimisticData: [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.BANK_ACCOUNT_LIST}`, + value: {[bankAccountID]: {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}}, + }, + ], + + // Sometimes pusher updates aren't received when we close the App while still offline, + // so we are setting the bankAccount to null here to ensure that it gets cleared out once we come back online. + successData: [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.BANK_ACCOUNT_LIST}`, + value: {[bankAccountID]: null}, + }, + ], + }); } /** @@ -210,43 +228,46 @@ function updatePersonalInformationForBankAccount(params: RequestorStepProps) { } function validateBankAccount(bankAccountID: number, validateCode: string) { - API.write( - 'ValidateBankAccountWithTransactions', - { - bankAccountID, - validateCode, - }, - { - optimisticData: [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, - value: { - isLoading: true, - errors: null, - }, + type ValidateBankAccountWithTransactionsParams = { + bankAccountID: number; + validateCode: string; + }; + + const parameters: ValidateBankAccountWithTransactionsParams = { + bankAccountID, + validateCode, + }; + + API.write('ValidateBankAccountWithTransactions', parameters, { + optimisticData: [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, + value: { + isLoading: true, + errors: null, }, - ], - successData: [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, - value: { - isLoading: false, - }, + }, + ], + successData: [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, + value: { + isLoading: false, }, - ], - failureData: [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, - value: { - isLoading: false, - }, + }, + ], + failureData: [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, + value: { + isLoading: false, }, - ], - }, - ); + }, + ], + }); } function openReimbursementAccountPage(stepToOpen: string, subStep: string, localCurrentStep: string) { @@ -280,58 +301,77 @@ function openReimbursementAccountPage(stepToOpen: string, subStep: string, local ], }; - const param = { + type OpenReimbursementAccountPageParams = { + stepToOpen: string; + subStep: string; + localCurrentStep: string; + }; + + const parameters: OpenReimbursementAccountPageParams = { stepToOpen, subStep, localCurrentStep, }; - return API.read('OpenReimbursementAccountPage', param, onyxData); + return API.read('OpenReimbursementAccountPage', parameters, onyxData); } /** * Updates the bank account in the database with the company step data */ function updateCompanyInformationForBankAccount(bankAccount: BankAccountCompanyInformation, policyID: string) { - API.write('UpdateCompanyInformationForBankAccount', {...bankAccount, policyID}, getVBBADataForOnyx()); + type UpdateCompanyInformationParams = {policyID: string}; + type UpdateCompanyInformationForBankAccountParams = BankAccountCompanyInformation & UpdateCompanyInformationParams; + + const parameters: UpdateCompanyInformationForBankAccountParams = {...bankAccount, policyID}; + + API.write('UpdateCompanyInformationForBankAccount', parameters, getVBBADataForOnyx()); } /** * Add beneficial owners for the bank account, accept the ACH terms and conditions and verify the accuracy of the information provided */ function updateBeneficialOwnersForBankAccount(params: ACHContractStepProps) { - API.write('UpdateBeneficialOwnersForBankAccount', {...params}, getVBBADataForOnyx()); + API.write('UpdateBeneficialOwnersForBankAccount', params, getVBBADataForOnyx()); } /** * Create the bank account with manually entered data. * */ -function connectBankAccountManually(bankAccountID: number, accountNumber: string, routingNumber: string, plaidMask: string) { - API.write( - 'ConnectBankAccountManually', - { - bankAccountID, - accountNumber, - routingNumber, - plaidMask, - }, - getVBBADataForOnyx(), - ); +function connectBankAccountManually(bankAccountID: number, accountNumber?: string, routingNumber?: string, plaidMask?: string) { + type ConnectBankAccountManuallyParams = { + bankAccountID: number; + accountNumber?: string; + routingNumber?: string; + plaidMask?: string; + }; + + const parameters: ConnectBankAccountManuallyParams = { + bankAccountID, + accountNumber, + routingNumber, + plaidMask, + }; + + API.write('ConnectBankAccountManually', parameters, getVBBADataForOnyx()); } /** * Verify the user's identity via Onfido */ function verifyIdentityForBankAccount(bankAccountID: number, onfidoData: OnfidoData) { - API.write( - 'VerifyIdentityForBankAccount', - { - bankAccountID, - onfidoData: JSON.stringify(onfidoData), - }, - getVBBADataForOnyx(), - ); + type VerifyIdentityForBankAccountParams = { + bankAccountID: number; + onfidoData: string; + }; + + const parameters: VerifyIdentityForBankAccountParams = { + bankAccountID, + onfidoData: JSON.stringify(onfidoData), + }; + + API.write('VerifyIdentityForBankAccount', parameters, getVBBADataForOnyx()); } function openWorkspaceView() { @@ -339,13 +379,23 @@ function openWorkspaceView() { } function handlePlaidError(bankAccountID: number, error: string, errorDescription: string, plaidRequestID: string) { - API.write('BankAccount_HandlePlaidError', { + type BankAccountHandlePlaidErrorParams = { + bankAccountID: number; + error: string; + // eslint-disable-next-line @typescript-eslint/naming-convention + error_description: string; + plaidRequestID: string; + }; + + const parameters: BankAccountHandlePlaidErrorParams = { bankAccountID, error, // eslint-disable-next-line @typescript-eslint/naming-convention error_description: errorDescription, plaidRequestID, - }); + }; + + API.write('BankAccount_HandlePlaidError', parameters); } /** From 2f8d51f6f72a3e9fcc1d1449c160ce59473c212f Mon Sep 17 00:00:00 2001 From: Viktoryia Kliushun Date: Tue, 3 Oct 2023 18:15:03 +0200 Subject: [PATCH 4/9] Types updates --- src/libs/Navigation/Navigation.js | 2 +- src/libs/actions/BankAccounts.ts | 16 ++++++++-------- src/types/onyx/PersonalBankAccount.ts | 4 +++- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/libs/Navigation/Navigation.js b/src/libs/Navigation/Navigation.js index de6162685079..5cbd8e9b0af6 100644 --- a/src/libs/Navigation/Navigation.js +++ b/src/libs/Navigation/Navigation.js @@ -77,7 +77,7 @@ const getActiveRouteIndex = function (route, index) { /** * Main navigation method for redirecting to a route. * @param {String} route - * @param {String} type - Type of action to perform. Currently UP is supported. + * @param {String} [type] - Type of action to perform. Currently UP is supported. */ function navigate(route = ROUTES.HOME, type) { if (!canNavigate('navigate', {route})) { diff --git a/src/libs/actions/BankAccounts.ts b/src/libs/actions/BankAccounts.ts index 1d25de8aff06..968aa4cdaab1 100644 --- a/src/libs/actions/BankAccounts.ts +++ b/src/libs/actions/BankAccounts.ts @@ -7,9 +7,9 @@ import * as PlaidDataProps from '../../pages/ReimbursementAccount/plaidDataPropT import Navigation from '../Navigation/Navigation'; import ROUTES from '../../ROUTES'; import * as ReimbursementAccount from './ReimbursementAccount'; -import PlaidBankAccount from '../../types/onyx/PlaidBankAccount'; -import {ACHContractStepProps, BankAccountStepProps, CompanyStepProps, OnfidoData, ReimbursementAccountProps, RequestorStepProps} from '../../types/onyx/ReimbursementAccountDraft'; -import {OnyxData} from '../../types/onyx/Request'; +import type PlaidBankAccount from '../../types/onyx/PlaidBankAccount'; +import type {ACHContractStepProps, BankAccountStepProps, CompanyStepProps, OnfidoData, ReimbursementAccountProps, RequestorStepProps} from '../../types/onyx/ReimbursementAccountDraft'; +import type {OnyxData} from '../../types/onyx/Request'; export { goToWithdrawalAccountSetupStep, @@ -46,7 +46,7 @@ function openPersonalBankAccountSetupView(exitReportID: string) { if (exitReportID) { Onyx.merge(ONYXKEYS.PERSONAL_BANK_ACCOUNT, {exitReportID}); } - Navigation.navigate(ROUTES.SETTINGS_ADD_BANK_ACCOUNT, ''); + Navigation.navigate(ROUTES.SETTINGS_ADD_BANK_ACCOUNT); }); } @@ -70,7 +70,7 @@ function getVBBADataForOnyx(): OnyxData { key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, value: { isLoading: true, - errors: undefined, + errors: null, }, }, ], @@ -80,7 +80,7 @@ function getVBBADataForOnyx(): OnyxData { key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, value: { isLoading: false, - errors: undefined, + errors: null, }, }, ], @@ -154,7 +154,7 @@ function addPersonalBankAccount(account: PlaidBankAccount) { plaidAccessToken: account.plaidAccessToken, }; - const onyxData = { + const onyxData: OnyxData = { optimisticData: [ { onyxMethod: Onyx.METHOD.MERGE, @@ -271,7 +271,7 @@ function validateBankAccount(bankAccountID: number, validateCode: string) { } function openReimbursementAccountPage(stepToOpen: string, subStep: string, localCurrentStep: string) { - const onyxData = { + const onyxData: OnyxData = { optimisticData: [ { onyxMethod: Onyx.METHOD.MERGE, diff --git a/src/types/onyx/PersonalBankAccount.ts b/src/types/onyx/PersonalBankAccount.ts index 04897ca24d25..ea993d7393e8 100644 --- a/src/types/onyx/PersonalBankAccount.ts +++ b/src/types/onyx/PersonalBankAccount.ts @@ -1,6 +1,8 @@ +import * as OnyxCommon from './OnyxCommon'; + type PersonalBankAccount = { /** An error message to display to the user */ - error?: string; + errors?: OnyxCommon.Errors; /** Whether we should show the view that the bank account was successfully added */ shouldShowSuccess?: boolean; From 3738181b231685b230d51733122b57a69ea7de27 Mon Sep 17 00:00:00 2001 From: Viktoryia Kliushun Date: Tue, 3 Oct 2023 18:38:34 +0200 Subject: [PATCH 5/9] Remove extra type --- src/libs/actions/BankAccounts.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/actions/BankAccounts.ts b/src/libs/actions/BankAccounts.ts index 968aa4cdaab1..056ddbc9ce64 100644 --- a/src/libs/actions/BankAccounts.ts +++ b/src/libs/actions/BankAccounts.ts @@ -320,8 +320,7 @@ function openReimbursementAccountPage(stepToOpen: string, subStep: string, local * Updates the bank account in the database with the company step data */ function updateCompanyInformationForBankAccount(bankAccount: BankAccountCompanyInformation, policyID: string) { - type UpdateCompanyInformationParams = {policyID: string}; - type UpdateCompanyInformationForBankAccountParams = BankAccountCompanyInformation & UpdateCompanyInformationParams; + type UpdateCompanyInformationForBankAccountParams = BankAccountCompanyInformation & {policyID: string}; const parameters: UpdateCompanyInformationForBankAccountParams = {...bankAccount, policyID}; From 1b1c044241a50831186d923c48548972532caa95 Mon Sep 17 00:00:00 2001 From: Viktoryia Kliushun Date: Tue, 10 Oct 2023 13:10:35 +0200 Subject: [PATCH 6/9] Rename error_description to errorDescription --- src/libs/actions/BankAccounts.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/BankAccounts.ts b/src/libs/actions/BankAccounts.ts index 056ddbc9ce64..2cec51517327 100644 --- a/src/libs/actions/BankAccounts.ts +++ b/src/libs/actions/BankAccounts.ts @@ -381,16 +381,14 @@ function handlePlaidError(bankAccountID: number, error: string, errorDescription type BankAccountHandlePlaidErrorParams = { bankAccountID: number; error: string; - // eslint-disable-next-line @typescript-eslint/naming-convention - error_description: string; + errorDescription: string; plaidRequestID: string; }; const parameters: BankAccountHandlePlaidErrorParams = { bankAccountID, error, - // eslint-disable-next-line @typescript-eslint/naming-convention - error_description: errorDescription, + errorDescription, plaidRequestID, }; From cbe27b1a4651e438a1d4482574d6d73b38af33c7 Mon Sep 17 00:00:00 2001 From: Viktoryia Kliushun Date: Wed, 11 Oct 2023 15:12:40 +0200 Subject: [PATCH 7/9] Type api requests onyxData as OnyxData --- src/libs/actions/BankAccounts.ts | 12 ++++++++---- src/types/onyx/BankAccount.ts | 4 ++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/BankAccounts.ts b/src/libs/actions/BankAccounts.ts index 2cec51517327..cbee8ca0b7c4 100644 --- a/src/libs/actions/BankAccounts.ts +++ b/src/libs/actions/BankAccounts.ts @@ -197,7 +197,7 @@ function deletePaymentBankAccount(bankAccountID: number) { const parameters: DeletePaymentBankAccountParams = {bankAccountID}; - API.write('DeletePaymentBankAccount', parameters, { + const onyxData: OnyxData = { optimisticData: [ { onyxMethod: Onyx.METHOD.MERGE, @@ -215,7 +215,9 @@ function deletePaymentBankAccount(bankAccountID: number) { value: {[bankAccountID]: null}, }, ], - }); + }; + + API.write('DeletePaymentBankAccount', parameters, onyxData); } /** @@ -238,7 +240,7 @@ function validateBankAccount(bankAccountID: number, validateCode: string) { validateCode, }; - API.write('ValidateBankAccountWithTransactions', parameters, { + const onyxData: OnyxData = { optimisticData: [ { onyxMethod: Onyx.METHOD.MERGE, @@ -267,7 +269,9 @@ function validateBankAccount(bankAccountID: number, validateCode: string) { }, }, ], - }); + }; + + API.write('ValidateBankAccountWithTransactions', parameters, onyxData); } function openReimbursementAccountPage(stepToOpen: string, subStep: string, localCurrentStep: string) { diff --git a/src/types/onyx/BankAccount.ts b/src/types/onyx/BankAccount.ts index 28d323205162..61c7e44f68d7 100644 --- a/src/types/onyx/BankAccount.ts +++ b/src/types/onyx/BankAccount.ts @@ -1,3 +1,4 @@ +import {ValueOf} from 'type-fest'; import CONST from '../../CONST'; type AdditionalData = { @@ -69,6 +70,9 @@ type BankAccount = { /** All data related to the bank account */ accountData?: AccountData; + + /** Action that is waiting to happen on the bank account */ + pendingAction?: ValueOf; }; export default BankAccount; From aa0a6ce1228850bd2d0412c95d8606d662aff64f Mon Sep 17 00:00:00 2001 From: Viktoryia Kliushun Date: Thu, 12 Oct 2023 17:35:25 +0200 Subject: [PATCH 8/9] Add bank account step type --- src/libs/actions/BankAccounts.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/BankAccounts.ts b/src/libs/actions/BankAccounts.ts index cbee8ca0b7c4..a42804753631 100644 --- a/src/libs/actions/BankAccounts.ts +++ b/src/libs/actions/BankAccounts.ts @@ -1,4 +1,5 @@ import Onyx from 'react-native-onyx'; +import {ValueOf} from 'type-fest'; import CONST from '../../CONST'; import * as API from '../API'; import ONYXKEYS from '../../ONYXKEYS'; @@ -28,6 +29,10 @@ export {openOnfidoFlow, answerQuestionsForWallet, verifyIdentity, acceptWalletTe type BankAccountCompanyInformation = BankAccountStepProps & CompanyStepProps & ReimbursementAccountProps; +type BankAccountStep = ValueOf | ''; + +type BankAccountSubStep = ValueOf | ''; + function clearPlaid(): Promise { Onyx.set(ONYXKEYS.PLAID_LINK_TOKEN, ''); @@ -274,7 +279,7 @@ function validateBankAccount(bankAccountID: number, validateCode: string) { API.write('ValidateBankAccountWithTransactions', parameters, onyxData); } -function openReimbursementAccountPage(stepToOpen: string, subStep: string, localCurrentStep: string) { +function openReimbursementAccountPage(stepToOpen: BankAccountStep, subStep: BankAccountSubStep, localCurrentStep: BankAccountStep) { const onyxData: OnyxData = { optimisticData: [ { @@ -306,9 +311,9 @@ function openReimbursementAccountPage(stepToOpen: string, subStep: string, local }; type OpenReimbursementAccountPageParams = { - stepToOpen: string; - subStep: string; - localCurrentStep: string; + stepToOpen: BankAccountStep; + subStep: BankAccountSubStep; + localCurrentStep: BankAccountStep; }; const parameters: OpenReimbursementAccountPageParams = { From 3c0246c8876d46ca15479815ed0fede11a858bf3 Mon Sep 17 00:00:00 2001 From: Viktoryia Kliushun Date: Mon, 16 Oct 2023 08:59:55 +0200 Subject: [PATCH 9/9] Fix ts errors after merging main --- src/libs/actions/BankAccounts.ts | 16 ++++++++-------- src/types/onyx/ReimbursementAccount.ts | 12 ++++++++++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/libs/actions/BankAccounts.ts b/src/libs/actions/BankAccounts.ts index 16048e768c19..c954e9a213b4 100644 --- a/src/libs/actions/BankAccounts.ts +++ b/src/libs/actions/BankAccounts.ts @@ -1,5 +1,4 @@ import Onyx from 'react-native-onyx'; -import {ValueOf} from 'type-fest'; import CONST from '../../CONST'; import * as API from '../API'; import ONYXKEYS from '../../ONYXKEYS'; @@ -11,6 +10,7 @@ import * as ReimbursementAccount from './ReimbursementAccount'; import type PlaidBankAccount from '../../types/onyx/PlaidBankAccount'; import type {ACHContractStepProps, BankAccountStepProps, CompanyStepProps, OnfidoData, ReimbursementAccountProps, RequestorStepProps} from '../../types/onyx/ReimbursementAccountDraft'; import type {OnyxData} from '../../types/onyx/Request'; +import type {BankAccountStep, BankAccountSubStep} from '../../types/onyx/ReimbursementAccount'; export { goToWithdrawalAccountSetupStep, @@ -29,9 +29,9 @@ export {openOnfidoFlow, answerQuestionsForWallet, verifyIdentity, acceptWalletTe type BankAccountCompanyInformation = BankAccountStepProps & CompanyStepProps & ReimbursementAccountProps; -type BankAccountStep = ValueOf | ''; +type ReimbursementAccountStep = BankAccountStep | ''; -type BankAccountSubStep = ValueOf | ''; +type ReimbursementAccountSubStep = BankAccountSubStep | ''; function clearPlaid(): Promise { Onyx.set(ONYXKEYS.PLAID_LINK_TOKEN, ''); @@ -67,7 +67,7 @@ function clearOnfidoToken() { /** * Helper method to build the Onyx data required during setup of a Verified Business Bank Account */ -function getVBBADataForOnyx(currentStep: BankAccountStep = undefined): OnyxData { +function getVBBADataForOnyx(currentStep?: BankAccountStep): OnyxData { return { optimisticData: [ { @@ -285,7 +285,7 @@ function validateBankAccount(bankAccountID: number, validateCode: string) { API.write('ValidateBankAccountWithTransactions', parameters, onyxData); } -function openReimbursementAccountPage(stepToOpen: BankAccountStep, subStep: BankAccountSubStep, localCurrentStep: BankAccountStep) { +function openReimbursementAccountPage(stepToOpen: ReimbursementAccountStep, subStep: ReimbursementAccountSubStep, localCurrentStep: ReimbursementAccountStep) { const onyxData: OnyxData = { optimisticData: [ { @@ -317,9 +317,9 @@ function openReimbursementAccountPage(stepToOpen: BankAccountStep, subStep: Bank }; type OpenReimbursementAccountPageParams = { - stepToOpen: BankAccountStep; - subStep: BankAccountSubStep; - localCurrentStep: BankAccountStep; + stepToOpen: ReimbursementAccountStep; + subStep: ReimbursementAccountSubStep; + localCurrentStep: ReimbursementAccountStep; }; const parameters: OpenReimbursementAccountPageParams = { diff --git a/src/types/onyx/ReimbursementAccount.ts b/src/types/onyx/ReimbursementAccount.ts index 4f2a05d7f4e1..fc46c9aa3132 100644 --- a/src/types/onyx/ReimbursementAccount.ts +++ b/src/types/onyx/ReimbursementAccount.ts @@ -2,12 +2,16 @@ import {ValueOf} from 'type-fest'; import * as OnyxCommon from './OnyxCommon'; import CONST from '../../CONST'; +type BankAccountStep = ValueOf; + +type BankAccountSubStep = ValueOf; + type ACHData = { /** Step of the setup flow that we are on. Determines which view is presented. */ - currentStep: ValueOf; + currentStep: BankAccountStep; /** Optional subStep we would like the user to start back on */ - subStep?: ValueOf; + subStep?: BankAccountSubStep; /** Bank account state */ state?: string; @@ -38,7 +42,11 @@ type ReimbursementAccount = { /** Any additional error message to show */ errors?: OnyxCommon.Errors; + /** Draft step of the setup flow from Onyx */ + draftStep?: BankAccountStep; + pendingAction?: OnyxCommon.PendingAction; }; export default ReimbursementAccount; +export type {BankAccountStep, BankAccountSubStep};