@glomopay/react-native-sdk 2.0.1 → 3.0.1

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.
Files changed (71) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +261 -314
  3. package/lib/config/base.d.ts +17 -11
  4. package/lib/config/base.d.ts.map +1 -1
  5. package/lib/config/base.js +19 -7
  6. package/lib/config/segment.js +3 -3
  7. package/lib/glomo-checkout.d.ts +8 -0
  8. package/lib/glomo-checkout.d.ts.map +1 -0
  9. package/lib/glomo-checkout.js +69 -0
  10. package/lib/glomo-lrs-checkout.d.ts.map +1 -1
  11. package/lib/glomo-lrs-checkout.js +9 -9
  12. package/lib/glomo-standard-checkout.d.ts +5 -0
  13. package/lib/glomo-standard-checkout.d.ts.map +1 -0
  14. package/lib/glomo-standard-checkout.js +218 -0
  15. package/lib/index.d.ts +5 -4
  16. package/lib/index.d.ts.map +1 -1
  17. package/lib/index.js +7 -5
  18. package/lib/injections/index.d.ts +1 -0
  19. package/lib/injections/index.d.ts.map +1 -1
  20. package/lib/injections/index.js +2 -0
  21. package/lib/injections/webview-flow.injection.d.ts.map +1 -1
  22. package/lib/injections/webview-flow.injection.js +106 -69
  23. package/lib/injections/webview-main.injection.d.ts.map +1 -1
  24. package/lib/injections/webview-main.injection.js +112 -77
  25. package/lib/injections/webview-standard.injection.d.ts +3 -0
  26. package/lib/injections/webview-standard.injection.d.ts.map +1 -0
  27. package/lib/injections/webview-standard.injection.js +214 -0
  28. package/lib/services/order-type-fetcher.d.ts +28 -0
  29. package/lib/services/order-type-fetcher.d.ts.map +1 -0
  30. package/lib/services/order-type-fetcher.js +99 -0
  31. package/lib/types/checkout.d.ts +53 -0
  32. package/lib/types/checkout.d.ts.map +1 -0
  33. package/lib/types/checkout.js +3 -0
  34. package/lib/types/standard-checkout.d.ts +40 -0
  35. package/lib/types/standard-checkout.d.ts.map +1 -0
  36. package/lib/types/standard-checkout.js +3 -0
  37. package/lib/use-glomo-checkout.d.ts +24 -0
  38. package/lib/use-glomo-checkout.d.ts.map +1 -0
  39. package/lib/use-glomo-checkout.js +182 -0
  40. package/lib/use-lrs-checkout.d.ts +9 -4
  41. package/lib/use-lrs-checkout.d.ts.map +1 -1
  42. package/lib/use-lrs-checkout.js +91 -93
  43. package/lib/use-standard-checkout.d.ts +65 -0
  44. package/lib/use-standard-checkout.d.ts.map +1 -0
  45. package/lib/use-standard-checkout.js +832 -0
  46. package/lib/utils/analytics.d.ts +102 -1
  47. package/lib/utils/analytics.d.ts.map +1 -1
  48. package/lib/utils/analytics.js +294 -21
  49. package/lib/utils/device-compliance.js +3 -3
  50. package/lib/utils/validation.d.ts.map +1 -1
  51. package/lib/utils/validation.js +7 -6
  52. package/package.json +3 -2
  53. package/src/config/base.ts +36 -17
  54. package/src/config/segment.ts +3 -3
  55. package/src/glomo-checkout.tsx +73 -0
  56. package/src/glomo-lrs-checkout.tsx +13 -10
  57. package/src/glomo-standard-checkout.tsx +324 -0
  58. package/src/index.ts +13 -7
  59. package/src/injections/index.ts +2 -0
  60. package/src/injections/webview-flow.injection.ts +106 -69
  61. package/src/injections/webview-main.injection.ts +112 -77
  62. package/src/injections/webview-standard.injection.ts +211 -0
  63. package/src/services/order-type-fetcher.ts +86 -0
  64. package/src/types/checkout.ts +65 -0
  65. package/src/types/standard-checkout.ts +49 -0
  66. package/src/use-glomo-checkout.tsx +228 -0
  67. package/src/use-lrs-checkout.tsx +115 -111
  68. package/src/use-standard-checkout.tsx +1185 -0
  69. package/src/utils/analytics.ts +431 -22
  70. package/src/utils/device-compliance.ts +3 -3
  71. package/src/utils/validation.ts +7 -8
