-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
RequestorOnfidoStep.js
103 lines (90 loc) · 3.85 KB
/
RequestorOnfidoStep.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import React from 'react';
import {withOnyx} from 'react-native-onyx';
import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOfflineBlockingView';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import Onfido from '@components/Onfido';
import ScreenWrapper from '@components/ScreenWrapper';
import ScrollView from '@components/ScrollView';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import Growl from '@libs/Growl';
import * as BankAccounts from '@userActions/BankAccounts';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import * as ReimbursementAccountProps from './reimbursementAccountPropTypes';
const propTypes = {
/** The bank account currently in setup */
reimbursementAccount: ReimbursementAccountProps.reimbursementAccountPropTypes.isRequired,
/** Goes to the previous step */
onBackButtonPress: PropTypes.func.isRequired,
/** The token required to initialize the Onfido SDK */
onfidoToken: PropTypes.string,
/** The application ID for our Onfido instance */
onfidoApplicantID: PropTypes.string,
};
const defaultProps = {
onfidoToken: null,
onfidoApplicantID: null,
};
const HEADER_STEP_COUNTER = {step: 3, total: 5};
const ONFIDO_ERROR_DISPLAY_DURATION = 10000;
function RequestorOnfidoStep({onBackButtonPress, reimbursementAccount, onfidoToken, onfidoApplicantID}) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const submitOnfidoData = (onfidoData) => {
BankAccounts.verifyIdentityForBankAccount(lodashGet(reimbursementAccount, 'achData.bankAccountID', 0), {
...onfidoData,
applicantID: onfidoApplicantID,
});
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'), ONFIDO_ERROR_DISPLAY_DURATION);
BankAccounts.clearOnfidoToken();
BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.REQUESTOR);
};
const handleOnfidoUserExit = () => {
BankAccounts.clearOnfidoToken();
BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.REQUESTOR);
};
return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
shouldShowOfflineIndicator={false}
testID={RequestorOnfidoStep.displayName}
>
<HeaderWithBackButton
title={translate('requestorStep.headerTitle')}
stepCounter={HEADER_STEP_COUNTER}
shouldShowGetAssistanceButton
guidesCallTaskID={CONST.GUIDES_CALL_TASK_IDS.WORKSPACE_BANK_ACCOUNT}
onBackButtonPress={onBackButtonPress}
/>
<FullPageOfflineBlockingView>
<ScrollView contentContainerStyle={styles.flex1}>
<Onfido
sdkToken={onfidoToken}
onUserExit={handleOnfidoUserExit}
onError={handleOnfidoError}
onSuccess={submitOnfidoData}
/>
</ScrollView>
</FullPageOfflineBlockingView>
</ScreenWrapper>
);
}
RequestorOnfidoStep.displayName = 'RequestorOnfidoStep';
RequestorOnfidoStep.propTypes = propTypes;
RequestorOnfidoStep.defaultProps = defaultProps;
RequestorOnfidoStep.displayName = 'RequestorOnfidoStep';
export default withOnyx({
onfidoToken: {
key: ONYXKEYS.ONFIDO_TOKEN,
},
onfidoApplicantID: {
key: ONYXKEYS.ONFIDO_APPLICANT_ID,
},
})(RequestorOnfidoStep);