@reown/appkit-core-react-native 2.0.0-alpha.6 → 2.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 (116) hide show
  1. package/lib/commonjs/controllers/ApiController.js +19 -8
  2. package/lib/commonjs/controllers/ApiController.js.map +1 -1
  3. package/lib/commonjs/controllers/BlockchainApiController.js +31 -28
  4. package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
  5. package/lib/commonjs/controllers/ConnectionsController.js +10 -0
  6. package/lib/commonjs/controllers/ConnectionsController.js.map +1 -1
  7. package/lib/commonjs/controllers/EnsController.js +2 -0
  8. package/lib/commonjs/controllers/EnsController.js.map +1 -1
  9. package/lib/commonjs/controllers/EventsController.js +51 -1
  10. package/lib/commonjs/controllers/EventsController.js.map +1 -1
  11. package/lib/commonjs/controllers/LogController.js +188 -0
  12. package/lib/commonjs/controllers/LogController.js.map +1 -0
  13. package/lib/commonjs/controllers/OnRampController.js +14 -0
  14. package/lib/commonjs/controllers/OnRampController.js.map +1 -1
  15. package/lib/commonjs/controllers/SendController.js +4 -2
  16. package/lib/commonjs/controllers/SendController.js.map +1 -1
  17. package/lib/commonjs/controllers/SwapController.js +10 -2
  18. package/lib/commonjs/controllers/SwapController.js.map +1 -1
  19. package/lib/commonjs/controllers/TransactionsController.js +2 -0
  20. package/lib/commonjs/controllers/TransactionsController.js.map +1 -1
  21. package/lib/commonjs/features/reown-authentication/ReownAuthentication.js +14 -6
  22. package/lib/commonjs/features/reown-authentication/ReownAuthentication.js.map +1 -1
  23. package/lib/commonjs/index.js +14 -0
  24. package/lib/commonjs/index.js.map +1 -1
  25. package/lib/commonjs/utils/ApiUtil.js +1 -1
  26. package/lib/commonjs/utils/ApiUtil.js.map +1 -1
  27. package/lib/commonjs/utils/ConstantsUtil.js +0 -1
  28. package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
  29. package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -1
  30. package/lib/commonjs/utils/FetchUtil.js +7 -2
  31. package/lib/commonjs/utils/FetchUtil.js.map +1 -1
  32. package/lib/commonjs/utils/LogUtils.js +131 -0
  33. package/lib/commonjs/utils/LogUtils.js.map +1 -0
  34. package/lib/commonjs/utils/StorageUtil.js +48 -49
  35. package/lib/commonjs/utils/StorageUtil.js.map +1 -1
  36. package/lib/module/controllers/ApiController.js +19 -8
  37. package/lib/module/controllers/ApiController.js.map +1 -1
  38. package/lib/module/controllers/BlockchainApiController.js +31 -28
  39. package/lib/module/controllers/BlockchainApiController.js.map +1 -1
  40. package/lib/module/controllers/ConnectionsController.js +10 -0
  41. package/lib/module/controllers/ConnectionsController.js.map +1 -1
  42. package/lib/module/controllers/EnsController.js +2 -0
  43. package/lib/module/controllers/EnsController.js.map +1 -1
  44. package/lib/module/controllers/EventsController.js +51 -1
  45. package/lib/module/controllers/EventsController.js.map +1 -1
  46. package/lib/module/controllers/LogController.js +185 -0
  47. package/lib/module/controllers/LogController.js.map +1 -0
  48. package/lib/module/controllers/OnRampController.js +14 -0
  49. package/lib/module/controllers/OnRampController.js.map +1 -1
  50. package/lib/module/controllers/SendController.js +4 -2
  51. package/lib/module/controllers/SendController.js.map +1 -1
  52. package/lib/module/controllers/SwapController.js +10 -2
  53. package/lib/module/controllers/SwapController.js.map +1 -1
  54. package/lib/module/controllers/TransactionsController.js +2 -0
  55. package/lib/module/controllers/TransactionsController.js.map +1 -1
  56. package/lib/module/features/reown-authentication/ReownAuthentication.js +14 -6
  57. package/lib/module/features/reown-authentication/ReownAuthentication.js.map +1 -1
  58. package/lib/module/index.js +2 -0
  59. package/lib/module/index.js.map +1 -1
  60. package/lib/module/utils/ApiUtil.js +1 -1
  61. package/lib/module/utils/ApiUtil.js.map +1 -1
  62. package/lib/module/utils/ConstantsUtil.js +0 -1
  63. package/lib/module/utils/ConstantsUtil.js.map +1 -1
  64. package/lib/module/utils/CoreHelperUtil.js.map +1 -1
  65. package/lib/module/utils/FetchUtil.js +8 -2
  66. package/lib/module/utils/FetchUtil.js.map +1 -1
  67. package/lib/module/utils/LogUtils.js +121 -0
  68. package/lib/module/utils/LogUtils.js.map +1 -0
  69. package/lib/module/utils/StorageUtil.js +48 -49
  70. package/lib/module/utils/StorageUtil.js.map +1 -1
  71. package/lib/typescript/controllers/ApiController.d.ts +6 -4
  72. package/lib/typescript/controllers/ApiController.d.ts.map +1 -1
  73. package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -1
  74. package/lib/typescript/controllers/ConnectionsController.d.ts +1 -0
  75. package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -1
  76. package/lib/typescript/controllers/EnsController.d.ts.map +1 -1
  77. package/lib/typescript/controllers/EventsController.d.ts +13 -1
  78. package/lib/typescript/controllers/EventsController.d.ts.map +1 -1
  79. package/lib/typescript/controllers/LogController.d.ts +65 -0
  80. package/lib/typescript/controllers/LogController.d.ts.map +1 -0
  81. package/lib/typescript/controllers/OnRampController.d.ts.map +1 -1
  82. package/lib/typescript/controllers/SendController.d.ts.map +1 -1
  83. package/lib/typescript/controllers/SwapController.d.ts.map +1 -1
  84. package/lib/typescript/controllers/TransactionsController.d.ts.map +1 -1
  85. package/lib/typescript/features/reown-authentication/ReownAuthentication.d.ts.map +1 -1
  86. package/lib/typescript/index.d.ts +2 -0
  87. package/lib/typescript/index.d.ts.map +1 -1
  88. package/lib/typescript/utils/ApiUtil.d.ts +1 -1
  89. package/lib/typescript/utils/ConstantsUtil.d.ts +0 -1
  90. package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
  91. package/lib/typescript/utils/CoreHelperUtil.d.ts +1 -1
  92. package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -1
  93. package/lib/typescript/utils/FetchUtil.d.ts +1 -1
  94. package/lib/typescript/utils/FetchUtil.d.ts.map +1 -1
  95. package/lib/typescript/utils/LogUtils.d.ts +15 -0
  96. package/lib/typescript/utils/LogUtils.d.ts.map +1 -0
  97. package/lib/typescript/utils/StorageUtil.d.ts.map +1 -1
  98. package/package.json +2 -2
  99. package/src/controllers/ApiController.ts +28 -8
  100. package/src/controllers/BlockchainApiController.ts +39 -29
  101. package/src/controllers/ConnectionsController.ts +14 -0
  102. package/src/controllers/EnsController.ts +2 -0
  103. package/src/controllers/EventsController.ts +73 -2
  104. package/src/controllers/LogController.ts +250 -0
  105. package/src/controllers/OnRampController.ts +12 -0
  106. package/src/controllers/SendController.ts +7 -2
  107. package/src/controllers/SwapController.ts +10 -2
  108. package/src/controllers/TransactionsController.ts +2 -0
  109. package/src/features/reown-authentication/ReownAuthentication.ts +11 -6
  110. package/src/index.ts +8 -0
  111. package/src/utils/ApiUtil.ts +1 -1
  112. package/src/utils/ConstantsUtil.ts +0 -1
  113. package/src/utils/CoreHelperUtil.ts +1 -1
  114. package/src/utils/FetchUtil.ts +11 -2
  115. package/src/utils/LogUtils.ts +179 -0
  116. package/src/utils/StorageUtil.ts +48 -49
