From 95f1913012da12c27294496cf08639c49f1841b6 Mon Sep 17 00:00:00 2001 From: bartektomczyk Date: Thu, 14 Sep 2023 11:43:58 +0200 Subject: [PATCH 1/3] refactor: transformed class componentne to the functional --- .../RequestorOnfidoStep.js | 103 ++++++++---------- 1 file changed, 48 insertions(+), 55 deletions(-) diff --git a/src/pages/ReimbursementAccount/RequestorOnfidoStep.js b/src/pages/ReimbursementAccount/RequestorOnfidoStep.js index 72e3850aabd0..6d6da185964c 100644 --- a/src/pages/ReimbursementAccount/RequestorOnfidoStep.js +++ b/src/pages/ReimbursementAccount/RequestorOnfidoStep.js @@ -4,10 +4,8 @@ import {withOnyx} from 'react-native-onyx'; import PropTypes from 'prop-types'; import lodashGet from 'lodash/get'; import styles from '../../styles/styles'; -import withLocalize from '../../components/withLocalize'; import * as BankAccounts from '../../libs/actions/BankAccounts'; import Onfido from '../../components/Onfido'; -import compose from '../../libs/compose'; import ONYXKEYS from '../../ONYXKEYS'; import Growl from '../../libs/Growl'; import CONST from '../../CONST'; @@ -15,6 +13,7 @@ import FullPageOfflineBlockingView from '../../components/BlockingViews/FullPage import StepPropTypes from './StepPropTypes'; import HeaderWithBackButton from '../../components/HeaderWithBackButton'; import ScreenWrapper from '../../components/ScreenWrapper'; +import useLocalize from '../../hooks/useLocalize'; const propTypes = { ...StepPropTypes, @@ -27,65 +26,59 @@ const defaultProps = { onfidoToken: null, }; -class RequestorOnfidoStep extends React.Component { - constructor(props) { - super(props); - this.submit = this.submit.bind(this); - } +const stepCounter = {step: 3, total: 5}; - submit(onfidoData) { - BankAccounts.verifyIdentityForBankAccount(lodashGet(this.props.reimbursementAccount, 'achData.bankAccountID') || 0, onfidoData); +function RequestorOnfidoStep({onBackButtonPress, reimbursementAccount, onfidoToken}) { + const {translate} = useLocalize(); + const submitOnfidoData = (onfidoData) => { + BankAccounts.verifyIdentityForBankAccount(lodashGet(reimbursementAccount, 'achData.bankAccountID') || 0, onfidoData); BankAccounts.updateReimbursementAccountDraft({isOnfidoSetupComplete: true}); - } + }; - render() { - return ( - - - - - { - BankAccounts.clearOnfidoToken(); - BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.REQUESTOR); - }} - onError={() => { - // In case of any unexpected error we log it to the server, show a growl, and return the user back to the requestor step so they can try again. - Growl.error(this.props.translate('onfidoStep.genericError'), 10000); - BankAccounts.clearOnfidoToken(); - BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.REQUESTOR); - }} - onSuccess={(onfidoData) => { - this.submit(onfidoData); - }} - /> - - - - ); - } + const handleOnfidoError = () => { + // In case of any unexpected error we log it to the server, show a growl, and return the user back to the requestor step so they can try again. + Growl.error(translate('onfidoStep.genericError'), 10000); + BankAccounts.clearOnfidoToken(); + BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.REQUESTOR); + }; + + const handleOnfidoUserExit = () => { + BankAccounts.clearOnfidoToken(); + BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.REQUESTOR); + }; + + return ( + + + + + + + + + ); } RequestorOnfidoStep.propTypes = propTypes; RequestorOnfidoStep.defaultProps = defaultProps; -export default compose( - withLocalize, - withOnyx({ - onfidoToken: { - key: ONYXKEYS.ONFIDO_TOKEN, - }, - }), -)(RequestorOnfidoStep); +export default withOnyx({ + onfidoToken: { + key: ONYXKEYS.ONFIDO_TOKEN, + }, +})(RequestorOnfidoStep); From 1682d47517bee0d556e347abf1a27f817430d513 Mon Sep 17 00:00:00 2001 From: bartektomczyk Date: Thu, 14 Sep 2023 17:53:16 +0200 Subject: [PATCH 2/3] refactor: used UPPER_SNAKE_CASE for local vars, add default value for verifyIdentityForBankAccount --- src/pages/ReimbursementAccount/RequestorOnfidoStep.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pages/ReimbursementAccount/RequestorOnfidoStep.js b/src/pages/ReimbursementAccount/RequestorOnfidoStep.js index 6d6da185964c..9fa9425ec751 100644 --- a/src/pages/ReimbursementAccount/RequestorOnfidoStep.js +++ b/src/pages/ReimbursementAccount/RequestorOnfidoStep.js @@ -26,19 +26,20 @@ const defaultProps = { onfidoToken: null, }; -const stepCounter = {step: 3, total: 5}; +const HEADER_STEP_COUNTER = {step: 3, total: 5}; +const ONFIDO_ERROR_DISPLAY_DURATION = 10000; function RequestorOnfidoStep({onBackButtonPress, reimbursementAccount, onfidoToken}) { const {translate} = useLocalize(); const submitOnfidoData = (onfidoData) => { - BankAccounts.verifyIdentityForBankAccount(lodashGet(reimbursementAccount, 'achData.bankAccountID') || 0, onfidoData); + BankAccounts.verifyIdentityForBankAccount(lodashGet(reimbursementAccount, 'achData.bankAccountID', 0), onfidoData); BankAccounts.updateReimbursementAccountDraft({isOnfidoSetupComplete: true}); }; const handleOnfidoError = () => { // In case of any unexpected error we log it to the server, show a growl, and return the user back to the requestor step so they can try again. - Growl.error(translate('onfidoStep.genericError'), 10000); + Growl.error(translate('onfidoStep.genericError'), ONFIDO_ERROR_DISPLAY_DURATION); BankAccounts.clearOnfidoToken(); BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.REQUESTOR); }; @@ -55,7 +56,7 @@ function RequestorOnfidoStep({onBackButtonPress, reimbursementAccount, onfidoTok testID={RequestorOnfidoStep.displayName}> Date: Thu, 12 Oct 2023 12:21:48 -0400 Subject: [PATCH 3/3] prettier --- src/pages/ReimbursementAccount/RequestorOnfidoStep.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/ReimbursementAccount/RequestorOnfidoStep.js b/src/pages/ReimbursementAccount/RequestorOnfidoStep.js index 9fa9425ec751..3405ad2d80f8 100644 --- a/src/pages/ReimbursementAccount/RequestorOnfidoStep.js +++ b/src/pages/ReimbursementAccount/RequestorOnfidoStep.js @@ -53,7 +53,8 @@ function RequestorOnfidoStep({onBackButtonPress, reimbursementAccount, onfidoTok + testID={RequestorOnfidoStep.displayName} + >