-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathindex.native.js
89 lines (82 loc) · 3.32 KB
/
index.native.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
import _ from 'underscore';
import lodashGet from 'lodash/get';
import React from 'react';
import {Alert, Linking} from 'react-native';
import {
Onfido as OnfidoSDK,
OnfidoCaptureType,
OnfidoDocumentType,
OnfidoCountryCode,
} from '@onfido/react-native-sdk';
import onfidoPropTypes from './onfidoPropTypes';
import CONST from '../../CONST';
import withLocalize, {withLocalizePropTypes} from '../withLocalize';
import Log from '../../libs/Log';
const propTypes = {
...withLocalizePropTypes,
...onfidoPropTypes,
};
class Onfido extends React.Component {
componentDidMount() {
OnfidoSDK.start({
sdkToken: this.props.sdkToken,
flowSteps: {
welcome: true,
captureFace: {
type: OnfidoCaptureType.VIDEO,
},
captureDocument: {
docType: OnfidoDocumentType.GENERIC,
countryCode: OnfidoCountryCode.USA,
},
},
})
.then(this.props.onSuccess)
.catch((error) => {
const errorMessage = lodashGet(error, 'message', CONST.ERROR.UNKNOWN_ERROR);
const errorType = lodashGet(error, 'type');
Log.hmmm('Onfido error on native', {errorType, errorMessage});
// If the user cancels the Onfido flow we won't log this error as it's normal. In the React Native SDK the user exiting the flow will trigger this error which we can use as
// our "user exited the flow" callback. On web, this event has it's own callback passed as a config so we don't need to bother with this there.
if (_.contains([CONST.ONFIDO.ERROR.USER_CANCELLED, CONST.ONFIDO.ERROR.USER_TAPPED_BACK], errorMessage)) {
this.props.onUserExit();
return;
}
// Handle user camera permission on iOS and Android
if (_.contains(
[
CONST.ONFIDO.ERROR.USER_CAMERA_PERMISSION,
CONST.ONFIDO.ERROR.USER_CAMERA_DENINED,
CONST.ONFIDO.ERROR.USER_CAMERA_CONSENT_DENIED,
],
errorMessage,
)) {
Alert.alert(
this.props.translate('onfidoStep.cameraPermissionsNotGranted'),
this.props.translate('onfidoStep.cameraRequestMessage'),
[
{
text: this.props.translate('common.cancel'),
onPress: () => this.props.onUserExit(),
},
{
text: this.props.translate('common.settings'),
onPress: () => {
this.props.onUserExit();
Linking.openSettings();
},
},
],
{cancelable: false},
);
return;
}
this.props.onError(errorMessage);
});
}
render() {
return null;
}
}
Onfido.propTypes = propTypes;
export default withLocalize(Onfido);