@@ -3,17 +3,25 @@ import { ApiController } from './ApiController';
3
3
  import { OptionsController } from './OptionsController';
4
4
  import { CoreHelperUtil } from '../utils/CoreHelperUtil';
5
5
  import { FetchUtil } from '../utils/FetchUtil';
6
- import type { Event, EventName } from '@reown/appkit-common-react-native';
6
+ import type {
7
+ Event,
8
+ EventName,
9
+ WalletImpressionItem,
10
+ WcWallet
11
+ } from '@reown/appkit-common-react-native';
7
12
 
8
13
  // -- Helpers ------------------------------------------- //
9
14
  const baseUrl = CoreHelperUtil.getAnalyticsUrl();
10
15
  const api = new FetchUtil({ baseUrl });
11
16
  const excluded = ['MODAL_CREATED'];
17
+ const IMPRESSION_TIMEOUT = 3000;
12
18
 
13
19
  // -- Types --------------------------------------------- //
14
20
  export interface EventsControllerState {
15
21
  timestamp: number;
16
22
  data: Event;
23
+ pendingWalletImpressions: WalletImpressionItem[];
24
+ pendingImpressionTimeout?: NodeJS.Timeout;
17
25
  }
18
26
 
19
27
  // -- State --------------------------------------------- //
@@ -22,7 +30,9 @@ const state = proxy<EventsControllerState>({
22
30
  data: {
23
31
  type: 'track',
24
32
  event: 'MODAL_CREATED' // just for init purposes
25
- }
33
+ },
34
+ pendingWalletImpressions: [],
35
+ pendingImpressionTimeout: undefined
26
36
  });
