Skip to content

Commit

Permalink
Merge pull request #30374 from ishpaul777/fix/ios-wrong-permission-me…
Browse files Browse the repository at this point in the history
…ssage

Fix/ios wrong permission message
  • Loading branch information
chiragsalian authored Dec 12, 2023
2 parents a7e650f + 8c0b10b commit 776849a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 32 deletions.
5 changes: 0 additions & 5 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1099,11 +1099,6 @@ const CONST = {
USER_CANCELLED: 'User canceled flow.',
USER_TAPPED_BACK: 'User exited by clicking the back button.',
USER_EXITED: 'User exited by manual action.',
USER_CAMERA_DENINED: 'Onfido.OnfidoFlowError',
USER_CAMERA_PERMISSION: 'Encountered an error: cameraPermission',
// eslint-disable-next-line max-len
USER_CAMERA_CONSENT_DENIED:
'Unexpected result Intent. It might be a result of incorrect integration, make sure you only pass Onfido intent to handleActivityResult. It might be due to unpredictable crash or error. Please report the problem to [email protected]. Intent: null \n resultCode: 0',
},
},

Expand Down
68 changes: 45 additions & 23 deletions src/components/Onfido/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import {OnfidoCaptureType, OnfidoCountryCode, OnfidoDocumentType, Onfido as Onfi
import lodashGet from 'lodash/get';
import React, {useEffect} from 'react';
import {Alert, Linking} from 'react-native';
import {checkMultiple, PERMISSIONS, RESULTS} from 'react-native-permissions';
import _ from 'underscore';
import FullscreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import useLocalize from '@hooks/useLocalize';
import getPlatform from '@libs/getPlatform';
import Log from '@libs/Log';
import CONST from '@src/CONST';
import onfidoPropTypes from './onfidoPropTypes';
Expand Down Expand Up @@ -39,30 +41,50 @@ function Onfido({sdkToken, onUserExit, onSuccess, onError}) {
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(
translate('onfidoStep.cameraPermissionsNotGranted'),
translate('onfidoStep.cameraRequestMessage'),
[
{
text: translate('common.cancel'),
onPress: () => onUserExit(),
},
{
text: translate('common.settings'),
onPress: () => {
onUserExit();
Linking.openSettings();
},
},
],
{cancelable: false},
);
return;
}
if (!_.isEmpty(errorMessage) && getPlatform() === CONST.PLATFORM.IOS) {
checkMultiple([PERMISSIONS.IOS.MICROPHONE, PERMISSIONS.IOS.CAMERA])
.then((statuses) => {
const isMicAllowed = statuses[PERMISSIONS.IOS.MICROPHONE] === RESULTS.GRANTED;
const isCameraAllowed = statuses[PERMISSIONS.IOS.CAMERA] === RESULTS.GRANTED;
let alertTitle = '';
let alertMessage = '';
if (!isCameraAllowed) {
alertTitle = 'onfidoStep.cameraPermissionsNotGranted';
alertMessage = 'onfidoStep.cameraRequestMessage';
} else if (!isMicAllowed) {
alertTitle = 'onfidoStep.microphonePermissionsNotGranted';
alertMessage = 'onfidoStep.microphoneRequestMessage';
}

onError(errorMessage);
if (!_.isEmpty(alertTitle) && !_.isEmpty(alertMessage)) {
Alert.alert(
translate(alertTitle),
translate(alertMessage),
[
{
text: translate('common.cancel'),
onPress: () => onUserExit(),
},
{
text: translate('common.settings'),
onPress: () => {
onUserExit();
Linking.openSettings();
},
},
],
{cancelable: false},
);
return;
}
onError(errorMessage);
})
.catch(() => {
onError(errorMessage);
});
} else {
onError(errorMessage);
}
});
// Onfido should be initialized only once on mount
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
6 changes: 4 additions & 2 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1266,8 +1266,10 @@ export default {
tryAgain: 'Try again',
verifyIdentity: 'Verify identity',
genericError: 'There was an error while processing this step. Please try again.',
cameraPermissionsNotGranted: 'Camera permissions not granted',
cameraRequestMessage: 'You have not granted us camera access. We need access to complete verification.',
cameraPermissionsNotGranted: 'Enable camera access',
cameraRequestMessage: 'We need access to your camera to complete bank account verification. Please enable via Settings > New Expensify.',
microphonePermissionsNotGranted: 'Enable microphone access',
microphoneRequestMessage: 'We need access to your microphone to complete bank account verification. Please enable via Settings > New Expensify.',
originalDocumentNeeded: 'Please upload an original image of your ID rather than a screenshot or scanned image.',
documentNeedsBetterQuality: 'Your ID appears to be damaged or has missing security features. Please upload an original image of an undamaged ID that is entirely visible.',
imageNeedsBetterQuality: "There's an issue with the image quality of your ID. Please upload a new image where your entire ID can be seen clearly.",
Expand Down
7 changes: 5 additions & 2 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1285,8 +1285,11 @@ export default {
tryAgain: 'Intentar otra vez',
verifyIdentity: 'Verificar identidad',
genericError: 'Hubo un error al procesar este paso. Inténtalo de nuevo.',
cameraPermissionsNotGranted: 'No has habilitado los permisos para acceder a la cámara',
cameraRequestMessage: 'No has habilitado los permisos para acceder a la cámara. Necesitamos acceso para completar la verificaciôn.',
cameraPermissionsNotGranted: 'Permiso para acceder a la cámara',
cameraRequestMessage: 'Necesitamos acceso a tu cámara para completar la verificación de tu cuenta de banco. Por favor habilita los permisos en Configuración > Nuevo Expensify.',
microphonePermissionsNotGranted: 'Permiso para acceder al micrófono',
microphoneRequestMessage:
'Necesitamos acceso a tu micrófono para completar la verificación de tu cuenta de banco. Por favor habilita los permisos en Configuración > Nuevo Expensify.',
originalDocumentNeeded: 'Por favor, sube una imagen original de tu identificación en lugar de una captura de pantalla o imagen escaneada.',
documentNeedsBetterQuality:
'Parece que tu identificación esta dañado o le faltan características de seguridad. Por favor, sube una imagen de tu documento sin daños y que se vea completamente.',
Expand Down

0 comments on commit 776849a

Please sign in to comment.