@@ -1,114 +1,149 @@
1
1
  /** Injection JavaScript for the Secondary WebView */
2
2
  export const injectedScript: string = `
3
3
  (function() {
4
- // Overriding console methods
4
+ // Log prefix for all messages originating from the flow WebView
5
+ const LOG_PREFIX = 'FLOW_WEBVIEW: ';
6
+
7
+ /**
8
+ * Formats an array of arguments into a single prefixed string for posting back to React Native.
9
+ * Objects are JSON-stringified; primitives are coerced to strings.
10
+ */
11
+ function formatMessage(args) {
12
+ return args.map(function(arg) {
13
+ if (typeof arg === 'object') {
14
+ try {
15
+ return LOG_PREFIX + JSON.stringify(arg, null, 2);
16
+ } catch (error) {
17
+ return LOG_PREFIX + '[unserializable object]';
18
+ }
19
+ }
20
+ return LOG_PREFIX + String(arg);
21
+ }).join(' ');
22
+ }
23
+
24
+ // Saving original console methods before overriding (must be declared before safePostMessage references them)
5
25
  const originalLog = console.log;
6
26
  const originalWarn = console.warn;
7
27
  const originalError = console.error;
8
28
  const originalInfo = console.info;
9
-
29
+
30
+ /**
31
+ * Safely posts a message to ReactNativeWebView with a guard check.
32
+ * Prevents crashes if the WebView bridge is not yet ready or has been torn down.
33
+ */
34
+ function safePostMessage(payload) {
35
+ try {
36
+ if (window.ReactNativeWebView && typeof window.ReactNativeWebView.postMessage === 'function') {
37
+ window.ReactNativeWebView.postMessage(JSON.stringify(payload));
38
+ }
39
+ } catch (error) {
40
+ originalError && originalError.call(console, LOG_PREFIX + 'Failed to post message to ReactNativeWebView', error);
41
+ }
42
+ }
43
+
44
+ // Overriding console methods to forward logs back to React Native
10
45
  console.log = function(...args) {
11
46
  originalLog.apply(console, args);
12
- window.ReactNativeWebView.postMessage(JSON.stringify({
47
+ safePostMessage({
13
48
  type: 'console',
14
49
  level: 'log',
15
- message: args.map(a => typeof a === 'object' ? "FLOW_WEBVIEW: " + JSON.stringify(a, null, 2) : "FLOW_WEBVIEW: " + String(a)).join(' ')
16
- }));
50
+ message: formatMessage(args)
51
+ });
17
52
  };
18
-
53
+
19
54
  console.warn = function(...args) {
20
55
  originalWarn.apply(console, args);
21
- window.ReactNativeWebView.postMessage(JSON.stringify({
56
+ safePostMessage({
22
57
  type: 'console',
23
58
  level: 'warn',
24
- message: args.map(a => typeof a === 'object' ? "FLOW_WEBVIEW: " + JSON.stringify(a, null, 2) : "FLOW_WEBVIEW: " + String(a)).join(' ')
25
- }));
59
+ message: formatMessage(args)
60
+ });
26
61
  };
27
-
62
+
28
63
  console.error = function(...args) {
29
64
  originalError.apply(console, args);
30
- window.ReactNativeWebView.postMessage(JSON.stringify({
65
+ safePostMessage({
31
66
  type: 'console',
32
67
  level: 'error',
33
- message: args.map(a => typeof a === 'object' ? "FLOW_WEBVIEW: " + JSON.stringify(a, null, 2) : "FLOW_WEBVIEW: " + String(a)).join(' ')
34
- }));
68
+ message: formatMessage(args)
69
+ });
35
70
  };
36
-
71
+
37
72
  console.info = function(...args) {
38
73
  originalInfo.apply(console, args);
39
- window.ReactNativeWebView.postMessage(JSON.stringify({
74
+ safePostMessage({
40
75
  type: 'console',
41
76
  level: 'info',
42
- message: args.map(a => typeof a === 'object' ? "FLOW_WEBVIEW: " + JSON.stringify(a, null, 2) : "FLOW_WEBVIEW: " + String(a)).join(' ')
43
- }));
77
+ message: formatMessage(args)
78
+ });
44
79
  };
45
-
46
- // Intercepting fetch requests
80
+
81
+ // Intercepting fetch requests to log network activity
47
82
  const originalFetch = window.fetch;
48
83
  window.fetch = function(...args) {
49
84
  const url = typeof args[0] === 'string' ? args[0] : args[0]?.url || 'Unknown URL';
50
- window.ReactNativeWebView.postMessage(JSON.stringify({
85
+ safePostMessage({
51
86
  type: 'console',
52
87
  level: 'network',
53
- message: "FLOW_WEBVIEW: " + 'FETCH REQUEST: ' + url
54
- }));
55
-
88
+ message: LOG_PREFIX + 'FETCH REQUEST: ' + url
89
+ });
90
+
56
91
  return originalFetch.apply(this, args)
57
92
  .then(response => {
58
- window.ReactNativeWebView.postMessage(JSON.stringify({
59
- type: 'console',
60
- level: 'network',
61
- message: "FLOW_WEBVIEW: " + 'FETCH RESPONSE: ' + url + ' - Status: ' + response.status
62
- }));
93
+ safePostMessage({
94
+ type: 'console',
95
+ level: 'network',
96
+ message: LOG_PREFIX + 'FETCH RESPONSE: ' + url + ' - Status: ' + response.status
97
+ });
63
98
  return response;
64
99
  })
65
100
  .catch(error => {
66
- window.ReactNativeWebView.postMessage(JSON.stringify({
101
+ safePostMessage({
67
102
  type: 'console',
68
103
  level: 'error',
69
- message: "FLOW_WEBVIEW: " + 'FETCH ERROR: ' + url + ' - ' + error.message
70
- }));
104
+ message: LOG_PREFIX + 'FETCH ERROR: ' + url + ' - ' + error.message
105
+ });
71
106
  throw error;
72
107
  });
73
108
  };
74
-
75
- // Intercepting XMLHttpRequest
109
+
110
+ // Intercepting XMLHttpRequest to log network activity
76
111
  const originalOpen = XMLHttpRequest.prototype.open;
77
112
  const originalSend = XMLHttpRequest.prototype.send;
78
-
113
+
79
114
  XMLHttpRequest.prototype.open = function(method, url) {
80
115
  this._url = url;
81
116
  this._method = method;
82
117
  return originalOpen.apply(this, arguments);
83
118
  };
84
-
119
+
85
120
  XMLHttpRequest.prototype.send = function() {
86
- window.ReactNativeWebView.postMessage(JSON.stringify({
121
+ safePostMessage({
87
122
  type: 'console',
88
123
  level: 'network',
89
- message: "FLOW_WEBVIEW: " + 'XHR REQUEST: ' + this._method + ' ' + this._url
90
- }));
91
-
124
+ message: LOG_PREFIX + 'XHR REQUEST: ' + this._method + ' ' + this._url
125
+ });
126
+
92
127
  this.addEventListener('load', function() {
93
- window.ReactNativeWebView.postMessage(JSON.stringify({
94
- type: 'console',
95
- level: 'network',
96
- message: "FLOW_WEBVIEW: " + 'XHR RESPONSE: ' + this._url + ' - Status: ' + this.status
97
- }));
128
+ safePostMessage({
129
+ type: 'console',
130
+ level: 'network',
131
+ message: LOG_PREFIX + 'XHR RESPONSE: ' + this._url + ' - Status: ' + this.status
132
+ });
98
133
  });
99
-
134
+
100
135
  this.addEventListener('error', function() {
101
- window.ReactNativeWebView.postMessage(JSON.stringify({
136
+ safePostMessage({
102
137
  type: 'console',
103
138
  level: 'error',
104
- message: "FLOW_WEBVIEW: " + 'XHR ERROR: ' + this._url
105
- }));
139
+ message: LOG_PREFIX + 'XHR ERROR: ' + this._url
140
+ });
106
141
  });
107
-
142
+
108
143
  return originalSend.apply(this, arguments);
109
144
  };
110
-
111
- // Intercepting programmatic form.submit() force target="_blank" to "_self"
145
+
146
+ // Intercepting programmatic form.submit() - force target="_blank" to "_self"
112
147
  // This prevents forms from trying to open new windows (which fail silently in WebView)
113
148
  const originalSubmit = HTMLFormElement.prototype.submit;
114
149
  HTMLFormElement.prototype.submit = function() {
@@ -121,54 +156,56 @@ export const injectedScript: string = `
121
156
  // Intercepting window.open
