-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
OnfidoPrivacy.tsx
102 lines (92 loc) · 4.26 KB
/
OnfidoPrivacy.tsx
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
import React, {useRef} from 'react';
import {View} from 'react-native';
// eslint-disable-next-line no-restricted-imports
import type {ScrollView} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import FixedFooter from '@components/FixedFooter';
import FormAlertWithSubmitButton from '@components/FormAlertWithSubmitButton';
import FormScrollView from '@components/FormScrollView';
import FullscreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import Text from '@components/Text';
import TextLink from '@components/TextLink';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ErrorUtils from '@libs/ErrorUtils';
import * as BankAccounts from '@userActions/BankAccounts';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {WalletOnfido} from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
const DEFAULT_WALLET_ONFIDO_DATA = {
applicantID: '',
sdkToken: '',
loading: false,
errors: {},
fixableErrors: [],
hasAcceptedPrivacyPolicy: false,
};
type OnfidoPrivacyOnyxProps = {
/** Stores various information used to build the UI and call any APIs */
walletOnfidoData: OnyxEntry<WalletOnfido>;
};
type OnfidoPrivacyProps = OnfidoPrivacyOnyxProps;
function OnfidoPrivacy({walletOnfidoData = DEFAULT_WALLET_ONFIDO_DATA}: OnfidoPrivacyProps) {
const {translate} = useLocalize();
const formRef = useRef<ScrollView>(null);
const styles = useThemeStyles();
if (!walletOnfidoData) {
return;
}
const {isLoading = false, hasAcceptedPrivacyPolicy} = walletOnfidoData;
const openOnfidoFlow = () => {
BankAccounts.openOnfidoFlow();
};
const onfidoError = ErrorUtils.getLatestErrorMessage(walletOnfidoData) ?? '';
const onfidoFixableErrors = walletOnfidoData?.fixableErrors ?? [];
if (Array.isArray(onfidoError)) {
onfidoError[0] += !isEmptyObject(onfidoFixableErrors) ? `\n${onfidoFixableErrors.join('\n')}` : '';
}
return (
<View style={[styles.flex1, styles.justifyContentBetween]}>
{!hasAcceptedPrivacyPolicy ? (
<>
<FormScrollView ref={formRef}>
<View style={[styles.mh5, styles.justifyContentCenter]}>
<Text style={[styles.mb5]}>
{translate('onfidoStep.acceptTerms')}
<TextLink href={CONST.ONFIDO_FACIAL_SCAN_POLICY_URL}>{translate('onfidoStep.facialScan')}</TextLink>
{', '}
<TextLink href={CONST.ONFIDO_PRIVACY_POLICY_URL}>{translate('common.privacy')}</TextLink>
{` ${translate('common.and')} `}
<TextLink href={CONST.ONFIDO_TERMS_OF_SERVICE_URL}>{translate('common.termsOfService')}</TextLink>.
</Text>
</View>
</FormScrollView>
<FixedFooter>
<FormAlertWithSubmitButton
isAlertVisible={!!onfidoError}
onSubmit={openOnfidoFlow}
onFixTheErrorsLinkPressed={() => {
formRef.current?.scrollTo({y: 0, animated: true});
}}
message={onfidoError}
isLoading={isLoading}
buttonText={onfidoError ? translate('onfidoStep.tryAgain') : translate('common.continue')}
containerStyles={[styles.mh0, styles.mv0, styles.mb0]}
/>
</FixedFooter>
</>
) : null}
{hasAcceptedPrivacyPolicy && isLoading ? <FullscreenLoadingIndicator /> : null}
</View>
);
}
OnfidoPrivacy.displayName = 'OnfidoPrivacy';
export default withOnyx<OnfidoPrivacyProps, OnfidoPrivacyOnyxProps>({
walletOnfidoData: {
key: ONYXKEYS.WALLET_ONFIDO,
// Let's get a new onfido token each time the user hits this flow (as it should only be once)
initWithStoredValues: false,
},
})(OnfidoPrivacy);