Repository navigation
Refactor/36648 wallet enablement flow #39038
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mountiny
merged 31 commits into
Expensify:main
from
koko57:refactor/36648-wallet-enablement-flow
Apr 4, 2024
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
fccd32f
feat: create a separate route for refactor
koko57 c20c2cb
feat: UI for step 0
koko57 61e3e86
Merge branch 'main' into refactor/36648-wallet-enablement-flow
koko57 c738d86
Merge branch 'main' into refactor/36648-wallet-enablement-flow
koko57 d6de861
Merge branch 'main' into refactor/36648-wallet-enablement-flow
koko57 42c592f
feat: add english translations
koko57 9d63de6
feat: wip - connect the substeps
koko57 3259d64
Merge branch 'main' into refactor/36648-wallet-enablement-flow
koko57 b89e714
fix: minor changes
koko57 58d65b9
fix: resolve conflicts
koko57 5dac8aa
fix: resolve conflicts
koko57 123f089
Merge branch 'main' into refactor/36648-wallet-enablement-flow
koko57 fc1fa09
refactor: wip
koko57 7e5d868
refactor: code cleanup
koko57 e57e120
fix: remove en translations dupes
koko57 bc8cc3a
fix: es translations
koko57 b21b721
fix: translations
koko57 f307708
fix: apply requested changes
koko57 3f91a9e
fix: lint
koko57 1c9c458
fix: minor fix
koko57 012c86f
Merge branch 'main' into refactor/36648-wallet-enablement-flow
koko57 d04be03
fix: resolve conflicts
koko57 955b5a3
fix: remove conflicting file
koko57 edf43c9
Merge branch 'main' into refactor/36648-wallet-enablement-flow
koko57 641008d
Merge branch 'main' into refactor/36648-wallet-enablement-flow
koko57 18b2fe1
fix: fix headline styles
koko57 0304e9a
Merge branch 'main' into refactor/36648-wallet-enablement-flow
koko57 1806c60
Merge branch 'main' into refactor/36648-wallet-enablement-flow
koko57 d9e9515
fix: rename components
koko57 0ee4dcb
fix: apply requested changes
koko57 12c690c
fix: minor fix
koko57 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import Onyx from 'react-native-onyx'; | ||
| import type {FormInputErrors, FormOnyxValues} from '@components/Form/types'; | ||
| import type {OnfidoDataWithApplicantID} from '@components/Onfido/types'; | ||
| import * as API from '@libs/API'; | ||
| import type { | ||
|
|
@@ -18,6 +19,7 @@ import CONST from '@src/CONST'; | |
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import ROUTES from '@src/ROUTES'; | ||
| import type {Route} from '@src/ROUTES'; | ||
| import type {PersonalBankAccountForm} from '@src/types/form'; | ||
| import type {ACHContractStepProps, BeneficialOwnersStepProps, CompanyStepProps, RequestorStepProps} from '@src/types/form/ReimbursementAccountForm'; | ||
| import type PlaidBankAccount from '@src/types/onyx/PlaidBankAccount'; | ||
| import type {BankAccountStep, BankAccountSubStep} from '@src/types/onyx/ReimbursementAccount'; | ||
|
|
@@ -42,6 +44,8 @@ type ReimbursementAccountStep = BankAccountStep | ''; | |
|
|
||
| type ReimbursementAccountSubStep = BankAccountSubStep | ''; | ||
|
|
||
| type AccountFormValues = typeof ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT_FORM | typeof ONYXKEYS.FORMS.REIMBURSEMENT_ACCOUNT_FORM; | ||
|
|
||
| type BusinessAddress = { | ||
| addressStreet?: string; | ||
| addressCity?: string; | ||
|
|
@@ -82,6 +86,23 @@ function openPersonalBankAccountSetupView(exitReportID?: string) { | |
| }); | ||
| } | ||
|
|
||
| /** | ||
| * TODO: remove the previous function and rename this function to openPersonalBankAccountSetupView after migrating to the new flow | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NAB: Usually its a good practice to add a link to the issue where we are already going to do this too, so the main issue would work here |
||
| * Open the personal bank account setup flow, with an optional exitReportID to redirect to once the flow is finished. | ||
| */ | ||
| function openPersonalBankAccountSetupViewRefactor(exitReportID?: string) { | ||
| clearPlaid().then(() => { | ||
| if (exitReportID) { | ||
| Onyx.merge(ONYXKEYS.PERSONAL_BANK_ACCOUNT, {exitReportID}); | ||
| } | ||
| Onyx.merge(ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT_FORM_DRAFT, {setupType: CONST.BANK_ACCOUNT.SETUP_TYPE.PLAID}); | ||
| }); | ||
| } | ||
|
|
||
| function clearPersonalBankAccountSetupType() { | ||
| Onyx.merge(ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT_FORM_DRAFT, {setupType: null}); | ||
| } | ||
|
|
||
| /** | ||
| * Whether after adding a bank account we should continue with the KYC flow. If so, we must specify the fallback route. | ||
| */ | ||
|
|
@@ -92,13 +113,19 @@ function setPersonalBankAccountContinueKYCOnSuccess(onSuccessFallbackRoute: Rout | |
| function clearPersonalBankAccount() { | ||
| clearPlaid(); | ||
| Onyx.set(ONYXKEYS.PERSONAL_BANK_ACCOUNT, {}); | ||
| Onyx.set(ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT_FORM_DRAFT, null); | ||
| clearPersonalBankAccountSetupType(); | ||
| } | ||
|
|
||
| function clearOnfidoToken() { | ||
| Onyx.merge(ONYXKEYS.ONFIDO_TOKEN, ''); | ||
| Onyx.merge(ONYXKEYS.ONFIDO_APPLICANT_ID, ''); | ||
| } | ||
|
|
||
| function updateAddPersonalBankAccountDraft(bankData: Partial<PersonalBankAccountForm>) { | ||
| Onyx.merge(ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT_FORM_DRAFT, bankData); | ||
| } | ||
|
|
||
| /** | ||
| * Helper method to build the Onyx data required during setup of a Verified Business Bank Account | ||
| */ | ||
|
|
@@ -503,6 +530,16 @@ function setReimbursementAccountLoading(isLoading: boolean) { | |
| Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {isLoading}); | ||
| } | ||
|
|
||
| function validatePlaidSelection(values: FormOnyxValues<AccountFormValues>): FormInputErrors<AccountFormValues> { | ||
| const errorFields: FormInputErrors<AccountFormValues> = {}; | ||
|
|
||
| if (!values.selectedPlaidAccountID) { | ||
| errorFields.selectedPlaidAccountID = 'bankAccount.error.youNeedToSelectAnOption'; | ||
| } | ||
|
|
||
| return errorFields; | ||
| } | ||
|
|
||
| export { | ||
| acceptACHContractForBankAccount, | ||
| addBusinessWebsiteForDraft, | ||
|
|
@@ -527,6 +564,10 @@ export { | |
| validateBankAccount, | ||
| verifyIdentityForBankAccount, | ||
| setReimbursementAccountLoading, | ||
| openPersonalBankAccountSetupViewRefactor, | ||
| updateAddPersonalBankAccountDraft, | ||
| clearPersonalBankAccountSetupType, | ||
| validatePlaidSelection, | ||
| }; | ||
|
|
||
| export type {BusinessAddress, PersonalAddress}; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| type GetPlaidDesktopMessage = () => string | undefined; | ||
| import type {TranslationPaths} from '@src/languages/types'; | ||
|
|
||
| type GetPlaidDesktopMessage = () => TranslationPaths | undefined; | ||
|
|
||
| export default GetPlaidDesktopMessage; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
src/pages/EnablePayments/AddBankAccount/AddBankAccount.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| import React, {useCallback, useEffect} from 'react'; | ||
| import {View} from 'react-native'; | ||
| import {withOnyx} from 'react-native-onyx'; | ||
| import type {OnyxEntry} from 'react-native-onyx'; | ||
| import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
| import InteractiveStepSubHeader from '@components/InteractiveStepSubHeader'; | ||
| import ScreenWrapper from '@components/ScreenWrapper'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useSubStep from '@hooks/useSubStep'; | ||
| import type {SubStepProps} from '@hooks/useSubStep/types'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import Navigation from '@navigation/Navigation'; | ||
| import * as BankAccounts from '@userActions/BankAccounts'; | ||
| import * as PaymentMethods from '@userActions/PaymentMethods'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import ROUTES from '@src/ROUTES'; | ||
| import type {PersonalBankAccountForm} from '@src/types/form'; | ||
| import type {PersonalBankAccount, PlaidData} from '@src/types/onyx'; | ||
| import SetupMethod from './SetupMethod'; | ||
| import Confirmation from './substeps/ConfirmationStep'; | ||
| import Plaid from './substeps/PlaidStep'; | ||
|
|
||
| type AddPersonalBankAccountPageWithOnyxProps = { | ||
| /** Contains plaid data */ | ||
| plaidData: OnyxEntry<PlaidData>; | ||
|
|
||
| /** The details about the Personal bank account we are adding saved in Onyx */ | ||
| personalBankAccount: OnyxEntry<PersonalBankAccount>; | ||
|
|
||
| /** The draft values of the bank account being setup */ | ||
| personalBankAccountDraft: OnyxEntry<PersonalBankAccountForm>; | ||
| }; | ||
|
|
||
| const plaidSubsteps: Array<React.ComponentType<SubStepProps>> = [Plaid, Confirmation]; | ||
|
|
||
| function AddBankAccount({personalBankAccount, plaidData, personalBankAccountDraft}: AddPersonalBankAccountPageWithOnyxProps) { | ||
| const {translate} = useLocalize(); | ||
| const styles = useThemeStyles(); | ||
|
|
||
| const submit = useCallback(() => { | ||
| const bankAccounts = plaidData?.bankAccounts ?? []; | ||
| const selectedPlaidBankAccount = bankAccounts.find((bankAccount) => bankAccount.plaidAccountID === personalBankAccountDraft?.plaidAccountID); | ||
|
|
||
| if (selectedPlaidBankAccount) { | ||
| BankAccounts.addPersonalBankAccount(selectedPlaidBankAccount); | ||
| Navigation.navigate(ROUTES.SETTINGS_ENABLE_PAYMENTS); | ||
| } | ||
| }, [personalBankAccountDraft?.plaidAccountID, plaidData?.bankAccounts]); | ||
|
|
||
| const isSetupTypeChosen = personalBankAccountDraft?.setupType === CONST.BANK_ACCOUNT.SETUP_TYPE.PLAID; | ||
|
|
||
| const {componentToRender: SubStep, isEditing, screenIndex, nextScreen, prevScreen, moveTo} = useSubStep({bodyContent: plaidSubsteps, startFrom: 0, onFinished: submit}); | ||
|
|
||
| const exitFlow = (shouldContinue = false) => { | ||
| const exitReportID = personalBankAccount?.exitReportID; | ||
| const onSuccessFallbackRoute = personalBankAccount?.onSuccessFallbackRoute ?? ''; | ||
|
|
||
| if (exitReportID) { | ||
| Navigation.dismissModal(exitReportID); | ||
| return; | ||
| } | ||
| if (shouldContinue && onSuccessFallbackRoute) { | ||
| PaymentMethods.continueSetup(onSuccessFallbackRoute); | ||
| return; | ||
| } | ||
| Navigation.goBack(ROUTES.SETTINGS_WALLET); | ||
| }; | ||
|
|
||
| const handleBackButtonPress = () => { | ||
| if (!isSetupTypeChosen) { | ||
| exitFlow(); | ||
| return; | ||
| } | ||
| if (screenIndex === 0) { | ||
| BankAccounts.clearPersonalBankAccount(); | ||
| return; | ||
| } | ||
|
koko57 marked this conversation as resolved.
Resolved
|
||
| prevScreen(); | ||
| }; | ||
|
|
||
| useEffect(() => BankAccounts.clearPersonalBankAccount, []); | ||
|
|
||
| return ( | ||
| <ScreenWrapper | ||
| testID={AddBankAccount.displayName} | ||
| includeSafeAreaPaddingBottom={false} | ||
| shouldEnablePickerAvoiding={false} | ||
| > | ||
| <HeaderWithBackButton | ||
| shouldShowBackButton | ||
| onBackButtonPress={handleBackButtonPress} | ||
| title={translate('bankAccount.addBankAccount')} | ||
| /> | ||
| {isSetupTypeChosen ? ( | ||
| <> | ||
| <View style={[styles.ph5, styles.mb5, styles.mt3, {height: CONST.BANK_ACCOUNT.STEPS_HEADER_HEIGHT}]}> | ||
| <InteractiveStepSubHeader | ||
| startStepIndex={0} | ||
| stepNames={CONST.WALLET.STEP_NAMES} | ||
| /> | ||
| </View> | ||
| <SubStep | ||
| isEditing={isEditing} | ||
| onNext={nextScreen} | ||
| onMove={moveTo} | ||
| /> | ||
| </> | ||
| ) : ( | ||
| <SetupMethod /> | ||
| )} | ||
| </ScreenWrapper> | ||
| ); | ||
| } | ||
|
|
||
| AddBankAccount.displayName = 'AddBankAccountPage'; | ||
|
|
||
| export default withOnyx<AddPersonalBankAccountPageWithOnyxProps, AddPersonalBankAccountPageWithOnyxProps>({ | ||
| plaidData: { | ||
| key: ONYXKEYS.PLAID_DATA, | ||
| }, | ||
| personalBankAccount: { | ||
| key: ONYXKEYS.PERSONAL_BANK_ACCOUNT, | ||
| }, | ||
| personalBankAccountDraft: { | ||
| key: ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT_FORM_DRAFT, | ||
| }, | ||
| })(AddBankAccount); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.