122
157
  const originalWindowOpen = window.open;
123
158
  window.open = function(url, target, features) {
124
- window.ReactNativeWebView.postMessage(JSON.stringify({
159
+ safePostMessage({
125
160
  type: 'window.open',
126
161
  url: url,
127
162
  target: target,
128
163
  features: features
129
- }));
130
-
131
- // Returning a dummy window object to prevent JS errors
164
+ });
165
+
166
+ // Returning a mock window object to prevent JS errors
132
167
  return {
133
168
  closed: false,
134
169
  close: function() {
135
- window.ReactNativeWebView.postMessage(JSON.stringify({
170
+ safePostMessage({
136
171
  type: 'window.close'
137
- }));
172
+ });
138
173
  },
139
174
  focus: function() {},
140
175
  blur: function() {}
141
176
  };
142
177
  };
143
-
178
+
144
179
  // Listening for unhandled errors
145
180
  window.addEventListener('error', function(event) {
146
- window.ReactNativeWebView.postMessage(JSON.stringify({
181
+ safePostMessage({
147
182
  type: 'console',
148
183
  level: 'error',
149
- message: "FLOW_WEBVIEW: " + 'Unhandled Error: ' + event.message + ' at ' + event.filename + ':' + event.lineno
150
- }));
184
+ message: LOG_PREFIX + 'Unhandled Error: ' + event.message + ' at ' + event.filename + ':' + event.lineno
185
+ });
151
186
  });
