@trustchex/react-native-sdk 1.245.0 → 1.249.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- import React, { useCallback, useContext, useEffect, useState } from 'react';
3
+ import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react';
4
4
  import { Alert, Image, Platform, SafeAreaView, ScrollView, StyleSheet, Text, View } from 'react-native';
5
5
  import AppContext from "../../Shared/Contexts/AppContext.js";
6
6
  import httpClient from "../../Shared/Libs/http-client.js";
@@ -22,17 +22,12 @@ const ResultScreen = () => {
22
22
  const [isSubmitting, setIsSubmitting] = useState(false);
23
23
  const [progress, setProgress] = useState(0);
24
24
  const navigationManagerRef = React.useRef(null);
25
- const [apiUrl, setApiUrl] = useState(`${appContext.baseUrl}/api/app/mobile`);
26
25
  const [shouldShowDemoData, setShouldShowDemoData] = useState(false);
27
26
  const [deviceIdentifier, setDeviceIdentifier] = useState('');
28
27
  const {
29
28
  t
30
29
  } = useTranslation();
31
- useEffect(() => {
32
- if (appContext.baseUrl) {
33
- setApiUrl(`${appContext.baseUrl}/api/app/mobile`);
34
- }
35
- }, [appContext.baseUrl]);
30
+ const apiUrl = useMemo(() => `${appContext.baseUrl}/api/app/mobile`, [appContext.baseUrl]);
36
31
  useEffect(() => {
37
32
  if (appContext.isDemoSession) {
38
33
  setShouldShowDemoData(true);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- import React, { useCallback, useContext, useEffect, useRef, useState } from 'react';
3
+ import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
4
4
  import { SafeAreaView, Text, StyleSheet, Alert, View, Image, Dimensions, KeyboardAvoidingView, Platform, ScrollView } from 'react-native';
5
5
  import { useSafeAreaInsets } from 'react-native-safe-area-context';
6
6
  import AppContext from "../../Shared/Contexts/AppContext.js";
@@ -28,15 +28,10 @@ const VerificationSessionCheckScreen = () => {
28
28
  } = useTranslation();
29
29
  const navigationManagerRef = React.useRef(null);
30
30
  const navigation = useNavigation();
31
- const [apiUrl, setApiUrl] = useState(`${appContext.baseUrl}/api/app/mobile`);
32
31
  const theme = useTheme();
33
32
  const initialized = useRef(false);
34
33
  const insets = useSafeAreaInsets();
35
- useEffect(() => {
36
- if (appContext.baseUrl) {
37
- setApiUrl(`${appContext.baseUrl}/api/app/mobile`);
38
- }
39
- }, [appContext.baseUrl]);
34
+ const apiUrl = useMemo(() => `${appContext.baseUrl}/api/app/mobile`, [appContext.baseUrl]);
40
35
  const validateSessionCode = useCallback(value => {
41
36
  return SESSION_CODE_VALIDATION_PATTERN.test(value.toUpperCase());
42
37
  }, []);
@@ -35,6 +35,7 @@ const Trustchex = ({
35
35
  const [baseUrl, setBaseUrl] = useState(null);
36
36
  const [sessionId, setSessionId] = useState(null);
37
37
  const [locale, setLocale] = useState(propLocale || i18n.language);
38
+ const [isInitialized, setIsInitialized] = useState(false);
38
39
  const branding = useMemo(() => ({
39
40
  ...DEFAULT_BRANDING,
40
41
  ...propBranding
@@ -69,22 +70,29 @@ const Trustchex = ({
69
70
  initializeTTS();
70
71
  }, []);
71
72
  useEffect(() => {
72
- if (propBaseUrl) {
73
- setBaseUrl(propBaseUrl);
74
- }
75
- }, [propBaseUrl]);
76
- useEffect(() => {
77
- if (propSessionId) {
78
- setSessionId(propSessionId);
79
- }
80
- }, [propSessionId]);
73
+ const timer = setTimeout(() => {
74
+ let shouldUpdate = false;
75
+ if (propBaseUrl && propBaseUrl !== baseUrl) {
76
+ shouldUpdate = true;
77
+ }
78
+ if (propSessionId !== undefined && propSessionId !== sessionId) {
79
+ shouldUpdate = true;
80
+ }
81
+ if (shouldUpdate && propBaseUrl && propSessionId !== undefined) {
82
+ setBaseUrl(propBaseUrl);
83
+ setSessionId(propSessionId);
84
+ }
85
+ setIsInitialized(true);
86
+ }, 100);
87
+ return () => clearTimeout(timer);
88
+ }, [propBaseUrl, propSessionId, baseUrl, sessionId]);
81
89
  useEffect(() => {
82
90
  if (propLocale) {
83
91
  setLocale(propLocale);
84
92
  i18n.changeLanguage(propLocale);
85
93
  }
86
94
  }, [propLocale]);
87
- if (!baseUrl) {
95
+ if (!baseUrl || !isInitialized) {
88
96
  return /*#__PURE__*/_jsx(View, {
89
97
  style: styles.loadingContainer,
90
98
  children: /*#__PURE__*/_jsx(ActivityIndicator, {
@@ -1 +1 @@
1
- {"version":3,"file":"ResultScreen.d.ts","sourceRoot":"","sources":["../../../../../src/Screens/Static/ResultScreen.tsx"],"names":[],"mappings":"AAiCA,QAAA,MAAM,YAAY,+CA4uBjB,CAAC;AAsGF,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"ResultScreen.d.ts","sourceRoot":"","sources":["../../../../../src/Screens/Static/ResultScreen.tsx"],"names":[],"mappings":"AAuCA,QAAA,MAAM,YAAY,+CAwuBjB,CAAC;AAsGF,eAAe,YAAY,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"VerificationSessionCheckScreen.d.ts","sourceRoot":"","sources":["../../../../../src/Screens/Static/VerificationSessionCheckScreen.tsx"],"names":[],"mappings":"AAyCA,QAAA,MAAM,8BAA8B,+CAgZnC,CAAC;AA0IF,eAAe,8BAA8B,CAAC"}
1
+ {"version":3,"file":"VerificationSessionCheckScreen.d.ts","sourceRoot":"","sources":["../../../../../src/Screens/Static/VerificationSessionCheckScreen.tsx"],"names":[],"mappings":"AA0CA,QAAA,MAAM,8BAA8B,+CA4YnC,CAAC;AA0IF,eAAe,8BAA8B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"Trustchex.d.ts","sourceRoot":"","sources":["../../../src/Trustchex.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAK5D,OAAO,gCAAgC,CAAC;AAexC,UAAU,iBAAiB;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,UAAU,cAAc;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IAC7B,MAAM,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC;AASD,QAAA,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CA+HvC,CAAC;AAWF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"Trustchex.d.ts","sourceRoot":"","sources":["../../../src/Trustchex.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAK5D,OAAO,gCAAgC,CAAC;AAexC,UAAU,iBAAiB;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,UAAU,cAAc;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IAC7B,MAAM,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC;AASD,QAAA,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CA2IvC,CAAC;AAWF,eAAe,SAAS,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trustchex/react-native-sdk",
3
- "version": "1.245.0",
3
+ "version": "1.249.0",
4
4
  "description": "Trustchex mobile app react native SDK for android or ios devices",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -1,4 +1,10 @@
1
- import React, { useCallback, useContext, useEffect, useState } from 'react';
1
+ import React, {
2
+ useCallback,
3
+ useContext,
4
+ useEffect,
5
+ useMemo,
6
+ useState,
7
+ } from 'react';
2
8
  import {
3
9
  Alert,
4
10
  Image,
@@ -36,18 +42,14 @@ const ResultScreen = () => {
36
42
  const [isSubmitting, setIsSubmitting] = useState(false);
37
43
  const [progress, setProgress] = useState(0);
38
44
  const navigationManagerRef = React.useRef<NavigationManagerRef>(null);
39
- const [apiUrl, setApiUrl] = useState<string>(
40
- `${appContext.baseUrl}/api/app/mobile`
41
- );
42
45
  const [shouldShowDemoData, setShouldShowDemoData] = useState(false);
43
46
  const [deviceIdentifier, setDeviceIdentifier] = useState<string>('');
44
47
  const { t } = useTranslation();
45
48
 
46
- useEffect(() => {
47
- if (appContext.baseUrl) {
48
- setApiUrl(`${appContext.baseUrl}/api/app/mobile`);
49
- }
50
- }, [appContext.baseUrl]);
49
+ const apiUrl = useMemo(
50
+ () => `${appContext.baseUrl}/api/app/mobile`,
51
+ [appContext.baseUrl]
52
+ );
51
53
 
52
54
  useEffect(() => {
53
55
  if (appContext.isDemoSession) {
@@ -2,6 +2,7 @@ import React, {
2
2
  useCallback,
3
3
  useContext,
4
4
  useEffect,
5
+ useMemo,
5
6
  useRef,
6
7
  useState,
7
8
  } from 'react';
@@ -50,18 +51,14 @@ const VerificationSessionCheckScreen = () => {
50
51
  const { t } = useTranslation();
51
52
  const navigationManagerRef = React.useRef<NavigationManagerRef>(null);
52
53
  const navigation = useNavigation();
53
- const [apiUrl, setApiUrl] = useState<string>(
54
- `${appContext.baseUrl}/api/app/mobile`
55
- );
56
54
  const theme = useTheme();
57
55
  const initialized = useRef(false);
58
56
  const insets = useSafeAreaInsets();
59
57
 
60
- useEffect(() => {
61
- if (appContext.baseUrl) {
62
- setApiUrl(`${appContext.baseUrl}/api/app/mobile`);
63
- }
64
- }, [appContext.baseUrl]);
58
+ const apiUrl = useMemo(
59
+ () => `${appContext.baseUrl}/api/app/mobile`,
60
+ [appContext.baseUrl]
61
+ );
65
62
 
66
63
  const validateSessionCode = useCallback((value: string) => {
67
64
  return SESSION_CODE_VALIDATION_PATTERN.test(value.toUpperCase());
package/src/Trustchex.tsx CHANGED
@@ -52,6 +52,7 @@ const Trustchex: React.FC<TrustchexProps> = ({
52
52
  const [baseUrl, setBaseUrl] = useState<string | null>(null);
53
53
  const [sessionId, setSessionId] = useState<string | null>(null);
54
54
  const [locale, setLocale] = useState(propLocale || i18n.language);
55
+ const [isInitialized, setIsInitialized] = useState(false);
55
56
 
56
57
  const branding = useMemo(
57
58
  () => ({
@@ -100,16 +101,27 @@ const Trustchex: React.FC<TrustchexProps> = ({
100
101
  }, []);
101
102
 
102
103
  useEffect(() => {
103
- if (propBaseUrl) {
104
- setBaseUrl(propBaseUrl);
105
- }
106
- }, [propBaseUrl]);
104
+ const timer = setTimeout(() => {
105
+ let shouldUpdate = false;
107
106
 
108
- useEffect(() => {
109
- if (propSessionId) {
110
- setSessionId(propSessionId);
111
- }
112
- }, [propSessionId]);
107
+ if (propBaseUrl && propBaseUrl !== baseUrl) {
108
+ shouldUpdate = true;
109
+ }
110
+
111
+ if (propSessionId !== undefined && propSessionId !== sessionId) {
112
+ shouldUpdate = true;
113
+ }
114
+
115
+ if (shouldUpdate && propBaseUrl && propSessionId !== undefined) {
116
+ setBaseUrl(propBaseUrl);
117
+ setSessionId(propSessionId);
118
+ }
119
+
120
+ setIsInitialized(true);
121
+ }, 100);
122
+
123
+ return () => clearTimeout(timer);
124
+ }, [propBaseUrl, propSessionId, baseUrl, sessionId]);
113
125
 
114
126
  useEffect(() => {
115
127
  if (propLocale) {
@@ -118,7 +130,7 @@ const Trustchex: React.FC<TrustchexProps> = ({
118
130
  }
119
131
  }, [propLocale]);
120
132
 
121
- if (!baseUrl) {
133
+ if (!baseUrl || !isInitialized) {
122
134
  return (
123
135
  <View style={styles.loadingContainer}>
124
136
  <ActivityIndicator size="large" color={branding.primaryColor} />