27
37
 
28
38
  // -- Controller ---------------------------------------- //
@@ -41,6 +51,53 @@ export const EventsController = {
41
51
  });
42
52
  },
43
53
 
54
+ trackWalletImpression(props: {
55
+ wallet: WcWallet;
56
+ view: 'Connect' | 'AllWallets';
57
+ displayIndex: number;
58
+ query?: string;
59
+ installed?: boolean;
60
+ }) {
61
+ state.pendingWalletImpressions.push({
62
+ name: props.wallet.name ?? 'Unknown',
63
+ walletRank: props.wallet.order,
64
+ explorerId: props.wallet.id,
65
+ certified: props.wallet.badge_type === 'certified',
66
+ displayIndex: props.displayIndex,
67
+ view: props.view,
68
+ query: props.query,
69
+ installed: props.installed
70
+ });
71
+
72
+ if (state.pendingImpressionTimeout) {
73
+ clearTimeout(state.pendingImpressionTimeout);
74
+ }
75
+
76
+ state.pendingImpressionTimeout = setTimeout(() => {
77
+ EventsController.sendWalletImpressions();
78
+ }, IMPRESSION_TIMEOUT);
79
+ },
80
+
81
+ sendWalletImpressions() {
82
+ if (state.pendingImpressionTimeout) {
83
+ clearTimeout(state.pendingImpressionTimeout);
84
+ state.pendingImpressionTimeout = undefined;
85
+ }
86
+
87
+ const impressions = state.pendingWalletImpressions;
88
+
89
+ if (impressions.length === 0) {
90
+ return;
91
+ }
92
+
93
+ state.pendingWalletImpressions = [];
94
+ EventsController.sendEvent({
95
+ type: 'track',
96
+ event: 'WALLET_IMPRESSION',
97
+ items: impressions
98
+ });
99
+ },
100
+
44
101
  async _sendAnalyticsEvent(data: EventsControllerState['data'], timestamp: number) {
45
102
  if (excluded.includes(data.event)) {
46
103
  return;
@@ -50,6 +107,7 @@ export const EventsController = {
50
107
  await api.post({
51
108
  path: '/e',
52
109
  headers: ApiController._getApiHeaders(),
110
+ params: ApiController._getApiParams(),
53
111
  body: {
54
112
  eventId: CoreHelperUtil.getUUID(),
55
113
  bundleId: CoreHelperUtil.getBundleId(),
@@ -71,5 +129,18 @@ export const EventsController = {
71
129
  if (OptionsController.state.enableAnalytics) {
72
130
  EventsController._sendAnalyticsEvent(data, timestamp);
73
131
  }
132
+ },
133
+
134
+ resetState() {
135
+ if (state.pendingImpressionTimeout) {
136
+ clearTimeout(state.pendingImpressionTimeout);
137
+ state.pendingImpressionTimeout = undefined;
138
+ }
139
+ state.pendingWalletImpressions = [];
140
+ state.data = {
141
+ type: 'track',
142
+ event: 'MODAL_CREATED'
143
+ };
144
+ state.timestamp = Date.now();
74
145
  }
75
146
  };
@@ -0,0 +1,250 @@
1
+ import { proxy } from 'valtio';
2
+ import { OptionsController } from './OptionsController';
3
+ import { sanitizeString, sanitizeStackTrace, sanitizeValue, sanitizeData } from '../utils/LogUtils';
4
+ import { CoreHelperUtil } from '../utils/CoreHelperUtil';
5
+
6
+ // -- Types --------------------------------------------- //
7
+ export type LogLevel = 'info' | 'warn' | 'error' | 'debug';
8
+
9
+ export interface LogEntry {
10
+ id: string;
11
+ timestamp: number;
12
+ level: LogLevel;
13
+ message: string;
14
+ fileName?: string;
15
+ functionName?: string;
16
+ data?: Record<string, unknown>;
17
+ }
18
+
19
+ export interface LogControllerState {
20
+ logs: LogEntry[];
21
+ }
22
+
23
+ // -- Constants ----------------------------------------- //
24
+ const MAX_LOGS_COUNT = 300; // Prevent memory issues
25
+
26
+ // -- State --------------------------------------------- //
27
+ const state = proxy<LogControllerState>({
28
+ logs: []
29
+ });
30
+
31
+ const generateLogId = (): string => {
32
+ return CoreHelperUtil.getUUID();
33
+ };
34
+
35
+ const logToConsole = (entry: LogEntry) => {
36
+ const { debug } = OptionsController.state;
37
+
38
+ if (!debug) {
39
+ return;
40
+ }
41
+
42
+ const location =
43
+ entry.fileName && entry.functionName
44
+ ? `[${entry.fileName}:${entry.functionName}]`
45
+ : entry.fileName
46
+ ? `[${entry.fileName}]`
47
+ : '';
48
+
49
+ const logMessage = `[AppKit] ${location} ${entry.message}`;
50
+
51
+ switch (entry.level) {
52
+ case 'error':
53
+ // eslint-disable-next-line no-console
54
+ console.error(logMessage);
55
+ break;
56
+ case 'warn':
57
+ console.warn(logMessage);
58
+ break;
59
+ case 'debug':
60
+ // eslint-disable-next-line no-console
61
+ console.debug(logMessage);
62
+ break;
63
+ case 'info':
64
+ default:
65
+ // eslint-disable-next-line no-console
66
+ console.log(logMessage);
67
+ break;
68
+ }
69
+ };
70
+
71
+ // -- Controller ---------------------------------------- //
72
+ export const LogController = {
73
+ state,
74
+
75
+ /**
76
+ * Destroy the LogController (cleanup resources)
77
+ */
78
+ destroy() {
79
+ // Clear all logs
80
+ state.logs = [];
81
+ },
82
+
83
+ /**
84
+ * Send a general log entry
85
+ */
86
+ sendLog(
87
+ level: LogLevel,
88
+ message: string,
89
+ fileName?: string,
90
+ functionName?: string,
91
+ data?: Record<string, unknown>
92
+ ) {
93
+ if (!OptionsController.state.debug) {
94
+ return;
95
+ }
96
+ const entry: LogEntry = {
97
+ id: generateLogId(),
98
+ timestamp: Date.now(),
99
+ level,
100
+ message: sanitizeString(message),
101
+ fileName,
102
+ functionName,
103
+ data: sanitizeData(data)
104
+ };
105
+
106
+ state.logs.push(entry);
107
+
108
+ // Enforce maximum log count
109
+ if (state.logs.length > MAX_LOGS_COUNT) {
110
+ state.logs = state.logs.slice(-MAX_LOGS_COUNT);
111
+ }
112
+
113
+ logToConsole(entry);
114
+ },
115
+
116
+ /**
117
+ * Send an error log entry - convenience method for try/catch blocks
118
+ */
119
+ sendError(
120
+ error: Error | string | unknown,
121
+ fileName?: string,
122
+ functionName?: string,
123
+ additionalData?: Record<string, unknown>
124
+ ) {
125
+ let message: string;
126
+ let data: Record<string, unknown> = sanitizeData(additionalData) || {};
127
+
128
+ if (error instanceof Error) {
129
+ message = error.message || 'Error occurred';
130
+ // Sanitize stack trace to remove sensitive file paths
131
+ data['stack'] = error.stack ? sanitizeStackTrace(error.stack) : undefined;
132
+ data['name'] = error.name;
133
+
134
+ // Sanitize any additional properties on the error object
135
+ const errorProps: Record<string, unknown> = {};
136
+ Object.getOwnPropertyNames(error).forEach(prop => {
137
+ if (prop !== 'message' && prop !== 'stack' && prop !== 'name') {
138
+ errorProps[prop] = (error as any)[prop];
139
+ }
140
+ });
141
+
142
+ if (Object.keys(errorProps).length > 0) {
143
+ Object.assign(data, sanitizeValue(errorProps) as Record<string, unknown>);
144
+ }
145
+ } else if (typeof error === 'string') {
146
+ message = error;
147
+ } else if (error && typeof error === 'object' && 'message' in error) {
148
+ // Handle error-like objects (e.g., RPC errors, custom error objects)
149
+ message = String((error as any).message) || 'Error occurred';
150
+ // Include all properties of the error object
151
+ Object.assign(data, sanitizeValue(error) as Record<string, unknown>);
152
+ } else {
153
+ message = 'Unknown error occurred';
154
+ // Sanitize the original error object
155
+ data['originalError'] = sanitizeValue(error);
156
+ }
157
+
158
+ // Note: sanitization happens in sendLog method
159
+ this.sendLog('error', message, fileName, functionName, data);
160
+ },
161
+
162
+ /**
163
+ * Send an info log entry
164
+ */
165
+ sendInfo(
166
+ message: string,
167
+ fileName?: string,
168
+ functionName?: string,
169
+ data?: Record<string, unknown>
170
+ ) {
171
+ this.sendLog('info', message, fileName, functionName, data);
172
+ },
173
+
174
+ /**
175
+ * Send a warning log entry
176
+ */
177
+ sendWarn(
178
+ message: string,
179
+ fileName?: string,
180
+ functionName?: string,
181
+ data?: Record<string, unknown>
182
+ ) {
183
+ this.sendLog('warn', message, fileName, functionName, data);
184
+ },
185
+
186
+ /**
187
+ * Send a debug log entry
188
+ */
189
+ sendDebug(
190
+ message: string,
191
+ fileName?: string,
192
+ functionName?: string,
193
+ data?: Record<string, unknown>
194
+ ) {
195
+ this.sendLog('debug', message, fileName, functionName, data);
196
+ },
197
+
198
+ /**
199
+ * Get all logs
200
+ */
201
+ getLogs(): LogEntry[] {
202
+ return [...state.logs];
203
+ },
204
+
205
+ /**
206
+ * Get logs by level
207
+ */
208
+ getLogsByLevel(level: LogLevel): LogEntry[] {
209
+ return state.logs.filter(log => log.level === level);
210
+ },
211
+
212
+ /**
213
+ * Get recent logs (last N entries)
214
+ */
215
+ getRecentLogs(count: number = 100): LogEntry[] {
216
+ return state.logs.slice(-count);
217
+ },
218
+
219
+ /**
220
+ * Clear all logs
221
+ */
222
+ clearLogs() {
223
+ state.logs = [];
224
+ },
225
+
226
+ /**
227
+ * Export logs as JSON string for debugging
228
+ */
229
+ exportLogs(): string {
230
+ return JSON.stringify(state.logs, null, 2);
231
+ },
232
+
233
+ /**
234
+ * Get logs count by level
235
+ */
236
+ getLogsStats(): Record<LogLevel, number> {
237
+ const stats: Record<LogLevel, number> = {
238
+ info: 0,
239
+ warn: 0,
240
+ error: 0,
241
+ debug: 0
242
+ };
243
+
244
+ state.logs.forEach(log => {
245
+ stats[log.level]++;
246
+ });
247
+
248
+ return stats;
249
+ }
250
+ };
@@ -19,6 +19,7 @@ import { OptionsController } from './OptionsController';
19
19
  import { ConstantsUtil, OnRampErrorType } from '../utils/ConstantsUtil';
20
20
  import { StorageUtil } from '../utils/StorageUtil';
21
21
  import { SnackController } from './SnackController';
22
+ import { LogController } from './LogController';
22
23
  import { EventsController } from './EventsController';
23
24
  import { BlockchainApiController, EXCLUDED_ONRAMP_PROVIDERS } from './BlockchainApiController';
24
25
  import { ConnectionsController } from './ConnectionsController';
@@ -142,6 +143,7 @@ export const OnRampController = {
142
143
 
143
144
  StorageUtil.setOnRampPreferredCountry(country);
144
145
  } catch (error) {
146
+ LogController.sendError(error, 'OnRampController.ts', 'setSelectedCountry');
145
147
  state.loading = false;
146
148
  state.error = {
147
149
  type: OnRampErrorType.FAILED_TO_LOAD_COUNTRIES,
@@ -240,6 +242,7 @@ export const OnRampController = {
240
242
  countries.find(c => c.countryCode === countryCode) || countries[0] || undefined;
241
243
  }
242
244
  } catch (error) {
245
+ LogController.sendError(error, 'OnRampController.ts', 'fetchCountries');
243
246
  state.error = {
244
247
  type: OnRampErrorType.FAILED_TO_LOAD_COUNTRIES,
245
248
  message: 'Failed to load countries'
@@ -261,6 +264,7 @@ export const OnRampController = {
261
264
 
262
265
  state.countriesDefaults = countriesDefaults;
263
266
  } catch (error) {
267
+ LogController.sendError(error, 'OnRampController.ts', 'fetchCountriesDefaults');
264
268
  state.error = {
265
269
  type: OnRampErrorType.FAILED_TO_LOAD_COUNTRIES,
266
270
  message: 'Failed to load countries defaults'
@@ -282,6 +286,7 @@ export const OnRampController = {
282
286
 
283
287
  state.serviceProviders = serviceProviders || [];
284
288
  } catch (error) {
289
+ LogController.sendError(error, 'OnRampController.ts', 'fetchServiceProviders');
285
290
  state.error = {
286
291
  type: OnRampErrorType.FAILED_TO_LOAD_PROVIDERS,
287
292
  message: 'Failed to load service providers'
@@ -313,6 +318,7 @@ export const OnRampController = {
313
318
 
314
319
  state.selectedPaymentMethod = state.paymentMethods[0];
315
320
  } catch (error) {
321
+ LogController.sendError(error, 'OnRampController.ts', 'fetchPaymentMethods');
316
322
  state.error = {
317
323
  type: OnRampErrorType.FAILED_TO_LOAD_METHODS,
318
324
  message: 'Failed to load payment methods'
@@ -342,6 +348,7 @@ export const OnRampController = {
342
348
 
343
349
  state.purchaseCurrency = selectedCurrency || undefined;
344
350
  } catch (error) {
351
+ LogController.sendError(error, 'OnRampController.ts', 'fetchCryptoCurrencies');
345
352
  state.error = {
346
353
  type: OnRampErrorType.FAILED_TO_LOAD_CURRENCIES,
347
354
  message: 'Failed to load crypto currencies'
@@ -385,6 +392,7 @@ export const OnRampController = {
385
392
  this.setPaymentCurrency(defaultCurrency);
386
393
  }
387
394
  } catch (error) {
395
+ LogController.sendError(error, 'OnRampController.ts', 'fetchFiatCurrencies');
388
396
  state.error = {
389
397
  type: OnRampErrorType.FAILED_TO_LOAD_CURRENCIES,
390
398
  message: 'Failed to load fiat currencies'
@@ -503,6 +511,7 @@ export const OnRampController = {
503
511
  sp => sp.serviceProvider === state.selectedQuote?.serviceProvider
504
512
  );
505
513
  } catch (error: any) {
514
+ LogController.sendError(error, 'OnRampController.ts', 'getQuotes');
506
515
  if (error.name === 'AbortError') {
507
516
  // Do nothing, another request was made
508
517
  return;
@@ -553,6 +562,7 @@ export const OnRampController = {
553
562
 
554
563
  state.paymentCurrenciesLimits = limits;
555
564
  } catch (error) {
565
+ LogController.sendError(error, 'OnRampController.ts', 'fetchFiatLimits');
556
566
  state.error = {
557
567
  type: OnRampErrorType.FAILED_TO_LOAD_LIMITS,
558
568
  message: 'Failed to load fiat limits'
@@ -617,6 +627,7 @@ export const OnRampController = {
617
627
 
618
628
  return widget;
619
629
  } catch (e: any) {
630
+ LogController.sendError(e, 'OnRampController.ts', 'generateWidget', { quote });
620
631
  EventsController.sendEvent({
621
632
  type: 'track',
622
633
  event: 'BUY_FAIL',
@@ -662,6 +673,7 @@ export const OnRampController = {
662
673
  this.fetchFiatCurrencies()
663
674
  ]);
664
675
  } catch (error) {
676
+ LogController.sendError(error, 'OnRampController.ts', 'loadOnRampData');
665
677
  if (!state.error) {
666
678
  state.error = {
667
679
  type: OnRampErrorType.FAILED_TO_LOAD,
@@ -9,6 +9,7 @@ import { RouterController } from './RouterController';
9
9
  import { ConnectionsController } from './ConnectionsController';
10
10
  import { SwapController } from './SwapController';
11
11
  import { ConstantsUtil as CoreConstantsUtil } from '../utils/ConstantsUtil';
12
+ import { LogController } from './LogController';
12
13
 
13
14
  // -- Types --------------------------------------------- //
14
15
  export interface TxParams {
@@ -86,7 +87,7 @@ export const SendController = {
86
87
  isSmartAccount: ConnectionsController.state.accountType === 'smartAccount',
87
88
  token: this.state.token?.address ?? this.state.token?.symbol ?? '',
88
89
  amount: this.state.sendTokenAmount || 0,
89
- network: ConnectionsController.state.activeNetwork?.caipNetworkId ?? ''
90
+ network: ConnectionsController.state.activeNetwork?.caipNetworkId
90
91
  };
91
92
 
92
93
  try {
@@ -120,13 +121,17 @@ export const SendController = {
120
121
  RouterController.reset(isAuth ? 'Account' : 'AccountDefault');
121
122
  this.resetState();
122
123
  } catch (error: any) {
124
+ LogController.sendError(error, 'SendController.ts', 'sendToken');
123
125
  EventsController.sendEvent({
124
126
  type: 'track',
125
127
  event: 'SEND_ERROR',
126
128
  properties: eventProperties
127
129
  });
128
130
 
129
- if (error?.message && error?.message.includes('user rejected')) {
131
+ if (
132
+ error?.message &&
133
+ (error?.message.includes('user rejected') || error?.message.includes('canceled'))
134
+ ) {
130
135
  SnackController.showError('Transaction cancelled');
131
136
  } else {
132
137
  SnackController.showError('Something went wrong');
@@ -14,6 +14,7 @@ import { BlockchainApiController } from './BlockchainApiController';
14
14
  import { OptionsController } from './OptionsController';
15
15
  import { SwapCalculationUtil } from '../utils/SwapCalculationUtil';
16
16
  import { SnackController } from './SnackController';
17
+ import { LogController } from './LogController';
17
18
  import { RouterController } from './RouterController';
18
19
  import { CoreHelperUtil } from '../utils/CoreHelperUtil';
19
20
  import { TransactionsController } from './TransactionsController';
@@ -249,6 +250,7 @@ export const SwapController = {
249
250
  this.setSourceTokenAmount('1');
250
251
  }
251
252
  } catch (error) {
253
+ LogController.sendError(error, 'SwapController.ts', 'initializeState');
252
254
  SnackController.showError('Failed to initialize swap');
253
255
  RouterController.goBack();
254
256
  } finally {
@@ -491,6 +493,7 @@ export const SwapController = {
491
493
  this.setTransactionDetails();
492
494
  }
493
495
  } catch (error) {
496
+ LogController.sendError(error, 'SwapController.ts', 'getQuote');
494
497
  SnackController.showError('Failed to get swap quote');
495
498
  } finally {
496
499
  state.loadingQuote = false;
@@ -729,7 +732,7 @@ export const SwapController = {
729
732
  type: 'track',
730
733
  event: 'SWAP_SUCCESS',
731
734
  properties: {
732
- network: ConnectionsController.state.activeNetwork?.caipNetworkId || '',
735
+ network: ConnectionsController.state.activeNetwork?.caipNetworkId,
733
736
  swapFromToken: this.state.sourceToken?.symbol || '',
734
737
  swapToToken: this.state.toToken?.symbol || '',
735
738
  swapFromAmount: this.state.sourceTokenAmount || '',
@@ -750,6 +753,11 @@ export const SwapController = {
750
753
  return transactionHash;
751
754
  } catch (err) {
752
755
  const error = err as TransactionError;
756
+ LogController.sendError(error, 'SwapController.ts', 'sendTransactionForSwap', {
757
+ sourceToken: this.state.sourceToken?.symbol,
758
+ toToken: this.state.toToken?.symbol,
759
+ amount: this.state.sourceTokenAmount
760
+ });
753
761
  state.transactionError = error?.shortMessage;
754
762
  state.loadingTransaction = false;
755
763
  SnackController.showError(error?.shortMessage ?? 'Transaction error');
@@ -758,7 +766,7 @@ export const SwapController = {
758
766
  event: 'SWAP_ERROR',
759
767
  properties: {
760
768
  message: error?.shortMessage ?? error?.message ?? 'Unknown',
761
- network: ConnectionsController.state.activeNetwork?.caipNetworkId || '',
769
+ network: ConnectionsController.state.activeNetwork?.caipNetworkId,
762
770
  swapFromToken: this.state.sourceToken?.symbol || '',
763
771
  swapToToken: this.state.toToken?.symbol || '',
764
772
  swapFromAmount: this.state.sourceTokenAmount || '',
@@ -5,6 +5,7 @@ import { EventsController } from './EventsController';
5
5
  import { SnackController } from './SnackController';
6
6
  import { BlockchainApiController } from './BlockchainApiController';
7
7
  import { ConnectionsController } from './ConnectionsController';
8
+ import { LogController } from './LogController';
8
9
 
9
10
  // -- Types --------------------------------------------- //
10
11
  type TransactionByMonthMap = Record<string, Transaction[]>;
@@ -74,6 +75,7 @@ export const TransactionsController = {
74
75
  state.empty = nonSpamTransactions.length === 0;
75
76
  state.next = response?.next ? response.next : undefined;
76
77
  } catch (error) {
78
+ LogController.sendError(error, 'TransactionsController.ts', 'fetchTransactions');
77
79
  EventsController.sendEvent({
78
80
  type: 'track',
79
81
  event: 'ERROR_FETCH_TRANSACTIONS',
@@ -16,6 +16,8 @@ import { ConnectionsController } from '../../controllers/ConnectionsController';
16
16
  import { CoreHelperUtil } from '../../utils/CoreHelperUtil';
17
17
  import { OptionsController } from '../../controllers/OptionsController';
18
18
  import { FetchUtil } from '../../utils/FetchUtil';
19
+ import { ApiUtil } from '../../utils/ApiUtil';
20
+ import { LogController } from '../../controllers/LogController';
19
21
 
20
22
  /**
21
23
  * This is the configuration for using SIWX with Reown Authentication service.
@@ -108,7 +110,9 @@ export class ReownAuthentication implements SIWXConfig {
108
110
  this.emit('sessionChanged', session);
109
111
 
110
112
  return [session];
111
- } catch {
113
+ } catch (error) {
114
+ LogController.sendError(error, 'ReownAuthentication.ts', 'getSessions');
115
+
112
116
  return [];
113
117
  }
114
118
  }
@@ -299,13 +303,14 @@ export class ReownAuthentication implements SIWXConfig {
299
303
  }
300
304
 
301
305
  private getSDKProperties(): { projectId: string; st: string; sv: string; domain: string } {
302
- const headers = ApiController._getApiHeaders();
306
+ const { projectId, st, sv } = ApiController._getApiParams();
307
+ const domain = ApiUtil.getOrigin();
303
308
 
304
309
  return {
305
- projectId: headers['x-project-id'],
306
- st: headers['x-sdk-type'],
307
- sv: headers['x-sdk-version'],
308
- domain: headers['origin']
310
+ projectId,
311
+ st,
312
+ sv,
313
+ domain
309
314
  };
310
315
  }
311
316
 
package/src/index.ts CHANGED
@@ -16,6 +16,13 @@ export {
16
16
 
17
17
  export { SnackController, type SnackControllerState } from './controllers/SnackController';
18
18
 
19
+ export {
20
+ LogController,
21
+ type LogControllerState,
22
+ type LogEntry,
23
+ type LogLevel
24
+ } from './controllers/LogController';
25
+
19
26
  export { ApiController, type ApiControllerState } from './controllers/ApiController';
20
27
 
21
28
  export { AssetController, type AssetControllerState } from './controllers/AssetController';
@@ -54,6 +61,7 @@ export { CoreHelperUtil } from './utils/CoreHelperUtil';
54
61
  export { StorageUtil } from './utils/StorageUtil';
55
62
  export { EventUtil } from './utils/EventUtil';
56
63
  export { WalletUtil } from './utils/WalletUtil';
64
+ export { LogUtils } from './utils/LogUtils';
57
65
 
58
66
  // -- Features ----------------------------------------------------------------
59
67
  export { ReownAuthentication } from './features/reown-authentication/ReownAuthentication';
@@ -3,7 +3,7 @@ import { CoreHelperUtil } from './CoreHelperUtil';
3
3
 
4
4
  export const ApiUtil = {
5
5
  getOrigin() {
6
- return CoreHelperUtil.getBundleId();
6
+ return CoreHelperUtil.getBundleId() ?? 'react-native-unknown-origin';
7
7
  },
8
8
 
9
9
  getReactNativeVersion() {
@@ -37,7 +37,6 @@ export const ConstantsUtil = {
37
37
  NATIVE_TOKEN_ADDRESS: {
38
38
  eip155: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
39
39
  solana: 'So11111111111111111111111111111111111111111',
40
- polkadot: '0x',
41
40
  bip122: '0x'
42
41
  } as const satisfies Record<ChainNamespace, string>,
43
42
 
@@ -252,7 +252,7 @@ export const CoreHelperUtil = {
252
252
  });
253
253
  },
254
254
 
255
- getBundleId() {
255
+ getBundleId(): string | undefined {
256
256
  if ((global as any)?.Application?.applicationId) {
257
257
  return (global as any)?.Application?.applicationId;
258
258
  }