152
-
187
+
153
188
  // Listening for unhandled promise rejections
154
189
  window.addEventListener('unhandledrejection', function(event) {
155
- window.ReactNativeWebView.postMessage(JSON.stringify({
190
+ safePostMessage({
156
191
  type: 'console',
157
192
  level: 'error',
158
- message: "FLOW_WEBVIEW: " + 'Unhandled Promise Rejection: ' + (event.reason?.toString() || 'Unknown')
159
- }));
193
+ message: LOG_PREFIX + 'Unhandled Promise Rejection: ' + (event.reason?.toString() || 'Unknown')
194
+ });
160
195
  });
161
196
 
162
197
  // Listening for messages from the WebView
163
198
  window.addEventListener('message', function(event) {
164
- console.log("FLOW_WEBVIEW: " + 'Message received: ' + event.data);
165
- window.ReactNativeWebView.postMessage(JSON.stringify({
199
+ console.log(LOG_PREFIX + 'Message received: ' + event.data);
200
+ safePostMessage({
166
201
  type: 'message',
167
202
  message: event.data
168
- }));
203
+ });
169
204
  });
170
205
 
171
206
  // Logging that injection is complete
172
- console.log("FLOW_WEBVIEW: " + 'GlomoPay WebView JavaScript injection complete');
207
+ console.log(LOG_PREFIX + 'GlomoPay WebView JavaScript injection complete');
208
+
209
+ true; // Required for injected JavaScript
173
210
  })();
