From 3de73637c36bfe449f24faba833b29f221948e9b Mon Sep 17 00:00:00 2001 From: Maria D'Costa Date: Tue, 13 Sep 2022 18:00:10 +0100 Subject: [PATCH 01/15] Use new verifyIdentityForBankAccount API command --- src/libs/actions/BankAccounts.js | 11 +++++++++++ src/pages/ReimbursementAccount/RequestorStep.js | 13 ++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index d2242b028962..65187ab60920 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -159,9 +159,20 @@ function deletePaymentBankAccount(bankAccountID) { }); } +/** + * Verify the user's identity via Onfido + * @param {Object} onfidoData + */ +function verifyIdentityForBankAccount(onfidoData) { + API.write('VerifyIdentityForBankAccount', { + onfidoData + }, getVBBADataForOnyx()); +} + export { addPersonalBankAccount, deletePaymentBankAccount, clearPersonalBankAccount, clearPlaid, + verifyIdentityForBankAccount, }; diff --git a/src/pages/ReimbursementAccount/RequestorStep.js b/src/pages/ReimbursementAccount/RequestorStep.js index 0f947beef32a..83afa650cf47 100644 --- a/src/pages/ReimbursementAccount/RequestorStep.js +++ b/src/pages/ReimbursementAccount/RequestorStep.js @@ -36,6 +36,7 @@ class RequestorStep extends React.Component { super(props); this.submit = this.submit.bind(this); + this.submitOnfidoVerification = this.submitOnfidoVerification.bind(this); this.clearErrorsAndSetValues = this.clearErrorsAndSetValues.bind(this); this.state = { @@ -142,6 +143,16 @@ class RequestorStep extends React.Component { BankAccounts.setupWithdrawalAccount(payload); } + submitOnfidoVerification() { + if (!this.validate()) { + return; + } + + BankAccounts.verifyIdentityForBankAccount({ + ...this.state, + }); + } + render() { return ( <> @@ -171,7 +182,7 @@ class RequestorStep extends React.Component { this.setState({ onfidoData, isOnfidoSetupComplete: true, - }, this.submit); + }, this.submitOnfidoVerification); }} /> From 462f728b5d15f5774cca095301d6ef7569237ad9 Mon Sep 17 00:00:00 2001 From: Maria D'Costa Date: Wed, 14 Sep 2022 11:09:07 +0100 Subject: [PATCH 02/15] Add bankAccountID request parameter --- src/libs/actions/BankAccounts.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index 65187ab60920..370df8330700 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -4,6 +4,8 @@ import * as API from '../API'; import ONYXKEYS from '../../ONYXKEYS'; import * as Localize from '../Localize'; import DateUtils from '../DateUtils'; +import lodashGet from 'lodash/get'; +import * as store from './ReimbursementAccount/store'; export { setupWithdrawalAccount, @@ -161,11 +163,13 @@ function deletePaymentBankAccount(bankAccountID) { /** * Verify the user's identity via Onfido - * @param {Object} onfidoData + * @param {Object} onfidoData */ function verifyIdentityForBankAccount(onfidoData) { + const bankAccountID = lodashGet(store.getReimbursementAccountInSetup(), 'bankAccountID'); API.write('VerifyIdentityForBankAccount', { - onfidoData + bankAccountID, + onfidoData: JSON.stringify(onfidoData), }, getVBBADataForOnyx()); } From 69f709966d3436568654495bc3c515ff16ee1f33 Mon Sep 17 00:00:00 2001 From: Maria D'Costa Date: Wed, 14 Sep 2022 12:20:16 +0100 Subject: [PATCH 03/15] Remove obsolete comment --- src/libs/actions/BankAccounts.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index 370df8330700..f47340154bc3 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -49,8 +49,6 @@ function clearPlaid() { * * @returns {Object} */ -// We'll remove the below once this function is used by the VBBA commands that are yet to be implemented -/* eslint-disable no-unused-vars */ function getVBBADataForOnyx() { return { optimisticData: [ From 0203ef94520580add946361319927587d9ffbd90 Mon Sep 17 00:00:00 2001 From: Maria D'Costa Date: Wed, 14 Sep 2022 12:21:01 +0100 Subject: [PATCH 04/15] Fix import --- src/libs/actions/BankAccounts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index f47340154bc3..19b9b91f6993 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -1,10 +1,10 @@ import Onyx from 'react-native-onyx'; +import lodashGet from 'lodash/get'; import CONST from '../../CONST'; import * as API from '../API'; import ONYXKEYS from '../../ONYXKEYS'; import * as Localize from '../Localize'; import DateUtils from '../DateUtils'; -import lodashGet from 'lodash/get'; import * as store from './ReimbursementAccount/store'; export { From f6cd14952a5b0f7ff3cea5a27c228d10c07c200f Mon Sep 17 00:00:00 2001 From: Maria D'Costa Date: Mon, 26 Sep 2022 12:56:56 +0400 Subject: [PATCH 05/15] Fix trailing space --- src/libs/actions/BankAccounts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index d19f69b8bdc1..5b3d75ca8de7 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -195,7 +195,7 @@ function validateBankAccount(bankAccountID, validateCode) { /** * Verify the user's identity via Onfido - * + * * @param {Object} onfidoData */ function verifyIdentityForBankAccount(onfidoData) { From da5d96b7738af8e4b2ae9f1c579af6f238ac46c6 Mon Sep 17 00:00:00 2001 From: Maria D'Costa Date: Fri, 30 Sep 2022 14:23:46 +0400 Subject: [PATCH 06/15] Fix params for verifyIdentityForBankAccount --- src/libs/actions/BankAccounts.js | 3 +-- src/pages/ReimbursementAccount/RequestorStep.js | 9 ++++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index c083d0fe84ea..8b792afef71c 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -297,8 +297,7 @@ function connectBankAccountManually(bankAccountID, accountNumber, routingNumber, * * @param {Object} onfidoData */ -function verifyIdentityForBankAccount(onfidoData) { - const bankAccountID = lodashGet(store.getReimbursementAccountInSetup(), 'bankAccountID'); +function verifyIdentityForBankAccount(bankAccountID, onfidoData) { API.write('VerifyIdentityForBankAccount', { bankAccountID, onfidoData: JSON.stringify(onfidoData), diff --git a/src/pages/ReimbursementAccount/RequestorStep.js b/src/pages/ReimbursementAccount/RequestorStep.js index 1e4354b2ee57..2a17f10fbbaa 100644 --- a/src/pages/ReimbursementAccount/RequestorStep.js +++ b/src/pages/ReimbursementAccount/RequestorStep.js @@ -153,9 +153,12 @@ class RequestorStep extends React.Component { return; } - BankAccounts.verifyIdentityForBankAccount({ - ...this.state, - }); + BankAccounts.verifyIdentityForBankAccount( + ReimbursementAccountUtils.getDefaultStateForField(this.props, 'bankAccountID', 0), + { + ...this.state, + }, + ); } render() { From b5173de10053bf3cd6e403b688e04e61455ef537 Mon Sep 17 00:00:00 2001 From: Maria D'Costa Date: Fri, 30 Sep 2022 14:25:21 +0400 Subject: [PATCH 07/15] Improve function name --- src/libs/actions/BankAccounts.js | 4 ++-- src/pages/ReimbursementAccount/RequestorStep.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index 8b792afef71c..1a4e1efb61a0 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -45,7 +45,7 @@ function updatePlaidData(plaidData) { Onyx.merge(ONYXKEYS.PLAID_DATA, plaidData); } -function clearOnfido() { +function clearOnfidoToken() { Onyx.merge(ONYXKEYS.ONFIDO_TOKEN, ''); } @@ -310,7 +310,7 @@ export { deletePaymentBankAccount, clearPersonalBankAccount, clearPlaid, - clearOnfido, + clearOnfidoToken, updatePersonalInformationForBankAccount, validateBankAccount, verifyIdentityForBankAccount, diff --git a/src/pages/ReimbursementAccount/RequestorStep.js b/src/pages/ReimbursementAccount/RequestorStep.js index 2a17f10fbbaa..526d77024c27 100644 --- a/src/pages/ReimbursementAccount/RequestorStep.js +++ b/src/pages/ReimbursementAccount/RequestorStep.js @@ -175,7 +175,7 @@ class RequestorStep extends React.Component { shouldShowBackButton onBackButtonPress={() => { if (shouldShowOnfido) { - BankAccounts.clearOnfido(); + BankAccounts.clearOnfidoToken(); } else { BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.COMPANY); } From f0216b2887f019b9a88b52ddd9b955e72eec6675 Mon Sep 17 00:00:00 2001 From: Maria D'Costa Date: Fri, 30 Sep 2022 14:30:21 +0400 Subject: [PATCH 08/15] Fix linter errors --- src/libs/actions/BankAccounts.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index 1a4e1efb61a0..c38912e62223 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -1,5 +1,4 @@ import Onyx from 'react-native-onyx'; -import lodashGet from 'lodash/get'; import CONST from '../../CONST'; import * as API from '../API'; import ONYXKEYS from '../../ONYXKEYS'; @@ -294,7 +293,8 @@ function connectBankAccountManually(bankAccountID, accountNumber, routingNumber, /** * Verify the user's identity via Onfido - * + * + * @param {Number} bankAccountID * @param {Object} onfidoData */ function verifyIdentityForBankAccount(bankAccountID, onfidoData) { From af6d93bdf5daf09da924a6b790725f8463f0db78 Mon Sep 17 00:00:00 2001 From: Maria D'Costa Date: Fri, 30 Sep 2022 14:38:44 +0400 Subject: [PATCH 09/15] Create new component for requestor onfido step --- src/libs/actions/BankAccounts.js | 2 +- .../RequestorOnfidoStep.js | 109 ++++++++++++++++++ .../ReimbursementAccount/RequestorStep.js | 26 +---- 3 files changed, 113 insertions(+), 24 deletions(-) create mode 100644 src/pages/ReimbursementAccount/RequestorOnfidoStep.js diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index c38912e62223..a9b6083c0adb 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -293,7 +293,7 @@ function connectBankAccountManually(bankAccountID, accountNumber, routingNumber, /** * Verify the user's identity via Onfido - * + * * @param {Number} bankAccountID * @param {Object} onfidoData */ diff --git a/src/pages/ReimbursementAccount/RequestorOnfidoStep.js b/src/pages/ReimbursementAccount/RequestorOnfidoStep.js new file mode 100644 index 000000000000..e2b028d17c90 --- /dev/null +++ b/src/pages/ReimbursementAccount/RequestorOnfidoStep.js @@ -0,0 +1,109 @@ +import React from 'react'; +import lodashGet from 'lodash/get'; +import {ScrollView} from 'react-native'; +import {withOnyx} from 'react-native-onyx'; +import PropTypes from 'prop-types'; +import styles from '../../styles/styles'; +import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize'; +import HeaderWithCloseButton from '../../components/HeaderWithCloseButton'; +import CONST from '../../CONST'; +import Navigation from '../../libs/Navigation/Navigation'; +import * as BankAccounts from '../../libs/actions/BankAccounts'; +import Onfido from '../../components/Onfido'; +import compose from '../../libs/compose'; +import ONYXKEYS from '../../ONYXKEYS'; +import * as ReimbursementAccountUtils from '../../libs/ReimbursementAccountUtils'; +import Growl from '../../libs/Growl'; +import reimbursementAccountPropTypes from './reimbursementAccountPropTypes'; + +const propTypes = { + /** Bank account currently in setup */ + reimbursementAccount: reimbursementAccountPropTypes.isRequired, + onfidoToken: PropTypes.string, + ...withLocalizePropTypes, +}; + +const defaultProps = { + onfidoToken: '', +}; + +class RequestorOnfidoStep extends React.Component { + constructor(props) { + super(props); + this.submit = this.submit.bind(this); + this.state = { + onfidoData: lodashGet(props, ['reimbursementAccount', 'achData', 'onfidoData'], ''), + }; + } + + submit() { + BankAccounts.verifyIdentityForBankAccount( + ReimbursementAccountUtils.getDefaultStateForField(this.props, 'bankAccountID', 0), + { + ...this.state, + }, + ); + } + + render() { + const achData = this.props.reimbursementAccount.achData; + const shouldShowOnfido = achData.useOnfido && this.props.onfidoToken && !this.state.isOnfidoSetupComplete; + + return ( + <> + { + if (shouldShowOnfido) { + BankAccounts.clearOnfidoToken(); + } else { + BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.COMPANY); + } + }} + onCloseButtonPress={Navigation.dismissModal} + /> + { + + { + // We're taking the user back to the company step. They will need to come back to the requestor step to make the Onfido flow appear again. + BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.COMPANY); + }} + onError={() => { + // In case of any unexpected error we log it to the server, show a growl, and return the user back to the company step so they can try again. + Growl.error(this.props.translate('onfidoStep.genericError'), 10000); + BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.COMPANY); + }} + onSuccess={(onfidoData) => { + this.setState({ + onfidoData, + isOnfidoSetupComplete: true, + }, this.submitOnfidoVerification); + }} + /> + + } + + ); + } +} + +RequestorOnfidoStep.propTypes = propTypes; +RequestorOnfidoStep.defaultProps = defaultProps; + +export default compose( + withLocalize, + withOnyx({ + onfidoToken: { + key: ONYXKEYS.ONFIDO_TOKEN, + }, + reimbursementAccountDraft: { + key: ONYXKEYS.REIMBURSEMENT_ACCOUNT_DRAFT, + }, + }), +)(RequestorOnfidoStep); diff --git a/src/pages/ReimbursementAccount/RequestorStep.js b/src/pages/ReimbursementAccount/RequestorStep.js index 526d77024c27..8f587c70a240 100644 --- a/src/pages/ReimbursementAccount/RequestorStep.js +++ b/src/pages/ReimbursementAccount/RequestorStep.js @@ -1,6 +1,6 @@ import React from 'react'; import lodashGet from 'lodash/get'; -import {ScrollView, View} from 'react-native'; +import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; import moment from 'moment'; @@ -16,14 +16,13 @@ import Text from '../../components/Text'; import * as BankAccounts from '../../libs/actions/BankAccounts'; import IdentityForm from './IdentityForm'; import * as ValidationUtils from '../../libs/ValidationUtils'; -import Onfido from '../../components/Onfido'; import compose from '../../libs/compose'; import ONYXKEYS from '../../ONYXKEYS'; import * as ReimbursementAccountUtils from '../../libs/ReimbursementAccountUtils'; -import Growl from '../../libs/Growl'; import reimbursementAccountPropTypes from './reimbursementAccountPropTypes'; import ReimbursementAccountForm from './ReimbursementAccountForm'; import * as Link from '../../libs/actions/Link'; +import RequestorOnfidoStep from './RequestorOnfidoStep'; const propTypes = { /** Bank account currently in setup */ @@ -183,26 +182,7 @@ class RequestorStep extends React.Component { onCloseButtonPress={Navigation.dismissModal} /> {shouldShowOnfido ? ( - - { - // We're taking the user back to the company step. They will need to come back to the requestor step to make the Onfido flow appear again. - BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.COMPANY); - }} - onError={() => { - // In case of any unexpected error we log it to the server, show a growl, and return the user back to the company step so they can try again. - Growl.error(this.props.translate('onfidoStep.genericError'), 10000); - BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.COMPANY); - }} - onSuccess={(onfidoData) => { - this.setState({ - onfidoData, - isOnfidoSetupComplete: true, - }, this.submitOnfidoVerification); - }} - /> - + ) : ( Date: Fri, 30 Sep 2022 14:42:09 +0400 Subject: [PATCH 10/15] Only pass onfidoData --- src/libs/actions/BankAccounts.js | 2 +- src/pages/ReimbursementAccount/RequestorStep.js | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/BankAccounts.js b/src/libs/actions/BankAccounts.js index c38912e62223..a9b6083c0adb 100644 --- a/src/libs/actions/BankAccounts.js +++ b/src/libs/actions/BankAccounts.js @@ -293,7 +293,7 @@ function connectBankAccountManually(bankAccountID, accountNumber, routingNumber, /** * Verify the user's identity via Onfido - * + * * @param {Number} bankAccountID * @param {Object} onfidoData */ diff --git a/src/pages/ReimbursementAccount/RequestorStep.js b/src/pages/ReimbursementAccount/RequestorStep.js index 526d77024c27..18c5f205c817 100644 --- a/src/pages/ReimbursementAccount/RequestorStep.js +++ b/src/pages/ReimbursementAccount/RequestorStep.js @@ -155,9 +155,7 @@ class RequestorStep extends React.Component { BankAccounts.verifyIdentityForBankAccount( ReimbursementAccountUtils.getDefaultStateForField(this.props, 'bankAccountID', 0), - { - ...this.state, - }, + this.state.onfidoData, ); } From e56761a56d69b30bff305c85145597b37d999888 Mon Sep 17 00:00:00 2001 From: Maria D'Costa Date: Fri, 30 Sep 2022 14:46:12 +0400 Subject: [PATCH 11/15] Fix Onfido component --- .../RequestorOnfidoStep.js | 67 ++++++------------- 1 file changed, 21 insertions(+), 46 deletions(-) diff --git a/src/pages/ReimbursementAccount/RequestorOnfidoStep.js b/src/pages/ReimbursementAccount/RequestorOnfidoStep.js index e2b028d17c90..c6cb00cc7bc4 100644 --- a/src/pages/ReimbursementAccount/RequestorOnfidoStep.js +++ b/src/pages/ReimbursementAccount/RequestorOnfidoStep.js @@ -5,9 +5,6 @@ import {withOnyx} from 'react-native-onyx'; import PropTypes from 'prop-types'; import styles from '../../styles/styles'; import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize'; -import HeaderWithCloseButton from '../../components/HeaderWithCloseButton'; -import CONST from '../../CONST'; -import Navigation from '../../libs/Navigation/Navigation'; import * as BankAccounts from '../../libs/actions/BankAccounts'; import Onfido from '../../components/Onfido'; import compose from '../../libs/compose'; @@ -39,56 +36,31 @@ class RequestorOnfidoStep extends React.Component { submit() { BankAccounts.verifyIdentityForBankAccount( ReimbursementAccountUtils.getDefaultStateForField(this.props, 'bankAccountID', 0), - { - ...this.state, - }, + this.state.onfidoData, ); } render() { - const achData = this.props.reimbursementAccount.achData; - const shouldShowOnfido = achData.useOnfido && this.props.onfidoToken && !this.state.isOnfidoSetupComplete; - return ( - <> - { - if (shouldShowOnfido) { - BankAccounts.clearOnfidoToken(); - } else { - BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.COMPANY); - } + + { + // We're taking the user back to the company step. They will need to come back to the requestor step to make the Onfido flow appear again. + BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.COMPANY); + }} + onError={() => { + // In case of any unexpected error we log it to the server, show a growl, and return the user back to the company step so they can try again. + Growl.error(this.props.translate('onfidoStep.genericError'), 10000); + BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.COMPANY); + }} + onSuccess={(onfidoData) => { + this.setState({ + onfidoData, + }, this.submit); }} - onCloseButtonPress={Navigation.dismissModal} /> - { - - { - // We're taking the user back to the company step. They will need to come back to the requestor step to make the Onfido flow appear again. - BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.COMPANY); - }} - onError={() => { - // In case of any unexpected error we log it to the server, show a growl, and return the user back to the company step so they can try again. - Growl.error(this.props.translate('onfidoStep.genericError'), 10000); - BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.COMPANY); - }} - onSuccess={(onfidoData) => { - this.setState({ - onfidoData, - isOnfidoSetupComplete: true, - }, this.submitOnfidoVerification); - }} - /> - - } - + ); } } @@ -99,6 +71,9 @@ RequestorOnfidoStep.defaultProps = defaultProps; export default compose( withLocalize, withOnyx({ + reimbursementAccount: { + key: ONYXKEYS.REIMBURSEMENT_ACCOUNT, + }, onfidoToken: { key: ONYXKEYS.ONFIDO_TOKEN, }, From a9bfb054092072301e555da445f793b810a9492f Mon Sep 17 00:00:00 2001 From: Maria D'Costa Date: Fri, 30 Sep 2022 16:04:00 +0400 Subject: [PATCH 12/15] Fix Onfido flow and linter errors --- .../ReimbursementAccount/RequestorOnfidoStep.js | 3 +++ src/pages/ReimbursementAccount/RequestorStep.js | 13 ++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/pages/ReimbursementAccount/RequestorOnfidoStep.js b/src/pages/ReimbursementAccount/RequestorOnfidoStep.js index c6cb00cc7bc4..50e98ffa94af 100644 --- a/src/pages/ReimbursementAccount/RequestorOnfidoStep.js +++ b/src/pages/ReimbursementAccount/RequestorOnfidoStep.js @@ -12,9 +12,11 @@ import ONYXKEYS from '../../ONYXKEYS'; import * as ReimbursementAccountUtils from '../../libs/ReimbursementAccountUtils'; import Growl from '../../libs/Growl'; import reimbursementAccountPropTypes from './reimbursementAccountPropTypes'; +import CONST from '../../CONST'; const propTypes = { /** Bank account currently in setup */ + /* eslint-disable-next-line react/no-unused-prop-types */ reimbursementAccount: reimbursementAccountPropTypes.isRequired, onfidoToken: PropTypes.string, ...withLocalizePropTypes, @@ -38,6 +40,7 @@ class RequestorOnfidoStep extends React.Component { ReimbursementAccountUtils.getDefaultStateForField(this.props, 'bankAccountID', 0), this.state.onfidoData, ); + this.props.onComplete(); } render() { diff --git a/src/pages/ReimbursementAccount/RequestorStep.js b/src/pages/ReimbursementAccount/RequestorStep.js index 6a7c25c3884c..28f83d10dcd4 100644 --- a/src/pages/ReimbursementAccount/RequestorStep.js +++ b/src/pages/ReimbursementAccount/RequestorStep.js @@ -41,6 +41,7 @@ class RequestorStep extends React.Component { this.submit = this.submit.bind(this); this.clearErrorsAndSetValues = this.clearErrorsAndSetValues.bind(this); + this.setOnfidoAsComplete = this.setOnfidoAsComplete.bind(this); this.state = { firstName: ReimbursementAccountUtils.getDefaultStateForField(props, 'firstName'), @@ -52,7 +53,6 @@ class RequestorStep extends React.Component { dob: ReimbursementAccountUtils.getDefaultStateForField(props, 'dob'), ssnLast4: ReimbursementAccountUtils.getDefaultStateForField(props, 'ssnLast4'), isControllingOfficer: ReimbursementAccountUtils.getDefaultStateForField(props, 'isControllingOfficer', false), - onfidoData: lodashGet(props, ['reimbursementAccount', 'achData', 'onfidoData'], ''), isOnfidoSetupComplete: lodashGet(props, ['achData', 'isOnfidoSetupComplete'], false), }; @@ -146,6 +146,10 @@ class RequestorStep extends React.Component { BankAccounts.updatePersonalInformationForBankAccount(payload); } + setOnfidoAsComplete() { + this.setState({isOnfidoSetupComplete: true}); + } + render() { const achData = this.props.reimbursementAccount.achData; const shouldShowOnfido = achData.useOnfido && this.props.onfidoToken && !this.state.isOnfidoSetupComplete; @@ -168,7 +172,9 @@ class RequestorStep extends React.Component { onCloseButtonPress={Navigation.dismissModal} /> {shouldShowOnfido ? ( - + ) : ( Date: Fri, 30 Sep 2022 16:05:34 +0400 Subject: [PATCH 13/15] Fix function order and add DocBlock --- src/pages/ReimbursementAccount/RequestorStep.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/pages/ReimbursementAccount/RequestorStep.js b/src/pages/ReimbursementAccount/RequestorStep.js index 28f83d10dcd4..64202ed9d9de 100644 --- a/src/pages/ReimbursementAccount/RequestorStep.js +++ b/src/pages/ReimbursementAccount/RequestorStep.js @@ -73,6 +73,13 @@ class RequestorStep extends React.Component { this.getErrors = () => ReimbursementAccountUtils.getErrors(this.props); } + /** + * Update state to indicate that the user has completed the Onfido verification process + */ + setOnfidoAsComplete() { + this.setState({isOnfidoSetupComplete: true}); + } + /** * Clear the errors associated to keys in values if found and store the new values in the state. * @@ -146,10 +153,6 @@ class RequestorStep extends React.Component { BankAccounts.updatePersonalInformationForBankAccount(payload); } - setOnfidoAsComplete() { - this.setState({isOnfidoSetupComplete: true}); - } - render() { const achData = this.props.reimbursementAccount.achData; const shouldShowOnfido = achData.useOnfido && this.props.onfidoToken && !this.state.isOnfidoSetupComplete; From 10191098881d056da42be0e8ad378ad28985ba9a Mon Sep 17 00:00:00 2001 From: Maria D'Costa Date: Tue, 4 Oct 2022 15:22:55 +0400 Subject: [PATCH 14/15] Update props --- src/pages/ReimbursementAccount/RequestorOnfidoStep.js | 1 + src/pages/ReimbursementAccount/RequestorStep.js | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/pages/ReimbursementAccount/RequestorOnfidoStep.js b/src/pages/ReimbursementAccount/RequestorOnfidoStep.js index 50e98ffa94af..d80b90c7020f 100644 --- a/src/pages/ReimbursementAccount/RequestorOnfidoStep.js +++ b/src/pages/ReimbursementAccount/RequestorOnfidoStep.js @@ -19,6 +19,7 @@ const propTypes = { /* eslint-disable-next-line react/no-unused-prop-types */ reimbursementAccount: reimbursementAccountPropTypes.isRequired, onfidoToken: PropTypes.string, + onComplete: PropTypes.func.isRequired, ...withLocalizePropTypes, }; diff --git a/src/pages/ReimbursementAccount/RequestorStep.js b/src/pages/ReimbursementAccount/RequestorStep.js index 64202ed9d9de..bba0dba6b06d 100644 --- a/src/pages/ReimbursementAccount/RequestorStep.js +++ b/src/pages/ReimbursementAccount/RequestorStep.js @@ -279,5 +279,8 @@ export default compose( onfidoToken: { key: ONYXKEYS.ONFIDO_TOKEN, }, + reimbursementAccountDraft: { + key: ONYXKEYS.REIMBURSEMENT_ACCOUNT_DRAFT, + }, }), )(RequestorStep); From 42d50b390b290d6464138bdab51f97175dbb8952 Mon Sep 17 00:00:00 2001 From: Maria D'Costa Date: Tue, 4 Oct 2022 15:52:13 +0400 Subject: [PATCH 15/15] Remove redundant state --- .../ReimbursementAccount/RequestorOnfidoStep.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/pages/ReimbursementAccount/RequestorOnfidoStep.js b/src/pages/ReimbursementAccount/RequestorOnfidoStep.js index d80b90c7020f..82b17d641d35 100644 --- a/src/pages/ReimbursementAccount/RequestorOnfidoStep.js +++ b/src/pages/ReimbursementAccount/RequestorOnfidoStep.js @@ -1,5 +1,4 @@ import React from 'react'; -import lodashGet from 'lodash/get'; import {ScrollView} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import PropTypes from 'prop-types'; @@ -31,15 +30,12 @@ class RequestorOnfidoStep extends React.Component { constructor(props) { super(props); this.submit = this.submit.bind(this); - this.state = { - onfidoData: lodashGet(props, ['reimbursementAccount', 'achData', 'onfidoData'], ''), - }; } - submit() { + submit(onfidoData) { BankAccounts.verifyIdentityForBankAccount( ReimbursementAccountUtils.getDefaultStateForField(this.props, 'bankAccountID', 0), - this.state.onfidoData, + onfidoData, ); this.props.onComplete(); } @@ -59,9 +55,7 @@ class RequestorOnfidoStep extends React.Component { BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.COMPANY); }} onSuccess={(onfidoData) => { - this.setState({ - onfidoData, - }, this.submit); + this.submit(onfidoData); }} />