partner_react_native_sdk 0.1.4 → 0.1.6
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.
- package/lib/module/helpers/analytics/analytics_logger.js +4 -3
- package/lib/module/helpers/analytics/analytics_logger.js.map +1 -1
- package/lib/module/helpers/network/APICall.js +96 -4
- package/lib/module/helpers/network/APICall.js.map +1 -1
- package/lib/module/helpers/network/Encryption.js +241 -0
- package/lib/module/helpers/network/Encryption.js.map +1 -0
- package/lib/module/helpers/partner_library_react_native.js +52 -54
- package/lib/module/helpers/partner_library_react_native.js.map +1 -1
- package/lib/module/helpers/webview.js +30 -10
- package/lib/module/helpers/webview.js.map +1 -1
- package/lib/typescript/src/helpers/analytics/analytics_logger.d.ts.map +1 -1
- package/lib/typescript/src/helpers/network/APICall.d.ts.map +1 -1
- package/lib/typescript/src/helpers/network/Encryption.d.ts +1 -0
- package/lib/typescript/src/helpers/network/Encryption.d.ts.map +1 -0
- package/lib/typescript/src/helpers/partner_library_react_native.d.ts.map +1 -1
- package/lib/typescript/src/helpers/webview.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/helpers/analytics/analytics_logger.tsx +73 -72
- package/src/helpers/network/APICall.tsx +139 -54
- package/src/helpers/network/Encryption.tsx +239 -0
- package/src/helpers/partner_library_react_native.tsx +279 -273
- package/src/helpers/webview.tsx +39 -12
|
@@ -10,292 +10,298 @@ import { StatusBar } from 'react-native';
|
|
|
10
10
|
export type { WebViewCallbackFunction } from './utils/webviewCallback';
|
|
11
11
|
import { AnalyticsLogger } from './analytics/analytics_logger';
|
|
12
12
|
type InitOptions = {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
whitelistedDomains: string[];
|
|
14
|
+
deviceBindingEnabled: boolean;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
|
|
18
17
|
export class PartnerLibrary {
|
|
18
|
+
private static instance: PartnerLibrary | null = null;
|
|
19
|
+
private static intialized = false;
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
static webViewCallback: WebViewCallbackFunction;
|
|
25
|
-
private _analyticsLogger!: AnalyticsLogger;
|
|
26
|
-
private constructor() { }
|
|
21
|
+
private _apiCall = new APICall();
|
|
22
|
+
static webViewCallback: WebViewCallbackFunction;
|
|
23
|
+
private _analyticsLogger!: AnalyticsLogger;
|
|
24
|
+
private constructor() {}
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
return PartnerLibrary.instance;
|
|
26
|
+
static getInstance(): PartnerLibrary {
|
|
27
|
+
if (!PartnerLibrary.instance) {
|
|
28
|
+
PartnerLibrary.instance = new PartnerLibrary();
|
|
33
29
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
// Ensure instance exists before setup
|
|
44
|
-
if (!PartnerLibrary.instance) {
|
|
45
|
-
// console.log("PartnerLibrary.init - creating new instance");
|
|
46
|
-
PartnerLibrary.instance = new PartnerLibrary();
|
|
47
|
-
}
|
|
48
|
-
await PartnerLibrary.instance._setup(hostName, options.whitelistedDomains, options.deviceBindingEnabled);
|
|
49
|
-
PartnerLibrary.intialized = true;
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
console.error("Initialization failed: ", error);
|
|
53
|
-
throw new Error("Initialization failed");
|
|
54
|
-
}
|
|
30
|
+
return PartnerLibrary.instance;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static async init(
|
|
34
|
+
hostName: string,
|
|
35
|
+
options: InitOptions = {
|
|
36
|
+
whitelistedDomains: [],
|
|
37
|
+
deviceBindingEnabled: false,
|
|
55
38
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
39
|
+
): Promise<void> {
|
|
40
|
+
// console.log("PartnerLibrary.init - initialized:", PartnerLibrary.intialized);
|
|
41
|
+
if (PartnerLibrary.intialized) return;
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
// Ensure instance exists before setup
|
|
45
|
+
if (!PartnerLibrary.instance) {
|
|
46
|
+
// console.log("PartnerLibrary.init - creating new instance");
|
|
47
|
+
PartnerLibrary.instance = new PartnerLibrary();
|
|
48
|
+
}
|
|
49
|
+
await PartnerLibrary.instance._setup(
|
|
50
|
+
hostName,
|
|
51
|
+
options.whitelistedDomains,
|
|
52
|
+
options.deviceBindingEnabled
|
|
53
|
+
);
|
|
54
|
+
PartnerLibrary.intialized = true;
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.error('Initialization failed: ', error);
|
|
57
|
+
throw new Error('Initialization failed');
|
|
71
58
|
}
|
|
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
|
-
console.error('Error opening webview:', e);
|
|
98
|
-
throw e;
|
|
99
|
-
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private async _setup(
|
|
62
|
+
hostName: string,
|
|
63
|
+
whitelistedDomains: string[],
|
|
64
|
+
deviceBindingEnabled: boolean
|
|
65
|
+
): Promise<void> {
|
|
66
|
+
LibraryConstants.init({
|
|
67
|
+
host: hostName,
|
|
68
|
+
whitelistedDomains: whitelistedDomains,
|
|
69
|
+
deviceBinding: deviceBindingEnabled,
|
|
70
|
+
});
|
|
71
|
+
this._analyticsLogger = new AnalyticsLogger();
|
|
72
|
+
// this._analyticsLogger.logEvent({ event: 'REACT_NATIVE_INTIALIZED' });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async open(
|
|
76
|
+
module: string,
|
|
77
|
+
token: string,
|
|
78
|
+
WebViewCallbackFunction: WebViewCallbackFunction
|
|
79
|
+
): Promise<React.ReactElement> {
|
|
80
|
+
// this._analyticsLogger.logEvent({ event: 'REACT_NATIVE_OPEN_FN_CALLED' });
|
|
81
|
+
|
|
82
|
+
if (!PartnerLibrary.intialized) {
|
|
83
|
+
throw new Error('PartnerLibrary not initialized. Call init() first.');
|
|
100
84
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
85
|
+
try {
|
|
86
|
+
let bank = '';
|
|
87
|
+
|
|
88
|
+
if (module.includes('banking/')) {
|
|
89
|
+
const startIndex = module.indexOf('banking/') + 'banking/'.length;
|
|
90
|
+
const temp = module.substring(startIndex);
|
|
91
|
+
const endIndex = temp.indexOf('/');
|
|
92
|
+
bank = endIndex === -1 ? temp : temp.substring(0, endIndex);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return this._loginAndNavigateToWebView(
|
|
96
|
+
module,
|
|
97
|
+
bank,
|
|
98
|
+
token,
|
|
99
|
+
WebViewCallbackFunction
|
|
100
|
+
);
|
|
101
|
+
} catch (e) {
|
|
102
|
+
console.error('Error opening webview:', e);
|
|
103
|
+
throw e;
|
|
121
104
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
);
|
|
144
|
-
this._analyticsLogger.logEvent({ "event": "REACT_NATIVE_LOGIN_FN_RESPONSE :", "response": tokenResponse })
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (tokenResponse?.data?.code === "USER_TOKEN_EXPIRED") {
|
|
148
|
-
console.log("Token expired");
|
|
149
|
-
return Promise.resolve(<></>);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (
|
|
153
|
-
tokenResponse &&
|
|
154
|
-
tokenResponse.data &&
|
|
155
|
-
typeof tokenResponse.data === 'object' &&
|
|
156
|
-
tokenResponse.data !== null &&
|
|
157
|
-
'RATE_LIMIT_USER' in tokenResponse.data
|
|
158
|
-
) {
|
|
159
|
-
console.log("rate limit user");
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// console.log("Checking login success condition:", {
|
|
163
|
-
// statusCode: tokenResponse?.statusCode,
|
|
164
|
-
// code: tokenResponse?.data?.code
|
|
165
|
-
// });
|
|
166
|
-
|
|
167
|
-
if (tokenResponse?.data?.code === "USER_LOGIN_SUCCESS") {
|
|
168
|
-
console.log("User login success");
|
|
169
|
-
this.fetchAndSetTheme();
|
|
170
|
-
return this._checkDeviceBinding(bank, module, WebViewCallbackFunction);
|
|
171
|
-
} else {
|
|
172
|
-
console.log("Login not successful. Token Response:", tokenResponse);
|
|
173
|
-
return Promise.resolve(<></>);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
} catch (e) {
|
|
177
|
-
console.error('Error during login:', e);
|
|
178
|
-
throw e;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private async _checkDeviceBinding(
|
|
108
|
+
bank: string,
|
|
109
|
+
url: string,
|
|
110
|
+
WebViewCallbackFunction: WebViewCallbackFunction
|
|
111
|
+
): Promise<React.ReactElement> {
|
|
112
|
+
// this._analyticsLogger.logEvent({
|
|
113
|
+
// event: 'REACT_NATIVE_DEVICE_BINDING_CALLED',
|
|
114
|
+
// });
|
|
115
|
+
|
|
116
|
+
console.log('SDK:LOG: entered in check device binding');
|
|
117
|
+
if (LibraryConstants.deviceBindingEnabled) {
|
|
118
|
+
// TODO: Build the device binding flow
|
|
119
|
+
return Promise.resolve(<></>);
|
|
120
|
+
} else {
|
|
121
|
+
console.log('SDK:LOG: calling setup device session');
|
|
122
|
+
|
|
123
|
+
return this._setupDeviceSession(bank, url, WebViewCallbackFunction);
|
|
182
124
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
ServiceNames.DEVICE_SESSION.params({ "partner": bank }),
|
|
205
|
-
{
|
|
206
|
-
body: {
|
|
207
|
-
[Constants.MANUFACTURER]: deviceInfo[Constants.MANUFACTURER],
|
|
208
|
-
[Constants.MODEL]: deviceInfo[Constants.MODEL],
|
|
209
|
-
[Constants.DEVICE_UUID]: deviceInfo[Constants.DEVICE_UUID],
|
|
210
|
-
[Constants.OS]: deviceInfo[Constants.OS],
|
|
211
|
-
[Constants.OS_VERSION]: deviceInfo[Constants.OS_VERSION],
|
|
212
|
-
[Constants.APP_VERSION]: appVersion,
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
);
|
|
216
|
-
//console.log("response from setup device session is : ", response)
|
|
217
|
-
if (
|
|
218
|
-
response &&
|
|
219
|
-
response.data &&
|
|
220
|
-
typeof response.data === 'object' &&
|
|
221
|
-
response.data !== null &&
|
|
222
|
-
'RATE_LIMIT_USER' in response.data
|
|
223
|
-
) {
|
|
224
|
-
console.log("rate limit user");
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
if (response?.status === 200) {
|
|
228
|
-
|
|
229
|
-
return this._openWebView(url, WebViewCallbackFunction);
|
|
230
|
-
} else {
|
|
231
|
-
console.warn('Error setting up device session:', response);
|
|
232
|
-
return this._openWebView(url, WebViewCallbackFunction);
|
|
233
|
-
}
|
|
234
|
-
} catch (e) {
|
|
235
|
-
console.error('Error setting up device session:', e);
|
|
236
|
-
throw e;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private async _loginAndNavigateToWebView(
|
|
128
|
+
module: string,
|
|
129
|
+
bank: string,
|
|
130
|
+
token: string,
|
|
131
|
+
WebViewCallbackFunction: WebViewCallbackFunction
|
|
132
|
+
): Promise<React.ReactElement> {
|
|
133
|
+
// console.log("PartnerLibrary._loginAndNavigateToWebView - LibraryConstants.hostName:", LibraryConstants.hostName);
|
|
134
|
+
try {
|
|
135
|
+
// this._analyticsLogger.logEvent({ event: 'REACT_NATIVE_LOGIN_FN_CALLED' });
|
|
136
|
+
let tokenResponse: any;
|
|
137
|
+
const url = ServiceNames.LOGIN_URL;
|
|
138
|
+
console.log('SDK:LOG: ', url);
|
|
139
|
+
tokenResponse = await this._apiCall.callAPI(
|
|
140
|
+
'POST',
|
|
141
|
+
ServiceNames.LOGIN_URL,
|
|
142
|
+
{
|
|
143
|
+
body: {
|
|
144
|
+
token: token,
|
|
145
|
+
},
|
|
237
146
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
147
|
+
);
|
|
148
|
+
// this._analyticsLogger.logEvent({
|
|
149
|
+
// event: 'REACT_NATIVE_LOGIN_FN_RESPONSE :',
|
|
150
|
+
// response: tokenResponse,
|
|
151
|
+
// });
|
|
152
|
+
|
|
153
|
+
if (tokenResponse?.data?.code === 'USER_TOKEN_EXPIRED') {
|
|
154
|
+
console.log('SDK:LOG Token expired');
|
|
155
|
+
return Promise.resolve(<></>);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (
|
|
159
|
+
tokenResponse &&
|
|
160
|
+
tokenResponse.data &&
|
|
161
|
+
typeof tokenResponse.data === 'object' &&
|
|
162
|
+
tokenResponse.data !== null &&
|
|
163
|
+
'RATE_LIMIT_USER' in tokenResponse.data
|
|
164
|
+
) {
|
|
165
|
+
console.log('SDK:LOG: rate limit user');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// console.log("Checking login success condition:", {
|
|
169
|
+
// statusCode: tokenResponse?.statusCode,
|
|
170
|
+
// code: tokenResponse?.data?.code
|
|
171
|
+
// });
|
|
172
|
+
|
|
173
|
+
if (tokenResponse?.data?.code === 'USER_LOGIN_SUCCESS') {
|
|
174
|
+
console.log('SDK:LOG: User login success');
|
|
175
|
+
this.fetchAndSetTheme();
|
|
176
|
+
return this._checkDeviceBinding(bank, module, WebViewCallbackFunction);
|
|
177
|
+
} else {
|
|
178
|
+
console.log(
|
|
179
|
+
'SDK:LOG: Login not successful. Token Response:',
|
|
180
|
+
tokenResponse
|
|
261
181
|
);
|
|
182
|
+
return Promise.resolve(<></>);
|
|
183
|
+
}
|
|
184
|
+
} catch (e) {
|
|
185
|
+
console.error('SDK:LOG: Error during login:', e);
|
|
186
|
+
throw e;
|
|
262
187
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
} catch (e) {
|
|
296
|
-
console.error("Error Fetching theme: ", e);
|
|
297
|
-
throw e;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
private async _setupDeviceSession(
|
|
191
|
+
bank: string,
|
|
192
|
+
url: string,
|
|
193
|
+
WebViewCallbackFunction: WebViewCallbackFunction
|
|
194
|
+
): Promise<React.ReactElement> {
|
|
195
|
+
try {
|
|
196
|
+
console.log('SDK:LOG: in setup device session');
|
|
197
|
+
|
|
198
|
+
const deviceInfo = await DeviceInfoManager.getDeviceInfo();
|
|
199
|
+
const appVersion = deviceInfo['app_version'] || 'unknown';
|
|
200
|
+
|
|
201
|
+
if (__DEV__) {
|
|
202
|
+
console.log('Device Info:', deviceInfo);
|
|
203
|
+
console.log('App Version:', appVersion);
|
|
204
|
+
}
|
|
205
|
+
console.log('SDK:LOG device uuid is ');
|
|
206
|
+
|
|
207
|
+
const response = await this._apiCall.callAPI(
|
|
208
|
+
'POST',
|
|
209
|
+
ServiceNames.DEVICE_SESSION.params({ partner: bank }),
|
|
210
|
+
{
|
|
211
|
+
body: {
|
|
212
|
+
[Constants.MANUFACTURER]: deviceInfo[Constants.MANUFACTURER],
|
|
213
|
+
[Constants.MODEL]: deviceInfo[Constants.MODEL],
|
|
214
|
+
[Constants.DEVICE_UUID]: deviceInfo[Constants.DEVICE_UUID],
|
|
215
|
+
[Constants.OS]: deviceInfo[Constants.OS],
|
|
216
|
+
[Constants.OS_VERSION]: deviceInfo[Constants.OS_VERSION],
|
|
217
|
+
[Constants.APP_VERSION]: appVersion,
|
|
218
|
+
},
|
|
298
219
|
}
|
|
220
|
+
);
|
|
221
|
+
//console.log("response from setup device session is : ", response)
|
|
222
|
+
if (
|
|
223
|
+
response &&
|
|
224
|
+
response.data &&
|
|
225
|
+
typeof response.data === 'object' &&
|
|
226
|
+
response.data !== null &&
|
|
227
|
+
'RATE_LIMIT_USER' in response.data
|
|
228
|
+
) {
|
|
229
|
+
console.log('SDK:LOG: rate limit user');
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (response?.status === 200) {
|
|
233
|
+
return this._openWebView(url, WebViewCallbackFunction);
|
|
234
|
+
} else {
|
|
235
|
+
console.warn('SDK:LOG: Error setting up device session:', response);
|
|
236
|
+
return this._openWebView(url, WebViewCallbackFunction);
|
|
237
|
+
}
|
|
238
|
+
} catch (e) {
|
|
239
|
+
console.error('SDK:LOG: Error setting up device session:', e);
|
|
240
|
+
throw e;
|
|
299
241
|
}
|
|
300
|
-
|
|
301
|
-
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
async _openWebView(
|
|
245
|
+
url: string,
|
|
246
|
+
WebViewCallbackFunction: WebViewCallbackFunction
|
|
247
|
+
): Promise<React.ReactElement> {
|
|
248
|
+
console.log('SDK:LOG: entered in open web view');
|
|
249
|
+
console.log('SDK:LOG: url is : ', LibraryConstants.hostName + url);
|
|
250
|
+
// this._analyticsLogger.logEvent({
|
|
251
|
+
// event: 'REACT_NATIVE_WEBVIEW_OPEN_CALLED',
|
|
252
|
+
// });
|
|
253
|
+
|
|
254
|
+
return (
|
|
255
|
+
<SafeAreaView style={{ flex: 1 }}>
|
|
256
|
+
<WebView
|
|
257
|
+
url={LibraryConstants.hostName + url}
|
|
258
|
+
onCallback={WebViewCallbackFunction}
|
|
259
|
+
whitelistedUrls={LibraryConstants.whitelistedDomains}
|
|
260
|
+
hostName={LibraryConstants.hostName}
|
|
261
|
+
onPageFinished={() =>
|
|
262
|
+
console.log('SDK:LOG: WebView page finished loading')
|
|
263
|
+
}
|
|
264
|
+
/>
|
|
265
|
+
</SafeAreaView>
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
async fetchAndSetTheme(): Promise<void> {
|
|
270
|
+
try {
|
|
271
|
+
console.log('SDK:LOG: Fetching theme from API');
|
|
272
|
+
|
|
273
|
+
const themeResponse: any = await this._apiCall.callAPI(
|
|
274
|
+
'GET',
|
|
275
|
+
ServiceNames.THEME_URL
|
|
276
|
+
);
|
|
277
|
+
const theme = themeResponse?.data;
|
|
278
|
+
|
|
279
|
+
if (theme && theme['--color-primary-500']) {
|
|
280
|
+
const rgbValues = theme['--color-primary-500'].split(' ').map(Number);
|
|
281
|
+
if (rgbValues.length === 3) {
|
|
282
|
+
const [r, g, b] = rgbValues;
|
|
283
|
+
|
|
284
|
+
// Update LibraryConstants color
|
|
285
|
+
LibraryConstants.setPrimaryColorFromRGB(r, g, b);
|
|
286
|
+
|
|
287
|
+
// Set status bar color
|
|
288
|
+
|
|
289
|
+
StatusBar.setBackgroundColor(LibraryConstants.primaryColor);
|
|
290
|
+
StatusBar.setBarStyle('light-content');
|
|
291
|
+
|
|
292
|
+
console.log(
|
|
293
|
+
'SDK:LOG: Theme color set successfully:',
|
|
294
|
+
LibraryConstants.primaryColor
|
|
295
|
+
);
|
|
296
|
+
} else {
|
|
297
|
+
console.warn('Invalid RGB values in theme response');
|
|
298
|
+
}
|
|
299
|
+
} else {
|
|
300
|
+
console.warn('--color-primary-500 not found in theme response');
|
|
301
|
+
}
|
|
302
|
+
} catch (e) {
|
|
303
|
+
console.error('Error Fetching theme: ', e);
|
|
304
|
+
throw e;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
package/src/helpers/webview.tsx
CHANGED
|
@@ -47,6 +47,14 @@ interface WebViewCustomProps {
|
|
|
47
47
|
whitelistedUrls?: string[];
|
|
48
48
|
onPageFinished?: () => void;
|
|
49
49
|
}
|
|
50
|
+
const clearAllCookies = async () => {
|
|
51
|
+
try {
|
|
52
|
+
await CookieManager.clearAll(true);
|
|
53
|
+
console.log('clearing cookies');
|
|
54
|
+
} catch (e) {
|
|
55
|
+
console.error('Failed to clear cookies:', e);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
50
58
|
|
|
51
59
|
export const WebView = ({
|
|
52
60
|
url,
|
|
@@ -81,18 +89,32 @@ export const WebView = ({
|
|
|
81
89
|
};
|
|
82
90
|
const showToast_with_code_message = (syntheticEvent: any) => {
|
|
83
91
|
const { nativeEvent } = syntheticEvent;
|
|
84
|
-
const errorCodesToHandle = [-6, -8, -10];
|
|
92
|
+
const errorCodesToHandle = [-2, -6, -8, -10];
|
|
85
93
|
if (errorCodesToHandle.includes(nativeEvent.code)) {
|
|
86
94
|
const message = `WebView Error: [${nativeEvent.code}] ${nativeEvent.description}`;
|
|
87
95
|
setToast({ visible: true, message });
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
ToastAndroid.
|
|
92
|
-
|
|
96
|
+
|
|
97
|
+
if (nativeEvent.code === -2) {
|
|
98
|
+
if (Platform.OS === 'android') {
|
|
99
|
+
ToastAndroid.show(
|
|
100
|
+
'There seems to be a network issue. Please try again.',
|
|
101
|
+
ToastAndroid.LONG
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
clearAllCookies();
|
|
105
|
+
onCallback?.(WebViewCallback.redirect('WEBVIEW_ERROR'));
|
|
106
|
+
} else {
|
|
107
|
+
if (Platform.OS === 'android') {
|
|
108
|
+
ToastAndroid.show(
|
|
109
|
+
'Oops! Something went wrong. Please try again.',
|
|
110
|
+
ToastAndroid.LONG
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
clearAllCookies();
|
|
114
|
+
onCallback?.(WebViewCallback.redirect('WEBVIEW_ERROR'));
|
|
93
115
|
}
|
|
94
|
-
|
|
95
|
-
|
|
116
|
+
|
|
117
|
+
setTimeout(() => setToast(null), 6000);
|
|
96
118
|
}
|
|
97
119
|
};
|
|
98
120
|
|
|
@@ -196,9 +218,18 @@ export const WebView = ({
|
|
|
196
218
|
// });
|
|
197
219
|
|
|
198
220
|
StatusBar.setBackgroundColor('#7E7E7EFF');
|
|
221
|
+
clearAllCookies();
|
|
199
222
|
onCallback?.(WebViewCallback.redirect(status ?? undefined));
|
|
200
223
|
return false;
|
|
201
224
|
}
|
|
225
|
+
if (url?.includes('/api/user/redirect')) {
|
|
226
|
+
console.log('overriding redirect url');
|
|
227
|
+
|
|
228
|
+
StatusBar.setBackgroundColor('#7E7E7EFF');
|
|
229
|
+
clearAllCookies();
|
|
230
|
+
onCallback?.(WebViewCallback.redirect('SESSION_EXPIRED'));
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
202
233
|
|
|
203
234
|
// Handle whitelisted URLs
|
|
204
235
|
const isWhitelisted =
|
|
@@ -331,10 +362,6 @@ export const WebView = ({
|
|
|
331
362
|
|
|
332
363
|
const handleWebViewLoadEnd = (syntheticEvent: any) => {
|
|
333
364
|
const loadedUrl = syntheticEvent?.nativeEvent?.url || url;
|
|
334
|
-
// _analyticsLogger.logEvent({
|
|
335
|
-
// event: 'REACT_NATIVE_WEBVIEW_LOADED',
|
|
336
|
-
// url: loadedUrl,
|
|
337
|
-
// });
|
|
338
365
|
|
|
339
366
|
onPageFinished?.();
|
|
340
367
|
};
|