diff --git a/package-lock.json b/package-lock.json index 87c7dd3d2600..029c5545d468 100644 --- a/package-lock.json +++ b/package-lock.json @@ -62,7 +62,7 @@ "lodash-es": "4.17.21", "lottie-react-native": "6.5.1", "mapbox-gl": "^2.15.0", - "onfido-sdk-ui": "14.15.0", + "onfido-sdk-ui": "14.37.1", "process": "^0.11.10", "pusher-js": "8.3.0", "react": "18.3.1", @@ -32636,8 +32636,9 @@ } }, "node_modules/onfido-sdk-ui": { - "version": "14.15.0", - "license": "SEE LICENSE in LICENSE" + "version": "14.37.1", + "resolved": "https://registry.npmjs.org/onfido-sdk-ui/-/onfido-sdk-ui-14.37.1.tgz", + "integrity": "sha512-4wvZRl97Kr8btV7p4IB4J4sHYt824/2ayFo7nEkb4xtDatW8EIEOAV44FktPXM7C7RtDbwyS8rCCyNv3g5LbDw==" }, "node_modules/open": { "version": "8.4.2", diff --git a/package.json b/package.json index 056d29a36c19..4f18c0f2ab0a 100644 --- a/package.json +++ b/package.json @@ -119,7 +119,7 @@ "lodash-es": "4.17.21", "lottie-react-native": "6.5.1", "mapbox-gl": "^2.15.0", - "onfido-sdk-ui": "14.15.0", + "onfido-sdk-ui": "14.37.1", "process": "^0.11.10", "pusher-js": "8.3.0", "react": "18.3.1", diff --git a/src/CONST.ts b/src/CONST.ts index 5a0c6f395eb4..52db19c5ede1 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -1902,6 +1902,7 @@ const CONST = { WRONG_ANSWERS: 'Wrong answers', ONFIDO_FIXABLE_ERROR: 'Onfido returned a fixable error', ONFIDO_USER_CONSENT_DENIED: 'user_consent_denied', + ONFIDO_EXCEPTION: 'exception', // KBA stands for Knowledge Based Answers (requiring us to show Idology questions) KBA_NEEDED: 'KBA needed', diff --git a/src/components/Onfido/BaseOnfidoWeb.tsx b/src/components/Onfido/BaseOnfidoWeb.tsx index 2a2882c155eb..2db268a74deb 100644 --- a/src/components/Onfido/BaseOnfidoWeb.tsx +++ b/src/components/Onfido/BaseOnfidoWeb.tsx @@ -11,7 +11,7 @@ import variables from '@styles/variables'; import CONST from '@src/CONST'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import './index.css'; -import type {OnfidoElement, OnfidoError, OnfidoProps} from './types'; +import type {OnfidoElement, OnfidoProps} from './types'; type InitializeOnfidoProps = OnfidoProps & Pick & { @@ -23,7 +23,7 @@ type OnfidoEvent = Event & { }; function initializeOnfido({sdkToken, onSuccess, onError, onUserExit, preferredLocale, translate, theme}: InitializeOnfidoProps) { - OnfidoSDK.init({ + return OnfidoSDK.init({ token: sdkToken, containerId: CONST.ONFIDO.CONTAINER_ID, customUI: { @@ -94,10 +94,13 @@ function initializeOnfido({sdkToken, onSuccess, onError, onUserExit, preferredLo } onSuccess(data); }, - onError: (error: OnfidoError) => { + onError: (error) => { const errorType = error.type; const errorMessage: string = error.message ?? CONST.ERROR.UNKNOWN_ERROR; Log.hmmm('Onfido error', {errorType, errorMessage}); + if (errorType === CONST.WALLET.ERROR.ONFIDO_EXCEPTION) { + return; + } if (errorType === CONST.WALLET.ERROR.ONFIDO_USER_CONSENT_DENIED) { onUserExit(); return; @@ -129,7 +132,7 @@ function Onfido({sdkToken, onSuccess, onError, onUserExit}: OnfidoProps, ref: Fo const theme = useTheme(); useEffect(() => { - initializeOnfido({ + const onfido = initializeOnfido({ sdkToken, onSuccess, onError, @@ -138,9 +141,11 @@ function Onfido({sdkToken, onSuccess, onError, onUserExit}: OnfidoProps, ref: Fo translate, theme, }); - window.addEventListener('userAnalyticsEvent', logOnFidoEvent); - return () => window.removeEventListener('userAnalyticsEvent', logOnFidoEvent); + return () => { + onfido.tearDown(); + window.removeEventListener('userAnalyticsEvent', logOnFidoEvent); + }; // Onfido should be initialized only once on mount // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps }, []); diff --git a/src/components/Onfido/types.ts b/src/components/Onfido/types.ts index 3e88ce3b2dda..f08cdbb566b0 100644 --- a/src/components/Onfido/types.ts +++ b/src/components/Onfido/types.ts @@ -1,6 +1,6 @@ import type {OnfidoResult} from '@onfido/react-native-sdk'; import type {Handle} from 'onfido-sdk-ui/types/Onfido'; -import type {CompleteData} from 'onfido-sdk-ui/types/Types'; +import type {CompleteData} from 'onfido-sdk-ui/types/shared/SdkParameters'; import type {OnyxEntry} from 'react-native-onyx'; type OnfidoData = CompleteData | OnfidoResult; diff --git a/src/libs/actions/BankAccounts.ts b/src/libs/actions/BankAccounts.ts index 3007bd2cb88c..2393c66d2155 100644 --- a/src/libs/actions/BankAccounts.ts +++ b/src/libs/actions/BankAccounts.ts @@ -117,6 +117,11 @@ function clearOnfidoToken() { Onyx.merge(ONYXKEYS.ONFIDO_APPLICANT_ID, ''); } +function setLocalOnfidoTokens(token: string, applicationID: string) { + Onyx.merge(ONYXKEYS.ONFIDO_TOKEN, token); + Onyx.merge(ONYXKEYS.ONFIDO_APPLICANT_ID, applicationID); +} + function updateAddPersonalBankAccountDraft(bankData: Partial) { Onyx.merge(ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT_FORM_DRAFT, bankData); } @@ -546,6 +551,7 @@ export { addBusinessWebsiteForDraft, addPersonalBankAccount, clearOnfidoToken, + setLocalOnfidoTokens, clearPersonalBankAccount, clearPlaid, setPlaidEvent, diff --git a/src/pages/ReimbursementAccount/ReimbursementAccountPage.tsx b/src/pages/ReimbursementAccount/ReimbursementAccountPage.tsx index 4b42aff1fc1d..7fcf194c0165 100644 --- a/src/pages/ReimbursementAccount/ReimbursementAccountPage.tsx +++ b/src/pages/ReimbursementAccount/ReimbursementAccountPage.tsx @@ -63,6 +63,9 @@ type ReimbursementAccountOnyxProps = { /** The token required to initialize the Onfido SDK */ onfidoToken: OnyxEntry; + + /** The application id which connected to onfido session */ + onfidoApplicantID: OnyxEntry; }; type ReimbursementAccountPageProps = WithPolicyOnyxProps & @@ -128,6 +131,7 @@ function ReimbursementAccountPage({ reimbursementAccount, route, onfidoToken = '', + onfidoApplicantID = '', policy, account, isLoadingApp = false, @@ -225,6 +229,7 @@ function ReimbursementAccountPage({ const prevIsReimbursementAccountLoading = usePrevious(reimbursementAccount?.isLoading); const prevReimbursementAccount = usePrevious(reimbursementAccount); const prevIsOffline = usePrevious(isOffline); + const onfidoLocalTokensRef = useRef({onfidoToken: '', onfidoApplicantID: ''}); /** * Retrieve verified business bank account currently being set up. @@ -243,6 +248,20 @@ function ReimbursementAccountPage({ BankAccounts.openReimbursementAccountPage(stepToOpen, ignoreLocalSubStep ? '' : subStep, ignoreLocalCurrentStep ? '' : localCurrentStep, policyIDParam); } + useEffect(() => { + if (!onfidoToken) { + return; + } + onfidoLocalTokensRef.current = {onfidoToken, onfidoApplicantID}; + }, [onfidoToken, onfidoApplicantID]); + + useEffect(() => { + if (!prevIsReimbursementAccountLoading && !onfidoLocalTokensRef.current.onfidoToken) { + return; + } + BankAccounts.setLocalOnfidoTokens(onfidoLocalTokensRef.current.onfidoToken, onfidoLocalTokensRef.current.onfidoApplicantID); + }, [prevIsReimbursementAccountLoading]); + useEffect(() => { if (!isReimbursementAccountLoading) { return; @@ -527,6 +546,9 @@ export default withPolicy( onfidoToken: { key: ONYXKEYS.ONFIDO_TOKEN, }, + onfidoApplicantID: { + key: ONYXKEYS.ONFIDO_APPLICANT_ID, + }, isLoadingApp: { key: ONYXKEYS.IS_LOADING_APP, },