diff --git a/src/libs/PaymentUtils.ts b/src/libs/PaymentUtils.ts index 64260569639e..7ea935577fb1 100644 --- a/src/libs/PaymentUtils.ts +++ b/src/libs/PaymentUtils.ts @@ -1,19 +1,13 @@ -import {SvgProps} from 'react-native-svg'; import BankAccountModel from './models/BankAccount'; import getBankIcon from '../components/Icon/BankIcons'; import CONST from '../CONST'; import * as Localize from './Localize'; import Fund from '../types/onyx/Fund'; import BankAccount from '../types/onyx/BankAccount'; +import PaymentMethod from '../types/onyx/PaymentMethod'; type AccountType = BankAccount['accountType'] | Fund['accountType']; -type PaymentMethod = (BankAccount | Fund) & { - description: string; - icon: React.FC; - iconSize?: number; -}; - /** * Check to see if user has either a debit card or personal bank account added */ diff --git a/src/libs/actions/PaymentMethods.js b/src/libs/actions/PaymentMethods.js deleted file mode 100644 index 0ed6f8b036bb..000000000000 --- a/src/libs/actions/PaymentMethods.js +++ /dev/null @@ -1,356 +0,0 @@ -import _ from 'underscore'; -import {createRef} from 'react'; -import Onyx from 'react-native-onyx'; -import ONYXKEYS from '../../ONYXKEYS'; -import * as API from '../API'; -import CONST from '../../CONST'; -import Navigation from '../Navigation/Navigation'; -import * as CardUtils from '../CardUtils'; -import ROUTES from '../../ROUTES'; - -/** - * Sets up a ref to an instance of the KYC Wall component. - */ -const kycWallRef = createRef(); - -/** - * When we successfully add a payment method or pass the KYC checks we will continue with our setup action if we have one set. - */ -function continueSetup() { - if (!kycWallRef.current || !kycWallRef.current.continue) { - Navigation.goBack(ROUTES.HOME); - return; - } - - // Close the screen (Add Debit Card, Add Bank Account, or Enable Payments) on success and continue with setup - Navigation.goBack(ROUTES.HOME); - kycWallRef.current.continue(); -} - -function openWalletPage() { - const onyxData = { - optimisticData: [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.IS_LOADING_PAYMENT_METHODS, - value: true, - }, - ], - successData: [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.IS_LOADING_PAYMENT_METHODS, - value: false, - }, - ], - failureData: [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.IS_LOADING_PAYMENT_METHODS, - value: false, - }, - ], - }; - - return API.read('OpenPaymentsPage', {}, onyxData); -} - -/** - * - * @param {Number} bankAccountID - * @param {Number} fundID - * @param {Object} previousPaymentMethod - * @param {Object} currentPaymentMethod - * @param {Boolean} isOptimisticData - * @return {Array} - * - */ -function getMakeDefaultPaymentOnyxData(bankAccountID, fundID, previousPaymentMethod, currentPaymentMethod, isOptimisticData = true) { - const onyxData = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.USER_WALLET, - value: { - walletLinkedAccountID: bankAccountID || fundID, - walletLinkedAccountType: bankAccountID ? CONST.PAYMENT_METHODS.BANK_ACCOUNT : CONST.PAYMENT_METHODS.DEBIT_CARD, - }, - }, - ]; - - // Only clear the error if this is optimistic data. If this is failure data, we do not want to clear the error that came from the server. - if (isOptimisticData) { - onyxData[0].value.errors = null; - } - - if (previousPaymentMethod) { - onyxData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: previousPaymentMethod.accountType === CONST.PAYMENT_METHODS.BANK_ACCOUNT ? ONYXKEYS.BANK_ACCOUNT_LIST : ONYXKEYS.FUND_LIST, - value: { - [previousPaymentMethod.methodID]: { - isDefault: !isOptimisticData, - }, - }, - }); - } - - if (currentPaymentMethod) { - onyxData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: currentPaymentMethod.accountType === CONST.PAYMENT_METHODS.BANK_ACCOUNT ? ONYXKEYS.BANK_ACCOUNT_LIST : ONYXKEYS.FUND_LIST, - value: { - [currentPaymentMethod.methodID]: { - isDefault: isOptimisticData, - }, - }, - }); - } - - return onyxData; -} - -/** - * Sets the default bank account or debit card for an Expensify Wallet - * - * @param {Number} bankAccountID - * @param {Number} fundID - * @param {Object} previousPaymentMethod - * @param {Object} currentPaymentMethod - * - */ -function makeDefaultPaymentMethod(bankAccountID, fundID, previousPaymentMethod, currentPaymentMethod) { - API.write( - 'MakeDefaultPaymentMethod', - { - bankAccountID, - fundID, - }, - { - optimisticData: getMakeDefaultPaymentOnyxData(bankAccountID, fundID, previousPaymentMethod, currentPaymentMethod, true, ONYXKEYS.FUND_LIST), - failureData: getMakeDefaultPaymentOnyxData(bankAccountID, fundID, previousPaymentMethod, currentPaymentMethod, false, ONYXKEYS.FUND_LIST), - }, - ); -} - -/** - * Calls the API to add a new card. - * - * @param {Object} params - */ -function addPaymentCard(params) { - const cardMonth = CardUtils.getMonthFromExpirationDateString(params.expirationDate); - const cardYear = CardUtils.getYearFromExpirationDateString(params.expirationDate); - - API.write( - 'AddPaymentCard', - { - cardNumber: params.cardNumber, - cardYear, - cardMonth, - cardCVV: params.securityCode, - addressName: params.nameOnCard, - addressZip: params.addressZipCode, - currency: CONST.CURRENCY.USD, - isP2PDebitCard: true, - }, - { - optimisticData: [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.FORMS.ADD_DEBIT_CARD_FORM, - value: {isLoading: true}, - }, - ], - successData: [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.FORMS.ADD_DEBIT_CARD_FORM, - value: {isLoading: false}, - }, - ], - failureData: [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.FORMS.ADD_DEBIT_CARD_FORM, - value: {isLoading: false}, - }, - ], - }, - ); -} - -/** - * Resets the values for the add debit card form back to their initial states - */ -function clearDebitCardFormErrorAndSubmit() { - Onyx.set(ONYXKEYS.FORMS.ADD_DEBIT_CARD_FORM, { - isLoading: false, - errors: null, - }); -} - -/** - * Call the API to transfer wallet balance. - * @param {Object} paymentMethod - * @param {*} paymentMethod.methodID - * @param {String} paymentMethod.accountType - */ -function transferWalletBalance(paymentMethod) { - const paymentMethodIDKey = paymentMethod.accountType === CONST.PAYMENT_METHODS.BANK_ACCOUNT ? CONST.PAYMENT_METHOD_ID_KEYS.BANK_ACCOUNT : CONST.PAYMENT_METHOD_ID_KEYS.DEBIT_CARD; - const parameters = { - [paymentMethodIDKey]: paymentMethod.methodID, - }; - - API.write('TransferWalletBalance', parameters, { - optimisticData: [ - { - onyxMethod: 'merge', - key: ONYXKEYS.WALLET_TRANSFER, - value: { - loading: true, - errors: null, - }, - }, - ], - successData: [ - { - onyxMethod: 'merge', - key: ONYXKEYS.WALLET_TRANSFER, - value: { - loading: false, - shouldShowSuccess: true, - paymentMethodType: paymentMethod.accountType, - }, - }, - ], - failureData: [ - { - onyxMethod: 'merge', - key: ONYXKEYS.WALLET_TRANSFER, - value: { - loading: false, - shouldShowSuccess: false, - }, - }, - ], - }); -} - -function resetWalletTransferData() { - Onyx.merge(ONYXKEYS.WALLET_TRANSFER, { - selectedAccountType: '', - selectedAccountID: null, - filterPaymentMethodType: null, - loading: false, - shouldShowSuccess: false, - }); -} - -/** - * @param {String} selectedAccountType - * @param {String} selectedAccountID - */ -function saveWalletTransferAccountTypeAndID(selectedAccountType, selectedAccountID) { - Onyx.merge(ONYXKEYS.WALLET_TRANSFER, {selectedAccountType, selectedAccountID}); -} - -/** - * Toggles the user's selected type of payment method (bank account or debit card) on the wallet transfer balance screen. - * @param {String} filterPaymentMethodType - */ -function saveWalletTransferMethodType(filterPaymentMethodType) { - Onyx.merge(ONYXKEYS.WALLET_TRANSFER, {filterPaymentMethodType}); -} - -function dismissSuccessfulTransferBalancePage() { - Onyx.merge(ONYXKEYS.WALLET_TRANSFER, {shouldShowSuccess: false}); - Navigation.goBack(ROUTES.SETTINGS_WALLET); -} - -/** - * Looks through each payment method to see if there is an existing error - * @param {Object} bankList - * @param {Object} fundList - * @returns {Boolean} - */ -function hasPaymentMethodError(bankList, fundList) { - const combinedPaymentMethods = {...bankList, ...fundList}; - return _.some(combinedPaymentMethods, (item) => !_.isEmpty(item.errors)); -} - -/** - * Clears the error for the specified payment item - * @param {String} paymentListKey The onyx key for the provided payment method - * @param {String} paymentMethodID - */ -function clearDeletePaymentMethodError(paymentListKey, paymentMethodID) { - Onyx.merge(paymentListKey, { - [paymentMethodID]: { - pendingAction: null, - errors: null, - }, - }); -} - -/** - * If there was a failure adding a payment method, clearing it removes the payment method from the list entirely - * @param {String} paymentListKey The onyx key for the provided payment method - * @param {String} paymentMethodID - */ -function clearAddPaymentMethodError(paymentListKey, paymentMethodID) { - Onyx.merge(paymentListKey, { - [paymentMethodID]: null, - }); -} - -/** - * Clear any error(s) related to the user's wallet - */ -function clearWalletError() { - Onyx.merge(ONYXKEYS.USER_WALLET, {errors: null}); -} - -/** - * Clear any error(s) related to the user's wallet terms - */ -function clearWalletTermsError() { - Onyx.merge(ONYXKEYS.WALLET_TERMS, {errors: null}); -} - -function deletePaymentCard(fundID) { - API.write( - 'DeletePaymentCard', - { - fundID, - }, - { - optimisticData: [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.FUND_LIST}`, - value: {[fundID]: {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}}, - }, - ], - }, - ); -} - -export { - deletePaymentCard, - addPaymentCard, - openWalletPage, - makeDefaultPaymentMethod, - kycWallRef, - continueSetup, - clearDebitCardFormErrorAndSubmit, - dismissSuccessfulTransferBalancePage, - transferWalletBalance, - resetWalletTransferData, - saveWalletTransferAccountTypeAndID, - saveWalletTransferMethodType, - hasPaymentMethodError, - clearDeletePaymentMethodError, - clearAddPaymentMethodError, - clearWalletError, - clearWalletTermsError, -}; diff --git a/src/libs/actions/PaymentMethods.ts b/src/libs/actions/PaymentMethods.ts new file mode 100644 index 000000000000..c532d0fbeb63 --- /dev/null +++ b/src/libs/actions/PaymentMethods.ts @@ -0,0 +1,393 @@ +import {createRef} from 'react'; +import Onyx, {OnyxUpdate} from 'react-native-onyx'; +import {ValueOf} from 'type-fest'; +import ONYXKEYS, {OnyxValues} from '../../ONYXKEYS'; +import * as API from '../API'; +import CONST from '../../CONST'; +import Navigation from '../Navigation/Navigation'; +import * as CardUtils from '../CardUtils'; +import ROUTES from '../../ROUTES'; +import {FilterMethodPaymentType} from '../../types/onyx/WalletTransfer'; +import PaymentMethod from '../../types/onyx/PaymentMethod'; + +type KYCWallRef = { + continue?: () => void; +}; + +/** + * Sets up a ref to an instance of the KYC Wall component. + */ +const kycWallRef = createRef(); + +/** + * When we successfully add a payment method or pass the KYC checks we will continue with our setup action if we have one set. + */ +function continueSetup() { + if (!kycWallRef.current?.continue) { + Navigation.goBack(ROUTES.HOME); + return; + } + + // Close the screen (Add Debit Card, Add Bank Account, or Enable Payments) on success and continue with setup + Navigation.goBack(ROUTES.HOME); + kycWallRef.current.continue(); +} + +function openWalletPage() { + const optimisticData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.IS_LOADING_PAYMENT_METHODS, + value: true, + }, + ]; + const successData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.IS_LOADING_PAYMENT_METHODS, + value: false, + }, + ]; + const failureData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.IS_LOADING_PAYMENT_METHODS, + value: false, + }, + ]; + + return API.read( + 'OpenPaymentsPage', + {}, + { + optimisticData, + successData, + failureData, + }, + ); +} + +function getMakeDefaultPaymentOnyxData( + bankAccountID: number, + fundID: number, + previousPaymentMethod: PaymentMethod, + currentPaymentMethod: PaymentMethod, + isOptimisticData = true, +): OnyxUpdate[] { + const onyxData: OnyxUpdate[] = [ + isOptimisticData + ? { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.USER_WALLET, + value: { + walletLinkedAccountID: bankAccountID || fundID, + walletLinkedAccountType: bankAccountID ? CONST.PAYMENT_METHODS.BANK_ACCOUNT : CONST.PAYMENT_METHODS.DEBIT_CARD, + // Only clear the error if this is optimistic data. If this is failure data, we do not want to clear the error that came from the server. + errors: null, + }, + } + : { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.USER_WALLET, + value: { + walletLinkedAccountID: bankAccountID || fundID, + walletLinkedAccountType: bankAccountID ? CONST.PAYMENT_METHODS.BANK_ACCOUNT : CONST.PAYMENT_METHODS.DEBIT_CARD, + }, + }, + ]; + + if (previousPaymentMethod?.methodID) { + onyxData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: previousPaymentMethod.accountType === CONST.PAYMENT_METHODS.BANK_ACCOUNT ? ONYXKEYS.BANK_ACCOUNT_LIST : ONYXKEYS.FUND_LIST, + value: { + [previousPaymentMethod.methodID]: { + isDefault: !isOptimisticData, + }, + }, + }); + } + + if (currentPaymentMethod?.methodID) { + onyxData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: currentPaymentMethod.accountType === CONST.PAYMENT_METHODS.BANK_ACCOUNT ? ONYXKEYS.BANK_ACCOUNT_LIST : ONYXKEYS.FUND_LIST, + value: { + [currentPaymentMethod.methodID]: { + isDefault: isOptimisticData, + }, + }, + }); + } + + return onyxData; +} + +/** + * Sets the default bank account or debit card for an Expensify Wallet + * + */ +function makeDefaultPaymentMethod(bankAccountID: number, fundID: number, previousPaymentMethod: PaymentMethod, currentPaymentMethod: PaymentMethod) { + type MakeDefaultPaymentMethodParams = { + bankAccountID: number; + fundID: number; + }; + + const parameters: MakeDefaultPaymentMethodParams = { + bankAccountID, + fundID, + }; + + API.write('MakeDefaultPaymentMethod', parameters, { + optimisticData: getMakeDefaultPaymentOnyxData(bankAccountID, fundID, previousPaymentMethod, currentPaymentMethod, true), + failureData: getMakeDefaultPaymentOnyxData(bankAccountID, fundID, previousPaymentMethod, currentPaymentMethod, false), + }); +} + +type PaymentCardParams = {expirationDate: string; cardNumber: string; securityCode: string; nameOnCard: string; addressZipCode: string}; + +/** + * Calls the API to add a new card. + * + */ +function addPaymentCard(params: PaymentCardParams) { + const cardMonth = CardUtils.getMonthFromExpirationDateString(params.expirationDate); + const cardYear = CardUtils.getYearFromExpirationDateString(params.expirationDate); + + type AddPaymentCardParams = { + cardNumber: string; + cardYear: string; + cardMonth: string; + cardCVV: string; + addressName: string; + addressZip: string; + currency: ValueOf; + isP2PDebitCard: boolean; + }; + + const parameters: AddPaymentCardParams = { + cardNumber: params.cardNumber, + cardYear, + cardMonth, + cardCVV: params.securityCode, + addressName: params.nameOnCard, + addressZip: params.addressZipCode, + currency: CONST.CURRENCY.USD, + isP2PDebitCard: true, + }; + + const optimisticData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.FORMS.ADD_DEBIT_CARD_FORM, + value: {isLoading: true}, + }, + ]; + + const successData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.FORMS.ADD_DEBIT_CARD_FORM, + value: {isLoading: false}, + }, + ]; + + const failureData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.FORMS.ADD_DEBIT_CARD_FORM, + value: {isLoading: false}, + }, + ]; + + API.write('AddPaymentCard', parameters, { + optimisticData, + successData, + failureData, + }); +} + +/** + * Resets the values for the add debit card form back to their initial states + */ +function clearDebitCardFormErrorAndSubmit() { + Onyx.set(ONYXKEYS.FORMS.ADD_DEBIT_CARD_FORM, { + isLoading: false, + errors: undefined, + setupComplete: true, + }); +} + +/** + * Call the API to transfer wallet balance. + * + */ +function transferWalletBalance(paymentMethod: PaymentMethod) { + const paymentMethodIDKey = paymentMethod.accountType === CONST.PAYMENT_METHODS.BANK_ACCOUNT ? CONST.PAYMENT_METHOD_ID_KEYS.BANK_ACCOUNT : CONST.PAYMENT_METHOD_ID_KEYS.DEBIT_CARD; + + type TransferWalletBalanceParameters = Partial, number | undefined>>; + + const parameters: TransferWalletBalanceParameters = { + [paymentMethodIDKey]: paymentMethod.methodID, + }; + + const optimisticData: OnyxUpdate[] = [ + { + onyxMethod: 'merge', + key: ONYXKEYS.WALLET_TRANSFER, + value: { + loading: true, + errors: null, + }, + }, + ]; + + const successData: OnyxUpdate[] = [ + { + onyxMethod: 'merge', + key: ONYXKEYS.WALLET_TRANSFER, + value: { + loading: false, + shouldShowSuccess: true, + paymentMethodType: paymentMethod.accountType, + }, + }, + ]; + + const failureData: OnyxUpdate[] = [ + { + onyxMethod: 'merge', + key: ONYXKEYS.WALLET_TRANSFER, + value: { + loading: false, + shouldShowSuccess: false, + }, + }, + ]; + + API.write('TransferWalletBalance', parameters, { + optimisticData, + successData, + failureData, + }); +} + +function resetWalletTransferData() { + Onyx.merge(ONYXKEYS.WALLET_TRANSFER, { + selectedAccountType: '', + selectedAccountID: null, + filterPaymentMethodType: null, + loading: false, + shouldShowSuccess: false, + }); +} + +function saveWalletTransferAccountTypeAndID(selectedAccountType: string, selectedAccountID: string) { + Onyx.merge(ONYXKEYS.WALLET_TRANSFER, {selectedAccountType, selectedAccountID}); +} + +/** + * Toggles the user's selected type of payment method (bank account or debit card) on the wallet transfer balance screen. + * + */ +function saveWalletTransferMethodType(filterPaymentMethodType?: FilterMethodPaymentType) { + Onyx.merge(ONYXKEYS.WALLET_TRANSFER, {filterPaymentMethodType}); +} + +function dismissSuccessfulTransferBalancePage() { + Onyx.merge(ONYXKEYS.WALLET_TRANSFER, {shouldShowSuccess: false}); + Navigation.goBack(ROUTES.SETTINGS_WALLET); +} + +/** + * Looks through each payment method to see if there is an existing error + * + */ +function hasPaymentMethodError(bankList: OnyxValues[typeof ONYXKEYS.BANK_ACCOUNT_LIST], fundList: OnyxValues[typeof ONYXKEYS.FUND_LIST]): boolean { + const combinedPaymentMethods = {...bankList, ...fundList}; + + return Object.values(combinedPaymentMethods).some((item) => Object.keys(item.errors ?? {}).length); +} + +type PaymentListKey = typeof ONYXKEYS.BANK_ACCOUNT_LIST | typeof ONYXKEYS.FUND_LIST; + +/** + * Clears the error for the specified payment item + * @param paymentListKey The onyx key for the provided payment method + * @param paymentMethodID + */ +function clearDeletePaymentMethodError(paymentListKey: PaymentListKey, paymentMethodID: string) { + Onyx.merge(paymentListKey, { + [paymentMethodID]: { + pendingAction: null, + errors: null, + }, + }); +} + +/** + * If there was a failure adding a payment method, clearing it removes the payment method from the list entirely + * @param paymentListKey The onyx key for the provided payment method + * @param paymentMethodID + */ +function clearAddPaymentMethodError(paymentListKey: PaymentListKey, paymentMethodID: string) { + Onyx.merge(paymentListKey, { + [paymentMethodID]: null, + }); +} + +/** + * Clear any error(s) related to the user's wallet + */ +function clearWalletError() { + Onyx.merge(ONYXKEYS.USER_WALLET, {errors: null}); +} + +/** + * Clear any error(s) related to the user's wallet terms + */ +function clearWalletTermsError() { + Onyx.merge(ONYXKEYS.WALLET_TERMS, {errors: null}); +} + +function deletePaymentCard(fundID: number) { + type DeletePaymentCardParams = { + fundID: number; + }; + + const parameters: DeletePaymentCardParams = { + fundID, + }; + + const optimisticData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.FUND_LIST}`, + value: {[fundID]: {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}}, + }, + ]; + + API.write('DeletePaymentCard', parameters, { + optimisticData, + }); +} + +export { + deletePaymentCard, + addPaymentCard, + openWalletPage, + makeDefaultPaymentMethod, + kycWallRef, + continueSetup, + clearDebitCardFormErrorAndSubmit, + dismissSuccessfulTransferBalancePage, + transferWalletBalance, + resetWalletTransferData, + saveWalletTransferAccountTypeAndID, + saveWalletTransferMethodType, + hasPaymentMethodError, + clearDeletePaymentMethodError, + clearAddPaymentMethodError, + clearWalletError, + clearWalletTermsError, +}; diff --git a/src/types/onyx/AccountData.ts b/src/types/onyx/AccountData.ts new file mode 100644 index 000000000000..79484e7886af --- /dev/null +++ b/src/types/onyx/AccountData.ts @@ -0,0 +1,55 @@ +import * as OnyxCommon from './OnyxCommon'; + +type AdditionalData = { + isP2PDebitCard?: boolean; + beneficialOwners?: string[]; + currency?: string; + bankName?: string; + fieldsType?: string; + country?: string; +}; + +type AccountData = { + /** The masked bank account number */ + accountNumber?: string; + + /** The name of the institution (bank of america, etc */ + addressName?: string; + + /** Can we use this account to pay other people? */ + allowDebit?: boolean; + + /** Can we use this account to receive money from other people? */ + defaultCredit?: boolean; + + /** Is a saving account */ + isSavings?: boolean; + + /** Return whether or not this bank account has been risk checked */ + riskChecked?: boolean; + + /** Account routing number */ + routingNumber?: string; + + /** The status of the bank account */ + state?: string; + + /** All user emails that have access to this bank account */ + sharees?: string[]; + + processor?: string; + + /** The bankAccountID in the bankAccounts db */ + bankAccountID?: number; + + /** All data related to the bank account */ + additionalData?: AdditionalData; + + /** The bank account type */ + type?: string; + + /** Any error message to show */ + errors?: OnyxCommon.Errors; +}; + +export default AccountData; diff --git a/src/types/onyx/BankAccount.ts b/src/types/onyx/BankAccount.ts index 61c7e44f68d7..58d9654f0c6f 100644 --- a/src/types/onyx/BankAccount.ts +++ b/src/types/onyx/BankAccount.ts @@ -1,54 +1,6 @@ -import {ValueOf} from 'type-fest'; import CONST from '../../CONST'; - -type AdditionalData = { - isP2PDebitCard?: boolean; - beneficialOwners?: string[]; - currency?: string; - bankName?: string; - fieldsType?: string; - country?: string; -}; - -type AccountData = { - /** The masked bank account number */ - accountNumber?: string; - - /** The name of the institution (bank of america, etc */ - addressName?: string; - - /** Can we use this account to pay other people? */ - allowDebit?: boolean; - - /** Can we use this account to receive money from other people? */ - defaultCredit?: boolean; - - /** Is a saving account */ - isSavings?: boolean; - - /** Return whether or not this bank account has been risk checked */ - riskChecked?: boolean; - - /** Account routing number */ - routingNumber?: string; - - /** The status of the bank account */ - state?: string; - - /** All user emails that have access to this bank account */ - sharees?: string[]; - - processor?: string; - - /** The bankAccountID in the bankAccounts db */ - bankAccountID?: number; - - /** All data related to the bank account */ - additionalData?: AdditionalData; - - /** The bank account type */ - type?: string; -}; +import AccountData from './AccountData'; +import * as OnyxCommon from './OnyxCommon'; type BankAccount = { /** The bank account type */ @@ -71,8 +23,11 @@ type BankAccount = { /** All data related to the bank account */ accountData?: AccountData; - /** Action that is waiting to happen on the bank account */ - pendingAction?: ValueOf; + /** Any additional error message to show */ + errors?: OnyxCommon.Errors; + + /** Indicates the type of change made to the bank account that hasn't been synced with the server yet */ + pendingAction?: OnyxCommon.PendingAction; }; export default BankAccount; diff --git a/src/types/onyx/Fund.ts b/src/types/onyx/Fund.ts index 2da0edf78045..e27cc0e20e0e 100644 --- a/src/types/onyx/Fund.ts +++ b/src/types/onyx/Fund.ts @@ -1,4 +1,5 @@ import CONST from '../../CONST'; +import * as OnyxCommon from './OnyxCommon'; type AdditionalData = { isBillingCard?: boolean; @@ -30,6 +31,9 @@ type Fund = { key?: string; methodID?: number; title?: string; + isDefault?: boolean; + errors?: OnyxCommon.Errors; + pendingAction?: OnyxCommon.PendingAction; }; export default Fund; diff --git a/src/types/onyx/PaymentMethod.ts b/src/types/onyx/PaymentMethod.ts new file mode 100644 index 000000000000..773e6ff1197c --- /dev/null +++ b/src/types/onyx/PaymentMethod.ts @@ -0,0 +1,11 @@ +import {SvgProps} from 'react-native-svg'; +import BankAccount from './BankAccount'; +import Fund from './Fund'; + +type PaymentMethod = (BankAccount | Fund) & { + description: string; + icon: React.FC; + iconSize?: number; +}; + +export default PaymentMethod; diff --git a/src/types/onyx/WalletTransfer.ts b/src/types/onyx/WalletTransfer.ts index 3dd28729ba96..18b223a0b1ef 100644 --- a/src/types/onyx/WalletTransfer.ts +++ b/src/types/onyx/WalletTransfer.ts @@ -1,5 +1,7 @@ +import {ValueOf} from 'type-fest'; import CONST from '../../CONST'; import * as OnyxCommon from './OnyxCommon'; +import PaymentMethod from './PaymentMethod'; type WalletTransfer = { /** Selected accountID for transfer */ @@ -9,7 +11,7 @@ type WalletTransfer = { selectedAccountType?: string; /** Type to filter the payment Method list */ - filterPaymentMethodType?: typeof CONST.PAYMENT_METHODS.DEBIT_CARD | typeof CONST.PAYMENT_METHODS.BANK_ACCOUNT; + filterPaymentMethodType?: FilterMethodPaymentType; /** Whether the success screen is shown to user. */ shouldShowSuccess?: boolean; @@ -19,6 +21,12 @@ type WalletTransfer = { /** Whether or not data is loading */ loading?: boolean; + + paymentMethodType?: ValueOf>; }; +type FilterMethodPaymentType = typeof CONST.PAYMENT_METHODS.DEBIT_CARD | typeof CONST.PAYMENT_METHODS.BANK_ACCOUNT | null; + export default WalletTransfer; + +export type {FilterMethodPaymentType}; diff --git a/src/types/onyx/index.ts b/src/types/onyx/index.ts index e50925e7adf2..571c2e04a390 100644 --- a/src/types/onyx/index.ts +++ b/src/types/onyx/index.ts @@ -46,6 +46,7 @@ import RecentWaypoint from './RecentWaypoint'; import RecentlyUsedCategories from './RecentlyUsedCategories'; import RecentlyUsedTags from './RecentlyUsedTags'; import PolicyTag from './PolicyTag'; +import AccountData from './AccountData'; export type { Account, @@ -98,4 +99,5 @@ export type { RecentlyUsedCategories, RecentlyUsedTags, PolicyTag, + AccountData, };