174
211
  `;
@@ -1,182 +1,217 @@
1
1
  /** Injection JavaScript for the Primary WebView */
2
2
  export const injectedScript: string = `
3
3
  (function() {
4
- // Overriding console methods
4
+ // Log prefix for all messages originating from the main WebView
5
+ const LOG_PREFIX = 'MAIN_WEBVIEW: ';
6
+
7
+ /**
8
+ * Formats an array of arguments into a single prefixed string for posting back to React Native.
9
+ * Objects are JSON-stringified; primitives are coerced to strings.
10
+ */
11
+ function formatMessage(args) {
12
+ return args.map(function(arg) {
13
+ if (typeof arg === 'object') {
14
+ try {
15
+ return LOG_PREFIX + JSON.stringify(arg, null, 2);
16
+ } catch (error) {
17
+ return LOG_PREFIX + '[unserializable object]';
18
+ }
19
+ }
20
+ return LOG_PREFIX + String(arg);
21
+ }).join(' ');
22
+ }
23
+
24
+ // Saving original console methods before overriding (must be declared before safePostMessage references them)
5
25
  const originalLog = console.log;
6
26
  const originalWarn = console.warn;
7
27
  const originalError = console.error;
8
28
  const originalInfo = console.info;
9
-
29
+
30
+ /**
31
+ * Safely posts a message to ReactNativeWebView with a guard check.
32
+ * Prevents crashes if the WebView bridge is not yet ready or has been torn down.
33
+ */
34
+ function safePostMessage(payload) {
35
+ try {
36
+ if (window.ReactNativeWebView && typeof window.ReactNativeWebView.postMessage === 'function') {
37
+ window.ReactNativeWebView.postMessage(JSON.stringify(payload));
38
+ }
39
+ } catch (error) {
40
+ originalError && originalError.call(console, LOG_PREFIX + 'Failed to post message to ReactNativeWebView', error);
41
+ }
42
+ }
43
+
44
+ // Overriding console methods to forward logs back to React Native
10
45
  console.log = function(...args) {
11
46
  originalLog.apply(console, args);
12
- window.ReactNativeWebView.postMessage(JSON.stringify({
47
+ safePostMessage({
13
48
  type: 'console',
14
49
  level: 'log',
15
- message: args.map(a => typeof a === 'object' ? JSON.stringify(a, null, 2) : String(a)).join(' ')
16
- }));
50
+ message: formatMessage(args)
51
+ });
17
52
  };
18
-
53
+
19
54
  console.warn = function(...args) {
20
55
  originalWarn.apply(console, args);
21
- window.ReactNativeWebView.postMessage(JSON.stringify({
56
+ safePostMessage({
22
57
  type: 'console',
23
58
  level: 'warn',
24
- message: args.map(a => typeof a === 'object' ? JSON.stringify(a, null, 2) : String(a)).join(' ')
25
- }));
59
+ message: formatMessage(args)
60
+ });
26
61
  };
27
-
62
+
28
63
  console.error = function(...args) {
29
64
  originalError.apply(console, args);
30
- window.ReactNativeWebView.postMessage(JSON.stringify({
65
+ safePostMessage({
31
66
  type: 'console',
32
67
  level: 'error',
33
- message: args.map(a => typeof a === 'object' ? JSON.stringify(a, null, 2) : String(a)).join(' ')
34
- }));
68
+ message: formatMessage(args)
69
+ });
35
70
  };
36
-
71
+
37
72
  console.info = function(...args) {
38
73
  originalInfo.apply(console, args);
39
- window.ReactNativeWebView.postMessage(JSON.stringify({
74
+ safePostMessage({
40
75
  type: 'console',
41
76
  level: 'info',
42
- message: args.map(a => typeof a === 'object' ? JSON.stringify(a, null, 2) : String(a)).join(' ')
43
- }));
77
+ message: formatMessage(args)
78
+ });
44
79
  };
45
-
46
- // Intercepting fetch requests
80
+
81
+ // Intercepting fetch requests to log network activity
47
82
  const originalFetch = window.fetch;
48
83
  window.fetch = function(...args) {
49
84
  const url = typeof args[0] === 'string' ? args[0] : args[0]?.url || 'Unknown URL';
50
- window.ReactNativeWebView.postMessage(JSON.stringify({
85
+ safePostMessage({
51
86
  type: 'console',
52
87
  level: 'network',
53
- message: 'FETCH REQUEST: ' + url
54
- }));
55
-
88
+ message: LOG_PREFIX + 'FETCH REQUEST: ' + url
89
+ });
90
+
56
91
  return originalFetch.apply(this, args)
57
92
  .then(response => {
58
- window.ReactNativeWebView.postMessage(JSON.stringify({
59
- type: 'console',
60
- level: 'network',
61
- message: 'FETCH RESPONSE: ' + url + ' - Status: ' + response.status
62
- }));
93
+ safePostMessage({
94
+ type: 'console',
95
+ level: 'network',
96
+ message: LOG_PREFIX + 'FETCH RESPONSE: ' + url + ' - Status: ' + response.status
97
+ });
63
98
  return response;
64
99
  })
65
100
  .catch(error => {
66
- window.ReactNativeWebView.postMessage(JSON.stringify({
101
+ safePostMessage({
67
102
  type: 'console',
68
103
  level: 'error',
69
- message: 'FETCH ERROR: ' + url + ' - ' + error.message
70
- }));
104
+ message: LOG_PREFIX + 'FETCH ERROR: ' + url + ' - ' + error.message
105
+ });
71
106
  throw error;
72
107
  });
73
108
  };
74
-
75
- // Intercepting XMLHttpRequest
109
+
110
+ // Intercepting XMLHttpRequest to log network activity
76
111
  const originalOpen = XMLHttpRequest.prototype.open;
77
112
  const originalSend = XMLHttpRequest.prototype.send;
78
-
113
+
79
114
  XMLHttpRequest.prototype.open = function(method, url) {
80
115
  this._url = url;
81
116
  this._method = method;
82
117
  return originalOpen.apply(this, arguments);
83
118
  };
84
-
119
+
85
120
  XMLHttpRequest.prototype.send = function() {
86
- window.ReactNativeWebView.postMessage(JSON.stringify({
121
+ safePostMessage({
87
122
  type: 'console',
88
123
  level: 'network',
89
- message: 'XHR REQUEST: ' + this._method + ' ' + this._url
90
- }));
91
-
124
+ message: LOG_PREFIX + 'XHR REQUEST: ' + this._method + ' ' + this._url
125
+ });
126
+
92
127
  this.addEventListener('load', function() {
93
128
  try {
94
- window.ReactNativeWebView.postMessage(JSON.stringify({
95
- type: 'console',
96
- level: 'network',
97
- message: 'XHR RESPONSE LOAD: ' + this._url + ' - Status: ' + this.status
98
- }));
129
+ safePostMessage({
130
+ type: 'console',
131
+ level: 'network',
132
+ message: LOG_PREFIX + 'XHR RESPONSE LOAD: ' + this._url + ' - Status: ' + this.status
133
+ });
99
134
  } catch (e) {
100
- window.ReactNativeWebView.postMessage(JSON.stringify({
135
+ safePostMessage({
101
136
  type: 'console',
102
137
  level: 'network',
103
- message: 'XHR RESPONSE ERROR: ' + this._url + ' - Status: ' + this.status
104
- }));
138
+ message: LOG_PREFIX + 'XHR RESPONSE ERROR: ' + this._url + ' - Status: ' + this.status
139
+ });
105
140
  }
106
141
  });
107
-
142
+
108
143
  this.addEventListener('error', function() {
109
- window.ReactNativeWebView.postMessage(JSON.stringify({
144
+ safePostMessage({
110
145
  type: 'console',
111
146
  level: 'error',
112
- message: 'XHR ERROR: ' + this._url
113
- }));
147
+ message: LOG_PREFIX + 'XHR ERROR: ' + this._url
148
+ });
114
149
  });
115
-
150
+
116
151
  return originalSend.apply(this, arguments);
117
152
  };
118
-
153
+
119
154
  // Intercepting window.open
120
155
  const originalWindowOpen = window.open;
121
156
  window.open = function(url, target, features) {
122
- window.ReactNativeWebView.postMessage(JSON.stringify({
157
+ safePostMessage({
123
158
  type: 'window.open',
124
159
  url: url,
125
160
  target: target,
126
161
  features: features
127
- }));
128
-
129
- // Returning a dummy window object to prevent JS errors
162
+ });
163
+
164
+ // Returning a mock window object to prevent JS errors
130
165
  return {
131
166
  closed: false,
132
167
  close: function() {
133
- window.ReactNativeWebView.postMessage(JSON.stringify({
168
+ safePostMessage({
134
169
  type: 'window.close'
135
- }));
170
+ });
136
171
  },
137
172
  focus: function() {
138
- window.ReactNativeWebView.postMessage(JSON.stringify({
173
+ safePostMessage({
139
174
  type: 'window.focus'
140
- }));
175
+ });
141
176
  },
142
177
  blur: function() {
143
- window.ReactNativeWebView.postMessage(JSON.stringify({
178
+ safePostMessage({
144
179
  type: 'window.blur'
145
- }));
180
+ });
146
181
  }
147
182
  };
148
183
  };
149
-
184
+
150
185
  // Listening for unhandled errors
151
186
  window.addEventListener('error', function(event) {
152
- window.ReactNativeWebView.postMessage(JSON.stringify({
187
+ safePostMessage({
153
188
  type: 'console',
154
189
  level: 'error',
155
- message: 'Unhandled Error: ' + event.message + ' at ' + event.filename + ':' + event.lineno
156
- }));
190
+ message: LOG_PREFIX + 'Unhandled Error: ' + event.message + ' at ' + event.filename + ':' + event.lineno
191
+ });
157
192
  });
158
-
193
+
159
194
  // Listening for unhandled promise rejections
160
195
  window.addEventListener('unhandledrejection', function(event) {
161
- window.ReactNativeWebView.postMessage(JSON.stringify({
196
+ safePostMessage({
162
197
  type: 'console',
163
198
  level: 'error',
164
- message: 'Unhandled Promise Rejection: ' + (event.reason?.toString() || 'Unknown')
165
- }));
199
+ message: LOG_PREFIX + 'Unhandled Promise Rejection: ' + (event.reason?.toString() || 'Unknown')
200
+ });
166
201
  });
167
202
 
168
203
  // Listening for messages from the WebView
169
204
  window.addEventListener('message', function(event) {
170
- console.log("MAIN_WEBVIEW: " + 'Message received: ' + event.data);
171
- window.ReactNativeWebView.postMessage(JSON.stringify({
205
+ console.log(LOG_PREFIX + 'Message received: ' + event.data);
206
+ safePostMessage({
172
207
  type: 'message',
173
208
  message: event.data
174
- }));
209
+ });
175
210
  });
176
-
211
+
177
212
  // Logging that injection is complete
178
- console.log('GlomoPay WebView JavaScript injection complete');
179
-
213
+ console.log(LOG_PREFIX + 'GlomoPay WebView JavaScript injection complete');
214
+
180
215
  true; // Required for injected JavaScript
181
216
  })();
182
217
  `;